PageSourceSearch

https://www.giornalepartiteiva.it/fileadmin/layout/common/js/jquery.openxtag.js

js giornalepartiteiva.it collected 2026-10-06 05:19:43 UTC 17,660 bytes, 503 lines download raw bytes

1/*
2 * jQuery OpenX ad tags plugin
3 *
4 * Tested with OpenX Community Edition 2.8.8-rc6
5 *
6 * @version 1.1
7 * @date Fri Jul 15 14:27:52 2011 +0400
8 * @requires jQuery
9 * @url http://plugins.jquery.com/project/openxtag
10 *
11 * @author Nikolay Morev <[email protected]>
12 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
13 *
14 */
15
16(function ($) {
17
18    // NOTE Use strings instead of symbolic names if that name will be used
19    // externally. It is needed to preserve the name after closure compiler
20    // advanced optimization
21
22    var _loopIterations = 10;
23
24    var defaults = {
25        'jsPrefix': 'OA_',
26        'swfObjectJS': 'fl.js',
27        'delivery': null,
28        'deliverySSL': null,
29        'jsTagScript': 'ajs.php',
30        'spcTagScript': 'spc.php',
31        'iframeTagScript': 'afr.php',
32        'adViewScript': 'avw.php',
33        'clickScript': 'ck.php',
34        'charset': 'UTF-8',
35        'zoneID': null,
36        'target': undefined,
37        'source': undefined,
38        'blockcampaign': undefined, // bool option
39        'block': undefined, // bool option
40        'forceAsync': false, // not compatible with block(campaign) parameters
41        'refresh': undefined,
42        'resize': undefined,
43        'allowtransparent': undefined,
44        'width': undefined,
45        'height': undefined,
46        'extra': undefined // object of key-value pairs for custom parameters
47    };
48
49    var init = function (options) {
50        defaults = $.extend(defaults, options);
51    };
52
53    // {{{ function _documentWriteSafeAppend(markup, $this, success) { ... }
54    function _documentWriteSafeAppend(markup, $this, success) {
55        var cnt = 0; // prevent infinite loops
56        (function (markup) {
57            if (markup.match(/document\.write|<script/)) {
58
59		var oldDocumentWrite = document.write;
60                var buffer = '';
61                document.write = function (markup) {
62                    buffer += markup;
63                };
64	
65                $this.append(markup);
66                 document.write = oldDocumentWrite;
67
68                cnt++;
69                if (cnt > _loopIterations) {
70                    $.error('openxtag: document.write loop stopped after ' + _loopIterations + ' iterations');
71                }
72
73                arguments.callee(buffer);
74		
75            }
76            else {
77                $this.append(markup);
78                if (typeof success == 'function') {
79                    setTimeout(function () { success.call($this); }, 0);
80                }
81            }
82        })(markup);
83    }
84    // }}} _documentWriteSafeAppend
85
86    // {{{ function _genericZoneCall(func, zoneID, options, success) { ... }
87    function _genericZoneCall(func, zoneID, options, success) {
88
89        // shift parameters if zoneID is skipped
90
91        if (typeof zoneID == 'object' || typeof zoneID == 'function') {
92            success = options;
93            options = zoneID;
94            zoneID = null;
95        }
96
97        // shift parameters if options are skipped
98
99        if (typeof options == 'function') {
100            success = options;
101            options = null;
102        }
103
104        var settings = $.extend(defaults, options);
105        if (zoneID != null) {
106            settings['zoneID'] = zoneID;
107        }
108
109        return func.apply(this, [zoneID, settings, success]);
110    }
111    // }}} _genericZoneCall
112
113    // {{{ function _validateSettings(settings) { ... }
114    function _validateSettings(settings) {
115
116        // check for required parameters
117
118        if (location.protocol == 'https:') {
119            if (typeof settings['deliverySSL'] != 'string') {
120                $.error('please set "deliverySSL" option for openxtag');
121            }
122        }
123        else {
124            if (typeof settings['delivery'] != 'string') {
125                $.error('please set "delivery" option for openxtag');
126            }
127        }
128    }
129    // }}} _validateSettings
130
131    // {{{ function _buildStandardRequestParameters() { ... }
132    function _buildStandardRequestParameters(settings) {
133        var data = {
134            'charset': settings['charset'],
135            'target': settings['target'],
136            'source': settings['source'],
137            'extra': settings['extra'],
138            'loc': window.location.href
139        };
140
141        if (typeof settings['block'] != 'undefined') {
142            data['block'] = settings['block'] ? 1 : 0;
143        }
144
145	if (typeof settings['extra'] != 'undefined') {
146		for (var key in settings['extra']) {
147			value = settings['extra'][key];
148			data[key] = value;
149		}
150		delete data['extra'];
151	}
152	
153        if (typeof settings['blockcampaign'] != 'undefined') {
154            data['blockcampaign'] = settings['blockcampaign'] ? 1 : 0;
155        }
156
157        if (document.referrer) {
158            data['referer'] = document.referrer;
159        }
160
161        // fixing http://bugs.jquery.com/ticket/8653
162
163        for (var key in data) {
164            if (typeof data[key] == 'undefined') {
165                delete data[key];
166            }
167        }
168
169        return data;
170    }
171    // }}} _buildStandardRequestParameters
172
173    // {{{ function jsZone(zoneID, settings, success) { ... }
174    // Javascript zone tag type
175    var jsZone = function (zoneID, settings, success) {
176        return this.each(function () {
177            var $this = $(this);
178
179            var thesettings = $.extend({}, settings);
180            if (typeof $.metadata != 'undefined') {
181                thesettings = $.extend(thesettings, $this.metadata());
182            }
183
184            _validateSettings(thesettings);
185
186            var zoneID = thesettings['zoneID'];
187            if (zoneID == null) {
188                $.error('please set "zoneID" option for openxtag jsZone');
189            }
190
191            var data = _buildStandardRequestParameters(thesettings);
192            data['zoneid'] = zoneID;
193            data['cb'] = Math.floor(Math.random()*99999999999);
194
195            // only needed for OpenX < 2.4
196            if (!document['MAX_used']) {
197                document['MAX_used'] = ',';
198            }
199            if (document['MAX_used'] != ',') {
200                data['exclude'] = document['MAX_used'];
201            }
202
203            if (document.context) {
204                data['context'] = document.context;
205            }
206            if (document.mmm_fo) {
207                data['mmm_fo'] = 1;
208            }
209
210            var scriptURL = (location.protocol == 'https:' ? thesettings['deliverySSL'] : thesettings['delivery']) + '/' + thesettings['jsTagScript'];
211            $.ajax({
212                url: scriptURL,
213                data: data,
214                dataType: 'script',
215                async: thesettings['forceAsync'], // should be disabled for block(campaign)
216                success: function (data) {
217                    _documentWriteSafeAppend('<script type="text/javascript">' + data + '</script>', $this, success);
218                }
219            });
220        });
221    };
222    // }}} jsZone
223
224    var iFrameZone = function (zoneID, settings, success) {
225        return this.each(function () {
226            var $this = $(this);
227
228            var thesettings = $.extend({}, settings);
229            if (typeof $.metadata != 'undefined') {
230                thesettings = $.extend(thesettings, $this.metadata());
231            }
232
233            _validateSettings(thesettings);
234
235            var zoneID = thesettings['zoneID'];
236            if (zoneID == null) {
237                $.error('please set "zoneID" option for openxtag iframe');
238            }
239
240            var data = _buildStandardRequestParameters(thesettings);
241            data['zoneid'] = zoneID;
242            data['cb'] = Math.floor(Math.random()*99999999999);
243
244            if (typeof thesettings['refresh'] != 'undefined') {
245                data['refresh'] = thesettings['refresh'];
246            }
247
248            if (typeof thesettings['resize'] != 'undefined') {
249                data['resize'] = thesettings['resize'] ? 1 : 0;
250            }
251
252            if (typeof thesettings['width'] == 'undefined') {
253                $.error('openxtag: width parameter is required for iframe tag');
254            }
255            var width = thesettings['width'];
256
257            if (typeof thesettings['height'] == 'undefined') {
258                $.error('openxtag: height parameter is required for iframe tag');
259            }
260            var height = thesettings['height'];
261
262            var allowtransparent = '';
263            if (typeof thesettings['allowtransparent'] != 'allowtransparent' &&
264                thesettings['allowtransparent']) {
265                allowtransparent = ' allowtransparency="true" ';
266            }
267
268            var uniqid = 'a' + Math.floor(Math.random()*999999);
269
270            var target = (typeof thesettings['target'] == 'undefined' ? '_blank' : thesettings['target']);
271
272            var delivery = (location.protocol == 'https:' ? thesettings['deliverySSL'] : thesettings['delivery']);
273            var scriptURL = delivery + '/' + thesettings['iframeTagScript'];
274            var clickURL = delivery + '/' + thesettings['clickScript'];
275            var adViewURL = delivery + '/' + thesettings['adViewScript'];
276
277            $this.append("<iframe id='" + uniqid + "' name='" + uniqid + "' src='" + scriptURL + "?" + $.param(data) +
278            "' frameborder='0' scrolling='no' width='" + width + "' height='" + height +
279            "'" + allowtransparent + "><a href='" + clickURL + "?n=" + uniqid + "&amp;cb=" + data['cb'] + "' target='" +
280            target + "'><img src='" + adViewURL + "?zoneid=" + zoneID + "&amp;cb=" +
281            data['cb'] + "&amp;n=" + uniqid + "' border='0' alt='' /></a></iframe>");
282
283        });
284    };
285
286    // {{{ function spcTag(zoneID, settings, success) { ... }
287    // Single Page Call tag type
288    var spcTag = function (zoneID, settings, success) {
289
290        // get zone ids
291
292        var zones = {};
293        var i = 0;
294        var chainObj = this.each(function () {
295            var $this = $(this);
296
297            var thesettings = $.extend({}, settings);
298            if (typeof $.metadata != 'undefined') {
299                thesettings = $.extend(thesettings, $this.metadata());
300            }
301
302            var zoneID = thesettings['zoneID'];
303            if (zoneID == null) {
304                $.error('please set "zoneID" option for openxtag jsZone');
305            }
306
307            var zoneName = 'z' + i;
308            zones[zoneName] = zoneID;
309            $this.data('openxtag', { 'zn': zoneName });
310
311            i++;
312        });
313
314        var thesettings = $.extend({}, settings);
315        _validateSettings(thesettings);
316
317        var data = _buildStandardRequestParameters(thesettings);
318	var allkeys = function(obj) {
319		var a = [];
320		$.each(obj, function(k) {
321			a.push(k);
322		});
323		return a;
324	};
325	data['zones'] = allkeys(zones).map(function (key) { return key + '=' + zone
325s[key]; }).join('|');
326        data['nz'] = 1; // named zones
327        data['r'] = Math.floor(Math.random()*99999999999);
328
329        var scriptURL = (location.protocol == 'https:' ? thesettings['deliverySSL'] : thesettings['delivery']) + '/' + thesettings['spcTagScript'];
330        var that = this;
331        $.ajax({
332            url: scriptURL,
333            data: data,
334            dataType: 'script',
335            async: thesettings['forceAsync'], // should be disabled for block(campaign)
336            success: function (data, textStatus, jqXHR) {
337                var flJsURL = (location.protocol == 'https:' ? thesettings['deliverySSL'] : thesettings['delivery']) + '/' + thesettings['swfObjectJS'];
338                $.getScript(flJsURL, function () {
339                    var output = eval('(function () {' + data + ';return ' + thesettings['jsPrefix'] + 'output;})()');
340                    that.each(function () {
341                        var $this = $(this);
342                        _documentWriteSafeAppend(output[$this.data('openxtag')['zn']], $this, success);
343                    });
344                });
345            },
346	    error: function(jqXHR, textStatus, errorThrown) {
347		//alert(textStatus + ": " + errorThrown);
348	    }
349        });
350
351        return chainObj;
352    };
353    /// }}} spcTag
354
355    var fnMethods = {
356        'zone': jsZone,
357        'jsZone': jsZone,
358        'spc': spcTag,
359        'iframe': iFrameZone
360    };
361
362    // {{{ function $.fn.openxtag(method) { ... }
363    /**
364     * Loads ad code from OpenX server into all HTML placeholders specified in
365     * jQuery object.
366     *
367     * @name openxtag
368     *
369     * @example <div class="banner"></div>
370     * $('.banner').openxtag('zone', 1);
371     *
372     * @descr Loads ads into elements
373     * @param string type Type of ad invocation tag. Currently supported types
374     * are 'jsZone' for JavaScript invocation tag, 'spc' for Single Page Call
375     * tag, and 'iframe' for iFrame tag. "zone" is alias for "jsZone".
376     * @param number zoneID ID of OpenX zone to load banner from.
377     * @param object options An object containing settings to override the
378     * defaults (see init).
379     * @param function success Callback function to call on successful loading
380     * of ad.
381     * @type jQuery
382     * @cat Plugins/OpenXTag
383     * @see http://www.openx.org/docs/tutorials/comparisons-between-invocation-tags types of OpenX ad invocation tags
384     */
385    $.fn.extend({
386        'openxtag': function (method) {
387            if (fnMethods[method]) {
388                return _genericZoneCall.apply(this, [ fnMethods[method] ].concat(Array.prototype.slice.call(arguments, 1)));
389            } else {
390                $.error('Method ' +  method + ' does not exist on jQuery.openxtag');
391            }
392        }
393    });
394    // }}} $.fn.openxtag
395
396    var methods = {
397        'init': init
398    };
399
400    // {{{ function $.openxtag(method) { ... }
401    /**
402     * Sets default settings for ad loading.
403     *
404     * The following settings are supported:
405     *
406     *   jsPrefix: prefix of JavaScript variables returned from OpenX server
407     *   (see var/prefix option in OpenX configuration). Default: 'OA_'.
408     *
409     *   swfObjectJS: SWFObject script with OpenX modifications (see file/flash
410     *   option in OpenX configuration). Default: 'fl.js'.
411     *
412     *   delivery: OpenX base URL for ad delivery scripts (see webpath/delivery
413     *   option in OpenX configuration). Example:
414     *   http://example.com/openx/delivery.
415     *
416     *   deliverySSL: Same for https web pages.
417     *
418     *   jsTagScript: Name of OpenX script to request JavaScript tag type (see
419     *   file/js option in OpenX configuration). Default: 'ajs.php'.
420     *
421     *   spcTagScript: Name of OpenX script to make Single Page Call request
422     *   (see file/singlepagecall option in OpenX configuration). Default:
423     *   'spc.php'.
424     *
425     *   iframeTagScript: Name of OpenX script to make IFrame tag request (see
426     *   file/frame option in OpenX configuration). Default: 'afr.php'.
427     *
428     *   clickScript: Name of OpenX script to log ad clicks (see file/click
429     *   option in OpenX configuration). Required for IFrame tag. Default:
430     *   'ck.php'.
431     *
432     *   adViewScript: Name of OpenX script to log ad views for IFrame tag.
433     *   Default: 'avw.php'.
434     *
435     *   charset: Character set of web page. Default: 'UTF-8'.
436     *
437     *   zoneID: ID of OpenX zone to load ads from (see Inventory > Zones in
438     *   OpenX manager interface).
439     *
440     *   target: Target frame for ad link. Example: '_blank' to open ad link in
441     *   new window.
442     *
443     *   source: Source parameter can be used to target ads by it's value.
444     *
445     *   blockcampaign: Boolean. When set ads from the same campaign will not
446     *   be loaded on the same page.
447     *
448     *   block: Boolean. When set the same ad will not be loaded on the same
449     *   page twice.
450     *
451     *   forceAsync: Boolean. Force asyncronous loading of ads so that one ad
452     *   will not block loading of another ad. Even when it is set to false ads
453     *   are still loaded asynchronously with page loading. Setting this option
454     *   to true is not compatible with block and blockcampaign options.
455     *   Default: false.
456     *
457     *   refresh: Refresh banner after N seconds. This option is only supported
458     *   in IFrame tag.
459     *
460     *   resize: (Boolean) Resize IFrame to banner dimensions. This option is only
461     *   supported in IFrame tag.
462     *
463     *   allowtransparent: (Boolean) Make the IFrame transparent. This option
464     *   is only supported in IFrame tag.
465     *
466     *   width: Width of banner zone. Required for IFrame tag type.
467     *
468     *   height: Height of banner zone. Required for IFrame tag type.
469     *
470     *   extra: An object of your own extra key-value pairs to pass to OpenX
471     *   for targeting or custom functionality.
472     *
473     * @name $.openxtag
474     *
475     * @example
476     * $.openxtag('init', {
477     *     delivery: 'http://example.com/openx/delivery',
478     *     deliverySSL: 'https://example.com/openx/delivery'
479     * });
480     *
481     * @param string method Must be "init"
482     * @param object options An object containing settings to override the
483     * defaults
484     * @desc Sets default settings for ad loading.
485     * @type undefined
486     * @see http://www.openx.org/docs/2.8/userguide/zone%20invocation
487     */
488    $.extend({
489        'openxtag': function (method) {
490            if (methods[method]) {
491                return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
492            } else if (typeof method === 'object' || !method) {
493                return methods.init.apply(this, arguments);
494            } else {
495                $.error('Method ' +  method + ' does not exist on jQuery.openxtag');
496            }
497        }
498    });
499    // }}} $.openxtag
500
501})(jQuery);
502
503

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.