modal.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  1. /*!
  2. * # Semantic UI 2.3.3 - Modal
  3. * http://github.com/semantic-org/semantic-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. window = (typeof window != 'undefined' && window.Math == Math)
  13. ? window
  14. : (typeof self != 'undefined' && self.Math == Math)
  15. ? self
  16. : Function('return this')()
  17. ;
  18. $.fn.modal = function(parameters) {
  19. var
  20. $allModules = $(this),
  21. $window = $(window),
  22. $document = $(document),
  23. $body = $('body'),
  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. requestAnimationFrame = window.requestAnimationFrame
  31. || window.mozRequestAnimationFrame
  32. || window.webkitRequestAnimationFrame
  33. || window.msRequestAnimationFrame
  34. || function(callback) { setTimeout(callback, 0); },
  35. returnedValue
  36. ;
  37. $allModules
  38. .each(function() {
  39. var
  40. settings = ( $.isPlainObject(parameters) )
  41. ? $.extend(true, {}, $.fn.modal.settings, parameters)
  42. : $.extend({}, $.fn.modal.settings),
  43. selector = settings.selector,
  44. className = settings.className,
  45. namespace = settings.namespace,
  46. error = settings.error,
  47. eventNamespace = '.' + namespace,
  48. moduleNamespace = 'module-' + namespace,
  49. $module = $(this),
  50. $context = $(settings.context),
  51. $close = $module.find(selector.close),
  52. $allModals,
  53. $otherModals,
  54. $focusedElement,
  55. $dimmable,
  56. $dimmer,
  57. element = this,
  58. instance = $module.data(moduleNamespace),
  59. ignoreRepeatedEvents = false,
  60. elementEventNamespace,
  61. id,
  62. observer,
  63. module
  64. ;
  65. module = {
  66. initialize: function() {
  67. module.verbose('Initializing dimmer', $context);
  68. module.create.id();
  69. module.create.dimmer();
  70. module.refreshModals();
  71. module.bind.events();
  72. if(settings.observeChanges) {
  73. module.observeChanges();
  74. }
  75. module.instantiate();
  76. },
  77. instantiate: function() {
  78. module.verbose('Storing instance of modal');
  79. instance = module;
  80. $module
  81. .data(moduleNamespace, instance)
  82. ;
  83. },
  84. create: {
  85. dimmer: function() {
  86. var
  87. defaultSettings = {
  88. debug : settings.debug,
  89. variation : settings.centered
  90. ? false
  91. : 'top aligned'
  92. ,
  93. dimmerName : 'modals'
  94. },
  95. dimmerSettings = $.extend(true, defaultSettings, settings.dimmerSettings)
  96. ;
  97. if($.fn.dimmer === undefined) {
  98. module.error(error.dimmer);
  99. return;
  100. }
  101. module.debug('Creating dimmer');
  102. $dimmable = $context.dimmer(dimmerSettings);
  103. if(settings.detachable) {
  104. module.verbose('Modal is detachable, moving content into dimmer');
  105. $dimmable.dimmer('add content', $module);
  106. }
  107. else {
  108. module.set.undetached();
  109. }
  110. $dimmer = $dimmable.dimmer('get dimmer');
  111. },
  112. id: function() {
  113. id = (Math.random().toString(16) + '000000000').substr(2,8);
  114. elementEventNamespace = '.' + id;
  115. module.verbose('Creating unique id for element', id);
  116. }
  117. },
  118. destroy: function() {
  119. module.verbose('Destroying previous modal');
  120. $module
  121. .removeData(moduleNamespace)
  122. .off(eventNamespace)
  123. ;
  124. $window.off(elementEventNamespace);
  125. $dimmer.off(elementEventNamespace);
  126. $close.off(eventNamespace);
  127. $context.dimmer('destroy');
  128. },
  129. observeChanges: function() {
  130. if('MutationObserver' in window) {
  131. observer = new MutationObserver(function(mutations) {
  132. module.debug('DOM tree modified, refreshing');
  133. module.refresh();
  134. });
  135. observer.observe(element, {
  136. childList : true,
  137. subtree : true
  138. });
  139. module.debug('Setting up mutation observer', observer);
  140. }
  141. },
  142. refresh: function() {
  143. module.remove.scrolling();
  144. module.cacheSizes();
  145. module.set.screenHeight();
  146. module.set.type();
  147. },
  148. refreshModals: function() {
  149. $otherModals = $module.siblings(selector.modal);
  150. $allModals = $otherModals.add($module);
  151. },
  152. attachEvents: function(selector, event) {
  153. var
  154. $toggle = $(selector)
  155. ;
  156. event = $.isFunction(module[event])
  157. ? module[event]
  158. : module.toggle
  159. ;
  160. if($toggle.length > 0) {
  161. module.debug('Attaching modal events to element', selector, event);
  162. $toggle
  163. .off(eventNamespace)
  164. .on('click' + eventNamespace, event)
  165. ;
  166. }
  167. else {
  168. module.error(error.notFound, selector);
  169. }
  170. },
  171. bind: {
  172. events: function() {
  173. module.verbose('Attaching events');
  174. $module
  175. .on('click' + eventNamespace, selector.close, module.event.close)
  176. .on('click' + eventNamespace, selector.approve, module.event.approve)
  177. .on('click' + eventNamespace, selector.deny, module.event.deny)
  178. ;
  179. $window
  180. .on('resize' + elementEventNamespace, module.event.resize)
  181. ;
  182. }
  183. },
  184. get: {
  185. id: function() {
  186. return (Math.random().toString(16) + '000000000').substr(2,8);
  187. }
  188. },
  189. event: {
  190. approve: function() {
  191. if(ignoreRepeatedEvents || settings.onApprove.call(element, $(this)) === false) {
  192. module.verbose('Approve callback returned false cancelling hide');
  193. return;
  194. }
  195. ignoreRepeatedEvents = true;
  196. module.hide(function() {
  197. ignoreRepeatedEvents = false;
  198. });
  199. },
  200. deny: function() {
  201. if(ignoreRepeatedEvents || settings.onDeny.call(element, $(this)) === false) {
  202. module.verbose('Deny callback returned false cancelling hide');
  203. return;
  204. }
  205. ignoreRepeatedEvents = true;
  206. module.hide(function() {
  207. ignoreRepeatedEvents = false;
  208. });
  209. },
  210. close: function() {
  211. module.hide();
  212. },
  213. click: function(event) {
  214. if(!settings.closable) {
  215. module.verbose('Dimmer clicked but closable setting is disabled');
  216. return;
  217. }
  218. var
  219. $target = $(event.target),
  220. isInModal = ($target.closest(selector.modal).length > 0),
  221. isInDOM = $.contains(document.documentElement, event.target)
  222. ;
  223. if(!isInModal && isInDOM && module.is.active()) {
  224. module.debug('Dimmer clicked, hiding all modals');
  225. module.remove.clickaway();
  226. if(settings.allowMultiple) {
  227. module.hide();
  228. }
  229. else {
  230. module.hideAll();
  231. }
  232. }
  233. },
  234. debounce: function(method, delay) {
  235. clearTimeout(module.timer);
  236. module.timer = setTimeout(method, delay);
  237. },
  238. keyboard: function(event) {
  239. var
  240. keyCode = event.which,
  241. escapeKey = 27
  242. ;
  243. if(keyCode == escapeKey) {
  244. if(settings.closable) {
  245. module.debug('Escape key pressed hiding modal');
  246. module.hide();
  247. }
  248. else {
  249. module.debug('Escape key pressed, but closable is set to false');
  250. }
  251. event.preventDefault();
  252. }
  253. },
  254. resize: function() {
  255. if( $dimmable.dimmer('is active') && ( module.is.animating() || module.is.active() ) ) {
  256. requestAnimationFrame(module.refresh);
  257. }
  258. }
  259. },
  260. toggle: function() {
  261. if( module.is.active() || module.is.animating() ) {
  262. module.hide();
  263. }
  264. else {
  265. module.show();
  266. }
  267. },
  268. show: function(callback) {
  269. callback = $.isFunction(callback)
  270. ? callback
  271. : function(){}
  272. ;
  273. module.refreshModals();
  274. module.set.dimmerSettings();
  275. module.showModal(callback);
  276. },
  277. hide: function(callback) {
  278. callback = $.isFunction(callback)
  279. ? callback
  280. : function(){}
  281. ;
  282. module.refreshModals();
  283. module.hideModal(callback);
  284. },
  285. showModal: function(callback) {
  286. callback = $.isFunction(callback)
  287. ? callback
  288. : function(){}
  289. ;
  290. if( module.is.animating() || !module.is.active() ) {
  291. module.showDimmer();
  292. module.cacheSizes();
  293. module.set.screenHeight();
  294. module.set.type();
  295. module.set.clickaway();
  296. if( !settings.allowMultiple && module.others.active() ) {
  297. module.hideOthers(module.showModal);
  298. }
  299. else {
  300. if(settings.allowMultiple && settings.detachable) {
  301. $module.detach().appendTo($dimmer);
  302. }
  303. settings.onShow.call(element);
  304. if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
  305. module.debug('Showing modal with css animations');
  306. $module
  307. .transition({
  308. debug : settings.debug,
  309. animation : settings.transition + ' in',
  310. queue : settings.queue,
  311. duration : settings.duration,
  312. useFailSafe : true,
  313. onComplete : function() {
  314. settings.onVisible.apply(element);
  315. if(settings.keyboardShortcuts) {
  316. module.add.keyboardShortcuts();
  317. }
  318. module.save.focus();
  319. module.set.active();
  320. if(settings.autofocus) {
  321. module.set.autofocus();
  322. }
  323. callback();
  324. }
  325. })
  326. ;
  327. }
  328. else {
  329. module.error(error.noTransition);
  330. }
  331. }
  332. }
  333. else {
  334. module.debug('Modal is already visible');
  335. }
  336. },
  337. hideModal: function(callback, keepDimmed) {
  338. callback = $.isFunction(callback)
  339. ? callback
  340. : function(){}
  341. ;
  342. module.debug('Hiding modal');
  343. if(settings.onHide.call(element, $(this)) === false) {
  344. module.verbose('Hide callback returned false cancelling hide');
  345. return;
  346. }
  347. if( module.is.animating() || module.is.active() ) {
  348. if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
  349. module.remove.active();
  350. $module
  351. .transition({
  352. debug : settings.debug,
  353. animation : settings.transition + ' out',
  354. queue : settings.queue,
  355. duration : settings.duration,
  356. useFailSafe : true,
  357. onStart : function() {
  358. if(!module.others.active() && !keepDimmed) {
  359. module.hideDimmer();
  360. }
  361. if(settings.keyboardShortcuts) {
  362. module.remove.keyboardShortcuts();
  363. }
  364. },
  365. onComplete : function() {
  366. settings.onHidden.call(element);
  367. module.restore.focus();
  368. callback();
  369. }
  370. })
  371. ;
  372. }
  373. else {
  374. module.error(error.noTransition);
  375. }
  376. }
  377. },
  378. showDimmer: function() {
  379. if($dimmable.dimmer('is animating') || !$dimmable.dimmer('is active') ) {
  380. module.debug('Showing dimmer');
  381. $dimmable.dimmer('show');
  382. }
  383. else {
  384. module.debug('Dimmer already visible');
  385. }
  386. },
  387. hideDimmer: function() {
  388. if( $dimmable.dimmer('is animating') || ($dimmable.dimmer('is active')) ) {
  389. $dimmable.dimmer('hide', function() {
  390. module.remove.clickaway();
  391. module.remove.screenHeight();
  392. });
  393. }
  394. else {
  395. module.debug('Dimmer is not visible cannot hide');
  396. return;
  397. }
  398. },
  399. hideAll: function(callback) {
  400. var
  401. $visibleModals = $allModals.filter('.' + className.active + ', .' + className.animating)
  402. ;
  403. callback = $.isFunction(callback)
  404. ? callback
  405. : function(){}
  406. ;
  407. if( $visibleModals.length > 0 ) {
  408. module.debug('Hiding all visible modals');
  409. module.hideDimmer();
  410. $visibleModals
  411. .modal('hide modal', callback)
  412. ;
  413. }
  414. },
  415. hideOthers: function(callback) {
  416. var
  417. $visibleModals = $otherModals.filter('.' + className.active + ', .' + className.animating)
  418. ;
  419. callback = $.isFunction(callback)
  420. ? callback
  421. : function(){}
  422. ;
  423. if( $visibleModals.length > 0 ) {
  424. module.debug('Hiding other modals', $otherModals);
  425. $visibleModals
  426. .modal('hide modal', callback, true)
  427. ;
  428. }
  429. },
  430. others: {
  431. active: function() {
  432. return ($otherModals.filter('.' + className.active).length > 0);
  433. },
  434. animating: function() {
  435. return ($otherModals.filter('.' + className.animating).length > 0);
  436. }
  437. },
  438. add: {
  439. keyboardShortcuts: function() {
  440. module.verbose('Adding keyboard shortcuts');
  441. $document
  442. .on('keyup' + eventNamespace, module.event.keyboard)
  443. ;
  444. }
  445. },
  446. save: {
  447. focus: function() {
  448. var
  449. $activeElement = $(document.activeElement),
  450. inCurrentModal = $activeElement.closest($module).length > 0
  451. ;
  452. if(!inCurrentModal) {
  453. $focusedElement = $(document.activeElement).blur();
  454. }
  455. }
  456. },
  457. restore: {
  458. focus: function() {
  459. if($focusedElement && $focusedElement.length > 0) {
  460. $focusedElement.focus();
  461. }
  462. }
  463. },
  464. remove: {
  465. active: function() {
  466. $module.removeClass(className.active);
  467. },
  468. clickaway: function() {
  469. $dimmer
  470. .off('click' + elementEventNamespace)
  471. ;
  472. },
  473. bodyStyle: function() {
  474. if($body.attr('style') === '') {
  475. module.verbose('Removing style attribute');
  476. $body.removeAttr('style');
  477. }
  478. },
  479. screenHeight: function() {
  480. module.debug('Removing page height');
  481. $body
  482. .css('height', '')
  483. ;
  484. },
  485. keyboardShortcuts: function() {
  486. module.verbose('Removing keyboard shortcuts');
  487. $document
  488. .off('keyup' + eventNamespace)
  489. ;
  490. },
  491. scrolling: function() {
  492. $dimmable.removeClass(className.scrolling);
  493. $module.removeClass(className.scrolling);
  494. }
  495. },
  496. cacheSizes: function() {
  497. $module.addClass(className.loading);
  498. var
  499. scrollHeight = $module.prop('scrollHeight'),
  500. modalHeight = $module.outerHeight()
  501. ;
  502. if(module.cache === undefined || modalHeight !== 0) {
  503. module.cache = {
  504. pageHeight : $(document).outerHeight(),
  505. height : modalHeight + settings.offset,
  506. scrollHeight : scrollHeight + settings.offset,
  507. contextHeight : (settings.context == 'body')
  508. ? $(window).height()
  509. : $dimmable.height(),
  510. };
  511. module.cache.topOffset = -(module.cache.height / 2);
  512. }
  513. $module.removeClass(className.loading);
  514. module.debug('Caching modal and container sizes', module.cache);
  515. },
  516. can: {
  517. fit: function() {
  518. var
  519. contextHeight = module.cache.contextHeight,
  520. verticalCenter = module.cache.contextHeight / 2,
  521. topOffset = module.cache.topOffset,
  522. scrollHeight = module.cache.scrollHeight,
  523. height = module.cache.height,
  524. paddingHeight = settings.padding,
  525. startPosition = (verticalCenter + topOffset)
  526. ;
  527. return (scrollHeight > height)
  528. ? (startPosition + scrollHeight + paddingHeight < contextHeight)
  529. : (height + (paddingHeight * 2) < contextHeight)
  530. ;
  531. }
  532. },
  533. is: {
  534. active: function() {
  535. return $module.hasClass(className.active);
  536. },
  537. animating: function() {
  538. return $module.transition('is supported')
  539. ? $module.transition('is animating')
  540. : $module.is(':visible')
  541. ;
  542. },
  543. scrolling: function() {
  544. return $dimmable.hasClass(className.scrolling);
  545. },
  546. modernBrowser: function() {
  547. // appName for IE11 reports 'Netscape' can no longer use
  548. return !(window.ActiveXObject || "ActiveXObject" in window);
  549. }
  550. },
  551. set: {
  552. autofocus: function() {
  553. var
  554. $inputs = $module.find('[tabindex], :input').filter(':visible'),
  555. $autofocus = $inputs.filter('[autofocus]'),
  556. $input = ($autofocus.length > 0)
  557. ? $autofocus.first()
  558. : $inputs.first()
  559. ;
  560. if($input.length > 0) {
  561. $input.focus();
  562. }
  563. },
  564. clickaway: function() {
  565. $dimmer
  566. .on('click' + elementEventNamespace, module.event.click)
  567. ;
  568. },
  569. dimmerSettings: function() {
  570. if($.fn.dimmer === undefined) {
  571. module.error(error.dimmer);
  572. return;
  573. }
  574. var
  575. defaultSettings = {
  576. debug : settings.debug,
  577. dimmerName : 'modals',
  578. closable : 'auto',
  579. variation : settings.centered
  580. ? false
  581. : 'top aligned'
  582. ,
  583. duration : {
  584. show : settings.duration,
  585. hide : settings.duration
  586. }
  587. },
  588. dimmerSettings = $.extend(true, defaultSettings, settings.dimmerSettings)
  589. ;
  590. if(settings.inverted) {
  591. dimmerSettings.variation = (dimmerSettings.variation !== undefined)
  592. ? dimmerSettings.variation + ' inverted'
  593. : 'inverted'
  594. ;
  595. $dimmer.addClass(className.inverted);
  596. }
  597. else {
  598. $dimmer.removeClass(className.inverted);
  599. }
  600. if(settings.blurring) {
  601. $dimmable.addClass(className.blurring);
  602. }
  603. else {
  604. $dimmable.removeClass(className.blurring);
  605. }
  606. $context.dimmer('setting', dimmerSettings);
  607. },
  608. screenHeight: function() {
  609. if( module.can.fit() ) {
  610. $body.css('height', '');
  611. }
  612. else {
  613. module.debug('Modal is taller than page content, resizing page height');
  614. $body
  615. .css('height', module.cache.height + (settings.padding * 2) )
  616. ;
  617. }
  618. },
  619. active: function() {
  620. $module.addClass(className.active);
  621. },
  622. scrolling: function() {
  623. $dimmable.addClass(className.scrolling);
  624. $module.addClass(className.scrolling);
  625. },
  626. type: function() {
  627. if(module.can.fit()) {
  628. module.verbose('Modal fits on screen');
  629. if(!module.others.active() && !module.others.animating()) {
  630. module.remove.scrolling();
  631. }
  632. }
  633. else {
  634. module.verbose('Modal cannot fit on screen setting to scrolling');
  635. module.set.scrolling();
  636. }
  637. },
  638. undetached: function() {
  639. $dimmable.addClass(className.undetached);
  640. }
  641. },
  642. setting: function(name, value) {
  643. module.debug('Changing setting', name, value);
  644. if( $.isPlainObject(name) ) {
  645. $.extend(true, settings, name);
  646. }
  647. else if(value !== undefined) {
  648. if($.isPlainObject(settings[name])) {
  649. $.extend(true, settings[name], value);
  650. }
  651. else {
  652. settings[name] = value;
  653. }
  654. }
  655. else {
  656. return settings[name];
  657. }
  658. },
  659. internal: function(name, value) {
  660. if( $.isPlainObject(name) ) {
  661. $.extend(true, module, name);
  662. }
  663. else if(value !== undefined) {
  664. module[name] = value;
  665. }
  666. else {
  667. return module[name];
  668. }
  669. },
  670. debug: function() {
  671. if(!settings.silent && settings.debug) {
  672. if(settings.performance) {
  673. module.performance.log(arguments);
  674. }
  675. else {
  676. module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
  677. module.debug.apply(console, arguments);
  678. }
  679. }
  680. },
  681. verbose: function() {
  682. if(!settings.silent && settings.verbose && settings.debug) {
  683. if(settings.performance) {
  684. module.performance.log(arguments);
  685. }
  686. else {
  687. module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
  688. module.verbose.apply(console, arguments);
  689. }
  690. }
  691. },
  692. error: function() {
  693. if(!settings.silent) {
  694. module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
  695. module.error.apply(console, arguments);
  696. }
  697. },
  698. performance: {
  699. log: function(message) {
  700. var
  701. currentTime,
  702. executionTime,
  703. previousTime
  704. ;
  705. if(settings.performance) {
  706. currentTime = new Date().getTime();
  707. previousTime = time || currentTime;
  708. executionTime = currentTime - previousTime;
  709. time = currentTime;
  710. performance.push({
  711. 'Name' : message[0],
  712. 'Arguments' : [].slice.call(message, 1) || '',
  713. 'Element' : element,
  714. 'Execution Time' : executionTime
  715. });
  716. }
  717. clearTimeout(module.performance.timer);
  718. module.performance.timer = setTimeout(module.performance.display, 500);
  719. },
  720. display: function() {
  721. var
  722. title = settings.name + ':',
  723. totalTime = 0
  724. ;
  725. time = false;
  726. clearTimeout(module.performance.timer);
  727. $.each(performance, function(index, data) {
  728. totalTime += data['Execution Time'];
  729. });
  730. title += ' ' + totalTime + 'ms';
  731. if(moduleSelector) {
  732. title += ' \'' + moduleSelector + '\'';
  733. }
  734. if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
  735. console.groupCollapsed(title);
  736. if(console.table) {
  737. console.table(performance);
  738. }
  739. else {
  740. $.each(performance, function(index, data) {
  741. console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
  742. });
  743. }
  744. console.groupEnd();
  745. }
  746. performance = [];
  747. }
  748. },
  749. invoke: function(query, passedArguments, context) {
  750. var
  751. object = instance,
  752. maxDepth,
  753. found,
  754. response
  755. ;
  756. passedArguments = passedArguments || queryArguments;
  757. context = element || context;
  758. if(typeof query == 'string' && object !== undefined) {
  759. query = query.split(/[\. ]/);
  760. maxDepth = query.length - 1;
  761. $.each(query, function(depth, value) {
  762. var camelCaseValue = (depth != maxDepth)
  763. ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
  764. : query
  765. ;
  766. if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
  767. object = object[camelCaseValue];
  768. }
  769. else if( object[camelCaseValue] !== undefined ) {
  770. found = object[camelCaseValue];
  771. return false;
  772. }
  773. else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
  774. object = object[value];
  775. }
  776. else if( object[value] !== undefined ) {
  777. found = object[value];
  778. return false;
  779. }
  780. else {
  781. return false;
  782. }
  783. });
  784. }
  785. if ( $.isFunction( found ) ) {
  786. response = found.apply(context, passedArguments);
  787. }
  788. else if(found !== undefined) {
  789. response = found;
  790. }
  791. if($.isArray(returnedValue)) {
  792. returnedValue.push(response);
  793. }
  794. else if(returnedValue !== undefined) {
  795. returnedValue = [returnedValue, response];
  796. }
  797. else if(response !== undefined) {
  798. returnedValue = response;
  799. }
  800. return found;
  801. }
  802. };
  803. if(methodInvoked) {
  804. if(instance === undefined) {
  805. module.initialize();
  806. }
  807. module.invoke(query);
  808. }
  809. else {
  810. if(instance !== undefined) {
  811. instance.invoke('destroy');
  812. }
  813. module.initialize();
  814. }
  815. })
  816. ;
  817. return (returnedValue !== undefined)
  818. ? returnedValue
  819. : this
  820. ;
  821. };
  822. $.fn.modal.settings = {
  823. name : 'Modal',
  824. namespace : 'modal',
  825. silent : false,
  826. debug : false,
  827. verbose : false,
  828. performance : true,
  829. observeChanges : false,
  830. allowMultiple : false,
  831. detachable : true,
  832. closable : true,
  833. autofocus : true,
  834. inverted : false,
  835. blurring : false,
  836. centered : true,
  837. dimmerSettings : {
  838. closable : false,
  839. useCSS : true
  840. },
  841. // whether to use keyboard shortcuts
  842. keyboardShortcuts: true,
  843. context : 'body',
  844. queue : false,
  845. duration : 500,
  846. offset : 0,
  847. transition : 'scale',
  848. // padding with edge of page
  849. padding : 50,
  850. // called before show animation
  851. onShow : function(){},
  852. // called after show animation
  853. onVisible : function(){},
  854. // called before hide animation
  855. onHide : function(){ return true; },
  856. // called after hide animation
  857. onHidden : function(){},
  858. // called after approve selector match
  859. onApprove : function(){ return true; },
  860. // called after deny selector match
  861. onDeny : function(){ return true; },
  862. selector : {
  863. close : '> .close',
  864. approve : '.actions .positive, .actions .approve, .actions .ok',
  865. deny : '.actions .negative, .actions .deny, .actions .cancel',
  866. modal : '.ui.modal'
  867. },
  868. error : {
  869. dimmer : 'UI Dimmer, a required component is not included in this page',
  870. method : 'The method you called is not defined.',
  871. notFound : 'The element you specified could not be found'
  872. },
  873. className : {
  874. active : 'active',
  875. animating : 'animating',
  876. blurring : 'blurring',
  877. inverted : 'inverted',
  878. loading : 'loading',
  879. scrolling : 'scrolling',
  880. undetached : 'undetached'
  881. }
  882. };
  883. })( jQuery, window, document );