Changeset 38912

Show
Ignore:
Timestamp:
05/05/11 21:01:10 (2 years ago)
Author:
NeoCat
Message:

resolve_url.js: Use xds.load instead of loadXDomainScript

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • websites/twicli/plugins/resolve_url.js

    r38828 r38912  
    33  var re = /^http:\/\/(t\.co|tinyurl\.com|bit\.ly|is\.gd|u\.nu|icio\.us|tr\.im|cli\.gs|twurl\.nl|url\.ie|j\.mp|ow\.ly|ff\.im|digg\.com|tumblr\.com|htn\.to|goo\.gl)\/|http:\/\/p\.tl\/(?!.\/)/; 
    44  var api = 'http://atsushaa.appspot.com/untiny/get'; 
    5   var queue = []; 
    6   var wait = 10000; 
    75  var remove = function(e){if (e && e.parentNode) e.parentNode.removeChild(e)}; 
    86 
    9   window.replaceUrl = function(hash) { 
     7  window.replaceUrl = function(hash, link) { 
    108    for (var shortUrl in hash) if (hash.hasOwnProperty(shortUrl)) { 
    119      var longUrl = hash[shortUrl]; 
     
    2220      } 
    2321 
    24       // search for a link with the shortUrl 
    25       var n = queue.length, task; 
    26       while (task = queue[--n]) if (task.link.href === shortUrl) { 
    27         var link = task.link; 
    28         // replace link href and text with longUrl 
    29         link.href = longUrl; 
    30         if (link.textContent === shortUrl) { 
    31           link.textContent = truncated; 
    32         } else if (link.innerText === shortUrl) { 
    33           link.innerText = truncated; 
    34         } 
    35         link.className += ' resolved'; 
    36         // cleanup 
    37         clearTimeout(task.timer); 
    38         remove(task.script); 
    39         queue.splice(n,1); 
    40         // notify to other plugins 
    41         if (link.parentNode && link.parentNode.parentNode) 
    42           callPlugins("replaceUrl", link.parentNode.parentNode, link, longUrl, shortUrl); 
     22      link.href = longUrl; 
     23      if (link.textContent === shortUrl) { 
     24        link.textContent = truncated; 
     25      } else if (link.innerText === shortUrl) { 
     26        link.innerText = truncated; 
    4327      } 
     28      link.className += ' resolved'; 
     29      // notify to other plugins 
     30      if (link.parentNode && link.parentNode.parentNode) 
     31        callPlugins("replaceUrl", link.parentNode.parentNode, link, longUrl, shortUrl); 
    4432    } 
    4533  } 
     
    4735  function setResolver(link) { 
    4836    // JSONP with callback window.replaceUrl 
    49     var src = api + '?callback=replaceUrl&url=' + encodeURIComponent(link.href); 
    50     var script = loadXDomainScript(src); 
    51  
    52     // cleanup if JSONP doesn't load in time 
    53     var timer = setTimeout(function(){ 
    54       var n = queue.length; 
    55       while (n--) if (task === queue[n]) { 
    56         queue.splice(n,1); 
    57         remove(task.script); 
    58       } 
    59     }, wait); 
    60     var task = {link:link, script:script, timer:timer}; 
    61     queue.push(task); 
     37    var src = api + '?url=' + encodeURIComponent(link.href); 
     38    var script = xds.load(src, function(hash){replaceUrl(hash, link)}, null, 0); 
    6239  } 
    6340