1(function( $ ) { 2 3 /* 4 The AdLayersDFPAPI class implements functionality specific to DFP For the AdLayersAPI. 5 */ 6 AdLayersDFPAPI = function() {} 7 8 // Refreshes a specific ad unit 9 AdLayersDFPAPI.prototype.refresh = function( ad_unit ) { 10 if ( 'undefined' !== typeof dfpAdUnits[ ad_unit ] ) { 11 googletag.pubads().refresh( [ dfpAdUnits[ ad_unit ] ] ); 12 } 13 } 14 15 // Refreshes all ad units 16 AdLayersDFPAPI.prototype.refreshAll = function() { 17 if ( false === $.isEmptyObject( dfpAdUnits ) ) { 18 // DFP needs a numerical indexed array 19 var unitsToRefresh = new Array; 20 for ( var adUnit in dfpAdUnits ) { 21 unitsToRefresh.push( dfpAdUnits[ adUnit ] ); 22 } 23 googletag.pubads().refresh( unitsToRefresh ); 24 } 25 } 26 27 AdLayersDFPAPI.prototype.buildAd = function( slotName, path, sizes, targets, sizeMapping ) { 28 if ( AdLayersAPI.isDebug() ) { 29 var adSizes = []; 30 31 if ( sizeMapping ) { 32 // Get the appropriate sizes for this breakpoint 33 var maxWidth = -1; 34 var maxHeight = -1; 35 $.each( sizeMapping, function( index, value ) { 36 if ( $( window ).width() >= value[0][0] 37 && $( window ).height() >= value[0][1] 38 && value[0][0] >= maxWidth 39 && value[0][1] >= maxHeight 40 ) { 41 maxWidth = value[0][0]; 42 maxHeight = value[0][1]; 43 adSizes = value[1]; 44 } 45 }); 46 } else { 47 if ( sizes && sizes[0] ) { 48 // Ensure sizes is a two-dimensional array 49 if ( ! sizes[0][0] ) { 50 sizes = [ sizes ]; 51 } 52 adSizes = sizes; 53 } 54 } 55 56 AdLayersDFPAPI.addDebugPlaceholder( $( '#' + adLayersDFP.adUnitPrefix + slotName ), adSizes ); 57 } else { 58 return googletag.cmd.push( function() { 59 var key, value, divId; 60 divId = adLayersDFP.adUnitPrefix + slotName; 61 dfpAdUnits = dfpAdUnits || {}; 62 dfpAdUnits[ slotName ] = googletag.defineSlot( path, sizes, divId ); 63 if ( targets ) { 64 for ( key in targets ) { 65 value = targets[ key ]; 66 dfpAdUnits[ slotName ].setTargeting( key, value ); 67 } 68 } 69 if ( sizeMapping ) { 70 dfpAdUnits[ slotName ].defineSizeMapping( sizeMapping ); 71 } 72 dfpAdUnits[ slotName ].addService( googletag.pubads() ); 73 googletag.display( divId ); 74 } ); 75 } 76 }; 77 78 AdLayersDFPAPI.prototype.lazyLoadAd = function( args ) { 79 if ( ! args.slotName ) { 80 return; 81 } 82 83 if ( args.format ) { 84 if ( ! ( dfpAdDetails && dfpAdDetails[ args.format ] ) ) { 85 return; 86 } 87 if ( ! args.path ) { 88 args.path = dfpAdDetails[ args.format ].path; 89 } 90 if ( ! args.sizes ) { 91 args.sizes = dfpAdDetails[ args.format ].sizes; 92 } 93 if ( ! args.targeting ) { 94 args.targeting = dfpAdDetails[ args.format ].targeting; 95 } 96 if ( ! args.sizeMapping ) { 97 if ( dfpBuiltMappings && dfpBuiltMappings[ args.format ] ) { 98 args.sizeMapping = dfpBuiltMappings[ args.format ]; 99 } else { 100 args.sizeMapping = null; 101 } 102 } 103 } 104 return this.buildAd( args.slotName, args.path, args.sizes, args.targeting, args.sizeMapping ); 105 }; 106 107 108 // Switches sizes in debug mode 109 AdLayersDFPAPI.swapSizes = function( $size ) { 110 // Unselect all other sizes and set this one 111 $size.siblings().removeClass( 'selected' ); 112 $size.addClass( 'selected' ); 113 114 // Set the width and height 115 $size.parents( '.dfp-ad' ).width( $size.data( 'width' ) ); 116 $size.parents( '.dfp-ad' ).height( $size.data( 'height' ) ); 117 118 // Center the debug container vertically 119 $size.parents( '.dfp-debug-container' ).css({ 120 top: ( $size.data( 'height' ) - $size.parents( '.dfp-debug-container' ).outerHeight() )/2, 121 }); 122 } 123 124 AdLayersDFPAPI.addDebugPlaceholder = function( $adDiv, adSizes ) { 125 // Get the ad slot sizes for the current breakpoint 126 var adSlot = $adDiv.data( 'adUnit' ); 127 128 // Set the background 129 $adDiv.addClass( 'dfp-debug' ); 130 131 // Create a container for the ad data 132 $container = $( '<div>' ) 133 .addClass( 'dfp-debug-container' ); 134 135 // Add a label 136 $label = $( '<div>' ) 137 .addClass( 'dfp-debug-unit' ) 138 .text( adSlot ); 139 $container.append( $label ); 140 141 // Add additional sizes for selection 142 $.each( adSizes, function( index, value ) { 143 $link = $( '<a>' ) 144 .attr( 'href', '#' ) 145 .data( 'width', value[0] ) 146 .data( 'height', value[1] ) 147 .text( value[0] + 'x' + value[1] ) 148 .addClass( 'dfp-debug-size' ); 149 150 $container.append( $link ); 151 }); 152 153 // Add to the ad div 154 $adDiv.append( $container ); 155 156 // Set to the first size 157 AdLayersDFPAPI.swapSizes( $adDiv.find( 'a' ).first() ); 158 } 159 160 // Enables debug mode 161 AdLayersDFPAPI.prototype.debug = function() { 162 // Iterate through all of the ad units and display them in debug mode 163 $( '.dfp-ad' ).each( function() { 164 var $adDiv = $( this ), 165 adSlot = $adDiv.data( 'adUnit' ); 166 167 if ( adSlot && 'undefined' !== dfpSizeMapping[ adSlot ] ) { 168 // Get the appropriate sizes for this breakpoint 169 var adSizes = []; 170 var maxWidth = -1; 171 var maxHeight = -1; 172 $.each( dfpSizeMapping[ adSlot ], function( index, value ) { 173 if ( $( window ).width() >= value[0][0] 174 && $( window ).height() >= value[0][1] 175 && value[0][0] >= maxWidth 176 && value[0][1] >= maxHeight 177 ) { 178 maxWidth = value[0][0]; 179 maxHeight = value[0][1]; 180 adSizes = value[1]; 181 } 182 }); 183 184 AdLayersDFPAPI.addDebugPlaceholder( $( this ), adSizes ); 185 } 186 }); 187 188 // Add a debug bar with general layer information and a DFP console toggle 189 $layerTitle = $( '<div>' ) 190 .addClass( 'dfp-ad-layer' )
191 .text( adLayersDFP.layerDebugLabel + ': ' + dfpAdLayer.title ); 192 193 $googleConsole = $( '<a>' ) 194 .addClass( 'dfp-console' ) 195 .attr( 'href', window.location.href.replace( 'adlayers_debug', 'googfc' ) ) 196 .text( adLayersDFP.consoleDebugLabel ); 197 198 $debugBar = $( '<div>' ) 199 .attr( 'id', 'dfp-debug-bar' ) 200 .addClass( 'dfp-debug' ) 201 .append( $layerTitle ) 202 .append( $googleConsole ); 203 204 $( 'body' ).append( $debugBar ); 205 206 // If the WordPress admin bar exists, push it down 207 if ( $( '#wpadminbar' ).length ) { 208 $( '#dfp-debug-bar' ).css( 'top', '32px' ); 209 } 210 } 211 212 // Handle click actions for swapping ad unit sizes 213 $( document ).ready(function() { 214 $( 'body' ).on( 'click', 'a.dfp-debug-size', function( e ) { 215 e.preventDefault(); 216 AdLayersDFPAPI.swapSizes( $( this ) ); 217 }); 218 }); 219})( jQuery ); 220; 221(function( $ ) { 222 223 /* 224 The AdLayersAPI class provides a suite of functions for manipulating ads on the client side. 225 This abstracts the functionality from the specific ad server in use. 226 Each ad server will be required to provide functionality for the below functions. 227 If any of the functions do not exist, they will simply do nothing. 228 */ 229 AdLayersAPI = function() { 230 // Create an object for the active ad server 231 this.adServer = null; 232 233 // Create an instance of the ad server class, if it exists 234 if ( 'string' === typeof adLayersAdServer.jsAPIClass && 'function' === typeof window[ adLayersAdServer.jsAPIClass ] ) { 235 this.adServer = new window[ adLayersAdServer.jsAPIClass ]; 236 } 237 } 238 239 // Refreshes a specific ad unit 240 AdLayersAPI.prototype.refresh = function( ad_unit ) { 241 if ( this.functionExists( 'refresh' ) ) { 242 this.adServer.refresh( ad_unit ); 243 } 244 } 245 246 // Refreshes all ad units 247 AdLayersAPI.prototype.refreshAll = function() { 248 if ( this.functionExists( 'refreshAll' ) ) { 249 this.adServer.refreshAll(); 250 } 251 } 252 253 // Lazy load an ad 254 AdLayersAPI.prototype.lazyLoadAd = function( args ) { 255 if ( this.functionExists( 'lazyLoadAd' ) ) { 256 return this.adServer.lazyLoadAd( args ); 257 } 258 }; 259 260 // Enables debug mode 261 AdLayersAPI.prototype.debug = function() { 262 if ( this.functionExists( 'debug' ) ) { 263 this.adServer.debug(); 264 } 265 } 266 267 // Determines if debug mode has been specified 268 AdLayersAPI.isDebug = function() { 269 return ( -1 != window.location.href.indexOf( '?adlayers_debug' ) ); 270 } 271 272 // Determines if the enabled ad server has implemented a function 273 AdLayersAPI.prototype.functionExists = function( name ) { 274 return ( null !== this.adServer && name in this.adServer ); 275 } 276 277 // Automatically enable debug mode if the URL parameter is present 278 $( document ).ready(function() { 279 if ( AdLayersAPI.isDebug() ) { 280 var adLayers = new AdLayersAPI(); 281 adLayers.debug(); 282 } 283 }); 284})( jQuery ); 285;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.