rich_cms 2.1.7 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. data/{CHANGELOG → CHANGELOG.rdoc} +24 -0
  2. data/README.textile +49 -33
  3. data/Rakefile +92 -10
  4. data/VERSION +1 -1
  5. data/app/controllers/rich/cms_controller.rb +10 -39
  6. data/app/controllers/rich/cms_sessions_controller.rb +31 -0
  7. data/app/views/rich/cms/dock/_menu.html.erb +10 -8
  8. data/app/views/rich/cms/dock/_panel.html.erb +1 -1
  9. data/app/views/rich/cms/dock/panel/edit/_rails2.html.erb +5 -3
  10. data/app/views/rich/cms/dock/panel/edit/_rails3.html.erb +4 -2
  11. data/app/views/rich/cms/dock/panel/login/_rails2.html.erb +18 -12
  12. data/app/views/rich/cms/dock/panel/login/_rails3.html.erb +18 -12
  13. data/app/views/rich_cms.html.erb +1 -1
  14. data/assets/jzip/jquery/cleditor.js +1132 -1132
  15. data/assets/jzip/jquery/extensions/browser_detect.js +1 -2
  16. data/assets/jzip/native/extensions.js +41 -0
  17. data/assets/jzip/rich/cms/editor.js +41 -7
  18. data/assets/jzip/rich_cms.jz +2 -1
  19. data/assets/sass/rich_cms/_panel.sass +11 -1
  20. data/config/routes.rb +12 -11
  21. data/lib/generators/rich/cms_admin/cms_admin_generator.rb +82 -0
  22. data/lib/generators/rich/{authlogic_user/templates → cms_admin/templates/authlogic}/migration.rb +0 -0
  23. data/lib/generators/rich/{authlogic_user/templates → cms_admin/templates/authlogic}/model.rb +0 -0
  24. data/lib/generators/rich/{authlogic_user/templates → cms_admin/templates/authlogic}/session.rb +0 -0
  25. data/lib/rich/cms/actionpack/action_controller/base.rb +3 -44
  26. data/lib/rich/cms/actionpack/action_view/base.rb +32 -10
  27. data/lib/rich/cms/actionpack.rb +1 -2
  28. data/lib/rich/cms/auth.rb +110 -0
  29. data/lib/rich/cms/content/group.rb +1 -2
  30. data/lib/rich/cms/content/item.rb +2 -3
  31. data/lib/rich/cms/core/string/html_safe.rb +1 -2
  32. data/lib/rich/cms/core/string.rb +1 -2
  33. data/lib/rich/cms/engine.rb +23 -51
  34. data/lib/rich/cms/rails/engine.rb +1 -2
  35. data/lib/rich/cms/version.rb +11 -0
  36. data/lib/rich_cms.rb +2 -2
  37. data/rails_generators/rich_cms_admin/lib/devise/route_devise.rb +32 -0
  38. data/rails_generators/rich_cms_admin/rich_cms_admin_generator.rb +113 -0
  39. data/rails_generators/{rich_authlogic_user/templates → rich_cms_admin/templates/authlogic}/migration.rb +0 -0
  40. data/rails_generators/{rich_authlogic_user/templates → rich_cms_admin/templates/authlogic}/model.rb +0 -0
  41. data/rails_generators/{rich_authlogic_user/templates → rich_cms_admin/templates/authlogic}/session.rb +0 -0
  42. data/rails_generators/{rich_authlogic_user → rich_cms_admin}/templates/config.rb +0 -0
  43. data/rails_generators/rich_cms_admin/templates/devise/README +23 -0
  44. data/rails_generators/rich_cms_admin/templates/devise/devise.rb +105 -0
  45. data/rails_generators/rich_cms_admin/templates/devise/en.yml +35 -0
  46. data/rails_generators/rich_cms_admin/templates/devise/migration.rb +23 -0
  47. data/rails_generators/rich_cms_admin/templates/devise/model.rb +9 -0
  48. data/rails_generators/rich_cms_content/rich_cms_content_generator.rb +18 -12
  49. data/rich_cms.gemspec +295 -105
  50. data/test/integrator.rb +89 -0
  51. data/test/rails-2/dummy/.bundle/config +2 -0
  52. data/test/rails-2/dummy/Gemfile +15 -0
  53. data/test/rails-2/dummy/Gemfile.lock +97 -0
  54. data/test/rails-2/dummy/Rakefile +10 -0
  55. data/test/rails-2/dummy/app/controllers/application_controller.rb +10 -0
  56. data/test/rails-2/dummy/app/helpers/application_helper.rb +3 -0
  57. data/test/rails-2/dummy/config/boot.rb +124 -0
  58. data/test/rails-2/dummy/config/database.yml +23 -0
  59. data/test/rails-2/dummy/config/environment.rb +41 -0
  60. data/test/rails-2/dummy/config/environments/development.rb +17 -0
  61. data/test/rails-2/dummy/config/environments/production.rb +28 -0
  62. data/test/rails-2/dummy/config/environments/test.rb +28 -0
  63. data/test/rails-2/dummy/config/initializers/backtrace_silencers.rb +7 -0
  64. data/test/rails-2/dummy/config/initializers/cookie_verification_secret.rb +7 -0
  65. data/test/rails-2/dummy/config/initializers/devise.rb +105 -0
  66. data/test/rails-2/dummy/config/initializers/enrichments.rb +5 -0
  67. data/test/rails-2/dummy/config/initializers/inflections.rb +10 -0
  68. data/test/rails-2/dummy/config/initializers/mime_types.rb +5 -0
  69. data/test/rails-2/dummy/config/initializers/new_rails_defaults.rb +21 -0
  70. data/test/rails-2/dummy/config/initializers/session_store.rb +15 -0
  71. data/test/rails-2/dummy/config/locales/en.yml +5 -0
  72. data/test/rails-2/dummy/config/preinitializer.rb +20 -0
  73. data/test/rails-2/dummy/config/routes.rb +44 -0
  74. data/test/rails-2/dummy/db/schema.rb +49 -0
  75. data/test/rails-2/dummy/db/seeds.rb +10 -0
  76. data/test/rails-2/dummy/public/404.html +30 -0
  77. data/test/rails-2/dummy/public/422.html +30 -0
  78. data/test/rails-2/dummy/public/500.html +30 -0
  79. data/test/rails-2/dummy/public/favicon.ico +0 -0
  80. data/test/rails-2/dummy/public/images/rails.png +0 -0
  81. data/test/rails-2/dummy/public/images/rich/cms/cleditor/buttons.gif +0 -0
  82. data/test/rails-2/dummy/public/images/rich/cms/cleditor/toolbar.gif +0 -0
  83. data/test/rails-2/dummy/public/javascripts/jquery/core.js +158 -0
  84. data/test/rails-2/dummy/public/javascripts/jquery/ui/rich_cms/core.js +1207 -0
  85. data/test/rails-2/dummy/public/javascripts/jquery/ui/rich_cms/draggable.js +798 -0
  86. data/test/rails-2/dummy/public/javascripts/jquery/ui/rich_cms/mouse.js +950 -0
  87. data/test/rails-2/dummy/public/javascripts/jquery/ui/rich_cms/widget.js +1188 -0
  88. data/test/rails-2/dummy/public/javascripts/rich_cms.js +1746 -0
  89. data/test/rails-2/dummy/public/robots.txt +5 -0
  90. data/test/rails-2/dummy/script/about +4 -0
  91. data/test/rails-2/dummy/script/console +3 -0
  92. data/test/rails-2/dummy/script/dbconsole +3 -0
  93. data/test/rails-2/dummy/script/destroy +3 -0
  94. data/test/rails-2/dummy/script/generate +3 -0
  95. data/test/rails-2/dummy/script/performance/benchmarker +3 -0
  96. data/test/rails-2/dummy/script/performance/profiler +3 -0
  97. data/test/rails-2/dummy/script/plugin +3 -0
  98. data/test/rails-2/dummy/script/runner +3 -0
  99. data/test/rails-2/dummy/script/server +3 -0
  100. data/test/rails-2/dummy/test/fixtures/authlogic_users.yml +6 -0
  101. data/test/rails-2/dummy/test/fixtures/devise_users.yml +5 -0
  102. data/test/rails-2/pending.rb +88 -0
  103. data/test/rails-2/test_helper.rb +13 -0
  104. data/test/rails-3/dummy/.bundle/config +2 -0
  105. data/test/rails-3/dummy/Gemfile +15 -0
  106. data/test/rails-3/dummy/Gemfile.lock +139 -0
  107. data/test/rails-3/dummy/Rakefile +7 -0
  108. data/test/rails-3/dummy/app/controllers/application_controller.rb +3 -0
  109. data/test/rails-3/dummy/app/helpers/application_helper.rb +2 -0
  110. data/test/rails-3/dummy/config/application.rb +42 -0
  111. data/test/rails-3/dummy/config/boot.rb +13 -0
  112. data/test/rails-3/dummy/config/database.yml +23 -0
  113. data/test/rails-3/dummy/config/environment.rb +5 -0
  114. data/test/rails-3/dummy/config/environments/development.rb +26 -0
  115. data/test/rails-3/dummy/config/environments/production.rb +49 -0
  116. data/test/rails-3/dummy/config/environments/test.rb +35 -0
  117. data/test/rails-3/dummy/config/initializers/backtrace_silencers.rb +7 -0
  118. data/test/rails-3/dummy/config/initializers/devise.rb +142 -0
  119. data/test/rails-3/dummy/config/initializers/enrichments.rb +5 -0
  120. data/test/rails-3/dummy/config/initializers/inflections.rb +10 -0
  121. data/test/rails-3/dummy/config/initializers/mime_types.rb +5 -0
  122. data/test/rails-3/dummy/config/initializers/secret_token.rb +7 -0
  123. data/test/rails-3/dummy/config/initializers/session_store.rb +8 -0
  124. data/test/rails-3/dummy/config/locales/en.yml +5 -0
  125. data/test/rails-3/dummy/config/routes.rb +59 -0
  126. data/test/rails-3/dummy/config.ru +4 -0
  127. data/test/rails-3/dummy/db/schema.rb +49 -0
  128. data/test/rails-3/dummy/db/seeds.rb +10 -0
  129. data/test/rails-3/dummy/public/404.html +26 -0
  130. data/test/rails-3/dummy/public/422.html +26 -0
  131. data/test/rails-3/dummy/public/500.html +26 -0
  132. data/test/rails-3/dummy/public/favicon.ico +0 -0
  133. data/test/rails-3/dummy/public/images/rich/cms/cleditor/buttons.gif +0 -0
  134. data/test/rails-3/dummy/public/images/rich/cms/cleditor/toolbar.gif +0 -0
  135. data/test/rails-3/dummy/public/javascripts/jquery/core.js +158 -0
  136. data/test/rails-3/dummy/public/javascripts/jquery/ui/rich_cms/core.js +1207 -0
  137. data/test/rails-3/dummy/public/javascripts/jquery/ui/rich_cms/draggable.js +798 -0
  138. data/test/rails-3/dummy/public/javascripts/jquery/ui/rich_cms/mouse.js +950 -0
  139. data/test/rails-3/dummy/public/javascripts/jquery/ui/rich_cms/widget.js +1188 -0
  140. data/test/rails-3/dummy/public/javascripts/rich_cms.js +1746 -0
  141. data/test/rails-3/dummy/script/rails +6 -0
  142. data/test/rails-3/dummy/test/fixtures/authlogic_users.yml +6 -0
  143. data/test/rails-3/dummy/test/fixtures/devise_users.yml +5 -0
  144. data/test/rails-3/test_helper.rb +17 -0
  145. data/test/shared/dummy/db/schema.rb +49 -0
  146. data/test/shared/dummy/db/seeds.rb +10 -0
  147. data/test/shared/dummy/fixtures/authlogic_users.yml +6 -0
  148. data/test/shared/dummy/models/authlogic_user.rb +8 -0
  149. data/test/shared/dummy/models/authlogic_user_session.rb +10 -0
  150. data/test/shared/dummy/models/cms_content.rb +2 -0
  151. data/test/shared/dummy/models/devise_user.rb +3 -0
  152. data/test/shared/dummy/stylesheets/app.css +100 -0
  153. data/test/shared/dummy/stylesheets/rich_cms.css +159 -0
  154. data/test/shared/dummy/views/application/index.html.erb +13 -0
  155. data/test/shared/dummy/views/layouts/application.html.erb +12 -0
  156. data/test/shared/support/action_controller/integration.rb +55 -0
  157. data/test/shared/support/action_controller/test_case.rb +28 -0
  158. data/test/shared/support/capybara/setup.rb +14 -0
  159. data/test/shared/support/test_helper.rb +1 -0
  160. data/test/shared/tests/actionpack/action_controller/base_test.rb +14 -0
  161. data/test/shared/tests/actionpack/action_view/base_test.rb +19 -0
  162. data/test/shared/tests/activesupport/active_support/dependencies_test.rb +15 -0
  163. data/test/shared/tests/app/integration/authenticated/authlogic.rb +88 -0
  164. data/test/shared/tests/app/integration/authenticated/devise_test.rb +89 -0
  165. data/test/shared/tests/app/integration/non_authenticated.rb +63 -0
  166. data/test/shared/tests/app/routing_test.rb +31 -0
  167. data/test/shared/tests/auth_test.rb +11 -0
  168. data/test/shared/tests/content/group.rb +10 -0
  169. data/test/shared/tests/content/item.rb +10 -0
  170. data/test/shared/tests/core/string/html_safe.rb +15 -0
  171. data/test/shared/tests/dummy_app.rb +228 -0
  172. data/test/shared/tests/engine_test.rb +19 -0
  173. data/test/shared/tests/rails/engine_test.rb +13 -0
  174. data/test/shared/tests/readme_test.rb +13 -0
  175. metadata +231 -63
  176. data/.gitignore +0 -2
  177. data/lib/generators/rich/authlogic_user/authlogic_user_generator.rb +0 -64
  178. data/rails_generators/rich_authlogic_user/rich_authlogic_user_generator.rb +0 -64
  179. data/test/test_helper.rb +0 -6
