/** * All offers must inherite this class */ function Offer() { } Offer.prototype.init = function() { console.log('offer init'); }; Offer.prototype.addCSS = function( cssString ) { jQuery("body:first").append( "" ); }; /** * Class for loading tests and targets */ OfferFactory = function() { /** * Where to we fetch the offer from? */ var adServer = "http://www.pokerlistings.com/offer/"; var offerName = ""; /** * Return the location of the script file */ function getServerLocation() { return adServer + offerName; } /** * Not the best solution to use eval() */ function createAndInitOffer( data, jsonConfig ) { // Parse script file eval( data ); // Inheritance eval( offerName + ".prototype = new Offer();" + offerName + ".prototype.constructor = " + offerName + ";"); // Set options as static vars eval( offerName + ".options = jsonConfig" ); eval( "offerObj = new " + offerName ); offerObj.init(); return true; } return { load : function( targetname, jsonConfig ) { jQuery(document).ready( function() { offerName = targetname; jQuery.ajax({ url: getServerLocation(), type: "GET", cache: false, dataType: "script", success: function( data ) { createAndInitOffer( data, jsonConfig ); }, error: function(){ // Die gracefully } }); }); }, getOfferUrl : function() { return getServerLocation(); } }; }();