aboutsummaryrefslogtreecommitdiffstats
path: root/app/assets/javascripts
diff options
context:
space:
mode:
authorre4k <re4k@re4k.info>2013-03-28 15:38:20 +0900
committerre4k <re4k@re4k.info>2013-03-28 15:38:20 +0900
commit61087e2460e60b08b554b600cdebc6efb2456dd6 (patch)
tree50c9288ae16e0a1934f071ceb4c70a75121445ef /app/assets/javascripts
parent295db76b7643868456eafb98cf760a5e383b41ed (diff)
downloadaclog-61087e2460e60b08b554b600cdebc6efb2456dd6.tar.gz
Add Twitter Web Intents
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r--app/assets/javascripts/twitter.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/app/assets/javascripts/twitter.js b/app/assets/javascripts/twitter.js
new file mode 100644
index 0000000..05993f2
--- /dev/null
+++ b/app/assets/javascripts/twitter.js
@@ -0,0 +1,43 @@
+(function() {
+ if (window.__twitterIntentHandler) return;
+ var intentRegex = /twitter\.com(\:\d{2,4})?\/intent\/(\w+)/,
+ windowOptions = 'scrollbars=yes,resizable=yes,toolbar=no,location=yes',
+ width = 550,
+ height = 420,
+ winHeight = screen.height,
+ winWidth = screen.width;
+
+ function handleIntent(e) {
+ e = e || window.event;
+ var target = e.target || e.srcElement,
+ m, left, top;
+
+ while (target && target.nodeName.toLowerCase() !== 'a') {
+ target = target.parentNode;
+ }
+
+ if (target && target.nodeName.toLowerCase() === 'a' && target.href) {
+ m = target.href.match(intentRegex);
+ if (m) {
+ left = Math.round((winWidth / 2) - (width / 2));
+ top = 0;
+
+ if (winHeight > height) {
+ top = Math.round((winHeight / 2) - (height / 2));
+ }
+
+ window.open(target.href, 'intent', windowOptions + ',width=' + width +
+ ',height=' + height + ',left=' + left + ',top=' + top);
+ e.returnValue = false;
+ e.preventDefault && e.preventDefault();
+ }
+ }
+ }
+
+ if (document.addEventListener) {
+ document.addEventListener('click', handleIntent, false);
+ } else if (document.attachEvent) {
+ document.attachEvent('onclick', handleIntent);
+ }
+ window.__twitterIntentHandler = true;
+}());