From 6fa29c170159e7bfbcaf7681cdfb52ba7f98cac0 Mon Sep 17 00:00:00 2001 From: ARC Date: Tue, 28 Apr 2015 11:26:57 -0400 Subject: Events navigation not works with a cool full screen mode and floating buttons --- www/lib/ng-mfb/src/mfb-directive.js | 170 ++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 www/lib/ng-mfb/src/mfb-directive.js (limited to 'www/lib/ng-mfb/src/mfb-directive.js') diff --git a/www/lib/ng-mfb/src/mfb-directive.js b/www/lib/ng-mfb/src/mfb-directive.js new file mode 100644 index 00000000..d4cf214f --- /dev/null +++ b/www/lib/ng-mfb/src/mfb-directive.js @@ -0,0 +1,170 @@ ++(function(window, angular, undefined){ + + 'use strict'; + + var mfb = angular.module('ng-mfb', []); + + mfb.run(['$templateCache', function($templateCache) { + $templateCache.put('ng-mfb-menu-default.tpl.html', + '' + ); + + $templateCache.put('ng-mfb-menu-md.tpl.html', + '' + ); + + $templateCache.put('ng-mfb-button-default.tpl.html', + '
  • ' + + ' ' + + ' ' + + ' ' + + ' ' + + '
  • ' + ); + + $templateCache.put('ng-mfb-button-md.tpl.html', + '
  • ' + + ' ' + + ' ' + + //' ' + + ' ' + + ' ' + + ' ' + + '
  • ' + ); + }]); + + mfb.directive('mfbMenu', ['$timeout',function($timeout){ + return { + restrict: 'EA', + transclude: true, + replace: true, + scope: { + position: '@', + effect: '@', + label: '@', + resting: '@restingIcon', + active: '@activeIcon', + + menuState: '=?', + togglingMethod: '@', + }, + templateUrl: function(elem, attrs) { + return attrs.templateUrl || 'ng-mfb-menu-default.tpl.html'; + }, + link: function(scope, elem, attrs) { + + var openState = 'open', + closedState = 'closed'; + + /** + * Check if we're on a touch-enabled device. + * Requires Modernizr to run, otherwise simply returns false + */ + function _isTouchDevice(){ + return window.Modernizr && Modernizr.touch; + } + + function _isHoverActive(){ + return scope.togglingMethod === 'hover'; + } + + /** + * Convert the toggling method to 'click'. + * This is used when 'hover' is selected by the user + * but a touch device is enabled. + */ + function useClick(){ + scope.$apply(function(){ + scope.togglingMethod = 'click'; + }); + } + /** + * Invert the current state of the menu. + */ + function flipState() { + scope.menuState = scope.menuState === openState ? closedState : openState; + } + + /** + * Set the state to user-defined value. Fallback to closed if no + * value is passed from the outside. + */ + //scope.menuState = attrs.menuState || closedState; + if(!scope.menuState){ + scope.menuState = closedState; + } + + scope.clicked = function() { + if(!_isHoverActive()){ + flipState(); + } + }; + scope.hovered = function() { + if(_isHoverActive()){ + //flipState(); + } + }; + + /** + * If on touch device AND 'hover' method is selected: + * wait for the digest to perform and then change hover to click. + */ + if ( _isTouchDevice() && _isHoverActive() ){ + $timeout(useClick); + } + + attrs.$observe('menuState', function(){ + scope.currentState = scope.menuState; + }); + + } + }; + }]); + + + mfb.directive('mfbButton', [function(){ + return { + require: '^mfbMenu', + restrict: 'EA', + transclude: true, + replace: true, + scope: { + icon: '@', + label: '@' + }, + templateUrl: function(elem, attrs) { + return attrs.templateUrl || 'ng-mfb-button-default.tpl.html'; + } + }; + }]); + +})(window, angular); -- cgit v1.2.3