dragdropgroup.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2006 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Multiple Element Drag and Drop.
  16. *
  17. * Drag and drop implementation for sources/targets consisting of multiple
  18. * elements.
  19. *
  20. * @author eae@google.com (Emil A Eklund)
  21. * @see ../demos/dragdrop.html
  22. */
  23. goog.provide('goog.fx.DragDropGroup');
  24. goog.require('goog.dom');
  25. goog.require('goog.fx.AbstractDragDrop');
  26. goog.require('goog.fx.DragDropItem');
  27. /**
  28. * Drag/drop implementation for creating drag sources/drop targets consisting of
  29. * multiple HTML Elements (items). All items share the same drop target(s) but
  30. * can be dragged individually.
  31. *
  32. * @extends {goog.fx.AbstractDragDrop}
  33. * @constructor
  34. * @struct
  35. */
  36. goog.fx.DragDropGroup = function() {
  37. goog.fx.AbstractDragDrop.call(this);
  38. };
  39. goog.inherits(goog.fx.DragDropGroup, goog.fx.AbstractDragDrop);
  40. /**
  41. * Add item to drag object.
  42. *
  43. * @param {Element|string} element Dom Node, or string representation of node
  44. * id, to be used as drag source/drop target.
  45. * @param {Object=} opt_data Data associated with the source/target.
  46. * @throws Error If no element argument is provided or if the type is
  47. * invalid
  48. * @override
  49. */
  50. goog.fx.DragDropGroup.prototype.addItem = function(element, opt_data) {
  51. var item = new goog.fx.DragDropItem(element, opt_data);
  52. this.addDragDropItem(item);
  53. };
  54. /**
  55. * Add DragDropItem to drag object.
  56. *
  57. * @param {goog.fx.DragDropItem} item DragDropItem being added to the
  58. * drag object.
  59. * @throws Error If no element argument is provided or if the type is
  60. * invalid
  61. */
  62. goog.fx.DragDropGroup.prototype.addDragDropItem = function(item) {
  63. item.setParent(this);
  64. this.items_.push(item);
  65. if (this.isInitialized()) {
  66. this.initItem(item);
  67. }
  68. };
  69. /**
  70. * Remove item from drag object.
  71. *
  72. * @param {Element|string} element Dom Node, or string representation of node
  73. * id, that was previously added with addItem().
  74. */
  75. goog.fx.DragDropGroup.prototype.removeItem = function(element) {
  76. element = goog.dom.getElement(element);
  77. for (var item, i = 0; item = this.items_[i]; i++) {
  78. if (item.element == element) {
  79. this.items_.splice(i, 1);
  80. this.disposeItem(item);
  81. break;
  82. }
  83. }
  84. };
  85. /**
  86. * Marks the supplied list of items as selected. A drag operation for any of the
  87. * selected items will affect all of them.
  88. *
  89. * @param {Array<goog.fx.DragDropItem>} list List of items to select or null to
  90. * clear selection.
  91. *
  92. * TODO(eae): Not yet implemented.
  93. */
  94. goog.fx.DragDropGroup.prototype.setSelection = function(list) {
  95. };