You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

967 lines
29 KiB

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