mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-26 00:29:38 +01:00
Use LABjs throughout framework to load javascript - prevents a lot of undefined / timing errors
This commit is contained in:
parent
1c076aa97b
commit
ef2a5d377d
@ -180,13 +180,16 @@ class etemplate_new extends etemplate_widget_template
|
|||||||
echo '
|
echo '
|
||||||
<div id="container"></div>
|
<div id="container"></div>
|
||||||
<script>
|
<script>
|
||||||
egw.langRequire(window, '.json_encode($langRequire).');
|
// Wait for all files to be loaded & executed first
|
||||||
egw(window).includeJS('.json_encode(egw_framework::get_script_links(true, true)). // return and clear
|
egw.LAB.wait(function() {
|
||||||
',function() {
|
egw.langRequire(window, '.json_encode($langRequire).');
|
||||||
egw.debug("info", "Instanciating etemplate2 object for '.$this->name.'");
|
egw(window).includeJS('.json_encode(egw_framework::get_script_links(true, true)). // return and clear
|
||||||
var et2 = new etemplate2(document.getElementById("container"), "etemplate::ajax_process_content");
|
',function() {
|
||||||
et2.load("'.$this->name.'","'.$GLOBALS['egw_info']['server']['webserver_url'].$this->rel_path.'",'.json_encode($data).');
|
egw.debug("info", "Instanciating etemplate2 object for '.$this->name.'");
|
||||||
}, window, egw.webserverUrl);
|
var et2 = new etemplate2(document.getElementById("container"), "etemplate::ajax_process_content");
|
||||||
|
et2.load("'.$this->name.'","'.$GLOBALS['egw_info']['server']['webserver_url'].$this->rel_path.'",'.json_encode($data).');
|
||||||
|
}, window, egw.webserverUrl);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
';
|
';
|
||||||
}
|
}
|
||||||
@ -195,11 +198,14 @@ class etemplate_new extends etemplate_widget_template
|
|||||||
echo '
|
echo '
|
||||||
<div id="container"></div>
|
<div id="container"></div>
|
||||||
<script>
|
<script>
|
||||||
egw.langRequire(window, '.json_encode($langRequire).');
|
// Wait for all files to be loaded & executed first
|
||||||
egw(window).ready(function() {
|
egw.LAB.wait(function() {
|
||||||
var et2 = new etemplate2(document.getElementById("container"), "etemplate::ajax_process_content");
|
egw.langRequire(window, '.json_encode($langRequire).');
|
||||||
et2.load("'.$this->name.'","'.$GLOBALS['egw_info']['server']['webserver_url'].$this->rel_path.'",'.json_encode($data).');
|
egw(window).ready(function() {
|
||||||
}, null, true);
|
var et2 = new etemplate2(document.getElementById("container"), "etemplate::ajax_process_content");
|
||||||
|
et2.load("'.$this->name.'","'.$GLOBALS['egw_info']['server']['webserver_url'].$this->rel_path.'",'.json_encode($data).');
|
||||||
|
}, null, true);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
';
|
';
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ if ($GLOBALS['egw_info']['user']['apps']['notifications'])
|
|||||||
$popup_poll_interval = empty($notification_config['popup_poll_interval']) ? 60 : $notification_config['popup_poll_interval'];
|
$popup_poll_interval = empty($notification_config['popup_poll_interval']) ? 60 : $notification_config['popup_poll_interval'];
|
||||||
echo '<script src="'. $GLOBALS['egw_info']['server']['webserver_url']. '/notifications/js/notificationajaxpopup.js?'.
|
echo '<script src="'. $GLOBALS['egw_info']['server']['webserver_url']. '/notifications/js/notificationajaxpopup.js?'.
|
||||||
filemtime(EGW_SERVER_ROOT.'/notifications/js/notificationajaxpopup.js'). '" type="text/javascript"></script>';
|
filemtime(EGW_SERVER_ROOT.'/notifications/js/notificationajaxpopup.js'). '" type="text/javascript"></script>';
|
||||||
echo '<script type="text/javascript">egwpopup_init("'.$popup_poll_interval.'");</script>';
|
echo '<script type="text/javascript">var lab = egw.LAB || $LAB; lab.wait(function(){egwpopup_init("'.$popup_poll_interval.'");});</script>';
|
||||||
echo '
|
echo '
|
||||||
<div id="egwpopup" style="display: none; z-index: 999;">
|
<div id="egwpopup" style="display: none; z-index: 999;">
|
||||||
<div id="egwpopup_header">'.lang('Notification'). '<span style="float:right;">'.
|
<div id="egwpopup_header">'.lang('Notification'). '<span style="float:right;">'.
|
||||||
|
@ -89,7 +89,9 @@ abstract class egw_framework
|
|||||||
public static function init_static()
|
public static function init_static()
|
||||||
{
|
{
|
||||||
self::$js_include_mgr = new egw_include_mgr(array(
|
self::$js_include_mgr = new egw_include_mgr(array(
|
||||||
'/phpgwapi/js/labjs/LAB.src.js',
|
// We need LABjs, but putting it through egw_include_mgr causes it to re-load itself
|
||||||
|
//'/phpgwapi/js/labjs/LAB.src.js',
|
||||||
|
|
||||||
// allways load jquery (not -ui) and egw_json first
|
// allways load jquery (not -ui) and egw_json first
|
||||||
'/phpgwapi/js/jquery/jquery.js',
|
'/phpgwapi/js/jquery/jquery.js',
|
||||||
'/phpgwapi/js/./egw_json.js',
|
'/phpgwapi/js/./egw_json.js',
|
||||||
@ -867,17 +869,26 @@ abstract class egw_framework
|
|||||||
}
|
}
|
||||||
</script>";
|
</script>";
|
||||||
|
|
||||||
$java_script .= self::get_script_links();
|
$to_include = self::get_script_links(true);
|
||||||
|
|
||||||
$java_script .= '<script type="text/javascript">window.egw_appName = "'.$GLOBALS['egw_info']['flags']['currentapp'].'";'."\n";
|
// Use LABjs to execute this stuff after all the script links are loaded
|
||||||
|
$after = 'window.egw_appName = "'.$GLOBALS['egw_info']['flags']['currentapp'].'";'."\n";
|
||||||
|
|
||||||
// add link registry to non-popup windows, if explicit requested (idots_framework::navbar() loads it, if not explicit specified!)
|
// add link registry to non-popup windows, if explicit requested (idots_framework::navbar() loads it, if not explicit specified!)
|
||||||
if ($GLOBALS['egw_info']['flags']['js_link_registry'])
|
if ($GLOBALS['egw_info']['flags']['js_link_registry'])
|
||||||
{
|
{
|
||||||
$java_script .= 'egw.set_preferences('.json_encode($GLOBALS['egw_info']['user']['preferences']['common']).', "common");'."\n";
|
$after .= 'egw.set_preferences('.json_encode($GLOBALS['egw_info']['user']['preferences']['common']).', "common");'."\n";
|
||||||
$java_script .= 'egw.set_user('.$GLOBALS['egw']->accounts->json($GLOBALS['egw_info']['user']['account_id']).');'."\n";
|
$after .= 'egw.set_user('.$GLOBALS['egw']->accounts->json($GLOBALS['egw_info']['user']['account_id']).');'."\n";
|
||||||
}
|
}
|
||||||
$java_script .= "</script>\n";
|
|
||||||
|
// Load LABjs ONCE here
|
||||||
|
$java_script .= '<script type="text/javascript" src="'. $GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/js/labjs/LAB.src.js"'." ></script>\n".
|
||||||
|
'<script type="text/javascript">
|
||||||
|
// Loads files in parallel, executes serially
|
||||||
|
window.egw.LAB = $LAB.setOptions({AlwaysPreserveOrder:true,BasePath:"'.$GLOBALS['egw_info']['server']['webserver_url'].'/"});
|
||||||
|
window.egw.LAB.script(
|
||||||
|
'.json_encode(array_map(function($str){return substr($str,1);}, $to_include, array(1))).').wait(function() {'."\n".$after.'});
|
||||||
|
</script>';
|
||||||
|
|
||||||
if(@isset($_GET['menuaction']))
|
if(@isset($_GET['menuaction']))
|
||||||
{
|
{
|
||||||
@ -890,8 +901,15 @@ abstract class egw_framework
|
|||||||
}
|
}
|
||||||
if (isset($GLOBALS['egw_info']['flags']['java_script']))
|
if (isset($GLOBALS['egw_info']['flags']['java_script']))
|
||||||
{
|
{
|
||||||
$java_script .= $GLOBALS['egw_info']['flags']['java_script'] . "\n";
|
// Strip out any script tags, this needs to be executed as anonymous function
|
||||||
|
$GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]+>)([^<]*)/is','/<\/script>/'),array('$2',''),$GLOBALS['egw_info']['flags']['java_script']);
|
||||||
|
if(trim($GLOBALS['egw_info']['flags']['java_script']) != '')
|
||||||
|
{
|
||||||
|
$java_script .= '<script type="text/javascript">window.egw.LAB.wait(function() {'.$GLOBALS['egw_info']['flags']['java_script'] . "});</script>\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return $java_script;
|
return $java_script;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1308,12 +1326,14 @@ abstract class egw_framework
|
|||||||
return "\n".$start.implode($end.$start, $to_include).$end;
|
return "\n".$start.implode($end.$start, $to_include).$end;
|
||||||
|
|
||||||
// using LABjs to load all javascript would require all other script-tags to run in wait() of queue!
|
// using LABjs to load all javascript would require all other script-tags to run in wait() of queue!
|
||||||
/*return "\n".$start.'/phpgwapi/js/labjs/LAB.src.js'.$end."\n".
|
/*
|
||||||
|
return "\n".$start.'/phpgwapi/js/labjs/LAB.src.js'.$end."\n".
|
||||||
'<script type="text/javascript">
|
'<script type="text/javascript">
|
||||||
$LAB.setOptions({AlwaysPreserveOrder:true,BasePath:"'.$GLOBALS['egw_info']['server']['webserver_url'].'/"}).script(
|
$LAB.setOptions({AlwaysPreserveOrder:true,BasePath:"'.$GLOBALS['egw_info']['server']['webserver_url'].'/"}).script(
|
||||||
'.json_encode(array_map(function($str){return substr($str,1);}, $to_include, array(1))).').wait();
|
'.json_encode(array_map(function($str){return substr($str,1);}, $to_include, array(1))).').wait();
|
||||||
</script>
|
</script>
|
||||||
';*/
|
';
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -295,7 +295,7 @@ class html
|
|||||||
if($enhanced) {
|
if($enhanced) {
|
||||||
egw_framework::validate_file('/phpgwapi/js/jquery/chosen/chosen.jquery.js');
|
egw_framework::validate_file('/phpgwapi/js/jquery/chosen/chosen.jquery.js');
|
||||||
egw_framework::includeCSS('/phpgwapi/js/jquery/chosen/chosen.css',null,false);
|
egw_framework::includeCSS('/phpgwapi/js/jquery/chosen/chosen.css',null,false);
|
||||||
$out .= "<script>\$j(function() {if(\$j().chosen) \$j('select[name=\"$name\"]').chosen();});</script>\n";
|
$out .= "<script>var lab = egw.LAB || \$LAB; lab.wait(function() {\$j(function() {if(\$j().chosen) \$j('select[name=\"$name\"]').chosen();});})</script>\n";
|
||||||
}
|
}
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user