projects
/
openx
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
85c5913
)
Fetch on resize: added resize-event that hides/shows banners accordingly
0.2.0
author
Kai Moritz
<kai@juplo.de>
Thu, 28 Feb 2013 17:32:57 +0000
(18:32 +0100)
committer
Kai Moritz
<kai@juplo.de>
Thu, 28 Feb 2013 17:32:57 +0000
(18:32 +0100)
jquery.openx.js
patch
|
blob
|
history
openx.jquery.json
patch
|
blob
|
history
diff --git
a/jquery.openx.js
b/jquery.openx.js
index
a37dcff
..
889a539
100644
(file)
--- a/
jquery.openx.js
+++ b/
jquery.openx.js
@@
-33,6
+33,9
@@
max_width = {},
width,
rendered = {},
max_width = {},
width,
rendered = {},
+ visible = {},
+ rendering = false,
+ resize_timer,
queue = [],
output = [];
queue = [],
output = [];
@@
-100,6
+103,11
@@
* CSS-classname. DEFAULT: "min_".
* max_prefix: string Prefix for the encoding of the maximal width as
* CSS-classname. DEFAULT: "max_".
* CSS-classname. DEFAULT: "min_".
* max_prefix: string Prefix for the encoding of the maximal width as
* CSS-classname. DEFAULT: "max_".
+ * resize_delay: number Number of milliseconds to wait, before a
+ * recalculation of the visible ads is scheduled.
+ * If the value is choosen to small, a recalculation
+ * might be scheduled, while resizing is still in
+ * progress. DEFAULT: 200.
*/
$.openx = function( options ) {
*/
$.openx = function( options ) {
@@
-133,6
+141,7
@@
'selector': '.oa',
'min_prefix': 'min_',
'max_prefix': 'max_',
'selector': '.oa',
'min_prefix': 'min_',
'max_prefix': 'max_',
+ 'resize_delay': 200
},
options
);
},
options
);
@@
-188,29
+197,55
@@
max_width[id] = match[1];
}
rendered[id] = false;
max_width[id] = match[1];
}
rendered[id] = false;
+ visible[id] = false;
}
});
}
}
});
}
- /** Set initial window-width */
- width = $(document).width();
+ /** Add resize-event */
+ $(window).resize(function() {
+ clearTimeout(resize_timer);
+ resize_timer = setTimeout(recalculate_visible , settings.resize_timeout);
+ });
/** Fetch the JavaScript for Flash and schedule the initial fetch */
/** Fetch the JavaScript for Flash and schedule the initial fetch */
- $.getScript(domain + settings.delivery + '/' + settings.fl,
fetch_ads
);
+ $.getScript(domain + settings.delivery + '/' + settings.fl,
recalculate_visible
);
}
}
+ function recalculate_visible() {
+
+ width = $(document).width();
+ if (!rendering)
+ fetch_ads();
+
+ }
+
function fetch_ads() {
function fetch_ads() {
+ /** Guide rendering-process for early restarts */
+ rendering = true;
+
var name, src = domain + settings.delivery + '/spc.php';
/** Order banners for all zones that were found on the page */
src += '?zones=';
for(id in slots) {
var name, src = domain + settings.delivery + '/spc.php';
/** Order banners for all zones that were found on the page */
src += '?zones=';
for(id in slots) {
- if (width >= min_width[id] && width <= max_width[id]) {
- queue.push(id);
- src += escape(id + '=' + OA_zones[slots[id].id] + "|");
- rendered[id] = true;
+ visible[id] = width >= min_width[id] && width <= max_width[id];
+ if (visible[id]) {
+ if (!rendered[id]) {
+ queue.push(id);
+ src += escape(id + '=' + OA_zones[slots[id].id] + "|");
+ rendered[id] = true;
+ }
+ else {
+ /** Unhide already fetched visible banners */
+ $(slots[id]).slideDown();
+ }
+ }
+ else {
+ /** Hide unvisible banners */
+ $(slots[id]).hide();
}
}
src += '&nz=1'; // << We want to fetch named zones!
}
}
src += '&nz=1'; // << We want to fetch named zones!
@@
-239,6
+274,9
@@
if (typeof OA_source !== 'undefined')
src += "&source=" + escape(OA_source);
if (typeof OA_source !== 'undefined')
src += "&source=" + escape(OA_source);
+ /** Signal, that this task is done / in progress */
+ width = undefined;
+
/** Fetch data from OpenX and schedule the render-preparation */
$.getScript(src, init_ads);
/** Fetch data from OpenX and schedule the render-preparation */
$.getScript(src, init_ads);
@@
-327,6
+365,12
@@
id = undefined;
node = undefined;
id = undefined;
node = undefined;
+ rendering = false;
+
+ /** Restart rendering, if new task was queued */
+ if (width)
+ fetch_ads();
+
}
/** This function is used to overwrite document.write and document.writeln */
}
/** This function is used to overwrite document.write and document.writeln */
diff --git
a/openx.jquery.json
b/openx.jquery.json
index
8b34333
..
2e8f5b2
100644
(file)
--- a/
openx.jquery.json
+++ b/
openx.jquery.json
@@
-3,7
+3,7
@@
"title": "jQuery OpenX",
"description": "jQuery plugin, that loads banner-ads from an OpenX-server in an asynchronous and responsive way",
"keywords": [ "openx", "adserver", "banner", "asynchrone", "responsive" ],
"title": "jQuery OpenX",
"description": "jQuery plugin, that loads banner-ads from an OpenX-server in an asynchronous and responsive way",
"keywords": [ "openx", "adserver", "banner", "asynchrone", "responsive" ],
- "version": "0.
1.3
",
+ "version": "0.
2.0
",
"author": { "name": "Kai Moritz", "email": "kai@juplo.de" },
"licenses": [ { "type": "LGPLv3", "url": "http://www.gnu.org/licenses/lgpl-3.0.html" } ],
"homepage": "http://juplo.de/openx",
"author": { "name": "Kai Moritz", "email": "kai@juplo.de" },
"licenses": [ { "type": "LGPLv3", "url": "http://www.gnu.org/licenses/lgpl-3.0.html" } ],
"homepage": "http://juplo.de/openx",