4 angular.module('foundation.popup', ['foundation.core'])
5 .directive('zfPopup', zfPopup)
6 .directive('zfPopupToggle', zfPopupToggle)
7 .service('FoundationPopup', FoundationPopup)
10 FoundationPopup.$inject = ['FoundationApi'];
12 function FoundationPopup(foundationApi) {
15 service.activate = activate;
16 service.deactivate = deactivate;
20 //target should be element ID
21 function activate(target) {
22 foundationApi.publish(target, 'show');
25 //target should be element ID
26 function deactivate(target) {
27 foundationApi.publish(target, 'hide');
30 function toggle(target, popupTarget) {
31 foundationApi.publish(target, ['toggle', popupTarget]);
35 zfPopup.$inject = ['FoundationApi'];
37 function zfPopup(foundationApi) {
42 templateUrl: 'components/popup/popup.html',
59 function preLink(scope, iElement, iAttrs) {
60 iAttrs.$set('zf-closable', 'popup');
63 function postLink(scope, element, attrs) {
65 scope.target = scope.target || false;
67 var attachment = scope.pinTo || 'top center';
68 var targetAttachment = scope.pinAt || 'bottom center';
69 var tetherInit = false;
73 foundationApi.subscribe(attrs.id, function(msg) {
74 if(msg[0] === 'show' || msg[0] === 'open') {
76 } else if (msg[0] === 'close' || msg[0] === 'hide') {
78 } else if (msg[0] === 'toggle') {
88 scope.hide = function() {
95 scope.show = function(newTarget) {
97 tetherElement(newTarget);
103 scope.toggle = function(newTarget) {
104 scope.active = !scope.active;
105 tetherElement(newTarget);
116 function tetherElement(target) {
121 scope.target = scope.target ? document.getElementById(scope.target) : document.getElementById(target);
123 tether = new Tether({
125 target: scope.target,
126 attachment: attachment,
127 targetAttachment: targetAttachment,
138 zfPopupToggle.$inject = ['FoundationApi'];
140 function zfPopupToggle(foundationApi) {
148 function link(scope, element, attrs) {
149 var target = attrs.zfPopupToggle;
150 var id = attrs.id || foundationApi.generateUuid();
151 attrs.$set('id', id);
153 element.on('click', function(e) {
154 foundationApi.publish(target, ['toggle', id]);