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

View file

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

View file

@ -52,8 +52,8 @@ $.Class("SliderHandleUI",
},
_mouseInit: function () {
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();
},
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);
this.handles.push(handle);
this.element.append(handle.element);
@ -160,10 +160,10 @@ $.Class("SliderUI",
});
} else {
console.log("We shouldn't be here!")
console.log("We shouldn't be here!");
console.log(event.target);
}
})
});
},
}
);

View file

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