if(typeof _ow == "undefined" ){ _ow = {}; // stuff in here will only run the first time because we just set _ow _ow.wwwurl = "http://onlywire.com"; _ow.imagesPath = "http://onlywire.com"; _ow.token = null; // safari fix _ow.E = function(tagName) { return document.createElement(tagName); }; _ow.T = function(text) { return document.createTextNode(text); }; _ow.DOMready = (function() { var _this = {}; _this.isReady = false; _this.init = function(fn) { if(!this.isReady) { this.bindReady(fn); } else { // DOM loaded fn(); } }; _this.bindReady = function(fn) { if ( document.addEventListener ) { document.addEventListener( "DOMContentLoaded", function(){ _this.isReady = true; _this.init(fn); }, false ); } else if ( document.attachEvent ) { // IE document.attachEvent("onreadystatechange", function(){ if ( document.readyState === "complete" ) { _this.isReady = true; _this.init(fn); } }); } }; return _this; })(); _ow.getScript = function(url, jCallback, callback) { this.url = url; this.seperator = (url.match(/\?/)) ? "&" : "?"; this.jsonpCallback = "jsonp" + (new Date()).getTime(); this.jsonp = "jsonp=" + this.jsonpCallback; this.cache = "_=" + (new Date()).getTime(); this.callback = callback || function(){}; window[ this.jsonpCallback ] = function(data) { jCallback(data); }; var _this = this; // add script tag to the DOM only when the DOM is ready _ow.DOMready.init(function() { _this.makeScriptTag(); }); }; _ow.getScript.prototype = { makeScriptTag: function() { var head = document.getElementsByTagName("head")[0]; var script = document.createElement("script"); script.setAttribute("type", "text/javascript"); script.src = this.url + this.seperator + this.jsonp + "&" + this.cache; var done = false; var that = this; script.onload = script.onreadystatechange = function() { if(!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") ) { done = true; that.callback(); head.removeChild(script); } } head.appendChild(script); } }; _ow.focusTo = function (obj, selectFrom) { if (typeof selectFrom == 'undefined') selectFrom = obj.value.length if(obj.createTextRange) { if (range == 0) range = obj.createTextRange() range.moveEnd("character",obj.value.length) range.moveStart("character",selectFrom) setTimeout('range.select()', 10) } else if (obj.setSelectionRange){ //ff obj.select() obj.setSelectionRange(selectFrom,obj.value.length) } else { obj.blur() } }; _ow.class_select = function(tag) { var ctag = document.getElementById('tag_'+tag); ctag.style.cursor = "pointer"; ctag.style.color = "#000"; ctag.style.textDecoration = "none"; ctag.className = 'tag_selected'; }; _ow.class_deselect = function(tag) { var ctag = document.getElementById('tag_'+tag); ctag.style.color = "#309acc"; ctag.style.textDecoration = "underline"; ctag.style.cursor = "pointer"; ctag.className = 'tag_deselected'; }; _ow.swap = function(tag){ var mytags = document.getElementById('tags').value; var mytags_trim = mytags.replace(/^\s+|\s+$/g,''); var tagArray = mytags_trim.split(' '), present=false, t, tl=tag.toLowerCase() if (tagArray[0].replace(/^\s+|\s+$/g,'') == '') tagArray.splice(0,1); for (t=0; t 1) ? content + ' ' : content; _ow.focusTo(document.getElementById('tags')); }; _ow.getTopLeft = function(elem) { var curleft = curtop = 0; var elHeight = elem.clientHeight; var elWidth = elem.clientWidth; if(elem.offsetParent) { do { curleft += elem.offsetLeft; curtop += elem.offsetTop; } while (elem = elem.offsetParent); } var offsetTop = curtop; var offsetLeft = curleft; var height = elHeight + offsetTop; var windowWidth = (document.body.offsetWidth > document.body.scrollWidth) ? document.body.offsetWidth : document.body.scrollWidth; var windowHeight = (document.body.offsetHeight > document.body.scrollHeight) ? document.body.offsetHeight : document.body.scrollHeight; /* if offsetLeft is bigger than the 'half' of the window.innerWidth; * decrease the offsetLeft */ if(offsetLeft > windowWidth/2) { offsetLeft = offsetLeft - _ow.Popup.popupWidth + elWidth; } var popupHeight = _ow.Popup.popup.clientHeight || _ow.Popup.getClientHeight(); if(offsetTop > windowHeight/2) { height = offsetTop - popupHeight; } return [height, offsetLeft]; }; _ow.Dom = (function() { function clearChildren(nod) { while(nod.hasChildNodes()) { nod.removeChild(nod.firstChild); } return nod; } function getElementById(id) { var f; return document.getElementById(id) || (f = document.getElementsByName(id) && f[0]); } getElementById.clearChildren = clearChildren; return getElementById; })(); _ow.Event = { stop: function(e) { if (!e) var e = window.event; e.cancelBubble = true; if(e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } if (e.stopPropagation) e.stopPropagation(); } ,stopPropagation: function(e) { if (!e) var e = window.event; e.cancelBubble = true; if (e.stopPropagation) e.stopPropagation(); } }; _ow.Box = function(val){ var success = function() { _ow.Dom.clearChildren(_ow.Popup.popup); // clear the popup var divCont = _ow.E("div"); divCont.appendChild(_ow.Template.genHeader(1)); var div = document.createElement("div"); div.className = "success"; div.style.position = "relative"; div.style.background = "url(\""+_ow.wwwurl+"/onlywire_button/images/success.png\") no-repeat"; div.style.width = "372px"; div.style.height = "40px"; div.style.margin = "10px"; var span = document.createElement("span"); span.style.color = "#65666a"; span.style.position = "absolute"; span.style.top = "13px"; span.style.left = "55px"; span.style.fontSize = "11px"; span.style.fontWeight = "bold"; if(typeof val == "string") { var textNode = document.createTextNode(val); span.appendChild(textNode); } else { span.appendChild(val); } div.appendChild(span); divCont.appendChild(div); _ow.Popup.popup.appendChild(divCont); }; return { success: success }; }; _ow.Auth = (function(){ var pub = {}; pub.authData = null; pub.init = function(){ var params = "url="+encodeURIComponent(window.location.href); if(_ow.token) params += "&token="+encodeURIComponent(_ow.token); new _ow.getScript(_ow.wwwurl+"/widget/getWidgetData?"+params, function(data) { pub.authData = data; _ow.Template.init(); _ow.Popup.init(); }); }; // important IE6 fix if(window.addEventListener) { pub.init(); } else { window.attachEvent("onload", function(){ pub.init(); }); } pub.isLoggedIn = function() { if(pub.authData.error) { return false; } else { return true; } }; return pub; })(); _ow.Submit = function(obj) { this.obj = obj; // obj of elements }; _ow.Submit.prototype._analCheck = function(el) { if(el.nodeName == "INPUT") { if(el.checked) { return el.value; } else { return ""; } } var string = ""; var count = 0; for(var i=0; i0) string += ","; string += el[i].value; count++; } } return string; }; _ow.Submit.prototype.bookmark = function(bookList) { var self = this; var services = this._analCheck(bookList); var servicesLength = services.split(",").length; if(this.obj.tags.value == "space separated" || this.obj.tags.value == ""){ this.obj.tags.value = "onlywire"; } if(this.obj.url.value == "") { alert("URL field cant be blank"); return; } new _ow.getScript(_ow.wwwurl+'/widget/save?title='+encodeURIComponent(this.obj.title.value)+'&url='+encodeURIComponent(this.obj.url.value)+'&tags='+this.obj.tags.value+'&private='+this.obj.priv.checked+'&c='+this.obj.notes.value+'&service='+services+'&token='+(_ow.token ? encodeURIComponent(_ow.token): ''), function(data) { var span = _ow.E("span"); //span.appendChild(_ow.T("Your bookmark has been posted. Some services require 1 extra step, ")); //var link = _ow.E("a"); //link.href="#"; //link.onclick = function(e) { // _ow.Event.stop(e); // window.open(_ow.wwwurl+"/home"); //}; //link.appendChild(_ow.T("click here")); //link.style.color = "#309acc"; //span.appendChild(link); span.appendChild(_ow.T("Done! We'll send you an email shortly when your bookmark has been posted.")); span.style.display = "block"; span.style.marginLeft = "-4px"; span.style.marginTop = "-5px"; _ow.Box(span).success(); /* box = new boxes("", "https://onlywire.com/home"); box.success(); */ }); }; _ow.Submit.prototype.share = function() { var self = this; /* get title/url from url*/ var title = encodeURIComponent(_ow.Popup.fieldsToUpdate.title.value); var url = encodeURIComponent(_ow.Popup.fieldsToUpdate.url.value); /* validation */ if(this.obj.from.value == "") { alert("From email cant be blank"); return; } else { var validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i; if(this.obj.from.value.search(validRegExp) == -1) { alert("Invalid e-mail address"); return; } } if(this.obj.to.value == "comma separated" || this.obj.to.value == "") { alert("To email cant be blank"); return; } var numEmails = this.obj.to.value.split(",").length; new _ow.getScript(_ow.wwwurl+'/widget/sendemail?from='+encodeURIComponent(this.obj.from.value)+'&to='+encodeURIComponent(this.obj.to.value)+'&message='+encodeURIComponent(this.obj.message.value)+'&title='+title+'&url='+url, function(data) { _ow.Box("Your email has been sent.").success(); }); }; _ow.Submit.prototype.signup = function() { var self = this; new _ow.getScript(_ow.wwwurl+'/widget/signup?subscription=free&cardnumber=&cvv=&mm=-1&yy=-1&zip=&cardname=&cardtype=&username='+this.obj.username.value+'&email='+this.obj.email.value+'&m='+this.obj.password.value+'&captcha_code='+this.obj.captcha_code.value+'&industry=Button', function(data) { if(data == "Success") { self.signin({ username: { value: self.obj.username.value}, password: { value: self.obj.password.value} }); } else { alert(data); } }); /* new Ajax.Request( '/signupform', { method: 'post', parameters: 'subscription=free&cardnumber=&cvv=&mm=-1&yy=-1&zip=&cardname=&cardtype=&username='+this.obj.username.value+'&email='+this.obj.email.value+'&m='+password+'&captcha_code='+this.obj.captcha_code.value+'&industry=Button&ajax=1&rand='+rand(), onComplete: function(request) { var return_response = request.responseText; if (strtrim(return_response) == 'Success') { self.signin({ username: { value: self.obj.username.value}, password: { value: password} }); } else { alert(return_response); self.obj.username.focus(); } } } ); */ }; _ow.Submit.prototype.signin = function(obj) { var self = this; if(obj) this.obj = obj; new _ow.getScript(_ow.wwwurl+'/widget/login?username='+this.obj.username.value+'&m='+this.obj.password.value, function(data) { if(data.response == "Success") { _ow.token = data.token; _ow.Auth.init(); } else { alert(data.response); } }); }; _ow.Template = (function(){ var pub = {}; pub.homepage = null; pub.bookmark = null; pub.share = null; pub.init = function() { pub.homepage = pub.genHomepage(); pub.bookmark = pub.genBookmark(); pub.share = pub.genShare(); pub.signup = pub.genSignup(); pub.signin = pub.genSignin(); //add other stuff for each page }; pub.genTitle = function(text) { var div = document.createElement("div"); div.style.background = "url(\""+_ow.wwwurl+"/onlywire_button/images/powered.png\") no-repeat right top"; div.style.height = "22px"; div.style.color = "#6699cc"; div.style.fontSize = "13px"; div.style.fontWeight = "bold"; div.style.margin = "10px"; div.style.cursor = "pointer"; div.onclick = function() { window.open("http://www.onlywire.com"); }; div.appendChild(document.createTextNode(text)); return div; }; pub.genRound = function(text, linkText, url) { var div = document.createElement("div"); div.style.position = "relative"; div.style.height = "21px"; div.style.width = "394px"; div.style.background = "url(\""+_ow.wwwurl+"/onlywire_button/images/round.png\") no-repeat top left"; div.style.fontSize = "10px" div.style.marginLeft = "6px"; var inDiv = document.createElement("div"); inDiv.style.position = "absolute"; inDiv.style.left = "10px"; inDiv.style.top = "3px"; inDiv.appendChild(document.createTextNode(text)); if (linkText) { var a= document.createElement("a"); a.style.position = "absolute"; a.style.top = "3px"; a.style.right = "10px"; a.style.color = "#309acc"; a.href = "#"; a.onclick = function() { window.open(url); return false; } a.appendChild(document.createTextNode(linkText)); div.appendChild(a); } div.appendChild(inDiv); return div; }; pub.genHeader = function(num) { var ul = document.createElement("ul"); ul.style.height = "31px"; ul.style.background = "url(\""+_ow.wwwurl+"/onlywire_button/images/header_bg.png\") repeat-x"; ul.style.padding = "0px"; ul.style.margin = "0px"; ul.style.borderBottom = "3px #72afdb solid"; var numLi = 2; for(var i=0, li, a, span; i"); } catch(err) { var inputItem = document.createElement("input"); } inputItem.setAttribute("id", labelId); inputItem.style.verticalAlign = "middle"; inputItem.style.marginRight = "3px"; inputItem.type = "checkbox"; inputItem.value = item.pk_id; inputItem.checked = "true"; imgItem = document.createElement("img"); imgItem.style.verticalAlign = "middle"; imgItem.style.marginRight = "3px"; imgItem.src = _ow.imagesPath+"/i/"+item.small_icon; if(_ow.Auth.isLoggedIn()) { divItem.appendChild(inputItem); } labelItem.appendChild(imgItem); if(_ow.Auth.isLoggedIn()) { labelItem.appendChild(document.createTextNode(item.name)); } else { var aLink = document.createElement("a"); aLink.style.color = "#000"; var postLink = item.post_link; aLink.href = postLink; aLink.setAttribute("post_link", postLink); if(_ow.Auth.isLoggedIn()) { aLink.setAttribute("title", "Auto submission not yet supported, coming soon!"); } aLink.setAttribute("rel", "external"); aLink.setAttribute("target", "_blank"); aLink.style.textDecoration = "underline"; aLink.appendChild(document.createTextNode(item.name)); if(!postLink) { labelItem.appendChild(document.createTextNode(item.name)); } else { labelItem.appendChild(aLink); } } divItem.appendChild(labelItem); div.appendChild(divItem); // add it to the self self.elements.push(inputItem); } self.list = div; return self; }; pub.genWrapper = function() { var div = document.createElement("div"); div.fontSize = "10px"; div.color = "#000"; div.style.margin = "10px"; div.style.textAlign = "center"; div.style.position = "relative"; return div; }; pub.genWrapContent = function() { var div = document.createElement("div"); div.style.marginTop = "10px"; div.style.textAlign = "center"; div.appendChild(document.createTextNode("By signing up, you agree to the ")); var terms = document.createElement("a"); terms.style.color = "#309acc"; terms.appendChild(document.createTextNode("Terms of service")); terms.href="#"; terms.onclick = function() { window.open("http://www.onlywire.com/terms"); return false; } var privacy = document.createElement("a"); privacy.style.color = "#309acc"; privacy.href="#"; privacy.onclick = function() { window.open("http://www.onlywire.com/terms"); return false; } privacy.appendChild(document.createTextNode("Privacy Policy.")); div.appendChild(terms); div.appendChild(document.createTextNode(" and ")); div.appendChild(privacy); return div; }; pub.genInfo = function(text) { var div = document.createElement("div"); div.style.border = "1px solid #ffcc00"; div.style.backgroundColor = "#FDED8B"; div.style.color = "#000"; div.style.fontWeight = "bold"; div.style.width = "192px"; div.style.height = "42px"; div.style.fontSize = "10px"; div.style.position = "absolute"; div.style.top = "10px"; div.style.right = "10px"; var span = document.createElement("span"); span.style.position = "absolute"; span.style.top = "8px"; span.style.left = "8px"; span.appendChild(document.createTextNode(text)) var div2 = document.createElement("div"); div2.style.position = "absolute"; div2.style.top = "42px !important"; div2.style.top = "40px"; div2.style.right = "10px"; div2.style.width = "8px"; div2.style.height = "15px"; div2.style.background = "url(\""+_ow.wwwurl+"/onlywire_button/images/arrow.gif\") no-repeat"; div.appendChild(div2); div.appendChild(span); return div; }; pub.genTags = function(tags) { var div = document.createElement("div"); div.style.cssText = "expression(this.scrollHeight > 49? '50px' : 'auto');"; div.style.position = "relative"; div.style.overflow = "auto"; div.style.background = "none"; div.style.maxHeight = "50px"; for(var i=0; iSign In", type: span }, { id: "username", left: "Username", value: "", type: "input" }, { id: "password", left: "Password", value: "", type: "input_password" }, { id: "email", left: "Email", value: "", type: "input" }, { id: "0", left: "", value: "", type: img }, { id: "captcha_code", left: "Enter Code", value: "", type: "input" } ]; var wrap = this.genWrapper(); var table = this.genTable(content); wrap.appendChild(table.table); wrap.appendChild(this.genWrapContent()); div.appendChild(wrap); var button = this.genButton("Sign Up", function(){ var submit = new _ow.Submit(table.elements); submit.signup(); }); div.appendChild(this.genFooter(button)); return div; }; pub.genSignin = function() { var div = _ow.E("div"); div.appendChild(this.genHeader(0)); div.appendChild(this.genTitle("Sign In")); div.appendChild(this.genRound("To bookmark content, first sign in")); var span = document.createElement("span"); var link = document.createElement("a"); link.style.color = "#309acc"; link.href = "#"; link.appendChild(document.createTextNode("Sign up")); link.onclick = function() { _ow.Popup.loadSignup(); return false; } var forgot = document.createElement("a"); forgot.style.color = "#309acc"; forgot.href = "#"; forgot.appendChild(document.createTextNode("Forgot password?")); forgot.onclick = function() { window.open(_ow.wwwurl+"/forgotpassword"); return false; } span.appendChild(document.createTextNode("New to OnlyWire? ")); span.appendChild(link); var content = [ { id: "0", left: "", value: "", type: span }, { id: "username", left: "Username", value: "", type: "input" }, { id: "password", left: "Password", value: "", type: "input_password" }, { id: "0", left: "", value: "Forgot password?", type: forgot } ]; var wrap = this.genWrapper(); var table = this.genTable(content); wrap.appendChild(table.table); div.appendChild(wrap); var button = this.genButton("Sign In", function(){ var submit = new _ow.Submit(table.elements); submit.signin(); }); div.appendChild(this.genFooter(button)); return div; }; return pub; })(); _ow.Popup = (function(){ var pub = {}; pub.popup = null; pub.currentTag = null; pub.fieldsToUpdate = {}; pub.popupHeight = 200; pub.popupWidth = 408; pub.init = function() { // generate popup only if we dont have the popup (for login process) if(!this.popup) { pub.popup = pub.genPopup(); document.body.appendChild(pub.popup); document.onclick = function() { _ow.Popup.hide(); }; } if(_ow.Auth.isLoggedIn()) { this.updateFields(); this.loadBookmark(); } else { this.loadHomepage(); } }; pub.show = function(button) { if(!this.popup) return; // return if its not created yet var topLeft = _ow.getTopLeft(button); this.popup.style.display = "block"; this.popup.style.top = topLeft[0]+"px"; this.popup.style.left = topLeft[1]+"px"; this.updateFields(); }; pub.hide = function(button) { this.popup.style.display = "none"; }; pub.updateFields = function() { //update fields given this.currentTag if(!this.currentTag) return; var title = this.currentTag.getAttribute("title") || window.document.title; var url = this.currentTag.getAttribute("url") || window.location.href; var tags = this.currentTag.getAttribute("tags") || "space separated"; this.fieldsToUpdate.title.value = title; this.fieldsToUpdate.url.value = url; this.fieldsToUpdate.tags.value = tags; for(var i=0, link; i