6b7d6da0220b192353125cc2191950e23f5bd132.svn-base 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. /*
  2. PNotify 3.0.0 sciactive.com/pnotify/
  3. (C) 2015 Hunter Perrin; Google, Inc.
  4. license Apache-2.0
  5. */
  6. /*
  7. * ====== PNotify ======
  8. *
  9. * http://sciactive.com/pnotify/
  10. *
  11. * Copyright 2009-2015 Hunter Perrin
  12. * Copyright 2015 Google, Inc.
  13. *
  14. * Licensed under Apache License, Version 2.0.
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. */
  17. (function (root, factory) {
  18. if (typeof define === 'function' && define.amd) {
  19. // AMD. Register as a module.
  20. define('pnotify', ['jquery'], function($){
  21. return factory($, root);
  22. });
  23. } else if (typeof exports === 'object' && typeof module !== 'undefined') {
  24. // CommonJS
  25. module.exports = factory(require('jquery'), global || root);
  26. } else {
  27. // Browser globals
  28. root.PNotify = factory(root.jQuery, root);
  29. }
  30. }(this, function($, root){
  31. var init = function(root){
  32. var default_stack = {
  33. dir1: "down",
  34. dir2: "left",
  35. push: "bottom",
  36. spacing1: 36,
  37. spacing2: 36,
  38. context: $("body"),
  39. modal: false
  40. };
  41. var posTimer, // Position all timer.
  42. body,
  43. jwindow = $(root);
  44. // Set global variables.
  45. var do_when_ready = function(){
  46. body = $("body");
  47. PNotify.prototype.options.stack.context = body;
  48. jwindow = $(root);
  49. // Reposition the notices when the window resizes.
  50. jwindow.bind('resize', function(){
  51. if (posTimer) {
  52. clearTimeout(posTimer);
  53. }
  54. posTimer = setTimeout(function(){
  55. PNotify.positionAll(true);
  56. }, 10);
  57. });
  58. };
  59. var createStackOverlay = function(stack) {
  60. var overlay = $("<div />", {"class": "ui-pnotify-modal-overlay"});
  61. overlay.prependTo(stack.context);
  62. if (stack.overlay_close) {
  63. // Close the notices on overlay click.
  64. overlay.click(function(){
  65. PNotify.removeStack(stack);
  66. });
  67. }
  68. return overlay;
  69. };
  70. var PNotify = function(options){
  71. this.parseOptions(options);
  72. this.init();
  73. };
  74. $.extend(PNotify.prototype, {
  75. // The current version of PNotify.
  76. version: "3.0.0",
  77. // === Options ===
  78. // Options defaults.
  79. options: {
  80. // The notice's title.
  81. title: false,
  82. // Whether to escape the content of the title. (Not allow HTML.)
  83. title_escape: false,
  84. // The notice's text.
  85. text: false,
  86. // Whether to escape the content of the text. (Not allow HTML.)
  87. text_escape: false,
  88. // What styling classes to use. (Can be either "brighttheme", "jqueryui", "bootstrap2", "bootstrap3", or "fontawesome".)
  89. styling: "bootstrap3",
  90. // Additional classes to be added to the notice. (For custom styling.)
  91. addclass: "",
  92. // Class to be added to the notice for corner styling.
  93. cornerclass: "",
  94. // Display the notice when it is created.
  95. auto_display: true,
  96. // Width of the notice.
  97. width: "300px",
  98. // Minimum height of the notice. It will expand to fit content.
  99. min_height: "16px",
  100. // Type of the notice. "notice", "info", "success", or "error".
  101. type: "notice",
  102. // Set icon to true to use the default icon for the selected
  103. // style/type, false for no icon, or a string for your own icon class.
  104. icon: true,
  105. // The animation to use when displaying and hiding the notice. "none"
  106. // and "fade" are supported through CSS. Others are supported
  107. // through the Animate module and Animate.css.
  108. animation: "none",
  109. // Speed at which the notice animates in and out. "slow", "normal",
  110. // or "fast". Respectively, 600ms, 400ms, 200ms.
  111. animate_speed: "fast",
  112. // Display a drop shadow.
  113. shadow: true,
  114. // After a delay, remove the notice.
  115. hide: true,
  116. // Delay in milliseconds before the notice is removed.
  117. delay: 3000,
  118. // Reset the hide timer if the mouse moves over the notice.
  119. mouse_reset: true,
  120. // Remove the notice's elements from the DOM after it is removed.
  121. remove: true,
  122. // Change new lines to br tags.
  123. insert_brs: true,
  124. // Whether to remove notices from the global array.
  125. destroy: true,
  126. // The stack on which the notices will be placed. Also controls the
  127. // direction the notices stack.
  128. stack: default_stack
  129. },
  130. // === Modules ===
  131. // This object holds all the PNotify modules. They are used to provide
  132. // additional functionality.
  133. modules: {},
  134. // This runs an event on all the modules.
  135. runModules: function(event, arg){
  136. var curArg;
  137. for (var module in this.modules) {
  138. curArg = ((typeof arg === "object" && module in arg) ? arg[module] : arg);
  139. if (typeof this.modules[module][event] === 'function') {
  140. this.modules[module].notice = this;
  141. this.modules[module].options = typeof this.options[module] === 'object' ? this.options[module] : {};
  142. this.modules[module][event](this, typeof this.options[module] === 'object' ? this.options[module] : {}, curArg);
  143. }
  144. }
  145. },
  146. // === Class Variables ===
  147. state: "initializing", // The state can be "initializing", "opening", "open", "closing", and "closed".
  148. timer: null, // Auto close timer.
  149. animTimer: null, // Animation timer.
  150. styles: null,
  151. elem: null,
  152. container: null,
  153. title_container: null,
  154. text_container: null,
  155. animating: false, // Stores what is currently being animated (in or out).
  156. timerHide: false, // Stores whether the notice was hidden by a timer.
  157. // === Events ===
  158. init: function(){
  159. var that = this;
  160. // First and foremost, we don't want our module objects all referencing the prototype.
  161. this.modules = {};
  162. $.extend(true, this.modules, PNotify.prototype.modules);
  163. // Get our styling object.
  164. if (typeof this.options.styling === "object") {
  165. this.styles = this.options.styling;
  166. } else {
  167. this.styles = PNotify.styling[this.options.styling];
  168. }
  169. // Create our widget.
  170. // Stop animation, reset the removal timer when the user mouses over.
  171. this.elem = $("<div />", {
  172. "class": "ui-pnotify "+this.options.addclass,
  173. "css": {"display": "none"},
  174. "aria-live": "assertive",
  175. "aria-role": "alertdialog",
  176. "mouseenter": function(e){
  177. if (that.options.mouse_reset && that.animating === "out") {
  178. if (!that.timerHide) {
  179. return;
  180. }
  181. that.cancelRemove();
  182. }
  183. // Stop the close timer.
  184. if (that.options.hide && that.options.mouse_reset) {
  185. that.cancelRemove();
  186. }
  187. },
  188. "mouseleave": function(e){
  189. // Start the close timer.
  190. if (that.options.hide && that.options.mouse_reset && that.animating !== "out") {
  191. that.queueRemove();
  192. }
  193. PNotify.positionAll();
  194. }
  195. });
  196. // Maybe we need to fade in/out.
  197. if (this.options.animation === "fade") {
  198. this.elem.addClass("ui-pnotify-fade-"+this.options.animate_speed);
  199. }
  200. // Create a container for the notice contents.
  201. this.container = $("<div />", {
  202. "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))),
  203. "role": "alert"
  204. }).appendTo(this.elem);
  205. if (this.options.cornerclass !== "") {
  206. this.container.removeClass("ui-corner-all").addClass(this.options.cornerclass);
  207. }
  208. // Create a drop shadow.
  209. if (this.options.shadow) {
  210. this.container.addClass("ui-pnotify-shadow");
  211. }
  212. // Add the appropriate icon.
  213. if (this.options.icon !== false) {
  214. $("<div />", {"class": "ui-pnotify-icon"})
  215. .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}))
  216. .prependTo(this.container);
  217. }
  218. // Add a title.
  219. this.title_container = $("<h4 />", {
  220. "class": "ui-pnotify-title"
  221. })
  222. .appendTo(this.container);
  223. if (this.options.title === false) {
  224. this.title_container.hide();
  225. } else if (this.options.title_escape) {
  226. this.title_container.text(this.options.title);
  227. } else {
  228. this.title_container.html(this.options.title);
  229. }
  230. // Add text.
  231. this.text_container = $("<div />", {
  232. "class": "ui-pnotify-text",
  233. "aria-role": "alert"
  234. })
  235. .appendTo(this.container);
  236. if (this.options.text === false) {
  237. this.text_container.hide();
  238. } else if (this.options.text_escape) {
  239. this.text_container.text(this.options.text);
  240. } else {
  241. this.text_container.html(this.options.insert_brs ? String(this.options.text).replace(/\n/g, "<br />") : this.options.text);
  242. }
  243. // Set width and min height.
  244. if (typeof this.options.width === "string") {
  245. this.elem.css("width", this.options.width);
  246. }
  247. if (typeof this.options.min_height === "string") {
  248. this.container.css("min-height", this.options.min_height);
  249. }
  250. // Add the notice to the notice array.
  251. if (this.options.stack.push === "top") {
  252. PNotify.notices = $.merge([this], PNotify.notices);
  253. } else {
  254. PNotify.notices = $.merge(PNotify.notices, [this]);
  255. }
  256. // Now position all the notices if they are to push to the top.
  257. if (this.options.stack.push === "top") {
  258. this.queuePosition(false, 1);
  259. }
  260. // Mark the stack so it won't animate the new notice.
  261. this.options.stack.animation = false;
  262. // Run the modules.
  263. this.runModules('init');
  264. // Display the notice.
  265. if (this.options.auto_display) {
  266. this.open();
  267. }
  268. return this;
  269. },
  270. // This function is for updating the notice.
  271. update: function(options){
  272. // Save old options.
  273. var oldOpts = this.options;
  274. // Then update to the new options.
  275. this.parseOptions(oldOpts, options);
  276. // Maybe we need to fade in/out.
  277. this.elem.removeClass("ui-pnotify-fade-slow ui-pnotify-fade-normal ui-pnotify-fade-fast");
  278. if (this.options.animation === "fade") {
  279. this.elem.addClass("ui-pnotify-fade-"+this.options.animate_speed);
  280. }
  281. // Update the corner class.
  282. if (this.options.cornerclass !== oldOpts.cornerclass) {
  283. this.container.removeClass("ui-corner-all "+oldOpts.cornerclass).addClass(this.options.cornerclass);
  284. }
  285. // Update the shadow.
  286. if (this.options.shadow !== oldOpts.shadow) {
  287. if (this.options.shadow) {
  288. this.container.addClass("ui-pnotify-shadow");
  289. } else {
  290. this.container.removeClass("ui-pnotify-shadow");
  291. }
  292. }
  293. // Update the additional classes.
  294. if (this.options.addclass === false) {
  295. this.elem.removeClass(oldOpts.addclass);
  296. } else if (this.options.addclass !== oldOpts.addclass) {
  297. this.elem.removeClass(oldOpts.addclass).addClass(this.options.addclass);
  298. }
  299. // Update the title.
  300. if (this.options.title === false) {
  301. this.title_container.slideUp("fast");
  302. } else if (this.options.title !== oldOpts.title) {
  303. if (this.options.title_escape) {
  304. this.title_container.text(this.options.title);
  305. } else {
  306. this.title_container.html(this.options.title);
  307. }
  308. if (oldOpts.title === false) {
  309. this.title_container.slideDown(200);
  310. }
  311. }
  312. // Update the text.
  313. if (this.options.text === false) {
  314. this.text_container.slideUp("fast");
  315. } else if (this.options.text !== oldOpts.text) {
  316. if (this.options.text_escape) {
  317. this.text_container.text(this.options.text);
  318. } else {
  319. this.text_container.html(this.options.insert_brs ? String(this.options.text).replace(/\n/g, "<br />") : this.options.text);
  320. }
  321. if (oldOpts.text === false) {
  322. this.text_container.slideDown(200);
  323. }
  324. }
  325. // Change the notice type.
  326. if (this.options.type !== oldOpts.type)
  327. this.container.removeClass(
  328. this.styles.error+" "+this.styles.notice+" "+this.styles.success+" "+this.styles.info
  329. ).addClass(this.options.type === "error" ?
  330. this.styles.error :
  331. (this.options.type === "info" ?
  332. this.styles.info :
  333. (this.options.type === "success" ?
  334. this.styles.success :
  335. this.styles.notice
  336. )
  337. )
  338. );
  339. if (this.options.icon !== oldOpts.icon || (this.options.icon === true && this.options.type !== oldOpts.type)) {
  340. // Remove any old icon.
  341. this.container.find("div.ui-pnotify-icon").remove();
  342. if (this.options.icon !== false) {
  343. // Build the new icon.
  344. $("<div />", {"class": "ui-pnotify-icon"})
  345. .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}))
  346. .prependTo(this.container);
  347. }
  348. }
  349. // Update the width.
  350. if (this.options.width !== oldOpts.width) {
  351. this.elem.animate({width: this.options.width});
  352. }
  353. // Update the minimum height.
  354. if (this.options.min_height !== oldOpts.min_height) {
  355. this.container.animate({minHeight: this.options.min_height});
  356. }
  357. // Update the timed hiding.
  358. if (!this.options.hide) {
  359. this.cancelRemove();
  360. } else if (!oldOpts.hide) {
  361. this.queueRemove();
  362. }
  363. this.queuePosition(true);
  364. // Run the modules.
  365. this.runModules('update', oldOpts);
  366. return this;
  367. },
  368. // Display the notice.
  369. open: function(){
  370. this.state = "opening";
  371. // Run the modules.
  372. this.runModules('beforeOpen');
  373. var that = this;
  374. // If the notice is not in the DOM, append it.
  375. if (!this.elem.parent().length) {
  376. this.elem.appendTo(this.options.stack.context ? this.options.stack.context : body);
  377. }
  378. // Try to put it in the right position.
  379. if (this.options.stack.push !== "top") {
  380. this.position(true);
  381. }
  382. this.animateIn(function(){
  383. that.queuePosition(true);
  384. // Now set it to hide.
  385. if (that.options.hide) {
  386. that.queueRemove();
  387. }
  388. that.state = "open";
  389. // Run the modules.
  390. that.runModules('afterOpen');
  391. });
  392. return this;
  393. },
  394. // Remove the notice.
  395. remove: function(timer_hide) {
  396. this.state = "closing";
  397. this.timerHide = !!timer_hide; // Make sure it's a boolean.
  398. // Run the modules.
  399. this.runModules('beforeClose');
  400. var that = this;
  401. if (this.timer) {
  402. root.clearTimeout(this.timer);
  403. this.timer = null;
  404. }
  405. this.animateOut(function(){
  406. that.state = "closed";
  407. // Run the modules.
  408. that.runModules('afterClose');
  409. that.queuePosition(true);
  410. // If we're supposed to remove the notice from the DOM, do it.
  411. if (that.options.remove) {
  412. that.elem.detach();
  413. }
  414. // Run the modules.
  415. that.runModules('beforeDestroy');
  416. // Remove object from PNotify.notices to prevent memory leak (issue #49)
  417. // unless destroy is off
  418. if (that.options.destroy) {
  419. if (PNotify.notices !== null) {
  420. var idx = $.inArray(that,PNotify.notices);
  421. if (idx !== -1) {
  422. PNotify.notices.splice(idx,1);
  423. }
  424. }
  425. }
  426. // Run the modules.
  427. that.runModules('afterDestroy');
  428. });
  429. return this;
  430. },
  431. // === Class Methods ===
  432. // Get the DOM element.
  433. get: function(){
  434. return this.elem;
  435. },
  436. // Put all the options in the right places.
  437. parseOptions: function(options, moreOptions){
  438. this.options = $.extend(true, {}, PNotify.prototype.options);
  439. // This is the only thing that *should* be copied by reference.
  440. this.options.stack = PNotify.prototype.options.stack;
  441. var optArray = [options, moreOptions], curOpts;
  442. for (var curIndex=0; curIndex < optArray.length; curIndex++) {
  443. curOpts = optArray[curIndex];
  444. if (typeof curOpts === "undefined") {
  445. break;
  446. }
  447. if (typeof curOpts !== 'object') {
  448. this.options.text = curOpts;
  449. } else {
  450. for (var option in curOpts) {
  451. if (this.modules[option]) {
  452. // Avoid overwriting module defaults.
  453. $.extend(true, this.options[option], curOpts[option]);
  454. } else {
  455. this.options[option] = curOpts[option];
  456. }
  457. }
  458. }
  459. }
  460. },
  461. // Animate the notice in.
  462. animateIn: function(callback){
  463. // Declare that the notice is animating in.
  464. this.animating = "in";
  465. var that = this;
  466. callback = (function(){
  467. if (that.animTimer) {
  468. clearTimeout(that.animTimer);
  469. }
  470. if (that.animating !== "in") {
  471. return;
  472. }
  473. if (that.elem.is(":visible")) {
  474. if (this) {
  475. this.call();
  476. }
  477. // Declare that the notice has completed animating.
  478. that.animating = false;
  479. } else {
  480. that.animTimer = setTimeout(callback, 40);
  481. }
  482. }).bind(callback);
  483. if (this.options.animation === "fade") {
  484. this.elem.one('webkitTransitionEnd mozTransitionEnd MSTransitionEnd oTransitionEnd transitionend', callback).addClass("ui-pnotify-in");
  485. this.elem.css("opacity"); // This line is necessary for some reason. Some notices don't fade without it.
  486. this.elem.addClass("ui-pnotify-fade-in");
  487. // Just in case the event doesn't fire, call it after 650 ms.
  488. this.animTimer = setTimeout(callback, 650);
  489. } else {
  490. this.elem.addClass("ui-pnotify-in");
  491. callback();
  492. }
  493. },
  494. // Animate the notice out.
  495. animateOut: function(callback){
  496. // Declare that the notice is animating out.
  497. this.animating = "out";
  498. var that = this;
  499. callback = (function(){
  500. if (that.animTimer) {
  501. clearTimeout(that.animTimer);
  502. }
  503. if (that.animating !== "out") {
  504. return;
  505. }
  506. if (that.elem.css("opacity") == "0" || !that.elem.is(":visible")) {
  507. that.elem.removeClass("ui-pnotify-in");
  508. if (this) {
  509. this.call();
  510. }
  511. // Declare that the notice has completed animating.
  512. that.animating = false;
  513. } else {
  514. // In case this was called before the notice finished animating.
  515. that.animTimer = setTimeout(callback, 40);
  516. }
  517. }).bind(callback);
  518. if (this.options.animation === "fade") {
  519. this.elem.one('webkitTransitionEnd mozTransitionEnd MSTransitionEnd oTransitionEnd transitionend', callback).removeClass("ui-pnotify-fade-in");
  520. // Just in case the event doesn't fire, call it after 650 ms.
  521. this.animTimer = setTimeout(callback, 650);
  522. } else {
  523. this.elem.removeClass("ui-pnotify-in");
  524. callback();
  525. }
  526. },
  527. // Position the notice. dont_skip_hidden causes the notice to
  528. // position even if it's not visible.
  529. position: function(dontSkipHidden){
  530. // Get the notice's stack.
  531. var stack = this.options.stack,
  532. elem = this.elem;
  533. if (typeof stack.context === "undefined") {
  534. stack.context = body;
  535. }
  536. if (!stack) {
  537. return;
  538. }
  539. if (typeof stack.nextpos1 !== "number") {
  540. stack.nextpos1 = stack.firstpos1;
  541. }
  542. if (typeof stack.nextpos2 !== "number") {
  543. stack.nextpos2 = stack.firstpos2;
  544. }
  545. if (typeof stack.addpos2 !== "number") {
  546. stack.addpos2 = 0;
  547. }
  548. var hidden = !elem.hasClass("ui-pnotify-in");
  549. // Skip this notice if it's not shown.
  550. if (!hidden || dontSkipHidden) {
  551. if (stack.modal) {
  552. if (stack.overlay) {
  553. stack.overlay.show();
  554. } else {
  555. stack.overlay = createStackOverlay(stack);
  556. }
  557. }
  558. // Add animate class by default.
  559. elem.addClass("ui-pnotify-move");
  560. var curpos1, curpos2;
  561. // Calculate the current pos1 value.
  562. var csspos1;
  563. switch (stack.dir1) {
  564. case "down":
  565. csspos1 = "top";
  566. break;
  567. case "up":
  568. csspos1 = "bottom";
  569. break;
  570. case "left":
  571. csspos1 = "right";
  572. break;
  573. case "right":
  574. csspos1 = "left";
  575. break;
  576. }
  577. curpos1 = parseInt(elem.css(csspos1).replace(/(?:\..*|[^0-9.])/g, ''));
  578. if (isNaN(curpos1)) {
  579. curpos1 = 0;
  580. }
  581. // Remember the first pos1, so the first visible notice goes there.
  582. if (typeof stack.firstpos1 === "undefined" && !hidden) {
  583. stack.firstpos1 = curpos1;
  584. stack.nextpos1 = stack.firstpos1;
  585. }
  586. // Calculate the current pos2 value.
  587. var csspos2;
  588. switch (stack.dir2) {
  589. case "down":
  590. csspos2 = "top";
  591. break;
  592. case "up":
  593. csspos2 = "bottom";
  594. break;
  595. case "left":
  596. csspos2 = "right";
  597. break;
  598. case "right":
  599. csspos2 = "left";
  600. break;
  601. }
  602. curpos2 = parseInt(elem.css(csspos2).replace(/(?:\..*|[^0-9.])/g, ''));
  603. if (isNaN(curpos2)) {
  604. curpos2 = 0;
  605. }
  606. // Remember the first pos2, so the first visible notice goes there.
  607. if (typeof stack.firstpos2 === "undefined" && !hidden) {
  608. stack.firstpos2 = curpos2;
  609. stack.nextpos2 = stack.firstpos2;
  610. }
  611. // Check that it's not beyond the viewport edge.
  612. if (
  613. (stack.dir1 === "down" && stack.nextpos1 + elem.height() > (stack.context.is(body) ? jwindow.height() : stack.context.prop('scrollHeight')) ) ||
  614. (stack.dir1 === "up" && stack.nextpos1 + elem.height() > (stack.context.is(body) ? jwindow.height() : stack.context.prop('scrollHeight')) ) ||
  615. (stack.dir1 === "left" && stack.nextpos1 + elem.width() > (stack.context.is(body) ? jwindow.width() : stack.context.prop('scrollWidth')) ) ||
  616. (stack.dir1 === "right" && stack.nextpos1 + elem.width() > (stack.context.is(body) ? jwindow.width() : stack.context.prop('scrollWidth')) )
  617. ) {
  618. // If it is, it needs to go back to the first pos1, and over on pos2.
  619. stack.nextpos1 = stack.firstpos1;
  620. stack.nextpos2 += stack.addpos2 + (typeof stack.spacing2 === "undefined" ? 25 : stack.spacing2);
  621. stack.addpos2 = 0;
  622. }
  623. if (typeof stack.nextpos2 === "number") {
  624. if (!stack.animation) {
  625. elem.removeClass("ui-pnotify-move");
  626. elem.css(csspos2, stack.nextpos2+"px");
  627. elem.css(csspos2);
  628. elem.addClass("ui-pnotify-move");
  629. } else {
  630. elem.css(csspos2, stack.nextpos2+"px");
  631. }
  632. }
  633. // Keep track of the widest/tallest notice in the column/row, so we can push the next column/row.
  634. switch (stack.dir2) {
  635. case "down":
  636. case "up":
  637. if (elem.outerHeight(true) > stack.addpos2) {
  638. stack.addpos2 = elem.height();
  639. }
  640. break;
  641. case "left":
  642. case "right":
  643. if (elem.outerWidth(true) > stack.addpos2) {
  644. stack.addpos2 = elem.width();
  645. }
  646. break;
  647. }
  648. // Move the notice on dir1.
  649. if (typeof stack.nextpos1 === "number") {
  650. if (!stack.animation) {
  651. elem.removeClass("ui-pnotify-move");
  652. elem.css(csspos1, stack.nextpos1+"px");
  653. elem.css(csspos1);
  654. elem.addClass("ui-pnotify-move");
  655. } else {
  656. elem.css(csspos1, stack.nextpos1+"px");
  657. }
  658. }
  659. // Calculate the next dir1 position.
  660. switch (stack.dir1) {
  661. case "down":
  662. case "up":
  663. stack.nextpos1 += elem.height() + (typeof stack.spacing1 === "undefined" ? 25 : stack.spacing1);
  664. break;
  665. case "left":
  666. case "right":
  667. stack.nextpos1 += elem.width() + (typeof stack.spacing1 === "undefined" ? 25 : stack.spacing1);
  668. break;
  669. }
  670. }
  671. return this;
  672. },
  673. // Queue the position all function so it doesn't run repeatedly and
  674. // use up resources.
  675. queuePosition: function(animate, milliseconds){
  676. if (posTimer) {
  677. clearTimeout(posTimer);
  678. }
  679. if (!milliseconds) {
  680. milliseconds = 10;
  681. }
  682. posTimer = setTimeout(function(){
  683. PNotify.positionAll(animate);
  684. }, milliseconds);
  685. return this;
  686. },
  687. // Cancel any pending removal timer.
  688. cancelRemove: function(){
  689. if (this.timer) {
  690. root.clearTimeout(this.timer);
  691. }
  692. if (this.animTimer) {
  693. root.clearTimeout(this.animTimer);
  694. }
  695. if (this.state === "closing") {
  696. // If it's animating out, stop it.
  697. this.state = "open";
  698. this.animating = false;
  699. this.elem.addClass("ui-pnotify-in");
  700. if (this.options.animation === "fade") {
  701. this.elem.addClass("ui-pnotify-fade-in");
  702. }
  703. }
  704. return this;
  705. },
  706. // Queue a removal timer.
  707. queueRemove: function(){
  708. var that = this;
  709. // Cancel any current removal timer.
  710. this.cancelRemove();
  711. this.timer = root.setTimeout(function(){
  712. that.remove(true);
  713. }, (isNaN(this.options.delay) ? 0 : this.options.delay));
  714. return this;
  715. }
  716. });
  717. // These functions affect all notices.
  718. $.extend(PNotify, {
  719. // This holds all the notices.
  720. notices: [],
  721. reload: init,
  722. removeAll: function(){
  723. $.each(PNotify.notices, function(){
  724. if (this.remove) {
  725. this.remove(false);
  726. }
  727. });
  728. },
  729. removeStack: function(stack){
  730. $.each(PNotify.notices, function(){
  731. if (this.remove && this.options.stack === stack) {
  732. this.remove(false);
  733. }
  734. });
  735. },
  736. positionAll: function(animate){
  737. // This timer is used for queueing this function so it doesn't run
  738. // repeatedly.
  739. if (posTimer) {
  740. clearTimeout(posTimer);
  741. }
  742. posTimer = null;
  743. // Reset the next position data.
  744. if (PNotify.notices && PNotify.notices.length) {
  745. $.each(PNotify.notices, function(){
  746. var s = this.options.stack;
  747. if (!s) {
  748. return;
  749. }
  750. if (s.overlay) {
  751. s.overlay.hide();
  752. }
  753. s.nextpos1 = s.firstpos1;
  754. s.nextpos2 = s.firstpos2;
  755. s.addpos2 = 0;
  756. s.animation = animate;
  757. });
  758. $.each(PNotify.notices, function(){
  759. this.position();
  760. });
  761. } else {
  762. var s = PNotify.prototype.options.stack;
  763. if (s) {
  764. delete s.nextpos1;
  765. delete s.nextpos2;
  766. }
  767. }
  768. },
  769. styling: {
  770. brighttheme: {
  771. // Bright Theme doesn't require any UI libraries.
  772. container: "brighttheme",
  773. notice: "brighttheme-notice",
  774. notice_icon: "brighttheme-icon-notice",
  775. info: "brighttheme-info",
  776. info_icon: "brighttheme-icon-info",
  777. success: "brighttheme-success",
  778. success_icon: "brighttheme-icon-success",
  779. error: "brighttheme-error",
  780. error_icon: "brighttheme-icon-error"
  781. },
  782. jqueryui: {
  783. container: "ui-widget ui-widget-content ui-corner-all",
  784. notice: "ui-state-highlight",
  785. // (The actual jQUI notice icon looks terrible.)
  786. notice_icon: "ui-icon ui-icon-info",
  787. info: "",
  788. info_icon: "ui-icon ui-icon-info",
  789. success: "ui-state-default",
  790. success_icon: "ui-icon ui-icon-circle-check",
  791. error: "ui-state-error",
  792. error_icon: "ui-icon ui-icon-alert"
  793. },
  794. bootstrap3: {
  795. container: "alert",
  796. notice: "alert-warning",
  797. notice_icon: "glyphicon glyphicon-exclamation-sign",
  798. info: "alert-info",
  799. info_icon: "glyphicon glyphicon-info-sign",
  800. success: "alert-success",
  801. success_icon: "glyphicon glyphicon-ok-sign",
  802. error: "alert-danger",
  803. error_icon: "glyphicon glyphicon-warning-sign"
  804. }
  805. }
  806. });
  807. /*
  808. * uses icons from http://fontawesome.io/
  809. * version 4.0.3
  810. */
  811. PNotify.styling.fontawesome = $.extend({}, PNotify.styling.bootstrap3);
  812. $.extend(PNotify.styling.fontawesome, {
  813. notice_icon: "fa fa-exclamation-circle",
  814. info_icon: "fa fa-info",
  815. success_icon: "fa fa-check",
  816. error_icon: "fa fa-warning"
  817. });
  818. if (root.document.body) {
  819. do_when_ready();
  820. } else {
  821. $(do_when_ready);
  822. }
  823. return PNotify;
  824. };
  825. return init(root);
  826. }));