Skip to content

Instantly share code, notes, and snippets.

@danscotton
danscotton / gist:3164353
Created July 23, 2012 15:52
mocking with amd
// ----------------------------------------
// /path/to/dependency.js
define(function() {
return {
doSomethingWithIt: function() {
// blah
}
};
});
// locator_news_responsive/webapp/static/js/module/main.js
define([
'vendor/ender/reqwest',
'locator/bootstrap', <---- 'locator' here...where does this path come from?
'locator/locatorView' <---- is this the curl path that _we_ define in _our_ base.spv?
], function(
reqwest,
bootstrap,
LocatorView
){
======
BEFORE
======
// base.spv
86: 'locator': '../../../locator/news/responsive/<?= $config['locatorVersion'] ?>/js/'
// localweather.js
3: 'locator/module/main',
@danscotton
danscotton / gist:3046645
Created July 4, 2012 10:33
emitted events from locator, local and weather
// LOCATOR
locator:error [response, actionType]
locator:renderChangePrompt
locator:renderForm
locator:open [selectorString]
locator:close
locator:locationChanged [location] <---- maybe we should listen to this?
locator:renderWait
locator:searchResults [data]
locator:newsLocalRegions [data]
@danscotton
danscotton / gist:3039157
Created July 3, 2012 11:20
refactoring our js templating using curl
======
BEFORE
======
This is how we currently do 'JS templating' when we want to insert
snippets of markup into the DOM: Strings of markup in an array,
using [].join(''); We then do String.replace() to replace the
{{placeholders}} with content.
// minihyper.js
define([
// -- changed lines
define(['module/bootstrap', 'module/hyperpuff/minihyper'], function(news, MiniHyper) {
module('MiniHyper');
test('has an init method', function() {
ok('init' in MiniHyper);
});
// -- changed lines
return {
init: function() {
// store DOM references
var hyperpuff = news.$('.hyperpuff'),
hyperTitleText = news.$('.hyper-title', hyperpuff).text(),
firstGroupArticles = news.$('.group:first-child .article-wrapper article', hyperpuff),
insertBeforeTarget = news.$('.story-body .introduction'),
/*global define:true */
define(
[
'module/bootstrap',
'module/timestamp',
'module/imageenhancer',
'module/transclude',
'module/hyperpuff/hyperpuff'
], function(
// device.config.js
define(['module/config/config'], function( config ) {
// some logic up somewhere
var device;
switch(true) {
case (screen.width > 1200): device = 'wide'; break;
case (screen.width > 640): device = 'tablet'; break;
...
}
@danscotton
danscotton / gist:2853184
Created June 1, 2012 16:00
Config singleton
define(function() {
// Config object
var Config = function( initialSettings ) {
var store = (initialSettings && typeof initialSettings === 'object') ? initialSettings : {};
return {
get: function( key ) {
if(key) return store[key];
return store;