aboutsummaryrefslogtreecommitdiff
path: root/chrome/content/redirectList.js
diff options
context:
space:
mode:
authorEinar Egilsson2008-01-01 21:40:32 +0000
committerEinar Egilsson2008-01-01 21:40:32 +0000
commit0ee5f981f3e708246674d26f8a26fc9b6d8f5fc9 (patch)
treecec3968640052197f028f4701f94ac7689f3e06a /chrome/content/redirectList.js
parentd30ede45e7ff0624ca4a1bcc565c344a6df23ee2 (diff)
git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@101 119bf307-c92d-0410-89bd-8f53e6181181
Diffstat (limited to 'chrome/content/redirectList.js')
-rw-r--r--chrome/content/redirectList.js62
1 files changed, 26 insertions, 36 deletions
diff --git a/chrome/content/redirectList.js b/chrome/content/redirectList.js
index 4680075..30bb64e 100644
--- a/chrome/content/redirectList.js
+++ b/chrome/content/redirectList.js
@@ -9,42 +9,35 @@ var RedirectList = {
addItemsToListBox : function(items) {
var list = $('lstRedirects');
- var item, row, value;
-
+ var item, row, value, newItem;
+
for each (item in items) {
- row = this.createRow(item);
- list.appendChild(row);
- }
- },
-
- createCell : function(row, value) {
- var cell = document.createElement('listcell');
- cell.setAttribute('label', value);
- cell.setAttribute('value', value);
- row.appendChild(cell);
- },
-
- createRow : function(item) {
- var row = document.createElement('listitem');
-
- this.createCell(row, item.pattern);
- this.createCell(row, item.exampleUrl);
- this.createCell(row, item.redirectUrl);
- this.createCell(row, item.onlyIfLinkExists);
- this.createCell(row, item.patternType);
+ newItem = this.template.cloneNode(true);
- row.item = item;
- return row;
+ newItem.getElementsByAttribute('name', 'dscrIncludePattern')[0].setAttribute('value', item.pattern);
+ newItem.getElementsByAttribute('name', 'dscrExcludePattern')[0].setAttribute('value', item.excludePattern);
+ newItem.getElementsByAttribute('name', 'dscrRedirectTo')[0].setAttribute('value', item.redirectUrl);
+ newItem.item = item;
+ list.appendChild(newItem);
+ }
+ if (list.children.length > 0) {
+ list.selectedIndex = 0;
+ }
+ list.clearSelection();
},
onLoad : function() {
try {
RedirLib.initialize(this);
Redirector.init();
+
this.lstRedirects = $('lstRedirects');
+ this.template = document.getElementsByTagName('richlistitem')[0];
+ this.lstRedirects.removeChild(this.template);
this.btnDelete = $('btnDelete');
this.btnEdit = $('btnEdit');
this.addItemsToListBox(Redirector.list);
+ this.lstRedirects.selectedIndex = -1;
} catch(e) {
alert(e);
}
@@ -63,8 +56,7 @@ var RedirectList = {
"chrome,dialog,modal,centerscreen", item);
if (item.saved) {
- var row = this.createRow(item);
- $('lstRedirects').appendChild(row);
+ this.addItemsToListBox([item]);
Redirector.addRedirect(item);
}
@@ -85,13 +77,9 @@ var RedirectList = {
"chrome,dialog,modal,centerscreen", item);
if (item.saved) {
- var map = [item.pattern, item.exampleUrl, item.redirectUrl, item.onlyIfLinkExists, item.patternType];
-
- for (var i in map) {
- listItem.childNodes[i].setAttribute('value', map[i]);
- listItem.childNodes[i].setAttribute('label', map[i]);
- }
-
+ 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);
Redirector.save();
}
@@ -105,9 +93,11 @@ var RedirectList = {
}
try {
- this.lstRedirects.removeItemAt(index);
- Redirector.deleteAt(index);
- } catch(e) {alert(e);}
+ this.lstRedirects.removeChild(this.lstRedirects.children[index]);
+ Redirector.deleteAt(index);
+ } catch(e) {
+ alert(e);
+ }
},
selectionChange : function() {