load_indicator.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /**
  2. * DevExtreme (ui/load_indicator.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var $ = require("../core/renderer");
  11. var windowUtils = require("../core/utils/window");
  12. var navigator = windowUtils.getNavigator();
  13. var support = require("../core/utils/support");
  14. var themes = require("./themes");
  15. var extend = require("../core/utils/extend").extend;
  16. var devices = require("../core/devices");
  17. var registerComponent = require("../core/component_registrator");
  18. var Widget = require("./widget/ui.widget");
  19. var LOADINDICATOR_CLASS = "dx-loadindicator";
  20. var LOADINDICATOR_WRAPPER_CLASS = "dx-loadindicator-wrapper";
  21. var LOADINDICATOR_CONTENT_CLASS = "dx-loadindicator-content";
  22. var LOADINDICATOR_ICON_CLASS = "dx-loadindicator-icon";
  23. var LOADINDICATOR_SEGMENT_CLASS = "dx-loadindicator-segment";
  24. var LOADINDICATOR_SEGMENT_INNER_CLASS = "dx-loadindicator-segment-inner";
  25. var LOADINDICATOR_IMAGE_CLASS = "dx-loadindicator-image";
  26. var LoadIndicator = Widget.inherit({
  27. _getDefaultOptions: function() {
  28. return extend(this.callBase(), {
  29. indicatorSrc: "",
  30. activeStateEnabled: false,
  31. hoverStateEnabled: false,
  32. _animatingSegmentCount: 1,
  33. _animatingSegmentInner: false
  34. })
  35. },
  36. _defaultOptionsRules: function() {
  37. var themeName = themes.current();
  38. return this.callBase().concat([{
  39. device: function() {
  40. var realDevice = devices.real();
  41. var obsoleteAndroid = "android" === realDevice.platform && !/chrome/i.test(navigator.userAgent);
  42. return obsoleteAndroid
  43. },
  44. options: {
  45. viaImage: true
  46. }
  47. }, {
  48. device: function() {
  49. return themes.isIos7(themeName)
  50. },
  51. options: {
  52. _animatingSegmentCount: 11
  53. }
  54. }, {
  55. device: function() {
  56. return themes.isMaterial(themeName)
  57. },
  58. options: {
  59. _animatingSegmentCount: 2,
  60. _animatingSegmentInner: true
  61. }
  62. }, {
  63. device: function() {
  64. return themes.isGeneric(themeName)
  65. },
  66. options: {
  67. _animatingSegmentCount: 7
  68. }
  69. }])
  70. },
  71. _init: function() {
  72. this.callBase();
  73. this.$element().addClass(LOADINDICATOR_CLASS)
  74. },
  75. _initMarkup: function() {
  76. this.callBase();
  77. this._renderWrapper();
  78. this._renderIndicatorContent();
  79. this._renderMarkup()
  80. },
  81. _renderWrapper: function() {
  82. this._$wrapper = $("<div>").addClass(LOADINDICATOR_WRAPPER_CLASS);
  83. this.$element().append(this._$wrapper)
  84. },
  85. _renderIndicatorContent: function() {
  86. this._$content = $("<div>").addClass(LOADINDICATOR_CONTENT_CLASS);
  87. this._$wrapper.append(this._$content)
  88. },
  89. _renderMarkup: function() {
  90. if (support.animation() && !this.option("viaImage") && !this.option("indicatorSrc")) {
  91. this._renderMarkupForAnimation()
  92. } else {
  93. this._renderMarkupForImage()
  94. }
  95. },
  96. _renderMarkupForAnimation: function() {
  97. var animatingSegmentInner = this.option("_animatingSegmentInner");
  98. this._$indicator = $("<div>").addClass(LOADINDICATOR_ICON_CLASS);
  99. this._$content.append(this._$indicator);
  100. for (var i = this.option("_animatingSegmentCount"); i >= 0; --i) {
  101. var $segment = $("<div>").addClass(LOADINDICATOR_SEGMENT_CLASS).addClass(LOADINDICATOR_SEGMENT_CLASS + i);
  102. if (animatingSegmentInner) {
  103. $segment.append($("<div>").addClass(LOADINDICATOR_SEGMENT_INNER_CLASS))
  104. }
  105. this._$indicator.append($segment)
  106. }
  107. },
  108. _renderMarkupForImage: function() {
  109. var indicatorSrc = this.option("indicatorSrc");
  110. this._$wrapper.addClass(LOADINDICATOR_IMAGE_CLASS);
  111. if (indicatorSrc) {
  112. this._$wrapper.css("backgroundImage", "url(" + indicatorSrc + ")")
  113. }
  114. },
  115. _renderDimensions: function() {
  116. this.callBase();
  117. this._updateContentSizeForAnimation()
  118. },
  119. _updateContentSizeForAnimation: function() {
  120. if (!this._$indicator) {
  121. return
  122. }
  123. var width = this.option("width");
  124. var height = this.option("height");
  125. if (width || height) {
  126. width = this.$element().width();
  127. height = this.$element().height();
  128. var minDimension = Math.min(height, width);
  129. this._$wrapper.css({
  130. height: minDimension,
  131. width: minDimension,
  132. fontSize: minDimension
  133. })
  134. }
  135. },
  136. _clean: function() {
  137. this.callBase();
  138. this._removeMarkupForAnimation();
  139. this._removeMarkupForImage()
  140. },
  141. _removeMarkupForAnimation: function() {
  142. if (!this._$indicator) {
  143. return
  144. }
  145. this._$indicator.remove();
  146. delete this._$indicator
  147. },
  148. _removeMarkupForImage: function() {
  149. this._$wrapper.css("backgroundImage", "none")
  150. },
  151. _optionChanged: function(args) {
  152. switch (args.name) {
  153. case "_animatingSegmentCount":
  154. case "_animatingSegmentInner":
  155. case "indicatorSrc":
  156. this._invalidate();
  157. break;
  158. default:
  159. this.callBase(args)
  160. }
  161. }
  162. });
  163. registerComponent("dxLoadIndicator", LoadIndicator);
  164. module.exports = LoadIndicator;
  165. module.exports.default = module.exports;