Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 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 | /* |
Bri Prebilic Cole | 70aacc4 | 2015-07-22 11:28:34 -0700 | [diff] [blame] | 18 | ONOS GUI -- General Purpose 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 | }; |
Bri Prebilic Cole | 70aacc4 | 2015-07-22 11:28:34 -0700 | [diff] [blame] | 62 | }]) |
| 63 | |
| 64 | .directive('ngRepeatComplete', [function () { |
| 65 | return function (scope) { |
| 66 | if (scope.$last) { |
| 67 | scope.$emit('ngRepeatComplete'); |
| 68 | scope.$broadcast('ngRepeatComplete'); |
| 69 | } |
| 70 | }; |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 71 | }]); |
Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 72 | }()); |