ui.drawer.rendering.strategy.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /**
  2. * DevExtreme (ui/drawer/ui.drawer.rendering.strategy.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 _renderer = require("../../core/renderer");
  11. var _renderer2 = _interopRequireDefault(_renderer);
  12. var _fx = require("../../animation/fx");
  13. var _fx2 = _interopRequireDefault(_fx);
  14. var _deferred = require("../../core/utils/deferred");
  15. var _inflector = require("../../core/utils/inflector");
  16. function _interopRequireDefault(obj) {
  17. return obj && obj.__esModule ? obj : {
  18. "default": obj
  19. }
  20. }
  21. function _classCallCheck(instance, Constructor) {
  22. if (!(instance instanceof Constructor)) {
  23. throw new TypeError("Cannot call a class as a function")
  24. }
  25. }
  26. function _defineProperties(target, props) {
  27. for (var i = 0; i < props.length; i++) {
  28. var descriptor = props[i];
  29. descriptor.enumerable = descriptor.enumerable || false;
  30. descriptor.configurable = true;
  31. if ("value" in descriptor) {
  32. descriptor.writable = true
  33. }
  34. Object.defineProperty(target, descriptor.key, descriptor)
  35. }
  36. }
  37. function _createClass(Constructor, protoProps, staticProps) {
  38. if (protoProps) {
  39. _defineProperties(Constructor.prototype, protoProps)
  40. }
  41. if (staticProps) {
  42. _defineProperties(Constructor, staticProps)
  43. }
  44. Object.defineProperty(Constructor, "prototype", {
  45. writable: false
  46. });
  47. return Constructor
  48. }
  49. var animation = {
  50. moveTo: function(config) {
  51. var $element = config.$element;
  52. var position = config.position;
  53. var direction = config.direction || "left";
  54. var toConfig = {};
  55. var animationType;
  56. if ("right" === direction) {
  57. toConfig.transform = "translate(" + position + "px, 0px)";
  58. animationType = "custom"
  59. }
  60. if ("left" === direction) {
  61. toConfig.left = position;
  62. animationType = "slide"
  63. }
  64. if ("top" === direction || "bottom" === direction) {
  65. toConfig.top = position;
  66. animationType = "slide"
  67. }
  68. _fx2.default.animate($element, {
  69. type: animationType,
  70. to: toConfig,
  71. duration: config.duration,
  72. complete: config.complete
  73. })
  74. },
  75. margin: function margin(config) {
  76. var $element = config.$element;
  77. var margin = config.margin;
  78. var direction = config.direction || "left";
  79. var toConfig = {};
  80. toConfig["margin" + (0, _inflector.camelize)(direction, true)] = margin;
  81. _fx2.default.animate($element, {
  82. to: toConfig,
  83. duration: config.duration,
  84. complete: config.complete
  85. })
  86. },
  87. fade: function($element, config, duration, completeAction) {
  88. _fx2.default.animate($element, {
  89. type: "fade",
  90. to: config.to,
  91. from: config.from,
  92. duration: duration,
  93. complete: completeAction
  94. })
  95. },
  96. size: function size(config) {
  97. var $element = config.$element;
  98. var size = config.size;
  99. var direction = config.direction || "left";
  100. var marginTop = config.marginTop || 0;
  101. var duration = config.duration;
  102. var toConfig = {};
  103. if ("right" === direction || "left" === direction) {
  104. toConfig.width = size
  105. } else {
  106. toConfig.height = size
  107. }
  108. if ("bottom" === direction) {
  109. toConfig.marginTop = marginTop
  110. }
  111. _fx2.default.animate($element, {
  112. to: toConfig,
  113. duration: duration,
  114. complete: config.complete
  115. })
  116. },
  117. complete: function($element) {
  118. _fx2.default.stop($element, true)
  119. }
  120. };
  121. var DrawerStrategy = function() {
  122. function DrawerStrategy(drawer) {
  123. _classCallCheck(this, DrawerStrategy);
  124. this._drawer = drawer
  125. }
  126. _createClass(DrawerStrategy, [{
  127. key: "getDrawerInstance",
  128. value: function() {
  129. return this._drawer
  130. }
  131. }, {
  132. key: "renderPanel",
  133. value: function(template, whenPanelRendered) {
  134. template && template.render({
  135. container: this.getDrawerInstance().content(),
  136. onRendered: function() {
  137. whenPanelRendered.resolve()
  138. }
  139. })
  140. }
  141. }, {
  142. key: "renderPosition",
  143. value: function(offset, animate) {
  144. var drawer = this.getDrawerInstance();
  145. var revealMode = drawer.option("revealMode");
  146. this.prepareAnimationDeferreds(animate);
  147. var config = this.getPositionRenderingConfig(offset);
  148. if (this.useDefaultAnimation()) {
  149. this.defaultPositionRendering(config, offset, animate)
  150. } else {
  151. if ("slide" === revealMode) {
  152. this.slidePositionRendering(config, offset, animate)
  153. }
  154. if ("expand" === revealMode) {
  155. this.expandPositionRendering(config, offset, animate)
  156. }
  157. }
  158. }
  159. }, {
  160. key: "prepareAnimationDeferreds",
  161. value: function(animate) {
  162. var drawer = this.getDrawerInstance();
  163. this._contentAnimation = new _deferred.Deferred;
  164. this._panelAnimation = new _deferred.Deferred;
  165. this._shaderAnimation = new _deferred.Deferred;
  166. drawer._animations.push(this._contentAnimation, this._panelAnimation, this._shaderAnimation);
  167. if (animate) {
  168. _deferred.when.apply(_renderer2.default, drawer._animations).done(function() {
  169. drawer._animationCompleteHandler()
  170. })
  171. } else {
  172. drawer.resizeContent()
  173. }
  174. }
  175. }, {
  176. key: "getPositionRenderingConfig",
  177. value: function(offset) {
  178. var drawer = this.getDrawerInstance();
  179. return {
  180. direction: drawer.getDrawerPosition(),
  181. $panel: (0, _renderer2.default)(drawer.content()),
  182. $content: (0, _renderer2.default)(drawer.viewContent()),
  183. defaultAnimationConfig: this._defaultAnimationConfig(),
  184. size: this._getPanelSize(offset)
  185. }
  186. }
  187. }, {
  188. key: "useDefaultAnimation",
  189. value: function() {
  190. return false
  191. }
  192. }, {
  193. key: "_elementsAnimationCompleteHandler",
  194. value: function() {
  195. this._contentAnimation.resolve();
  196. this._panelAnimation.resolve()
  197. }
  198. }, {
  199. key: "_defaultAnimationConfig",
  200. value: function() {
  201. var _this = this;
  202. return {
  203. complete: function() {
  204. _this._elementsAnimationCompleteHandler()
  205. }
  206. }
  207. }
  208. }, {
  209. key: "_getPanelOffset",
  210. value: function(offset) {
  211. var drawer = this.getDrawerInstance();
  212. var size = drawer.isHorizontalDirection() ? drawer.getRealPanelWidth() : drawer.getRealPanelHeight();
  213. if (offset) {
  214. return -(size - drawer.getMaxSize())
  215. } else {
  216. return -(size - drawer.getMinSize())
  217. }
  218. }
  219. }, {
  220. key: "_getPanelSize",
  221. value: function(offset) {
  222. return offset ? this.getDrawerInstance().getMaxSize() : this.getDrawerInstance().getMinSize()
  223. }
  224. }, {
  225. key: "renderShaderVisibility",
  226. value: function(offset, animate, duration) {
  227. var _this2 = this;
  228. var fadeConfig = this._getFadeConfig(offset);
  229. var drawer = this.getDrawerInstance();
  230. if (animate) {
  231. animation.fade((0, _renderer2.default)(drawer._$shader), fadeConfig, duration, function() {
  232. _this2._drawer._toggleShaderVisibility(offset);
  233. _this2._shaderAnimation.resolve()
  234. })
  235. } else {
  236. drawer._toggleShaderVisibility(offset);
  237. drawer._$shader.css("opacity", fadeConfig.to)
  238. }
  239. }
  240. }, {
  241. key: "_getFadeConfig",
  242. value: function(offset) {
  243. if (offset) {
  244. return {
  245. to: 1,
  246. from: 0
  247. }
  248. } else {
  249. return {
  250. to: 0,
  251. from: 1
  252. }
  253. }
  254. }
  255. }, {
  256. key: "getPanelContent",
  257. value: function() {
  258. return (0, _renderer2.default)(this.getDrawerInstance().content())
  259. }
  260. }, {
  261. key: "getWidth",
  262. value: function() {
  263. return this.getDrawerInstance().$element().get(0).getBoundingClientRect().width
  264. }
  265. }, {
  266. key: "setPanelSize",
  267. value: function(keepMaxSize) {
  268. var drawer = this.getDrawerInstance();
  269. var panelSize = this._getPanelSize(drawer.option("opened"));
  270. if (drawer.isHorizontalDirection()) {
  271. (0, _renderer2.default)(drawer.content()).width(keepMaxSize ? drawer.getRealPanelWidth() : panelSize)
  272. } else {
  273. (0, _renderer2.default)(drawer.content()).height(keepMaxSize ? drawer.getRealPanelHeight() : panelSize)
  274. }
  275. }
  276. }, {
  277. key: "needOrderContent",
  278. value: function() {
  279. return false
  280. }
  281. }]);
  282. return DrawerStrategy
  283. }();
  284. module.exports = DrawerStrategy;
  285. module.exports.animation = animation;