Skip to content

Commit 283ed1a

Browse files
jmervinescottgonzalez
authored andcommitted
Add SRI modal for CDN
Closes gh-391 Ref jquery/codeorigin.jquery.com#22
1 parent 08688bc commit 283ed1a

File tree

4 files changed

+181
-0
lines changed

4 files changed

+181
-0
lines changed

themes/codeorigin.jquery.com/page.php

+32
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
1+
<?php
2+
wp_enqueue_style('jquery-ui', 'https://code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.css');
3+
wp_enqueue_style('sri-modal', get_template_directory_uri() . '/css/sri-modal.css');
4+
5+
wp_enqueue_script('jquery-ui', 'https://code.jquery.com/ui/1.11.4/jquery-ui.min.js');
6+
wp_enqueue_script('clipboard', get_template_directory_uri() . '/js/clipboard.1.5.5.min.js');
7+
wp_enqueue_script('sri-modal', get_template_directory_uri() . '/js/sri-modal.js');
8+
?>
9+
110
<?php get_header(); ?>
211

312
<?php the_post(); ?>
413

14+
<div id="sri-modal-template" title="Code Integration">
15+
<div class="sri-modal-link">
16+
<code>&lt;script
17+
&nbsp;&nbsp;<span>src="{{link}}"</span>
18+
&nbsp;&nbsp;<span>integrity="{{hash}}"</span>
19+
&nbsp;&nbsp;<span>crossorigin="anonymous"&gt;&lt;/script&gt;</span>
20+
</code>
21+
22+
<button class="sri-modal-copy-btn" title="Copy to clipboard!"
23+
data-clipboard-text='&lt;script src="{{link}}" integrity="{{hash}}" crossorigin="anonymous"&gt;&lt;/script&gt;'>
24+
<i class="sri-modal-icon-copy icon-copy"></i>
25+
</button>
26+
</div>
27+
28+
<div class="sri-modal-info">
29+
The <code>integrity</code> and <code>crossorigin</code> attributes are used for
30+
<a href="https://www.w3.org/TR/SRI/" target="_blank">Subresource Integrity (SRI) checking</a>.
31+
This allows browsers to ensure that resources hosted on third-party servers have
32+
not been tampered with. Use of SRI is recommended as a best-practice, whenever
33+
libraries are loaded from a third-party source. Read more at <a href="https://www.srihash.org/" target="_blank">srihash.org</a>
34+
</div>
35+
</div>
36+
537
<div class="content-full twelve columns">
638
<div id="content">
739
<?php if ( !count( get_post_meta( $post->ID, "hide_title" ) ) ) : ?>

themes/jquery/css/sri-modal.css

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Added for SRI Modal
3+
*/
4+
.sri-modal {
5+
padding: 0;
6+
border: none;
7+
background: #fff;
8+
border-radius: 0;
9+
}
10+
11+
.sri-modal .ui-dialog-titlebar {
12+
padding: 0;
13+
border: none;
14+
background: #fff;
15+
color: #000;
16+
cursor: auto;
17+
}
18+
19+
.sri-modal .ui-dialog-title {
20+
padding-top: 20px;
21+
text-align: center;
22+
font-family: "klavika-web", "Helvetica Neue", Helvetica, Arial, Geneva, sans-serif;
23+
font-weight: 400;
24+
width: 100%;
25+
}
26+
27+
.sri-modal .ui-dialog-titlebar-close {
28+
background: none;
29+
border: none;
30+
right: 28px;
31+
}
32+
33+
.sri-modal .ui-icon-closethick {
34+
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAclBMVEUAAADMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMxg1ZvWAAAAJXRSTlMAAQIDBAUGCQsNDhQWGSg4g4uUoKOoq62vsLW8wMrO2tzk5ujxm/5xbwAAAGxJREFUGBmNwVcWgkAQRcFHg4FgzjomZu7+t+hpRv6p0iS7byPJTs+5BluIjewML5O7A3F1AdJMrgpkqVVWBVxqNVriNhrZDRdrZXYl62sNjkBaB6Cv5PaQOpUB3iZXHFInqXx8FvozDQpN8gNoXAtiMhPWmQAAAABJRU5ErkJggg==) 0 0;
35+
}
36+
37+
.sri-modal .ui-widget-content {
38+
padding: 30px 0 0 0;
39+
}
40+
41+
.sri-modal .ui-widget-content a {
42+
color: #b24926;
43+
}
44+
45+
.sri-modal-link {
46+
width: 810px;
47+
word-wrap: break-word;
48+
word-break: break-all;
49+
display: inline-block;
50+
background-color: #f8fbfb;
51+
padding: 0 10px;
52+
position: relative;
53+
}
54+
55+
.sri-modal-link code {
56+
width: 765px;
57+
display: inline-block;
58+
white-space: pre-line;
59+
background-color: transparent;
60+
padding: 0;
61+
font-size: 13px;
62+
line-height: 16px;
63+
}
64+
65+
.sri-modal-copy-btn {
66+
background-color: #1c6db3;
67+
border: none;
68+
font-size: 1rem;
69+
width: 35px;
70+
height: 35px;
71+
cursor: pointer;
72+
position: absolute;
73+
top: 5px;
74+
}
75+
76+
.sri-modal-copy-btn > i {
77+
color: #fff;
78+
}
79+
80+
.sri-modal-info {
81+
padding: 15px;
82+
font: 15px/22px "Helvetica Neue", HelveticaNeue, Helvetica, Arial, sans-serif;
83+
}
84+
85+
#sri-modal-template {
86+
display: none;
87+
}
88+

themes/jquery/js/clipboard.1.5.5.min.js

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

themes/jquery/js/sri-modal.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
$(document).ready(function() {
2+
// Store modal templates
3+
var modalTemplate = $( "#sri-modal-template" )[ 0 ].outerHTML,
4+
clipboard;
5+
6+
// Show modal on click
7+
$( "body" ).on( "click", ".open-sri-modal", function( event ) {
8+
if ( event.ctrlKey || event.metaKey ) {
9+
return;
10+
}
11+
12+
$( replace( modalTemplate, {
13+
link: document.location.origin + $( this ).attr( "href" ),
14+
hash: $( this ).attr( "data-hash" )
15+
} ) ).removeAttr( "id" ).appendTo( "body" ).dialog( {
16+
modal: true,
17+
resizable: false,
18+
width: 830,
19+
dialogClass: "sri-modal",
20+
draggable: false,
21+
close: function() {
22+
$( this ).remove();
23+
}
24+
} );
25+
26+
$('.sri-modal-copy-btn').tooltip();
27+
event.preventDefault();
28+
} );
29+
30+
// Helper functions
31+
function replace ( string, values ) {
32+
return string.replace( /\{\{([^}]+)}}/g, function( _, key ) {
33+
return values[key];
34+
});
35+
}
36+
37+
clipboard = new Clipboard( "[data-clipboard-text]" );
38+
39+
clipboard.on( "success", function( e ) {
40+
$( e.trigger )
41+
.tooltip( "option", "content", "Copied!" )
42+
.one( "mouseout", function() {
43+
$( this ).tooltip( "option", "content", "Copy to clipboard!" );
44+
} );
45+
} );
46+
47+
clipboard.on( "error", function( e ) {
48+
$( e.trigger )
49+
.tooltip( "option", "content", "Press Ctrl+C to copy!" )
50+
.one( "mouseout", function() {
51+
$( this ).tooltip( "option", "content", "Copy to clipboard!" );
52+
} );
53+
} );
54+
});

0 commit comments

Comments
 (0)