blob: 9cbcf6d697197057f3cc91c8bbad17de4b7758df [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.
19
20 @author Simon Hunt
21 */
22
23(function () {
24 'use strict';
25
26 angular.module('onosApp')
27
28 // Create a resize directive, that we can apply to elements
29 // so that they can respond to window resize events.
30 .directive('resize', ['$window', function ($window) {
31 return function (scope, element, attrs) {
32 var w = angular.element($window);
33 scope.$watch(function () {
34 return {
35 h: window.innerHeight,
36 w: window.innerWidth
37 };
38 }, function (newVal, oldVal) {
39 scope.windowHeight = newVal.h;
40 scope.windowWidth = newVal.w;
41
42 scope.resizeWithOffset = function (offH, offW) {
43 var oh = offH || 0,
44 ow = offW || 0;
45 scope.$eval(attrs.notifier);
46 return {
47 height: (newVal.h - oh) + 'px',
48 width: (newVal.w - ow) + 'px'
49 };
50 };
51 }, true);
52
53 w.bind('resize', function () {
54 scope.$apply();
55 });
56 };
57 }])
58
Simon Hunt58f23bb2015-01-16 16:32:24 -080059
60 // create icon directive, so that we can inject icons into
61 // HTML tables etc.
Simon Hunt97225382015-01-19 13:33:09 -080062 .directive('icon', ['IconService', function (is) {
Simon Hunt58f23bb2015-01-16 16:32:24 -080063 return {
Simon Hunt58f23bb2015-01-16 16:32:24 -080064 restrict: 'A',
Simon Hunt97225382015-01-19 13:33:09 -080065 scope: {
66 iconId: '@'
67 },
Simon Hunt58f23bb2015-01-16 16:32:24 -080068 link: function (scope, element, attrs) {
Simon Hunt97225382015-01-19 13:33:09 -080069 is.loadEmbeddedIcon(d3.select(element[0]), scope.iconId);
Simon Hunt58f23bb2015-01-16 16:32:24 -080070 }
71 };
72
Simon Hunt58f23bb2015-01-16 16:32:24 -080073 }]);
Simon Hunt0541fb82015-01-14 18:59:57 -080074}());