{"id":3664,"date":"2009-09-03T12:37:26","date_gmt":"2009-09-03T19:37:26","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=3664"},"modified":"2009-09-10T08:46:31","modified_gmt":"2009-09-10T15:46:31","slug":"jquery-tweetify-text","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/snippets\/jquery\/jquery-tweetify-text\/","title":{"rendered":"jQuery Tweetify Text"},"content":{"rendered":"

Function<\/h4>\n
$.fn.tweetify = function() {\r\n\tthis.each(function() {\r\n\t\t$(this).html(\r\n\t\t\t$(this).html()\r\n\t\t\t\t.replace(\/((ftp|http|https):\\\/\\\/(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(\\\/|\\\/([\\w#!:.?+=&%@!\\-\\\/]))?)\/gi,'<a href=\"$1\">$1<\/a>')\r\n\t\t\t\t.replace(\/(^|\\s)#(\\w+)\/g,'$1<a href=\"http:\/\/search.twitter.com\/search?q=%23$2\">#$2<\/a>')\r\n\t\t\t\t.replace(\/(^|\\s)@(\\w+)\/g,'$1<a href=\"http:\/\/twitter.com\/$2\">@$2<\/a>')\r\n\t\t);\r\n\t});\r\n\treturn $(this);\r\n}<\/code><\/pre>\n

Usage<\/h4>\n
$(\"p\").tweetify();<\/code><\/pre>\n

Before<\/h4>\n
<p>@seanhood have you seen this http:\/\/icanhascheezburger.com\/ #lol<\/p><\/code><\/pre>\n

After<\/h4>\n
<p><a href=\"http:\/\/twitter.com\/seanhood\">@seanhood<\/a> have you seen this\r\n<a href=\"http:\/\/icanhascheezburger.com\/\">http:\/\/icanhascheezburger.com\/<\/a>\r\n<a href=\"http:\/\/search.twitter.com\/search?q=%23lol\">#lol<\/a><\/p><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

Function $.fn.tweetify = function() { this.each(function() { $(this).html( $(this).html() .replace(\/((ftp|http|https):\\\/\\\/(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(\\\/|\\\/([\\w#!:.?+=&%@!\\-\\\/]))?)\/gi,'<a href=”$1″>$1<\/a>’) .replace(\/(^|\\s)#(\\w+)\/g,’$1<a href=”http:\/\/search.twitter.com\/search?q=%23$2″>#$2<\/a>’) .replace(\/(^|\\s)@(\\w+)\/g,’$1<a href=”http:\/\/twitter.com\/$2″>@$2<\/a>’) ); }); return $(this); } Usage $(“p”).tweetify(); Before <p>@seanhood have you seen this http:\/\/icanhascheezburger.com\/ #lol<\/p> After <p><a href=”http:\/\/twitter.com\/seanhood”>@seanhood<\/a> have you seen this <a href=”http:\/\/icanhascheezburger.com\/”>http:\/\/icanhascheezburger.com\/<\/a> <a href=”http:\/\/search.twitter.com\/search?q=%23lol”>#lol<\/a><\/p><\/p>\n","protected":false},"author":3,"featured_media":0,"parent":3245,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"page-snippet.php","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":""},"tags":[],"acf":[],"jetpack-related-posts":[{"id":5948,"url":"https:\/\/css-tricks.com\/snippets\/jquery\/search-replace\/","url_meta":{"origin":3664,"position":0},"title":"Search\/Replace","date":"March 15, 2010","format":false,"excerpt":"jQuery(function () { jQuery(\":contains(FIND)\").not(\":has(:contains(FIND))\").each(function () { var that = $(this), html = that.html(); html = html.replace(\/(\\(FIND:.*?\\))\/g, \"REPLACE-WITH\"); that.html(html); }); });","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7435,"url":"https:\/\/css-tricks.com\/snippets\/javascript\/htmlentities-for-javascript\/","url_meta":{"origin":3664,"position":1},"title":"htmlEntities for JavaScript","date":"September 14, 2010","format":false,"excerpt":"htmlentities() is a PHP function which converts special characters (like <) into their escaped\/encoded values (like <). This allows you to show to display the string without the browser reading it as HTML. JavaScript doesn't have a native version of it. If you just need the very basics to so\u2026","rel":"","context":"With 29 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":163748,"url":"https:\/\/css-tricks.com\/snippets\/javascript\/print-object-screen\/","url_meta":{"origin":3664,"position":2},"title":"Print Object To Screen","date":"February 22, 2014","format":false,"excerpt":"PHP has a nice print_r function for printing out information about a variable to the screen. console.log() is great for that in JavaScript also, but sometimes you just need\/want to look at it on the screen. function print_r(o) { return JSON.stringify(o,null,'\\t').replace(\/\\n\/g,'').replace(\/\\t\/g,'\u00a0\u00a0\u00a0'); } So if you have an object like: var\u2026","rel":"","context":"With 1 comment","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":191217,"url":"https:\/\/css-tricks.com\/snippets\/sass\/str-replace-function\/","url_meta":{"origin":3664,"position":3},"title":"Str-replace Function","date":"December 19, 2014","format":false,"excerpt":"Sass provides a collection of handy functions to manipulate strings, however there is no function to replace a substring with another string. Here is a quick str-replace function if you ever need one. \/\/\/ Replace `$search` with `$replace` in `$string` \/\/\/ @author Kitty Giraudel \/\/\/ @param {String} $string - Initial\u2026","rel":"","context":"With 10 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3880,"url":"https:\/\/css-tricks.com\/snippets\/jquery\/password-strength\/","url_meta":{"origin":3664,"position":4},"title":"Password Strength","date":"September 5, 2009","format":false,"excerpt":"$('#pass').keyup(function(e) { var strongRegex = new RegExp(\"^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\\\W).*$\", \"g\"); var mediumRegex = new RegExp(\"^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$\", \"g\"); var enoughRegex = new RegExp(\"(?=.{6,}).*\", \"g\"); if (false == enoughRegex.test($(this).val())) { $('#passstrength').html('More Characters'); } else if (strongRegex.test($(this).val())) { $('#passstrength').className = 'ok'; $('#passstrength').html('Strong!'); } else if (mediumRegex.test($(this).val())) { $('#passstrength').className = 'alert'; $('#passstrength').html('Medium!'); } else { $('#passstrength').className =\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3818,"url":"https:\/\/css-tricks.com\/snippets\/wordpress\/replace-excerpt-ellipsis-with-permalink\/","url_meta":{"origin":3664,"position":5},"title":"Replace Excerpt Ellipsis with Permalink","date":"September 4, 2009","format":false,"excerpt":"This is useful if you would like to replace the ellipsis [...] from the excerpt with a permalink to the post. functions.php addition: function replace_excerpt($content) { return str_replace('[...]', 'Continue Reading', $content ); } add_filter('the_excerpt', 'replace_excerpt');","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3664"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=3664"}],"version-history":[{"count":3,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3664\/revisions"}],"predecessor-version":[{"id":3985,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3664\/revisions\/3985"}],"up":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3245"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=3664"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=3664"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}