<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</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>
<p id="hello">Hello World df kasfsdkalf sdklfjsdlkjf skdfj dskf kfjkl sdkjfsdlkf jsdlkfj lsdjf klsd fjlkdjf k dffgasg sdfgsd gsdg sgagsafgsfgsfg sgasragsg sgsfgdagasfgsfagsagsfagasg</p>
</body>
</html>
/*
@author: remy sharp / http://remysharp.com
@params:
feedback - the selector for the element that gives the user feedback. Note that this will be relative to the form the plugin is run against.
hardLimit - whether to stop the user being able to keep adding characters. Defaults to true.
useInput - whether to look for a hidden input named 'maxlength' instead of the maxlength attribute. Defaults to false.
words - limit by characters or words, set this to true to limit by words. Defaults to false.
@license: Creative Commons License - ShareAlike http://creativecommons.org/licenses/by-sa/3.0/
@version: 1.2
@changes: code tidy via Ariel Flesler and fix when pasting over limit and including \t or \n
*/
(function ($) {
$.fn.maxlength = function (settings) {
if (typeof settings == 'string') {
settings = { feedback : settings };
}
settings = $.extend({}, $.fn.maxlength.defaults, settings);
function length(el) {
var parts = el.value;
if ( settings.words )
parts = el.value.length ? parts.split(/\s+/) : { length : 0 };
return parts.length;
}
return this.each(function () {
var field = this,
$field = $(field),
$form = $(field.form),
limit = settings.useInput ? $form.find('input[name=maxlength]').val() : $field.attr('maxlength'),
$charsLeft = $form.find(settings.feedback);
function limitCheck(event) {
var len = length(this),
exceeded = len >= limit,
code = event.keyCode;
if ( !exceeded )
return;
switch (code) {
case 8: // allow delete
case 9:
case 17:
case 36: // and cursor keys
case 35:
case 37:
case 38:
case 39:
case 40:
case 46:
case 65:
return;
default:
return settings.words && code != 32 && code != 13 && len == limit;
}
}
var updateCount = function () {
var len = length(field),
diff = limit - len;
$charsLeft.html( diff || "0" );
// truncation code
if (settings.hardLimit && diff < 0) {
field.value = settings.words ?
// split by white space, capturing it in the result, then glue them back
field.value.split(/(\s+)/, (limit*2)-1).join('') :
field.value.substr(0, limit);
updateCount();
}
};
$field.keyup(updateCount).change(updateCount);
if (settings.hardLimit) {
$field.keydown(limitCheck);
}
updateCount();
});
};
$.fn.maxlength.defaults = {
useInput : false,
hardLimit : true,
feedback : '.charsLeft',
words : false
};
})(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. |