Created
July 21, 2008 23:54
-
-
Save GuyLewin/472 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compress_url: | |
function () { | |
var currentPos = 0; | |
while ($('status').value.indexOf("http://", currentPos) != -1) | |
{ | |
var firstPosition = $('status').value.indexOf("http://", currentPos); | |
var endPosition = $('status').value.indexOf(" ", firstPosition); | |
if (endPosition == -1) { | |
if ($('status').value.charAt(document.getElementById('status').selectionEnd - 1) == '.') { | |
var endPosition = document.getElementById('status').selectionEnd - 1; | |
} | |
else | |
{ | |
var endPosition = document.getElementById('status').selectionEnd; | |
} | |
} else if ($('status').value.charAt($('status').value.indexOf(" ", firstPosition) - 1) == '.') { | |
endPosition = $('status').value.indexOf(" ", firstPosition) - 1; | |
} | |
var selection = $('status').value.substring(firstPosition, endPosition); | |
if ( selection.length == 0 ) { | |
return; | |
} | |
var url = "http://is.gd/api.php?longurl="+selection; | |
var aj = new Ajax( url, | |
{ method: 'get', | |
onSuccess: | |
function (replaced) { | |
var selection = document.getElementById('status').value.substring(document.getElementById('status').selectionStart, document.getElementById('status').selectionEnd); | |
var text = document.getElementById('status').value.substring(0,Tweetbar.compress_url.firstPosition) + replaced + (selection.length==selection.trim().length?"":" ")+ document.getElementById('status').value.substring(Tweetbar.compress_url.endPosition); | |
document.getElementById('status').value=text; | |
}, | |
}).request(); | |
var currentPos = endPosition; | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment