| 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; |
| 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); |