X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/6a7e4474cba9d8be4b2ec445e10f1691f7277c50..HEAD:/examples/ux/ToolbarDroppable.js diff --git a/examples/ux/ToolbarDroppable.js b/examples/ux/ToolbarDroppable.js index c9ba8559..65da45b1 100644 --- a/examples/ux/ToolbarDroppable.js +++ b/examples/ux/ToolbarDroppable.js @@ -1,9 +1,17 @@ -/*! - * Ext JS Library 3.2.0 - * Copyright(c) 2006-2010 Ext JS, Inc. - * licensing@extjs.com - * http://www.extjs.com/license - */ +/* + +This file is part of Ext JS 4 + +Copyright (c) 2011 Sencha Inc + +Contact: http://www.sencha.com/contact + +GNU General Public License Usage +This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. + +If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact. + +*/ /** * @class Ext.ux.ToolbarDroppable * @extends Object @@ -11,44 +19,44 @@ * To use the plugin, you just need to provide a createItem implementation that takes the drop * data as an argument and returns an object that can be placed onto the toolbar. Example: *
- * new Ext.ux.ToolbarDroppable({ + * Ext.create('Ext.ux.ToolbarDroppable', { * createItem: function(data) { - * return new Ext.Button({text: data.text}); + * return Ext.create('Ext.Button', {text: data.text}); * } * }); *- * The afterLayout function can also be overridden, and is called after a new item has been + * The afterLayout function can also be overridden, and is called after a new item has been * created and inserted into the Toolbar. Use this for any logic that needs to be run after * the item has been created. */ -Ext.ux.ToolbarDroppable = Ext.extend(Object, { + Ext.define('Ext.ux.ToolbarDroppable', { + extend: 'Object', + /** * @constructor */ constructor: function(config) { - Ext.apply(this, config, { - - }); + Ext.apply(this, config); }, - + /** * Initializes the plugin and saves a reference to the toolbar - * @param {Ext.Toolbar} toolbar The toolbar instance + * @param {Ext.toolbar.Toolbar} toolbar The toolbar instance */ init: function(toolbar) { /** * @property toolbar - * @type Ext.Toolbar + * @type Ext.toolbar.Toolbar * The toolbar instance that this plugin is tied to */ this.toolbar = toolbar; - + this.toolbar.on({ scope : this, render: this.createDropTarget }); }, - + /** * Creates a drop target on the toolbar */ @@ -58,12 +66,12 @@ Ext.ux.ToolbarDroppable = Ext.extend(Object, { * @type Ext.dd.DropTarget * The drop target attached to the toolbar instance */ - this.dropTarget = new Ext.dd.DropTarget(this.toolbar.getEl(), { - notifyOver: this.notifyOver.createDelegate(this), - notifyDrop: this.notifyDrop.createDelegate(this) + this.dropTarget = Ext.create('Ext.dd.DropTarget', this.toolbar.getEl(), { + notifyOver: Ext.Function.bind(this.notifyOver, this), + notifyDrop: Ext.Function.bind(this.notifyDrop, this) }); }, - + /** * Adds the given DD Group to the drop target * @param {String} ddGroup The DD Group @@ -71,7 +79,7 @@ Ext.ux.ToolbarDroppable = Ext.extend(Object, { addDDGroup: function(ddGroup) { this.dropTarget.addToGroup(ddGroup); }, - + /** * Calculates the location on the toolbar to create the new sorter button based on the XY of the * drag event @@ -85,26 +93,26 @@ Ext.ux.ToolbarDroppable = Ext.extend(Object, { count = items.length, xTotal = toolbar.getEl().getXY()[0], xHover = e.getXY()[0] - xTotal; - + for (var index = 0; index < count; index++) { var item = items[index], width = item.getEl().getWidth(), midpoint = xTotal + width / 2; - + xTotal += width; - + if (xHover < midpoint) { - entryIndex = index; + entryIndex = index; break; } else { entryIndex = index + 1; } } - + return entryIndex; }, - + /** * Returns true if the drop is allowed on the drop target. This function can be overridden * and defaults to simply return true @@ -114,7 +122,7 @@ Ext.ux.ToolbarDroppable = Ext.extend(Object, { canDrop: function(data) { return true; }, - + /** * Custom notifyOver method which will be used in the plugin's internal DropTarget * @return {String} The CSS class to add @@ -122,7 +130,7 @@ Ext.ux.ToolbarDroppable = Ext.extend(Object, { notifyOver: function(dragSource, event, data) { return this.canDrop.apply(this, arguments) ? this.dropTarget.dropAllowed : this.dropTarget.dropNotAllowed; }, - + /** * Called when the drop has been made. Creates the new toolbar item, places it at the correct location * and calls the afterLayout callback. @@ -130,30 +138,33 @@ Ext.ux.ToolbarDroppable = Ext.extend(Object, { notifyDrop: function(dragSource, event, data) { var canAdd = this.canDrop(dragSource, event, data), tbar = this.toolbar; - + if (canAdd) { var entryIndex = this.calculateEntryIndex(event); - + tbar.insert(entryIndex, this.createItem(data)); tbar.doLayout(); - + this.afterLayout(); } - + return canAdd; }, - + /** * Creates the new toolbar item based on drop data. This method must be implemented by the plugin instance * @param {Object} data Arbitrary data from the drop * @return {Mixed} An item that can be added to a toolbar */ createItem: function(data) { - throw new Error("The createItem method must be implemented in the ToolbarDroppable plugin"); + //