Skip to content

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

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
adding sri modal to codeorigin
  • Loading branch information
jmervine committed Feb 2, 2016
commit 2d6cd06b6d1f4cfaf64d819686f410bcbd2d0b2b
47 changes: 47 additions & 0 deletions themes/codeorigin.jquery.com/page.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,54 @@
<?php

// attach custom header and footer tags
function header_append() {
echo '
<link rel="stylesheet" href="' . get_template_directory_uri() . '/css/font-awesome.css" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Font Awesome is already loaded on the page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw it in the themes/jquery/css directory, but not included. I'l drop this out.

<link rel="stylesheet" href="' . get_template_directory_uri() . '/css/hint.2.0.0.min.css" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use jQuery UI.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scottgonzalez to be clear, use jQuery UI Tooltip instead of hint.css?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. It's already being loaded.

<link rel="stylesheet" href="' . get_template_directory_uri() . '/css/jquery-ui.1.11.4.min.css" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you adding a local copy of a jQuery UI theme instead of using the CDN?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an oversight, I believe I was using the cdn at one point. I'll fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

<link rel="stylesheet" href="' . get_template_directory_uri() . '/css/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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jQuery is already loaded.

<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/modal.js"></script>
';
}

?>

<?php get_header(); ?>

<?php the_post(); ?>

<div id="sri-modal-template" title="jQuery Code Integration">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This title isn't great since not everything is about jQuery.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking just "Code Integration", unless someone has a better suggestion.

<div class="sri-modal-link">
<code>
&lt;script
&nbsp;&nbsp;<span>src="{{link}}"</span>
&nbsp;&nbsp;<span>integrity="{{hash}}"</span>
&nbsp;&nbsp;<span>crossorigin="anonymous"&gt;&lt;/script&gt;</span>
</code>

<button class="sri-modal-copy-btn hint--top hint-rounded hint--always"
data-clipboard-text='&lt;script src="{{link}}" integrity="{{hash}}" crossorigin="anonymous"&gt;&lt;/script&gt;'>
<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" ) ) ) : ?>
Expand Down
5 changes: 5 additions & 0 deletions themes/jquery/css/hint.2.0.0.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions themes/jquery/css/jquery-ui.1.11.4.min.css

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions themes/jquery/css/modal.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* 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;
}

code {
font-family: "source-code-pro", Consolas, monospace ;
word-spacing: 0;
padding: 0 3px;
background-color: #e6e6e6;
border-radius: 3px;
white-space: pre-wrap;
word-wrap: break-word;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this file contains a fair amount of code in order to not follow the existing design.

cc @jquery/content

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too right, removing.


code span {
word-wrap: normal;
white-space: nowrap;
}

#sri-modal-template {
display: none;
}

7 changes: 6 additions & 1 deletion themes/jquery/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@
</div>
</footer>

<?php wp_footer(); ?>
<?php
wp_footer();

if ( function_exists( 'footer_append' ) )
footer_append();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just leaving myself a note to come back to this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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 page.php with the following code works just fine for me:

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');

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>
3 changes: 3 additions & 0 deletions themes/jquery/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
wp_enqueue_script( 'comment-reply' );

wp_head();

if ( function_exists( 'header_append' ) )
header_append();
?>

</head>
Expand Down
Loading