function loadJavascript($contexts)
{
$request = Application::getRequest();
$templateMgr = TemplateManager::getManager($request);
// Register Chart.js on the frontend article view
$templateMgr->addJavaScript('chartJS', 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.0.1/Chart.js', array('contexts' => $contexts));
// Add locale and configuration data
$script_data = 'var pkpUsageStats = pkpUsageStats || {};';
$script_data .= 'pkpUsageStats.locale = pkpUsageStats.locale || {};';
$script_data .= 'pkpUsageStats.locale.months = ' . json_encode(explode(' ', __('plugins.generic.usageStats.monthInitials'))) . ';';
$script_data .= 'pkpUsageStats.config = pkpUsageStats.config || {};';
$script_data .= 'pkpUsageStats.config.chartType = ' . json_encode($this->getSetting(CONTEXT_ID_NONE, 'chartType')) . ';';
$templateMgr->addJavaScript('pkpUsageStatsConfig', $script_data, array('inline' => true, 'contexts' => $contexts));
// Register the JS which initializes the chart
$baseImportPath = Request::getBaseUrl() . DIRECTORY_SEPARATOR . PKP_LIB_PATH . DIRECTORY_SEPARATOR . $this->getPluginPath() . DIRECTORY_SEPARATOR;
$templateMgr->addJavaScript('usageStatsFrontend', $baseImportPath . 'js/UsageStatsFrontendHandler.js', array('contexts' => $contexts));
}