source: trunk/wtorrent/home/js/javasc.js @ 53

Revision 53, 9.2 KB checked in by royger, 2 years ago (diff)
  • New Interface.
  • wTorrent no longer uses shadedborder javascript library, since it made the rendering slow. Now it's all done with transparent pngs.
  • This should fix #57.
Line 
1function resizeInnerTab(hash) {
2    if($('tab' + hash).innerHTML == "")
3    {
4        load('tab' + hash, 'info');
5    } else {
6        Effect.toggle('ttab' + hash, 'blind', {duration:0.5});
7    }
8}
9/* Check all elements of the specified class */
10function checkAllByClass(styleClass) {
11        var elements = document.getElementsByClassName(styleClass);
12                for (var i = 0; i < elements.length; i++) {
13                        elements[i].checked = true;
14                }
15}
16/* Uncheck all elements of the specified class */
17function uncheckAllByClass(styleClass) {
18        var elements = document.getElementsByClassName(styleClass);
19                for (var i = 0; i < elements.length; i++) {
20                        elements[i].checked = false;
21                }
22}
23/* Invert selection */
24function invertAllByClass(styleClass) {
25        var elements = document.getElementsByClassName(styleClass);
26                for (var i = 0; i < elements.length; i++) {
27                        elements[i].checked = !elements[i].checked;
28                }
29}
30/* Function that does the AJAX loading process */
31/* Possible FRAMES:
32    'content': main div
33    'tab' + hash: every torrent div (tabs in the left not included)
34    'itab' + hash: div with the name of the torrent, erase, start... buttons
35    'ttab' + hash; div that contents 'tab' + hash and every torrent left tabs
36    'messages': messages frame
37*/
38function load(frame, content) {
39        if(frame == 'content') // Actions for frame 'content' (MAIN FRAME)
40        {
41                var get = getContent(content);
42        }
43        else // Actions for torrent frames
44        {
45                var get = getFrame(content, frame);
46        }
47        ajaxCall(frame, get);
48}
49/* Generate showLoad and showresponse */
50function getShowFunctions(frame)
51{
52        var functions = new Array();
53
54        functions[0] = (function (frame) { return function () { loadingContent(frame); } })(frame);
55        functions[1] = (function (frame) { return function (request) { responseContent(request, frame); } })(frame);
56    //functions[2] = (function (frame) { return function () { resizeFrame(frame); } })(frame);
57       
58        return functions;
59}       
60/* Get URL to change the content of the Top tabs */
61function getContent(id)
62{
63        if(id == 'public') {
64                var pars = 'cls=ListT&tpl=ajax&view=public';
65                view = 'public';
66                tab = 1;
67        }
68        if(id == 'private') {
69                var pars = 'cls=ListT&tpl=ajax&view=private';
70                view = 'private';
71                tab = 1;
72        }
73        return pars;
74}
75/* Get URL to change the content of the torrent tabs */
76function getFrame(content, frame)
77{
78        var cls;
79        switch(content)
80        {
81                case 'info':
82                        cls = 'General';
83                        break;
84                case 'files':
85                        cls = 'Files';
86                        break;
87                case 'trackers':       
88                        cls = 'Tracker';
89                        break;
90                default:
91                        break;
92        }
93        var pars = 'cls=' + cls + '&tpl=details&hash=' + frame.substr(3);
94        return pars;
95}
96/* Load LOADING content in the given frame */
97function loadingContent(frame) {
98    switch(frame)
99    {
100        case 'messages':
101                        $(frame + '_box').style.display = "block";
102                        var loadingDiv = loadingCommand;
103          $(frame).innerHTML = loadingDiv;
104          break;
105        case 'content':
106                        var loadingDiv = loading;
107          $(frame).innerHTML = loadingDiv;
108          break;
109        default:
110          loadingTab(frame);
111          break;
112    }
113    //contractFrame(frame);
114}
115function loadingTab(frame)
116{
117    contractFrame('t' + frame);
118    var overlayCell = $('loadingCell').cloneNode(true);
119    var positions = findPos($('i' + frame));
120    overlayCell.setAttribute('id', 'l' + frame);
121    overlayCell.style.left = (positions[0] + 31) + 'px';
122    overlayCell.style.top = positions[1] + 'px';
123    document.body.appendChild(overlayCell);
124    overlayCell.show();
125                //overlayCell.setOpacity(0.6);
126    //new Effect.Opacity(overlayCell, {duration:0.2, from:0, to:0.6});
127    return;
128}
129/* Load AJAX RESPONSE in given content */
130function responseContent(originalRequest, frame) {
131        var newData = originalRequest.responseText;
132    $(frame).innerHTML = newData;
133    if(frame != "content" && frame != "messages") {
134        var onFinish = (function (frame) { return function (obj) { $(frame).remove(); } })('l'+ frame);
135        //new Effect.Opacity('l' + frame, {duration:0.2, from:0.6, to:0, afterFinish: onFinish});
136        //$('l' + frame).setOpacity(0);
137                                $('l' + frame).remove();
138                                window.setTimeout("expandFrame('t" + frame + "')", 100);
139    }
140        postAjax();
141}
142function expandFrame(frame) {
143    new Effect.BlindDown(frame, {duration:0.5});
144}
145function contractFrame(frame, onFinish) {
146    new Effect.BlindUp(frame, {duration:0.5, afterFinish: onFinish});
147}
148/* Process commands given through the ajax interface */
149function command(command, param)
150{
151        /* Default frame for wTorrent messages and loading/showing functions */
152        var frame = 'messages';
153        var call = new Array();
154        switch(command)
155        {
156                case 'files':
157                        var call = files(param);
158                        break;
159                case 'info':
160                        var call = info(param);
161                        break;
162                case 'trackers':
163                        var call = trackers(param);
164                        break;
165                case 'batch':
166                        var call = batch();
167                        break;
168                default:
169                        var call = defaultCall(command, param);
170                        break;
171        }
172        // Execute the command through ajax
173        ajaxCall(frame, call[0]);
174        // Update the page (after 500ms to give rtorrent time to process the command (also set the frame to loading)
175        //loadingContent(call[1]);
176        window.setTimeout("load('" + call[1] + "', '" + call[2] + "')", 100);
177}
178
179function ajaxCall(frame, pars)
180{
181        // Get show functions with correct frames
182        var functions = getShowFunctions(frame);
183        var showLoad = functions[0];
184        var showResponse = functions[1];
185    //var resizeDiv = functions[2];
186        // Dummy variable to avoid iexplorer cache
187        pars = pars + "&dummy=" + new Date().getTime();
188        var myAjax = new Ajax.Request( url, {
189                        method: 'get', 
190                        parameters: pars, 
191                        onLoading: showLoad, 
192                        onComplete: showResponse
193        } );
194}
195function getChecked(identifier)
196{
197        var params = new Array();
198        var objects = document.getElementsByClassName(identifier);
199        for (var i = 0; i < objects.length; i++) {
200                if(objects[i].checked === true)
201                        params.push(objects[i].id);
202        }
203        return params;
204}
205function files(param)
206{
207        var call = new Array();
208        var params = getChecked('files' + param);
209        var param2 = params.join('~');     
210        param2 = encodeURIComponent(param2);
211        var param1 = $('sf' + param).options[$('sf' + param).selectedIndex].value;
212        call[0] = 'cls=commands&tpl=commands&command=files&param=' + param + '&param1=' + param1 + '&param2=' + param2;
213        call[1] = 'tab' + param;
214        call[2] = 'files';
215       
216        return call;
217}
218function info(param)
219{
220        var call = new Array();
221        param1 = $('sp' + param).options[$('sp' + param).selectedIndex].value;
222        call[0] = 'cls=commands&tpl=commands&command=info&param=' + param + '&param1=' + param1;
223        call[1] = 'tab' + param;
224        call[2] = 'info';
225       
226        return call;
227}
228function trackers(param)
229{
230        var call = new Array();
231        var params = getChecked('trackers' + param);
232        var param2 = params.join('~');     
233        param2 = encodeURIComponent(param2);
234        var param1 = $('st' + param).options[$('st' + param).selectedIndex].value;
235        call[0] = 'cls=commands&tpl=commands&command=trackers&param=' + param + '&param1=' + param1 + '&param2=' + param2;
236        call[1] = 'tab' + param;
237        call[2] = 'trackers';
238       
239        return call;
240}
241function batch()
242{
243        var call = new Array();
244        var command;
245        var params = getChecked('torrent');
246        var number = $('actions').options[$('actions').selectedIndex].value;
247       
248        switch(number)
249        {
250                case '0':
251                        command = 'stop';
252                        break;
253                case '1':
254                        command = 'start';
255                        break;
256                case '2':
257                        command = 'erase';
258                        break;
259                case '3':
260                        command = 'chash';
261                        break;
262                case '4':
263                        command = 'close';
264                        break;
265        }
266                       
267        var param = params.join('~');     
268        param = encodeURIComponent(param);
269        if(command == 'erase')
270        {
271                if(!confirm(confirmMsg))
272                return;
273        }
274        call[0] = 'cls=commands&tpl=commands&command=' + command + '&param=' + param;
275        call[1] = 'content';
276        call[2] = view;
277       
278        return call;
279}
280function defaultCall(command, param)
281{
282        var call = new Array();
283        if(command == 'erase')
284        {
285                if(!confirm(confirmMsg))
286                        return;
287        }
288        call[0] = 'cls=commands&tpl=commands&command=' + command + '&param=' + param;
289        call[1] = 'content';
290        call[2] = view;
291       
292        return call;
293}
294/* Find position of an element */
295function findPos(obj) {
296        var curleft = curtop = 0;
297        if (obj.offsetParent) {
298                do {
299                        curleft += obj.offsetLeft;
300                        curtop += obj.offsetTop;
301                } while (obj = obj.offsetParent);
302        }
303        return [curleft,curtop];
304}
305function torrentTip(elementId) {
306    var content = $('tipContent' + elementId).cloneNode(true);
307    content.id = elementId + 'copy';
308    content.show();
309    new Tip(
310        'tip' + elementId,                 // the id of your element
311        content,                 // a string or an element
312        { 
313            closeButton: false,    // or true
314            duration: 0.3,         // duration of the effect, if used
315            delay: 0,             // seconds before tooltip appears
316            effect: false,         // false, 'appear' or 'blind'
317            fixed: false,          // follow the mouse if false
318            hideAfter: false,      // hides after seconds of inactivity, not hovering the element or the tooltip
319            hideOn: 'mouseout',     // any other event, false or: { element: 'element|target|tip|closeButton|.close', event: 'click|mouseover|mousemove' }
320            hook: false,           // { target: 'topLeft|topRight|bottomLeft|bottomRight|topMiddle|bottomMiddle|leftMiddle|rightMiddle',tip: 'topLeft|topRight|bottomLeft|bottomRight|topMiddle|bottomMiddle|leftMiddle|rightMiddle' }
321            showOn: 'mousemove',   // or any other event
322            viewport: false         // keep within viewport, false when fixed or hooked
323        }
324    );
325}
Note: See TracBrowser for help on using the repository browser.