Skip to content

Commit c2b1dee

Browse files
committed
Merge pull request #2 from troolee/master
Update from troolee
2 parents 77159bf + 7cc5271 commit c2b1dee

File tree

7 files changed

+68
-15
lines changed

7 files changed

+68
-15
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Inspired by [gridster.js](http://gridster.net). Built with love.
1414
- [Demo](#demo)
1515
- [Usage](#usage)
1616
- [Requirements](#requirements)
17+
- [Rails integration](#rails-integration)
1718
- [Basic usage](#basic-usage)
1819
- [Options](#options)
1920
- [Grid attributes](#grid-attributes)
@@ -45,11 +46,11 @@ Inspired by [gridster.js](http://gridster.net). Built with love.
4546
- [remove_all()](#remove_all)
4647
- [resize(el, width, height)](#resizeel-width-height)
4748
- [resizable(el, val)](#resizableel-val)
48-
- [set_static(val)](#set_staticstatic_value)
49+
- [set_static(static_value)](#set_staticstatic_value)
4950
- [update(el, x, y, width, height)](#updateel-x-y-width-height)
5051
- [will_it_fit(x, y, width, height, auto_position)](#will_it_fitx-y-width-height-auto_position)
5152
- [Utils](#utils)
52-
- [GridStackUI.Utils.sort(nodes, dir, width)](#gridstackuiutilssortnodes-dir-width)
53+
- [GridStackUI.Utils.sort(nodes[, dir[, width]])](#gridstackuiutilssortnodes-dir-width)
5354
- [Touch devices support](#touch-devices-support)
5455
- [Use with knockout.js](#use-with-knockoutjs)
5556
- [Change grid width](#change-grid-width)
@@ -91,6 +92,10 @@ Usage
9192

9293
Note: You can still use [underscore.js](http://underscorejs.org) (>= 1.7.0) instead of lodash.js
9394

95+
## Rails integration
96+
97+
For rails users, integration of gridstack.js and its dependencies can be done through [gridstack-js-rails](https://github.com/randoum/gridstack-js-rails)
98+
9499
## Basic usage
95100

96101
```html
@@ -127,6 +132,7 @@ $(function () {
127132
- `cell_height` - one cell height (default: `60`)
128133
- `draggable` - allows to override jQuery UI draggable options. (default: `{handle: '.grid-stack-item-content', scroll: true, appendTo: 'body'}`)
129134
- `handle` - draggable handle selector (default: `'.grid-stack-item-content'`)
135+
- `handle_class` - draggable handle class (e.g. `'grid-stack-item-content'`). If set `handle` is ignored (default: `null`)
130136
- `height` - maximum rows amount. Default is `0` which means no maximum rows
131137
- `float` - enable floating widgets (default: `false`) See [example](http://troolee.github.io/gridstack.js/demo/float.html)
132138
- `item_class` - widget class (default: `'grid-stack-item'`)
@@ -392,7 +398,7 @@ else {
392398

393399
## Utils
394400

395-
### GridStackUI.Utils.sort(nodes, dir, width)
401+
### GridStackUI.Utils.sort(nodes[, dir[, width]])
396402

397403
Sorts array of nodes
398404

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gridstack",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"homepage": "https://github.com/troolee/gridstack.js",
55
"authors": [
66
"Pavel Reznikov <pashka.reznikov@gmail.com>"

dist/gridstack.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@
383383
var GridStack = function(el, opts) {
384384
var self = this, one_column_mode;
385385

386+
opts = opts || {};
387+
386388
this.container = $(el);
387389

388390
opts.item_class = opts.item_class || 'grid-stack-item';
@@ -394,6 +396,7 @@
394396
item_class: 'grid-stack-item',
395397
placeholder_class: 'grid-stack-placeholder',
396398
handle: '.grid-stack-item-content',
399+
handle_class: null,
397400
cell_height: 60,
398401
vertical_margin: 20,
399402
auto: true,
@@ -408,14 +411,17 @@
408411
handles: 'se'
409412
}),
410413
draggable: _.defaults(opts.draggable || {}, {
411-
handle: '.grid-stack-item-content',
414+
handle: (opts.handle_class ? '.' + opts.handle_class : (opts.handle ? opts.handle : '')) || '.grid-stack-item-content',
412415
scroll: false,
413416
appendTo: 'body'
414417
})
415418
});
416419
this.opts.is_nested = is_nested;
417420

418421
this.container.addClass(this.opts._class);
422+
423+
this._set_static_class();
424+
419425
if (is_nested) {
420426
this.container.addClass('grid-stack-nested');
421427
}
@@ -443,7 +449,7 @@
443449
if (this.opts.auto) {
444450
var elements = [];
445451
var _this = this;
446-
this.container.children('.' + this.opts.item_class).each(function(index, el) {
452+
this.container.children('.' + this.opts.item_class + ':not(.' + this.opts.placeholder_class + ')').each(function(index, el) {
447453
el = $(el);
448454
elements.push({
449455
el: el,
@@ -511,7 +517,7 @@
511517
$(window).resize(this.on_resize_handler);
512518
this.on_resize_handler();
513519
};
514-
520+
515521
GridStack.prototype._trigger_change_event = function(forceTrigger) {
516522
var elements = this.grid.get_dirty_nodes();
517523
var hasChanges = false;
@@ -755,7 +761,7 @@
755761
this.container.remove();
756762
Utils.remove_stylesheet(this._styles_id);
757763
if (this.grid)
758-
this.grid = null;
764+
this.grid = null;
759765
};
760766

761767
GridStack.prototype.resizable = function(el, val) {
@@ -946,6 +952,21 @@
946952
return this.grid.is_area_empty(x, y, width, height);
947953
};
948954

955+
GridStack.prototype.set_static = function(static_value) {
956+
this.opts.static_grid = (static_value === true);
957+
this._set_static_class();
958+
};
959+
960+
GridStack.prototype._set_static_class = function() {
961+
var static_class_name = 'grid-stack-static';
962+
963+
if (this.opts.static_grid === true) {
964+
this.container.addClass(static_class_name);
965+
} else {
966+
this.container.removeClass(static_class_name);
967+
}
968+
};
969+
949970
scope.GridStackUI = GridStack;
950971

951972
scope.GridStackUI.Utils = Utils;

dist/gridstack.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/gridstack.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "gridstack",
3+
"version": "0.2.3",
4+
"description": "gridstack.js is a jQuery plugin for widget layout",
5+
"main": "dist/gridstack.js",
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/troolee/gridstack.js.git"
9+
},
10+
"keywords": [
11+
"gridstack",
12+
"grid",
13+
"gridster",
14+
"layout",
15+
"jquery"
16+
],
17+
"author": "Pavel Reznikov <pashka.reznikov@gmail.com>",
18+
"license": "MIT",
19+
"bugs": {
20+
"url": "https://github.com/troolee/gridstack.js/issues"
21+
},
22+
"homepage": "http://troolee.github.io/gridstack.js/"
23+
}

src/gridstack.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@
383383
var GridStack = function(el, opts) {
384384
var self = this, one_column_mode;
385385

386+
opts = opts || {};
387+
386388
this.container = $(el);
387389

388390
opts.item_class = opts.item_class || 'grid-stack-item';
@@ -394,6 +396,7 @@
394396
item_class: 'grid-stack-item',
395397
placeholder_class: 'grid-stack-placeholder',
396398
handle: '.grid-stack-item-content',
399+
handle_class: null,
397400
cell_height: 60,
398401
vertical_margin: 20,
399402
auto: true,
@@ -408,7 +411,7 @@
408411
handles: 'se'
409412
}),
410413
draggable: _.defaults(opts.draggable || {}, {
411-
handle: '.grid-stack-item-content',
414+
handle: (opts.handle_class ? '.' + opts.handle_class : (opts.handle ? opts.handle : '')) || '.grid-stack-item-content',
412415
scroll: false,
413416
appendTo: 'body'
414417
})
@@ -446,7 +449,7 @@
446449
if (this.opts.auto) {
447450
var elements = [];
448451
var _this = this;
449-
this.container.children('.' + this.opts.item_class).each(function(index, el) {
452+
this.container.children('.' + this.opts.item_class + ':not(.' + this.opts.placeholder_class + ')').each(function(index, el) {
450453
el = $(el);
451454
elements.push({
452455
el: el,
@@ -514,7 +517,7 @@
514517
$(window).resize(this.on_resize_handler);
515518
this.on_resize_handler();
516519
};
517-
520+
518521
GridStack.prototype._trigger_change_event = function(forceTrigger) {
519522
var elements = this.grid.get_dirty_nodes();
520523
var hasChanges = false;
@@ -758,7 +761,7 @@
758761
this.container.remove();
759762
Utils.remove_stylesheet(this._styles_id);
760763
if (this.grid)
761-
this.grid = null;
764+
this.grid = null;
762765
};
763766

764767
GridStack.prototype.resizable = function(el, val) {
@@ -956,7 +959,7 @@
956959

957960
GridStack.prototype._set_static_class = function() {
958961
var static_class_name = 'grid-stack-static';
959-
962+
960963
if (this.opts.static_grid === true) {
961964
this.container.addClass(static_class_name);
962965
} else {

0 commit comments

Comments
 (0)