Merge branch 'feature/dd-plugins'
This commit is contained in:
commit
a749a930c0
|
@ -37,7 +37,8 @@ module.exports = function(grunt) {
|
|||
copy: {
|
||||
dist: {
|
||||
files: {
|
||||
'dist/gridstack.js': ['src/gridstack.js']
|
||||
'dist/gridstack.js': ['src/gridstack.js'],
|
||||
'dist/gridstack.jQueryUI.js': ['src/gridstack.jQueryUI.js'],
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -50,7 +51,9 @@ module.exports = function(grunt) {
|
|||
},
|
||||
dist: {
|
||||
files: {
|
||||
'dist/gridstack.min.js': ['src/gridstack.js']
|
||||
'dist/gridstack.min.js': ['src/gridstack.js'],
|
||||
'dist/gridstack.jQueryUI.js': ['src/gridstack.jQueryUI.js'],
|
||||
'dist/gridstack.all.js': ['src/gridstack.js', 'src/gridstack.jQueryUI.js']
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
20
README.md
20
README.md
|
@ -25,6 +25,7 @@ Join gridstack.js on Slack: https://gridstackjs.troolee.com
|
|||
- [Requirements](#requirements)
|
||||
- [Install](#install)
|
||||
- [Basic usage](#basic-usage)
|
||||
- [Migrating to v0.2.7](#migrating-to-v027)
|
||||
- [Migrating to v0.2.5](#migrating-to-v025)
|
||||
- [API Documentation](#api-documentation)
|
||||
- [Questions and Answers](#questions-and-answers)
|
||||
|
@ -129,6 +130,25 @@ $(function () {
|
|||
</script>
|
||||
```
|
||||
|
||||
## Migrating to v0.2.7
|
||||
|
||||
As of v0.2.7, gridstack introduces a new plugin system. The drag'n'drop functionality has been modified to take advantage of this system. Because of this, and to avoid dependency on core code from jQuery UI, the plugin was functionality was moved to a separate file.
|
||||
|
||||
To ensure gridstack continues to work, either include the additional `gridstack.jQueryUI.js` file into your HTML or use `gridstack.all.js`:
|
||||
|
||||
```html
|
||||
<script src="gridstack.js"></script>
|
||||
<script src="gridstack.jQueryUI.js"></script>
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```html
|
||||
<script src="gridstack.all.js"></script>
|
||||
```
|
||||
|
||||
We're working on implementing support for other drag'n'drop libraries through the new plugin system.
|
||||
|
||||
## Migrating to v0.2.5
|
||||
|
||||
As of v0.2.5 all methods and parameters are in camel case to respect [JavaScript Style Guide and Coding Conventions](http://www.w3schools.com/js/js_conventions.asp).
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
|
||||
<script src="../dist/gridstack.js"></script>
|
||||
<script src="../dist/gridstack.jQueryUI.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
.grid-stack {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
|
||||
<script src="../dist/gridstack.js"></script>
|
||||
<script src="../dist/gridstack.jQueryUI.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
.grid-stack {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
|
||||
<script src="../dist/gridstack.js"></script>
|
||||
<script src="../dist/gridstack.jQueryUI.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
.grid-stack {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
|
||||
<script src="../dist/gridstack.js"></script>
|
||||
<script src="../dist/gridstack.jQueryUI.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
.grid-stack {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
|
||||
<script src="../dist/gridstack.js"></script>
|
||||
<script src="../dist/gridstack.jQueryUI.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
.grid-stack {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
|
||||
<script src="../dist/gridstack.js"></script>
|
||||
<script src="../dist/gridstack.jQueryUI.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
.grid-stack {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
|
||||
<script src="../dist/gridstack.js"></script>
|
||||
<script src="../dist/gridstack.jQueryUI.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
.grid-stack {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
|
||||
<script src="../dist/gridstack.js"></script>
|
||||
<script src="../dist/gridstack.jQueryUI.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
.grid-stack {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
|
||||
<script src="../dist/gridstack.js"></script>
|
||||
<script src="../dist/gridstack.jQueryUI.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
#grid1 {
|
||||
|
|
39
dist/gridstack.all.js
vendored
Normal file
39
dist/gridstack.all.js
vendored
Normal file
File diff suppressed because one or more lines are too long
13
dist/gridstack.jQueryUI.js
vendored
Normal file
13
dist/gridstack.jQueryUI.js
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* gridstack.js 0.2.7-dev
|
||||
* http://troolee.github.io/gridstack.js/
|
||||
* (c) 2014-2016 Pavel Reznikov, Dylan Weiss
|
||||
* gridstack.js may be freely distributed under the MIT license.
|
||||
* @preserve
|
||||
*/
|
||||
!function(a){if("function"==typeof define&&define.amd)define(["jquery","lodash","gridstack","jquery-ui/data","jquery-ui/disable-selection","jquery-ui/focusable","jquery-ui/form","jquery-ui/ie","jquery-ui/keycode","jquery-ui/labels","jquery-ui/jquery-1-7","jquery-ui/plugin","jquery-ui/safe-active-element","jquery-ui/safe-blur","jquery-ui/scroll-parent","jquery-ui/tabbable","jquery-ui/unique-id","jquery-ui/version","jquery-ui/widget","jquery-ui/widgets/mouse","jquery-ui/widgets/draggable","jquery-ui/widgets/droppable","jquery-ui/widgets/resizable"],a);else if("undefined"!=typeof exports){try{jQuery=require("jquery")}catch(a){}try{_=require("lodash")}catch(a){}try{GridStackUI=require("gridstack")}catch(a){}a(jQuery,_,GridStackUI)}else a(jQuery,_,GridStackUI)}(function(a,b,c){/**
|
||||
* @class JQueryUIGridStackDragDropPlugin
|
||||
* jQuery UI implementation of drag'n'drop gridstack plugin.
|
||||
*/
|
||||
function d(a){c.GridStackDragDropPlugin.call(this,a)}window;return c.GridStackDragDropPlugin.registerPlugin(d),d.prototype=Object.create(c.GridStackDragDropPlugin.prototype),d.prototype.constructor=d,d.prototype.resizable=function(c,d){if(c=a(c),"disable"===d||"enable"===d)c.resizable(d);else if("option"===d){var e=arguments[2],f=arguments[3];c.resizable(d,e,f)}else c.resizable(b.extend({},this.grid.opts.resizable,{start:d.start||function(){},stop:d.stop||function(){},resize:d.resize||function(){}}));return this},d.prototype.draggable=function(c,d){return c=a(c),"disable"===d||"enable"===d?c.draggable(d):c.draggable(b.extend({},this.grid.opts.draggable,{containment:this.grid.opts.isNested?this.grid.container.parent():null,start:d.start||function(){},stop:d.stop||function(){},drag:d.drag||function(){}})),this},d.prototype.droppable=function(b,c){return b=a(b),"disable"===c||"enable"===c?b.droppable(c):b.droppable({accept:c.accept}),this},d.prototype.isDroppable=function(b,c){return b=a(b),Boolean(b.data("droppable"))},d.prototype.on=function(b,c,d){return a(b).on(c,d),this},d});
|
||||
//# sourceMappingURL=gridstack.min.map
|
132
dist/gridstack.js
vendored
132
dist/gridstack.js
vendored
|
@ -1,18 +1,13 @@
|
|||
/**
|
||||
* gridstack.js 0.2.7-dev
|
||||
* http://troolee.github.io/gridstack.js/
|
||||
* (c) 2014-2016 Pavel Reznikov
|
||||
* (c) 2014-2016 Pavel Reznikov, Dylan Weiss
|
||||
* gridstack.js may be freely distributed under the MIT license.
|
||||
* @preserve
|
||||
*/
|
||||
(function(factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(['jquery', 'lodash', 'jquery-ui/data', 'jquery-ui/disable-selection', 'jquery-ui/focusable',
|
||||
'jquery-ui/form', 'jquery-ui/ie', 'jquery-ui/keycode', 'jquery-ui/labels', 'jquery-ui/jquery-1-7',
|
||||
'jquery-ui/plugin', 'jquery-ui/safe-active-element', 'jquery-ui/safe-blur', 'jquery-ui/scroll-parent',
|
||||
'jquery-ui/tabbable', 'jquery-ui/unique-id', 'jquery-ui/version', 'jquery-ui/widget',
|
||||
'jquery-ui/widgets/mouse', 'jquery-ui/widgets/draggable', 'jquery-ui/widgets/droppable',
|
||||
'jquery-ui/widgets/resizable'], factory);
|
||||
define(['jquery', 'lodash'], factory);
|
||||
} else if (typeof exports !== 'undefined') {
|
||||
try { jQuery = require('jquery'); } catch (e) {}
|
||||
try { _ = require('lodash'); } catch (e) {}
|
||||
|
@ -124,6 +119,41 @@
|
|||
Utils.insert_css_rule = obsolete(Utils.insertCSSRule, 'insert_css_rule', 'insertCSSRule');
|
||||
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
|
||||
/**
|
||||
* @class GridStackDragDropPlugin
|
||||
* Base class for drag'n'drop plugin.
|
||||
*/
|
||||
function GridStackDragDropPlugin(grid) {
|
||||
this.grid = grid;
|
||||
}
|
||||
|
||||
GridStackDragDropPlugin.registeredPlugins = [];
|
||||
|
||||
GridStackDragDropPlugin.registerPlugin = function(pluginClass) {
|
||||
GridStackDragDropPlugin.registeredPlugins.push(pluginClass);
|
||||
};
|
||||
|
||||
GridStackDragDropPlugin.prototype.resizable = function(el, opts) {
|
||||
return this;
|
||||
};
|
||||
|
||||
GridStackDragDropPlugin.prototype.draggable = function(el, opts) {
|
||||
return this;
|
||||
};
|
||||
|
||||
GridStackDragDropPlugin.prototype.droppable = function(el, opts) {
|
||||
return this;
|
||||
};
|
||||
|
||||
GridStackDragDropPlugin.prototype.isDroppable = function(el) {
|
||||
return false;
|
||||
};
|
||||
|
||||
GridStackDragDropPlugin.prototype.on = function(el, eventName, callback) {
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
var idSeq = 0;
|
||||
|
||||
var GridStackEngine = function(width, onchange, floatMode, height, items) {
|
||||
|
@ -571,9 +601,18 @@
|
|||
removeTimeout: 2000,
|
||||
verticalMarginUnit: 'px',
|
||||
cellHeightUnit: 'px',
|
||||
oneColumnModeClass: opts.oneColumnModeClass || 'grid-stack-one-column-mode'
|
||||
oneColumnModeClass: opts.oneColumnModeClass || 'grid-stack-one-column-mode',
|
||||
ddPlugin: null
|
||||
});
|
||||
|
||||
if (this.opts.ddPlugin === false) {
|
||||
this.opts.ddPlugin = GridStackDragDropPlugin;
|
||||
} else if (this.opts.ddPlugin === null) {
|
||||
this.opts.ddPlugin = _.first(GridStackDragDropPlugin.registeredPlugins) || GridStackDragDropPlugin;
|
||||
}
|
||||
|
||||
this.dd = new this.opts.ddPlugin(this);
|
||||
|
||||
if (this.opts.rtl === 'auto') {
|
||||
this.opts.rtl = this.container.css('direction') === 'rtl';
|
||||
}
|
||||
|
@ -670,10 +709,10 @@
|
|||
return;
|
||||
}
|
||||
if (node.noMove || self.opts.disableDrag) {
|
||||
node.el.draggable('disable');
|
||||
self.dd.draggable(node.el, 'disable');
|
||||
}
|
||||
if (node.noResize || self.opts.disableResize) {
|
||||
node.el.resizable('disable');
|
||||
self.dd.resizable(node.el, 'disable');
|
||||
}
|
||||
|
||||
node.el.trigger('resize');
|
||||
|
@ -692,10 +731,10 @@
|
|||
|
||||
_.each(self.grid.nodes, function(node) {
|
||||
if (!node.noMove && !self.opts.disableDrag) {
|
||||
node.el.draggable('enable');
|
||||
self.dd.draggable(node.el, 'enable');
|
||||
}
|
||||
if (!node.noResize && !self.opts.disableResize) {
|
||||
node.el.resizable('enable');
|
||||
self.dd.resizable(node.el, 'enable');
|
||||
}
|
||||
|
||||
node.el.trigger('resize');
|
||||
|
@ -708,13 +747,13 @@
|
|||
|
||||
if (!self.opts.staticGrid && typeof self.opts.removable === 'string') {
|
||||
var trashZone = $(self.opts.removable);
|
||||
if (!trashZone.data('droppable')) {
|
||||
trashZone.droppable({
|
||||
if (!this.dd.isDroppable(trashZone)) {
|
||||
this.dd.droppable(trashZone, {
|
||||
accept: '.' + self.opts.itemClass
|
||||
});
|
||||
}
|
||||
trashZone
|
||||
.on('dropover', function(event, ui) {
|
||||
this.dd
|
||||
.on(trashZone, 'dropover', function(event, ui) {
|
||||
var el = $(ui.draggable);
|
||||
var node = el.data('_gridstack_node');
|
||||
if (node._grid !== self) {
|
||||
|
@ -722,7 +761,7 @@
|
|||
}
|
||||
self._setupRemovingTimeout(el);
|
||||
})
|
||||
.on('dropout', function(event, ui) {
|
||||
.on(trashZone, 'dropout', function(event, ui) {
|
||||
var el = $(ui.draggable);
|
||||
var node = el.data('_gridstack_node');
|
||||
if (node._grid !== self) {
|
||||
|
@ -772,16 +811,18 @@
|
|||
}
|
||||
};
|
||||
|
||||
$(self.container).droppable({
|
||||
accept: function(el) {
|
||||
el = $(el);
|
||||
var node = el.data('_gridstack_node');
|
||||
if (node && node._grid === self) {
|
||||
return false;
|
||||
this.dd
|
||||
.droppable(self.container, {
|
||||
accept: function(el) {
|
||||
el = $(el);
|
||||
var node = el.data('_gridstack_node');
|
||||
if (node && node._grid === self) {
|
||||
return false;
|
||||
}
|
||||
return el.is(self.opts.acceptWidgets === true ? '.grid-stack-item' : self.opts.acceptWidgets);
|
||||
}
|
||||
return el.is(self.opts.acceptWidgets === true ? '.grid-stack-item' : self.opts.acceptWidgets);
|
||||
},
|
||||
over: function(event, ui) {
|
||||
})
|
||||
.on(self.container, 'dropover', function(event, ui) {
|
||||
var offset = self.container.offset();
|
||||
var el = $(ui.draggable);
|
||||
var cellWidth = self.cellWidth();
|
||||
|
@ -798,8 +839,8 @@
|
|||
el.data('_gridstack_node_orig', origNode);
|
||||
|
||||
el.on('drag', onDrag);
|
||||
},
|
||||
out: function(event, ui) {
|
||||
})
|
||||
.on(self.container, 'dropout', function(event, ui) {
|
||||
var el = $(ui.draggable);
|
||||
el.unbind('drag', onDrag);
|
||||
var node = el.data('_gridstack_node');
|
||||
|
@ -808,8 +849,8 @@
|
|||
self.placeholder.detach();
|
||||
self._updateContainerHeight();
|
||||
el.data('_gridstack_node', el.data('_gridstack_node_orig'));
|
||||
},
|
||||
drop: function(event, ui) {
|
||||
})
|
||||
.on(self.container, 'drop', function(event, ui) {
|
||||
self.placeholder.detach();
|
||||
|
||||
var node = $(ui.draggable).data('_gridstack_node');
|
||||
|
@ -836,8 +877,7 @@
|
|||
self._triggerChangeEvent();
|
||||
|
||||
self.grid.endUpdate();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1081,8 +1121,8 @@
|
|||
node._beforeDragX = node.x;
|
||||
node._beforeDragY = node.y;
|
||||
|
||||
el.resizable('option', 'minWidth', cellWidth * (node.minWidth || 1));
|
||||
el.resizable('option', 'minHeight', strictCellHeight * (node.minHeight || 1));
|
||||
self.dd.resizable(el, 'option', 'minWidth', cellWidth * (node.minWidth || 1));
|
||||
self.dd.resizable(el, 'option', 'minHeight', strictCellHeight * (node.minHeight || 1));
|
||||
|
||||
if (event.type == 'resizestart') {
|
||||
o.find('.grid-stack-item').trigger('resizestart');
|
||||
|
@ -1139,25 +1179,24 @@
|
|||
}
|
||||
};
|
||||
|
||||
el
|
||||
.draggable(_.extend({}, this.opts.draggable, {
|
||||
containment: this.opts.isNested ? this.container.parent() : null,
|
||||
this.dd
|
||||
.draggable(el, {
|
||||
start: onStartMoving,
|
||||
stop: onEndMoving,
|
||||
drag: dragOrResize
|
||||
}))
|
||||
.resizable(_.extend({}, this.opts.resizable, {
|
||||
})
|
||||
.resizable(el, {
|
||||
start: onStartMoving,
|
||||
stop: onEndMoving,
|
||||
resize: dragOrResize
|
||||
}));
|
||||
});
|
||||
|
||||
if (node.noMove || this._isOneColumnMode() || this.opts.disableDrag) {
|
||||
el.draggable('disable');
|
||||
this.dd.draggable(el, 'disable');
|
||||
}
|
||||
|
||||
if (node.noResize || this._isOneColumnMode() || this.opts.disableResize) {
|
||||
el.resizable('disable');
|
||||
this.dd.resizable(el, 'disable');
|
||||
}
|
||||
|
||||
el.attr('data-gs-locked', node.locked ? 'yes' : null);
|
||||
|
@ -1291,9 +1330,9 @@
|
|||
|
||||
node.noResize = !(val || false);
|
||||
if (node.noResize || self._isOneColumnMode()) {
|
||||
el.resizable('disable');
|
||||
self.dd.resizable(el, 'disable');
|
||||
} else {
|
||||
el.resizable('enable');
|
||||
self.dd.resizable(el, 'enable');
|
||||
}
|
||||
});
|
||||
return this;
|
||||
|
@ -1311,10 +1350,10 @@
|
|||
|
||||
node.noMove = !(val || false);
|
||||
if (node.noMove || self._isOneColumnMode()) {
|
||||
el.draggable('disable');
|
||||
self.dd.draggable(el, 'disable');
|
||||
el.removeClass('ui-draggable-handle');
|
||||
} else {
|
||||
el.draggable('enable');
|
||||
self.dd.draggable(el, 'enable');
|
||||
el.addClass('ui-draggable-handle');
|
||||
}
|
||||
});
|
||||
|
@ -1670,6 +1709,7 @@
|
|||
|
||||
scope.GridStackUI.Utils = Utils;
|
||||
scope.GridStackUI.Engine = GridStackEngine;
|
||||
scope.GridStackUI.GridStackDragDropPlugin = GridStackDragDropPlugin;
|
||||
|
||||
$.fn.gridstack = function(opts) {
|
||||
return this.each(function() {
|
||||
|
|
24
dist/gridstack.min.js
vendored
24
dist/gridstack.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/gridstack.min.map
vendored
2
dist/gridstack.min.map
vendored
File diff suppressed because one or more lines are too long
|
@ -68,6 +68,7 @@ gridstack.js API
|
|||
- a string (ex: '10em', '100px', '10rem')
|
||||
- 0 or null, in which case the library will not generate styles for rows. Everything must be defined in CSS files.
|
||||
- `'auto'` - height will be calculated from cell width.
|
||||
- `ddPlugin` - class that implement drag'n'drop functionallity for gridstack. If `false` grid will be static. (default: `null` - first available plugin will be used)
|
||||
- `disableDrag` - disallows dragging of widgets (default: `false`).
|
||||
- `disableResize` - disallows resizing of widgets (default: `false`).
|
||||
- `draggable` - allows to override jQuery UI draggable options. (default: `{handle: '.grid-stack-item-content', scroll: false, appendTo: 'body'}`)
|
||||
|
|
|
@ -19,6 +19,7 @@ module.exports = function(config) {
|
|||
'bower_components/jquery-ui/jquery-ui.min.js',
|
||||
'bower_components/lodash/dist/lodash.min.js',
|
||||
'src/gridstack.js',
|
||||
'src/gridstack.jQueryUI.js',
|
||||
'spec/*-spec.js'
|
||||
],
|
||||
|
||||
|
@ -31,7 +32,8 @@ module.exports = function(config) {
|
|||
// preprocess matching files before serving them to the browser
|
||||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
||||
preprocessors: {
|
||||
'src/gridstack.js': ['coverage']
|
||||
'src/gridstack.js': ['coverage'],
|
||||
'src/gridstack.jQueryUI.js': ['coverage'],
|
||||
},
|
||||
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
|
||||
<script src="../../../dist/gridstack.js"></script>
|
||||
<script src="../../../dist/gridstack.jQueryUI.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
.grid-stack {
|
||||
|
|
97
src/gridstack.jQueryUI.js
Normal file
97
src/gridstack.jQueryUI.js
Normal file
|
@ -0,0 +1,97 @@
|
|||
/**
|
||||
* gridstack.js 0.2.7-dev
|
||||
* http://troolee.github.io/gridstack.js/
|
||||
* (c) 2014-2016 Pavel Reznikov, Dylan Weiss
|
||||
* gridstack.js may be freely distributed under the MIT license.
|
||||
* @preserve
|
||||
*/
|
||||
(function(factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(['jquery', 'lodash', 'gridstack', 'jquery-ui/data', 'jquery-ui/disable-selection', 'jquery-ui/focusable',
|
||||
'jquery-ui/form', 'jquery-ui/ie', 'jquery-ui/keycode', 'jquery-ui/labels', 'jquery-ui/jquery-1-7',
|
||||
'jquery-ui/plugin', 'jquery-ui/safe-active-element', 'jquery-ui/safe-blur', 'jquery-ui/scroll-parent',
|
||||
'jquery-ui/tabbable', 'jquery-ui/unique-id', 'jquery-ui/version', 'jquery-ui/widget',
|
||||
'jquery-ui/widgets/mouse', 'jquery-ui/widgets/draggable', 'jquery-ui/widgets/droppable',
|
||||
'jquery-ui/widgets/resizable'], factory);
|
||||
} else if (typeof exports !== 'undefined') {
|
||||
try { jQuery = require('jquery'); } catch (e) {}
|
||||
try { _ = require('lodash'); } catch (e) {}
|
||||
try { GridStackUI = require('gridstack'); } catch (e) {}
|
||||
factory(jQuery, _, GridStackUI);
|
||||
} else {
|
||||
factory(jQuery, _, GridStackUI);
|
||||
}
|
||||
})(function($, _, GridStackUI) {
|
||||
|
||||
var scope = window;
|
||||
|
||||
/**
|
||||
* @class JQueryUIGridStackDragDropPlugin
|
||||
* jQuery UI implementation of drag'n'drop gridstack plugin.
|
||||
*/
|
||||
function JQueryUIGridStackDragDropPlugin(grid) {
|
||||
GridStackUI.GridStackDragDropPlugin.call(this, grid);
|
||||
}
|
||||
|
||||
GridStackUI.GridStackDragDropPlugin.registerPlugin(JQueryUIGridStackDragDropPlugin);
|
||||
|
||||
JQueryUIGridStackDragDropPlugin.prototype = Object.create(GridStackUI.GridStackDragDropPlugin.prototype);
|
||||
JQueryUIGridStackDragDropPlugin.prototype.constructor = JQueryUIGridStackDragDropPlugin;
|
||||
|
||||
JQueryUIGridStackDragDropPlugin.prototype.resizable = function(el, opts) {
|
||||
el = $(el);
|
||||
if (opts === 'disable' || opts === 'enable') {
|
||||
el.resizable(opts);
|
||||
} else if (opts === 'option') {
|
||||
var key = arguments[2];
|
||||
var value = arguments[3];
|
||||
el.resizable(opts, key, value);
|
||||
} else {
|
||||
el.resizable(_.extend({}, this.grid.opts.resizable, {
|
||||
start: opts.start || function() {},
|
||||
stop: opts.stop || function() {},
|
||||
resize: opts.resize || function() {}
|
||||
}));
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
JQueryUIGridStackDragDropPlugin.prototype.draggable = function(el, opts) {
|
||||
el = $(el);
|
||||
if (opts === 'disable' || opts === 'enable') {
|
||||
el.draggable(opts);
|
||||
} else {
|
||||
el.draggable(_.extend({}, this.grid.opts.draggable, {
|
||||
containment: this.grid.opts.isNested ? this.grid.container.parent() : null,
|
||||
start: opts.start || function() {},
|
||||
stop: opts.stop || function() {},
|
||||
drag: opts.drag || function() {}
|
||||
}));
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
JQueryUIGridStackDragDropPlugin.prototype.droppable = function(el, opts) {
|
||||
el = $(el);
|
||||
if (opts === 'disable' || opts === 'enable') {
|
||||
el.droppable(opts);
|
||||
} else {
|
||||
el.droppable({
|
||||
accept: opts.accept
|
||||
});
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
JQueryUIGridStackDragDropPlugin.prototype.isDroppable = function(el, opts) {
|
||||
el = $(el);
|
||||
return Boolean(el.data('droppable'));
|
||||
};
|
||||
|
||||
JQueryUIGridStackDragDropPlugin.prototype.on = function(el, eventName, callback) {
|
||||
$(el).on(eventName, callback);
|
||||
return this;
|
||||
};
|
||||
|
||||
return JQueryUIGridStackDragDropPlugin;
|
||||
});
|
132
src/gridstack.js
132
src/gridstack.js
|
@ -1,18 +1,13 @@
|
|||
/**
|
||||
* gridstack.js 0.2.7-dev
|
||||
* http://troolee.github.io/gridstack.js/
|
||||
* (c) 2014-2016 Pavel Reznikov
|
||||
* (c) 2014-2016 Pavel Reznikov, Dylan Weiss
|
||||
* gridstack.js may be freely distributed under the MIT license.
|
||||
* @preserve
|
||||
*/
|
||||
(function(factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(['jquery', 'lodash', 'jquery-ui/data', 'jquery-ui/disable-selection', 'jquery-ui/focusable',
|
||||
'jquery-ui/form', 'jquery-ui/ie', 'jquery-ui/keycode', 'jquery-ui/labels', 'jquery-ui/jquery-1-7',
|
||||
'jquery-ui/plugin', 'jquery-ui/safe-active-element', 'jquery-ui/safe-blur', 'jquery-ui/scroll-parent',
|
||||
'jquery-ui/tabbable', 'jquery-ui/unique-id', 'jquery-ui/version', 'jquery-ui/widget',
|
||||
'jquery-ui/widgets/mouse', 'jquery-ui/widgets/draggable', 'jquery-ui/widgets/droppable',
|
||||
'jquery-ui/widgets/resizable'], factory);
|
||||
define(['jquery', 'lodash'], factory);
|
||||
} else if (typeof exports !== 'undefined') {
|
||||
try { jQuery = require('jquery'); } catch (e) {}
|
||||
try { _ = require('lodash'); } catch (e) {}
|
||||
|
@ -124,6 +119,41 @@
|
|||
Utils.insert_css_rule = obsolete(Utils.insertCSSRule, 'insert_css_rule', 'insertCSSRule');
|
||||
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
|
||||
/**
|
||||
* @class GridStackDragDropPlugin
|
||||
* Base class for drag'n'drop plugin.
|
||||
*/
|
||||
function GridStackDragDropPlugin(grid) {
|
||||
this.grid = grid;
|
||||
}
|
||||
|
||||
GridStackDragDropPlugin.registeredPlugins = [];
|
||||
|
||||
GridStackDragDropPlugin.registerPlugin = function(pluginClass) {
|
||||
GridStackDragDropPlugin.registeredPlugins.push(pluginClass);
|
||||
};
|
||||
|
||||
GridStackDragDropPlugin.prototype.resizable = function(el, opts) {
|
||||
return this;
|
||||
};
|
||||
|
||||
GridStackDragDropPlugin.prototype.draggable = function(el, opts) {
|
||||
return this;
|
||||
};
|
||||
|
||||
GridStackDragDropPlugin.prototype.droppable = function(el, opts) {
|
||||
return this;
|
||||
};
|
||||
|
||||
GridStackDragDropPlugin.prototype.isDroppable = function(el) {
|
||||
return false;
|
||||
};
|
||||
|
||||
GridStackDragDropPlugin.prototype.on = function(el, eventName, callback) {
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
var idSeq = 0;
|
||||
|
||||
var GridStackEngine = function(width, onchange, floatMode, height, items) {
|
||||
|
@ -571,9 +601,18 @@
|
|||
removeTimeout: 2000,
|
||||
verticalMarginUnit: 'px',
|
||||
cellHeightUnit: 'px',
|
||||
oneColumnModeClass: opts.oneColumnModeClass || 'grid-stack-one-column-mode'
|
||||
oneColumnModeClass: opts.oneColumnModeClass || 'grid-stack-one-column-mode',
|
||||
ddPlugin: null
|
||||
});
|
||||
|
||||
if (this.opts.ddPlugin === false) {
|
||||
this.opts.ddPlugin = GridStackDragDropPlugin;
|
||||
} else if (this.opts.ddPlugin === null) {
|
||||
this.opts.ddPlugin = _.first(GridStackDragDropPlugin.registeredPlugins) || GridStackDragDropPlugin;
|
||||
}
|
||||
|
||||
this.dd = new this.opts.ddPlugin(this);
|
||||
|
||||
if (this.opts.rtl === 'auto') {
|
||||
this.opts.rtl = this.container.css('direction') === 'rtl';
|
||||
}
|
||||
|
@ -670,10 +709,10 @@
|
|||
return;
|
||||
}
|
||||
if (node.noMove || self.opts.disableDrag) {
|
||||
node.el.draggable('disable');
|
||||
self.dd.draggable(node.el, 'disable');
|
||||
}
|
||||
if (node.noResize || self.opts.disableResize) {
|
||||
node.el.resizable('disable');
|
||||
self.dd.resizable(node.el, 'disable');
|
||||
}
|
||||
|
||||
node.el.trigger('resize');
|
||||
|
@ -692,10 +731,10 @@
|
|||
|
||||
_.each(self.grid.nodes, function(node) {
|
||||
if (!node.noMove && !self.opts.disableDrag) {
|
||||
node.el.draggable('enable');
|
||||
self.dd.draggable(node.el, 'enable');
|
||||
}
|
||||
if (!node.noResize && !self.opts.disableResize) {
|
||||
node.el.resizable('enable');
|
||||
self.dd.resizable(node.el, 'enable');
|
||||
}
|
||||
|
||||
node.el.trigger('resize');
|
||||
|
@ -708,13 +747,13 @@
|
|||
|
||||
if (!self.opts.staticGrid && typeof self.opts.removable === 'string') {
|
||||
var trashZone = $(self.opts.removable);
|
||||
if (!trashZone.data('droppable')) {
|
||||
trashZone.droppable({
|
||||
if (!this.dd.isDroppable(trashZone)) {
|
||||
this.dd.droppable(trashZone, {
|
||||
accept: '.' + self.opts.itemClass
|
||||
});
|
||||
}
|
||||
trashZone
|
||||
.on('dropover', function(event, ui) {
|
||||
this.dd
|
||||
.on(trashZone, 'dropover', function(event, ui) {
|
||||
var el = $(ui.draggable);
|
||||
var node = el.data('_gridstack_node');
|
||||
if (node._grid !== self) {
|
||||
|
@ -722,7 +761,7 @@
|
|||
}
|
||||
self._setupRemovingTimeout(el);
|
||||
})
|
||||
.on('dropout', function(event, ui) {
|
||||
.on(trashZone, 'dropout', function(event, ui) {
|
||||
var el = $(ui.draggable);
|
||||
var node = el.data('_gridstack_node');
|
||||
if (node._grid !== self) {
|
||||
|
@ -772,16 +811,18 @@
|
|||
}
|
||||
};
|
||||
|
||||
$(self.container).droppable({
|
||||
accept: function(el) {
|
||||
el = $(el);
|
||||
var node = el.data('_gridstack_node');
|
||||
if (node && node._grid === self) {
|
||||
return false;
|
||||
this.dd
|
||||
.droppable(self.container, {
|
||||
accept: function(el) {
|
||||
el = $(el);
|
||||
var node = el.data('_gridstack_node');
|
||||
if (node && node._grid === self) {
|
||||
return false;
|
||||
}
|
||||
return el.is(self.opts.acceptWidgets === true ? '.grid-stack-item' : self.opts.acceptWidgets);
|
||||
}
|
||||
return el.is(self.opts.acceptWidgets === true ? '.grid-stack-item' : self.opts.acceptWidgets);
|
||||
},
|
||||
over: function(event, ui) {
|
||||
})
|
||||
.on(self.container, 'dropover', function(event, ui) {
|
||||
var offset = self.container.offset();
|
||||
var el = $(ui.draggable);
|
||||
var cellWidth = self.cellWidth();
|
||||
|
@ -798,8 +839,8 @@
|
|||
el.data('_gridstack_node_orig', origNode);
|
||||
|
||||
el.on('drag', onDrag);
|
||||
},
|
||||
out: function(event, ui) {
|
||||
})
|
||||
.on(self.container, 'dropout', function(event, ui) {
|
||||
var el = $(ui.draggable);
|
||||
el.unbind('drag', onDrag);
|
||||
var node = el.data('_gridstack_node');
|
||||
|
@ -808,8 +849,8 @@
|
|||
self.placeholder.detach();
|
||||
self._updateContainerHeight();
|
||||
el.data('_gridstack_node', el.data('_gridstack_node_orig'));
|
||||
},
|
||||
drop: function(event, ui) {
|
||||
})
|
||||
.on(self.container, 'drop', function(event, ui) {
|
||||
self.placeholder.detach();
|
||||
|
||||
var node = $(ui.draggable).data('_gridstack_node');
|
||||
|
@ -836,8 +877,7 @@
|
|||
self._triggerChangeEvent();
|
||||
|
||||
self.grid.endUpdate();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1081,8 +1121,8 @@
|
|||
node._beforeDragX = node.x;
|
||||
node._beforeDragY = node.y;
|
||||
|
||||
el.resizable('option', 'minWidth', cellWidth * (node.minWidth || 1));
|
||||
el.resizable('option', 'minHeight', strictCellHeight * (node.minHeight || 1));
|
||||
self.dd.resizable(el, 'option', 'minWidth', cellWidth * (node.minWidth || 1));
|
||||
self.dd.resizable(el, 'option', 'minHeight', strictCellHeight * (node.minHeight || 1));
|
||||
|
||||
if (event.type == 'resizestart') {
|
||||
o.find('.grid-stack-item').trigger('resizestart');
|
||||
|
@ -1139,25 +1179,24 @@
|
|||
}
|
||||
};
|
||||
|
||||
el
|
||||
.draggable(_.extend({}, this.opts.draggable, {
|
||||
containment: this.opts.isNested ? this.container.parent() : null,
|
||||
this.dd
|
||||
.draggable(el, {
|
||||
start: onStartMoving,
|
||||
stop: onEndMoving,
|
||||
drag: dragOrResize
|
||||
}))
|
||||
.resizable(_.extend({}, this.opts.resizable, {
|
||||
})
|
||||
.resizable(el, {
|
||||
start: onStartMoving,
|
||||
stop: onEndMoving,
|
||||
resize: dragOrResize
|
||||
}));
|
||||
});
|
||||
|
||||
if (node.noMove || this._isOneColumnMode() || this.opts.disableDrag) {
|
||||
el.draggable('disable');
|
||||
this.dd.draggable(el, 'disable');
|
||||
}
|
||||
|
||||
if (node.noResize || this._isOneColumnMode() || this.opts.disableResize) {
|
||||
el.resizable('disable');
|
||||
this.dd.resizable(el, 'disable');
|
||||
}
|
||||
|
||||
el.attr('data-gs-locked', node.locked ? 'yes' : null);
|
||||
|
@ -1291,9 +1330,9 @@
|
|||
|
||||
node.noResize = !(val || false);
|
||||
if (node.noResize || self._isOneColumnMode()) {
|
||||
el.resizable('disable');
|
||||
self.dd.resizable(el, 'disable');
|
||||
} else {
|
||||
el.resizable('enable');
|
||||
self.dd.resizable(el, 'enable');
|
||||
}
|
||||
});
|
||||
return this;
|
||||
|
@ -1311,10 +1350,10 @@
|
|||
|
||||
node.noMove = !(val || false);
|
||||
if (node.noMove || self._isOneColumnMode()) {
|
||||
el.draggable('disable');
|
||||
self.dd.draggable(el, 'disable');
|
||||
el.removeClass('ui-draggable-handle');
|
||||
} else {
|
||||
el.draggable('enable');
|
||||
self.dd.draggable(el, 'enable');
|
||||
el.addClass('ui-draggable-handle');
|
||||
}
|
||||
});
|
||||
|
@ -1670,6 +1709,7 @@
|
|||
|
||||
scope.GridStackUI.Utils = Utils;
|
||||
scope.GridStackUI.Engine = GridStackEngine;
|
||||
scope.GridStackUI.GridStackDragDropPlugin = GridStackDragDropPlugin;
|
||||
|
||||
$.fn.gridstack = function(opts) {
|
||||
return this.each(function() {
|
||||
|
|
Loading…
Reference in a new issue