Skip to content

Commit

Permalink
releases.jquery.com: Attempt to fix script showing in page previews
Browse files Browse the repository at this point in the history
Add the `hidden` attribute to the template so that static analysis
(such as preview cards that only process the first few KB of the
HTML on its own) can know that this is not intended as visible content
hidden, without relying on runtime CSS (which is where we also set it
to display none).

Ref jquery/codeorigin.jquery.com#96
  • Loading branch information
Krinkle committed Aug 13, 2023
1 parent e78f692 commit fcf1e33
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
31 changes: 18 additions & 13 deletions themes/jquery/js/sri-modal.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
$( function() {
// Store modal templates
var modalTemplate = $( "#sri-modal-template" )[ 0 ].outerHTML;
var modalTemplate = $( "#sri-modal-template" )[ 0 ].outerHTML,
$modal = $( "<div>" ).attr( "title", "Code Integration" );

// Show modal on click
$( "body" ).on( "click", ".open-sri-modal", function( event ) {
if ( event.ctrlKey || event.metaKey ) {
return;
}
var link = this;

$( replace( modalTemplate, {
link: $( this ).prop( "href" ),
hash: $( this ).attr( "data-hash" )
} ) ).removeAttr( "id" ).appendTo( "body" ).dialog( {
modal: true,
resizable: false,
dialogClass: "sri-modal",
draggable: false,
close: function() {
$( this ).remove();
}
} );
$modal
.html( replace( modalTemplate, {
link: link.href,
hash: $( link ).attr( "data-hash" )
} ) )
.appendTo( "body" )
.dialog( {
modal: true,
resizable: false,
dialogClass: "sri-modal",
draggable: false,
close: function() {
$( this ).remove();
}
} );

$('.sri-modal-copy-btn')
.tooltip()
Expand Down
2 changes: 1 addition & 1 deletion themes/releases.jquery.com/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<?php the_post(); ?>

<div id="sri-modal-template" title="Code Integration">
<div hidden id="sri-modal-template">
<div class="sri-modal-link">
<code>&lt;script
&nbsp;&nbsp;<span>src="{{link}}"</span>
Expand Down

0 comments on commit fcf1e33

Please sign in to comment.