Replaced doubled variable ads with queue
[openx] / jquery.openx.js
index f5f2253..3f3669f 100644 (file)
@@ -30,7 +30,6 @@
   count = 0,
   slots = {},
   queue = [],
-  ads = [],
   output = [];
 
 
    * charset:       string  Charset used, when delivering the banner-codes.
    *                        If empty, the charset is guessed by OpenX. Examples
    *                        for sensible values: "UTF-8", "ISO-8859-1".
+   *
+   *
+   * Other settings:
+   *
+   * selector:      string  A selector for selecting the DOM-elements, that
+   *                        should display ad-banners. DEFAULT: ".oa".
+   *                        See: http://api.jquery.com/category/selectors/
    */
   $.openx = function( options ) {
 
         'protocol': document.location.protocol,
         'delivery': '/www/delivery',
         'fl': 'fl.js',
+        'selector': '.oa',
         'cache': true
       },
       options
      */
     src += '?zones=';
     for(name in OA_zones) {
-      $('.oa').each(function() {
+      $(settings.selector).each(function() {
         var
         node = $(this),
         id;
 
   function init_ads() {
 
-    var i, id;
+    var i, id, ads = [];
     for (i=0; i<queue.length; i++) {
       id = queue[i];
       if (typeof(OA_output[id]) != 'undefined' && OA_output[id] != '')
         ads.push(id);
     }
+    queue = ads;
 
     document.write = document_write;
     document.writeln = document_write;
 
   function render_ads() {
 
-    while (ads.length > 0) {
+    while (queue.length > 0) {
 
       var result, src, inline;
 
-      id = ads.shift();
+      id = queue.shift();
       node = slots[id];
 
       node.slideDown();
             /** script-tag with src-URL! */
             if (OA_output[id].length > 0)
               /** The banner-code was not rendered completely yet! */
-              ads.unshift(id);
+              queue.unshift(id);
             /** Load the script and halt all work until the script is loaded and executed... */
             $.getScript(result[1], render_ads); // << jQuery.getScript() generates onload-Handler for _all_ browsers ;)
             return;
     for (var i=0; i<arguments.length; i++)
       output.push(arguments[i]);
 
-    if (id != ads[0])
+    if (id != queue[0])
       /**
        * Re-Add the last banner-code to the working-queue, because included
        * scripts had added markup via document.write(), which is not
        * Otherwise the added markup would be falsely rendered together with
        * the markup from the following banner-code.
        */
-      ads.unshift(id);
+      queue.unshift(id);
 
   }