diff --git a/api/src/Framework.php b/api/src/Framework.php index b32b90d129..86ee675e61 100644 --- a/api/src/Framework.php +++ b/api/src/Framework.php @@ -359,6 +359,40 @@ abstract class Framework extends Framework\Extra return $var; } + /** + * Body tags for onLoad, onUnload and onResize + * + * @deprecated since 14.1 use app.js et2_ready method instead to execute code or bind a handler (CSP will stop onXXX attributes!) + * @var array + */ + protected static $body_tags = array(); + + /** + * Adds on(Un)Load= attributes to the body tag of a page + * + * Can only be set via egw_framework::set_on* methods. + * + * @deprecated since 14.1 use app.js et2_ready method instead to execute code or bind a handler (CSP will stop onXXX attributes!) + * @returns string the attributes to be used + */ + static public function _get_body_attribs() + { + $js = ''; + foreach(self::$body_tags as $what => $data) + { + if (!empty($data)) + { + if($what == 'onLoad') + { + $js .= 'onLoad="egw_LAB.wait(function() {'. htmlspecialchars($data).'})"'; + continue; + } + $js .= ' '.$what.'="' . htmlspecialchars($data) . '"'; + } + } + return $js; + } + /** * Get header as array to eg. set as vars for a template (from idots' head.inc.php) * @@ -419,6 +453,7 @@ abstract class Framework extends Framework\Extra 'lang_code' => $lang_code, 'charset' => Translation::charset(), 'website_title' => $site_title, + 'body_tags' => self::_get_body_attribs(), 'java_script' => self::_get_js($extra), 'meta_robots' => $robots, 'dir_code' => lang('language_direction_rtl') != 'rtl' ? '' : ' dir="rtl"', diff --git a/phpgwapi/inc/class.egw_framework.inc.php b/phpgwapi/inc/class.egw_framework.inc.php index 3e617db13a..ab1deb8462 100644 --- a/phpgwapi/inc/class.egw_framework.inc.php +++ b/phpgwapi/inc/class.egw_framework.inc.php @@ -120,7 +120,15 @@ abstract class egw_framework extends Api\Framework */ static function set_onload($code='',$replace=false) { - unset($code, $replace); + if ($replace || empty(self::$body_tags['onLoad'])) + { + self::$body_tags['onLoad'] = $code; + } + else + { + self::$body_tags['onLoad'] .= $code; + } + return self::$body_tags['onLoad']; } /** @@ -133,7 +141,15 @@ abstract class egw_framework extends Api\Framework */ static function set_onunload($code='',$replace=false) { - unset($code, $replace); + if ($replace || empty(self::$body_tags['onUnload'])) + { + self::$body_tags['onUnload'] = $code; + } + else + { + self::$body_tags['onUnload'] .= $code; + } + return self::$body_tags['onUnload']; } /** @@ -146,7 +162,15 @@ abstract class egw_framework extends Api\Framework */ static function set_onbeforeunload($code='',$replace=false) { - unset($code, $replace); + if ($replace || empty(self::$body_tags['onBeforeUnload'])) + { + self::$body_tags['onBeforeUnload'] = $code; + } + else + { + self::$body_tags['onBeforeUnload'] .= $code; + } + return self::$body_tags['onBeforeUnload']; } /** @@ -159,7 +183,15 @@ abstract class egw_framework extends Api\Framework */ static function set_onresize($code='',$replace=false) { - unset($code, $replace); + if ($replace || empty(self::$body_tags['onResize'])) + { + self::$body_tags['onResize'] = $code; + } + else + { + self::$body_tags['onResize'] .= $code; + } + return self::$body_tags['onResize']; } /**