diff --git a/dfp.module b/dfp.module index 270b333..4ce7c65 100755 --- a/dfp.module +++ b/dfp.module @@ -676,8 +676,9 @@ function _dfp_js_global_settings() { 'weight' => -10, 'force header' => TRUE, ); - // Adds async attribute. Depends on this patch https://www.drupal.org/files/issues/js_attributes-1664602-116.patch. Covered in this issue https://www.drupal.org/node/1664602. - // Also work with Advagg + Advagg_mod installed. Otherwise does nothing. + // Adds async attribute. Depends on this patch https://www.drupal.org/files/issues/js_attributes-1664602-116.patch. + // Covered in this issue https://www.drupal.org/node/1664602. + // Alternatively you can use Advagg + Advagg_mod installed. if (variable_get('dfp_async_rendering', 1)) { $options['async'] = TRUE; } @@ -692,13 +693,11 @@ function _dfp_js_global_settings() { // Add global settings with a heavy weight so that they appear after all the // defineSlot() calls otherwise IE8 and Opera fail to display ads properly. - - // If async option is true wrap the following in cmd.push. if (variable_get('dfp_async_rendering', 1)) { $js = 'googletag.cmd.push(function() {' . "\n"; } else { - $js .= ' googletag.pubads().enableSyncRendering();' . "\n"; + $js = 'googletag.pubads().enableSyncRendering();' . "\n"; } if (variable_get('dfp_single_request', 1)) { $js .= ' googletag.pubads().enableSingleRequest();' . "\n"; @@ -731,10 +730,10 @@ function _dfp_js_global_settings() { $js .= ' googletag.enableServices();' . "\n"; if (variable_get('dfp_async_rendering', 1)) { $js .= '});' . "\n"; - } - + } + $js .= variable_get('dfp_injected_js2', '') . "\n"; - + $options = array( 'type' => 'inline', 'group' => JS_DEFAULT, @@ -773,7 +772,6 @@ function _dfp_js_slot_definition($tag) { $js .= ' .build();' . "\n"; } - if (!empty($tag->settings['out_of_page'])) { $js .= 'googletag.slots["' . $tag->machinename . '"] = googletag.defineOutOfPageSlot("' . $tag->adunit . '", "' . $tag->placeholder_id . '")' . "\n"; } @@ -809,11 +807,10 @@ function _dfp_js_slot_definition($tag) { } if (variable_get('dfp_async_rendering', 1)) { $js = rtrim($js, "\n") . '});' . "\n"; - } - else{ + } + else { $js = rtrim($js, "\n") . ';' . "\n"; } - $options = array( 'type' => 'inline', @@ -1011,21 +1008,16 @@ function template_preprocess_dfp_tag(&$variables) { ); } - - // If async option is true wrap the display call in cmd.push. - if(variable_get('dfp_async_rendering', 1)){ - $variables['display_call'] = + if (variable_get('dfp_async_rendering', 1)){ + $variables['display_call'] = "googletag.cmd.push(function() { - googletag.display(\"".$tag->placeholder_id."\"); + googletag.display(\"" . $tag->placeholder_id . "\"); });\n"; - } + } else { - $variables['display_call'] = "googletag.display(\"".$tag->placeholder_id."\");\n"; - } - - - + $variables['display_call'] = "googletag.display(\"" . $tag->placeholder_id . "\");\n"; + } // Define a javascript ad slot for this tag. _dfp_js_slot_definition($tag); diff --git a/tests/dfp.test b/tests/dfp.test index c8d344c..6aab880 100644 --- a/tests/dfp.test +++ b/tests/dfp.test @@ -464,6 +464,7 @@ class dfpGlobalsTest extends dfpBaseTest { function testGlobalSettingsOn() { $injected_js = $this->randomName(32); + $injected_js2 = $this->randomName(32); $target = array( 'target' => $this->randomName(8), 'value' => $this->randomName(8), @@ -473,12 +474,14 @@ class dfpGlobalsTest extends dfpBaseTest { variable_set('dfp_single_request', '1'); variable_set('dfp_collapse_empty_divs', '1'); variable_set('dfp_injected_js', $injected_js); + variable_set('dfp_injected_js2', $injected_js2); variable_set('dfp_targeting', array($target)); $this->drupalGet('/'); - $this->assertRaw('googletag.pubads().enableAsyncRendering();', 'Asyncronous rendering is turned on.'); + $this->assertRaw('googletag.cmd.push(function() {', 'Asyncronous rendering is turned on.'); $this->assertRaw('googletag.pubads().enableSingleRequest();', 'Single request is turned on.'); $this->assertRaw('googletag.pubads().collapseEmptyDivs();', 'Collapse empty divs is turned on.'); $this->assertRaw($injected_js, 'Injected javascript correctly appears on the page.'); + $this->assertRaw($injected_js2, 'Injected javascript 2 correctly appears on the page.'); $this->assertRaw('googletag.pubads().setTargeting("' . $target['target'] . '", "' . $target['value'] . '");', 'Global targetting values appear correclty in javascript.'); } @@ -487,6 +490,7 @@ class dfpGlobalsTest extends dfpBaseTest { variable_set('dfp_single_request', '0'); variable_set('dfp_collapse_empty_divs', '0'); $this->drupalGet('/'); + $this->assertRaw('googletag.pubads().enableSyncRendering();', 'Syncronous rendering is turned on.'); $this->assertNoRaw('googletag.pubads().enableAsyncRendering();', 'Asyncronous rendering is turned off.'); $this->assertNoRaw('googletag.pubads().enableSingleRequest();', 'Single request is turned off.'); $this->assertNoRaw('googletag.pubads().collapseEmptyDivs();', 'Collapse empty divs is turned off.');