/** * Implements hook_js_alter(). */ function radix_js_alter(&$javascript) { // Add radix-modal when required. $ctools_modal = drupal_get_path('module', 'ctools') . '/js/modal.js'; $radix_modal = drupal_get_path('theme', 'radix') . '/assets/javascripts/radix-modal.js'; if (!empty($javascript[$ctools_modal]) && empty($javascript[$radix_modal])) { $javascript[$radix_modal] = array_merge( drupal_js_defaults(), array('group' => JS_THEME, 'data' => $radix_modal)); } // Add radix-field-slideshow when required. $field_slideshow = drupal_get_path('module', 'field_slideshow') . '/field_slideshow.js'; $radix_field_slideshow = drupal_get_path('theme', 'radix') . '/assets/javascripts/radix-field-slideshow.js'; if (!empty($javascript[$field_slideshow]) && empty($javascript[$radix_field_slideshow])) { $javascript[$radix_field_slideshow] = array_merge( drupal_js_defaults(), array('group' => JS_THEME, 'data' => $radix_field_slideshow)); } // Add radix-progress when required. $progress = 'misc/progress.js'; $radix_progress = drupal_get_path('theme', 'radix') . '/assets/javascripts/radix-progress.js'; if (!empty($javascript[$progress]) && empty($javascript[$radix_progress])) { $javascript[$radix_progress] = array_merge( drupal_js_defaults(), array('group' => JS_THEME, 'data' => $radix_progress)); } }
/** * Implements hook_js_alter(). */ function clackamas_js_alter(&$js) { // Only add offcanvas.js if it's actually being used on the page. // Determin this by checking to see if navbar-offcanvas is being added. $path = drupal_get_path('theme', 'clackamas') . '/jansy-bootstrap/js/offcanvas.js'; if (!empty($js[drupal_get_path('module', 'cpagardens_widgets') . '/js/navbar-offcanvas.js'])) { $js[$path] = array_merge(drupal_js_defaults(), array('group' => JS_DEFAULT, 'scope' => 'footer', 'data' => $path)); } }
/** * Implements hook_js_alter(). * * Borrowed from Radix :) * */ function kalatheme_js_alter(&$javascript) { // Add kalatheme-modal only when required. $ctools_modal = drupal_get_path('module', 'ctools') . '/js/modal.js'; $kalatheme_modal = drupal_get_path('theme', 'kalatheme') . '/js/kalatheme-modal.js'; if (!empty($javascript[$ctools_modal]) && empty($javascript[$kalatheme_modal])) { $javascript[$kalatheme_modal] = array_merge(drupal_js_defaults(), array('group' => JS_THEME, 'data' => $kalatheme_modal)); } }
/** * Implements hook_js_alter(). */ function oa_radix_js_alter(&$javascript) { // Add oa-radix-modal when required. $ctools_modal = drupal_get_path('module', 'ctools') . '/js/modal.js'; $radix_modal = drupal_get_path('theme', 'radix') . '/assets/javascripts/radix-modal.js'; $oa_radix_modal = drupal_get_path('theme', 'oa_radix') . '/assets/javascripts/oa-radix-modal.js'; if ((!empty($javascript[$ctools_modal]) || !empty($javascript[$radix_modal])) && empty($javascript[$oa_radix_modal])) { unset($javascript[$radix_modal]); $javascript[$oa_radix_modal] = array_merge(drupal_js_defaults(), array('group' => JS_THEME, 'data' => $oa_radix_modal)); } }
/** * Implements hook_js_alter(). */ function bootstrap_agency_js_alter(&$js) { // This code is only ncessary because of [#2162165] // Always add bootstrap.js last. unset($js[drupal_get_path('theme', 'bootstrap') . '/js/bootstrap.js']); $theme_path = drupal_get_path('theme', 'bootstrap_agency'); $bootstrap = $theme_path . '/js/bootstrap.js'; $js[$bootstrap] = drupal_js_defaults($bootstrap); $js[$bootstrap]['group'] = JS_THEME; $js[$bootstrap]['scope'] = 'footer'; }
/** * Implements hook_js_alter(). * * Make sure the library files provided by MDB load last, then initialize. * * @see bootstrap_material_preprocess_html() */ function bootstrap_material_js_alter(&$js) { $file = path_to_theme() . '/js/bootstrap_material.js'; $js[$file] = drupal_js_defaults($file); $js[$file]['group'] = JS_BOOTSTRAP_MATERIAL; $js[$file]['scope'] = 'footer'; $js[$file]['weight'] = $weight = 0; // Ensure we initialize only after files are loaded. foreach ($js as $key => $val) { if (is_int($key) && $val['group'] == JS_BOOTSTRAP_MATERIAL) { $weight++; $js[$key]['weight'] = $weight; } } }
/** * Implements hook_js_alter(). */ function cignaglobal_js_alter(&$js) { $theme_path = drupal_get_path('theme', 'cignaglobal'); // JS to be exluded: not needed currently for anonymous users. $exclude_js = array('sites/all/modules/contrib/views/js/base.js', 'sites/all/modules/contrib/views/js/ajax_view.js', 'sites/all/themes/bootstrap/js/modules/views/js/ajax_view.js', 'sites/all/themes/bootstrap/js/misc/_progress.js', 'sites/all/themes/bootstrap/js/misc/ajax.js', 'sites/all/modules/contrib/jquery_update/replace/misc/jquery.form.min.js', 'sites/all/modules/contrib/jquery_update/replace/ui/external/jquery.cookie.js', 'sites/all/themes/bootstrap/js/bootstrap.js'); // Place all js in footer except mapbox and exclude unused from Bootstrap theme and Drupal core. foreach ($js as $key => $value) { $js[$key]['scope'] = strpos($key, 'mapbox.js') !== FALSE ? 'header' : 'footer'; if (in_array($key, $exclude_js)) { unset($js[$key]); } } // Visual Website Optimiser script. This must stay in the header to avoid flicker. $vwoScript = 'var _vwo_code=(function(){'; $vwoScript .= 'var account_id=77201,'; $vwoScript .= 'settings_tolerance=2000,'; $vwoScript .= 'library_tolerance=2500,'; $vwoScript .= 'use_existing_jquery=false,'; $vwoScript .= 'f=false,d=document;return{use_existing_jquery:function(){return use_existing_jquery;},library_tolerance:function(){return library_tolerance;},finish:function(){if(!f){f=true;var a=d.getElementById(\'_vis_opt_path_hides\');if(a)a.parentNode.removeChild(a);}},finished:function(){return f;},load:function(a){var b=d.createElement(\'script\');b.src=a;b.type=\'text/javascript\';b.innerText;b.onerror=function(){_vwo_code.finish();};d.getElementsByTagName(\'head\')[0].appendChild(b);},init:function(){settings_timer=setTimeout(\'_vwo_code.finish()\',settings_tolerance);this.load(\'//dev.visualwebsiteoptimizer.com/j.php?a=\'+account_id+\'&u=\'+encodeURIComponent(d.URL)+\'&r=\'+Math.random());var a=d.createElement(\'style\'),b=\'body{opacity:0 !important;filter:alpha(opacity=0) !important;background:none !important;}\',h=d.getElementsByTagName(\'head\')[0];a.setAttribute(\'id\',\'_vis_opt_path_hides\');a.setAttribute(\'type\',\'text/css\');if(a.styleSheet)a.styleSheet.cssText=b;else a.appendChild(d.createTextNode(b));h.appendChild(a);return settings_timer;}};}());_vwo_settings_timer=_vwo_code.init();'; $js['vwoTagScript'] = drupal_js_defaults(); $js['vwoTagScript']['data'] = $vwoScript; $js['vwoTagScript']['type'] = 'inline'; $js['vwoTagScript']['scope'] = 'header'; $js['vwoTagScript']['group'] = JS_THEME; $js['vwoTagScript']['every_page'] = TRUE; $js['vwoTagScript']['weight'] = 1; // Typkeit fonts script. This must stay in the header to load correctly $typekitScript = "(function(d) {"; $typekitScript .= "var config = {"; $typekitScript .= "kitId: 'djj7lex',"; $typekitScript .= "scriptTimeout: 3000,"; $typekitScript .= "async: true"; $typekitScript .= "},"; $typekitScript .= "h=d.documentElement,t=setTimeout(function(){h.className=h.className.replace(/\\bwf-loading\\b/g,\"\")+\" wf-inactive\";},config.scriptTimeout),tk=d.createElement(\"script\"),f=false,s=d.getElementsByTagName(\"script\")[0],a;h.className+=\" wf-loading\";tk.src='https://use.typekit.net/'+config.kitId+'.js';tk.async=true;tk.onload=tk.onreadystatechange=function(){a=this.readyState;if(f||a&&a!=\"complete\"&&a!=\"loaded\")return;f=true;clearTimeout(t);try{Typekit.load(config)}catch(e){}};s.parentNode.insertBefore(tk,s)"; $typekitScript .= "})(document);"; $js['TypekitScript'] = drupal_js_defaults(); $js['TypekitScript']['data'] = $typekitScript; $js['TypekitScript']['type'] = 'inline'; $js['TypekitScript']['scope'] = 'header'; $js['TypekitScript']['group'] = JS_THEME; $js['TypekitScript']['every_page'] = TRUE; $js['TypekitScript']['weight'] = 2; // A variable for assigning a weight to each js resource. $js_footer_weight = 999; // Temporary method of adding brand awareness landing javascript $landing_page_urls = function_exists('cigna_lp_menu_keys') ? cigna_lp_menu_keys() : array(); if (in_array(current_path(), $landing_page_urls)) { $wistiaEv1JS = '//fast.wistia.com/assets/external/E-v1.js'; $js[$wistiaEv1JS] = drupal_js_defaults(); $js[$wistiaEv1JS]['data'] = $wistiaEv1JS; $js[$wistiaEv1JS]['type'] = 'file'; $js[$wistiaEv1JS]['scope'] = 'footer'; $js[$wistiaEv1JS]['group'] = JS_THEME; $js[$wistiaEv1JS]['every_page'] = TRUE; $js[$wistiaEv1JS]['weight'] = $js_footer_weight; $cignaLandingJS = $theme_path . '/js/cignalanding.min.js'; $js[$cignaLandingJS] = drupal_js_defaults(); $js[$cignaLandingJS]['data'] = $cignaLandingJS; $js[$cignaLandingJS]['type'] = 'file'; $js[$cignaLandingJS]['scope'] = 'footer'; $js[$cignaLandingJS]['group'] = JS_THEME; $js[$cignaLandingJS]['every_page'] = TRUE; $js[$cignaLandingJS]['weight'] = ++$js_footer_weight; /*$wistiaPluginJS = $theme_path . '/js/plugin.js'; $js[$wistiaPluginJS] = drupal_js_defaults(); $js[$wistiaPluginJS]['data'] = $wistiaPluginJS; $js[$wistiaPluginJS]['type'] = 'file'; $js[$wistiaPluginJS]['scope'] = 'footer'; $js[$wistiaPluginJS]['group'] = JS_THEME; $js[$wistiaPluginJS]['every_page'] = TRUE; $js[$wistiaPluginJS]['weight'] = ++$js_footer_weight;*/ return; } // Language switch js. $languageSwithcJS = $theme_path . '/js/language.js'; $js[$languageSwithcJS] = drupal_js_defaults(); $js[$languageSwithcJS]['data'] = $languageSwithcJS; $js[$languageSwithcJS]['type'] = 'file'; $js[$languageSwithcJS]['scope'] = 'footer'; $js[$languageSwithcJS]['group'] = JS_THEME; $js[$languageSwithcJS]['every_page'] = TRUE; $js[$languageSwithcJS]['weight'] = ++$js_footer_weight; // Work out if on broker pages. $is_broker_page = is_broker_page(); // Determine which js is required. $cignaglobalJS = !$is_broker_page ? $theme_path . '/js/cignaglobal.min.js' : $theme_path . '/js/brokers.min.js'; $js[$cignaglobalJS] = drupal_js_defaults(); $js[$cignaglobalJS]['data'] = $cignaglobalJS; $js[$cignaglobalJS]['type'] = 'file'; $js[$cignaglobalJS]['scope'] = 'footer'; $js[$cignaglobalJS]['group'] = JS_THEME; $js[$cignaglobalJS]['every_page'] = TRUE; $js[$cignaglobalJS]['weight'] = ++$js_footer_weight; // Add affinity partner js. $affinityPartnerJS = $theme_path . '/js/affinityPartner.js'; $js[$affinityPartnerJS] = drupal_js_defaults(); $js[$affinityPartnerJS]['data'] = $affinityPartnerJS; $js[$affinityPartnerJS]['type'] = 'file'; $js[$affinityPartnerJS]['scope'] = 'footer'; $js[$affinityPartnerJS]['group'] = JS_THEME; $js[$affinityPartnerJS]['every_page'] = TRUE; $js[$affinityPartnerJS]['weight'] = ++$js_footer_weight; // Ubertag script. $uberScript = 'var ut_params = ut_params || [];ut_params.push("UT-238808730");'; $uberScript .= '(function() {var ut = document.createElement(\'script\'); ut.type = \'text/javascript\'; ut.async = true;'; $uberScript .= 'ut.src = (("https:" == document.location.protocol) ? "https://" : "http://") + \'app.ubertags.com/javascripts/ubertags.js\';'; $uberScript .= 'var script = document.getElementsByTagName(\'script\')[0]; script.parentNode.insertBefore(ut, script);})();'; $js['uberTagScript'] = drupal_js_defaults(); $js['uberTagScript']['data'] = $uberScript; $js['uberTagScript']['type'] = 'inline'; $js['uberTagScript']['scope'] = 'footer'; $js['uberTagScript']['group'] = JS_THEME; $js['uberTagScript']['every_page'] = TRUE; $js['uberTagScript']['weight'] = ++$js_footer_weight; }
/** * Implements hook_js_alter(). */ function color_glass_js_alter(&$js) { // Exclude specified JavaScript files from theme. $excludes = _bootstrap_get_theme_info(NULL, 'exclude][js'); $theme_path = drupal_get_path('theme', 'color_glass'); // Add or replace JavaScript files when matching paths are detected. // Replacement files must begin with '_', like '_node.js'. $files = _bootstrap_file_scan_directory($theme_path . '/js', '/\\.js$/'); foreach ($files as $file) { $path = str_replace($theme_path . '/js/', '', $file->uri); // Detect if this is a replacement file. $replace = FALSE; if (preg_match('/^[_]/', $file->filename)) { $replace = TRUE; $path = dirname($path) . '/' . preg_replace('/^[_]/', '', $file->filename); } $matches = array(); if (preg_match('/^modules\\/([^\\/]*)/', $path, $matches)) { if (!module_exists($matches[1])) { continue; } else { $path = str_replace('modules/' . $matches[1], drupal_get_path('module', $matches[1]), $path); } } // Path should always exist to either add or replace JavaScript file. if (!empty($js[$path])) { // Replace file. if ($replace) { $js[$file->uri] = $js[$path]; $js[$file->uri]['data'] = $file->uri; unset($js[$path]); } else { $js[$file->uri] = drupal_js_defaults($file->uri); $js[$file->uri]['group'] = JS_THEME; } } } // Ensure jQuery Once is always loaded. // @see https://drupal.org/node/2149561 if (empty($js['misc/jquery.once.js'])) { $jquery_once = drupal_get_library('system', 'jquery.once'); $js['misc/jquery.once.js'] = $jquery_once['js']['misc/jquery.once.js']; $js['misc/jquery.once.js'] += drupal_js_defaults('misc/jquery.once.js'); } // Always add bootstrap.js last. $bootstrap = $theme_path . '/js/bootstrap.js'; $js[$bootstrap] = drupal_js_defaults($bootstrap); $js[$bootstrap]['group'] = JS_THEME; $js[$bootstrap]['scope'] = 'footer'; if (!empty($excludes)) { $js = array_diff_key($js, drupal_map_assoc($excludes)); } // Add Bootstrap settings. $js['settings']['data'][]['bootstrap'] = array('anchorsFix' => _bootstrap_setting('anchors_fix'), 'anchorsSmoothScrolling' => _bootstrap_setting('anchors_smooth_scrolling'), 'formHasError' => (int) _bootstrap_setting('forms_has_error_value_toggle'), 'popoverEnabled' => _bootstrap_setting('popover_enabled'), 'popoverOptions' => array('animation' => (int) _bootstrap_setting('popover_animation'), 'html' => (int) _bootstrap_setting('popover_html'), 'placement' => _bootstrap_setting('popover_placement'), 'selector' => _bootstrap_setting('popover_selector'), 'trigger' => implode(' ', array_filter(array_values((array) _bootstrap_setting('popover_trigger')))), 'triggerAutoclose' => (int) _bootstrap_setting('popover_trigger_autoclose'), 'title' => _bootstrap_setting('popover_title'), 'content' => _bootstrap_setting('popover_content'), 'delay' => (int) _bootstrap_setting('popover_delay'), 'container' => _bootstrap_setting('popover_container')), 'tooltipEnabled' => _bootstrap_setting('tooltip_enabled'), 'tooltipOptions' => array('animation' => (int) _bootstrap_setting('tooltip_animation'), 'html' => (int) _bootstrap_setting('tooltip_html'), 'placement' => _bootstrap_setting('tooltip_placement'), 'selector' => _bootstrap_setting('tooltip_selector'), 'trigger' => implode(' ', array_filter(array_values((array) _bootstrap_setting('tooltip_trigger')))), 'delay' => (int) _bootstrap_setting('tooltip_delay'), 'container' => _bootstrap_setting('tooltip_container'))); if ($bscdn_js = _bootstrap_setting('bscdn_js')) { $cdn_weight = -99.98999999999999; $js[$bscdn_js] = drupal_js_defaults($bscdn_js); $js[$bscdn_js]['type'] = 'external'; $js[$bscdn_js]['every_page'] = TRUE; $js[$bscdn_js]['weight'] = $cdn_weight; } }
/** * Tests that new JavaScript and CSS files are lazy-loaded on an AJAX request. */ public function testLazyLoad() { $expected = array('setting_name' => 'ajax_forms_test_lazy_load_form_submit', 'setting_value' => 'executed', 'css' => drupal_get_path('module', 'system') . '/css/system.admin.css', 'js' => drupal_get_path('module', 'system') . '/system.js'); // CSS files are stored by basename, see _drupal_add_css(). $expected_css_basename = drupal_basename($expected['css']); // @todo D8: Add a drupal_css_defaults() helper function. $expected_css_html = drupal_get_css(array($expected_css_basename => array('type' => 'file', 'group' => CSS_AGGREGATE_DEFAULT, 'weight' => 0, 'every_page' => FALSE, 'media' => 'all', 'preprocess' => TRUE, 'data' => $expected['css'], 'browsers' => array('IE' => TRUE, '!IE' => TRUE))), TRUE); $expected_js_html = drupal_get_js('header', array($expected['js'] => drupal_js_defaults($expected['js'])), TRUE); // Get the base page. $this->drupalGet('ajax_forms_test_lazy_load_form'); $original_settings = $this->getDrupalSettings(); $original_css = $original_settings['ajaxPageState']['css']; $original_js = $original_settings['ajaxPageState']['js']; // Verify that the base page doesn't have the settings and files that are to // be lazy loaded as part of the next requests. $this->assertTrue(!isset($original_settings[$expected['setting_name']]), format_string('Page originally lacks the %setting, as expected.', array('%setting' => $expected['setting_name']))); $this->assertTrue(!isset($original_css[$expected['css']]), format_string('Page originally lacks the %css file, as expected.', array('%css' => $expected['css']))); $this->assertTrue(!isset($original_js[$expected['js']]), format_string('Page originally lacks the %js file, as expected.', array('%js' => $expected['js']))); // Submit the AJAX request without triggering files getting added. $commands = $this->drupalPostAjaxForm(NULL, array('add_files' => FALSE), array('op' => t('Submit'))); $new_settings = $this->getDrupalSettings(); $new_css = $new_settings['ajaxPageState']['css']; $new_js = $new_settings['ajaxPageState']['js']; // Verify the setting was not added when not expected. $this->assertTrue(!isset($new_settings[$expected['setting_name']]), format_string('Page still lacks the %setting, as expected.', array('%setting' => $expected['setting_name']))); $this->assertTrue(!isset($new_css[$expected['css']]), format_string('Page still lacks the %css file, as expected.', array('%css' => $expected['css']))); $this->assertTrue(!isset($new_js[$expected['js']]), format_string('Page still lacks the %js file, as expected.', array('%js' => $expected['js']))); // Verify a settings command does not add CSS or scripts to drupalSettings // and no command inserts the corresponding tags on the page. $found_settings_command = FALSE; $found_markup_command = FALSE; foreach ($commands as $command) { if ($command['command'] == 'settings' && (array_key_exists('css', $command['settings']['ajaxPageState']) || array_key_exists('js', $command['settings']['ajaxPageState']))) { $found_settings_command = TRUE; } if (isset($command['data']) && ($command['data'] == $expected_js_html || $command['data'] == $expected_css_html)) { $found_markup_command = TRUE; } } $this->assertFalse($found_settings_command, format_string('Page state still lacks the %css and %js files, as expected.', array('%css' => $expected['css'], '%js' => $expected['js']))); $this->assertFalse($found_markup_command, format_string('Page still lacks the %css and %js files, as expected.', array('%css' => $expected['css'], '%js' => $expected['js']))); // Submit the AJAX request and trigger adding files. $commands = $this->drupalPostAjaxForm(NULL, array('add_files' => TRUE), array('op' => t('Submit'))); $new_settings = $this->getDrupalSettings(); $new_css = $new_settings['ajaxPageState']['css']; $new_js = $new_settings['ajaxPageState']['js']; // Verify the expected setting was added, both to drupalSettings, and as // the first AJAX command. $this->assertIdentical($new_settings[$expected['setting_name']], $expected['setting_value'], format_string('Page now has the %setting.', array('%setting' => $expected['setting_name']))); $expected_command = new SettingsCommand(array($expected['setting_name'] => $expected['setting_value']), TRUE); $this->assertCommand(array_slice($commands, 0, 1), $expected_command->render(), format_string('The settings command was first.')); // Verify the expected CSS file was added, both to drupalSettings, and as // the second AJAX command for inclusion into the HTML. $this->assertEqual($new_css, $original_css + array($expected_css_basename => 1), format_string('Page state now has the %css file.', array('%css' => $expected['css']))); $this->assertCommand(array_slice($commands, 1, 1), array('data' => $expected_css_html), format_string('Page now has the %css file.', array('%css' => $expected['css']))); // Verify the expected JS file was added, both to drupalSettings, and as // the third AJAX command for inclusion into the HTML. By testing for an // exact HTML string containing the SCRIPT tag, we also ensure that // unexpected JavaScript code, such as a jQuery.extend() that would // potentially clobber rather than properly merge settings, didn't // accidentally get added. $this->assertEqual($new_js, $original_js + array($expected['js'] => 1), format_string('Page state now has the %js file.', array('%js' => $expected['js']))); $this->assertCommand(array_slice($commands, 2, 1), array('data' => $expected_js_html), format_string('Page now has the %js file.', array('%js' => $expected['js']))); }
/** * Implements hook_js_alter(). * Borrowed from AdaptiveTheme. * @link http://drupal.org/project/adaptivetheme */ function zentropy_js_alter(&$javascript) { // Use our own vesion of vertical-tabs.js for better error handling, see http://drupal.org/node/607752 if (isset($javascript['misc/vertical-tabs.js'])) { $file = drupal_get_path('theme', 'zentropy') . '/js/vertical-tabs.js'; $javascript['misc/vertical-tabs.js'] = drupal_js_defaults($file); } }
/** * Implements hook_js_alter(). */ function psf_atc_js_alter(&$javascript) { // Disable animation of Main Menu $file = drupal_get_path('theme', 'psf_atc') . '/scripts/sfsmallscreen.js'; $javascript[libraries_get_path('superfish') . '/sfsmallscreen.js'] = drupal_js_defaults($file); }