2010-06-16 17:19:11 -07:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is items.js.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
2010-08-11 15:28:45 -07:00
|
|
|
* the Mozilla Foundation.
|
2010-06-16 17:19:11 -07:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2010-08-11 15:28:45 -07:00
|
|
|
* Ian Gilman <ian@iangilman.com>
|
2010-06-16 17:19:11 -07:00
|
|
|
* Aza Raskin <aza@mozilla.com>
|
|
|
|
* Michael Yoshitaka Erlewine <mitcho@mitcho.com>
|
2010-09-26 23:25:00 -07:00
|
|
|
* Sean Dunn <seanedunn@yahoo.com>
|
2011-01-21 15:15:22 -08:00
|
|
|
* Tim Taubert <tim.taubert@gmx.de>
|
2010-06-16 17:19:11 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
// **********
|
2010-07-18 08:58:10 -07:00
|
|
|
// Title: items.js
|
2010-04-30 17:24:03 -07:00
|
|
|
|
2010-03-29 16:08:48 -07:00
|
|
|
// ##########
|
2010-04-30 17:24:03 -07:00
|
|
|
// Class: Item
|
2010-08-06 15:46:55 -07:00
|
|
|
// Superclass for all visible objects (<TabItem>s and <GroupItem>s).
|
2010-05-13 17:24:37 -07:00
|
|
|
//
|
2010-07-18 08:58:10 -07:00
|
|
|
// If you subclass, in addition to the things Item provides, you need to also provide these methods:
|
2010-09-26 23:25:00 -07:00
|
|
|
// setBounds - function(rect, immediately, options)
|
2010-05-13 17:24:37 -07:00
|
|
|
// setZ - function(value)
|
2010-07-18 08:58:10 -07:00
|
|
|
// close - function()
|
2010-05-24 14:49:03 -07:00
|
|
|
// save - function()
|
2010-05-13 17:24:37 -07:00
|
|
|
//
|
2010-07-27 20:02:51 -07:00
|
|
|
// Subclasses of Item must also provide the <Subscribable> interface.
|
|
|
|
//
|
2010-07-18 08:58:10 -07:00
|
|
|
// ... and this property:
|
2010-05-13 17:24:37 -07:00
|
|
|
// defaultSize - a Point
|
|
|
|
//
|
2010-07-18 08:58:10 -07:00
|
|
|
// Make sure to call _init() from your subclass's constructor.
|
2010-09-08 10:02:08 -07:00
|
|
|
function Item() {
|
2010-04-08 16:36:11 -07:00
|
|
|
// Variable: isAnItem
|
|
|
|
// Always true for Items
|
2010-03-29 16:08:48 -07:00
|
|
|
this.isAnItem = true;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-04-08 16:36:11 -07:00
|
|
|
// Variable: bounds
|
2010-07-18 08:58:10 -07:00
|
|
|
// The position and size of this Item, represented as a <Rect>.
|
2010-09-26 23:25:00 -07:00
|
|
|
// This should never be modified without using setBounds()
|
2010-04-01 17:20:59 -07:00
|
|
|
this.bounds = null;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-07 14:12:04 -07:00
|
|
|
// Variable: zIndex
|
2010-07-18 08:58:10 -07:00
|
|
|
// The z-index for this item.
|
2010-07-07 14:12:04 -07:00
|
|
|
this.zIndex = 0;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-04-08 16:36:11 -07:00
|
|
|
// Variable: container
|
|
|
|
// The outermost DOM element that describes this item on screen.
|
2010-04-01 17:20:59 -07:00
|
|
|
this.container = null;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-04-26 13:37:39 -07:00
|
|
|
// Variable: parent
|
2010-08-06 15:46:55 -07:00
|
|
|
// The groupItem that this item is a child of
|
2010-04-26 13:37:39 -07:00
|
|
|
this.parent = null;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-04-26 16:48:46 -07:00
|
|
|
// Variable: userSize
|
|
|
|
// A <Point> that describes the last size specifically chosen by the user.
|
|
|
|
// Used by unsquish.
|
|
|
|
this.userSize = null;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-16 16:30:48 -07:00
|
|
|
// Variable: dragOptions
|
2010-06-22 16:42:06 -07:00
|
|
|
// Used by <draggable>
|
2010-07-18 08:58:10 -07:00
|
|
|
//
|
2010-06-22 16:42:06 -07:00
|
|
|
// Possible properties:
|
|
|
|
// cancelClass - A space-delimited list of classes that should cancel a drag
|
|
|
|
// start - A function to be called when a drag starts
|
|
|
|
// drag - A function to be called each time the mouse moves during drag
|
|
|
|
// stop - A function to be called when the drag is done
|
2010-06-16 16:30:48 -07:00
|
|
|
this.dragOptions = null;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-16 16:30:48 -07:00
|
|
|
// Variable: dropOptions
|
2010-06-22 16:42:06 -07:00
|
|
|
// Used by <draggable> if the item is set to droppable.
|
2010-07-18 08:58:10 -07:00
|
|
|
//
|
2010-06-22 16:42:06 -07:00
|
|
|
// Possible properties:
|
2010-07-18 08:58:10 -07:00
|
|
|
// accept - A function to determine if a particular item should be accepted for dropping
|
2010-06-22 16:42:06 -07:00
|
|
|
// over - A function to be called when an item is over this item
|
|
|
|
// out - A function to be called when an item leaves this item
|
2010-07-18 08:58:10 -07:00
|
|
|
// drop - A function to be called when an item is dropped in this item
|
2010-06-16 16:30:48 -07:00
|
|
|
this.dropOptions = null;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-19 17:45:23 -07:00
|
|
|
// Variable: resizeOptions
|
2010-06-22 16:42:06 -07:00
|
|
|
// Used by <resizable>
|
2010-07-18 08:58:10 -07:00
|
|
|
//
|
2010-06-22 16:42:06 -07:00
|
|
|
// Possible properties:
|
2010-07-18 08:58:10 -07:00
|
|
|
// minWidth - Minimum width allowable during resize
|
2010-06-22 16:42:06 -07:00
|
|
|
// minHeight - Minimum height allowable during resize
|
|
|
|
// aspectRatio - true if we should respect aspect ratio; default false
|
|
|
|
// start - A function to be called when resizing starts
|
|
|
|
// resize - A function to be called each time the mouse moves during resize
|
|
|
|
// stop - A function to be called when the resize is done
|
2010-06-19 17:45:23 -07:00
|
|
|
this.resizeOptions = null;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-19 11:56:07 -07:00
|
|
|
// Variable: isDragging
|
|
|
|
// Boolean for whether the item is currently being dragged or not.
|
|
|
|
this.isDragging = false;
|
2010-03-29 16:08:48 -07:00
|
|
|
};
|
|
|
|
|
2010-09-08 10:02:08 -07:00
|
|
|
Item.prototype = {
|
2010-07-18 08:58:10 -07:00
|
|
|
// ----------
|
2010-04-08 16:36:11 -07:00
|
|
|
// Function: _init
|
2010-07-18 08:58:10 -07:00
|
|
|
// Initializes the object. To be called from the subclass's intialization function.
|
2010-04-08 16:36:11 -07:00
|
|
|
//
|
2010-07-18 08:58:10 -07:00
|
|
|
// Parameters:
|
|
|
|
// container - the outermost DOM element that describes this item onscreen.
|
2010-09-08 10:02:08 -07:00
|
|
|
_init: function Item__init(container) {
|
2010-08-10 16:20:05 -07:00
|
|
|
Utils.assert(typeof this.addSubscriber == 'function' &&
|
|
|
|
typeof this.removeSubscriber == 'function' &&
|
|
|
|
typeof this._sendToSubscribers == 'function',
|
2010-08-10 11:13:10 -07:00
|
|
|
'Subclass must implement the Subscribable interface');
|
|
|
|
Utils.assert(Utils.isDOMElement(container), 'container must be a DOM element');
|
2010-08-10 16:20:05 -07:00
|
|
|
Utils.assert(typeof this.setBounds == 'function', 'Subclass must provide setBounds');
|
|
|
|
Utils.assert(typeof this.setZ == 'function', 'Subclass must provide setZ');
|
|
|
|
Utils.assert(typeof this.close == 'function', 'Subclass must provide close');
|
|
|
|
Utils.assert(typeof this.save == 'function', 'Subclass must provide save');
|
2010-08-10 11:13:10 -07:00
|
|
|
Utils.assert(Utils.isPoint(this.defaultSize), 'Subclass must provide defaultSize');
|
|
|
|
Utils.assert(Utils.isRect(this.bounds), 'Subclass must provide bounds');
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-04-01 17:20:59 -07:00
|
|
|
this.container = container;
|
2010-11-05 06:32:00 -07:00
|
|
|
this.$container = iQ(container);
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-05-27 17:25:14 -07:00
|
|
|
iQ(this.container).data('item', this);
|
2010-06-16 16:30:48 -07:00
|
|
|
|
|
|
|
// ___ drag
|
|
|
|
this.dragOptions = {
|
2010-06-21 17:27:12 -07:00
|
|
|
cancelClass: 'close stackExpander',
|
2010-06-16 16:30:48 -07:00
|
|
|
start: function(e, ui) {
|
2011-06-10 02:40:20 -07:00
|
|
|
UI.setActive(this);
|
|
|
|
if (this.isAGroupItem)
|
2011-01-21 15:15:22 -08:00
|
|
|
this._unfreezeItemSize();
|
2011-01-12 13:48:42 -08:00
|
|
|
// if we start dragging a tab within a group, start with dropSpace on.
|
|
|
|
else if (this.parent != null)
|
|
|
|
this.parent._dropSpaceActive = true;
|
2010-06-16 16:30:48 -07:00
|
|
|
drag.info = new Drag(this, e);
|
|
|
|
},
|
2010-08-10 14:23:53 -07:00
|
|
|
drag: function(e) {
|
|
|
|
drag.info.drag(e);
|
2010-06-16 16:30:48 -07:00
|
|
|
},
|
|
|
|
stop: function() {
|
|
|
|
drag.info.stop();
|
2011-07-04 15:23:35 -07:00
|
|
|
|
|
|
|
if (!this.isAGroupItem && !this.parent) {
|
|
|
|
new GroupItem([drag.info.$el], {focusTitle: true});
|
2011-02-16 08:06:54 -08:00
|
|
|
gTabView.firstUseExperienced = true;
|
2011-07-04 15:23:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
drag.info = null;
|
2010-09-21 10:22:07 -07:00
|
|
|
},
|
|
|
|
// The minimum the mouse must move after mouseDown in order to move an
|
|
|
|
// item
|
|
|
|
minDragDistance: 3
|
2010-06-16 16:30:48 -07:00
|
|
|
};
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-16 16:30:48 -07:00
|
|
|
// ___ drop
|
|
|
|
this.dropOptions = {
|
2010-07-30 02:54:30 -07:00
|
|
|
over: function() {},
|
|
|
|
out: function() {
|
2010-12-15 19:43:25 -08:00
|
|
|
let groupItem = drag.info.item.parent;
|
2010-08-06 15:46:55 -07:00
|
|
|
if (groupItem)
|
2011-07-03 17:11:40 -07:00
|
|
|
groupItem.remove(drag.info.$el, {dontClose: true});
|
2010-07-03 18:13:31 -07:00
|
|
|
iQ(this.container).removeClass("acceptsDrop");
|
|
|
|
},
|
2010-07-30 02:54:30 -07:00
|
|
|
drop: function(event) {
|
2010-07-03 18:13:31 -07:00
|
|
|
iQ(this.container).removeClass("acceptsDrop");
|
|
|
|
},
|
|
|
|
// Function: dropAcceptFunction
|
|
|
|
// Given a DOM element, returns true if it should accept tabs being dropped on it.
|
|
|
|
// Private to this file.
|
|
|
|
accept: function dropAcceptFunction(item) {
|
|
|
|
return (item && item.isATabItem && (!item.parent || !item.parent.expanded));
|
|
|
|
}
|
|
|
|
};
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-03 18:13:31 -07:00
|
|
|
// ___ resize
|
|
|
|
var self = this;
|
2010-06-19 17:45:23 -07:00
|
|
|
this.resizeOptions = {
|
|
|
|
aspectRatio: self.keepProportional,
|
|
|
|
minWidth: 90,
|
|
|
|
minHeight: 90,
|
2010-07-30 02:54:30 -07:00
|
|
|
start: function(e,ui) {
|
2011-06-10 02:40:20 -07:00
|
|
|
UI.setActive(this);
|
2010-11-24 13:19:47 -08:00
|
|
|
resize.info = new Drag(this, e);
|
2010-06-19 17:45:23 -07:00
|
|
|
},
|
2010-07-30 02:54:30 -07:00
|
|
|
resize: function(e,ui) {
|
2010-09-09 22:29:00 -07:00
|
|
|
resize.info.snap(UI.rtl ? 'topright' : 'topleft', false, self.keepProportional);
|
2010-06-19 17:45:23 -07:00
|
|
|
},
|
2010-07-30 02:54:30 -07:00
|
|
|
stop: function() {
|
2010-06-19 17:45:23 -07:00
|
|
|
self.setUserSize();
|
|
|
|
self.pushAway();
|
2010-09-09 22:29:00 -07:00
|
|
|
resize.info.stop();
|
|
|
|
resize.info = null;
|
2010-07-18 08:58:10 -07:00
|
|
|
}
|
2010-06-19 17:45:23 -07:00
|
|
|
};
|
2010-04-01 17:20:59 -07:00
|
|
|
},
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-04-01 17:20:59 -07:00
|
|
|
// ----------
|
2010-04-08 16:36:11 -07:00
|
|
|
// Function: getBounds
|
|
|
|
// Returns a copy of the Item's bounds as a <Rect>.
|
2010-09-08 10:02:08 -07:00
|
|
|
getBounds: function Item_getBounds() {
|
2010-09-26 23:25:00 -07:00
|
|
|
Utils.assert(Utils.isRect(this.bounds), 'this.bounds should be a rect');
|
2010-07-18 08:58:10 -07:00
|
|
|
return new Rect(this.bounds);
|
2010-04-01 17:20:59 -07:00
|
|
|
},
|
2010-06-22 20:16:49 -07:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: overlapsWithOtherItems
|
|
|
|
// Returns true if this Item overlaps with any other Item on the screen.
|
2010-09-08 10:02:08 -07:00
|
|
|
overlapsWithOtherItems: function Item_overlapsWithOtherItems() {
|
2010-07-03 18:13:31 -07:00
|
|
|
var self = this;
|
|
|
|
var items = Items.getTopLevelItems();
|
|
|
|
var bounds = this.getBounds();
|
|
|
|
return items.some(function(item) {
|
|
|
|
if (item == self) // can't overlap with yourself.
|
|
|
|
return false;
|
|
|
|
var myBounds = item.getBounds();
|
|
|
|
return myBounds.intersects(bounds);
|
|
|
|
} );
|
2010-06-22 20:16:49 -07:00
|
|
|
},
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-04-01 17:20:59 -07:00
|
|
|
// ----------
|
2010-04-08 16:36:11 -07:00
|
|
|
// Function: setPosition
|
2010-07-18 08:58:10 -07:00
|
|
|
// Moves the Item to the specified location.
|
|
|
|
//
|
|
|
|
// Parameters:
|
2010-04-08 16:36:11 -07:00
|
|
|
// left - the new left coordinate relative to the window
|
|
|
|
// top - the new top coordinate relative to the window
|
|
|
|
// immediately - if false or omitted, animates to the new position;
|
|
|
|
// otherwise goes there immediately
|
2010-09-08 10:02:08 -07:00
|
|
|
setPosition: function Item_setPosition(left, top, immediately) {
|
2010-08-10 11:13:10 -07:00
|
|
|
Utils.assert(Utils.isRect(this.bounds), 'this.bounds');
|
2010-04-01 17:20:59 -07:00
|
|
|
this.setBounds(new Rect(left, top, this.bounds.width, this.bounds.height), immediately);
|
|
|
|
},
|
|
|
|
|
2010-07-18 08:58:10 -07:00
|
|
|
// ----------
|
2010-04-08 16:36:11 -07:00
|
|
|
// Function: setSize
|
2010-07-18 08:58:10 -07:00
|
|
|
// Resizes the Item to the specified size.
|
|
|
|
//
|
|
|
|
// Parameters:
|
2010-04-08 16:36:11 -07:00
|
|
|
// width - the new width in pixels
|
|
|
|
// height - the new height in pixels
|
|
|
|
// immediately - if false or omitted, animates to the new size;
|
|
|
|
// otherwise resizes immediately
|
2010-09-08 10:02:08 -07:00
|
|
|
setSize: function Item_setSize(width, height, immediately) {
|
2010-08-10 11:13:10 -07:00
|
|
|
Utils.assert(Utils.isRect(this.bounds), 'this.bounds');
|
2010-04-01 17:20:59 -07:00
|
|
|
this.setBounds(new Rect(this.bounds.left, this.bounds.top, width, height), immediately);
|
|
|
|
},
|
|
|
|
|
2010-04-26 16:48:46 -07:00
|
|
|
// ----------
|
|
|
|
// Function: setUserSize
|
2010-07-18 08:58:10 -07:00
|
|
|
// Remembers the current size as one the user has chosen.
|
2010-09-08 10:02:08 -07:00
|
|
|
setUserSize: function Item_setUserSize() {
|
2010-08-10 11:13:10 -07:00
|
|
|
Utils.assert(Utils.isRect(this.bounds), 'this.bounds');
|
2010-04-26 16:48:46 -07:00
|
|
|
this.userSize = new Point(this.bounds.width, this.bounds.height);
|
2010-05-24 14:49:03 -07:00
|
|
|
this.save();
|
2010-04-26 16:48:46 -07:00
|
|
|
},
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-04-02 17:33:06 -07:00
|
|
|
// ----------
|
2010-04-08 16:36:11 -07:00
|
|
|
// Function: getZ
|
|
|
|
// Returns the zIndex of the Item.
|
2010-09-08 10:02:08 -07:00
|
|
|
getZ: function Item_getZ() {
|
2010-07-07 14:12:04 -07:00
|
|
|
return this.zIndex;
|
2010-04-02 17:33:06 -07:00
|
|
|
},
|
2010-04-27 16:11:49 -07:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: setRotation
|
|
|
|
// Rotates the object to the given number of degrees.
|
2010-09-08 10:02:08 -07:00
|
|
|
setRotation: function Item_setRotation(degrees) {
|
2010-08-08 21:06:54 -07:00
|
|
|
var value = degrees ? "rotate(%deg)".replace(/%/, degrees) : null;
|
2010-05-27 17:25:14 -07:00
|
|
|
iQ(this.container).css({"-moz-transform": value});
|
2010-04-27 16:11:49 -07:00
|
|
|
},
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-05-24 14:49:03 -07:00
|
|
|
// ----------
|
|
|
|
// Function: setParent
|
2010-07-18 08:58:10 -07:00
|
|
|
// Sets the receiver's parent to the given <Item>.
|
2010-09-08 10:02:08 -07:00
|
|
|
setParent: function Item_setParent(parent) {
|
2010-05-24 14:49:03 -07:00
|
|
|
this.parent = parent;
|
2010-06-15 21:08:39 -07:00
|
|
|
this.removeTrenches();
|
2010-05-24 14:49:03 -07:00
|
|
|
this.save();
|
|
|
|
},
|
|
|
|
|
2010-07-18 08:58:10 -07:00
|
|
|
// ----------
|
2010-04-08 16:36:11 -07:00
|
|
|
// Function: pushAway
|
|
|
|
// Pushes all other items away so none overlap this Item.
|
2010-10-09 12:46:18 -07:00
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// immediately - boolean for doing the pushAway without animation
|
|
|
|
pushAway: function Item_pushAway(immediately) {
|
2011-08-02 22:38:07 -07:00
|
|
|
var items = Items.getTopLevelItems();
|
|
|
|
|
|
|
|
// we need at least two top-level items to push something away
|
|
|
|
if (items.length < 2)
|
|
|
|
return;
|
|
|
|
|
2010-07-30 02:54:30 -07:00
|
|
|
var buffer = Math.floor(Items.defaultGutter / 2);
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-03 18:13:31 -07:00
|
|
|
// setup each Item's pushAwayData attribute:
|
2010-07-13 16:38:51 -07:00
|
|
|
items.forEach(function pushAway_setupPushAwayData(item) {
|
2010-03-29 16:08:48 -07:00
|
|
|
var data = {};
|
|
|
|
data.bounds = item.getBounds();
|
|
|
|
data.startBounds = new Rect(data.bounds);
|
2010-07-03 18:13:31 -07:00
|
|
|
// Infinity = (as yet) unaffected
|
2010-03-29 16:08:48 -07:00
|
|
|
data.generation = Infinity;
|
|
|
|
item.pushAwayData = data;
|
|
|
|
});
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:50:37 -07:00
|
|
|
// The first item is a 0-generation pushed item. It all starts here.
|
2010-03-29 16:08:48 -07:00
|
|
|
var itemsToPush = [this];
|
|
|
|
this.pushAwayData.generation = 0;
|
|
|
|
|
2011-01-12 07:20:28 -08:00
|
|
|
var pushOne = function Item_pushAway_pushOne(baseItem) {
|
2010-07-03 18:13:31 -07:00
|
|
|
// the baseItem is an n-generation pushed item. (n could be 0)
|
2010-03-29 16:08:48 -07:00
|
|
|
var baseData = baseItem.pushAwayData;
|
|
|
|
var bb = new Rect(baseData.bounds);
|
2010-06-22 16:50:37 -07:00
|
|
|
|
2010-07-03 18:13:31 -07:00
|
|
|
// make the bounds larger, adding a +buffer margin to each side.
|
2010-03-29 16:08:48 -07:00
|
|
|
bb.inset(-buffer, -buffer);
|
2010-07-03 18:13:31 -07:00
|
|
|
// bbc = center of the base's bounds
|
2010-03-29 16:08:48 -07:00
|
|
|
var bbc = bb.center();
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2011-01-12 07:20:28 -08:00
|
|
|
items.forEach(function Item_pushAway_pushOne_pushEach(item) {
|
2011-01-27 23:07:30 -08:00
|
|
|
if (item == baseItem)
|
2010-03-29 16:08:48 -07:00
|
|
|
return;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-03-29 16:08:48 -07:00
|
|
|
var data = item.pushAwayData;
|
2010-06-22 16:50:37 -07:00
|
|
|
// if the item under consideration has already been pushed, or has a lower
|
|
|
|
// "generation" (and thus an implictly greater placement priority) then don't move it.
|
2010-07-11 17:54:42 -07:00
|
|
|
if (data.generation <= baseData.generation)
|
2010-03-29 16:08:48 -07:00
|
|
|
return;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:50:37 -07:00
|
|
|
// box = this item's current bounds, with a +buffer margin.
|
2010-03-29 16:08:48 -07:00
|
|
|
var bounds = data.bounds;
|
|
|
|
var box = new Rect(bounds);
|
|
|
|
box.inset(-buffer, -buffer);
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:50:37 -07:00
|
|
|
// if the item under consideration overlaps with the base item...
|
2010-07-11 17:54:42 -07:00
|
|
|
if (box.intersects(bb)) {
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-03 18:13:31 -07:00
|
|
|
// Let's push it a little.
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-03 18:13:31 -07:00
|
|
|
// First, decide in which direction and how far to push. This is the offset.
|
2010-03-29 16:08:48 -07:00
|
|
|
var offset = new Point();
|
2010-06-22 16:50:37 -07:00
|
|
|
// center = the current item's center.
|
|
|
|
var center = box.center();
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:50:37 -07:00
|
|
|
// Consider the relationship between the current item (box) + the base item.
|
|
|
|
// If it's more vertically stacked than "side by side"...
|
2010-07-11 17:54:42 -07:00
|
|
|
if (Math.abs(center.x - bbc.x) < Math.abs(center.y - bbc.y)) {
|
2010-07-03 18:13:31 -07:00
|
|
|
// push vertically.
|
2010-07-11 17:54:42 -07:00
|
|
|
if (center.y > bbc.y)
|
2010-07-18 08:58:10 -07:00
|
|
|
offset.y = bb.bottom - box.top;
|
2010-03-29 16:08:48 -07:00
|
|
|
else
|
|
|
|
offset.y = bb.top - box.bottom;
|
2010-06-22 16:50:37 -07:00
|
|
|
} else { // if they're more "side by side" than stacked vertically...
|
2010-07-03 18:13:31 -07:00
|
|
|
// push horizontally.
|
2010-07-11 17:54:42 -07:00
|
|
|
if (center.x > bbc.x)
|
2010-07-18 08:58:10 -07:00
|
|
|
offset.x = bb.right - box.left;
|
2010-03-29 16:08:48 -07:00
|
|
|
else
|
|
|
|
offset.x = bb.left - box.right;
|
|
|
|
}
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:50:37 -07:00
|
|
|
// Actually push the Item.
|
2010-07-18 08:58:10 -07:00
|
|
|
bounds.offset(offset);
|
|
|
|
|
2010-06-22 16:50:37 -07:00
|
|
|
// This item now becomes an (n+1)-generation pushed item.
|
2010-03-29 16:08:48 -07:00
|
|
|
data.generation = baseData.generation + 1;
|
2010-06-22 16:50:37 -07:00
|
|
|
// keep track of who pushed this item.
|
2010-04-16 17:21:03 -07:00
|
|
|
data.pusher = baseItem;
|
2010-06-22 16:50:37 -07:00
|
|
|
// add this item to the queue, so that it, in turn, can push some other things.
|
2010-03-29 16:08:48 -07:00
|
|
|
itemsToPush.push(item);
|
|
|
|
}
|
|
|
|
});
|
2010-07-18 08:58:10 -07:00
|
|
|
};
|
|
|
|
|
2010-06-22 16:50:37 -07:00
|
|
|
// push each of the itemsToPush, one at a time.
|
|
|
|
// itemsToPush starts with just [this], but pushOne can add more items to the stack.
|
|
|
|
// Maximally, this could run through all Items on the screen.
|
2010-07-11 17:54:42 -07:00
|
|
|
while (itemsToPush.length)
|
2010-07-18 08:58:10 -07:00
|
|
|
pushOne(itemsToPush.shift());
|
2010-03-29 16:08:48 -07:00
|
|
|
|
2010-04-16 17:21:03 -07:00
|
|
|
// ___ Squish!
|
2010-06-22 16:50:37 -07:00
|
|
|
var pageBounds = Items.getSafeWindowBounds();
|
2011-01-12 07:20:28 -08:00
|
|
|
items.forEach(function Item_pushAway_squish(item) {
|
2010-07-03 18:13:31 -07:00
|
|
|
var data = item.pushAwayData;
|
2011-01-27 23:07:30 -08:00
|
|
|
if (data.generation == 0)
|
2010-07-03 18:13:31 -07:00
|
|
|
return;
|
|
|
|
|
2011-01-12 07:20:28 -08:00
|
|
|
let apply = function Item_pushAway_squish_apply(item, posStep, posStep2, sizeStep) {
|
2010-07-03 18:13:31 -07:00
|
|
|
var data = item.pushAwayData;
|
2010-07-11 17:54:42 -07:00
|
|
|
if (data.generation == 0)
|
2010-07-03 18:13:31 -07:00
|
|
|
return;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-03 18:13:31 -07:00
|
|
|
var bounds = data.bounds;
|
2010-07-18 08:58:10 -07:00
|
|
|
bounds.width -= sizeStep.x;
|
2010-07-03 18:13:31 -07:00
|
|
|
bounds.height -= sizeStep.y;
|
|
|
|
bounds.left += posStep.x;
|
|
|
|
bounds.top += posStep.y;
|
2010-09-26 23:25:00 -07:00
|
|
|
|
|
|
|
let validSize;
|
2011-01-12 07:20:28 -08:00
|
|
|
if (item.isAGroupItem) {
|
2010-09-26 23:25:00 -07:00
|
|
|
validSize = GroupItems.calcValidSize(
|
|
|
|
new Point(bounds.width, bounds.height));
|
|
|
|
bounds.width = validSize.x;
|
|
|
|
bounds.height = validSize.y;
|
2011-01-12 07:20:28 -08:00
|
|
|
} else {
|
2010-07-11 17:54:42 -07:00
|
|
|
if (sizeStep.y > sizeStep.x) {
|
2010-09-26 23:25:00 -07:00
|
|
|
validSize = TabItems.calcValidSize(new Point(-1, bounds.height));
|
|
|
|
bounds.left += (bounds.width - validSize.x) / 2;
|
|
|
|
bounds.width = validSize.x;
|
2010-07-03 18:13:31 -07:00
|
|
|
} else {
|
2010-09-26 23:25:00 -07:00
|
|
|
validSize = TabItems.calcValidSize(new Point(bounds.width, -1));
|
|
|
|
bounds.top += (bounds.height - validSize.y) / 2;
|
|
|
|
bounds.height = validSize.y;
|
2010-07-03 18:13:31 -07:00
|
|
|
}
|
|
|
|
}
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-03 18:13:31 -07:00
|
|
|
var pusher = data.pusher;
|
2010-07-22 12:46:51 -07:00
|
|
|
if (pusher) {
|
2010-07-30 02:54:30 -07:00
|
|
|
var newPosStep = new Point(posStep.x + posStep2.x, posStep.y + posStep2.y);
|
2010-07-22 12:46:51 -07:00
|
|
|
apply(pusher, newPosStep, posStep2, sizeStep);
|
|
|
|
}
|
2010-07-03 18:13:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var bounds = data.bounds;
|
|
|
|
var posStep = new Point();
|
|
|
|
var posStep2 = new Point();
|
|
|
|
var sizeStep = new Point();
|
|
|
|
|
2010-07-18 08:58:10 -07:00
|
|
|
if (bounds.left < pageBounds.left) {
|
2010-07-03 18:13:31 -07:00
|
|
|
posStep.x = pageBounds.left - bounds.left;
|
|
|
|
sizeStep.x = posStep.x / data.generation;
|
2010-07-18 08:58:10 -07:00
|
|
|
posStep2.x = -sizeStep.x;
|
2011-01-12 07:20:28 -08:00
|
|
|
} else if (bounds.right > pageBounds.right) { // this may be less of a problem post-601534
|
2010-07-03 18:13:31 -07:00
|
|
|
posStep.x = pageBounds.right - bounds.right;
|
|
|
|
sizeStep.x = -posStep.x / data.generation;
|
|
|
|
posStep.x += sizeStep.x;
|
|
|
|
posStep2.x = sizeStep.x;
|
|
|
|
}
|
|
|
|
|
2010-07-18 08:58:10 -07:00
|
|
|
if (bounds.top < pageBounds.top) {
|
2010-07-03 18:13:31 -07:00
|
|
|
posStep.y = pageBounds.top - bounds.top;
|
|
|
|
sizeStep.y = posStep.y / data.generation;
|
2010-07-18 08:58:10 -07:00
|
|
|
posStep2.y = -sizeStep.y;
|
2011-01-12 07:20:28 -08:00
|
|
|
} else if (bounds.bottom > pageBounds.bottom) { // this may be less of a problem post-601534
|
2010-07-03 18:13:31 -07:00
|
|
|
posStep.y = pageBounds.bottom - bounds.bottom;
|
|
|
|
sizeStep.y = -posStep.y / data.generation;
|
|
|
|
posStep.y += sizeStep.y;
|
|
|
|
posStep2.y = sizeStep.y;
|
|
|
|
}
|
|
|
|
|
2010-07-18 08:58:10 -07:00
|
|
|
if (posStep.x || posStep.y || sizeStep.x || sizeStep.y)
|
2010-09-26 23:25:00 -07:00
|
|
|
apply(item, posStep, posStep2, sizeStep);
|
2010-07-03 18:13:31 -07:00
|
|
|
});
|
2010-04-16 17:21:03 -07:00
|
|
|
|
2010-04-20 14:45:29 -07:00
|
|
|
// ___ Unsquish
|
2010-05-07 15:49:54 -07:00
|
|
|
var pairs = [];
|
2011-01-12 07:20:28 -08:00
|
|
|
items.forEach(function Item_pushAway_setupUnsquish(item) {
|
2010-04-20 14:45:29 -07:00
|
|
|
var data = item.pushAwayData;
|
2010-05-07 15:49:54 -07:00
|
|
|
pairs.push({
|
|
|
|
item: item,
|
|
|
|
bounds: data.bounds
|
|
|
|
});
|
2010-04-20 14:45:29 -07:00
|
|
|
});
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-05-07 15:49:54 -07:00
|
|
|
Items.unsquish(pairs);
|
2010-04-20 14:45:29 -07:00
|
|
|
|
2010-04-16 17:21:03 -07:00
|
|
|
// ___ Apply changes
|
2011-01-12 07:20:28 -08:00
|
|
|
items.forEach(function Item_pushAway_setBounds(item) {
|
2010-03-29 16:08:48 -07:00
|
|
|
var data = item.pushAwayData;
|
2010-04-16 17:21:03 -07:00
|
|
|
var bounds = data.bounds;
|
2010-07-11 17:54:42 -07:00
|
|
|
if (!bounds.equals(data.startBounds)) {
|
2010-10-09 12:46:18 -07:00
|
|
|
item.setBounds(bounds, immediately);
|
2010-04-16 17:21:03 -07:00
|
|
|
}
|
2010-03-29 16:08:48 -07:00
|
|
|
});
|
2010-04-01 17:20:59 -07:00
|
|
|
},
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-30 11:05:01 -07:00
|
|
|
// ----------
|
|
|
|
// Function: setTrenches
|
|
|
|
// Sets up/moves the trenches for snapping to this item.
|
2010-09-08 10:02:08 -07:00
|
|
|
setTrenches: function Item_setTrenches(rect) {
|
2010-07-03 18:13:31 -07:00
|
|
|
if (this.parent !== null)
|
|
|
|
return;
|
|
|
|
|
2010-07-17 20:18:43 -07:00
|
|
|
if (!this.borderTrenches)
|
|
|
|
this.borderTrenches = Trenches.registerWithItem(this,"border");
|
2010-07-03 18:13:31 -07:00
|
|
|
|
|
|
|
var bT = this.borderTrenches;
|
|
|
|
Trenches.getById(bT.left).setWithRect(rect);
|
|
|
|
Trenches.getById(bT.right).setWithRect(rect);
|
|
|
|
Trenches.getById(bT.top).setWithRect(rect);
|
|
|
|
Trenches.getById(bT.bottom).setWithRect(rect);
|
2010-07-17 20:18:43 -07:00
|
|
|
|
|
|
|
if (!this.guideTrenches)
|
|
|
|
this.guideTrenches = Trenches.registerWithItem(this,"guide");
|
|
|
|
|
2010-07-18 08:58:10 -07:00
|
|
|
var gT = this.guideTrenches;
|
2010-07-03 18:13:31 -07:00
|
|
|
Trenches.getById(gT.left).setWithRect(rect);
|
|
|
|
Trenches.getById(gT.right).setWithRect(rect);
|
|
|
|
Trenches.getById(gT.top).setWithRect(rect);
|
|
|
|
Trenches.getById(gT.bottom).setWithRect(rect);
|
2010-06-15 16:08:21 -07:00
|
|
|
|
|
|
|
},
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-30 11:05:01 -07:00
|
|
|
// ----------
|
|
|
|
// Function: removeTrenches
|
|
|
|
// Removes the trenches for snapping to this item.
|
2010-09-08 10:02:08 -07:00
|
|
|
removeTrenches: function Item_removeTrenches() {
|
2010-07-15 01:41:08 -07:00
|
|
|
for (var edge in this.borderTrenches) {
|
2010-07-03 18:13:31 -07:00
|
|
|
Trenches.unregister(this.borderTrenches[edge]); // unregister can take an array
|
|
|
|
}
|
|
|
|
this.borderTrenches = null;
|
2010-07-15 01:41:08 -07:00
|
|
|
for (var edge in this.guideTrenches) {
|
2010-07-03 18:13:31 -07:00
|
|
|
Trenches.unregister(this.guideTrenches[edge]); // unregister can take an array
|
|
|
|
}
|
|
|
|
this.guideTrenches = null;
|
|
|
|
},
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-03 18:13:31 -07:00
|
|
|
// ----------
|
2010-07-13 20:48:22 -07:00
|
|
|
// Function: snap
|
2010-08-06 15:46:55 -07:00
|
|
|
// The snap function used during groupItem creation via drag-out
|
2010-10-09 12:46:18 -07:00
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// immediately - bool for having the drag do the final positioning without animation
|
|
|
|
snap: function Item_snap(immediately) {
|
2010-07-03 18:13:31 -07:00
|
|
|
// make the snapping work with a wider range!
|
|
|
|
var defaultRadius = Trenches.defaultRadius;
|
|
|
|
Trenches.defaultRadius = 2 * defaultRadius; // bump up from 10 to 20!
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2011-07-04 15:23:35 -07:00
|
|
|
var FauxDragInfo = new Drag(this, {});
|
2010-11-24 13:19:47 -08:00
|
|
|
FauxDragInfo.snap('none', false);
|
2010-10-09 12:46:18 -07:00
|
|
|
FauxDragInfo.stop(immediately);
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-03 18:13:31 -07:00
|
|
|
Trenches.defaultRadius = defaultRadius;
|
2010-06-22 16:42:06 -07:00
|
|
|
},
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
// ----------
|
|
|
|
// Function: draggable
|
|
|
|
// Enables dragging on this item. Note: not to be called multiple times on the same item!
|
2010-09-08 10:02:08 -07:00
|
|
|
draggable: function Item_draggable() {
|
2010-06-22 16:42:06 -07:00
|
|
|
try {
|
2010-08-10 11:13:10 -07:00
|
|
|
Utils.assert(this.dragOptions, 'dragOptions');
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
var cancelClasses = [];
|
2010-08-10 16:20:05 -07:00
|
|
|
if (typeof this.dragOptions.cancelClass == 'string')
|
2010-06-22 16:42:06 -07:00
|
|
|
cancelClasses = this.dragOptions.cancelClass.split(' ');
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
var self = this;
|
|
|
|
var $container = iQ(this.container);
|
|
|
|
var startMouse;
|
|
|
|
var startPos;
|
|
|
|
var startSent;
|
|
|
|
var startEvent;
|
|
|
|
var droppables;
|
|
|
|
var dropTarget;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2011-01-21 15:15:22 -08:00
|
|
|
// determine the best drop target based on the current mouse coordinates
|
|
|
|
let determineBestDropTarget = function (e, box) {
|
|
|
|
// drop events
|
|
|
|
var best = {
|
|
|
|
dropTarget: null,
|
|
|
|
score: 0
|
|
|
|
};
|
|
|
|
|
|
|
|
droppables.forEach(function(droppable) {
|
|
|
|
var intersection = box.intersection(droppable.bounds);
|
|
|
|
if (intersection && intersection.area() > best.score) {
|
|
|
|
var possibleDropTarget = droppable.item;
|
|
|
|
var accept = true;
|
|
|
|
if (possibleDropTarget != dropTarget) {
|
|
|
|
var dropOptions = possibleDropTarget.dropOptions;
|
|
|
|
if (dropOptions && typeof dropOptions.accept == "function")
|
|
|
|
accept = dropOptions.accept.apply(possibleDropTarget, [self]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (accept) {
|
|
|
|
best.dropTarget = possibleDropTarget;
|
|
|
|
best.score = intersection.area();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return best.dropTarget;
|
|
|
|
}
|
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
// ___ mousemove
|
|
|
|
var handleMouseMove = function(e) {
|
2010-09-09 22:29:00 -07:00
|
|
|
// global drag tracking
|
|
|
|
drag.lastMoveTime = Date.now();
|
|
|
|
|
2010-07-18 08:58:10 -07:00
|
|
|
// positioning
|
2010-11-06 17:08:57 -07:00
|
|
|
var mouse = new Point(e.pageX, e.pageY);
|
2010-07-11 17:54:42 -07:00
|
|
|
if (!startSent) {
|
2010-09-21 10:22:07 -07:00
|
|
|
if(Math.abs(mouse.x - startMouse.x) > self.dragOptions.minDragDistance ||
|
|
|
|
Math.abs(mouse.y - startMouse.y) > self.dragOptions.minDragDistance) {
|
|
|
|
if (typeof self.dragOptions.start == "function")
|
|
|
|
self.dragOptions.start.apply(self,
|
|
|
|
[startEvent, {position: {left: startPos.x, top: startPos.y}}]);
|
|
|
|
startSent = true;
|
|
|
|
}
|
2010-06-22 16:42:06 -07:00
|
|
|
}
|
2010-09-21 10:22:07 -07:00
|
|
|
if (startSent) {
|
|
|
|
// drag events
|
|
|
|
var box = self.getBounds();
|
|
|
|
box.left = startPos.x + (mouse.x - startMouse.x);
|
|
|
|
box.top = startPos.y + (mouse.y - startMouse.y);
|
|
|
|
self.setBounds(box, true);
|
|
|
|
|
|
|
|
if (typeof self.dragOptions.drag == "function")
|
|
|
|
self.dragOptions.drag.apply(self, [e]);
|
|
|
|
|
2011-01-21 15:15:22 -08:00
|
|
|
let bestDropTarget = determineBestDropTarget(e, box);
|
2010-09-21 10:22:07 -07:00
|
|
|
|
2011-01-21 15:15:22 -08:00
|
|
|
if (bestDropTarget != dropTarget) {
|
2010-09-21 10:22:07 -07:00
|
|
|
var dropOptions;
|
|
|
|
if (dropTarget) {
|
|
|
|
dropOptions = dropTarget.dropOptions;
|
|
|
|
if (dropOptions && typeof dropOptions.out == "function")
|
|
|
|
dropOptions.out.apply(dropTarget, [e]);
|
2010-06-22 16:42:06 -07:00
|
|
|
}
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2011-01-21 15:15:22 -08:00
|
|
|
dropTarget = bestDropTarget;
|
2010-06-22 16:42:06 -07:00
|
|
|
|
2010-09-21 10:22:07 -07:00
|
|
|
if (dropTarget) {
|
|
|
|
dropOptions = dropTarget.dropOptions;
|
|
|
|
if (dropOptions && typeof dropOptions.over == "function")
|
|
|
|
dropOptions.over.apply(dropTarget, [e]);
|
|
|
|
}
|
2010-06-22 16:42:06 -07:00
|
|
|
}
|
2011-01-12 13:48:42 -08:00
|
|
|
if (dropTarget) {
|
|
|
|
dropOptions = dropTarget.dropOptions;
|
|
|
|
if (dropOptions && typeof dropOptions.move == "function")
|
|
|
|
dropOptions.move.apply(dropTarget, [e]);
|
|
|
|
}
|
2010-06-22 16:42:06 -07:00
|
|
|
}
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
e.preventDefault();
|
|
|
|
};
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
// ___ mouseup
|
|
|
|
var handleMouseUp = function(e) {
|
2010-07-22 12:34:13 -07:00
|
|
|
iQ(gWindow)
|
2010-06-22 16:42:06 -07:00
|
|
|
.unbind('mousemove', handleMouseMove)
|
|
|
|
.unbind('mouseup', handleMouseUp);
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2011-04-14 13:55:36 -07:00
|
|
|
if (startSent && dropTarget) {
|
2010-06-22 16:42:06 -07:00
|
|
|
var dropOptions = dropTarget.dropOptions;
|
2010-07-23 19:29:32 -07:00
|
|
|
if (dropOptions && typeof dropOptions.drop == "function")
|
2010-06-22 16:42:06 -07:00
|
|
|
dropOptions.drop.apply(dropTarget, [e]);
|
|
|
|
}
|
|
|
|
|
2010-07-23 19:29:32 -07:00
|
|
|
if (startSent && typeof self.dragOptions.stop == "function")
|
2010-06-22 16:42:06 -07:00
|
|
|
self.dragOptions.stop.apply(self, [e]);
|
2010-07-18 08:58:10 -07:00
|
|
|
|
|
|
|
e.preventDefault();
|
2010-06-22 16:42:06 -07:00
|
|
|
};
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
// ___ mousedown
|
|
|
|
$container.mousedown(function(e) {
|
2011-01-25 13:13:21 -08:00
|
|
|
if (!Utils.isLeftClick(e))
|
2010-06-22 16:42:06 -07:00
|
|
|
return;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
var cancel = false;
|
|
|
|
var $target = iQ(e.target);
|
2010-07-13 16:38:51 -07:00
|
|
|
cancelClasses.forEach(function(className) {
|
2010-08-11 19:01:29 -07:00
|
|
|
if ($target.hasClass(className))
|
2010-06-22 16:42:06 -07:00
|
|
|
cancel = true;
|
|
|
|
});
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-11 17:54:42 -07:00
|
|
|
if (cancel) {
|
2010-06-22 16:42:06 -07:00
|
|
|
e.preventDefault();
|
|
|
|
return;
|
|
|
|
}
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
startMouse = new Point(e.pageX, e.pageY);
|
2011-01-21 15:15:22 -08:00
|
|
|
let bounds = self.getBounds();
|
|
|
|
startPos = bounds.position();
|
2010-06-22 16:42:06 -07:00
|
|
|
startEvent = e;
|
|
|
|
startSent = false;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
droppables = [];
|
2010-07-13 21:03:47 -07:00
|
|
|
iQ('.iq-droppable').each(function(elem) {
|
|
|
|
if (elem != self.container) {
|
|
|
|
var item = Items.item(elem);
|
2010-06-22 16:42:06 -07:00
|
|
|
droppables.push({
|
2010-07-18 08:58:10 -07:00
|
|
|
item: item,
|
2010-06-22 16:42:06 -07:00
|
|
|
bounds: item.getBounds()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-01-21 15:15:22 -08:00
|
|
|
dropTarget = determineBestDropTarget(e, bounds);
|
|
|
|
|
2010-07-22 12:34:13 -07:00
|
|
|
iQ(gWindow)
|
2010-06-22 16:42:06 -07:00
|
|
|
.mousemove(handleMouseMove)
|
2010-07-18 08:58:10 -07:00
|
|
|
.mouseup(handleMouseUp);
|
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
} catch(e) {
|
|
|
|
Utils.log(e);
|
2010-07-18 08:58:10 -07:00
|
|
|
}
|
2010-06-22 16:42:06 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: droppable
|
|
|
|
// Enables or disables dropping on this item.
|
2010-09-08 10:02:08 -07:00
|
|
|
droppable: function Item_droppable(value) {
|
2010-06-22 16:42:06 -07:00
|
|
|
try {
|
|
|
|
var $container = iQ(this.container);
|
2010-10-09 12:46:18 -07:00
|
|
|
if (value) {
|
2010-09-04 12:15:31 -07:00
|
|
|
Utils.assert(this.dropOptions, 'dropOptions');
|
2010-10-09 12:46:18 -07:00
|
|
|
$container.addClass('iq-droppable');
|
|
|
|
} else
|
2010-06-22 16:42:06 -07:00
|
|
|
$container.removeClass('iq-droppable');
|
|
|
|
} catch(e) {
|
|
|
|
Utils.log(e);
|
|
|
|
}
|
|
|
|
},
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
// ----------
|
|
|
|
// Function: resizable
|
|
|
|
// Enables or disables resizing of this item.
|
2010-09-08 10:02:08 -07:00
|
|
|
resizable: function Item_resizable(value) {
|
2010-06-22 16:42:06 -07:00
|
|
|
try {
|
|
|
|
var $container = iQ(this.container);
|
|
|
|
iQ('.iq-resizable-handle', $container).remove();
|
|
|
|
|
2010-07-11 17:54:42 -07:00
|
|
|
if (!value) {
|
2010-06-22 16:42:06 -07:00
|
|
|
$container.removeClass('iq-resizable');
|
|
|
|
} else {
|
2010-08-10 11:13:10 -07:00
|
|
|
Utils.assert(this.resizeOptions, 'resizeOptions');
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
$container.addClass('iq-resizable');
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
var startMouse;
|
|
|
|
var startSize;
|
2011-01-18 04:25:59 -08:00
|
|
|
var startAspect;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
// ___ mousemove
|
|
|
|
var handleMouseMove = function(e) {
|
2010-09-09 22:29:00 -07:00
|
|
|
// global resize tracking
|
|
|
|
resize.lastMoveTime = Date.now();
|
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
var mouse = new Point(e.pageX, e.pageY);
|
|
|
|
var box = self.getBounds();
|
2010-11-07 22:38:24 -08:00
|
|
|
if (UI.rtl) {
|
|
|
|
var minWidth = (self.resizeOptions.minWidth || 0);
|
|
|
|
var oldWidth = box.width;
|
|
|
|
if (minWidth != oldWidth || mouse.x < startMouse.x) {
|
|
|
|
box.width = Math.max(minWidth, startSize.x - (mouse.x - startMouse.x));
|
|
|
|
box.left -= box.width - oldWidth;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
box.width = Math.max(self.resizeOptions.minWidth || 0, startSize.x + (mouse.x - startMouse.x));
|
|
|
|
}
|
2010-06-22 16:42:06 -07:00
|
|
|
box.height = Math.max(self.resizeOptions.minHeight || 0, startSize.y + (mouse.y - startMouse.y));
|
|
|
|
|
2010-07-11 17:54:42 -07:00
|
|
|
if (self.resizeOptions.aspectRatio) {
|
|
|
|
if (startAspect < 1)
|
2010-06-22 16:42:06 -07:00
|
|
|
box.height = box.width * startAspect;
|
|
|
|
else
|
|
|
|
box.width = box.height / startAspect;
|
|
|
|
}
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
self.setBounds(box, true);
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-23 19:29:32 -07:00
|
|
|
if (typeof self.resizeOptions.resize == "function")
|
2010-06-22 16:42:06 -07:00
|
|
|
self.resizeOptions.resize.apply(self, [e]);
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
};
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
// ___ mouseup
|
|
|
|
var handleMouseUp = function(e) {
|
2010-07-22 12:34:13 -07:00
|
|
|
iQ(gWindow)
|
2010-06-22 16:42:06 -07:00
|
|
|
.unbind('mousemove', handleMouseMove)
|
|
|
|
.unbind('mouseup', handleMouseUp);
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-23 19:29:32 -07:00
|
|
|
if (typeof self.resizeOptions.stop == "function")
|
2010-06-22 16:42:06 -07:00
|
|
|
self.resizeOptions.stop.apply(self, [e]);
|
2010-07-18 08:58:10 -07:00
|
|
|
|
|
|
|
e.preventDefault();
|
2010-06-22 16:42:06 -07:00
|
|
|
e.stopPropagation();
|
|
|
|
};
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
// ___ handle + mousedown
|
|
|
|
iQ('<div>')
|
|
|
|
.addClass('iq-resizable-handle iq-resizable-se')
|
|
|
|
.appendTo($container)
|
|
|
|
.mousedown(function(e) {
|
2011-01-25 13:13:21 -08:00
|
|
|
if (!Utils.isLeftClick(e))
|
2010-06-22 16:42:06 -07:00
|
|
|
return;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
startMouse = new Point(e.pageX, e.pageY);
|
|
|
|
startSize = self.getBounds().size();
|
|
|
|
startAspect = startSize.y / startSize.x;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-23 19:29:32 -07:00
|
|
|
if (typeof self.resizeOptions.start == "function")
|
2010-07-03 18:13:31 -07:00
|
|
|
self.resizeOptions.start.apply(self, [e]);
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-22 12:34:13 -07:00
|
|
|
iQ(gWindow)
|
2010-06-22 16:42:06 -07:00
|
|
|
.mousemove(handleMouseMove)
|
2010-07-18 08:58:10 -07:00
|
|
|
.mouseup(handleMouseUp);
|
|
|
|
|
2010-06-22 16:42:06 -07:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch(e) {
|
|
|
|
Utils.log(e);
|
|
|
|
}
|
2010-06-15 21:08:39 -07:00
|
|
|
}
|
2010-07-18 08:58:10 -07:00
|
|
|
};
|
2010-03-29 16:08:48 -07:00
|
|
|
|
2010-03-29 11:55:13 -07:00
|
|
|
// ##########
|
2010-04-08 16:36:11 -07:00
|
|
|
// Class: Items
|
2010-07-18 08:58:10 -07:00
|
|
|
// Keeps track of all Items.
|
2010-09-08 10:02:08 -07:00
|
|
|
let Items = {
|
2011-02-26 06:28:00 -08:00
|
|
|
// ----------
|
|
|
|
// Function: toString
|
|
|
|
// Prints [Items] for debug use
|
|
|
|
toString: function Items_toString() {
|
|
|
|
return "[Items]";
|
|
|
|
},
|
|
|
|
|
2010-06-19 13:08:14 -07:00
|
|
|
// ----------
|
|
|
|
// Variable: defaultGutter
|
|
|
|
// How far apart Items should be from each other and from bounds
|
|
|
|
defaultGutter: 15,
|
2010-07-18 08:58:10 -07:00
|
|
|
|
|
|
|
// ----------
|
2010-04-08 16:36:11 -07:00
|
|
|
// Function: item
|
2010-07-18 08:58:10 -07:00
|
|
|
// Given a DOM element representing an Item, returns the Item.
|
2010-09-08 10:02:08 -07:00
|
|
|
item: function Items_item(el) {
|
2010-05-27 17:25:14 -07:00
|
|
|
return iQ(el).data('item');
|
2010-03-29 16:08:48 -07:00
|
|
|
},
|
2010-07-18 08:58:10 -07:00
|
|
|
|
|
|
|
// ----------
|
2010-04-08 16:36:11 -07:00
|
|
|
// Function: getTopLevelItems
|
2010-08-06 15:46:55 -07:00
|
|
|
// Returns an array of all Items not grouped into groupItems.
|
2010-09-08 10:02:08 -07:00
|
|
|
getTopLevelItems: function Items_getTopLevelItems() {
|
2010-03-29 11:55:13 -07:00
|
|
|
var items = [];
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2011-10-13 00:55:08 -07:00
|
|
|
iQ('.tab, .groupItem').each(function(elem) {
|
2010-07-13 21:03:47 -07:00
|
|
|
var $this = iQ(elem);
|
2010-07-18 08:58:10 -07:00
|
|
|
var item = $this.data('item');
|
2010-07-11 17:54:42 -07:00
|
|
|
if (item && !item.parent && !$this.hasClass('phantom'))
|
2010-04-26 13:37:39 -07:00
|
|
|
items.push(item);
|
2010-03-29 11:55:13 -07:00
|
|
|
});
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-03-29 11:55:13 -07:00
|
|
|
return items;
|
2010-07-18 08:58:10 -07:00
|
|
|
},
|
2010-04-14 17:12:06 -07:00
|
|
|
|
2010-04-16 17:21:03 -07:00
|
|
|
// ----------
|
|
|
|
// Function: getPageBounds
|
2010-07-18 08:58:10 -07:00
|
|
|
// Returns a <Rect> defining the area of the page <Item>s should stay within.
|
2010-09-08 10:02:08 -07:00
|
|
|
getPageBounds: function Items_getPageBounds() {
|
2010-04-26 16:48:46 -07:00
|
|
|
var width = Math.max(100, window.innerWidth);
|
2010-08-04 22:43:05 -07:00
|
|
|
var height = Math.max(100, window.innerHeight);
|
2010-06-29 22:06:36 -07:00
|
|
|
return new Rect(0, 0, width, height);
|
2010-04-16 17:21:03 -07:00
|
|
|
},
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-19 17:45:23 -07:00
|
|
|
// ----------
|
|
|
|
// Function: getSafeWindowBounds
|
|
|
|
// Returns the bounds within which it is safe to place all non-stationary <Item>s.
|
2010-09-08 10:02:08 -07:00
|
|
|
getSafeWindowBounds: function Items_getSafeWindowBounds() {
|
2010-06-19 17:45:23 -07:00
|
|
|
// the safe bounds that would keep it "in the window"
|
|
|
|
var gutter = Items.defaultGutter;
|
|
|
|
// Here, I've set the top gutter separately, as the top of the window has its own
|
|
|
|
// extra chrome which makes a large top gutter unnecessary.
|
|
|
|
// TODO: set top gutter separately, elsewhere.
|
|
|
|
var topGutter = 5;
|
2010-08-08 18:49:43 -07:00
|
|
|
return new Rect(gutter, topGutter,
|
2010-07-30 02:54:30 -07:00
|
|
|
window.innerWidth - 2 * gutter, window.innerHeight - gutter - topGutter);
|
2010-06-22 20:35:38 -07:00
|
|
|
|
2010-06-19 17:45:23 -07:00
|
|
|
},
|
2010-07-18 08:58:10 -07:00
|
|
|
|
|
|
|
// ----------
|
2010-04-14 17:12:06 -07:00
|
|
|
// Function: arrange
|
2010-07-18 08:58:10 -07:00
|
|
|
// Arranges the given items in a grid within the given bounds,
|
2010-04-14 17:12:06 -07:00
|
|
|
// maximizing item size but maintaining standard tab aspect ratio for each
|
2010-07-18 08:58:10 -07:00
|
|
|
//
|
|
|
|
// Parameters:
|
2010-11-06 17:08:57 -07:00
|
|
|
// items - an array of <Item>s. Can be null, in which case we won't
|
|
|
|
// actually move anything.
|
2010-04-14 17:12:06 -07:00
|
|
|
// bounds - a <Rect> defining the space to arrange within
|
2010-05-13 17:24:37 -07:00
|
|
|
// options - an object with various properites (see below)
|
|
|
|
//
|
2010-07-18 08:58:10 -07:00
|
|
|
// Possible "options" properties:
|
2010-05-13 17:24:37 -07:00
|
|
|
// animate - whether to animate; default: true.
|
|
|
|
// z - the z index to set all the items; default: don't change z.
|
2010-11-06 17:08:57 -07:00
|
|
|
// return - if set to 'widthAndColumns', it'll return an object with the
|
|
|
|
// width of children and the columns.
|
|
|
|
// count - overrides the item count for layout purposes;
|
|
|
|
// default: the actual item count
|
|
|
|
// columns - (int) a preset number of columns to use
|
2011-01-12 13:48:42 -08:00
|
|
|
// dropPos - a <Point> which should have a one-tab space left open, used
|
|
|
|
// when a tab is dragged over.
|
2010-07-18 08:58:10 -07:00
|
|
|
//
|
|
|
|
// Returns:
|
2010-09-26 23:25:00 -07:00
|
|
|
// By default, an object with three properties: `rects`, the list of <Rect>s,
|
|
|
|
// `dropIndex`, the index which a dragged tab should have if dropped
|
|
|
|
// (null if no `dropPos` was specified), and the number of columns (`columns`).
|
2011-01-12 13:48:42 -08:00
|
|
|
// If the `return` option is set to 'widthAndColumns', an object with the
|
|
|
|
// width value of the child items (`childWidth`) and the number of columns
|
|
|
|
// (`columns`) is returned.
|
2010-09-08 10:02:08 -07:00
|
|
|
arrange: function Items_arrange(items, bounds, options) {
|
2011-01-17 09:31:39 -08:00
|
|
|
if (!options)
|
2010-04-14 17:12:06 -07:00
|
|
|
options = {};
|
2011-01-17 09:31:39 -08:00
|
|
|
var animate = "animate" in options ? options.animate : true;
|
2010-11-06 17:08:57 -07:00
|
|
|
var immediately = !animate;
|
|
|
|
|
|
|
|
var rects = [];
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-05-03 17:11:44 -07:00
|
|
|
var count = options.count || (items ? items.length : 0);
|
2011-01-12 13:48:42 -08:00
|
|
|
if (options.addTab)
|
|
|
|
count++;
|
|
|
|
if (!count) {
|
|
|
|
let dropIndex = (Utils.isPoint(options.dropPos)) ? 0 : null;
|
|
|
|
return {rects: rects, dropIndex: dropIndex};
|
|
|
|
}
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-11-06 17:08:57 -07:00
|
|
|
var columns = options.columns || 1;
|
2010-09-08 16:44:16 -07:00
|
|
|
// We'll assume for the time being that all the items have the same styling
|
|
|
|
// and that the margin is the same width around.
|
|
|
|
var itemMargin = items && items.length ?
|
|
|
|
parseInt(iQ(items[0].container).css('margin-left')) : 0;
|
|
|
|
var padding = itemMargin * 2;
|
2010-04-14 17:12:06 -07:00
|
|
|
var rows;
|
|
|
|
var tabWidth;
|
|
|
|
var tabHeight;
|
|
|
|
var totalHeight;
|
|
|
|
|
|
|
|
function figure() {
|
2010-07-18 08:58:10 -07:00
|
|
|
rows = Math.ceil(count / columns);
|
2010-09-26 23:25:00 -07:00
|
|
|
let validSize = TabItems.calcValidSize(
|
|
|
|
new Point((bounds.width - (padding * columns)) / columns, -1),
|
|
|
|
options);
|
|
|
|
tabWidth = validSize.x;
|
|
|
|
tabHeight = validSize.y;
|
|
|
|
|
|
|
|
totalHeight = (tabHeight * rows) + (padding * rows);
|
2010-07-18 08:58:10 -07:00
|
|
|
}
|
|
|
|
|
2010-04-14 17:12:06 -07:00
|
|
|
figure();
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-11 17:54:42 -07:00
|
|
|
while (rows > 1 && totalHeight > bounds.height) {
|
2010-07-18 08:58:10 -07:00
|
|
|
columns++;
|
2010-04-14 17:12:06 -07:00
|
|
|
figure();
|
|
|
|
}
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-11 17:54:42 -07:00
|
|
|
if (rows == 1) {
|
2010-09-26 23:25:00 -07:00
|
|
|
let validSize = TabItems.calcValidSize(new Point(tabWidth,
|
|
|
|
bounds.height - 2 * itemMargin), options);
|
|
|
|
tabWidth = validSize.x;
|
|
|
|
tabHeight = validSize.y;
|
2010-04-14 17:12:06 -07:00
|
|
|
}
|
2010-11-30 11:50:42 -08:00
|
|
|
|
2010-11-06 17:08:57 -07:00
|
|
|
if (options.return == 'widthAndColumns')
|
|
|
|
return {childWidth: tabWidth, columns: columns};
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-11-07 22:38:25 -08:00
|
|
|
let initialOffset = 0;
|
|
|
|
if (UI.rtl) {
|
2010-11-10 19:48:43 -08:00
|
|
|
initialOffset = bounds.width - tabWidth - padding;
|
2010-11-07 22:38:25 -08:00
|
|
|
}
|
|
|
|
var box = new Rect(bounds.left + initialOffset, bounds.top, tabWidth, tabHeight);
|
|
|
|
|
2010-04-14 17:12:06 -07:00
|
|
|
var column = 0;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2011-01-12 13:48:42 -08:00
|
|
|
var dropIndex = false;
|
|
|
|
var dropRect = false;
|
|
|
|
if (Utils.isPoint(options.dropPos))
|
|
|
|
dropRect = new Rect(options.dropPos.x, options.dropPos.y, 1, 1);
|
2010-11-06 17:08:57 -07:00
|
|
|
for (let a = 0; a < count; a++) {
|
2011-01-12 13:48:42 -08:00
|
|
|
// If we had a dropPos, see if this is where we should place it
|
|
|
|
if (dropRect) {
|
|
|
|
let activeBox = new Rect(box);
|
|
|
|
activeBox.inset(-itemMargin - 1, -itemMargin - 1);
|
|
|
|
// if the designated position (dropRect) is within the active box,
|
|
|
|
// this is where, if we drop the tab being dragged, it should land!
|
|
|
|
if (activeBox.contains(dropRect))
|
|
|
|
dropIndex = a;
|
2011-01-12 11:37:41 -08:00
|
|
|
}
|
2011-01-12 13:48:42 -08:00
|
|
|
|
|
|
|
// record the box.
|
|
|
|
rects.push(new Rect(box));
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-11-07 22:38:25 -08:00
|
|
|
box.left += (UI.rtl ? -1 : 1) * (box.width + padding);
|
2010-04-14 17:12:06 -07:00
|
|
|
column++;
|
2010-07-11 17:54:42 -07:00
|
|
|
if (column == columns) {
|
2010-11-07 22:38:25 -08:00
|
|
|
box.left = bounds.left + initialOffset;
|
2010-09-26 23:25:00 -07:00
|
|
|
box.top += box.height + padding;
|
2010-04-14 17:12:06 -07:00
|
|
|
column = 0;
|
|
|
|
}
|
2010-05-03 17:11:44 -07:00
|
|
|
}
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-09-26 23:25:00 -07:00
|
|
|
return {rects: rects, dropIndex: dropIndex, columns: columns};
|
2010-05-07 15:49:54 -07:00
|
|
|
},
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-05-07 15:49:54 -07:00
|
|
|
// ----------
|
|
|
|
// Function: unsquish
|
2010-07-18 08:58:10 -07:00
|
|
|
// Checks to see which items can now be unsquished.
|
2010-05-07 15:49:54 -07:00
|
|
|
//
|
2010-07-18 08:58:10 -07:00
|
|
|
// Parameters:
|
|
|
|
// pairs - an array of objects, each with two properties: item and bounds. The bounds are
|
2010-05-07 15:49:54 -07:00
|
|
|
// modified as appropriate, but the items are not changed. If pairs is null, the
|
2010-07-18 08:58:10 -07:00
|
|
|
// operation is performed directly on all of the top level items.
|
2010-05-07 15:49:54 -07:00
|
|
|
// ignore - an <Item> to not include in calculations (because it's about to be closed, for instance)
|
2010-09-08 10:02:08 -07:00
|
|
|
unsquish: function Items_unsquish(pairs, ignore) {
|
2010-05-07 15:49:54 -07:00
|
|
|
var pairsProvided = (pairs ? true : false);
|
2010-07-11 17:54:42 -07:00
|
|
|
if (!pairsProvided) {
|
2010-05-07 15:49:54 -07:00
|
|
|
var items = Items.getTopLevelItems();
|
|
|
|
pairs = [];
|
2010-07-13 16:38:51 -07:00
|
|
|
items.forEach(function(item) {
|
2010-05-07 15:49:54 -07:00
|
|
|
pairs.push({
|
|
|
|
item: item,
|
|
|
|
bounds: item.getBounds()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-06-22 16:50:37 -07:00
|
|
|
var pageBounds = Items.getSafeWindowBounds();
|
2010-07-13 16:38:51 -07:00
|
|
|
pairs.forEach(function(pair) {
|
2010-05-07 15:49:54 -07:00
|
|
|
var item = pair.item;
|
2011-01-27 23:07:30 -08:00
|
|
|
if (item == ignore)
|
2010-05-07 15:49:54 -07:00
|
|
|
return;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-05-07 15:49:54 -07:00
|
|
|
var bounds = pair.bounds;
|
|
|
|
var newBounds = new Rect(bounds);
|
|
|
|
|
|
|
|
var newSize;
|
2010-07-22 12:46:51 -07:00
|
|
|
if (Utils.isPoint(item.userSize))
|
2010-05-07 15:49:54 -07:00
|
|
|
newSize = new Point(item.userSize);
|
2010-09-26 23:25:00 -07:00
|
|
|
else if (item.isAGroupItem)
|
|
|
|
newSize = GroupItems.calcValidSize(
|
|
|
|
new Point(GroupItems.minGroupWidth, -1));
|
2010-05-07 15:49:54 -07:00
|
|
|
else
|
2010-09-26 23:25:00 -07:00
|
|
|
newSize = TabItems.calcValidSize(
|
|
|
|
new Point(TabItems.tabWidth, -1));
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-08-06 15:46:55 -07:00
|
|
|
if (item.isAGroupItem) {
|
2010-05-07 15:49:54 -07:00
|
|
|
newBounds.width = Math.max(newBounds.width, newSize.x);
|
|
|
|
newBounds.height = Math.max(newBounds.height, newSize.y);
|
|
|
|
} else {
|
2010-07-11 17:54:42 -07:00
|
|
|
if (bounds.width < newSize.x) {
|
2010-05-07 15:49:54 -07:00
|
|
|
newBounds.width = newSize.x;
|
|
|
|
newBounds.height = newSize.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newBounds.left -= (newBounds.width - bounds.width) / 2;
|
|
|
|
newBounds.top -= (newBounds.height - bounds.height) / 2;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-05-07 15:49:54 -07:00
|
|
|
var offset = new Point();
|
2010-07-11 17:54:42 -07:00
|
|
|
if (newBounds.left < pageBounds.left)
|
2010-05-07 15:49:54 -07:00
|
|
|
offset.x = pageBounds.left - newBounds.left;
|
2010-07-11 17:54:42 -07:00
|
|
|
else if (newBounds.right > pageBounds.right)
|
2010-05-07 15:49:54 -07:00
|
|
|
offset.x = pageBounds.right - newBounds.right;
|
|
|
|
|
2010-07-11 17:54:42 -07:00
|
|
|
if (newBounds.top < pageBounds.top)
|
2010-05-07 15:49:54 -07:00
|
|
|
offset.y = pageBounds.top - newBounds.top;
|
2010-07-11 17:54:42 -07:00
|
|
|
else if (newBounds.bottom > pageBounds.bottom)
|
2010-05-07 15:49:54 -07:00
|
|
|
offset.y = pageBounds.bottom - newBounds.bottom;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-05-07 15:49:54 -07:00
|
|
|
newBounds.offset(offset);
|
|
|
|
|
2010-07-18 08:58:10 -07:00
|
|
|
if (!bounds.equals(newBounds)) {
|
2010-05-07 15:49:54 -07:00
|
|
|
var blocked = false;
|
2010-07-13 16:38:51 -07:00
|
|
|
pairs.forEach(function(pair2) {
|
2010-07-11 17:54:42 -07:00
|
|
|
if (pair2 == pair || pair2.item == ignore)
|
2010-05-07 15:49:54 -07:00
|
|
|
return;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-05-07 15:49:54 -07:00
|
|
|
var bounds2 = pair2.bounds;
|
2010-08-11 19:01:29 -07:00
|
|
|
if (bounds2.intersects(newBounds))
|
2010-05-07 15:49:54 -07:00
|
|
|
blocked = true;
|
2010-08-12 16:32:18 -07:00
|
|
|
return;
|
2010-05-07 15:49:54 -07:00
|
|
|
});
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-11 17:54:42 -07:00
|
|
|
if (!blocked) {
|
2010-05-07 15:49:54 -07:00
|
|
|
pair.bounds.copy(newBounds);
|
|
|
|
}
|
|
|
|
}
|
2010-08-11 19:01:29 -07:00
|
|
|
return;
|
2010-05-07 15:49:54 -07:00
|
|
|
});
|
|
|
|
|
2010-07-11 17:54:42 -07:00
|
|
|
if (!pairsProvided) {
|
2010-07-13 16:38:51 -07:00
|
|
|
pairs.forEach(function(pair) {
|
2010-05-07 15:49:54 -07:00
|
|
|
pair.item.setBounds(pair.bounds);
|
|
|
|
});
|
|
|
|
}
|
2010-03-29 11:55:13 -07:00
|
|
|
}
|
2010-09-08 10:02:08 -07:00
|
|
|
};
|