2010-03-29 11:55:13 -07:00
|
|
|
// ##########
|
|
|
|
window.TabItem = function(container, tab) {
|
2010-04-01 17:20:59 -07:00
|
|
|
this._init(container);
|
2010-03-29 11:55:13 -07:00
|
|
|
this.tab = tab;
|
2010-03-31 17:24:16 -07:00
|
|
|
this.defaultSize = new Point(TabItems.tabWidth, TabItems.tabHeight);
|
2010-03-29 11:55:13 -07:00
|
|
|
};
|
|
|
|
|
2010-03-29 16:08:48 -07:00
|
|
|
window.TabItem.prototype = $.extend(new Item(), {
|
2010-04-01 17:20:59 -07:00
|
|
|
// ----------
|
|
|
|
reloadBounds: function() {
|
|
|
|
this.bounds = Utils.getBounds(this.container);
|
|
|
|
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-01 17:20:59 -07:00
|
|
|
var css = {};
|
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) {
|
|
|
|
css.width = rect.width;
|
|
|
|
var scale = rect.width / TabItems.tabWidth;
|
|
|
|
css.fontSize = TabItems.fontSize * scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rect.height != this.bounds.height)
|
|
|
|
css.height = rect.height;
|
|
|
|
|
|
|
|
if($.isEmptyObject(css))
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.bounds.copy(rect);
|
|
|
|
|
2010-04-02 17:33:06 -07:00
|
|
|
if(immediately) {
|
2010-04-01 17:20:59 -07:00
|
|
|
$(this.container).css(css);
|
2010-04-02 17:33:06 -07:00
|
|
|
} else {
|
2010-04-01 17:20:59 -07:00
|
|
|
TabMirror.pausePainting();
|
|
|
|
$(this.container).animate(css, {complete: function() {
|
|
|
|
TabMirror.resumePainting();
|
|
|
|
}}).dequeue();
|
|
|
|
}
|
2010-03-29 16:08:48 -07:00
|
|
|
|
2010-04-01 17:20:59 -07:00
|
|
|
this._updateDebugBounds();
|
|
|
|
},
|
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();
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
addOnClose: function(referenceObject, callback) {
|
|
|
|
this.tab.mirror.addOnClose(referenceObject, callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
removeOnClose: function(referenceObject) {
|
|
|
|
this.tab.mirror.removeOnClose(referenceObject);
|
|
|
|
}
|
|
|
|
});
|
2010-03-29 11:55:13 -07:00
|
|
|
|
|
|
|
// ##########
|
|
|
|
window.TabItems = {
|
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-03-29 11:55:13 -07:00
|
|
|
init: function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if(e.target.className == "close") {
|
|
|
|
$(this).find("canvas").data("link").tab.close(); }
|
|
|
|
else {
|
|
|
|
if(!$(this).data('isDragging')) {
|
2010-04-09 12:49:54 -07:00
|
|
|
|
2010-03-29 11:55:13 -07:00
|
|
|
// ZOOM!
|
|
|
|
var [w,h,z] = [$(this).width(), $(this).height(), $(this).css("zIndex")];
|
|
|
|
var origPos = $(this).position();
|
|
|
|
var zIndex = $(this).css("zIndex");
|
|
|
|
var scale = window.innerWidth/w;
|
2010-04-09 12:49:54 -07:00
|
|
|
var big = 99999;
|
2010-03-29 11:55:13 -07:00
|
|
|
|
|
|
|
var tab = Tabs.tab(this);
|
|
|
|
var mirror = tab.mirror;
|
|
|
|
//mirror.forceCanvasSize(w * scale/3, h * scale);
|
|
|
|
|
|
|
|
var overflow = $("body").css("overflow");
|
|
|
|
$("body").css("overflow", "hidden");
|
2010-04-09 12:49:54 -07:00
|
|
|
|
|
|
|
function onZoomDone(){
|
|
|
|
$(this).find("canvas").data("link").tab.focus();
|
|
|
|
$(this)
|
|
|
|
.css({top: origPos.top, left: origPos.left, width:w, height:h, zIndex:z});
|
|
|
|
Navbar.show();
|
|
|
|
$("body").css("overflow", overflow);
|
|
|
|
}
|
2010-03-29 11:55:13 -07:00
|
|
|
|
2010-04-09 12:49:54 -07:00
|
|
|
$(this)
|
|
|
|
.css("zIndex",big)
|
|
|
|
.animate({
|
|
|
|
top: -10,
|
|
|
|
left: 0,
|
|
|
|
easing: "easein",
|
|
|
|
width:w*scale,
|
|
|
|
height:h*scale
|
|
|
|
}, 200, onZoomDone);
|
2010-03-29 11:55:13 -07:00
|
|
|
|
|
|
|
} else {
|
|
|
|
$(this).find("canvas").data("link").tab.raw.pos = $(this).position();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-04-08 17:38:06 -07:00
|
|
|
$("<div class='close'><img src='img/closetab.png'/></div>").appendTo($div);
|
|
|
|
$("<div class='expander'><img src='img/expand.png'/></div>").appendTo($div);
|
2010-03-29 11:55:13 -07:00
|
|
|
|
|
|
|
if($div.length == 1) {
|
2010-03-29 17:23:35 -07:00
|
|
|
var p = Page.findOpenSpaceFor($div); // TODO shouldn't know about Page
|
2010-03-29 11:55:13 -07:00
|
|
|
$div.css({left: p.x, top: p.y});
|
|
|
|
}
|
|
|
|
|
2010-03-30 11:05:53 -07:00
|
|
|
$div.each(function() {
|
|
|
|
var tab = Tabs.tab(this);
|
|
|
|
$(this).data('tabItem', new TabItem(this, tab));
|
|
|
|
});
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TabItems.init();
|