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.

1036 lines
32 KiB

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
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
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
10 years ago
10 years ago
10 years ago
10 years ago
  1. /*
  2. * # Semantic - Popup
  3. * http://github.com/jlukic/semantic-ui/
  4. *
  5. *
  6. * Copyright 2014 Contributor
  7. * Released under the MIT license
  8. * http://opensource.org/licenses/MIT
  9. *
  10. */
  11. ;(function ($, window, document, undefined) {
  12. "use strict";
  13. $.fn.popup = function(parameters) {
  14. var
  15. $allModules = $(this),
  16. $document = $(document),
  17. moduleSelector = $allModules.selector || '',
  18. hasTouch = ('ontouchstart' in document.documentElement),
  19. time = new Date().getTime(),
  20. performance = [],
  21. query = arguments[0],
  22. methodInvoked = (typeof query == 'string'),
  23. queryArguments = [].slice.call(arguments, 1),
  24. returnedValue
  25. ;
  26. $allModules
  27. .each(function() {
  28. var
  29. settings = ( $.isPlainObject(parameters) )
  30. ? $.extend(true, {}, $.fn.popup.settings, parameters)
  31. : $.extend({}, $.fn.popup.settings),
  32. selector = settings.selector,
  33. className = settings.className,
  34. error = settings.error,
  35. metadata = settings.metadata,
  36. namespace = settings.namespace,
  37. eventNamespace = '.' + settings.namespace,
  38. moduleNamespace = 'module-' + namespace,
  39. $module = $(this),
  40. $context = $(settings.context),
  41. $target = (settings.target)
  42. ? $(settings.target)
  43. : $module,
  44. $window = $(window),
  45. $body = $('body'),
  46. $popup,
  47. $offsetParent,
  48. searchDepth = 0,
  49. element = this,
  50. instance = $module.data(moduleNamespace),
  51. module
  52. ;
  53. module = {
  54. // binds events
  55. initialize: function() {
  56. module.debug('Initializing module', $module);
  57. module.refresh();
  58. if(settings.on == 'click') {
  59. $module
  60. .on('click' + eventNamespace, module.toggle)
  61. ;
  62. }
  63. else if( module.get.startEvent() ) {
  64. $module
  65. .on(module.get.startEvent() + eventNamespace, module.event.start)
  66. .on(module.get.endEvent() + eventNamespace, module.event.end)
  67. ;
  68. }
  69. if(settings.target) {
  70. module.debug('Target set to element', $target);
  71. }
  72. $window
  73. .on('resize' + eventNamespace, module.event.resize)
  74. ;
  75. if( !module.exists() ) {
  76. module.create();
  77. }
  78. else if(settings.hoverable) {
  79. module.bind.popup();
  80. }
  81. module.instantiate();
  82. },
  83. instantiate: function() {
  84. module.verbose('Storing instance of module', module);
  85. instance = module;
  86. $module
  87. .data(moduleNamespace, instance)
  88. ;
  89. },
  90. refresh: function() {
  91. $popup = (settings.popup)
  92. ? $(settings.popup)
  93. : (settings.inline)
  94. ? $target.next(settings.selector.popup)
  95. : false
  96. ;
  97. $offsetParent = (settings.popup)
  98. ? $popup.offsetParent()
  99. : (settings.inline)
  100. ? $target.offsetParent()
  101. : $body
  102. ;
  103. },
  104. reposition: function() {
  105. module.refresh();
  106. module.set.position();
  107. },
  108. destroy: function() {
  109. module.debug('Destroying previous module');
  110. if($popup && !settings.preserve) {
  111. module.removePopup();
  112. }
  113. $module
  114. .off(eventNamespace)
  115. .removeData(moduleNamespace)
  116. ;
  117. },
  118. event: {
  119. start: function(event) {
  120. var
  121. delay = ($.isPlainObject(settings.delay))
  122. ? settings.delay.show
  123. : settings.delay
  124. ;
  125. clearTimeout(module.hideTimer);
  126. module.showTimer = setTimeout(function() {
  127. if( module.is.hidden() && !( module.is.active() && module.is.dropdown()) ) {
  128. module.show();
  129. }
  130. }, delay);
  131. },
  132. end: function() {
  133. var
  134. delay = ($.isPlainObject(settings.delay))
  135. ? settings.delay.hide
  136. : settings.delay
  137. ;
  138. clearTimeout(module.showTimer);
  139. module.hideTimer = setTimeout(function() {
  140. if( module.is.visible() ) {
  141. module.hide();
  142. }
  143. }, delay);
  144. },
  145. resize: function() {
  146. if( module.is.visible() ) {
  147. module.set.position();
  148. }
  149. }
  150. },
  151. // generates popup html from metadata
  152. create: function() {
  153. var
  154. html = $module.data(metadata.html) || settings.html,
  155. variation = $module.data(metadata.variation) || settings.variation,
  156. title = $module.data(metadata.title) || settings.title,
  157. content = $module.data(metadata.content) || $module.attr('title') || settings.content
  158. ;
  159. if(html || content || title) {
  160. module.debug('Creating pop-up html');
  161. if(!html) {
  162. html = settings.templates.popup({
  163. title : title,
  164. content : content
  165. });
  166. }
  167. $popup = $('<div/>')
  168. .addClass(className.popup)
  169. .addClass(variation)
  170. .html(html)
  171. ;
  172. if(variation) {
  173. $popup
  174. .addClass(variation)
  175. ;
  176. }
  177. if(settings.inline) {
  178. module.verbose('Inserting popup element inline', $popup);
  179. $popup
  180. .insertAfter($module)
  181. ;
  182. }
  183. else {
  184. module.verbose('Appending popup element to body', $popup);
  185. $popup
  186. .appendTo( $context )
  187. ;
  188. }
  189. if(settings.hoverable) {
  190. module.bind.popup();
  191. }
  192. $.proxy(settings.onCreate, $popup)(element);
  193. }
  194. else if($target.next(settings.selector.popup).size() !== 0) {
  195. module.verbose('Pre-existing popup found, reverting to inline');
  196. settings.inline = true;
  197. module.refresh();
  198. if(settings.hoverable) {
  199. module.bind.popup();
  200. }
  201. }
  202. else {
  203. module.debug('No content specified skipping display', element);
  204. }
  205. },
  206. // determines popup state
  207. toggle: function() {
  208. module.debug('Toggling pop-up');
  209. if( module.is.hidden() ) {
  210. module.debug('Popup is hidden, showing pop-up');
  211. module.unbind.close();
  212. module.hideAll();
  213. module.show();
  214. }
  215. else {
  216. module.debug('Popup is visible, hiding pop-up');
  217. module.hide();
  218. }
  219. },
  220. show: function(callback) {
  221. callback = $.isFunction(callback) ? callback : function(){};
  222. module.debug('Showing pop-up', settings.transition);
  223. if(!settings.preserve && !settings.popup) {
  224. module.refresh();
  225. }
  226. if( !module.exists() ) {
  227. module.create();
  228. }
  229. if( $popup && module.set.position() ) {
  230. module.save.conditions();
  231. module.animate.show(callback);
  232. }
  233. },
  234. hide: function(callback) {
  235. callback = $.isFunction(callback) ? callback : function(){};
  236. module.remove.visible();
  237. module.unbind.close();
  238. if( module.is.visible() ) {
  239. module.restore.conditions();
  240. module.animate.hide(callback);
  241. }
  242. },
  243. hideAll: function() {
  244. $(selector.popup)
  245. .filter(':visible')
  246. .popup('hide')
  247. ;
  248. },
  249. hideGracefully: function(event) {
  250. // don't close on clicks inside popup
  251. if(event && $(event.target).closest(selector.popup).size() === 0) {
  252. module.debug('Click occurred outside popup hiding popup');
  253. module.hide();
  254. }
  255. else {
  256. module.debug('Click was inside popup, keeping popup open');
  257. }
  258. },
  259. exists: function() {
  260. if(!$popup) {
  261. return false;
  262. }
  263. if(settings.inline || settings.popup) {
  264. return ( $popup.size() !== 0 );
  265. }
  266. else {
  267. return ( $popup.closest($context).size() );
  268. }
  269. },
  270. removePopup: function() {
  271. module.debug('Removing popup');
  272. $.proxy(settings.onRemove, $popup)(element);
  273. $popup
  274. .removePopup()
  275. ;
  276. },
  277. save: {
  278. conditions: function() {
  279. module.cache = {
  280. title: $module.attr('title')
  281. };
  282. if (module.cache.title) {
  283. $module.removeAttr('title');
  284. }
  285. module.verbose('Saving original attributes', module.cache.title);
  286. }
  287. },
  288. restore: {
  289. conditions: function() {
  290. element.blur();
  291. if(module.cache && module.cache.title) {
  292. $module.attr('title', module.cache.title);
  293. module.verbose('Restoring original attributes', module.cache.title);
  294. }
  295. return true;
  296. }
  297. },
  298. animate: {
  299. show: function(callback) {
  300. callback = $.isFunction(callback) ? callback : function(){};
  301. if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
  302. module.set.visible();
  303. $popup
  304. .transition({
  305. animation : settings.transition + ' in',
  306. queue : false,
  307. debug : settings.debug,
  308. verbose : settings.verbose,
  309. duration : settings.duration,
  310. onComplete : function() {
  311. module.bind.close();
  312. $.proxy(callback, $popup)(element);
  313. $.proxy(settings.onVisible, $popup)(element);
  314. }
  315. })
  316. ;
  317. }
  318. else {
  319. module.set.visible();
  320. $popup
  321. .stop()
  322. .fadeIn(settings.duration, settings.easing, function() {
  323. module.bind.close();
  324. $.proxy(callback, element)();
  325. })
  326. ;
  327. }
  328. $.proxy(settings.onShow, $popup)(element);
  329. },
  330. hide: function(callback) {
  331. callback = $.isFunction(callback) ? callback : function(){};
  332. module.debug('Hiding pop-up');
  333. if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
  334. $popup
  335. .transition({
  336. animation : settings.transition + ' out',
  337. queue : false,
  338. duration : settings.duration,
  339. debug : settings.debug,
  340. verbose : settings.verbose,
  341. onComplete : function() {
  342. module.reset();
  343. $.proxy(callback, $popup)(element);
  344. $.proxy(settings.onHidden, $popup)(element);
  345. }
  346. })
  347. ;
  348. }
  349. else {
  350. $popup
  351. .stop()
  352. .fadeOut(settings.duration, settings.easing, function() {
  353. module.reset();
  354. callback();
  355. })
  356. ;
  357. }
  358. $.proxy(settings.onHide, $popup)(element);
  359. }
  360. },
  361. get: {
  362. startEvent: function() {
  363. if(settings.on == 'hover') {
  364. return 'mouseenter';
  365. }
  366. else if(settings.on == 'focus') {
  367. return 'focus';
  368. }
  369. return false;
  370. },
  371. endEvent: function() {
  372. if(settings.on == 'hover') {
  373. return 'mouseleave';
  374. }
  375. else if(settings.on == 'focus') {
  376. return 'blur';
  377. }
  378. return false;
  379. },
  380. offstagePosition: function(position) {
  381. var
  382. position = position || false,
  383. boundary = {
  384. top : $(window).scrollTop(),
  385. bottom : $(window).scrollTop() + $(window).height(),
  386. left : 0,
  387. right : $(window).width()
  388. },
  389. popup = {
  390. width : $popup.width(),
  391. height : $popup.height(),
  392. offset : $popup.offset()
  393. },
  394. offstage = {},
  395. offstagePositions = []
  396. ;
  397. if(popup.offset && position) {
  398. module.verbose('Checking if outside viewable area', popup.offset);
  399. offstage = {
  400. top : (popup.offset.top < boundary.top),
  401. bottom : (popup.offset.top + popup.height > boundary.bottom),
  402. right : (popup.offset.left + popup.width > boundary.right),
  403. left : (popup.offset.left < boundary.left)
  404. };
  405. }
  406. // return only boundaries that have been surpassed
  407. $.each(offstage, function(direction, isOffstage) {
  408. if(isOffstage) {
  409. offstagePositions.push(direction);
  410. }
  411. });
  412. return (offstagePositions.length > 0)
  413. ? offstagePositions.join(' ')
  414. : false
  415. ;
  416. },
  417. nextPosition: function(position) {
  418. switch(position) {
  419. case 'top left':
  420. position = 'bottom left';
  421. break;
  422. case 'bottom left':
  423. position = 'top right';
  424. break;
  425. case 'top right':
  426. position = 'bottom right';
  427. break;
  428. case 'bottom right':
  429. position = 'top center';
  430. break;
  431. case 'top center':
  432. position = 'bottom center';
  433. break;
  434. case 'bottom center':
  435. position = 'right center';
  436. break;
  437. case 'right center':
  438. position = 'left center';
  439. break;
  440. case 'left center':
  441. position = 'top center';
  442. break;
  443. }
  444. return position;
  445. }
  446. },
  447. set: {
  448. position: function(position, arrowOffset) {
  449. var
  450. windowWidth = $(window).width(),
  451. windowHeight = $(window).height(),
  452. targetWidth = $target.outerWidth(),
  453. targetHeight = $target.outerHeight(),
  454. popupWidth = $popup.outerWidth(),
  455. popupHeight = $popup.outerHeight(),
  456. parentWidth = ( $offsetParent.is('html') )
  457. ? $offsetParent.find('body').width()
  458. : $offsetParent.outerWidth(),
  459. parentHeight = ( $offsetParent.is('html') )
  460. ? $offsetParent.find('body').height()
  461. : $offsetParent.outerHeight(),
  462. distanceAway = settings.distanceAway,
  463. targetElement = $target[0],
  464. marginTop = (settings.inline)
  465. ? parseInt( window.getComputedStyle(targetElement).getPropertyValue('margin-top'), 10)
  466. : 0,
  467. marginLeft = (settings.inline)
  468. ? parseInt( window.getComputedStyle(targetElement).getPropertyValue('margin-left'), 10)
  469. : 0,
  470. target = (settings.inline || settings.popup)
  471. ? $target.position()
  472. : $target.offset(),
  473. positioning,
  474. offstagePosition
  475. ;
  476. position = position || $module.data(metadata.position) || settings.position;
  477. arrowOffset = arrowOffset || $module.data(metadata.offset) || settings.offset;
  478. if(settings.inline) {
  479. module.debug('Adding targets margin to calculation');
  480. if(position == 'left center' || position == 'right center') {
  481. arrowOffset += marginTop;
  482. distanceAway += -marginLeft;
  483. }
  484. else if (position == 'top left' || position == 'top center' || position == 'top right') {
  485. arrowOffset += marginLeft;
  486. distanceAway -= marginTop;
  487. }
  488. else {
  489. arrowOffset += marginLeft;
  490. distanceAway += marginTop;
  491. }
  492. }
  493. module.debug('Calculating popup positioning', position);
  494. switch(position) {
  495. case 'top left':
  496. positioning = {
  497. top : 'auto',
  498. bottom : parentHeight - target.top + distanceAway,
  499. left : target.left + arrowOffset,
  500. right : 'auto'
  501. };
  502. break;
  503. case 'top center':
  504. positioning = {
  505. bottom : parentHeight - target.top + distanceAway,
  506. left : target.left + (targetWidth / 2) - (popupWidth / 2) + arrowOffset,
  507. top : 'auto',
  508. right : 'auto'
  509. };
  510. break;
  511. case 'top right':
  512. positioning = {
  513. bottom : parentHeight - target.top + distanceAway,
  514. right : parentWidth - target.left - targetWidth - arrowOffset,
  515. top : 'auto',
  516. left : 'auto'
  517. };
  518. break;
  519. case 'left center':
  520. positioning = {
  521. top : target.top + (targetHeight / 2) - (popupHeight / 2) + arrowOffset,
  522. right : parentWidth - target.left + distanceAway,
  523. left : 'auto',
  524. bottom : 'auto'
  525. };
  526. break;
  527. case 'right center':
  528. positioning = {
  529. top : target.top + (targetHeight / 2) - (popupHeight / 2) + arrowOffset,
  530. left : target.left + targetWidth + distanceAway,
  531. bottom : 'auto',
  532. right : 'auto'
  533. };
  534. break;
  535. case 'bottom left':
  536. positioning = {
  537. top : target.top + targetHeight + distanceAway,
  538. left : target.left + arrowOffset,
  539. bottom : 'auto',
  540. right : 'auto'
  541. };
  542. break;
  543. case 'bottom center':
  544. positioning = {
  545. top : target.top + targetHeight + distanceAway,
  546. left : target.left + (targetWidth / 2) - (popupWidth / 2) + arrowOffset,
  547. bottom : 'auto',
  548. right : 'auto'
  549. };
  550. break;
  551. case 'bottom right':
  552. positioning = {
  553. top : target.top + targetHeight + distanceAway,
  554. right : parentWidth - target.left - targetWidth - arrowOffset,
  555. left : 'auto',
  556. bottom : 'auto'
  557. };
  558. break;
  559. }
  560. if(positioning === undefined) {
  561. module.error(error.invalidPosition);
  562. }
  563. // tentatively place on stage
  564. $popup
  565. .css(positioning)
  566. .removeClass(className.position)
  567. .addClass(position)
  568. .addClass(className.loading)
  569. ;
  570. // check if is offstage
  571. offstagePosition = module.get.offstagePosition(position);
  572. // recursively find new positioning
  573. if(offstagePosition) {
  574. module.debug('Element is outside boundaries', offstagePosition);
  575. if(searchDepth < settings.maxSearchDepth) {
  576. position = module.get.nextPosition(position);
  577. searchDepth++;
  578. module.debug('Trying new position', position);
  579. return ($popup)
  580. ? module.set.position(position)
  581. : false
  582. ;
  583. }
  584. else {
  585. module.error(error.recursion);
  586. searchDepth = 0;
  587. module.reset();
  588. $popup.removeClass(className.loading);
  589. return false;
  590. }
  591. }
  592. else {
  593. module.debug('Position is on stage', position);
  594. searchDepth = 0;
  595. $popup.removeClass(className.loading);
  596. return true;
  597. }
  598. },
  599. visible: function() {
  600. $module.addClass(className.visible);
  601. }
  602. },
  603. remove: {
  604. visible: function() {
  605. $module.removeClass(className.visible);
  606. }
  607. },
  608. bind: {
  609. popup: function() {
  610. module.verbose('Allowing hover events on popup to prevent closing');
  611. $popup
  612. .on('mouseenter' + eventNamespace, module.event.start)
  613. .on('mouseleave' + eventNamespace, module.event.end)
  614. ;
  615. },
  616. close:function() {
  617. if(settings.hideOnScroll) {
  618. $document
  619. .on('touchmove' + eventNamespace, module.hideGracefully)
  620. .on('scroll' + eventNamespace, module.hideGracefully)
  621. ;
  622. $context
  623. .on('touchmove' + eventNamespace, module.hideGracefully)
  624. .on('scroll' + eventNamespace, module.hideGracefully)
  625. ;
  626. }
  627. if(settings.on == 'click' && settings.closable) {
  628. module.verbose('Binding popup close event to document');
  629. $document
  630. .on('click' + eventNamespace, function(event) {
  631. module.verbose('Pop-up clickaway intent detected');
  632. $.proxy(module.hideGracefully, element)(event);
  633. })
  634. ;
  635. }
  636. }
  637. },
  638. unbind: {
  639. close: function() {
  640. if(settings.hideOnScroll) {
  641. $document
  642. .off('scroll' + eventNamespace, module.hide)
  643. ;
  644. $context
  645. .off('scroll' + eventNamespace, module.hide)
  646. ;
  647. }
  648. if(settings.on == 'click' && settings.closable) {
  649. module.verbose('Removing close event from document');
  650. $document
  651. .off('click' + eventNamespace)
  652. ;
  653. }
  654. }
  655. },
  656. is: {
  657. active: function() {
  658. return $module.hasClass(className.active);
  659. },
  660. animating: function() {
  661. return ( $popup && $popup.is(':animated') || $popup.hasClass(className.animating) );
  662. },
  663. visible: function() {
  664. return $popup && $popup.is(':visible');
  665. },
  666. dropdown: function() {
  667. return $module.hasClass(className.dropdown);
  668. },
  669. hidden: function() {
  670. return !module.is.visible();
  671. }
  672. },
  673. reset: function() {
  674. module.remove.visible();
  675. if(settings.preserve || settings.popup) {
  676. if($.fn.transition !== undefined) {
  677. $popup
  678. .transition('remove transition')
  679. ;
  680. }
  681. }
  682. else {
  683. module.removePopup();
  684. }
  685. },
  686. setting: function(name, value) {
  687. if( $.isPlainObject(name) ) {
  688. $.extend(true, settings, name);
  689. }
  690. else if(value !== undefined) {
  691. settings[name] = value;
  692. }
  693. else {
  694. return settings[name];
  695. }
  696. },
  697. internal: function(name, value) {
  698. if( $.isPlainObject(name) ) {
  699. $.extend(true, module, name);
  700. }
  701. else if(value !== undefined) {
  702. module[name] = value;
  703. }
  704. else {
  705. return module[name];
  706. }
  707. },
  708. debug: function() {
  709. if(settings.debug) {
  710. if(settings.performance) {
  711. module.performance.log(arguments);
  712. }
  713. else {
  714. module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
  715. module.debug.apply(console, arguments);
  716. }
  717. }
  718. },
  719. verbose: function() {
  720. if(settings.verbose && settings.debug) {
  721. if(settings.performance) {
  722. module.performance.log(arguments);
  723. }
  724. else {
  725. module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
  726. module.verbose.apply(console, arguments);
  727. }
  728. }
  729. },
  730. error: function() {
  731. module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
  732. module.error.apply(console, arguments);
  733. },
  734. performance: {
  735. log: function(message) {
  736. var
  737. currentTime,
  738. executionTime,
  739. previousTime
  740. ;
  741. if(settings.performance) {
  742. currentTime = new Date().getTime();
  743. previousTime = time || currentTime;
  744. executionTime = currentTime - previousTime;
  745. time = currentTime;
  746. performance.push({
  747. 'Name' : message[0],
  748. 'Arguments' : [].slice.call(message, 1) || '',
  749. 'Element' : element,
  750. 'Execution Time' : executionTime
  751. });
  752. }
  753. clearTimeout(module.performance.timer);
  754. module.performance.timer = setTimeout(module.performance.display, 100);
  755. },
  756. display: function() {
  757. var
  758. title = settings.name + ':',
  759. totalTime = 0
  760. ;
  761. time = false;
  762. clearTimeout(module.performance.timer);
  763. $.each(performance, function(index, data) {
  764. totalTime += data['Execution Time'];
  765. });
  766. title += ' ' + totalTime + 'ms';
  767. if(moduleSelector) {
  768. title += ' \'' + moduleSelector + '\'';
  769. }
  770. if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
  771. console.groupCollapsed(title);
  772. if(console.table) {
  773. console.table(performance);
  774. }
  775. else {
  776. $.each(performance, function(index, data) {
  777. console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
  778. });
  779. }
  780. console.groupEnd();
  781. }
  782. performance = [];
  783. }
  784. },
  785. invoke: function(query, passedArguments, context) {
  786. var
  787. object = instance,
  788. maxDepth,
  789. found,
  790. response
  791. ;
  792. passedArguments = passedArguments || queryArguments;
  793. context = element || context;
  794. if(typeof query == 'string' && object !== undefined) {
  795. query = query.split(/[\. ]/);
  796. maxDepth = query.length - 1;
  797. $.each(query, function(depth, value) {
  798. var camelCaseValue = (depth != maxDepth)
  799. ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
  800. : query
  801. ;
  802. if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
  803. object = object[camelCaseValue];
  804. }
  805. else if( object[camelCaseValue] !== undefined ) {
  806. found = object[camelCaseValue];
  807. return false;
  808. }
  809. else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
  810. object = object[value];
  811. }
  812. else if( object[value] !== undefined ) {
  813. found = object[value];
  814. return false;
  815. }
  816. else {
  817. return false;
  818. }
  819. });
  820. }
  821. if ( $.isFunction( found ) ) {
  822. response = found.apply(context, passedArguments);
  823. }
  824. else if(found !== undefined) {
  825. response = found;
  826. }
  827. if($.isArray(returnedValue)) {
  828. returnedValue.push(response);
  829. }
  830. else if(returnedValue !== undefined) {
  831. returnedValue = [returnedValue, response];
  832. }
  833. else if(response !== undefined) {
  834. returnedValue = response;
  835. }
  836. return found;
  837. }
  838. };
  839. if(methodInvoked) {
  840. if(instance === undefined) {
  841. module.initialize();
  842. }
  843. module.invoke(query);
  844. }
  845. else {
  846. if(instance !== undefined) {
  847. module.destroy();
  848. }
  849. module.initialize();
  850. }
  851. })
  852. ;
  853. return (returnedValue !== undefined)
  854. ? returnedValue
  855. : this
  856. ;
  857. };
  858. $.fn.popup.settings = {
  859. name : 'Popup',
  860. debug : false,
  861. verbose : true,
  862. performance : true,
  863. namespace : 'popup',
  864. onCreate : function(){},
  865. onRemove : function(){},
  866. onShow : function(){},
  867. onVisible : function(){},
  868. onHide : function(){},
  869. onHidden : function(){},
  870. variation : '',
  871. content : false,
  872. html : false,
  873. title : false,
  874. on : 'hover',
  875. closable : true,
  876. hideOnScroll : true,
  877. context : 'body',
  878. position : 'top left',
  879. delay : {
  880. show : 30,
  881. hide : 0
  882. },
  883. target : false,
  884. popup : false,
  885. inline : false,
  886. preserve : true,
  887. hoverable : false,
  888. duration : 200,
  889. easing : 'easeOutQuint',
  890. transition : 'scale',
  891. distanceAway : 0,
  892. offset : 0,
  893. maxSearchDepth : 10,
  894. error: {
  895. invalidPosition : 'The position you specified is not a valid position',
  896. method : 'The method you called is not defined.',
  897. recursion : 'Popup attempted to reposition element to fit, but could not find an adequate position.'
  898. },
  899. metadata: {
  900. content : 'content',
  901. html : 'html',
  902. offset : 'offset',
  903. position : 'position',
  904. title : 'title',
  905. variation : 'variation'
  906. },
  907. className : {
  908. active : 'active',
  909. animating : 'animating',
  910. dropdown : 'dropdown',
  911. loading : 'loading',
  912. popup : 'ui popup',
  913. position : 'top left center bottom right',
  914. visible : 'visible'
  915. },
  916. selector : {
  917. popup : '.ui.popup'
  918. },
  919. templates: {
  920. escape: function(string) {
  921. var
  922. badChars = /[&<>"'`]/g,
  923. shouldEscape = /[&<>"'`]/,
  924. escape = {
  925. "&": "&amp;",
  926. "<": "&lt;",
  927. ">": "&gt;",
  928. '"': "&quot;",
  929. "'": "&#x27;",
  930. "`": "&#x60;"
  931. },
  932. escapedChar = function(chr) {
  933. return escape[chr];
  934. }
  935. ;
  936. if(shouldEscape.test(string)) {
  937. return string.replace(badChars, escapedChar);
  938. }
  939. return string;
  940. },
  941. popup: function(text) {
  942. var
  943. html = '',
  944. escape = $.fn.popup.settings.templates.escape
  945. ;
  946. if(typeof text !== undefined) {
  947. if(typeof text.title !== undefined && text.title) {
  948. text.title = escape(text.title);
  949. html += '<div class="header">' + text.title + '</div>';
  950. }
  951. if(typeof text.content !== undefined && text.content) {
  952. text.content = escape(text.content);
  953. html += '<div class="content">' + text.content + '</div>';
  954. }
  955. }
  956. return html;
  957. }
  958. }
  959. };
  960. // Adds easing
  961. $.extend( $.easing, {
  962. easeOutQuad: function (x, t, b, c, d) {
  963. return -c *(t/=d)*(t-2) + b;
  964. }
  965. });
  966. })( jQuery, window , document );