Skip to content

Instantly share code, notes, and snippets.

@dnoiz1
Created December 15, 2012 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnoiz1/4291242 to your computer and use it in GitHub Desktop.
Save dnoiz1/4291242 to your computer and use it in GitHub Desktop.
(function($){
$.confirm = function(params){
if($('#confirmOverlay').length){
// A confirm is already shown on the page:
return false;
}
var buttonHTML = '';
$.each(params.buttons,function(name,obj){
// Generating the markup for the buttons:
buttonHTML += '<a href="#" class="button '+obj['class']+'">'+name+'<span></span></a>';
if(!obj.action){
obj.action = function(){ return true };
}
});
var markup = [
'<div id="confirmOverlay"></div>',
'<div id="confirmBox">',
'<h1>',params.title,'</h1>',
'<p>',params.message,'</p>',
'<div id="confirmButtons">',
buttonHTML,
'</div></div>'
].join('');
$(markup).hide().appendTo('body').fadeIn(function(){
if(typeof params['onload'] == 'function') params.onload();
});
var buttons = $('#confirmBox .button'),
i = 0;
$.each(params.buttons,function(name,obj){
buttons.eq(i++).click(function(){
// Calling the action attribute when a
// click occurs, and hiding the confirm.
if(obj.action() !== false) $.confirm.hide();
return false;
});
});
}
$.confirm.hide = function(){
$('#confirmOverlay').fadeOut(function(){
$(this).remove();
});
$('#confirmBox').fadeOut(function(){
$(this).remove();
});
}
})(jQuery);
jQuery.confim({
title: 'Confirm Order',
message: 'confirm the shit out of whatever this is',
buttons: {
'Confirm': {
class: 'btn',
action: function(){ console.log('gogogoog'); } //le bouf dat
},
'Cancel': {
class: 'btn',
action: function(){ console.log('nonononono'); }
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment