diff options
-rw-r--r-- | chrome/css/redirector.css | 13 | ||||
-rw-r--r-- | chrome/js/redirector-ui.js | 9 | ||||
-rw-r--r-- | chrome/js/redirector.js | 31 | ||||
-rw-r--r-- | chrome/js/xpcom.js | 6 | ||||
-rw-r--r-- | chrome/redirector.html | 4 |
5 files changed, 35 insertions, 28 deletions
diff --git a/chrome/css/redirector.css b/chrome/css/redirector.css index 382b6a9..7903171 100644 --- a/chrome/css/redirector.css +++ b/chrome/css/redirector.css @@ -10,7 +10,7 @@ html { margin:0; padding:0; } -h1 { font-family: ; text-align:center; color:#555; text-shadow:0px 0px 15px white; font-size:34pt; padding:0px; margin:20px 0px 0px 0px; letter-spacing:2px; } +h1 { text-align:center; color:#555; text-shadow:0px 0px 15px white; font-size:34pt; padding:0px; margin:20px 0px 0px 0px; letter-spacing:2px; } label { display:table-cell; } input { display:table-cell; } li { margin:0; padding:5px; border-top: dotted 1px grey;} @@ -47,6 +47,17 @@ h5 { text-align:center; margin:0px; padding-left:130px; } #redirect-form div input[type='text']{ margin-top:7px; width:300px; display:inline-block; } .button-row { text-align:center; display:block !important;} + +.dialog { + background:-moz-linear-gradient(top,#fff, #AFCFFE); + border-radius:8px; + display:none; + position:fixed; + margin:0 auto; + padding:10px; + box-shadow: 0px 0px 4px black; +} + #redirect-form { background:-moz-linear-gradient(top,#fff, #AFCFFE); border-radius:8px; diff --git a/chrome/js/redirector-ui.js b/chrome/js/redirector-ui.js index 3152718..30af176 100644 --- a/chrome/js/redirector-ui.js +++ b/chrome/js/redirector-ui.js @@ -28,7 +28,6 @@ function validateRedirect(redirect) { if (!result.isMatch) { title = tr('warningExampleUrlDoesntMatchPatternTitle'); msg = tr('warningExampleUrlDoesntMatchPattern'); - var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); var rv = PromptService.confirmEx(window, title, msg, PromptService.STD_YES_NO_BUTTONS, PromptService.BUTTON_TITLE_YES, PromptService.BUTTON_TITLE_NO, null, null, {}); return rv == 0; } else { @@ -38,10 +37,10 @@ function validateRedirect(redirect) { resultUrl = uri.resolve(resultUrl); } - var secondResult = args.redirect.getMatch(resultUrl); + var secondResult = redirect.getMatch(resultUrl); if (secondResult.isMatch) { - title = this.strings.getString('errorExampleUrlMatchesRecursiveTitle'); - msg = this.strings.getFormattedString('errorExampleUrlMatchesRecursive', [args.redirect.exampleUrl, resultUrl]); + title = tr('errorExampleUrlMatchesRecursiveTitle'); + msg = tr('errorExampleUrlMatchesRecursive', [redirect.exampleUrl, resultUrl]); alert(title, msg); return false; } @@ -179,7 +178,7 @@ function saveRedirect() { } function configure() { - $('#config').show(); + $('#config').center().css('top', '-=40px').show(); } function bindConfig() { $('#config input[type="checkbox"]').each(function() { diff --git a/chrome/js/redirector.js b/chrome/js/redirector.js index 21268e6..14468b6 100644 --- a/chrome/js/redirector.js +++ b/chrome/js/redirector.js @@ -36,7 +36,7 @@ Redirector = { debug : function(msg) { if (this._prefs.debugEnabled) { - this._cout.logStringMessage('REDIRECTOR: ' + msg); + ConsoleService.logStringMessage('REDIRECTOR: ' + msg); } }, @@ -46,14 +46,12 @@ Redirector = { }, exportRedirects : function(file) { - var fileStream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream); const PR_WRONLY = 0x02; const PR_CREATE_FILE = 0x08; const PR_TRUNCATE = 0x20; - fileStream.init(file, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0644, 0); - var stream = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream); - stream.init(fileStream, "UTF-8", 16384, Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER); + var fileStream = new FileOutputStream(file, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0644, 0); + var stream = new ConverterOutputStream(fileStream, "UTF-8", 16384, Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER); var rjson = { createdBy : 'Redirector v' + this._prefs.version, createdAt : new Date(), redirects :[]}; for each (var re in this._list) { rjson.redirects.push(re.toObject()); @@ -106,13 +104,13 @@ Redirector = { }, _getRedirectsFile : function() { - var file = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile); + var file = DirectoryService.get("ProfD", Ci.nsIFile); file.append('redirector.rjson'); return file; }, handleUpgrades : function(){ - var currentVersion = '2.6'; + var currentVersion = '3.0'; this._list = []; if (this._prefs.version == currentVersion) { @@ -121,7 +119,7 @@ Redirector = { //Here update checks are handled try { - var branch = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).getBranch("extensions.redirector."); + var branch = PrefService.getBranch("extensions.redirector."); var data = branch.getCharPref("redirects"); } catch(e) { this._prefs.version = currentVersion; @@ -294,13 +292,12 @@ Redirector = { _prefs : null, _list : null, _strings : null, - _cout : Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService), init : function() { if (this._prefs) { this._prefs.dispose(); } - this._cout.logStringMessage('REDIRECTOR CREATED'); + ConsoleService.logStringMessage('REDIRECTOR CREATED'); this._prefs = new RedirectorPrefs(); //Check if we need to update existing redirects var data = this._prefs.redirects; @@ -321,10 +318,8 @@ Redirector = { _loadStrings : function() { var src = 'chrome://redirector/locale/redirector.properties'; - var localeService = Cc["@mozilla.org/intl/nslocaleservice;1"].getService(Ci.nsILocaleService); - var appLocale = localeService.getApplicationLocale(); - var stringBundleService = Cc["@mozilla.org/intl/stringbundle;1"].getService(Ci.nsIStringBundleService); - this._strings = stringBundleService.createBundle(src, appLocale); + var appLocale = LocaleService.getApplicationLocale(); + this._strings = StringBundleService.createBundle(src, appLocale); }, _containsRedirect : function(redirect) { @@ -345,9 +340,7 @@ Redirector = { }, _msgBox : function(title, text) { - Cc["@mozilla.org/embedcomp/prompt-service;1"] - .getService(Ci.nsIPromptService) - .alert(null, title, text); + PromptService.alert(null, title, text); }, _makeAbsoluteUrl : function(currentUrl, relativeUrl) { @@ -356,9 +349,7 @@ Redirector = { return relativeUrl; } - var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); - var uri = ioService.newURI(currentUrl, null, null); - + var uri = IOService.newURI(currentUrl, null, null); return uri.resolve(relativeUrl); } }; diff --git a/chrome/js/xpcom.js b/chrome/js/xpcom.js index e81f58e..2d18ff3 100644 --- a/chrome/js/xpcom.js +++ b/chrome/js/xpcom.js @@ -7,10 +7,13 @@ const ServerSocket = Components.Constructor("@mozilla.org/network/server-socket; const ScriptableInputStream = Components.Constructor("@mozilla.org/scriptableinputstream;1", "nsIScriptableInputStream", "init"); const FileInputStream = Components.Constructor("@mozilla.org/network/file-input-stream;1", "nsIFileInputStream", "init"); const ConverterInputStream = Components.Constructor("@mozilla.org/intl/converter-input-stream;1", "nsIConverterInputStream", "init"); +const FileOutputStream = Components.Constructor("@mozilla.org/network/file-output-stream;1", "nsIFileOutputStream", "init"); +const ConverterOutputStream = Components.Constructor("@mozilla.org/intl/converter-output-stream;1", "nsIConverterOutputStream", "init"); const LocalFile = Components.Constructor("@mozilla.org/file/local;1", "nsILocalFile", "initWithPath"); const FilePicker = Components.Constructor("@mozilla.org/filepicker;1", "nsIFilePicker", "init"); const FilePickerMode = { save : Ci.nsIFilePicker.modeSave, open : Ci.nsIFilePicker.modeOpen }; + function Service(className, interfaceName) { return Cc[className].getService(Ci[interfaceName]); } @@ -19,6 +22,9 @@ const PromptService = Service("@mozilla.org/embedcomp/prompt-service;1","nsIProm const IOService = Service("@mozilla.org/network/io-service;1","nsIIOService"); const LocaleService = Service("@mozilla.org/intl/nslocaleservice;1", "nsILocaleService"); const StringBundleService = Service("@mozilla.org/intl/stringbundle;1", "nsIStringBundleService"); +const ConsoleService = Service("@mozilla.org/consoleservice;1", "nsIConsoleService"); +const PrefServie = Service("@mozilla.org/preferences-service;1", "nsIPrefService"); +const DirectoryService = Service("@mozilla.org/file/directory_service;1", "nsIProperties"); var EXPORTED_SYMBOLS = []; for (var name in this) { diff --git a/chrome/redirector.html b/chrome/redirector.html index 54676f1..8af747e 100644 --- a/chrome/redirector.html +++ b/chrome/redirector.html @@ -25,14 +25,14 @@ </div> </li> </ul> - <div id="config"> + <div id="config" class="dialog"> <h2>Configuration</h2> <input type="checkbox" id="enable-redirector" data-pref="enabled" /><label>Enabled</label> <input type="checkbox" id="show-status-bar-icon" data-pref="showStatusBarIcon"/><label>Statusbar icon</label> <input type="checkbox" id="show-context-menu" data-pref="showContextMenu"/><label>Context menu</label> <input type="checkbox" id="enable-debug-output" data-pref="debugEnabled"/><label>Debug output</label> </div> - <div id="redirect-form"> + <div id="redirect-form" class="dialog"> <div> <label>Description</label> <input type="text" id="description" /> |