diff options
author | Einar Egilsson | 2009-05-09 20:46:48 +0000 |
---|---|---|
committer | Einar Egilsson | 2009-05-09 20:46:48 +0000 |
commit | 612e652d4a9feac5331c0262bbe6d234df3542e7 (patch) | |
tree | b62a5821f9188454db189c033127263e3c48ffd5 /chrome/content/redirectList.js | |
parent | 385393f45b40ad4bb67ec245388e271cf51f4994 (diff) |
1.7 start
git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@209 119bf307-c92d-0410-89bd-8f53e6181181
Diffstat (limited to 'chrome/content/redirectList.js')
-rw-r--r-- | chrome/content/redirectList.js | 50 |
1 files changed, 41 insertions, 9 deletions
diff --git a/chrome/content/redirectList.js b/chrome/content/redirectList.js index 1e61067..c50583b 100644 --- a/chrome/content/redirectList.js +++ b/chrome/content/redirectList.js @@ -1,3 +1,10 @@ + +var Redirector = Components.classes["@einaregilsson.com/redirector;1"].getService(Components.interfaces.nsISupports).wrappedJSObject; + +function $(id) { + return document.getElementById(id); +} + var RedirectList = { id : "redirector@einaregilsson.com", @@ -26,11 +33,8 @@ var RedirectList = { onLoad : function() { try { - RedirLib.initialize(this); - Redirector.init(); - this.lstRedirects = $('lstRedirects'); - this.lstRedirects.selType = 'single'; //For fx3 + this.lstRedirects.selType = 'single'; this.template = document.getElementsByTagName('richlistitem')[0]; this.lstRedirects.removeChild(this.template); this.btnDelete = $('btnDelete'); @@ -44,10 +48,41 @@ var RedirectList = { close : function() { window.close(); }, + + moveUp : function(){ + if (this.lstRedirects.selectedIndex <= 0) { + return; + } + this.switchItems(this.lstRedirects.selectedIndex-1); + }, + moveDown : function() { + if (this.lstRedirects.selectedIndex == Redirector.list.length-1) { + return; + } + this.switchItems(this.lstRedirects.selectedIndex); + }, + + switchItems : function(firstIndex) { + var first = Redirector.list[firstIndex]; + var second = Redirector.list[firstIndex+1]; + Redirector.list[firstIndex] = second; + Redirector.list[firstIndex+1] = first; + this.setListItemValues(this.lstRedirects.children[firstIndex+1], first); + this.setListItemValues(this.lstRedirects.children[firstIndex], second); + this.lstRedirects.selectedIndex -= 1; + Redirector.save(); + }, + + setListItemValues : function(listItem, item){ + listItem.getElementsByAttribute('name', 'dscrIncludePattern')[0].setAttribute('value', item.pattern); + listItem.getElementsByAttribute('name', 'dscrExcludePattern')[0].setAttribute('value', item.excludePattern); + listItem.getElementsByAttribute('name', 'dscrRedirectTo')[0].setAttribute('value', item.redirectUrl); + }, + addRedirect : function() { - var item = { pattern : '', exampleUrl : '', redirectUrl : '', onlyIfLinkExists : false, patternType : 'W'}; + var item = { pattern : '', exampleUrl : '', redirectUrl : '', patternType : 'W'}; window.openDialog("chrome://redirector/content/redirect.xul", "redirect", @@ -75,12 +110,9 @@ var RedirectList = { "chrome,dialog,modal,centerscreen", item); if (item.saved) { - listItem.getElementsByAttribute('name', 'dscrIncludePattern')[0].setAttribute('value', item.pattern); - listItem.getElementsByAttribute('name', 'dscrExcludePattern')[0].setAttribute('value', item.excludePattern); - listItem.getElementsByAttribute('name', 'dscrRedirectTo')[0].setAttribute('value', item.redirectUrl); + this.setListItemValues(listItem, item); Redirector.save(); } - }, deleteRedirect : function() { |