gridster-rails 0.1.0.1 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,19 +6,19 @@ This is [gridster.js](http://gridster.net) GEMified for the Rails >= 3.1 asset p
6
6
  cd gridster-rails
7
7
  mkdir -p vendor/assets/javascripts
8
8
  mkdir -p vendor/assets/stylesheets
9
- curl https://raw.github.com/ducksboard/gridster.js/master/dist/jquery.gridster.js -o vendor/assets/javascripts/jquery.gridster.js
10
- curl https://raw.github.com/ducksboard/gridster.js/master/dist/jquery.gridster.css -o vendor/assets/stylesheets/jquery.gridster.css
9
+ curl https://raw.github.com/dustmoo/gridster.js/master/dist/jquery.gridster.js -o vendor/assets/javascripts/jquery.gridster.js
10
+ curl https://raw.github.com/dustmoo/gridster.js/master/dist/jquery.gridster.css -o vendor/assets/stylesheets/jquery.gridster.css
11
11
  echo "" >> README.md; echo "# gridster.js appended README #" >> README.md; echo "" >> README.md
12
- curl https://raw.github.com/ducksboard/gridster.js/master/README.md >> README.md
12
+ curl https://raw.github.com/dustmoo/gridster.js/master/README.md >> README.md
13
13
  echo "" >> LICENSE; echo "# gridster.js appended LICENSE #" >> LICENSE; echo "" >> LICENSE
14
- curl https://raw.github.com/ducksboard/gridster.js/master/LICENSE >> LICENSE
14
+ curl https://raw.github.com/dustmoo/gridster.js/master/LICENSE >> LICENSE
15
15
  git add .
16
16
  git commit -am "initial gridster-rails"
17
17
  git remote add origin git@github.com:vanetten/gridster-rails.git
18
18
 
19
19
  * modify **lib/gridster-rails/version.rb** to match gridster.js version
20
20
 
21
- VERSION = "0.1.0.1"
21
+ VERSION = "0.1.5"
22
22
 
23
23
  * modify **lib/gridster-rails.rb** to subclass Rails::Engine
24
24
 
@@ -59,11 +59,11 @@ Or install it yourself as:
59
59
 
60
60
  Add to **application.js**
61
61
 
62
- //= require jquery.gridster.js`
62
+ //= require jquery.gridster.js
63
63
 
64
64
  Add to **application.css**
65
65
 
66
- *= require fullcalendar`
66
+ *= require jquery.gridster.css
67
67
 
68
68
  ## Contributing
69
69
 
@@ -84,6 +84,27 @@ dynamically add and remove elements from the grid.
84
84
 
85
85
  More at [http://gridster.net/](http://gridster.net/).
86
86
 
87
+ Public Service Announcement from Dustin Moore (dustmoo)
88
+ =======================================================
89
+
90
+ Gridster is not currently being actively maintained by
91
+ [Ducksboard](http://ducksboard.com/).
92
+
93
+ I and others have been given access to the repo to help
94
+ maintain and address issues.
95
+
96
+ I have created a fork of gridster that supports more advanced
97
+ features, like widget-swapping and static widgets.
98
+
99
+ It can be found here: https://github.com/dustmoo/gridster.js
100
+
101
+ Currently the code-base is different and I don't have time to
102
+ reconcile the fork with this repo.
103
+
104
+ If anyone would like to help me improve my fork and reconcile
105
+ it with the main library I would be happy for the help.
106
+
107
+
87
108
  License
88
109
  =======
89
110
 
@@ -93,3 +114,65 @@ Whodunit
93
114
  ========
94
115
 
95
116
  Gridster is built by [Ducksboard](http://ducksboard.com/).
117
+
118
+ dustmoo Modifications
119
+ ===========
120
+
121
+ Changelog 2013-04-3
122
+
123
+ Fork now handles standard behavior properly with swap allowing larger widgets to shift down.
124
+
125
+ Changelog 2013-04-2
126
+
127
+ Added Demo to Repository.
128
+
129
+ Changelog 2013-02-27
130
+
131
+ Added "Static widget support" Static Items default to the "static" class.
132
+
133
+ You can customize this class by using the code below:
134
+
135
+ $.gridster({
136
+ static_class: 'custom_class',
137
+ draggable: {
138
+ items: ".gs_w:not(.custom_class)"
139
+ }
140
+ });
141
+
142
+ I have also added functions creating a much more thourough check of whether the player can occupy the space you are moving it too.
143
+ This version is much more reliable in swapping space with widgets.
144
+
145
+ There are also new options for Maximum Rows and Maximum Columns:
146
+
147
+ $.gridster({
148
+ max_rows: map_rows,
149
+ max_cols: map_cols,
150
+ shift_larger_widgets_down: false
151
+ });
152
+
153
+ Setting the maximum amount of rows only completely works if you disable shifting larger widgets down at the moment.
154
+
155
+
156
+ Changelog 2012-11-26
157
+
158
+ Reworked swapping functionality to better handle large to small widget handling.
159
+
160
+ ---
161
+
162
+ Widgets of smaller or equal size to the dragged widget (player)
163
+ will swap places with the original widget.
164
+
165
+ This causes tiles to swap left and right as well as up and down.
166
+
167
+ By default smaller players will shift larger widgets down.
168
+
169
+ I have added an option to prevent this behavior:
170
+
171
+ $.gridster({
172
+ shift_larger_widgets_down: false
173
+ });
174
+
175
+ By setting shift_larger_widgets_down to false, smaller widgets will not displace larger ones.
176
+
177
+
178
+
@@ -1,5 +1,5 @@
1
1
  module Gridster
2
2
  module Rails
3
- VERSION = "0.1.0.1"
3
+ VERSION = "0.1.5"
4
4
  end
5
5
  end
@@ -1,6 +1,10 @@
1
- /*! gridster.js - v0.1.0 - 2012-10-20
2
- * http://gridster.net/
3
- * Copyright (c) 2012 ducksboard; Licensed MIT */
1
+ /*
2
+ * jquery.coords
3
+ * https://github.com/ducksboard/gridster.js
4
+ *
5
+ * Copyright (c) 2012 ducksboard
6
+ * Licensed under the MIT licenses.
7
+ */
4
8
 
5
9
  ;(function($, window, document, undefined){
6
10
  /**
@@ -103,6 +107,14 @@
103
107
 
104
108
  }(jQuery, window, document));
105
109
 
110
+ /*
111
+ * jquery.collision
112
+ * https://github.com/ducksboard/gridster.js
113
+ *
114
+ * Copyright (c) 2012 ducksboard
115
+ * Licensed under the MIT licenses.
116
+ */
117
+
106
118
  ;(function($, window, document, undefined){
107
119
 
108
120
  var defaults = {
@@ -274,7 +286,7 @@
274
286
 
275
287
  if (self.options.on_overlap_stop || self.options.on_overlap_start) {
276
288
  this.manage_colliders_start_stop(colliders_coords,
277
- self.options.on_overlap_stop, self.options.on_overlap_start);
289
+ self.options.on_overlap_start, self.options.on_overlap_stop);
278
290
  }
279
291
 
280
292
  this.last_colliders_coords = colliders_coords;
@@ -358,6 +370,14 @@
358
370
 
359
371
  })(window);
360
372
 
373
+ /*
374
+ * jquery.draggable
375
+ * https://github.com/ducksboard/gridster.js
376
+ *
377
+ * Copyright (c) 2012 ducksboard
378
+ * Licensed under the MIT licenses.
379
+ */
380
+
361
381
  ;(function($, window, document, undefined){
362
382
 
363
383
  var defaults = {
@@ -368,7 +388,7 @@
368
388
  autoscroll: true,
369
389
  ignore_dragging: ['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON'],
370
390
  handle: null
371
- // ,drag: function(e){},
391
+ // drag: function(e){},
372
392
  // start : function(e, ui){},
373
393
  // stop : function(e){}
374
394
  };
@@ -425,24 +445,26 @@
425
445
  this.disabled = false;
426
446
  this.events();
427
447
 
428
- $(window).bind('resize',
429
- throttle($.proxy(this.calculate_positions, this), 200));
448
+ this.on_window_resize = throttle($.proxy(this.calculate_positions, this), 200);
449
+ $(window).bind('resize', this.on_window_resize);
430
450
  };
431
451
 
432
452
  fn.events = function() {
433
- this.$container.on('selectstart', $.proxy(this.on_select_start, this));
453
+ this.proxied_on_select_start = $.proxy(this.on_select_start, this);
454
+ this.$container.on('selectstart', this.proxied_on_select_start);
434
455
 
435
- this.$container.on(pointer_events.start, this.options.items, $.proxy(
436
- this.drag_handler, this));
456
+ this.proxied_drag_handler = $.proxy(this.drag_handler, this);
457
+ this.$container.on(pointer_events.start, this.options.items, this.proxied_drag_handler);
437
458
 
438
- this.$body.on(pointer_events.end, $.proxy(function(e) {
459
+ this.proxied_pointer_events_end = $.proxy(function(e) {
439
460
  this.is_dragging = false;
440
461
  if (this.disabled) { return; }
441
462
  this.$body.off(pointer_events.move);
442
463
  if (this.drag_start) {
443
464
  this.on_dragstop(e);
444
465
  }
445
- }, this));
466
+ }, this);
467
+ this.$body.on(pointer_events.end, this.proxied_pointer_events_end);
446
468
  };
447
469
 
448
470
  fn.get_actual_pos = function($el) {
@@ -549,7 +571,7 @@
549
571
  this.mouse_init_pos = this.get_mouse_pos(e);
550
572
  this.offsetY = this.mouse_init_pos.top - this.el_init_pos.top;
551
573
 
552
- this.$body.on(pointer_events.move, function(mme){
574
+ this.on_pointer_events_move = function(mme){
553
575
  var mouse_actual_pos = self.get_mouse_pos(mme);
554
576
  var diff_x = Math.abs(
555
577
  mouse_actual_pos.left - self.mouse_init_pos.left);
@@ -557,7 +579,7 @@
557
579
  mouse_actual_pos.top - self.mouse_init_pos.top);
558
580
  if (!(diff_x > self.options.distance ||
559
581
  diff_y > self.options.distance)
560
- ) {
582
+ ) {
561
583
  return false;
562
584
  }
563
585
 
@@ -572,7 +594,9 @@
572
594
  }
573
595
 
574
596
  return false;
575
- });
597
+ };
598
+
599
+ this.$body.on(pointer_events.move, this.on_pointer_events_move);
576
600
 
577
601
  return false;
578
602
  };
@@ -678,6 +702,13 @@
678
702
 
679
703
  fn.destroy = function(){
680
704
  this.disable();
705
+
706
+ this.$container.off('selectstart', this.proxied_on_select_start);
707
+ this.$container.off(pointer_events.start, this.proxied_drag_handler);
708
+ this.$body.off(pointer_events.end, this.proxied_pointer_events_end);
709
+ this.$body.off(pointer_events.move, this.on_pointer_events_move);
710
+ $(window).unbind('resize', this.on_window_resize);
711
+
681
712
  $.removeData(this.$container, 'drag');
682
713
  };
683
714
 
@@ -690,7 +721,7 @@
690
721
  };
691
722
 
692
723
  //jQuery adapter
693
- $.fn.drag = function ( options ) {
724
+ $.fn.dragg = function ( options ) {
694
725
  return this.each(function () {
695
726
  if (!$.data(this, 'drag')) {
696
727
  $.data(this, 'drag', new Draggable( this, options ));
@@ -701,20 +732,32 @@
701
732
 
702
733
  }(jQuery, window, document));
703
734
 
735
+ /*
736
+ * jquery.gridster
737
+ * https://github.com/ducksboard/gridster.js
738
+ *
739
+ * Copyright (c) 2012 ducksboard
740
+ * Licensed under the MIT licenses.
741
+ */
704
742
  ;(function($, window, document, undefined) {
705
743
 
744
+ //ToDo Max_cols and Max_size_x conflict.. need to unify
706
745
  var defaults = {
707
746
  namespace: '',
708
747
  widget_selector: 'li',
748
+ static_class: 'static',
709
749
  widget_margins: [10, 10],
710
750
  widget_base_dimensions: [400, 225],
711
751
  extra_rows: 0,
712
752
  extra_cols: 0,
713
753
  min_cols: 1,
754
+ max_cols: 60,
714
755
  min_rows: 15,
756
+ max_rows: 15,
715
757
  max_size_x: 6,
716
758
  autogenerate_stylesheet: true,
717
759
  avoid_overlapped_widgets: true,
760
+ shift_larger_widgets_down: true,
718
761
  serialize_params: function($w, wgd) {
719
762
  return {
720
763
  col: wgd.col,
@@ -725,7 +768,8 @@
725
768
  },
726
769
  collision: {},
727
770
  draggable: {
728
- distance: 4
771
+ distance: 4,
772
+ items: ".gs_w:not(.static)"
729
773
  }
730
774
  };
731
775
 
@@ -783,6 +827,7 @@
783
827
  this.$widgets = this.$el.children(this.options.widget_selector).addClass('gs_w');
784
828
  this.widgets = [];
785
829
  this.$changed = $([]);
830
+ this.w_queue = {};
786
831
  this.wrapper_width = this.$wrapper.width();
787
832
  this.min_widget_width = (this.options.widget_margins[0] * 2) +
788
833
  this.options.widget_base_dimensions[0];
@@ -869,6 +914,7 @@
869
914
  }).addClass('gs_w').appendTo(this.$el).hide();
870
915
 
871
916
  this.$widgets = this.$widgets.add($w);
917
+ this.$changed = this.$changed.add($w);
872
918
 
873
919
  this.register_widget($w);
874
920
 
@@ -1071,9 +1117,12 @@
1071
1117
  size_y: size_y
1072
1118
  });
1073
1119
 
1120
+ /*
1074
1121
  $nexts.not(exclude).each($.proxy(function(i, widget) {
1122
+ console.log("from_remove")
1075
1123
  this.move_widget_up( $(widget), size_y );
1076
1124
  }, this));
1125
+ */
1077
1126
 
1078
1127
  this.set_dom_grid_height();
1079
1128
 
@@ -1123,6 +1172,13 @@
1123
1172
  return false;
1124
1173
  };
1125
1174
 
1175
+ fn.remove_by_grid = function(col, row){
1176
+ var $w = this.is_widget(col, row);
1177
+ if($w){
1178
+ this.remove_widget($w);
1179
+ }
1180
+ }
1181
+
1126
1182
 
1127
1183
  /**
1128
1184
  * Remove a widget from the grid.
@@ -1199,14 +1255,15 @@
1199
1255
  $widgets || ($widgets = this.$widgets);
1200
1256
  var result = [];
1201
1257
  $widgets.each($.proxy(function(i, widget) {
1202
- result.push(this.options.serialize_params(
1258
+ if(typeof($(widget).coords().grid) != "undefined"){
1259
+ result.push(this.options.serialize_params(
1203
1260
  $(widget), $(widget).coords().grid ) );
1261
+ }
1204
1262
  }, this));
1205
1263
 
1206
1264
  return result;
1207
1265
  };
1208
1266
 
1209
-
1210
1267
  /**
1211
1268
  * Returns a serialized array of the widgets that have changed their
1212
1269
  * position.
@@ -1241,6 +1298,10 @@
1241
1298
  !this.can_move_to(
1242
1299
  {size_x: wgd.size_x, size_y: wgd.size_y}, wgd.col, wgd.row)
1243
1300
  ) {
1301
+ /*if(!$el.hasClass('.disp_ad')){
1302
+ $el.remove();
1303
+ return false;
1304
+ }*/
1244
1305
  wgd = this.next_position(wgd.size_x, wgd.size_y);
1245
1306
  wgd.el = $el;
1246
1307
  $el.attr({
@@ -1309,13 +1370,13 @@
1309
1370
  */
1310
1371
  fn.add_to_gridmap = function(grid_data, value) {
1311
1372
  this.update_widget_position(grid_data, value || grid_data.el);
1312
-
1313
- if (grid_data.el) {
1373
+ /*if (grid_data.el) {
1314
1374
  var $widgets = this.widgets_below(grid_data.el);
1315
1375
  $widgets.each($.proxy(function(i, widget) {
1376
+ console.log("from_add_to_gridmap");
1316
1377
  this.move_widget_up( $(widget));
1317
1378
  }, this));
1318
- }
1379
+ } */
1319
1380
  };
1320
1381
 
1321
1382
 
@@ -1352,7 +1413,7 @@
1352
1413
  }, 60)
1353
1414
  });
1354
1415
 
1355
- this.drag_api = this.$el.drag(draggable_options).data('drag');
1416
+ this.drag_api = this.$el.dragg(draggable_options).data('drag');
1356
1417
  return this;
1357
1418
  };
1358
1419
 
@@ -1507,6 +1568,7 @@
1507
1568
  this.player_grid_data = {};
1508
1569
  this.cells_occupied_by_placeholder = {};
1509
1570
  this.cells_occupied_by_player = {};
1571
+ this.w_queue = {};
1510
1572
 
1511
1573
  this.set_dom_grid_height();
1512
1574
  };
@@ -1600,12 +1662,13 @@
1600
1662
  */
1601
1663
  fn.set_player = function(col, row, no_player) {
1602
1664
  var self = this;
1665
+ var swap = false;
1603
1666
  if (!no_player) {
1604
1667
  this.empty_cells_player_occupies();
1605
1668
  }
1606
1669
  var cell = !no_player ? self.colliders_data[0].el.data : {col: col};
1607
1670
  var to_col = cell.col;
1608
- var to_row = row || cell.row;
1671
+ var to_row = cell.row || row;
1609
1672
 
1610
1673
  this.player_grid_data = {
1611
1674
  col: to_col,
@@ -1617,13 +1680,102 @@
1617
1680
  this.cells_occupied_by_player = this.get_cells_occupied(
1618
1681
  this.player_grid_data);
1619
1682
 
1683
+ //Added placeholder for more advanced movement.
1684
+ this.cells_occupied_by_placeholder = this.get_cells_occupied(
1685
+ this.placeholder_grid_data);
1686
+
1620
1687
  var $overlapped_widgets = this.get_widgets_overlapped(
1621
1688
  this.player_grid_data);
1622
1689
 
1623
- var constraints = this.widgets_constraints($overlapped_widgets);
1690
+ var player_size_y = this.player_grid_data.size_y;
1691
+ var player_size_x = this.player_grid_data.size_x;
1692
+ var placeholder_cells = this.cells_occupied_by_placeholder;
1693
+ var $gr = this;
1694
+
1695
+
1696
+ //Queue Swaps
1697
+ $overlapped_widgets.each($.proxy(function(i, w){
1698
+ var $w = $(w);
1699
+ var wgd = $w.coords().grid;
1700
+
1701
+ // Ensure all values are in integer format
1702
+ wgd.col = parseInt(wgd.col);
1703
+ wgd.row = parseInt(wgd.row);
1704
+ wgd.size_x = parseInt(wgd.size_x);
1705
+ wgd.size_y = parseInt(wgd.size_y);
1706
+ player_size_x = parseInt(player_size_x);
1707
+ player_size_y = parseInt(player_size_y);
1708
+
1709
+ var outside_col = placeholder_cells.cols[0]+player_size_x-1;
1710
+ var outside_row = placeholder_cells.rows[0]+player_size_y-1;
1711
+ if ($w.hasClass($gr.options.static_class)){
1712
+ //next iteration
1713
+ return true;
1714
+ }
1715
+ if(wgd.size_x <= player_size_x && wgd.size_y <= player_size_y){
1716
+ if(!$gr.is_swap_occupied(placeholder_cells.cols[0], wgd.row, wgd.size_x, wgd.size_y) && !$gr.is_player_in(placeholder_cells.cols[0], wgd.row) && !$gr.is_in_queue(placeholder_cells.cols[0], wgd.row, $w)){
1717
+ swap = $gr.queue_widget(placeholder_cells.cols[0], wgd.row, $w);
1718
+ }
1719
+ else if(!$gr.is_swap_occupied(outside_col, wgd.row, wgd.size_x, wgd.size_y) && !$gr.is_player_in(outside_col, wgd.row) && !$gr.is_in_queue(outside_col, wgd.row, $w)){
1720
+ swap = $gr.queue_widget(outside_col, wgd.row, $w);
1721
+ }
1722
+ else if(!$gr.is_swap_occupied(wgd.col, placeholder_cells.rows[0], wgd.size_x, wgd.size_y) && !$gr.is_player_in(wgd.col, placeholder_cells.rows[0]) && !$gr.is_in_queue(wgd.col, placeholder_cells.rows[0], $w)){
1723
+ swap = $gr.queue_widget(wgd.col, placeholder_cells.rows[0], $w);
1724
+ }
1725
+ else if(!$gr.is_swap_occupied(wgd.col, outside_row, wgd.size_x, wgd.size_y) && !$gr.is_player_in(wgd.col, outside_row) && !$gr.is_in_queue(wgd.col, outside_row, $w)){
1726
+ swap = $gr.queue_widget(wgd.col, outside_row, $w);
1727
+ }
1728
+ else if(!$gr.is_swap_occupied(placeholder_cells.cols[0],placeholder_cells.rows[0], wgd.size_x, wgd.size_y) && !$gr.is_player_in(placeholder_cells.cols[0],placeholder_cells.rows[0]) && !$gr.is_in_queue(placeholder_cells.cols[0],placeholder_cells.rows[0], $w)){
1729
+ swap = $gr.queue_widget(placeholder_cells.cols[0], placeholder_cells.rows[0], $w);
1730
+ } else {
1731
+ //in one last attempt we check for any other empty spaces
1732
+ for (var c = 0; c < player_size_x; c++){
1733
+ for (var r = 0; r < player_size_y; r++){
1734
+ var colc = placeholder_cells.cols[0]+c;
1735
+ var rowc = placeholder_cells.rows[0]+r;
1736
+ if (!$gr.is_swap_occupied(colc,rowc, wgd.size_x, wgd.size_y) && !$gr.is_player_in(colc,rowc) && !$gr.is_in_queue(colc, rowc, $w)){
1737
+ swap = $gr.queue_widget(colc, rowc, $w);
1738
+ c = player_size_x;
1739
+ break;
1740
+ }
1741
+ }
1742
+ }
1743
+
1744
+ }
1745
+ } else if ($gr.options.shift_larger_widgets_down && !swap) {
1746
+ $overlapped_widgets.each($.proxy(function(i, w){
1747
+ var $w = $(w);
1748
+ var wgd = $w.coords().grid;
1749
+
1750
+ if($gr.can_go_down($w)){
1751
+ $gr.move_widget_down($w, $gr.player_grid_data.size_y);
1752
+ $gr.set_placeholder(to_col, to_row);
1753
+ }
1754
+ }));
1755
+ }
1756
+
1757
+ $gr.clean_up_changed();
1758
+ }));
1759
+
1760
+
1761
+ /* To show queued items in console
1762
+ for(var key in this.w_queue){
1763
+ console.log("key " +key);
1764
+ console.log(this.w_queue[key]);
1765
+ }
1766
+ */
1624
1767
 
1625
- this.manage_movements(constraints.can_go_up, to_col, to_row);
1626
- this.manage_movements(constraints.can_not_go_up, to_col, to_row);
1768
+ //Move queued widgets
1769
+ if(swap && this.can_placeholder_be_set(to_col, to_row, player_size_x, player_size_y)){
1770
+ for(var key in this.w_queue){
1771
+ var col = parseInt(key.split("_")[0]);
1772
+ var row = parseInt(key.split("_")[1]);
1773
+ if (this.w_queue[key] != "full"){
1774
+ this.new_move_widget_to(this.w_queue[key], col, row);
1775
+ }
1776
+ }
1777
+ this.set_placeholder(to_col, to_row);
1778
+ }
1627
1779
 
1628
1780
  /* if there is not widgets overlapping in the new player position,
1629
1781
  * update the new placeholder position. */
@@ -1632,9 +1784,13 @@
1632
1784
  if (pp !== false) {
1633
1785
  to_row = pp;
1634
1786
  }
1635
- this.set_placeholder(to_col, to_row);
1787
+ if(this.can_placeholder_be_set(to_col, to_row, player_size_x, player_size_y)){
1788
+ this.set_placeholder(to_col, to_row);
1789
+ }
1636
1790
  }
1637
1791
 
1792
+ this.w_queue = {};
1793
+
1638
1794
  return {
1639
1795
  col: to_col,
1640
1796
  row: to_row
@@ -1642,6 +1798,151 @@
1642
1798
  };
1643
1799
 
1644
1800
 
1801
+ fn.is_swap_occupied = function(col, row, w_size_x, w_size_y) {
1802
+ var occupied = false;
1803
+ for (var c = 0; c < w_size_x; c++){
1804
+ for (var r = 0; r < w_size_y; r++){
1805
+ var colc = col + c;
1806
+ var rowc = row + r;
1807
+ var key = colc+"_"+rowc;
1808
+ if(this.is_occupied(colc,rowc)){
1809
+ occupied = true;
1810
+ } else if(key in this.w_queue){
1811
+ if(this.w_queue[key] == "full"){
1812
+ occupied = true;
1813
+ continue;
1814
+ }
1815
+ $tw = this.w_queue[key];
1816
+ tgd = $tw.coords().grid;
1817
+ //remove queued items if no longer under player.
1818
+ if(!this.is_widget_under_player(tgd.col,tgd.row)){
1819
+ delete this.w_queue[key];
1820
+ }
1821
+ }
1822
+ if(rowc > parseInt(this.options.max_rows)){
1823
+ occupied = true;
1824
+ }
1825
+ if(colc > parseInt(this.options.max_cols)){
1826
+ occupied = true;
1827
+ }
1828
+ if (this.is_player_in(colc,rowc)){
1829
+ occupied = true;
1830
+ }
1831
+ }
1832
+ }
1833
+
1834
+ return occupied;
1835
+ }
1836
+
1837
+ fn.can_placeholder_be_set = function(col, row, player_size_x, player_size_y){
1838
+ var can_set = true;
1839
+ for (var c = 0; c < player_size_x; c++){
1840
+ for (var r = 0; r < player_size_y; r++){
1841
+ var colc = col + c;
1842
+ var rowc = row + r;
1843
+ var key = colc+"_"+rowc;
1844
+ var $tw = this.is_widget(colc, rowc);
1845
+ //if this space is occupied and not queued for move.
1846
+ if(rowc > parseInt(this.options.max_rows)){
1847
+ can_set = false;
1848
+ }
1849
+ if(colc > parseInt(this.options.max_cols)){
1850
+ can_set = false;
1851
+ }
1852
+ if(this.is_occupied(colc,rowc) && !this.is_widget_queued_and_can_move($tw)){
1853
+ can_set = false;
1854
+ }
1855
+ }
1856
+ }
1857
+ return can_set;
1858
+ }
1859
+
1860
+ fn.queue_widget = function(col, row, $widget){
1861
+ var $w = $widget
1862
+ var wgd = $w.coords().grid;
1863
+ var primary_key = col+"_"+row;
1864
+ if (primary_key in this.w_queue){
1865
+ return false;
1866
+ }
1867
+
1868
+ this.w_queue[primary_key] = $w;
1869
+
1870
+ for (var c = 0; c < wgd.size_x; c++){
1871
+ for (var r = 0; r < wgd.size_y; r++){
1872
+ var colc = col + c;
1873
+ var rowc = row + r;
1874
+ var key = colc+"_"+rowc;
1875
+ if (key == primary_key){
1876
+ continue;
1877
+ }
1878
+ this.w_queue[key] = "full";
1879
+ }
1880
+ }
1881
+
1882
+ return true;
1883
+ }
1884
+
1885
+ fn.is_widget_queued_and_can_move = function($widget){
1886
+ var queued = false;
1887
+ if ($widget === false){
1888
+ return false;
1889
+ }
1890
+
1891
+ for(var key in this.w_queue){
1892
+ if(this.w_queue[key] == "full"){
1893
+ continue;
1894
+ }
1895
+ if(this.w_queue[key].attr("data-col") == $widget.attr("data-col") && this.w_queue[key].attr("data-row") == $widget.attr("data-row")){
1896
+ queued = true;
1897
+ //test whole space
1898
+ var $w = this.w_queue[key];
1899
+ var dcol = parseInt(key.split("_")[0]);
1900
+ var drow = parseInt(key.split("_")[1]);
1901
+ var wgd = $w.coords().grid;
1902
+
1903
+ for (var c = 0; c < wgd.size_x; c++){
1904
+ for (var r = 0; r < wgd.size_y; r++){
1905
+ var colc = dcol + c;
1906
+ var rowc = drow + r;
1907
+ if (this.is_player_in(colc,rowc)){
1908
+ queued = false;
1909
+ }
1910
+
1911
+ }
1912
+ }
1913
+
1914
+ }
1915
+ }
1916
+
1917
+ return queued
1918
+ }
1919
+
1920
+ fn.is_in_queue = function(col,row, $widget){
1921
+ var queued = false;
1922
+ var key = col+"_"+row;
1923
+
1924
+ if ((key in this.w_queue)){
1925
+ if (this.w_queue[key] == "full"){
1926
+ queued = true;
1927
+ } else {
1928
+ $tw = this.w_queue[key];
1929
+ tgd = $tw.coords().grid;
1930
+ if(!this.is_widget_under_player(tgd.col,tgd.row)){
1931
+ delete this.w_queue[key]
1932
+ queued = false;
1933
+ } else if(this.w_queue[key].attr("data-col") == $widget.attr("data-col") && this.w_queue[key].attr("data-row") == $widget.attr("data-row")) {
1934
+ delete this.w_queue[key]
1935
+ queued = false;
1936
+ } else {
1937
+ queued = true;
1938
+ }
1939
+ }
1940
+ }
1941
+
1942
+ return queued;
1943
+ }
1944
+
1945
+
1645
1946
  /**
1646
1947
  * See which of the widgets in the $widgets param collection can go to
1647
1948
  * a upper row and which not.
@@ -1765,6 +2066,8 @@
1765
2066
  /**
1766
2067
  * Sorts an Array of grid coords objects (representing the grid coords of
1767
2068
  * each widget) in descending way.
2069
+
2070
+ * Depreciated.
1768
2071
  *
1769
2072
  * @method manage_movements
1770
2073
  * @param {HTMLElements} $widgets A jQuery collection of HTMLElements
@@ -1797,9 +2100,11 @@
1797
2100
  // so we need to move widget down to a position that dont
1798
2101
  // overlaps player
1799
2102
  var y = (to_row + this.player_grid_data.size_y) - wgd.row;
1800
-
1801
- this.move_widget_down($w, y);
1802
- this.set_placeholder(to_col, to_row);
2103
+ if (this.can_go_down($w)){
2104
+ console.log("In Move Down!")
2105
+ this.move_widget_down($w, y);
2106
+ this.set_placeholder(to_col, to_row);
2107
+ }
1803
2108
  }
1804
2109
  }
1805
2110
  }, this));
@@ -1929,6 +2234,32 @@
1929
2234
  return false;
1930
2235
  };
1931
2236
 
2237
+ /**
2238
+ * Determines if widget is supposed to be static.
2239
+ * @method is_static
2240
+ * @param {Number} col The column to check.
2241
+ * @param {Number} row The row to check.
2242
+ * @return {Boolean} Returns true if widget exists and has static class,
2243
+ * else returns false
2244
+ */
2245
+
2246
+ fn.is_static = function(col, row) {
2247
+ var cell = this.gridmap[col];
2248
+ if (!cell) {
2249
+ return false;
2250
+ }
2251
+
2252
+ cell = cell[row];
2253
+
2254
+ if (cell) {
2255
+ if(cell.hasClass(this.options.static_class)){
2256
+ return true;
2257
+ }
2258
+ }
2259
+
2260
+ return false;
2261
+ };
2262
+
1932
2263
 
1933
2264
  /**
1934
2265
  * Determines if there is a widget in the cell represented by col/row
@@ -1990,7 +2321,7 @@
1990
2321
  });
1991
2322
 
1992
2323
  // Prevents widgets go out of the grid
1993
- var right_col = (col + phgd.size_x - 1);
2324
+ var right_col = (col + parseInt(phgd.size_x) - 1);
1994
2325
  if (right_col > this.cols) {
1995
2326
  col = col - (right_col - col);
1996
2327
  }
@@ -2011,8 +2342,16 @@
2011
2342
 
2012
2343
  if (moved_down || changed_column) {
2013
2344
  $nexts.each($.proxy(function(i, widget) {
2014
- this.move_widget_up(
2015
- $(widget), this.placeholder_grid_data.col - col + phgd.size_y);
2345
+ //Make sure widget is at it's topmost position
2346
+ $w = $(widget);
2347
+ wgd = $w.coords().grid;
2348
+
2349
+ var can_go_widget_up = this.can_go_widget_up(wgd);
2350
+
2351
+ if (can_go_widget_up) {
2352
+ this.move_widget_to($w, can_go_widget_up);
2353
+ }
2354
+
2016
2355
  }, this));
2017
2356
  }
2018
2357
 
@@ -2274,13 +2613,14 @@
2274
2613
  * @return {HTMLElements} Returns a jQuery collection of HTMLElements.
2275
2614
  */
2276
2615
  fn.on_stop_overlapping_column = function(col) {
2277
- this.set_player(col, false);
2278
-
2616
+ //this.set_player(col, false);
2279
2617
  var self = this;
2280
- this.for_each_widget_below(col, this.cells_occupied_by_player.rows[0],
2281
- function(tcol, trow) {
2282
- self.move_widget_up(this, self.player_grid_data.size_y);
2283
- });
2618
+ if(this.options.shift_larger_widgets_down){
2619
+ this.for_each_widget_below(col, this.cells_occupied_by_player.rows[0],
2620
+ function(tcol, trow) {
2621
+ self.move_widget_up(this, self.player_grid_data.size_y);
2622
+ });
2623
+ }
2284
2624
  };
2285
2625
 
2286
2626
 
@@ -2292,17 +2632,37 @@
2292
2632
  * @return {HTMLElements} Returns a jQuery collection of HTMLElements.
2293
2633
  */
2294
2634
  fn.on_stop_overlapping_row = function(row) {
2295
- this.set_player(false, row);
2296
-
2635
+ //this.set_player(false, row);
2297
2636
  var self = this;
2298
2637
  var cols = this.cells_occupied_by_player.cols;
2299
- for (var c = 0, cl = cols.length; c < cl; c++) {
2300
- this.for_each_widget_below(cols[c], row, function(tcol, trow) {
2301
- self.move_widget_up(this, self.player_grid_data.size_y);
2302
- });
2638
+ if(this.options.shift_larger_widgets_down){
2639
+ for (var c = 0, cl = cols.length; c < cl; c++) {
2640
+ this.for_each_widget_below(cols[c], row, function(tcol, trow) {
2641
+ console.log("from_on_stop_overlapping_row");
2642
+ self.move_widget_up(this, self.player_grid_data.size_y);
2643
+ });
2644
+ }
2303
2645
  }
2304
2646
  };
2305
2647
 
2648
+ //Not yet part of api - DM.
2649
+ fn.new_move_widget_to = function($widget, col, row){
2650
+ var self = this;
2651
+ var widget_grid_data = $widget.coords().grid;
2652
+
2653
+ this.remove_from_gridmap(widget_grid_data);
2654
+ widget_grid_data.row = row;
2655
+ widget_grid_data.col = col;
2656
+
2657
+ this.add_to_gridmap(widget_grid_data);
2658
+ $widget.attr('data-row', row);
2659
+ $widget.attr('data-col', col);
2660
+ this.update_widget_position(widget_grid_data, $widget);
2661
+ this.$changed = this.$changed.add($widget);
2662
+
2663
+ return this;
2664
+ }
2665
+
2306
2666
 
2307
2667
  /**
2308
2668
  * Move a widget to a specific row. The cell or cells must be empty.
@@ -2386,9 +2746,10 @@
2386
2746
 
2387
2747
  moved.push($widget);
2388
2748
 
2389
- $next_widgets.each($.proxy(function(i, widget) {
2749
+ /* $next_widgets.each($.proxy(function(i, widget) {
2750
+ console.log("from_within_move_widget_up");
2390
2751
  this.move_widget_up($(widget), y_units);
2391
- }, this));
2752
+ }, this)); */
2392
2753
  }
2393
2754
  });
2394
2755
 
@@ -2587,6 +2948,23 @@
2587
2948
  return this;
2588
2949
  };
2589
2950
 
2951
+ fn.can_go_down = function($el) {
2952
+ var can_go_down = true;
2953
+ var $gr = this;
2954
+
2955
+ if ($el.hasClass(this.options.static_class)){
2956
+ can_go_down = false;
2957
+ }
2958
+
2959
+ this.widgets_below($el).each(function(){
2960
+ if ($(this).hasClass($gr.options.static_class)){
2961
+ can_go_down = false;
2962
+ }
2963
+ })
2964
+
2965
+ return can_go_down;
2966
+ }
2967
+
2590
2968
 
2591
2969
  fn.can_go_up = function($el) {
2592
2970
  var el_grid_data = $el.coords().grid;
@@ -2783,6 +3161,15 @@
2783
3161
  }
2784
3162
  };
2785
3163
 
3164
+ fn.clean_up_changed = function(){
3165
+ $gr = this;
3166
+ $gr.$changed.each(function(){
3167
+ if($gr.options.shift_larger_widgets_down){
3168
+ $gr.move_widget_up($(this));
3169
+ }
3170
+ });
3171
+ }
3172
+
2786
3173
 
2787
3174
 
2788
3175
  fn._traversing_widgets = function(type, direction, col, row, callback) {
@@ -2820,7 +3207,8 @@
2820
3207
  ) {
2821
3208
  cr = callback.call(ga[col][trow], col, trow);
2822
3209
  matched.push(ga[col][trow]);
2823
- if (cr) { break; }
3210
+ //break was causing problems, leaving for testing.
3211
+ //if (cr) { break; }
2824
3212
  }
2825
3213
  }
2826
3214
  }
@@ -3205,7 +3593,8 @@
3205
3593
  });
3206
3594
 
3207
3595
  this.cols = Math.max(min_cols, cols, this.options.min_cols);
3208
- this.rows = Math.max(max_rows, this.options.min_rows);
3596
+ //this.rows = Math.max(max_rows, this.options.min_rows);
3597
+ this.rows = this.options.max_rows;
3209
3598
 
3210
3599
  this.baseX = ($(window).width() - aw) / 2;
3211
3600
  this.baseY = this.$wrapper.offset().top;
@@ -1,7 +1,3 @@
1
- /*! gridster.js - v0.1.0 - 2012-10-20
2
- * http://gridster.net/
3
- * Copyright (c) 2012 ducksboard; Licensed MIT */
4
-
5
1
  .gridster {
6
2
  position:relative;
7
3
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gridster-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.1
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-17 00:00:00.000000000 Z
12
+ date: 2013-11-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties