blob: 1cb188fd9e9555b867cdb35a43b149fccab11fca [file] [log] [blame]
Simon Hunt0541fb82015-01-14 18:59:57 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Simon Hunt0541fb82015-01-14 18:59:57 -08003 *
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/*
Simon Hunt8a0429a2017-01-06 16:52:47 -080018 ONOS GUI -- General Purpose Angular directives.
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: '@',
Steven Burrows1c2a9682017-07-14 16:52:46 +010033 notifier: '&',
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070034 },
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,
Steven Burrows1c2a9682017-07-14 16:52:46 +010040 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',
Steven Burrows1c2a9682017-07-14 16:52:46 +010049 width: wsz.width + 'px',
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070050 });
51
52 if (fs.isF(scope.notifier)) {
53 scope.notifier();
54 }
55 });
56
57 angular.element($window).bind('resize', function () {
58 scope.$apply();
59 });
Steven Burrows1c2a9682017-07-14 16:52:46 +010060 },
Simon Hunt0541fb82015-01-14 18:59:57 -080061 };
Bri Prebilic Cole70aacc42015-07-22 11:28:34 -070062 }])
63
64 .directive('ngRepeatComplete', [function () {
65 return function (scope) {
66 if (scope.$last) {
67 scope.$emit('ngRepeatComplete');
68 scope.$broadcast('ngRepeatComplete');
69 }
70 };
Simon Hunt58f23bb2015-01-16 16:32:24 -080071 }]);
Simon Hunt0541fb82015-01-14 18:59:57 -080072}());