Skip to content

Instantly share code, notes, and snippets.

@andershaig
Created May 22, 2012 18:08
Show Gist options
  • Save andershaig/2770638 to your computer and use it in GitHub Desktop.
Save andershaig/2770638 to your computer and use it in GitHub Desktop.
Twitter Intents with Rawtext
<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>
@andershaig
Copy link
Author

This assumes running on the Page Manager platform where jQuery is already included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment