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.

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