source: OpenRLabs-Git/deploy/rlabs-docker/web2py-rlabs/applications/admin/static/js/autoscroll.js

main
Last change on this file was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100755
File size: 2.0 KB
Line 
1/*
2 * autoscroll.js widget with jquery event(s)
3 * Copyright 2011 Michael Whitford <michael@alwandassociates.com>
4 * License: BSD
5 */
6
7// toggle - id of the toggle element for the click event
8// textarea  - id of the textarea to autoscroll
9var toggleAutoScroll = function (toggle, textarea) {
10    var autoScrollDebug = false;
11    var state = toggle + 'interval';
12    var scrollOn = function() {
13        if (autoScrollDebug) { console.log('on:', toggle, textarea); }
14        var onAnimation = function(name, target) {
15            jQuery('#' + name).unbind().click(function() {
16                toggleAutoScroll(name, target);
17            }).fadeTo(350, 1);
18        };
19        // uses obj attached to window for state
20        window[state] = {};
21        window[state].name = toggle;
22        window[state].target = textarea;
23        // get a handle to the textarea el
24        var area = jQuery('#' + textarea);
25        // set the interval
26        window[state].interval = setInterval(function() {
27            // ui hack?  needs more testing
28            area[0].scrollTop = area[0].scrollHeight;
29        }, 2500);  // 2.5 seconds
30        onAnimation(toggle, textarea);
31    };
32    var scrollOff = function() {
33        if (autoScrollDebug) { console.log('off:', toggle, textarea); }
34        var offAnimation = function(name, target) {
35            jQuery('#' + name).unbind().click(function() {
36                    toggleAutoScroll(name, target);
37                }).fadeTo(350, 0.55);
38        };
39        offAnimation(toggle, textarea);
40        clearInterval(window[state].interval);
41        window[state] = undefined;
42    };
43    if (arguments.length == 2) {
44        if (typeof window[state] === 'undefined') {
45            scrollOn();
46        } else {
47            scrollOff();
48        }
49    }
50    return;
51};
52
53// jquery onready
54
55jQuery(document).ready(function () {
56    // turn it on by default
57    toggleAutoScroll('autoscroll', 'output');
58});
59
60// todo: some key - toggle off
61// todo: drag scrollbar up - toggle off
62// todo: drag scrollbar to bottom - toggle off
63
Note: See TracBrowser for help on using the repository browser.