<html>
<head>
<link class="jsbin" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
<meta charset=utf-8 />
<title>jQuery UI RTE - Default functionality</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
</style>
</head>
<body>
<div class="demo">
<textarea id="textarea" cols="50" rows="5">Hello world </textarea>
<a href="#" onclick="$('#textarea').rte('toggle')">Toogle</a></div><!-- End demo -->
<div class="demo-description">
<p>
Click headers to expand/collapse content that is broken into logical sections, much like tabs.
Optionally, toggle sections open/closed on mouseover.
</p>
<p>
The underlying HTML markup is a series of headers (H3 tags) and content divs so the content is
usable without JavaScript.
</p>
</div><!-- End demo-description -->
</body>
</html>
/*
* jQuery UI RichTextEditor 0.1.0
*
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* http://docs.jquery.com/UI/RichTextEditor
*
* Depends:
* jquery.ui.core.js
* jquery.ui.widget.js
*/
(function ($,undefined) {
$.widget ("ui.rte",
{
options:
{
cleanupData:true,
contentParser:null,
controlsActive:[
[ "Hide" ],
[ "Paste","-","Undo","Redo","-","RemoveFormat" ],
"/",
[ "Bold","Italic","Underline","Strikethrough","-","subscript","superscript" ],
[ "Outdent","Indent","-","InsertUnorderedList","InsertOrderedList" ],
[ "JustifyLeft","JustifyCenter","JustifyRight","JustifyFull" ],
[ "InsertHorizontalRule","Link","Unlink","-","Image" ],
[ "ForeColor","HiliteColor" ]
],
controlsInactive:[
[ "Show" ]
],
controlsSelected:[
[ "Hide" ],
[ "Cut","Copy","Paste","-","Undo","Redo","-","RemoveFormat" ],
"/",
[ "Bold","Italic","Underline","Strikethrough","-","subscript","superscript" ],
[ "Outdent","Indent","-","InsertUnorderedList","InsertOrderedList" ],
[ "JustifyLeft","JustifyCenter","JustifyRight","JustifyFull" ],
[ "InsertHorizontalRule","Link","Unlink","-","Image" ],
[ "ForeColor","HiliteColor" ]
],
designMode:true,
iframeCss:null,
presentationParser:null
},
_create:function ()
{
if ($.support.designMode)
{
var width = this.element.innerWidth (),height = this.element.innerHeight ();
if ($.support.contentEditable == null)
{
this.contentEditable = $("<div contentEditable='true' class='ui-widget-content' style='width:" + width + "px;height:" + height + "px;overflow:auto'>" + this.element.val () + "</div>");
if (typeof (this.contentEditable.get(0)['isContentEditable']) == "undefined")
{
$.support.contentEditable = false;
this.contentEditable.replaceWith ("<iframe src='javascript:\"\"' class='ui-widget-content' style='width:" + width + "px;height:" + height + "px'></iframe>");
}
else { $.support.contentEditable = true; }
}
else { this.contentEditable = ($.support.contentEditable ? $("<div contentEditable='true' class='ui-widget-content' style='width:" + width + "px;height:" + height + "px'>" + this.element.val () + "</div>") : $("<iframe src='javascript:\"\"' class='ui-widget-content' style='width:" + width + "px;height:" + height + "px'></iframe>")); }
this.element.after (this.contentEditable);
this.toggle (this.options.designMode);
}
},
_parseData:function (data) { return data; },
_parseDomChildNodes:function (childNodes)
{
var childNode,childName,pendingData = "",returnValue = "";
for (var i = 0;i < childNodes.length;i++)
{
childNode = childNodes[i];
try
{
switch (childNode.nodeType)
{
case 1:
{
childName = childNode.nodeName.toLowerCase ();
if ((childNode.hasChildNodes ())||(typeof (this._xmlNodes[childName]) == "undefined")||(!this._xmlNodes[childName]))
{
if ((this.options.cleanupData)&&(!childNode.hasChildNodes ())) { pendingData += ("<" + childName + ">" + (this._parseDomChildNodes (childNode.childNodes)) + "</" + childName + ">"); }
else { returnValue += (pendingData + "<" + childName + ">" + (this._parseDomChildNodes (childNode.childNodes)) + "</" + childName + ">"); }
pendingData = "";
}
else if ((this.options.cleanupData)&&(childName == "br")) { pendingData += ("<" + childName + " />"); }
else
{
returnValue += (pendingData + "<" + childName + " />");
pendingData = "";
}
break;
}
case 3:
{
returnValue += (pendingData + (childNode.nodeValue.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")));
pendingData = "";
break;
}
case 8:
{
returnValue += "<!--" + childNode.nodeValue + "-->";
break;
}
default:
{
alert (childNode.nodeName);
break;
}
}
}
catch (unhandledException) { }
}
return returnValue;
},
_setEditableContent:function (content)
{
if ($.support.contentEditable)
{
this.contentEditable.empty ();
this.contentEditable.append (content);
}
else { this._setIFrameContent (content); }
},
_setIFrameContent:function (data)
{
var body = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'><html><head><title>Editor</title><style type='text/css'><!--\nbody { margin:0px;padding:0px }\n// --></style>";
for (var i = 0;i < self.document.styleSheets.length;i++)
{
var f_stylesheet = self.document.styleSheets[i];
if (!f_stylesheet.disabled) { body += "<link rel='stylesheet' type='" + f_stylesheet.type + "' href='" + f_stylesheet.href + "'>"; }
}
if (this.options.iframeCss !== null) { body += "<link rel='stylesheet' type='text/css' href='" + this.options.iframeCss + "'>"; }
body += "</head><body style='" + self.getComputedStyle(this.element.get (0),null).cssText + "'>" + data + "</body></html>";
var iframe = this.contentEditable.get(0).contentWindow;
iframe.document.open ();
iframe.document.write (body);
iframe.document.close ();
iframe.document.designMode = "on";
},
_setTextAreaContent:function (content)
{
this.element.val (content);
},
_setOption:function (key,value)
{
$.Widget.prototype._setOption.apply (this,arguments);
},
_xmlNodes:{ "area":true,"audio":true,"base":true,"br":true,"canvas":true,
"embed":true,"hr":true,"iframe":true,"img":true,"input":true,"keygen":true,
"link":true,"meta":true,"object":true,"option":true,"output":true,
"param":true,"video":true },
destroy:function ()
{
if ($.support.designMode)
{
this.toggle (false);
this.contentEditable.remove ();
return $.Widget.prototype.destroy.call (this);
}
},
toggle:function (mode)
{
if ($.support.designMode)
{
if (mode == null) { mode = (!this.designMode); }
if (mode != this.designMode)
{
if (mode)
{
if (this.options.contentParser === null) { var content = this._parseData (this.element.val ()); }
else { var content = this.options.contentParser (this.element.val ()); }
if (content !== null)
{
this._setEditableContent (content);
this.element.hide ();
this.contentEditable.show ();
}
}
else
{
var content = ($.support.contentEditable ? this.contentEditable.get (0) : this.contentEditable.get(0).contentWindow.document.getElementsByTagName("body")[0]);
if ((typeof (content) == "undefined")||(!content.hasChildNodes ())) { content = null; }
else { content = content.childNodes; }
if (this.options.presentationParser === null) { content = this._parseDomChildNodes (content); }
else { content = this.options.presentationParser (content); }
if (content !== null)
{
this._setTextAreaContent (content);
this.contentEditable.hide ();
this.element.show ();
}
}
this.designMode = mode;
}
}
return false;
}
});
$.extend ($.support,{ contentEditable:null,designMode:(typeof (self.document['designMode']) != "undefined") });
$.extend ($.ui.rte,{ version:"0.1.0" });
})(jQuery);
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |