| [4206d64] | 1 | /*jslint browser: true */
|
|---|
| 2 | /*global rtwi_strings*/
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 | var RTWI = {};
|
|---|
| 6 | RTWI.xmlHttp = null;
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 | RTWI.getHttpReqestObject = function () {
|
|---|
| 10 | 'use strict';
|
|---|
| 11 | var xmlHttp = null;
|
|---|
| 12 |
|
|---|
| 13 | try {
|
|---|
| 14 | xmlHttp = new window.XMLHttpRequest();
|
|---|
| 15 | } catch (exception) {
|
|---|
| 16 | window.alert(rtwi_strings.ajaxNotSupported); // "Your browser does not support AJAX!"
|
|---|
| 17 | return false;
|
|---|
| 18 | }
|
|---|
| 19 | return xmlHttp;
|
|---|
| 20 | };
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 | // Some AJAX operation changed state, show it...
|
|---|
| 24 | RTWI.handleReadyStateChange = function () {
|
|---|
| 25 | 'use strict';
|
|---|
| 26 | var node = document.getElementById('TB_content');
|
|---|
| 27 |
|
|---|
| 28 | switch (RTWI.xmlHttp.readyState) {
|
|---|
| 29 | case 0:
|
|---|
| 30 | node.innerHTML = 0;
|
|---|
| 31 | break;
|
|---|
| 32 | case 1:
|
|---|
| 33 | node.innerHTML = rtwi_strings.requesting; // 'Requesting...'
|
|---|
| 34 | break;
|
|---|
| 35 | case 2:
|
|---|
| 36 | node.innerHTML = 2;
|
|---|
| 37 | break;
|
|---|
| 38 | case 3:
|
|---|
| 39 | node.innerHTML = rtwi_strings.processing; // 'Processing...'
|
|---|
| 40 | break;
|
|---|
| 41 | case 4:
|
|---|
| 42 | node.innerHTML = RTWI.xmlHttp.responseText;
|
|---|
| 43 | RTWI.xmlHttp = null;
|
|---|
| 44 | break;
|
|---|
| 45 | default:
|
|---|
| 46 | node.innerHTML = '.';
|
|---|
| 47 | break;
|
|---|
| 48 | }
|
|---|
| 49 | };
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 | // Load: peer list, informations, file list or tracker list.
|
|---|
| 53 | RTWI.loadcontent = function (page, node) {
|
|---|
| 54 | 'use strict';
|
|---|
| 55 | var titleNode = document.getElementById('TB_title'),
|
|---|
| 56 | hash = titleNode.getAttribute('data-hash'),
|
|---|
| 57 | menuitems = null,
|
|---|
| 58 | i = 0,
|
|---|
| 59 | c = 0;
|
|---|
| 60 |
|
|---|
| 61 | // check if ajax request is already running
|
|---|
| 62 | if (RTWI.xmlHttp) {
|
|---|
| 63 | return;
|
|---|
| 64 | }
|
|---|
| 65 | RTWI.xmlHttp = RTWI.getHttpReqestObject();
|
|---|
| 66 | if (!RTWI.xmlHttp) {
|
|---|
| 67 | return;
|
|---|
| 68 | }
|
|---|
| 69 | // unselect all menuitems
|
|---|
| 70 | menuitems = document.getElementById('TB_menu').getElementsByClassName('menuitem');
|
|---|
| 71 | c = menuitems.length;
|
|---|
| 72 | for (i = 0; i < c; i += 1) {
|
|---|
| 73 | menuitems[i].className = 'menuitem';
|
|---|
| 74 | }
|
|---|
| 75 | // select clicked menuitem
|
|---|
| 76 | node.className = 'menuitem current';
|
|---|
| 77 | RTWI.xmlHttp.onreadystatechange = RTWI.handleReadyStateChange;
|
|---|
| 78 | RTWI.xmlHttp.open('GET', '?mod=torrent&hash=' + hash + '&page=' + page + '&ajax=true', true);
|
|---|
| 79 | RTWI.xmlHttp.send(null);
|
|---|
| 80 | };
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 | // Set directory priority.
|
|---|
| 84 | RTWI.loadcontent_dirpriority = function (iurl, hash, dir, dirpriority) {
|
|---|
| 85 | 'use strict';
|
|---|
| 86 |
|
|---|
| 87 | // check if AJAX call is already running
|
|---|
| 88 | if (RTWI.xmlHttp) {
|
|---|
| 89 | return;
|
|---|
| 90 | }
|
|---|
| 91 | RTWI.xmlHttp = RTWI.getHttpReqestObject();
|
|---|
| 92 | if (!RTWI.xmlHttp) {
|
|---|
| 93 | return;
|
|---|
| 94 | }
|
|---|
| 95 | RTWI.xmlHttp.onreadystatechange = RTWI.handleReadyStateChange;
|
|---|
| 96 | RTWI.xmlHttp.open('GET', iurl + '?mod=changedirpriority&hash=' + hash + '&dir=' + dir + '&dirpriority=' + dirpriority + '&ajax=true', true);
|
|---|
| 97 | RTWI.xmlHttp.send(null);
|
|---|
| 98 | };
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 | // Set file priority.
|
|---|
| 102 | RTWI.loadcontent_filepriority = function (iurl, hash, id, filepriority) {
|
|---|
| 103 | 'use strict';
|
|---|
| 104 |
|
|---|
| 105 | // check if AJAX call is already running
|
|---|
| 106 | if (RTWI.xmlHttp) {
|
|---|
| 107 | return;
|
|---|
| 108 | }
|
|---|
| 109 | RTWI.xmlHttp = RTWI.getHttpReqestObject();
|
|---|
| 110 | if (!RTWI.xmlHttp) {
|
|---|
| 111 | return;
|
|---|
| 112 | }
|
|---|
| 113 | RTWI.xmlHttp.onreadystatechange = RTWI.handleReadyStateChange;
|
|---|
| 114 | RTWI.xmlHttp.open('GET', iurl + '?mod=changefilepriority&hash=' + hash + '&id=' + id + '&filepriority=' + filepriority + '&ajax=true', true);
|
|---|
| 115 | RTWI.xmlHttp.send(null);
|
|---|
| 116 | };
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 | // Enable or disable torrent tracker.
|
|---|
| 120 | RTWI.loadcontent_trackerenabled = function (iurl, hash, id, trackerenabled) {
|
|---|
| 121 | 'use strict';
|
|---|
| 122 |
|
|---|
| 123 | // check if AJAX call is already running
|
|---|
| 124 | if (RTWI.xmlHttp) {
|
|---|
| 125 | return;
|
|---|
| 126 | }
|
|---|
| 127 | RTWI.xmlHttp = RTWI.getHttpReqestObject();
|
|---|
| 128 | if (!RTWI.xmlHttp) {
|
|---|
| 129 | return;
|
|---|
| 130 | }
|
|---|
| 131 | RTWI.xmlHttp.onreadystatechange = RTWI.handleReadyStateChange;
|
|---|
| 132 | RTWI.xmlHttp.open('GET', iurl + '?mod=changetrackerenabled&hash=' + hash + '&id=' + id + '&trackerenabled=' + trackerenabled + '&ajax=true', true);
|
|---|
| 133 | RTWI.xmlHttp.send(null);
|
|---|
| 134 | };
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 | // show popup divs
|
|---|
| 138 | RTWI.hideDetailsPopup = function () {
|
|---|
| 139 | 'use strict';
|
|---|
| 140 | var o = document.getElementById('TB_overlay'),
|
|---|
| 141 | w = document.getElementById('TB_window'),
|
|---|
| 142 | menuitems = null,
|
|---|
| 143 | i = 0,
|
|---|
| 144 | c = 0;
|
|---|
| 145 |
|
|---|
| 146 | o.style.display = 'none';
|
|---|
| 147 | w.style.visibility = 'hidden';
|
|---|
| 148 | document.getElementById('TB_content').innerHTML = '';
|
|---|
| 149 | // unselect all menuitems
|
|---|
| 150 | menuitems = document.getElementById('TB_menu').getElementsByClassName('menuitem');
|
|---|
| 151 | c = menuitems.length;
|
|---|
| 152 | for (i = 0; i < c; i += 1) {
|
|---|
| 153 | menuitems[i].className = 'menuitem';
|
|---|
| 154 | }
|
|---|
| 155 | // cancel any running ajax request
|
|---|
| 156 | if (RTWI.xmlHttp) {
|
|---|
| 157 | RTWI.xmlHttp.abort();
|
|---|
| 158 | RTWI.xmlHttp = null;
|
|---|
| 159 | }
|
|---|
| 160 | };
|
|---|
| 161 |
|
|---|
| 162 | // show popup divs
|
|---|
| 163 | RTWI.showDetailsPopup = function (event) {
|
|---|
| 164 | 'use strict';
|
|---|
| 165 | var o = document.getElementById('TB_overlay'),
|
|---|
| 166 | w = document.getElementById('TB_window'),
|
|---|
| 167 | t = document.getElementById('TB_title'),
|
|---|
| 168 | m = document.getElementById('TB_menu'),
|
|---|
| 169 | c = document.getElementById('TB_content'),
|
|---|
| 170 | node = event.target || event.srcElement,
|
|---|
| 171 | width = (window.innerWidth > 1000 ? 950 : window.innerWidth - 20),
|
|---|
| 172 | height = window.innerHeight - 60;
|
|---|
| 173 |
|
|---|
| 174 | event.preventDefault();
|
|---|
| 175 | t.setAttribute('data-hash', node.getAttribute('data-hash'));
|
|---|
| 176 | t.innerText = node.innerText;
|
|---|
| 177 | o.style.display = 'block';
|
|---|
| 178 | w.style.width = width + 'px';
|
|---|
| 179 | w.style.marginLeft = -1 * window.Math.round(width / 2) + 'px';
|
|---|
| 180 | w.style.height = height + 'px';
|
|---|
| 181 | w.style.top = 30 + 'px';
|
|---|
| 182 | w.style.visibility = 'visible';
|
|---|
| 183 | c.style.height = height - t.offsetHeight - m.offsetHeight - 2 * 16 + 'px';
|
|---|
| 184 | };
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 | // Called on body.onload and DOM node clicks,
|
|---|
| 188 | // show and hide some DOM nodes.
|
|---|
| 189 | RTWI.toggle = function (modpage) {
|
|---|
| 190 | 'use strict';
|
|---|
| 191 | var uls = null,
|
|---|
| 192 | atts = null,
|
|---|
| 193 | i = 0,
|
|---|
| 194 | j = 0;
|
|---|
| 195 |
|
|---|
| 196 | switch (modpage) {
|
|---|
| 197 | case '_info':
|
|---|
| 198 | case 'torrent_info':
|
|---|
| 199 | case 'torrent_peers':
|
|---|
| 200 | case 'torrent_trackers':
|
|---|
| 201 | if (document.getElementById('changethrottleform')) {
|
|---|
| 202 | document.getElementById('throttleupinput').style.display = 'none';
|
|---|
| 203 | document.getElementById('throttledowninput').style.display = 'none';
|
|---|
| 204 | document.getElementById('tsubmit').style.display = 'none';
|
|---|
| 205 | document.getElementById('throttleup').style.display = '';
|
|---|
| 206 | document.getElementById('throttledown').style.display = '';
|
|---|
| 207 | }
|
|---|
| 208 | break;
|
|---|
| 209 | case 'serverinfo_info':
|
|---|
| 210 | if (document.getElementById('changethrottleform')) {
|
|---|
| 211 | document.getElementById('throttleupinput').style.display = 'none';
|
|---|
| 212 | document.getElementById('throttledowninput').style.display = 'none';
|
|---|
| 213 | document.getElementById('tsubmit').style.display = 'none';
|
|---|
| 214 | document.getElementById('throttleup').style.display = '';
|
|---|
| 215 | document.getElementById('throttledown').style.display = '';
|
|---|
| 216 | }
|
|---|
| 217 | document.getElementById('changedht').style.display = '';
|
|---|
| 218 | document.getElementById('changedhtselect').style.display = 'none';
|
|---|
| 219 | break;
|
|---|
| 220 | case '_info_restore':
|
|---|
| 221 | document.getElementById('throttleupinput').style.display = '';
|
|---|
| 222 | document.getElementById('throttledowninput').style.display = '';
|
|---|
| 223 | document.getElementById('tsubmit').style.display = '';
|
|---|
| 224 | document.getElementById('throttleup').style.display = 'none';
|
|---|
| 225 | document.getElementById('throttledown').style.display = 'none';
|
|---|
| 226 | break;
|
|---|
| 227 | case 'serverinfo_info_restore':
|
|---|
| 228 | if (document.getElementById('changethrottleform')) {
|
|---|
| 229 | document.getElementById('changedht').style.display = 'none';
|
|---|
| 230 | document.getElementById('changedhtselect').style.display = '';
|
|---|
| 231 | }
|
|---|
| 232 | break;
|
|---|
| 233 | case 'addtorrent_info':
|
|---|
| 234 | document.getElementById('torrenturl').style.display = 'none';
|
|---|
| 235 | break;
|
|---|
| 236 | case 'torrent_files':
|
|---|
| 237 | uls = document.getElementsByTagName('ul');
|
|---|
| 238 | for (i = 0; i < uls.length; i += 1) {
|
|---|
| 239 | atts = uls.item(i).attributes;
|
|---|
| 240 | for (j = 0; j < atts.length; j += 1) {
|
|---|
| 241 | if ('class' === atts[j].nodeName && 'directory' === atts[j].nodeValue) {
|
|---|
| 242 | uls.item(i).style.display = 'none';
|
|---|
| 243 | }
|
|---|
| 244 | }
|
|---|
| 245 | }
|
|---|
| 246 | document.getElementById('throttleupinput').style.display = 'none';
|
|---|
| 247 | document.getElementById('throttledowninput').style.display = 'none';
|
|---|
| 248 | document.getElementById('tsubmit').style.display = 'none';
|
|---|
| 249 | document.getElementById('throttleup').style.display = '';
|
|---|
| 250 | document.getElementById('throttledown').style.display = '';
|
|---|
| 251 | break;
|
|---|
| 252 | }
|
|---|
| 253 | };
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 | // add click handlers when DOM is ready
|
|---|
| 257 | RTWI.onDOMready = function () {
|
|---|
| 258 | 'use strict';
|
|---|
| 259 | var arr = null,
|
|---|
| 260 | i = 0,
|
|---|
| 261 | c = 0,
|
|---|
| 262 | node = null;
|
|---|
| 263 |
|
|---|
| 264 | // open popup
|
|---|
| 265 | arr = document.getElementsByClassName('hasPopup');
|
|---|
| 266 | c = arr.length;
|
|---|
| 267 | for (i = 0; i < c; i += 1) {
|
|---|
| 268 | node = arr[i];
|
|---|
| 269 | node.addEventListener('click', RTWI.showDetailsPopup, false);
|
|---|
| 270 | }
|
|---|
| 271 | // close popup
|
|---|
| 272 | document.getElementById('TB_overlay').addEventListener('click', function () {
|
|---|
| 273 | RTWI.hideDetailsPopup();
|
|---|
| 274 | }, false);
|
|---|
| 275 | document.getElementById('TB_closeWindowButton').addEventListener('click', function (event) {
|
|---|
| 276 | event.preventDefault();
|
|---|
| 277 | RTWI.hideDetailsPopup();
|
|---|
| 278 | }, false);
|
|---|
| 279 | };
|
|---|
| 280 | document.addEventListener("DOMContentLoaded", RTWI.onDOMready);
|
|---|