]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/evergreen/util/deck.js
syntax
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / evergreen / util / deck.js
1 dump('entering util/deck.js\n');
2
3 if (typeof util == 'undefined') util = {};
4 util.deck = function (id) {
5
6         this.node = document.getElementById(id);
7
8         if (!this.node) throw('Could not find element ' + id);
9         if (this.node.nodeName != 'deck') throw(id + ' is not a deck');
10
11         return this;
12 };
13
14 util.deck.prototype = {
15
16         'find_index' : function (url) {
17                 var idx = -1;
18                 var nodes = this.node.childNodes;
19                 for (var i in nodes) {
20                         if (nodes[i].getAttribute('src') == url) idx = i;
21                 }
22                 return idx;
23         },
24
25         'set_iframe' : function (url) {
26                 var idx = this.find_index(url);
27                 if (idx>-1) {
28                         this.node.selectedIndex = idx;
29                 } else {
30                         this.new_iframe(url);
31                 }
32                 
33                 
34         },
35
36         'reset_iframe' : function (url) {
37                 this.remove_iframe(url);
38                 this.new_iframe(url);
39         },
40
41         'new_iframe' : function (url) {
42                 var idx = this.find_index(url);
43                 if (idx>-1) throw('An iframe already exists in deck with url = ' + url);
44
45                 var iframe = document.createElement('iframe');
46                 iframe.setAttribute('src',url);
47                 iframe.setAttribute('flex','1');
48                 this.node.appendChild( iframe );
49                 //this.node.selectedIndex = this.node.childNodes.length - 1;
50         },
51
52         'remove_iframe' : function (url) {
53                 var idx = this.find_index(url);
54                 if (idx>-1) {
55                         this.node.removeChild( this.node.childNodes[ idx ] );
56                 }
57         }
58 }       
59
60 dump('exiting util/deck.js\n');