|
1 | 1 | <script type="text/javascript">
|
2 | 2 | (function () {
|
| 3 | + function onClick(aEv) { |
| 4 | + var container = aEv.target; |
| 5 | + var anchor = null; |
| 6 | + var url = null; |
3 | 7 |
|
4 |
| - $(document).ready(function () { |
5 |
| - // https://stackoverflow.com/questions/4904938/link-entire-table-row |
6 |
| - |
7 |
| - $('.tr-link').click(function (aE) { |
8 |
| - var anchor = null; |
9 |
| - var url = null; |
10 |
| - |
11 |
| - if ($(aE.target).is('a,input,a *')) { // anything else you don't want to trigger the click |
| 8 | + // Traverse up the DOM to find the container tr tag |
| 9 | + while (!container.classList.contains('tr-link')) { |
| 10 | + if (!(container = container.parentNode)) { |
12 | 11 | return;
|
13 | 12 | }
|
| 13 | + } |
14 | 14 |
|
15 |
| - anchor = $(this).find('a.tr-link-a').first(); |
16 |
| - if (!anchor) { |
17 |
| - return; |
18 |
| - } |
| 15 | + // Find the anchor tag for redirection |
| 16 | + anchor = container.querySelector('a.tr-link-a'); |
| 17 | + if (!anchor) { |
| 18 | + return; |
| 19 | + } |
19 | 20 |
|
20 |
| - url = anchor.attr('href'); |
21 |
| - if (!url) { |
22 |
| - return; |
23 |
| - } |
| 21 | + // Check to see if the href tag exists |
| 22 | + url = anchor.getAttribute('href'); |
| 23 | + if (!url) { |
| 24 | + return; |
| 25 | + } |
| 26 | + |
| 27 | + // Stop propagation as soon as possible |
| 28 | + aEv.stopPropagation(); |
| 29 | + |
| 30 | + // Redirect to the anchor href |
| 31 | + window.location = url; |
| 32 | + } |
| 33 | + |
| 34 | + function onDOMContentLoaded(aEv) { |
| 35 | + var i = undefined; |
| 36 | + var el = undefined; |
| 37 | + var els = document.querySelectorAll('tr.tr-link'); |
| 38 | + |
| 39 | + // Place handler on everything within the tr.tr-link |
| 40 | + for (i = 0, el; el = els[i++];) { |
| 41 | + el.addEventListener('click', onClick); |
| 42 | + } |
| 43 | + } |
24 | 44 |
|
25 |
| - window.location = url; |
26 |
| - aE.stopPropagation(); |
27 |
| - }) |
28 |
| - }); |
| 45 | + document.addEventListener('DOMContentLoaded', onDOMContentLoaded); |
29 | 46 |
|
30 | 47 | })();
|
31 | 48 | </script>
|
0 commit comments