gridstack.jQueryUI.js 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. el.resizable(_.extend({}, this.grid.opts.resizable, {
  46. start: opts.start || function() {},
  47. stop: opts.stop || function() {},
  48. resize: opts.resize || function() {}
  49. }));
  50. }
  51. return this;
  52. };
  53. JQueryUIGridStackDragDropPlugin.prototype.draggable = function(el, opts) {
  54. el = $(el);
  55. if (opts === 'disable' || opts === 'enable') {
  56. el.draggable(opts);
  57. } else {
  58. el.draggable(_.extend({}, this.grid.opts.draggable, {
  59. containment: this.grid.opts.isNested ? this.grid.container.parent() : null,
  60. start: opts.start || function() {},
  61. stop: opts.stop || function() {},
  62. drag: opts.drag || function() {}
  63. }));
  64. }
  65. return this;
  66. };
  67. JQueryUIGridStackDragDropPlugin.prototype.droppable = function(el, opts) {
  68. el = $(el);
  69. if (opts === 'disable' || opts === 'enable') {
  70. el.droppable(opts);
  71. } else {
  72. el.droppable({
  73. accept: opts.accept
  74. });
  75. }
  76. return this;
  77. };
  78. JQueryUIGridStackDragDropPlugin.prototype.isDroppable = function(el, opts) {
  79. el = $(el);
  80. return Boolean(el.data('droppable'));
  81. };
  82. JQueryUIGridStackDragDropPlugin.prototype.on = function(el, eventName, callback) {
  83. $(el).on(eventName, callback);
  84. return this;
  85. };
  86. return JQueryUIGridStackDragDropPlugin;
  87. });