Browse files

caret goes to end of text area when active

  • Loading branch information...
1 parent 185faae commit 2338eb5b2b3f74b52f03f17af53c9cecb24878c0 @hallahan committed May 29, 2012
Showing with 223 additions and 102 deletions.
  1. +126 −59 client/client.js
  2. +1 −1 client/lib/legacy.coffee
  3. +10 −0 client/lib/util.coffee
  4. +86 −42 client/test/testclient.js
View
185 client/client.js
@@ -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, state, util;
- var __slice = Array.prototype.slice;
+ var active, pageHandler, plugin, refresh, state, util,
+ __slice = [].slice;
window.wiki = {};
@@ -388,14 +388,14 @@ require.define("/lib/legacy.coffee", function (require, module, exports, __dirna
}
};
wiki.dump = function() {
- var i, p, _i, _j, _len, _len2, _ref, _ref2;
+ var i, p, _i, _j, _len, _len1, _ref, _ref1;
_ref = $('.page');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
p = _ref[_i];
wiki.log('.page', p);
- _ref2 = $(p).find('.item');
- for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
- i = _ref2[_j];
+ _ref1 = $(p).find('.item');
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
+ i = _ref1[_j];
wiki.log('.item', i, 'data-item', $(i).data('item'));
}
}
@@ -435,7 +435,9 @@ require.define("/lib/legacy.coffee", function (require, module, exports, __dirna
prev = journalElement.find(".edit[data-id=" + (action.id || 0) + "]");
}
actionTitle = action.type;
- if (action.type === 'edit') actionTitle += "(" + prev.length + ")";
+ if (action.type === 'edit') {
+ actionTitle += "(" + prev.length + ")";
+ }
if (action.date != null) {
actionTitle += ": " + (util.formatDate(action.date));
}
@@ -484,7 +486,9 @@ require.define("/lib/legacy.coffee", function (require, module, exports, __dirna
textarea = $("<textarea>" + (original = (_ref = item.text) != null ? _ref : '') + "</textarea>").focusout(function() {
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,
@@ -506,7 +510,9 @@ require.define("/lib/legacy.coffee", function (require, module, exports, __dirna
}
if (e.which === $.ui.keyCode.ENTER) {
caret = util.getCaretPosition(textarea.get(0));
- if (!caret) return false;
+ if (!caret) {
+ return false;
+ }
text = textarea.val();
prefix = text.substring(0, caret);
suffix = text.substring(caret);
@@ -520,7 +526,7 @@ require.define("/lib/legacy.coffee", function (require, module, exports, __dirna
return false;
});
div.html(textarea);
- return textarea.focus();
+ return util.setCaretPosition(textarea.get(0), textarea.val().length);
};
getItem = wiki.getItem = function(element) {
if ($(element).length > 0) {
@@ -559,7 +565,9 @@ require.define("/lib/legacy.coffee", function (require, module, exports, __dirna
};
doInternalLink = wiki.doInternalLink = function(name, page) {
name = util.asSlug(name);
- if (page != null) $(page).nextAll().remove();
+ if (page != null) {
+ $(page).nextAll().remove();
+ }
createPage(name).appendTo($('.main')).each(refresh);
return active.set($('.page').last());
};
@@ -595,12 +603,16 @@ require.define("/lib/legacy.coffee", function (require, module, exports, __dirna
var msg;
wiki.log('ajax error', event, request, settings);
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');
+ }
return doInternalLink(name, page);
};
$('.main').delegate('.show-page-source', 'click', function(e) {
@@ -610,7 +622,9 @@ 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');
@@ -638,15 +652,21 @@ require.define("/lib/legacy.coffee", function (require, module, exports, __dirna
titleUrl = util.asSlug(data.title);
revUrl = "" + titleUrl + "_rev" + journalEntryIndex;
e.preventDefault();
- if (!e.shiftKey) page = $(e.target).parents('.page');
- if (page != null) $(page).nextAll().remove();
+ if (!e.shiftKey) {
+ page = $(e.target).parents('.page');
+ }
+ if (page != null) {
+ $(page).nextAll().remove();
+ }
createPage(revUrl).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
@@ -748,6 +768,20 @@ require.define("/lib/util.coffee", function (require, module, exports, __dirname
return caretPos;
};
+ util.setCaretPosition = function(elem, caretPos) {
+ var range;
+ if (elem != null) {
+ if (elem.createTextRange) {
+ range = elem.createTextRange();
+ range.move("character", caretPos);
+ range.select();
+ } else {
+ elem.setSelectionRange(caretPos, caretPos);
+ }
+ return elem.focus();
+ }
+ };
+
}).call(this);
});
@@ -775,17 +809,19 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
pageElement.addClass("local");
return callback(JSON.parse(json));
}
- if (!(pageHandler.context.length > 0)) pageHandler.context = ['origin'];
+ if (!(pageHandler.context.length > 0)) {
+ pageHandler.context = ['origin'];
+ }
if (site) {
localContext = [];
} else {
if (localContext == null) {
localContext = (function() {
- var _i, _len, _ref2, _results;
- _ref2 = pageHandler.context;
+ var _i, _len, _ref1, _results;
+ _ref1 = pageHandler.context;
_results = [];
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
- i = _ref2[_i];
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
+ i = _ref1[_i];
_results.push(i);
}
return _results;
@@ -801,7 +837,9 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
success: function(page) {
wiki.log('fetch success', page, site || 'origin');
$(pageElement).data('site', site);
- if (rev) page = revision.create(rev, page);
+ if (rev) {
+ page = revision.create(rev, page);
+ }
return callback(page);
},
error: function(xhr, type, msg) {
@@ -832,14 +870,18 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
pushToLocal = function(pageElement, action) {
var page;
page = localStorage[pageElement.attr("id")];
- if (page) page = JSON.parse(page);
+ if (page) {
+ page = JSON.parse(page);
+ }
if (action.type === 'create') {
page = {
title: action.item.title
};
}
page || (page = pageElement.data("data"));
- if (page.journal == null) page.journal = [];
+ if (page.journal == null) {
+ page.journal = [];
+ }
page.journal = page.journal.concat(action);
page.story = $(pageElement).find(".item").map(function() {
return $(this).data("item");
@@ -893,8 +935,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;
- 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; };
+ 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; };
active = require('./active');
@@ -943,9 +985,9 @@ require.define("/lib/state.coffee", function (require, module, exports, __dirnam
locs = state.locsInDom();
pages = state.pagesInDom();
url = ((function() {
- var _len, _results;
+ var _i, _len, _results;
_results = [];
- for (idx = 0, _len = pages.length; idx < _len; idx++) {
+ for (idx = _i = 0, _len = pages.length; _i < _len; idx = ++_i) {
page = pages[idx];
_results.push("/" + ((locs != null ? locs[idx] : void 0) || 'view') + "/" + page);
}
@@ -959,20 +1001,24 @@ require.define("/lib/state.coffee", function (require, module, exports, __dirnam
};
state.show = function(e) {
- var idx, name, newLocs, newPages, old, oldLocs, oldPages, previous, _len;
+ var idx, name, newLocs, newPages, old, oldLocs, oldPages, previous, _i, _len;
wiki.log('popstate', e);
oldPages = state.pagesInDom();
newPages = state.urlPages();
oldLocs = state.locsInDom();
newLocs = state.urlLocs();
- if (!location.pathname || location.pathname === '/') return;
+ if (!location.pathname || location.pathname === '/') {
+ return;
+ }
wiki.log('showState', oldPages, newPages, oldLocs, newLocs);
previous = $('.page').eq(0);
- for (idx = 0, _len = newPages.length; idx < _len; idx++) {
+ for (idx = _i = 0, _len = newPages.length; _i < _len; idx = ++_i) {
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);
@@ -982,16 +1028,18 @@ require.define("/lib/state.coffee", function (require, module, exports, __dirnam
};
state.first = function() {
- var firstUrlLocs, firstUrlPages, idx, oldPages, urlPage, _len, _results;
+ var firstUrlLocs, firstUrlPages, idx, oldPages, urlPage, _i, _len, _results;
state.setUrl();
firstUrlPages = state.urlPages();
firstUrlLocs = state.urlLocs();
oldPages = state.pagesInDom();
wiki.log('amost createPage', firstUrlPages, firstUrlLocs, oldPages);
_results = [];
- for (idx = 0, _len = firstUrlPages.length; idx < _len; idx++) {
+ for (idx = _i = 0, _len = firstUrlPages.length; _i < _len; idx = ++_i) {
urlPage = firstUrlPages[idx];
- if (!(__indexOf.call(oldPages, urlPage) < 0)) continue;
+ if (!(__indexOf.call(oldPages, urlPage) < 0)) {
+ continue;
+ }
wiki.log('createPage', urlPage, idx);
if (urlPage !== '') {
_results.push(wiki.createPage(urlPage, firstUrlLocs[idx]).appendTo('.main'));
@@ -1071,7 +1119,7 @@ require.define("/lib/revision.coffee", function (require, module, exports, __dir
var create;
create = function(revIndex, data) {
- var i, itemEdited, itemId, itemSplicedIn, items, journal, journalEntry, removeId, revJournal, revStory, revTitle, storyItem, _i, _j, _k, _len, _len2, _len3, _len4, _len5, _len6, _ref, _ref2;
+ var i, itemEdited, itemId, itemSplicedIn, items, journal, journalEntry, removeId, revJournal, revStory, revTitle, storyItem, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _len5, _m, _n, _ref, _ref1;
journal = data.journal;
revTitle = data.title;
revStory = [];
@@ -1084,50 +1132,56 @@ require.define("/lib/revision.coffee", function (require, module, exports, __dir
revJournal.push(journalEntry);
switch (journalEntry.type) {
case 'create':
- if (journalEntry.item.title != null) revTitle = journalEntry.item.title;
+ if (journalEntry.item.title != null) {
+ revTitle = journalEntry.item.title;
+ }
break;
case 'add':
if (journalEntry.after != null) {
- for (i = 0, _len2 = revStory.length; i < _len2; i++) {
+ for (i = _j = 0, _len1 = revStory.length; _j < _len1; i = ++_j) {
storyItem = revStory[i];
if (storyItem.id === journalEntry.after) {
itemSplicedIn = true;
revStory.splice(i + 1, 0, journalEntry.item);
break;
}
}
- if (!itemSplicedIn) revStory.push(journalEntry.item);
+ if (!itemSplicedIn) {
+ revStory.push(journalEntry.item);
+ }
} else {
revStory.push(journalEntry.item);
}
break;
case 'edit':
- for (i = 0, _len3 = revStory.length; i < _len3; i++) {
+ for (i = _k = 0, _len2 = revStory.length; _k < _len2; i = ++_k) {
storyItem = revStory[i];
if (storyItem.id === journalEntry.id) {
revStory[i] = journalEntry.item;
itemEdited = true;
break;
}
}
- if (!itemEdited) revStory.push(journalEntry.item);
+ if (!itemEdited) {
+ revStory.push(journalEntry.item);
+ }
break;
case 'move':
items = [];
- for (_j = 0, _len4 = revStory.length; _j < _len4; _j++) {
- storyItem = revStory[_j];
+ for (_l = 0, _len3 = revStory.length; _l < _len3; _l++) {
+ storyItem = revStory[_l];
items[storyItem.id] = storyItem;
}
revStory = [];
- _ref2 = journalEntry.order;
- for (_k = 0, _len5 = _ref2.length; _k < _len5; _k++) {
- itemId = _ref2[_k];
+ _ref1 = journalEntry.order;
+ for (_m = 0, _len4 = _ref1.length; _m < _len4; _m++) {
+ itemId = _ref1[_m];
revStory.push(items[itemId]);
}
break;
case 'remove':
removeId = journalEntry.id;
- for (i = 0, _len6 = revStory.length; i < _len6; i++) {
+ for (i = _n = 0, _len5 = revStory.length; _n < _len5; i = ++_n) {
storyItem = revStory[i];
if (storyItem.id === removeId) {
revStory.splice(i, 1);
@@ -1160,7 +1214,9 @@ 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 {
@@ -1174,9 +1230,13 @@ 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]);
});
@@ -1238,10 +1298,10 @@ require.define("/lib/plugin.coffee", function (require, module, exports, __dirna
},
changes: {
emit: function(div, item) {
- var a, i, key, ul, _ref, _results;
+ var a, i, key, ul, _i, _ref, _results;
div.append(ul = $('<ul />').append(localStorage.length ? $('<input type="button" value="discard all" />').css('margin-top', '10px') : $('<p>empty</p>')));
_results = [];
- for (i = 0, _ref = localStorage.length; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) {
+ for (i = _i = 0, _ref = localStorage.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
key = localStorage.key(i);
a = $('<a class="internal" href="#" />').append(key).data('pageName', key);
_results.push(ul.prepend($('<li />').append(a)));
@@ -1364,7 +1424,7 @@ require.define("/lib/refresh.coffee", function (require, module, exports, __dirn
var buildPage, pageElement;
pageElement = $(this);
buildPage = function(data) {
- var action, addContext, context, footerElement, journalElement, page, site, slug, storyElement, _i, _len, _ref, _ref2;
+ var action, addContext, context, footerElement, journalElement, page, site, slug, storyElement, _i, _len, _ref, _ref1;
if (!(data != null)) {
pageElement.find('.item').each(function(i, each) {
var item;
@@ -1379,7 +1439,9 @@ require.define("/lib/refresh.coffee", function (require, module, exports, __dirn
slug = $(pageElement).attr('id');
site = $(pageElement).data('site');
context = ['origin'];
- 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);
@@ -1393,12 +1455,14 @@ require.define("/lib/refresh.coffee", function (require, module, exports, __dirn
wiki.resolutionContext = context;
wiki.log('build', slug, 'site', site, 'context', context.join(' => '));
emitHeader(pageElement, page);
- _ref2 = ['story', 'journal', 'footer'].map(function(className) {
+ _ref1 = ['story', 'journal', 'footer'].map(function(className) {
return $("<div />").addClass(className).appendTo(pageElement);
- }), storyElement = _ref2[0], journalElement = _ref2[1], footerElement = _ref2[2];
+ }), storyElement = _ref1[0], journalElement = _ref1[1], footerElement = _ref1[2];
$.each(page.story, function(i, item) {
var div;
- 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);
@@ -1421,8 +1485,11 @@ require.define("/lib/refresh.coffee", function (require, module, exports, __dirn
});
require.define("/client.coffee", function (require, module, exports, __dirname, __filename) {
-
+ (function() {
+
require('./lib/legacy.coffee');
+}).call(this);
+
});
require("/client.coffee");
View
2 client/lib/legacy.coffee
@@ -150,7 +150,7 @@ $ ->
return false; #don't pass dblclick on to the div, as it'll reload
div.html textarea
- textarea.focus()
+ util.setCaretPosition textarea.get(0), textarea.val().length
getItem = wiki.getItem = (element) ->
$(element).data("item") or $(element).data('staticItem') if $(element).length > 0
View
10 client/lib/util.coffee
@@ -52,3 +52,13 @@ util.getCaretPosition = (div) ->
# for the rest of the world
else caretPos = div.selectionStart if div.selectionStart or div.selectionStart is "0"
caretPos
+
+util.setCaretPosition = (elem, caretPos) ->
+ if elem?
+ if elem.createTextRange # IE
+ range = elem.createTextRange()
+ range.move "character", caretPos
+ range.select()
+ else # rest of the world
+ elem.setSelectionRange caretPos, caretPos
+ elem.focus()
View
128 client/test/testclient.js
@@ -475,6 +475,20 @@ require.define("/lib/util.coffee", function (require, module, exports, __dirname
return caretPos;
};
+ util.setCaretPosition = function(elem, caretPos) {
+ var range;
+ if (elem != null) {
+ if (elem.createTextRange) {
+ range = elem.createTextRange();
+ range.move("character", caretPos);
+ range.select();
+ } else {
+ elem.setSelectionRange(caretPos, caretPos);
+ }
+ return elem.focus();
+ }
+ };
+
}).call(this);
});
@@ -703,17 +717,19 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
pageElement.addClass("local");
return callback(JSON.parse(json));
}
- if (!(pageHandler.context.length > 0)) pageHandler.context = ['origin'];
+ if (!(pageHandler.context.length > 0)) {
+ pageHandler.context = ['origin'];
+ }
if (site) {
localContext = [];
} else {
if (localContext == null) {
localContext = (function() {
- var _i, _len, _ref2, _results;
- _ref2 = pageHandler.context;
+ var _i, _len, _ref1, _results;
+ _ref1 = pageHandler.context;
_results = [];
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
- i = _ref2[_i];
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
+ i = _ref1[_i];
_results.push(i);
}
return _results;
@@ -729,7 +745,9 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
success: function(page) {
wiki.log('fetch success', page, site || 'origin');
$(pageElement).data('site', site);
- if (rev) page = revision.create(rev, page);
+ if (rev) {
+ page = revision.create(rev, page);
+ }
return callback(page);
},
error: function(xhr, type, msg) {
@@ -760,14 +778,18 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
pushToLocal = function(pageElement, action) {
var page;
page = localStorage[pageElement.attr("id")];
- if (page) page = JSON.parse(page);
+ if (page) {
+ page = JSON.parse(page);
+ }
if (action.type === 'create') {
page = {
title: action.item.title
};
}
page || (page = pageElement.data("data"));
- if (page.journal == null) page.journal = [];
+ if (page.journal == null) {
+ page.journal = [];
+ }
page.journal = page.journal.concat(action);
page.story = $(pageElement).find(".item").map(function() {
return $(this).data("item");
@@ -821,8 +843,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;
- 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; };
+ 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; };
active = require('./active');
@@ -871,9 +893,9 @@ require.define("/lib/state.coffee", function (require, module, exports, __dirnam
locs = state.locsInDom();
pages = state.pagesInDom();
url = ((function() {
- var _len, _results;
+ var _i, _len, _results;
_results = [];
- for (idx = 0, _len = pages.length; idx < _len; idx++) {
+ for (idx = _i = 0, _len = pages.length; _i < _len; idx = ++_i) {
page = pages[idx];
_results.push("/" + ((locs != null ? locs[idx] : void 0) || 'view') + "/" + page);
}
@@ -887,20 +909,24 @@ require.define("/lib/state.coffee", function (require, module, exports, __dirnam
};
state.show = function(e) {
- var idx, name, newLocs, newPages, old, oldLocs, oldPages, previous, _len;
+ var idx, name, newLocs, newPages, old, oldLocs, oldPages, previous, _i, _len;
wiki.log('popstate', e);
oldPages = state.pagesInDom();
newPages = state.urlPages();
oldLocs = state.locsInDom();
newLocs = state.urlLocs();
- if (!location.pathname || location.pathname === '/') return;
+ if (!location.pathname || location.pathname === '/') {
+ return;
+ }
wiki.log('showState', oldPages, newPages, oldLocs, newLocs);
previous = $('.page').eq(0);
- for (idx = 0, _len = newPages.length; idx < _len; idx++) {
+ for (idx = _i = 0, _len = newPages.length; _i < _len; idx = ++_i) {
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);
@@ -910,16 +936,18 @@ require.define("/lib/state.coffee", function (require, module, exports, __dirnam
};
state.first = function() {
- var firstUrlLocs, firstUrlPages, idx, oldPages, urlPage, _len, _results;
+ var firstUrlLocs, firstUrlPages, idx, oldPages, urlPage, _i, _len, _results;
state.setUrl();
firstUrlPages = state.urlPages();
firstUrlLocs = state.urlLocs();
oldPages = state.pagesInDom();
wiki.log('amost createPage', firstUrlPages, firstUrlLocs, oldPages);
_results = [];
- for (idx = 0, _len = firstUrlPages.length; idx < _len; idx++) {
+ for (idx = _i = 0, _len = firstUrlPages.length; _i < _len; idx = ++_i) {
urlPage = firstUrlPages[idx];
- if (!(__indexOf.call(oldPages, urlPage) < 0)) continue;
+ if (!(__indexOf.call(oldPages, urlPage) < 0)) {
+ continue;
+ }
wiki.log('createPage', urlPage, idx);
if (urlPage !== '') {
_results.push(wiki.createPage(urlPage, firstUrlLocs[idx]).appendTo('.main'));
@@ -939,7 +967,7 @@ require.define("/lib/revision.coffee", function (require, module, exports, __dir
var create;
create = function(revIndex, data) {
- var i, itemEdited, itemId, itemSplicedIn, items, journal, journalEntry, removeId, revJournal, revStory, revTitle, storyItem, _i, _j, _k, _len, _len2, _len3, _len4, _len5, _len6, _ref, _ref2;
+ var i, itemEdited, itemId, itemSplicedIn, items, journal, journalEntry, removeId, revJournal, revStory, revTitle, storyItem, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _len5, _m, _n, _ref, _ref1;
journal = data.journal;
revTitle = data.title;
revStory = [];
@@ -952,50 +980,56 @@ require.define("/lib/revision.coffee", function (require, module, exports, __dir
revJournal.push(journalEntry);
switch (journalEntry.type) {
case 'create':
- if (journalEntry.item.title != null) revTitle = journalEntry.item.title;
+ if (journalEntry.item.title != null) {
+ revTitle = journalEntry.item.title;
+ }
break;
case 'add':
if (journalEntry.after != null) {
- for (i = 0, _len2 = revStory.length; i < _len2; i++) {
+ for (i = _j = 0, _len1 = revStory.length; _j < _len1; i = ++_j) {
storyItem = revStory[i];
if (storyItem.id === journalEntry.after) {
itemSplicedIn = true;
revStory.splice(i + 1, 0, journalEntry.item);
break;
}
}
- if (!itemSplicedIn) revStory.push(journalEntry.item);
+ if (!itemSplicedIn) {
+ revStory.push(journalEntry.item);
+ }
} else {
revStory.push(journalEntry.item);
}
break;
case 'edit':
- for (i = 0, _len3 = revStory.length; i < _len3; i++) {
+ for (i = _k = 0, _len2 = revStory.length; _k < _len2; i = ++_k) {
storyItem = revStory[i];
if (storyItem.id === journalEntry.id) {
revStory[i] = journalEntry.item;
itemEdited = true;
break;
}
}
- if (!itemEdited) revStory.push(journalEntry.item);
+ if (!itemEdited) {
+ revStory.push(journalEntry.item);
+ }
break;
case 'move':
items = [];
- for (_j = 0, _len4 = revStory.length; _j < _len4; _j++) {
- storyItem = revStory[_j];
+ for (_l = 0, _len3 = revStory.length; _l < _len3; _l++) {
+ storyItem = revStory[_l];
items[storyItem.id] = storyItem;
}
revStory = [];
- _ref2 = journalEntry.order;
- for (_k = 0, _len5 = _ref2.length; _k < _len5; _k++) {
- itemId = _ref2[_k];
+ _ref1 = journalEntry.order;
+ for (_m = 0, _len4 = _ref1.length; _m < _len4; _m++) {
+ itemId = _ref1[_m];
revStory.push(items[itemId]);
}
break;
case 'remove':
removeId = journalEntry.id;
- for (i = 0, _len6 = revStory.length; i < _len6; i++) {
+ for (i = _n = 0, _len5 = revStory.length; _n < _len5; i = ++_n) {
storyItem = revStory[i];
if (storyItem.id === removeId) {
revStory.splice(i, 1);
@@ -1149,7 +1183,7 @@ require.define("/lib/refresh.coffee", function (require, module, exports, __dirn
var buildPage, pageElement;
pageElement = $(this);
buildPage = function(data) {
- var action, addContext, context, footerElement, journalElement, page, site, slug, storyElement, _i, _len, _ref, _ref2;
+ var action, addContext, context, footerElement, journalElement, page, site, slug, storyElement, _i, _len, _ref, _ref1;
if (!(data != null)) {
pageElement.find('.item').each(function(i, each) {
var item;
@@ -1164,7 +1198,9 @@ require.define("/lib/refresh.coffee", function (require, module, exports, __dirn
slug = $(pageElement).attr('id');
site = $(pageElement).data('site');
context = ['origin'];
- 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);
@@ -1178,12 +1214,14 @@ require.define("/lib/refresh.coffee", function (require, module, exports, __dirn
wiki.resolutionContext = context;
wiki.log('build', slug, 'site', site, 'context', context.join(' => '));
emitHeader(pageElement, page);
- _ref2 = ['story', 'journal', 'footer'].map(function(className) {
+ _ref1 = ['story', 'journal', 'footer'].map(function(className) {
return $("<div />").addClass(className).appendTo(pageElement);
- }), storyElement = _ref2[0], journalElement = _ref2[1], footerElement = _ref2[2];
+ }), storyElement = _ref1[0], journalElement = _ref1[1], footerElement = _ref1[2];
$.each(page.story, function(i, item) {
var div;
- 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);
@@ -1216,7 +1254,9 @@ 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 {
@@ -1230,9 +1270,13 @@ 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]);
});
@@ -1294,10 +1338,10 @@ require.define("/lib/plugin.coffee", function (require, module, exports, __dirna
},
changes: {
emit: function(div, item) {
- var a, i, key, ul, _ref, _results;
+ var a, i, key, ul, _i, _ref, _results;
div.append(ul = $('<ul />').append(localStorage.length ? $('<input type="button" value="discard all" />').css('margin-top', '10px') : $('<p>empty</p>')));
_results = [];
- for (i = 0, _ref = localStorage.length; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) {
+ for (i = _i = 0, _ref = localStorage.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
key = localStorage.key(i);
a = $('<a class="internal" href="#" />').append(key).data('pageName', key);
_results.push(ul.prepend($('<li />').append(a)));
@@ -1408,7 +1452,7 @@ require.define("/test/revision.coffee", function (require, module, exports, __di
require.define("/testclient.coffee", function (require, module, exports, __dirname, __filename) {
(function() {
- var __slice = Array.prototype.slice;
+ var __slice = [].slice;
mocha.setup('bdd');

0 comments on commit 2338eb5

Please sign in to comment.