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.

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