Path: blob/trunk/third_party/closure/goog/fx/dragdropgroup.js
2868 views
// Copyright 2006 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Multiple Element Drag and Drop.16*17* Drag and drop implementation for sources/targets consisting of multiple18* elements.19*20* @author [email protected] (Emil A Eklund)21* @see ../demos/dragdrop.html22*/2324goog.provide('goog.fx.DragDropGroup');2526goog.require('goog.dom');27goog.require('goog.fx.AbstractDragDrop');28goog.require('goog.fx.DragDropItem');29303132/**33* Drag/drop implementation for creating drag sources/drop targets consisting of34* multiple HTML Elements (items). All items share the same drop target(s) but35* can be dragged individually.36*37* @extends {goog.fx.AbstractDragDrop}38* @constructor39* @struct40*/41goog.fx.DragDropGroup = function() {42goog.fx.AbstractDragDrop.call(this);43};44goog.inherits(goog.fx.DragDropGroup, goog.fx.AbstractDragDrop);454647/**48* Add item to drag object.49*50* @param {Element|string} element Dom Node, or string representation of node51* id, to be used as drag source/drop target.52* @param {Object=} opt_data Data associated with the source/target.53* @throws Error If no element argument is provided or if the type is54* invalid55* @override56*/57goog.fx.DragDropGroup.prototype.addItem = function(element, opt_data) {58var item = new goog.fx.DragDropItem(element, opt_data);59this.addDragDropItem(item);60};616263/**64* Add DragDropItem to drag object.65*66* @param {goog.fx.DragDropItem} item DragDropItem being added to the67* drag object.68* @throws Error If no element argument is provided or if the type is69* invalid70*/71goog.fx.DragDropGroup.prototype.addDragDropItem = function(item) {72item.setParent(this);73this.items_.push(item);74if (this.isInitialized()) {75this.initItem(item);76}77};787980/**81* Remove item from drag object.82*83* @param {Element|string} element Dom Node, or string representation of node84* id, that was previously added with addItem().85*/86goog.fx.DragDropGroup.prototype.removeItem = function(element) {87element = goog.dom.getElement(element);88for (var item, i = 0; item = this.items_[i]; i++) {89if (item.element == element) {90this.items_.splice(i, 1);91this.disposeItem(item);92break;93}94}95};969798/**99* Marks the supplied list of items as selected. A drag operation for any of the100* selected items will affect all of them.101*102* @param {Array<goog.fx.DragDropItem>} list List of items to select or null to103* clear selection.104*105* TODO(eae): Not yet implemented.106*/107goog.fx.DragDropGroup.prototype.setSelection = function(list) {108109};110111112