API Docs for: 3.17.2
Show:

File: resize/js/resize-proxy.js

  1. var ACTIVE_HANDLE_NODE = 'activeHandleNode',
  2. CURSOR = 'cursor',
  3. DRAG_CURSOR = 'dragCursor',
  4. HOST = 'host',
  5. PARENT_NODE = 'parentNode',
  6. PROXY = 'proxy',
  7. PROXY_NODE = 'proxyNode',
  8. RESIZE = 'resize',
  9. RESIZE_PROXY = 'resize-proxy',
  10. WRAPPER = 'wrapper',
  11.  
  12. getCN = Y.ClassNameManager.getClassName,
  13.  
  14. CSS_RESIZE_PROXY = getCN(RESIZE, PROXY);
  15.  
  16.  
  17. /**
  18. Adds a `proxyNode` attribute and resizes it instead of the actual node. __very similar to DDProxy__
  19.  
  20. var resize = new Y.Resize({
  21. //Selector of the node to resize
  22. node: '#demo'
  23. });
  24. resize.plug(Y.Plugin.ResizeProxy);
  25.  
  26.  
  27. @class ResizeProxy
  28. @module resize
  29. @submodule resize-proxy
  30. @constructor
  31. @extends Plugin.Base
  32. @namespace Plugin
  33. */
  34.  
  35.  
  36. function ResizeProxy() {
  37. ResizeProxy.superclass.constructor.apply(this, arguments);
  38. }
  39.  
  40. Y.mix(ResizeProxy, {
  41. NAME: RESIZE_PROXY,
  42.  
  43. NS: PROXY,
  44.  
  45. ATTRS: {
  46. /**
  47. * The Resize proxy element.
  48. *
  49. * @attribute proxyNode
  50. * @default Generated using an internal HTML markup
  51. * @type String|Node
  52. */
  53. proxyNode: {
  54. setter: Y.one,
  55. valueFn: function() {
  56. return Y.Node.create(this.PROXY_TEMPLATE);
  57. }
  58. }
  59. }
  60. });
  61.  
  62. Y.extend(ResizeProxy, Y.Plugin.Base, {
  63. /**
  64. * Template used to create the resize proxy.
  65. *
  66. * @property PROXY_TEMPLATE
  67. * @type {String}
  68. */
  69. PROXY_TEMPLATE: '<div class="'+CSS_RESIZE_PROXY+'"></div>',
  70.  
  71. initializer: function() {
  72. var instance = this;
  73.  
  74. instance.afterHostEvent('resize:start', instance._afterResizeStart);
  75. instance.beforeHostMethod('_resize', instance._beforeHostResize);
  76. instance.afterHostMethod('_resizeEnd', instance._afterHostResizeEnd);
  77. },
  78.  
  79. destructor: function() {
  80. var instance = this;
  81.  
  82. instance.get(PROXY_NODE).remove(true);
  83. },
  84.  
  85. _afterHostResizeEnd: function(event) {
  86. var instance = this,
  87. drag = event.dragEvent.target;
  88.  
  89. // reseting actXY from drag when drag end
  90. drag.actXY = [];
  91.  
  92. // if proxy is true, hide it on resize end
  93. instance._syncProxyUI();
  94.  
  95. instance.get(PROXY_NODE).hide();
  96. },
  97.  
  98. _afterResizeStart: function() {
  99. var instance = this;
  100.  
  101. instance._renderProxy();
  102. },
  103.  
  104. _beforeHostResize: function(event) {
  105. var instance = this,
  106. host = this.get(HOST);
  107.  
  108. host._handleResizeAlignEvent(event.dragEvent);
  109.  
  110. // if proxy is true _syncProxyUI instead of _syncUI
  111. instance._syncProxyUI();
  112.  
  113. return new Y.Do.Prevent();
  114. },
  115.  
  116. /**
  117. * Render the <a href="ResizeProxy.html#attr_proxyNode">proxyNode</a> element and
  118. * make it sibling of the <a href="Resize.html#attr_node">node</a>.
  119. *
  120. * @method _renderProxy
  121. * @protected
  122. */
  123. _renderProxy: function() {
  124. var instance = this,
  125. host = this.get(HOST),
  126. proxyNode = instance.get(PROXY_NODE);
  127.  
  128. if (!proxyNode.inDoc()) {
  129. host.get(WRAPPER).get(PARENT_NODE).append(
  130. proxyNode.hide()
  131. );
  132. }
  133. },
  134.  
  135. /**
  136. * Sync the proxy UI with internal values from
  137. * <a href="ResizeProxy.html#property_info">info</a>.
  138. *
  139. * @method _syncProxyUI
  140. * @protected
  141. */
  142. _syncProxyUI: function() {
  143. var instance = this,
  144. host = this.get(HOST),
  145. info = host.info,
  146. activeHandleNode = host.get(ACTIVE_HANDLE_NODE),
  147. proxyNode = instance.get(PROXY_NODE),
  148. cursor = activeHandleNode.getStyle(CURSOR);
  149.  
  150. proxyNode.show().setStyle(CURSOR, cursor);
  151.  
  152. host.delegate.dd.set(DRAG_CURSOR, cursor);
  153.  
  154. proxyNode.sizeTo(info.offsetWidth, info.offsetHeight);
  155.  
  156. proxyNode.setXY([ info.left, info.top ]);
  157. }
  158. });
  159.  
  160. Y.namespace('Plugin');
  161. Y.Plugin.ResizeProxy = ResizeProxy;
  162.