From 612e652d4a9feac5331c0262bbe6d234df3542e7 Mon Sep 17 00:00:00 2001 From: Einar Egilsson Date: Sat, 9 May 2009 20:46:48 +0000 Subject: 1.7 start git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@209 119bf307-c92d-0410-89bd-8f53e6181181 --- chrome/content/redirectList.js | 50 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'chrome/content/redirectList.js') 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() { -- cgit v1.2.3-70-g09d2