Update notifyjs

This commit is contained in:
Daniel Berteaud 2016-09-02 09:05:39 +02:00
parent 29f8dfba4c
commit 9af7c613a1
1 changed files with 19 additions and 10 deletions

View File

@ -91,6 +91,15 @@
return styles[name]; return styles[name];
}; };
var removeStyle = function(name) {
if (!name) {
throw "Missing Style name";
}
if (styles[name]) {
delete styles[name];
}
};
var addStyle = function(name, def) { var addStyle = function(name, def) {
if (!name) { if (!name) {
throw "Missing Style name"; throw "Missing Style name";
@ -337,7 +346,7 @@
var align = positions[pAlign]; var align = positions[pAlign];
var key = pMain + "|" + pAlign; var key = pMain + "|" + pAlign;
var anchor = globalAnchors[key]; var anchor = globalAnchors[key];
if (!anchor) { if (!anchor || !document.contains(anchor[0])) {
anchor = globalAnchors[key] = createElem("div"); anchor = globalAnchors[key] = createElem("div");
var css = {}; var css = {};
css[main] = 0; css[main] = 0;
@ -522,7 +531,8 @@
}; };
Notification.prototype.destroy = function() { Notification.prototype.destroy = function() {
return this.wrapper.remove(); this.wrapper.data(pluginClassName, null);
this.wrapper.remove();
}; };
$[pluginName] = function(elem, data, options) { $[pluginName] = function(elem, data, options) {
@ -538,13 +548,11 @@
$.fn[pluginName] = function(data, options) { $.fn[pluginName] = function(data, options) {
$(this).each(function() { $(this).each(function() {
var inst; var prev = getAnchorElement($(this)).data(pluginClassName);
inst = getAnchorElement($(this)).data(pluginClassName); if (prev) {
if (inst) { prev.destroy();
return inst.run(data, options);
} else {
return new Notification($(this), data, options);
} }
var curr = new Notification($(this), data, options);
}); });
return this; return this;
}; };
@ -552,6 +560,7 @@
$.extend($[pluginName], { $.extend($[pluginName], {
defaults: defaults, defaults: defaults,
addStyle: addStyle, addStyle: addStyle,
removeStyle: removeStyle,
pluginOptions: pluginOptions, pluginOptions: pluginOptions,
getStyle: getStyle, getStyle: getStyle,
insertCSS: insertCSS insertCSS: insertCSS
@ -603,9 +612,9 @@
$(function() { $(function() {
insertCSS(coreStyle.css).attr("id", "core-notify"); insertCSS(coreStyle.css).attr("id", "core-notify");
$(document).on("click", "." + pluginClassName + "-hidable", function(e) { $(document).on("click", "." + pluginClassName + "-hidable", function(e) {
return $(this).trigger("notify-hide"); $(this).trigger("notify-hide");
}); });
return $(document).on("notify-hide", "." + pluginClassName + "-wrapper", function(e) { $(document).on("notify-hide", "." + pluginClassName + "-wrapper", function(e) {
var elem = $(this).data(pluginClassName); var elem = $(this).data(pluginClassName);
if(elem) { if(elem) {
elem.show(false); elem.show(false);