Created
May 22, 2012 18:08
-
-
Save andershaig/2770638 to your computer and use it in GitHub Desktop.
Twitter Intents with Rawtext
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
<button id="tweet_button">Click to Tweet</button> | |
<script type="text/javascript"> | |
{% plugin rawtext tweet_url %} | |
{% plugin rawtext tweet_text %} | |
{% plugin rawtext tweet_hashtags %} | |
var params = {}; | |
// Note: until we get support for escaping single quotes, they can't be used in the message. | |
{% if tweet_url %} | |
params.url = {{ tweet_url | json }}; | |
{% endif %} | |
{% if tweet_text %} | |
params.text = {{ tweet_text | json }}; | |
{% endif %} | |
{% if tweet_hashtags %} | |
params.hashtags = {{ tweet_hashtags | json }}; | |
{% endif %} | |
var intent_url = 'https://twitter.com/intent/tweet?' + $.param(params); | |
$('#tweet_button').click( function (e) { | |
e.preventDefault(); | |
window.open(intent_url, 'tweet_intent'); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This assumes running on the Page Manager platform where jQuery is already included.