Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6ebd101

Browse files
committed
updated dist
1 parent 42ce094 commit 6ebd101

6 files changed

+3460
-57
lines changed

dist/jquery.gridster.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! gridster.js - v0.1.0 - 2012-09-12
1+
/*! gridster.js - v0.1.0 - 2012-10-03
22
* http://gridster.net/
33
* Copyright (c) 2012 ducksboard; Licensed MIT */
44

dist/jquery.gridster.js

Lines changed: 95 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! gridster.js - v0.1.0 - 2012-09-12
1+
/*! gridster.js - v0.1.0 - 2012-10-03
22
* http://gridster.net/
33
* Copyright (c) 2012 ducksboard; Licensed MIT */
44

@@ -420,12 +420,28 @@
420420
fn.init = function() {
421421
this.calculate_positions();
422422
this.$container.css('position', 'relative');
423-
this.enable();
423+
this.disabled = false;
424+
this.events();
424425

425426
$(window).bind('resize',
426427
throttle($.proxy(this.calculate_positions, this), 200));
427428
};
428429

430+
fn.events = function() {
431+
this.$container.on('selectstart', this.on_select_start);
432+
433+
this.$container.on(pointer_events.start, this.options.items, $.proxy(
434+
this.drag_handler, this));
435+
436+
this.$body.on(pointer_events.end, $.proxy(function(e) {
437+
this.is_dragging = false;
438+
if (this.disabled) { return; }
439+
this.$body.off(pointer_events.move);
440+
if (this.drag_start) {
441+
this.on_dragstop(e);
442+
}
443+
}, this));
444+
};
429445

430446
fn.get_actual_pos = function($el) {
431447
var pos = $el.position();
@@ -437,7 +453,7 @@
437453
if (isTouch) {
438454
var oe = e.originalEvent;
439455
e = oe.touches.length ? oe.touches[0] : oe.changedTouches[0];
440-
};
456+
}
441457

442458
return {
443459
left: e.clientX,
@@ -496,34 +512,33 @@
496512
$window.scrollTop(nextScrollTop);
497513
this.scrollOffset = this.scrollOffset + 30;
498514
}
499-
};
515+
}
500516

501517
if (abs_mouse_top <= mouse_up_zone) {
502518
nextScrollTop = scrollTop - 30;
503519
if (nextScrollTop > 0) {
504520
$window.scrollTop(nextScrollTop);
505521
this.scrollOffset = this.scrollOffset - 30;
506522
}
507-
};
508-
}
523+
}
524+
};
509525

510526

511527
fn.calculate_positions = function(e) {
512528
this.window_height = $window.height();
513-
}
529+
};
514530

515531

516532
fn.drag_handler = function(e) {
517533
var node = e.target.nodeName;
518-
519-
if (e.which !== 1 && !isTouch) {
534+
if (this.disabled || e.which !== 1 && !isTouch) {
520535
return;
521536
}
522537

523538
if (node === 'INPUT' || node === 'TEXTAREA' || node === 'SELECT' ||
524539
node === 'BUTTON') {
525540
return;
526-
};
541+
}
527542

528543
var self = this;
529544
var first = true;
@@ -551,7 +566,7 @@
551566
return false;
552567
}
553568

554-
if (self.is_dragging == true) {
569+
if (self.is_dragging === true) {
555570
self.on_dragmove.call(self, mme);
556571
}
557572

@@ -642,30 +657,16 @@
642657
};
643658

644659
fn.on_select_start = function(e) {
660+
if (this.disabled) { return; }
645661
return false;
646-
}
647-
648-
649-
fn.enable = function(){
650-
this.$container.on('selectstart', this.on_select_start);
651-
652-
this.$container.on(pointer_events.start, this.options.items, $.proxy(
653-
this.drag_handler, this));
654-
655-
this.$body.on(pointer_events.end, $.proxy(function(e) {
656-
this.is_dragging = false;
657-
this.$body.off(pointer_events.move);
658-
if (this.drag_start) {
659-
this.on_dragstop(e);
660-
}
661-
}, this));
662662
};
663663

664+
fn.enable = function() {
665+
this.disabled = false;
666+
};
664667

665-
fn.disable = function(){
666-
this.$container.off(pointer_events.start);
667-
this.$body.off(pointer_events.end);
668-
this.$container.off('selectstart', this.on_select_start);
668+
fn.disable = function() {
669+
this.disabled = true;
669670
};
670671

671672

@@ -674,7 +675,6 @@
674675
$.removeData(this.$container, 'drag');
675676
};
676677

677-
678678
//jQuery adapter
679679
$.fn.drag = function ( options ) {
680680
return this.each(function () {
@@ -859,6 +859,7 @@
859859
this.register_widget($w);
860860

861861
this.add_faux_rows(pos.size_y);
862+
this.add_faux_cols(pos.size_x);
862863

863864
this.set_dom_grid_height();
864865

@@ -884,7 +885,7 @@
884885

885886
if (size_x > this.cols) {
886887
size_x = this.cols;
887-
};
888+
}
888889

889890
var old_cells_occupied = this.get_cells_occupied(wgd);
890891
var old_size_x = wgd.size_x;
@@ -898,7 +899,7 @@
898899
var diff = old_col + (size_x - 1) - this.cols;
899900
var c = old_col - diff;
900901
new_col = Math.max(1, c);
901-
};
902+
}
902903

903904
var new_grid_data = {
904905
col: new_col,
@@ -913,7 +914,7 @@
913914
$.each(old_cells_occupied.cols, function(i, col) {
914915
if ($.inArray(col, new_cells_occupied.cols) === -1) {
915916
empty_cols.push(col);
916-
};
917+
}
917918
});
918919

919920
var occupied_cols = [];
@@ -927,14 +928,14 @@
927928
$.each(old_cells_occupied.rows, function(i, row) {
928929
if ($.inArray(row, new_cells_occupied.rows) === -1) {
929930
empty_rows.push(row);
930-
};
931+
}
931932
});
932933

933934
var occupied_rows = [];
934935
$.each(new_cells_occupied.rows, function(i, row) {
935936
if ($.inArray(row, old_cells_occupied.rows) === -1) {
936937
occupied_rows.push(row);
937-
};
938+
}
938939
});
939940

940941
this.remove_from_gridmap(wgd);
@@ -944,12 +945,12 @@
944945
new_col, wgd.row, size_x, Math.min(old_size_y, size_y), $widget
945946
];
946947
this.empty_cells.apply(this, cols_to_empty);
947-
};
948+
}
948949

949950
if (occupied_rows.length) {
950951
var rows_to_empty = [new_col, wgd.row, size_x, size_y, $widget];
951952
this.empty_cells.apply(this, rows_to_empty);
952-
};
953+
}
953954

954955
wgd.col = new_col;
955956
wgd.size_x = size_x;
@@ -966,7 +967,11 @@
966967

967968
if (size_y > old_size_y) {
968969
this.add_faux_rows(size_y - old_size_y);
969-
};
970+
}
971+
972+
if (size_x > old_size_x) {
973+
this.add_faux_cols(size_x - old_size_x);
974+
}
970975

971976
$widget.attr({
972977
'data-col': new_col,
@@ -1019,7 +1024,7 @@
10191024

10201025
$nexts.not($exclude).each($.proxy(function(i, w) {
10211026
var wgd = $(w).coords().grid;
1022-
if (!(wgd.row <= (row + size_y - 1))) { return; };
1027+
if (!(wgd.row <= (row + size_y - 1))) { return; }
10231028
var diff = (row + size_y) - wgd.row;
10241029
this.move_widget_down($(w), diff);
10251030
}, this));
@@ -1059,7 +1064,7 @@
10591064
this.set_dom_grid_height();
10601065

10611066
return this;
1062-
}
1067+
};
10631068

10641069

10651070
/**
@@ -1077,9 +1082,10 @@
10771082
var ga = this.gridmap;
10781083
var cols_l = ga.length;
10791084
var valid_pos = [];
1085+
var rows_l;
10801086

10811087
for (var c = 1; c < cols_l; c++) {
1082-
var rows_l = ga[c].length;
1088+
rows_l = ga[c].length;
10831089
for (var r = 1; r <= rows_l; r++) {
10841090
var can_move_to = this.can_move_to({
10851091
size_x: size_x,
@@ -1211,7 +1217,7 @@
12111217
$el.data('coords').grid = wgd;
12121218

12131219
this.add_to_gridmap(wgd, $el);
1214-
this.widgets.push($el);
1220+
12151221
return this;
12161222
};
12171223

@@ -1372,7 +1378,7 @@
13721378
//break if dragstop has been fired
13731379
if (this.$player === null) {
13741380
return false;
1375-
};
1381+
}
13761382

13771383
var abs_offset = {
13781384
left: ui.position.left + this.baseX,
@@ -1555,7 +1561,7 @@
15551561
var self = this;
15561562
if (!no_player) {
15571563
this.empty_cells_player_occupies();
1558-
};
1564+
}
15591565
var cell = !no_player ? self.colliders_data[0].el.data : {col: col};
15601566
var to_col = cell.col;
15611567
var to_row = row || cell.row;
@@ -1644,7 +1650,7 @@
16441650
if (!a.row) {
16451651
a = $(a).coords().grid;
16461652
b = $(b).coords().grid;
1647-
};
1653+
}
16481654

16491655
if (a.row > b.row) {
16501656
return 1;
@@ -1666,7 +1672,7 @@
16661672
*/
16671673
fn.sort_by_row_and_col_asc = function(widgets) {
16681674
widgets = widgets.sort(function(a, b) {
1669-
if (a.row > b.row || a.row == b.row && a.col > b.col) {
1675+
if (a.row > b.row || a.row === b.row && a.col > b.col) {
16701676
return 1;
16711677
}
16721678
return -1;
@@ -2579,9 +2585,10 @@
25792585
* the widget.
25802586
* @param {Object} col The col to check.
25812587
* @param {Object} row The row to check.
2588+
* @param {Number} [max_row] The max row allowed.
25822589
* @return {Boolean} Returns true if all cells are empty, else return false.
25832590
*/
2584-
fn.can_move_to = function(widget_grid_data, col, row) {
2591+
fn.can_move_to = function(widget_grid_data, col, row, max_row) {
25852592
var ga = this.gridmap;
25862593
var $w = widget_grid_data.el;
25872594
var future_wd = {
@@ -2596,7 +2603,11 @@
25962603
var right_col = col + widget_grid_data.size_x - 1;
25972604
if (right_col > this.cols) {
25982605
return false;
2599-
};
2606+
}
2607+
2608+
if (max_row && max_row < row + widget_grid_data.size_y - 1) {
2609+
return false;
2610+
}
26002611

26012612
this.for_each_cell_occupied(future_wd, function(tcol, trow) {
26022613
var $tw = this.is_widget(tcol, trow);
@@ -2904,7 +2915,7 @@
29042915
opts || (opts = {});
29052916
opts.cols || (opts.cols = this.cols);
29062917
opts.rows || (opts.rows = this.rows);
2907-
opts.namespace || (opts.namespace = '');
2918+
opts.namespace || (opts.namespace = this.options.namespace);
29082919
opts.widget_base_dimensions ||
29092920
(opts.widget_base_dimensions = this.options.widget_base_dimensions);
29102921
opts.widget_margins ||
@@ -3021,6 +3032,10 @@
30213032
original_row: row
30223033
}).coords();
30233034

3035+
if (!$.isArray(this.gridmap[col])) {
3036+
this.gridmap[col] = [];
3037+
}
3038+
30243039
this.gridmap[col][row] = false;
30253040
this.faux_grid.push(coords);
30263041

@@ -3048,7 +3063,33 @@
30483063
this.rows = max_rows;
30493064

30503065
if (this.options.autogenerate_stylesheet) {
3051-
this.generate_stylesheet({namespace: this.options.namespace});
3066+
this.generate_stylesheet();
3067+
}
3068+
3069+
return this;
3070+
};
3071+
3072+
/**
3073+
* Add cols to the faux grid.
3074+
*
3075+
* @method add_faux_cols
3076+
* @param {Number} cols The number of cols you want to add to the faux grid.
3077+
* @return {Object} Returns the instance of the Gridster class.
3078+
*/
3079+
fn.add_faux_cols = function(cols) {
3080+
var actual_cols = this.cols;
3081+
var max_cols = actual_cols + (cols || 1);
3082+
3083+
for (var c = actual_cols; c < max_cols; c++) {
3084+
for (var r = this.rows; r >= 1; r--) {
3085+
this.add_faux_cell(r, c);
3086+
};
3087+
};
3088+
3089+
this.cols = max_cols;
3090+
3091+
if (this.options.autogenerate_stylesheet) {
3092+
this.generate_stylesheet();
30523093
}
30533094

30543095
return this;
@@ -3118,7 +3159,7 @@
31183159

31193160
// get all rows that could be occupied by the current widgets
31203161
var max_rows = this.options.extra_rows;
3121-
this.$widgets.each(function(i, w){
3162+
this.$widgets.each(function(i, w) {
31223163
max_rows += (+$(w).attr('data-sizey'));
31233164
});
31243165

@@ -3145,5 +3186,6 @@
31453186
});
31463187
};
31473188

3189+
$.Gridster = fn;
31483190

31493191
}(jQuery, window, document));

0 commit comments

Comments
 (0)