diff --git a/lib/browser/app.js b/lib/browser/app.js index 6eed3530..c627adfc 100644 --- a/lib/browser/app.js +++ b/lib/browser/app.js @@ -33,13 +33,13 @@ require('./browser/modules/image-writer'); require('./browser/modules/path'); require('./browser/modules/notifier'); require('./browser/modules/analytics'); -require('./browser/controllers/navigation'); require('./browser/components/progress-button/progress-button'); require('./browser/components/drive-selector'); require('./browser/pages/finish/finish'); require('./browser/pages/settings/settings'); require('./browser/utils/window-progress/window-progress'); require('./browser/utils/open-external/open-external'); +require('./browser/utils/if-state/if-state'); const app = angular.module('Etcher', [ 'ui.router', @@ -52,9 +52,6 @@ const app = angular.module('Etcher', [ 'Etcher.notifier', 'Etcher.analytics', - // Controllers - 'Etcher.controllers.navigation', - // Models 'Etcher.Models.SelectionState', @@ -68,7 +65,8 @@ const app = angular.module('Etcher', [ // Utils 'Etcher.Utils.WindowProgress', - 'Etcher.Utils.OpenExternal' + 'Etcher.Utils.OpenExternal', + 'Etcher.Utils.IfState' ]); app.config(function($stateProvider, $urlRouterProvider) { diff --git a/lib/browser/utils/if-state/directives/hide-if-state.js b/lib/browser/utils/if-state/directives/hide-if-state.js new file mode 100644 index 00000000..9636865a --- /dev/null +++ b/lib/browser/utils/if-state/directives/hide-if-state.js @@ -0,0 +1,54 @@ +/* + * Copyright 2016 Resin.io + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +/** + * @summary HideIfState directive + * @function + * @public + * + * @description + * This directive provides an attribute to hide an element + * when the current UI Router state matches the specified one. + * + * @param {Object} $state - ui router $state + * @returns {Object} directive + * + * @example + * + */ +module.exports = function($state) { + return { + restrict: 'A', + scope: { + hideIfState: '@' + }, + link: function(scope, element) { + scope.$watch(function() { + return $state.is(scope.hideIfState); + }, function(isState) { + + if (isState) { + element.css('display', 'none'); + } else { + element.css('display', 'initial'); + } + + }); + } + }; +}; diff --git a/lib/browser/utils/if-state/directives/show-if-state.js b/lib/browser/utils/if-state/directives/show-if-state.js new file mode 100644 index 00000000..e0fda652 --- /dev/null +++ b/lib/browser/utils/if-state/directives/show-if-state.js @@ -0,0 +1,54 @@ +/* + * Copyright 2016 Resin.io + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +/** + * @summary ShowIfState directive + * @function + * @public + * + * @description + * This directive provides an attribute to show an element + * when the current UI Router state matches the specified one. + * + * @param {Object} $state - ui router $state + * @returns {Object} directive + * + * @example + * + */ +module.exports = function($state) { + return { + restrict: 'A', + scope: { + showIfState: '@' + }, + link: function(scope, element) { + scope.$watch(function() { + return $state.is(scope.showIfState); + }, function(isState) { + + if (isState) { + element.css('display', 'initial'); + } else { + element.css('display', 'none'); + } + + }); + } + }; +}; diff --git a/lib/browser/controllers/navigation.js b/lib/browser/utils/if-state/if-state.js similarity index 58% rename from lib/browser/controllers/navigation.js rename to lib/browser/utils/if-state/if-state.js index 201a5a78..6d7ef0ee 100644 --- a/lib/browser/controllers/navigation.js +++ b/lib/browser/utils/if-state/if-state.js @@ -17,31 +17,19 @@ 'use strict'; /** - * @module Etcher.controllers.navigation + * @module Etcher.Utils.IfState + * + * The purpose of this module is to provide an attribute + * directive to show/hide an element when the current UI Router + * state matches the one specified in the attribute. */ const angular = require('angular'); - require('angular-ui-router'); -const navigation = angular.module('Etcher.controllers.navigation', [ + +const IfState = angular.module('Etcher.Utils.IfState', [ 'ui.router' ]); -navigation.controller('NavigationController', function($state) { - - /** - * @summary Check the current state - * @function - * @public - * - * @param {String} state - state - * @returns {Boolean} whether the state matches - * - * @example - * if(NavigationController.isState('state')) { - * console.log('We are in this state'). - * } - */ - this.isState = $state.is; - -}); +IfState.directive('showIfState', require('./directives/show-if-state')); +IfState.directive('hideIfState', require('./directives/hide-if-state')); diff --git a/lib/index.html b/lib/index.html index f22fd169..72ba256c 100644 --- a/lib/index.html +++ b/lib/index.html @@ -20,23 +20,23 @@ -
+
- -
-