function registerJSLibrary()
{
$basePath = $this->_request->getBasePath();
$baseUrl = $this->_request->getBaseUrl();
$localeChecks = array(AppLocale::getLocale(), strtolower(substr(AppLocale::getLocale(), 0, 2)));
// Common $args array used for all our core JS files
$args = array('priority' => STYLE_SEQUENCE_CORE, 'contexts' => 'backend');
// Load jQuery validate separately because it can not be linted
// properly by our build script
$this->addJavaScript('jqueryValidate', $baseUrl . '/lib/pkp/js/lib/jquery/plugins/validate/jquery.validate.min.js', $args);
$localePath = '/lib/pkp/js/lib/jquery/plugins/validate/localization/messages_';
foreach ($localeChecks as $localeCheck) {
if (file_exists($basePath . $localePath . $localeCheck . '.js')) {
$this->addJavaScript('jqueryValidateLocale', $baseUrl . $localePath . $localeCheck . '.js', $args);
}
}
$this->addJavaScript('plUpload', $baseUrl . '/lib/pkp/lib/vendor/moxiecode/plupload/js/plupload.full.min.js', $args);
$this->addJavaScript('jQueryPlUpload', $baseUrl . '/lib/pkp/lib/vendor/moxiecode/plupload/js/jquery.ui.plupload/jquery.ui.plupload.js', $args);
$localePath = '/lib/pkp/lib/vendor/moxiecode/plupload/js/i18n/';
foreach ($localeChecks as $localeCheck) {
if (file_exists($basePath . $localePath . $localeCheck . '.js')) {
$this->addJavaScript('plUploadLocale', $baseUrl . $localePath . $localeCheck . '.js.', $args);
}
}
$this->addJavaScript('pNotify', $baseUrl . '/lib/pkp/js/lib/pnotify/pnotify.core.js', $args);
$this->addJavaScript('pNotifyButtons', $baseUrl . '/lib/pkp/js/lib/pnotify/pnotify.buttons.js', $args);
// Load minified file if it exists
if (Config::getVar('general', 'enable_minified')) {
$path = $basePath . '/js/pkp.min.js';
if (file_exists($path)) {
$this->addJavaScript('pkpLib', $path, array('priority' => STYLE_SEQUENCE_CORE, 'contexts' => array('backend', 'frontend')));
return;
}
}
// Otherwise retrieve and register all script files
$minifiedScripts = array_filter(array_map('trim', file('registry/minifiedScripts.txt')), function ($s) {
return strlen($s) && $s[0] != '#';
// Exclude empty and commented (#) lines
});
foreach ($minifiedScripts as $key => $script) {
$this->addJavaScript('pkpLib' . $key, "{$baseUrl}/{$script}", $args);
}
}