function OWButton(el, stag) { this.iframeUrl = "http://www.onlywire.com/owbutton.php"; this.el = el; // the button that you click on this.stag = stag; // the script tag we are using this.divWidth = 408; this.divHeight = 640; if(OWButton.loadedWithSTag != this.stag) { if(OWButton.div) OWButton.div.style.display = "none"; this.loadIframe(); } else { if(OWButton.div.style.display == "") { OWButton.div.style.display = "none"; }else{ OWButton.div.style.display = ""; } } } /* static stuff */ OWButton.loadedWithSTag = false; OWButton.div = ""; OWButton.prototype._workIframe = function(iframe) { iframe.src = this.iframeUrl + this.generateParams(); iframe.style.width = this.divWidth+"px"; iframe.style.height = this.divHeight+"px"; iframe.style.position = "absolute"; iframe.style.top = "0"; iframe.style.left = "0"; iframe.onreadystatechange = function() { OWButton.div.style.background = "none"; OWButton.div.firstChild.style.display = "none"; } iframe.onload = function() { OWButton.div.style.background = "none"; OWButton.div.firstChild.style.display = "none"; } iframe.setAttribute("frameBorder", 0); iframe.setAttribute("allowTransparency", "true"); iframe.setAttribute("border", 0); iframe.setAttribute("scrolling", "no"); } OWButton.prototype._workDiv = function() { OWButton.div.style.position = "absolute"; /* figure out top/left depending on this.el */ var topLeft = this.getTopLeft(); OWButton.div.style.top = topLeft[0]+"px"; OWButton.div.style.left = topLeft[1]+"px"; OWButton.div.style.zIndex = "1000020"; OWButton.div.style.width = this.divWidth+"px"; OWButton.div.style.height = "50px"; OWButton.div.style.background = "#fff"; var spanny = document.createElement("span"); spanny.style.fontSize = "20px"; spanny.style.textAlign = "center"; spanny.style.paddingTop = "20px"; var text = document.createTextNode("Loading..."); spanny.appendChild(text); OWButton.div.appendChild(spanny); } OWButton.prototype._workCloseButton = function(el) { el.style.width = "50px"; el.style.position = "absolute"; el.style.top = "16px"; el.style.left = "355px"; el.style.cursor = "pointer"; el.style.color = "#309acc"; el.style.fontSize = "10px"; el.style.fontFamily = "verdana"; el.innerHTML = "Close X"; var self = this; el.onclick = function() { new OWButton("", self.stag); } } OWButton.prototype.generateParams = function() { /* first check if the script tag has the values (title, url, tags) */ var scriptTag = this.stag; var title = ""; var url = ""; var tags = ""; var ad = ""; if(scriptTag.getAttribute("title")) { title = scriptTag.getAttribute("title"); } else { title = window.document.title; } if(scriptTag.getAttribute("url")) { url = scriptTag.getAttribute("url"); } else { url = window.location.href; } if(scriptTag.getAttribute("tags")) { tags = "&tags=" + encodeURIComponent(scriptTag.getAttribute("tags")); } if(scriptTag.getAttribute("ad")) { ad = "&ad=yes"; } return "?title=" + encodeURIComponent(title) + "&url=" + encodeURIComponent(url) + "&absurl=" + encodeURIComponent(window.location.href) + tags + ad; } OWButton.prototype.getTopLeft = function() { var curleft = curtop = 0; var elHeight = this.el.clientHeight; var elWidth = this.el.clientWidth; if(this.el.offsetParent) { do { curleft += this.el.offsetLeft; curtop += this.el.offsetTop; } while (this.el = this.el.offsetParent); } var offsetTop = curtop; var offsetLeft = curleft; var height = elHeight + offsetTop; /* if offsetLeft is bigger than the 'half' of the window.innerWidth; * decrease the offsetLeft */ //alert(window.innerWidth); //alert(document.body.offsetWidth); var windowWidth = document.body.offsetWidth; if(offsetLeft > windowWidth/2) { offsetLeft = offsetLeft - this.divWidth + elWidth; } return [height, offsetLeft]; } OWButton.prototype.loadIframe = function() { OWButton.div = document.createElement("div"); var iframe = document.createElement("iframe"); var closeButton = document.createElement("div"); /*FIXME*/ this._workDiv(); this._workIframe(iframe); this._workCloseButton(closeButton); OWButton.div.appendChild(iframe); OWButton.div.appendChild(closeButton); document.body.appendChild(OWButton.div); OWButton.loadedWithSTag = this.stag; } OWButton.createButton = function(stag) { var button = document.createElement("div"); button.style.display = "inline-block"; button.style.cursor = "pointer"; button.style.textTransform = "uppercase"; button.style.fontSize = "10px"; button.style.height = "22px"; button.style.width = "145px"; button.style.color = "#309acc"; button.style.background = "url(http://www.onlywire.com/i/buttons/145x22_1.png) no-repeat"; button.style.position = "relative"; button.onclick = function() { new OWButton(this, stag); } return button; } OWButton.createIframeLog = function() { var tempIFrame=document.createElement('iframe'); tempIFrame.style.border='0px'; tempIFrame.style.width='0px'; tempIFrame.style.height='0px'; tempIFrame.src = "http://www.onlywire.com/buttonlog?url="+encodeURIComponent(window.location.href)+"&served=1&clicked=0&bookmarked=0&shared=0"; return tempIFrame; } OWButton.load = function() { var stags = document.getElementsByTagName("script"); var sarray = []; // loop through all the tags in the page, and push to an array // only the ones with className "owbutton", if no className push // the ones with id "owbutton" for(var i=0; i< stags.length; i++) { // gotta skip all the script tags in the queue // only do this for the last script tag in the stags array var stag = stags[i]; if(stag.className == "owbutton") { sarray.push(stag); } else if (stag.id == "owbutton") { sarray.push(stag); } } var lastTag = sarray[sarray.length - 1]; lastTag.parentNode.insertBefore(OWButton.createButton(lastTag), lastTag); lastTag.parentNode.insertBefore(OWButton.createIframeLog(), lastTag); } OWButton.load();