home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2005 December
/
PCWorld_2005-12_cd.bin
/
komunikace
/
netscape
/
nsb-install-8-0.exe
/
chrome
/
browser.jar
/
content
/
browser
/
titlebar.js
< prev
next >
Wrap
Text File
|
2005-09-26
|
6KB
|
183 lines
var titlebar = {
windowTitleListener : {
onWindowTitleChange : function(xulwin, title) {
//var thisWindow = document.getElementById('main-window');
//var thisWindow = window.QueryInterface(Components.interfaces.nsIXULWindow);
//dump('>>>>>>>>>>>>>> onWindowTitleChange: window: '+xulwin+', '+title+'\n');
var docshell = xulwin.docShell;
try { // Bin - if this (try & catch) affects performance, we should remove it
var requestor = docshell.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var domwin = requestor.getInterface(Components.interfaces.nsIDOMWindow);
if (domwin != window) return;
var lbl = document.getElementById('titlebar-title');
if(lbl)//JA
lbl.value = title;
}
catch (e){}
},
onOpenWindow : function(wnd) { },
onCloseWindow : function(wnd) { },
},
init : function() {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
wm.addListener(this.windowTitleListener);
},
debug : function(txt) {
//dump('titlebar: '+txt+'\n');
},
menuState : 2, // 0=label 1=transition 2=menus 3=transition
onmouseover : function(event) {
if (this.menuState==0) {
this.debug('onmouseover()');
this.animLabelToMenus();
} else {
this.debug('onmouseover(): menuState: '+this.menuState);
}
},
onmousemove : function(event) {
if (this.menuState==0) {
this.debug('onmousemove()');
// The mouse cursor somehow got inside the titlebar without
// initiating the transition to menus, so force the menus
// display immediately
this.forceLabelToMenus();
}
},
onmouseout : function(event) {
if (this.menuState==2) {
this.debug('onmouseout()');
if (this.isOverTitlebar(event) || this.isMenuOpen()) {
// Check again after a few seconds
//setTimeout('titlebar.onmouseout();',5000);
return;
}
this.animMenusToLabel();
}
},
// Test if any menus are currently open
isMenuOpen : function() {
var menubar = document.getElementById('main-menubar');
var menus = menubar.childNodes;
for (var i = 0; i < menus.length; i++) {
if (menus[i].getAttribute('open')=='true') return true;
}
return false;
},
// Test if the mouse is currently inside the titlebar
isOverTitlebar : function(event) {
var tb = document.getElementById('titlebar');
if ((tb.boxObject.screenX <= event.screenX)
&& (event.screenX - tb.boxObject.screenX <= tb.boxObject.width)
&& (tb.boxObject.screenY <= event.screenY)
&& (event.screenY - tb.boxObject.screenY <= tb.boxObject.height)) {
return true;
}
return false;
},
lastMouseDown : null,
throbberMouseDown : function(event) {
lastMouseDown = new Object();
lastMouseDown.x = event.screenX;
lastMouseDown.y = event.screenY;
},
throbberMouseUp : function(event) {
// We want a single click on the throbber to go to the throbber URL,
// but we DON'T want a click-and-drag action to do this.
if (lastMouseDown &&
(lastMouseDown.x == event.screenX) &&
(lastMouseDown.y == event.screenY))
{
goClickThrobber('browser.throbber.url', event);
lastMouseDown = null;
}
},
animWait : 15, // milliseconds
// Animate from label to menus
animLabelToMenus : function(phase, iter) {
this.menuState = 1;
if (!phase) phase = 1;
if (!iter) iter = 0;
this.debug('animLabelToMenus('+phase+','+iter+')');
switch (phase) {
case 1: // Fade out the label
var label = document.getElementById('menu-label-box');
if (iter <= 10) {
label.style.MozOpacity = 1 - (iter/10);
setTimeout('titlebar.animLabelToMenus(1,'+(iter+1)+');',this.animWait);
} else {
label.setAttribute('hidden','true');
setTimeout('titlebar.animLabelToMenus(2,0);',this.animWait);
}
break;
case 2: // Fade in menus
if (iter <= 10) {
var menus = document.getElementById('menubar-items');
menus.style.MozOpacity = iter / 10;
if (iter == 0) menus.removeAttribute('hidden');
}
if (iter < 10)
setTimeout('titlebar.animLabelToMenus(2,'+(iter+1)+');',this.animWait);
else if (iter == 10) this.menuState = 2;
}
},
// In some cases we may want to force the transition to menus more rapidly
forceLabelToMenus : function() {
this.menuState = 1;
var label = document.getElementById('menu-label-box');
label.style.MozOpacity = 0;
label.setAttribute('hidden','true');
var menus = document.getElementById('menubar-items');
menus.style.MozOpacity = 1;
menus.removeAttribute('hidden');
this.menuState = 2;
},
// Animate from menus to label
animMenusToLabel : function(phase, iter) {
this.menuState = 3;
if (!phase) phase = 1;
if (!iter) iter = 0;
this.debug('animMenusToLabel('+phase+','+iter+')');
switch (phase) {
case 1: // Fade out the menus
var menus = document.getElementById('menubar-items');
if (iter <= 10) {
menus.style.MozOpacity = 1 - (iter/10);
setTimeout('titlebar.animMenusToLabel(1,'+(iter+1)+');',this.animWait);
} else {
menus.setAttribute('hidden','true');
setTimeout('titlebar.animMenusToLabel(2,0);',this.animWait);
}
break;
case 2: // Fade in label
if (iter <= 10) {
var label = document.getElementById('menu-label-box');
label.style.MozOpacity = iter / 10;
if (iter == 0) label.removeAttribute('hidden');
}
if (iter < 10)
setTimeout('titlebar.animMenusToLabel(2,'+(iter+1)+');',this.animWait);
else if (iter == 10) this.menuState = 0;
}
},
menuKeydown : function(event) {
this.debug(' KEY DOWN!!! ');
}
};