123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              .description
	// In progress....
	h1 HTML Design Mode Rich Text Editor
	p I wanted to try to recreate a TinyMCE type editor using 'contenteditable' and 'document.execCommand()'

.editor
	button(data-action='bold' title='Bold')
		i.fa.fa-bold
	button(data-action='italic' title='Italic')
		i.fa.fa-italic
	button(data-action='underline' title='Underline')
		i.fa.fa-underline
	
	.divider
	
	button(data-action='justifyLeft' title='Align Left')
		i.fa.fa-align-left

	button(data-action='justifyCenter' title='Align Center')
		i.fa.fa-align-center

	button(data-action='justifyRight' title='Align Right')
		i.fa.fa-align-right
		
	button(data-action='justifyFull' title='Justify')
		i.fa.fa-align-justify
		
	.divider
		
	button(data-action='insertUnorderedList' title='Bullet List')
		i.fa.fa-list-ul
		
	button(data-action='insertOrderedList' title='Numbered List')
		i.fa.fa-list-ol
		
	.divider
		
	select(title='Font Family' data-action='fontName')
		option(selected disabled) Font Family
		option(value='arial') Arial
		option(value='sans-serif') Sans Serif
		option(value='georgia') Georgia		
		option(value='impact') Impact
		option(value='roboto') Roboto
		option(value='verdana') Verdana
		
	select(title='Font Size' data-action='fontSize')
		each val, index in {1:'10px',2:'12px',3:'14px',4:'16px',5:'18px',6:'21px',7:'26px'}
			option(value=index)= val
		
	select(title='Format' data-action='formatBlock')
		option(selected disabled) Formatting
		option(value='h1') Heading 1
		option(value='h2') Heading 2
		option(value='h3') Heading 3
		option(value='p') Paragraph
		
	.divider
		
	button(data-action='createLink' title='Insert Link')
		i.fa.fa-link
		
	button(data-action='insertImage' title='Insert Image')
		i.fa.fa-image
		
	button(data-action='insertHorizontalRule' title="Insert Horizontal Rule") -
	
	.divider
	
	button(data-action='undo' title='Undo')
		i.fa.fa-undo
		
	button(data-action='redo' title='Redo')
		i.fa.fa-repeat
		
	button(data-action='removeFormat' title='Remove Formatting')
		i.fa.fa-eraser
		
	button(data-action='delete' title='Delete')
		i.fa.fa-trash

#document(contenteditable='true') 
	h1 Lorem ipsum, dolor sit amet consectetur adipisicing elit.
	p Assumenda magnam quibusdam error iste dicta sunt? Itaque minima fuga fugiat obcaecati quidem pariatur laboriosam quos velit atque suscipit, amet, natus nobis reprehenderit dolore possimus repellendus eaque in corporis! Modi, quae nulla ipsam omnis alias voluptates, nemo praesentium officiis excepturi veniam aliquid fugit sapiente eius reprehenderit beatae quasi libero laudantium iusto cumque.
	p
		img.right(src='http://via.placeholder.com/350x150')
		| Dolor numquam veritatis maiores suscipit perspiciatis, atque impedit corporis, maxime reiciendis fugit dolorum sapiente iste sunt ab animi, assumenda reprehenderit repellat rerum laudantium architecto ut. Reiciendis exercitationem expedita quod? Totam, rerum! Ratione quas provident eligendi. Aliquam tempore molestias hic quisquam veritatis consectetur ut, repellat deserunt voluptatum corrupti sit culpa accusantium, nulla sunt odit ipsa aut? Consequatur, maiores minima.
	p Commodi quibusdam molestias alias iusto nemo perferendis laudantium sed, ab, deserunt, praesentium quos perspiciatis ut officiis corrupti dolorem doloremque repellat tempore illum asperiores enim. Eveniet vero inventore repudiandae ut facilis alias amet natus minus maiores vel, eum placeat nobis ad, explicabo earum incidunt facere ullam repellat omnis eaque consequatur. Optio in quo suscipit commodi, quas tempore asperiores necessitatibus ab doloremque ad? Tempora rem iste repudiandae obcaecati aliquam quaerat soluta, atque debitis aliquid deserunt sed cumque minus quidem porro corporis sunt a! Quia.
            
          
!
            
              :root {
	font-family:sans-serif;	
	margin:10px;	
}

body {
	position:relative;
}

.description {
	margin-bottom:50px;
	padding:10px;
	background:#eee;
	border-radius:5px;
	
	h1{
		margin-bottom:0;
	}
	p {
		font-size:14px;
	}
}


#document {
	margin:25px 0;
	padding:10px;	
	font-size:15px;
	line-height:1.4;
	border-radius:5px;
	border:2px solid transparent;
	outline:none;
	
	&:hover,
	&:focus {
		border-color:fade(blue, 40%)	
	}
	
	li {
		margin-bottom:10px;
	}
	
	p {
		img {
			float:left;
			max-width:250px;
			width:100%;
			height:auto;
			margin:5px 5px 5px 0;

			&.right {
				float:right;
				margin:5px 0 5px 5px;
			}
		}		
	}
}

font[size='1'] { font-size:10px; }
font[size='2'] { font-size:12px; }
font[size='3'] { font-size:14px; }
font[size='4'] { font-size:16px; }
font[size='5'] { font-size:18px; }
font[size='6'] { font-size:21px; }
font[size='7'] { font-size:26px; }

.editor {
	border:1px solid #999;
	border-radius:5px;
	padding:10px;
	background:#eee;
	
	.hide {
		display:none;
	}
	
	.divider {
		margin:0 4px;
		display:inline-block;
		
		&:after {
			content:"|";
			color:#666;
		}
	}
	
	button {
		width:25px;
		text-transform:uppercase;
		font-weight:700;
		
		&[data-action='italic'] { font-style:italic }
		&[data-action='underline'] { text-decoration:underline }
	
		&:hover {
			background:#ccc;
			color:#fff;
		}	
	}
	
	button, select {
		background:#fff;
		border:1px solid #666;
		border-radius:5px;
		height:25px;
		margin:5px 2px;
		
		&:hover {
			cursor:pointer;
		}
	}
}


.context-menu {
	background:#fff;
	position:absolute;
	top:0; left:50%;
	padding:15px;
	border:1px solid #333;
}
            
          
!
            
              // Font Style
$('button').on('click', function(e) {
	var $this = $(this),
			action = $this.data("action");
	
	var aShowDefaultUI = false, aValueArgument = null;
	if($this.data('show-default-ui'))
		aShowDefaultUI = $this.data('show-default-ui');
	
	if($this.data('value-args'))		
		aValueArgument = $this.data('value-args');
	
	if($this.data('action') == 'createLink')
		aValueArgument = prompt("Please specify URL (including http protocol)", 'http://www.');
	
	if($this.data('action') == 'insertImage')
		aValueArgument = prompt("Please specify Image URL (including http protocol)", 'http://www.');	
	
	document.execCommand(action, aShowDefaultUI, aValueArgument);
});


// Font Formatting Selects
$('select').on('change', function() {
	var $this = $(this),
			action = $this.data("action"),
			aValueArgument = $this.val(),			
			aShowDefaultUI = false;
	
	if($this.data('show-default-ui'))
		aShowDefaultUI = $this.data('show-default-ui');	
	
	document.execCommand(action, aShowDefaultUI, aValueArgument);
});


// Image handling
$('img').on('click', function() {
	var $this = $(this);
	$this.toggleClass('right');
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console