1 dump('entering util/deck.js\n');
3 if (typeof util == 'undefined') util = {};
4 util.deck = function (id_or_node) {
6 this.node = typeof id_or_node == 'object' ? id_or_node : document.getElementById(id_or_node);
8 JSAN.use('util.error'); this.error = new util.error();
11 var error = 'util.deck: Could not find element ' + id_or_node;
12 this.error.sdump('D_ERROR',error);
15 if (this.node.nodeName != 'deck') {
16 var error = 'util.deck: ' + id_or_node + 'is not a deck' + "\nIt's a " + this.node.nodeName;
17 this.error.sdump('D_ERROR',error);
24 util.deck.prototype = {
26 'clear' : function() {
27 while (this.node.lastChild) this.node.removeChild( this.node.lastChild );
30 'clear_all_except' : function(url) {
31 var keep_me = this.find_index(url); var remove_me = [];
32 for (var i = 0; i < this.node.childNodes.length; i++) {
33 if (i != keep_me) remove_me.push( this.node.childNodes[i] );
35 for (var i = 0; i < remove_me.length; i++) this.node.removeChild( remove_me[i] );
38 'find_index' : function (url) {
40 var nodes = this.node.childNodes;
41 for (var i = 0; i < nodes.length; i++) {
42 if (nodes[i].getAttribute('src') == url) idx = i;
47 'set_iframe' : function (url,params,content_params) {
48 this.error.sdump('D_TRACE','util.deck.set_iframe: url = ' + url);
49 var idx = this.find_index(url);
51 this.node.selectedIndex = idx;
53 var iframe = this.node.childNodes[idx];
57 this.error.sdump('D_DECK', 'set_iframe\nurl = ' + url + '\nframe.contentWindow = ' + iframe.contentWindow + '\n' + 'content_params = ' + (content_params) );
58 var cw = iframe.contentWindow;
59 if (typeof iframe.contentWindow.wrappedJSObject != 'undefined') cw = iframe.contentWindow.wrappedJSObject;
60 cw.IAMXUL = true; cw.xulG = content_params;
61 setTimeout( function() { if (typeof cw.default_focus == 'function') cw.default_focus(); }, 0 );
63 this.error.sdump('D_ERROR','E: ' + E + '\n');
69 return this.new_iframe(url,params,content_params);
74 'reset_iframe' : function (url,params,content_params) {
75 this.remove_iframe(url);
76 return this.new_iframe(url,params,content_params);
79 'new_iframe' : function (url,params,content_params) {
80 var idx = this.find_index(url);
81 if (idx>-1) throw('An iframe already exists in deck with url = ' + url);
83 var iframe = document.createElement('iframe');
84 iframe.setAttribute('src',url);
85 //iframe.setAttribute('flex','1');
86 //iframe.setAttribute('style','overflow: scroll');
87 //iframe.setAttribute('style','border: solid thin red');
88 this.node.appendChild( iframe );
89 this.node.selectedIndex = this.node.childNodes.length - 1;
92 this.error.sdump('D_DECK', 'new_iframe\nurl = ' + url + '\nframe.contentWindow = ' + iframe.contentWindow + '\n' + 'content_params = ' + (content_params) );
93 var cw = iframe.contentWindow;
94 if (typeof iframe.contentWindow.wrappedJSObject != 'undefined') cw = iframe.contentWindow.wrappedJSObject;
95 cw.IAMXUL = true; cw.xulG = content_params;
96 this.error.sdump('D_DECK', 'cw = ' + cw + ' cw.xulG = ' + (cw.xulG) );
97 setTimeout( function() { if (typeof cw.default_focus == 'function') cw.default_focus(); }, 0 );
99 this.error.sdump('D_ERROR','E: ' + E + '\n');
105 'remove_iframe' : function (url) {
106 var idx = this.find_index(url);
108 this.node.removeChild( this.node.childNodes[ idx ] );
112 /* FIXME -- consider all the browser stuff broken.. very weird behavior in new_browser */
114 'get_iframe' : function() {
115 return this.node.childNodes[ this.node.selectedIndex ];
118 'get_contentWindow' : function() {
119 return get_contentWindow( this.get_iframe() );
122 'set_browser' : function (url,params,content_params) {
123 this.error.sdump('D_TRACE','util.deck.set_browser: url = ' + url);
124 var idx = this.find_index(url);
126 this.node.selectedIndex = idx;
128 var browser = this.node.childNodes[idx];
130 if (content_params) {
131 /* FIXME -- we'd need to reach in and change the passthru_content_params for the browser, as well as the xulG for the content */
132 alert("we're in set_browser, content_params = true");
137 return this.new_browser(url,params,content_params);
142 'reset_browser' : function (url,params,content_params) {
143 this.remove_browser(url);
144 return this.new_browser(url,params,content_params);
147 'new_browser' : function (url,params,content_params) {
149 alert('in new_browser.. typeof xulG == ' + typeof xulG);
150 alert('in new_browser.. typeof content_params == ' + typeof content_params);
152 var idx = this.find_index(url);
153 if (idx>-1) throw('A browser already exists in deck with url = ' + url);
155 var browser = document.createElement('browser');
157 browser.setAttribute('type','content');
158 browser.setAttribute('autoscroll','false');
159 browser.setAttribute('id','frame_'+obj.id_incr);
160 browser.setAttribute('src',url);
161 this.node.appendChild( browser );
162 alert('after append');
163 this.node.selectedIndex = this.node.childNodes.length - 1;
164 dump('creating browser with src = ' + url + '\n');
165 alert('content_params = ' + content_params);
166 JSAN.use('util.browser');
167 var b = new util.browser();
173 'browser_id' : 'frame_'+obj.id_incr,
174 'passthru_content_params' : content_params
183 'remove_browser' : function (url) {
184 var idx = this.find_index(url);
186 this.node.removeChild( this.node.childNodes[ idx ] );
193 dump('exiting util/deck.js\n');