gridstack.jQueryUI.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * gridstack.js 1.0.0-dev
  3. * http://troolee.github.io/gridstack.js/
  4. * (c) 2014-2017 Pavel Reznikov, Dylan Weiss
  5. * gridstack.js may be freely distributed under the MIT license.
  6. * @preserve
  7. */
  8. (function(factory) {
  9. if (typeof define === 'function' && define.amd) {
  10. define(['jquery', 'lodash', 'gridstack', 'jquery-ui/data', 'jquery-ui/disable-selection', 'jquery-ui/focusable',
  11. 'jquery-ui/form', 'jquery-ui/ie', 'jquery-ui/keycode', 'jquery-ui/labels', 'jquery-ui/jquery-1-7',
  12. 'jquery-ui/plugin', 'jquery-ui/safe-active-element', 'jquery-ui/safe-blur', 'jquery-ui/scroll-parent',
  13. 'jquery-ui/tabbable', 'jquery-ui/unique-id', 'jquery-ui/version', 'jquery-ui/widget',
  14. 'jquery-ui/widgets/mouse', 'jquery-ui/widgets/draggable', 'jquery-ui/widgets/droppable',
  15. 'jquery-ui/widgets/resizable'], factory);
  16. } else if (typeof exports !== 'undefined') {
  17. try { jQuery = require('jquery'); } catch (e) {}
  18. try { _ = require('lodash'); } catch (e) {}
  19. try { GridStackUI = require('gridstack'); } catch (e) {}
  20. factory(jQuery, _, GridStackUI);
  21. } else {
  22. factory(jQuery, _, GridStackUI);
  23. }
  24. })(function($, _, GridStackUI) {
  25. var scope = window;
  26. /**
  27. * @class JQueryUIGridStackDragDropPlugin
  28. * jQuery UI implementation of drag'n'drop gridstack plugin.
  29. */
  30. function JQueryUIGridStackDragDropPlugin(grid) {
  31. GridStackUI.GridStackDragDropPlugin.call(this, grid);
  32. }
  33. GridStackUI.GridStackDragDropPlugin.registerPlugin(JQueryUIGridStackDragDropPlugin);
  34. JQueryUIGridStackDragDropPlugin.prototype = Object.create(GridStackUI.GridStackDragDropPlugin.prototype);
  35. JQueryUIGridStackDragDropPlugin.prototype.constructor = JQueryUIGridStackDragDropPlugin;
  36. JQueryUIGridStackDragDropPlugin.prototype.resizable = function(el, opts) {
  37. el = $(el);
  38. if (opts === 'disable' || opts === 'enable') {
  39. el.resizable(opts);
  40. } else if (opts === 'option') {
  41. var key = arguments[2];
  42. var value = arguments[3];
  43. el.resizable(opts, key, value);
  44. } else {
  45. var handles = el.data('gs-resize-handles') ? el.data('gs-resize-handles') :
  46. this.grid.opts.resizable.handles;
  47. el.resizable(_.extend({}, this.grid.opts.resizable, {
  48. handles: handles
  49. }, {
  50. start: opts.start || function() {},
  51. stop: opts.stop || function() {},
  52. resize: opts.resize || function() {}
  53. }));
  54. }
  55. return this;
  56. };
  57. JQueryUIGridStackDragDropPlugin.prototype.draggable = function(el, opts) {
  58. el = $(el);
  59. if (opts === 'disable' || opts === 'enable') {
  60. el.draggable(opts);
  61. } else {
  62. el.draggable(_.extend({}, this.grid.opts.draggable, {
  63. containment: this.grid.opts.isNested ? this.grid.container.parent() : null,
  64. start: opts.start || function() {},
  65. stop: opts.stop || function() {},
  66. drag: opts.drag || function() {}
  67. }));
  68. }
  69. return this;
  70. };
  71. JQueryUIGridStackDragDropPlugin.prototype.droppable = function(el, opts) {
  72. el = $(el);
  73. el.droppable(opts);
  74. return this;
  75. };
  76. JQueryUIGridStackDragDropPlugin.prototype.isDroppable = function(el, opts) {
  77. el = $(el);
  78. return Boolean(el.data('droppable'));
  79. };
  80. JQueryUIGridStackDragDropPlugin.prototype.on = function(el, eventName, callback) {
  81. $(el).on(eventName, callback);
  82. return this;
  83. };
  84. return JQueryUIGridStackDragDropPlugin;
  85. });