From 4691d2c97d4c3154c20020487dcd916a2b81abf2 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 26 Feb 2013 22:31:06 +0100 Subject: [PATCH] Changed the script into a jquery-plugin --- openx.js => jquery.openx.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) rename openx.js => jquery.openx.js (91%) diff --git a/openx.js b/jquery.openx.js similarity index 91% rename from openx.js rename to jquery.openx.js index 76e994b..5825593 100644 --- a/openx.js +++ b/jquery.openx.js @@ -15,7 +15,13 @@ * - Kai Moritz */ -(function( openx, $, undefined ) { +/* + * See http://coding.smashingmagazine.com/2011/10/11/essential-jquery-plugin-patterns/ + * for detailed explanations for the applied best practices. + * + * The semicolon guides our code for poorly written concatenated scripts. + */ +;(function( $, window, document, undefined ) { var @@ -28,7 +34,13 @@ output = []; - openx.show_ads = function(server, zones) { + $.openx = function( server, zones, options ) { + + if (domain) { + if (console.error) + console.error('jQuery.openx was already initialized!'); + return; + } domain = document.location.protocol == 'https:' ? 'https://' + server + ':8443':'http://' + server; @@ -99,7 +111,7 @@ while (ads.length > 0) { - var result, src, inline, i; + var result, src, inline; id = ads.shift(); node = slots[id]; @@ -200,6 +212,6 @@ } -} ( window.openx = window.openx || {}, jQuery )); +})( jQuery, window, document ); var OA_output = {}; // << Needed, because IE will complain loudly otherwise! -- 2.20.1