1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * common functions used for communicating between main, navigation and querywindow
9 * holds the browser query window
14 * holds the query to be load from a new query window
16 var query_to_load
= '';
19 * attach a function to object event
22 * addEvent(window, 'load', PMA_initPage);
25 * @param string event type (load, mouseover, focus, ...)
26 * @param function to be attached
28 function addEvent(obj
, type
, fn
)
30 if (obj
.attachEvent
) {
31 obj
['e' + type
+ fn
] = fn
;
32 obj
[type
+ fn
] = function() {obj
['e' + type
+ fn
](window
.event
);}
33 obj
.attachEvent('on' + type
, obj
[type
+ fn
]);
35 obj
.addEventListener(type
, fn
, false);
40 * detach/remove a function from an object event
43 * @param event type (load, mouseover, focus, ...)
44 * @param function naem of function to be attached
46 function removeEvent(obj
, type
, fn
)
48 if (obj
.detachEvent
) {
49 obj
.detachEvent('on' + type
, obj
[type
+ fn
]);
50 obj
[type
+ fn
] = null;
52 obj
.removeEventListener(type
, fn
, false);
57 * get DOM elements by html class
59 * @param string class_name - name of class
60 * @param node node - search only sub nodes of this node (optional)
61 * @param string tag - search only these tags (optional)
63 function getElementsByClassName(class_name
, node
, tag
)
65 var classElements
= new Array();
75 var els
= node
.getElementsByTagName(tag
);
76 var elsLen
= els
.length
;
78 for (i
= 0; i
< elsLen
; i
++) {
79 if (els
[i
].className
.indexOf(class_name
) != -1) {
80 teststr
= "," + els
[i
].className
.split(" ").join(",") + ",";
81 if (teststr
.indexOf("," + class_name
+ ",") != -1) {
82 classElements
[j
] = els
[i
];
91 * sets current selected db
93 * @param string db name
95 function setDb(new_db
) {
96 //alert('setDb(' + new_db + ')');
99 //alert( new_db + '(' + new_db.length + ') : ' + db );
104 if (window
.frame_navigation
.document
.getElementById(db
) == null) {
105 // db is unknown, reload complete left frame
108 unmarkDbTable(old_db
);
112 // TODO: add code to expand db in lightview mode
114 // refresh querywindow
115 refreshQuerywindow();
120 * sets current selected table (called from navigation.php)
122 * @param string table name
124 function setTable(new_table
) {
125 //alert('setTable(' + new_table + ')');
126 if (new_table
!= table
) {
128 //alert( new_table + '(' + new_table.length + ') : ' + table );
132 if (window
.frame_navigation
.document
.getElementById(db
+ '.' + table
) == null
134 // table is unknown, reload complete left frame
138 // TODO: add code to expand table in lightview mode
140 // refresh querywindow
141 refreshQuerywindow();
155 * @uses collation_connection
156 * @uses encodeURIComponent()
157 * @param string url name of page to be loaded
159 function refreshMain(url
) {
168 goTo(url
+ '?server=' + encodeURIComponent(server
) +
169 '&token=' + encodeURIComponent(token
) +
170 '&db=' + encodeURIComponent(db
) +
171 '&table=' + encodeURIComponent(table
) +
172 '&lang=' + encodeURIComponent(lang
) +
173 '&collation_connection=' + encodeURIComponent(collation_connection
),
178 * reloads navigation frame
186 * @uses collation_connection
187 * @uses encodeURIComponent()
189 function refreshNavigation() {
190 goTo('navigation.php?server=' + encodeURIComponent(server
) +
191 '&token=' + encodeURIComponent(token
) +
192 '&db=' + encodeURIComponent(db
) +
193 '&table=' + encodeURIComponent(table
) +
194 '&lang=' + encodeURIComponent(lang
) +
195 '&collation_connection=' + encodeURIComponent(collation_connection
)
200 * adds class to element
202 function addClass(element
, classname
)
204 if (element
!= null) {
205 element
.className
+= ' ' + classname
;
206 //alert('set class: ' + classname + ', now: ' + element.className);
211 * removes class from element
213 function removeClass(element
, classname
)
215 if (element
!= null) {
216 element
.className
= element
.className
.replace(' ' + classname
, '');
217 // if there is no other class anem there is no leading space
218 element
.className
= element
.className
.replace(classname
, '');
219 //alert('removed class: ' + classname + ', now: ' + element.className);
223 function unmarkDbTable(db
, table
)
225 var element_reference
= window
.frame_navigation
.document
.getElementById(db
);
226 if (element_reference
!= null) {
227 //alert('remove from: ' + db);
228 removeClass(element_reference
.parentNode
, 'marked');
231 element_reference
= window
.frame_navigation
.document
.getElementById(db
+ '.' + table
);
232 if (element_reference
!= null) {
233 //alert('remove from: ' + db + '.' + table);
234 removeClass(element_reference
.parentNode
, 'marked');
238 function markDbTable(db
, table
)
240 var element_reference
= window
.frame_navigation
.document
.getElementById(db
);
241 if (element_reference
!= null) {
242 addClass(element_reference
.parentNode
, 'marked');
244 element_reference
.focus();
245 // opera marks the text, we dont want this ...
246 element_reference
.blur();
249 element_reference
= window
.frame_navigation
.document
.getElementById(db
+ '.' + table
);
250 if (element_reference
!= null) {
251 addClass(element_reference
.parentNode
, 'marked');
253 element_reference
.focus();
254 // opera marks the text, we dont want this ...
255 element_reference
.blur();
258 // return to main frame ...
259 window
.frame_content
.focus();
263 * sets current selected server, table and db (called from libraries/footer.inc.php)
265 function setAll( new_lang
, new_collation_connection
, new_server
, new_db
, new_table
, new_token
) {
266 //alert('setAll( ' + new_lang + ', ' + new_collation_connection + ', ' + new_server + ', ' + new_db + ', ' + new_table + ', ' + new_token + ' )');
267 if (new_server
!= server
|| new_lang
!= lang
268 || new_collation_connection
!= collation_connection
) {
269 // something important has changed
273 collation_connection
= new_collation_connection
;
277 } else if (new_db
!= db
|| new_table
!= table
) {
278 // save new db and table
280 var old_table
= table
;
284 if (window
.frame_navigation
.document
.getElementById(db
) == null
285 && window
.frame_navigation
.document
.getElementById(db
+ '.' + table
) == null ) {
286 // table or db is unknown, reload complete left frame
289 unmarkDbTable(old_db
, old_table
);
290 markDbTable(db
, table
);
293 // TODO: add code to expand db in lightview mode
295 // refresh querywindow
296 refreshQuerywindow();
300 function reload_querywindow(db
, table
, sql_query
)
302 if ( ! querywindow
.closed
&& querywindow
.location
) {
303 if ( ! querywindow
.document
.sqlform
.LockFromUpdate
304 || ! querywindow
.document
.sqlform
.LockFromUpdate
.checked
) {
305 querywindow
.document
.getElementById('hiddenqueryform').db
.value
= db
;
306 querywindow
.document
.getElementById('hiddenqueryform').table
.value
= table
;
309 querywindow
.document
.getElementById('hiddenqueryform').sql_query
.value
= sql_query
;
312 querywindow
.document
.getElementById('hiddenqueryform').submit();
318 * brings query window to front and inserts query to be edited
320 function focus_querywindow(sql_query
)
322 /* if ( querywindow && !querywindow.closed && querywindow.location) { */
323 if ( !querywindow
|| querywindow
.closed
|| !querywindow
.location
) {
324 // we need first to open the window and cannot pass the query with it
325 // as we dont know if the query exceeds max url length
326 /* url = 'querywindow.php?' + common_query + '&db=' + db + '&table=' + table + '&sql_query=SELECT * FROM'; */
327 query_to_load
= sql_query
;
331 //var querywindow = querywindow;
332 if ( querywindow
.document
.getElementById('hiddenqueryform').querydisplay_tab
!= 'sql' ) {
333 querywindow
.document
.getElementById('hiddenqueryform').querydisplay_tab
.value
= "sql";
334 querywindow
.document
.getElementById('hiddenqueryform').sql_query
.value
= sql_query
;
335 querywindow
.document
.getElementById('hiddenqueryform').submit();
345 * inserts query string into query window textarea
346 * called from script tag in querywindow
348 function insertQuery() {
349 if (query_to_load
!= '' && querywindow
.document
&& querywindow
.document
.getElementById
&& querywindow
.document
.getElementById('sqlquery')) {
350 querywindow
.document
.getElementById('sqlquery').value
= query_to_load
;
357 function open_querywindow( url
) {
359 url
= 'querywindow.php?' + common_query
+ '&db=' + encodeURIComponent(db
) + '&table=' + encodeURIComponent(table
);
362 if (!querywindow
.closed
&& querywindow
.location
) {
363 goTo( url
, 'query' );
366 querywindow
= window
.open( url
+ '&init=1', '',
367 'toolbar=0,location=0,directories=0,status=1,menubar=0,' +
368 'scrollbars=yes,resizable=yes,' +
369 'width=' + querywindow_width
+ ',' +
370 'height=' + querywindow_height
);
373 if ( ! querywindow
.opener
) {
374 querywindow
.opener
= window
.window
;
377 if ( window
.focus
) {
384 function refreshQuerywindow( url
) {
386 if ( ! querywindow
.closed
&& querywindow
.location
) {
387 if ( ! querywindow
.document
.sqlform
.LockFromUpdate
388 || ! querywindow
.document
.sqlform
.LockFromUpdate
.checked
) {
389 open_querywindow( url
)
395 * opens new url in target frame, with default being left frame
396 * valid is 'main' and 'querywindow' all others leads to 'left'
398 * @param string targeturl new url to load
399 * @param string target frame where to load the new url
401 function goTo(targeturl
, target
) {
403 if ( target
== 'main' ) {
404 target
= window
.frame_content
;
405 } else if ( target
== 'query' ) {
406 target
= querywindow
;
407 //return open_querywindow( targeturl );
408 } else if ( ! target
) {
409 target
= window
.frame_navigation
;
413 if ( target
.location
.href
== targeturl
) {
415 } else if ( target
.location
.href
== pma_absolute_uri
+ targeturl
) {
419 if ( safari_browser
) {
420 target
.location
.href
= targeturl
;
422 target
.location
.replace(targeturl
);
429 // opens selected db in main frame
430 function openDb(new_db
) {
431 //alert('opendb(' + new_db + ')');
434 refreshMain(opendb_url
);
438 function updateTableTitle( table_link_id
, new_title
) {
439 //alert('updateTableTitle');
440 if ( window
.parent
.frame_navigation
.document
&& window
.parent
.frame_navigation
.document
.getElementById(table_link_id
) ) {
441 var left
= window
.parent
.frame_navigation
.document
;
443 var link
= left
.getElementById(table_link_id
);
444 link
.title
= window
.parent
.pma_text_default_tab
+ ': ' + new_title
;
446 var link
= left
.getElementById('quick_' + table_link_id
);
447 link
.title
= window
.parent
.pma_text_left_default_tab
+ ': ' + new_title
;