Move optional parameters into single $opts parameter.
Add parameter to load definitions at top of stack.
/**
* Add inline javascript variable definitions to the output buffer.
*
- * @param array $data Keys are the variable names, values are the data
- * to JSON encode. If the key begins with a '-', the
- * data will be added to the output as-is.
- * @param boolean $ret If true, will return the list of variable
- * definitions instead of outputting to page.
- * @param string $onload Wrap the definition in an onload handler?
- * Either 'dom' (on dom:loaded), 'load'.
- */
- static public function addInlineJsVars($data, $ret = false, $onload = null)
+ * @param array $data Keys are the variable names, values are the data
+ * to JSON encode. If the key begins with a '-',
+ * the data will be added to the output as-is.
+ * @param array $opts Options:
+ * <pre>
+ * onload - (string) Wrap the definition in an onload handler? Either
+ * 'dom' (on dom:loaded), 'load'.
+ * DEFAULT: false
+ * ret_vars - (boolean) If true, will return the list of variable
+ * definitions instead of outputting to page.
+ * DEFAULT: false
+ * top - (boolean) Add definitions to top of stack?
+ * DEFAULT: false
+ * </pre>
+ *
+ * @return array Returns the variable list of 'ret_vars' option is true.
+ */
+ static public function addInlineJsVars($data, array $opts = array())
{
$out = array();
+ $opts = array_merge(array(
+ 'onload' => null,
+ 'ret_vars' => false,
+ 'top' => false
+ ), $opts);
foreach ($data as $key => $val) {
if ($key[0] == '-') {
$out[] = $key . '=' . $val;
}
- if ($ret) {
+ if ($opts['ret_vars']) {
return $out;
- } else {
- self::addInlineScript($out, $onload);
}
+
+ self::addInlineScript($out, $opts['onload'], $opts['top']);
}
/**
if (($file == 'popup.js') && ($app == 'horde')) {
Horde::addInlineJsVars(array(
'Horde.popup_block_text' => Horde_Core_Translation::t("A popup window could not be opened. Your browser may be blocking popups.")
- ), 'dom');
+ ), array('onload' => 'dom'));
}
if ($file[0] == '/') {
'if (!window.IMP) window.IMP = {}'
), Horde::addInlineJsVars(array(
'IMP.ac_list' => $addrlist
- ), true)));
+ ), array('ret_vars' => true))));
self::$_listOutput = true;
}
return Horde::addInlineJsVars(array(
'IMP_Compose_Base.identities' => $identities
- ), true);
+ ), array('ret_vars' => true));
}
/**
}
$result['js'] = array_merge($result['js'], Horde::addInlineJsVars(array(
'DIMP.conf_compose.flist' => $flist
- ), true));
+ ), array('ret_vars' => true)));
}
$compose_link = Horde::getServiceLink('ajax', 'imp');
} else {
$result['js'] = array_merge($result['js'], Horde::addInlineJsVars(array(
'-DIMP.conf_compose.redirect' => 1
- ), true));
+ ), array('ret_vars' => true)));
}
$t->set('bcc', $prefs->getValue('compose_bcc'));
$js_vars['DimpFullmessage.' . $val] = $show_msg_result[$val];
}
}
-$js_out = Horde::addInlineJsVars($js_vars, true);
+$js_out = Horde::addInlineJsVars($js_vars, array('ret_vars' => true));
/* Determine if compose mode is disabled. */
$disable_compose = !IMP::canCompose();
'or' => _("OR"),
'search_term' => _("Search Term:")
)
-)), false, 'dom');
+)), array('onload' => 'dom'));
if ($dimp_view) {
if (!$vars->edit_query) {
}
}
-Horde::addInlineScript(array(
- 'var DIMP = ' . Horde_Serialize::serialize($code, Horde_Serialize::JSON, 'UTF-8')
-), null, true);
+Horde::addInlineJsVars(array(
+ 'var DIMP' => $code
+), array('top' => true));
)
);
-Horde::addInlineScript(array(
- 'var IMP = ' . Horde_Serialize::serialize($code, Horde_Serialize::JSON, 'UTF-8')
-), null, true);
+Horde::addInlineJsVars(array(
+ 'var IMP' => $code
+), array('top' => true));
{
if ($GLOBALS['registry']->hasMethod('mail/createFolder')) {
Horde::addScriptFile('new_folder.js', 'ingo');
- Horde::addInlineScript(array(
- 'IngoNewFolder.folderprompt = ' . Horde_Serialize::serialize(_("Please enter the name of the new folder:"), Horde_Serialize::JSON)
+ Horde::addInlineJsVars(array(
+ 'IngoNewFolder.folderprompt' => _("Please enter the name of the new folder:")
));
}
}
// Maps
$code['conf']['maps'] = $GLOBALS['conf']['maps'];
- return array('var Kronolith = ' . Horde_Serialize::serialize($code, Horde_Serialize::JSON) . ';');
+ return Horde::addInlineJsVars(array(
+ 'var Kronolith' => $code
+ ), array('ret_vars' => true));
}
/**
'loading' => _("Loading ..."),
);
-?>
-<script type="text/javascript">//<![CDATA[
-var KronolithDate = new Date(<?php printf('%d, %d, %d', $currentDate->year, $currentDate->month - 1, $currentDate->mday) ?>);
-var KronolithText = <?php echo Horde_Serialize::serialize($gettext, Horde_Serialize::JSON) ?>;
-var KronolithVar = <?php echo Horde_Serialize::serialize($var, Horde_Serialize::JSON) ?>;
-var KronolithView = '<?php if (isset($view) && is_object($view)) echo $view->getName() ?>';
-//]]></script>
+Horde::addInlineJsVars(array(
+ '-var KronolithDate' => 'new Date(' . sprintf('%d, %d, %d', $currentDate->year, $currentDate->month - 1, $currentDate->mday) . ')',
+ 'var KronolithText' => $gettext,
+ 'var KronolithVar' => $var,
+ 'var KronolithView' => (isset($view) && is_object($view)) ? $view->getName() : ''
+), array('top' => true));