diff options
author | Einar Egilsson | 2007-05-28 23:17:52 +0000 |
---|---|---|
committer | Einar Egilsson | 2007-05-28 23:17:52 +0000 |
commit | f77a93fe56b90c89d3a881d9af84d43e451efe8d (patch) | |
tree | c7be0b2a34e2e7566961793d7168f698ae96240a /chrome | |
parent | ca4130f47bbe7f461dc1bc29d4aebb2dec305677 (diff) |
git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@56 119bf307-c92d-0410-89bd-8f53e6181181
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/content/overlay.js | 101 | ||||
-rw-r--r-- | chrome/content/redirectList.js | 29 | ||||
-rw-r--r-- | chrome/content/redirectList.xul | 4 | ||||
-rw-r--r-- | chrome/content/redirector.js | 2 |
4 files changed, 123 insertions, 13 deletions
diff --git a/chrome/content/overlay.js b/chrome/content/overlay.js new file mode 100644 index 0000000..9092938 --- /dev/null +++ b/chrome/content/overlay.js @@ -0,0 +1,101 @@ +//// $Id$ + +var RedirectorOverlay = { + + id : "redirector@einaregilsson.com", + name : "Redirector", + initialized : false, + strings : null, + + onLoad : function(event) { + try { + + // initialization code + RedirLib.initialize(this); + RedirLib.debug("Initializing..."); + + $('contentAreaContextMenu') + .addEventListener("popupshowing", function(e) { RedirectorOverlay.showContextMenu(e); }, false); + + Redirector.init(); + + var appcontent = window.document.getElementById('appcontent'); + + if (appcontent && !appcontent.processed) { + appcontent.processed = true; + + appcontent.addEventListener('DOMContentLoaded', function(event) { + + RedirectorOverlay.onDOMContentLoaded(event); + + }, false); + } + this.strings = document.getElementById("redirector-strings"); + + RedirLib.debug("Finished initialization"); + this.initialized = true; + + } catch(e) { + //Don't use RedirLib because it's initialization might have failed. + if (this.strings) { + alert(this.strings.getString("initError")._(this.name) + "\n\n" + e); + } else { + alert(e); + } + } + }, + + onDOMContentLoaded : function(event) { + var redirect, link, links, url; + + if (event.target != window.content.document) { + return; + } + + url = window.content.location.href; + + RedirLib.debug('Processing url %1'._(url)); + Redirector.processUrl(url); + }, + + + onUnload : function(event) { + //Clean up here + RedirLib.debug("Finished cleanup"); + }, + + showContextMenu : function(event) { + if (gContextMenu.onLink) { + $("redirector-context").label = this.strings.getString('addLinkUrl'); + } else { + $("redirector-context").label = this.strings.getString('addCurrentUrl'); + } + }, + + onContextMenuCommand: function(event) { + + params = { inn : { url : window.content.location.href}, out : {} }; + if (gContextMenu.onLink) { + params.inn.redirect = gContextMenu.link.toString(); + } + + window.openDialog("chrome://redirector/content/redirect.xul", + "redirect", + "chrome,dialog,modal,centerscreen", params); + + if (params.out.pattern) { + Redirector.addRedirect(params.out); + } + + }, + + onMenuItemCommand: function(event) { + window.openDialog("chrome://redirector/content/redirectList.xul", + "redirectList", + "chrome,dialog,modal,centerscreen", this); + + }, + +}; +window.addEventListener("load", function(event) { RedirectorOverlay.onLoad(event); }, false); +window.addEventListener("unload", function(event) { RedirectorOverlay.onUnload(event); }, false);
\ No newline at end of file diff --git a/chrome/content/redirectList.js b/chrome/content/redirectList.js index 522fa20..7a273cd 100644 --- a/chrome/content/redirectList.js +++ b/chrome/content/redirectList.js @@ -1,30 +1,41 @@ var RedirectList = { + id : "redirector@einaregilsson.com", + name : "Redirector", addItemsToListBox : function(items) { - var list = document.getElementById('foo'); + var list = $('lstRedirects'); var item, row, value; for each (item in items) { - row = document.createElement('listitem'); - for each (value in item) { - cell = document.createElement('listcell'); - cell.setAttribute('label',value); - cell.setAttribute('value',value); - row.appendChild(cell); - } + this.createCell(row, item.exampleUrl); + this.createCell(row, item.pattern); + this.createCell(row, item.redirectUrl); + this.createCell(row, item.onlyIfLinkExists); list.appendChild(row); } }, + createCell : function(row, value) { + var cell = document.createElement('listcell'); + cell.setAttribute('label', value); + cell.setAttribute('value', value); + row.appendChild(cell); + }, onLoad : function() { - addItemsToList(items); + try { + RedirLib.initialize(this); + Redirector.init(); + this.addItemsToListBox(Redirector.list); + } catch(e) { + alert(e); + } } }; diff --git a/chrome/content/redirectList.xul b/chrome/content/redirectList.xul index 163703e..3c0b687 100644 --- a/chrome/content/redirectList.xul +++ b/chrome/content/redirectList.xul @@ -10,13 +10,13 @@ xmlns:nc="http://home.netscape.com/NC-rdf#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
- <script type="application/x-javascript" src="common.js"/>
<script type="application/x-javascript" src="redirlib.js"/>
+ <script type="application/x-javascript" src="redirector.js"/>
<script type="application/x-javascript" src="redirectList.js"/>
<dialogheader title="&header;" description="&header.description;"/>
- <listbox id="foo">
+ <listbox id="lstRedirects">
<listhead>
<listheader label="&colPattern.label;"/>
diff --git a/chrome/content/redirector.js b/chrome/content/redirector.js index 73d59fa..63ee85d 100644 --- a/chrome/content/redirector.js +++ b/chrome/content/redirector.js @@ -17,7 +17,6 @@ var Redirector = { for each (r in this.list) { tempList.push([r.exampleUrl, r.pattern, r.redirectUrl, r.onlyIfLinkExists, r.patternType]); } - alert(tempList.toSource()); RedirLib.setCharPref('redirects', tempList.toSource()); }, @@ -41,7 +40,6 @@ var Redirector = { addRedirect : function(redirect) { this.list.push(redirect); - alert(redirect.toSource()); this.save(); }, |