You are here

function google_admanager_add_js in DFP Small Business (Google Ad Manager) 6

Same name and namespace in other branches
  1. 5 google_admanager.module \google_admanager_add_js()
  2. 6.3 google_admanager.module \google_admanager_add_js()
  3. 6.2 google_admanager.module \google_admanager_add_js()
  4. 7.2 google_admanager.module \google_admanager_add_js()

Store ad slots js and when called with no slot, return the whole ad manager javascript

Parameters

$js (optional) string with the slot script to add to the array.:

$type (optional) scripts have to be split up into 4 types and are output: in order ['init', 'service', 'slot', 'close'].

Return value

if $js is empty, then an array of stored google_admanager javascript

3 calls to google_admanager_add_js()
google_admanager_footer in ./google_admanager.module
Implementation of hook_footer().
google_admanager_get_js in ./google_admanager.module
Output the Google Admanager scripts by way of drupal_add_js().
theme_google_admanager_block in ./google_admanager.module
Theme function the Ad Slot code

File

./google_admanager.module, line 339

Code

function google_admanager_add_js($js = NULL, $type = 'slot') {
  static $ga_js = array();

  // add the js to a type
  if (isset($js) && isset($type)) {
    $ga_js[$type][] = $js;

    //add the init and service scripts the first time this is run
    if (!isset($ga_js['init'])) {

      //drupal_add_js can't load externaljs in 6, but it will in 7. this is a workaround.
      $external_js = 'http://partner.googleadservices.com/gampad/google_service.js';
      google_admanager_add_js('document.write(unescape("%3Cscript src=\'' . $external_js . '\' type=\'text/javascript\'%3E%3C/script%3E"));', 'init');
      $id = variable_get('google_admanager_account', '');
      google_admanager_add_js('GS_googleAddAdSenseService("' . $id . '");', 'service');
      google_admanager_add_js('GS_googleEnableAllServices();', 'service');

      // set the close script to fetch the ads.
      google_admanager_add_js('GA_googleFetchAds();', 'close');
    }
    return;
  }

  //check that there is something to return
  if (!isset($ga_js['init'])) {
    return;
  }

  // $ga_js['init'] must have been set since we didn't return, so if js isn't set then return
  // the whole array, just like drupal_add_js().
  if (!isset($js)) {
    return $ga_js;
  }
}