Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

catching up with javascript

  • Loading branch information...
commit 78da440f26b6dbc2054aa6e7a3081d401a3be22a 1 parent 2595103
Ward Cunningham authored
Showing with 152 additions and 337 deletions.
  1. +81 −187 client/client.js
  2. +71 −150 client/test/testclient.js
268 client/client.js
View
@@ -346,8 +346,8 @@ exports.extname = function(path) {
require.define("/lib/legacy.coffee", function (require, module, exports, __dirname, __filename) {
(function() {
- var active, pageHandler, plugin, refresh, resolveLinks, state, util,
- __slice = [].slice;
+ var active, pageHandler, plugin, refresh, resolveLinks, state, util;
+ var __slice = Array.prototype.slice;
window.wiki = {};
@@ -451,17 +451,13 @@ require.define("/lib/legacy.coffee", function (require, module, exports, __dirna
};
textEditor = wiki.textEditor = function(div, item, caretPos, doubleClicked) {
var original, textarea, _ref;
- if (div.hasClass('textEditing')) {
- return;
- }
+ if (div.hasClass('textEditing')) return;
div.addClass('textEditing');
textarea = $("<textarea>" + (original = (_ref = item.text) != null ? _ref : '') + "</textarea>").focusout(function() {
div.removeClass('textEditing');
if (item.text = textarea.val()) {
plugin["do"](div.empty(), item);
- if (item.text === original) {
- return;
- }
+ if (item.text === original) return;
pageHandler.put(div.parents('.page:first'), {
type: 'edit',
id: item.id,
@@ -485,31 +481,23 @@ require.define("/lib/legacy.coffee", function (require, module, exports, __dirna
sel = util.getSelectionPos(textarea);
if (e.which === $.ui.keyCode.BACKSPACE && sel.start === 0 && sel.start === sel.end) {
prevItem = getItem(div.prev());
- if (prevItem.type !== 'paragraph') {
- return false;
- }
+ if (prevItem.type !== 'paragraph') return false;
prevTextLen = prevItem.text.length;
prevItem.text += textarea.val();
textarea.val('');
textEditor(div.prev(), prevItem, prevTextLen);
return false;
} else if (e.which === $.ui.keyCode.ENTER && item.type === 'paragraph') {
- if (!sel) {
- return false;
- }
+ if (!sel) return false;
text = textarea.val();
prefix = text.substring(0, sel.start);
- if (sel.start !== sel.end) {
- middle = text.substring(sel.start, sel.end);
- }
+ if (sel.start !== sel.end) middle = text.substring(sel.start, sel.end);
suffix = text.substring(sel.end);
textarea.val(prefix);
textarea.focusout();
pageElement = div.parent().parent();
createTextElement(pageElement, div, suffix);
- if (middle != null) {
- createTextElement(pageElement, div, middle);
- }
+ if (middle != null) createTextElement(pageElement, div, middle);
return false;
}
}
@@ -560,13 +548,9 @@ require.define("/lib/legacy.coffee", function (require, module, exports, __dirna
}
};
doInternalLink = wiki.doInternalLink = function(name, page, site) {
- if (site == null) {
- site = null;
- }
+ if (site == null) site = null;
name = util.asSlug(name);
- if (page != null) {
- $(page).nextAll().remove();
- }
+ if (page != null) $(page).nextAll().remove();
wiki.createPage(name, site).appendTo($('.main')).each(refresh);
return active.set($('.page').last());
};
@@ -594,20 +578,14 @@ require.define("/lib/legacy.coffee", function (require, module, exports, __dirna
$(document).ajaxError(function(event, request, settings) {
var msg;
wiki.log('ajax error', event, request, settings);
- if (request.status === 0) {
- return;
- }
+ if (request.status === 0) return;
msg = "<li class='error'>Error on " + settings.url + ": " + request.responseText + "</li>";
- if (request.status !== 404) {
- return $('.main').prepend(msg);
- }
+ if (request.status !== 404) return $('.main').prepend(msg);
});
finishClick = function(e, name) {
var page;
e.preventDefault();
- if (!e.shiftKey) {
- page = $(e.target).parents('.page');
- }
+ if (!e.shiftKey) page = $(e.target).parents('.page');
doInternalLink(name, page, $(e.target).data('site'));
return false;
};
@@ -618,9 +596,7 @@ require.define("/lib/legacy.coffee", function (require, module, exports, __dirna
json = pageElement.data('data');
return wiki.dialog("JSON for " + json.title, $('<pre/>').text(JSON.stringify(json, null, 2)));
}).delegate('.page', 'click', function(e) {
- if (!$(e.target).is("a")) {
- return active.set(this);
- }
+ if (!$(e.target).is("a")) return active.set(this);
}).delegate('.internal', 'click', function(e) {
var name;
name = $(e.target).data('pageName');
@@ -651,18 +627,14 @@ require.define("/lib/legacy.coffee", function (require, module, exports, __dirna
$page = $(this).parents('.page');
slug = util.asSlug($page.data('data').title);
rev = $(this).parent().children().index($action);
- if (!e.shiftKey) {
- $page.nextAll().remove();
- }
+ if (!e.shiftKey) $page.nextAll().remove();
wiki.createPage("" + slug + "_rev" + rev, $page.data('site')).appendTo($('.main')).each(refresh);
return active.set($('.page').last());
}
}).delegate('.fork-page', 'click', function(e) {
var pageElement, remoteSite;
pageElement = $(e.target).parents('.page');
- if ((remoteSite = pageElement.data('site')) == null) {
- return;
- }
+ if ((remoteSite = pageElement.data('site')) == null) return;
return pageHandler.put(pageElement, {
type: 'fork',
site: remoteSite
@@ -789,24 +761,12 @@ require.define("/lib/util.coffee", function (require, module, exports, __dirname
if ((secs = msecs / 1000) < 2) {
return "" + (Math.floor(msecs)) + " milliseconds ago";
}
- if ((mins = secs / 60) < 2) {
- return "" + (Math.floor(secs)) + " seconds ago";
- }
- if ((hrs = mins / 60) < 2) {
- return "" + (Math.floor(mins)) + " minutes ago";
- }
- if ((days = hrs / 24) < 2) {
- return "" + (Math.floor(hrs)) + " hours ago";
- }
- if ((weeks = days / 7) < 2) {
- return "" + (Math.floor(days)) + " days ago";
- }
- if ((months = days / 31) < 2) {
- return "" + (Math.floor(weeks)) + " weeks ago";
- }
- if ((years = days / 365) < 2) {
- return "" + (Math.floor(months)) + " months ago";
- }
+ if ((mins = secs / 60) < 2) return "" + (Math.floor(secs)) + " seconds ago";
+ if ((hrs = mins / 60) < 2) return "" + (Math.floor(mins)) + " minutes ago";
+ if ((days = hrs / 24) < 2) return "" + (Math.floor(hrs)) + " hours ago";
+ if ((weeks = days / 7) < 2) return "" + (Math.floor(days)) + " days ago";
+ if ((months = days / 31) < 2) return "" + (Math.floor(weeks)) + " weeks ago";
+ if ((years = days / 365) < 2) return "" + (Math.floor(months)) + " months ago";
return "" + (Math.floor(years)) + " years ago";
};
@@ -814,9 +774,7 @@ require.define("/lib/util.coffee", function (require, module, exports, __dirname
return name.replace(/\s/g, '-').replace(/[^A-Za-z0-9-]/g, '').toLowerCase();
};
- if (typeof wiki !== "undefined" && wiki !== null) {
- wiki.asSlug = util.asSlug;
- }
+ if (typeof wiki !== "undefined" && wiki !== null) wiki.asSlug = util.asSlug;
util.emptyPage = function() {
return {
@@ -867,18 +825,10 @@ require.define("/lib/util.coffee", function (require, module, exports, __dirname
if ((page != null) && (page.story != null)) {
p1 = page.story[0];
p2 = page.story[1];
- if (p1 && p1.type === 'paragraph') {
- synopsis || (synopsis = p1.text);
- }
- if (p2 && p2.type === 'paragraph') {
- synopsis || (synopsis = p2.text);
- }
- if (p1) {
- synopsis || (synopsis = p1.text != null);
- }
- if (p2) {
- synopsis || (synopsis = p2.text != null);
- }
+ if (p1 && p1.type === 'paragraph') synopsis || (synopsis = p1.text);
+ if (p2 && p2.type === 'paragraph') synopsis || (synopsis = p2.text);
+ if (p1) synopsis || (synopsis = p1.text != null);
+ if (p2) synopsis || (synopsis = p2.text != null);
synopsis || (synopsis = (page.story != null) && ("A page with " + page.story.length + " items."));
} else {
synopsis = 'A page with no story.';
@@ -907,7 +857,7 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
if (json = localStorage[slug]) {
return JSON.parse(json);
} else {
- return void 0;
+ return;
}
};
@@ -920,9 +870,7 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
} else {
site = localContext.shift();
}
- if (site === 'view') {
- site = null;
- }
+ if (site === 'view') site = null;
if (site != null) {
if (site === 'local') {
if (localPage = pageFromLocalStorage(pageInformation.slug)) {
@@ -945,9 +893,7 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
dataType: 'json',
url: url + ("?random=" + (util.randomBytes(4))),
success: function(page) {
- if (rev) {
- page = revision.create(rev, page);
- }
+ if (rev) page = revision.create(rev, page);
return whenGotten(page, site);
},
error: function(xhr, type, msg) {
@@ -984,9 +930,7 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
var localPage, pageInformation, whenGotten, whenNotGotten;
whenGotten = _arg.whenGotten, whenNotGotten = _arg.whenNotGotten, pageInformation = _arg.pageInformation;
wiki.log('pageHandler.get', pageInformation.site, pageInformation.slug, pageInformation.rev, 'context', pageHandler.context.join(' => '));
- if (pageInformation.wasServerGenerated) {
- return whenGotten(null);
- }
+ if (pageInformation.wasServerGenerated) return whenGotten(null);
if (!pageInformation.site) {
if (localPage = pageFromLocalStorage(pageInformation.slug)) {
if (pageInformation.rev) {
@@ -995,9 +939,7 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
return whenGotten(localPage, 'local');
}
}
- if (!pageHandler.context.length) {
- pageHandler.context = ['view'];
- }
+ if (!pageHandler.context.length) pageHandler.context = ['view'];
return recursiveGet({
pageInformation: pageInformation,
whenGotten: whenGotten,
@@ -1017,9 +959,7 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
};
}
page || (page = pageElement.data("data"));
- if (page.journal == null) {
- page.journal = [];
- }
+ if (page.journal == null) page.journal = [];
if ((site = action['fork']) != null) {
page.journal = page.journal.concat({
'type': 'fork',
@@ -1083,9 +1023,7 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
}
}
action.date = (new Date()).getTime();
- if (action.site === 'origin') {
- delete action.site;
- }
+ if (action.site === 'origin') delete action.site;
if (forkFrom) {
pageElement.find('h1 img').attr('src', '/favicon.png');
pageElement.find('h1 a').attr('href', '/');
@@ -1114,8 +1052,8 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
require.define("/lib/state.coffee", function (require, module, exports, __dirname, __filename) {
(function() {
- var active, state,
- __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
+ var active, state;
+ var __hasProp = Object.prototype.hasOwnProperty, __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (__hasProp.call(this, i) && this[i] === item) return i; } return -1; };
active = require('./active');
@@ -1165,9 +1103,9 @@ require.define("/lib/state.coffee", function (require, module, exports, __dirnam
locs = state.locsInDom();
pages = state.pagesInDom();
url = ((function() {
- var _i, _len, _results;
+ var _len, _results;
_results = [];
- for (idx = _i = 0, _len = pages.length; _i < _len; idx = ++_i) {
+ for (idx = 0, _len = pages.length; idx < _len; idx++) {
page = pages[idx];
_results.push("/" + ((locs != null ? locs[idx] : void 0) || 'view') + "/" + page);
}
@@ -1180,22 +1118,18 @@ require.define("/lib/state.coffee", function (require, module, exports, __dirnam
};
state.show = function(e) {
- var idx, name, newLocs, newPages, old, oldLocs, oldPages, previous, _i, _len, _ref;
+ var idx, name, newLocs, newPages, old, oldLocs, oldPages, previous, _len, _ref;
oldPages = state.pagesInDom();
newPages = state.urlPages();
oldLocs = state.locsInDom();
newLocs = state.urlLocs();
- if (!location.pathname || location.pathname === '/') {
- return;
- }
+ if (!location.pathname || location.pathname === '/') return;
previous = $('.page').eq(0);
- for (idx = _i = 0, _len = newPages.length; _i < _len; idx = ++_i) {
+ for (idx = 0, _len = newPages.length; idx < _len; idx++) {
name = newPages[idx];
if (name !== oldPages[idx]) {
old = $('.page').eq(idx);
- if (old) {
- old.remove();
- }
+ if (old) old.remove();
wiki.createPage(name, newLocs[idx]).insertAfter(previous).each(wiki.refresh);
}
previous = $('.page').eq(idx);
@@ -1206,13 +1140,13 @@ require.define("/lib/state.coffee", function (require, module, exports, __dirnam
};
state.first = function() {
- var firstUrlLocs, firstUrlPages, idx, oldPages, urlPage, _i, _len, _results;
+ var firstUrlLocs, firstUrlPages, idx, oldPages, urlPage, _len, _results;
state.setUrl();
firstUrlPages = state.urlPages();
firstUrlLocs = state.urlLocs();
oldPages = state.pagesInDom();
_results = [];
- for (idx = _i = 0, _len = firstUrlPages.length; _i < _len; idx = ++_i) {
+ for (idx = 0, _len = firstUrlPages.length; idx < _len; idx++) {
urlPage = firstUrlPages[idx];
if (__indexOf.call(oldPages, urlPage) < 0) {
if (urlPage !== '') {
@@ -1292,7 +1226,7 @@ require.define("/lib/revision.coffee", function (require, module, exports, __dir
var create;
create = function(revIndex, data) {
- var afterIndex, editIndex, itemId, items, journal, journalEntry, removeIndex, revJournal, revStory, revStoryIds, revTitle, storyItem, _i, _j, _k, _len, _len1, _len2, _ref;
+ var afterIndex, editIndex, itemId, items, journal, journalEntry, removeIndex, revJournal, revStory, revStoryIds, revTitle, storyItem, _i, _j, _k, _len, _len2, _len3, _ref;
journal = data.journal;
revTitle = data.title;
revStory = [];
@@ -1325,13 +1259,13 @@ require.define("/lib/revision.coffee", function (require, module, exports, __dir
break;
case 'move':
items = [];
- for (_j = 0, _len1 = revStory.length; _j < _len1; _j++) {
+ for (_j = 0, _len2 = revStory.length; _j < _len2; _j++) {
storyItem = revStory[_j];
items[storyItem.id] = storyItem;
}
revStory = [];
_ref = journalEntry.order;
- for (_k = 0, _len2 = _ref.length; _k < _len2; _k++) {
+ for (_k = 0, _len3 = _ref.length; _k < _len3; _k++) {
itemId = _ref[_k];
revStory.push(items[itemId]);
}
@@ -1366,9 +1300,7 @@ require.define("/lib/plugin.coffee", function (require, module, exports, __dirna
scripts = {};
getScript = wiki.getScript = function(url, callback) {
- if (callback == null) {
- callback = function() {};
- }
+ if (callback == null) callback = function() {};
if (scripts[url] != null) {
return callback();
} else {
@@ -1382,13 +1314,9 @@ require.define("/lib/plugin.coffee", function (require, module, exports, __dirna
};
plugin.get = wiki.getPlugin = function(name, callback) {
- if (window.plugins[name]) {
- return callback(window.plugins[name]);
- }
+ if (window.plugins[name]) return callback(window.plugins[name]);
return getScript("/plugins/" + name + "/" + name + ".js", function() {
- if (window.plugins[name]) {
- return callback(window.plugins[name]);
- }
+ if (window.plugins[name]) return callback(window.plugins[name]);
return getScript("/plugins/" + name + ".js", function() {
return callback(window.plugins[name]);
});
@@ -1397,9 +1325,7 @@ require.define("/lib/plugin.coffee", function (require, module, exports, __dirna
plugin["do"] = wiki.doPlugin = function(div, item, done) {
var error;
- if (done == null) {
- done = function() {};
- }
+ if (done == null) done = function() {};
error = function(ex) {
var errorElement;
errorElement = $("<div />").addClass('error');
@@ -1517,11 +1443,7 @@ require.define("/lib/refresh.coffee", function (require, module, exports, __dirn
}) : moveToPage ? (itemElement.data('pageElement', thisPageElement), beforeElement = itemElement.prev('.item'), before = wiki.getItem(beforeElement), {
type: 'add',
item: item,
- after: before != null ? before.id : void 0,
- origin: {
- slug: sourcePageElement.attr("id"),
- site: sourceSite
- }
+ after: before != null ? before.id : void 0
}) : void 0;
action.id = item.id;
return pageHandler.put(thisPageElement, action);
@@ -1583,7 +1505,7 @@ require.define("/lib/refresh.coffee", function (require, module, exports, __dirn
};
wiki.buildPage = function(data, siteFound, pageElement) {
- var action, addContext, context, doItem, footerElement, journalElement, page, site, slug, storyElement, _i, _len, _ref, _ref1;
+ var action, addContext, context, doItem, footerElement, journalElement, page, site, slug, storyElement, _i, _len, _ref, _ref2;
if (siteFound === 'local') {
pageElement.addClass('local');
} else {
@@ -1603,13 +1525,9 @@ require.define("/lib/refresh.coffee", function (require, module, exports, __dirn
slug = $(pageElement).attr('id');
site = $(pageElement).data('site');
context = ['view'];
- if (site != null) {
- context.push(site);
- }
+ if (site != null) context.push(site);
addContext = function(site) {
- if ((site != null) && !_.include(context, site)) {
- return context.push(site);
- }
+ if ((site != null) && !_.include(context, site)) return context.push(site);
};
_ref = page.journal.slice(0).reverse();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -1619,18 +1537,14 @@ require.define("/lib/refresh.coffee", function (require, module, exports, __dirn
wiki.resolutionContext = context;
wiki.log('buildPage', slug, 'site', site, 'context', context.join(' => '));
emitHeader(pageElement, page);
- _ref1 = ['story', 'journal', 'footer'].map(function(className) {
+ _ref2 = ['story', 'journal', 'footer'].map(function(className) {
return $("<div />").addClass(className).appendTo(pageElement);
- }), storyElement = _ref1[0], journalElement = _ref1[1], footerElement = _ref1[2];
+ }), storyElement = _ref2[0], journalElement = _ref2[1], footerElement = _ref2[2];
doItem = function(i) {
var div, item;
- if (i >= page.story.length) {
- return;
- }
+ if (i >= page.story.length) return;
item = page.story[i];
- if ($.isArray(item)) {
- item = item[0];
- }
+ if ($.isArray(item)) item = item[0];
div = $("<div />").addClass("item").addClass(item.type).attr("data-id", item.id);
storyElement.append(div);
return plugin["do"](div, item, function() {
@@ -1677,23 +1591,21 @@ require.define("/lib/refresh.coffee", function (require, module, exports, __dirn
return wiki.buildPage(page, void 0, pageElement).addClass('ghost');
};
registerNeighbors = function(data, site) {
- var action, item, _i, _j, _len, _len1, _ref1, _ref2, _results;
+ var action, item, _i, _j, _len, _len2, _ref2, _ref3, _results;
if (_.include(['local', 'origin', 'view', null, void 0], site)) {
neighborhood.registerNeighbor(location.host);
} else {
neighborhood.registerNeighbor(site);
}
- _ref1 = data.story || [];
- for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
- item = _ref1[_i];
- if (item.site != null) {
- neighborhood.registerNeighbor(item.site);
- }
+ _ref2 = data.story || [];
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
+ item = _ref2[_i];
+ if (item.site != null) neighborhood.registerNeighbor(item.site);
}
- _ref2 = data.journal || [];
+ _ref3 = data.journal || [];
_results = [];
- for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
- action = _ref2[_j];
+ for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
+ action = _ref3[_j];
if (action.site != null) {
_results.push(neighborhood.registerNeighbor(action.site));
} else {
@@ -1719,8 +1631,8 @@ require.define("/lib/refresh.coffee", function (require, module, exports, __dirn
require.define("/lib/neighborhood.coffee", function (require, module, exports, __dirname, __filename) {
(function() {
- var active, createSearch, neighborhood, nextAvailableFetch, nextFetchInterval, populateSiteInfoFor, util, _ref,
- __hasProp = {}.hasOwnProperty;
+ var active, createSearch, neighborhood, nextAvailableFetch, nextFetchInterval, populateSiteInfoFor, util, _ref;
+ var __hasProp = Object.prototype.hasOwnProperty;
active = require('./active.coffee');
@@ -1730,9 +1642,7 @@ require.define("/lib/neighborhood.coffee", function (require, module, exports, _
module.exports = neighborhood = {};
- if ((_ref = wiki.neighborhood) == null) {
- wiki.neighborhood = {};
- }
+ if ((_ref = wiki.neighborhood) == null) wiki.neighborhood = {};
nextAvailableFetch = 0;
@@ -1740,9 +1650,7 @@ require.define("/lib/neighborhood.coffee", function (require, module, exports, _
populateSiteInfoFor = function(site, neighborInfo) {
var fetchMap, now, transition;
- if (neighborInfo.sitemapRequestInflight) {
- return;
- }
+ if (neighborInfo.sitemapRequestInflight) return;
neighborInfo.sitemapRequestInflight = true;
transition = function(site, from, to) {
return $(".neighbor[data-site=\"" + site + "\"]").find('div').removeClass(from).addClass(to);
@@ -1777,9 +1685,7 @@ require.define("/lib/neighborhood.coffee", function (require, module, exports, _
wiki.registerNeighbor = neighborhood.registerNeighbor = function(site) {
var neighborInfo;
- if (wiki.neighborhood[site] != null) {
- return;
- }
+ if (wiki.neighborhood[site] != null) return;
neighborInfo = {};
wiki.neighborhood[site] = neighborInfo;
populateSiteInfoFor(site, neighborInfo);
@@ -1791,7 +1697,7 @@ require.define("/lib/neighborhood.coffee", function (require, module, exports, _
};
neighborhood.search = function(searchQuery) {
- var finds, match, matchingPages, neighborInfo, neighborSite, sitemap, start, tally, tick, _ref1;
+ var finds, match, matchingPages, neighborInfo, neighborSite, sitemap, start, tally, tick, _ref2;
finds = [];
tally = {};
tick = function(key) {
@@ -1804,20 +1710,16 @@ require.define("/lib/neighborhood.coffee", function (require, module, exports, _
match = function(key, text) {
var hit;
hit = (text != null) && text.toLowerCase().indexOf(searchQuery.toLowerCase()) >= 0;
- if (hit) {
- tick(key);
- }
+ if (hit) tick(key);
return hit;
};
start = Date.now();
- _ref1 = wiki.neighborhood;
- for (neighborSite in _ref1) {
- if (!__hasProp.call(_ref1, neighborSite)) continue;
- neighborInfo = _ref1[neighborSite];
+ _ref2 = wiki.neighborhood;
+ for (neighborSite in _ref2) {
+ if (!__hasProp.call(_ref2, neighborSite)) continue;
+ neighborInfo = _ref2[neighborSite];
sitemap = neighborInfo.sitemap;
- if (sitemap != null) {
- tick('sites');
- }
+ if (sitemap != null) tick('sites');
matchingPages = _.each(sitemap, function(page) {
tick('pages');
if (!(match('title', page.title) || match('text', page.synopsis) || match('slug', page.slug))) {
@@ -1854,9 +1756,7 @@ require.define("/lib/neighborhood.coffee", function (require, module, exports, _
});
return $('input.search').on('keypress', function(e) {
var searchQuery;
- if (e.keyCode !== 13) {
- return;
- }
+ if (e.keyCode !== 13) return;
searchQuery = $(this).val();
search.performSearch(searchQuery);
return $(this).val("");
@@ -1927,7 +1827,6 @@ require.define("/lib/search.coffee", function (require, module, exports, __dirna
});
require.define("/lib/dom.coffee", function (require, module, exports, __dirname, __filename) {
-(function() {
wiki.createPage = function(name, loc) {
if (loc && loc !== 'view') {
@@ -1937,16 +1836,11 @@ require.define("/lib/dom.coffee", function (require, module, exports, __dirname,
}
};
-}).call(this);
-
});
require.define("/client.coffee", function (require, module, exports, __dirname, __filename) {
- (function() {
-
+
require('./lib/legacy.coffee');
-}).call(this);
-
});
require("/client.coffee");
221 client/test/testclient.js
View
@@ -416,24 +416,12 @@ require.define("/lib/util.coffee", function (require, module, exports, __dirname
if ((secs = msecs / 1000) < 2) {
return "" + (Math.floor(msecs)) + " milliseconds ago";
}
- if ((mins = secs / 60) < 2) {
- return "" + (Math.floor(secs)) + " seconds ago";
- }
- if ((hrs = mins / 60) < 2) {
- return "" + (Math.floor(mins)) + " minutes ago";
- }
- if ((days = hrs / 24) < 2) {
- return "" + (Math.floor(hrs)) + " hours ago";
- }
- if ((weeks = days / 7) < 2) {
- return "" + (Math.floor(days)) + " days ago";
- }
- if ((months = days / 31) < 2) {
- return "" + (Math.floor(weeks)) + " weeks ago";
- }
- if ((years = days / 365) < 2) {
- return "" + (Math.floor(months)) + " months ago";
- }
+ if ((mins = secs / 60) < 2) return "" + (Math.floor(secs)) + " seconds ago";
+ if ((hrs = mins / 60) < 2) return "" + (Math.floor(mins)) + " minutes ago";
+ if ((days = hrs / 24) < 2) return "" + (Math.floor(hrs)) + " hours ago";
+ if ((weeks = days / 7) < 2) return "" + (Math.floor(days)) + " days ago";
+ if ((months = days / 31) < 2) return "" + (Math.floor(weeks)) + " weeks ago";
+ if ((years = days / 365) < 2) return "" + (Math.floor(months)) + " months ago";
return "" + (Math.floor(years)) + " years ago";
};
@@ -441,9 +429,7 @@ require.define("/lib/util.coffee", function (require, module, exports, __dirname
return name.replace(/\s/g, '-').replace(/[^A-Za-z0-9-]/g, '').toLowerCase();
};
- if (typeof wiki !== "undefined" && wiki !== null) {
- wiki.asSlug = util.asSlug;
- }
+ if (typeof wiki !== "undefined" && wiki !== null) wiki.asSlug = util.asSlug;
util.emptyPage = function() {
return {
@@ -494,18 +480,10 @@ require.define("/lib/util.coffee", function (require, module, exports, __dirname
if ((page != null) && (page.story != null)) {
p1 = page.story[0];
p2 = page.story[1];
- if (p1 && p1.type === 'paragraph') {
- synopsis || (synopsis = p1.text);
- }
- if (p2 && p2.type === 'paragraph') {
- synopsis || (synopsis = p2.text);
- }
- if (p1) {
- synopsis || (synopsis = p1.text != null);
- }
- if (p2) {
- synopsis || (synopsis = p2.text != null);
- }
+ if (p1 && p1.type === 'paragraph') synopsis || (synopsis = p1.text);
+ if (p2 && p2.type === 'paragraph') synopsis || (synopsis = p2.text);
+ if (p1) synopsis || (synopsis = p1.text != null);
+ if (p2) synopsis || (synopsis = p2.text != null);
synopsis || (synopsis = (page.story != null) && ("A page with " + page.story.length + " items."));
} else {
synopsis = 'A page with no story.';
@@ -821,7 +799,7 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
if (json = localStorage[slug]) {
return JSON.parse(json);
} else {
- return void 0;
+ return;
}
};
@@ -834,9 +812,7 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
} else {
site = localContext.shift();
}
- if (site === 'view') {
- site = null;
- }
+ if (site === 'view') site = null;
if (site != null) {
if (site === 'local') {
if (localPage = pageFromLocalStorage(pageInformation.slug)) {
@@ -859,9 +835,7 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
dataType: 'json',
url: url + ("?random=" + (util.randomBytes(4))),
success: function(page) {
- if (rev) {
- page = revision.create(rev, page);
- }
+ if (rev) page = revision.create(rev, page);
return whenGotten(page, site);
},
error: function(xhr, type, msg) {
@@ -898,9 +872,7 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
var localPage, pageInformation, whenGotten, whenNotGotten;
whenGotten = _arg.whenGotten, whenNotGotten = _arg.whenNotGotten, pageInformation = _arg.pageInformation;
wiki.log('pageHandler.get', pageInformation.site, pageInformation.slug, pageInformation.rev, 'context', pageHandler.context.join(' => '));
- if (pageInformation.wasServerGenerated) {
- return whenGotten(null);
- }
+ if (pageInformation.wasServerGenerated) return whenGotten(null);
if (!pageInformation.site) {
if (localPage = pageFromLocalStorage(pageInformation.slug)) {
if (pageInformation.rev) {
@@ -909,9 +881,7 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
return whenGotten(localPage, 'local');
}
}
- if (!pageHandler.context.length) {
- pageHandler.context = ['view'];
- }
+ if (!pageHandler.context.length) pageHandler.context = ['view'];
return recursiveGet({
pageInformation: pageInformation,
whenGotten: whenGotten,
@@ -931,9 +901,7 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
};
}
page || (page = pageElement.data("data"));
- if (page.journal == null) {
- page.journal = [];
- }
+ if (page.journal == null) page.journal = [];
if ((site = action['fork']) != null) {
page.journal = page.journal.concat({
'type': 'fork',
@@ -997,9 +965,7 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
}
}
action.date = (new Date()).getTime();
- if (action.site === 'origin') {
- delete action.site;
- }
+ if (action.site === 'origin') delete action.site;
if (forkFrom) {
pageElement.find('h1 img').attr('src', '/favicon.png');
pageElement.find('h1 a').attr('href', '/');
@@ -1028,8 +994,8 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
require.define("/lib/state.coffee", function (require, module, exports, __dirname, __filename) {
(function() {
- var active, state,
- __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
+ var active, state;
+ var __hasProp = Object.prototype.hasOwnProperty, __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (__hasProp.call(this, i) && this[i] === item) return i; } return -1; };
active = require('./active');
@@ -1079,9 +1045,9 @@ require.define("/lib/state.coffee", function (require, module, exports, __dirnam
locs = state.locsInDom();
pages = state.pagesInDom();
url = ((function() {
- var _i, _len, _results;
+ var _len, _results;
_results = [];
- for (idx = _i = 0, _len = pages.length; _i < _len; idx = ++_i) {
+ for (idx = 0, _len = pages.length; idx < _len; idx++) {
page = pages[idx];
_results.push("/" + ((locs != null ? locs[idx] : void 0) || 'view') + "/" + page);
}
@@ -1094,22 +1060,18 @@ require.define("/lib/state.coffee", function (require, module, exports, __dirnam
};
state.show = function(e) {
- var idx, name, newLocs, newPages, old, oldLocs, oldPages, previous, _i, _len, _ref;
+ var idx, name, newLocs, newPages, old, oldLocs, oldPages, previous, _len, _ref;
oldPages = state.pagesInDom();
newPages = state.urlPages();
oldLocs = state.locsInDom();
newLocs = state.urlLocs();
- if (!location.pathname || location.pathname === '/') {
- return;
- }
+ if (!location.pathname || location.pathname === '/') return;
previous = $('.page').eq(0);
- for (idx = _i = 0, _len = newPages.length; _i < _len; idx = ++_i) {
+ for (idx = 0, _len = newPages.length; idx < _len; idx++) {
name = newPages[idx];
if (name !== oldPages[idx]) {
old = $('.page').eq(idx);
- if (old) {
- old.remove();
- }
+ if (old) old.remove();
wiki.createPage(name, newLocs[idx]).insertAfter(previous).each(wiki.refresh);
}
previous = $('.page').eq(idx);
@@ -1120,13 +1082,13 @@ require.define("/lib/state.coffee", function (require, module, exports, __dirnam
};
state.first = function() {
- var firstUrlLocs, firstUrlPages, idx, oldPages, urlPage, _i, _len, _results;
+ var firstUrlLocs, firstUrlPages, idx, oldPages, urlPage, _len, _results;
state.setUrl();
firstUrlPages = state.urlPages();
firstUrlLocs = state.urlLocs();
oldPages = state.pagesInDom();
_results = [];
- for (idx = _i = 0, _len = firstUrlPages.length; _i < _len; idx = ++_i) {
+ for (idx = 0, _len = firstUrlPages.length; idx < _len; idx++) {
urlPage = firstUrlPages[idx];
if (__indexOf.call(oldPages, urlPage) < 0) {
if (urlPage !== '') {
@@ -1148,7 +1110,7 @@ require.define("/lib/revision.coffee", function (require, module, exports, __dir
var create;
create = function(revIndex, data) {
- var afterIndex, editIndex, itemId, items, journal, journalEntry, removeIndex, revJournal, revStory, revStoryIds, revTitle, storyItem, _i, _j, _k, _len, _len1, _len2, _ref;
+ var afterIndex, editIndex, itemId, items, journal, journalEntry, removeIndex, revJournal, revStory, revStoryIds, revTitle, storyItem, _i, _j, _k, _len, _len2, _len3, _ref;
journal = data.journal;
revTitle = data.title;
revStory = [];
@@ -1181,13 +1143,13 @@ require.define("/lib/revision.coffee", function (require, module, exports, __dir
break;
case 'move':
items = [];
- for (_j = 0, _len1 = revStory.length; _j < _len1; _j++) {
+ for (_j = 0, _len2 = revStory.length; _j < _len2; _j++) {
storyItem = revStory[_j];
items[storyItem.id] = storyItem;
}
revStory = [];
_ref = journalEntry.order;
- for (_k = 0, _len2 = _ref.length; _k < _len2; _k++) {
+ for (_k = 0, _len3 = _ref.length; _k < _len3; _k++) {
itemId = _ref[_k];
revStory.push(items[itemId]);
}
@@ -1224,9 +1186,7 @@ require.define("/test/mockServer.coffee", function (require, module, exports, __
};
simulatePageFound = function(pageToReturn) {
- if (pageToReturn == null) {
- pageToReturn = {};
- }
+ if (pageToReturn == null) pageToReturn = {};
return sinon.stub(jQuery, "ajax").yieldsTo('success', pageToReturn);
};
@@ -1324,11 +1284,7 @@ require.define("/lib/refresh.coffee", function (require, module, exports, __dirn
}) : moveToPage ? (itemElement.data('pageElement', thisPageElement), beforeElement = itemElement.prev('.item'), before = wiki.getItem(beforeElement), {
type: 'add',
item: item,
- after: before != null ? before.id : void 0,
- origin: {
- slug: sourcePageElement.attr("id"),
- site: sourceSite
- }
+ after: before != null ? before.id : void 0
}) : void 0;
action.id = item.id;
return pageHandler.put(thisPageElement, action);
@@ -1390,7 +1346,7 @@ require.define("/lib/refresh.coffee", function (require, module, exports, __dirn
};
wiki.buildPage = function(data, siteFound, pageElement) {
- var action, addContext, context, doItem, footerElement, journalElement, page, site, slug, storyElement, _i, _len, _ref, _ref1;
+ var action, addContext, context, doItem, footerElement, journalElement, page, site, slug, storyElement, _i, _len, _ref, _ref2;
if (siteFound === 'local') {
pageElement.addClass('local');
} else {
@@ -1410,13 +1366,9 @@ require.define("/lib/refresh.coffee", function (require, module, exports, __dirn
slug = $(pageElement).attr('id');
site = $(pageElement).data('site');
context = ['view'];
- if (site != null) {
- context.push(site);
- }
+ if (site != null) context.push(site);
addContext = function(site) {
- if ((site != null) && !_.include(context, site)) {
- return context.push(site);
- }
+ if ((site != null) && !_.include(context, site)) return context.push(site);
};
_ref = page.journal.slice(0).reverse();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -1426,18 +1378,14 @@ require.define("/lib/refresh.coffee", function (require, module, exports, __dirn
wiki.resolutionContext = context;
wiki.log('buildPage', slug, 'site', site, 'context', context.join(' => '));
emitHeader(pageElement, page);
- _ref1 = ['story', 'journal', 'footer'].map(function(className) {
+ _ref2 = ['story', 'journal', 'footer'].map(function(className) {
return $("<div />").addClass(className).appendTo(pageElement);
- }), storyElement = _ref1[0], journalElement = _ref1[1], footerElement = _ref1[2];
+ }), storyElement = _ref2[0], journalElement = _ref2[1], footerElement = _ref2[2];
doItem = function(i) {
var div, item;
- if (i >= page.story.length) {
- return;
- }
+ if (i >= page.story.length) return;
item = page.story[i];
- if ($.isArray(item)) {
- item = item[0];
- }
+ if ($.isArray(item)) item = item[0];
div = $("<div />").addClass("item").addClass(item.type).attr("data-id", item.id);
storyElement.append(div);
return plugin["do"](div, item, function() {
@@ -1484,23 +1432,21 @@ require.define("/lib/refresh.coffee", function (require, module, exports, __dirn
return wiki.buildPage(page, void 0, pageElement).addClass('ghost');
};
registerNeighbors = function(data, site) {
- var action, item, _i, _j, _len, _len1, _ref1, _ref2, _results;
+ var action, item, _i, _j, _len, _len2, _ref2, _ref3, _results;
if (_.include(['local', 'origin', 'view', null, void 0], site)) {
neighborhood.registerNeighbor(location.host);
} else {
neighborhood.registerNeighbor(site);
}
- _ref1 = data.story || [];
- for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
- item = _ref1[_i];
- if (item.site != null) {
- neighborhood.registerNeighbor(item.site);
- }
+ _ref2 = data.story || [];
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
+ item = _ref2[_i];
+ if (item.site != null) neighborhood.registerNeighbor(item.site);
}
- _ref2 = data.journal || [];
+ _ref3 = data.journal || [];
_results = [];
- for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
- action = _ref2[_j];
+ for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
+ action = _ref3[_j];
if (action.site != null) {
_results.push(neighborhood.registerNeighbor(action.site));
} else {
@@ -1535,9 +1481,7 @@ require.define("/lib/plugin.coffee", function (require, module, exports, __dirna
scripts = {};
getScript = wiki.getScript = function(url, callback) {
- if (callback == null) {
- callback = function() {};
- }
+ if (callback == null) callback = function() {};
if (scripts[url] != null) {
return callback();
} else {
@@ -1551,13 +1495,9 @@ require.define("/lib/plugin.coffee", function (require, module, exports, __dirna
};
plugin.get = wiki.getPlugin = function(name, callback) {
- if (window.plugins[name]) {
- return callback(window.plugins[name]);
- }
+ if (window.plugins[name]) return callback(window.plugins[name]);
return getScript("/plugins/" + name + "/" + name + ".js", function() {
- if (window.plugins[name]) {
- return callback(window.plugins[name]);
- }
+ if (window.plugins[name]) return callback(window.plugins[name]);
return getScript("/plugins/" + name + ".js", function() {
return callback(window.plugins[name]);
});
@@ -1566,9 +1506,7 @@ require.define("/lib/plugin.coffee", function (require, module, exports, __dirna
plugin["do"] = wiki.doPlugin = function(div, item, done) {
var error;
- if (done == null) {
- done = function() {};
- }
+ if (done == null) done = function() {};
error = function(ex) {
var errorElement;
errorElement = $("<div />").addClass('error');
@@ -1644,8 +1582,8 @@ require.define("/lib/plugin.coffee", function (require, module, exports, __dirna
require.define("/lib/neighborhood.coffee", function (require, module, exports, __dirname, __filename) {
(function() {
- var active, createSearch, neighborhood, nextAvailableFetch, nextFetchInterval, populateSiteInfoFor, util, _ref,
- __hasProp = {}.hasOwnProperty;
+ var active, createSearch, neighborhood, nextAvailableFetch, nextFetchInterval, populateSiteInfoFor, util, _ref;
+ var __hasProp = Object.prototype.hasOwnProperty;
active = require('./active.coffee');
@@ -1655,9 +1593,7 @@ require.define("/lib/neighborhood.coffee", function (require, module, exports, _
module.exports = neighborhood = {};
- if ((_ref = wiki.neighborhood) == null) {
- wiki.neighborhood = {};
- }
+ if ((_ref = wiki.neighborhood) == null) wiki.neighborhood = {};
nextAvailableFetch = 0;
@@ -1665,9 +1601,7 @@ require.define("/lib/neighborhood.coffee", function (require, module, exports, _
populateSiteInfoFor = function(site, neighborInfo) {
var fetchMap, now, transition;
- if (neighborInfo.sitemapRequestInflight) {
- return;
- }
+ if (neighborInfo.sitemapRequestInflight) return;
neighborInfo.sitemapRequestInflight = true;
transition = function(site, from, to) {
return $(".neighbor[data-site=\"" + site + "\"]").find('div').removeClass(from).addClass(to);
@@ -1702,9 +1636,7 @@ require.define("/lib/neighborhood.coffee", function (require, module, exports, _
wiki.registerNeighbor = neighborhood.registerNeighbor = function(site) {
var neighborInfo;
- if (wiki.neighborhood[site] != null) {
- return;
- }
+ if (wiki.neighborhood[site] != null) return;
neighborInfo = {};
wiki.neighborhood[site] = neighborInfo;
populateSiteInfoFor(site, neighborInfo);
@@ -1716,7 +1648,7 @@ require.define("/lib/neighborhood.coffee", function (require, module, exports, _
};
neighborhood.search = function(searchQuery) {
- var finds, match, matchingPages, neighborInfo, neighborSite, sitemap, start, tally, tick, _ref1;
+ var finds, match, matchingPages, neighborInfo, neighborSite, sitemap, start, tally, tick, _ref2;
finds = [];
tally = {};
tick = function(key) {
@@ -1729,20 +1661,16 @@ require.define("/lib/neighborhood.coffee", function (require, module, exports, _
match = function(key, text) {
var hit;
hit = (text != null) && text.toLowerCase().indexOf(searchQuery.toLowerCase()) >= 0;
- if (hit) {
- tick(key);
- }
+ if (hit) tick(key);
return hit;
};
start = Date.now();
- _ref1 = wiki.neighborhood;
- for (neighborSite in _ref1) {
- if (!__hasProp.call(_ref1, neighborSite)) continue;
- neighborInfo = _ref1[neighborSite];
+ _ref2 = wiki.neighborhood;
+ for (neighborSite in _ref2) {
+ if (!__hasProp.call(_ref2, neighborSite)) continue;
+ neighborInfo = _ref2[neighborSite];
sitemap = neighborInfo.sitemap;
- if (sitemap != null) {
- tick('sites');
- }
+ if (sitemap != null) tick('sites');
matchingPages = _.each(sitemap, function(page) {
tick('pages');
if (!(match('title', page.title) || match('text', page.synopsis) || match('slug', page.slug))) {
@@ -1779,9 +1707,7 @@ require.define("/lib/neighborhood.coffee", function (require, module, exports, _
});
return $('input.search').on('keypress', function(e) {
var searchQuery;
- if (e.keyCode !== 13) {
- return;
- }
+ if (e.keyCode !== 13) return;
searchQuery = $(this).val();
search.performSearch(searchQuery);
return $(this).val("");
@@ -1852,7 +1778,6 @@ require.define("/lib/search.coffee", function (require, module, exports, __dirna
});
require.define("/lib/dom.coffee", function (require, module, exports, __dirname, __filename) {
-(function() {
wiki.createPage = function(name, loc) {
if (loc && loc !== 'view') {
@@ -1862,8 +1787,6 @@ require.define("/lib/dom.coffee", function (require, module, exports, __dirname,
}
};
-}).call(this);
-
});
require.define("/test/plugin.coffee", function (require, module, exports, __dirname, __filename) {
@@ -2304,7 +2227,7 @@ require.define("/test/search.coffee", function (require, module, exports, __dirn
});
-require.define("/plugins/changes/changes.js", function (require, module, exports, __dirname, __filename) {
+require.define("/changes.js", function (require, module, exports, __dirname, __filename) {
// Generated by CoffeeScript 1.3.3
(function() {
var constructor, listItemHtml, pageBundle;
@@ -2412,8 +2335,8 @@ require.define("/plugins/changes/changes.js", function (require, module, exports
require.define("/testclient.coffee", function (require, module, exports, __dirname, __filename) {
(function() {
- var util,
- __slice = [].slice;
+ var util;
+ var __slice = Array.prototype.slice;
mocha.setup('bdd');
@@ -2459,7 +2382,7 @@ require.define("/testclient.coffee", function (require, module, exports, __dirna
});
require("/testclient.coffee");
-require.define("/plugins/changes/test.coffee", function (require, module, exports, __dirname, __filename) {
+require.define("/test.coffee", function (require, module, exports, __dirname, __filename) {
(function() {
var createFakeLocalStorage, pluginCtor;
@@ -2467,9 +2390,7 @@ require.define("/plugins/changes/test.coffee", function (require, module, export
createFakeLocalStorage = function(initialContents) {
var fake, getStoreSize, keys, store;
- if (initialContents == null) {
- initialContents = {};
- }
+ if (initialContents == null) initialContents = {};
store = initialContents;
keys = function() {
var k, _, _results;
@@ -2580,4 +2501,4 @@ require.define("/plugins/changes/test.coffee", function (require, module, export
}).call(this);
});
-require("/plugins/changes/test.coffee");
+require("/test.coffee");
Please sign in to comment.
Something went wrong with that request. Please try again.