1// Generated by CoffeeScript 1.8.0 2 3/*! 4* jQuery POP'n SocialButton v0.1.9 5* 6* http://github.com/ktty1220/jquery.popn-socialbutton 7* 8* åèãµã¤ã 9* 10* - http://q.hatena.ne.jp/1320898356 11* - http://stackoverflow.com/questions/5699270/how-to-get-share-counts-using-graph-api 12* - http://stackoverflow.com/questions/8853342/how-to-get-google-1-count-for-current-page-in-php 13* - http://hail2u.net/blog/coding/jquery-query-yql-plugin.html 14* - http://hail2u.net/blog/coding/jquery-query-yql-plugin-supports-open-data-tables.html 15* - http://www.absolute-keitarou.net/blog/?p=1068 16* 17* Copyright (c) 2013 ktty1220 [email protected] 18* Licensed under the MIT license 19 */ 20 21(function() { 22 (function(jQuery) { 23 'use strict'; 24 var $; 25 $ = jQuery; 26 return $.fn.popnSocialButton = function(services, options) { 27 var exOptions, iconSize, idx, mkYQL, popnUp, sName, scheme, servicesProp, _addLink, _i, _len; 28 if (options == null) { 29 options = {}; 30 } 31 exOptions = $.extend({}, { 32 url: document.location.href, 33 text: $('title').html(), 34 imgDir: './img', 35 buttonSpace: 24, 36 countPosition: { 37 top: 32, 38 right: -12 39 }, 40 countColor: { 41 text: '#ffffff', 42 bg: '#cc0000', 43 textHover: '#ffffff', 44 bgHover: '#ff6666', 45 border: '#ffffff' 46 }, 47 countSize: 11, 48 popupWindow: { 49 width: 640, 50 height: 480 51 } 52 }, options); 53 exOptions.urlOrg = exOptions.url; 54 exOptions.url = encodeURIComponent(exOptions.urlOrg); 55 exOptions.text = encodeURIComponent(exOptions.text); 56 iconSize = 44; 57 popnUp = 4; 58 scheme = /https/.test(document.location.protocol) ? 'https' : 'http'; 59 mkYQL = function(url, wantJson) { 60 var yUrl; 61 if (wantJson == null) { 62 wantJson = false; 63 } 64 yUrl = "" + scheme + "://query.yahooapis.com/v1/public/yql?env=https://www.datatables.org/alltables.env&q=" + (encodeURIComponent("SELECT content FROM data.headers WHERE url='" + url + "' and ua='Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 5.1)'")); 65 if (wantJson) { 66 yUrl += '&format=json'; 67 } 68 return yUrl; 69 }; 70 servicesProp = { 71 twitter: { 72 img: 'twitter_2x.png', 73 alt: 'Twitter Share Button', 74 shareUrl: "https://twitter.com/share?url=" + exOptions.url + "&text=" + exOptions.text, 75 commentUrl: "https://twitter.com/search/?q=" + exOptions.url, 76 countUrl: "https://jsoon.digitiminimi.com/twitter/count.json?url=" + exOptions.url, 77 jsonpFunc: function(json, cb) { 78 var _ref; 79 return cb((_ref = json.count) != null ? _ref : 0); 80 } 81 }, 82 facebook: { 83 img: 'facebook_2x.png', 84 alt: 'Facebook Share Button', 85 shareUrl: "https://www.facebook.com/sharer.php?u=" + exOptions.url + "&t=" + exOptions.text, 86// countUrl: "https://graph.facebook.com?id=" + exOptions.url, 87 countUrl: "https://graph.facebook.com?id=" + exOptions.url + "&access_token=1517481048549027|2lLyLq8RfNfboQw7dXi_EwFgOmA&fields=og_object{engagement},engagement", 88 jsonpFunc: function(json, cb) { 89 90 /* 91 * - Graph APIã§sharesãåå¾ã§ããªãå ´åã¯FQLã§total_countãåå¾ãã 92 * - Graph APIã®likes + FQLã®total_countã§ããããã¿ã³ã¨åãä»¶æ°ã«ãªã模æ§(ããã¤ãã®ã±ã¼ã¹ã調ã¹ãçµæ) 93 * - ã»ã¨ãã©ã®ãµã¤ãã§ã¯FQLã®total_countã ãã§ããããã¿ã³ã¨åãä»¶æ°ã«ãªã 94 */ 95 var graphLikes, _ref; 96 97 /* ä¸è¨ã®FQLãåããªããªã£ãçºå¤æ´ */ 98// console.log( Object.keys( json ).length ); 99 if ( Object.keys( json ).length <= 1 ) { 100 return cb( 0 ); 101 }else{ 102 if ( json.engagement.share_count != null) { 103 return cb( json.engagement.share_count ); 104 } 105// if ( json.share.share_count != null) { 106// return cb( json.share.share_count ); 107// } 108 graphLikes = (_ref = json.likes) != null ? _ref : 0; 109 return $.ajax({ 110 url: "https://graph.facebook.com/fql?q=" + (encodeURIComponent("SELECT total_count FROM link_stat WHERE url='" + exOptions.urlOrg + "'")), 111 dataType: 'jsonp' 112 }).done(function(json) { 113 var fqlTotal, _ref1, _ref2; 114 fqlTotal = (_ref1 = (_ref2 = json.data[0]) != null ? _ref2.total_count : void 0) != null ? _ref1 : 0; 115 return cb(graphLikes + fqlTotal); 116 }); 117 } 118 } 119 }, 120 hatebu: { 121 img: 'hatena_bookmark_2x.png', 122 alt: 'Hatena Bookmark Share Button', 123 shareUrl: "https://b.hatena.ne.jp/add?mode=confirm&url=" + exOptions.url + "&title=" + exOptions.text + "&mode=confirm", 124 commentUrl: "https://b.hatena.ne.jp/entry/" + exOptions.urlOrg, 125 countUrl: "https://api.b.st-hatena.com/entry.count?url=" + exOptions.url, 126 jsonpFunc: function(json, cb) { 127 return cb(json != null ? json : 0); 128 } 129 }, 130 gplus: { 131 img: 'google+1_2x.png', 132 alt: 'Google Plus Share Button', 133 shareUrl: "https://plusone.google.com/share?url=" + exOptions.url, 134 135 /* 136 * - Google+1ãã¿ã³ã¯ã·ã§ã¢æ°ã«é¢ããjsonpãæä¾ãã¦ããªã(jsonããæä¾ãã¦ããªã)ã®ã§+1ãã¿ã³ã®htmlãåå¾ãã¦ãã®ä¸ããä»¶æ°ãåå¾ãã 137 * - ã¯ãã¹ãã¡ã¤ã³ã«ããåå¾ã«ãªãã®ã§YQLã使ç¨ãã 138 * - ãã ãgoogleã®ãµã¼ãã¼ã«è¨ç½®ãã¦ããrobots.txtã¯YQL(ã¨ãããYahooã®ããããå ¨è¬ï¼)ã®UAãæå¦ããã®ã§Open Data Tableã®data.headerãã©ã°ã¤ã³ã使ç¨ãã 139 */ 140 countUrl: mkYQL("https://plusone.google.com/_/+1/fastbutton?hl=ja&url=" + exOptions.urlOrg), 141 jsonpFunc: function(json, cb) { 142 var count, m, _ref; 143 count = 0; 144 if (((_ref = json.query) != null ? _ref.count : void 0) > 0) { 145 m = json.results[0].match(/window\.__SSR = {c: ([\d]+)/); 146 if (m != null) { 147 count = m[1]; 148 } 149 } 150 return cb(count); 151 } 152 }, 153 pocket: { 154 img: 'pocket_2x.png', 155 alt: 'Pocket Stock Button', 156 shareUrl: "https://getpocket.com/save?url=" + exOptions.url + "&title=" + exOptions.text, 157 158 /* 159 * Google+1ãã¿ã³ã¨åæ§ã«YQLã§ã«ã¦ã³ããåå¾ãã 160 */ 161 countUrl: mkYQL("https://widgets.getpocket.com/v1/button?label=pocket&count=vertical&align=left&v=1&url=" + exOptions.urlOrg + "&src=" + exOptions.urlOrg + "&r=" + (Math.random() * 100000000)), 162 jsonpFunc: function(json, cb) { 163 var count, m, _ref; 164 count = 0; 165 if (((_ref = json.query) != null ? _ref.count : void 0) > 0) { 166 m = json.results[0].match(/em id="cnt">(\d+)</); 167 if (m != null) { 168 count = m[1]; 169 } 170 } 171 return cb(count); 172 } 173 }, 174 feedly: { 175 img: 'feedly_2x.png', 176 alt: 'Feedly Follow Button', 177 shareUrl: "https://feedly.com/index.html#subscription%2Ffeed%2F" + exOptions.feedUrl, 178 179 /* 180 * Google+1ãã¿ã³ã¨åæ§ã«YQLã§ã«ã¦ã³ããåå¾ãã 181 */ 182 countUrl: mkYQL("https://cloud.feedly.com/v3/feeds/feed%2F" + (encodeURIComponent(exOptions.feedUrl)), true), 183 jsonpFunc: function(json, cb) { 184 var _ref, _ref1, _ref2, _ref3, _ref4, _ref5; 185 return cb((_ref = json != null ? (_ref1 = json.query) != null ? (_ref2 = _ref1.results) != null ? (_ref3 = _ref2.resources) != null ? (_ref4 = _ref3.content) != null ? (_ref5 = _ref4.json) != null ? _ref5.subscribers : void 0 : void 0 : void 0 : void 0 : void 0 : void 0) != null ? _ref : 0); 186 } 187 }, 188 github: { 189 img: 'github_alt_2x.png', 190 alt: 'GitHub Repository', 191 shareUrl: "https://github.com/" + exOptions.githubRepo, 192 commentUrl: "https://github.com/" + exOptions.githubRepo + "/stargazers", 193 countUrl: "https://api.github.com/repos/" + exOptions.githubRepo, 194 jsonpFunc: function(json, cb) { 195 var _ref, _ref1; 196 return cb((_ref = json != null ? (_ref1 = json.data) != null ? _ref1.watchers : void 0 : void 0) != null ? _ref : 0); 197 } 198 } 199 }; 200 _addLink = (function(_this) { 201 return function(name, prop, idx) { 202 var countTag, countTagType, imgTag, shareTag, wrapTag; 203 wrapTag = $('<div/>').attr({
204 "class": "popn-socialbutton-wrap " + name 205 }).css({ 206 'float': 'left', 207 position: 'relative', 208 width: iconSize, 209 height: iconSize, 210 marginTop: popnUp 211 }); 212 if (idx > 0) { 213 wrapTag.css({ 214 marginLeft: exOptions.buttonSpace 215 }); 216 } 217 shareTag = $('<a/>').attr({ 218 href: prop.shareUrl, 219 "class": 'popn-socialbutton-share', 220 target: '_blank' 221 }).css({ 222 outline: 'none', 223 display: 'block', 224 width: '100%', 225 height: '100%' 226 }); 227 imgTag = $('<img/>').attr({ 228 src: "" + exOptions.imgDir + "/" + prop.img, 229 alt: prop.alt 230 }).css({ 231 border: 'none' 232 }); 233 countTagType = prop.commentUrl ? 'a' : 'span'; 234 countTag = $("<" + countTagType + "/>").attr({ 235 "class": 'popn-socialbutton-count' 236 }); 237 if (countTagType === 'a') { 238 countTag.attr({ 239 href: prop.commentUrl, 240 target: '_blank' 241 }); 242 } else { 243 countTag.css({ 244 cursor: 'default' 245 }); 246 } 247 countTag.css($.extend({}, { 248 display: 'none', 249 position: 'absolute', 250 color: exOptions.countColor.text, 251 backgroundColor: exOptions.countColor.bg, 252 border: "solid 2px " + exOptions.countColor.border, 253 fontSize: exOptions.countSize, 254 textDecoration: 'none', 255 outline: 'none', 256 fontWeight: 'bold', 257 padding: '0 4px', 258 borderRadius: 6, 259 boxShadow: '0 1px 2px rgba(0, 0, 0, 0.8)', 260 zIndex: 1 261 }, exOptions.countPosition)); 262 wrapTag.append(shareTag.append(imgTag)).append(countTag); 263 $(_this).append(wrapTag); 264 return $.ajax({ 265 url: prop.countUrl, 266 dataType: 'jsonp' 267 }).done(function(json) { 268 return prop.jsonpFunc(json, function(count) { 269 return countTag.show().text(count); 270 }); 271 }); 272 }; 273 })(this); 274 for (idx = _i = 0, _len = services.length; _i < _len; idx = ++_i) { 275 sName = services[idx]; 276 if (servicesProp[sName] != null) { 277 _addLink(sName, servicesProp[sName], idx); 278 } 279 } 280 $(this).height(iconSize + popnUp); 281 $(this).find('.popn-socialbutton-share').click(function() { 282 var left, top; 283 if (/(github|feedly)/.test($(this).parent().attr('class'))) { 284 return true; 285 } 286 top = (screen.height / 2) - (exOptions.popupWindow.height / 2); 287 left = (screen.width / 2) - (exOptions.popupWindow.width / 2); 288 window.open(this.href, '', "width=" + exOptions.popupWindow.width + ", height=" + exOptions.popupWindow.height + ", top=" + top + ", left=" + left); 289 return false; 290 }); 291 $(this).find('a.popn-socialbutton-count').mouseenter(function() { 292 return $(this).css({ 293 color: exOptions.countColor.textHover, 294 backgroundColor: exOptions.countColor.bgHover 295 }); 296 }).mouseleave(function() { 297 return $(this).css({ 298 color: exOptions.countColor.text, 299 backgroundColor: exOptions.countColor.bg 300 }); 301 }); 302 return $(this).find('.popn-socialbutton-wrap').mouseenter(function() { 303 return $(this).stop().animate({ 304 marginTop: 0 305 }, 100, 'swing'); 306 }).mouseleave(function() { 307 return $(this).stop().animate({ 308 marginTop: 4 309 }, 100, 'swing'); 310 }); 311 }; 312 })(jQuery); 313 314}).call(this);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.