Skip to content

Commit

Permalink
Built new version
Browse files Browse the repository at this point in the history
  • Loading branch information
brokenseal committed Feb 15, 2013
1 parent 233129b commit 7217b04
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 92 deletions.
4 changes: 2 additions & 2 deletions dist/jquery.gridster.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! gridster.js - v0.1.0 - 2012-10-20
/*! gridster.js - v0.1.0 - 2013-02-15
* http://gridster.net/
* Copyright (c) 2012 ducksboard; Licensed MIT */
* Copyright (c) 2013 ducksboard; Licensed MIT */

.gridster {
position:relative;
Expand Down
114 changes: 72 additions & 42 deletions dist/jquery.gridster.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! gridster.js - v0.1.0 - 2012-10-20
/*! gridster.js - v0.1.0 - 2013-02-15
* http://gridster.net/
* Copyright (c) 2012 ducksboard; Licensed MIT */
* Copyright (c) 2013 ducksboard; Licensed MIT */

;(function($, window, document, undefined){
/**
Expand Down Expand Up @@ -368,7 +368,7 @@
autoscroll: true,
ignore_dragging: ['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON'],
handle: null
// ,drag: function(e){},
// drag: function(e){},
// start : function(e, ui){},
// stop : function(e){}
};
Expand Down Expand Up @@ -425,24 +425,26 @@
this.disabled = false;
this.events();

$(window).bind('resize',
throttle($.proxy(this.calculate_positions, this), 200));
this.on_window_resize = throttle($.proxy(this.calculate_positions, this), 200);
$(window).bind('resize', this.on_window_resize);
};

fn.events = function() {
this.$container.on('selectstart', $.proxy(this.on_select_start, this));
this.proxied_on_select_start = $.proxy(this.on_select_start, this);
this.$container.on('selectstart', this.proxied_on_select_start);

this.$container.on(pointer_events.start, this.options.items, $.proxy(
this.drag_handler, this));
this.proxied_drag_handler = $.proxy(this.drag_handler, this);
this.$container.on(pointer_events.start, this.options.items, this.proxied_drag_handler);

this.$body.on(pointer_events.end, $.proxy(function(e) {
this.proxied_pointer_events_end = $.proxy(function(e) {
this.is_dragging = false;
if (this.disabled) { return; }
this.$body.off(pointer_events.move);
if (this.drag_start) {
this.on_dragstop(e);
}
}, this));
}, this);
this.$body.on(pointer_events.end, this.proxied_pointer_events_end);
};

fn.get_actual_pos = function($el) {
Expand Down Expand Up @@ -549,15 +551,15 @@
this.mouse_init_pos = this.get_mouse_pos(e);
this.offsetY = this.mouse_init_pos.top - this.el_init_pos.top;

this.$body.on(pointer_events.move, function(mme){
this.on_pointer_events_move = function(mme){
var mouse_actual_pos = self.get_mouse_pos(mme);
var diff_x = Math.abs(
mouse_actual_pos.left - self.mouse_init_pos.left);
var diff_y = Math.abs(
mouse_actual_pos.top - self.mouse_init_pos.top);
if (!(diff_x > self.options.distance ||
diff_y > self.options.distance)
) {
) {
return false;
}

Expand All @@ -572,7 +574,9 @@
}

return false;
});
};

this.$body.on(pointer_events.move, this.on_pointer_events_move);

return false;
};
Expand Down Expand Up @@ -678,6 +682,13 @@

fn.destroy = function(){
this.disable();

this.$container.off('selectstart', this.proxied_on_select_start);
this.$container.off(pointer_events.start, this.proxied_drag_handler);
this.$body.off(pointer_events.end, this.proxied_pointer_events_end);
this.$body.off(pointer_events.move, this.on_pointer_events_move);
$(window).unbind('resize', this.on_window_resize);

$.removeData(this.$container, 'drag');
};

Expand Down Expand Up @@ -802,8 +813,9 @@
this.$wrapper.addClass('ready');
this.draggable();

$(window).bind(
'resize', throttle($.proxy(this.recalculate_faux_grid, this), 200));
this.on_window_resize = throttle($.proxy(this.recalculate_faux_grid, this), 200);

$(window).bind('resize', this.on_window_resize);
};


Expand Down Expand Up @@ -1060,7 +1072,7 @@
* occupy.
* @param {Number} size_y The number of rows that the group of cells
* occupy.
* @param {HTMLElement} $exclude Exclude widgets from being moved.
* @param {HTMLElement} exclude Exclude widgets from being moved.
* @return {Class} Returns the instance of the Gridster Class.
*/
fn.remove_empty_cells = function(col, row, size_x, size_y, exclude) {
Expand Down Expand Up @@ -1361,8 +1373,8 @@
* This function is executed when the player begins to be dragged.
*
* @method on_start_drag
* @param {Event} The original browser event
* @param {Object} A prepared ui object.
* @param {Event} event The original browser event
* @param {Object} ui A prepared ui object.
*/
fn.on_start_drag = function(event, ui) {

Expand Down Expand Up @@ -1412,8 +1424,8 @@
* This function is executed when the player is being dragged.
*
* @method on_drag
* @param {Event} The original browser event
* @param {Object} A prepared ui object.
* @param {Event} event The original browser event
* @param {Object} ui A prepared ui object.
*/
fn.on_drag = function(event, ui) {
//break if dragstop has been fired
Expand Down Expand Up @@ -1455,8 +1467,8 @@
* This function is executed when the player stops being dragged.
*
* @method on_stop_drag
* @param {Event} The original browser event
* @param {Object} A prepared ui object.
* @param {Event} event The original browser event
* @param {Object} ui A prepared ui object.
*/
fn.on_stop_drag = function(event, ui) {
this.$helper.add(this.$player).add(this.$wrapper)
Expand Down Expand Up @@ -1525,7 +1537,7 @@
*/
fn.on_overlapped_column_change = function(start_callback, stop_callback) {
if (!this.colliders_data.length) {
return;
return this;
}
var cols = this.get_targeted_columns(
this.colliders_data[0].el.data.col);
Expand Down Expand Up @@ -1558,14 +1570,14 @@
*
* @param {Function} start_callback Function executed when a new row begins
* to be overlapped. The row is passed as first argument.
* @param {Function} stop_callback Function executed when a row stops being
* @param {Function} end_callback Function executed when a row stops being
* overlapped. The row is passed as first argument.
* @method on_overlapped_row_change
* @return {Class} Returns the instance of the Gridster Class.
*/
fn.on_overlapped_row_change = function(start_callback, end_callback) {
if (!this.colliders_data.length) {
return;
return this;
}
var rows = this.get_targeted_rows(this.colliders_data[0].el.data.row);
var last_n_rows = this.last_rows.length;
Expand All @@ -1591,12 +1603,11 @@
/**
* Sets the current position of the player
*
* @param {Function} start_callback Function executed when a new row begins
* to be overlapped. The row is passed as first argument.
* @param {Function} stop_callback Function executed when a row stops being
* overlapped. The row is passed as first argument.
* @param {Number} col
* @param {Number} row
* @param {Boolean} no_player
* @method set_player
* @return {Class} Returns the instance of the Gridster Class.
* @return {object}
*/
fn.set_player = function(col, row, no_player) {
var self = this;
Expand Down Expand Up @@ -1647,9 +1658,9 @@
* a upper row and which not.
*
* @method widgets_contraints
* @param {HTMLElements} $widgets A jQuery wrapped collection of
* @param {jQuery} $widgets A jQuery wrapped collection of
* HTMLElements.
* @return {Array} Returns a literal Object with two keys: `can_go_up` &
* @return {object} Returns a literal Object with two keys: `can_go_up` &
* `can_not_go_up`. Each contains a set of HTMLElements.
*/
fn.widgets_constraints = function($widgets) {
Expand Down Expand Up @@ -1767,7 +1778,7 @@
* each widget) in descending way.
*
* @method manage_movements
* @param {HTMLElements} $widgets A jQuery collection of HTMLElements
* @param {jQuery} $widgets A jQuery collection of HTMLElements
* representing the widgets you want to move.
* @param {Number} to_col The column to which we want to move the widgets.
* @param {Number} to_row The row to which we want to move the widgets.
Expand Down Expand Up @@ -2214,7 +2225,7 @@
* Get widgets overlapping with the player.
*
* @method get_widgets_overlapped
* @return {HTMLElements} Returns a jQuery collection of HTMLElements.
* @return {jQuery} Returns a jQuery collection of HTMLElements.
*/
fn.get_widgets_overlapped = function() {
var $w;
Expand Down Expand Up @@ -2247,7 +2258,7 @@
*
* @method on_start_overlapping_column
* @param {Number} col The collided column.
* @return {HTMLElements} Returns a jQuery collection of HTMLElements.
* @return {jQuery} Returns a jQuery collection of HTMLElements.
*/
fn.on_start_overlapping_column = function(col) {
this.set_player(col, false);
Expand All @@ -2258,8 +2269,8 @@
* A callback executed when the player begins to collide with a row.
*
* @method on_start_overlapping_row
* @param {Number} col The collided row.
* @return {HTMLElements} Returns a jQuery collection of HTMLElements.
* @param {Number} row The collided row.
* @return {jQuery} Returns a jQuery collection of HTMLElements.
*/
fn.on_start_overlapping_row = function(row) {
this.set_player(false, row);
Expand All @@ -2271,7 +2282,7 @@
*
* @method on_stop_overlapping_column
* @param {Number} col The collided row.
* @return {HTMLElements} Returns a jQuery collection of HTMLElements.
* @return {jQuery} Returns a jQuery collection of HTMLElements.
*/
fn.on_stop_overlapping_column = function(col) {
this.set_player(col, false);
Expand All @@ -2289,7 +2300,7 @@
*
* @method on_stop_overlapping_row
* @param {Number} row The collided row.
* @return {HTMLElements} Returns a jQuery collection of HTMLElements.
* @return {jQuery} Returns a jQuery collection of HTMLElements.
*/
fn.on_stop_overlapping_row = function(row) {
this.set_player(false, row);
Expand Down Expand Up @@ -2399,9 +2410,9 @@
* Move down the specified widget and all below it.
*
* @method move_widget_down
* @param {HTMLElement} $widget The jQuery object representing the widget
* @param {jQuery} $widget The jQuery object representing the widget
* you want to move.
* @param {Number} The number of cells that the widget has to move.
* @param {Number} y_units The number of cells that the widget has to move.
* @return {Class} Returns the instance of the Gridster Class.
*/
fn.move_widget_down = function($widget, y_units) {
Expand Down Expand Up @@ -2537,7 +2548,7 @@
*
* @method widgets_below
* @param {HTMLElement} $el The jQuery wrapped HTMLElement.
* @return {HTMLElements} A jQuery collection of HTMLElements.
* @return {jQuery} A jQuery collection of HTMLElements.
*/
fn.widgets_below = function($el) {
var el_grid_data = $.isPlainObject($el) ? $el : $el.coords().grid;
Expand Down Expand Up @@ -3217,6 +3228,25 @@
return this.generate_faux_grid(this.rows, this.cols);
};

/**
* Destroy this gridster by removing any sign of its presence, making it easy to avoid memory leaks
*
* @method destroy
* @return {undefined}
*/
fn.destroy = function(){
// remove bound callback on window resize
$(window).unbind('resize', this.resize_callback);

// TODO: remove draggable bindings
this.drag_api.destroy();

// lastly, remove gridster element
// this will additionally cause any data associated to this element to be removed, including this
// very gridster instance
this.$el.remove();
};


//jQuery adapter
$.fn.gridster = function(options) {
Expand Down
6 changes: 3 additions & 3 deletions dist/jquery.gridster.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 7217b04

Please sign in to comment.