Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 24 | function setColWidth($log, t) { |
Bri Prebilic Cole | d36a90f | 2015-01-22 16:19:27 -0800 | [diff] [blame^] | 25 | var tHeaders, tdElement, colWidth; |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 26 | |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 27 | tHeaders = t.selectAll('th'); |
Bri Prebilic Cole | d36a90f | 2015-01-22 16:19:27 -0800 | [diff] [blame^] | 28 | |
| 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); |
| 39 | //thElement.style('color', 'blue'); |
| 40 | //tdElement.style('color', 'red'); |
| 41 | |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 42 | }); |
| 43 | } |
| 44 | |
| 45 | function setCSS(thead, tbody) { |
Bri Prebilic Cole | d36a90f | 2015-01-22 16:19:27 -0800 | [diff] [blame^] | 46 | thead.style('display', 'block'); |
| 47 | tbody.style({'display': 'block', |
| 48 | 'height': '100px', |
| 49 | 'overflow': 'auto' |
| 50 | }); |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | function trimTable(tbody) { |
| 54 | |
| 55 | } |
| 56 | |
| 57 | function fixTable($log, t, th, tb) { |
| 58 | setColWidth($log, t); |
| 59 | setCSS(th, tb); |
| 60 | trimTable(tb); |
| 61 | } |
| 62 | |
| 63 | angular.module('practiceTable', []) |
| 64 | |
| 65 | .directive('fixedHeader', ['$log', '$timeout', function ($log, $timeout) { |
| 66 | return { |
| 67 | restrict: 'A', |
| 68 | |
| 69 | link: function (scope, element, attrs) { |
| 70 | var table = d3.select(element[0]), |
| 71 | thead = table.select('thead'), |
| 72 | tbody = table.select('tbody'); |
| 73 | |
| 74 | // wait until the table is visible |
| 75 | scope.$watch( |
| 76 | function () { return (!(table.offsetParent === null)); }, |
| 77 | function (newValue, oldValue) { |
| 78 | if (newValue === true) { |
| 79 | $log.log('table is visible'); |
| 80 | |
| 81 | // ensure thead and tbody have no display |
| 82 | thead.style('display', null); |
| 83 | tbody.style('display', null); |
| 84 | |
| 85 | $timeout(function() { |
| 86 | $log.log('timeout is over'); |
| 87 | fixTable($log, table, thead, tbody); |
Bri Prebilic Cole | d36a90f | 2015-01-22 16:19:27 -0800 | [diff] [blame^] | 88 | }); |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 89 | } |
| 90 | }); |
| 91 | $log.log('fixedHeader directive has been created'); |
| 92 | } |
| 93 | }; |
| 94 | }]); |
Bri Prebilic Cole | d36a90f | 2015-01-22 16:19:27 -0800 | [diff] [blame^] | 95 | }()); |