Skip to content
This repository has been archived by the owner on Apr 18, 2019. It is now read-only.

Commit

Permalink
now initializing widget via yui loader so we don't try to init before…
Browse files Browse the repository at this point in the history
… libs are ready. now encoding token so we can pass it in post
  • Loading branch information
erik committed Jul 17, 2009
1 parent 2526335 commit 25b1cbc
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions widget.js
@@ -1,19 +1,18 @@
//init widget
var widget = document.getElementById('widget'),
token = YAHOO.util.Cookie.get("yosAccessToken"),
token = null,
url = 'index.php',
launchPopup = function(event){
launchPopup = function () {
window.open(url+'?auth', 'auth', 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,width=800,height=650,left=450,top=250');
},
postComment = function(){
postComment = function () {
if(!token){
return;
}
var href = encodeURIComponent(document.location.href),
text = widget.getElementsByTagName('textarea')[0].value,
title = ' left a comment at '+href,
body = encodeURIComponent(text.substr(0,9)+'...'),//title will be the first 10 char from comment w/ trailing elipses
params = 'link='+href+'&title='+title+'&body='+body+'&token='+token,
params = 'link='+href+'&title='+title+'&body='+body+'&token='+encodeURIComponent(token),
callback = {
success: function(o){
if (o.responseText){
Expand All @@ -24,22 +23,34 @@ var widget = document.getElementById('widget'),
};
YAHOO.util.Connect.asyncRequest('POST', url+'?submit', callback, params);
},
html = '';
buildWidget = function () {
var html = '';
if(token){
html+=''
+'<span>publishing updates to Yahoo!</span>';
}else{
html+=''
+'<a href="" onclick="launchPopup()">'
+'<img src="http://l.yimg.com/a/i/ydn/social/updt-spurp.png" style="border-width:0px;"/>'
+'</a>';
}
html+=''
+'<form>'
+'<textarea></textarea><br/>'
+'<button onclick="postComment(); return false">Post Comment</button>'
+'</form>';
widget.innerHTML = html;
widget.style.display = 'block';
},
loader = new YAHOO.util.YUILoader({
require: ["connection", "cookie"],
loadOptional: true,
onSuccess: function() {
token = YAHOO.util.Cookie.get("yosAccessToken");
buildWidget();
},
timeout: 100000,
combine: true
});
loader.insert();

//build widget html
if(token){
html+=''
+'<span>publishing updates to Yahoo!</span>';
}else{
html+=''
+'<a href="" onclick="launchPopup()">'
+'<img src="http://l.yimg.com/a/i/ydn/social/updt-spurp.png" style="border-width:0px;"/>'
+'</a>';
}
html+=''
+'<form>'
+'<textarea></textarea><br/>'
+'<button onclick="postComment(); return false">Post Comment</button>'
+'</form>';
widget.innerHTML = html;
widget.style.display = 'block';

0 comments on commit 25b1cbc

Please sign in to comment.