diff --git a/core/jquery.shapeshift.coffee b/core/jquery.shapeshift.coffee index 372029d..3011c51 100644 --- a/core/jquery.shapeshift.coffee +++ b/core/jquery.shapeshift.coffee @@ -44,6 +44,7 @@ cutoffStart: null cutoffEnd: null handle: false + centerDragging: true # Customize CSS cloneClass: "ss-cloned-child" @@ -517,8 +518,11 @@ ), drag_rate # Manually center the element with respect to mouse position - ui.position.left = e.pageX - $selected.parent().offset().left - selected_offset_x; - ui.position.top = e.pageY - $selected.parent().offset().top - selected_offset_y; + if options.centerDragging + ui.position.left = e.pageX - $selected.parent().offset().left - selected_offset_x; + return ui.position.top = e.pageY - $selected.parent().offset().top - selected_offset_y; + else + return 1; stop: => @globals.dragging = false @@ -763,3 +767,4 @@ $.data(@, "plugin_#{pluginName}", new Plugin(@, options)) )(jQuery, window, document) + diff --git a/core/jquery.shapeshift.js b/core/jquery.shapeshift.js index 3b3621f..34caf37 100644 --- a/core/jquery.shapeshift.js +++ b/core/jquery.shapeshift.js @@ -1,305 +1,311 @@ -// Generated by CoffeeScript 1.4.0 -(function() { - - (function($, window, document) { - var Plugin, defaults, pluginName; - pluginName = "shapeshift"; - defaults = { - selector: "*", - enableDrag: true, - enableCrossDrop: true, - enableResize: true, - enableTrash: false, - align: "center", - colWidth: null, - columns: null, - minColumns: 1, - autoHeight: true, - maxHeight: null, - minHeight: 100, - gutterX: 10, - gutterY: 10, - paddingX: 10, - paddingY: 10, - animated: true, - animateOnInit: false, - animationSpeed: 225, - animationThreshold: 100, - dragClone: false, - deleteClone: true, - dragRate: 100, - dragWhitelist: "*", - crossDropWhitelist: "*", - cutoffStart: null, - cutoffEnd: null, - handle: false, - cloneClass: "ss-cloned-child", - activeClass: "ss-active-child", - draggedClass: "ss-dragged-child", - placeholderClass: "ss-placeholder-child", - originalContainerClass: "ss-original-container", - currentContainerClass: "ss-current-container", - previousContainerClass: "ss-previous-container" - }; - Plugin = (function() { - - function Plugin(element, options) { - this.element = element; - this.options = $.extend({}, defaults, options); - this.globals = {}; - this.$container = $(element); - if (this.errorCheck()) { - this.init(); - } +(function($, window, document) { + var Plugin, defaults, pluginName; + pluginName = "shapeshift"; + defaults = { + selector: "*", + enableDrag: true, + enableCrossDrop: true, + enableResize: true, + enableTrash: false, + align: "center", + colWidth: null, + columns: null, + minColumns: 1, + autoHeight: true, + maxHeight: null, + minHeight: 100, + gutterX: 10, + gutterY: 10, + paddingX: 10, + paddingY: 10, + animated: true, + animateOnInit: false, + animationSpeed: 225, + animationThreshold: 100, + dragClone: false, + deleteClone: true, + dragRate: 100, + dragWhitelist: "*", + crossDropWhitelist: "*", + cutoffStart: null, + cutoffEnd: null, + handle: false, + centerDragging: true, + cloneClass: "ss-cloned-child", + activeClass: "ss-active-child", + draggedClass: "ss-dragged-child", + placeholderClass: "ss-placeholder-child", + originalContainerClass: "ss-original-container", + currentContainerClass: "ss-current-container", + previousContainerClass: "ss-previous-container" + }; + Plugin = (function() { + function Plugin(element, options) { + this.element = element; + this.options = $.extend({}, defaults, options); + this.globals = {}; + this.$container = $(element); + if (this.errorCheck()) { + this.init(); } + } - Plugin.prototype.errorCheck = function() { - var $children, error_msg, errors, options; - options = this.options; - errors = false; - error_msg = "Shapeshift ERROR:"; - if (options.colWidth === null) { - $children = this.$container.children(options.selector); - if ($children.length === 0) { - errors = true; - console.error("" + error_msg + " option colWidth must be specified if Shapeshift is initialized with no active children."); - } + Plugin.prototype.errorCheck = function() { + var $children, error_msg, errors, options; + options = this.options; + errors = false; + error_msg = "Shapeshift ERROR:"; + if (options.colWidth === null) { + $children = this.$container.children(options.selector); + if ($children.length === 0) { + errors = true; + console.error("" + error_msg + " option colWidth must be specified if Shapeshift is initialized with no active children."); } - return !errors; - }; + } + return !errors; + }; - Plugin.prototype.init = function() { - this.createEvents(); - this.setGlobals(); - this.setIdentifier(); - this.setActiveChildren(); - this.enableFeatures(); - this.gridInit(); - this.render(); - return this.afterInit(); - }; + Plugin.prototype.init = function() { + this.createEvents(); + this.setGlobals(); + this.setIdentifier(); + this.setActiveChildren(); + this.enableFeatures(); + this.gridInit(); + this.render(); + return this.afterInit(); + }; - Plugin.prototype.createEvents = function() { - var $container, options, - _this = this; - options = this.options; - $container = this.$container; - $container.off("ss-arrange").on("ss-arrange", function(e, trigger_drop_finished) { + Plugin.prototype.createEvents = function() { + var $container, options; + options = this.options; + $container = this.$container; + $container.off("ss-arrange").on("ss-arrange", (function(_this) { + return function(e, trigger_drop_finished) { if (trigger_drop_finished == null) { trigger_drop_finished = false; } return _this.render(false, trigger_drop_finished); - }); - $container.off("ss-rearrange").on("ss-rearrange", function() { + }; + })(this)); + $container.off("ss-rearrange").on("ss-rearrange", (function(_this) { + return function() { return _this.render(true); - }); - $container.off("ss-setTargetPosition").on("ss-setTargetPosition", function() { + }; + })(this)); + $container.off("ss-setTargetPosition").on("ss-setTargetPosition", (function(_this) { + return function() { return _this.setTargetPosition(); - }); - $container.off("ss-destroy").on("ss-destroy", function() { + }; + })(this)); + $container.off("ss-destroy").on("ss-destroy", (function(_this) { + return function() { return _this.destroy(); - }); - return $container.off("ss-shuffle").on("ss-shuffle", function() { + }; + })(this)); + return $container.off("ss-shuffle").on("ss-shuffle", (function(_this) { + return function() { return _this.shuffle(); - }); - }; + }; + })(this)); + }; - Plugin.prototype.setGlobals = function() { - this.globals.animated = this.options.animateOnInit; - return this.globals.dragging = false; - }; + Plugin.prototype.setGlobals = function() { + this.globals.animated = this.options.animateOnInit; + return this.globals.dragging = false; + }; - Plugin.prototype.afterInit = function() { - return this.globals.animated = this.options.animated; - }; + Plugin.prototype.afterInit = function() { + return this.globals.animated = this.options.animated; + }; - Plugin.prototype.setIdentifier = function() { - this.identifier = "shapeshifted_container_" + Math.random().toString(36).substring(7); - return this.$container.addClass(this.identifier); - }; + Plugin.prototype.setIdentifier = function() { + this.identifier = "shapeshifted_container_" + Math.random().toString(36).substring(7); + return this.$container.addClass(this.identifier); + }; - Plugin.prototype.enableFeatures = function() { - if (this.options.enableResize) { - this.enableResize(); - } - if (this.options.enableDrag || this.options.enableCrossDrop) { - return this.enableDragNDrop(); - } - }; + Plugin.prototype.enableFeatures = function() { + if (this.options.enableResize) { + this.enableResize(); + } + if (this.options.enableDrag || this.options.enableCrossDrop) { + return this.enableDragNDrop(); + } + }; - Plugin.prototype.setActiveChildren = function() { - var $children, active_child_class, colspan, columns, i, min_columns, options, total, _i, _j, _ref, _results; - options = this.options; - $children = this.$container.children(options.selector); - active_child_class = options.activeClass; - total = $children.length; - for (i = _i = 0; 0 <= total ? _i < total : _i > total; i = 0 <= total ? ++_i : --_i) { - $($children[i]).addClass(active_child_class); - } - this.setParsedChildren(); - columns = options.columns; - _results = []; - for (i = _j = 0, _ref = this.parsedChildren.length; 0 <= _ref ? _j < _ref : _j > _ref; i = 0 <= _ref ? ++_j : --_j) { - colspan = this.parsedChildren[i].colspan; - min_columns = options.minColumns; - if (colspan > columns && colspan > min_columns) { - options.minColumns = colspan; - _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)); - } else { - _results.push(void 0); - } + Plugin.prototype.setActiveChildren = function() { + var $children, active_child_class, colspan, columns, i, min_columns, options, total, _i, _j, _ref, _results; + options = this.options; + $children = this.$container.children(options.selector); + active_child_class = options.activeClass; + total = $children.length; + for (i = _i = 0; 0 <= total ? _i < total : _i > total; i = 0 <= total ? ++_i : --_i) { + $($children[i]).addClass(active_child_class); + } + this.setParsedChildren(); + columns = options.columns; + _results = []; + for (i = _j = 0, _ref = this.parsedChildren.length; 0 <= _ref ? _j < _ref : _j > _ref; i = 0 <= _ref ? ++_j : --_j) { + colspan = this.parsedChildren[i].colspan; + min_columns = options.minColumns; + if (colspan > columns && colspan > min_columns) { + options.minColumns = colspan; + _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)); + } else { + _results.push(void 0); } - return _results; - }; + } + return _results; + }; - Plugin.prototype.setParsedChildren = function() { - var $child, $children, child, i, parsedChildren, total, _i; - $children = this.$container.find("." + this.options.activeClass).filter(":visible"); - total = $children.length; - parsedChildren = []; - for (i = _i = 0; 0 <= total ? _i < total : _i > total; i = 0 <= total ? ++_i : --_i) { - $child = $($children[i]); - child = { - i: i, - el: $child, - colspan: parseInt($child.attr("data-ss-colspan")) || 1, - height: $child.outerHeight() - }; - parsedChildren.push(child); - } - return this.parsedChildren = parsedChildren; - }; + Plugin.prototype.setParsedChildren = function() { + var $child, $children, child, i, parsedChildren, total, _i; + $children = this.$container.find("." + this.options.activeClass).filter(":visible"); + total = $children.length; + parsedChildren = []; + for (i = _i = 0; 0 <= total ? _i < total : _i > total; i = 0 <= total ? ++_i : --_i) { + $child = $($children[i]); + child = { + i: i, + el: $child, + colspan: parseInt($child.attr("data-ss-colspan")) || 1, + height: $child.outerHeight() + }; + parsedChildren.push(child); + } + return this.parsedChildren = parsedChildren; + }; - Plugin.prototype.gridInit = function() { - var fc_colspan, fc_width, first_child, gutter_x, single_width; - gutter_x = this.options.gutterX; - if (!(this.options.colWidth >= 1)) { - first_child = this.parsedChildren[0]; - fc_width = first_child.el.outerWidth(); - fc_colspan = first_child.colspan; - single_width = (fc_width - ((fc_colspan - 1) * gutter_x)) / fc_colspan; - return this.globals.col_width = single_width + gutter_x; - } else { - return this.globals.col_width = this.options.colWidth + gutter_x; - } - }; + Plugin.prototype.gridInit = function() { + var fc_colspan, fc_width, first_child, gutter_x, single_width; + gutter_x = this.options.gutterX; + if (!(this.options.colWidth >= 1)) { + first_child = this.parsedChildren[0]; + fc_width = first_child.el.outerWidth(); + fc_colspan = first_child.colspan; + single_width = (fc_width - ((fc_colspan - 1) * gutter_x)) / fc_colspan; + return this.globals.col_width = single_width + gutter_x; + } else { + return this.globals.col_width = this.options.colWidth + gutter_x; + } + }; - Plugin.prototype.render = function(reparse, trigger_drop_finished) { - if (reparse == null) { - reparse = false; - } - if (reparse) { - this.setActiveChildren(); - } - this.setGridColumns(); - return this.arrange(false, trigger_drop_finished); - }; + Plugin.prototype.render = function(reparse, trigger_drop_finished) { + if (reparse == null) { + reparse = false; + } + if (reparse) { + this.setActiveChildren(); + } + this.setGridColumns(); + return this.arrange(false, trigger_drop_finished); + }; - Plugin.prototype.setGridColumns = function() { - var actual_columns, children_count, col_width, colspan, columns, globals, grid_width, gutter_x, i, inner_width, minColumns, options, padding_x, _i, _ref; - globals = this.globals; - options = this.options; - col_width = globals.col_width; - gutter_x = options.gutterX; - padding_x = options.paddingX; - inner_width = this.$container.innerWidth() - (padding_x * 2); - minColumns = options.minColumns; - columns = options.columns || Math.floor((inner_width + gutter_x) / col_width); - if (minColumns && minColumns > columns) { - columns = minColumns; - } - globals.columns = columns; - children_count = this.parsedChildren.length; - if (columns > children_count) { - actual_columns = 0; - for (i = _i = 0, _ref = this.parsedChildren.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { - colspan = this.parsedChildren[i].colspan; - if (colspan + actual_columns <= columns) { - actual_columns += colspan; - } + Plugin.prototype.setGridColumns = function() { + var actual_columns, children_count, col_width, colspan, columns, globals, grid_width, gutter_x, i, inner_width, minColumns, options, padding_x, _i, _ref; + globals = this.globals; + options = this.options; + col_width = globals.col_width; + gutter_x = options.gutterX; + padding_x = options.paddingX; + inner_width = this.$container.innerWidth() - (padding_x * 2); + minColumns = options.minColumns; + columns = options.columns || Math.floor((inner_width + gutter_x) / col_width); + if (minColumns && minColumns > columns) { + columns = minColumns; + } + globals.columns = columns; + children_count = this.parsedChildren.length; + if (columns > children_count) { + actual_columns = 0; + for (i = _i = 0, _ref = this.parsedChildren.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + colspan = this.parsedChildren[i].colspan; + if (colspan + actual_columns <= columns) { + actual_columns += colspan; } - columns = actual_columns; } - globals.child_offset = padding_x; - switch (options.align) { - case "center": - grid_width = (columns * col_width) - gutter_x; - return globals.child_offset += (inner_width - grid_width) / 2; - case "right": - grid_width = (columns * col_width) - gutter_x; - return globals.child_offset += inner_width - grid_width; - } - }; + columns = actual_columns; + } + globals.child_offset = padding_x; + switch (options.align) { + case "center": + grid_width = (columns * col_width) - gutter_x; + return globals.child_offset += (inner_width - grid_width) / 2; + case "right": + grid_width = (columns * col_width) - gutter_x; + return globals.child_offset += inner_width - grid_width; + } + }; - Plugin.prototype.arrange = function(reparse, trigger_drop_finished) { - 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; - if (reparse) { - this.setParsedChildren(); + Plugin.prototype.arrange = function(reparse, trigger_drop_finished) { + 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; + if (reparse) { + this.setParsedChildren(); + } + globals = this.globals; + options = this.options; + $container = this.$container; + child_positions = this.getPositions(); + parsed_children = this.parsedChildren; + total_children = parsed_children.length; + animated = globals.animated && total_children <= options.animationThreshold; + animation_speed = options.animationSpeed; + dragged_class = options.draggedClass; + for (i = _i = 0; 0 <= total_children ? _i < total_children : _i > total_children; i = 0 <= total_children ? ++_i : --_i) { + $child = parsed_children[i].el; + attributes = child_positions[i]; + is_dragged_child = $child.hasClass(dragged_class); + if (is_dragged_child) { + placeholder_class = options.placeholderClass; + $child = $child.siblings("." + placeholder_class); } - globals = this.globals; - options = this.options; - $container = this.$container; - child_positions = this.getPositions(); - parsed_children = this.parsedChildren; - total_children = parsed_children.length; - animated = globals.animated && total_children <= options.animationThreshold; - animation_speed = options.animationSpeed; - dragged_class = options.draggedClass; - for (i = _i = 0; 0 <= total_children ? _i < total_children : _i > total_children; i = 0 <= total_children ? ++_i : --_i) { - $child = parsed_children[i].el; - attributes = child_positions[i]; - is_dragged_child = $child.hasClass(dragged_class); - if (is_dragged_child) { - placeholder_class = options.placeholderClass; - $child = $child.siblings("." + placeholder_class); - } - if (animated && !is_dragged_child) { - $child.stop(true, false).animate(attributes, animation_speed, function() {}); - } else { - $child.css(attributes); - } + if (animated && !is_dragged_child) { + $child.stop(true, false).animate(attributes, animation_speed, function() {}); + } else { + $child.css(attributes); } - if (trigger_drop_finished) { - if (animated) { - setTimeout((function() { - return $container.trigger("ss-drop-complete"); - }), animation_speed); - } else { - $container.trigger("ss-drop-complete"); - } + } + if (trigger_drop_finished) { + if (animated) { + setTimeout((function() { + return $container.trigger("ss-drop-complete"); + }), animation_speed); + } else { + $container.trigger("ss-drop-complete"); } - $container.trigger("ss-arranged"); - if (options.autoHeight) { - container_height = globals.container_height; - max_height = options.maxHeight; - min_height = options.minHeight; - if (min_height && container_height < min_height) { - container_height = min_height; - } else if (max_height && container_height > max_height) { - container_height = max_height; - } - return $container.height(container_height); + } + $container.trigger("ss-arranged"); + if (options.autoHeight) { + container_height = globals.container_height; + max_height = options.maxHeight; + min_height = options.minHeight; + if (min_height && container_height < min_height) { + container_height = min_height; + } else if (max_height && container_height > max_height) { + container_height = max_height; } - }; + return $container.height(container_height); + } + }; - Plugin.prototype.getPositions = function(include_dragged) { - 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, - _this = this; - if (include_dragged == null) { - include_dragged = true; - } - globals = this.globals; - options = this.options; - gutter_y = options.gutterY; - padding_y = options.paddingY; - dragged_class = options.draggedClass; - parsed_children = this.parsedChildren; - total_children = parsed_children.length; - col_heights = []; - for (i = _i = 0, _ref = globals.columns; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { - col_heights.push(padding_y); - } - savePosition = function(child) { + Plugin.prototype.getPositions = function(include_dragged) { + 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; + if (include_dragged == null) { + include_dragged = true; + } + globals = this.globals; + options = this.options; + gutter_y = options.gutterY; + padding_y = options.paddingY; + dragged_class = options.draggedClass; + parsed_children = this.parsedChildren; + total_children = parsed_children.length; + col_heights = []; + for (i = _i = 0, _ref = globals.columns; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + col_heights.push(padding_y); + } + savePosition = (function(_this) { + return function(child) { var col, colspan, j, offset_x, offset_y, _j, _results; col = child.col; colspan = child.colspan; @@ -318,7 +324,9 @@ return _results; } }; - determineMultiposition = function(child) { + })(this); + determineMultiposition = (function(_this) { + return function(child) { var chosen_col, col, colspan, height, kosher, next_height, offset, possible_col_heights, possible_cols, span, _j, _k; possible_cols = col_heights.length - child.colspan + 1; possible_col_heights = col_heights.slice(0).splice(0, possible_cols); @@ -342,8 +350,10 @@ } return chosen_col; }; - saved_children = []; - recalculateSavedChildren = function() { + })(this); + saved_children = []; + recalculateSavedChildren = (function(_this) { + return function() { var index, pop_i, saved_child, saved_i, to_pop, _j, _k, _ref1, _ref2, _results; to_pop = []; for (saved_i = _j = 0, _ref1 = saved_children.length; 0 <= _ref1 ? _j < _ref1 : _j > _ref1; saved_i = 0 <= _ref1 ? ++_j : --_j) { @@ -361,8 +371,10 @@ } return _results; }; - positions = []; - (determinePositions = function() { + })(this); + positions = []; + (determinePositions = (function(_this) { + return function() { var child, _j, _results; _results = []; for (i = _j = 0; 0 <= total_children ? _j < total_children : _j > total_children; i = 0 <= total_children ? ++_j : --_j) { @@ -384,38 +396,39 @@ } } return _results; - })(); - if (options.autoHeight) { - grid_height = col_heights[this.highestCol(col_heights)] - gutter_y; - globals.container_height = grid_height + padding_y; - } - return positions; - }; + }; + })(this))(); + if (options.autoHeight) { + grid_height = col_heights[this.highestCol(col_heights)] - gutter_y; + globals.container_height = grid_height + padding_y; + } + return positions; + }; - Plugin.prototype.enableDragNDrop = function() { - 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, - _this = this; - options = this.options; - $container = this.$container; - active_class = options.activeClass; - dragged_class = options.draggedClass; - placeholder_class = options.placeholderClass; - original_container_class = options.originalContainerClass; - current_container_class = options.currentContainerClass; - previous_container_class = options.previousContainerClass; - delete_clone = options.deleteClone; - drag_rate = options.dragRate; - drag_clone = options.dragClone; - clone_class = options.cloneClass; - $selected = $placeholder = $clone = selected_offset_y = selected_offset_x = null; - drag_timeout = false; - if (options.enableDrag) { - $container.children("." + active_class).filter(options.dragWhitelist).draggable({ - addClasses: false, - containment: 'document', - handle: options.handle, - zIndex: 9999, - start: function(e, ui) { + Plugin.prototype.enableDragNDrop = function() { + 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; + options = this.options; + $container = this.$container; + active_class = options.activeClass; + dragged_class = options.draggedClass; + placeholder_class = options.placeholderClass; + original_container_class = options.originalContainerClass; + current_container_class = options.currentContainerClass; + previous_container_class = options.previousContainerClass; + delete_clone = options.deleteClone; + drag_rate = options.dragRate; + drag_clone = options.dragClone; + clone_class = options.cloneClass; + $selected = $placeholder = $clone = selected_offset_y = selected_offset_x = null; + drag_timeout = false; + if (options.enableDrag) { + $container.children("." + active_class).filter(options.dragWhitelist).draggable({ + addClasses: false, + containment: 'document', + handle: options.handle, + zIndex: 9999, + start: (function(_this) { + return function(e, ui) { var selected_tag; _this.globals.dragging = true; $selected = $(e.target); @@ -428,8 +441,10 @@ $selected.parent().addClass(original_container_class).addClass(current_container_class); selected_offset_y = $selected.outerHeight() / 2; return selected_offset_x = $selected.outerWidth() / 2; - }, - drag: function(e, ui) { + }; + })(this), + drag: (function(_this) { + return function(e, ui) { if (!drag_timeout && !(drag_clone && delete_clone && $("." + current_container_class)[0] === $("." + original_container_class)[0])) { $placeholder.remove().appendTo("." + current_container_class); $("." + current_container_class).trigger("ss-setTargetPosition"); @@ -438,10 +453,16 @@ return drag_timeout = false; }), drag_rate); } - ui.position.left = e.pageX - $selected.parent().offset().left - selected_offset_x; - return ui.position.top = e.pageY - $selected.parent().offset().top - selected_offset_y; - }, - stop: function() { + if (options.centerDragging) { + ui.position.left = e.pageX - $selected.parent().offset().left - selected_offset_x; + return ui.position.top = e.pageY - $selected.parent().offset().top - selected_offset_y; + } else { + return 1; + } + }; + })(this), + stop: (function(_this) { + return function() { var $current_container, $original_container, $previous_container; _this.globals.dragging = false; $original_container = $("." + original_container_class); @@ -454,9 +475,7 @@ $clone.remove(); $("." + current_container_class).trigger("ss-rearrange"); } else { - $clone.removeClass(clone_class); - $original_container.shapeshift($original_container.data("plugin_shapeshift").options); - $current_container.shapeshift($current_container.data("plugin_shapeshift").options); + $clone.removeClass(clone_class); } } if ($original_container[0] === $current_container[0]) { @@ -469,19 +488,23 @@ $current_container.trigger("ss-arrange", true).removeClass(current_container_class); $previous_container.trigger("ss-arrange").removeClass(previous_container_class); return $selected = $placeholder = null; - } - }); - } - if (options.enableCrossDrop) { - return $container.droppable({ - accept: options.crossDropWhitelist, - tolerance: 'intersect', - over: function(e) { + }; + })(this) + }); + } + if (options.enableCrossDrop) { + return $container.droppable({ + accept: options.crossDropWhitelist, + tolerance: 'intersect', + over: (function(_this) { + return function(e) { $("." + previous_container_class).removeClass(previous_container_class); $("." + current_container_class).removeClass(current_container_class).addClass(previous_container_class); return $(e.target).addClass(current_container_class); - }, - drop: function(e, selected) { + }; + })(this), + drop: (function(_this) { + return function(e, selected) { var $current_container, $original_container, $previous_container; if (_this.options.enableTrash) { $original_container = $("." + original_container_class); @@ -494,88 +517,85 @@ $current_container.trigger("ss-rearrange").removeClass(current_container_class); return $previous_container.trigger("ss-arrange").removeClass(previous_container_class); } - } - }); - } - }; + }; + })(this) + }); + } + }; - Plugin.prototype.setTargetPosition = function() { - 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; - options = this.options; - if (!options.enableTrash) { - dragged_class = options.draggedClass; - $selected = $("." + dragged_class); - $start_container = $selected.parent(); - parsed_children = this.parsedChildren; - child_positions = this.getPositions(false); - total_positions = child_positions.length; - selected_x = $selected.offset().left - $start_container.offset().left + (this.globals.col_width / 2); - selected_y = $selected.offset().top - $start_container.offset().top + ($selected.height() / 2); - shortest_distance = 9999999; - target_position = 0; - if (total_positions > 1) { - cutoff_start = options.cutoffStart + 1 || 0; - cutoff_end = options.cutoffEnd || total_positions; - for (position_i = _i = cutoff_start; cutoff_start <= cutoff_end ? _i < cutoff_end : _i > cutoff_end; position_i = cutoff_start <= cutoff_end ? ++_i : --_i) { - attributes = child_positions[position_i]; - if (attributes) { - y_dist = selected_x - attributes.left; - x_dist = selected_y - attributes.top; - if (y_dist > 0 && x_dist > 0) { - distance = Math.sqrt((x_dist * x_dist) + (y_dist * y_dist)); - if (distance < shortest_distance) { - shortest_distance = distance; - target_position = position_i; - if (position_i === total_positions - 1) { - if (y_dist > parsed_children[position_i].height / 2) { - target_position++; - } + Plugin.prototype.setTargetPosition = function() { + 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; + options = this.options; + if (!options.enableTrash) { + dragged_class = options.draggedClass; + $selected = $("." + dragged_class); + $start_container = $selected.parent(); + parsed_children = this.parsedChildren; + child_positions = this.getPositions(false); + total_positions = child_positions.length; + selected_x = $selected.offset().left - $start_container.offset().left + (this.globals.col_width / 2); + selected_y = $selected.offset().top - $start_container.offset().top + ($selected.height() / 2); + shortest_distance = 9999999; + target_position = 0; + if (total_positions > 1) { + cutoff_start = options.cutoffStart + 1 || 0; + cutoff_end = options.cutoffEnd || total_positions; + for (position_i = _i = cutoff_start; cutoff_start <= cutoff_end ? _i < cutoff_end : _i > cutoff_end; position_i = cutoff_start <= cutoff_end ? ++_i : --_i) { + attributes = child_positions[position_i]; + if (attributes) { + y_dist = selected_x - attributes.left; + x_dist = selected_y - attributes.top; + if (y_dist > 0 && x_dist > 0) { + distance = Math.sqrt((x_dist * x_dist) + (y_dist * y_dist)); + if (distance < shortest_distance) { + shortest_distance = distance; + target_position = position_i; + if (position_i === total_positions - 1) { + if (y_dist > parsed_children[position_i].height / 2) { + target_position++; } } } } } - if (target_position === parsed_children.length) { - $target = parsed_children[target_position - 1].el; - $selected.insertAfter($target); - } else { - $target = parsed_children[target_position].el; - $selected.insertBefore($target); - } + } + if (target_position === parsed_children.length) { + $target = parsed_children[target_position - 1].el; + $selected.insertAfter($target); } else { - if (total_positions === 1) { - attributes = child_positions[0]; - if (attributes.left < selected_x) { - this.$container.append($selected); - } else { - this.$container.prepend($selected); - } - } else { + $target = parsed_children[target_position].el; + $selected.insertBefore($target); + } + } else { + if (total_positions === 1) { + attributes = child_positions[0]; + if (attributes.left < selected_x) { this.$container.append($selected); + } else { + this.$container.prepend($selected); } + } else { + this.$container.append($selected); } - this.arrange(true); - if ($start_container[0] !== $selected.parent()[0]) { - previous_container_class = options.previousContainerClass; - if ($("." + previous_container_class).data("plugin_shapeshift").options.enableCrossDrop == true) { - return $("." + previous_container_class).trigger("ss-rearrange"); - } else { - return $("." + previous_container_class); - } - } - } else { - placeholder_class = this.options.placeholderClass; - return $("." + placeholder_class).remove(); } - }; + this.arrange(true); + if ($start_container[0] !== $selected.parent()[0]) { + previous_container_class = options.previousContainerClass; + return $("." + previous_container_class).trigger("ss-rearrange"); + } + } else { + placeholder_class = this.options.placeholderClass; + return $("." + placeholder_class).remove(); + } + }; - Plugin.prototype.enableResize = function() { - var animation_speed, binding, resizing, - _this = this; - animation_speed = this.options.animationSpeed; - resizing = false; - binding = "resize." + this.identifier; - return $(window).on(binding, function() { + Plugin.prototype.enableResize = function() { + var animation_speed, binding, resizing; + animation_speed = this.options.animationSpeed; + resizing = false; + binding = "resize." + this.identifier; + return $(window).on(binding, (function(_this) { + return function() { if (!resizing) { resizing = true; setTimeout((function() { @@ -589,102 +609,101 @@ return _this.render(); }, animation_speed / 3); } - }); - }; - - Plugin.prototype.shuffle = function() { - var calculateShuffled; - calculateShuffled = function(container, activeClass) { - var shuffle; - shuffle = function(arr) { - var i, j, x; - j = void 0; - x = void 0; - i = arr.length; - while (i) { - j = parseInt(Math.random() * i); - x = arr[--i]; - arr[i] = arr[j]; - arr[j] = x; - } - return arr; - }; - return container.each(function() { - var items; - items = container.find("." + activeClass).filter(":visible"); - if (items.length) { - return container.html(shuffle(items)); - } else { - return this; - } - }); }; - if (!this.globals.dragging) { - calculateShuffled(this.$container, this.options.activeClass); - this.enableFeatures(); - return this.$container.trigger("ss-rearrange"); - } - }; + })(this)); + }; - Plugin.prototype.lowestCol = function(array, offset) { - var augmented_array, i, length, _i; - if (offset == null) { - offset = 0; - } - length = array.length; - augmented_array = []; - for (i = _i = 0; 0 <= length ? _i < length : _i > length; i = 0 <= length ? ++_i : --_i) { - augmented_array.push([array[i], i]); - } - augmented_array.sort(function(a, b) { - var ret; - ret = a[0] - b[0]; - if (ret === 0) { - ret = a[1] - b[1]; + Plugin.prototype.shuffle = function() { + var calculateShuffled; + calculateShuffled = function(container, activeClass) { + var shuffle; + shuffle = function(arr) { + var i, j, x; + j = void 0; + x = void 0; + i = arr.length; + while (i) { + j = parseInt(Math.random() * i); + x = arr[--i]; + arr[i] = arr[j]; + arr[j] = x; + } + return arr; + }; + return container.each(function() { + var items; + items = container.find("." + activeClass).filter(":visible"); + if (items.length) { + return container.html(shuffle(items)); + } else { + return this; } - return ret; }); - return augmented_array[offset][1]; - }; - - Plugin.prototype.highestCol = function(array) { - return $.inArray(Math.max.apply(window, array), array); }; + if (!this.globals.dragging) { + calculateShuffled(this.$container, this.options.activeClass); + this.enableFeatures(); + return this.$container.trigger("ss-rearrange"); + } + }; - Plugin.prototype.destroy = function() { - var $active_children, $container, active_class; - $container = this.$container; - $container.off("ss-arrange"); - $container.off("ss-rearrange"); - $container.off("ss-setTargetPosition"); - $container.off("ss-destroy"); - active_class = this.options.activeClass; - $active_children = $container.find("." + active_class); - if (this.options.enableDrag) { - $active_children.draggable('destroy'); - } - if (this.options.enableCrossDrop) { - $container.droppable('destroy'); + Plugin.prototype.lowestCol = function(array, offset) { + var augmented_array, i, length, _i; + if (offset == null) { + offset = 0; + } + length = array.length; + augmented_array = []; + for (i = _i = 0; 0 <= length ? _i < length : _i > length; i = 0 <= length ? ++_i : --_i) { + augmented_array.push([array[i], i]); + } + augmented_array.sort(function(a, b) { + var ret; + ret = a[0] - b[0]; + if (ret === 0) { + ret = a[1] - b[1]; } - $active_children.removeClass(active_class); - return $container.removeClass(this.identifier); - }; + return ret; + }); + return augmented_array[offset][1]; + }; - return Plugin; + Plugin.prototype.highestCol = function(array) { + return $.inArray(Math.max.apply(window, array), array); + }; - })(); - return $.fn[pluginName] = function(options) { - return this.each(function() { - var bound_indentifier, old_class, _ref, _ref1; - old_class = (_ref = $(this).attr("class")) != null ? (_ref1 = _ref.match(/shapeshifted_container_\w+/)) != null ? _ref1[0] : void 0 : void 0; - if (old_class) { - bound_indentifier = "resize." + old_class; - $(window).off(bound_indentifier); - $(this).removeClass(old_class); - } - return $.data(this, "plugin_" + pluginName, new Plugin(this, options)); - }); + Plugin.prototype.destroy = function() { + var $active_children, $container, active_class; + $container = this.$container; + $container.off("ss-arrange"); + $container.off("ss-rearrange"); + $container.off("ss-setTargetPosition"); + $container.off("ss-destroy"); + active_class = this.options.activeClass; + $active_children = $container.find("." + active_class); + if (this.options.enableDrag) { + $active_children.draggable('destroy'); + } + if (this.options.enableCrossDrop) { + $container.droppable('destroy'); + } + $active_children.removeClass(active_class); + return $container.removeClass(this.identifier); }; - })(jQuery, window, document); -}).call(this); + return Plugin; + + })(); + return $.fn[pluginName] = function(options) { + return this.each(function() { + var bound_indentifier, old_class, _ref, _ref1; + old_class = (_ref = $(this).attr("class")) != null ? (_ref1 = _ref.match(/shapeshifted_container_\w+/)) != null ? _ref1[0] : void 0 : void 0; + if (old_class) { + bound_indentifier = "resize." + old_class; + $(window).off(bound_indentifier); + $(this).removeClass(old_class); + } + return $.data(this, "plugin_" + pluginName, new Plugin(this, options)); + }); + }; +})(jQuery, window, document); diff --git a/core/jquery.shapeshift.min.js b/core/jquery.shapeshift.min.js index cc66246..4367708 100644 --- a/core/jquery.shapeshift.min.js +++ b/core/jquery.shapeshift.min.js @@ -1 +1 @@ -(function(){(function(e,c,a){var b,f,d;d="shapeshift";f={selector:"*",enableDrag:true,enableCrossDrop:true,enableResize:true,enableTrash:false,align:"center",colWidth:null,columns:null,minColumns:1,autoHeight:true,maxHeight:null,minHeight:100,gutterX:10,gutterY:10,paddingX:10,paddingY:10,animated:true,animateOnInit:false,animationSpeed:225,animationThreshold:100,dragClone:false,deleteClone:true,dragRate:100,dragWhitelist:"*",crossDropWhitelist:"*",cutoffStart:null,cutoffEnd:null,handle:false,cloneClass:"ss-cloned-child",activeClass:"ss-active-child",draggedClass:"ss-dragged-child",placeholderClass:"ss-placeholder-child",originalContainerClass:"ss-original-container",currentContainerClass:"ss-current-container",previousContainerClass:"ss-previous-container"};b=(function(){function g(i,h){this.element=i;this.options=e.extend({},f,h);this.globals={};this.$container=e(i);if(this.errorCheck()){this.init()}}g.prototype.errorCheck=function(){var h,j,k,i;i=this.options;k=false;j="Shapeshift ERROR:";if(i.colWidth===null){h=this.$container.children(i.selector);if(h.length===0){k=true;console.error(""+j+" option colWidth must be specified if Shapeshift is initialized with no active children.")}}return !k};g.prototype.init=function(){this.createEvents();this.setGlobals();this.setIdentifier();this.setActiveChildren();this.enableFeatures();this.gridInit();this.render();return this.afterInit()};g.prototype.createEvents=function(){var i,h,j=this;h=this.options;i=this.$container;i.off("ss-arrange").on("ss-arrange",function(l,k){if(k==null){k=false}return j.render(false,k)});i.off("ss-rearrange").on("ss-rearrange",function(){return j.render(true)});i.off("ss-setTargetPosition").on("ss-setTargetPosition",function(){return j.setTargetPosition()});i.off("ss-destroy").on("ss-destroy",function(){return j.destroy()});return i.off("ss-shuffle").on("ss-shuffle",function(){return j.shuffle()})};g.prototype.setGlobals=function(){this.globals.animated=this.options.animateOnInit;return this.globals.dragging=false};g.prototype.afterInit=function(){return this.globals.animated=this.options.animated};g.prototype.setIdentifier=function(){this.identifier="shapeshifted_container_"+Math.random().toString(36).substring(7);return this.$container.addClass(this.identifier)};g.prototype.enableFeatures=function(){if(this.options.enableResize){this.enableResize()}if(this.options.enableDrag||this.options.enableCrossDrop){return this.enableDragNDrop()}};g.prototype.setActiveChildren=function(){var s,p,h,j,o,q,t,r,m,l,n,k;t=this.options;s=this.$container.children(t.selector);p=t.activeClass;r=s.length;for(o=m=0;0<=r?mr;o=0<=r?++m:--m){e(s[o]).addClass(p)}this.setParsedChildren();j=t.columns;k=[];for(o=l=0,n=this.parsedChildren.length;0<=n?ln;o=0<=n?++l:--l){h=this.parsedChildren[o].colspan;q=t.minColumns;if(h>j&&h>q){t.minColumns=h;k.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 "+h))}else{k.push(void 0)}}return k};g.prototype.setParsedChildren=function(){var m,h,o,j,n,k,l;h=this.$container.find("."+this.options.activeClass).filter(":visible");k=h.length;n=[];for(j=l=0;0<=k?lk;j=0<=k?++l:--l){m=e(h[j]);o={i:j,el:m,colspan:parseInt(m.attr("data-ss-colspan"))||1,height:m.outerHeight()};n.push(o)}return this.parsedChildren=n};g.prototype.gridInit=function(){var i,h,k,j,l;j=this.options.gutterX;if(!(this.options.colWidth>=1)){k=this.parsedChildren[0];h=k.el.outerWidth();i=k.colspan;l=(h-((i-1)*j))/i;return this.globals.col_width=l+j}else{return this.globals.col_width=this.options.colWidth+j}};g.prototype.render=function(i,h){if(i==null){i=false}this.setGridColumns();return this.arrange(i,h)};g.prototype.setGridColumns=function(){var s,v,u,j,l,q,k,t,p,h,r,w,m,n,o;q=this.globals;w=this.options;u=q.col_width;t=w.gutterX;m=w.paddingX;h=this.$container.innerWidth()-(m*2);r=w.minColumns;l=w.columns||Math.floor((h+t)/u);if(r&&r>l){l=r}q.columns=l;v=this.parsedChildren.length;if(l>v){s=0;for(p=n=0,o=this.parsedChildren.length;0<=o?no;p=0<=o?++n:--n){j=this.parsedChildren[p].colspan;if(j+s<=l){s+=j}}l=s}q.child_offset=m;switch(w.align){case"center":k=(l*u)-t;return q.child_offset+=(h-k)/2;case"right":k=(l*u)-t;return q.child_offset+=h-k}};g.prototype.arrange=function(m,y){var z,v,x,h,r,o,s,q,n,w,j,u,B,p,A,t,l,k;if(m){this.setParsedChildren()}n=this.globals;p=this.options;v=this.$container;o=this.getPositions();A=this.parsedChildren;l=A.length;x=n.animated&&l<=p.animationThreshold;h=p.animationSpeed;q=p.draggedClass;for(w=k=0;0<=l?kl;w=0<=l?++k:--k){z=A[w].el;r=o[w];j=z.hasClass(q);if(j){t=p.placeholderClass;z=z.siblings("."+t)}if(x&&!j){z.stop(true,false).animate(r,h,function(){})}else{z.css(r)}}if(y){if(x){setTimeout((function(){return v.trigger("ss-drop-complete")}),h)}else{v.trigger("ss-drop-complete")}}v.trigger("ss-arranged");if(p.autoHeight){s=n.container_height;u=p.maxHeight;B=p.minHeight;if(B&&su){s=u}}return v.height(s)}};g.prototype.getPositions=function(v){var n,y,q,o,l,z,h,w,m,t,B,p,A,x,s,k,j,r,u=this;if(v==null){v=true}l=this.globals;m=this.options;h=m.gutterY;t=m.paddingY;o=m.draggedClass;B=this.parsedChildren;k=B.length;n=[];for(w=j=0,r=l.columns;0<=r?jr;w=0<=r?++j:--j){n.push(t)}x=function(I){var D,H,C,G,E,F,i;D=I.col;H=I.colspan;G=(I.col*l.col_width)+l.child_offset;E=n[D];p[I.i]={left:G,top:E};n[D]+=I.height+h;if(H>=1){i=[];for(C=F=1;1<=H?FH;C=1<=H?++F:--F){i.push(n[D+C]=n[D])}return i}};y=function(i){var N,E,C,M,I,D,H,L,J,K,G,F;J=n.length-i.colspan+1;L=n.slice(0).splice(0,J);N=void 0;for(H=G=0;0<=J?GJ;H=0<=J?++G:--G){E=u.lowestCol(L,H);C=i.colspan;M=n[E];I=true;for(K=F=1;1<=C?FC;K=1<=C?++F:--F){D=n[E+K];if(MH;I=0<=H?++G:--G){E=s[I];E.col=y(E);if(E.col>=0){x(E);K.push(I)}}F=[];for(i=D=C=K.length-1;D>=0;i=D+=-1){J=K[i];F.push(s.splice(J,1))}return F};p=[];(q=function(){var D,C,i;i=[];for(w=C=0;0<=k?Ck;w=0<=k?++C:--C){D=B[w];if(!(!v&&D.el.hasClass(o))){if(D.colspan>1){D.col=y(D)}else{D.col=u.lowestCol(n)}if(D.col===void 0){s.push(D)}else{x(D)}i.push(A())}else{i.push(void 0)}}return i})();if(m.autoHeight){z=n[this.highestCol(n)]-h;l.container_height=z+t}return p};g.prototype.enableDragNDrop=function(){var p,v,n,y,l,t,o,w,q,z,s,m,j,x,r,k,i,h,u=this;j=this.options;v=this.$container;l=j.activeClass;m=j.draggedClass;r=j.placeholderClass;x=j.originalContainerClass;o=j.currentContainerClass;k=j.previousContainerClass;w=j.deleteClone;z=j.dragRate;q=j.dragClone;t=j.cloneClass;y=n=p=h=i=null;s=false;if(j.enableDrag){v.children("."+l).filter(j.dragWhitelist).draggable({addClasses:false,containment:"document",handle:j.handle,zIndex:9999,start:function(C,B){var A;u.globals.dragging=true;y=e(C.target);if(q){p=y.clone(false,false).insertBefore(y).addClass(t)}y.addClass(m);A=y.prop("tagName");n=e("<"+A+" class='"+r+"' style='height: "+(y.height())+"px; width: "+(y.width())+"px'>");y.parent().addClass(x).addClass(o);h=y.outerHeight()/2;return i=y.outerWidth()/2},drag:function(B,A){if(!s&&!(q&&w&&e("."+o)[0]===e("."+x)[0])){n.remove().appendTo("."+o);e("."+o).trigger("ss-setTargetPosition");s=true;c.setTimeout((function(){return s=false}),z)}A.position.left=B.pageX-y.parent().offset().left-i;return A.position.top=B.pageY-y.parent().offset().top-h},stop:function(){var A,C,B;u.globals.dragging=false;C=e("."+x);A=e("."+o);B=e("."+k);y.removeClass(m);e("."+r).remove();if(q){if(w&&e("."+o)[0]===e("."+x)[0]){p.remove();e("."+o).trigger("ss-rearrange")}else{p.removeClass(t)}}if(C[0]===A[0]){A.trigger("ss-rearranged",y)}else{C.trigger("ss-removed",y);A.trigger("ss-added",y)}C.trigger("ss-arrange").removeClass(x);A.trigger("ss-arrange",true).removeClass(o);B.trigger("ss-arrange").removeClass(k);return y=n=null}})}if(j.enableCrossDrop){return v.droppable({accept:j.crossDropWhitelist,tolerance:"intersect",over:function(A){e("."+k).removeClass(k);e("."+o).removeClass(o).addClass(k);return e(A.target).addClass(o)},drop:function(E,B){var A,D,C;if(u.options.enableTrash){D=e("."+x);A=e("."+o);C=e("."+k);y=e(B.helper);A.trigger("ss-trashed",y);y.remove();D.trigger("ss-rearrange").removeClass(x);A.trigger("ss-rearrange").removeClass(o);return C.trigger("ss-arrange").removeClass(k)}}})}};g.prototype.setTargetPosition=function(){var C,A,k,t,j,y,u,n,p,m,B,w,z,o,s,q,r,v,x,h,l,i;m=this.options;if(!m.enableTrash){p=m.draggedClass;C=e("."+p);A=C.parent();B=this.parsedChildren;j=this.getPositions(false);x=j.length;s=C.offset().left-A.offset().left+(this.globals.col_width/2);q=C.offset().top-A.offset().top+(C.height()/2);r=9999999;v=0;if(x>1){u=m.cutoffStart+1||0;y=m.cutoffEnd||x;for(z=i=u;u<=y?iy;z=u<=y?++i:--i){t=j[z];if(t){l=s-t.left;h=q-t.top;if(l>0&&h>0){n=Math.sqrt((h*h)+(l*l));if(nB[z].height/2){v++}}}}}}if(v===B.length){k=B[v-1].el;C.insertAfter(k)}else{k=B[v].el;C.insertBefore(k)}}else{if(x===1){t=j[0];if(t.leftk;j=0<=k?++l:--l){h.push([n[j],j])}h.sort(function(o,i){var p;p=o[0]-i[0];if(p===0){p=o[1]-i[1]}return p});return h[m][1]};g.prototype.highestCol=function(h){return e.inArray(Math.max.apply(c,h),h)};g.prototype.destroy=function(){var h,j,i;j=this.$container;j.off("ss-arrange");j.off("ss-rearrange");j.off("ss-setTargetPosition");j.off("ss-destroy");i=this.options.activeClass;h=j.find("."+i);if(this.options.enableDrag){h.draggable("destroy")}if(this.options.enableCrossDrop){j.droppable("destroy")}h.removeClass(i);return j.removeClass(this.identifier)};return g})();return e.fn[d]=function(g){return this.each(function(){var k,i,j,h;i=(j=e(this).attr("class"))!=null?(h=j.match(/shapeshifted_container_\w+/))!=null?h[0]:void 0:void 0;if(i){k="resize."+i;e(c).off(k);e(this).removeClass(i)}return e.data(this,"plugin_"+d,new b(this,g))})}})(jQuery,window,document)}).call(this); \ No newline at end of file +(function(e,t,n){var r,i,s;s="shapeshift";i={selector:"*",enableDrag:true,enableCrossDrop:true,enableResize:true,enableTrash:false,align:"center",colWidth:null,columns:null,minColumns:1,autoHeight:true,maxHeight:null,minHeight:100,gutterX:10,gutterY:10,paddingX:10,paddingY:10,animated:true,animateOnInit:false,animationSpeed:225,animationThreshold:100,dragClone:false,deleteClone:true,dragRate:100,dragWhitelist:"*",crossDropWhitelist:"*",cutoffStart:null,cutoffEnd:null,handle:false,centerDragging:true,cloneClass:"ss-cloned-child",activeClass:"ss-active-child",draggedClass:"ss-dragged-child",placeholderClass:"ss-placeholder-child",originalContainerClass:"ss-original-container",currentContainerClass:"ss-current-container",previousContainerClass:"ss-previous-container"};r=function(){function n(t,n){this.element=t;this.options=e.extend({},i,n);this.globals={};this.$container=e(t);if(this.errorCheck()){this.init()}}n.prototype.errorCheck=function(){var e,t,n,r;r=this.options;n=false;t="Shapeshift ERROR:";if(r.colWidth===null){e=this.$container.children(r.selector);if(e.length===0){n=true;console.error(""+t+" option colWidth must be specified if Shapeshift is initialized with no active children.")}}return!n};n.prototype.init=function(){this.createEvents();this.setGlobals();this.setIdentifier();this.setActiveChildren();this.enableFeatures();this.gridInit();this.render();return this.afterInit()};n.prototype.createEvents=function(){var e,t;t=this.options;e=this.$container;e.off("ss-arrange").on("ss-arrange",function(e){return function(t,n){if(n==null){n=false}return e.render(false,n)}}(this));e.off("ss-rearrange").on("ss-rearrange",function(e){return function(){return e.render(true)}}(this));e.off("ss-setTargetPosition").on("ss-setTargetPosition",function(e){return function(){return e.setTargetPosition()}}(this));e.off("ss-destroy").on("ss-destroy",function(e){return function(){return e.destroy()}}(this));return e.off("ss-shuffle").on("ss-shuffle",function(e){return function(){return e.shuffle()}}(this))};n.prototype.setGlobals=function(){this.globals.animated=this.options.animateOnInit;return this.globals.dragging=false};n.prototype.afterInit=function(){return this.globals.animated=this.options.animated};n.prototype.setIdentifier=function(){this.identifier="shapeshifted_container_"+Math.random().toString(36).substring(7);return this.$container.addClass(this.identifier)};n.prototype.enableFeatures=function(){if(this.options.enableResize){this.enableResize()}if(this.options.enableDrag||this.options.enableCrossDrop){return this.enableDragNDrop()}};n.prototype.setActiveChildren=function(){var t,n,r,i,s,o,u,a,f,l,c,h;u=this.options;t=this.$container.children(u.selector);n=u.activeClass;a=t.length;for(s=f=0;0<=a?fa;s=0<=a?++f:--f){e(t[s]).addClass(n)}this.setParsedChildren();i=u.columns;h=[];for(s=l=0,c=this.parsedChildren.length;0<=c?lc;s=0<=c?++l:--l){r=this.parsedChildren[s].colspan;o=u.minColumns;if(r>i&&r>o){u.minColumns=r;h.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 "+r))}else{h.push(void 0)}}return h};n.prototype.setParsedChildren=function(){var t,n,r,i,s,o,u;n=this.$container.find("."+this.options.activeClass).filter(":visible");o=n.length;s=[];for(i=u=0;0<=o?uo;i=0<=o?++u:--u){t=e(n[i]);r={i:i,el:t,colspan:parseInt(t.attr("data-ss-colspan"))||1,height:t.outerHeight()};s.push(r)}return this.parsedChildren=s};n.prototype.gridInit=function(){var e,t,n,r,i;r=this.options.gutterX;if(!(this.options.colWidth>=1)){n=this.parsedChildren[0];t=n.el.outerWidth();e=n.colspan;i=(t-(e-1)*r)/e;return this.globals.col_width=i+r}else{return this.globals.col_width=this.options.colWidth+r}};n.prototype.render=function(e,t){if(e==null){e=false}if(e){this.setActiveChildren()}this.setGridColumns();return this.arrange(false,t)};n.prototype.setGridColumns=function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p,d;s=this.globals;c=this.options;n=s.col_width;u=c.gutterX;h=c.paddingX;f=this.$container.innerWidth()-h*2;l=c.minColumns;i=c.columns||Math.floor((f+u)/n);if(l&&l>i){i=l}s.columns=i;t=this.parsedChildren.length;if(i>t){e=0;for(a=p=0,d=this.parsedChildren.length;0<=d?pd;a=0<=d?++p:--p){r=this.parsedChildren[a].colspan;if(r+e<=i){e+=r}}i=e}s.child_offset=h;switch(c.align){case"center":o=i*n-u;return s.child_offset+=(f-o)/2;case"right":o=i*n-u;return s.child_offset+=f-o}};n.prototype.arrange=function(e,t){var n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b;if(e){this.setParsedChildren()}l=this.globals;v=this.options;r=this.$container;u=this.getPositions();m=this.parsedChildren;y=m.length;i=l.animated&&y<=v.animationThreshold;s=v.animationSpeed;f=v.draggedClass;for(c=b=0;0<=y?by;c=0<=y?++b:--b){n=m[c].el;o=u[c];h=n.hasClass(f);if(h){g=v.placeholderClass;n=n.siblings("."+g)}if(i&&!h){n.stop(true,false).animate(o,s,function(){})}else{n.css(o)}}if(t){if(i){setTimeout(function(){return r.trigger("ss-drop-complete")},s)}else{r.trigger("ss-drop-complete")}}r.trigger("ss-arranged");if(v.autoHeight){a=l.container_height;p=v.maxHeight;d=v.minHeight;if(d&&ap){a=p}return r.height(a)}};n.prototype.getPositions=function(e){var t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y;if(e==null){e=true}s=this.globals;f=this.options;u=f.gutterY;l=f.paddingY;i=f.draggedClass;c=this.parsedChildren;m=c.length;t=[];for(a=g=0,y=s.columns;0<=y?gy;a=0<=y?++g:--g){t.push(l)}d=function(e){return function(e){var n,r,i,o,a,f,l;n=e.col;r=e.colspan;o=e.col*s.col_width+s.child_offset;a=t[n];h[e.i]={left:o,top:a};t[n]+=e.height+u;if(r>=1){l=[];for(i=f=1;1<=r?fr;i=1<=r?++f:--f){l.push(t[n+i]=t[n])}return l}}}(this);n=function(e){return function(n){var r,i,s,o,u,a,f,l,c,h,p,d;c=t.length-n.colspan+1;l=t.slice(0).splice(0,c);r=void 0;for(f=p=0;0<=c?pc;f=0<=c?++p:--p){i=e.lowestCol(l,f);s=n.colspan;o=t[i];u=true;for(h=d=1;1<=s?ds;h=1<=s?++d:--d){a=t[i+h];if(oa;i=0<=a?++o:--o){r=v[i];r.col=n(r);if(r.col>=0){d(r);s.push(i)}}l=[];for(t=u=f=s.length-1;u>=0;t=u+=-1){e=s[t];l.push(v.splice(e,1))}return l}}(this);h=[];(r=function(r){return function(){var s,o,u;u=[];for(a=o=0;0<=m?om;a=0<=m?++o:--o){s=c[a];if(!(!e&&s.el.hasClass(i))){if(s.colspan>1){s.col=n(s)}else{s.col=r.lowestCol(t)}if(s.col===void 0){v.push(s)}else{d(s)}u.push(p())}else{u.push(void 0)}}return u}}(this))();if(f.autoHeight){o=t[this.highestCol(t)]-u;s.container_height=o+l}return h};n.prototype.enableDragNDrop=function(){var n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b;d=this.options;r=this.$container;o=d.activeClass;p=d.draggedClass;m=d.placeholderClass;v=d.originalContainerClass;a=d.currentContainerClass;g=d.previousContainerClass;f=d.deleteClone;c=d.dragRate;l=d.dragClone;u=d.cloneClass;s=i=n=b=y=null;h=false;if(d.enableDrag){r.children("."+o).filter(d.dragWhitelist).draggable({addClasses:false,containment:"document",handle:d.handle,zIndex:9999,start:function(t){return function(r,o){var f;t.globals.dragging=true;s=e(r.target);if(l){n=s.clone(false,false).insertBefore(s).addClass(u)}s.addClass(p);f=s.prop("tagName");i=e("<"+f+" class='"+m+"' style='height: "+s.height()+"px; width: "+s.width()+"px'>");s.parent().addClass(v).addClass(a);b=s.outerHeight()/2;return y=s.outerWidth()/2}}(this),drag:function(n){return function(n,r){if(!h&&!(l&&f&&e("."+a)[0]===e("."+v)[0])){i.remove().appendTo("."+a);e("."+a).trigger("ss-setTargetPosition");h=true;t.setTimeout(function(){return h=false},c)}if(d.centerDragging){r.position.left=n.pageX-s.parent().offset().left-y;return r.position.top=n.pageY-s.parent().offset().top-b}else{return 1}}}(this),stop:function(t){return function(){var r,o,c;t.globals.dragging=false;o=e("."+v);r=e("."+a);c=e("."+g);s.removeClass(p);e("."+m).remove();if(l){if(f&&e("."+a)[0]===e("."+v)[0]){n.remove();e("."+a).trigger("ss-rearrange")}else{n.removeClass(u)}}if(o[0]===r[0]){r.trigger("ss-rearranged",s)}else{o.trigger("ss-removed",s);r.trigger("ss-added",s)}o.trigger("ss-arrange").removeClass(v);r.trigger("ss-arrange",true).removeClass(a);c.trigger("ss-arrange").removeClass(g);return s=i=null}}(this)})}if(d.enableCrossDrop){return r.droppable({accept:d.crossDropWhitelist,tolerance:"intersect",over:function(t){return function(t){e("."+g).removeClass(g);e("."+a).removeClass(a).addClass(g);return e(t.target).addClass(a)}}(this),drop:function(t){return function(n,r){var i,o,u;if(t.options.enableTrash){o=e("."+v);i=e("."+a);u=e("."+g);s=e(r.helper);i.trigger("ss-trashed",s);s.remove();o.trigger("ss-rearrange").removeClass(v);i.trigger("ss-rearrange").removeClass(a);return u.trigger("ss-arrange").removeClass(g)}}}(this)})}};n.prototype.setTargetPosition=function(){var t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S;l=this.options;if(!l.enableTrash){f=l.draggedClass;t=e("."+f);n=t.parent();c=this.parsedChildren;s=this.getPositions(false);b=s.length;v=t.offset().left-n.offset().left+this.globals.col_width/2;m=t.offset().top-n.offset().top+t.height()/2;g=9999999;y=0;if(b>1){u=l.cutoffStart+1||0;o=l.cutoffEnd||b;for(p=S=u;u<=o?So;p=u<=o?++S:--S){i=s[p];if(i){E=v-i.left;w=m-i.top;if(E>0&&w>0){a=Math.sqrt(w*w+E*E);if(ac[p].height/2){y++}}}}}}if(y===c.length){r=c[y-1].el;t.insertAfter(r)}else{r=c[y].el;t.insertBefore(r)}}else{if(b===1){i=s[0];if(i.lefti;r=0<=i?++s:--s){n.push([e[r],r])}n.sort(function(e,t){var n;n=e[0]-t[0];if(n===0){n=e[1]-t[1]}return n});return n[t][1]};n.prototype.highestCol=function(n){return e.inArray(Math.max.apply(t,n),n)};n.prototype.destroy=function(){var e,t,n;t=this.$container;t.off("ss-arrange");t.off("ss-rearrange");t.off("ss-setTargetPosition");t.off("ss-destroy");n=this.options.activeClass;e=t.find("."+n);if(this.options.enableDrag){e.draggable("destroy")}if(this.options.enableCrossDrop){t.droppable("destroy")}e.removeClass(n);return t.removeClass(this.identifier)};return n}();return e.fn[s]=function(n){return this.each(function(){var i,o,u,a;o=(u=e(this).attr("class"))!=null?(a=u.match(/shapeshifted_container_\w+/))!=null?a[0]:void 0:void 0;if(o){i="resize."+o;e(t).off(i);e(this).removeClass(o)}return e.data(this,"plugin_"+s,new r(this,n))})}})(jQuery,window,document)