blob: bac559bbb5a9c51a4d938240204ae2ea1fedf617 [file] [log] [blame]
Simon Hunt0541fb82015-01-14 18:59:57 -08001/*
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 Hunt0541fb82015-01-14 18:59:57 -080019 */
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 Cole068814d2015-05-14 16:06:38 -070028 .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 Hunt0541fb82015-01-14 18:59:57 -080038 return {
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070039 h: $window.innerHeight,
40 w: $window.innerWidth
Simon Hunt0541fb82015-01-14 18:59:57 -080041 };
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070042 }, function () {
43 var offH = scope.offsetHeight || 0,
44 offW = scope.offsetWidth || 0,
45 wsz = fs.windowSize(offH, offW);
Simon Hunt0541fb82015-01-14 18:59:57 -080046
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070047 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 Hunt0541fb82015-01-14 18:59:57 -080061 };
62 }])
63
Simon Hunt58f23bb2015-01-16 16:32:24 -080064
65 // create icon directive, so that we can inject icons into
66 // HTML tables etc.
Simon Hunt97225382015-01-19 13:33:09 -080067 .directive('icon', ['IconService', function (is) {
Simon Hunt58f23bb2015-01-16 16:32:24 -080068 return {
Simon Hunt58f23bb2015-01-16 16:32:24 -080069 restrict: 'A',
Simon Hunt97225382015-01-19 13:33:09 -080070 scope: {
Bri Prebilic Coledee46622015-02-03 16:36:11 -080071 iconId: '@',
72 iconSize: '@'
Simon Hunt97225382015-01-19 13:33:09 -080073 },
Simon Hunt58f23bb2015-01-16 16:32:24 -080074 link: function (scope, element, attrs) {
Bri Prebilic Colea7f81e52015-06-23 10:11:08 -070075 attrs.$observe('iconId', function () {
76 var div = d3.select(element[0]);
77 div.selectAll('*').remove();
78 is.loadEmbeddedIcon(div, scope.iconId, scope.iconSize);
79 });
Simon Hunt58f23bb2015-01-16 16:32:24 -080080 }
81 };
Bri Prebilic Coleb0e66be2015-02-10 10:53:15 -080082 }])
83
84 // create a general ng-repeat complete notifier directive
85 .directive('ngRepeatDone', [function () {
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070086 return function (scope) {
87 if (scope.$last) {
Bri Prebilic Coleb0e66be2015-02-10 10:53:15 -080088 scope.$emit('LastElement');
89 }
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070090 };
Simon Hunt58f23bb2015-01-16 16:32:24 -080091 }]);
Simon Hunt0541fb82015-01-14 18:59:57 -080092}());