Last active
December 15, 2015 12:38
-
-
Save jorgepinon/5261177 to your computer and use it in GitHub Desktop.
A tiny jquery plugin that adds a close link to an alert div
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
$.fn.extend({ | |
//pass the options variable to the function | |
alert: function(options) { | |
//Set the default values | |
var defaults = { | |
pull: 'right', | |
callback: function () {} | |
} | |
var options = $.extend(defaults, options); | |
return this.each(function() { | |
var opts = options; | |
// assign current alert to a variable | |
var alertbox = $(this), | |
closeLink = '<a href="#" class="icon-close pull-' + opts.pull + '">×</a>'; | |
// remove any existing close icons | |
$(this).find(".icon-close").remove(); | |
$(this).prepend(closeLink).on('click', function (e) { | |
e.preventDefault(); | |
$(this).closest(".alert").fadeOut(200, function () { | |
$(this).remove(); | |
if (typeof defaults.callback == 'function') { | |
defaults.callback.call(this); | |
} | |
}); | |
}); | |
}); | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment