Cleanup code (jshint)

This commit is contained in:
s1341 2013-12-12 13:43:33 +02:00
parent 88971c1462
commit 3d4b6a9a4a
4 changed files with 69 additions and 68 deletions

View file

@ -39,7 +39,7 @@ $.Class("RevisionSlider",
this.elements = {}; this.elements = {};
this.loadElements(root_element); this.loadElements(root_element);
var _this = this; var _this = this;
this.slider = new SliderUI(this.elements['slider-bar'], this.slider = new SliderUI(this.elements.slider_bar,
options = { options = {
max: this.timeslider.head_revision, max: this.timeslider.head_revision,
change: function () { _this.onChange.apply(_this, arguments); }, change: function () { _this.onChange.apply(_this, arguments); },
@ -56,23 +56,23 @@ $.Class("RevisionSlider",
console.log("in slide handler:", value); console.log("in slide handler:", value);
}, },
loadElements: function (root_element) { loadElements: function (root_element) {
this.elements['root'] = root_element; this.elements.root = root_element;
//this.elements['slider-handle'] = root_element.first("#ui-slider-handle"); //this.elements['slider-handle'] = root_element.first("#ui-slider-handle");
this.elements['slider-bar'] = root_element.find("#ui-slider-bar"); this.elements.slider_bar = root_element.find("#ui-slider-bar");
this.elements['slider'] = root_element.find("#timeslider-slider"); this.elements.slider = root_element.find("#timeslider-slider");
this.elements['button-left'] = root_element.find("#leftstep"); this.elements.button_left = root_element.find("#leftstep");
this.elements['button-right'] = root_element.find("#rightstep"); this.elements.button_right = root_element.find("#rightstep");
this.elements['button-play'] = root_element.find("#playpause_button"); this.elements.button_play = root_element.find("#playpause_button");
this.elements['timestamp'] = root_element.find("#timer"); this.elements.timestamp = root_element.find("#timer");
this.elements['revision-label'] = root_element.find("#revision_label"); this.elements.revision_label = root_element.find("#revision_label");
this.elements['revision-date'] = root_element.find("#revision_date"); this.elements.revision_date = root_element.find("#revision_date");
this.elements['authors'] = root_element.first("#authorsList"); this.elements.authors = root_element.first("#authorsList");
}, },
loadSavedRevisionHandles: function () { loadSavedRevisionHandles: function () {
for (var r in this.timeslider.savedRevisions) { for (var r in this.timeslider.savedRevisions) {
var rev = this.timeslider.savedRevisions[r]; var rev = this.timeslider.savedRevisions[r];
this.slider.createHandle(rev.revNum, "star"); this.slider.createHandle(rev.revNum, "star");
}; }
}, },
goToRevision: function (revNum) { goToRevision: function (revNum) {
//TODO: this should actually do an async jump to revision (with all the server fetching //TODO: this should actually do an async jump to revision (with all the server fetching
@ -83,7 +83,7 @@ $.Class("RevisionSlider",
revNum = this.timeslider.latest_revision; revNum = this.timeslider.latest_revision;
if (revNum < 0) if (revNum < 0)
revNum = 0; revNum = 0;
console.log("GO TO REVISION", revNum) console.log("GO TO REVISION", revNum);
this.elements["revision-label"].html(html10n.get("timeslider.version", { "version": revNum })); this.elements["revision-label"].html(html10n.get("timeslider.version", { "version": revNum }));
this.slider.setValue(revNum); this.slider.setValue(revNum);
this.revision_number = revNum; this.revision_number = revNum;
@ -91,12 +91,12 @@ $.Class("RevisionSlider",
}, },
_mouseInit: function () { _mouseInit: function () {
var _this = this; var _this = this;
this.elements["button-left"].on("click", function (event) { this.elements.button_left.on("click", function (event) {
console.log("was :", _this.revision_number); console.log("was :", _this.revision_number);
_this.goToRevision(_this.revision_number - 1); _this.goToRevision(_this.revision_number - 1);
}); });
this.elements["button-right"].on("click", function (event) { this.elements.button_right.on("click", function (event) {
_this.goToRevision(_this.revision_number + 1); _this.goToRevision(_this.revision_number + 1);
}); });
@ -147,7 +147,7 @@ function loadBroadcastSliderJS(tsclient, fireWhenAllScriptsAreLoaded)
{ {
slidercallbacks[i](newval); slidercallbacks[i](newval);
} }
} };
var removeSavedRevision = function(position) var removeSavedRevision = function(position)
{ {
var element = $("div.star [pos=" + position + "]"); var element = $("div.star [pos=" + position + "]");
@ -184,10 +184,10 @@ function loadBroadcastSliderJS(tsclient, fireWhenAllScriptsAreLoaded)
$("#revision_label").html(html10n.get("timeslider.version", { "version": newpos})); $("#revision_label").html(html10n.get("timeslider.version", { "version": newpos}));
if (newpos == 0) if (newpos === 0)
{ {
$("#leftstar").css('opacity', .5); $("#leftstar").css('opacity', 0.5);
$("#leftstep").css('opacity', .5); $("#leftstep").css('opacity', 0.5);
} }
else else
{ {
@ -197,8 +197,8 @@ function loadBroadcastSliderJS(tsclient, fireWhenAllScriptsAreLoaded)
if (newpos == sliderLength) if (newpos == sliderLength)
{ {
$("#rightstar").css('opacity', .5); $("#rightstar").css('opacity', 0.5);
$("#rightstep").css('opacity', .5); $("#rightstep").css('opacity', 0.5);
} }
else else
{ {
@ -285,7 +285,7 @@ function loadBroadcastSliderJS(tsclient, fireWhenAllScriptsAreLoaded)
} }
} }
if (authors.length == 0) if (authors.length === 0)
{ {
authorsList.append(html10n.get("timeslider.toolbar.authorsList")); authorsList.append(html10n.get("timeslider.toolbar.authorsList"));
} }
@ -308,7 +308,7 @@ function loadBroadcastSliderJS(tsclient, fireWhenAllScriptsAreLoaded)
playpause: playpause, playpause: playpause,
showReconnectUI: showReconnectUI, showReconnectUI: showReconnectUI,
setAuthors: setAuthors setAuthors: setAuthors
} };
function playButtonUpdater() function playButtonUpdater()
{ {
@ -352,7 +352,7 @@ function loadBroadcastSliderJS(tsclient, fireWhenAllScriptsAreLoaded)
$(document).keyup(function(e) $(document).keyup(function(e)
{ {
var code = -1; var code = -1;
if (!e) var e = window.event; if (!e) e = window.event;
if (e.keyCode) code = e.keyCode; if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which; else if (e.which) code = e.which;
@ -381,13 +381,13 @@ function loadBroadcastSliderJS(tsclient, fireWhenAllScriptsAreLoaded)
} }
else else
{ {
var nextStar = sliderLength; // default to last revision in document var _nextStar = sliderLength; // default to last revision in document
for (var i = 0; i < savedRevisions.length; i++) for (var _i = 0; _i < savedRevisions.length; _i++)
{ {
var pos = parseInt(savedRevisions[i].attr('pos')); var _pos = parseInt(savedRevisions[_i].attr('pos'));
if (pos > getSliderPosition() && nextStar > pos) nextStar = pos; if (_pos > getSliderPosition() && _nextStar > _pos) _nextStar = _pos;
} }
setSliderPosition(nextStar); setSliderPosition(_nextStar);
} }
} }
else if (code == 32) playpause(); else if (code == 32) playpause();
@ -430,7 +430,7 @@ function loadBroadcastSliderJS(tsclient, fireWhenAllScriptsAreLoaded)
var newcss = (origcss.split(" ")[0] + " " + newpos + "px"); var newcss = (origcss.split(" ")[0] + " " + newpos + "px");
if ($(self).css('opacity') != 1.0) newcss = origcss; if ($(self).css('opacity') != 1.0) newcss = origcss;
$(self).css('background-position', newcss) $(self).css('background-position', newcss);
$(self).mouseup(function(evt2) $(self).mouseup(function(evt2)
{ {
@ -457,13 +457,13 @@ function loadBroadcastSliderJS(tsclient, fireWhenAllScriptsAreLoaded)
} }
else if ($(self).attr("id") == ("rightstar")) else if ($(self).attr("id") == ("rightstar"))
{ {
var nextStar = sliderLength; // default to last revision in document var _nextStar = sliderLength; // default to last revision in document
for (var i = 0; i < savedRevisions.length; i++) for (var _i = 0; _i < savedRevisions.length; _i++)
{ {
var pos = parseInt(savedRevisions[i].attr('pos')); var _pos = parseInt(savedRevisions[_i].attr('pos'));
if (pos > getSliderPosition() && nextStar > pos) nextStar = pos; if (_pos > getSliderPosition() && _nextStar > _pos) _nextStar = _pos;
} }
setSliderPosition(nextStar); setSliderPosition(_nextStar);
} }
}); });
$(document).mouseup(function(evt2) $(document).mouseup(function(evt2)
@ -472,7 +472,7 @@ function loadBroadcastSliderJS(tsclient, fireWhenAllScriptsAreLoaded)
$(self).unbind('mouseup'); $(self).unbind('mouseup');
$(document).unbind('mouseup'); $(document).unbind('mouseup');
}); });
}) });
if (clientVars) if (clientVars)
{ {
@ -485,7 +485,7 @@ function loadBroadcastSliderJS(tsclient, fireWhenAllScriptsAreLoaded)
BroadcastSlider.onSlider(function(loc) BroadcastSlider.onSlider(function(loc)
{ {
$("#viewlatest").html(loc == BroadcastSlider.getSliderLength() ? "Viewing latest content" : "View latest content"); $("#viewlatest").html(loc == BroadcastSlider.getSliderLength() ? "Viewing latest content" : "View latest content");
}) });
return BroadcastSlider; return BroadcastSlider;
} }

