Skip to content
Browse files

now initializing widget via yui loader so we don't try to init before…

… libs are ready. now encoding token so we can pass it in post
  • Loading branch information...
1 parent 2526335 commit 25b1cbc0a7dd3a8b2bbbc71215be9d5879e59e00 erik committed Jul 17, 2009
Showing with 34 additions and 23 deletions.
  1. +34 −23 widget.js
View
57 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){
@@ -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.
Something went wrong with that request. Please try again.