Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | ONOS GUI -- Our own Angular directives defined here. |
Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | (function () { |
| 22 | 'use strict'; |
| 23 | |
| 24 | angular.module('onosApp') |
| 25 | |
| 26 | // Create a resize directive, that we can apply to elements |
| 27 | // so that they can respond to window resize events. |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 28 | .directive('resize', ['$window', 'FnService', function ($window, fs) { |
| 29 | return { |
| 30 | scope: { |
| 31 | offsetHeight: '@', |
| 32 | offsetWidth: '@', |
| 33 | notifier: '&' |
| 34 | }, |
| 35 | link: function (scope, element) { |
| 36 | var elem = d3.select(element[0]); |
| 37 | scope.$watchCollection(function () { |
Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 38 | return { |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 39 | h: $window.innerHeight, |
| 40 | w: $window.innerWidth |
Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 41 | }; |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 42 | }, function () { |
| 43 | var offH = scope.offsetHeight || 0, |
| 44 | offW = scope.offsetWidth || 0, |
| 45 | wsz = fs.windowSize(offH, offW); |
Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 46 | |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 47 | elem.style({ |
| 48 | height: wsz.height + 'px', |
| 49 | width: wsz.width + 'px' |
| 50 | }); |
| 51 | |
| 52 | if (fs.isF(scope.notifier)) { |
| 53 | scope.notifier(); |
| 54 | } |
| 55 | }); |
| 56 | |
| 57 | angular.element($window).bind('resize', function () { |
| 58 | scope.$apply(); |
| 59 | }); |
| 60 | } |
Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 61 | }; |
| 62 | }]) |
| 63 | |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 64 | |
| 65 | // create icon directive, so that we can inject icons into |
| 66 | // HTML tables etc. |
Simon Hunt | 9722538 | 2015-01-19 13:33:09 -0800 | [diff] [blame] | 67 | .directive('icon', ['IconService', function (is) { |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 68 | return { |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 69 | restrict: 'A', |
Simon Hunt | 9722538 | 2015-01-19 13:33:09 -0800 | [diff] [blame] | 70 | scope: { |
Bri Prebilic Cole | dee4662 | 2015-02-03 16:36:11 -0800 | [diff] [blame] | 71 | iconId: '@', |
| 72 | iconSize: '@' |
Simon Hunt | 9722538 | 2015-01-19 13:33:09 -0800 | [diff] [blame] | 73 | }, |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 74 | link: function (scope, element, attrs) { |
Bri Prebilic Cole | dee4662 | 2015-02-03 16:36:11 -0800 | [diff] [blame] | 75 | is.loadEmbeddedIcon(d3.select(element[0]), |
| 76 | scope.iconId, scope.iconSize); |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 77 | } |
| 78 | }; |
Bri Prebilic Cole | b0e66be | 2015-02-10 10:53:15 -0800 | [diff] [blame] | 79 | }]) |
| 80 | |
| 81 | // create a general ng-repeat complete notifier directive |
| 82 | .directive('ngRepeatDone', [function () { |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 83 | return function (scope) { |
| 84 | if (scope.$last) { |
Bri Prebilic Cole | b0e66be | 2015-02-10 10:53:15 -0800 | [diff] [blame] | 85 | scope.$emit('LastElement'); |
| 86 | } |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 87 | }; |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 88 | }]); |
Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 89 | }()); |