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.

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