<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js"></script>
<title>Sandbox</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen">
body{font-family:Verdana;}
#jNotify{
position:fixed; top:10px; margin-left:auto; margin-right:auto; width:50%;
}
.jNotify-notification{
display:none;
padding:10px;
max-width:400px;
margin-bottom:10px;
position:fixed;
cursor:move;
/*Shadows for CSS3 browsers*/
box-shadow:0 0 8px #333;
box-shadow:0 0 8px #333;
box-shadow:0 0 8px #333;
}
.jNotify-notification .title{font-weight:bold;}
.jNotify-notification .title, .jNotify-notification .message{margin-right:20px;}
.jNotify-close{
height:18px;
margin:-8px 0 0;
padding:1px;
position:absolute;
right:3px;
width:19px;
cursor:pointer;
}
.jNotify-closer{
display:none;
position:fixed;
top:5px;
right:5px;
padding:5px;
cursor:pointer;
}
.jNotify-notification .jNotify-icon{float:left; margin-right:3px;}
.jNotify-close .ui-icon, .jNotify-closer .ui-icon{margin:1px;display:block;}
.jNotify-closer .ui-icon{float:left;}
</style>
</head>
<body>
<h1>Custom jQuery Notifications</h1>
<h5>Clicking the buttons too fast seems to break everything</h5>
<p>
<button onclick="$.jNotify('There is no title!',{icon:''});">Info (no icon)</button> -
<button onclick="$.jNotify('Hello world!',{title:'My Title!'});">Info with a title</button>
</p>
<p>
<button onclick="$.jNotify('Something broke.',{state:'ui-state-error',icon:'ui-icon-alert',sticky:true});">Error</button> -
<button onclick="$.jNotify('Something has gone horribly wrong and this has a lot of extra text!',{title:'Error!',state:'ui-state-error',icon:'ui-icon-alert',sticky:true});">Error with a title</button>
</p>
</body>
</html>
/*
jNotify 1.0
Code based on the jGrowl plugin by Stan Lemon - http://www.stanlemon.net/projects/jgrowl.html
Modified by Chris Barr - http://chris-barr.com
*/
(function($) {
/** jNotify Wrapper - Establish a base jNotify Container for compatibility with older releases. **/
$.jNotify = function( m , o ) {
// To maintain compatibility with older version that only supported one instance we'll create the base container.
if ( $('#jNotify').size() == 0 ) $('<div id="jNotify"></div>').appendTo('body');
// Create a notification on the container.
$('#jNotify').jNotify(m,o);
};
/** Raise jNotify Notification on a jNotify Container **/
$.fn.jNotify = function( m , o ) {
if ( $.isFunction(this.each) ) {
var args = arguments;
return this.each(function() {
var self = this;
/** Create a jNotify Instance on the Container if it does not exist **/
if ( $(this).data('jNotify.instance') == undefined ) {
$(this).data('jNotify.instance', new $.fn.jNotify());
$(this).data('jNotify.instance').startup( this );
}
/** Optionally call jNotify instance methods, or just raise a normal notification **/
if ( $.isFunction($(this).data('jNotify.instance')[m]) ) {
$(this).data('jNotify.instance')[m].apply( $(this).data('jNotify.instance') , $.makeArray(args).slice(1) );
} else {
$(this).data('jNotify.instance').notification( m , o );
}
});
};
};
$.extend( $.fn.jNotify.prototype , {
/** Default jNotify Settings **/
defaults: {
title: '',
sticky: false,
draggable: true,
roundedCorners: true,
state: 'ui-state-highlight',
icon: 'ui-icon-info',
check: 500,
life: 5000,
speed: 400,
easing: 'swing',
closer: true,
closerTemplate: '<div><span class="ui-icon ui-icon-closethick"></span>close all messages</div>',
closerState: 'ui-state-default',
dragOptions: {
containment:'html',
scroll:true,
scrollSensitivity:100,
scrollSpeed:100,
opacity:0.9,
stack:{
group:'#jNotify .ui-draggable',
min:5000
}
},
log: function(e,m,o) {},
beforeOpen: function(e,m,o) {},
open: function(e,m,o) {},
beforeClose: function(e,m,o) {},
close: function(e,m,o) {},
useFx: true,
openFx: "drop",
openFxOptions: {
direction:"up",
easing:"easeOutBounce",
duration:400
},
closeFx: "drop",
closeFxOptions: {
direction:"down",
easing:"easeInBack",
duration:400
},
animateOpen: {opacity:'show'},
animateClose: {opacity:'hide'}
},
/** jNotify Container Node **/
element: null,
/** Interval Function **/
interval: null,
/** Create a Notification **/
notification: function( message, o ) {
var self = this;
var o = $.extend({}, this.defaults, o);
var corner=(o.roundedCorners)?" ui-corner-all ":" ";
var icon=(o.icon!='')?"<span class='jNotify-icon ui-icon "+o.icon+"'></span>":"";
o.log.apply( this.element , [this.element,message,o] );
var notification = $('<div class="jNotify-notification'+corner+o.state+'">'+
'<span class="jNotify-close'+corner+'"><span class="ui-icon ui-icon-closethick"></span></span>'+
'<div class="title">'+icon+o.title+'</div><div class="message">'+message+'</div></div>')
.data("jNotify",o)
.children('.jNotify-close')
.hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');})
.bind("click.jNotify", function() {
if(o.useFx){
$(this).unbind('click.jNotify').parent().trigger('jNotify.beforeClose').hide(o.closeFx,o.closeFxOptions, function() {
$(this).trigger('.jNotify-close').remove();
});
}else{
$(this).unbind('click.jNotify').parent().trigger('jNotify.beforeClose').animate(o.animateClose, o.speed, o.easing, function() {
$(this).trigger('.jNotify-close').remove();
});
}
}).parent();
if(o.draggable) notification.draggable(o.dragOptions);
nextTop= $('.jNotify-notification:last', this.element).offset().top+$('.jNotify-notification:last', this.element).outerHeight(true);
console.log(nextTop);
//insert after other notifications
$('.jNotify-notification:last', this.element).after(notification);
/** Notification Actions **/
$(notification).bind("mouseover.jNotify", function() {
$(this).data("jNotify").pause = true;
}).bind("mouseout.jNotify", function() {
$(this).data("jNotify").pause = false;
}).bind('jNotify.beforeOpen', function() {
o.beforeOpen.apply( self.element , [self.element,message,o] );
}).bind('jNotify.open', function() {
o.open.apply( self.element , [self.element,message,o] );
}).bind('jNotify.beforeClose', function() {
o.beforeClose.apply( self.element , [self.element,message,o] );
}).bind('jNotify.close', function() {
o.close.apply( self.element , [self.element,message,o] );
}).trigger('jNotify.beforeOpen')
.css("top",nextTop);
if(o.useFx){
$(notification).show(o.openFx, o.openFxOptions, function() {
$(this).data("jNotify").created = new Date();
}).dequeue();
}else{
$(notification).animate(o.animateOpen, o.speed, o.easing, function() {
$(this).data("jNotify").created = new Date();
});
}
$(notification).trigger('jNotify.open');
/** Add a Global Closer if more than one notification exists **/
if ( $('.jNotify-notification:parent', this.element).size() > 1 && $('.jNotify-closer', this.element).size() == 0 && this.defaults.closer != false ) {
$(this.defaults.closerTemplate)
.addClass('jNotify-closer'+corner+this.defaults.closerState)
.appendTo(this.element);
if(this.defaults.useFx){
$("#jNotify .jNotify-closer").show(this.defaults.openFx, this.defaults.openFxOptions).dequeue();
}else{
$("#jNotify .jNotify-closer").animate(this.defaults.animateOpen, this.defaults.speed, this.defaults.easing);
}
$("#jNotify .jNotify-closer")
.hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');})
.bind("click.jNotify", function() {
$(this).siblings().children('.jNotify-close').trigger("click.jNotify");
if ( $.isFunction( self.defaults.closer ) ) self.defaults.closer.apply( $(this).parent()[0] , [$(this).parent()[0]] );
});
};
},
/** Update the jNotify Container, removing old jNotify notifications **/
update: function() {
$(this.element).find('div.jNotify-notification:parent').each( function() {
if ( $(this).data("jNotify") != undefined && $(this).data("jNotify").created != undefined && ($(this).data("jNotify").created.getTime() + $(this).data("jNotify").life) < (new Date()).getTime() && $(this).data("jNotify").sticky != true &&
($(this).data("jNotify").pause == undefined || $(this).data("jNotify").pause != true) ) {
$(this).children('.jNotify-close').trigger('click.jNotify');
}
});
if ( $(this.element).find('div.jNotify-notification:parent').size() < 2 ) {
if(this.defaults.useFx){
$(this.element).find('div.jNotify-closer').hide(this.defaults.closeFx,this.defaults.closeFxOptions, function() {
$(this).remove();
});
}else{
$(this.element).find('div.jNotify-closer').animate(this.defaults.animateClose, this.defaults.speed, this.defaults.easing, function() {
$(this).remove();
});
}
};
},
/** Setup the jNotify Notification Container **/
startup: function(e) {
this.element = $(e).addClass('jNotify').append('<div class="jNotify-notification"></div>');
this.interval = setInterval( function() { jQuery(e).data('jNotify.instance').update(); }, this.defaults.check);
if ($.browser.msie && parseInt($.browser.version) < 7 && !window["XMLHttpRequest"]) $(this.element).addClass('ie6');
},
/** Shutdown jNotify, removing it and clearing the interval **/
shutdown: function() {
$(this.element).removeClass('jNotify').find('div.jNotify-notification').remove();
clearInterval( this.interval );
}
});
})(jQuery);
Output
300px
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. |