123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873 |
- (function (root, factory) {
- if (typeof define === 'function' && define.amd) {
-
- define('pnotify', ['jquery'], function($){
- return factory($, root);
- });
- } else if (typeof exports === 'object' && typeof module !== 'undefined') {
-
- module.exports = factory(require('jquery'), global || root);
- } else {
-
- root.PNotify = factory(root.jQuery, root);
- }
- }(this, function($, root){
- var init = function(root){
- var default_stack = {
- dir1: "down",
- dir2: "left",
- push: "bottom",
- spacing1: 36,
- spacing2: 36,
- context: $("body"),
- modal: false
- };
- var posTimer,
- body,
- jwindow = $(root);
-
- var do_when_ready = function(){
- body = $("body");
- PNotify.prototype.options.stack.context = body;
- jwindow = $(root);
-
- jwindow.bind('resize', function(){
- if (posTimer) {
- clearTimeout(posTimer);
- }
- posTimer = setTimeout(function(){
- PNotify.positionAll(true);
- }, 10);
- });
- };
- var createStackOverlay = function(stack) {
- var overlay = $("<div />", {"class": "ui-pnotify-modal-overlay"});
- overlay.prependTo(stack.context);
- if (stack.overlay_close) {
-
- overlay.click(function(){
- PNotify.removeStack(stack);
- });
- }
- return overlay;
- };
- var PNotify = function(options){
- this.parseOptions(options);
- this.init();
- };
- $.extend(PNotify.prototype, {
-
- version: "3.0.0",
-
-
- options: {
-
- title: false,
-
- title_escape: false,
-
- text: false,
-
- text_escape: false,
-
- styling: "bootstrap3",
-
- addclass: "",
-
- cornerclass: "",
-
- auto_display: true,
-
- width: "300px",
-
- min_height: "16px",
-
- type: "notice",
-
-
- icon: true,
-
-
-
- animation: "none",
-
-
- animate_speed: "fast",
-
- shadow: true,
-
- hide: true,
-
- delay: 3000,
-
- mouse_reset: true,
-
- remove: true,
-
- insert_brs: true,
-
- destroy: true,
-
-
- stack: default_stack
- },
-
-
-
- modules: {},
-
- runModules: function(event, arg){
- var curArg;
- for (var module in this.modules) {
- curArg = ((typeof arg === "object" && module in arg) ? arg[module] : arg);
- if (typeof this.modules[module][event] === 'function') {
- this.modules[module].notice = this;
- this.modules[module].options = typeof this.options[module] === 'object' ? this.options[module] : {};
- this.modules[module][event](this, typeof this.options[module] === 'object' ? this.options[module] : {}, curArg);
- }
- }
- },
-
- state: "initializing",
- timer: null,
- animTimer: null,
- styles: null,
- elem: null,
- container: null,
- title_container: null,
- text_container: null,
- animating: false,
- timerHide: false,
-
- init: function(){
- var that = this;
-
- this.modules = {};
- $.extend(true, this.modules, PNotify.prototype.modules);
-
- if (typeof this.options.styling === "object") {
- this.styles = this.options.styling;
- } else {
- this.styles = PNotify.styling[this.options.styling];
- }
-
-
- this.elem = $("<div />", {
- "class": "ui-pnotify "+this.options.addclass,
- "css": {"display": "none"},
- "aria-live": "assertive",
- "aria-role": "alertdialog",
- "mouseenter": function(e){
- if (that.options.mouse_reset && that.animating === "out") {
- if (!that.timerHide) {
- return;
- }
- that.cancelRemove();
- }
-
- if (that.options.hide && that.options.mouse_reset) {
- that.cancelRemove();
- }
- },
- "mouseleave": function(e){
-
- if (that.options.hide && that.options.mouse_reset && that.animating !== "out") {
- that.queueRemove();
- }
- PNotify.positionAll();
- }
- });
-
- if (this.options.animation === "fade") {
- this.elem.addClass("ui-pnotify-fade-"+this.options.animate_speed);
- }
-
- this.container = $("<div />", {
- "class": this.styles.container+" ui-pnotify-container "+(this.options.type === "error" ? this.styles.error : (this.options.type === "info" ? this.styles.info : (this.options.type === "success" ? this.styles.success : this.styles.notice))),
- "role": "alert"
- }).appendTo(this.elem);
- if (this.options.cornerclass !== "") {
- this.container.removeClass("ui-corner-all").addClass(this.options.cornerclass);
- }
-
- if (this.options.shadow) {
- this.container.addClass("ui-pnotify-shadow");
- }
-
- if (this.options.icon !== false) {
- $("<div />", {"class": "ui-pnotify-icon"})
- .append($("<span />", {"class": this.options.icon === true ? (this.options.type === "error" ? this.styles.error_icon : (this.options.type === "info" ? this.styles.info_icon : (this.options.type === "success" ? this.styles.success_icon : this.styles.notice_icon))) : this.options.icon}))
- .prependTo(this.container);
- }
-
- this.title_container = $("<h4 />", {
- "class": "ui-pnotify-title"
- })
- .appendTo(this.container);
- if (this.options.title === false) {
- this.title_container.hide();
- } else if (this.options.title_escape) {
- this.title_container.text(this.options.title);
- } else {
- this.title_container.html(this.options.title);
- }
-
- this.text_container = $("<div />", {
- "class": "ui-pnotify-text",
- "aria-role": "alert"
- })
- .appendTo(this.container);
- if (this.options.text === false) {
- this.text_container.hide();
- } else if (this.options.text_escape) {
- this.text_container.text(this.options.text);
- } else {
- this.text_container.html(this.options.insert_brs ? String(this.options.text).replace(/\n/g, "<br />") : this.options.text);
- }
-
- if (typeof this.options.width === "string") {
- this.elem.css("width", this.options.width);
- }
- if (typeof this.options.min_height === "string") {
- this.container.css("min-height", this.options.min_height);
- }
-
- if (this.options.stack.push === "top") {
- PNotify.notices = $.merge([this], PNotify.notices);
- } else {
- PNotify.notices = $.merge(PNotify.notices, [this]);
- }
-
- if (this.options.stack.push === "top") {
- this.queuePosition(false, 1);
- }
-
- this.options.stack.animation = false;
-
- this.runModules('init');
-
- if (this.options.auto_display) {
- this.open();
- }
- return this;
- },
-
- update: function(options){
-
- var oldOpts = this.options;
-
- this.parseOptions(oldOpts, options);
-
- this.elem.removeClass("ui-pnotify-fade-slow ui-pnotify-fade-normal ui-pnotify-fade-fast");
- if (this.options.animation === "fade") {
- this.elem.addClass("ui-pnotify-fade-"+this.options.animate_speed);
- }
-
- if (this.options.cornerclass !== oldOpts.cornerclass) {
- this.container.removeClass("ui-corner-all "+oldOpts.cornerclass).addClass(this.options.cornerclass);
- }
-
- if (this.options.shadow !== oldOpts.shadow) {
- if (this.options.shadow) {
- this.container.addClass("ui-pnotify-shadow");
- } else {
- this.container.removeClass("ui-pnotify-shadow");
- }
- }
-
- if (this.options.addclass === false) {
- this.elem.removeClass(oldOpts.addclass);
- } else if (this.options.addclass !== oldOpts.addclass) {
- this.elem.removeClass(oldOpts.addclass).addClass(this.options.addclass);
- }
-
- if (this.options.title === false) {
- this.title_container.slideUp("fast");
- } else if (this.options.title !== oldOpts.title) {
- if (this.options.title_escape) {
- this.title_container.text(this.options.title);
- } else {
- this.title_container.html(this.options.title);
- }
- if (oldOpts.title === false) {
- this.title_container.slideDown(200);
- }
- }
-
- if (this.options.text === false) {
- this.text_container.slideUp("fast");
- } else if (this.options.text !== oldOpts.text) {
- if (this.options.text_escape) {
- this.text_container.text(this.options.text);
- } else {
- this.text_container.html(this.options.insert_brs ? String(this.options.text).replace(/\n/g, "<br />") : this.options.text);
- }
- if (oldOpts.text === false) {
- this.text_container.slideDown(200);
- }
- }
-
- if (this.options.type !== oldOpts.type)
- this.container.removeClass(
- this.styles.error+" "+this.styles.notice+" "+this.styles.success+" "+this.styles.info
- ).addClass(this.options.type === "error" ?
- this.styles.error :
- (this.options.type === "info" ?
- this.styles.info :
- (this.options.type === "success" ?
- this.styles.success :
- this.styles.notice
- )
- )
- );
- if (this.options.icon !== oldOpts.icon || (this.options.icon === true && this.options.type !== oldOpts.type)) {
-
- this.container.find("div.ui-pnotify-icon").remove();
- if (this.options.icon !== false) {
-
- $("<div />", {"class": "ui-pnotify-icon"})
- .append($("<span />", {"class": this.options.icon === true ? (this.options.type === "error" ? this.styles.error_icon : (this.options.type === "info" ? this.styles.info_icon : (this.options.type === "success" ? this.styles.success_icon : this.styles.notice_icon))) : this.options.icon}))
- .prependTo(this.container);
- }
- }
-
- if (this.options.width !== oldOpts.width) {
- this.elem.animate({width: this.options.width});
- }
-
- if (this.options.min_height !== oldOpts.min_height) {
- this.container.animate({minHeight: this.options.min_height});
- }
-
- if (!this.options.hide) {
- this.cancelRemove();
- } else if (!oldOpts.hide) {
- this.queueRemove();
- }
- this.queuePosition(true);
-
- this.runModules('update', oldOpts);
- return this;
- },
-
- open: function(){
- this.state = "opening";
-
- this.runModules('beforeOpen');
- var that = this;
-
- if (!this.elem.parent().length) {
- this.elem.appendTo(this.options.stack.context ? this.options.stack.context : body);
- }
-
- if (this.options.stack.push !== "top") {
- this.position(true);
- }
- this.animateIn(function(){
- that.queuePosition(true);
-
- if (that.options.hide) {
- that.queueRemove();
- }
- that.state = "open";
-
- that.runModules('afterOpen');
- });
- return this;
- },
-
- remove: function(timer_hide) {
- this.state = "closing";
- this.timerHide = !!timer_hide;
-
- this.runModules('beforeClose');
- var that = this;
- if (this.timer) {
- root.clearTimeout(this.timer);
- this.timer = null;
- }
- this.animateOut(function(){
- that.state = "closed";
-
- that.runModules('afterClose');
- that.queuePosition(true);
-
- if (that.options.remove) {
- that.elem.detach();
- }
-
- that.runModules('beforeDestroy');
-
-
- if (that.options.destroy) {
- if (PNotify.notices !== null) {
- var idx = $.inArray(that,PNotify.notices);
- if (idx !== -1) {
- PNotify.notices.splice(idx,1);
- }
- }
- }
-
- that.runModules('afterDestroy');
- });
- return this;
- },
-
-
- get: function(){
- return this.elem;
- },
-
- parseOptions: function(options, moreOptions){
- this.options = $.extend(true, {}, PNotify.prototype.options);
-
- this.options.stack = PNotify.prototype.options.stack;
- var optArray = [options, moreOptions], curOpts;
- for (var curIndex=0; curIndex < optArray.length; curIndex++) {
- curOpts = optArray[curIndex];
- if (typeof curOpts === "undefined") {
- break;
- }
- if (typeof curOpts !== 'object') {
- this.options.text = curOpts;
- } else {
- for (var option in curOpts) {
- if (this.modules[option]) {
-
- $.extend(true, this.options[option], curOpts[option]);
- } else {
- this.options[option] = curOpts[option];
- }
- }
- }
- }
- },
-
- animateIn: function(callback){
-
- this.animating = "in";
- var that = this;
- callback = (function(){
- if (that.animTimer) {
- clearTimeout(that.animTimer);
- }
- if (that.animating !== "in") {
- return;
- }
- if (that.elem.is(":visible")) {
- if (this) {
- this.call();
- }
-
- that.animating = false;
- } else {
- that.animTimer = setTimeout(callback, 40);
- }
- }).bind(callback);
- if (this.options.animation === "fade") {
- this.elem.one('webkitTransitionEnd mozTransitionEnd MSTransitionEnd oTransitionEnd transitionend', callback).addClass("ui-pnotify-in");
- this.elem.css("opacity");
- this.elem.addClass("ui-pnotify-fade-in");
-
- this.animTimer = setTimeout(callback, 650);
- } else {
- this.elem.addClass("ui-pnotify-in");
- callback();
- }
- },
-
- animateOut: function(callback){
-
- this.animating = "out";
- var that = this;
- callback = (function(){
- if (that.animTimer) {
- clearTimeout(that.animTimer);
- }
- if (that.animating !== "out") {
- return;
- }
- if (that.elem.css("opacity") == "0" || !that.elem.is(":visible")) {
- that.elem.removeClass("ui-pnotify-in");
- if (this) {
- this.call();
- }
-
- that.animating = false;
- } else {
-
- that.animTimer = setTimeout(callback, 40);
- }
- }).bind(callback);
- if (this.options.animation === "fade") {
- this.elem.one('webkitTransitionEnd mozTransitionEnd MSTransitionEnd oTransitionEnd transitionend', callback).removeClass("ui-pnotify-fade-in");
-
- this.animTimer = setTimeout(callback, 650);
- } else {
- this.elem.removeClass("ui-pnotify-in");
- callback();
- }
- },
-
-
- position: function(dontSkipHidden){
-
- var stack = this.options.stack,
- elem = this.elem;
- if (typeof stack.context === "undefined") {
- stack.context = body;
- }
- if (!stack) {
- return;
- }
- if (typeof stack.nextpos1 !== "number") {
- stack.nextpos1 = stack.firstpos1;
- }
- if (typeof stack.nextpos2 !== "number") {
- stack.nextpos2 = stack.firstpos2;
- }
- if (typeof stack.addpos2 !== "number") {
- stack.addpos2 = 0;
- }
- var hidden = !elem.hasClass("ui-pnotify-in");
-
- if (!hidden || dontSkipHidden) {
- if (stack.modal) {
- if (stack.overlay) {
- stack.overlay.show();
- } else {
- stack.overlay = createStackOverlay(stack);
- }
- }
-
- elem.addClass("ui-pnotify-move");
- var curpos1, curpos2;
-
- var csspos1;
- switch (stack.dir1) {
- case "down":
- csspos1 = "top";
- break;
- case "up":
- csspos1 = "bottom";
- break;
- case "left":
- csspos1 = "right";
- break;
- case "right":
- csspos1 = "left";
- break;
- }
- curpos1 = parseInt(elem.css(csspos1).replace(/(?:\..*|[^0-9.])/g, ''));
- if (isNaN(curpos1)) {
- curpos1 = 0;
- }
-
- if (typeof stack.firstpos1 === "undefined" && !hidden) {
- stack.firstpos1 = curpos1;
- stack.nextpos1 = stack.firstpos1;
- }
-
- var csspos2;
- switch (stack.dir2) {
- case "down":
- csspos2 = "top";
- break;
- case "up":
- csspos2 = "bottom";
- break;
- case "left":
- csspos2 = "right";
- break;
- case "right":
- csspos2 = "left";
- break;
- }
- curpos2 = parseInt(elem.css(csspos2).replace(/(?:\..*|[^0-9.])/g, ''));
- if (isNaN(curpos2)) {
- curpos2 = 0;
- }
-
- if (typeof stack.firstpos2 === "undefined" && !hidden) {
- stack.firstpos2 = curpos2;
- stack.nextpos2 = stack.firstpos2;
- }
-
- if (
- (stack.dir1 === "down" && stack.nextpos1 + elem.height() > (stack.context.is(body) ? jwindow.height() : stack.context.prop('scrollHeight')) ) ||
- (stack.dir1 === "up" && stack.nextpos1 + elem.height() > (stack.context.is(body) ? jwindow.height() : stack.context.prop('scrollHeight')) ) ||
- (stack.dir1 === "left" && stack.nextpos1 + elem.width() > (stack.context.is(body) ? jwindow.width() : stack.context.prop('scrollWidth')) ) ||
- (stack.dir1 === "right" && stack.nextpos1 + elem.width() > (stack.context.is(body) ? jwindow.width() : stack.context.prop('scrollWidth')) )
- ) {
-
- stack.nextpos1 = stack.firstpos1;
- stack.nextpos2 += stack.addpos2 + (typeof stack.spacing2 === "undefined" ? 25 : stack.spacing2);
- stack.addpos2 = 0;
- }
- if (typeof stack.nextpos2 === "number") {
- if (!stack.animation) {
- elem.removeClass("ui-pnotify-move");
- elem.css(csspos2, stack.nextpos2+"px");
- elem.css(csspos2);
- elem.addClass("ui-pnotify-move");
- } else {
- elem.css(csspos2, stack.nextpos2+"px");
- }
- }
-
- switch (stack.dir2) {
- case "down":
- case "up":
- if (elem.outerHeight(true) > stack.addpos2) {
- stack.addpos2 = elem.height();
- }
- break;
- case "left":
- case "right":
- if (elem.outerWidth(true) > stack.addpos2) {
- stack.addpos2 = elem.width();
- }
- break;
- }
-
- if (typeof stack.nextpos1 === "number") {
- if (!stack.animation) {
- elem.removeClass("ui-pnotify-move");
- elem.css(csspos1, stack.nextpos1+"px");
- elem.css(csspos1);
- elem.addClass("ui-pnotify-move");
- } else {
- elem.css(csspos1, stack.nextpos1+"px");
- }
- }
-
- switch (stack.dir1) {
- case "down":
- case "up":
- stack.nextpos1 += elem.height() + (typeof stack.spacing1 === "undefined" ? 25 : stack.spacing1);
- break;
- case "left":
- case "right":
- stack.nextpos1 += elem.width() + (typeof stack.spacing1 === "undefined" ? 25 : stack.spacing1);
- break;
- }
- }
- return this;
- },
-
-
- queuePosition: function(animate, milliseconds){
- if (posTimer) {
- clearTimeout(posTimer);
- }
- if (!milliseconds) {
- milliseconds = 10;
- }
- posTimer = setTimeout(function(){
- PNotify.positionAll(animate);
- }, milliseconds);
- return this;
- },
-
- cancelRemove: function(){
- if (this.timer) {
- root.clearTimeout(this.timer);
- }
- if (this.animTimer) {
- root.clearTimeout(this.animTimer);
- }
- if (this.state === "closing") {
-
- this.state = "open";
- this.animating = false;
- this.elem.addClass("ui-pnotify-in");
- if (this.options.animation === "fade") {
- this.elem.addClass("ui-pnotify-fade-in");
- }
- }
- return this;
- },
-
- queueRemove: function(){
- var that = this;
-
- this.cancelRemove();
- this.timer = root.setTimeout(function(){
- that.remove(true);
- }, (isNaN(this.options.delay) ? 0 : this.options.delay));
- return this;
- }
- });
-
- $.extend(PNotify, {
-
- notices: [],
- reload: init,
- removeAll: function(){
- $.each(PNotify.notices, function(){
- if (this.remove) {
- this.remove(false);
- }
- });
- },
- removeStack: function(stack){
- $.each(PNotify.notices, function(){
- if (this.remove && this.options.stack === stack) {
- this.remove(false);
- }
- });
- },
- positionAll: function(animate){
-
-
- if (posTimer) {
- clearTimeout(posTimer);
- }
- posTimer = null;
-
- if (PNotify.notices && PNotify.notices.length) {
- $.each(PNotify.notices, function(){
- var s = this.options.stack;
- if (!s) {
- return;
- }
- if (s.overlay) {
- s.overlay.hide();
- }
- s.nextpos1 = s.firstpos1;
- s.nextpos2 = s.firstpos2;
- s.addpos2 = 0;
- s.animation = animate;
- });
- $.each(PNotify.notices, function(){
- this.position();
- });
- } else {
- var s = PNotify.prototype.options.stack;
- if (s) {
- delete s.nextpos1;
- delete s.nextpos2;
- }
- }
- },
- styling: {
- brighttheme: {
-
- container: "brighttheme",
- notice: "brighttheme-notice",
- notice_icon: "brighttheme-icon-notice",
- info: "brighttheme-info",
- info_icon: "brighttheme-icon-info",
- success: "brighttheme-success",
- success_icon: "brighttheme-icon-success",
- error: "brighttheme-error",
- error_icon: "brighttheme-icon-error"
- },
- jqueryui: {
- container: "ui-widget ui-widget-content ui-corner-all",
- notice: "ui-state-highlight",
-
- notice_icon: "ui-icon ui-icon-info",
- info: "",
- info_icon: "ui-icon ui-icon-info",
- success: "ui-state-default",
- success_icon: "ui-icon ui-icon-circle-check",
- error: "ui-state-error",
- error_icon: "ui-icon ui-icon-alert"
- },
- bootstrap3: {
- container: "alert",
- notice: "alert-warning",
- notice_icon: "glyphicon glyphicon-exclamation-sign",
- info: "alert-info",
- info_icon: "glyphicon glyphicon-info-sign",
- success: "alert-success",
- success_icon: "glyphicon glyphicon-ok-sign",
- error: "alert-danger",
- error_icon: "glyphicon glyphicon-warning-sign"
- }
- }
- });
-
- PNotify.styling.fontawesome = $.extend({}, PNotify.styling.bootstrap3);
- $.extend(PNotify.styling.fontawesome, {
- notice_icon: "fa fa-exclamation-circle",
- info_icon: "fa fa-info",
- success_icon: "fa fa-check",
- error_icon: "fa fa-warning"
- });
- if (root.document.body) {
- do_when_ready();
- } else {
- $(do_when_ready);
- }
- return PNotify;
- };
- return init(root);
- }));
|