Skip to content

Instantly share code, notes, and snippets.

@btilford
Created July 31, 2012 04:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save btilford/3213752 to your computer and use it in GitHub Desktop.
Save btilford/3213752 to your computer and use it in GitHub Desktop.
jam + angularjs gists
'use-strict';
define(
'directives/directive-aggregator'
['directives/todoBlur' ,'directives/todoFocus']
,{blur:blur, focus:focus}
);
//-----------------------------------------
//or
//-----------------------------------------
'use-strict';
define(
'directives/todo-directives'
,['app']
,function todoDirectiveModule(app) {
var blur,focus;
blur = app.todomvc.directive('todoBlur', function() {
return function blurDirective( scope, elem, attrs ) {
elem.bind('blur', function() {
scope.$apply(attrs.todoBlur);
});
};
});
focus = app.todomvc.directive('todoFocus', function( $timeout ) {
return function( scope, elem, attrs ) {
scope.$watch(attrs.todoFocus, function( newval ) {
if ( newval ) {
$timeout(function() {
elem[0].focus();
}, 0, false);
}
});
};
});
return {blur:blur, focus:focus};
}
)
'use strict';
/**
* The main TodoMVC app module.
*
* @type {angular.Module}
*/
var todomvc = angular.module('todomvc', []);
//-----------------------------------------
//becomes
//-----------------------------------------
'use strict';
define(
'app'
,[
'angularjs'
]
,function TodoMVCApp(angularPlaceHolder /*angular is not a AMD module*/) {
var angularModule = angular.module('todomvc', [])
,app = {}
app.init = function init() {
//using global angular var
angular.bootstrap(document, ['todomvc']);
}
//make the "todomvc" (Angular) module available on the "app" (AMD) module
app.__defineGetter__('todomvc', function() {return angularModule;})
return app;
}
);
<script src="../../assets/base.js"></script>
<script src="js/libs/angular/angular.min.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers/todoCtrl.js"></script>
<script src="js/services/todoStorage.js"></script>
<script src="js/directives/todoFocus.js"></script>
<script src="js/directives/todoBlur.js"></script>
//-----------------------------------------
//becomes
//-----------------------------------------
<script data-main="main" src="jam/require.js"></script>
jam install angularjs
ls jam/angularjs
cat jam/jam.json
cat jam/require-config.js
sudo npm install -g jamjs
//instead of this
require('angularjs', function(angular) {/*angular is undefined*/})
//use this
require('angularjs', function() {/*angular is in the global namespace*/})
//or something this
require('angularjs', function(notAngular) {/*notAngular is indefined but angular is in the global namespace*/})
'use-strict';
define(
'main'
,[
'app'
,'controllers/todoCtrl'
,'directives/todoBlur'
,'directives/todoFocus'
,'services/todoStorage'
]
,function mainModule(todomvc) {
todomvc.init();
}
)
'use strict';
/**
* Directive that executes an expression when the element it is applied to loses focus.
*/
app.todomvc.directive('todoBlur', function() {
return function blurDirective( scope, elem, attrs ) {
elem.bind('blur', function() {
scope.$apply(attrs.todoBlur);
});
};
});
//-----------------------------------------
//becomes
//-----------------------------------------
'use strict';
define(
'app'
,[
'angularjs'
]
,function TodoMVCApp(angularPlaceHolder /*angular is not a AMD module*/) {
var angularModule = angular.module('todomvc', [])
,app = {}
app.init = function init() {
//using global angular var
angular.bootstrap(document, ['todomvc']);
}
//make the "todomvc" (Angular) module available on the "app" (AMD) module
app.__defineGetter__('todomvc', function() {return angularModule;})
return app;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment