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.

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