4 angular.module('foundation.common', ['foundation.core'])
5 .directive('zfClose', zfClose)
6 .directive('zfOpen', zfOpen)
7 .directive('zfToggle', zfToggle)
8 .directive('zfEscClose', zfEscClose)
9 .directive('zfSwipeClose', zfSwipeClose)
10 .directive('zfHardToggle', zfHardToggle)
13 zfClose.$inject = ['FoundationApi'];
15 function zfClose(foundationApi) {
23 function link(scope, element, attrs) {
26 targetId = attrs.zfClose;
28 var parentElement= false;
29 var tempElement = element.parent();
31 while(parentElement === false) {
32 if(tempElement[0].nodeName == 'BODY') {
36 if(typeof tempElement.attr('zf-closable') !== 'undefined' && tempElement.attr('zf-closable') !== false) {
37 parentElement = tempElement;
40 tempElement = tempElement.parent();
42 targetId = parentElement.attr('id');
45 element.on('click', function(e) {
46 foundationApi.publish(targetId, 'close');
52 zfOpen.$inject = ['FoundationApi'];
54 function zfOpen(foundationApi) {
62 function link(scope, element, attrs) {
63 element.on('click', function(e) {
64 foundationApi.publish(attrs.zfOpen, 'open');
70 zfToggle.$inject = ['FoundationApi'];
72 function zfToggle(foundationApi) {
80 function link(scope, element, attrs) {
81 element.on('click', function(e) {
82 foundationApi.publish(attrs.zfToggle, 'toggle');
88 zfEscClose.$inject = ['FoundationApi'];
90 function zfEscClose(foundationApi) {
98 function link(scope, element, attrs) {
99 element.on('keyup', function(e) {
100 if (e.keyCode === 27) {
101 foundationApi.closeActiveElements();
108 zfSwipeClose.$inject = ['FoundationApi'];
110 function zfSwipeClose(foundationApi) {
117 function link($scope, element, attrs) {
121 hammerElem = new Hammer(element[0]);
122 // set the options for swipe (to make them a bit more forgiving in detection)
123 hammerElem.get('swipe').set({
124 direction: Hammer.DIRECTION_ALL,
125 threshold: 5, // this is how far the swipe has to travel
126 velocity: 0.5 // and this is how fast the swipe must travel
129 // detect what direction the directive is pointing
130 switch (attrs.zfSwipeClose) {
132 swipeDirection = 'swiperight';
135 swipeDirection = 'swipeleft';
138 swipeDirection = 'swipeup';
141 swipeDirection = 'swipedown';
144 swipeDirection = 'swipe';
146 hammerElem.on(swipeDirection, function() {
147 foundationApi.publish(attrs.id, 'close');
152 zfHardToggle.$inject = ['FoundationApi'];
154 function zfHardToggle(foundationApi) {
162 function link(scope, element, attrs) {
163 element.on('click', function(e) {
164 foundationApi.closeActiveElements({exclude: attrs.zfHardToggle});
165 foundationApi.publish(attrs.zfHardToggle, 'toggle');