diff options
author | Stephane Desneux <stephane.desneux@iot.bzh> | 2016-05-31 18:16:48 +0200 |
---|---|---|
committer | Stephane Desneux <stephane.desneux@iot.bzh> | 2016-05-31 18:16:48 +0200 |
commit | 5b1e6cc132f44262a873fa8296a2a3e1017b0278 (patch) | |
tree | 43b2cd54e2e300b399ff3f2af4458a2c4ed8a144 /afb-client/bower_components/foundation-apps/js/angular/components/offcanvas/offcanvas.js | |
parent | f7d2f9ac4168ee5064580c666d508667a73cefc0 (diff) | |
parent | 85ace9c1ce9a98e9b8a22f045c7dd752b38d9129 (diff) |
Merge afb-client
Diffstat (limited to 'afb-client/bower_components/foundation-apps/js/angular/components/offcanvas/offcanvas.js')
-rw-r--r-- | afb-client/bower_components/foundation-apps/js/angular/components/offcanvas/offcanvas.js | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/afb-client/bower_components/foundation-apps/js/angular/components/offcanvas/offcanvas.js b/afb-client/bower_components/foundation-apps/js/angular/components/offcanvas/offcanvas.js new file mode 100644 index 0000000..b1d6cff --- /dev/null +++ b/afb-client/bower_components/foundation-apps/js/angular/components/offcanvas/offcanvas.js @@ -0,0 +1,102 @@ +(function() { + 'use strict'; + + angular.module('foundation.offcanvas', ['foundation.core']) + .directive('zfOffcanvas', zfOffcanvas) + .service('FoundationOffcanvas', FoundationOffcanvas) + ; + + FoundationOffcanvas.$inject = ['FoundationApi']; + + function FoundationOffcanvas(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'); + } + + function toggle(target) { + foundationApi.publish(target, 'toggle'); + } + } + + zfOffcanvas.$inject = ['FoundationApi']; + + function zfOffcanvas(foundationApi) { + var directive = { + restrict: 'EA', + templateUrl: 'components/offcanvas/offcanvas.html', + transclude: true, + scope: { + position: '@' + }, + replace: true, + compile: compile + }; + + return directive; + + function compile(tElement, tAttrs, transclude) { + var type = 'offcanvas'; + + return { + pre: preLink, + post: postLink + } + + function preLink(scope, iElement, iAttrs, controller) { + iAttrs.$set('zf-closable', type); + document.body.classList.add('has-off-canvas'); + } + + function postLink(scope, element, attrs) { + scope.position = scope.position || 'left'; + + scope.active = false; + //setup + foundationApi.subscribe(attrs.id, function(msg) { + if(msg === 'show' || msg === 'open') { + scope.show(); + } else if (msg === 'close' || msg === 'hide') { + scope.hide(); + } else if (msg === 'toggle') { + scope.toggle(); + } + + if (!scope.$root.$$phase) { + scope.$apply(); + } + + return; + }); + + scope.hide = function() { + scope.active = false; + return; + }; + + scope.show = function() { + scope.active = true; + return; + }; + + scope.toggle = function() { + scope.active = !scope.active; + return; + }; + } + } + } + +})(); |