function registerJSLibraryData()
{
$application = PKPApplication::getApplication();
// Instantiate the namespace
$output = '$.pkp = $.pkp || {};';
// Load data intended for general use by the app
$app_data = array('baseUrl' => $this->_request->getBaseUrl());
$output .= '$.pkp.app = ' . json_encode($app_data) . ';';
// Load exposed constants
$exposedConstants = $application->getExposedConstants();
if (!empty($exposedConstants)) {
$output .= '$.pkp.cons = ' . json_encode($exposedConstants) . ';';
}
// Load locale keys
$localeKeys = $application->getJSLocaleKeys();
if (!empty($localeKeys)) {
// Replace periods in the key name with underscores for better-
// formatted JS keys
$jsLocaleKeys = array();
foreach ($localeKeys as $key) {
$jsLocaleKeys[str_replace('.', '_', $key)] = __($key);
}
$output .= '$.pkp.locale = ' . json_encode($jsLocaleKeys) . ';';
}
// Allow plugins to load data within their own namespace
$plugin_data = array();
HookRegistry::call('TemplateManager::registerJSLibraryData', array(&$plugin_data));
if (!empty($plugin_data) && is_array($plugin_data)) {
$output .= '$.pkp.plugins = {};';
foreach ($plugin_data as $namespace => $data) {
$output .= $namespace . ' = ' . json_encode($data) . ';';
}
}
$this->addJavaScript('pkpLibData', $output, array('priority' => STYLE_SEQUENCE_CORE, 'contexts' => 'backend', 'inline' => true));
}