More linting. This time of the JavaScript for the chat-box extension.

This commit is contained in:
jgen 2014-04-23 22:43:42 -04:00
parent 0bd031a269
commit 8cdf919827
2 changed files with 87 additions and 77 deletions

View file

@ -1,7 +1,11 @@
/*jshint bitwise:true, curly:true, devel:true, eqeqeq:true, evil:true, forin:false, noarg:true, noempty:true, nonew:true, undef:true, strict:false, browser:true, jquery:true */
Array.prototype.inArray = function (value) { Array.prototype.inArray = function (value) {
for (var i = 0; i < this.length; i++) for (var i = 0; i < this.length; i++) {
if (this[i] === value) if (this[i] === value) {
return true; return true;
}
}
return false; return false;
}; };
@ -25,8 +29,9 @@ AdminCP.prototype = {
this.initializing = true; this.initializing = true;
this.loginForm(); this.loginForm();
this.initEvents(); this.initEvents();
if (this.loaded()) this.afterLogin(); if (this.loaded()) {
else { this.afterLogin();
} else {
$('#login-password')[0].focus(); $('#login-password')[0].focus();
} }
@ -54,10 +59,11 @@ AdminCP.prototype = {
$('.logout').click(function() { self.logout(); return false; }); $('.logout').click(function() { self.logout(); return false; });
// Show the nav // Show the nav
if (this.initializing) if (this.initializing) {
$('#nav ul').css('display', 'block'); $('#nav ul').css('display', 'block');
else } else {
$('#nav ul').slideDown(); $('#nav ul').slideDown();
}
// Some css for betterlookingness // Some css for betterlookingness
$('#preferences-form fieldset:odd').addClass('odd'); $('#preferences-form fieldset:odd').addClass('odd');
@ -75,10 +81,11 @@ AdminCP.prototype = {
// If they want to go directly to a section // If they want to go directly to a section
var anchor = this.getAnchor(); var anchor = this.getAnchor();
if (anchor.length > 0 && ['preferences', 'bans', 'about'].inArray(anchor)) if (anchor.length > 0 && ['preferences', 'bans', 'about'].inArray(anchor)) {
self.show(anchor); self.show(anchor);
else } else {
self.show('preferences'); self.show('preferences');
}
}, },
initEventsAfter: function() { initEventsAfter: function() {
@ -101,15 +108,16 @@ AdminCP.prototype = {
// Preferences // Preferences
$('#preferences-form input').keypress(function(e) { $('#preferences-form input').keypress(function(e) {
var key = window.event ? e.keyCode : e.which; var key = window.event ? e.keyCode : e.which;
if (key == 13 || key == 3) { if (key === 13 || key === 3) {
self.changePref.apply(self, [$(this).attr('rel'), this.value]); self.changePref.apply(self, [$(this).attr('rel'), this.value]);
return false; return false;
} }
}).focus(function() { }).focus(function() {
this.name = this.value; this.name = this.value;
}).blur(function() { }).blur(function() {
if (this.name != this.value) if (this.name !== this.value) {
self.changePref.apply(self, [$(this).attr('rel'), this.value]); self.changePref.apply(self, [$(this).attr('rel'), this.value]);
}
}); });
$('#preferences-form select').change(function() { $('#preferences-form select').change(function() {
@ -125,10 +133,11 @@ AdminCP.prototype = {
'value': value 'value': value
}; };
this.ajax(function(json) { this.ajax(function(json) {
if (!json.error) if (!json.error) {
this.done(); this.done();
else } else {
alert(json.error); alert(json.error);
}
}, pars); }, pars);
}, },
@ -137,20 +146,20 @@ AdminCP.prototype = {
var pars = { var pars = {
mode: 'resetpreferences' mode: 'resetpreferences'
} };
this.ajax(function(json) { this.ajax(function(json) {
this.done(); this.done();
if (json.prefs) if (json.prefs) {
for(pref in json.prefs) { for (pref in json.prefs) {
var value = json.prefs[pref]; var value = json.prefs[pref];
var el = $('#preferences-form input[@rel=' + pref + '], select[@rel=' + pref + ']')[0]; var el = $('#preferences-form input[@rel=' + pref + '], select[@rel=' + pref + ']')[0];
if (el.type == 'text') if (el.type === 'text') {
el.value = value; el.value = value;
else { } else {
if (value == true) value = 'true'; if (value === true) { value = 'true'; }
if (value == false) value = 'false'; if (value === false) { value = 'false'; }
$('#preferences-form select[@rel=' + pref + ']') $('#preferences-form select[@rel=' + pref + ']')
.find('option') .find('option')
@ -158,11 +167,10 @@ AdminCP.prototype = {
.end() .end()
.find('option[@rel=' + value + ']') .find('option[@rel=' + value + ']')
.attr('selected', 'yeah'); .attr('selected', 'yeah');
} }
} }
}, pars); }
}, pars);
}, },
invalidPassword: function() { invalidPassword: function() {
@ -230,49 +238,53 @@ AdminCP.prototype = {
// if (!sections.inArray(section)) section = 'preferences'; // if (!sections.inArray(section)) section = 'preferences';
if ($.browser.msie) { if ($.browser.msie) {
if (section == 'preferences') if (section === 'preferences') {
$('#preferences select').css('display', 'block'); $('#preferences select').css('display', 'block');
else } else {
$('#preferences select').css('display', 'none'); $('#preferences select').css('display', 'none');
}
} }
if (section == this.curSection) return; if (section === this.curSection) { return; }
this.curSection = section; this.curSection = section;
$('#' + section)[0].style.zIndex = ++this.z; $('#' + section)[0].style.zIndex = ++this.z;
if (this.initializing)
if (this.initializing) {
$('#' + section).css('display', 'block'); $('#' + section).css('display', 'block');
else } else {
$('#' + section).fadeIn(this.animSpeed, callback); $('#' + section).fadeIn(this.animSpeed, callback);
}
}, },
showPrefPane: function(pane) { showPrefPane: function(pane) {
var self = this; var self = this;
if (pane == this.curPrefPane) return; if (pane === this.curPrefPane) { return; }
this.curPrefPane = pane; this.curPrefPane = pane;
$('#preferences .cp-pane').css('display', 'none'); $('#preferences .cp-pane').css('display', 'none');
$('#cp-pane-' + pane).css('display', 'block').fadeIn(this.animSpeed, function() { $('#cp-pane-' + pane).css('display', 'block').fadeIn(this.animSpeed, function() {
if (self.curPrefPane == pane) if (self.curPrefPane === pane) {
$('#preferences .cp-pane').not('#cp-pane-' + pane).css('display', 'none'); $('#preferences .cp-pane').not('#cp-pane-' + pane).css('display', 'none');
else } else {
$('#cp-pane-' + pane).css('display', 'none'); $('#cp-pane-' + pane).css('display', 'none');
}
}); });
}, },
showAboutPane: function(pane) { showAboutPane: function(pane) {
var self = this; var self = this;
if (pane == this.curAboutPane) return; if (pane === this.curAboutPane) { return; }
this.curAboutPane = pane; this.curAboutPane = pane;
$('#about .cp-pane').css('display', 'none'); $('#about .cp-pane').css('display', 'none');
$('#cp-pane-' + pane).css('display', 'block').fadeIn(this.animSpeed, function() { $('#cp-pane-' + pane).css('display', 'block').fadeIn(this.animSpeed, function() {
if (self.curAboutPane == pane) if (self.curAboutPane === pane) {
$('#about .cp-pane').not('#cp-pane-' + pane).css('display', 'none'); $('#about .cp-pane').not('#cp-pane-' + pane).css('display', 'none');
else } else {
$('#cp-pane-' + pane).css('display', 'none'); $('#cp-pane-' + pane).css('display', 'none');
}
}); });
}, },
@ -281,13 +293,15 @@ AdminCP.prototype = {
$.post('ajax.php', pars, function(parse) { $.post('ajax.php', pars, function(parse) {
// alert(parse); // alert(parse);
if (parse) if (parse) {
if (html) if (html) {
callback.apply(self, [parse]); callback.apply(self, [parse]);
else } else {
callback.apply(self, [self.json(parse)]); callback.apply(self, [self.json(parse)]);
else }
} else {
callback.apply(self); callback.apply(self);
}
}); });
}, },
@ -297,7 +311,7 @@ AdminCP.prototype = {
}, },
loaded: function() { loaded: function() {
return ($('#cp-loaded').length == 1); return ($('#cp-loaded').length === 1);
}, },
loading: function() { loading: function() {
@ -325,10 +339,11 @@ AdminCP.prototype = {
}, },
getAnchor: function() { getAnchor: function() {
var href = window.location.href; var href = window.location.href;
if (href.indexOf('#') > -1 ) if (href.indexOf('#') > -1 ) {
return href.substr(href.indexOf('#') + 1).toLowerCase(); return href.substr(href.indexOf('#') + 1).toLowerCase();
return ''; }
return '';
}, },
unban: function(ip, el) { unban: function(ip, el) {
@ -357,7 +372,7 @@ AdminCP.prototype = {
var pars = { var pars = {
mode: 'unbanall' mode: 'unbanall'
} };
this.ajax(function(json) { this.ajax(function(json) {
this.done(); this.done();

View file

@ -1,3 +1,5 @@
/*jshint bitwise:true, curly:true, devel:true, eqeqeq:true, evil:true, forin:false, noarg:true, noempty:true, nonew:true, undef:true, strict:false, browser:true, jquery:true */
var History = function() { var History = function() {
var self = this; var self = this;
var args = arguments; var args = arguments;
@ -17,13 +19,11 @@ History.prototype = {
$('body').ScrollToAnchors({ duration: 800 }); $('body').ScrollToAnchors({ duration: 800 });
}, },
initEvents: function() { initEvents: function() {
var self = this; var self = this;
this.initLogEvents(); this.initLogEvents();
// Select log // Select log
$('#log').change(function() { $('#log').change(function() {
var logIndex = $(this).find('option[@selected]').attr('rel'); var logIndex = $(this).find('option[@selected]').attr('rel');
@ -31,15 +31,13 @@ History.prototype = {
var pars = { var pars = {
p: 'yes', p: 'yes',
log: logIndex log: logIndex
} };
self.ajax(function(html) { self.ajax(function(html) {
$('#ys-posts').html(html) $('#ys-posts').html(html);
$('#yshout').fadeIn(); $('#yshout').fadeIn();
self.initLogEvents(); self.initLogEvents();
}, pars, true, 'index.php'); }, pars, true, 'index.php');
}); });
// Clear the log // Clear the log
@ -56,13 +54,12 @@ History.prototype = {
self.error('You\'re not an admin. Log in through the admin CP to clear the log.'); self.error('You\'re not an admin. Log in through the admin CP to clear the log.');
el.innerHTML = 'Clear this log'; el.innerHTML = 'Clear this log';
return; return;
break;
} }
} }
$('#ys-posts').html(self.noPosts); $('#ys-posts').html(self.noPosts);
self.initLogEvents(); self.initLogEvents();
el.innerHTML = 'Clear this log' el.innerHTML = 'Clear this log';
}, pars); }, pars);
this.innerHTML = 'Clearing...'; this.innerHTML = 'Clearing...';
@ -80,16 +77,15 @@ History.prototype = {
if (json.error) { if (json.error) {
switch(json.error) { switch(json.error) {
case 'admin': case 'admin':
el.innerHTML = 'Clear all logs' el.innerHTML = 'Clear all logs';
self.error('You\'re not an admin. Log in through the admin CP to clear logs.'); self.error('You\'re not an admin. Log in through the admin CP to clear logs.');
return; return;
break;
} }
} }
$('#ys-posts').html(self.noPosts); $('#ys-posts').html(self.noPosts);
self.initLogEvents(); self.initLogEvents();
el.innerHTML = 'Clear all logs' el.innerHTML = 'Clear all logs';
}, pars); }, pars);
this.innerHTML = 'Clearing...'; this.innerHTML = 'Clearing...';
@ -115,26 +111,28 @@ History.prototype = {
showInfo: function(id, el) { showInfo: function(id, el) {
var jEl = $('#' + id + ' .ys-post-info'); var jEl = $('#' + id + ' .ys-post-info');
if (jEl.length == 0) return false; if (jEl.length === 0) { return false; }
if (this.prefsInfo == 'overlay') if (this.prefsInfo === 'overlay') {
jEl.css('display', 'block').fadeIn(this.animSpeed); jEl.css('display', 'block').fadeIn(this.animSpeed);
else } else {
jEl.slideDown(this.animSpeed); jEl.slideDown(this.animSpeed);
}
el.innerHTML ='Close Info' el.innerHTML ='Close Info';
return false; return false;
}, },
hideInfo: function(id, el) { hideInfo: function(id, el) {
var jEl = $('#' + id + ' .ys-post-info'); var jEl = $('#' + id + ' .ys-post-info');
if (jEl.length == 0) return false; if (jEl.length === 0) { return false; }
if (this.prefsInfo == 'overlay') if (this.prefsInfo === 'overlay') {
jEl.fadeOut(this.animSpeed); jEl.fadeOut(this.animSpeed);
else } else {
jEl.slideUp(this.animSpeed); jEl.slideUp(this.animSpeed);
}
el.innerHTML = 'Info'; el.innerHTML = 'Info';
return false; return false;
@ -144,7 +142,8 @@ History.prototype = {
var self = this; var self = this;
var link = $('#' + post.id).find('.ys-ban-link')[0]; var link = $('#' + post.id).find('.ys-ban-link')[0];
switch(link.innerHTML) { switch(link.innerHTML)
{
case 'Ban': case 'Ban':
var pIP = $(post).find('.ys-h-ip').html(); var pIP = $(post).find('.ys-h-ip').html();
var pNickname = $(post).find('.ys-h-nickname').html(); var pNickname = $(post).find('.ys-h-nickname').html();
@ -175,11 +174,9 @@ History.prototype = {
link.innerHTML = 'Banning...'; link.innerHTML = 'Banning...';
return false; return false;
break;
case 'Banning...': case 'Banning...':
return false; return false;
break;
case 'Unban': case 'Unban':
var pIP = $(post).find('.ys-h-ip').html(); var pIP = $(post).find('.ys-h-ip').html();
@ -194,7 +191,6 @@ History.prototype = {
case 'admin': case 'admin':
self.error('You\'re not an admin. Log in through the admin CP to unban people.'); self.error('You\'re not an admin. Log in through the admin CP to unban people.');
return; return;
break;
} }
} }
@ -207,11 +203,9 @@ History.prototype = {
link.innerHTML = 'Unbanning...'; link.innerHTML = 'Unbanning...';
return false; return false;
break;
case 'Unbanning...': case 'Unbanning...':
return false; return false;
break;
} }
}, },
@ -219,7 +213,7 @@ History.prototype = {
var self = this; var self = this;
var link = $('#' + post.id).find('.ys-delete-link')[0]; var link = $('#' + post.id).find('.ys-delete-link')[0];
if (link.innerHTML == 'Deleting...') return; if (link.innerHTML === 'Deleting...') { return; }
var pUID = $(post).find('.ys-h-uid').html(); var pUID = $(post).find('.ys-h-uid').html();
@ -234,7 +228,6 @@ History.prototype = {
case 'admin': case 'admin':
self.error('You\'re not an admin. Log in through the admin CP to ban people.'); self.error('You\'re not an admin. Log in through the admin CP to ban people.');
return; return;
break;
} }
} }
@ -260,16 +253,18 @@ History.prototype = {
var self = this; var self = this;
if (page == null) page = '../yshout.php'; if (page === null) { page = '../yshout.php'; }
$.post(page, pars, function(parse) { $.post(page, pars, function(parse) {
if (parse) if (parse) {
if (html) if (html) {
callback.apply(self, [parse]); callback.apply(self, [parse]);
else } else {
callback.apply(self, [self.json(parse)]); callback.apply(self, [self.json(parse)]);
else }
} else {
callback.apply(self); callback.apply(self);
}
}); });
}, },