jshint compliance

pull/1/head
ansuz 9 years ago
parent d1885fbab6
commit 3cb94b8d80

@ -25,6 +25,7 @@ define([
'/common/messages.js', '/common/messages.js',
'/bower_components/modalBox/modalBox-min.js' '/bower_components/modalBox/modalBox-min.js'
], function (Messages) { ], function (Messages) {
var $ = window.jQuery;
var STYLE = [ var STYLE = [
'<style>', '<style>',

@ -19,7 +19,7 @@ define([
'/common/otaml.js' '/common/otaml.js'
], function () { ], function () {
var $ = jQuery; var $ = window.jQuery;
var Otaml = window.Otaml; var Otaml = window.Otaml;
var module = { exports: {} }; var module = { exports: {} };
var PARANOIA = true; var PARANOIA = true;

@ -8,6 +8,11 @@
* Build date: 8 December 2013 * Build date: 8 December 2013
*/ */
/*
TODO FIXME use www/common/rangy if possible...
*/
(function(global) { (function(global) {
var amdSupported = (typeof global.define == "function" && global.define.amd); var amdSupported = (typeof global.define == "function" && global.define.amd);

@ -268,7 +268,7 @@ console.log(new Error().stack);
var incomingPatch = function () { var incomingPatch = function () {
if (isErrorState || initializing) { return; } if (isErrorState || initializing) { return; }
userDocBeforePatch = userDocBeforePatch || getDocHTML(doc); userDocBeforePatch = userDocBeforePatch || getDocHTML(doc);
if (PARANOIA && userDocBeforePatch != getDocHTML(doc)) { if (PARANOIA && userDocBeforePatch !== getDocHTML(doc)) {
error(false, "userDocBeforePatch != getDocHTML(doc)"); error(false, "userDocBeforePatch != getDocHTML(doc)");
} }
var op = attempt(Otaml.makeTextOperation)(userDocBeforePatch, realtime.getUserDoc()); var op = attempt(Otaml.makeTextOperation)(userDocBeforePatch, realtime.getUserDoc());

@ -30,6 +30,8 @@ define([
// How long to wait before determining that the connection is lost. // How long to wait before determining that the connection is lost.
var MAX_LAG_BEFORE_DISCONNECT = 30000; var MAX_LAG_BEFORE_DISCONNECT = 30000;
var MAX_RECOVERABLE_ERRORS = 15;
var warn = function (x) { }; var warn = function (x) { };
var debug = function (x) { }; var debug = function (x) { };
//debug = function (x) { console.log(x) }; //debug = function (x) { console.log(x) };
@ -409,7 +411,7 @@ define([
if (initializing && userList.indexOf(userName) > -1) { if (initializing && userList.indexOf(userName) > -1) {
initializing = false; initializing = false;
$(textArea).val(realtime.getUserDoc()); $(textArea).val(realtime.getUserDoc());
TextArea.attach($(textArea)[0], realtime); textArea.attach($(textArea)[0], realtime);
$(textArea).removeAttr("disabled"); $(textArea).removeAttr("disabled");
} }
if (!initializing) { if (!initializing) {
@ -676,6 +678,7 @@ define([
return onbeforeunload(ev); return onbeforeunload(ev);
}; };
var isErrorState = false; var isErrorState = false;
var recoverableErrorCount = 0;
var error = function (recoverable, err) { var error = function (recoverable, err) {
console.log(new Error().stack); console.log(new Error().stack);
console.log('error: ' + err.stack); console.log('error: ' + err.stack);
@ -683,7 +686,9 @@ define([
var realtime = socket.realtime; var realtime = socket.realtime;
var docHtml = $(textArea).val(); var docHtml = $(textArea).val();
isErrorState = true; isErrorState = true;
handleError(socket, realtime, err, docHtml, allMessages);
// FIXME pull this in from more mainline version
//handleError(socket, realtime, err, docHtml, allMessages);
}; };
var attempt = function (func) { var attempt = function (func) {
return function () { return function () {
@ -756,8 +761,8 @@ define([
if (isErrorState || initializing) { return; } if (isErrorState || initializing) { return; }
var textAreaVal = $(textArea).val(); var textAreaVal = $(textArea).val();
userDocBeforePatch = userDocBeforePatch || textAreaVal; userDocBeforePatch = userDocBeforePatch || textAreaVal;
if (userDocBeforePatch != textAreaVal) { if (userDocBeforePatch !== textAreaVal) {
//error(false, "userDocBeforePatch != textAreaVal"); //error(false, "userDocBeforePatch !== textAreaVal");
} }
var op = attempt(Otaml.makeTextOperation)(userDocBeforePatch, realtime.getUserDoc()); var op = attempt(Otaml.makeTextOperation)(userDocBeforePatch, realtime.getUserDoc());

@ -52,7 +52,7 @@ define(function () {
*/ */
var applyChange = function(ctx, oldval, newval) { var applyChange = function(ctx, oldval, newval) {
// Strings are immutable and have reference equality. I think this test is O(1), so its worth doing. // Strings are immutable and have reference equality. I think this test is O(1), so its worth doing.
if (oldval === newval) return; if (oldval === newval) { return; }
var commonStart = 0; var commonStart = 0;
while (oldval.charAt(commonStart) === newval.charAt(commonStart)) { while (oldval.charAt(commonStart) === newval.charAt(commonStart)) {
@ -130,7 +130,7 @@ var attachTextarea = function(elem, ctx, cmElem) {
content = elem.value; // Not done on one line so the browser can do newline conversion. content = elem.value; // Not done on one line so the browser can do newline conversion.
if(!cmElem) { if(!cmElem) {
if (elem.scrollTop !== scrollTop) elem.scrollTop = scrollTop; if (elem.scrollTop !== scrollTop) { elem.scrollTop = scrollTop; }
// Setting the selection moves the cursor. We'll just have to let your // Setting the selection moves the cursor. We'll just have to let your
// cursor drift if the element isn't active, though usually users don't // cursor drift if the element isn't active, though usually users don't

@ -6,7 +6,7 @@ define([
'/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery/dist/jquery.min.js',
'/customize/pad.js' '/customize/pad.js'
], function (Config, Realtime, Messages, Crypto) { ], function (Config, Realtime, Messages, Crypto) {
var $ = jQuery; var $ = window.jQuery;
$(window).on('hashchange', function() { $(window).on('hashchange', function() {
window.location.reload(); window.location.reload();
}); });
@ -36,7 +36,8 @@ define([
try { try {
eval(content); // jshint ignore:line eval(content); // jshint ignore:line
} catch (err) { } catch (err) {
alert(err.message); // FIXME don't use alert, make an errorbox
window.alert(err.message);
} }
}); });
}); });

@ -6,7 +6,7 @@ define([
'/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery/dist/jquery.min.js',
'/customize/pad.js' '/customize/pad.js'
], function (Config, Realtime, Messages, Crypto) { ], function (Config, Realtime, Messages, Crypto) {
var $ = jQuery; var $ = window.jQuery;
$(window).on('hashchange', function() { $(window).on('hashchange', function() {
window.location.reload(); window.location.reload();
}); });

@ -25,6 +25,7 @@ define([
'/common/messages.js', '/common/messages.js',
'/bower_components/modalBox/modalBox-min.js' '/bower_components/modalBox/modalBox-min.js'
], function (Messages) { ], function (Messages) {
var $ = window.jQuery;
var STYLE = [ var STYLE = [
'<style>', '<style>',

@ -19,7 +19,7 @@ define([
'/common/otaml.js' '/common/otaml.js'
], function () { ], function () {
var $ = jQuery; var $ = window.jQuery;
var Otaml = window.Otaml; var Otaml = window.Otaml;
var module = { exports: {} }; var module = { exports: {} };
var PARANOIA = true; var PARANOIA = true;

@ -332,13 +332,13 @@ console.log(new Error().stack);
var incomingPatch = function () { var incomingPatch = function () {
if (isErrorState || initializing) { return; } if (isErrorState || initializing) { return; }
userDocBeforePatch = userDocBeforePatch || getFixedDocText(doc, ifr.contentWindow); userDocBeforePatch = userDocBeforePatch || getFixedDocText(doc, ifr.contentWindow);
if (PARANOIA && userDocBeforePatch != getFixedDocText(doc, ifr.contentWindow)) { if (PARANOIA && userDocBeforePatch !== getFixedDocText(doc, ifr.contentWindow)) {
error(false, "userDocBeforePatch != getFixedDocText(doc, ifr.contentWindow)"); error(false, "userDocBeforePatch !== getFixedDocText(doc, ifr.contentWindow)");
} }
var op = attempt(makeHTMLOperation)(userDocBeforePatch, realtime.getUserDoc()); var op = attempt(makeHTMLOperation)(userDocBeforePatch, realtime.getUserDoc());
if (!op) { return; } if (!op) { return; }
attempt(HTMLPatcher.applyOp)( attempt(HTMLPatcher.applyOp)(
userDocBeforePatch, op, doc.body, rangy, ifr.contentWindow); userDocBeforePatch, op, doc.body, Rangy, ifr.contentWindow);
}; };
realtime.onUserListChange(function (userList) { realtime.onUserListChange(function (userList) {

@ -9,7 +9,7 @@ define([
'/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery/dist/jquery.min.js',
'/customize/pad.js' '/customize/pad.js'
], function (Config, Realtime, Messages, Crypto, Marked, Convert, Rainbow) { ], function (Config, Realtime, Messages, Crypto, Marked, Convert, Rainbow) {
var $ = jQuery; var $ = window.jQuery;
var Vdom = Convert.core.vdom, var Vdom = Convert.core.vdom,
Hyperjson = Convert.core.hyperjson, Hyperjson = Convert.core.hyperjson,
@ -39,7 +39,7 @@ define([
sanitize: true sanitize: true
}); });
window.draw = (function () { var draw = window.draw = (function () {
var target = $target[0], var target = $target[0],
inner = $target.find('#inner')[0]; inner = $target.find('#inner')[0];
@ -58,7 +58,8 @@ define([
}; };
}()); }());
window.colour = Rainbow(); // FIXME
var colour = window.colour = Rainbow();
var $inner = $('#inner'); var $inner = $('#inner');
@ -78,7 +79,7 @@ define([
if (redrawTimeout) { clearTimeout(redrawTimeout); } if (redrawTimeout) { clearTimeout(redrawTimeout); }
redrawTimeout = setTimeout(function () { redrawTimeout = setTimeout(function () {
draw(md); draw(md);
if (makeRainbow) { makeRainbows(); } if (window.makeRainbow) { makeRainbows(); }
}, 450); }, 450);
}; };

@ -8,7 +8,7 @@ define([
'/common/otaml.js', '/common/otaml.js',
'/customize/sheet.js' '/customize/sheet.js'
], function (Config, Messages, Crypto, Toolbar) { ], function (Config, Messages, Crypto, Toolbar) {
var $ = jQuery; var $ = window.jQuery;
var ChainPad = window.ChainPad; var ChainPad = window.ChainPad;
var Otaml = window.Otaml; var Otaml = window.Otaml;
@ -51,7 +51,9 @@ define([
}; };
var applyChange = function(ctx, oldval, newval) { var applyChange = function(ctx, oldval, newval) {
if (oldval === newval) return; if (oldval === newval) {
return;
}
var commonStart = 0; var commonStart = 0;
while (oldval.charAt(commonStart) === newval.charAt(commonStart)) { while (oldval.charAt(commonStart) === newval.charAt(commonStart)) {

@ -7,7 +7,7 @@ define([
'/customize/pad.js' '/customize/pad.js'
], function (Config, Realtime, Messages, Crypto) { ], function (Config, Realtime, Messages, Crypto) {
// TODO consider adding support for less.js // TODO consider adding support for less.js
var $ = jQuery; var $ = window.jQuery;
$(window).on('hashchange', function() { $(window).on('hashchange', function() {
window.location.reload(); window.location.reload();
}); });

@ -6,7 +6,7 @@ define([
'/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery/dist/jquery.min.js',
'/customize/pad.js' '/customize/pad.js'
], function (Config, Realtime, Messages, Crypto) { ], function (Config, Realtime, Messages, Crypto) {
var $ = jQuery; var $ = window.jQuery;
$(window).on('hashchange', function() { $(window).on('hashchange', function() {
window.location.reload(); window.location.reload();
}); });

@ -1,3 +1,6 @@
/*
globals define console
*/
define([ define([
'/api/config?cb=' + Math.random().toString(16).substring(2), '/api/config?cb=' + Math.random().toString(16).substring(2),
'/common/messages.js', '/common/messages.js',
@ -13,8 +16,10 @@ define([
], function (Config, Messages, Crypto, realtimeInput, Convert, Toolbar, Cursor) { ], function (Config, Messages, Crypto, realtimeInput, Convert, Toolbar, Cursor) {
var $ = window.jQuery; var $ = window.jQuery;
var ifrw = $('#pad-iframe')[0].contentWindow; var ifrw = $('#pad-iframe')[0].contentWindow;
var Ckeditor; // to be initialized later...
//window.Ckeditor = ifrw.CKEDITOR; //window.Ckeditor = ifrw.CKEDITOR;
var DiffDom = window.diffDOM; var DiffDom = window.diffDOM;
var ChainPad = window.ChainPad;
var userName = Crypto.rand64(8), var userName = Crypto.rand64(8),
toolbar; toolbar;
@ -35,7 +40,7 @@ define([
var fixThings = false; var fixThings = false;
var key = Crypto.parseKey(window.location.hash.substring(1)); var key = Crypto.parseKey(window.location.hash.substring(1));
window.editor = Ckeditor.replace('editor1', { var editor = window.editor = Ckeditor.replace('editor1', {
// https://dev.ckeditor.com/ticket/10907 // https://dev.ckeditor.com/ticket/10907
needsBrFiller: fixThings, needsBrFiller: fixThings,
needsNbspFiller: fixThings, needsNbspFiller: fixThings,
@ -45,7 +50,6 @@ define([
removePlugins: 'magicline,resize' removePlugins: 'magicline,resize'
}); });
editor.on('instanceReady', function (Ckeditor) { editor.on('instanceReady', function (Ckeditor) {
editor.execCommand('maximize'); editor.execCommand('maximize');
var documentBody = ifrw.$('iframe')[0].contentDocument.body; var documentBody = ifrw.$('iframe')[0].contentDocument.body;
@ -54,7 +58,7 @@ define([
var inner = documentBody; var inner = documentBody;
window.inner = inner; window.inner = inner;
window.cursor = Cursor(Ckeditor, editor, inner); var cursor = window.cursor = Cursor(Ckeditor, editor, inner);
var $textarea = $('#feedback'); var $textarea = $('#feedback');
@ -62,7 +66,9 @@ define([
var applyHjson = function (shjson) { var applyHjson = function (shjson) {
console.log("Applying HJSON"); console.log("Applying HJSON");
var userDocStateDom = Vdom.create(Convert.hjson.to.vdom(JSON.parse(shjson))); var userDocStateDom = Convert.hjson.to.dom(JSON.parse(shjson));
//var userDocStateDom = Vdom.create(Convert.hjson.to.vdom(JSON.parse(shjson)));
userDocStateDom.setAttribute("contentEditable", "true"); // lol wtf userDocStateDom.setAttribute("contentEditable", "true"); // lol wtf
var patch = (new DiffDom()).diff(inner, userDocStateDom); var patch = (new DiffDom()).diff(inner, userDocStateDom);
(new DiffDom()).apply(inner, patch); (new DiffDom()).apply(inner, patch);
@ -77,14 +83,15 @@ define([
cursor.find(); cursor.find();
// put the cursor back where you left it // put the cursor back where you left it
cursor.replace(); // FIXME put this back in
//cursor.replace();
}; };
var onInit = function (info) { var onInit = function (info) {
// TODO initialize the toolbar // TODO initialize the toolbar
}; };
window.rti = realtimeInput.start($textarea[0], // synced element var rti = realtimeInput.start($textarea[0], // synced element
Config.websocketURL, // websocketURL, ofc Config.websocketURL, // websocketURL, ofc
userName, // userName userName, // userName
key.channel, // channelName key.channel, // channelName

Loading…
Cancel
Save