Skip to content

Instantly share code, notes, and snippets.

@andershaig
andershaig / regex.js
Created November 14, 2011 20:44
Turn URL Titles into Links
<script type="text/javascript">
var to_parse = '{{ media_item.title | strip_newlines }}';
var URL_RE = /(?:(?=[\s`!()\[\]{};:'".,<>?«»“”‘’])|\b)((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/|[a-z0-9.\-]+[.](?:com|org|net))(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))*(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]|\b))/gi;
var parsed_url = to_parse.match(URL_RE);
document.write('<a id="magic_button" href="' + parsed_url + '" target="_blank">View Blog Post &raquo;</a>');
</script>
@andershaig
andershaig / size.js
Created November 14, 2011 23:49
Center Images Vertically & Horizontally
$(window).load(function () {
var button_w = $('#button img').height();
var button_h = $('#button img').width();
var margin_left = button_w / 2 * -1;
var margin_top = button_h / 2 * -1;
$('#button').css('marginLeft', margin_left);
$('#button').css('marginTop', margin_top);
});
@andershaig
andershaig / mock_ajax.js
Created November 17, 2011 16:54
Load More Items
function mockAjax() {
// The element containing a number of items, some of which you want to hide at first
var cont = $('#deal_cnt');
// Hide all but the first 5.
$("div.deal:gt(4)", cont).hide();
// On-click, load up to 5 more unless there are not left, then hide the button.
$('#load_more_deals').show().live('click', function() {
var hidden_divs = $("div.deal:hidden", cont);
@andershaig
andershaig / like_count.js
Last active September 28, 2015 03:38
Fan Meter
function like_count(args) {
function addCommas(nStr) {
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
@andershaig
andershaig / FB.init.detector.js
Created November 21, 2011 19:12 — forked from GCheung55/FB.init.detector.js
Facebook Init detector!
// Sample of usage
$(document).bind('FB.ready',function(){
console.log('FB is ready');
FB.api('/me',function(response){
console.log(response);
});
});
// Init Detector
var _FB = {
@andershaig
andershaig / signup_form.js
Created November 22, 2011 18:57
Modify Submit Button Value on Page Load
<script type="text/javascript">
$(window).load( function () {
{% plugin rawtext submit_button_text %}
$('.engagements_submit').val('{{ submit_button_text }}');
});
</script>
@andershaig
andershaig / video.js
Created November 22, 2011 22:51
Create Videos iFrames
// YouTube iFrame Creator
function getVideo(id, height, width) {
var output = '';
var youtube_id = id;
output = '<iframe width="' + width + '" height="' + height + '" src="http://www.youtube.com/embed/' + youtube_id + '?rel=0&autoplay=1" frameBorder="0" allowfullscreen>';
return output;
}
// Usage
var width = 418;
@andershaig
andershaig / twitter.js
Created December 5, 2011 15:55
Add Target="_top" to Twitter Links after Page Load
$(window).load( function () {
$('.tweet a').each( function () {
$(this).attr('target', '_top');
}
});
@andershaig
andershaig / trim.js
Created December 14, 2011 00:38
Add Trim Function
if(typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
}
}
@andershaig
andershaig / buttons.css
Created December 19, 2011 16:34
CSS3 Buttons
/* Red + Glossy */
.red_delcious {
padding:6px 12px;
border:1px solid #ED161B;
background: #FACAD0;
background: -moz-linear-gradient(top, #FACAD0 0%, #CA2437 50%, #BE0016 51%, #7C000E 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#FACAD0), color-stop(50%,#CA2437), color-stop(51%,#BE0016), color-stop(100%,#7C000E));
background: -webkit-linear-gradient(top, #FACAD0 0%,#CA2437 50%,#BE0016 51%,#7C000E 100%);
background: -o-linear-gradient(top, #FACAD0 0%,#CA2437 50%,#BE0016 51%,#7C000E 100%);
background: -ms-linear-gradient(top, #FACAD0 0%,#CA2437 50%,#BE0016 51%,#7C000E 100%);