blob: ce94bd645e3d2663e37befaca35b757ab8098da2 [file] [log] [blame]
Simon Hunt0541fb82015-01-14 18:59:57 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
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/*
Bri Prebilic Cole70aacc42015-07-22 11:28:34 -070018 ONOS GUI -- General Purpose 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 };
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}());