Reusable Accessible Mapping Platform

API Docs for: 5.3.1
Show:

File: src/js/RAMP/Modules/theme.js

  1. /*global define, TimelineLite, TweenLite, $ */
  2.  
  3. /**
  4. * This submodule contains theme-specific classes with animation sequences such as Full Screen transition or tooltip setter helper method.
  5. *
  6. * @module RAMP
  7. * @submodule Theme
  8. *
  9. */
  10.  
  11. /**
  12. * Base theme for RAMP.
  13. *
  14. * ####Imports RAMP Modules:
  15. * {{#crossLink "Util"}}{{/crossLink}}
  16. *
  17. * @class Theme
  18. * @static
  19. * @uses dojo/_base/lang
  20. */
  21.  
  22. define(["dojo/_base/lang"],
  23. function (lang) {
  24. "use strict";
  25.  
  26. var body = $("body"),
  27. wbCore = $("main"),
  28. wbFoot = $("footer"),
  29.  
  30. megaMenuDiv = $("#wb-sm"),
  31. navigation = $("#wb-bar"),
  32.  
  33. header = $("body>header"),
  34.  
  35. transitionDuration = 0.5,
  36.  
  37. layout = {
  38. headerHeight: 155,
  39. headerHeightCollapsed: 64,
  40.  
  41. footerHeight: 30,
  42. footerHeightCollapsed: 5,
  43.  
  44. subtitleHeight: 35,
  45.  
  46. toolbarHeight: 32
  47. },
  48.  
  49. // height gain from the fullscreening the template
  50. heightGain = layout.headerHeight - layout.headerHeightCollapsed + layout.footerHeight - layout.footerHeightCollapsed,
  51.  
  52. isFullScreen = false,
  53.  
  54. fullScreenTimeLine = new TimelineLite({ paused: true }),
  55. subpanelTimeline = new TimelineLite();
  56.  
  57. // tweening wet template parts
  58. fullScreenTimeLine
  59. .to(header, transitionDuration, { top: navigation.outerHeight() * -1, position: "relative", ease: "easeOutCirc" }, 0)
  60. .set([navigation, megaMenuDiv], { display: "none !important" })
  61.  
  62. .to(wbCore, transitionDuration, { top: layout.headerHeightCollapsed, bottom: layout.footerHeightCollapsed, ease: "easeOutCirc" }, 0)
  63. .to(wbFoot, transitionDuration, { height: layout.footerHeightCollapsed, ease: "easeOutCirc" }, 0)
  64.  
  65. .call(function () { body.addClass("full-screen"); }) // set full-screen class here, not in the callback since callbacks can be overwritten by fullScreenCallback function
  66.  
  67. .add(subpanelTimeline, 0); // special timeline to tween subpanels
  68.  
  69. /**
  70. * Toggles full screen mode
  71. *
  72. * @method _toggleFullScreenMode
  73. * @param {Boolean} fullscreen true - full screen on; false - full screen off; undefined - toggle;
  74. */
  75. function _toggleFullScreenMode(fullscreen) {
  76. subpanelTimeline
  77. .clear() // need to recreate this timeline every time to capture newly created subpanels
  78. .fromTo(".sub-panel-container.summary-data-details", transitionDuration,
  79. { top: layout.headerHeight + layout.toolbarHeight, bottom: layout.footerHeight },
  80. { top: layout.headerHeightCollapsed + layout.toolbarHeight, bottom: layout.footerHeightCollapsed, ease: "easeOutCirc" }, 0)
  81. .fromTo(".sub-panel-container.full-data-details", transitionDuration,
  82. { top: layout.headerHeight, bottom: layout.footerHeight },
  83. { top: layout.headerHeightCollapsed, bottom: layout.footerHeightCollapsed, ease: "easeOutCirc" }, 0);
  84.  
  85. isFullScreen = typeof fullscreen === 'boolean' ? fullscreen : !isFullScreen ;
  86.  
  87. if (isFullScreen) {
  88. // need to tween datatables separately since it's very cumbersome to calculate their exact height - easier just to adjust height up/down by height gained when fullscreening the template
  89. TweenLite
  90. .to(".full-data-mode .dataTables_scrollBody", transitionDuration,
  91. { height: "+=" + heightGain, ease: "easeOutCirc", delay: 0.02 }); // animate height of the datatable scrollBody since it's explicitly set ,
  92.  
  93. fullScreenTimeLine.play();
  94.  
  95. } else {
  96. TweenLite
  97. .to(".full-data-mode .dataTables_scrollBody", transitionDuration - 0.02,
  98. { height: "-=" + heightGain, ease: "easeInCirc" }); // animate height of the datatable scrollBody since it's explicitly set ,
  99.  
  100. body.removeClass("full-screen");
  101. fullScreenTimeLine.reverse();
  102. }
  103. }
  104.  
  105. return {
  106. /**
  107. * Allows to set callbacks to the full screen transition.
  108. *
  109. * @method fullScreenCallback
  110. * @param {String} event Event name to set a callback on
  111. * @param {Function} func A callback function
  112. * @return {Object} This
  113. * @chainable
  114. */
  115. fullScreenCallback: function (event, func) {
  116. fullScreenTimeLine.eventCallback(event, func);
  117.  
  118. return this;
  119. },
  120.  
  121. /**
  122. * Returns a boolean indication whether the full screen mode is on.
  123. *
  124. * @method isFullScreen
  125. * @return {Boolean} true / false
  126. */
  127. isFullScreen: function () {
  128. return isFullScreen;
  129. },
  130.  
  131. /**
  132. * Toggles the FullScreen mode of the application
  133. *
  134. * @method toggleFullScreenMode
  135. * @param {Boolean} fullscreen true - expand; false - collapse; undefined - toggle;
  136. * @return {Object} This
  137. * @chainable
  138. */
  139. toggleFullScreenMode: function (fullscreen) {
  140. _toggleFullScreenMode(fullscreen);
  141.  
  142. return this;
  143. },
  144.  
  145. /**
  146. * Tooltip setter helper method.
  147. *
  148. * @method tooltipster
  149. * @param {Jquery} target A node to looked for tooltiped children on
  150. * @param {String} type Type of the tooltips to set
  151. * @param {String} [action] Action name: "update" will update all the tooltips on target with their respective title attributes;
  152. * null will create new tooltips
  153. * @return {Object} This
  154. * @chainable
  155. */
  156. tooltipster: function (target, type, action, options) {
  157. var attr;
  158. target = target || $("body");
  159.  
  160. switch (type) {
  161. case "map":
  162. break;
  163.  
  164. default:
  165. attr = {
  166. theme: 'tooltipster-shadow',
  167. delay: 500
  168. };
  169. break;
  170. }
  171.  
  172. switch (action) {
  173. case "update":
  174.  
  175. target
  176. .find(".tooltipstered")
  177. .each(function (i, obj) {
  178. var node = $(obj);
  179. node
  180. .attr("data-tooltip", node.attr("title"))
  181. .tooltipster("content", node.attr("title"))
  182. .removeAttr("title");
  183. });
  184. break;
  185.  
  186. case "destroy":
  187. target
  188. .find(".tooltipstered")
  189. .each(function (i, obj) {
  190. var node = $(obj);
  191. node
  192. .tooltipster("destroy");
  193. });
  194. break;
  195.  
  196. default:
  197. target
  198. .find('.tooltip, ._tooltip')
  199. // preserve title value for future use
  200. .each(function (i, obj) {
  201. var node = $(obj),
  202. title = node.attr("title");
  203.  
  204. if (title) {
  205. node.attr("data-tooltip", node.attr("title"));
  206. } else {
  207. node.attr("title", node.data("tooltip"));
  208. }
  209.  
  210. node.tooltipster(
  211. lang.mixin({
  212. theme: node.data("tooltip-theme") || attr.theme,
  213. //autoClose: false,
  214. maxWidth: node.data("tooltip-maxwidth") || null,
  215. delay: attr.delay
  216. },
  217. options
  218. )
  219. );
  220. })
  221. .removeAttr("title");
  222. break;
  223. }
  224.  
  225. return this;
  226. }
  227. };
  228. });