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 opbject 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();
154 * @uses collation_connection
155 * @uses encodeURIComponent()
156 * @param string url name of page to be loaded
158 function refreshMain(url) {
167 goTo(url + '?server=' + encodeURIComponent(server) +
168 '&db=' + encodeURIComponent(db) +
169 '&table=' + encodeURIComponent(table) +
170 '&lang=' + encodeURIComponent(lang) +
171 '&collation_connection=' + encodeURIComponent(collation_connection),
176 * reloads navigation frame
183 * @uses collation_connection
184 * @uses encodeURIComponent()
186 function refreshNavigation() {
187 goTo('navigation.php?server=' + encodeURIComponent(server) +
188 '&db=' + encodeURIComponent(db) +
189 '&table=' + encodeURIComponent(table) +
190 '&lang=' + encodeURIComponent(lang) +
191 '&collation_connection=' + encodeURIComponent(collation_connection)
196 * adds class to element
198 function addClass(element, classname)
200 if (element != null) {
201 element.className += ' ' + classname;
202 //alert('set class: ' + classname + ', now: ' + element.className);
207 * removes class from element
209 function removeClass(element, classname)
211 if (element != null) {
212 element.className = element.className.replace(' ' + classname, '');
213 // if there is no other class anem there is no leading space
214 element.className = element.className.replace(classname, '');
215 //alert('removed class: ' + classname + ', now: ' + element.className);
219 function unmarkDbTable(db, table)
221 var element_reference = window.frame_navigation.document.getElementById(db);
222 if (element_reference != null) {
223 //alert('remove from: ' + db);
224 removeClass(element_reference.parentNode, 'marked');
227 element_reference = window.frame_navigation.document.getElementById(db + '.' + table);
228 if (element_reference != null) {
229 //alert('remove from: ' + db + '.' + table);
230 removeClass(element_reference.parentNode, 'marked');
234 function markDbTable(db, table)
236 var element_reference = window.frame_navigation.document.getElementById(db);
237 if (element_reference != null) {
238 addClass(element_reference.parentNode, 'marked');
240 element_reference.focus();
241 // opera marks the text, we dont want this ...
242 element_reference.blur();
245 element_reference = window.frame_navigation.document.getElementById(db + '.' + table);
246 if (element_reference != null) {
247 addClass(element_reference.parentNode, 'marked');
249 element_reference.focus();
250 // opera marks the text, we dont want this ...
251 element_reference.blur();
254 // return to main frame ...
255 window.frame_content.focus();
259 * sets current selected server, table and db (called from libraries/footer.inc.php)
261 function setAll( new_lang, new_collation_connection, new_server, new_db, new_table ) {
262 //alert('setAll( ' + new_lang + ', ' + new_collation_connection + ', ' + new_server + ', ' + new_db + ', ' + new_table + ' )');
263 if (new_server != server || new_lang != lang
264 || new_collation_connection != collation_connection) {
265 // something important has changed
269 collation_connection = new_collation_connection;
272 } else if (new_db != db || new_table != table) {
273 // save new db and table
275 var old_table = table;
279 if (window.frame_navigation.document.getElementById(db) == null
280 && window.frame_navigation.document.getElementById(db + '.' + table) == null ) {
281 // table or db is unknown, reload complete left frame
284 unmarkDbTable(old_db, old_table);
285 markDbTable(db, table);
288 // TODO: add code to expand db in lightview mode
290 // refresh querywindow
291 refreshQuerywindow();
295 function reload_querywindow(db, table, sql_query)
297 if ( ! querywindow.closed && querywindow.location ) {
298 if ( ! querywindow.document.sqlform.LockFromUpdate
299 || ! querywindow.document.sqlform.LockFromUpdate.checked ) {
300 querywindow.document.getElementById('hiddenqueryform').db.value = db;
301 querywindow.document.getElementById('hiddenqueryform').table.value = table;
304 querywindow.document.getElementById('hiddenqueryform').sql_query.value = sql_query;
307 querywindow.document.getElementById('hiddenqueryform').submit();
313 * brings query window to front and inserts query to be edited
315 function focus_querywindow(sql_query)
317 /* if ( querywindow && !querywindow.closed && querywindow.location) { */
318 if ( !querywindow || querywindow.closed || !querywindow.location) {
319 // we need first to open the window and cannot pass the query with it
320 // as we dont know if the query exceeds max url length
321 /* url = 'querywindow.php?' + common_query + '&db=' + db + '&table=' + table + '&sql_query=SELECT * FROM'; */
322 query_to_load = sql_query;
326 //var querywindow = querywindow;
327 if ( querywindow.document.getElementById('hiddenqueryform').querydisplay_tab != 'sql' ) {
328 querywindow.document.getElementById('hiddenqueryform').querydisplay_tab.value = "sql";
329 querywindow.document.getElementById('hiddenqueryform').sql_query.value = sql_query;
330 querywindow.document.getElementById('hiddenqueryform').submit();
340 * inserts query string into query window textarea
341 * called from script tag in querywindow
343 function insertQuery() {
344 if (query_to_load != '' && querywindow.document && querywindow.document.getElementById && querywindow.document.getElementById('sqlquery')) {
345 querywindow.document.getElementById('sqlquery').value = query_to_load;
352 function open_querywindow( url ) {
354 url = 'querywindow.php?' + common_query + '&db=' + encodeURIComponent(db) + '&table=' + encodeURIComponent(table);
357 if (!querywindow.closed && querywindow.location) {
358 goTo( url, 'query' );
361 querywindow = window.open( url + '&init=1', '',
362 'toolbar=0,location=0,directories=0,status=1,menubar=0,' +
363 'scrollbars=yes,resizable=yes,' +
364 'width=' + querywindow_width + ',' +
365 'height=' + querywindow_height );
368 if ( ! querywindow.opener ) {
369 querywindow.opener = window.window;
372 if ( window.focus ) {
379 function refreshQuerywindow( url ) {
381 if ( ! querywindow.closed && querywindow.location ) {
382 if ( ! querywindow.document.sqlform.LockFromUpdate
383 || ! querywindow.document.sqlform.LockFromUpdate.checked ) {
384 open_querywindow( url )
390 * opens new url in target frame, with default beeing left frame
391 * valid is 'main' and 'querywindow' all others leads to 'left'
393 * @param string targeturl new url to load
394 * @param string target frame where to load the new url
396 function goTo(targeturl, target) {
398 if ( target == 'main' ) {
399 target = window.frame_content;
400 } else if ( target == 'query' ) {
401 target = querywindow;
402 //return open_querywindow( targeturl );
403 } else if ( ! target ) {
404 target = window.frame_navigation;
408 if ( target.location.href == targeturl ) {
410 } else if ( target.location.href == pma_absolute_uri + targeturl ) {
414 if ( safari_browser ) {
415 target.location.href = targeturl;
417 target.location.replace(targeturl);
424 // opens selected db in main frame
425 function openDb(new_db) {
426 //alert('opendb(' + new_db + ')');
429 refreshMain(opendb_url);
433 function updateTableTitle( table_link_id, new_title ) {
434 //alert('updateTableTitle');
435 if ( window.parent.frame_navigation.document.getElementById(table_link_id) ) {
436 var left = window.parent.frame_navigation.document;
437 left.getElementById(table_link_id).title = new_title;
438 new_title = left.getElementById('icon_' + table_link_id).alt + ': ' + new_title;
439 left.getElementById('quick_' + table_link_id).title = new_title;