extra_pnotify.js 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # PNotify notifications
  4. *
  5. * Demo JS code for extra_pnotify.html page
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var Pnotify = function() {
  11. //
  12. // Setup module components
  13. //
  14. // PNotify examples
  15. var _componentPnotify = function() {
  16. if (typeof PNotify == 'undefined') {
  17. console.warn('Warning - pnotify.min.js is not loaded.');
  18. return;
  19. }
  20. //
  21. // Notification styles
  22. //
  23. // Default style
  24. $('#pnotify-default').on('click', function () {
  25. new PNotify({
  26. title: 'Primary notice',
  27. text: 'Check me out! I\'m a notice.',
  28. icon: 'icon-warning22'
  29. });
  30. });
  31. // Styled left
  32. $('#pnotify-styled-left').on('click', function () {
  33. new PNotify({
  34. title: 'Left icon',
  35. text: 'Check me out! I\'m a notice.',
  36. addclass: 'alert alert-styled-left',
  37. type: 'info'
  38. });
  39. });
  40. // Styled right
  41. $('#pnotify-styled-right').on('click', function () {
  42. new PNotify({
  43. title: 'Right icon',
  44. text: 'Check me out! I\'m a notice.',
  45. addclass: 'alert alert-warning alert-styled-right',
  46. type: 'error'
  47. });
  48. });
  49. // Styled with arrow
  50. $('#pnotify-styled-arrow').on('click', function () {
  51. new PNotify({
  52. title: 'Notice with arrow',
  53. text: 'Check me out! I\'m a notice.',
  54. addclass: 'alert alert-styled-left alert-arrow-left',
  55. type: 'info'
  56. });
  57. });
  58. // Custom style
  59. $('#pnotify-custom-styled').on('click', function () {
  60. new PNotify({
  61. title: 'Custom color notice',
  62. text: 'Check me out! I\'m a notice.',
  63. addclass: 'alert alert-styled-left alert-styled-custom alert-arrow-left alpha-teal text-teal-800 border-teal'
  64. });
  65. });
  66. //
  67. // Contextual alternatives
  68. //
  69. // Danger notification
  70. $('#pnotify-danger').on('click', function () {
  71. new PNotify({
  72. title: 'Danger notice',
  73. text: 'Check me out! I\'m a notice.',
  74. icon: 'icon-blocked',
  75. type: 'error'
  76. });
  77. });
  78. // Success notification
  79. $('#pnotify-success').on('click', function () {
  80. new PNotify({
  81. title: 'Success notice',
  82. text: 'Check me out! I\'m a notice.',
  83. icon: 'icon-checkmark3',
  84. type: 'success'
  85. });
  86. });
  87. // Info notification
  88. $('#pnotify-info').on('click', function () {
  89. new PNotify({
  90. title: 'Info notice',
  91. text: 'Check me out! I\'m a notice.',
  92. icon: 'icon-info22',
  93. type: 'info'
  94. });
  95. });
  96. //
  97. // Solid color style
  98. //
  99. // Solid primary
  100. $('#pnotify-solid-primary').on('click', function () {
  101. new PNotify({
  102. title: 'Primary notice',
  103. text: 'Check me out! I\'m a notice.',
  104. addclass: 'bg-primary border-primary'
  105. });
  106. });
  107. // Solid danger
  108. $('#pnotify-solid-danger').on('click', function () {
  109. new PNotify({
  110. title: 'Danger notice',
  111. text: 'Check me out! I\'m a notice.',
  112. addclass: 'bg-danger border-danger'
  113. });
  114. });
  115. // Solid success
  116. $('#pnotify-solid-success').on('click', function () {
  117. new PNotify({
  118. title: 'Success notice',
  119. text: 'Check me out! I\'m a notice.',
  120. addclass: 'bg-success border-success'
  121. });
  122. });
  123. // Solid warning
  124. $('#pnotify-solid-warning').on('click', function () {
  125. new PNotify({
  126. title: 'Warning notice',
  127. text: 'Check me out! I\'m a notice.',
  128. addclass: 'bg-warning border-warning'
  129. });
  130. });
  131. // Solid info
  132. $('#pnotify-solid-info').on('click', function () {
  133. new PNotify({
  134. title: 'Info notice',
  135. text: 'Check me out! I\'m a notice.',
  136. addclass: 'bg-info border-info'
  137. });
  138. });
  139. // Custom solid color
  140. $('#pnotify-solid-custom').on('click', function () {
  141. new PNotify({
  142. title: 'Custom color notice',
  143. text: 'Check me out! I\'m a notice.',
  144. addclass: 'bg-teal border-teal'
  145. });
  146. });
  147. // Solid styled left
  148. $('#pnotify-solid-styled-left').on('click', function () {
  149. new PNotify({
  150. title: 'Left icon',
  151. text: 'Check me out! I\'m a notice.',
  152. addclass: 'alert bg-primary border-primary alert-styled-left'
  153. });
  154. });
  155. // Solid styled right
  156. $('#pnotify-solid-styled-right').on('click', function () {
  157. new PNotify({
  158. title: 'Right icon',
  159. text: 'Check me out! I\'m a notice.',
  160. addclass: 'alert bg-danger border-danger alert-styled-right',
  161. type: 'error'
  162. });
  163. });
  164. //
  165. // Desktop notifications
  166. //
  167. // Default
  168. $('#pnotify-desktop-default').on('click', function () {
  169. PNotify.desktop.permission();
  170. (new PNotify({
  171. title: 'Default Desktop Notice',
  172. text: 'If you\'ve given me permission, I\'ll appear as a desktop notification.',
  173. desktop: {
  174. desktop: true,
  175. addclass: 'bg-green border-green',
  176. icon: '../../../../global_assets/images/pnotify/default.png'
  177. }
  178. })
  179. ).get().click(function(e) {
  180. if ($('.ui-pnotify-closer, .ui-pnotify-sticker, .ui-pnotify-closer *, .ui-pnotify-sticker *').is(e.target)) return;
  181. alert('Hey! You clicked the desktop notification!');
  182. });
  183. });
  184. // Danger
  185. $('#pnotify-desktop-danger').on('click', function () {
  186. PNotify.desktop.permission();
  187. (new PNotify({
  188. title: 'Danger Desktop Notice',
  189. type: 'danger',
  190. text: 'I\'m a danger desktop notification, if you have given me a permission.',
  191. desktop: {
  192. desktop: true,
  193. icon: '../../../../global_assets/images/pnotify/danger.png'
  194. }
  195. })
  196. ).get().click(function(e) {
  197. if ($('.ui-pnotify-closer, .ui-pnotify-sticker, .ui-pnotify-closer *, .ui-pnotify-sticker *').is(e.target)) return;
  198. alert('Hey! You clicked the desktop notification!');
  199. });
  200. });
  201. // Success
  202. $('#pnotify-desktop-success').on('click', function () {
  203. PNotify.desktop.permission();
  204. (new PNotify({
  205. title: 'Success Desktop Notice',
  206. type: 'success',
  207. text: 'I\'m a success desktop notification, if you have given me a permission.',
  208. desktop: {
  209. desktop: true,
  210. icon: '../../../../global_assets/images/pnotify/success.png'
  211. }
  212. })
  213. ).get().click(function(e) {
  214. if ($('.ui-pnotify-closer, .ui-pnotify-sticker, .ui-pnotify-closer *, .ui-pnotify-sticker *').is(e.target)) return;
  215. alert('Hey! You clicked the desktop notification!');
  216. });
  217. });
  218. // Warning
  219. $('#pnotify-desktop-warning').on('click', function () {
  220. PNotify.desktop.permission();
  221. (new PNotify({
  222. title: 'Warning Desktop Notice',
  223. type: 'warning',
  224. text: 'I\'m a warning desktop notification, if you have given me a permission.',
  225. desktop: {
  226. desktop: true,
  227. icon: '../../../../global_assets/images/pnotify/warning.png'
  228. }
  229. })
  230. ).get().click(function(e) {
  231. if ($('.ui-pnotify-closer, .ui-pnotify-sticker, .ui-pnotify-closer *, .ui-pnotify-sticker *').is(e.target)) return;
  232. alert('Hey! You clicked the desktop notification!');
  233. });
  234. });
  235. // Info
  236. $('#pnotify-desktop-info').on('click', function () {
  237. PNotify.desktop.permission();
  238. (new PNotify({
  239. title: 'Info Desktop Notice',
  240. type: 'info',
  241. text: 'I\'m an info desktop notification, if you have given me a permission.',
  242. desktop: {
  243. desktop: true,
  244. icon: '../../../../global_assets/images/pnotify/info.png'
  245. }
  246. })
  247. ).get().click(function(e) {
  248. if ($('.ui-pnotify-closer, .ui-pnotify-sticker, .ui-pnotify-closer *, .ui-pnotify-sticker *').is(e.target)) return;
  249. alert('Hey! You clicked the desktop notification!');
  250. });
  251. });
  252. //
  253. // Options
  254. //
  255. // No title
  256. $('#pnotify-no-title').on('click', function () {
  257. new PNotify({
  258. text: 'Check me out! I\'m a notice without title.',
  259. addclass: 'bg-primary border-primary'
  260. });
  261. });
  262. // Rich content
  263. $('#pnotify-rich').on('click', function () {
  264. new PNotify({
  265. title: 'Rich content notice',
  266. text: 'Look at my beautiful <strong>strong</strong>, <a href="#" class="alert-link">linked</a>, <em>emphasized</em>, and <u>underlined</u> text with <i class="icon-make-group"></i> icon.',
  267. icon: 'icon-comment-discussion'
  268. });
  269. });
  270. // Close on click
  271. $('#pnotify-click').on('click', function () {
  272. var notice = new PNotify({
  273. title: 'Close on click',
  274. text: 'Click me anywhere to dismiss me.',
  275. addclass: 'bg-warning-400 border-warning-400',
  276. hide: false,
  277. buttons: {
  278. closer: false,
  279. sticker: false
  280. }
  281. });
  282. notice.get().click(function() {
  283. notice.remove();
  284. });
  285. });
  286. // Form
  287. $('#pnotify-form').on('click', function () {
  288. var notice = new PNotify({
  289. text: $('#form_notice').html(),
  290. width: '300px',
  291. hide: false,
  292. addclass: 'bg-slate border-slate',
  293. buttons: {
  294. closer: false,
  295. sticker: false
  296. },
  297. insert_brs: false
  298. });
  299. // Remove if cancelled
  300. notice.get().find('button[name=cancel]').on('click', function() {
  301. notice.remove();
  302. })
  303. // Submit form
  304. notice.get().submit(function() {
  305. var username = $(this).find('input[name=username]').val();
  306. if (!username) {
  307. alert('Please provide a username.');
  308. return false;
  309. }
  310. notice.update({
  311. title: 'Welcome',
  312. text: 'Successfully logged in as ' + username,
  313. addclass: 'bg-teal border-teal',
  314. icon: true,
  315. width: PNotify.prototype.options.width,
  316. hide: true,
  317. buttons: {
  318. closer: true,
  319. sticker: true
  320. }
  321. });
  322. return false;
  323. });
  324. });
  325. // Sticky notice
  326. $('#pnotify-sticky').on('click', function () {
  327. new PNotify({
  328. title: 'Sticky notice',
  329. text: 'Check me out! I\'m a sticky notice. You\'ll have to close me yourself.',
  330. addclass: 'bg-primary border-primary',
  331. hide: false
  332. });
  333. });
  334. // Sticky buttons
  335. $('#pnotify-sticky-buttons').on('click', function () {
  336. new PNotify({
  337. title: 'No sticky button notice',
  338. text: 'I\'m a sticky notice with no unsticky button. You\'ll have to close me yourself.',
  339. addclass: 'bg-primary border-primary',
  340. hide: false,
  341. buttons: {
  342. sticker: false
  343. }
  344. });
  345. });
  346. // Permanent buttons
  347. $('#pnotify-permanent-buttons').on('click', function () {
  348. new PNotify({
  349. title: 'Permanent buttons notice',
  350. text: 'My buttons are really lonely, so they\'re gonna hang out with us.',
  351. addclass: 'bg-slate border-slate',
  352. buttons: {
  353. closer_hover: false,
  354. sticker_hover: false
  355. }
  356. });
  357. });
  358. //
  359. // Modules
  360. //
  361. // Confirm
  362. $('#pnotify-confirm').on('click', function () {
  363. // Setup
  364. var notice = new PNotify({
  365. title: 'Confirmation',
  366. text: '<p>Are you sure you want to discard changes?</p>',
  367. hide: false,
  368. type: 'warning',
  369. confirm: {
  370. confirm: true,
  371. buttons: [
  372. {
  373. text: 'Yes',
  374. addClass: 'btn btn-sm btn-primary'
  375. },
  376. {
  377. addClass: 'btn btn-sm btn-link'
  378. }
  379. ]
  380. },
  381. buttons: {
  382. closer: false,
  383. sticker: false
  384. }
  385. })
  386. // On confirm
  387. notice.get().on('pnotify.confirm', function() {
  388. alert('Ok, cool.');
  389. })
  390. // On cancel
  391. notice.get().on('pnotify.cancel', function() {
  392. alert('Oh ok. Chicken, I see.');
  393. });
  394. });
  395. // Prompt
  396. $('#pnotify-prompt').on('click', function () {
  397. // Setup
  398. var notice = new PNotify({
  399. title: 'Input needed',
  400. text: 'What side would you like?',
  401. hide: false,
  402. confirm: {
  403. prompt: true,
  404. buttons: [
  405. {
  406. text: 'Yes',
  407. addClass: 'btn btn-sm btn-primary'
  408. },
  409. {
  410. addClass: 'btn btn-sm btn-link'
  411. }
  412. ]
  413. },
  414. buttons: {
  415. closer: false,
  416. sticker: false
  417. }
  418. });
  419. // On confirm
  420. notice.get().on('pnotify.confirm', function(e, notice, val) {
  421. notice.cancelRemove().update({
  422. title: 'You\'ve chosen a side',
  423. text: 'You want ' + $('<div/>').text(val).html() + '.',
  424. icon: 'icon-checkmark3',
  425. type: 'success',
  426. delay: 2000,
  427. hide: true,
  428. confirm: {
  429. prompt: false
  430. },
  431. buttons: {
  432. closer: true,
  433. sticker: true
  434. }
  435. });
  436. })
  437. // On cancel
  438. notice.get().on('pnotify.cancel', function(e, notice) {
  439. notice.cancelRemove().update({
  440. title: 'You don\'t want a side',
  441. text: 'No soup for you!',
  442. icon: 'icon-blocked',
  443. type: 'error',
  444. delay: 2000,
  445. hide: true,
  446. confirm: {
  447. prompt: false
  448. },
  449. buttons: {
  450. closer: true,
  451. sticker: true
  452. }
  453. });
  454. });
  455. });
  456. // Multiline prompt
  457. $('#pnotify-multiline').on('click', function () {
  458. // Setup
  459. var notice = new PNotify({
  460. title: 'Input needed',
  461. text: 'Write me a poem, please.',
  462. hide: false,
  463. confirm: {
  464. prompt: true,
  465. prompt_multi_line: true,
  466. prompt_default: 'Roses are red,\nViolets are blue,\n',
  467. buttons: [
  468. {
  469. text: 'Yes',
  470. addClass: 'btn btn-sm btn-primary'
  471. },
  472. {
  473. addClass: 'btn btn-sm btn-link'
  474. }
  475. ]
  476. },
  477. buttons: {
  478. closer: false,
  479. sticker: false
  480. }
  481. });
  482. // Confirm
  483. notice.get().on('pnotify.confirm', function(e, notice, val) {
  484. notice.cancelRemove().update({
  485. title: 'Your poem',
  486. text: $('<div/>').text(val).html(),
  487. icon: 'icon-checkmark3',
  488. type: 'success',
  489. hide: true,
  490. confirm: {
  491. prompt: false
  492. },
  493. buttons: {
  494. closer: true,
  495. sticker: true
  496. }
  497. });
  498. });
  499. // On cancel
  500. notice.get().on('pnotify.cancel', function(e, notice) {
  501. notice.cancelRemove().update({
  502. title: 'You don\'t like poetry',
  503. text: 'Roses are dead,\nViolets are dead,\nI suck at gardening.',
  504. icon: 'icon-blocked',
  505. type: 'error',
  506. hide: true,
  507. confirm: {
  508. prompt: false
  509. },
  510. buttons: {
  511. closer: true,
  512. sticker: true
  513. }
  514. });
  515. });
  516. });
  517. // Custom buttons
  518. $('#pnotify-buttons').on('click', function () {
  519. new PNotify({
  520. title: 'Choose a side',
  521. text: 'You have three options to choose from.',
  522. hide: false,
  523. width: 420,
  524. confirm: {
  525. confirm: true,
  526. buttons: [
  527. {
  528. text: 'Fries',
  529. addClass: 'btn btn-sm bg-blue',
  530. click: function(notice) {
  531. notice.update({
  532. title: 'You\'ve chosen a side',
  533. text: 'You want fries.',
  534. icon: 'icon-checkmark3',
  535. type: 'success',
  536. hide: true,
  537. confirm: {
  538. confirm: false
  539. },
  540. buttons: {
  541. closer: true,
  542. sticker: true
  543. }
  544. });
  545. }
  546. },
  547. {
  548. text: 'Mashed Potatoes',
  549. addClass: 'btn btn-sm bg-pink-400',
  550. click: function(notice) {
  551. notice.update({
  552. title: 'You\'ve chosen a side',
  553. text: 'You want mashed potatoes.',
  554. icon: 'icon-checkmark3',
  555. type: 'info',
  556. hide: true,
  557. confirm: {
  558. confirm: false
  559. },
  560. buttons: {
  561. closer: true,
  562. sticker: true
  563. }
  564. });
  565. }
  566. },
  567. {
  568. text: 'Fruit',
  569. addClass: 'btn btn-sm bg-indigo-400',
  570. click: function(notice) {
  571. notice.update({
  572. title: 'You\'ve chosen a side',
  573. text: 'You want fruit.',
  574. icon: 'icon-checkmark3',
  575. type: 'info',
  576. hide: true,
  577. confirm: {
  578. confirm: false
  579. },
  580. buttons: {
  581. closer: true,
  582. sticker: true
  583. }
  584. });
  585. }
  586. }
  587. ]
  588. },
  589. buttons: {
  590. closer: false,
  591. sticker: false
  592. }
  593. });
  594. });
  595. // Permanotice
  596. $('#pnotify-permanotice').on('click', function () {
  597. var permanotice;
  598. if (permanotice) {
  599. permanotice.open();
  600. }
  601. else {
  602. permanotice = new PNotify({
  603. title: 'Now look here',
  604. text: 'There\'s something you need to know, and I won\'t go away until you come to grips with it.',
  605. addclass: 'bg-danger border-danger',
  606. hide: false,
  607. buttons: {
  608. closer: false,
  609. sticker: false
  610. }
  611. });
  612. }
  613. });
  614. // Callbacks
  615. $('#pnotify-callbacks').on('click', function () {
  616. var dont_alert = function() {};
  617. new PNotify({
  618. title: 'I\'m here',
  619. text: 'I have a callback for each of my events. I\'ll call all my callbacks while I change states.',
  620. addclass: 'bg-teal border-teal',
  621. before_init: function(opts) {
  622. dont_alert('I\'m called before the notice initializes. I\'m passed the options used to make the notice. I can modify them. Watch me replace the word callback with tire iron!');
  623. opts.text = opts.text.replace(/callback/g, 'tire iron');
  624. },
  625. after_init: function(PNotify) {
  626. dont_alert('I\'m called after the notice initializes. I\'m passed the PNotify object for the current notice: ' + PNotify + '\n\nThere are more callbacks you can assign, but this is the last notice you\'ll see. Check the code to see them all.');
  627. },
  628. before_open: function(PNotify) {
  629. var source_note = 'Return false to cancel opening.';
  630. dont_alert('I\'m called before the notice opens. I\'m passed the PNotify object for the current notice: ' + PNotify);
  631. },
  632. after_open: function(PNotify) {
  633. alert('I\'m called after the notice opens. I\'m passed the PNotify object for the current notice: ' + PNotify);
  634. },
  635. before_close: function(PNotify, timer_hide) {
  636. var source_note = 'Return false to cancel close. Use PNotify.queueRemove() to set the removal timer again.';
  637. dont_alert('I\'m called before the notice closes. I\'m passed the PNotify object for the current notice: ' + PNotify);
  638. dont_alert('I also have an argument called timer_hide, which is true if the notice was closed because the timer ran down. Value: ' + timer_hide);
  639. },
  640. after_close: function(PNotify, timer_hide) {
  641. alert('I\'m called after the notice closes. I\'m passed the PNotify object for the current notice: ' + PNotify);
  642. dont_alert('I also have an argument called timer_hide, which is true if the notice was closed because the timer ran down. Value: ' + timer_hide);
  643. }
  644. });
  645. });
  646. // Switching notices
  647. $('#pnotify-switching').on('click', function () {
  648. new PNotify({
  649. title: 'Notice',
  650. text: 'Right now I\'m a notice.',
  651. addclass: 'alert bg-primary border-primary alert-styled-right',
  652. before_close: function(PNotify) {
  653. PNotify.update({
  654. title: 'Error',
  655. text: 'Uh oh. Now I\'ve become an error.',
  656. addclass: 'alert bg-danger border-danger alert-styled-right',
  657. type: 'error',
  658. before_close: function(PNotify) {
  659. PNotify.update({
  660. title: 'Success',
  661. text: 'I fixed the error!',
  662. addclass: 'alert bg-success border-success alert-styled-right',
  663. type: 'success',
  664. before_close: function(PNotify) {
  665. PNotify.update({
  666. title: 'Info',
  667. text: 'Everything\'s cool now.',
  668. addclass: 'alert bg-info border-info alert-styled-right',
  669. type: 'info',
  670. before_close: null
  671. });
  672. PNotify.queueRemove();
  673. return false;
  674. }
  675. });
  676. PNotify.queueRemove();
  677. return false;
  678. }
  679. });
  680. PNotify.queueRemove();
  681. return false;
  682. }
  683. });
  684. });
  685. // Progress loader
  686. $('#pnotify-progress').on('click', function () {
  687. var cur_value = 1,
  688. progress;
  689. // Make a loader.
  690. var loader = new PNotify({
  691. title: "Creating series of tubes",
  692. text: '<div class="progress" style="margin:0">\
  693. <div class="progress-bar bg-danger progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0">\
  694. <span class="sr-only">0%</span>\
  695. </div>\
  696. </div>',
  697. addclass: 'bg-primary border-primary',
  698. icon: 'icon-spinner4 spinner',
  699. hide: false,
  700. buttons: {
  701. closer: false,
  702. sticker: false
  703. },
  704. before_open: function(PNotify) {
  705. progress = PNotify.get().find("div.progress-bar");
  706. progress.width(cur_value + "%").attr("aria-valuenow", cur_value).find("span").html(cur_value + "%");
  707. // Pretend to do something.
  708. var timer = setInterval(function() {
  709. if (cur_value >= 100) {
  710. // Remove the interval.
  711. window.clearInterval(timer);
  712. loader.remove();
  713. return;
  714. }
  715. cur_value += 1;
  716. progress.width(cur_value + "%").attr("aria-valuenow", cur_value).find("span").html(cur_value + "%");
  717. }, 65);
  718. }
  719. });
  720. });
  721. // Dynamic loader
  722. $('#pnotify-dynamic').on('click', function () {
  723. var percent = 0;
  724. var notice = new PNotify({
  725. text: "Please wait",
  726. addclass: 'bg-primary border-primary',
  727. type: 'info',
  728. icon: 'icon-spinner4 spinner',
  729. hide: false,
  730. buttons: {
  731. closer: false,
  732. sticker: false
  733. },
  734. opacity: .9,
  735. width: "170px"
  736. });
  737. setTimeout(function() {
  738. notice.update({
  739. title: false
  740. });
  741. var interval = setInterval(function() {
  742. percent += 2;
  743. var options = {
  744. text: percent + "% complete."
  745. };
  746. if (percent == 80) options.title = "Almost There";
  747. if (percent >= 100) {
  748. window.clearInterval(interval);
  749. options.title = "Done!";
  750. options.addclass = "bg-success border-success";
  751. options.type = "success";
  752. options.hide = true;
  753. options.buttons = {
  754. closer: true,
  755. sticker: true
  756. };
  757. options.icon = 'icon-checkmark3';
  758. options.opacity = 1;
  759. options.width = PNotify.prototype.options.width;
  760. }
  761. notice.update(options);
  762. }, 120);
  763. }, 2000);
  764. });
  765. // Stacks
  766. // ------------------------------
  767. // Define directions
  768. var stack_top_left = {"dir1": "right", "dir2": "down", "push": "top"};
  769. var stack_bottom_left = {"dir1": "right", "dir2": "up", "push": "top"};
  770. var stack_bottom_right = {"dir1": "left", "dir2": "up", "firstpos1": 20, "firstpos2": 20};
  771. var stack_custom_left = {"dir1": "right", "dir2": "down"};
  772. var stack_custom_right = {"dir1": "left", "dir2": "up", "push": "top"};
  773. var stack_custom_top = {"dir1": "right", "dir2": "down", "push": "top", "spacing1": 1};
  774. var stack_custom_bottom = {"dir1": "right", "dir2": "up", "spacing1": 1};
  775. var stack_top_left_rtl = {"dir1": "left", "dir2": "down", "push": "top"};
  776. var stack_bottom_left_rtl = {"dir1": "left", "dir2": "up", "push": "top"};
  777. var stack_bottom_right_rtl = {"dir1": "right", "dir2": "up", "firstpos1": 20, "firstpos2": 20};
  778. var stack_custom_left_rtl = {"dir1": "left", "dir2": "down"};
  779. var stack_custom_right_rtl = {"dir1": "right", "dir2": "up", "push": "top"};
  780. //
  781. // Setup options for positions
  782. //
  783. // Top left
  784. function show_stack_top_left(type) {
  785. var opts = {
  786. title: "Over here",
  787. text: "Check me out. I'm in a different stack.",
  788. addclass: "stack-top-left bg-primary border-primary",
  789. stack: $('html').attr('dir') == 'rtl' ? stack_top_left_rtl : stack_top_left
  790. };
  791. switch (type) {
  792. case 'error':
  793. opts.title = "Oh No";
  794. opts.text = "Watch out for that water tower!";
  795. opts.addclass = "stack-top-left bg-danger border-danger";
  796. opts.type = "error";
  797. break;
  798. case 'info':
  799. opts.title = "Breaking News";
  800. opts.text = "Have you met Ted?";
  801. opts.addclass = "stack-top-left bg-info border-info";
  802. opts.type = "info";
  803. break;
  804. case 'success':
  805. opts.title = "Good News Everyone";
  806. opts.text = "I've invented a device that bites shiny metal asses.";
  807. opts.addclass = "stack-top-left bg-success border-success";
  808. opts.type = "success";
  809. break;
  810. }
  811. new PNotify(opts);
  812. }
  813. // Bottom left
  814. function show_stack_bottom_left(type) {
  815. var opts = {
  816. title: "Over here",
  817. text: "Check me out. I'm in a different stack.",
  818. addclass: "stack-bottom-left bg-primary border-primary",
  819. stack: $('html').attr('dir') == 'rtl' ? stack_bottom_left_rtl : stack_bottom_left
  820. };
  821. switch (type) {
  822. case 'error':
  823. opts.title = "Oh No";
  824. opts.text = "Watch out for that water tower!";
  825. opts.addclass = "stack-bottom-left bg-danger border-danger";
  826. opts.type = "error";
  827. break;
  828. case 'info':
  829. opts.title = "Breaking News";
  830. opts.text = "Have you met Ted?";
  831. opts.addclass = "stack-bottom-left bg-info border-info";
  832. opts.type = "info";
  833. break;
  834. case 'success':
  835. opts.title = "Good News Everyone";
  836. opts.text = "I've invented a device that bites shiny metal asses.";
  837. opts.addclass = "stack-bottom-left bg-success border-success";
  838. opts.type = "success";
  839. break;
  840. }
  841. new PNotify(opts);
  842. }
  843. // Bottom right
  844. function show_stack_bottom_right(type) {
  845. var opts = {
  846. title: "Over here",
  847. text: "Check me out. I'm in a different stack.",
  848. addclass: "stack-bottom-right bg-primary border-primary",
  849. stack: $('html').attr('dir') == 'rtl' ? stack_bottom_right_rtl : stack_bottom_right
  850. };
  851. switch (type) {
  852. case 'error':
  853. opts.title = "Oh No";
  854. opts.text = "Watch out for that water tower!";
  855. opts.addclass = "stack-bottom-right bg-danger border-danger";
  856. opts.type = "error";
  857. break;
  858. case 'info':
  859. opts.title = "Breaking News";
  860. opts.text = "Have you met Ted?";
  861. opts.addclass = "stack-bottom-right bg-info border-info";
  862. opts.type = "info";
  863. break;
  864. case 'success':
  865. opts.title = "Good News Everyone";
  866. opts.text = "I've invented a device that bites shiny metal asses.";
  867. opts.addclass = "stack-bottom-right bg-success border-success";
  868. opts.type = "success";
  869. break;
  870. }
  871. new PNotify(opts);
  872. }
  873. // Custom left position
  874. function show_stack_custom_left(type) {
  875. var opts = {
  876. title: "Over here",
  877. text: "Check me out. I'm in a different stack.",
  878. addclass: "stack-custom-left bg-primary border-primary alert-styled-right",
  879. stack: $('html').attr('dir') == 'rtl' ? stack_custom_left_rtl : stack_custom_left
  880. };
  881. switch (type) {
  882. case 'error':
  883. opts.title = "Oh No";
  884. opts.text = "Watch out for that water tower!";
  885. opts.addclass = "stack-custom-left bg-danger border-danger";
  886. opts.type = "error";
  887. break;
  888. case 'info':
  889. opts.title = "Breaking News";
  890. opts.text = "Have you met Ted?";
  891. opts.addclass = "stack-custom-left bg-info border-info";
  892. opts.type = "info";
  893. break;
  894. case 'success':
  895. opts.title = "Good News Everyone";
  896. opts.text = "I've invented a device that bites shiny metal asses.";
  897. opts.addclass = "stack-custom-left bg-success border-success";
  898. opts.type = "success";
  899. break;
  900. }
  901. new PNotify(opts);
  902. }
  903. // Custom right position
  904. function show_stack_custom_right(type) {
  905. var opts = {
  906. title: "Over here",
  907. text: "Check me out. I'm in a different stack.",
  908. addclass: "stack-custom-right bg-primary border-primary",
  909. stack: $('html').attr('dir') == 'rtl' ? stack_custom_right_rtl : stack_custom_right
  910. };
  911. switch (type) {
  912. case 'error':
  913. opts.title = "Oh No";
  914. opts.text = "Watch out for that water tower!";
  915. opts.addclass = "stack-custom-right bg-danger border-danger";
  916. opts.type = "error";
  917. break;
  918. case 'info':
  919. opts.title = "Breaking News";
  920. opts.text = "Have you met Ted?";
  921. opts.addclass = "stack-custom-right bg-info border-info";
  922. opts.type = "info";
  923. break;
  924. case 'success':
  925. opts.title = "Good News Everyone";
  926. opts.text = "I've invented a device that bites shiny metal asses.";
  927. opts.addclass = "stack-custom-right bg-success border-success";
  928. opts.type = "success";
  929. break;
  930. }
  931. new PNotify(opts);
  932. }
  933. // Custom top position
  934. function show_stack_custom_top(type) {
  935. var opts = {
  936. title: "Over here",
  937. text: "Check me out. I'm in a different stack.",
  938. width: "100%",
  939. cornerclass: "rounded-0",
  940. addclass: "stack-custom-top bg-primary border-primary",
  941. stack: stack_custom_top
  942. };
  943. switch (type) {
  944. case 'error':
  945. opts.title = "Oh No";
  946. opts.text = "Watch out for that water tower!";
  947. opts.addclass = "stack-custom-top bg-danger border-danger";
  948. opts.type = "error";
  949. break;
  950. case 'info':
  951. opts.title = "Breaking News";
  952. opts.text = "Have you met Ted?";
  953. opts.addclass = "stack-custom-top bg-info border-info";
  954. opts.type = "info";
  955. break;
  956. case 'success':
  957. opts.title = "Good News Everyone";
  958. opts.text = "I've invented a device that bites shiny metal asses.";
  959. opts.addclass = "stack-custom-top bg-success border-success";
  960. opts.type = "success";
  961. break;
  962. }
  963. new PNotify(opts);
  964. }
  965. // Custom bottom position
  966. function show_stack_custom_bottom(type) {
  967. var opts = {
  968. title: "Over here",
  969. text: "Check me out. I'm in a different stack.",
  970. width: "100%",
  971. cornerclass: "rounded-0",
  972. addclass: "stack-custom-bottom bg-primary border-primary",
  973. stack: stack_custom_bottom
  974. };
  975. switch (type) {
  976. case 'error':
  977. opts.title = "Oh No";
  978. opts.text = "Watch out for that water tower!";
  979. opts.addclass = "stack-custom-bottom bg-danger border-danger";
  980. opts.type = "error";
  981. break;
  982. case 'info':
  983. opts.title = "Breaking News";
  984. opts.text = "Have you met Ted?";
  985. opts.addclass = "stack-custom-bottom bg-info border-info";
  986. opts.type = "info";
  987. break;
  988. case 'success':
  989. opts.title = "Good News Everyone";
  990. opts.text = "I've invented a device that bites shiny metal asses.";
  991. opts.addclass = "stack-custom-bottom bg-success border-success";
  992. opts.type = "success";
  993. break;
  994. }
  995. new PNotify(opts);
  996. }
  997. //
  998. // Initialize
  999. //
  1000. // Top left
  1001. $('#pnotify-stack-top-left').on('click', function () {
  1002. show_stack_top_left('primary');
  1003. });
  1004. // Bottom left
  1005. $('#pnotify-stack-bottom-left').on('click', function () {
  1006. show_stack_bottom_left('primary');
  1007. });
  1008. // Bottom right
  1009. $('#pnotify-stack-bottom-right').on('click', function () {
  1010. show_stack_bottom_right('danger');
  1011. });
  1012. // Custom left
  1013. $('#pnotify-stack-custom-left').on('click', function () {
  1014. show_stack_custom_left('success');
  1015. });
  1016. // Custom right
  1017. $('#pnotify-stack-custom-right').on('click', function () {
  1018. show_stack_custom_right('success');
  1019. });
  1020. // Custom top
  1021. $('#pnotify-stack-custom-top').on('click', function () {
  1022. show_stack_custom_top('info');
  1023. });
  1024. // Custom bottom
  1025. $('#pnotify-stack-custom-bottom').on('click', function () {
  1026. show_stack_custom_bottom('info');
  1027. });
  1028. };
  1029. //
  1030. // Return objects assigned to module
  1031. //
  1032. return {
  1033. init: function() {
  1034. _componentPnotify();
  1035. }
  1036. }
  1037. }();
  1038. // Initialize module
  1039. // ------------------------------
  1040. document.addEventListener('DOMContentLoaded', function() {
  1041. Pnotify.init();
  1042. });