Skip to content

Instantly share code, notes, and snippets.

View fredsterss's full-sized avatar
🤔

Fred Stevens-Smith fredsterss

🤔
View GitHub Profile
@fredsterss
fredsterss / lol.coffee
Created July 6, 2012 20:20
Backbone phail
checkTurk: () ->
# If the turk browser chars do not match assignment requirements, redirect
requirements = @assignmentModel.get('requirements')
if /\d/.test(requirements.browser) is true and requirements.browser != (@browser.browser + @browser.version)
new JobHoldingView({ assignmentId: @assignment, state: @state, browser: @browser })
# or when the version is not required but the browser doesn't match
else if /\d/.test(requirements.browser) is false and requirements.browser != @browser.browser
checkTurk: () ->
# If the turk browser chars do not match assignment requirements, redirect
requirements = @assignmentModel.get('requirements')
if /\d/.test(requirements.browser) is true and requirements.browser != (@browser.browser + @browser.version)
# The beef is requirements does not appear in the view
new JobHoldingView({ assignmentId: @assignment, state: @state, browser: @browser, requirements: 'lol' })
getSteps: () ->
# hold the steps for this test in a collection
@stepCollection = new StepCollection({ testId: @testModel.get('_id') })
# when a step is added to the collection create a new step view
@stepCollection.bind 'all', @added
# fetch the collection
@fredsterss
fredsterss / eg.coffee
Created August 10, 2012 08:19
KILL ALL ZOMBIES
###
Example view usage
###
# add popovers to all elements
# with the popover class, but
# don't trigger the fuckers
@fredsterss
fredsterss / gist:4237171
Created December 7, 2012 22:49
Pushtate for Backbonejs hack in IE
Backbone.history.start({
pushState: Modernizr.history,
silent: true
});
if (!Modernizr.history) {
rootLength = Backbone.history.options.root.length;
fragment = window.location.pathname.substr(rootLength);
search = window.location.search;
return Backbone.history.navigate(fragment + search, {
@fredsterss
fredsterss / app.js
Created December 7, 2012 22:51 — forked from johnkpaul/app.js
IE9- and Backbone.history's pushState
//in your application, rather than using window.location to get the current url
App.getLocation = function(){
return window.location.protocol + '//' + window.location.host
+ '/' + Backbone.history.options.root + Backbone.history.getFragment()
}
# backbone fetch + async lib helper method, automatically routes
# the callback from success/error to the async required callback
async.fetch = (model) ->
return (callback) ->
model.fetch
success: (model, response) ->
callback null, model
initialize: (models, @options) ->
@.on 'all', (ev, route) ->
if route is 'activity'
console.log ev, route
return
it "calls response when a button is clicked", ->
spyOn @view, 'clickAction'
@view.$el.find('button.yes').click()
expect(@view.clickAction).toHaveBeenCalled()
@fredsterss
fredsterss / loading.coffee
Created June 4, 2013 00:10
Elegant loading
# handle ajax events (loading and auth errors)
$(document).ajaxStart ->
settings = lines: 12, length: 6, width: 4, radius: 8, trail: 75, color: '#fff'
$('.loading-main').html new r.ui.spinner( settings ).spin().el
$('[data-section=logo]').addClass('loading')
$(document).ajaxStop ->
$('[data-section=logo]').removeClass('loading')
$(document).ajaxComplete (e, xhr, options) ->
r.errorHandler.handle(xhr)