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.

982 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
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. /*
  2. * # Semantic - Popup
  3. * http://github.com/jlukic/semantic-ui/
  4. *
  5. *
  6. * Copyright 2014 Contributor
  7. * Released under the MIT license
  8. * http://opensource.org/licenses/MIT
  9. *
  10. */
  11. ;(function ($, window, document, undefined) {
  12. "use strict";
  13. $.fn.popup = function(parameters) {
  14. var
  15. $allModules = $(this),
  16. $document = $(document),
  17. moduleSelector = $allModules.selector || '',
  18. hasTouch = ('ontouchstart' in document.documentElement),
  19. time = new Date().getTime(),
  20. performance = [],
  21. query = arguments[0],
  22. methodInvoked = (typeof query == 'string'),
  23. queryArguments = [].slice.call(arguments, 1),
  24. returnedValue
  25. ;
  26. $allModules
  27. .each(function() {
  28. var
  29. settings = ( $.isPlainObject(parameters) )
  30. ? $.extend(true, {}, $.fn.popup.settings, parameters)
  31. : $.extend({}, $.fn.popup.settings),
  32. selector = settings.selector,
  33. className = settings.className,
  34. error = settings.error,
  35. metadata = settings.metadata,
  36. namespace = settings.namespace,
  37. eventNamespace = '.' + settings.namespace,
  38. moduleNamespace = 'module-' + namespace,
  39. $module = $(this),
  40. $context = $(settings.context),
  41. $target = (settings.target)
  42. ? $(settings.target)
  43. : $module,
  44. $window = $(window),
  45. $body = $('body'),
  46. $popup,
  47. $offsetParent,
  48. searchDepth = 0,
  49. element = this,
  50. instance = $module.data(moduleNamespace),
  51. module
  52. ;
  53. module = {
  54. // binds events
  55. initialize: function() {
  56. module.debug('Initializing module', $module);
  57. module.refresh();
  58. if(settings.on == 'click') {
  59. $module
  60. .on('click' + eventNamespace, module.toggle)
  61. ;
  62. }
  63. else if( module.get.startEvent() ) {
  64. $module
  65. .on(module.get.startEvent() + eventNamespace, module.event.start)
  66. .on(module.get.endEvent() + eventNamespace, module.event.end)
  67. ;
  68. }
  69. if(settings.target) {
  70. module.debug('Target set to element', $target);
  71. }
  72. $window
  73. .on('resize' + eventNamespace, module.event.resize)
  74. ;
  75. if( !module.exists() ) {
  76. module.create();
  77. }
  78. else if(settings.hoverable) {
  79. module.bind.popup();
  80. }
  81. module.instantiate();
  82. },
  83. instantiate: function() {
  84. module.verbose('Storing instance of module', module);
  85. instance = module;
  86. $module
  87. .data(moduleNamespace, instance)
  88. ;
  89. },
  90. refresh: function() {
  91. $popup = (settings.popup)
  92. ? $(settings.popup)
  93. : (settings.inline)
  94. ? $target.next(settings.selector.popup)
  95. : false
  96. ;
  97. $offsetParent = (settings.popup)
  98. ? $popup.offsetParent()
  99. : (settings.inline)
  100. ? $target.offsetParent()
  101. : $body
  102. ;
  103. },
  104. 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.error(error.content, 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(settings.transition + ' in', settings.duration, function() {
  300. module.bind.close();
  301. $.proxy(callback, element)();
  302. })
  303. ;
  304. }
  305. else {
  306. $popup
  307. .stop()
  308. .fadeIn(settings.duration, settings.easing, function() {
  309. module.bind.close();
  310. $.proxy(callback, element)();
  311. })
  312. ;
  313. }
  314. $.proxy(settings.onShow, element)();
  315. },
  316. hide: function(callback) {
  317. callback = callback || function(){};
  318. module.debug('Hiding pop-up');
  319. if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
  320. $popup
  321. .transition(settings.transition + ' out', settings.duration, function() {
  322. module.reset();
  323. callback();
  324. })
  325. ;
  326. }
  327. else {
  328. $popup
  329. .stop()
  330. .fadeOut(settings.duration, settings.easing, function() {
  331. module.reset();
  332. callback();
  333. })
  334. ;
  335. }
  336. $.proxy(settings.onHide, element)();
  337. }
  338. },
  339. get: {
  340. startEvent: function() {
  341. if(settings.on == 'hover') {
  342. return 'mouseenter';
  343. }
  344. else if(settings.on == 'focus') {
  345. return 'focus';
  346. }
  347. return false;
  348. },
  349. endEvent: function() {
  350. if(settings.on == 'hover') {
  351. return 'mouseleave';
  352. }
  353. else if(settings.on == 'focus') {
  354. return 'blur';
  355. }
  356. return false;
  357. },
  358. offstagePosition: function() {
  359. var
  360. boundary = {
  361. top : $(window).scrollTop(),
  362. bottom : $(window).scrollTop() + $(window).height(),
  363. left : 0,
  364. right : $(window).width()
  365. },
  366. popup = {
  367. width : $popup.width(),
  368. height : $popup.outerHeight(),
  369. offset : $popup.offset()
  370. },
  371. offstage = {},
  372. offstagePositions = []
  373. ;
  374. if(popup.offset) {
  375. offstage = {
  376. top : (popup.offset.top < boundary.top),
  377. bottom : (popup.offset.top + popup.height > boundary.bottom),
  378. right : (popup.offset.left + popup.width > boundary.right),
  379. left : (popup.offset.left < boundary.left)
  380. };
  381. }
  382. module.verbose('Checking if outside viewable area', popup.offset);
  383. // return only boundaries that have been surpassed
  384. $.each(offstage, function(direction, isOffstage) {
  385. if(isOffstage) {
  386. offstagePositions.push(direction);
  387. }
  388. });
  389. return (offstagePositions.length > 0)
  390. ? offstagePositions.join(' ')
  391. : false
  392. ;
  393. },
  394. nextPosition: function(position) {
  395. switch(position) {
  396. case 'top left':
  397. position = 'bottom left';
  398. break;
  399. case 'bottom left':
  400. position = 'top right';
  401. break;
  402. case 'top right':
  403. position = 'bottom right';
  404. break;
  405. case 'bottom right':
  406. position = 'top center';
  407. break;
  408. case 'top center':
  409. position = 'bottom center';
  410. break;
  411. case 'bottom center':
  412. position = 'right center';
  413. break;
  414. case 'right center':
  415. position = 'left center';
  416. break;
  417. case 'left center':
  418. position = 'top center';
  419. break;
  420. }
  421. return position;
  422. }
  423. },
  424. set: {
  425. position: function(position, arrowOffset) {
  426. var
  427. windowWidth = $(window).width(),
  428. windowHeight = $(window).height(),
  429. targetWidth = $target.outerWidth(),
  430. targetHeight = $target.outerHeight(),
  431. popupWidth = $popup.outerWidth(),
  432. popupHeight = $popup.outerHeight(),
  433. parentWidth = $offsetParent.outerWidth(),
  434. parentHeight = $offsetParent.outerHeight(),
  435. distanceAway = settings.distanceAway,
  436. targetElement = $target[0],
  437. marginTop = (settings.inline)
  438. ? parseInt( window.getComputedStyle(targetElement).getPropertyValue('margin-top'), 10)
  439. : 0,
  440. marginLeft = (settings.inline)
  441. ? parseInt( window.getComputedStyle(targetElement).getPropertyValue('margin-left'), 10)
  442. : 0,
  443. target = (settings.inline || settings.popup)
  444. ? $target.position()
  445. : $target.offset(),
  446. positioning,
  447. offstagePosition
  448. ;
  449. position = position || $module.data(metadata.position) || settings.position;
  450. arrowOffset = arrowOffset || $module.data(metadata.offset) || settings.offset;
  451. if(settings.inline) {
  452. module.debug('Adding targets margin to calculation');
  453. if(position == 'left center' || position == 'right center') {
  454. arrowOffset += marginTop;
  455. distanceAway += -marginLeft;
  456. }
  457. else if (position == 'top left' || position == 'top center' || position == 'top right') {
  458. arrowOffset += marginLeft;
  459. distanceAway -= marginTop;
  460. }
  461. else {
  462. arrowOffset += marginLeft;
  463. distanceAway += marginTop;
  464. }
  465. }
  466. module.debug('Calculating popup positioning', position);
  467. switch(position) {
  468. case 'top left':
  469. positioning = {
  470. top : 'auto',
  471. bottom : parentHeight - target.top + distanceAway,
  472. left : target.left + arrowOffset,
  473. right : 'auto'
  474. };
  475. break;
  476. case 'top center':
  477. positioning = {
  478. bottom : parentHeight - target.top + distanceAway,
  479. left : target.left + (targetWidth / 2) - (popupWidth / 2) + arrowOffset,
  480. top : 'auto',
  481. right : 'auto'
  482. };
  483. break;
  484. case 'top right':
  485. positioning = {
  486. bottom : parentHeight - target.top + distanceAway,
  487. right : parentWidth - target.left - targetWidth - arrowOffset,
  488. top : 'auto',
  489. left : 'auto'
  490. };
  491. break;
  492. case 'left center':
  493. positioning = {
  494. top : target.top + (targetHeight / 2) - (popupHeight / 2) + arrowOffset,
  495. right : parentWidth - target.left + distanceAway,
  496. left : 'auto',
  497. bottom : 'auto'
  498. };
  499. break;
  500. case 'right center':
  501. positioning = {
  502. top : target.top + (targetHeight / 2) - (popupHeight / 2) + arrowOffset,
  503. left : target.left + targetWidth + distanceAway,
  504. bottom : 'auto',
  505. right : 'auto'
  506. };
  507. break;
  508. case 'bottom left':
  509. positioning = {
  510. top : target.top + targetHeight + distanceAway,
  511. left : target.left + arrowOffset,
  512. bottom : 'auto',
  513. right : 'auto'
  514. };
  515. break;
  516. case 'bottom center':
  517. positioning = {
  518. top : target.top + targetHeight + distanceAway,
  519. left : target.left + (targetWidth / 2) - (popupWidth / 2) + arrowOffset,
  520. bottom : 'auto',
  521. right : 'auto'
  522. };
  523. break;
  524. case 'bottom right':
  525. positioning = {
  526. top : target.top + targetHeight + distanceAway,
  527. right : parentWidth - target.left - targetWidth - arrowOffset,
  528. left : 'auto',
  529. bottom : 'auto'
  530. };
  531. break;
  532. }
  533. if(positioning === undefined) {
  534. module.error(error.invalidPosition);
  535. }
  536. // tentatively place on stage
  537. $popup
  538. .css(positioning)
  539. .removeClass(className.position)
  540. .addClass(position)
  541. .addClass(className.loading)
  542. ;
  543. // check if is offstage
  544. offstagePosition = module.get.offstagePosition();
  545. // recursively find new positioning
  546. if(offstagePosition) {
  547. module.debug('Element is outside boundaries', offstagePosition);
  548. if(searchDepth < settings.maxSearchDepth) {
  549. position = module.get.nextPosition(position);
  550. searchDepth++;
  551. module.debug('Trying new position', position);
  552. return ($popup)
  553. ? module.set.position(position)
  554. : false
  555. ;
  556. }
  557. else {
  558. module.error(error.recursion);
  559. searchDepth = 0;
  560. module.reset();
  561. $popup.removeClass(className.loading);
  562. return false;
  563. }
  564. }
  565. else {
  566. module.debug('Position is on stage', position);
  567. searchDepth = 0;
  568. $popup.removeClass(className.loading);
  569. return true;
  570. }
  571. }
  572. },
  573. bind: {
  574. popup: function() {
  575. if(settings.hoverable) {
  576. module.verbose('Allowing hover events on popup to prevent closing');
  577. $popup
  578. .on('mouseenter', module.event.start)
  579. .on('mouseleave', module.event.end)
  580. ;
  581. }
  582. },
  583. close:function() {
  584. if(settings.on == 'click' && settings.closable) {
  585. module.verbose('Binding popup close event to document');
  586. $document
  587. .on('click' + eventNamespace, function(event) {
  588. module.verbose('Pop-up clickaway intent detected');
  589. $.proxy(module.hideGracefully, element)(event);
  590. })
  591. ;
  592. }
  593. }
  594. },
  595. unbind: {
  596. close: function() {
  597. if(settings.on == 'click' && settings.closable) {
  598. module.verbose('Removing close event from document');
  599. $document
  600. .off('click' + eventNamespace)
  601. ;
  602. }
  603. }
  604. },
  605. is: {
  606. active: function() {
  607. return $module.hasClass(className.active);
  608. },
  609. animating: function() {
  610. return ( $popup && $popup.is(':animated') || $popup.hasClass(className.animating) );
  611. },
  612. visible: function() {
  613. return $popup && $popup.is(':visible');
  614. },
  615. dropdown: function() {
  616. return $module.hasClass(className.dropdown);
  617. },
  618. hidden: function() {
  619. return !module.is.visible();
  620. }
  621. },
  622. reset: function() {
  623. $popup
  624. .removeClass(className.visible)
  625. ;
  626. if(settings.preserve || settings.popup) {
  627. if($.fn.transition !== undefined) {
  628. $popup
  629. .transition('remove transition')
  630. ;
  631. }
  632. }
  633. else {
  634. module.remove();
  635. }
  636. },
  637. setting: function(name, value) {
  638. if( $.isPlainObject(name) ) {
  639. $.extend(true, settings, name);
  640. }
  641. else if(value !== undefined) {
  642. settings[name] = value;
  643. }
  644. else {
  645. return settings[name];
  646. }
  647. },
  648. internal: function(name, value) {
  649. if( $.isPlainObject(name) ) {
  650. $.extend(true, module, name);
  651. }
  652. else if(value !== undefined) {
  653. module[name] = value;
  654. }
  655. else {
  656. return module[name];
  657. }
  658. },
  659. debug: function() {
  660. if(settings.debug) {
  661. if(settings.performance) {
  662. module.performance.log(arguments);
  663. }
  664. else {
  665. module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
  666. module.debug.apply(console, arguments);
  667. }
  668. }
  669. },
  670. verbose: function() {
  671. if(settings.verbose && settings.debug) {
  672. if(settings.performance) {
  673. module.performance.log(arguments);
  674. }
  675. else {
  676. module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
  677. module.verbose.apply(console, arguments);
  678. }
  679. }
  680. },
  681. error: function() {
  682. module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
  683. module.error.apply(console, arguments);
  684. },
  685. performance: {
  686. log: function(message) {
  687. var
  688. currentTime,
  689. executionTime,
  690. previousTime
  691. ;
  692. if(settings.performance) {
  693. currentTime = new Date().getTime();
  694. previousTime = time || currentTime;
  695. executionTime = currentTime - previousTime;
  696. time = currentTime;
  697. performance.push({
  698. 'Element' : element,
  699. 'Name' : message[0],
  700. 'Arguments' : [].slice.call(message, 1) || '',
  701. 'Execution Time' : executionTime
  702. });
  703. }
  704. clearTimeout(module.performance.timer);
  705. module.performance.timer = setTimeout(module.performance.display, 100);
  706. },
  707. display: function() {
  708. var
  709. title = settings.name + ':',
  710. totalTime = 0
  711. ;
  712. time = false;
  713. clearTimeout(module.performance.timer);
  714. $.each(performance, function(index, data) {
  715. totalTime += data['Execution Time'];
  716. });
  717. title += ' ' + totalTime + 'ms';
  718. if(moduleSelector) {
  719. title += ' \'' + moduleSelector + '\'';
  720. }
  721. if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
  722. console.groupCollapsed(title);
  723. if(console.table) {
  724. console.table(performance);
  725. }
  726. else {
  727. $.each(performance, function(index, data) {
  728. console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
  729. });
  730. }
  731. console.groupEnd();
  732. }
  733. performance = [];
  734. }
  735. },
  736. invoke: function(query, passedArguments, context) {
  737. var
  738. object = instance,
  739. maxDepth,
  740. found,
  741. response
  742. ;
  743. passedArguments = passedArguments || queryArguments;
  744. context = element || context;
  745. if(typeof query == 'string' && object !== undefined) {
  746. query = query.split(/[\. ]/);
  747. maxDepth = query.length - 1;
  748. $.each(query, function(depth, value) {
  749. var camelCaseValue = (depth != maxDepth)
  750. ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
  751. : query
  752. ;
  753. if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
  754. object = object[camelCaseValue];
  755. }
  756. else if( object[camelCaseValue] !== undefined ) {
  757. found = object[camelCaseValue];
  758. return false;
  759. }
  760. else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
  761. object = object[value];
  762. }
  763. else if( object[value] !== undefined ) {
  764. found = object[value];
  765. return false;
  766. }
  767. else {
  768. return false;
  769. }
  770. });
  771. }
  772. if ( $.isFunction( found ) ) {
  773. response = found.apply(context, passedArguments);
  774. }
  775. else if(found !== undefined) {
  776. response = found;
  777. }
  778. if($.isArray(returnedValue)) {
  779. returnedValue.push(response);
  780. }
  781. else if(returnedValue !== undefined) {
  782. returnedValue = [returnedValue, response];
  783. }
  784. else if(response !== undefined) {
  785. returnedValue = response;
  786. }
  787. return found;
  788. }
  789. };
  790. if(methodInvoked) {
  791. if(instance === undefined) {
  792. module.initialize();
  793. }
  794. module.invoke(query);
  795. }
  796. else {
  797. if(instance !== undefined) {
  798. module.destroy();
  799. }
  800. module.initialize();
  801. }
  802. })
  803. ;
  804. return (returnedValue !== undefined)
  805. ? returnedValue
  806. : this
  807. ;
  808. };
  809. $.fn.popup.settings = {
  810. name : 'Popup',
  811. debug : false,
  812. verbose : false,
  813. performance : false,
  814. namespace : 'popup',
  815. onCreate : function(){},
  816. onRemove : function(){},
  817. onShow : function(){},
  818. onHide : function(){},
  819. variation : '',
  820. content : false,
  821. html : false,
  822. title : false,
  823. on : 'hover',
  824. closable : true,
  825. context : 'body',
  826. position : 'top left',
  827. delay : {
  828. show : 50,
  829. hide : 0
  830. },
  831. target : false,
  832. popup : false,
  833. inline : false,
  834. preserve : true,
  835. hoverable : false,
  836. duration : 200,
  837. easing : 'easeOutQuint',
  838. transition : 'scale',
  839. distanceAway : 0,
  840. offset : 0,
  841. maxSearchDepth : 10,
  842. error: {
  843. content : 'Your popup has no content specified',
  844. invalidPosition : 'The position you specified is not a valid position',
  845. method : 'The method you called is not defined.',
  846. recursion : 'Popup attempted to reposition element to fit, but could not find an adequate position.'
  847. },
  848. metadata: {
  849. content : 'content',
  850. html : 'html',
  851. offset : 'offset',
  852. position : 'position',
  853. title : 'title',
  854. variation : 'variation'
  855. },
  856. className : {
  857. active : 'active',
  858. animating : 'animating',
  859. dropdown : 'dropdown',
  860. loading : 'loading',
  861. popup : 'ui popup',
  862. position : 'top left center bottom right',
  863. visible : 'visible'
  864. },
  865. selector : {
  866. popup : '.ui.popup'
  867. },
  868. templates: {
  869. escape: function(string) {
  870. var
  871. badChars = /[&<>"'`]/g,
  872. shouldEscape = /[&<>"'`]/,
  873. escape = {
  874. "&": "&amp;",
  875. "<": "&lt;",
  876. ">": "&gt;",
  877. '"': "&quot;",
  878. "'": "&#x27;",
  879. "`": "&#x60;"
  880. },
  881. escapedChar = function(chr) {
  882. return escape[chr];
  883. }
  884. ;
  885. if(shouldEscape.test(string)) {
  886. return string.replace(badChars, escapedChar);
  887. }
  888. return string;
  889. },
  890. popup: function(text) {
  891. var
  892. html = '',
  893. escape = $.fn.popup.settings.templates.escape
  894. ;
  895. if(typeof text !== undefined) {
  896. if(typeof text.title !== undefined && text.title) {
  897. text.title = escape(text.title);
  898. html += '<div class="header">' + text.title + '</div>';
  899. }
  900. if(typeof text.content !== undefined && text.content) {
  901. text.content = escape(text.content);
  902. html += '<div class="content">' + text.content + '</div>';
  903. }
  904. }
  905. return html;
  906. }
  907. }
  908. };
  909. // Adds easing
  910. $.extend( $.easing, {
  911. easeOutQuad: function (x, t, b, c, d) {
  912. return -c *(t/=d)*(t-2) + b;
  913. }
  914. });
  915. })( jQuery, window , document );