{"id":2233,"date":"2011-08-02T20:47:19","date_gmt":"2011-08-03T00:47:19","guid":{"rendered":"http:\/\/www.gubatron.com\/blog\/?p=2233"},"modified":"2011-08-02T20:47:19","modified_gmt":"2011-08-03T00:47:19","slug":"twitterautolinks-jquery-extension-to-replace-twitter-names-for-links-to-their-respective-pages","status":"publish","type":"post","link":"https:\/\/www.gubatron.com\/blog\/twitterautolinks-jquery-extension-to-replace-twitter-names-for-links-to-their-respective-pages\/","title":{"rendered":"twitterAutoLinks: jQuery extension to replace twitter @names for links to their respective pages."},"content":{"rendered":"<p><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/farm7.static.flickr.com\/6022\/5896418528_f8183111dd.jpg?w=640\" \/><\/p>\n<p>Save the following on a .js file, preferably named <strong>jquery.twitterAutoLinks.js<\/strong><br \/>\n[javascript]<br \/>\n\/** Auto replace all Twitter nicknames for links *\/<br \/>\n$.fn.twitterAutoLinks = function() {<br \/>\n  return this.each(function() {<br \/>\n    var html = $(this).html();<br \/>\n    $(this).html(html.replace(\/B@([w-]+)\/gm, &#8216;&lt;a href=&quot;http:\/\/twitter.com\/$1&quot; target=&quot;_blank&quot;&gt;@$1&lt;\/a&gt;&#8217;));<br \/>\n  });<br \/>\n};<br \/>\n[\/javascript]<\/p>\n<p><strong>Usage<\/strong><\/p>\n<p>After importing the jquery.twitterAutoLinks.js file (make sure it&#8217;s after you&#8217;ve imported jquery itself), you&#8217;ll use the extension as follows.<\/p>\n<p>[html]<br \/>\n&lt;script type=&quot;text\/javascript&quot; language=&quot;Javascript&quot;&gt;<\/p>\n<p>    $(document).ready(function() {<br \/>\n      \/\/say you&#8217;re running a wordpress blog and you want to do this for your posts<br \/>\n      $(&quot;div.entry&quot;).twitterAutoLinks();<br \/>\n    });<\/p>\n<p>&lt;\/script&gt;<br \/>\n[\/html] <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Save the following on a .js file, preferably named jquery.twitterAutoLinks.js [javascript] \/** Auto replace all Twitter nicknames for links *\/ $.fn.twitterAutoLinks = function() { return this.each(function() { var html = $(this).html(); $(this).html(html.replace(\/B@([w-]+)\/gm, &#8216;&lt;a href=&quot;http:\/\/twitter.com\/$1&quot; target=&quot;_blank&quot;&gt;@$1&lt;\/a&gt;&#8217;)); }); }; [\/javascript] Usage After importing the jquery.twitterAutoLinks.js file (make sure it&#8217;s after you&#8217;ve imported jquery itself), you&#8217;ll use the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,15],"tags":[],"class_list":["post-2233","post","type-post","status-publish","format-standard","hentry","category-ajax","category-code"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5Unzf-A1","jetpack-related-posts":[{"id":1051,"url":"https:\/\/www.gubatron.com\/blog\/jquery-tag-wrapping\/","url_meta":{"origin":2233,"position":0},"title":"jQuery tag wrapping","author":"gubatron","date":"December 19, 2008","format":false,"excerpt":"Many times you'll be working on something in HTML that could be long and repetitive, and then for some reason you need to edit the entire thing to wrap each of the tags on some other tags, a common example would be to link many elements. Take this example, there's\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":308,"url":"https:\/\/www.gubatron.com\/blog\/useful-firefox-extensions\/","url_meta":{"origin":2233,"position":1},"title":"Useful Firefox extensions","author":"gubatron","date":"May 2, 2006","format":false,"excerpt":"Here's a page I've been meaning to do a long time ago, if you're a web developer you might want to bookmark it so that next time you set up Firefox +1.5 you'll have direct links to all the web developer tools you'll ever need. Web Developer Extension (Best extension\u2026","rel":"","context":"In &quot;Gubatron&quot;","block_context":{"text":"Gubatron","link":"https:\/\/www.gubatron.com\/blog\/category\/gubatron\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2634,"url":"https:\/\/www.gubatron.com\/blog\/javascript-format-a-number-to-display-thousands-us-style\/","url_meta":{"origin":2233,"position":2},"title":"javascript: Format a number to display thousands US style (#,###,###,###)","author":"gubatron","date":"January 5, 2012","format":false,"excerpt":"[javascript] \/** * Format a number to display thousands like in the US -> 1000000 => 1,000,000 * @param number * @returns *\/ function formatThousands(number) { return Math.max(0, number).toFixed(0).replace(\/(?=(?:d{3})+$)(?!^)\/g, ','); } [\/javascript]","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":402,"url":"https:\/\/www.gubatron.com\/blog\/an-useful-example-on-how-to-extend-javascript\/","url_meta":{"origin":2233,"position":3},"title":"An useful example on how to extend Javascript","author":"gubatron","date":"November 29, 2006","format":false,"excerpt":"Today I found out I could extend the functionality of __EXISTING__ html classes with javascript. I was manipulating DOM objects, better known as HTMLElement objects, and I needed a way to print the HTML that represents the tag of the object, not what's contained by the tags... a friend told\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2121,"url":"https:\/\/www.gubatron.com\/blog\/playing-with-basics-of-html5-canvas\/","url_meta":{"origin":2233,"position":4},"title":"Playing with basics of HTML5 Canvas","author":"gubatron","date":"December 18, 2010","format":false,"excerpt":"Here's a snippet of something I did tonight to play a bit with the Canvas and 2d Graphics context objects in javascript. [html] <html> <head> <title>Playing with Canvas<\/title> <\/head> <body style=\"padding:0 0; margin: 0 0; background:black\"> <canvas id=\"myCanvas\" width=\"1024\" height=\"1024\" ><\/canvas> <script type=\"text\/javascript\"> \/\/convert to CSS friendly Hex String function\u2026","rel":"","context":"In &quot;Geeklife&quot;","block_context":{"text":"Geeklife","link":"https:\/\/www.gubatron.com\/blog\/category\/geeklife\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2749,"url":"https:\/\/www.gubatron.com\/blog\/deploying-html5-apps-on-cloudfront-with-efficient-invalidation-requests\/","url_meta":{"origin":2233,"position":5},"title":"Deploying HTML5 apps on CloudFront with efficient invalidation requests","author":"gubatron","date":"June 8, 2012","format":false,"excerpt":"So you decided to build your next web app\/site using nothing but HTML5 and Javascript. No server side processing for anything related to UI. This means you will be coding a lot of JavaScript. Wouldn't it be nice to put all that static HTML and JS on your CloudFront CDN\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/2233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/comments?post=2233"}],"version-history":[{"count":0,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/2233\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/media?parent=2233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/categories?post=2233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/tags?post=2233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}