Skip to content

Instantly share code, notes, and snippets.

@TigorC
Forked from airtonix/angular.zurb.js
Created December 8, 2013 02:30
Show Gist options
  • Select an option

  • Save TigorC/7852634 to your computer and use it in GitHub Desktop.

Select an option

Save TigorC/7852634 to your computer and use it in GitHub Desktop.

Revisions

  1. @airtonix airtonix created this gist Jun 14, 2013.
    55 changes: 55 additions & 0 deletions angular.zurb.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    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']);