Created
June 6, 2012 20:52
-
-
Save sveisvei/2884693 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function collectData(){ | |
function copy(src, obj, keys){ | |
for(var name, i = 0, len = keys.length; i < len; i++){ | |
name = keys[i]; | |
if(typeof src[name] !== 'undefined'){ | |
if (typeof src[name] === 'function') { // function this and that | |
} else if (typeof src[name] === 'object'){ | |
for(var subkey in src[name]){ obj[name+'_'+subkey] = src[name][subkey]; } | |
} else { | |
obj[name] = src[name]; | |
} | |
} | |
} | |
return obj; | |
} | |
var obj = { | |
screen : {}, | |
win : {}, | |
doc : {}, | |
nav : {}, | |
feature : {}, | |
banners : {}, | |
user : {}, | |
page : {}, | |
time : (new Date()).toString() | |
}; | |
for(var key in screen){ obj.screen[key] = screen[key]; } | |
copy(window, obj.win, ['width', 'height', 'innerWidth', 'innerHeight', 'outerWidth', 'outerHeight']); | |
copy(document, obj.doc, ['width', 'height']); | |
copy(navigator, obj.nav, ['userAgent', 'cookieEnabled', 'language']); | |
//collect banner renderdata | |
obj.banners.active = !!(window.FINN && !!window.FINN.webAds); | |
if (obj.banners.active && FINN.webAds._getBanner){ | |
var banners = $.map(FINN.data.banners, function(val){ return FINN.webAds._getBanner(val.name); }); | |
var selectProps = ["name", "url", "width", "height", "active", "retries", "resolved", "failed", "incomplete", "resized", "notValid", "ignoreOnload", "refreshCalled"]; | |
obj.banners.rendered = $.map(banners, function(banner){ return copy(banner, {}, selectProps); }); | |
} | |
if (typeof window.Modernizr !== 'undefined'){ | |
copy(Modernizr, obj.feature, ["flexbox", "canvas", "canvastext", "webgl", "touch", "geolocation", "postmessage", "websqldatabase", "indexeddb", "hashchange", "history", "draganddrop", "websockets", "multiplebgs", "backgroundsize", "borderimage", "borderradius", "boxshadow", "textshadow", "opacity", "cssanimations", "csscolumns", "cssgradients", "cssreflections", "csstransforms", "csstransforms3d", "csstransitions", "fontface", "video", "audio", "localstorage", "sessionstorage", "webworkers", "svg", "inlinesvg", "smil", "svgclippaths", "input", "inputtypes", "crosswindowmessaging", "historymanagement"]); | |
} | |
if (FINN && FINN.user && FINN.user.auth && typeof FINN.user.auth.isLoggedIn === 'function'){ | |
obj.user.isLoggedIn = FINN.user.auth.isLoggedIn(); | |
} | |
if (jQuery){ | |
obj.win.$width = jQuery(window ).width(); | |
obj.win.$height = jQuery(window ).height(); | |
obj.doc.$width = jQuery(document).width(); | |
obj.doc.$height = jQuery(document).height(); | |
obj.user.position = { | |
scrollTop : jQuery(window).scrollTop(), | |
scrollLeft : jQuery(window).scrollLeft() | |
}; | |
var page = $(".wrapper,.page").first(); | |
obj.page.width = page.width(); | |
obj.page.height = page.height(); | |
obj.page.outerWidth = page.outerWidth(); | |
obj.page.outerHeight = page.outerHeight(); | |
obj.page.innerWidth = page.innerWidth(); | |
obj.page.innerHeight = page.innerHeight(); | |
} | |
return obj; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment