1// ---------------------------------------------------------- recordFacebookLike 2var recordFacebookLike = function() 3{ 4 var urlTag = $( "meta[property='og:url']" ).first(); 5 $.post( '/likes', { 'url': urlTag.content }, function(){} ); 6} 7// -------------------------------------------------------------- getProfileHash 8function getProfileHash() 9{ 10 var img, url, pageTitle, title, desc; 11 img = $("meta[property='og:image:url']").first().attr( 'content' ); 12 url = $("meta[property='og:url']").first().attr("content" ); 13 pageTitle = $("meta[property='og:title']").first().attr( 'content' ); 14 desc = $("meta[property='og:description']").first(); 15 desc = desc.length == 1 ? desc.attr( 'content' ) : ''; 16 title = pageTitle.replace( /on TeamPages\.com/, '' ); 17 return { 18 'message': 'Check out ' + title + ' ' + CustomLike.pageType + ' on TeamPages.com!', 19 'action_links': [{"text": "View the " + CustomLike.pageType, "href": url }], 20 'method': 'stream.publish', 21 "attachment": 22 { "name": pageTitle, 23 "href": url, 24 "description": desc, 25 "media": [{"type": "image", "src": img, "href": url }] 26 }, 27 "user_message_prompt": "Share your " + CustomLike.pageType + " with your friends:" 28 }; 29} 30// -------------------------------------------------------------- getLoginStatus 31customLike = function() 32{ 33 FB.getLoginStatus( getLoginStatusCallback( getProfileHash, true ) ); 34} 35// ------------------------------------------------------ getLoginStatusCallback 36function getLoginStatusCallback( f, firstTry ) 37{ 38 try { 39 return function(response ) 40 { 41 if( response.status == 'unknown' ) 42 { 43 if( firstTry ) 44 { 45 response = FB.getAuthResponse( getLoginStatusCallback( getProfileHash, false ) ); 46 FB.login( function( r ) 47 { 48 if( response == null || response.status != 'unknown' ) 49 { 50 FB.ui( f() ); 51 } 52 } ); 53 return; 54 } 55 else 56 { 57 FB.login( function( r ) 58 { 59 if( response.status != 'unknown' ) 60 { 61 FB.ui( f() ); 62 } 63 } ); 64 } 65 } 66 else 67 { 68 FB.ui( f() ); 69 } 70 }; 71 } catch(e){ alert(e); } 72} 73// ------------------------------------------------------------------- likeEvent 74likeEvent = function( title, eventType ) 75{ 76 var t = title; 77 var et = eventType; 78 var cb = function(){ return getEventHash( t, et ); }; 79 var session = FB.getAuthResponse( getLoginStatusCallback( cb ) ); 80 FB.getLoginStatus( getLoginStatusCallback( cb ) ); 81} 82// -------------------------------------------------------------- getEventHash 83function getEventHash( title, eventType ) 84{ 85 var img, url, pageTitle, desc; 86 img = $("meta[property='og:image:url']").first().attr( 'content' ); 87 url = $("meta[property='og:url']").first().attr('content'); 88 pageTitle = $("meta[property='og:title']").first().attr( 'content' ); 89 desc = $("meta[property='og:description']").first(); 90 desc = desc.length == 1 ? desc.attr('content') : ''; 91 return { 92 'message': title, 93 'action_links': [{"text": "View the " + eventType, "href": url }], 94 'method': 'stream.publish', 95 "attachment": 96 { "name": pageTitle, 97 "href": url, 98 "description": desc 99 }, 100 "user_message_prompt": "Share your event with your friends:", 101 "href": url 102 }; 103}; 104var TwitterButton = Class.create( 105{ 106 // ---------------------------------------------------------------- initialize 107 initialize: function( element, url, title, size ) 108 { 109 locked = false; 110 if( title ) 111 { 112 this._title = title; 113 } 114 else 115 { 116 var titleTag = $( "meta[property='og:title']" ).first(); 117 this._title = titleTag.attr( 'content' ); 118 } 119 if( url ) 120 { 121 this.url = url; 122 } 123 else 124 { 125 var urlTag = $( "meta[property='og:url']" ).first(); 126 this.url = urlTag.attr( 'content' ); 127 } 128 var id = TwitterButton.buttonCount; 129 TwitterButton.buttons[this.url] = this; 130 TwitterButton.buttonCount++; 131 var img = ( size == 'big' ) ? "/assets/icons/twitter_big-9fbb2c0910b38e0c7f86da84704eafcdf05e04fd5561f5dae1658003ce3aaef4.png" : "/assets/icons/tweet-7f743218a5168952c5658766666339c52aeb6094a212fbcd46126f2e62285eae.png"; 132 var klass = ( size == 'big' ) ? 'big_twitter_button' : 'twitter_button'; 133 var height = ''; 134 if ( element.attr( 'height' ) ) 135 { 136 height = 'height="' + element.height() + '"'; 137 } 138 element.append("<div class='" + klass + "' id='twitter_button_" + id + "'><img " + height + " src='" + img + "' alt='tweet'/></div>" ); 139 this.container = $( '#twitter_button_' + id ); 140 var x = this; 141 this.container.click( function(e){ x.onClick( e ) } ); 142 }, 143 // --------------------------------------------------------------------- title 144 title: function() 145 { 146 if( this.shortForm ) 147 { 148 return this._title + ' ' + this.shortForm; 149 } 150 else 151 { 152 return this._title + ' ' + this.url; 153 } 154 }, 155 // -------------------------------------------------------------- setShortForm 156 setShortForm: function( hash, url ) 157 { 158 TwitterButton.hash[hash] = this; 159 this.shortForm = url; 160 this.active = false;
161 }, 162 // ------------------------------------------------------------------- onClick 163 onClick: function( e ) 164 { 165 if( e ) 166 { 167 jQuery ? e.preventDefault() : e.stop(); 168 } 169 if( this.active ) 170 { 171 return; 172 } 173 this.active = true; 174 var button = this; 175 176 $.get('/shorten_link?long_url=' + encodeURIComponent(this.url), function(data) { button.setShortForm( data.hash, data.url || data.long_url ); }); 177 var newWindow = window.open(); 178 this.waitForBitly( newWindow ); 179 }, 180 // -------------------------------------------------------------- waitForBitly 181 waitForBitly: function( w ) 182 { 183 if( this.shortForm ) 184 { 185 w.location.href = 'https://twitter.com/intent/tweet?text=' + encodeURIComponent( this.status() ); 186 this.active = false; 187 } 188 else 189 { 190 var x= this; 191 setTimeout( function(){ x.waitForBitly( w ); }, 100 ); 192 } 193 }, 194 // -------------------------------------------------------------------- status 195 status: function() 196 { 197 return this.title() + ', via @teampages'; 198 } 199} ); 200 201TwitterButton.buttonCount = 0; 202TwitterButton.buttons = {}; 203TwitterButton.hash = {}; 204 205// ---------------------------------------------------------- initTwitterButtons 206function initTwitterButtons() 207{ 208 if( typeof( g_TwitterButtonsInitialized ) == 'undefined' ) 209 { 210 g_TwitterButtonsInitialized = true; 211 var search = ( typeof( document.body.scopeName ) == "undefined" ? 'tp:twitter_button' : 'twitter_button' ); 212 var elems = document.getElementsByTagName( search ); 213 for(var i = 0; i < elems.length; i++ ) 214 { 215 var button = $( elems[i] ); 216 var href = button.attr( 'href' ); 217 var title = button.attr( 'title' ); 218 var size = button.attr( 'size' ); 219 new TwitterButton( button, href, title, size ); 220 } 221 } 222} 223; 224 225
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.