Created
September 23, 2013 21:27
-
-
Save micronax/6677196 to your computer and use it in GitHub Desktop.
Eine URL in einem HTML-Input bei Änderung automatisch in ein Bit.ly Kurzlink umwandeln. Dieses Snippet nutzt jQuery. Support unter: http://www.fabian-golle.de----Transform a url in a given html-input into a bit.ly shortlink using jQuery.
This file contains 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
/** | |
* Auto Shorten URLs in a given text-input | |
* @author Fabian Golle <me@fabian-golle.de> | |
**/ | |
jQuery(document).ready(function() { | |
var yourInput = $('#yourInputField'); | |
var yourApiLogin = '__INSERT_YOUR_LOGIN_HERE'; // Get your API Credentials here: | |
var yourApiKey = '_INSERT_YOUR_API_KEY_HERE'; // https://bitly.com/a/settings/advanced | |
yourInput.change(function() { | |
var theURL = yourInput.val(); | |
yourInput.fadeTo(0.7); | |
jQuery.getJSON( | |
"http://api.bitly.com/v3/shorten?callback=?", | |
{ | |
"format": "json", | |
"apiKey": yourApiKey, | |
"login": yourApiLogin, | |
"longUrl": yourInput.val() | |
}, | |
function(response) { | |
if ('url' in response.data) { | |
yourInput.val(response.data.url); | |
yourInput.fadeTo(1.0); | |
} | |
} | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment