Statistics
| Branch: | Revision:

blinker / firefox.plugin / data / scripts / htmlElements.js @ 76dd22bd

History | View | Annotate | Download (2.067 KB)

1
/*
2
 * Copyright 2015 Thies Pfeiffer and Dimitri Heil and Kevin Taron
3
 * Blinker is distributed under the terms of the GNU General Public License
4
 * 
5
 * This file is part of Blinker.
6
 * 
7
 * Blinker is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 * 
12
 * Blinker is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU General Public License for more details.
16
 * 
17
 * You should have received a copy of the GNU General Public License
18
 * along with Blinker. If not, see <http://www.gnu.org/licenses/>.
19
 */
20

    
21
var myhtmlelements = "";
22

    
23
/*
24
* Extract Attributes from Settings.
25
*/
26
self.port.on("getElements", function(htmlelements) {
27
        myhtmlelements = htmlelements;
28
        initGazeElements(htmlelements);
29
});
30

    
31
/**
32
 * Init gaze elements
33
 */
34
function initGazeElements(htmlelements) {
35
        jQuery.each(htmlelements, function(key, attributes) {
36
                jQuery.each(attributes,  function(attribute, value) { 
37
                        gazeAddAttribute(jQuery(key), attribute, value);
38
                });
39
        });
40
}
41

    
42
/**
43
 * Add Attributes to HTML Elements
44
 */
45
function gazeAddAttribute(elements, attribute, value) {
46
        for (var i = 0; i < elements.length; i++) {
47
                if(!jQuery(elements[i]).attr(attribute)) {
48
                    jQuery(elements[i]).attr(attribute, value);
49
                }
50
  }
51
}
52

    
53
// Dom Watch
54

    
55

    
56
jQuery(document).ready(function($) {
57
        jQuery( document ).change(function() {
58
                reloadElementes();
59
                setTimeout(reloadElementes, 1000);
60
                setTimeout(reloadElementes, 2000);
61
        });
62

    
63
        jQuery( document ).ajaxComplete(function() {
64
                reloadElementes();
65
                setTimeout(reloadElementes, 1000);
66
                setTimeout(reloadElementes, 2000);
67
        });
68
        
69
        setInterval(reloadElementes, 5000);
70
});
71

    
72
function reloadElementes() {
73
//        console.log("reload elements");
74
        initGazeElements(myhtmlelements);
75
        worker.port.emit("docChange", htmlelements);
76
}