Skip to content

Instantly share code, notes, and snippets.

@bholmberg
bholmberg / authRoute.js
Created November 12, 2012 01:29 — forked from xcambar/LICENSE
Authenticated routing using AngularJS
authRouteProvider.$inject = ['$routeProvider'];
function authRouteProvider ($routeProvider) {
/**
* Creates a controller bound to the route, or wraps the controller in param
* so the authentication check is run before the original controller is executed
* @param currentController
* @return {Function} The wrapper controller
*/
function redirectCtrlFactory (currentController) {
_ctrl.$inject = ['currentUser__', 'userRole__', '$location'];
// normally the ServiceObject would just be assigned to the service injected into the controller
$scope.ServiceObject = {
property1:null,
property2:null
};
// or it could be done this way
$scope.property1 = ServiceObject.property1;
ngView.directive('myModal', function() { // in the template, the 'container' of your modal would have my-modal as an attribute
return {
scope: true,
link: function(scope, element, attrs) {
$(element).modal({show:false, backdrop:true, keyboard:true }); // this is instantiating a bootstrap modal i think
scope.$on('showModal', function (eventObj, record) {
scope.record = record; // refer to properties in the template like {{record.property}}
@bholmberg
bholmberg / cornify.directive.js
Created March 25, 2013 16:34
AngularJS directive to cornify a web page when the "konami code" entered on the keyboard. I wrapped js I found on a blog into a DDO.
ngApp.directive("cornify", function () {
return {
link: function (scope, element, attrs) {
var konami_keys = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
var konami_index = 0;
$(document).keydown(function(e){
if (e.keyCode === konami_keys[konami_index++]) {
if (konami_index === konami_keys.length) {
$(document).unbind('keydown', arguments.callee);
$.getScript('http://www.cornify.com/js/cornify.js',function(){