jquery-shapeshift-rails 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f6991fa7500776c63d27421b325913cd1de2a802
4
+ data.tar.gz: 9bcb28a23d603928dc0162a81cb8b6614d636943
5
+ SHA512:
6
+ metadata.gz: d42e8b36ff912dea10ac07ae3446793477f02639f813d7cdef995e9d307f3a724a41c06e8d577cadc4cd84d1c12ed42cc0806a12952878beda25c211ea21f733
7
+ data.tar.gz: bdadcd5289f1e45ad4e5a6f9b0b37a4a5024cd0ff3dfcd59408d5f1653abac6921f3921408329d5610a2f4e26793244b293257eda2b501450a3dd1eb047ebb3c
@@ -0,0 +1,20 @@
1
+ Copyright 2014 Yury Snegirev
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,7 @@
1
+ module Jquery
2
+ module Shapeshift
3
+ module Rails
4
+ VERSION = "2.0.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,690 @@
1
+ // Generated by CoffeeScript 1.4.0
2
+ (function() {
3
+
4
+ (function($, window, document) {
5
+ var Plugin, defaults, pluginName;
6
+ pluginName = "shapeshift";
7
+ defaults = {
8
+ selector: "*",
9
+ enableDrag: true,
10
+ enableCrossDrop: true,
11
+ enableResize: true,
12
+ enableTrash: false,
13
+ align: "center",
14
+ colWidth: null,
15
+ columns: null,
16
+ minColumns: 1,
17
+ autoHeight: true,
18
+ maxHeight: null,
19
+ minHeight: 100,
20
+ gutterX: 10,
21
+ gutterY: 10,
22
+ paddingX: 10,
23
+ paddingY: 10,
24
+ animated: true,
25
+ animateOnInit: false,
26
+ animationSpeed: 225,
27
+ animationThreshold: 100,
28
+ dragClone: false,
29
+ deleteClone: true,
30
+ dragRate: 100,
31
+ dragWhitelist: "*",
32
+ crossDropWhitelist: "*",
33
+ cutoffStart: null,
34
+ cutoffEnd: null,
35
+ handle: false,
36
+ cloneClass: "ss-cloned-child",
37
+ activeClass: "ss-active-child",
38
+ draggedClass: "ss-dragged-child",
39
+ placeholderClass: "ss-placeholder-child",
40
+ originalContainerClass: "ss-original-container",
41
+ currentContainerClass: "ss-current-container",
42
+ previousContainerClass: "ss-previous-container"
43
+ };
44
+ Plugin = (function() {
45
+
46
+ function Plugin(element, options) {
47
+ this.element = element;
48
+ this.options = $.extend({}, defaults, options);
49
+ this.globals = {};
50
+ this.$container = $(element);
51
+ if (this.errorCheck()) {
52
+ this.init();
53
+ }
54
+ }
55
+
56
+ Plugin.prototype.errorCheck = function() {
57
+ var $children, error_msg, errors, options;
58
+ options = this.options;
59
+ errors = false;
60
+ error_msg = "Shapeshift ERROR:";
61
+ if (options.colWidth === null) {
62
+ $children = this.$container.children(options.selector);
63
+ if ($children.length === 0) {
64
+ errors = true;
65
+ console.error("" + error_msg + " option colWidth must be specified if Shapeshift is initialized with no active children.");
66
+ }
67
+ }
68
+ return !errors;
69
+ };
70
+
71
+ Plugin.prototype.init = function() {
72
+ this.createEvents();
73
+ this.setGlobals();
74
+ this.setIdentifier();
75
+ this.setActiveChildren();
76
+ this.enableFeatures();
77
+ this.gridInit();
78
+ this.render();
79
+ return this.afterInit();
80
+ };
81
+
82
+ Plugin.prototype.createEvents = function() {
83
+ var $container, options,
84
+ _this = this;
85
+ options = this.options;
86
+ $container = this.$container;
87
+ $container.off("ss-arrange").on("ss-arrange", function(e, trigger_drop_finished) {
88
+ if (trigger_drop_finished == null) {
89
+ trigger_drop_finished = false;
90
+ }
91
+ return _this.render(false, trigger_drop_finished);
92
+ });
93
+ $container.off("ss-rearrange").on("ss-rearrange", function() {
94
+ return _this.render(true);
95
+ });
96
+ $container.off("ss-setTargetPosition").on("ss-setTargetPosition", function() {
97
+ return _this.setTargetPosition();
98
+ });
99
+ $container.off("ss-destroy").on("ss-destroy", function() {
100
+ return _this.destroy();
101
+ });
102
+ return $container.off("ss-shuffle").on("ss-shuffle", function() {
103
+ return _this.shuffle();
104
+ });
105
+ };
106
+
107
+ Plugin.prototype.setGlobals = function() {
108
+ this.globals.animated = this.options.animateOnInit;
109
+ return this.globals.dragging = false;
110
+ };
111
+
112
+ Plugin.prototype.afterInit = function() {
113
+ return this.globals.animated = this.options.animated;
114
+ };
115
+
116
+ Plugin.prototype.setIdentifier = function() {
117
+ this.identifier = "shapeshifted_container_" + Math.random().toString(36).substring(7);
118
+ return this.$container.addClass(this.identifier);
119
+ };
120
+
121
+ Plugin.prototype.enableFeatures = function() {
122
+ if (this.options.enableResize) {
123
+ this.enableResize();
124
+ }
125
+ if (this.options.enableDrag || this.options.enableCrossDrop) {
126
+ return this.enableDragNDrop();
127
+ }
128
+ };
129
+
130
+ Plugin.prototype.setActiveChildren = function() {
131
+ var $children, active_child_class, colspan, columns, i, min_columns, options, total, _i, _j, _ref, _results;
132
+ options = this.options;
133
+ $children = this.$container.children(options.selector);
134
+ active_child_class = options.activeClass;
135
+ total = $children.length;
136
+ for (i = _i = 0; 0 <= total ? _i < total : _i > total; i = 0 <= total ? ++_i : --_i) {
137
+ $($children[i]).addClass(active_child_class);
138
+ }
139
+ this.setParsedChildren();
140
+ columns = options.columns;
141
+ _results = [];
142
+ for (i = _j = 0, _ref = this.parsedChildren.length; 0 <= _ref ? _j < _ref : _j > _ref; i = 0 <= _ref ? ++_j : --_j) {
143
+ colspan = this.parsedChildren[i].colspan;
144
+ min_columns = options.minColumns;
145
+ if (colspan > columns && colspan > min_columns) {
146
+ options.minColumns = colspan;
147
+ _results.push(console.error("Shapeshift ERROR: There are child elements that have a larger colspan than the minimum columns set through options.\noptions.minColumns has been set to " + colspan));
148
+ } else {
149
+ _results.push(void 0);
150
+ }
151
+ }
152
+ return _results;
153
+ };
154
+
155
+ Plugin.prototype.setParsedChildren = function() {
156
+ var $child, $children, child, i, parsedChildren, total, _i;
157
+ $children = this.$container.find("." + this.options.activeClass).filter(":visible");
158
+ total = $children.length;
159
+ parsedChildren = [];
160
+ for (i = _i = 0; 0 <= total ? _i < total : _i > total; i = 0 <= total ? ++_i : --_i) {
161
+ $child = $($children[i]);
162
+ child = {
163
+ i: i,
164
+ el: $child,
165
+ colspan: parseInt($child.attr("data-ss-colspan")) || 1,
166
+ height: $child.outerHeight()
167
+ };
168
+ parsedChildren.push(child);
169
+ }
170
+ return this.parsedChildren = parsedChildren;
171
+ };
172
+
173
+ Plugin.prototype.gridInit = function() {
174
+ var fc_colspan, fc_width, first_child, gutter_x, single_width;
175
+ gutter_x = this.options.gutterX;
176
+ if (!(this.options.colWidth >= 1)) {
177
+ first_child = this.parsedChildren[0];
178
+ fc_width = first_child.el.outerWidth();
179
+ fc_colspan = first_child.colspan;
180
+ single_width = (fc_width - ((fc_colspan - 1) * gutter_x)) / fc_colspan;
181
+ return this.globals.col_width = single_width + gutter_x;
182
+ } else {
183
+ return this.globals.col_width = this.options.colWidth + gutter_x;
184
+ }
185
+ };
186
+
187
+ Plugin.prototype.render = function(reparse, trigger_drop_finished) {
188
+ if (reparse == null) {
189
+ reparse = false;
190
+ }
191
+ if (reparse) {
192
+ this.setActiveChildren();
193
+ }
194
+ this.setGridColumns();
195
+ return this.arrange(false, trigger_drop_finished);
196
+ };
197
+
198
+ Plugin.prototype.setGridColumns = function() {
199
+ var actual_columns, children_count, col_width, colspan, columns, globals, grid_width, gutter_x, i, inner_width, minColumns, options, padding_x, _i, _ref;
200
+ globals = this.globals;
201
+ options = this.options;
202
+ col_width = globals.col_width;
203
+ gutter_x = options.gutterX;
204
+ padding_x = options.paddingX;
205
+ inner_width = this.$container.innerWidth() - (padding_x * 2);
206
+ minColumns = options.minColumns;
207
+ columns = options.columns || Math.floor((inner_width + gutter_x) / col_width);
208
+ if (minColumns && minColumns > columns) {
209
+ columns = minColumns;
210
+ }
211
+ globals.columns = columns;
212
+ children_count = this.parsedChildren.length;
213
+ if (columns > children_count) {
214
+ actual_columns = 0;
215
+ for (i = _i = 0, _ref = this.parsedChildren.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
216
+ colspan = this.parsedChildren[i].colspan;
217
+ if (colspan + actual_columns <= columns) {
218
+ actual_columns += colspan;
219
+ }
220
+ }
221
+ columns = actual_columns;
222
+ }
223
+ globals.child_offset = padding_x;
224
+ switch (options.align) {
225
+ case "center":
226
+ grid_width = (columns * col_width) - gutter_x;
227
+ return globals.child_offset += (inner_width - grid_width) / 2;
228
+ case "right":
229
+ grid_width = (columns * col_width) - gutter_x;
230
+ return globals.child_offset += inner_width - grid_width;
231
+ }
232
+ };
233
+
234
+ Plugin.prototype.arrange = function(reparse, trigger_drop_finished) {
235
+ var $child, $container, animated, animation_speed, attributes, child_positions, container_height, dragged_class, globals, i, is_dragged_child, max_height, min_height, options, parsed_children, placeholder_class, total_children, _i;
236
+ if (reparse) {
237
+ this.setParsedChildren();
238
+ }
239
+ globals = this.globals;
240
+ options = this.options;
241
+ $container = this.$container;
242
+ child_positions = this.getPositions();
243
+ parsed_children = this.parsedChildren;
244
+ total_children = parsed_children.length;
245
+ animated = globals.animated && total_children <= options.animationThreshold;
246
+ animation_speed = options.animationSpeed;
247
+ dragged_class = options.draggedClass;
248
+ for (i = _i = 0; 0 <= total_children ? _i < total_children : _i > total_children; i = 0 <= total_children ? ++_i : --_i) {
249
+ $child = parsed_children[i].el;
250
+ attributes = child_positions[i];
251
+ is_dragged_child = $child.hasClass(dragged_class);
252
+ if (is_dragged_child) {
253
+ placeholder_class = options.placeholderClass;
254
+ $child = $child.siblings("." + placeholder_class);
255
+ }
256
+ if (animated && !is_dragged_child) {
257
+ $child.stop(true, false).animate(attributes, animation_speed, function() {});
258
+ } else {
259
+ $child.css(attributes);
260
+ }
261
+ }
262
+ if (trigger_drop_finished) {
263
+ if (animated) {
264
+ setTimeout((function() {
265
+ return $container.trigger("ss-drop-complete");
266
+ }), animation_speed);
267
+ } else {
268
+ $container.trigger("ss-drop-complete");
269
+ }
270
+ }
271
+ $container.trigger("ss-arranged");
272
+ if (options.autoHeight) {
273
+ container_height = globals.container_height;
274
+ max_height = options.maxHeight;
275
+ min_height = options.minHeight;
276
+ if (min_height && container_height < min_height) {
277
+ container_height = min_height;
278
+ } else if (max_height && container_height > max_height) {
279
+ container_height = max_height;
280
+ }
281
+ return $container.height(container_height);
282
+ }
283
+ };
284
+
285
+ Plugin.prototype.getPositions = function(include_dragged) {
286
+ var col_heights, determineMultiposition, determinePositions, dragged_class, globals, grid_height, gutter_y, i, options, padding_y, parsed_children, positions, recalculateSavedChildren, savePosition, saved_children, total_children, _i, _ref,
287
+ _this = this;
288
+ if (include_dragged == null) {
289
+ include_dragged = true;
290
+ }
291
+ globals = this.globals;
292
+ options = this.options;
293
+ gutter_y = options.gutterY;
294
+ padding_y = options.paddingY;
295
+ dragged_class = options.draggedClass;
296
+ parsed_children = this.parsedChildren;
297
+ total_children = parsed_children.length;
298
+ col_heights = [];
299
+ for (i = _i = 0, _ref = globals.columns; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
300
+ col_heights.push(padding_y);
301
+ }
302
+ savePosition = function(child) {
303
+ var col, colspan, j, offset_x, offset_y, _j, _results;
304
+ col = child.col;
305
+ colspan = child.colspan;
306
+ offset_x = (child.col * globals.col_width) + globals.child_offset;
307
+ offset_y = col_heights[col];
308
+ positions[child.i] = {
309
+ left: offset_x,
310
+ top: offset_y
311
+ };
312
+ col_heights[col] += child.height + gutter_y;
313
+ if (colspan >= 1) {
314
+ _results = [];
315
+ for (j = _j = 1; 1 <= colspan ? _j < colspan : _j > colspan; j = 1 <= colspan ? ++_j : --_j) {
316
+ _results.push(col_heights[col + j] = col_heights[col]);
317
+ }
318
+ return _results;
319
+ }
320
+ };
321
+ determineMultiposition = function(child) {
322
+ var chosen_col, col, colspan, height, kosher, next_height, offset, possible_col_heights, possible_cols, span, _j, _k;
323
+ possible_cols = col_heights.length - child.colspan + 1;
324
+ possible_col_heights = col_heights.slice(0).splice(0, possible_cols);
325
+ chosen_col = void 0;
326
+ for (offset = _j = 0; 0 <= possible_cols ? _j < possible_cols : _j > possible_cols; offset = 0 <= possible_cols ? ++_j : --_j) {
327
+ col = _this.lowestCol(possible_col_heights, offset);
328
+ colspan = child.colspan;
329
+ height = col_heights[col];
330
+ kosher = true;
331
+ for (span = _k = 1; 1 <= colspan ? _k < colspan : _k > colspan; span = 1 <= colspan ? ++_k : --_k) {
332
+ next_height = col_heights[col + span];
333
+ if (height < next_height) {
334
+ kosher = false;
335
+ break;
336
+ }
337
+ }
338
+ if (kosher) {
339
+ chosen_col = col;
340
+ break;
341
+ }
342
+ }
343
+ return chosen_col;
344
+ };
345
+ saved_children = [];
346
+ recalculateSavedChildren = function() {
347
+ var index, pop_i, saved_child, saved_i, to_pop, _j, _k, _ref1, _ref2, _results;
348
+ to_pop = [];
349
+ for (saved_i = _j = 0, _ref1 = saved_children.length; 0 <= _ref1 ? _j < _ref1 : _j > _ref1; saved_i = 0 <= _ref1 ? ++_j : --_j) {
350
+ saved_child = saved_children[saved_i];
351
+ saved_child.col = determineMultiposition(saved_child);
352
+ if (saved_child.col >= 0) {
353
+ savePosition(saved_child);
354
+ to_pop.push(saved_i);
355
+ }
356
+ }
357
+ _results = [];
358
+ for (pop_i = _k = _ref2 = to_pop.length - 1; _k >= 0; pop_i = _k += -1) {
359
+ index = to_pop[pop_i];
360
+ _results.push(saved_children.splice(index, 1));
361
+ }
362
+ return _results;
363
+ };
364
+ positions = [];
365
+ (determinePositions = function() {
366
+ var child, _j, _results;
367
+ _results = [];
368
+ for (i = _j = 0; 0 <= total_children ? _j < total_children : _j > total_children; i = 0 <= total_children ? ++_j : --_j) {
369
+ child = parsed_children[i];
370
+ if (!(!include_dragged && child.el.hasClass(dragged_class))) {
371
+ if (child.colspan > 1) {
372
+ child.col = determineMultiposition(child);
373
+ } else {
374
+ child.col = _this.lowestCol(col_heights);
375
+ }
376
+ if (child.col === void 0) {
377
+ saved_children.push(child);
378
+ } else {
379
+ savePosition(child);
380
+ }
381
+ _results.push(recalculateSavedChildren());
382
+ } else {
383
+ _results.push(void 0);
384
+ }
385
+ }
386
+ return _results;
387
+ })();
388
+ if (options.autoHeight) {
389
+ grid_height = col_heights[this.highestCol(col_heights)] - gutter_y;
390
+ globals.container_height = grid_height + padding_y;
391
+ }
392
+ return positions;
393
+ };
394
+
395
+ Plugin.prototype.enableDragNDrop = function() {
396
+ var $clone, $container, $placeholder, $selected, active_class, clone_class, current_container_class, delete_clone, drag_clone, drag_rate, drag_timeout, dragged_class, options, original_container_class, placeholder_class, previous_container_class, selected_offset_x, selected_offset_y,
397
+ _this = this;
398
+ options = this.options;
399
+ $container = this.$container;
400
+ active_class = options.activeClass;
401
+ dragged_class = options.draggedClass;
402
+ placeholder_class = options.placeholderClass;
403
+ original_container_class = options.originalContainerClass;
404
+ current_container_class = options.currentContainerClass;
405
+ previous_container_class = options.previousContainerClass;
406
+ delete_clone = options.deleteClone;
407
+ drag_rate = options.dragRate;
408
+ drag_clone = options.dragClone;
409
+ clone_class = options.cloneClass;
410
+ $selected = $placeholder = $clone = selected_offset_y = selected_offset_x = null;
411
+ drag_timeout = false;
412
+ if (options.enableDrag) {
413
+ $container.children("." + active_class).filter(options.dragWhitelist).draggable({
414
+ addClasses: false,
415
+ containment: 'document',
416
+ handle: options.handle,
417
+ zIndex: 9999,
418
+ start: function(e, ui) {
419
+ var selected_tag;
420
+ _this.globals.dragging = true;
421
+ $selected = $(e.target);
422
+ if (drag_clone) {
423
+ $clone = $selected.clone(false, false).insertBefore($selected).addClass(clone_class);
424
+ }
425
+ $selected.addClass(dragged_class);
426
+ selected_tag = $selected.prop("tagName");
427
+ $placeholder = $("<" + selected_tag + " class='" + placeholder_class + "' style='height: " + ($selected.height()) + "px; width: " + ($selected.width()) + "px'></" + selected_tag + ">");
428
+ $selected.parent().addClass(original_container_class).addClass(current_container_class);
429
+ selected_offset_y = $selected.outerHeight() / 2;
430
+ return selected_offset_x = $selected.outerWidth() / 2;
431
+ },
432
+ drag: function(e, ui) {
433
+ if (!drag_timeout && !(drag_clone && delete_clone && $("." + current_container_class)[0] === $("." + original_container_class)[0])) {
434
+ $placeholder.remove().appendTo("." + current_container_class);
435
+ $("." + current_container_class).trigger("ss-setTargetPosition");
436
+ drag_timeout = true;
437
+ window.setTimeout((function() {
438
+ return drag_timeout = false;
439
+ }), drag_rate);
440
+ }
441
+ ui.position.left = e.pageX - $selected.parent().offset().left - selected_offset_x;
442
+ return ui.position.top = e.pageY - $selected.parent().offset().top - selected_offset_y;
443
+ },
444
+ stop: function() {
445
+ var $current_container, $original_container, $previous_container;
446
+ _this.globals.dragging = false;
447
+ $original_container = $("." + original_container_class);
448
+ $current_container = $("." + current_container_class);
449
+ $previous_container = $("." + previous_container_class);
450
+ $selected.removeClass(dragged_class);
451
+ $("." + placeholder_class).remove();
452
+ if (drag_clone) {
453
+ if (delete_clone && $("." + current_container_class)[0] === $("." + original_container_class)[0]) {
454
+ $clone.remove();
455
+ $("." + current_container_class).trigger("ss-rearrange");
456
+ } else {
457
+ $clone.removeClass(clone_class);
458
+ $original_container.shapeshift($original_container.data("plugin_shapeshift").options);
459
+ $current_container.shapeshift($current_container.data("plugin_shapeshift").options);
460
+ }
461
+ }
462
+ if ($original_container[0] === $current_container[0]) {
463
+ $current_container.trigger("ss-rearranged", $selected);
464
+ } else {
465
+ $original_container.trigger("ss-removed", $selected);
466
+ $current_container.trigger("ss-added", $selected);
467
+ }
468
+ $original_container.trigger("ss-arrange").removeClass(original_container_class);
469
+ $current_container.trigger("ss-arrange", true).removeClass(current_container_class);
470
+ $previous_container.trigger("ss-arrange").removeClass(previous_container_class);
471
+ return $selected = $placeholder = null;
472
+ }
473
+ });
474
+ }
475
+ if (options.enableCrossDrop) {
476
+ return $container.droppable({
477
+ accept: options.crossDropWhitelist,
478
+ tolerance: 'intersect',
479
+ over: function(e) {
480
+ $("." + previous_container_class).removeClass(previous_container_class);
481
+ $("." + current_container_class).removeClass(current_container_class).addClass(previous_container_class);
482
+ return $(e.target).addClass(current_container_class);
483
+ },
484
+ drop: function(e, selected) {
485
+ var $current_container, $original_container, $previous_container;
486
+ if (_this.options.enableTrash) {
487
+ $original_container = $("." + original_container_class);
488
+ $current_container = $("." + current_container_class);
489
+ $previous_container = $("." + previous_container_class);
490
+ $selected = $(selected.helper);
491
+ $current_container.trigger("ss-trashed", $selected);
492
+ $selected.remove();
493
+ $original_container.trigger("ss-rearrange").removeClass(original_container_class);
494
+ $current_container.trigger("ss-rearrange").removeClass(current_container_class);
495
+ return $previous_container.trigger("ss-arrange").removeClass(previous_container_class);
496
+ }
497
+ }
498
+ });
499
+ }
500
+ };
501
+
502
+ Plugin.prototype.setTargetPosition = function() {
503
+ var $selected, $start_container, $target, attributes, child_positions, cutoff_end, cutoff_start, distance, dragged_class, options, parsed_children, placeholder_class, position_i, previous_container_class, selected_x, selected_y, shortest_distance, target_position, total_positions, x_dist, y_dist, _i;
504
+ options = this.options;
505
+ if (!options.enableTrash) {
506
+ dragged_class = options.draggedClass;
507
+ $selected = $("." + dragged_class);
508
+ $start_container = $selected.parent();
509
+ parsed_children = this.parsedChildren;
510
+ child_positions = this.getPositions(false);
511
+ total_positions = child_positions.length;
512
+ selected_x = $selected.offset().left - $start_container.offset().left + (this.globals.col_width / 2);
513
+ selected_y = $selected.offset().top - $start_container.offset().top + ($selected.height() / 2);
514
+ shortest_distance = 9999999;
515
+ target_position = 0;
516
+ if (total_positions > 1) {
517
+ cutoff_start = options.cutoffStart + 1 || 0;
518
+ cutoff_end = options.cutoffEnd || total_positions;
519
+ for (position_i = _i = cutoff_start; cutoff_start <= cutoff_end ? _i < cutoff_end : _i > cutoff_end; position_i = cutoff_start <= cutoff_end ? ++_i : --_i) {
520
+ attributes = child_positions[position_i];
521
+ if (attributes) {
522
+ y_dist = selected_x - attributes.left;
523
+ x_dist = selected_y - attributes.top;
524
+ if (y_dist > 0 && x_dist > 0) {
525
+ distance = Math.sqrt((x_dist * x_dist) + (y_dist * y_dist));
526
+ if (distance < shortest_distance) {
527
+ shortest_distance = distance;
528
+ target_position = position_i;
529
+ if (position_i === total_positions - 1) {
530
+ if (y_dist > parsed_children[position_i].height / 2) {
531
+ target_position++;
532
+ }
533
+ }
534
+ }
535
+ }
536
+ }
537
+ }
538
+ if (target_position === parsed_children.length) {
539
+ $target = parsed_children[target_position - 1].el;
540
+ $selected.insertAfter($target);
541
+ } else {
542
+ $target = parsed_children[target_position].el;
543
+ $selected.insertBefore($target);
544
+ }
545
+ } else {
546
+ if (total_positions === 1) {
547
+ attributes = child_positions[0];
548
+ if (attributes.left < selected_x) {
549
+ this.$container.append($selected);
550
+ } else {
551
+ this.$container.prepend($selected);
552
+ }
553
+ } else {
554
+ this.$container.append($selected);
555
+ }
556
+ }
557
+ this.arrange(true);
558
+ if ($start_container[0] !== $selected.parent()[0]) {
559
+ previous_container_class = options.previousContainerClass;
560
+ if ($("." + previous_container_class).data("plugin_shapeshift").options.enableCrossDrop == true) {
561
+ return $("." + previous_container_class).trigger("ss-rearrange");
562
+ } else {
563
+ return $("." + previous_container_class);
564
+ }
565
+ }
566
+ } else {
567
+ placeholder_class = this.options.placeholderClass;
568
+ return $("." + placeholder_class).remove();
569
+ }
570
+ };
571
+
572
+ Plugin.prototype.enableResize = function() {
573
+ var animation_speed, binding, resizing,
574
+ _this = this;
575
+ animation_speed = this.options.animationSpeed;
576
+ resizing = false;
577
+ binding = "resize." + this.identifier;
578
+ return $(window).on(binding, function() {
579
+ if (!resizing) {
580
+ resizing = true;
581
+ setTimeout((function() {
582
+ return _this.render();
583
+ }), animation_speed / 3);
584
+ setTimeout((function() {
585
+ return _this.render();
586
+ }), animation_speed / 3);
587
+ return setTimeout(function() {
588
+ resizing = false;
589
+ return _this.render();
590
+ }, animation_speed / 3);
591
+ }
592
+ });
593
+ };
594
+
595
+ Plugin.prototype.shuffle = function() {
596
+ var calculateShuffled;
597
+ calculateShuffled = function(container, activeClass) {
598
+ var shuffle;
599
+ shuffle = function(arr) {
600
+ var i, j, x;
601
+ j = void 0;
602
+ x = void 0;
603
+ i = arr.length;
604
+ while (i) {
605
+ j = parseInt(Math.random() * i);
606
+ x = arr[--i];
607
+ arr[i] = arr[j];
608
+ arr[j] = x;
609
+ }
610
+ return arr;
611
+ };
612
+ return container.each(function() {
613
+ var items;
614
+ items = container.find("." + activeClass).filter(":visible");
615
+ if (items.length) {
616
+ return container.html(shuffle(items));
617
+ } else {
618
+ return this;
619
+ }
620
+ });
621
+ };
622
+ if (!this.globals.dragging) {
623
+ calculateShuffled(this.$container, this.options.activeClass);
624
+ this.enableFeatures();
625
+ return this.$container.trigger("ss-rearrange");
626
+ }
627
+ };
628
+
629
+ Plugin.prototype.lowestCol = function(array, offset) {
630
+ var augmented_array, i, length, _i;
631
+ if (offset == null) {
632
+ offset = 0;
633
+ }
634
+ length = array.length;
635
+ augmented_array = [];
636
+ for (i = _i = 0; 0 <= length ? _i < length : _i > length; i = 0 <= length ? ++_i : --_i) {
637
+ augmented_array.push([array[i], i]);
638
+ }
639
+ augmented_array.sort(function(a, b) {
640
+ var ret;
641
+ ret = a[0] - b[0];
642
+ if (ret === 0) {
643
+ ret = a[1] - b[1];
644
+ }
645
+ return ret;
646
+ });
647
+ return augmented_array[offset][1];
648
+ };
649
+
650
+ Plugin.prototype.highestCol = function(array) {
651
+ return $.inArray(Math.max.apply(window, array), array);
652
+ };
653
+
654
+ Plugin.prototype.destroy = function() {
655
+ var $active_children, $container, active_class;
656
+ $container = this.$container;
657
+ $container.off("ss-arrange");
658
+ $container.off("ss-rearrange");
659
+ $container.off("ss-setTargetPosition");
660
+ $container.off("ss-destroy");
661
+ active_class = this.options.activeClass;
662
+ $active_children = $container.find("." + active_class);
663
+ if (this.options.enableDrag) {
664
+ $active_children.draggable('destroy');
665
+ }
666
+ if (this.options.enableCrossDrop) {
667
+ $container.droppable('destroy');
668
+ }
669
+ $active_children.removeClass(active_class);
670
+ return $container.removeClass(this.identifier);
671
+ };
672
+
673
+ return Plugin;
674
+
675
+ })();
676
+ return $.fn[pluginName] = function(options) {
677
+ return this.each(function() {
678
+ var bound_indentifier, old_class, _ref, _ref1;
679
+ old_class = (_ref = $(this).attr("class")) != null ? (_ref1 = _ref.match(/shapeshifted_container_\w+/)) != null ? _ref1[0] : void 0 : void 0;
680
+ if (old_class) {
681
+ bound_indentifier = "resize." + old_class;
682
+ $(window).off(bound_indentifier);
683
+ $(this).removeClass(old_class);
684
+ }
685
+ return $.data(this, "plugin_" + pluginName, new Plugin(this, options));
686
+ });
687
+ };
688
+ })(jQuery, window, document);
689
+
690
+ }).call(this);
@@ -0,0 +1,11 @@
1
+ /*
2
+ * jQuery UI Touch Punch 0.2.2
3
+ *
4
+ * Copyright 2011, Dave Furfero
5
+ * Dual licensed under the MIT or GPL Version 2 licenses.
6
+ *
7
+ * Depends:
8
+ * jquery.ui.widget.js
9
+ * jquery.ui.mouse.js
10
+ */
11
+ (function(b){b.support.touch="ontouchend" in document;if(!b.support.touch){return;}var c=b.ui.mouse.prototype,e=c._mouseInit,a;function d(g,h){if(g.originalEvent.touches.length>1){return;}g.preventDefault();var i=g.originalEvent.changedTouches[0],f=document.createEvent("MouseEvents");f.initMouseEvent(h,true,true,window,1,i.screenX,i.screenY,i.clientX,i.clientY,false,false,false,false,0,null);g.target.dispatchEvent(f);}c._touchStart=function(g){var f=this;if(a||!f._mouseCapture(g.originalEvent.changedTouches[0])){return;}a=true;f._touchMoved=false;d(g,"mouseover");d(g,"mousemove");d(g,"mousedown");};c._touchMove=function(f){if(!a){return;}this._touchMoved=true;d(f,"mousemove");};c._touchEnd=function(f){if(!a){return;}d(f,"mouseup");d(f,"mouseout");if(!this._touchMoved){d(f,"click");}a=false;};c._mouseInit=function(){var f=this;f.element.bind("touchstart",b.proxy(f,"_touchStart")).bind("touchmove",b.proxy(f,"_touchMove")).bind("touchend",b.proxy(f,"_touchEnd"));e.call(f);};})(jQuery);
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery-shapeshift-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Yury Snegirev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A dynamic grid system with drag and drop functionality for Ruby On Rails.
56
+ email:
57
+ - jurianp@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - MIT-LICENSE
63
+ - Rakefile
64
+ - lib/jquery/shapeshift/rails/version.rb
65
+ - vendor/assets/javascripts/jquery.shapeshift.js
66
+ - vendor/assets/javascripts/jquery.touch-punch.min.js
67
+ homepage: https://github.com/jurrick/jquery-shapeshift-rails
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.2.1
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: A dynamic grid system with drag and drop functionality for Ruby On Rails.
91
+ test_files: []