/*! Django Messages UI - v2.0.2 - 2015-03-01 * https://github.com/jgerigmeyer/jquery-django-messages-ui * Copyright (c) 2015 Jonny Gerig Meyer; Licensed MIT */ !function(a){"use strict";var b=0,c={init:function(b){var d=a(this),e=a.extend({},a.fn.messages.defaults,d.data("messages-ui-opts"),b);return d.data("messages-ui-opts",e),e.closeLink&&d.on("click",e.message+" "+e.closeLink,function(f){f.preventDefault(),a(this).blur();var g=a(this).closest(e.message);c.remove(g,b,d)}),e.handleAjax&&a.ajaxSetup({dataType:"json",dataFilter:function(e,f){if(e&&"json"===f){var g;try{g=a.parseJSON(e)}catch(h){g=!1}if(g&&g.messages){var i=a(g.messages);i.each(function(){c.add(this,b,d)})}}return e}}),c.bindHandlers(d.find(e.message),e,d),d},add:function(b,d,e){var f,g=e||a(this),h=a.extend({},a.fn.messages.defaults,g.data("messages-ui-opts"),d),i=b||{},j=h.template||Handlebars.templates.message;if(i.escapeHTML=h.escapeHTML,!j||"function"!=typeof j)throw new Error("Template not found");return f=a(j(i)),f.appendTo(g),c.bindHandlers(f,h,g),f},remove:function(b,c,d){var e=d||a(this),f=a.extend({},a.fn.messages.defaults,e.data("messages-ui-opts"),c);b.data("count")&&a.doTimeout("msg-"+b.data("count")),f.closeCallback&&f.closeCallback(b)},bindHandlers:function(c,d,e){var f=e||a(this),g=a.extend({},a.fn.messages.defaults,f.data("messages-ui-opts"),d),h=c.filter(g.transientMessage);if(h.length){var i=function(b){var c=b.data("count");a(document).off(".msg-"+c),b.off(".msg-"+c),a.doTimeout("msg-"+c,g.transientDelay,function(){g.transientCallback&&g.transientCallback(b)})};h.each(function(){var c=a(this);b+=1,c.data("count",b),a(document).one("mousedown.msg-"+b+" keydown.msg-"+b+" scroll.msg-"+b,function(){i(c)}),c.one("mouseover.msg-"+b,function(){i(c)})})}},exposeMethods:function(){return c}};a.fn.messages=function(b){return c[b]?c[b].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof b&&b?void a.error("Method "+b+" does not exist on jQuery.messages"):c.init.apply(this,arguments)},a.fn.messages.defaults={message:".message",transientMessage:".success",closeLink:".close",closeCallback:function(a){a.stop().fadeOut("fast",function(){a.remove()})},transientDelay:500,transientCallback:function(a){a.fadeOut(2e3,function(){a.remove()})},handleAjax:!1,template:!1,escapeHTML:!0}}(jQuery);