Based on @kennypu comment, I've done this:
I haven't tested it at all, but I think this is a good way to refactor your plugin :
(function( $ ) {
$.fn.myPlugin = function( options ) {
// Create some defaults, extending them with any options that were provided
var settings = $.extend( {
message : "Hello World!",
animSpeed : 300,
animType : 'fadeIn',
icon : "pin",
btnText : "Purchase",
btnColor : "pink",
btnLink : 'www.google.com',
}, options);
// A tidier way to create the content would be to use jQuery like this : http://api.jquery.com/jQuery/#jQuery2
var content : '<div id="mn_close" class="light"></div>' + '<div id="mn_border"></div>' + '<i class="icon-' + settings.icon + '"></i>' + '<span class="mn_message">' + settings.message + '</span>' + '<a href="' + settings.btnLink + '" class="button ' + settings.btnColor + '">' + settings.btnText + '</a>';
var mn_bar = $(".mn_bar");
mn_bar.append(content);
$("#mn_close").on("click", function () {
mn_bar.animate({
top: '-50'
}, settings.animSpeed, function () {});
});
mn_bar.addClass("animated " + settings.animType);
})
})(jQuery);
EDIT : I set a variable for .mn_bar
because there is no reason to look for this element in the DOM again. And I also removed the two calls to addClass()
and made only one.