~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to lib/helioviewer/LEGACY/DomNodeCache.js

  • Committer: Keith Hughitt
  • Date: 2010-02-17 22:00:59 UTC
  • mfrom: (402.1.68 hv)
  • Revision ID: keith.hughitt@nasa.gov-20100217220059-wmdq7kgokj4seryx
Merged with Keith's branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * @author Patrick Schmiedel patrick.schmiedel@gmx.net
3
 
 */
4
 
/**
5
 
 * @class DomNodeCache This class manages a cache of DOM nodes to improve loading times.
6
 
 */
7
 
  /*global Class, $, $A*/
8
 
var DomNodeCache = Class.create();
9
 
 
10
 
DomNodeCache.prototype = {
11
 
        /**
12
 
         * @constructor
13
 
         */
14
 
        initialize: function () {
15
 
                this.cache = $A([]);
16
 
        },
17
 
        list: function ()
18
 
        {
19
 
                return this.cache;
20
 
        },
21
 
 
22
 
        /**
23
 
         * @function add                                Adds a new DOM Node to the cache.
24
 
         * @param {DOM Node} element    The DOM Node to add.
25
 
         * @param {Number} zoomLevel    The zoom level of the element.
26
 
         * @param {Number} xIndex               The x index of the element.
27
 
         * @param {Number} yIndex               The y index of the element.
28
 
         */
29
 
        add: function (element, zoomLevel, xIndex, yIndex) {
30
 
                if (!this.cache[zoomLevel]) {
31
 
                    this.cache[zoomLevel] = [];
32
 
                }
33
 
                if (!this.cache[zoomLevel][xIndex]) {
34
 
                    this.cache[zoomLevel][xIndex] = [];
35
 
                }
36
 
                this.cache[zoomLevel][xIndex][yIndex] = element;
37
 
        },
38
 
 
39
 
        /**
40
 
         * @method                              Returns a DOM Node in the cache.
41
 
         * @param {Number} zoomLevel    The zoom level of the element.
42
 
         * @param {Number} xIndex               The x index of the element.
43
 
         * @param {Number} yIndex               The y index of the element.
44
 
         * @return (DOM Node}           The DOM Node in the cache.
45
 
         */
46
 
        get: function (zoomLevel, xIndex, yIndex) {
47
 
                if (this.cache[zoomLevel] && this.cache[zoomLevel][xIndex] && this.cache[zoomLevel][xIndex][yIndex]) {
48
 
                    return this.cache[zoomLevel][xIndex][yIndex];
49
 
                }
50
 
                return null;
51
 
        },
52
 
 
53
 
        /**
54
 
         * @method contains                     Returns whether the cache contains an element at the given position.
55
 
         * @param {Number} zoomLevel    The zoom level of the element.
56
 
         * @param {Number} xIndex               The x index of the element.
57
 
         * @param {Number} yIndex               The y index of the element.
58
 
         * @return {Boolean}                    Whether the cache contains an element at the given position.
59
 
         */
60
 
        contains: function (zoomLevel, xIndex, yIndex) {
61
 
                return (this.cache[zoomLevel]
62
 
                         && this.cache[zoomLevel][xIndex]
63
 
                         && this.cache[zoomLevel][xIndex][yIndex] ? true : false);
64
 
        },
65
 
        
66
 
        /**
67
 
         * @method zoomLevels   Returns the number of zoom levels in the cache.
68
 
         * @return {Number}             The number of zoom levels.
69
 
         */
70
 
        zoomLevels: function () {
71
 
                return this.cache.length;
72
 
        },
73
 
        
74
 
        /**
75
 
         * @method clear        Clears the cache.
76
 
         */
77
 
        clear: function () {
78
 
                this.cache = $A([]);
79
 
                return this;
80
 
        },
81
 
        
82
 
        /**
83
 
         * @method remove       Removes all elements from the DOM.
84
 
         */
85
 
        remove: function () {
86
 
                this.cache.flatten().each(function (element) {
87
 
                    if (element && element.parentNode) {
88
 
                        element.remove();
89
 
                    }
90
 
                });
91
 
                return this;
92
 
        },
93
 
        
94
 
        /**
95
 
         * @method removeAndClear       Removes all elements from the DOM and clears the cache.
96
 
         */
97
 
        removeAndClear: function () {
98
 
                this.remove().clear();
99
 
        },
100
 
        
101
 
        /**
102
 
         * @method setStyle             Sets CSS style properties on all elements in the cache.
103
 
         * @param {Hash} style  A Hash of CSS property/value pairs.
104
 
         */
105
 
        setStyle: function (style) {
106
 
    //Debug.output('setting style', this.cache.flatten().pluck('style').pluck('zIndex'), $H(style).inspect());
107
 
                this.cache.flatten().each(function (domNode) {
108
 
                    if (domNode && domNode.style) {
109
 
                        $(domNode).setStyle(style);
110
 
                    }
111
 
                });
112
 
    //Debug.output('style set', this.cache.flatten().pluck('style').pluck('zIndex'), $H(style).inspect());
113
 
        }
114
 
};
115
 
 
116
 
/*
117
 
var TileCache = Class.create();
118
 
 
119
 
TileCache.prototype = Object.extend(new DomNodeCache(), {
120
 
        initialize: function() {
121
 
                this.cache = new Array();
122
 
        },
123
 
        
124
 
        remove: function() {
125
 
                this.cache.flatten().each(function(element) { if (element && element.domNode) element.domNode.remove(); });
126
 
                return this;
127
 
        }
128
 
});
129
 
*/