Created
August 16, 2011 10:50
-
-
Save Takazudo/1148841 to your computer and use it in GitHub Desktop.
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
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
<!-- load this in head | |
<script src="http://platform.twitter.com/widgets.js"></script> | |
--> | |
<a | |
href="https://twitter.com/intent/tweet" | |
class="js-twttrintent" | |
data-intent-text="The quick brown fox jumps over the lazy dog." | |
data-intent-url="http://example.com" | |
data-intent-hashtags="hoge,foo" | |
> | |
TWEEEEEEETTTT | |
</a> | |
<p>* note: This does not work on jsfiddle because of x-frame-options. </p> |
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
/** | |
* $.fn.twttrintent | |
* https://gist.github.com/1148841 | |
* http://jsfiddle.net/gh/gist/jQuery/1.6.2/1148841/ | |
* see following about intent api | |
* https://dev.twitter.com/docs/intents | |
*/ | |
$.fn.twttrintent = function(options){ | |
function attachDataVal($el, attrKey, finalKey, obj){ | |
var val = $el.data(attrKey); | |
if (val === undefined){ | |
return obj; | |
} | |
obj[finalKey] = val; | |
return obj; | |
} | |
return this.each(function(){ | |
var $el = $(this); | |
var dataVals = {}; | |
attachDataVal($el, 'intentText', 'text', dataVals); | |
attachDataVal($el, 'intentUrl', 'url', dataVals); | |
attachDataVal($el, 'intentHashtags', 'hashtags', dataVals); | |
var data = $.extend({}, options, dataVals); | |
var paramstr = $.param(data); | |
$el.attr('href', $el.attr('href') + '?' + paramstr); | |
}); | |
}; | |
/* fire */ | |
$(function(){ | |
// twitter intent | |
$('.js-twttrintent').twttrintent(); | |
}); |
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
name: $.fn.twttrintent | |
description: post to twitter using twitter intent api http://jsfiddle.net/gh/gist/jQuery/1.6.2/1148841/ https://gist.github.com/1148841 | |
authors: | |
- Takeshi Takatsudo | |
normalize_css: no |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment