Dashboard sipadu mbip
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.

aui-loading-mask.js 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. AUI.add('aui-loading-mask', function(A) {
  2. /**
  3. * The LoadingMask Utility
  4. *
  5. * @module aui-loading-mask
  6. */
  7. var Lang = A.Lang,
  8. BOUNDING_BOX = 'boundingBox',
  9. CONTENT_BOX = 'contentBox',
  10. HIDE = 'hide',
  11. HOST = 'host',
  12. MESSAGE_EL = 'messageEl',
  13. NAME = 'loadingmask',
  14. POSITION = 'position',
  15. SHOW = 'show',
  16. STATIC = 'static',
  17. STRINGS = 'strings',
  18. TARGET = 'target',
  19. TOGGLE = 'toggle',
  20. getClassName = A.getClassName,
  21. CSS_LOADINGMASK = getClassName(NAME),
  22. CSS_MASKED = getClassName(NAME, 'masked'),
  23. CSS_MASKED_RELATIVE = getClassName(NAME, 'masked', 'relative'),
  24. CSS_MESSAGE_LOADING = getClassName(NAME, 'message'),
  25. CSS_MESSAGE_LOADING_CONTENT = getClassName(NAME, 'message', 'content'),
  26. TPL_MESSAGE_LOADING = '<div class="' + CSS_MESSAGE_LOADING + '"><div class="' + CSS_MESSAGE_LOADING_CONTENT + '">{0}</div></div>';
  27. /**
  28. * <p><img src="assets/images/aui-loading-mask/main.png"/></p>
  29. *
  30. * A base class for LoadingMask, providing:
  31. * <ul>
  32. * <li>Cross browser mask functionality to cover an element or the entire page</li>
  33. * <li>Customizable mask (i.e., background, opacity)</li>
  34. * <li>Display a centered "loading" message on the masked node</li>
  35. * </ul>
  36. *
  37. * Quick Example:<br/>
  38. *
  39. * <pre><code>node.plug(A.LoadingMask, { background: '#000' });</code></pre>
  40. *
  41. * Check the list of <a href="LoadingMask.html#configattributes">Configuration Attributes</a> available for
  42. * LoadingMask.
  43. *
  44. * @param config {Object} Object literal specifying widget configuration properties.
  45. *
  46. * @class LoadingMask
  47. * @constructor
  48. * @extends Plugin.Base
  49. */
  50. var LoadingMask = A.Component.create(
  51. {
  52. /**
  53. * Static property provides a string to identify the class.
  54. *
  55. * @property LoadingMask.NAME
  56. * @type String
  57. * @static
  58. */
  59. NAME: NAME,
  60. /**
  61. * Static property provides a string to identify the namespace.
  62. *
  63. * @property LoadingMask.NS
  64. * @type String
  65. * @static
  66. */
  67. NS: NAME,
  68. /**
  69. * Static property used to define the default attribute
  70. * configuration for the LoadingMask.
  71. *
  72. * @property LoadingMask.ATTRS
  73. * @type Object
  74. * @static
  75. */
  76. ATTRS: {
  77. /**
  78. * Node element to display the message.
  79. *
  80. * @attribute messageEl
  81. * @default Generated HTML div element.
  82. * @type String
  83. */
  84. messageEl: {
  85. valueFn: function(val) {
  86. var instance = this;
  87. var strings = instance.get(STRINGS);
  88. return A.Node.create(
  89. Lang.sub(TPL_MESSAGE_LOADING, [strings.loading])
  90. );
  91. }
  92. },
  93. /**
  94. * Strings used on the LoadingMask. See
  95. * <a href="Widget.html#method_strings">strings</a>.
  96. *
  97. * @attribute strings
  98. * @default { loading: 'Loading&hellip;' }
  99. * @type Object
  100. */
  101. strings: {
  102. value: {
  103. loading: 'Loading&hellip;'
  104. }
  105. },
  106. /**
  107. * Node where the mask will be positioned and re-dimensioned.
  108. *
  109. * @attribute target
  110. * @default null
  111. * @type Node | Widget
  112. */
  113. target: {
  114. setter: function() {
  115. var instance = this;
  116. var target = instance.get(HOST);
  117. if (target instanceof A.Widget) {
  118. target = target.get(CONTENT_BOX);
  119. }
  120. return target;
  121. },
  122. value: null
  123. }
  124. },
  125. EXTENDS: A.Plugin.Base,
  126. prototype: {
  127. /**
  128. * Construction logic executed during LoadingMask instantiation. Lifecycle.
  129. *
  130. * @method initializer
  131. * @protected
  132. */
  133. initializer: function(config) {
  134. var instance = this;
  135. instance.IGNORED_ATTRS = A.merge(
  136. {
  137. host: true
  138. },
  139. LoadingMask.ATTRS
  140. );
  141. instance.renderUI();
  142. instance.bindUI();
  143. instance._createDynamicAttrs(config);
  144. },
  145. /**
  146. * Create the DOM structure for the LoadingMask. Lifecycle.
  147. *
  148. * @method renderUI
  149. * @protected
  150. */
  151. renderUI: function() {
  152. var instance = this;
  153. var strings = instance.get(STRINGS);
  154. instance._renderOverlayMask();
  155. instance.overlayMask.get(BOUNDING_BOX).append(
  156. instance.get(MESSAGE_EL)
  157. );
  158. },
  159. /**
  160. * Bind the events on the LoadingMask UI. Lifecycle.
  161. *
  162. * @method bindUI
  163. * @protected
  164. */
  165. bindUI: function() {
  166. var instance = this;
  167. instance._bindOverlayMaskUI();
  168. },
  169. /**
  170. * Bind events to the
  171. * <a href="LoadingMask.html#property_overlayMask">overlayMask</a>.
  172. *
  173. * @method _bindOverlayMaskUI
  174. * @protected
  175. */
  176. _bindOverlayMaskUI: function() {
  177. var instance = this;
  178. instance.overlayMask.after('visibleChange', instance._afterVisibleChange, instance);
  179. },
  180. /**
  181. * Center the
  182. * <a href="LoadingMask.html#config_messageEl">messageEl</a> with the
  183. * <a href="LoadingMask.html#config_target">target</a> node.
  184. *
  185. * @method centerMessage
  186. */
  187. centerMessage: function() {
  188. var instance = this;
  189. instance.get(MESSAGE_EL).center(
  190. instance.overlayMask.get(BOUNDING_BOX)
  191. );
  192. },
  193. /**
  194. * Invoke the
  195. * <a href="LoadingMask.html#property_overlayMask">overlayMask</a>
  196. * <code>refreshMask</code> method.
  197. *
  198. * @method refreshMask
  199. */
  200. refreshMask: function() {
  201. var instance = this;
  202. instance.overlayMask.refreshMask();
  203. instance.centerMessage();
  204. },
  205. /**
  206. * Fires after the value of the
  207. * <a href="LoadingMask.html#config_visible">visible</a> attribute change.
  208. *
  209. * @method _afterVisibleChange
  210. * @param {EventFacade} event
  211. * @protected
  212. */
  213. _afterVisibleChange: function(event) {
  214. var instance = this;
  215. var target = instance.get(TARGET);
  216. var isStaticPositioned = (target.getStyle(POSITION) == STATIC);
  217. target.toggleClass(CSS_MASKED, (event.newVal));
  218. target.toggleClass(CSS_MASKED_RELATIVE, (event.newVal && isStaticPositioned));
  219. if (event.newVal) {
  220. instance.refreshMask();
  221. }
  222. },
  223. /**
  224. * Render
  225. * <a href="LoadingMask.html#property_overlayMask">overlayMask</a>
  226. * instance.
  227. *
  228. * @method _renderOverlayMask
  229. * @protected
  230. */
  231. _renderOverlayMask: function() {
  232. var instance = this;
  233. var target = instance.get(TARGET);
  234. /**
  235. * Stores the <a href="OverlayMask.html">OverlayMask</a> used
  236. * internally.
  237. *
  238. * @property overlayMask
  239. * @type OverlayMask
  240. * @protected
  241. */
  242. instance.overlayMask = new A.OverlayMask(
  243. {
  244. target: target,
  245. cssClass: CSS_LOADINGMASK
  246. }
  247. ).render(target);
  248. },
  249. /**
  250. * Create dynamic attributes listeners to invoke the setter on
  251. * <a href="LoadingMask.html#property_overlayMask">overlayMask</a> after
  252. * the attribute is set on the LoadingMask instance.
  253. *
  254. * @method _createDynamicAttrs
  255. * @param {Object} config Object literal specifying widget configuration properties.
  256. * @protected
  257. */
  258. _createDynamicAttrs: function(config) {
  259. var instance = this;
  260. A.each(config, function(value, key) {
  261. var ignoredAttr = instance.IGNORED_ATTRS[key];
  262. if (!ignoredAttr) {
  263. instance.addAttr(key, {
  264. setter: function(val) {
  265. this.overlayMask.set(key, val);
  266. return val;
  267. },
  268. value: value
  269. });
  270. }
  271. });
  272. }
  273. }
  274. }
  275. );
  276. A.each([HIDE, SHOW, TOGGLE], function(method) {
  277. /**
  278. * Invoke the
  279. * <a href="LoadingMask.html#property_overlayMask">overlayMask</a>
  280. * <code>hide</code> method.
  281. *
  282. * @method hide
  283. */
  284. /**
  285. * Invoke the
  286. * <a href="LoadingMask.html#property_overlayMask">overlayMask</a>
  287. * <code>show</code> method.
  288. *
  289. * @method show
  290. */
  291. /**
  292. * Invoke the
  293. * <a href="LoadingMask.html#property_overlayMask">overlayMask</a>
  294. * <code>toggle</code> method.
  295. *
  296. * @method toggle
  297. */
  298. LoadingMask.prototype[method] = function() {
  299. this.overlayMask[method]();
  300. };
  301. });
  302. A.LoadingMask = LoadingMask;
  303. }, '@VERSION@' ,{requires:['aui-overlay-mask','plugin'], skinnable:true});