View file

@ -50,8 +50,8 @@ $.Class("DirectionalIterator",
self.current = self.direction ? self.list.length - 1 : 0; self.current = self.direction ? self.list.length - 1 : 0;
}, },
haveNext: function () { haveNext: function () {
if ((self.direction && self.current > 0) if ((self.direction && self.current > 0) ||
|| (!self.direction && self.current < self.list.length)) (!self.direction && self.current < self.list.length))
return true; return true;
return false; return false;
}, },
@ -97,7 +97,7 @@ $.Class("Revision2",
for (var granularity in this.granularties) { for (var granularity in this.granularties) {
this.next[granularity] = null; this.next[granularity] = null;
this.previous[granularity] = null; this.previous[granularity] = null;
}; }
}, },
addChangeset: function (target, changset, timedelta) { addChangeset: function (target, changset, timedelta) {
if (this.revnum == target.revnum) if (this.revnum == target.revnum)
@ -114,8 +114,8 @@ $.Class("Revision2",
//TODO: modify changeset to store the REVISION, not the revnum. //TODO: modify changeset to store the REVISION, not the revnum.
edge[granularity] = new Changeset(target, timedelta, changeset); edge[granularity] = new Changeset(target, timedelta, changeset);
return edge[granularity]; return edge[granularity];
}; }
}; }
// our delta_revnum isn't one of the granularities. Something is wrong // our delta_revnum isn't one of the granularities. Something is wrong
//TODO: handle this case? //TODO: handle this case?
return null; return null;
@ -129,7 +129,7 @@ $.Class("Revision2",
var current = this; var current = this;
while (current.lt(target)) { while (current.lt(target)) {
for (var granularity in this.granularities) { for (var granularity in this.granularities) {
if (! Math.abs(current.revnum - target.revnum) >= this.granularities[granularity]) { if (Math.abs(current.revnum - target.revnum) >= this.granularities[granularity]) {
// the delta is larger than the granularity, let's use the granularity // the delta is larger than the granularity, let's use the granularity
//TODO: what happens if we DON'T have the edge? //TODO: what happens if we DON'T have the edge?
// in theory we need to fetch it (and this is certainly the case for playback // in theory we need to fetch it (and this is certainly the case for playback
@ -140,11 +140,11 @@ $.Class("Revision2",
path.push(e); path.push(e);
current = e.target_revision; current = e.target_revision;
break; break;
}; }
}; }
//TODO: none of the granularities matched. WTF? This probably means that there is NO useful //TODO: none of the granularities matched. WTF? This probably means that there is NO useful
//edge in the direction of traversal. Is this a termination condition? //edge in the direction of traversal. Is this a termination condition?
}; }
return path; return path;
} }
} }
@ -202,7 +202,7 @@ $.Class("RevisionCache",
findPath: function (from, to) { findPath: function (from, to) {
var current_rev = this.getRevision(from); var current_rev = this.getRevision(from);
var to_rev = this.getRevision(to); var to_rev = this.getRevision(to);
var is_reverse = !(from < to); var is_reverse = (from >= to);
var res = { var res = {
from: current_rev, from: current_rev,
current: current_rev, current: current_rev,
@ -300,10 +300,10 @@ $.Class("Thread",
// start the run loop // start the run loop
start: function () { start: function () {
var _this = this; var _this = this;
console.log("[thread] starting") console.log("[thread] starting");
var wrapper = function () { var wrapper = function () {
if (_this._is_running && _this._is_stopping) { if (_this._is_running && _this._is_stopping) {
console.log("[thread] shutting down") console.log("[thread] shutting down");
clearInterval(_this._interval_id); clearInterval(_this._interval_id);
_this._is_running = false; _this._is_running = false;
return; return;
@ -317,7 +317,7 @@ $.Class("Thread",
// stop the run loop // stop the run loop
stop: function () { stop: function () {
this._is_stopping = true; this._is_stopping = true;
console.log("[thread] request stop") console.log("[thread] request stop");
// TODO: consider finding a way to make this block // TODO: consider finding a way to make this block
// or alternatively, having a callback which is called // or alternatively, having a callback which is called
// when the thread stops // when the thread stops
@ -364,7 +364,7 @@ Thread("ChangesetLoader",
small: [], small: [],
medium: [], medium: [],
large: [], large: [],
} };
this.pending = {}; this.pending = {};
var _this = this; var _this = this;
this.connection.on("CHANGESET_REQ", function () { this.connection.on("CHANGESET_REQ", function () {
@ -412,8 +412,12 @@ Thread("ChangesetLoader",
}, },
_run: function () { _run: function () {
console.log("[changesetloader] tick"); console.log("[changesetloader] tick");
var _this = this;
function addToPending () {
_this.pending[request.getRequestID()] = request;
}
//TODO: pop an item from the queue and perform a request. //TODO: pop an item from the queue and perform a request.
for (q in this.queues) { for (var q in this.queues) {
var queue = this.queues[q]; var queue = this.queues[q];
if (queue.length > 0) { if (queue.length > 0) {
// TODO: pop and handle // TODO: pop and handle
@ -426,23 +430,20 @@ Thread("ChangesetLoader",
//need to perform a server request. Note: it might be worth changing enqueue //need to perform a server request. Note: it might be worth changing enqueue
//to check the pending requests queue to avoid this situation entirely. //to check the pending requests queue to avoid this situation entirely.
var _this = this;
this.connection.sendMessage("CHANGESET_REQ", { this.connection.sendMessage("CHANGESET_REQ", {
start: request.start, start: request.start,
granularity: request.granularity, granularity: request.granularity,
requestID: request.getRequestID(), requestID: request.getRequestID(),
}, function () { }, addToPending);
_this.pending[request.getRequestID()] = request; }
}); }
};
};
//TODO: this stop is just for debugging!!!! //TODO: this stop is just for debugging!!!!
//FIXME: remove when done testing //FIXME: remove when done testing
this.stop(); this.stop();
}, },
on_response: function (data) { on_response: function (data) {
console.log("on_response: ", data) console.log("on_response: ", data);
if (!data.requestID in this.pending) { if (!(data.requestID in this.pending)) {
console.log("[changesetloader] WTF? changeset not pending: ", data.requestID); console.log("[changesetloader] WTF? changeset not pending: ", data.requestID);
return; return;
} }
@ -488,7 +489,7 @@ $.Class("PadClient",
var div = this._getDivForLine(this.lines[i], this.alines[i]); var div = this._getDivForLine(this.lines[i], this.alines[i]);
this.divs.push(div); this.divs.push(div);
this.padcontent.append(div); this.padcontent.append(div);
}; }
//TODO: monkey patch divs.splice to use our custom splice function //TODO: monkey patch divs.splice to use our custom splice function
this.divs.original_splice = this.divs.splice; this.divs.original_splice = this.divs.splice;
@ -536,7 +537,7 @@ $.Class("PadClient",
// remove howMany divs starting from index. We need to remove them from // remove howMany divs starting from index. We need to remove them from
// the DOM. // the DOM.
for (var i = index; i < howMany && i < this.divs.length; i++) for (var i = index; i < howMany && i < this.divs.length; i++)
this.divs[i].remove() this.divs[i].remove();
// generate divs for the new elements: // generate divs for the new elements:
var newdivs = []; var newdivs = [];

View file

@ -52,8 +52,8 @@ $.Class("SliderHandleUI",
}, },
_mouseInit: function () { _mouseInit: function () {
this.element.on("mousedown.sliderhandle", null, this, function(event) { this.element.on("mousedown.sliderhandle", null, this, function(event) {
console.log("sliderhandleui - mousedown") console.log("sliderhandleui - mousedown");
}) });
}, },
} }
); );
@ -115,7 +115,7 @@ $.Class("SliderUI",
this.render(); this.render();
}, },
createHandle: function (value, type) { createHandle: function (value, type) {
console.log("createHandle(%d, %s)", value, type) console.log("createHandle(%d, %s)", value, type);
var handle = new SliderHandleUI(this, value, type); var handle = new SliderHandleUI(this, value, type);
this.handles.push(handle); this.handles.push(handle);
this.element.append(handle.element); this.element.append(handle.element);
@ -160,10 +160,10 @@ $.Class("SliderUI",
}); });
} else { } else {
console.log("We shouldn't be here!") console.log("We shouldn't be here!");
console.log(event.target); console.log(event.target);
} }
}) });
}, },
} }
); );

View file

@ -24,7 +24,7 @@
// assigns to the global `$` and augments it with plugins. // assigns to the global `$` and augments it with plugins.
require('./jquery'); require('./jquery');
require('./jquery.class'); require('./jquery.class');
JSON = require('./json2'); //JSON = require('./json2');
var createCookie = require('./pad_utils').createCookie; var createCookie = require('./pad_utils').createCookie;
var readCookie = require('./pad_utils').readCookie; var readCookie = require('./pad_utils').readCookie;