@@ -0,0 +1,950 @@
1
+
2
+ /*!
3
+ * jQuery UI Mouse 1.8.4
4
+ *
5
+ * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
6
+ * Dual licensed under the MIT or GPL Version 2 licenses.
7
+ * http://jquery.org/license
8
+ *
9
+ * http://docs.jquery.com/UI/Mouse
10
+ *
11
+ * Depends:
12
+ * jquery.ui.widget.js
13
+ */
14
+ (function( $, undefined ) {
15
+
16
+ $.widget("ui.mouse", {
17
+ options: {
18
+ cancel: ':input,option',
19
+ distance: 1,
20
+ delay: 0
21
+ },
22
+ _mouseInit: function() {
23
+ var self = this;
24
+
25
+ this.element
26
+ .bind('mousedown.'+this.widgetName, function(event) {
27
+ return self._mouseDown(event);
28
+ })
29
+ .bind('click.'+this.widgetName, function(event) {
30
+ if(self._preventClickEvent) {
31
+ self._preventClickEvent = false;
32
+ event.stopImmediatePropagation();
33
+ return false;
34
+ }
35
+ });
36
+
37
+ this.started = false;
38
+ },
39
+
40
+ // TODO: make sure destroying one instance of mouse doesn't mess with
41
+ // other instances of mouse
42
+ _mouseDestroy: function() {
43
+ this.element.unbind('.'+this.widgetName);
44
+ },
45
+
46
+ _mouseDown: function(event) {
47
+ // don't let more than one widget handle mouseStart
48
+ // TODO: figure out why we have to use originalEvent
49
+ event.originalEvent = event.originalEvent || {};
50
+ if (event.originalEvent.mouseHandled) { return; }
51
+
52
+ // we may have missed mouseup (out of window)
53
+ (this._mouseStarted && this._mouseUp(event));
54
+
55
+ this._mouseDownEvent = event;
56
+
57
+ var self = this,
58
+ btnIsLeft = (event.which == 1),
59
+ elIsCancel = (typeof this.options.cancel == "string" ? $(event.target).parents().add(event.target).filter(this.options.cancel).length : false);
60
+ if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
61
+ return true;
62
+ }
63
+
64
+ this.mouseDelayMet = !this.options.delay;
65
+ if (!this.mouseDelayMet) {
66
+ this._mouseDelayTimer = setTimeout(function() {
67
+ self.mouseDelayMet = true;
68
+ }, this.options.delay);
69
+ }
70
+
71
+ if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
72
+ this._mouseStarted = (this._mouseStart(event) !== false);
73
+ if (!this._mouseStarted) {
74
+ event.preventDefault();
75
+ return true;
76
+ }
77
+ }
78
+
79
+ // these delegates are required to keep context
80
+ this._mouseMoveDelegate = function(event) {
81
+ return self._mouseMove(event);
82
+ };
83
+ this._mouseUpDelegate = function(event) {
84
+ return self._mouseUp(event);
85
+ };
86
+ $(document)
87
+ .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
88
+ .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
89
+
90
+ // preventDefault() is used to prevent the selection of text here -
91
+ // however, in Safari, this causes select boxes not to be selectable
92
+ // anymore, so this fix is needed
93
+ ($.browser.safari || event.preventDefault());
94
+
95
+ event.originalEvent.mouseHandled = true;
96
+ return true;
97
+ },
98
+
99
+ _mouseMove: function(event) {
100
+ // IE mouseup check - mouseup happened when mouse was out of window
101
+ if ($.browser.msie && !event.button) {
102
+ return this._mouseUp(event);
103
+ }
104
+
105
+ if (this._mouseStarted) {
106
+ this._mouseDrag(event);
107
+ return event.preventDefault();
108
+ }
109
+
110
+ if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
111
+ this._mouseStarted =
112
+ (this._mouseStart(this._mouseDownEvent, event) !== false);
113
+ (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
114
+ }
115
+
116
+ return !this._mouseStarted;
117
+ },
118
+
119
+ _mouseUp: function(event) {
120
+ $(document)
121
+ .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
122
+ .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
123
+
124
+ if (this._mouseStarted) {
125
+ this._mouseStarted = false;
126
+ this._preventClickEvent = (event.target == this._mouseDownEvent.target);
127
+ this._mouseStop(event);
128
+ }
129
+
130
+ return false;
131
+ },
132
+
133
+ _mouseDistanceMet: function(event) {
134
+ return (Math.max(
135
+ Math.abs(this._mouseDownEvent.pageX - event.pageX),
136
+ Math.abs(this._mouseDownEvent.pageY - event.pageY)
137
+ ) >= this.options.distance
138
+ );
139
+ },
140
+
141
+ _mouseDelayMet: function(event) {
142
+ return this.mouseDelayMet;
143
+ },
144
+
145
+ // These are placeholder methods, to be overriden by extending plugin
146
+ _mouseStart: function(event) {},
147
+ _mouseDrag: function(event) {},
148
+ _mouseStop: function(event) {},
149
+ _mouseCapture: function(event) { return true; }
150
+ });
151
+
152
+ })(jQuery);
153
+
154
+ /*
155
+ * jQuery UI Draggable 1.8.4
156
+ *
157
+ * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
158
+ * Dual licensed under the MIT or GPL Version 2 licenses.
159
+ * http://jquery.org/license
160
+ *
161
+ * http://docs.jquery.com/UI/Draggables
162
+ *
163
+ * Depends:
164
+ * jquery.ui.core.js
165
+ * jquery.ui.mouse.js
166
+ * jquery.ui.widget.js
167
+ */
168
+ (function( $, undefined ) {
169
+
170
+ $.widget("ui.draggable", $.ui.mouse, {
171
+ widgetEventPrefix: "drag",
172
+ options: {
173
+ addClasses: true,
174
+ appendTo: "parent",
175
+ axis: false,
176
+ connectToSortable: false,
177
+ containment: false,
178
+ cursor: "auto",
179
+ cursorAt: false,
180
+ grid: false,
181
+ handle: false,
182
+ helper: "original",
183
+ iframeFix: false,
184
+ opacity: false,
185
+ refreshPositions: false,
186
+ revert: false,
187
+ revertDuration: 500,
188
+ scope: "default",
189
+ scroll: true,
190
+ scrollSensitivity: 20,
191
+ scrollSpeed: 20,
192
+ snap: false,
193
+ snapMode: "both",
194
+ snapTolerance: 20,
195
+ stack: false,
196
+ zIndex: false
197
+ },
198
+ _create: function() {
199
+
200
+ if (this.options.helper == 'original' && !(/^(?:r|a|f)/).test(this.element.css("position")))
201
+ this.element[0].style.position = 'relative';
202
+
203
+ (this.options.addClasses && this.element.addClass("ui-draggable"));
204
+ (this.options.disabled && this.element.addClass("ui-draggable-disabled"));
205
+
206
+ this._mouseInit();
207
+
208
+ },
209
+
210
+ destroy: function() {
211
+ if(!this.element.data('draggable')) return;
212
+ this.element
213
+ .removeData("draggable")
214
+ .unbind(".draggable")
215
+ .removeClass("ui-draggable"
216
+ + " ui-draggable-dragging"
217
+ + " ui-draggable-disabled");
218
+ this._mouseDestroy();
219
+
220
+ return this;
221
+ },
222
+
223
+ _mouseCapture: function(event) {
224
+
225
+ var o = this.options;
226
+
227
+ // among others, prevent a drag on a resizable-handle
228
+ if (this.helper || o.disabled || $(event.target).is('.ui-resizable-handle'))
229
+ return false;
230
+
231
+ //Quit if we're not on a valid handle
232
+ this.handle = this._getHandle(event);
233
+ if (!this.handle)
234
+ return false;
235
+
236
+ return true;
237
+
238
+ },
239
+
240
+ _mouseStart: function(event) {
241
+
242
+ var o = this.options;
243
+
244
+ //Create and append the visible helper
245
+ this.helper = this._createHelper(event);
246
+
247
+ //Cache the helper size
248
+ this._cacheHelperProportions();
249
+
250
+ //If ddmanager is used for droppables, set the global draggable
251
+ if($.ui.ddmanager)
252
+ $.ui.ddmanager.current = this;
253
+
254
+ /*
255
+ * - Position generation -
256
+ * This block generates everything position related - it's the core of draggables.
257
+ */
258
+
259
+ //Cache the margins of the original element
260
+ this._cacheMargins();
261
+
262
+ //Store the helper's css position
263
+ this.cssPosition = this.helper.css("position");
264
+ this.scrollParent = this.helper.scrollParent();
265
+
266
+ //The element's absolute position on the page minus margins
267
+ this.offset = this.positionAbs = this.element.offset();
268
+ this.offset = {
269
+ top: this.offset.top - this.margins.top,
270
+ left: this.offset.left - this.margins.left
271
+ };
272
+
273
+ $.extend(this.offset, {
274
+ click: { //Where the click happened, relative to the element
275
+ left: event.pageX - this.offset.left,
276
+ top: event.pageY - this.offset.top
277
+ },
278
+ parent: this._getParentOffset(),
279
+ relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
280
+ });
281
+
282
+ //Generate the original position
283
+ this.originalPosition = this.position = this._generatePosition(event);
284
+ this.originalPageX = event.pageX;
285
+ this.originalPageY = event.pageY;
286
+
287
+ //Adjust the mouse offset relative to the helper if 'cursorAt' is supplied
288
+ (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));
289
+
290
+ //Set a containment if given in the options
291
+ if(o.containment)
292
+ this._setContainment();
293
+
294
+ //Trigger event + callbacks
295
+ if(this._trigger("start", event) === false) {
296
+ this._clear();
297
+ return false;
298
+ }
299
+
300
+ //Recache the helper size
301
+ this._cacheHelperProportions();
302
+
303
+ //Prepare the droppable offsets
304
+ if ($.ui.ddmanager && !o.dropBehaviour)
305
+ $.ui.ddmanager.prepareOffsets(this, event);
306
+
307
+ this.helper.addClass("ui-draggable-dragging");
308
+ this._mouseDrag(event, true); //Execute the drag once - this causes the helper not to be visible before getting its correct position
309
+ return true;
310
+ },
311
+
312
+ _mouseDrag: function(event, noPropagation) {
313
+
314
+ //Compute the helpers position
315
+ this.position = this._generatePosition(event);
316
+ this.positionAbs = this._convertPositionTo("absolute");
317
+
318
+ //Call plugins and callbacks and use the resulting position if something is returned
319
+ if (!noPropagation) {
320
+ var ui = this._uiHash();
321
+ if(this._trigger('drag', event, ui) === false) {
322
+ this._mouseUp({});
323
+ return false;
324
+ }
325
+ this.position = ui.position;
326
+ }
327
+
328
+ if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px';
329
+ if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px';
330
+ if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
331
+
332
+ return false;
333
+ },
334
+
335
+ _mouseStop: function(event) {
336
+
337
+ //If we are using droppables, inform the manager about the drop
338
+ var dropped = false;
339
+ if ($.ui.ddmanager && !this.options.dropBehaviour)
340
+ dropped = $.ui.ddmanager.drop(this, event);
341
+
342
+ //if a drop comes from outside (a sortable)
343
+ if(this.dropped) {
344
+ dropped = this.dropped;
345
+ this.dropped = false;
346
+ }
347
+
348
+ //if the original element is removed, don't bother to continue
349
+ if(!this.element[0] || !this.element[0].parentNode)
350
+ return false;
351
+
352
+ if((this.options.revert == "invalid" && !dropped) || (this.options.revert == "valid" && dropped) || this.options.revert === true || ($.isFunction(this.options.revert) && this.options.revert.call(this.element, dropped))) {
353
+ var self = this;
354
+ $(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), function() {
355
+ if(self._trigger("stop", event) !== false) {
356
+ self._clear();
357
+ }
358
+ });
359
+ } else {
360
+ if(this._trigger("stop", event) !== false) {
361
+ this._clear();
362
+ }
363
+ }
364
+
365
+ return false;
366
+ },
367
+
368
+ cancel: function() {
369
+
370
+ if(this.helper.is(".ui-draggable-dragging")) {
371
+ this._mouseUp({});
372
+ } else {
373
+ this._clear();
374
+ }
375
+
376
+ return this;
377
+
378
+ },
379
+
380
+ _getHandle: function(event) {
381
+
382
+ var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false;
383
+ $(this.options.handle, this.element)
384
+ .find("*")
385
+ .andSelf()
386
+ .each(function() {
387
+ if(this == event.target) handle = true;
388
+ });
389
+
390
+ return handle;
391
+
392
+ },
393
+
394
+ _createHelper: function(event) {
395
+
396
+ var o = this.options;
397
+ var helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event])) : (o.helper == 'clone' ? this.element.clone() : this.element);
398
+
399
+ if(!helper.parents('body').length)
400
+ helper.appendTo((o.appendTo == 'parent' ? this.element[0].parentNode : o.appendTo));
401
+
402
+ if(helper[0] != this.element[0] && !(/(fixed|absolute)/).test(helper.css("position")))
403
+ helper.css("position", "absolute");
404
+
405
+ return helper;
406
+
407
+ },
408
+
409
+ _adjustOffsetFromHelper: function(obj) {
410
+ if (typeof obj == 'string') {
411
+ obj = obj.split(' ');
412
+ }
413
+ if ($.isArray(obj)) {
414
+ obj = {left: +obj[0], top: +obj[1] || 0};
415
+ }
416
+ if ('left' in obj) {
417
+ this.offset.click.left = obj.left + this.margins.left;
418
+ }
419
+ if ('right' in obj) {
420
+ this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
421
+ }
422
+ if ('top' in obj) {
423
+ this.offset.click.top = obj.top + this.margins.top;
424
+ }
425
+ if ('bottom' in obj) {
426
+ this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
427
+ }
428
+ },
429
+
430
+ _getParentOffset: function() {
431
+
432
+ //Get the offsetParent and cache its position
433
+ this.offsetParent = this.helper.offsetParent();
434
+ var po = this.offsetParent.offset();
435
+
436
+ // This is a special case where we need to modify a offset calculated on start, since the following happened:
437
+ // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
438
+ // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
439
+ // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
440
+ if(this.cssPosition == 'absolute' && this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) {
441
+ po.left += this.scrollParent.scrollLeft();
442
+ po.top += this.scrollParent.scrollTop();
443
+ }
444
+
445
+ if((this.offsetParent[0] == document.body) //This needs to be actually done for all browsers, since pageX/pageY includes this information
446
+ || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.browser.msie)) //Ugly IE fix
447
+ po = { top: 0, left: 0 };
448
+
449
+ return {
450
+ top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
451
+ left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
452
+ };
453
+
454
+ },
455
+
456
+ _getRelativeOffset: function() {
457
+
458
+ if(this.cssPosition == "relative") {
459
+ var p = this.element.position();
460
+ return {
461
+ top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
462
+ left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft()
463
+ };
464
+ } else {
465
+ return { top: 0, left: 0 };
466
+ }
467
+
468
+ },
469
+
470
+ _cacheMargins: function() {
471
+ this.margins = {
472
+ left: (parseInt(this.element.css("marginLeft"),10) || 0),
473
+ top: (parseInt(this.element.css("marginTop"),10) || 0)
474
+ };
475
+ },
476
+
477
+ _cacheHelperProportions: function() {
478
+ this.helperProportions = {
479
+ width: this.helper.outerWidth(),
480
+ height: this.helper.outerHeight()
481
+ };
482
+ },
483
+
484
+ _setContainment: function() {
485
+
486
+ var o = this.options;
487
+ if(o.containment == 'parent') o.containment = this.helper[0].parentNode;
488
+ if(o.containment == 'document' || o.containment == 'window') this.containment = [
489
+ 0 - this.offset.relative.left - this.offset.parent.left,
490
+ 0 - this.offset.relative.top - this.offset.parent.top,
491
+ $(o.containment == 'document' ? document : window).width() - this.helperProportions.width - this.margins.left,
492
+ ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
493
+ ];
494
+
495
+ if(!(/^(document|window|parent)$/).test(o.containment) && o.containment.constructor != Array) {
496
+ var ce = $(o.containment)[0]; if(!ce) return;
497
+ var co = $(o.containment).offset();
498
+ var over = ($(ce).css("overflow") != 'hidden');
499
+
500
+ this.containment = [
501
+ co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0) - this.margins.left,
502
+ co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0) - this.margins.top,
503
+ co.left+(over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left,
504
+ co.top+(over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top
505
+ ];
506
+ } else if(o.containment.constructor == Array) {
507
+ this.containment = o.containment;
508
+ }
509
+
510
+ },
511
+
512
+ _convertPositionTo: function(d, pos) {
513
+
514
+ if(!pos) pos = this.position;
515
+ var mod = d == "absolute" ? 1 : -1;
516
+ var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
517
+
518
+ return {
519
+ top: (
520
+ pos.top // The absolute mouse position
521
+ + this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent
522
+ + this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border)
523
+ - ($.browser.safari && $.browser.version < 526 && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
524
+ ),
525
+ left: (
526
+ pos.left // The absolute mouse position
527
+ + this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent
528
+ + this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border)
529
+ - ($.browser.safari && $.browser.version < 526 && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
530
+ )
531
+ };
532
+
533
+ },
534
+
535
+ _generatePosition: function(event) {
536
+
537
+ var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
538
+ var pageX = event.pageX;
539
+ var pageY = event.pageY;
540
+
541
+ /*
542
+ * - Position constraining -
543
+ * Constrain the position to a mix of grid, containment.
544
+ */
545
+
546
+ if(this.originalPosition) { //If we are not dragging yet, we won't check for options
547
+
548
+ if(this.containment) {
549
+ if(event.pageX - this.offset.click.left < this.containment[0]) pageX = this.containment[0] + this.offset.click.left;
550
+ if(event.pageY - this.offset.click.top < this.containment[1]) pageY = this.containment[1] + this.offset.click.top;
551
+ if(event.pageX - this.offset.click.left > this.containment[2]) pageX = this.containment[2] + this.offset.click.left;
552
+ if(event.pageY - this.offset.click.top > this.containment[3]) pageY = this.containment[3] + this.offset.click.top;
553
+ }
554
+
555
+ if(o.grid) {
556
+ var top = this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1];
557
+ pageY = this.containment ? (!(top - this.offset.click.top < this.containment[1] || top - this.offset.click.top > this.containment[3]) ? top : (!(top - this.offset.click.top < this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
558
+
559
+ var left = this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0];
560
+ pageX = this.containment ? (!(left - this.offset.click.left < this.containment[0] || left - this.offset.click.left > this.containment[2]) ? left : (!(left - this.offset.click.left < this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left;
561
+ }
562
+
563
+ }
564
+
565
+ return {
566
+ top: (
567
+ pageY // The absolute mouse position
568
+ - this.offset.click.top // Click offset (relative to the element)
569
+ - this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent
570
+ - this.offset.parent.top // The offsetParent's offset without borders (offset + border)
571
+ + ($.browser.safari && $.browser.version < 526 && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
572
+ ),
573
+ left: (
574
+ pageX // The absolute mouse position
575
+ - this.offset.click.left // Click offset (relative to the element)
576
+ - this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent
577
+ - this.offset.parent.left // The offsetParent's offset without borders (offset + border)
578
+ + ($.browser.safari && $.browser.version < 526 && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
579
+ )
580
+ };
581
+
582
+ },
583
+
584
+ _clear: function() {
585
+ this.helper.removeClass("ui-draggable-dragging");
586
+ if(this.helper[0] != this.element[0] && !this.cancelHelperRemoval) this.helper.remove();
587
+ //if($.ui.ddmanager) $.ui.ddmanager.current = null;
588
+ this.helper = null;
589
+ this.cancelHelperRemoval = false;
590
+ },
591
+
592
+ // From now on bulk stuff - mainly helpers
593
+
594
+ _trigger: function(type, event, ui) {
595
+ ui = ui || this._uiHash();
596
+ $.ui.plugin.call(this, type, [event, ui]);
597
+ if(type == "drag") this.positionAbs = this._convertPositionTo("absolute"); //The absolute position has to be recalculated after plugins
598
+ return $.Widget.prototype._trigger.call(this, type, event, ui);
599
+ },
600
+
601
+ plugins: {},
602
+
603
+ _uiHash: function(event) {
604
+ return {
605
+ helper: this.helper,
606
+ position: this.position,
607
+ originalPosition: this.originalPosition,
608
+ offset: this.positionAbs
609
+ };
610
+ }
611
+
612
+ });
613
+
614
+ $.extend($.ui.draggable, {
615
+ version: "1.8.4"
616
+ });
617
+
618
+ $.ui.plugin.add("draggable", "connectToSortable", {
619
+ start: function(event, ui) {
620
+
621
+ var inst = $(this).data("draggable"), o = inst.options,
622
+ uiSortable = $.extend({}, ui, { item: inst.element });
623
+ inst.sortables = [];
624
+ $(o.connectToSortable).each(function() {
625
+ var sortable = $.data(this, 'sortable');
626
+ if (sortable && !sortable.options.disabled) {
627
+ inst.sortables.push({
628
+ instance: sortable,
629
+ shouldRevert: sortable.options.revert
630
+ });
631
+ sortable._refreshItems(); //Do a one-time refresh at start to refresh the containerCache
632
+ sortable._trigger("activate", event, uiSortable);
633
+ }
634
+ });
635
+
636
+ },
637
+ stop: function(event, ui) {
638
+
639
+ //If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
640
+ var inst = $(this).data("draggable"),
641
+ uiSortable = $.extend({}, ui, { item: inst.element });
642
+
643
+ $.each(inst.sortables, function() {
644
+ if(this.instance.isOver) {
645
+
646
+ this.instance.isOver = 0;
647
+
648
+ inst.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance
649
+ this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work)
650
+
651
+ //The sortable revert is supported, and we have to set a temporary dropped variable on the draggable to support revert: 'valid/invalid'
652
+ if(this.shouldRevert) this.instance.options.revert = true;
653
+
654
+ //Trigger the stop of the sortable
655
+ this.instance._mouseStop(event);
656
+
657
+ this.instance.options.helper = this.instance.options._helper;
658
+
659
+ //If the helper has been the original item, restore properties in the sortable
660
+ if(inst.options.helper == 'original')
661
+ this.instance.currentItem.css({ top: 'auto', left: 'auto' });
662
+
663
+ } else {
664
+ this.instance.cancelHelperRemoval = false; //Remove the helper in the sortable instance
665
+ this.instance._trigger("deactivate", event, uiSortable);
666
+ }
667
+
668
+ });
669
+
670
+ },
671
+ drag: function(event, ui) {
672
+
673
+ var inst = $(this).data("draggable"), self = this;
674
+
675
+ var checkPos = function(o) {
676
+ var dyClick = this.offset.click.top, dxClick = this.offset.click.left;
677
+ var helperTop = this.positionAbs.top, helperLeft = this.positionAbs.left;
678
+ var itemHeight = o.height, itemWidth = o.width;
679
+ var itemTop = o.top, itemLeft = o.left;
680
+
681
+ return $.ui.isOver(helperTop + dyClick, helperLeft + dxClick, itemTop, itemLeft, itemHeight, itemWidth);
682
+ };
683
+
684
+ $.each(inst.sortables, function(i) {
685
+
686
+ //Copy over some variables to allow calling the sortable's native _intersectsWith
687
+ this.instance.positionAbs = inst.positionAbs;
688
+ this.instance.helperProportions = inst.helperProportions;
689
+ this.instance.offset.click = inst.offset.click;
690
+
691
+ if(this.instance._intersectsWith(this.instance.containerCache)) {
692
+
693
+ //If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once
694
+ if(!this.instance.isOver) {
695
+
696
+ this.instance.isOver = 1;
697
+ //Now we fake the start of dragging for the sortable instance,
698
+ //by cloning the list group item, appending it to the sortable and using it as inst.currentItem
699
+ //We can then fire the start event of the sortable with our passed browser event, and our own helper (so it doesn't create a new one)
700
+ this.instance.currentItem = $(self).clone().appendTo(this.instance.element).data("sortable-item", true);
701
+ this.instance.options._helper = this.instance.options.helper; //Store helper option to later restore it
702
+ this.instance.options.helper = function() { return ui.helper[0]; };
703
+
704
+ event.target = this.instance.currentItem[0];
705
+ this.instance._mouseCapture(event, true);
706
+ this.instance._mouseStart(event, true, true);
707
+
708
+ //Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
709
+ this.instance.offset.click.top = inst.offset.click.top;
710
+ this.instance.offset.click.left = inst.offset.click.left;
711
+ this.instance.offset.parent.left -= inst.offset.parent.left - this.instance.offset.parent.left;
712
+ this.instance.offset.parent.top -= inst.offset.parent.top - this.instance.offset.parent.top;
713
+
714
+ inst._trigger("toSortable", event);
715
+ inst.dropped = this.instance.element; //draggable revert needs that
716
+ //hack so receive/update callbacks work (mostly)
717
+ inst.currentItem = inst.element;
718
+ this.instance.fromOutside = inst;
719
+
720
+ }
721
+
722
+ //Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable
723
+ if(this.instance.currentItem) this.instance._mouseDrag(event);
724
+
725
+ } else {
726
+
727
+ //If it doesn't intersect with the sortable, and it intersected before,
728
+ //we fake the drag stop of the sortable, but make sure it doesn't remove the helper by using cancelHelperRemoval
729
+ if(this.instance.isOver) {
730
+
731
+ this.instance.isOver = 0;
732
+ this.instance.cancelHelperRemoval = true;
733
+
734
+ //Prevent reverting on this forced stop
735
+ this.instance.options.revert = false;
736
+
737
+ // The out event needs to be triggered independently
738
+ this.instance._trigger('out', event, this.instance._uiHash(this.instance));
739
+
740
+ this.instance._mouseStop(event, true);
741
+ this.instance.options.helper = this.instance.options._helper;
742
+
743
+ //Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
744
+ this.instance.currentItem.remove();
745
+ if(this.instance.placeholder) this.instance.placeholder.remove();
746
+
747
+ inst._trigger("fromSortable", event);
748
+ inst.dropped = false; //draggable revert needs that
749
+ }
750
+
751
+ };
752
+
753
+ });
754
+
755
+ }
756
+ });
757
+
758
+ $.ui.plugin.add("draggable", "cursor", {
759
+ start: function(event, ui) {
760
+ var t = $('body'), o = $(this).data('draggable').options;
761
+ if (t.css("cursor")) o._cursor = t.css("cursor");
762
+ t.css("cursor", o.cursor);
763
+ },
764
+ stop: function(event, ui) {
765
+ var o = $(this).data('draggable').options;
766
+ if (o._cursor) $('body').css("cursor", o._cursor);
767
+ }
768
+ });
769
+
770
+ $.ui.plugin.add("draggable", "iframeFix", {
771
+ start: function(event, ui) {
772
+ var o = $(this).data('draggable').options;
773
+ $(o.iframeFix === true ? "iframe" : o.iframeFix).each(function() {
774
+ $('<div class="ui-draggable-iframeFix" style="background: #fff;"></div>')
775
+ .css({
776
+ width: this.offsetWidth+"px", height: this.offsetHeight+"px",
777
+ position: "absolute", opacity: "0.001", zIndex: 1000
778
+ })
779
+ .css($(this).offset())
780
+ .appendTo("body");
781
+ });
782
+ },
783
+ stop: function(event, ui) {
784
+ $("div.ui-draggable-iframeFix").each(function() { this.parentNode.removeChild(this); }); //Remove frame helpers
785
+ }
786
+ });
787
+
788
+ $.ui.plugin.add("draggable", "opacity", {
789
+ start: function(event, ui) {
790
+ var t = $(ui.helper), o = $(this).data('draggable').options;
791
+ if(t.css("opacity")) o._opacity = t.css("opacity");
792
+ t.css('opacity', o.opacity);
793
+ },
794
+ stop: function(event, ui) {
795
+ var o = $(this).data('draggable').options;
796
+ if(o._opacity) $(ui.helper).css('opacity', o._opacity);
797
+ }
798
+ });
799
+
800
+ $.ui.plugin.add("draggable", "scroll", {
801
+ start: function(event, ui) {
802
+ var i = $(this).data("draggable");
803
+ if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') i.overflowOffset = i.scrollParent.offset();
804
+ },
805
+ drag: function(event, ui) {
806
+
807
+ var i = $(this).data("draggable"), o = i.options, scrolled = false;
808
+
809
+ if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') {
810
+
811
+ if(!o.axis || o.axis != 'x') {
812
+ if((i.overflowOffset.top + i.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity)
813
+ i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop + o.scrollSpeed;
814
+ else if(event.pageY - i.overflowOffset.top < o.scrollSensitivity)
815
+ i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop - o.scrollSpeed;
816
+ }
817
+
818
+ if(!o.axis || o.axis != 'y') {
819
+ if((i.overflowOffset.left + i.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity)
820
+ i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft + o.scrollSpeed;
821
+ else if(event.pageX - i.overflowOffset.left < o.scrollSensitivity)
822
+ i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft - o.scrollSpeed;
823
+ }
824
+
825
+ } else {
826
+
827
+ if(!o.axis || o.axis != 'x') {
828
+ if(event.pageY - $(document).scrollTop() < o.scrollSensitivity)
829
+ scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
830
+ else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity)
831
+ scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
832
+ }
833
+
834
+ if(!o.axis || o.axis != 'y') {
835
+ if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity)
836
+ scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
837
+ else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
838
+ scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
839
+ }
840
+
841
+ }
842
+
843
+ if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour)
844
+ $.ui.ddmanager.prepareOffsets(i, event);
845
+
846
+ }
847
+ });
848
+
849
+ $.ui.plugin.add("draggable", "snap", {
850
+ start: function(event, ui) {
851
+
852
+ var i = $(this).data("draggable"), o = i.options;
853
+ i.snapElements = [];
854
+
855
+ $(o.snap.constructor != String ? ( o.snap.items || ':data(draggable)' ) : o.snap).each(function() {
856
+ var $t = $(this); var $o = $t.offset();
857
+ if(this != i.element[0]) i.snapElements.push({
858
+ item: this,
859
+ width: $t.outerWidth(), height: $t.outerHeight(),
860
+ top: $o.top, left: $o.left
861
+ });
862
+ });
863
+
864
+ },
865
+ drag: function(event, ui) {
866
+
867
+ var inst = $(this).data("draggable"), o = inst.options;
868
+ var d = o.snapTolerance;
869
+
870
+ var x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width,
871
+ y1 = ui.offset.top, y2 = y1 + inst.helperProportions.height;
872
+
873
+ for (var i = inst.snapElements.length - 1; i >= 0; i--){
874
+
875
+ var l = inst.snapElements[i].left, r = l + inst.snapElements[i].width,
876
+ t = inst.snapElements[i].top, b = t + inst.snapElements[i].height;
877
+
878
+ //Yes, I know, this is insane ;)
879
+ if(!((l-d < x1 && x1 < r+d && t-d < y1 && y1 < b+d) || (l-d < x1 && x1 < r+d && t-d < y2 && y2 < b+d) || (l-d < x2 && x2 < r+d && t-d < y1 && y1 < b+d) || (l-d < x2 && x2 < r+d && t-d < y2 && y2 < b+d))) {
880
+ if(inst.snapElements[i].snapping) (inst.options.snap.release && inst.options.snap.release.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
881
+ inst.snapElements[i].snapping = false;
882
+ continue;
883
+ }
884
+
885
+ if(o.snapMode != 'inner') {
886
+ var ts = Math.abs(t - y2) <= d;
887
+ var bs = Math.abs(b - y1) <= d;
888
+ var ls = Math.abs(l - x2) <= d;
889
+ var rs = Math.abs(r - x1) <= d;
890
+ if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top - inst.margins.top;
891
+ if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top - inst.margins.top;
892
+ if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left - inst.margins.left;
893
+ if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left - inst.margins.left;
894
+ }
895
+
896
+ var first = (ts || bs || ls || rs);
897
+
898
+ if(o.snapMode != 'outer') {
899
+ var ts = Math.abs(t - y1) <= d;
900
+ var bs = Math.abs(b - y2) <= d;
901
+ var ls = Math.abs(l - x1) <= d;
902
+ var rs = Math.abs(r - x2) <= d;
903
+ if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t, left: 0 }).top - inst.margins.top;
904
+ if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top - inst.margins.top;
905
+ if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left - inst.margins.left;
906
+ if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left - inst.margins.left;
907
+ }
908
+
909
+ if(!inst.snapElements[i].snapping && (ts || bs || ls || rs || first))
910
+ (inst.options.snap.snap && inst.options.snap.snap.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
911
+ inst.snapElements[i].snapping = (ts || bs || ls || rs || first);
912
+
913
+ };
914
+
915
+ }
916
+ });
917
+
918
+ $.ui.plugin.add("draggable", "stack", {
919
+ start: function(event, ui) {
920
+
921
+ var o = $(this).data("draggable").options;
922
+
923
+ var group = $.makeArray($(o.stack)).sort(function(a,b) {
924
+ return (parseInt($(a).css("zIndex"),10) || 0) - (parseInt($(b).css("zIndex"),10) || 0);
925
+ });
926
+ if (!group.length) { return; }
927
+
928
+ var min = parseInt(group[0].style.zIndex) || 0;
929
+ $(group).each(function(i) {
930
+ this.style.zIndex = min + i;
931
+ });
932
+
933
+ this[0].style.zIndex = min + group.length;
934
+
935
+ }
936
+ });
937
+
938
+ $.ui.plugin.add("draggable", "zIndex", {
939
+ start: function(event, ui) {
940
+ var t = $(ui.helper), o = $(this).data("draggable").options;
941
+ if(t.css("zIndex")) o._zIndex = t.css("zIndex");
942
+ t.css('zIndex', o.zIndex);
943
+ },
944
+ stop: function(event, ui) {
945
+ var o = $(this).data("draggable").options;
946
+ if(o._zIndex) $(ui.helper).css('zIndex', o._zIndex);
947
+ }
948
+ });
949
+
950
+ })(jQuery);