From 71114877e8e5409e37dc5a4c03015408f8e905fc Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Sun, 31 Mar 2019 07:26:37 -0400 Subject: #801 rip out bower, move to unmanaged externals --- www/external/js/mfb-directive.js | 175 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 www/external/js/mfb-directive.js (limited to 'www/external/js/mfb-directive.js') diff --git a/www/external/js/mfb-directive.js b/www/external/js/mfb-directive.js new file mode 100644 index 00000000..68a3c350 --- /dev/null +++ b/www/external/js/mfb-directive.js @@ -0,0 +1,175 @@ ++(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', + mainAction: '&', + 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 there is a main action, let's fire it + if (scope.mainAction) { + scope.mainAction(); + } + + 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