-
Notifications
You must be signed in to change notification settings - Fork 170
adding sri modal to codeorigin #391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
2d6cd06
aec1567
37a4ecd
50680d7
b084449
ed6cd93
0d5db46
3570ee7
2b99d13
e4f0003
d30709b
0a77507
5656dc2
eb0c755
3df694f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,51 @@ | ||
<?php | ||
|
||
// attach custom header and footer tags | ||
function header_append() { | ||
echo ' | ||
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.css" integrity="sha384-mf72GmkUsTKkmt05bABaLGVDDWha9SeDJTZ0tTQv4t1Tgz3CRQX+PENxJR8nQ7Tk" crossorigin="anonymous"> | ||
<link rel="stylesheet" href="' . get_template_directory_uri() . '/css/sri-modal.css" /> | ||
'; | ||
} | ||
|
||
function footer_append() { | ||
echo ' | ||
<script src="https://code.jquery.com/jquery-2.2.0.min.js" integrity="sha384-K+ctZQ+LL8q6tP7I94W+qzQsfRV2a+AfHIi9k8z8l9ggpc8X+Ytst4yBo/hH+8Fk" crossorigin="anonymous"></script> | ||
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js" integrity="sha384-YWP9O4NjmcGo4oEJFXvvYSEzuHIvey+LbXkBNJ1Kd0yfugEZN9NCQNpRYBVC1RvA" crossorigin="anonymous"></script> | ||
<script src="' . get_template_directory_uri() . '/js/clipboard.1.5.5.min.js"></script> | ||
<script src="' . get_template_directory_uri() . '/js/sri-modal.js"></script> | ||
'; | ||
} | ||
|
||
?> | ||
|
||
<?php get_header(); ?> | ||
|
||
<?php the_post(); ?> | ||
|
||
<div id="sri-modal-template" title="Code Integration"> | ||
<div class="sri-modal-link"> | ||
<code><script | ||
<span>src="{{link}}"</span> | ||
<span>integrity="{{hash}}"</span> | ||
<span>crossorigin="anonymous"></script></span> | ||
</code> | ||
|
||
<button class="sri-modal-copy-btn" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This button should start with a title and have the tooltip initialized so that the feature is discoverable. |
||
data-clipboard-text='<script src="{{link}}" integrity="{{hash}}" crossorigin="anonymous"></script>'> | ||
<i class="sri-modal-icon-copy icon-copy"></i> | ||
</button> | ||
</div> | ||
|
||
<div class="sri-modal-info"> | ||
The <code>integrity</code> and <code>crossorigin</code> attributes are used for | ||
<a href="https://www.w3.org/TR/SRI/" target="_blank">Subresource Integrity (SRI) checking</a>. | ||
This allows browsers to ensure that resources hosted on third-party servers have | ||
not been tampered with. Use of SRI is recommended as a best-practice, whenever | ||
libraries are loaded from a third-party source. Read more at <a href="https://www.srihash.org/" target="_blank">srihash.org</a> | ||
</div> | ||
</div> | ||
|
||
<div class="content-full twelve columns"> | ||
<div id="content"> | ||
<?php if ( !count( get_post_meta( $post->ID, "hide_title" ) ) ) : ?> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Added for SRI Modal | ||
*/ | ||
.sri-modal { | ||
padding: 0; | ||
border: none; | ||
background: #fff; | ||
border-radius: 0; | ||
} | ||
|
||
.sri-modal .ui-dialog-titlebar { | ||
padding: 0; | ||
border: none; | ||
background: #fff; | ||
color: #000; | ||
cursor: auto; | ||
} | ||
|
||
.sri-modal .ui-dialog-title { | ||
padding-top: 20px; | ||
text-align: center; | ||
font-family: "klavika-web", "Helvetica Neue", Helvetica, Arial, Geneva, sans-serif; | ||
font-weight: 400; | ||
width: 100%; | ||
} | ||
|
||
.sri-modal .ui-dialog-titlebar-close { | ||
background: none; | ||
border: none; | ||
right: 28px; | ||
} | ||
|
||
.sri-modal .ui-icon-closethick { | ||
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAclBMVEUAAADMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMxg1ZvWAAAAJXRSTlMAAQIDBAUGCQsNDhQWGSg4g4uUoKOoq62vsLW8wMrO2tzk5ujxm/5xbwAAAGxJREFUGBmNwVcWgkAQRcFHg4FgzjomZu7+t+hpRv6p0iS7byPJTs+5BluIjewML5O7A3F1AdJMrgpkqVVWBVxqNVriNhrZDRdrZXYl62sNjkBaB6Cv5PaQOpUB3iZXHFInqXx8FvozDQpN8gNoXAtiMhPWmQAAAABJRU5ErkJggg==) 0 0; | ||
} | ||
|
||
.sri-modal .ui-widget-content { | ||
padding: 30px 0 0 0; | ||
} | ||
|
||
.sri-modal .ui-widget-content a { | ||
color: #b24926; | ||
} | ||
|
||
.sri-modal-link { | ||
width: 810px; | ||
word-wrap: break-word; | ||
word-break: break-all; | ||
display: inline-block; | ||
background-color: #f8fbfb; | ||
padding: 0 10px; | ||
position: relative; | ||
} | ||
|
||
.sri-modal-link code { | ||
width: 765px; | ||
display: inline-block; | ||
white-space: pre-line; | ||
background-color: transparent; | ||
padding: 0; | ||
font-size: 13px; | ||
line-height: 16px; | ||
} | ||
|
||
.sri-modal-copy-btn { | ||
background-color: #1c6db3; | ||
border: none; | ||
font-size: 1rem; | ||
width: 35px; | ||
height: 35px; | ||
cursor: pointer; | ||
position: absolute; | ||
top: 5px; | ||
} | ||
|
||
.sri-modal-copy-btn > i { | ||
color: #fff; | ||
} | ||
|
||
.sri-modal-info { | ||
padding: 15px; | ||
font: 15px/22px "Helvetica Neue", HelveticaNeue, Helvetica, Arial, sans-serif; | ||
} | ||
|
||
#sri-modal-template { | ||
display: none; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,12 @@ | |
</div> | ||
</footer> | ||
|
||
<?php wp_footer(); ?> | ||
<?php | ||
wp_footer(); | ||
|
||
if ( function_exists( 'footer_append' ) ) | ||
footer_append(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just leaving myself a note to come back to this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure about this approach, so I'd be interested in your feedback and possible alternative. It does allow other themes to follow suit, but feels a little hacky at the same time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what problem you were having enqueueing these files, but replacing the function definitions in wp_enqueue_style('jquery-ui', 'https://code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.css');
wp_enqueue_style('sri-modal', get_template_directory_uri() . '/css/sri-modal.css');
wp_enqueue_script('jquery-ui', 'https://code.jquery.com/ui/1.11.4/jquery-ui.min.js');
wp_enqueue_script('clipboard', get_template_directory_uri() . '/js/clipboard.1.5.5.min.js');
wp_enqueue_script('sri-modal', get_template_directory_uri() . '/js/sri-modal.js'); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, yes that works. Apologies, I must have had a type or something in my tests. |
||
?> | ||
|
||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
(function() { | ||
// Store modal templates | ||
var modalTemplate = $( "#sri-modal-template" )[ 0 ].outerHTML, | ||
clipboard; | ||
|
||
// Show modal on click | ||
$( "body" ).on( "click", ".open-sri-modal", function( event ) { | ||
if ( event.ctrlKey || event.metaKey ) { | ||
return; | ||
} | ||
|
||
$( replace( modalTemplate, { | ||
link: document.location.origin + $( this ).attr( "href" ), | ||
hash: $( this ).attr( "data-hash" ) | ||
} ) ).removeAttr( "id" ).appendTo( "body" ).dialog( { | ||
modal: true, | ||
resizable: false, | ||
width: 830, | ||
dialogClass: "sri-modal", | ||
draggable: false, | ||
close: function() { | ||
$( this ).remove(); | ||
} | ||
} ); | ||
|
||
event.preventDefault(); | ||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the return statement. |
||
} ); | ||
|
||
// Helper functions | ||
function replace ( string, values ) { | ||
return string.replace( /\{\{([^}]+)}}/g, function( _, key ) { | ||
return values[key]; | ||
}); | ||
} | ||
|
||
clipboard = new Clipboard( "[data-clipboard-text]" ); | ||
|
||
clipboard.on( "success", function( e ) { | ||
$( e.trigger ) | ||
.attr( "title", "Copied!" ) | ||
.tooltip() | ||
.tooltip( "open" ) | ||
.one( "mouseout", function() { | ||
$( this ) | ||
.removeAttr( "title" ) | ||
.tooltip( "destroy" ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Invert the order so the tooltip is destroyed first. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, this would completely change once the button always has a tooltip (like GitHub); at that point you won't be destroying it. |
||
} ); | ||
} ); | ||
|
||
clipboard.on( "error", function( e ) { | ||
$( e.trigger ) | ||
.attr( "title", "Press Ctrl+C to copy!" ) | ||
.tooltip() | ||
.tooltip( "open" ) | ||
.one( "mouseout", function() { | ||
$( this ) | ||
.removeAttr( "title" ) | ||
.tooltip( "destroy" ); | ||
} ); | ||
} ); | ||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jQuery is already loaded.