Requires

Provides

Resizable.js

Resize widget with the mouse freely

License:
Public domain (http://unlicense.org).
Authors:
Yaroslaff Fedin
  1. 23
  2. 24
  3. 25
  4. 26
  5. 27
  6. 28
  7. 29
  8. 30
  9. 31
  10. 32
  11. 33
  12. 34
  13. 35
  14. 36
  15. 37
  16. 38
  17. 39
  18. 40
  19. 41
  20. 42
  21. 43
  22. 44
  23. 45
  24. 46
  25. 47
  26. 48
  27. 49
  28. 50
  29. 51
  30. 52
  31. 53
  32. 54
  33. 55
  34. 56
  35. 57
  36. 58
  37. 59
  38. 60
  39. 61
  40. 62
  41. 63
  42. 64
  43. 65
  44. 66
  45. 67
  46. 68
  47. 69
  48. 70
  49. 71
  50. 72
  51. 73
  52. 74
  53. 75
  54. 76
  55. 77
  56. 78
  57. 79
  58. 80
  59. 81
  60. 82
  61. 83
  62. 84
  63. 85
  64. 86
  65. 87
  66. 88
  67. 89
  68. 90
  69. 91
  70. 92
  71. 93
  72. 94
  73. 95
  74. 96
  75. 97
  76. 98
  77. 99
  78. 100
  79. 101
  80. 102
  81. 103
  82. 104
  83. 105
  84. 106
  85. 107
  86. 108
  87. 109
  88. 110
  89. 111
  90. 112
  91. 113
  92. 114
  93. 115
  94. 116
  95. 117
  96. 118
  97. 119
  98. 120
  99. 121
  100. 122
  101. 123
  102. 124
  103. 125
  104. 126
  105. 127
  106. 128
  107. 129
  108. 130
  109. 131
  110. 132
  111. 133
  112. 134
  113. 135
  114. 136
  115. 137
  116. 138
  117. 139
  118. 140
  119. 141
  120. 142
  121. 143
  122. 144
  123. 145
  124. 146
  125. 147
  126. 148
  127. 149
  128. 150
  129. 151
  130. 152
  131. 153
  132. 154
  133. 155
  134. 156
  135. 157
  136. 158
  137. 159
  138. 160
  139. 161
  140. 162
  141. 163
  142. 164
  143. 165
  144. 166
  145. 167
  146. 168
  147. 169
  148. 170
  149. 171
  150. 172
  151. 173
  152. 174
  153. 175
  154. 176
  155. 177
  156. 178
  157. 179
  158. 180
LSD.Mixin.Resizable = new Class({ behaviour: '[resizable][resizable!=false]', options: { resizer: { modifiers: { x: 'width', y: 'height' }, snap: false, style: false, crop: false, handle: [], container: true, limit: { x: [0, 3000], y: [0, 3000] }, }, actions: { resizable: { enable: function(handle, resizable) { this.handle = handle; this.resized = resizable || this; this.onStateChange('resizable', true); var resizer = this.resizer; if (resizer == this.getResizer(document.id(this.resized))) resizer.attach(); if (handle) document.id(handle).addEvent('mousedown', this.resizer.bound.start); if (this.options.resizer.fit) this.fit(resizable) }, disable: function(handle, content) { this.onStateChange('resizable', false); if (this.resizer) this.resizer.detach(); if (handle) document.id(handle).removeEvent('mousedown', this.resizer.bound.start); delete this.resized, this.handle; }, } } }, initialize: function() { this.parent.apply(this, arguments); var options = this.options.resizer; var rules = (new FastArray).concat(this.getAttribute('resizable').split(/\s+/)); options.modifiers.x = (!rules.x && rules.y) ? false : 'width'; options.modifiers.y = (!rules.y && rules.x) ? false : 'height'; options.fit = !!rules.fit; }, uninitialize: function() { if (this.handle) this.options.actions.resizable.disable.call(this, this.handle, this.resized); delete this.resizer; }, getResizer: function(resized) { var element = resized if (this.resizer) { if (this.resizer.element == element) return this.resizer; return this.resizer.element = element; } var resizer = this.resizer = new Drag(element, Object.append(this.options, this.options.resizer)); resizer.addEvents(this.events.resizer); resizer.addEvents({ 'beforeStart': this.onBeforeResize.bind(this), 'start': this.onResizeStart.bind(this), 'complete': this.onResizeComplete.bind(this), 'cancel': this.onResizeComplete.bind(this), 'drag': this.onResize.bind(this) }, true); return resizer; }, check: function(size) { if (!this.resizer) return; var width = this.element.offsetWidth - this.offset.inner.left - this.offset.inner.right; if (!size) size = {width: this.resized.toElement().width} if (size.width < width) { if (!$chk(this.limit)) this.limit = this.resized.getStyle('minWidth') || 1 this.resized.setStyle('minWidth', width); $clear(this.delay); this.delay = (function() { //reset limit options in one second this.resized.setStyle('minWidth', this.limit); }).delay(1000, this); size.width = width; } return size; }, onBeforeResize: function() { Object.append(this.resized.toElement(), this.resized.size) }, onResizeStart: function() { this.onStateChange('resized', true); var getLiquid = function(child, prop) { var value = child.style.current[prop]; return ((value == 'inherit') || (value == 'auto') || child.style.expressed[prop]) ? value : null } if (!this.liquid) { this.liquid = this.collect(function(c) { return getLiquid(c, 'width')}).include(this.resized); if (this.resized != this) { var style = this.resized.style.liquid = {}; var width = getLiquid(this.resized, 'width'); if (width) style.width = width; var height = getLiquid(this.resized, 'height'); if (height) style.height = height; } } }, onResizeComplete: function() { if (this.resized.style.liquid) this.resized.setStyles(this.resized.style.liquid); this.onStateChange('resized', false); delete this.liquid }, onResize: function() { var now = this.resizer.value.now; var resized = this.resized; if (!resized.style.dimensions) { resized.style.dimensions = {}; var width = resized.style.current.width if (width == 'auto') resized.style.dimensions.width = 'auto'; var height = resized.toElement().getStyle('height'); if (height == 'auto') resized.style.dimensions.height = 'auto'; } if (!now.x) now.x = resized.size.width; if (!now.y) now.y = resized.size.height; var size = this.check({width: resized.setWidth(now.x) || now.x, height: resized.setHeight(now.y) || now.y}); resized.setStyles(size); if (this.liquid) { this.liquid.each(function(child) { child.update(); }) } this.refresh(); }, fit: function(content) { if (!content) content = this.resized; var element = content.getWrapper(); var display = element.getStyle('display'); if (display != 'inline-block') element.setStyle('display', 'inline-block'); var width = element.offsetWidth; var height = element.offsetHeight; element.setStyle('display', display) content.setHeight(height); content.setWidth(width); this.refresh({ maxWidth: width, maxHeight: height }); }, getScrolled: function() { return this.resized.getWrapper(); } });