Skip to content

Instantly share code, notes, and snippets.

View byrichardpowell's full-sized avatar

Richard Powell byrichardpowell

View GitHub Profile
// Setup global objects
window.SITE = {}
window.SITE.decoration = {};
// Setup the decoration method
SITE.decoration.selects = function( $wrapper ) {
// Search within the wrapper
// Or search wihin the body if $wrapper is undefined
$wrapper.or().find('select').chosen();
@byrichardpowell
byrichardpowell / gist:3884846
Created October 13, 2012 14:37
Countries with tips
@countries = Country.find( :all, :order => 'name' )
@countries_with_tips = []
@countries.each do |country|
if country.tips.any?
@countries_with_tips.push( country )
end
end
@byrichardpowell
byrichardpowell / gist:3857905
Created October 9, 2012 10:44
Model Fetch Unit Test
describe("A Model should", function() {
// FETCH
describe( "have a fetch method that", function() {
beforeEach(function() {
urls = ['url1', 'url2', 'url3', 'url4', 'url5']
spyOn( $, 'ajax');
(function($) {
// console.log('RPCHANGE');
// RPCHANGE:
// Updating a query string on a HREF string
// http://stackoverflow.com/questions/5999118/add-or-update-query-string-parameter
// Use this to add/remove 'openfacet' paramater to each HREF inside the facets
// Add when facet is open
// Remove when facet is closed
@byrichardpowell
byrichardpowell / gist:3778107
Created September 24, 2012 20:20
Loop through Logo text
// The purpose of this javascript is
// to wrap every letter inside a the #logo-text span in a span
// Unless it is already wrapped in a span
// in which case we ignore it
// We wrap every letter in a span so we can animate it seperately
// HTML:
// <span id="logo-text" class="text">
// tap<span class="and">+</span>hold
// </span>
<article>
<section class="stats">
<h1>Why Mobile?</h1>
<img class="stats-bg" src="" alt="Reasons to go mobile" />
<ul>
<li>
<strong class="stats-diamond">1.4</strong>
@byrichardpowell
byrichardpowell / gist:3655898
Created September 6, 2012 12:46
Method Optimisation
// Cycle through these URL's
// We update the models URL using these
// Then we fetch data using it
var nextUrl = function() {
var urls = [
'js/_data/api/tags/index.json%3frange=21-30',
'js/_data/api/tags/index.json%3frange=31-40',
'js/_data/api/tags/index.json%3frange=0-10',
'js/_data/api/tags/index.json%3frange=11-20'
@byrichardpowell
byrichardpowell / gist:3519382
Created August 29, 2012 21:50
jquery out of bounds
// Out of bounds
// Checks wether the element has been hidden by the user scrolling its parent
// Returns an object with, if above
// above : true
// crop : 92
// If below
// below : true
// crop 182
// Where crop is the no of pixels is it cropped by
// Object will be empty if its not out of bounds
@byrichardpowell
byrichardpowell / gist:3517425
Created August 29, 2012 19:14
jQuery decoration & interaction
$(document).ready(function() {
// Add ALL the decoration
// e.g jquery chosen
_.each(site.decoration, function(decorate) {
decorate();
});
@byrichardpowell
byrichardpowell / gist:3471055
Created August 25, 2012 21:14
Comment CSS Objects
/* MESSAGES
A container for message from the app to the user
These appear between the header and main content
*/
.messages {position:fixed; top: @line * 6; left:50%; width:480px; margin-left:-240px; text-align:left; z-index:700;}
.messages .box:hover {.shadow(0, 0, 6px, 0.5)}
/* State */
.fullscreen {