blob: 858494d06eb86f9900387e5518d41ed9184469bd [file] [log] [blame]
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -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 -- Showing Icons Test Module
19 */
20
21(function () {
22 'use strict';
23
Bri Prebilic Colee7399f32015-01-22 16:50:55 -080024 function setColWidth(t) {
Bri Prebilic Coled36a90f2015-01-22 16:19:27 -080025 var tHeaders, tdElement, colWidth;
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -080026
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -080027 tHeaders = t.selectAll('th');
Bri Prebilic Coled36a90f2015-01-22 16:19:27 -080028
29 // select each td in the first row and set the header's width to the
30 // corresponding td's width, if td is larger than header's width
31 tHeaders.each(function(thElement, index){
32 thElement = d3.select(this);
33
34 tdElement = t.select('td:nth-of-type(' + (index + 1) + ')');
35 colWidth = tdElement.style('width');
36
37 thElement.style('width', colWidth);
38 tdElement.style('width', colWidth);
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -080039 });
40 }
41
Bri Prebilic Colee7399f32015-01-22 16:50:55 -080042 function setCSS(thead, tbody, height) {
Bri Prebilic Coled36a90f2015-01-22 16:19:27 -080043 thead.style('display', 'block');
44 tbody.style({'display': 'block',
Bri Prebilic Colee7399f32015-01-22 16:50:55 -080045 'height': height || '500px',
Bri Prebilic Coled36a90f2015-01-22 16:19:27 -080046 'overflow': 'auto'
47 });
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -080048 }
49
Bri Prebilic Colee7399f32015-01-22 16:50:55 -080050 function fixTable(t, th, tb, height) {
51 setColWidth(t);
52 setCSS(th, tb, height);
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -080053 }
54
55 angular.module('practiceTable', [])
56
57 .directive('fixedHeader', ['$log', '$timeout', function ($log, $timeout) {
58 return {
59 restrict: 'A',
Bri Prebilic Colee7399f32015-01-22 16:50:55 -080060 scope: {
61 tableHeight: '@'
62 },
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -080063
64 link: function (scope, element, attrs) {
65 var table = d3.select(element[0]),
66 thead = table.select('thead'),
67 tbody = table.select('tbody');
68
69 // wait until the table is visible
70 scope.$watch(
71 function () { return (!(table.offsetParent === null)); },
72 function (newValue, oldValue) {
73 if (newValue === true) {
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -080074
75 // ensure thead and tbody have no display
76 thead.style('display', null);
77 tbody.style('display', null);
78
79 $timeout(function() {
Bri Prebilic Colee7399f32015-01-22 16:50:55 -080080 fixTable(table, thead, tbody, scope.tableHeight);
Bri Prebilic Coled36a90f2015-01-22 16:19:27 -080081 });
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -080082 }
83 });
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -080084 }
85 };
86 }]);
Bri Prebilic Coled36a90f2015-01-22 16:19:27 -080087}());