From 0baac4cc622adb73eed89141cf06e0424f902184 Mon Sep 17 00:00:00 2001 From: piro Date: Tue, 22 Jun 2010 09:38:42 +0000 Subject: [PATCH] =?UTF-8?q?namespace.jsm=E3=82=92=E4=BD=BF=E3=81=A3?= =?UTF-8?q?=E3=81=A6=E3=81=BF=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@6681 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- modules/boxObject.js | 3 ++- modules/namespace.jsm | 46 +++++++++++++++++++++++++++++++++++++++++ modules/prefs.js | 3 ++- modules/stringBundle.js | 3 ++- modules/utils.js | 17 +++++++-------- 5 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 modules/namespace.jsm diff --git a/modules/boxObject.js b/modules/boxObject.js index 2c02a8e8..2da053b1 100644 --- a/modules/boxObject.js +++ b/modules/boxObject.js @@ -1,5 +1,6 @@ var EXPORTED_SYMBOLS = ['window']; -var window = {}; +Components.utils.import('resource://treestyletab-modules/namespace.jsm'); +var window = getNamespaceFor('piro.sakura.ne.jp'); /* "getBoxObjectFor()" compatibility library for Firefox 3.6 or later diff --git a/modules/namespace.jsm b/modules/namespace.jsm new file mode 100644 index 00000000..217d46bc --- /dev/null +++ b/modules/namespace.jsm @@ -0,0 +1,46 @@ +/* + Shared Namespace Library for JavaScript Code Modules + + Usage: + Components.utils.import('resource://my-modules/namespace.jsm'); + var namespace = getNamespaceFor('mylibrary'); + namespace.func1 = function() { ... }; + namespace.func2 = function() { ... }; + var EXPORTED_SYMBOLS = ['func1', 'func2']; + var func1 = namespace.func1; + var func2 = namespace.func2; + + 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/namespace.js +*/ + +var EXPORTED_SYMBOLS = ['getNamespaceFor']; + +const Cc = Components.classes; +const Ci = Components.interfaces; + +const currentRevision = 1; + +var hiddenWindow = Cc['@mozilla.org/appshell/appShellService;1'] + .getService(Ci.nsIAppShellService) + .hiddenDOMWindow; + +if (!('piro.sakura.ne.jp' in hiddenWindow)) + hiddenWindow['piro.sakura.ne.jp'] = {}; + +var namespaces = hiddenWindow['piro.sakura.ne.jp'].sharedNameSpaces || {}; +if (!('sharedNameSpaces' in hiddenWindow['piro.sakura.ne.jp'])) + hiddenWindow['piro.sakura.ne.jp'].sharedNameSpaces = namespaces; + +function getNamespaceFor(aName) +{ + if (!aName) + throw new Error('you must specify the name of the namespace!'); + + if (!(aName in namespaces)) + namespaces[aName] = {}; + + return namespaces[aName]; +} diff --git a/modules/prefs.js b/modules/prefs.js index 309e1706..0cad9286 100644 --- a/modules/prefs.js +++ b/modules/prefs.js @@ -1,5 +1,6 @@ var EXPORTED_SYMBOLS = ['window']; -var window = {}; +Components.utils.import('resource://treestyletab-modules/namespace.jsm'); +var window = getNamespaceFor('piro.sakura.ne.jp'); /* Preferences Library diff --git a/modules/stringBundle.js b/modules/stringBundle.js index caf72df0..4752bb19 100644 --- a/modules/stringBundle.js +++ b/modules/stringBundle.js @@ -1,5 +1,6 @@ var EXPORTED_SYMBOLS = ['window']; -var window = {}; +Components.utils.import('resource://treestyletab-modules/namespace.jsm'); +var window = getNamespaceFor('piro.sakura.ne.jp'); /* string bundle utility diff --git a/modules/utils.js b/modules/utils.js index 905113f3..8c0f86f7 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -38,17 +38,16 @@ var EXPORTED_SYMBOLS = ['TreeStyleTabUtils']; var Cc = Components.classes; var Ci = Components.interfaces; -var prefs = {}; -Components.utils.import('resource://treestyletab-modules/prefs.js', prefs); -prefs = prefs.window['piro.sakura.ne.jp'].prefs; +Components.utils.import('resource://treestyletab-modules/prefs.js'); +Components.utils.import('resource://treestyletab-modules/boxObject.js'); +Components.utils.import('resource://treestyletab-modules/stringBundle.js'); -var boxObject = {}; -Components.utils.import('resource://treestyletab-modules/boxObject.js', boxObject); -boxObject = boxObject.window['piro.sakura.ne.jp'].boxObject; +Components.utils.import('resource://treestyletab-modules/namespace.jsm'); +var window = getNamespaceFor('piro.sakura.ne.jp'); -var stringBundle = {}; -Components.utils.import('resource://treestyletab-modules/stringBundle.js', stringBundle); -stringBundle = stringBundle.window['piro.sakura.ne.jp'].stringBundle; +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,