Skip to content

Instantly share code, notes, and snippets.

@andershaig
andershaig / gist:1229330
Created September 20, 2011 14:59
Use Text Plugin to Pass Variables
{% capture foo_plaintext %}{% text foo %}{% endcapture %}
<a href="http://twitter.com/{{ foo_plaintext | strip_html | strip_newlines }}">Follow me on Twitter!</a>
@andershaig
andershaig / gist:1229340
Created September 20, 2011 15:02
Flexible Width Video
<script src="path/to/jquery.fitvids.js"></script>
<script>
$(document).ready(function(){
// Target your .container, .wrapper, .post, etc.
$(".video-container").fitVids();
});
</script>
@andershaig
andershaig / gist:1229346
Created September 20, 2011 15:04
Use Image Plugin for Background Image
<div id="bg" style="position:absolute;left:-9999px;">
{% image background %}
</div>
<script type="text/javascript">
var bg = $('#bg img').attr('src');
$('body').css("background","url("+bg+") no-repeat");
</script>
@andershaig
andershaig / gist:1230507
Created September 20, 2011 21:47
Custom: Entry Titles Into Links
<!--
/ Before
/-----------------------------
/ Note: This only worked because the media_item.title
/ field already had URLs entered (http://) and that's it.
////////////////////////////// -->
<div class="media_title">
{{ media_item.title }}
</div>
@andershaig
andershaig / gist:1242944
Created September 26, 2011 18:22
Store Values on Page Load, Replace When Empty
<script type="text/javascript">
$(document).ready(function(){
$('form input:text, form textarea').each(function(){
$.data(this, 'default', this.value);
}).focus(function(){
if ($.data(this, 'default') == this.value) {
this.value = '';
}
}).blur(function(){
if (this.value == '') {
@andershaig
andershaig / gist:1317159
Created October 26, 2011 17:58
JavaScript Snippets
// Replace spaces with underscores
.split(' ').join('_')
// Add a .trim function to remove whitespace from strings
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }
// Add commas to a number
function addCommas(nStr) {
nStr += '';
x = nStr.split('.');
@andershaig
andershaig / script.js
Created November 9, 2011 01:10
Facebook Post to Wall w/ Variable Share Link
<script type="text/javascript">
jQuery(document).bind('afterfbinit', function () {
// The ID of your share button or link
$('#share_button').live('click', function () {
FB.ui({
method: 'feed',
name: 'Title of Share Info',
description: 'Description under title in Share Info',
picture: 'Link to an image (90 by 90px)',
link: 'http://www.facebook.com/pages/@/{{ fb.page.id }}'
@andershaig
andershaig / countdown.js
Created November 9, 2011 20:36
Live Countdown
<script type="text/javascript">
var end = new Date('6 Oct 2011 23:59:59'); // Timer Expiration
var _second = 1000;
var _minute = _second * 60;
var _hour = _minute * 60;
var _day = _hour *24;
var timer;
function showRemaining() {
@andershaig
andershaig / live_countdown.js
Created November 9, 2011 21:06
Live Countdown from Countdown Plugin
<script type="text/javascript">
var days_left = {{ time_clock.days }};
var hours_left = {{ time_clock.hours }};
var minutes_left = {{ time_clock.minutes }};
var _now = new Date();
var end = new Date(_now.getTime() + (minutes_left * 60 * 1000) );
var _second = 1000;
var _minute = _second * 60;
@andershaig
andershaig / gallery.js
Created November 11, 2011 21:26
Remove Extra Elements Around Gallery <li>