一部のライブラリをJavaScriptコードモジュールとして読み込むようにした

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@6689 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2010-06-22 18:00:16 +00:00
parent dd75958b3c
commit 8a733db96c
12 changed files with 192 additions and 41 deletions

View File

@ -1,6 +1,5 @@
<?xml version="1.0"?>
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="res/animationManager.js" type="application/javascript"/>
<script src="treestyletab.js" type="application/javascript"/>
<script src="bookmarksOverlay.js" type="application/javascript"/>
</overlay>

View File

@ -6,6 +6,10 @@ var Prefs = Components
.classes['@mozilla.org/preferences;1']
.getService(Components.interfaces.nsIPrefBranch);
Components.utils.import('resource://treestyletab-modules/animationManager.js', {});
Components.utils.import('resource://treestyletab-modules/namespace.jsm');
var animationManager = getNamespaceFor('piro.sakura.ne.jp')['piro.sakura.ne.jp'].animationManager;
var gGroupBookmarkRadio,
gGroupBookmarkUnderParent,
gGroupBookmarkType,
@ -103,7 +107,7 @@ function initAppearancePane()
}
return finished;
};
window['piro.sakura.ne.jp'].animationManager.addTask(task, 0, 0, 500);
animationManager.addTask(task, 0, 0, 500);
});
}

View File

@ -783,7 +783,6 @@
</prefpane>
<script src="res/animationManager.js" type="application/javascript"/>
<script src="config.js" type="application/javascript"/>
</prefwindow>

View File

