2010-03-29 11:55:13 -07:00
|
|
|
// ##########
|
|
|
|
window.TabItem = function(container, tab) {
|
2010-04-30 17:24:03 -07:00
|
|
|
this.defaultSize = new Point(TabItems.tabWidth, TabItems.tabHeight);
|
2010-04-01 17:20:59 -07:00
|
|
|
this._init(container);
|
2010-05-04 15:57:19 -07:00
|
|
|
this._hasBeenDrawn = false;
|
2010-03-29 11:55:13 -07:00
|
|
|
this.tab = tab;
|
2010-04-12 17:20:35 -07:00
|
|
|
this.setResizable(true);
|
2010-03-29 11:55:13 -07:00
|
|
|
};
|
|
|
|
|
2010-03-29 16:08:48 -07:00
|
|
|
window.TabItem.prototype = $.extend(new Item(), {
|
2010-04-23 17:11:06 -07:00
|
|
|
// ----------
|
|
|
|
getStorageData: function() {
|
|
|
|
return {
|
|
|
|
bounds: this.bounds,
|
2010-04-26 16:48:46 -07:00
|
|
|
userSize: this.userSize,
|
2010-04-26 13:37:39 -07:00
|
|
|
url: this.tab.url,
|
|
|
|
groupID: (this.parent ? this.parent.id : 0)
|
2010-04-23 17:11:06 -07:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
getURL: function() {
|
|
|
|
return this.tab.url;
|
|
|
|
},
|
|
|
|
|
2010-04-22 14:26:57 -07:00
|
|
|
// ----------
|
|
|
|
_getSizeExtra: function() {
|
|
|
|
var $container = $(this.container);
|
|
|
|
|
|
|
|
var widthExtra = parseInt($container.css('padding-left'))
|
|
|
|
+ parseInt($container.css('padding-right'));
|
|
|
|
|
|
|
|
var heightExtra = parseInt($container.css('padding-top'))
|
|
|
|
+ parseInt($container.css('padding-bottom'));
|
|
|
|
|
|
|
|
return new Point(widthExtra, heightExtra);
|
|
|
|
},
|
|
|
|
|
2010-04-01 17:20:59 -07:00
|
|
|
// ----------
|
|
|
|
reloadBounds: function() {
|
2010-04-26 17:23:15 -07:00
|
|
|
var newBounds = Utils.getBounds(this.container);
|
2010-04-22 14:26:57 -07:00
|
|
|
var extra = this._getSizeExtra();
|
2010-04-26 17:23:15 -07:00
|
|
|
newBounds.width += extra.x;
|
|
|
|
newBounds.height += extra.y;
|
2010-04-22 14:26:57 -07:00
|
|
|
|
2010-04-26 17:23:15 -07:00
|
|
|
/*
|
|
|
|
if(!this.bounds || newBounds.width != this.bounds.width || newBounds.height != this.bounds.height) {
|
|
|
|
// if resizing, or first time, do the whole deal
|
|
|
|
if(!this.bounds)
|
|
|
|
this.bounds = new Rect(0, 0, 0, 0);
|
|
|
|
|
|
|
|
this.setBounds(newBounds, true);
|
|
|
|
} else {
|
|
|
|
*/
|
|
|
|
// if we're just moving, this is more efficient
|
|
|
|
this.bounds = newBounds;
|
|
|
|
this._updateDebugBounds();
|
|
|
|
/* } */
|
2010-03-29 11:55:13 -07:00
|
|
|
},
|
|
|
|
|
2010-03-29 16:08:48 -07:00
|
|
|
// ----------
|
2010-03-29 17:23:35 -07:00
|
|
|
setBounds: function(rect, immediately) {
|
2010-04-12 17:20:35 -07:00
|
|
|
var $container = $(this.container);
|
|
|
|
var $title = $('.tab-title', $container);
|
|
|
|
var $thumb = $('.thumb', $container);
|
|
|
|
var $close = $('.close', $container);
|
2010-04-22 14:26:57 -07:00
|
|
|
var extra = this._getSizeExtra();
|
2010-04-01 17:20:59 -07:00
|
|
|
var css = {};
|
2010-04-28 13:17:43 -07:00
|
|
|
|
2010-04-28 16:39:15 -07:00
|
|
|
const minFontSize = 8;
|
2010-04-28 13:17:43 -07:00
|
|
|
const maxFontSize = 15;
|
2010-03-29 16:08:48 -07:00
|
|
|
|
2010-04-01 17:20:59 -07:00
|
|
|
if(rect.left != this.bounds.left)
|
|
|
|
css.left = rect.left;
|
|
|
|
|
|
|
|
if(rect.top != this.bounds.top)
|
|
|
|
css.top = rect.top;
|
|
|
|
|
|
|
|
if(rect.width != this.bounds.width) {
|
2010-04-22 14:26:57 -07:00
|
|
|
css.width = rect.width - extra.x;
|
2010-04-12 17:20:35 -07:00
|
|
|
var scale = css.width / TabItems.tabWidth;
|
2010-04-28 13:17:43 -07:00
|
|
|
|
|
|
|
// The ease function ".5+.5*Math.tanh(2*x-2)" is a pretty
|
|
|
|
// little graph. It goes from near 0 at x=0 to near 1 at x=2
|
|
|
|
// smoothly and beautifully.
|
|
|
|
css.fontSize = minFontSize + (maxFontSize-minFontSize)*(.5+.5*Math.tanh(2*scale-2))
|
2010-04-01 17:20:59 -07:00
|
|
|
}
|
|
|
|
|
2010-04-12 17:20:35 -07:00
|
|
|
if(rect.height != this.bounds.height) {
|
2010-04-22 14:26:57 -07:00
|
|
|
css.height = rect.height - extra.y;
|
2010-04-12 17:20:35 -07:00
|
|
|
}
|
2010-04-01 17:20:59 -07:00
|
|
|
|
|
|
|
if($.isEmptyObject(css))
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.bounds.copy(rect);
|
2010-05-04 15:57:19 -07:00
|
|
|
// If this is a brand new tab don't animate it in from
|
2010-05-04 15:58:29 -07:00
|
|
|
// a random location (i.e., from [0,0]). Instead, just
|
|
|
|
// have it appear where it should be.
|
2010-05-04 15:57:19 -07:00
|
|
|
if(immediately || (!this._hasBeenDrawn) ) {
|
2010-04-12 17:20:35 -07:00
|
|
|
$container.css(css);
|
2010-04-02 17:33:06 -07:00
|
|
|
} else {
|
2010-04-01 17:20:59 -07:00
|
|
|
TabMirror.pausePainting();
|
2010-04-28 20:12:34 -07:00
|
|
|
$container.animate(css,{
|
|
|
|
complete: function() {TabMirror.resumePainting();},
|
|
|
|
duration: 350,
|
|
|
|
easing: "tabcandyBounce"
|
|
|
|
}).dequeue();
|
2010-04-01 17:20:59 -07:00
|
|
|
}
|
2010-03-29 16:08:48 -07:00
|
|
|
|
2010-04-30 17:24:03 -07:00
|
|
|
if(css.fontSize && !$container.hasClass("stacked")) {
|
2010-04-29 00:42:37 -07:00
|
|
|
if(css.fontSize < minFontSize )
|
|
|
|
$title.fadeOut().dequeue();
|
2010-04-12 17:20:35 -07:00
|
|
|
else
|
2010-04-29 00:42:37 -07:00
|
|
|
$title.fadeIn().dequeue();
|
2010-04-12 17:20:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if(css.width) {
|
|
|
|
if(css.width < 30) {
|
|
|
|
$thumb.fadeOut();
|
|
|
|
$close.fadeOut();
|
|
|
|
} else {
|
|
|
|
$thumb.fadeIn();
|
|
|
|
$close.fadeIn();
|
|
|
|
}
|
2010-04-29 00:42:37 -07:00
|
|
|
}
|
2010-04-12 17:20:35 -07:00
|
|
|
|
2010-04-01 17:20:59 -07:00
|
|
|
this._updateDebugBounds();
|
2010-05-04 15:57:19 -07:00
|
|
|
this._hasBeenDrawn = true;
|
2010-04-01 17:20:59 -07:00
|
|
|
},
|
2010-04-02 17:33:06 -07:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
setZ: function(value) {
|
|
|
|
$(this.container).css({zIndex: value});
|
|
|
|
},
|
|
|
|
|
2010-03-29 16:08:48 -07:00
|
|
|
// ----------
|
|
|
|
close: function() {
|
|
|
|
this.tab.close();
|
|
|
|
},
|
|
|
|
|
2010-04-29 00:42:37 -07:00
|
|
|
// ----------
|
|
|
|
addClass: function(className) {
|
|
|
|
$(this.container).addClass(className);
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
removeClass: function(className) {
|
|
|
|
$(this.container).removeClass(className);
|
|
|
|
},
|
|
|
|
|
2010-03-29 16:08:48 -07:00
|
|
|
// ----------
|
|
|
|
addOnClose: function(referenceObject, callback) {
|
|
|
|
this.tab.mirror.addOnClose(referenceObject, callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
removeOnClose: function(referenceObject) {
|
|
|
|
this.tab.mirror.removeOnClose(referenceObject);
|
2010-04-12 17:20:35 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
setResizable: function(value){
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var $resizer = $('.expander', this.container);
|
|
|
|
if(value) {
|
|
|
|
$resizer.fadeIn();
|
|
|
|
$(this.container).resizable({
|
|
|
|
handles: "se",
|
|
|
|
aspectRatio: true,
|
|
|
|
minWidth: TabItems.minTabWidth,
|
|
|
|
minHeight: TabItems.minTabWidth * (TabItems.tabHeight / TabItems.tabWidth),
|
|
|
|
resize: function(){
|
|
|
|
self.reloadBounds();
|
|
|
|
},
|
|
|
|
stop: function(){
|
|
|
|
self.reloadBounds();
|
2010-04-26 16:48:46 -07:00
|
|
|
self.setUserSize();
|
2010-04-12 17:20:35 -07:00
|
|
|
self.pushAway();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$resizer.fadeOut();
|
|
|
|
$(this.container).resizable('destroy');
|
|
|
|
}
|
2010-03-29 16:08:48 -07:00
|
|
|
}
|
|
|
|
});
|
2010-03-29 11:55:13 -07:00
|
|
|
|
|
|
|
// ##########
|
|
|
|
window.TabItems = {
|
2010-04-12 17:20:35 -07:00
|
|
|
minTabWidth: 40,
|
2010-03-31 17:24:16 -07:00
|
|
|
tabWidth: 160,
|
2010-04-09 12:49:54 -07:00
|
|
|
tabHeight: 120,
|
2010-03-31 17:24:16 -07:00
|
|
|
fontSize: 9,
|
|
|
|
|
2010-04-23 17:11:06 -07:00
|
|
|
// ----------
|
2010-03-29 11:55:13 -07:00
|
|
|
init: function() {
|
|
|
|
var self = this;
|
2010-04-28 16:39:15 -07:00
|
|
|
|
2010-03-29 11:55:13 -07:00
|
|
|
function mod($div){
|
|
|
|
if(window.Groups) {
|
2010-03-31 17:24:16 -07:00
|
|
|
$div.data('isDragging', false);
|
2010-03-29 11:55:13 -07:00
|
|
|
$div.draggable(window.Groups.dragOptions);
|
|
|
|
$div.droppable(window.Groups.dropOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
$div.mousedown(function(e) {
|
|
|
|
if(!Utils.isRightClick(e))
|
|
|
|
self.lastMouseDownTarget = e.target;
|
|
|
|
});
|
|
|
|
|
|
|
|
$div.mouseup(function(e) {
|
|
|
|
var same = (e.target == self.lastMouseDownTarget);
|
|
|
|
self.lastMouseDownTarget = null;
|
|
|
|
if(!same)
|
|
|
|
return;
|
2010-04-10 02:16:02 -07:00
|
|
|
|
2010-03-29 11:55:13 -07:00
|
|
|
if(e.target.className == "close") {
|
|
|
|
$(this).find("canvas").data("link").tab.close(); }
|
|
|
|
else {
|
|
|
|
if(!$(this).data('isDragging')) {
|
2010-04-27 16:11:49 -07:00
|
|
|
var item = $(this).data('tabItem');
|
|
|
|
if(!item.parent || !item.parent.childHit(item)) {
|
2010-04-28 16:39:15 -07:00
|
|
|
// Zoom in!
|
2010-04-27 16:11:49 -07:00
|
|
|
var orig = {
|
|
|
|
width: $(this).width(),
|
|
|
|
height: $(this).height(),
|
|
|
|
pos: $(this).position()
|
|
|
|
}
|
2010-03-29 11:55:13 -07:00
|
|
|
|
2010-04-27 16:11:49 -07:00
|
|
|
var scale = window.innerWidth/orig.width;
|
|
|
|
|
|
|
|
var tab = Tabs.tab(this);
|
|
|
|
var mirror = tab.mirror;
|
|
|
|
|
|
|
|
var overflow = $("body").css("overflow");
|
|
|
|
$("body").css("overflow", "hidden");
|
|
|
|
|
|
|
|
function onZoomDone(){
|
2010-04-27 16:30:15 -07:00
|
|
|
UI.tabBar.show(false);
|
2010-04-27 16:11:49 -07:00
|
|
|
TabMirror.resumePainting();
|
|
|
|
$(this).find("canvas").data("link").tab.focus();
|
|
|
|
$(this).css({
|
|
|
|
top: orig.pos.top,
|
|
|
|
left: orig.pos.left,
|
|
|
|
width: orig.width,
|
|
|
|
height:orig.height,
|
|
|
|
})
|
|
|
|
.removeClass("front");
|
2010-04-28 16:39:15 -07:00
|
|
|
Navbar.show();
|
2010-05-05 00:47:07 -07:00
|
|
|
|
|
|
|
// If the tab is in a group set then set the active
|
|
|
|
// group to the tab's parent.
|
|
|
|
if( self.getItemByTab(this).parent ){
|
|
|
|
var gID = self.getItemByTab(this).parent.id;
|
2010-05-03 15:24:22 -07:00
|
|
|
var group = Groups.group(gID);
|
2010-05-05 00:47:07 -07:00
|
|
|
Groups.setActiveGroup( group );
|
2010-04-27 16:30:15 -07:00
|
|
|
}
|
2010-05-05 00:47:07 -07:00
|
|
|
else
|
|
|
|
Groups.setActiveGroup( null );
|
|
|
|
|
2010-04-27 16:30:15 -07:00
|
|
|
|
2010-04-27 16:11:49 -07:00
|
|
|
$("body").css("overflow", overflow);
|
|
|
|
}
|
|
|
|
|
|
|
|
TabMirror.pausePainting();
|
|
|
|
$(this)
|
|
|
|
.addClass("front")
|
|
|
|
.animate({
|
|
|
|
top: -10,
|
|
|
|
left: 0,
|
|
|
|
width: orig.width*scale,
|
|
|
|
height: orig.height*scale
|
2010-04-29 00:42:37 -07:00
|
|
|
}, 200, "easeInQuad", onZoomDone);
|
2010-04-27 16:11:49 -07:00
|
|
|
}
|
2010-03-29 11:55:13 -07:00
|
|
|
} else {
|
|
|
|
$(this).find("canvas").data("link").tab.raw.pos = $(this).position();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-04-10 02:16:02 -07:00
|
|
|
$("<div class='close'></div>").appendTo($div);
|
|
|
|
$("<div class='expander'></div>").appendTo($div);
|
2010-03-29 11:55:13 -07:00
|
|
|
|
2010-04-26 13:37:39 -07:00
|
|
|
var reconnected = false;
|
2010-03-30 11:05:53 -07:00
|
|
|
$div.each(function() {
|
|
|
|
var tab = Tabs.tab(this);
|
2010-05-03 15:32:11 -07:00
|
|
|
if(tab == Utils.homeTab)
|
|
|
|
$(this).hide();
|
|
|
|
else {
|
|
|
|
var item = new TabItem(this, tab);
|
|
|
|
$(this).data('tabItem', item);
|
|
|
|
|
|
|
|
if(TabItems.reconnect(item))
|
|
|
|
reconnected = true;
|
|
|
|
else if(!tab.url || tab.url == 'about:blank') {
|
|
|
|
tab.mirror.addSubscriber(item, 'urlChanged', function(who, info) {
|
|
|
|
Utils.assert('changing away from blank', info.oldURL == 'about:blank' || !info.oldURL);
|
|
|
|
TabItems.reconnect(item);
|
|
|
|
tab.mirror.removeSubscriber(item);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2010-03-30 11:05:53 -07:00
|
|
|
});
|
2010-03-29 11:55:13 -07:00
|
|
|
|
2010-05-04 13:52:25 -07:00
|
|
|
if(!reconnected && $div.length == 1 && Groups){
|
|
|
|
Groups.newTab($div.data('tabItem'));
|
|
|
|
}
|
|
|
|
|
2010-04-28 16:39:15 -07:00
|
|
|
|
2010-03-29 11:55:13 -07:00
|
|
|
// TODO: Figure out this really weird bug?
|
|
|
|
// Why is that:
|
|
|
|
// $div.find("canvas").data("link").tab.url
|
|
|
|
// returns chrome://tabcandy/content/candies/original/index.html for
|
|
|
|
// every $div (which isn't right), but that
|
|
|
|
// $div.bind("test", function(){
|
|
|
|
// var url = $(this).find("canvas").data("link").tab.url;
|
|
|
|
// });
|
|
|
|
// $div.trigger("test")
|
|
|
|
// returns the right result (i.e., the per-tab URL)?
|
|
|
|
// I'm so confused...
|
|
|
|
// Although I can use the trigger trick, I was thinking about
|
|
|
|
// adding code in here which sorted the tabs into groups.
|
|
|
|
// -- Aza
|
|
|
|
}
|
|
|
|
|
|
|
|
window.TabMirror.customize(mod);
|
2010-04-23 17:11:06 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
getItems: function() {
|
|
|
|
var items = [];
|
2010-05-03 15:32:11 -07:00
|
|
|
$('.tab:visible').each(function() {
|
2010-04-23 17:11:06 -07:00
|
|
|
items.push($(this).data('tabItem'));
|
|
|
|
});
|
|
|
|
|
|
|
|
return items;
|
|
|
|
},
|
2010-05-05 00:47:07 -07:00
|
|
|
|
2010-04-27 15:31:20 -07:00
|
|
|
// ----------
|
|
|
|
getItemByTab: function(tab) {
|
|
|
|
return $(tab).data("tabItem");
|
|
|
|
},
|
|
|
|
|
2010-04-23 17:11:06 -07:00
|
|
|
// ----------
|
|
|
|
getStorageData: function() {
|
|
|
|
var data = {tabs: []};
|
|
|
|
var items = this.getItems();
|
|
|
|
$.each(items, function(index, item) {
|
|
|
|
data.tabs.push(item.getStorageData());
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
reconstitute: function(data) {
|
2010-04-26 13:37:39 -07:00
|
|
|
this.storageData = data;
|
2010-04-23 17:11:06 -07:00
|
|
|
var items = this.getItems();
|
|
|
|
if(data && data.tabs) {
|
2010-04-26 13:37:39 -07:00
|
|
|
var self = this;
|
|
|
|
$.each(items, function(index, item) {
|
|
|
|
if(!self.reconnect(item))
|
|
|
|
Groups.newTab(item);
|
2010-04-23 17:11:06 -07:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
var box = Items.getPageBounds();
|
|
|
|
box.inset(20, 20);
|
|
|
|
|
|
|
|
Items.arrange(items, box, {padding: 10, animate:false});
|
|
|
|
}
|
2010-04-26 13:37:39 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
reconnect: function(item) {
|
2010-05-04 16:44:03 -07:00
|
|
|
if(item.reconnected)
|
|
|
|
return true;
|
|
|
|
|
2010-04-26 13:37:39 -07:00
|
|
|
var found = false;
|
|
|
|
if(this.storageData && this.storageData.tabs) {
|
2010-05-04 16:44:03 -07:00
|
|
|
var self = this;
|
2010-04-26 13:37:39 -07:00
|
|
|
$.each(this.storageData.tabs, function(index, tab) {
|
2010-05-04 14:55:17 -07:00
|
|
|
if(tab.url == 'about:blank')
|
|
|
|
return;
|
|
|
|
|
2010-04-26 13:37:39 -07:00
|
|
|
if(item.getURL() == tab.url) {
|
2010-05-04 16:44:03 -07:00
|
|
|
if(item.parent)
|
|
|
|
item.parent.remove(item);
|
2010-05-03 15:32:11 -07:00
|
|
|
|
2010-05-04 16:44:03 -07:00
|
|
|
item.setBounds(tab.bounds, true);
|
|
|
|
item.userSize = tab.userSize;
|
|
|
|
if(tab.groupID) {
|
|
|
|
var group = Groups.group(tab.groupID);
|
|
|
|
group.add(item);
|
2010-04-26 13:37:39 -07:00
|
|
|
}
|
|
|
|
|
2010-05-04 16:44:03 -07:00
|
|
|
self.storageData.tabs.splice(index, 1);
|
|
|
|
item.reconnected = true;
|
2010-04-26 13:37:39 -07:00
|
|
|
found = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
2010-03-29 11:55:13 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TabItems.init();
|