Permalink
Browse files

make the redlinks more efficient and robust

  • Loading branch information...
1 parent 2ed7124 commit 25b0267d5078e75e191dada52f043de54eab2adf @jchris jchris committed Jul 31, 2010
Showing with 18 additions and 16 deletions.
  1. +18 −16 evently/wiki/_init.js
View
@@ -2,26 +2,28 @@ function() {
var wiki = $(this), app = $$(wiki).app, m, pages = {}, keys = [];
$("a",wiki).each(function() {
m = this.href.match(/.*\/page\/([^\/]+)$/);
- if (m[1]) {
+ if (m && m[1]) {
pages[m[1]] = true;
}
});
// unique keys will be faster on big pages
for (m in pages) {
keys.push(m);
}
- app.view("all-pages", {
- keys : keys,
- success : function(resp) {
- var i, p;
- for (i=0; i < resp.rows.length; i++) {
- p = resp.rows[i].key;
- delete pages[p];
- };
- for (m in pages) {
- $("a[href='"+m+"']", wiki).addClass("missing");
- }
- },
- error : function() {}
- });
-};
+ if (keys.length > 0) {
+ app.view("all-pages", {
+ keys : keys,
+ success : function(resp) {
+ var i, p;
+ for (i=0; i < resp.rows.length; i++) {
+ p = resp.rows[i].key;
+ delete pages[p];
+ }
+ for (m in pages) {
+ $("a[href='"+m+"']", wiki).addClass("missing");
+ }
+ },
+ error : function() {}
+ });
+ }
+};

0 comments on commit 25b0267

Please sign in to comment.