toast.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. /*!
  2. * # Fomantic-UI - Toast
  3. * http://github.com/fomantic/Fomantic-UI/
  4. *
  5. *
  6. * Released under the MIT license
  7. * http://opensource.org/licenses/MIT
  8. *
  9. */
  10. ;(function ($, window, document, undefined) {
  11. 'use strict';
  12. $.isFunction = $.isFunction || function(obj) {
  13. return typeof obj === "function" && typeof obj.nodeType !== "number";
  14. };
  15. window = (typeof window != 'undefined' && window.Math == Math)
  16. ? window
  17. : (typeof self != 'undefined' && self.Math == Math)
  18. ? self
  19. : Function('return this')()
  20. ;
  21. $.fn.toast = function(parameters) {
  22. var
  23. $allModules = $(this),
  24. moduleSelector = $allModules.selector || '',
  25. time = new Date().getTime(),
  26. performance = [],
  27. query = arguments[0],
  28. methodInvoked = (typeof query == 'string'),
  29. queryArguments = [].slice.call(arguments, 1),
  30. returnedValue
  31. ;
  32. $allModules
  33. .each(function() {
  34. var
  35. settings = ( $.isPlainObject(parameters) )
  36. ? $.extend(true, {}, $.fn.toast.settings, parameters)
  37. : $.extend({}, $.fn.toast.settings),
  38. className = settings.className,
  39. selector = settings.selector,
  40. error = settings.error,
  41. namespace = settings.namespace,
  42. fields = settings.fields,
  43. eventNamespace = '.' + namespace,
  44. moduleNamespace = namespace + '-module',
  45. $module = $(this),
  46. $toastBox,
  47. $toast,
  48. $actions,
  49. $progress,
  50. $progressBar,
  51. $animationObject,
  52. $close,
  53. $context = (settings.context)
  54. ? $(settings.context)
  55. : $('body'),
  56. isToastComponent = $module.hasClass('toast') || $module.hasClass('message') || $module.hasClass('card'),
  57. element = this,
  58. instance = isToastComponent ? $module.data(moduleNamespace) : undefined,
  59. module
  60. ;
  61. module = {
  62. initialize: function() {
  63. module.verbose('Initializing element');
  64. if (!module.has.container()) {
  65. module.create.container();
  66. }
  67. if(isToastComponent || settings.message !== '' || settings.title !== '' || module.get.iconClass() !== '' || settings.showImage || module.has.configActions()) {
  68. if(typeof settings.showProgress !== 'string' || [className.top,className.bottom].indexOf(settings.showProgress) === -1 ) {
  69. settings.showProgress = false;
  70. }
  71. module.create.toast();
  72. if(settings.closeOnClick && (settings.closeIcon || $($toast).find(selector.input).length > 0 || module.has.configActions())){
  73. settings.closeOnClick = false;
  74. }
  75. if(!settings.closeOnClick) {
  76. $toastBox.addClass(className.unclickable);
  77. }
  78. module.bind.events();
  79. }
  80. module.instantiate();
  81. if($toastBox) {
  82. module.show();
  83. }
  84. },
  85. instantiate: function() {
  86. module.verbose('Storing instance of toast');
  87. instance = module;
  88. $module
  89. .data(moduleNamespace, instance)
  90. ;
  91. },
  92. destroy: function() {
  93. if($toastBox) {
  94. module.debug('Removing toast', $toastBox);
  95. module.unbind.events();
  96. $toastBox.remove();
  97. $toastBox = undefined;
  98. $toast = undefined;
  99. $animationObject = undefined;
  100. settings.onRemove.call($toastBox, element);
  101. $progress = undefined;
  102. $progressBar = undefined;
  103. $close = undefined;
  104. }
  105. $module
  106. .removeData(moduleNamespace)
  107. ;
  108. },
  109. show: function(callback) {
  110. callback = callback || function(){};
  111. module.debug('Showing toast');
  112. if(settings.onShow.call($toastBox, element) === false) {
  113. module.debug('onShow callback returned false, cancelling toast animation');
  114. return;
  115. }
  116. module.animate.show(callback);
  117. },
  118. close: function(callback) {
  119. callback = callback || function(){};
  120. module.remove.visible();
  121. module.unbind.events();
  122. module.animate.close(callback);
  123. },
  124. create: {
  125. container: function() {
  126. module.verbose('Creating container');
  127. $context.append($('<div/>',{class: settings.position + ' ' + className.container}));
  128. },
  129. toast: function() {
  130. $toastBox = $('<div/>', {class: className.box});
  131. if (!isToastComponent) {
  132. module.verbose('Creating toast');
  133. $toast = $('<div/>');
  134. var $content = $('<div/>', {class: className.content});
  135. var iconClass = module.get.iconClass();
  136. if (iconClass !== '') {
  137. $toast.append($('<i/>', {class: iconClass + ' ' + className.icon}));
  138. }
  139. if (settings.showImage) {
  140. $toast.append($('<img>', {
  141. class: className.image + ' ' + settings.classImage,
  142. src: settings.showImage
  143. }));
  144. }
  145. if (settings.title !== '') {
  146. $content.append($('<div/>', {
  147. class: className.title,
  148. text: settings.title
  149. }));
  150. }
  151. $content.append($('<div/>', {html: module.helpers.escape(settings.message, settings.preserveHTML)}));
  152. $toast
  153. .addClass(settings.class + ' ' + className.toast)
  154. .append($content)
  155. ;
  156. $toast.css('opacity', settings.opacity);
  157. if (settings.closeIcon) {
  158. $close = $('<i/>', {class: className.close + ' ' + (typeof settings.closeIcon === 'string' ? settings.closeIcon : '')});
  159. if($close.hasClass(className.left)) {
  160. $toast.prepend($close);
  161. } else {
  162. $toast.append($close);
  163. }
  164. }
  165. } else {
  166. $toast = settings.cloneModule ? $module.clone().removeAttr('id') : $module;
  167. $close = $toast.find('> i'+module.helpers.toClass(className.close));
  168. settings.closeIcon = ($close.length > 0);
  169. }
  170. if ($toast.hasClass(className.compact)) {
  171. settings.compact = true;
  172. }
  173. if ($toast.hasClass('card')) {
  174. settings.compact = false;
  175. }
  176. $actions = $toast.find('.actions');
  177. if (module.has.configActions()) {
  178. if ($actions.length === 0) {
  179. $actions = $('<div/>', {class: className.actions + ' ' + (settings.classActions || '')}).appendTo($toast);
  180. }
  181. if($toast.hasClass('card') && !$actions.hasClass(className.attached)) {
  182. $actions.addClass(className.extraContent);
  183. if($actions.hasClass(className.vertical)) {
  184. $actions.removeClass(className.vertical);
  185. module.error(error.verticalCard);
  186. }
  187. }
  188. settings.actions.forEach(function (el) {
  189. var icon = el[fields.icon] ? '<i class="' + module.helpers.deQuote(el[fields.icon]) + ' icon"></i>' : '',
  190. text = module.helpers.escape(el[fields.text] || '', settings.preserveHTML),
  191. cls = module.helpers.deQuote(el[fields.class] || ''),
  192. click = el[fields.click] && $.isFunction(el[fields.click]) ? el[fields.click] : function () {};
  193. $actions.append($('<button/>', {
  194. html: icon + text,
  195. class: className.button + ' ' + cls,
  196. click: function () {
  197. if (click.call(element, $module) === false) {
  198. return;
  199. }
  200. module.close();
  201. }
  202. }));
  203. });
  204. }
  205. if ($actions && $actions.hasClass(className.vertical)) {
  206. $toast.addClass(className.vertical);
  207. }
  208. if($actions.length > 0 && !$actions.hasClass(className.attached)) {
  209. if ($actions && (!$actions.hasClass(className.basic) || $actions.hasClass(className.left))) {
  210. $toast.addClass(className.actions);
  211. }
  212. }
  213. if(settings.displayTime === 'auto'){
  214. settings.displayTime = Math.max(settings.minDisplayTime, $toast.text().split(" ").length / settings.wordsPerMinute * 60000);
  215. }
  216. $toastBox.append($toast);
  217. if($actions.length > 0 && $actions.hasClass(className.attached)) {
  218. $actions.addClass(className.buttons);
  219. $actions.detach();
  220. $toast.addClass(className.attached);
  221. if (!$actions.hasClass(className.vertical)) {
  222. if ($actions.hasClass(className.top)) {
  223. $toastBox.prepend($actions);
  224. $toast.addClass(className.bottom);
  225. } else {
  226. $toastBox.append($actions);
  227. $toast.addClass(className.top);
  228. }
  229. } else {
  230. $toast.wrap(
  231. $('<div/>',{
  232. class:className.vertical + ' ' +
  233. className.attached + ' ' +
  234. (settings.compact ? className.compact : '')
  235. })
  236. );
  237. if($actions.hasClass(className.left)) {
  238. $toast.addClass(className.left).parent().addClass(className.left).prepend($actions);
  239. } else {
  240. $toast.parent().append($actions);
  241. }
  242. }
  243. }
  244. if($module !== $toast) {
  245. $module = $toast;
  246. element = $toast[0];
  247. }
  248. if(settings.displayTime > 0) {
  249. var progressingClass = className.progressing+' '+(settings.pauseOnHover ? className.pausable:'');
  250. if (!!settings.showProgress) {
  251. $progress = $('<div/>', {
  252. class: className.progress + ' ' + (settings.classProgress || settings.class),
  253. 'data-percent': ''
  254. });
  255. if(!settings.classProgress) {
  256. if ($toast.hasClass('toast') && !$toast.hasClass(className.inverted)) {
  257. $progress.addClass(className.inverted);
  258. } else {
  259. $progress.removeClass(className.inverted);
  260. }
  261. }
  262. $progressBar = $('<div/>', {class: 'bar '+(settings.progressUp ? 'up ' : 'down ')+progressingClass});
  263. $progress
  264. .addClass(settings.showProgress)
  265. .append($progressBar);
  266. if ($progress.hasClass(className.top)) {
  267. $toastBox.prepend($progress);
  268. } else {
  269. $toastBox.append($progress);
  270. }
  271. $progressBar.css('animation-duration', settings.displayTime / 1000 + 's');
  272. }
  273. $animationObject = $('<span/>',{class:'wait '+progressingClass});
  274. $animationObject.css('animation-duration', settings.displayTime / 1000 + 's');
  275. $animationObject.appendTo($toast);
  276. }
  277. if (settings.compact) {
  278. $toastBox.addClass(className.compact);
  279. $toast.addClass(className.compact);
  280. if($progress) {
  281. $progress.addClass(className.compact);
  282. }
  283. }
  284. if (settings.newestOnTop) {
  285. $toastBox.prependTo(module.get.container());
  286. }
  287. else {
  288. $toastBox.appendTo(module.get.container());
  289. }
  290. }
  291. },
  292. bind: {
  293. events: function() {
  294. module.debug('Binding events to toast');
  295. if(settings.closeOnClick || settings.closeIcon) {
  296. (settings.closeIcon ? $close : $toast)
  297. .on('click' + eventNamespace, module.event.click)
  298. ;
  299. }
  300. if($animationObject) {
  301. $animationObject.on('animationend' + eventNamespace, module.close);
  302. }
  303. $toastBox
  304. .on('click' + eventNamespace, selector.approve, module.event.approve)
  305. .on('click' + eventNamespace, selector.deny, module.event.deny)
  306. ;
  307. }
  308. },
  309. unbind: {
  310. events: function() {
  311. module.debug('Unbinding events to toast');
  312. if(settings.closeOnClick || settings.closeIcon) {
  313. (settings.closeIcon ? $close : $toast)
  314. .off('click' + eventNamespace)
  315. ;
  316. }
  317. if($animationObject) {
  318. $animationObject.off('animationend' + eventNamespace);
  319. }
  320. $toastBox
  321. .off('click' + eventNamespace)
  322. ;
  323. }
  324. },
  325. animate: {
  326. show: function(callback) {
  327. callback = $.isFunction(callback) ? callback : function(){};
  328. if(settings.transition && module.can.useElement('transition') && $module.transition('is supported')) {
  329. module.set.visible();
  330. $toastBox
  331. .transition({
  332. animation : settings.transition.showMethod + ' in',
  333. queue : false,
  334. debug : settings.debug,
  335. verbose : settings.verbose,
  336. duration : settings.transition.showDuration,
  337. onComplete : function() {
  338. callback.call($toastBox, element);
  339. settings.onVisible.call($toastBox, element);
  340. }
  341. })
  342. ;
  343. }
  344. },
  345. close: function(callback) {
  346. callback = $.isFunction(callback) ? callback : function(){};
  347. module.debug('Closing toast');
  348. if(settings.onHide.call($toastBox, element) === false) {
  349. module.debug('onHide callback returned false, cancelling toast animation');
  350. return;
  351. }
  352. if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
  353. $toastBox
  354. .transition({
  355. animation : settings.transition.hideMethod + ' out',
  356. queue : false,
  357. duration : settings.transition.hideDuration,
  358. debug : settings.debug,
  359. verbose : settings.verbose,
  360. interval : 50,
  361. onBeforeHide: function(callback){
  362. callback = $.isFunction(callback)?callback : function(){};
  363. if(settings.transition.closeEasing !== ''){
  364. if($toastBox) {
  365. $toastBox.css('opacity', 0);
  366. $toastBox.wrap('<div/>').parent().slideUp(500, settings.transition.closeEasing, function () {
  367. if ($toastBox) {
  368. $toastBox.parent().remove();
  369. callback.call($toastBox);
  370. }
  371. });
  372. }
  373. } else {
  374. callback.call($toastBox);
  375. }
  376. },
  377. onComplete : function() {
  378. callback.call($toastBox, element);
  379. settings.onHidden.call($toastBox, element);
  380. module.destroy();
  381. }
  382. })
  383. ;
  384. }
  385. else {
  386. module.error(error.noTransition);
  387. }
  388. },
  389. pause: function() {
  390. $animationObject.css('animationPlayState','paused');
  391. if($progressBar) {
  392. $progressBar.css('animationPlayState', 'paused');
  393. }
  394. },
  395. continue: function() {
  396. $animationObject.css('animationPlayState','running');
  397. if($progressBar) {
  398. $progressBar.css('animationPlayState', 'running');
  399. }
  400. }
  401. },
  402. has: {
  403. container: function() {
  404. module.verbose('Determining if there is already a container');
  405. return ($context.find(module.helpers.toClass(settings.position) + selector.container).length > 0);
  406. },
  407. toast: function(){
  408. return !!module.get.toast();
  409. },
  410. toasts: function(){
  411. return module.get.toasts().length > 0;
  412. },
  413. configActions: function () {
  414. return Array.isArray(settings.actions) && settings.actions.length > 0;
  415. }
  416. },
  417. get: {
  418. container: function() {
  419. return ($context.find(module.helpers.toClass(settings.position) + selector.container)[0]);
  420. },
  421. toastBox: function() {
  422. return $toastBox || null;
  423. },
  424. toast: function() {
  425. return $toast || null;
  426. },
  427. toasts: function() {
  428. return $(module.get.container()).find(selector.box);
  429. },
  430. iconClass: function() {
  431. return typeof settings.showIcon === 'string' ? settings.showIcon : settings.showIcon && settings.icons[settings.class] ? settings.icons[settings.class] : '';
  432. },
  433. remainingTime: function() {
  434. return $animationObject ? $animationObject.css('opacity') * settings.displayTime : 0;
  435. }
  436. },
  437. set: {
  438. visible: function() {
  439. $toast.addClass(className.visible);
  440. }
  441. },
  442. remove: {
  443. visible: function() {
  444. $toast.removeClass(className.visible);
  445. }
  446. },
  447. event: {
  448. click: function(event) {
  449. if($(event.target).closest('a').length === 0) {
  450. settings.onClick.call($toastBox, element);
  451. module.close();
  452. }
  453. },
  454. approve: function() {
  455. if(settings.onApprove.call(element, $module) === false) {
  456. module.verbose('Approve callback returned false cancelling close');
  457. return;
  458. }
  459. module.close();
  460. },
  461. deny: function() {
  462. if(settings.onDeny.call(element, $module) === false) {
  463. module.verbose('Deny callback returned false cancelling close');
  464. return;
  465. }
  466. module.close();
  467. }
  468. },
  469. helpers: {
  470. toClass: function(selector) {
  471. var
  472. classes = selector.split(' '),
  473. result = ''
  474. ;
  475. classes.forEach(function (element) {
  476. result += '.' + element;
  477. });
  478. return result;
  479. },
  480. deQuote: function(string) {
  481. return String(string).replace(/"/g,"");
  482. },
  483. escape: function(string, preserveHTML) {
  484. if (preserveHTML){
  485. return string;
  486. }
  487. var
  488. badChars = /[<>"'`]/g,
  489. shouldEscape = /[&<>"'`]/,
  490. escape = {
  491. "<": "&lt;",
  492. ">": "&gt;",
  493. '"': "&quot;",
  494. "'": "&#x27;",
  495. "`": "&#x60;"
  496. },
  497. escapedChar = function(chr) {
  498. return escape[chr];
  499. }
  500. ;
  501. if(shouldEscape.test(string)) {
  502. string = string.replace(/&(?![a-z0-9#]{1,6};)/, "&amp;");
  503. return string.replace(badChars, escapedChar);
  504. }
  505. return string;
  506. }
  507. },
  508. can: {
  509. useElement: function(element){
  510. if ($.fn[element] !== undefined) {
  511. return true;
  512. }
  513. module.error(error.noElement.replace('{element}',element));
  514. return false;
  515. }
  516. },
  517. setting: function(name, value) {
  518. module.debug('Changing setting', name, value);
  519. if( $.isPlainObject(name) ) {
  520. $.extend(true, settings, name);
  521. }
  522. else if(value !== undefined) {
  523. if($.isPlainObject(settings[name])) {
  524. $.extend(true, settings[name], value);
  525. }
  526. else {
  527. settings[name] = value;
  528. }
  529. }
  530. else {
  531. return settings[name];
  532. }
  533. },
  534. internal: function(name, value) {
  535. if( $.isPlainObject(name) ) {
  536. $.extend(true, module, name);
  537. }
  538. else if(value !== undefined) {
  539. module[name] = value;
  540. }
  541. else {
  542. return module[name];
  543. }
  544. },
  545. debug: function() {
  546. if(!settings.silent && settings.debug) {
  547. if(settings.performance) {
  548. module.performance.log(arguments);
  549. }
  550. else {
  551. module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
  552. module.debug.apply(console, arguments);
  553. }
  554. }
  555. },
  556. verbose: function() {
  557. if(!settings.silent && settings.verbose && settings.debug) {
  558. if(settings.performance) {
  559. module.performance.log(arguments);
  560. }
  561. else {
  562. module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
  563. module.verbose.apply(console, arguments);
  564. }
  565. }
  566. },
  567. error: function() {
  568. if(!settings.silent) {
  569. module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
  570. module.error.apply(console, arguments);
  571. }
  572. },
  573. performance: {
  574. log: function(message) {
  575. var
  576. currentTime,
  577. executionTime,
  578. previousTime
  579. ;
  580. if(settings.performance) {
  581. currentTime = new Date().getTime();
  582. previousTime = time || currentTime;
  583. executionTime = currentTime - previousTime;
  584. time = currentTime;
  585. performance.push({
  586. 'Name' : message[0],
  587. 'Arguments' : [].slice.call(message, 1) || '',
  588. 'Element' : element,
  589. 'Execution Time' : executionTime
  590. });
  591. }
  592. clearTimeout(module.performance.timer);
  593. module.performance.timer = setTimeout(module.performance.display, 500);
  594. },
  595. display: function() {
  596. var
  597. title = settings.name + ':',
  598. totalTime = 0
  599. ;
  600. time = false;
  601. clearTimeout(module.performance.timer);
  602. $.each(performance, function(index, data) {
  603. totalTime += data['Execution Time'];
  604. });
  605. title += ' ' + totalTime + 'ms';
  606. if(moduleSelector) {
  607. title += ' \'' + moduleSelector + '\'';
  608. }
  609. if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
  610. console.groupCollapsed(title);
  611. if(console.table) {
  612. console.table(performance);
  613. }
  614. else {
  615. $.each(performance, function(index, data) {
  616. console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
  617. });
  618. }
  619. console.groupEnd();
  620. }
  621. performance = [];
  622. }
  623. },
  624. invoke: function(query, passedArguments, context) {
  625. var
  626. object = instance,
  627. maxDepth,
  628. found,
  629. response
  630. ;
  631. passedArguments = passedArguments || queryArguments;
  632. context = element || context;
  633. if(typeof query == 'string' && object !== undefined) {
  634. query = query.split(/[\. ]/);
  635. maxDepth = query.length - 1;
  636. $.each(query, function(depth, value) {
  637. var camelCaseValue = (depth != maxDepth)
  638. ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
  639. : query
  640. ;
  641. if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
  642. object = object[camelCaseValue];
  643. }
  644. else if( object[camelCaseValue] !== undefined ) {
  645. found = object[camelCaseValue];
  646. return false;
  647. }
  648. else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
  649. object = object[value];
  650. }
  651. else if( object[value] !== undefined ) {
  652. found = object[value];
  653. return false;
  654. }
  655. else {
  656. module.error(error.method, query);
  657. return false;
  658. }
  659. });
  660. }
  661. if ( $.isFunction( found ) ) {
  662. response = found.apply(context, passedArguments);
  663. }
  664. else if(found !== undefined) {
  665. response = found;
  666. }
  667. if(Array.isArray(returnedValue)) {
  668. returnedValue.push(response);
  669. }
  670. else if(returnedValue !== undefined) {
  671. returnedValue = [returnedValue, response];
  672. }
  673. else if(response !== undefined) {
  674. returnedValue = response;
  675. }
  676. return found;
  677. }
  678. };
  679. if(methodInvoked) {
  680. if(instance === undefined) {
  681. module.initialize();
  682. }
  683. module.invoke(query);
  684. }
  685. else {
  686. if(instance !== undefined) {
  687. instance.invoke('destroy');
  688. }
  689. module.initialize();
  690. returnedValue = $module;
  691. }
  692. })
  693. ;
  694. return (returnedValue !== undefined)
  695. ? returnedValue
  696. : this
  697. ;
  698. };
  699. $.fn.toast.settings = {
  700. name : 'Toast',
  701. namespace : 'toast',
  702. silent : false,
  703. debug : false,
  704. verbose : false,
  705. performance : true,
  706. context : 'body',
  707. position : 'top right',
  708. class : 'neutral',
  709. classProgress : false,
  710. classActions : false,
  711. classImage : 'mini',
  712. title : '',
  713. message : '',
  714. displayTime : 3000, // set to zero to require manually dismissal, otherwise hides on its own
  715. minDisplayTime : 1000, // minimum displaytime in case displayTime is set to 'auto'
  716. wordsPerMinute : 120,
  717. showIcon : false,
  718. newestOnTop : false,
  719. showProgress : false,
  720. pauseOnHover : true,
  721. progressUp : false, //if true, the bar will start at 0% and increase to 100%
  722. opacity : 1,
  723. compact : true,
  724. closeIcon : false,
  725. closeOnClick : true,
  726. cloneModule : true,
  727. actions : false,
  728. preserveHTML : true,
  729. showImage : false,
  730. // transition settings
  731. transition : {
  732. showMethod : 'scale',
  733. showDuration : 500,
  734. hideMethod : 'scale',
  735. hideDuration : 500,
  736. closeEasing : 'easeOutCubic' //Set to empty string to stack the closed toast area immediately (old behaviour)
  737. },
  738. error: {
  739. method : 'The method you called is not defined.',
  740. noElement : 'This module requires ui {element}',
  741. verticalCard : 'Vertical but not attached actions are not supported for card layout'
  742. },
  743. className : {
  744. container : 'ui toast-container',
  745. box : 'floating toast-box',
  746. progress : 'ui attached active progress',
  747. toast : 'ui toast',
  748. icon : 'centered icon',
  749. visible : 'visible',
  750. content : 'content',
  751. title : 'ui header',
  752. actions : 'actions',
  753. extraContent : 'extra content',
  754. button : 'ui button',
  755. buttons : 'ui buttons',
  756. close : 'close icon',
  757. image : 'ui image',
  758. vertical : 'vertical',
  759. attached : 'attached',
  760. inverted : 'inverted',
  761. compact : 'compact',
  762. pausable : 'pausable',
  763. progressing : 'progressing',
  764. top : 'top',
  765. bottom : 'bottom',
  766. left : 'left',
  767. basic : 'basic',
  768. unclickable : 'unclickable'
  769. },
  770. icons : {
  771. info : 'info',
  772. success : 'checkmark',
  773. warning : 'warning',
  774. error : 'times'
  775. },
  776. selector : {
  777. container : '.ui.toast-container',
  778. box : '.toast-box',
  779. toast : '.ui.toast',
  780. input : 'input:not([type="hidden"]), textarea, select, button, .ui.button, ui.dropdown',
  781. approve : '.actions .positive, .actions .approve, .actions .ok',
  782. deny : '.actions .negative, .actions .deny, .actions .cancel'
  783. },
  784. fields : {
  785. class : 'class',
  786. text : 'text',
  787. icon : 'icon',
  788. click : 'click'
  789. },
  790. // callbacks
  791. onShow : function(){},
  792. onVisible : function(){},
  793. onClick : function(){},
  794. onHide : function(){},
  795. onHidden : function(){},
  796. onRemove : function(){},
  797. onApprove : function(){},
  798. onDeny : function(){}
  799. };
  800. $.extend( $.easing, {
  801. easeOutBounce: function (x, t, b, c, d) {
  802. if ((t/=d) < (1/2.75)) {
  803. return c*(7.5625*t*t) + b;
  804. } else if (t < (2/2.75)) {
  805. return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
  806. } else if (t < (2.5/2.75)) {
  807. return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
  808. } else {
  809. return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
  810. }
  811. },
  812. easeOutCubic: function (t) {
  813. return (--t)*t*t+1;
  814. }
  815. });
  816. })( jQuery, window, document );