summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2015-08-17 13:06:05 +0200
committerYorhel <git@yorhel.nl>2015-08-17 13:16:48 +0200
commit7f81ec60b4c3fd1b6ef5aed2fe4a7f44ee21eeb1 (patch)
tree028104124553bd46ad2c4d11172da43d14a868d6 /data
parent0fcc3797a7cef3f063ebcbc59aecfab5eb89eecb (diff)
js: Clean up misc.js
- Individual blocks don't leak variables into the parent scope anymore. Previously some blocks would re-use variables from other blocks, creating (almost invisible) dependencies between te blocks. - More consistent code for ulist-change-dropdowns, and all of them have a ref= argument now. - Use 'hidden' class instead of style.display wherever that makes sense. - Remove dead 'advselect' code. Hasn't been used since the addition of search filters. - lang_select doesn't rely on the position of the language class in className anymore (seriously that stuff is fragile...)
Diffstat (limited to 'data')
-rw-r--r--data/js/misc.js271
-rw-r--r--data/style.css2
2 files changed, 145 insertions, 128 deletions
diff --git a/data/js/misc.js b/data/js/misc.js
index cf29bf26..89572e82 100644
--- a/data/js/misc.js
+++ b/data/js/misc.js
@@ -1,22 +1,29 @@
// search box
-{
- var i = byId('sq');
- i.onfocus = function () {
- if(this.value == mt('_menu_emptysearch')) {
- this.value = '';
- this.style.fontStyle = 'normal'
- }
- };
- i.onblur = function () {
- if(this.value.length < 1) {
- this.value = mt('_menu_emptysearch');
- this.style.fontStyle = 'italic'
- }
- };
+byId('sq').onfocus = function () {
+ if(this.value == mt('_menu_emptysearch')) {
+ this.value = '';
+ this.style.fontStyle = 'normal'
+ }
+};
+byId('sq').onblur = function () {
+ if(this.value.length < 1) {
+ this.value = mt('_menu_emptysearch');
+ this.style.fontStyle = 'italic'
+ }
+};
+
+
+function ulist_redirect(type, path, formcode, args) {
+ var r = new RegExp('/('+type+'[0-9]+).*$');
+ location.href = location.href.replace(r, '/$1')+path
+ +'?formcode='+formcode
+ +';ref='+encodeURIComponent(location.pathname+location.search)
+ +';'+args;
}
+
// VN Voting (/v+)
-if(byId('votesel')) {
+if(byId('votesel'))
byId('votesel').onchange = function() {
var s = this.options[this.selectedIndex].value;
if(s == -2)
@@ -34,38 +41,46 @@ if(byId('votesel')) {
if(s == 10 && !confirm(mt('_vnpage_uopt_10vote')))
return;
if(s > 0 || s == -1)
- location.href = location.href.replace(/#.*/, '').replace(/\/(chars|staff)/, '').replace(/(v\d+)\.\d+/, '$1')+'/vote?formcode='+this.name+';v='+s;
+ ulist_redirect('v', '/vote', this.name, 'v='+s);
};
-}
-// Advanced search (/v/*)
-if(byId('advselect')) {
- byId('advselect').onclick = function() {
- var box = byId('advoptions');
- var hidden = !hasClass(box, 'hidden');
- setClass(box, 'hidden', hidden);
- setText(byName(this, 'i')[0], hidden ? collapsed_icon : expanded_icon);
- return false;
+
+// VN Wishlist dropdown box (/v+)
+if(byId('wishsel'))
+ byId('wishsel').onchange = function() {
+ if(this.selectedIndex != 0)
+ ulist_redirect('v', '/wish', this.name, ';s='+this.options[this.selectedIndex].value);
};
-}
+
+
+// Release & VN list dropdown box (/r+ and /v+)
+if(byId('listsel'))
+ byId('listsel').onchange = function() {
+ if(this.selectedIndex != 0)
+ ulist_redirect('[rv]', '/list', this.name, 'e='+this.options[this.selectedIndex].value);
+ };
+
// NSFW VN image toggle (/v+)
-if(byId('nsfw_show')) {
+(function() {
var msg = byId('nsfw_show');
- var img = byId('nsfw_hid');
- byName(msg, 'a')[0].onclick = function() {
- msg.style.display = 'none';
- img.style.display = 'block';
- return false;
- };
- img.onclick = function() {
- msg.style.display = 'block';
- img.style.display = 'none';
- };
-}
+ if(msg) {
+ var img = byId('nsfw_hid');
+ byName(msg, 'a')[0].onclick = function() {
+ setClass(msg, 'hidden', true);
+ setClass(img, 'hidden', false);
+ return false;
+ };
+ img.onclick = function() {
+ setClass(msg, 'hidden', false);
+ setClass(img, 'hidden', true);
+ };
+ }
+})();
+
// NSFW toggle for screenshots (/v+)
-if(byId('nsfwhide')) {
+if(byId('nsfwhide'))
byId('nsfwhide').onclick = function() {
var shown = 0;
var l = byClass(byId('screenshots'), 'a', 'scrlnk');
@@ -81,44 +96,31 @@ if(byId('nsfwhide')) {
setText(byId('nsfwshown'), shown);
return false;
};
-}
-// VN Wishlist dropdown box (/v+)
-if(byId('wishsel')) {
- byId('wishsel').onchange = function() {
- if(this.selectedIndex != 0)
- location.href = location.href.replace(/#.*/, '').replace(/\/(chars|staff)/, '').replace(/\.[0-9]+/, '')
- +'/wish?formcode='+this.name+';s='+this.options[this.selectedIndex].value;
- };
-}
-
-// Release & VN list dropdown box (/r+ and /v+)
-if(byId('listsel')) {
- byId('listsel').onchange = function() {
- if(this.selectedIndex != 0)
- location.href = location.href.replace(/#.*/, '').replace(/\/(chars|staff)/, '').replace(/\.[0-9]+/, '')
- +'/list?formcode='+this.name+';e='+this.options[this.selectedIndex].value+';ref='+encodeURIComponent(location.pathname+location.search);
- };
-}
// Notification list onclick
-if(byId('notifies')) {
- var l = byClass(byId('notifies'), 'td', 'clickable');
+(function(){
+ var d = byId('notifies');
+ if(!d)
+ return;
+ var l = byClass(d, 'td', 'clickable');
for(var i=0; i<l.length; i++)
l[i].onclick = function() {
var baseurl = location.href.replace(/\/u([0-9]+)\/notifies.*$/, '/u$1/notify/');
location.href = baseurl + this.id.replace(/notify_/, '');
};
-}
+})();
+
// BBCode spoiler tags
-{
+(function(){
var l = byClass('b', 'spoiler');
for(var i=0; i<l.length; i++) {
l[i].onmouseover = function() { setClass(this, 'spoiler', false); setClass(this, 'spoiler_shown', true) };
l[i].onmouseout = function() { setClass(this, 'spoiler', true); setClass(this, 'spoiler_shown', false) };
}
-}
+})();
+
// vndb.org domain check
// (let's just keep this untranslatable, nobody cares anyway ^^)
@@ -131,9 +133,10 @@ if(location.hostname != 'vndb.org') {
));
}
+
// make some fields readonly when patch flag is set (/r+/edit)
-if(byId('jt_box_rel_geninfo')) {
- var func = function() {
+(function(){
+ function sync() {
byId('doujin').disabled =
byId('resolution').disabled =
byId('voiced').disabled =
@@ -141,12 +144,15 @@ if(byId('jt_box_rel_geninfo')) {
byId('ani_ero').disabled =
byId('patch').checked;
};
- func();
- byId('patch').onclick = func;
-}
+ if(byId('jt_box_rel_geninfo')) {
+ sync();
+ byId('patch').onclick = sync;
+ }
+})();
+
// Batch edit dropdown box (/u+/wish and /u+/votes)
-if(byId('batchedit')) {
+if(byId('batchedit'))
byId('batchedit').onchange = function() {
if(this.selectedIndex == 0)
return true;
@@ -155,66 +161,69 @@ if(byId('batchedit')) {
frm = frm.parentNode;
frm.submit();
};
-}
+
// collapse/expand row groups (/u+/list)
-if(byId('expandall')) {
+(function(){
var table = byId('expandall');
+ if(!table)
+ return;
while(table.nodeName.toLowerCase() != 'table')
table = table.parentNode;
var heads = byClass(table, 'td', 'collapse_but');
var allhid = false;
- var alltoggle = function() {
- allhid = !allhid;
- var l = byClass(table, 'tr', 'collapse');
- for(var i=0; i<l.length; i++) {
- setClass(l[i], 'hidden', allhid);
+ function sethid(l, h, hid) {
+ var i;
+ for(i=0; i<l.length; i++) {
+ setClass(l[i], 'hidden', hid);
+ // Set the hidden class on the input checkbox, if it exists. This
+ // prevents the "select all" functionality from selecting it if the row
+ // is not visible.
var sel = byName(l[i], 'input')[0];
- if(sel) setClass(sel, 'hidden', allhid);
+ if(sel)
+ setClass(sel, 'hidden', hid);
}
+ for(i=0; i<h.length; i++)
+ setText(h[i], allhid ? collapsed_icon : expanded_icon);
+ }
+
+ function alltoggle() {
+ allhid = !allhid;
setText(byId('expandall'), allhid ? collapsed_icon : expanded_icon);
- for(var i=0; i<heads.length; i++)
- setText(heads[i], allhid ? collapsed_icon : expanded_icon);
+ sethid(byClass(table, 'tr', 'collapse'), heads, allhid);
return false;
}
- byId('expandall').onclick = alltoggle;
- alltoggle();
- var singletoggle = function() {
+ function singletoggle() {
var l = byClass(table, 'tr', 'collapse_'+this.id);
- if(l.length < 1)
- return;
- var hid = !hasClass(l[0], 'hidden');
- for(var i=0; i<l.length; i++) {
- setClass(l[i], 'hidden', hid);
- var sel = byName(l[i], 'input')[0];
- if(sel) setClass(sel, 'hidden', hid);
- }
- setText(this, hid ? collapsed_icon : expanded_icon);
- };
+ sethid(l, [this], !hasClass(l[0], 'hidden'));
+ }
+
+ byId('expandall').onclick = alltoggle;
for(var i=0; i<heads.length; i++)
heads[i].onclick = singletoggle;
-}
-
-
+ alltoggle();
+})();
// mouse-over price information / disclaimer
-if(byId('buynow')) {
- var l = byClass(byId('buynow'), 'acronym', 'pricenote');
- for(var i=0; i<l.length; i++) {
- l[i].buynow_last = l[i].title;
- l[i].title = null;
- ddInit(l[i], 'bottom', function(acr) {
- return tag('p', {onmouseover:ddHide, style:'padding: 3px'},
- acr.buynow_last, tag('br', null),
- '* The displayed price only serves as an indication and',
- tag('br', null), 'usually excludes shipping. Actual price may differ.'
- );
- });
+(function(){
+ if(byId('buynow')) {
+ var l = byClass(byId('buynow'), 'acronym', 'pricenote');
+ for(var i=0; i<l.length; i++) {
+ l[i].buynow_last = l[i].title;
+ l[i].title = null;
+ ddInit(l[i], 'bottom', function(acr) {
+ return tag('p', {onmouseover:ddHide, style:'padding: 3px'},
+ acr.buynow_last, tag('br', null),
+ '* The displayed price only serves as an indication and',
+ tag('br', null), 'usually excludes shipping. Actual price may differ.'
+ );
+ });
+ }
}
-}
+})();
// set note input box (/u+/list)
@@ -227,31 +236,34 @@ if(byId('not') && byId('vns'))
// expand/collapse release listing (/p+)
-if(byId('expandprodrel')) {
+(function(){
var lnk = byId('expandprodrel');
- setexpand = function() {
+ if(!lnk)
+ return;
+ function setexpand() {
var exp = !(getCookie('prodrelexpand') == 1);
setText(lnk, exp ? mt('_js_collapse') : mt('_js_expand'));
setClass(byId('prodrel'), 'collapse', !exp);
};
- setexpand();
lnk.onclick = function () {
setCookie('prodrelexpand', getCookie('prodrelexpand') == 1 ? 0 : 1);
setexpand();
return false;
};
-}
+ setexpand();
+})();
+
// Language selector
-if(byId('lang_select')) {
+(function(){
var d = byId('lang_select');
- var curlang = byName(d, 'acronym')[0].className.substr(11, 2);
+ var flag = byName(d, 'acronym')[0];
ddInit(d, 'bottom', function(lnk) {
var lst = tag('ul', null);
for(var i=0; i<VARS.l10n_lang.length; i++) {
var ln = VARS.l10n_lang[i];
var icon = tag('acronym', {'class':'icons lang '+ln[0]}, ' ');
- lst.appendChild(tag('li', {'class':'lang_selector'}, curlang == ln[0]
+ lst.appendChild(tag('li', {'class':'lang_selector'}, hasClass(flag, ln[0])
? tag('i', icon, ln[1])
: tag('a', {href:'/setlang?lang='+ln[0]+';ref='+encodeURIComponent(location.pathname+location.search)}, icon, ln[1])
));
@@ -259,25 +271,27 @@ if(byId('lang_select')) {
return lst;
});
d.onclick = function() {return false};
-}
+})();
+
// "check all" checkbox
-{
- var f = function() {
+(function(){
+ function set() {
var l = byName('input');
for(var i=0; i<l.length; i++)
if(l[i].type == this.type && l[i].name == this.name && !hasClass(l[i], 'hidden'))
l[i].checked = this.checked;
- };
+ }
var l = byClass('input', 'checkall');
for(var i=0; i<l.length; i++)
if(l[i].type == 'checkbox')
- l[i].onclick = f;
-}
+ l[i].onclick = set;
+})();
+
// search tabs
-if(byId('searchtabs')) {
- var f = function() {
+(function(){
+ function click() {
var str = byId('q').value;
if(str.length > 1) {
this.href = this.href.split('?')[0];
@@ -287,13 +301,16 @@ if(byId('searchtabs')) {
}
return true;
};
- var l = byName(byId('searchtabs'), 'a');
- for(var i=0; i<l.length; i++)
- l[i].onclick = f;
-}
+ if(byId('searchtabs')) {
+ var l = byName(byId('searchtabs'), 'a');
+ for(var i=0; i<l.length; i++)
+ l[i].onclick = click;
+ }
+})();
+
// spam protection on all forms
setTimeout(function() {
- for(i=1; i<document.forms.length; i++)
+ for(var i=1; i<document.forms.length; i++)
document.forms[i].action = document.forms[i].action.replace(/\/nospam\?/,'');
}, 500);
diff --git a/data/style.css b/data/style.css
index d6fe3ae7..17b3b0bc 100644
--- a/data/style.css
+++ b/data/style.css
@@ -333,7 +333,7 @@ div.vnimg i { display: block; width: 100%; text-align: center;
div.vnimg p { text-align: center; padding: 0px; margin: 0; }
.vndesc h2 { margin: 5px 0 0 0; }
.vndesc p { padding: 0 0 0 5px; }
-p#nsfw_hid { display: none; cursor: pointer; }
+p#nsfw_hid { display: block; cursor: pointer; }
div.vndetails table { float: left; width: 530px; }
div.vndetails table td.key { width: 80px; }
div.vndetails table dt { float: left; font-style: italic; }