/**
* $.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();
});