|
1 | 1 | /*
|
2 |
| - * showhide.js v1.1.0 |
| 2 | + * showhide.js v1.2.1 |
3 | 3 | */
|
4 | 4 | (function() {
|
5 | 5 | var mLine = document.createElement( 'span' );
|
|
102 | 102 | this.showHideOptions.linkElement.classList.remove( 'shown' );
|
103 | 103 | this.showHideOptions.linkElement.classList.add( 'notshown' );
|
104 | 104 |
|
105 |
| - if( this.showHideOptions.showText ) |
106 |
| - this.showHideOptions.linkElement.textContent = this.showHideOptions.showText; |
107 |
| - else { |
| 105 | + if( this.showHideOptions.showText ) { |
| 106 | + this.showHideOptions.linkTextNode.textContent = this.showHideOptions.showText; |
| 107 | + } else { |
108 | 108 | if( resizeObserver )
|
109 | 109 | resizeObserver.unobserve( this );
|
110 | 110 | this.showHideOptions.linkElement.remove();
|
|
145 | 145 | this.showHideOptions.linkElement.classList.remove( 'notshown' );
|
146 | 146 | this.showHideOptions.linkElement.classList.add( 'shown' );
|
147 | 147 |
|
148 |
| - if( this.showHideOptions.hideText ) |
149 |
| - this.showHideOptions.linkElement.textContent = this.showHideOptions.hideText; |
150 |
| - else { |
| 148 | + if( this.showHideOptions.hideText ) { |
| 149 | + this.showHideOptions.linkTextNode.textContent = this.showHideOptions.hideText; |
| 150 | + } else { |
151 | 151 | if( resizeObserver )
|
152 | 152 | resizeObserver.unobserve( this );
|
153 | 153 | this.showHideOptions.linkElement.remove();
|
|
217 | 217 | this.showHideOptions.linkElement.classList.add( 'showHideText' );
|
218 | 218 | }
|
219 | 219 |
|
| 220 | + this.showHideOptions.linkTextNode = null; |
| 221 | + for( let childNode of this.showHideOptions.linkElement.childNodes ) { |
| 222 | + if( childNode.nodeType === Node.TEXT_NODE ) { |
| 223 | + this.showHideOptions.linkTextNode = childNode; |
| 224 | + break; |
| 225 | + } |
| 226 | + } |
| 227 | + |
| 228 | + if( this.showHideOptions.linkTextNode === null ) { |
| 229 | + this.showHideOptions.linkTextNode = document.createTextNode(''); |
| 230 | + this.showHideOptions.linkElement.appendChild( this.showHideOptions.linkTextNode ); |
| 231 | + } |
| 232 | + |
220 | 233 | for( let extraElement of this.showHideOptions.extraElements )
|
221 | 234 | extraElement.showHideParent = this;
|
222 | 235 |
|
|
265 | 278 | // Add click event for showing and hiding the content
|
266 | 279 | var clickListener = function( e ) {
|
267 | 280 | e.preventDefault();
|
268 |
| - var target = e.target.parentElement; |
269 |
| - if( null === target.showHideOptions ) |
| 281 | + let target = e.target.parentElement; |
| 282 | + let i = 0; |
| 283 | + while( !target.showHideOptions && i < 3 ) { |
270 | 284 | target = target.parentElement;
|
| 285 | + i++; |
| 286 | + } |
271 | 287 |
|
272 | 288 | var showHideOptions = target.showHideOptions;
|
273 | 289 | if( showHideOptions.state && showHideOptions.state === 'hidden' ) {
|
|
0 commit comments