| 1 |
/* global document, requestAnimationFrame */ |
| 2 |
( function () { |
| 3 |
'use strict'; |
| 4 |
|
| 5 |
/** |
| 6 |
* For URL columns that use CSS truncation (overflow:hidden + text-overflow:ellipsis), |
| 7 |
* detect which cells actually overflow after layout and convert those to a |
| 8 |
* native <details>/<summary> expandable widget. Cells that fit on one line |
| 9 |
* are left as plain links — no [+] clutter. |
| 10 |
*/ |
| 11 |
function initExpandableCells() { |
| 12 |
var selectors = [ |
| 13 |
'#accua_dashboard_page td.column-afs_referrer', |
| 14 |
'#accua_dashboard_page td.column-afs_uri', |
| 15 |
'#accua_forms_submissions_list_page td.column-referrer', |
| 16 |
'#accua_forms_submissions_list_page td.column-uri', |
| 17 |
].join( ',' ); |
| 18 |
|
| 19 |
document.querySelectorAll( selectors ).forEach( function ( td ) { |
| 20 |
var link = td.querySelector( 'a' ); |
| 21 |
if ( ! link ) { |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
// td.scrollWidth === td.clientWidth for table cells even when clipped, |
| 26 |
// so measure the link's natural width via a text Range instead. |
| 27 |
var range = document.createRange(); |
| 28 |
range.selectNodeContents( link ); |
| 29 |
var naturalWidth = range.getBoundingClientRect().width; |
| 30 |
|
| 31 |
if ( naturalWidth <= td.clientWidth ) { |
| 32 |
return; // Content fits — no expandable needed. |
| 33 |
} |
| 34 |
|
| 35 |
var fullText = link.textContent; |
| 36 |
var fullHref = link.getAttribute( 'href' ); |
| 37 |
var fullTarget = link.getAttribute( 'target' ) || ''; |
| 38 |
|
| 39 |
// Build <details>/<summary> structure. |
| 40 |
var details = document.createElement( 'details' ); |
| 41 |
details.className = 'accua-expandable-cell'; |
| 42 |
|
| 43 |
var summary = document.createElement( 'summary' ); |
| 44 |
summary.title = fullText; |
| 45 |
|
| 46 |
var span = document.createElement( 'span' ); |
| 47 |
span.textContent = fullText; |
| 48 |
summary.appendChild( span ); |
| 49 |
details.appendChild( summary ); |
| 50 |
|
| 51 |
var fullLink = document.createElement( 'a' ); |
| 52 |
fullLink.href = fullHref; |
| 53 |
if ( fullTarget ) { |
| 54 |
fullLink.target = fullTarget; |
| 55 |
} |
| 56 |
fullLink.textContent = fullText; |
| 57 |
details.appendChild( fullLink ); |
| 58 |
|
| 59 |
td.innerHTML = ''; |
| 60 |
td.appendChild( details ); |
| 61 |
|
| 62 |
// When expanded, lift the overflow constraint so the full URL |
| 63 |
// can wrap within the column width (row height grows). |
| 64 |
details.addEventListener( 'toggle', function () { |
| 65 |
if ( details.open ) { |
| 66 |
td.style.overflow = 'visible'; |
| 67 |
td.style.whiteSpace = 'normal'; |
| 68 |
} else { |
| 69 |
td.style.overflow = ''; |
| 70 |
td.style.whiteSpace = ''; |
| 71 |
} |
| 72 |
} ); |
| 73 |
} ); |
| 74 |
} |
| 75 |
|
| 76 |
// The script runs in the footer. By then 'load' may already have fired, |
| 77 |
// so check readyState and fall through immediately if so. |
| 78 |
// setTimeout(0) defers until after the current rendering cycle. |
| 79 |
function scheduleInit() { |
| 80 |
setTimeout( initExpandableCells, 0 ); |
| 81 |
} |
| 82 |
|
| 83 |
if ( document.readyState === 'complete' ) { |
| 84 |
scheduleInit(); |
| 85 |
} else { |
| 86 |
window.addEventListener( 'load', scheduleInit ); |
| 87 |
} |
| 88 |
}() ); |
| 89 |
|