jshint compliance

This commit is contained in:
ansuz 2016-02-15 16:07:46 +01:00
parent d1885fbab6
commit 3cb94b8d80
16 changed files with 52 additions and 29 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -52,7 +52,7 @@ define(function () {
*/
var applyChange = function(ctx, oldval, newval) {
// 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;
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.
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
// cursor drift if the element isn't active, though usually users don't

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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