Commit 34ab1614
34ab16146513Merged
Justin Dorfman <[email protected]> · 10 years ago · 1 file · +1 added
Description
Added jquery-sri-demo
Details
- Commit
- 34ab16146513
- Parent
- 520f7069f7a0
public/2015/temp/jquery-sri-demo.htmladdedView file
1+
<!DOCTYPE html>2+
<html lang="en">3+
<head>4+
<meta charset="UTF-8">5+
<title>Modal</title>6+
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet">7+
<link href="https://cdn.jsdelivr.net/hint.css/2.0.0/hint.min.css" rel="stylesheet">8+
9+
<!-- Modal CSS -->10+
<style>11+
/* General modal style */12+
.modal-overlay {13+
position: fixed;14+
top: 0;15+
left: 0;16+
width: 100%;17+
height: 100%;18+
z-index: 10000;19+
background-color: #000;20+
opacity: 0;21+
}22+
23+
.modal {24+
position: relative;25+
top: -400px;26+
width: 830px;27+
margin: 0 auto;28+
background-color: #fff;29+
z-index: 10100;30+
box-shadow: 2px 4px 8px 0 rgba(0, 0, 0, .5);31+
}32+
33+
.modal-header {34+
text-align: center;35+
padding: 20px 10px;36+
}37+
38+
.modal-title {39+
margin: 0;40+
}41+
42+
.modal-close {43+
position: absolute;44+
top: 20px;45+
right: 30px;46+
color: #ccc;47+
cursor: pointer;48+
}49+
50+
/* SRI modal specific */51+
.sri-modal-link {52+
width: 810px;53+
word-wrap: break-word;54+
word-break: break-all;55+
display: inline-block;56+
background-color: #f8fbfb;57+
padding: 0 10px;58+
position: relative;59+
}60+
61+
.sri-modal-link code {62+
width: 765px;63+
display: inline-block;64+
white-space: pre-line;65+
background-color: transparent;66+
padding: 0;67+
font-size: 13px;68+
line-height: 16px;69+
}70+
71+
.sri-modal-copy-btn {72+
background-color: #1c6db3;73+
color: #fff;74+
border: none;75+
font-size: 1rem;76+
width: 35px;77+
height: 35px;78+
cursor: pointer;79+
position: absolute;80+
top: 5px;81+
}82+
83+
.sri-modal-info {84+
padding: 15px;85+
}86+
87+
/* Just to make it prettier */88+
.modal-title {89+
font-family: "klavika-web", "Helvetica Neue", Helvetica, Arial, Geneva, sans-serif !important;90+
font-weight: 400;91+
}92+
93+
.modal-body {94+
font: 15px/22px "Helvetica Neue", HelveticaNeue, Helvetica, Arial, sans-serif;95+
}96+
97+
a {98+
color: #b24926;99+
}100+
101+
code {102+
font-family: "source-code-pro", Consolas, monospace !important;103+
word-spacing: 0;104+
padding: 0 3px;105+
background-color: #e6e6e6;106+
border-radius: 3px;107+
white-space: pre-wrap;108+
word-wrap: break-word;109+
}110+
</style>111+
</head>112+
113+
<body>114+
<a class="open-sri-modal" href="https://code.jquery.com/jquery-2.2.0.min.js" data-hash="sha256-ihAoc6M/JPfrIiIeayPE9xjin4UWjsx2mjW/rtmxLM4=">Show modal</a>115+
116+
<!-- Modal header template -->117+
<script type="text/html" id="sri-modal-header">118+
<h3 class="modal-title">Copy Below</h3>119+
</script>120+
121+
<!-- Modal body template -->122+
<script type="text/html" id="sri-modal-body">123+
<div class="sri-modal-link">124+
<code><script src="{{link}}"125+
integrity="{{hash}}"126+
crossorigin="anonymous"></script></code>127+
128+
<button class="sri-modal-copy-btn hint--top hint-rounded hint--no-animate" data-clipboard-text='<script src="{{link}}" integrity="{{hash}}" crossorigin="anonymous"></script>'>129+
<i class="fa fa-copy"></i>130+
</button>131+
</div>132+
133+
<div class="sri-modal-info">134+
If you are wondering what <code>integrity</code> attribute is all about les us135+
explain. Subresource Integrity or SRI is a new <a href="https://www.w3.org/TR/SRI/">136+
W3C specification</a> that allows web developers to ensure that resources hosted on137+
third-party servers like code.jquery.com have not been tampered with. Use of SRI is138+
recommended as a best-practice, whenever libraries are loaded from a third-party139+
source.<br>140+
Read more at <a href="https://www.srihash.org/">srihash.org</a>141+
</div>142+
</script>143+
144+
<!-- jQuery and clipboard.js -->145+
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>146+
<script src="https://cdn.jsdelivr.net/clipboard.js/1.5.5/clipboard.min.js"></script>147+
148+
<script>149+
// Modal150+
function Modal ( header, body ) {151+
this.$el = $( "<div class='modal'></div>" );152+
this.$overlay = $( "<div class='modal-overlay'></div>" );153+
this.$header = $( "<div class='modal-header'></div>" ).html( header ).appendTo( this.$el );154+
this.$body = $( "<div class='modal-body'></div>" ).html( body ).appendTo( this.$el );155+
this.$closeBtn = $( "<span class='modal-close'><i class='fa fa-close'></i></span>" )156+
.appendTo( this.$header );157+
}158+
159+
Modal.prototype.hide = function() {160+
this.$overlay.animate( { opacity: 0 }, function() {161+
this.$overlay.remove();162+
}.bind( this ) );163+
164+
this.$el.animate( { top: -400 }, function() {165+
this.$el.remove();166+
}.bind( this ) );167+
};168+
169+
Modal.prototype.show = function() {170+
this.$el.add( this.$overlay ).appendTo( "body" );171+
172+
this.$overlay.add( this.$closeBtn ).on( "click", function() {173+
this.hide();174+
}.bind( this ) );175+
176+
this.$el.animate( { top: 200 } );177+
this.$overlay.animate( { opacity: .5 } );178+
};179+
180+
// Store modal templates181+
var title = $( "#sri-modal-header" ).html(),182+
body = $( "#sri-modal-body" ).html(),183+
clipboard;184+
185+
// Show modal on click186+
$( "body" ).on( "click", ".open-sri-modal", function() {187+
new Modal( title, replace( body, {188+
link: $( this ).attr( "href" ),189+
hash: $( this ).attr( "data-hash" )190+
} ) ).show();191+
192+
return false;193+
} );194+
195+
// Helper functions196+
function replace ( string, values ) {197+
$.each( values, function( key, value ) {198+
string = string.replace( new RegExp( "\\{\\{" + key + "}}", "g" ), value );199+
} );200+
201+
return string;202+
}203+
204+
clipboard = new Clipboard( "[data-clipboard-text]" );205+
206+
clipboard.on( "success", function( e ) {207+
$( e.trigger ).attr( "data-hint", "Copied!").on( "mouseout", function() {208+
$( this ).removeAttr( "data-hint" );209+
} );210+
} );211+
212+
clipboard.on( "error", function( e ) {213+
$( e.trigger ).attr( "data-hint", "Press Ctrl+C to copy!").on( "mouseout", function() {214+
$( this ).removeAttr( "data-hint" );215+
} );216+
} );217+
</script>218+
</body>219+
</html>