PKPTemplateManager::registerJSLibraryData PHP Method

registerJSLibraryData() public method

This function registers script data that is required by the core JS library. This data is queued after jQuery but before the pkp-lib framework, allowing dynamic data to be passed to the framework. It is intended to be used for passing constants and locale strings, but plugins may also take advantage of a hook to include data required by their own scripts, when integrating with the pkp-lib framework.
    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));
    }