X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Fapp-framework-demo.git;a=blobdiff_plain;f=afb-client%2Fbower_components%2Ffoundation-apps%2Fjs%2Fangular%2Fcomponents%2Fcommon%2Fcommon.js;fp=afb-client%2Fbower_components%2Ffoundation-apps%2Fjs%2Fangular%2Fcomponents%2Fcommon%2Fcommon.js;h=a818a6ddeb2924e9b3f129657040a94aef29ba05;hp=0000000000000000000000000000000000000000;hb=5b1e6cc132f44262a873fa8296a2a3e1017b0278;hpb=f7d2f9ac4168ee5064580c666d508667a73cefc0 diff --git a/afb-client/bower_components/foundation-apps/js/angular/components/common/common.js b/afb-client/bower_components/foundation-apps/js/angular/components/common/common.js new file mode 100644 index 0000000..a818a6d --- /dev/null +++ b/afb-client/bower_components/foundation-apps/js/angular/components/common/common.js @@ -0,0 +1,171 @@ +(function() { + 'use strict'; + + angular.module('foundation.common', ['foundation.core']) + .directive('zfClose', zfClose) + .directive('zfOpen', zfOpen) + .directive('zfToggle', zfToggle) + .directive('zfEscClose', zfEscClose) + .directive('zfSwipeClose', zfSwipeClose) + .directive('zfHardToggle', zfHardToggle) + ; + + zfClose.$inject = ['FoundationApi']; + + function zfClose(foundationApi) { + var directive = { + restrict: 'A', + link: link + }; + + return directive; + + function link(scope, element, attrs) { + var targetId = ''; + if (attrs.zfClose) { + targetId = attrs.zfClose; + } else { + var parentElement= false; + var tempElement = element.parent(); + //find parent modal + while(parentElement === false) { + if(tempElement[0].nodeName == 'BODY') { + parentElement = ''; + } + + if(typeof tempElement.attr('zf-closable') !== 'undefined' && tempElement.attr('zf-closable') !== false) { + parentElement = tempElement; + } + + tempElement = tempElement.parent(); + } + targetId = parentElement.attr('id'); + } + + element.on('click', function(e) { + foundationApi.publish(targetId, 'close'); + e.preventDefault(); + }); + } + } + + zfOpen.$inject = ['FoundationApi']; + + function zfOpen(foundationApi) { + var directive = { + restrict: 'A', + link: link + }; + + return directive; + + function link(scope, element, attrs) { + element.on('click', function(e) { + foundationApi.publish(attrs.zfOpen, 'open'); + e.preventDefault(); + }); + } + } + + zfToggle.$inject = ['FoundationApi']; + + function zfToggle(foundationApi) { + var directive = { + restrict: 'A', + link: link + } + + return directive; + + function link(scope, element, attrs) { + element.on('click', function(e) { + foundationApi.publish(attrs.zfToggle, 'toggle'); + e.preventDefault(); + }); + } + } + + zfEscClose.$inject = ['FoundationApi']; + + function zfEscClose(foundationApi) { + var directive = { + restrict: 'A', + link: link + }; + + return directive; + + function link(scope, element, attrs) { + element.on('keyup', function(e) { + if (e.keyCode === 27) { + foundationApi.closeActiveElements(); + } + e.preventDefault(); + }); + } + } + + zfSwipeClose.$inject = ['FoundationApi']; + + function zfSwipeClose(foundationApi) { + var directive = { + restrict: 'A', + link: link + }; + return directive; + + function link($scope, element, attrs) { + var swipeDirection; + var hammerElem; + if (Hammer) { + hammerElem = new Hammer(element[0]); + // set the options for swipe (to make them a bit more forgiving in detection) + hammerElem.get('swipe').set({ + direction: Hammer.DIRECTION_ALL, + threshold: 5, // this is how far the swipe has to travel + velocity: 0.5 // and this is how fast the swipe must travel + }); + } + // detect what direction the directive is pointing + switch (attrs.zfSwipeClose) { + case 'right': + swipeDirection = 'swiperight'; + break; + case 'left': + swipeDirection = 'swipeleft'; + break; + case 'up': + swipeDirection = 'swipeup'; + break; + case 'down': + swipeDirection = 'swipedown'; + break; + default: + swipeDirection = 'swipe'; + } + hammerElem.on(swipeDirection, function() { + foundationApi.publish(attrs.id, 'close'); + }); + } + } + + zfHardToggle.$inject = ['FoundationApi']; + + function zfHardToggle(foundationApi) { + var directive = { + restrict: 'A', + link: link + }; + + return directive; + + function link(scope, element, attrs) { + element.on('click', function(e) { + foundationApi.closeActiveElements({exclude: attrs.zfHardToggle}); + foundationApi.publish(attrs.zfHardToggle, 'toggle'); + e.preventDefault(); + }); + } + } + +})();