@ -693,7 +693,7 @@ TreeStyleTabService.overrideExtensionsOnInitAfter = function TSTService_override
// Focus Last Selected Tab 0.9.5.x
// http://www.gozer.org/mozilla/extensions/
if (window['piro.sakura.ne.jp'].extensions.isAvailable('focuslastselectedtab@gozer.org')) {
if (this.extensions.isAvailable('focuslastselectedtab@gozer.org')) {
TreeStyleTabService.registerTabFocusAllowance(function(aTabBrowser) {
return !aTabBrowser.selectedTab.hasAttribute('lastselected');
});
@ -1099,7 +1099,7 @@ TreeStyleTabService.overrideExtensionsOnInitAfter = function TSTService_override
// Remove New Tab Button
// https://addons.mozilla.org/firefox/addon/10535
if (window['piro.sakura.ne.jp'].extensions.isAvailable('remove-new-tab-button@forerunnerdesigns.com')) {
if (this.extensions.isAvailable('remove-new-tab-button@forerunnerdesigns.com')) {
document.documentElement.setAttribute(TreeStyleTabService.kHIDE_NEWTAB, true);
}

View File

@ -1291,7 +1291,6 @@ catch(e) {
try {
window.removeEventListener('unload', this, false);
window['piro.sakura.ne.jp'].animationManager.stop();
gBrowser.treeStyleTab.saveCurrentState();
this.destroyTabBrowser(gBrowser);

View File

@ -7,10 +7,7 @@
<overlay id="treestyletab-overlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="res/autoScroll.js" type="application/javascript"/>
<script src="res/animationManager.js" type="application/javascript"/>
<script src="res/stopRendering.js" type="application/javascript"/>
<script src="res/extensions.js" type="application/javascript"/>
<script src="res/UninstallationListener.js" type="application/javascript"/>
<script src="treestyletab.js" type="application/javascript"/>

View File

@ -1349,6 +1349,8 @@ TreeStyleTabBrowser.prototype = {
destroy : function TSTBrowser_destroy()
{
this.animationManager.removeTask(this.smoothScrollTask);
this.autoHide.destroy();
delete this._autoHide;
@ -1356,6 +1358,8 @@ TreeStyleTabBrowser.prototype = {
delete b.tabContainer.treeStyleTab;
this.getTabsArray(b).forEach(function(aTab) {
this.stopTabIndentAnimation(aTab);
this.stopTabCollapseAnimation(aTab);
this.destroyTab(aTab);
}, this);
@ -1640,7 +1644,7 @@ TreeStyleTabBrowser.prototype = {
aStyle = 'osx';
}
else if (
window['piro.sakura.ne.jp'].extensions.isAvailable('informationaltab@piro.sakura.ne.jp') &&
this.extensions.isAvailable('informationaltab@piro.sakura.ne.jp') &&
this.getPref('extensions.informationaltab.thumbnail.enabled') &&
this.getPref('extensions.informationaltab.thumbnail.position') < 100
) {
@ -3809,14 +3813,14 @@ TreeStyleTabBrowser.prototype = {
}
return finished;
};
window['piro.sakura.ne.jp'].animationManager.addTask(
this.animationManager.addTask(
aTab.__treestyletab__updateTabIndentTask,
0, 0, this.indentDuration
);
},
stopTabIndentAnimation : function TSTBrowser_stopTabIndentAnimation(aTab)
{
window['piro.sakura.ne.jp'].animationManager.removeTask(
this.animationManager.removeTask(
aTab.__treestyletab__updateTabIndentTask
);
},
@ -4183,7 +4187,7 @@ TreeStyleTabBrowser.prototype = {
return false;
}
};
window['piro.sakura.ne.jp'].animationManager.addTask(
this.animationManager.addTask(
aTab.__treestyletab__updateTabCollapsedTask,
0, 0, this.collapseDuration
);
@ -4191,7 +4195,7 @@ TreeStyleTabBrowser.prototype = {
kOPACITY_RULE_REGEXP : /opacity\s*:[^;]+;?/,
stopTabCollapseAnimation : function TSTBrowser_stopTabCollapseAnimation(aTab)
{
window['piro.sakura.ne.jp'].animationManager.removeTask(
this.animationManager.removeTask(
aTab.__treestyletab__updateTabCollapsedTask
);
},
@ -4296,7 +4300,7 @@ TreeStyleTabBrowser.prototype = {
smoothScrollTo : function TSTBrowser_smoothScrollTo(aEndX, aEndY)
{
var b = this.mTabBrowser;
window['piro.sakura.ne.jp'].animationManager.removeTask(this.smoothScrollTask);
this.animationManager.removeTask(this.smoothScrollTask);
var scrollBoxObject = this.scrollBoxObject;
var x = {}, y = {};
@ -4339,7 +4343,7 @@ TreeStyleTabBrowser.prototype = {
scrollBoxObject.scrollTo(newX, newY);
return false;
};
window['piro.sakura.ne.jp'].animationManager.addTask(
this.animationManager.addTask(
this.smoothScrollTask,
0, 0, this.smoothScrollDuration
);

View File

@ -1,3 +1,10 @@
var EXPORTED_SYMBOLS = ['window'];
Components.utils.import('resource://treestyletab-modules/namespace.jsm');
var window = getNamespaceFor('piro.sakura.ne.jp');
if (!('setInterval' in window))
Components.utils.import('resource://treestyletab-modules/jstimer.jsm', window);
/*
Animation Task Manager

View File

@ -1,3 +1,7 @@
var EXPORTED_SYMBOLS = ['window'];
Components.utils.import('resource://treestyletab-modules/namespace.jsm');
var window = getNamespaceFor('piro.sakura.ne.jp');
/*
Tab Bar AutoScroll Library for Vertical and Horizontal Tab Bar
@ -6,13 +10,13 @@
.autoScroll
.processAutoScroll(mouseMoveOrDragOverEvent);
lisence: The MIT License, Copyright (c) 2009 SHIMODA "Piro" Hiroshi
lisence: The MIT License, Copyright (c) 2009-2010 SHIMODA "Piro" Hiroshi
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt
original:
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/autoScroll.js
*/
(function() {
const currentRevision = 2;
const currentRevision = 3;
if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
@ -23,8 +27,8 @@
return;
}
var Cc = Components.classes;
var Ci = Components.interfaces;
const Cc = Components.classes;
const Ci = Components.interfaces;
window['piro.sakura.ne.jp'].autoScroll = {
revision : currentRevision,
@ -36,7 +40,7 @@
'ancestor-or-self::*[local-name()="tabbrowser"]',
target,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
if (!b) return false;
@ -45,6 +49,8 @@
if (tabs.getAttribute('overflow') != 'true')
return false;
var view = target.ownerDocument.defaultView;
var box = this.getScrollBox(b);
var boxObject = this.getScrollBoxObject(b);
var innerBoxObject = (box.localName == 'arrowscrollbox' ? box._scrollbox : box ).boxObject;
@ -53,7 +59,7 @@
var isMultirow = tabs.getAttribute('flowing') == 'multibar'; // Tab Mix Plus
var isVertical = (
isMultirow ||
((orientBox.getAttribute('orient') || window.getComputedStyle(orientBox, '').getPropertyValue('-moz-box-orient')) == 'vertical')
((orientBox.getAttribute('orient') || view.getComputedStyle(orientBox, '').getPropertyValue('-moz-box-orient')) == 'vertical')
);
var maxX = {}, maxY = {}, curX = {}, curY = {};
@ -77,7 +83,7 @@
}
else {
pixels = box.scrollIncrement;
var ltr = window.getComputedStyle(tabs, null).direction == 'ltr';
var ltr = view.getComputedStyle(tabs, null).direction == 'ltr';
if (aEvent.screenX < boxObject.screenX + this.getUpButtonWidth(b)) {
if (curX.value == 0) return false;
pixels *= -1;
@ -106,7 +112,7 @@
getScrollBox : function(aTabBrowser)
{
return document.getAnonymousElementByAttribute(aTabBrowser.mTabContainer, 'class', 'tabs-frame') || // Tab Mix Plus
return aTabBrowser.ownerDocument.getAnonymousElementByAttribute(aTabBrowser.mTabContainer, 'class', 'tabs-frame') || // Tab Mix Plus
aTabBrowser.mTabContainer.mTabstrip;
},
@ -121,15 +127,15 @@
{
var box = this.getScrollBox(aTabBrowser);
return box._scrollButtonUp ||
document.getAnonymousElementByAttribute(box, 'class', 'scrollbutton-up') ||
document.getAnonymousElementByAttribute(box.previousSibling, 'class', 'scrollbutton-up'); // Tab Mix Plus
aTabBrowser.ownerDocument.getAnonymousElementByAttribute(box, 'class', 'scrollbutton-up') ||
aTabBrowser.ownerDocument.getAnonymousElementByAttribute(box.previousSibling, 'class', 'scrollbutton-up'); // Tab Mix Plus
},
getDownButton : function(aTabBrowser)
{
var box = this.getScrollBox(aTabBrowser);
return box._scrollButtonDown ||
document.getAnonymousElementByAttribute(box, 'class', 'scrollbutton-down') ||
document.getAnonymousElementByAttribute(box.nextSibling, 'class', 'scrollbutton-up'); // Tab Mix Plus
aTabBrowser.ownerDocument.getAnonymousElementByAttribute(box, 'class', 'scrollbutton-down') ||
aTabBrowser.ownerDocument.getAnonymousElementByAttribute(box.nextSibling, 'class', 'scrollbutton-up'); // Tab Mix Plus
},
autoScrollArea : 20,

View File

@ -1,3 +1,7 @@
var EXPORTED_SYMBOLS = ['window'];
Components.utils.import('resource://treestyletab-modules/namespace.jsm');
var window = getNamespaceFor('piro.sakura.ne.jp');
/*
Extensions Compatibility Library
@ -16,7 +20,7 @@
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/extensions.js
*/
(function() {
const currentRevision = 5;
const currentRevision = 6;
if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
@ -32,7 +36,7 @@
// Firefox 3.7 or later
var AM = {};
if ('@mozilla.org/addons/integration;1' in Components.classes)
if ('@mozilla.org/addons/integration;1' in Cc)
Components.utils.import('resource://gre/modules/AddonManager.jsm', AM);
window['piro.sakura.ne.jp'].extensions = {
@ -45,7 +49,7 @@
AM.AddonManager.getAddonByID(aId, function(aAddon) {
addon = aAddon;
});
var thread = Components.classes['@mozilla.org/thread-manager;1']
var thread = Cc['@mozilla.org/thread-manager;1']
.getService()
.mainThread;
while (addon === void(0)) {
@ -131,7 +135,7 @@
return false;
},
goToOptions : function(aId)
goToOptions : function(aId, aOwnerWindow)
{
var uri = this.ExtensionManager ? this.getOptionsURI_EM(aId) : this.getOptionsURI_AM(aId) ;
if (!uri) return;
@ -151,7 +155,7 @@
}
catch(e) {
}
window.openDialog(
(aOwnerWindow || window).openDialog(
uri,
'',
'chrome,titlebar,toolbar,centerscreen,' + (instantApply ? 'dialog=no' : 'modal' )

129
modules/jstimer.jsm Normal file
View File

@ -0,0 +1,129 @@
/*
JavaScript Timer Library
Usage:
var namespace = {};
Components.utils.import('resource://foo-modules/jstimer.jsm', namespace);
var callback = function(aMessage) { alert(aMessage); };
var timeout = namespace.setTimeout(callback, 1000, 'OK');
namespace.clearTimeout(timeout);
var interval = namespace.setInterval(callback, 1000, 'OK');
namespace.clearInterval(interval);
lisence: The MIT License, Copyright (c) 2010 SHIMODA "Piro" Hiroshi
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt
original:
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/jstimer.jsm
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/jstimer.test.js
*/
var Cc = Components.classes;
var Ci = Components.interfaces;
var EXPORTED_SYMBOLS = [
'setTimeout',
'clearTimeout',
'setInterval',
'clearInterval'
];
function setTimeout()
{
var args = Array.slice(arguments);
var callback = args.shift();
var timeout = args.shift();
return (new Timer(
(typeof callback == 'string' ?
callback :
function() { callback.apply(getGlobal(), args); }
),
timeout,
Ci.nsITimer.TYPE_ONE_SHOT
)).id;
}
function clearTimeout(aId)
{
Timer.cancel(aId);
}
function setInterval()
{
var args = Array.slice(arguments);
var callback = args.shift();
var interval = args.shift();
return (new Timer(
(typeof callback == 'string' ?
callback :
function() { callback.apply(getGlobal(), args); }
),
interval,
Ci.nsITimer.TYPE_REPEATING_SLACK
)).id;
}
function clearInterval(aId)
{
Timer.cancel(aId);
}
function Timer(aCallback, aTime, aType) {
this.finished = false;
this.callback = aCallback;
this.type = aType;
this.init(aTime);
Timer.instances[this.id] = this;
}
Timer.prototype = {
init : function(aTime, aType)
{
this.id = parseInt(Math.random() * 65000)
this.timer = Cc['@mozilla.org/timer;1']
.createInstance(Ci.nsITimer);
this.timer.init(this, aTime, this.type);
},
cancel : function()
{
if (!this.timer) return;
delete this.timer;
delete this.callback;
this.finished = true;
delete Timer.instances[this.id];
},
observe : function(aSubject, aTopic, aData)
{
if (aTopic != 'timer-callback') return;
if (typeof this.callback == 'function')
this.callback();
else
evalInSandbox(this.callback);
if (this.type == Ci.nsITimer.TYPE_ONE_SHOT)
this.cancel();
}
};
Timer.instances = {};
Timer.cancel = function(aId) {
var timer = this.getInstanceById(aId);
if (timer)
timer.cancel();
};
Timer.getInstanceById = function(aId) {
return this.instances[aId] || null ;
};
function evalInSandbox(aCode, aSandboxOwner)
{
var sandbox = new Components.utils.Sandbox(aSandboxOwner || 'about:blank');
return Components.utils.evalInSandbox(aCode, sandbox);
}
function getGlobal()
{
return (function() { return this; })();
}

View File

@ -41,13 +41,12 @@ var Ci = Components.interfaces;
Components.utils.import('resource://treestyletab-modules/prefs.js');
Components.utils.import('resource://treestyletab-modules/boxObject.js');
Components.utils.import('resource://treestyletab-modules/stringBundle.js');
Components.utils.import('resource://treestyletab-modules/extensions.js');
Components.utils.import('resource://treestyletab-modules/animationManager.js');
Components.utils.import('resource://treestyletab-modules/autoScroll.js');
Components.utils.import('resource://treestyletab-modules/namespace.jsm');
var window = getNamespaceFor('piro.sakura.ne.jp');
var prefs = window['piro.sakura.ne.jp'].prefs;
var boxObject = window['piro.sakura.ne.jp'].boxObject;
var stringBundle = window['piro.sakura.ne.jp'].stringBundle;
var TreeStyleTabUtils = {
tabsHash : null,
@ -231,14 +230,18 @@ var TreeStyleTabUtils = {
_Comparator : null,
get treeBundle() {
return stringBundle
return window['piro.sakura.ne.jp'].stringBundle
.get('chrome://treestyletab/locale/treestyletab.properties');
},
get tabbrowserBundle() {
return stringBundle
return window['piro.sakura.ne.jp'].stringBundle
.get('chrome://browser/locale/tabbrowser.properties');
},
get extensions() { return window['piro.sakura.ne.jp'].extensions; },
get animationManager() { return window['piro.sakura.ne.jp'].animationManager; },
get autoScroll() { return window['piro.sakura.ne.jp'].autoScroll; },
init : function TSTUtils_init()
{
if (this._initialized) return;
@ -301,7 +304,7 @@ var TreeStyleTabUtils = {
getBoxObjectFor : function TSTUtils_getBoxObjectFor(aNode)
{
return boxObject.getBoxObjectFor(aNode);
return window['piro.sakura.ne.jp'].boxObject.getBoxObjectFor(aNode);
},
evalInSandbox : function TSTUtils_evalInSandbox(aCode, aOwner)
@ -1870,5 +1873,5 @@ var TreeStyleTabUtils = {
};
TreeStyleTabUtils.__proto__ = prefs;
TreeStyleTabUtils.__proto__ = window['piro.sakura.ne.jp'].prefs;