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%2Factionsheet%2Factionsheet.js;fp=afb-client%2Fbower_components%2Ffoundation-apps%2Fjs%2Fangular%2Fcomponents%2Factionsheet%2Factionsheet.js;h=e38b67a37d3b1d32ce0c5f64101e2907a686d68d;hp=0000000000000000000000000000000000000000;hb=5b1e6cc132f44262a873fa8296a2a3e1017b0278;hpb=f7d2f9ac4168ee5064580c666d508667a73cefc0 diff --git a/afb-client/bower_components/foundation-apps/js/angular/components/actionsheet/actionsheet.js b/afb-client/bower_components/foundation-apps/js/angular/components/actionsheet/actionsheet.js new file mode 100644 index 0000000..e38b67a --- /dev/null +++ b/afb-client/bower_components/foundation-apps/js/angular/components/actionsheet/actionsheet.js @@ -0,0 +1,226 @@ +(function() { + 'use strict'; + + angular.module('foundation.actionsheet', ['foundation.core']) + .controller('ZfActionSheetController', zfActionSheetController) + .directive('zfActionSheet', zfActionSheet) + .directive('zfAsContent', zfAsContent) + .directive('zfAsButton', zfAsButton) + .service('FoundationActionSheet', FoundationActionSheet) + ; + + FoundationActionSheet.$inject = ['FoundationApi']; + + function FoundationActionSheet(foundationApi) { + var service = {}; + + service.activate = activate; + service.deactivate = deactivate; + + return service; + + //target should be element ID + function activate(target) { + foundationApi.publish(target, 'show'); + } + + //target should be element ID + function deactivate(target) { + foundationApi.publish(target, 'hide'); + } + } + + zfActionSheetController.$inject = ['$scope', 'FoundationApi']; + + function zfActionSheetController($scope, foundationApi) { + var controller = this; + var content = controller.content = $scope.content; + var container = controller.container = $scope.container; + var body = angular.element(document.body); + + controller.registerContent = function(scope) { + content = scope; + content.active = false; + }; + + controller.registerContainer = function(scope) { + container = scope; + container.active = false; + }; + + controller.toggle = toggle; + controller.hide = hide; + + controller.registerListener = function() { + document.body.addEventListener('click', listenerLogic); + }; + + controller.deregisterListener = function() { + document.body.removeEventListener('click', listenerLogic); + } + + function listenerLogic(e) { + var el = e.target; + var insideActionSheet = false; + + do { + if(el.classList && el.classList.contains('action-sheet-container')) { + insideActionSheet = true; + break; + } + + } while ((el = el.parentNode)); + + if(!insideActionSheet) { + // if the element has a toggle attribute, do nothing + if (e.target.attributes['zf-toggle'] || e.target.attributes['zf-hard-toggle']) { + return; + }; + // if the element is outside the action sheet and is NOT a toggle element, hide + hide(); + } + } + + function hide() { + content.hide(); + container.hide(); + + content.$apply(); + container.$apply(); + } + + function toggle() { + content.toggle(); + container.toggle(); + + content.$apply(); + container.$apply(); + } + } + + zfActionSheet.$inject = ['FoundationApi']; + + function zfActionSheet(foundationApi) { + var directive = { + restrict: 'EA', + transclude: true, + replace: true, + templateUrl: 'components/actionsheet/actionsheet.html', + controller: 'ZfActionSheetController', + compile: compile + }; + + return directive; + + function compile() { + + return { + pre: preLink, + post: postLink + }; + + function preLink(scope, iElement, iAttrs) { + iAttrs.$set('zf-closable', 'actionsheet'); + } + + function postLink(scope, element, attrs, controller) { + var id = attrs.id || foundationApi.generateUuid(); + attrs.$set('id', id); + + scope.active = false; + + foundationApi.subscribe(id, function(msg) { + if (msg === 'toggle') { + controller.toggle(); + } + + if (msg === 'hide' || msg === 'close') { + controller.hide(); + } + + }); + + controller.registerContainer(scope); + + scope.toggle = function() { + scope.active = !scope.active; + return; + }; + + scope.hide = function() { + scope.active = false; + return; + }; + } + } + } + + zfAsContent.$inject = ['FoundationApi']; + + function zfAsContent(foundationApi) { + var directive = { + restrict: 'EA', + transclude: true, + replace: true, + templateUrl: 'components/actionsheet/actionsheet-content.html', + require: '^zfActionSheet', + scope: { + position: '@?' + }, + link: link + }; + + return directive; + + function link(scope, element, attrs, controller) { + scope.active = false; + scope.position = scope.position || 'bottom'; + controller.registerContent(scope); + + scope.toggle = function() { + scope.active = !scope.active; + if(scope.active) { + controller.registerListener(); + } else { + controller.deregisterListener(); + } + + return; + }; + + scope.hide = function() { + scope.active = false; + controller.deregisterListener(); + return; + }; + } + } + + zfAsButton.$inject = ['FoundationApi']; + + function zfAsButton(foundationApi) { + var directive = { + restrict: 'EA', + transclude: true, + replace: true, + templateUrl: 'components/actionsheet/actionsheet-button.html', + require: '^zfActionSheet', + scope: { + title: '@?' + }, + link: link + } + + return directive; + + function link(scope, element, attrs, controller) { + + element.on('click', function(e) { + controller.toggle(); + e.preventDefault(); + }); + + } + } + +})();