visibility has a value of 0 (BLOCK_VISIBILITY_NOTLISTED), // the wow.js library is loaded on all pages except those listed in // $wowjs_pages. When set to 1 (BLOCK_VISIBILITY_LISTED), it is // displayed only on those pages listed in $wowjs_pages. $page_match = !($wowjs_visibility xor $page_match); } elseif (module_exists('php')) { $page_match = php_eval($wowjs_pages); } else { $page_match = FALSE; } } else { // There is no page configuration for theme. $page_match = ($wowjs_visibility == BLOCK_VISIBILITY_NOTLISTED); } if ($page_match) { // There is a match. We load the wow.js library. libraries_load('wow'); } } /** * Implements hook_libraries_info(). */ function wowjs_libraries_info() { $libraries['wow'] = array( 'name' => 'wow', 'vendor url' => WOWJS_VENDOR_URL, 'download url' => WOWJS_DOWNLOAD_URL, 'version arguments' => array( 'file' => 'package.json', 'pattern' => '/((?:\d+\.?){2,3})/', ), 'files' => array( 'js' => array( 'dist/wow.min.js', ), ), 'variants' => array( 'minified' => array( 'files' => array( 'js' => array( 'dist/wow.min.js', ), ), ), 'source' => array( 'files' => array( 'js' => array( 'dist/wow.js', ), ), ), ), ); return $libraries; } /** * Implements hook_form_FORM_ID_alter() for system_theme_settings(). * * Add a new configuration option to each theme's configuration page to set the * pages where the wow.js library will be loaded. The library will be loaded in * every page by default. */ function wowjs_form_system_theme_settings_alter(&$form, &$form_state) { if (isset($form_state['build_info']['args'][0]) && ($theme = $form_state['build_info']['args'][0])) { $form['wowjs'] = array( '#title' => t('WOW Javascript library'), '#type' => 'fieldset', '#weight' => 30, '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['wowjs_theme'] = array('#type' => 'value', '#value' => $theme); $visibility_default = variable_get('wowjs_' . $theme . '_visibility', BLOCK_VISIBILITY_NOTLISTED); $pages_default = variable_get('wowjs_' . $theme . '_pages', ''); $access = user_access('use PHP for settings'); if ($visibility_default == BLOCK_VISIBILITY_PHP && !$access) { $form['wowjs']['wowjs_visibility'] = array( '#type' => 'value', '#value' => BLOCK_VISIBILITY_PHP, ); $form['wowjs']['wowjs_pages'] = array( '#type' => 'value', '#value' => $pages_default, ); } else { $options = array( BLOCK_VISIBILITY_NOTLISTED => t('All pages except those listed'), BLOCK_VISIBILITY_LISTED => t('Only the listed pages'), ); $description = t("Specify pages where the wow.js will be loaded by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array( '%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '', )); if (module_exists('php') && $access) { $options += array(BLOCK_VISIBILITY_PHP => t('Pages on which this PHP code returns TRUE (experts only)')); $title = t('Pages where wow.js library will be loaded (or PHP code)'); $description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. Note that executing incorrect PHP code can break your Drupal site.', array('%php' => '')); } else { $title = t('Pages where wow.js library will be loaded'); } $form['wowjs']['wowjs_visibility'] = array( '#type' => 'radios', '#title' => t('Load wow.js library on specific pages'), '#options' => $options, '#default_value' => $visibility_default, ); $form['wowjs']['wowjs_pages'] = array( '#title' => $title, '#type' => 'textarea', '#description' => $description, '#default_value' => $pages_default, ); } $form['#submit'][] = 'wowjs_form_system_theme_settings_submit'; } } /** * Form submission handler for wowjs_form_system_theme_settings_alter(). */ function wowjs_form_system_theme_settings_submit($form, &$form_state) { $theme = $form_state['values']['wowjs_theme']; $wowjs_pages = $form_state['values']['wowjs_pages']; $wowjs_visibility = $form_state['values']['wowjs_visibility']; variable_set('wowjs_' . $theme . '_pages', $wowjs_pages); variable_set('wowjs_' . $theme . '_visibility', $wowjs_visibility); } /** * Helper function. Returns the help message. */ function _wowjs_get_help_message() { $message = '

' . t("The WOWJS module integrates the wow.js library into Drupal.", array("@wowjs_link" => WOWJS_VENDOR_URL)); $message .= t("WOW is a Javascript library which works nicely with the Animate CSS library to create great cross browser CSS3-based animations in your Drupal sites.", array("@animate_css_link" => WOWJS_ANIMATE_CSS_URL)); $message .= '

'; $message .= '

'; $message .= t("The Animate CSS library provides a complete set of CSS3 animations you can apply to any HTML element in your Drupal site using some JQuery code or providing some CSS classes on your templates for the HTML elements you want to animate. You can see this animations in action in the Animate CSS library's webpage.", array( "@animate_css_link" => WOWJS_ANIMATE_CSS_URL, "@animate_css_website_link" => WOWJS_ANIMATE_CSS_WEBPAGE_URL, )); $message .= '

'; $message .= '

'; $message .= t("The wow.js library provides more control over those animations, letting you to set how many times an animation will be repeated, how much time the animation will last, how much time the animation will delay until it will start, etc.", array("@wowjs_link" => WOWJS_VENDOR_URL)); $message .= '

'; $message .= '

'; $message .= t("The wow.js library provides another nice feature: if you use the Animate CSS library only and you set an animation for an HTML element which is outside the fold, when you scroll down the page to see that HTML element, the CSS animation will probably have finished. Using the wow.js library with the Animate CSS library, the CSS animations of the HTML elements will start when those elements become visible as you scroll down the page. You can see a demo in the wow.js librarys's home page.", array("@wowjs_link" => WOWJS_VENDOR_URL)); $message .= '

'; $message .= '

'; $message .= t("Don't forget to clear Drupal's caches. By default, this module will load the wow.js library on every page of your website. If you only want to load the wow.js library in certain pages, go to your theme's configuration settings page and provide the list of pages where you want the wow.js library to be loaded (or not loaded). This module integrates with Drupal's core PHP filter module, so you can load the wow.js library on those pages where certain PHP expression returns true."); $message .= '

'; $message .= '

Resources

'; $message .= '

'; $message .= '

'; $message .= '

'; return $message; }