|
|
@@ -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']); |