summaryrefslogtreecommitdiff
path: root/static/files/def.js
blob: 72b5cd80d90d9b7bcd35c39ec51b060daf0d4bc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249


/*  G L O B A L   S T U F F  */

function x(y){return document.getElementById(y)}
function cl(o,f){if(x(o))x(o).onclick=f}
function DOMLoad(y){var d=0;var f=function(){if(d++)return;y()};
if(document.addEventListener)document.addEventListener("DOMCont"
+"entLoaded",f,false);document.write("<script id=_ie defer src="
+"javascript:void(0)><\/script>");document.getElementById('_ie')
.onreadystatechange=function(){if(this.readyState=="complete")f()
};if(/WebKit/i.test(navigator.userAgent))var t=setInterval(
function(){if(/loaded|complete/.test(document.readyState)){
clearInterval(t);f()}},10);window.onload=f;}




/*   F O R M   S U B S  */

var formsubs = [];
function formhid() {
  var i;
  var j;
  var l = document.forms[1].getElementsByTagName('a');
  for(i=0; i<l.length; i++)
    if(l[i].className.indexOf('s_') != -1) {
      formsubs[ l[i].className.substr(l[i].className.indexOf('s_')+2) ] = 0;
      l[i].onclick = function() {
        formtoggle(this.className.substr(this.className.indexOf('s_')+2));
        return false;
      };
    }

  if(x('_hid') && x('_hid').value.length > 1) {
    l = x('_hid').value.split(/,/);
    for(i in formsubs) {
      var inz=0;
      for(j=0; j<l.length; j++)
        if(l[j] == i)
          inz = 1;
      if(!inz)
        formsubs[i] = !formsubs[i];
    }
  }
}
function formtoggle(n) {
  formsubs[n] = !formsubs[n];
  var i;
  var l = document.forms[1].getElementsByTagName('a');
  for(i=0; i<l.length; i++)
    if(l[i].className.indexOf('s_'+n) != -1)
      l[i].innerHTML = (formsubs[n] ? '&#9656;' : '&#9662;') + l[i].innerHTML.substr(1);

  l = document.forms[1].getElementsByTagName('li');
  for(i=0; i<l.length; i++)
    if(l[i].className.indexOf('sf_'+n) != -1) {
      if(formsubs[n])
        l[i].className += ' formhid';
      else
        l[i].className = l[i].className.replace(/formhid/g, '');
    }

  if(x('_hid')) {
    l = [];
    for(i in formsubs)
      if(!formsubs[i])
        l[l.length] = i;
    x('_hid').value = l.toString();
  }
}




/*  D R O P D O W N   M E N U S  */


var ddx;var ddy;var dds=null;
function dropDown(e) {
  e = e || window.event;
  var tg = e.target || e.srcElement;
  if(tg.nodeType == 3)
    tg = tg.parentNode;

  if(!dds && (tg.nodeName.toLowerCase() != 'a' || !tg.rel || tg.className.indexOf('dropdown') < 0))
    return;
  if(tg.rel)
    tg.rel = tg.rel.replace(/ *nofollow */,"");
  if(!dds && !tg.rel)
    return;
  
  if(!dds) {
    var obj=tg;
    ddx = ddy = 0;
    do {
      ddx += obj.offsetLeft;
      ddy += obj.offsetTop;
    } while(obj = obj.offsetParent);
    ddy += 16;
    obj = x(tg.rel);
    obj.style.left = ddx+'px';
    obj.style.top = ddy+'px';
    dds = tg;
  }

  if(dds) {
    var mouseX = e.pageX || (e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft);
    var mouseY = e.pageY || (e.clientY + document.body.scrollTop  + document.documentElement.scrollTop);
    var obj = x(dds.rel);
    if((mouseX < ddx-5 || mouseX > ddx+obj.offsetWidth+5 || mouseY < ddy-20 || mouseY > ddy + obj.offsetHeight)
        || (mouseY < ddy && tg.nodeName.toLowerCase() == 'a' && tg != dds)) {
      obj.style.left = '-500px';
      dds = null;
    }
  }
}




/*  O N L O A D  */

DOMLoad(function() {
  var i;

 // search box
  i = x('searchfield');
  i.onfocus = function () {
    if(this.value == 'search') {
      this.value = '';
      this.style.color = '#000'; } };
  i.onblur = function () {
    if(this.value.length < 1) {
      this.value = 'search';
      this.style.color = '#999';} };

 // browse categories
  if(x('catsearch')) {
    x('catsearch').onclick = function () {
      var u = { i:'',e:'',l:'' };
      var l = x('cat').getElementsByTagName('li');
      var y;var j;
      for(y=0;y<l.length;y++)
        if((j = l[y].className.indexOf('cat_')) != -1) {
          var k = l[y].className.substr(j+4, 3);
          if(l[y].className.indexOf(' inc') != -1)
            u.i += (u.i?',':'')+k;
          if(l[y].className.indexOf(' exc') != -1)
            u.e += (u.e?',':'')+k;
        }
      l = x('lfilter').getElementsByTagName('input');
      for(y=0;y<l.length;y++)
        if(l[y].checked)
          u.l+=(u.l!=''?',':'')+l[y].name.substr(5);
      var url = '/v/cat';
      for (y in u)
        if(u[y])
          url+=(url.indexOf('?')<0?'?':';')+y+'='+u[y];
      location.href=url;
      return false;
    };
    var l = x('cat').getElementsByTagName('li');
    for(i=0;i<l.length;i++)
      if(l[i].className.indexOf('cat_') != -1)
        l[i].onclick = function () {
          try { document.selection.empty() } catch(e) { try { window.getSelection().collapse(this, 0) } catch(e) {} };
          var sel = this.className.substr(this.className.indexOf('cat_'), 7);
          this.className = this.className.indexOf(' inc') != -1 ? (sel+' exc') : this.className.indexOf(' exc') != -1 ? sel : (sel + ' inc');
        };
  }

 // vnlist
  cl('askcomment', function() {
    this.href = this.href + '&amp;c=' + encodeURIComponent(prompt("Enter personal note (optional)", '')||'');
    return true;
  });

 // mass-change vnlist status
  if(x('vnlistchange')) {
    x('vnlistchange').onchange = function() {
      var val = this.options[this.selectedIndex].value;
      if(val == '-3') 
        return;
      var l = document.getElementsByTagName('input');
      var y; var ch=0;
      for(y=0;y<l.length;y++)
        if(l[y].type == 'checkbox' && l[y].checked)
          ch++;
      if(!ch)
        return alert('Nothing selected...');
      if(val == '-1' && !confirm('Are you sure you want to remove the selected items from your visual novel list?'))
        return;
      if(val == '-2')
        x('comments').value = prompt('Enter personal note (leave blank to delete note)','')||'';
      document.forms[1].submit();
    }
  }

 // autocheck
  cl('checkall', function () {
    var l = document.getElementsByTagName('input');
    var y;
    for(y=0;y<l.length;y++)
      if(l[y].type == 'checkbox' && l[y].name == this.name)
        l[y].checked = this.checked;
  });

 // a few confirm popups
  cl('idel', function () {
    return confirm('Are you sure you want to delete this item?\n\nAll previous edits will be deleted, this action can not be reverted!') });
//  cl('vhide', function () {
//    return confirm('!WARNING!\nHiding a visual novel also DELETES the following information:\n - VN Relations of ALL revisions\n - VN lists\n - Votes\nThis is NOT recoverable!');  });
  cl('massdel', function () {
    return confirm('Are you sure you want to mass-delete all the selected changes?\n\nThis action can not be reverted!') });

 // NSFW
  cl('nsfw', function () {
    this.src = this.className;
    this.id = '';
  });

 // spam protection on all forms
  if(document.forms.length > 1)
    for(i=1; i<document.forms.length; i++)
      document.forms[i].action = document.forms[i].action.replace(/\/nospam\?/,'');

 // dropdown menus
  var z = document.getElementsByTagName('a');
  for(i=0;i<z.length;i++)
    if(z[i].rel && z[i].className.indexOf('dropdown') >= 0) {
      document.onmousemove = dropDown;
      break;
    }

 // form-stuff
  if(document.forms.length > 1)
    formhid();

 // init dyna
//  if(x('vn_select') || x('md_select') || x('pd_select') || x('rl_select'))
  if(window.dInit)
    dInit();

 // zebra-striped tables (client side!? yes... client side :3)
  var sub = document.getElementsByTagName('tr');
  for(i=1; i<sub.length; i+=2)
    sub[i].style.backgroundColor = '#f5f5f5';
});