refactored JavaScript handling

This commit is contained in:
Sebastian Mendel
2007-10-05 11:45:55 +00:00
parent 092d675255
commit 98c8a7719e
5 changed files with 176 additions and 146 deletions

37
js/querywindow.js Normal file
View File

@@ -0,0 +1,37 @@
function PMA_queryAutoCommit()
{
document.getElementById('sqlqueryform').target = window.opener.frame_content.name;
document.getElementById('sqlqueryform').submit();
return;
}
function PMA_querywindowCommit(tab)
{
document.getElementById('hiddenqueryform').querydisplay_tab.value = tab;
document.getElementById('hiddenqueryform').submit();
return false;
}
function PMA_querywindowResize()
{
// for Gecko
if (typeof(self.sizeToContent) == 'function') {
self.sizeToContent();
//self.scrollbars.visible = false;
// give some more space ... to prevent 'fli(pp/ck)ing'
self.resizeBy(10, 50);
return;
}
// for IE, Opera
if (document.getElementById && typeof(document.getElementById('querywindowcontainer')) != 'undefined') {
// get content size
var newWidth = document.getElementById('querywindowcontainer').offsetWidth;
var newHeight = document.getElementById('querywindowcontainer').offsetHeight;
// set size to contentsize
// plus some offset for scrollbars, borders, statusbar, menus ...
self.resizeTo(newWidth + 45, newHeight + 75);
}
}

View File

@@ -453,6 +453,12 @@ $GLOBALS['js_include'] = array();
*/ */
$GLOBALS['js_messages'] = array(); $GLOBALS['js_messages'] = array();
/**
* JavaScript events that will be registered
* @global array $js_events
*/
$GLOBALS['js_events'] = array();
/******************************************************************************/ /******************************************************************************/
/* parsing configuration file LABEL_parsing_config_file */ /* parsing configuration file LABEL_parsing_config_file */

View File

@@ -25,90 +25,7 @@ if (empty($GLOBALS['is_header_sent'])) {
require_once './libraries/header_http.inc.php'; require_once './libraries/header_http.inc.php';
require_once './libraries/header_meta_style.inc.php'; require_once './libraries/header_meta_style.inc.php';
require_once './libraries/header_scripts.inc.php';
// generate title
$title = str_replace(
array(
'@HTTP_HOST@',
'@SERVER@',
'@VERBOSE@',
'@VSERVER@',
'@DATABASE@',
'@TABLE@',
'@PHPMYADMIN@',
),
array(
PMA_getenv('HTTP_HOST') ? PMA_getenv('HTTP_HOST') : '',
isset($GLOBALS['cfg']['Server']['host']) ? $GLOBALS['cfg']['Server']['host'] : '',
isset($GLOBALS['cfg']['Server']['verbose']) ? $GLOBALS['cfg']['Server']['verbose'] : '',
!empty($GLOBALS['cfg']['Server']['verbose']) ? $GLOBALS['cfg']['Server']['verbose'] : (isset($GLOBALS['cfg']['Server']['host']) ? $GLOBALS['cfg']['Server']['host'] : ''),
$GLOBALS['db'],
$GLOBALS['table'],
'phpMyAdmin ' . PMA_VERSION,
),
!empty($GLOBALS['table']) ? $GLOBALS['cfg']['TitleTable'] :
(!empty($GLOBALS['db']) ? $GLOBALS['cfg']['TitleDatabase'] :
(!empty($GLOBALS['cfg']['Server']['host']) ? $GLOBALS['cfg']['TitleServer'] :
$GLOBALS['cfg']['TitleDefault']))
);
// here, the function does not exist with this configuration: $cfg['ServerDefault'] = 0;
$is_superuser = function_exists('PMA_isSuperuser') && PMA_isSuperuser();
if (in_array('functions.js', $GLOBALS['js_include'])) {
$js_messages['strFormEmpty'] = $GLOBALS['strFormEmpty'];
$js_messages['strNotNumber'] = $GLOBALS['strNotNumber'];
if (!$is_superuser && !$GLOBALS['cfg']['AllowUserDropDatabase']) {
$js_messages['strNoDropDatabases'] = $GLOBALS['strNoDropDatabases'];
} else {
$js_messages['strNoDropDatabases'] = '';
}
if ($GLOBALS['cfg']['Confirm']) {
$js_messages['strDoYouReally'] = $GLOBALS['strDoYouReally'];
$js_messages['strDropDatabaseStrongWarning'] = $GLOBALS['strDropDatabaseStrongWarning'];
} else {
$js_messages['strDoYouReally'] = '';
$js_messages['strDropDatabaseStrongWarning'] = '';
}
} elseif (in_array('indexes.js', $GLOBALS['js_include'])) {
$js_messages['strFormEmpty'] = $GLOBALS['strFormEmpty'];
$js_messages['strNotNumber'] = $GLOBALS['strNotNumber'];
}
if (in_array('server_privileges.js', $GLOBALS['js_include'])) {
$js_messages['strHostEmpty'] = $GLOBALS['strHostEmpty'];
$js_messages['strUserEmpty'] = $GLOBALS['strUserEmpty'];
$js_messages['strPasswordEmpty'] = $GLOBALS['strPasswordEmpty'];
$js_messages['strPasswordNotSame'] = $GLOBALS['strPasswordNotSame'];
}
$GLOBALS['js_include'][] = 'tooltip.js';
?>
<script type="text/javascript">
// <![CDATA[
// Updates the title of the frameset if possible (ns4 does not allow this)
if (typeof(parent.document) != 'undefined' && typeof(parent.document) != 'unknown'
&& typeof(parent.document.title) == 'string') {
parent.document.title = '<?php echo PMA_sanitize(PMA_escapeJsString($title)); ?>';
}
var PMA_messages = new Array();
<?php
foreach ($js_messages as $name => $js_message) {
echo "PMA_messages['" . $name . "'] = '" . PMA_escapeJsString($js_message) . "';\n";
}
?>
// ]]>
</script>
<?php
foreach ($GLOBALS['js_include'] as $js_script_file) {
echo '<script src="./js/' . $js_script_file . '" type="text/javascript"></script>' . "\n";
}
// Reloads the navigation frame via JavaScript if required
PMA_reloadNavigation();
?> ?>
<meta name="OBGZip" content="<?php echo ($GLOBALS['cfg']['OBGzip'] ? 'true' : 'false'); ?>" /> <meta name="OBGZip" content="<?php echo ($GLOBALS['cfg']['OBGzip'] ? 'true' : 'false'); ?>" />
<?php /* remove vertical scroll bar bug in ie */ ?> <?php /* remove vertical scroll bar bug in ie */ ?>

View File

@@ -0,0 +1,107 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
*
* @version $Id: header.inc.php 10719 2007-10-04 15:03:44Z cybot_tm $
*/
/**
*
*/
require_once './libraries/common.inc.php';
// generate title
$title = str_replace(
array(
'@HTTP_HOST@',
'@SERVER@',
'@VERBOSE@',
'@VSERVER@',
'@DATABASE@',
'@TABLE@',
'@PHPMYADMIN@',
),
array(
PMA_getenv('HTTP_HOST') ? PMA_getenv('HTTP_HOST') : '',
isset($GLOBALS['cfg']['Server']['host']) ? $GLOBALS['cfg']['Server']['host'] : '',
isset($GLOBALS['cfg']['Server']['verbose']) ? $GLOBALS['cfg']['Server']['verbose'] : '',
!empty($GLOBALS['cfg']['Server']['verbose']) ? $GLOBALS['cfg']['Server']['verbose'] : (isset($GLOBALS['cfg']['Server']['host']) ? $GLOBALS['cfg']['Server']['host'] : ''),
$GLOBALS['db'],
$GLOBALS['table'],
'phpMyAdmin ' . PMA_VERSION,
),
!empty($GLOBALS['table']) ? $GLOBALS['cfg']['TitleTable'] :
(!empty($GLOBALS['db']) ? $GLOBALS['cfg']['TitleDatabase'] :
(!empty($GLOBALS['cfg']['Server']['host']) ? $GLOBALS['cfg']['TitleServer'] :
$GLOBALS['cfg']['TitleDefault']))
);
// here, the function does not exist with this configuration: $cfg['ServerDefault'] = 0;
$is_superuser = function_exists('PMA_isSuperuser') && PMA_isSuperuser();
if (in_array('functions.js', $GLOBALS['js_include'])) {
$js_messages['strFormEmpty'] = $GLOBALS['strFormEmpty'];
$js_messages['strNotNumber'] = $GLOBALS['strNotNumber'];
if (!$is_superuser && !$GLOBALS['cfg']['AllowUserDropDatabase']) {
$js_messages['strNoDropDatabases'] = $GLOBALS['strNoDropDatabases'];
} else {
$js_messages['strNoDropDatabases'] = '';
}
if ($GLOBALS['cfg']['Confirm']) {
$js_messages['strDoYouReally'] = $GLOBALS['strDoYouReally'];
$js_messages['strDropDatabaseStrongWarning'] = $GLOBALS['strDropDatabaseStrongWarning'];
} else {
$js_messages['strDoYouReally'] = '';
$js_messages['strDropDatabaseStrongWarning'] = '';
}
} elseif (in_array('indexes.js', $GLOBALS['js_include'])) {
$js_messages['strFormEmpty'] = $GLOBALS['strFormEmpty'];
$js_messages['strNotNumber'] = $GLOBALS['strNotNumber'];
}
if (in_array('server_privileges.js', $GLOBALS['js_include'])) {
$js_messages['strHostEmpty'] = $GLOBALS['strHostEmpty'];
$js_messages['strUserEmpty'] = $GLOBALS['strUserEmpty'];
$js_messages['strPasswordEmpty'] = $GLOBALS['strPasswordEmpty'];
$js_messages['strPasswordNotSame'] = $GLOBALS['strPasswordNotSame'];
}
$GLOBALS['js_include'][] = 'tooltip.js';
$js_events[] = array(
'object' => 'window',
'event' => 'load',
'function' => 'PMA_TT_init',
);
foreach ($GLOBALS['js_include'] as $js_script_file) {
echo '<script src="./js/' . $js_script_file . '" type="text/javascript"></script>' . "\n";
}
?>
<script type="text/javascript">
// <![CDATA[
// Updates the title of the frameset if possible (ns4 does not allow this)
if (typeof(parent.document) != 'undefined' && typeof(parent.document) != 'unknown'
&& typeof(parent.document.title) == 'string') {
parent.document.title = '<?php echo PMA_sanitize(PMA_escapeJsString($title)); ?>';
}
var PMA_messages = new Array();
<?php
foreach ($js_messages as $name => $js_message) {
echo "PMA_messages['" . $name . "'] = '" . PMA_escapeJsString($js_message) . "';\n";
}
foreach ($js_events as $js_event) {
echo "window.parent.addEvent(" . $js_event['object'] . ", '" . $js_event['event'] . "', "
. $js_event['function'] . ");\n";
}
?>
// ]]>
</script>
<?php
// Reloads the navigation frame via JavaScript if required
PMA_reloadNavigation();
?>

View File

@@ -163,74 +163,37 @@ if (! empty($show_query)) {
$sql_query = ''; $sql_query = '';
/** /**
* start HTML output * prepare JavaScript functionality
*/
$js_include[] = 'common.js';
$js_include[] = 'functions.js';
$js_include[] = 'querywindow.js';
if (PMA_isValid($_REQUEST['auto_commit'], 'identical', 'true')) {
$js_events[] = array(
'object' => 'window',
'event' => 'load',
'function' => 'PMA_queryAutoCommit',
);
}
if (PMA_isValid($_REQUEST['init'])) {
$js_events[] = array(
'object' => 'window',
'event' => 'load',
'function' => 'PMA_querywindowResize',
);
}
/**
* start HTTP/HTML output
*/ */
require_once './libraries/header_http.inc.php'; require_once './libraries/header_http.inc.php';
require_once './libraries/header_meta_style.inc.php'; require_once './libraries/header_meta_style.inc.php';
require_once './libraries/header_scripts.inc.php';
?> ?>
<script type="text/javascript">
//<![CDATA[
var PMA_messages = new Array();
PMA_messages['strFormEmpty'] = '<?php echo PMA_escapeJsString($GLOBALS['strFormEmpty']); ?>';
PMA_messages['strNotNumber'] = '<?php echo PMA_escapeJsString($GLOBALS['strNotNumber']); ?>';
PMA_messages['strNoDropDatabases'] = '<?php echo (!$is_superuser && !$GLOBALS['cfg']['AllowUserDropDatabase'])
? PMA_escapeJsString($GLOBALS['strNoDropDatabases']) : ''; ?>';
PMA_messages['strDoYouReally'] = '<?php echo $GLOBALS['cfg']['Confirm']
? PMA_escapeJsString($GLOBALS['strDoYouReally']) : ''; ?>';
function PMA_queryAutoCommit() {
document.getElementById('sqlqueryform').target = window.opener.frame_content.name;
document.getElementById('sqlqueryform').submit();
return;
}
function PMA_querywindowCommit(tab) {
document.getElementById('hiddenqueryform').querydisplay_tab.value = tab;
document.getElementById('hiddenqueryform').submit();
return false;
}
function PMA_querywindowResize() {
// for Gecko
if (typeof(self.sizeToContent) == 'function') {
self.sizeToContent();
//self.scrollbars.visible = false;
// give some more space ... to prevent 'fli(pp/ck)ing'
self.resizeBy(10, 50);
return;
}
// for IE, Opera
if (document.getElementById && typeof(document.getElementById('querywindowcontainer')) != 'undefined') {
// get content size
var newWidth = document.getElementById('querywindowcontainer').offsetWidth;
var newHeight = document.getElementById('querywindowcontainer').offsetHeight;
// set size to contentsize
// plus some offset for scrollbars, borders, statusbar, menus ...
self.resizeTo(newWidth + 45, newHeight + 75);
}
}
function PMA_querywindowInit()
{
<?php
if (PMA_isValid($_REQUEST['auto_commit'], 'identical', 'true')) {
echo 'PMA_queryAutoCommit();' . "\n";
}
if (PMA_isValid($_REQUEST['init'])) {
echo 'PMA_querywindowResize();' . "\n";
}
?>
}
//]]>
</script>
<script src="./js/functions.js" type="text/javascript"></script>
</head> </head>
<body id="bodyquerywindow" onload="PMA_querywindowInit();"> <body id="bodyquerywindow">
<div id="querywindowcontainer"> <div id="querywindowcontainer">
<?php <?php