2018-05-05 13:35:10 +00:00
|
|
|
/*! UIkit 2.27.4 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
|
2016-03-06 00:50:22 +00:00
|
|
|
(function(addon) {
|
|
|
|
|
|
|
|
var component;
|
|
|
|
|
2018-05-05 13:35:10 +00:00
|
|
|
if (window.UIkit2) {
|
|
|
|
component = addon(UIkit2);
|
2016-03-06 00:50:22 +00:00
|
|
|
}
|
|
|
|
|
2018-05-05 13:35:10 +00:00
|
|
|
if (typeof define == 'function' && define.amd) {
|
|
|
|
define('uikit-notify', ['uikit'], function(){
|
|
|
|
return component || addon(UIkit2);
|
2016-03-06 00:50:22 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
})(function(UI){
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var containers = {},
|
|
|
|
messages = {},
|
|
|
|
|
|
|
|
notify = function(options){
|
|
|
|
|
|
|
|
if (UI.$.type(options) == 'string') {
|
|
|
|
options = { message: options };
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arguments[1]) {
|
|
|
|
options = UI.$.extend(options, UI.$.type(arguments[1]) == 'string' ? {status:arguments[1]} : arguments[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (new Message(options)).show();
|
|
|
|
},
|
|
|
|
closeAll = function(group, instantly){
|
|
|
|
|
|
|
|
var id;
|
|
|
|
|
|
|
|
if (group) {
|
|
|
|
for(id in messages) { if(group===messages[id].group) messages[id].close(instantly); }
|
|
|
|
} else {
|
|
|
|
for(id in messages) { messages[id].close(instantly); }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var Message = function(options){
|
|
|
|
|
|
|
|
this.options = UI.$.extend({}, Message.defaults, options);
|
|
|
|
|
2018-05-05 13:35:10 +00:00
|
|
|
this.uuid = UI.Utils.uid('notifymsg');
|
2016-03-06 00:50:22 +00:00
|
|
|
this.element = UI.$([
|
|
|
|
|
|
|
|
'<div class="uk-notify-message">',
|
|
|
|
'<a class="uk-close"></a>',
|
|
|
|
'<div></div>',
|
|
|
|
'</div>'
|
|
|
|
|
|
|
|
].join('')).data("notifyMessage", this);
|
|
|
|
|
|
|
|
this.content(this.options.message);
|
|
|
|
|
|
|
|
// status
|
|
|
|
if (this.options.status) {
|
|
|
|
this.element.addClass('uk-notify-message-'+this.options.status);
|
|
|
|
this.currentstatus = this.options.status;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.group = this.options.group;
|
|
|
|
|
|
|
|
messages[this.uuid] = this;
|
|
|
|
|
|
|
|
if(!containers[this.options.pos]) {
|
|
|
|
containers[this.options.pos] = UI.$('<div class="uk-notify uk-notify-'+this.options.pos+'"></div>').appendTo('body').on("click", ".uk-notify-message", function(){
|
|
|
|
|
2018-05-05 13:35:10 +00:00
|
|
|
var message = UI.$(this).data('notifyMessage');
|
2016-03-06 00:50:22 +00:00
|
|
|
|
|
|
|
message.element.trigger('manualclose.uk.notify', [message]);
|
|
|
|
message.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
UI.$.extend(Message.prototype, {
|
|
|
|
|
|
|
|
uuid: false,
|
|
|
|
element: false,
|
|
|
|
timout: false,
|
|
|
|
currentstatus: "",
|
|
|
|
group: false,
|
|
|
|
|
|
|
|
show: function() {
|
|
|
|
|
2018-05-05 13:35:10 +00:00
|
|
|
if (this.element.is(':visible')) return;
|
2016-03-06 00:50:22 +00:00
|
|
|
|
|
|
|
var $this = this;
|
|
|
|
|
|
|
|
containers[this.options.pos].show().prepend(this.element);
|
|
|
|
|
2018-05-05 13:35:10 +00:00
|
|
|
var marginbottom = parseInt(this.element.css('margin-bottom'), 10);
|
2016-03-06 00:50:22 +00:00
|
|
|
|
2018-05-05 13:35:10 +00:00
|
|
|
this.element.css({opacity:0, marginTop: -1*this.element.outerHeight(), marginBottom:0}).animate({opacity:1, marginTop:0, marginBottom:marginbottom}, function(){
|
2016-03-06 00:50:22 +00:00
|
|
|
|
|
|
|
if ($this.options.timeout) {
|
|
|
|
|
|
|
|
var closefn = function(){ $this.close(); };
|
|
|
|
|
|
|
|
$this.timeout = setTimeout(closefn, $this.options.timeout);
|
|
|
|
|
|
|
|
$this.element.hover(
|
|
|
|
function() { clearTimeout($this.timeout); },
|
|
|
|
function() { $this.timeout = setTimeout(closefn, $this.options.timeout); }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
close: function(instantly) {
|
|
|
|
|
|
|
|
var $this = this,
|
|
|
|
finalize = function(){
|
|
|
|
$this.element.remove();
|
|
|
|
|
|
|
|
if (!containers[$this.options.pos].children().length) {
|
|
|
|
containers[$this.options.pos].hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this.options.onClose.apply($this, []);
|
|
|
|
$this.element.trigger('close.uk.notify', [$this]);
|
|
|
|
|
|
|
|
delete messages[$this.uuid];
|
|
|
|
};
|
|
|
|
|
|
|
|
if (this.timeout) clearTimeout(this.timeout);
|
|
|
|
|
|
|
|
if (instantly) {
|
|
|
|
finalize();
|
|
|
|
} else {
|
2018-05-05 13:35:10 +00:00
|
|
|
this.element.animate({opacity:0, marginTop: -1* this.element.outerHeight(), marginBottom:0}, function(){
|
2016-03-06 00:50:22 +00:00
|
|
|
finalize();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
content: function(html){
|
|
|
|
|
|
|
|
var container = this.element.find(">div");
|
|
|
|
|
|
|
|
if(!html) {
|
|
|
|
return container.html();
|
|
|
|
}
|
|
|
|
|
|
|
|
container.html(html);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
status: function(status) {
|
|
|
|
|
|
|
|
if (!status) {
|
|
|
|
return this.currentstatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.element.removeClass('uk-notify-message-'+this.currentstatus).addClass('uk-notify-message-'+status);
|
|
|
|
|
|
|
|
this.currentstatus = status;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Message.defaults = {
|
|
|
|
message: "",
|
|
|
|
status: "",
|
|
|
|
timeout: 5000,
|
|
|
|
group: null,
|
|
|
|
pos: 'top-center',
|
|
|
|
onClose: function() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
UI.notify = notify;
|
|
|
|
UI.notify.message = Message;
|
|
|
|
UI.notify.closeAll = closeAll;
|
|
|
|
|
|
|
|
return notify;
|
|
|
|
});
|