From 73161140fba0d7775beca37deaffb78d766f42cd Mon Sep 17 00:00:00 2001 From: Yorhel Date: Sat, 3 Oct 2009 10:03:43 +0200 Subject: JS: Rewrote date selector and fixed onclick bug added in c7f7fdbf --- static/f/script.js | 85 +++++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 40 deletions(-) (limited to 'static') diff --git a/static/f/script.js b/static/f/script.js index 9b82fa33..06aa0d8f 100644 --- a/static/f/script.js +++ b/static/f/script.js @@ -458,40 +458,51 @@ tvsInit(); -/* date input */ +/* D A T E I N P U T */ + var months = ['January','February','March','April','May','June','July','August','September','October','November','December']; -function dtLoad(obj) { - var r = Math.floor(obj.value) || 0; - var v = [ Math.floor(r/10000), Math.floor(r/100)%100, r%100 ]; - var i; - r = ''; - v = document.createElement('div'); - v.obj = obj; - v.innerHTML = r; - obj.parentNode.insertBefore(v, obj); -} -function dtSerialize(obj) { - obj = obj.parentNode; - var l = obj.getElementsByTagName('select'); - var v = [ l[0].options[l[0].selectedIndex].value*1, l[1].options[l[1].selectedIndex].value*1, l[2].options[l[2].selectedIndex].value*1 ]; - obj = obj.obj; - if(v[0] == 0) obj.value = 0; - else if(v[0] == 9999) obj.value = 99999999; - else obj.value = v[0]*10000 + v[1]*100 + (v[1]==99?99:v[2]); + +function dateLoad(obj) { + var val = Math.floor(obj.value) || 0; + val = [ Math.floor(val/10000), Math.floor(val/100)%100, val%100 ]; + + var year = tag('select', {style: 'width: 70px', onchange: dateSerialize}, tag('option', {value:0}, '-year-')); + for(var i=1980; i<=(new Date()).getFullYear()+5; i++) + year.appendChild(tag('option', {value: i, selected: i==val[0]}, i)); + year.appendChild(tag('option', {value: 9999, selected: val[0]==9999}, 'TBA')); + + var month = tag('select', {style: 'width: 100px', onchange: dateSerialize}, tag('option', {value:99}, '-month-')); + for(var i=1; i<=12; i++) + month.appendChild(tag('option', {value: i, selected: i==val[1]}, months[i-1])); + + var day = tag('select', {style: 'width: 70px', onchange: dateSerialize}, tag('option', {value:99}, '-day-')); + for(var i=1; i<=31; i++) + day.appendChild(tag('option', {value: i, selected: i==val[2]}, i)); + + obj.parentNode.insertBefore(tag('div', {date_obj: obj}, year, month, day), obj); +} + +function dateSerialize() { + var div = this.parentNode; + var sel = byName(div, 'select'); + var val = [ + sel[0].options[sel[0].selectedIndex].value*1, + sel[1].options[sel[1].selectedIndex].value*1, + sel[2].options[sel[2].selectedIndex].value*1 + ]; + div.date_obj.value = val[0] == 0 ? 0 : val[0] == 9999 ? 99999999 : val[0]*10000+val[1]*100+(val[1]==99?99:val[2]); + alert(div.date_obj.value); +} + +{ + var l = byClass('input', 'dateinput'); + for(i=0; i=0 ? '' : 'hidden'; this.getElementsByTagName('i')[0].innerHTML = e.className.indexOf('hidden')>=0 ? '▸' : '▾'; @@ -622,9 +633,9 @@ function dtSerialize(obj) { // update spoiler cookie on VN search radio button if(x('sp_0')) { - x('sp_0').onload = function(){setCookie('tagspoil',0)}; - x('sp_1').onload = function(){setCookie('tagspoil',1)}; - x('sp_2').onload = function(){setCookie('tagspoil',2)}; + x('sp_0').onclick = function(){setCookie('tagspoil',0)}; + x('sp_1').onclick = function(){setCookie('tagspoil',1)}; + x('sp_2').onclick = function(){setCookie('tagspoil',2)}; if((i = getCookie('tagspoil')) == null) i = 1; x('sp_'+i).checked = true; @@ -644,7 +655,7 @@ function dtSerialize(obj) { // NSFW toggle for screenshots if(x('nsfwhide')) - x('nsfwhide').onload = function() { + x('nsfwhide').onclick = function() { var s=0; var l = x('screenshots').getElementsByTagName('div'); for(var i=0;i