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. |
| 28 | .directive('resize', ['$window', function ($window) { |
| 29 | return function (scope, element, attrs) { |
| 30 | var w = angular.element($window); |
| 31 | scope.$watch(function () { |
| 32 | return { |
| 33 | h: window.innerHeight, |
| 34 | w: window.innerWidth |
| 35 | }; |
| 36 | }, function (newVal, oldVal) { |
| 37 | scope.windowHeight = newVal.h; |
| 38 | scope.windowWidth = newVal.w; |
| 39 | |
| 40 | scope.resizeWithOffset = function (offH, offW) { |
| 41 | var oh = offH || 0, |
| 42 | ow = offW || 0; |
| 43 | scope.$eval(attrs.notifier); |
| 44 | return { |
| 45 | height: (newVal.h - oh) + 'px', |
| 46 | width: (newVal.w - ow) + 'px' |
| 47 | }; |
| 48 | }; |
| 49 | }, true); |
| 50 | |
| 51 | w.bind('resize', function () { |
| 52 | scope.$apply(); |
| 53 | }); |
| 54 | }; |
| 55 | }]) |
| 56 | |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 57 | |
| 58 | // create icon directive, so that we can inject icons into |
| 59 | // HTML tables etc. |
Simon Hunt | 9722538 | 2015-01-19 13:33:09 -0800 | [diff] [blame] | 60 | .directive('icon', ['IconService', function (is) { |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 61 | return { |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 62 | restrict: 'A', |
Simon Hunt | 9722538 | 2015-01-19 13:33:09 -0800 | [diff] [blame] | 63 | scope: { |
Bri Prebilic Cole | dee4662 | 2015-02-03 16:36:11 -0800 | [diff] [blame] | 64 | iconId: '@', |
| 65 | iconSize: '@' |
Simon Hunt | 9722538 | 2015-01-19 13:33:09 -0800 | [diff] [blame] | 66 | }, |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 67 | link: function (scope, element, attrs) { |
Bri Prebilic Cole | dee4662 | 2015-02-03 16:36:11 -0800 | [diff] [blame] | 68 | is.loadEmbeddedIcon(d3.select(element[0]), |
| 69 | scope.iconId, scope.iconSize); |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 70 | } |
| 71 | }; |
| 72 | |
Bri Prebilic Cole | b0e66be | 2015-02-10 10:53:15 -0800 | [diff] [blame] | 73 | }]) |
| 74 | |
| 75 | // create a general ng-repeat complete notifier directive |
| 76 | .directive('ngRepeatDone', [function () { |
| 77 | return function (scope, element, attrs) { |
| 78 | if(scope.$last) { |
| 79 | scope.$emit('LastElement'); |
| 80 | } |
| 81 | } |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 82 | }]); |
Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 83 | }()); |