// the script is heavily influenced by Kent Brewster's Case-Hardened // Javascript (http://kentbrewster.com/case-hardened-javascript). ( function() { // create a random global variable to run everything under var myProjCrowdriseVar = ""; for (var i = 0; i < 16; i++) { myProjCrowdriseVar += String.fromCharCode(Math.floor(Math.random() * 26) + 97); } window[myProjCrowdriseVar] = {}; // create a private pointer so you don't have to keep saying window[myProjCrowdriseVar] var $ = window[myProjCrowdriseVar]; // $.f is your main function $.f = function() { return { runFunction : [], init : function(target) { var theScripts = document.getElementsByTagName("SCRIPT"); for (var i = 0; i < theScripts.length; i++) { // if you find yourself if (theScripts[i].src.match(target)) { // make a container for user arguments $.a = {}; // parse the innerHTML into arguments if (theScripts[i].innerHTML) { $.a = $.f.parseJson(theScripts[i].innerHTML); } // create a DIV to run inside $.w = document.createElement("DIV"); $.w.className = "container"; theScripts[i].parentNode.insertBefore($.w, theScripts[i]); // remove yourself theScripts[i].parentNode.removeChild(theScripts[i]); // make and run the rest of the badge $.f.buildStructure(); // quit looping; you are done break; } } }, // safe JSON parser parseJson : function(json) { this.parseJson.data = json; if (typeof json !== "string") { return {"err":"trying to parse a non-string JSON object"}; } try { var f = Function(["var document,top,self,window,parent,Number,Data,Object,Function,", "Array,String,Math,RegExp,Image,ActiveXObject;", "return (" , json.replace(/<\!--.+-->/gim,'').replace(/\bfunction\b/g,'function') , ");"].join("")); return f(); } catch(e) { return {"err":"trouble parsing JSON object"}; } }, // insertCSS insertCSS : function(rules) { var ns = document.createElement("style"); document.getElementsByTagName("head")[0].appendChild(ns); // Safari does not see the new stylesheet unless you append something to it // However IE will blow chunks, so ... filter it thusly: if (!window.createPopup) { ns.appendChild(document.createTextNode("")); ns.setAttribute("type", "text/css"); } var s = document.styleSheets[document.styleSheets.length - 1]; var ieRules = ""; for (var r in rules) { var selector = "div#" + myProjCrowdriseVar + " " + r; if (!window.createPopup) { var rule = document.createTextNode(selector + rules[r]); ns.appendChild(rule); } else { ieRules += selector + rules[r]; } } if (window.createPopup) { s.cssText = ieRules; } }, // build chrome buildStructure : function() { $.d = { "title" : "Team Streetwise Partners NYC Marathon 2012", "width" : "auto", "height" : "auto" }; // assign defaults if not present in user args for (var k in $.d) { if ($.a[k] === undefined) { $.a[k] = $.d[k]; } } //$.w.className = myProjCrowdriseVar; $.w.id = myProjCrowdriseVar; if ($.a.addClassName !== undefined) { try { $.w.className += " " + $.a.addClassName; } catch(eClassName) { } } if ($.a.id !== undefined) { try { $.w.id = $.a.id; } catch(eId) {} } if ($.a.width !== undefined) { try { if (/^\s*\d+\s*$/.test($.a.width)) { $.a.width += "px"; } $.w.style.width = $.a.width; } catch(eWidth) { } } if ($.a.height !== undefined && $.a.height != 'auto') { try { if (/^\s*\d+\s*$/.test($.a.height)) { $.a.height += "px"; } $.w.style.height = $.a.height; } catch (eHeight) { } } var rules = { "" : "{zoom:1; background:" + $.a.backgroundColor + "; color:#FFF; font-family: Helvetica, Arial, sans-serif; padding:0px 0 0px 0;text-align:left; border:" + $.a.border + "}", "*" : "{font-weight:normal; font-size:100%; font-style: normal; line-height:1.0em; margin:0; padding:0; text-align:left; border:0; color:#ffffff; text-shadow: none;}", "a" : "{text-decoration:none;}", "a.hover" : "{text-decoration:none;}", ".inside" : "{}", "h1" : "{font-size:19px; margin:20px 0 0 0; letter-spacing:-1px; text-transform:uppercase; color: #FFF; width:100%;}", ".clear" : "{clear:both;}", ".floatLeft" : "{float:left;}", ".floatRight" : "{float:right;}", ".crProjectWidget" : "{border:8px solid #ff9a1a;width:226px;background-color:#2c2c2c;font-family: Arial,Helvetica,sans-serif;font-size: 12px;}", ".crProjectWidget h4" : "{background:url(https://c814182.ssl.cf0.rackcdn.com/event_widget_sprite3.png) 0 -68px repeat-x;height:44px;line-height:44px;text-align:center;color:#fff;padding:0px;margin:0px 0px 25px 0px;font-size:18px;}", ".crProjectWidget h5" : "{line-height:20px;text-align:left;color:#ffffff;padding:0px 20px 0px 20px;margin:0px 0px 25px 0px;font-size:18px;text-transform:uppercase;}", ".gradientButton" : "{background: rgb(243,121,35); /* Old browsers *//* IE9 SVG, needs conditional override of 'filter' to 'none' */ background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2ZmOTgwZCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNmMzc5MjMiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);background: -moz-linear-gradient(top, rgba(255,154,26,1) 0%, rgba(243,121,35,1) 100%); /* FF3.6+ */ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,154,26,1)), color-stop(100%,rgba(243,121,35,1))); /* Chrome,Safari4+ */ background: -webkit-linear-gradient(top, rgba(255,154,26,1) 0%,rgba(243,121,35,1) 100%); /* Chrome10+,Safari5.1+ */ background: -o-linear-gradient(top, rgba(255,154,26,1) 0%,rgba(243,121,35,1) 100%); /* Opera 11.10+ */ background: -ms-linear-gradient(top, rgba(255,154,26,1) 0%,rgba(243,121,35,1) 100%); /* IE10+ */ background: linear-gradient(top, rgba(255,154,26,1) 0%,rgba(243,121,35,1) 100%); /* W3C */ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff9a1a', endColorstr='#f37923',GradientType=0 ); /* IE6-8 */ height:44px; width:196px; margin:0px auto 25px; }", ".donateNow" : "{text-align:center;color:#ffffff;line-height:44px;width:196px;display:block;font-size:18px;}", ".crProjectInfo" : "{padding:0px 20px 20px;}", ".crDividerH" : "{height: 0;line-height: 0;border-bottom: 1px solid #9A988C;margin-bottom: 15px;}", ".crProjectInfo img" : "{float:left;padding-right:10px;}", ".crDonated" : "{color:#f37923;font-size:28px;padding-top:10px;text-align:center;}", ".crDonatedLabel" : "{color:#9f9f9f;font-size:12px;text-align:center;}", ".crProjectAction" : "{color:#ffffff;padding-top:20px;}", ".crLogoWrap" : "{background:url(https://c814182.ssl.cf0.rackcdn.com/event_widget_sprite3.png) 0 -171px repeat-x;height:48px;}", ".crLogo" : "{background:url(https://c814182.ssl.cf0.rackcdn.com/event_widget_sprite3.png) center 0 no-repeat;height:48px;}", "a.crMore" : "{color:#f37923;}", "#crThermContainer" : "{padding-bottom:10px;padding-left:13px;}", "#thermometer" : "{height:27px;width:196px;background-color:#fff;padding:2px;-moz-border-radius: 13px;border-radius: 13px;}", "#mercurybg" : "{background:url(https://c814182.ssl.cf0.rackcdn.com/event_widget_sprite3.png) 0 -132px repeat-x;height:100%;width:100%;-moz-border-radius: 13px;border-radius: 13px;}", "#mercury" : "{width:100%;height:100%;-moz-border-radius: 13px;border-radius: 13px;background: rgb(243,121,35); background: rgba(243,121,35, 1);}", ".crPercentInfo" : "{color:#9f9f9f;font-size:14px;text-align:center;padding-bottom:25px;}", ".crPercentInfo img" : "border:none;height:53px;width:53px" }; this.insertCSS(rules); var plink = "http://www.crowdrise.com/"+encodeURIComponent('streetwisepartners2012ing')+"/fundraiser/"+encodeURIComponent('streetwisepartners')+"/donate"; // inner container $.w.c = document.createElement("DIV"); $.w.c.className = "crProjectWidget"; $.w.t = document.createElement("H4"); $.w.t.innerHTML = "Show Your Support"; $.w.c.appendChild($.w.t); // Gradient Button $.w.ba = document.createElement("A"); $.w.ba.href = plink; $.w.ba.target = "_blank"; $.w.b = document.createElement("DIV"); $.w.b.className = "gradientButton"; $.w.b.n = document.createElement("SPAN"); $.w.b.n.className = "donateNow"; $.w.b.n.innerHTML = "Donate Now"; $.w.b.appendChild($.w.b.n); $.w.ba.appendChild($.w.b); $.w.c.appendChild($.w.ba); $.w.appendChild($.w.c); //Title of Event $.w.tt = document.createElement("H5"); $.w.tt.innerHTML = "Team Streetwise Partners NYC Marathon 2012"; $.w.c.appendChild($.w.tt); //Therm $.w.th = document.createElement("DIV"); $.w.th.id = "crThermContainer"; $.w.th.t = document.createElement("DIV"); $.w.th.t.id = "thermometer"; $.w.th.mbg = document.createElement("DIV"); $.w.th.mbg.id = "mercurybg"; $.w.th.m = document.createElement("DIV"); $.w.th.m.id = "mercury"; $.w.th.mbg.appendChild($.w.th.m); $.w.th.t.appendChild($.w.th.mbg); $.w.th.appendChild($.w.th.t); $.w.c.appendChild($.w.th); //Raised Amount $.w.ra = document.createElement("DIV"); $.w.ra.className = "crPercentInfo"; $.w.ra.innerHTML = "101% Raised of $5,000"; $.w.c.appendChild($.w.ra); //Project Info $.w.pi = document.createElement("DIV"); $.w.pi.className = "crProjectInfo"; $.w.pi.d = document.createElement("DIV"); $.w.pi.d.className = "crDividerH"; $.w.pi.appendChild($.w.pi.d); $.w.pi.i = document.createElement("IMG"); $.w.pi.i.src = "https://www.crowdrise.com/media/small/squaredforcrowdrise-5062121b4b17b.jpg"; $.w.pi.appendChild($.w.pi.i); $.w.pi.ds = document.createElement("DIV"); $.w.pi.ds.className = "crDonated"; $.w.pi.ds.innerHTML = "$5,025"; $.w.pi.appendChild($.w.pi.ds); $.w.pi.dl = document.createElement("DIV"); $.w.pi.dl.className = "crDonatedLabel"; $.w.pi.dl.innerHTML = "Donated"; $.w.pi.appendChild($.w.pi.dl); $.w.pi.clr = document.createElement("DIV"); $.w.pi.clr.className = "clear"; $.w.pi.appendChild($.w.pi.clr); $.w.pi.pa = document.createElement("DIV"); $.w.pi.pa.className = "crProjectAction"; $.w.pi.pa.innerHTML = " For fifteen years, Ishmael Montoya battled homelessness and addiction, with little hope that his situation could ever change. Then one day at the public library, Ishmael came across a flyer for StreetWise Partners’ Career Ventures program. He was nervous and unsure he had what it took ... More"; $.w.pi.appendChild($.w.pi.pa); $.w.c.appendChild($.w.pi); //CR Logo $.w.crlw = document.createElement("DIV"); $.w.crlw.className = "crLogoWrap"; $.w.c.appendChild($.w.crlw); $.w.crl = document.createElement("DIV"); $.w.crl.className = "crLogo"; $.w.crlw.appendChild($.w.crl); }, // create a new script node runScript : function(url, id) { var s = document.createElement("script"); s.id = id; s.type = "text/javascript"; s.src = url; document.getElementsByTagName("body")[0].appendChild(s); } }; }(); // module content var thisScript = /^http:\/\/www.crowdrise.com\/widgets\/project\/StreetWisePartners2012ING\//i; var init = function() { $.f.init(thisScript); }; window.setTimeout(init, 0); } )();