diff --git a/src/gridstack.jQueryUI.js b/src/gridstack.jQueryUI.js new file mode 100644 index 0000000..1ae8575 --- /dev/null +++ b/src/gridstack.jQueryUI.js @@ -0,0 +1,97 @@ +/** + * gridstack.js 0.2.7-dev + * http://troolee.github.io/gridstack.js/ + * (c) 2014-2016 Pavel Reznikov + * 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); + } 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; +}); diff --git a/src/gridstack.js b/src/gridstack.js index ce6e032..03c4d90 100644 --- a/src/gridstack.js +++ b/src/gridstack.js @@ -158,69 +158,6 @@ return this; }; - /** - * @class JQueryUIGridStackDragDropPlugin - * jQuery UI implementation of drag'n'drop gridstack plugin. - */ - function JQueryUIGridStackDragDropPlugin(grid) { - GridStackDragDropPlugin.call(this, grid); - } - - GridStackDragDropPlugin.registerPlugin(JQueryUIGridStackDragDropPlugin); - - JQueryUIGridStackDragDropPlugin.prototype = Object.create(GridStackDragDropPlugin.prototype); - JQueryUIGridStackDragDropPlugin.prototype.constructor = JQueryUIGridStackDragDropPlugin; - - JQueryUIGridStackDragDropPlugin.prototype.resizable = function(el, opts) { - el = $(el); - if (opts === 'disable' || opts === 'enable') { - el.resizable(opts); - } 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; - }; var idSeq = 0; @@ -676,7 +613,7 @@ if (this.opts.ddPlugin === false) { this.opts.ddPlugin = GridStackDragDropPlugin; } else if (this.opts.ddPlugin === null) { - this.opts.ddPlugin = _.first(GridStackDragDropPlugin.registeredPlugins); + this.opts.ddPlugin = _.first(GridStackDragDropPlugin.registeredPlugins) || GridStackDragDropPlugin; } this.dd = new this.opts.ddPlugin(this);