Created
March 24, 2012 00:32
-
-
Save kara-ryli/2176744 to your computer and use it in GitHub Desktop.
YUI module to handle clicks on Twitter Intents
This file contains hidden or 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
YUI.add("twitter-intents",function(a){var g=/twitter\.com(\:\d{2,4})?\/intent\/(\w+)/,b=550,h=420,i="scrollbars=yes,resizable=yes,toolbar=no,location=yes,width={w},height={h},top={t},left={l}",e=a.config.win,f=e.screen.width,d=e.screen.height,c=function(k){var j=k.currentTarget.get("href");if(g.test(j)){k.halt();e.open(j,"intent",a.Lang.sub(i,{l:Math.round((f/2)-(b/2)),t:d>h?Math.round((d/2)-(h/2)):0,w:b,h:h}))}};a.namespace("Twitter").handleIntents=function(j){return a.one(j).delegate("click",c,"a")}},"3.4.1",{requires:["event-delegate","node-base"]}); |
This file contains hidden or 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
/*global YUI*/ | |
/** | |
* Allows you to handle clicks on Twitter Intents without a twitter | |
* platform dependency. | |
* | |
* based on https://dev.twitter.com/docs/intents | |
* | |
* @module twitter-intents | |
*/ | |
YUI.add("twitter-intents", function (Y) { | |
"use strict"; | |
var intentRegex = /twitter\.com(\:\d{2,4})?\/intent\/(\w+)/, | |
width = 550, | |
height = 420, | |
options = 'scrollbars=yes,resizable=yes,toolbar=no,location=yes,width={w},height={h},top={t},left={l}', | |
win = Y.config.win, | |
scrnWidth = win.screen.width, | |
scrnHeight = win.screen.height, | |
onIntentsClick = function (event) { | |
var href = event.currentTarget.get("href"); | |
if (intentRegex.test(href)) { | |
event.halt(); | |
win.open(href, "intent", Y.Lang.sub(options, { | |
l: Math.round((scrnWidth / 2) - (width / 2)), | |
t: scrnHeight > height ? Math.round((scrnHeight / 2) - (height / 2)) : 0, | |
w: width, | |
h: height | |
})); | |
} | |
}; | |
/** | |
* Attaches an event listener to handle clicks on Twitter Intents links | |
* | |
* @method handleIntents | |
* @param {String|Node} selector Node to listen for Twitter Intents on | |
* @return {EventHandle} the detach handle | |
* @namespace Twitter | |
* @static | |
*/ | |
Y.namespace("Twitter").handleIntents = function (selector) { | |
return Y.one(selector).delegate("click", onIntentsClick, "a"); | |
}; | |
}, "3.4.1", { requires: ["event-delegate", "node-base"] }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment