Skip to content

Instantly share code, notes, and snippets.

@airtonix
Created June 14, 2013 11:00
Show Gist options
  • Save airtonix/5781035 to your computer and use it in GitHub Desktop.
Save airtonix/5781035 to your computer and use it in GitHub Desktop.
The beginnings of a angular-zurb frankenstein.
angular.module('reveal.directives', [])
.directive('zurbReveal', function($revealService, $log){
return {
restrict: 'A',
link: function postLink(scope, element, attrs) {
scope.$watch(attrs.zurbReveal, function(url){
if(typeof(url)=='undefined') url = attrs.zurbReveal;
element.bind( "click", function(){
scope.$emit("event:modal-request", url, scope, attrs.revealOptions);
});
})
}
};
})
angular.module('reveal.service', [])
.factory('$revealService', function ($http, $rootScope, $compile, $log, $templateCache){
var revealService = {
modalElement: null
};
revealService.getModal = function(create){
if (!revealService.modalElement && create){
revealService.modalElement = $('<div class="reveal-modal hide">{{content}}</div>');
revealService.modalElement.appendTo('BODY');
}
return revealService.modalElement;
}
revealService.compileAndRunModal = function (modal, scope, options) {
$log.info("Compiling")
$compile(modal)(scope);
modal.reveal(options);
$log.info("Compiled")
}
revealService.load = function(url, scope, options){
$log.info("loading", url)
$http.get(url, {cache: $templateCache})
.then(function (response, status) {
$log.info("fetched", response, status)
var modal = revealService.getModal(true);
modal.html(response.data);
revealService.compileAndRunModal(modal, scope, options);
});
$rootScope.$apply()
}
$rootScope.$on("event:modal-request", function(scope, url, iScope, options){
$log.info("modal request event", url, options)
revealService.load(url, iScope, options);
})
return revealService;
});
angular.module('zurb', ['reveal.directives', 'reveal.service']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment