mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-25 16:19:00 +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 '
|
||||
<div id="container"></div>
|
||||
<script>
|
||||
egw.langRequire(window, '.json_encode($langRequire).');
|
||||
egw(window).includeJS('.json_encode(egw_framework::get_script_links(true, true)). // return and clear
|
||||
',function() {
|
||||
egw.debug("info", "Instanciating etemplate2 object for '.$this->name.'");
|
||||
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);
|
||||
// Wait for all files to be loaded & executed first
|
||||
egw.LAB.wait(function() {
|
||||
egw.langRequire(window, '.json_encode($langRequire).');
|
||||
egw(window).includeJS('.json_encode(egw_framework::get_script_links(true, true)). // return and clear
|
||||
',function() {
|
||||
egw.debug("info", "Instanciating etemplate2 object for '.$this->name.'");
|
||||
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>
|
||||
';
|
||||
}
|
||||
@ -195,11 +198,14 @@ class etemplate_new extends etemplate_widget_template
|
||||
echo '
|
||||
<div id="container"></div>
|
||||
<script>
|
||||
egw.langRequire(window, '.json_encode($langRequire).');
|
||||
egw(window).ready(function() {
|
||||
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);
|
||||
// Wait for all files to be loaded & executed first
|
||||
egw.LAB.wait(function() {
|
||||
egw.langRequire(window, '.json_encode($langRequire).');
|
||||
egw(window).ready(function() {
|
||||
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>
|
||||
';
|
||||
}
|
||||
|
@ -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'];
|
||||
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>';
|
||||
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 '
|
||||
<div id="egwpopup" style="display: none; z-index: 999;">
|
||||
<div id="egwpopup_header">'.lang('Notification'). '<span style="float:right;">'.
|
||||
|
@ -89,7 +89,9 @@ abstract class egw_framework
|
||||
public static function init_static()
|
||||
{
|
||||
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
|
||||
'/phpgwapi/js/jquery/jquery.js',
|
||||
'/phpgwapi/js/./egw_json.js',
|
||||
@ -867,17 +869,26 @@ abstract class egw_framework
|
||||
}
|
||||
</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!)
|
||||
if ($GLOBALS['egw_info']['flags']['js_link_registry'])
|
||||
{
|
||||
$java_script .= '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_preferences('.json_encode($GLOBALS['egw_info']['user']['preferences']['common']).', "common");'."\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']))
|
||||
{
|
||||
@ -890,8 +901,15 @@ abstract class egw_framework
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1308,12 +1326,14 @@ abstract class egw_framework
|
||||
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!
|
||||
/*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">
|
||||
$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();
|
||||
</script>
|
||||
';*/
|
||||
';
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -295,7 +295,7 @@ class html
|
||||
if($enhanced) {
|
||||
egw_framework::validate_file('/phpgwapi/js/jquery/chosen/chosen.jquery.js');
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user