blob: 8bd31e2f73a94b05a7ce4898504b1c0f1b7283ce [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.
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 Hunt58f23bb2015-01-16 16:32:24 -080057
58 // create icon directive, so that we can inject icons into
59 // HTML tables etc.
Simon Hunt97225382015-01-19 13:33:09 -080060 .directive('icon', ['IconService', function (is) {
Simon Hunt58f23bb2015-01-16 16:32:24 -080061 return {
Simon Hunt58f23bb2015-01-16 16:32:24 -080062 restrict: 'A',
Simon Hunt97225382015-01-19 13:33:09 -080063 scope: {
Bri Prebilic Coledee46622015-02-03 16:36:11 -080064 iconId: '@',
65 iconSize: '@'
Simon Hunt97225382015-01-19 13:33:09 -080066 },
Simon Hunt58f23bb2015-01-16 16:32:24 -080067 link: function (scope, element, attrs) {
Bri Prebilic Coledee46622015-02-03 16:36:11 -080068 is.loadEmbeddedIcon(d3.select(element[0]),
69 scope.iconId, scope.iconSize);
Simon Hunt58f23bb2015-01-16 16:32:24 -080070 }
71 };
72
Bri Prebilic Coleb0e66be2015-02-10 10:53:15 -080073 }])
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 Hunt58f23bb2015-01-16 16:32:24 -080082 }]);
Simon Hunt0541fb82015-01-14 18:59:57 -080083}());