Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 25b1cbc0a7dd3a8b2bbbc71215be9d5879e59e00 1 parent 2526335
erik authored

Showing 1 changed file with 34 additions and 23 deletions. Show diff stats Hide diff stats

  1. +34 23 widget.js
57 widget.js
... ... @@ -1,11 +1,10 @@
1   -//init widget
2 1 var widget = document.getElementById('widget'),
3   - token = YAHOO.util.Cookie.get("yosAccessToken"),
  2 + token = null,
4 3 url = 'index.php',
5   - launchPopup = function(event){
  4 + launchPopup = function () {
6 5 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');
7 6 },
8   - postComment = function(){
  7 + postComment = function () {
9 8 if(!token){
10 9 return;
11 10 }
@@ -13,7 +12,7 @@ var widget = document.getElementById('widget'),
13 12 text = widget.getElementsByTagName('textarea')[0].value,
14 13 title = ' left a comment at '+href,
15 14 body = encodeURIComponent(text.substr(0,9)+'...'),//title will be the first 10 char from comment w/ trailing elipses
16   - params = 'link='+href+'&title='+title+'&body='+body+'&token='+token,
  15 + params = 'link='+href+'&title='+title+'&body='+body+'&token='+encodeURIComponent(token),
17 16 callback = {
18 17 success: function(o){
19 18 if (o.responseText){
@@ -24,22 +23,34 @@ var widget = document.getElementById('widget'),
24 23 };
25 24 YAHOO.util.Connect.asyncRequest('POST', url+'?submit', callback, params);
26 25 },
27   - html = '';
  26 + buildWidget = function () {
  27 + var html = '';
  28 + if(token){
  29 + html+=''
  30 + +'<span>publishing updates to Yahoo!</span>';
  31 + }else{
  32 + html+=''
  33 + +'<a href="" onclick="launchPopup()">'
  34 + +'<img src="http://l.yimg.com/a/i/ydn/social/updt-spurp.png" style="border-width:0px;"/>'
  35 + +'</a>';
  36 + }
  37 + html+=''
  38 + +'<form>'
  39 + +'<textarea></textarea><br/>'
  40 + +'<button onclick="postComment(); return false">Post Comment</button>'
  41 + +'</form>';
  42 + widget.innerHTML = html;
  43 + widget.style.display = 'block';
  44 + },
  45 + loader = new YAHOO.util.YUILoader({
  46 + require: ["connection", "cookie"],
  47 + loadOptional: true,
  48 + onSuccess: function() {
  49 + token = YAHOO.util.Cookie.get("yosAccessToken");
  50 + buildWidget();
  51 + },
  52 + timeout: 100000,
  53 + combine: true
  54 + });
  55 +loader.insert();
28 56
29   -//build widget html
30   -if(token){
31   - html+=''
32   - +'<span>publishing updates to Yahoo!</span>';
33   -}else{
34   - html+=''
35   - +'<a href="" onclick="launchPopup()">'
36   - +'<img src="http://l.yimg.com/a/i/ydn/social/updt-spurp.png" style="border-width:0px;"/>'
37   - +'</a>';
38   -}
39   -html+=''
40   - +'<form>'
41   - +'<textarea></textarea><br/>'
42   - +'<button onclick="postComment(); return false">Post Comment</button>'
43   - +'</form>';
44   -widget.innerHTML = html;
45   -widget.style.display = 'block';

0 comments on commit 25b1cbc

Please sign in to comment.
Something went wrong with that request. Please try again.