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) {
for (var i = 0; i < this.length; i++)
if (this[i] === value)
for (var i = 0; i < this.length; i++) {
if (this[i] === value) {
return true;
}
}
return false;
};
@ -25,8 +29,9 @@ AdminCP.prototype = {
this.initializing = true;
this.loginForm();
this.initEvents();
if (this.loaded()) this.afterLogin();
else {
if (this.loaded()) {
this.afterLogin();
} else {
$('#login-password')[0].focus();
}
@ -54,10 +59,11 @@ AdminCP.prototype = {
$('.logout').click(function() { self.logout(); return false; });
// Show the nav
if (this.initializing)
if (this.initializing) {
$('#nav ul').css('display', 'block');
else
} else {
$('#nav ul').slideDown();
}
// Some css for betterlookingness
$('#preferences-form fieldset:odd').addClass('odd');
@ -75,10 +81,11 @@ AdminCP.prototype = {
// If they want to go directly to a section
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);
else
} else {
self.show('preferences');
}
},
initEventsAfter: function() {
@ -101,15 +108,16 @@ AdminCP.prototype = {
// Preferences
$('#preferences-form input').keypress(function(e) {
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]);
return false;
}
}).focus(function() {
this.name = this.value;
}).blur(function() {
if (this.name != this.value)
if (this.name !== this.value) {
self.changePref.apply(self, [$(this).attr('rel'), this.value]);
}
});
$('#preferences-form select').change(function() {
@ -125,10 +133,11 @@ AdminCP.prototype = {
'value': value
};
this.ajax(function(json) {
if (!json.error)
if (!json.error) {
this.done();
else
} else {
alert(json.error);
}
}, pars);
},
@ -137,20 +146,20 @@ AdminCP.prototype = {
var pars = {
mode: 'resetpreferences'
}
};
this.ajax(function(json) {
this.done();
if (json.prefs)
for(pref in json.prefs) {
if (json.prefs) {
for (pref in json.prefs) {
var value = json.prefs[pref];
var el = $('#preferences-form input[@rel=' + pref + '], select[@rel=' + pref + ']')[0];
if (el.type == 'text')
if (el.type === 'text') {
el.value = value;
else {
if (value == true) value = 'true';
if (value == false) value = 'false';
} else {
if (value === true) { value = 'true'; }
if (value === false) { value = 'false'; }
$('#preferences-form select[@rel=' + pref + ']')
.find('option')
@ -158,11 +167,10 @@ AdminCP.prototype = {
.end()
.find('option[@rel=' + value + ']')
.attr('selected', 'yeah');
}
}
}, pars);
}
}, pars);
},
invalidPassword: function() {
@ -230,49 +238,53 @@ AdminCP.prototype = {
// if (!sections.inArray(section)) section = 'preferences';
if ($.browser.msie) {
if (section == 'preferences')
if (section === 'preferences') {
$('#preferences select').css('display', 'block');
else
} else {
$('#preferences select').css('display', 'none');
}
}
if (section == this.curSection) return;
if (section === this.curSection) { return; }
this.curSection = section;
$('#' + section)[0].style.zIndex = ++this.z;
if (this.initializing)
if (this.initializing) {
$('#' + section).css('display', 'block');
else
} else {
$('#' + section).fadeIn(this.animSpeed, callback);
}
},
showPrefPane: function(pane) {
var self = this;
if (pane == this.curPrefPane) return;
if (pane === this.curPrefPane) { return; }
this.curPrefPane = pane;
$('#preferences .cp-pane').css('display', 'none');
$('#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');
else
} else {
$('#cp-pane-' + pane).css('display', 'none');
}
});
},
showAboutPane: function(pane) {
var self = this;
if (pane == this.curAboutPane) return;
if (pane === this.curAboutPane) { return; }
this.curAboutPane = pane;
$('#about .cp-pane').css('display', 'none');
$('#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');
else
} else {
$('#cp-pane-' + pane).css('display', 'none');
}
});
},
@ -281,13 +293,15 @@ AdminCP.prototype = {
$.post('ajax.php', pars, function(parse) {
// alert(parse);
if (parse)
if (html)
if (parse) {
if (html) {
callback.apply(self, [parse]);
else
} else {
callback.apply(self, [self.json(parse)]);
else
}
} else {
callback.apply(self);
}
});
},
@ -297,7 +311,7 @@ AdminCP.prototype = {
},
loaded: function() {
return ($('#cp-loaded').length == 1);
return ($('#cp-loaded').length === 1);
},
loading: function() {
@ -325,10 +339,11 @@ AdminCP.prototype = {
},
getAnchor: function() {
var href = window.location.href;
if (href.indexOf('#') > -1 )
return href.substr(href.indexOf('#') + 1).toLowerCase();
return '';
var href = window.location.href;
if (href.indexOf('#') > -1 ) {
return href.substr(href.indexOf('#') + 1).toLowerCase();
}
return '';
},
unban: function(ip, el) {
@ -357,7 +372,7 @@ AdminCP.prototype = {
var pars = {
mode: 'unbanall'
}
};
this.ajax(function(json) {
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 self = this;
var args = arguments;
@ -17,13 +19,11 @@ History.prototype = {
$('body').ScrollToAnchors({ duration: 800 });
},
initEvents: function() {
var self = this;
this.initLogEvents();
// Select log
$('#log').change(function() {
var logIndex = $(this).find('option[@selected]').attr('rel');
@ -31,15 +31,13 @@ History.prototype = {
var pars = {
p: 'yes',
log: logIndex
}
};
self.ajax(function(html) {
$('#ys-posts').html(html)
$('#ys-posts').html(html);
$('#yshout').fadeIn();
self.initLogEvents();
}, pars, true, 'index.php');
});
// 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.');
el.innerHTML = 'Clear this log';
return;
break;
}
}
$('#ys-posts').html(self.noPosts);
self.initLogEvents();
el.innerHTML = 'Clear this log'
el.innerHTML = 'Clear this log';
}, pars);
this.innerHTML = 'Clearing...';
@ -80,16 +77,15 @@ History.prototype = {
if (json.error) {
switch(json.error) {
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.');
return;
break;
}
}
$('#ys-posts').html(self.noPosts);
self.initLogEvents();
el.innerHTML = 'Clear all logs'
el.innerHTML = 'Clear all logs';
}, pars);
this.innerHTML = 'Clearing...';
@ -115,27 +111,29 @@ History.prototype = {
showInfo: function(id, el) {
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);
else
} else {
jEl.slideDown(this.animSpeed);
}
el.innerHTML ='Close Info'
el.innerHTML ='Close Info';
return false;
},
hideInfo: function(id, el) {
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);
else
} else {
jEl.slideUp(this.animSpeed);
}
el.innerHTML = 'Info';
return false;
},
@ -144,7 +142,8 @@ History.prototype = {
var self = this;
var link = $('#' + post.id).find('.ys-ban-link')[0];
switch(link.innerHTML) {
switch(link.innerHTML)
{
case 'Ban':
var pIP = $(post).find('.ys-h-ip').html();
var pNickname = $(post).find('.ys-h-nickname').html();
@ -175,11 +174,9 @@ History.prototype = {
link.innerHTML = 'Banning...';
return false;
break;
case 'Banning...':
return false;
break;
case 'Unban':
var pIP = $(post).find('.ys-h-ip').html();
@ -194,7 +191,6 @@ History.prototype = {
case 'admin':
self.error('You\'re not an admin. Log in through the admin CP to unban people.');
return;
break;
}
}
@ -207,11 +203,9 @@ History.prototype = {
link.innerHTML = 'Unbanning...';
return false;
break;
case 'Unbanning...':
return false;
break;
}
},
@ -219,7 +213,7 @@ History.prototype = {
var self = this;
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();
@ -234,7 +228,6 @@ History.prototype = {
case 'admin':
self.error('You\'re not an admin. Log in through the admin CP to ban people.');
return;
break;
}
}
@ -260,16 +253,18 @@ History.prototype = {
var self = this;
if (page == null) page = '../yshout.php';
if (page === null) { page = '../yshout.php'; }
$.post(page, pars, function(parse) {
if (parse)
if (html)
if (parse) {
if (html) {
callback.apply(self, [parse]);
else
} else {
callback.apply(self, [self.json(parse)]);
else
}
} else {
callback.apply(self);
}
});
},