]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/evergreen/util/deck.js
util.deck
[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         'set_iframe' : 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                 if (idx>-1) {
23                         this.node.selectedIndex = idx;
24                 } else {
25                         this.new_iframe(url);
26                 }
27                 
28                 
29         },
30
31         'reset_iframe' : function (url) {
32                 this.remove_iframe(url);
33                 this.new_iframe(url);
34         },
35
36         'new_iframe' : function (url) {
37                 var idx = -1;
38                 var nodes = this.node.childNodes;
39                 for (var i in nodes) {
40                         if (nodes[i].getAttribute('src' == url) idx = i;
41                 }
42                 if (idx>-1) throw('An iframe already exists in deck with url = ' + url);
43
44                 var iframe = document.createElement('iframe');
45                 iframe.setAttribute('src',url);
46                 iframe.setAttribute('flex','1');
47                 this.node.appendChild( iframe );
48                 //this.node.selectedIndex = this.node.childNodes.length - 1;
49         }
50
51         'remove_iframe' : function (url) {
52                 var idx = -1;
53                 var nodes = this.node.childNodes;
54                 for (var i in nodes) {
55                         if (nodes[i].getAttribute('src' == url) idx = i;
56                 }
57                 if (idx>-1) {
58                         this.node.removeChild( this.node.childNodes[ idx ] );
59                 }
60         }
61 }       
62
63 dump('exiting util/deck.js\n');