You are here

function sharerich_page_build in Sharerich 7

Same name and namespace in other branches
  1. 7.3 sharerich.module \sharerich_page_build()
  2. 7.2 sharerich.module \sharerich_page_build()

Implements hook_page_build().

File

./sharerich.module, line 321

Code

function sharerich_page_build() {
  if (path_is_admin(current_path())) {
    return;
  }

  // Add CSS from the configuration page.
  $css = explode('|', preg_replace('/(\\r\\n?|\\n)/', '|', variable_get('sharerich_add_css')));
  foreach ($css as $key => $url) {
    if (!empty($url)) {
      if (stripos($url, 'http') !== FALSE) {
        drupal_add_css($url, 'external');
      }
      else {
        drupal_add_css($url);
      }
    }
  }

  // Add Js from the configuration page.
  $js = explode('|', preg_replace('/(\\r\\n?|\\n)/', '|', variable_get('sharerich_add_js')));
  foreach ($js as $key => $url) {
    if (!empty($url)) {
      if (stripos($url, 'http') !== FALSE) {
        drupal_add_js($url, 'external');
      }
      else {
        drupal_add_js($url, array(
          'scope' => 'footer',
        ));
      }
    }
  }

  // Backwards compatibility to jQuery.live.
  $js = <<<JS
(function(\$) {
  typeof \$ && typeof \$.fn.on !== "function" && \$.fn.extend({
     on: function(event, callback, fallback) {
       switch (typeof callback) {
         case "function": return this.live(event, callback);
         case "string"  : return \$(callback).live(event, fallback);
       }
     }
   });
}(jQuery));
JS;
  drupal_add_js($js, array(
    'type' => 'inline',
    'scope' => 'header',
  ));
}