Permalink
Browse files

replaced jsmin with uglify

  • Loading branch information...
zserge committed Jun 13, 2016
1 parent 3ca42a8 commit 9fd24535509776477723c74518f61fec415bb935
Showing with 4 additions and 16 deletions.
  1. +2 −2 build.js
  2. +1 −1 package.json
  3. +1 −13 slide.html
View
@@ -1,14 +1,14 @@
var fs = require('fs');
var jsmin = require('jsmin').jsmin;
var uglify = require("uglify-js").minify;
var cssmin = require('cssmin');
var css = fs.readFileSync("src/slide.css", encoding='utf8');
var js = fs.readFileSync("src/slide.js", encoding='utf8');
var html = fs.readFileSync("src/slide.html", encoding='utf8');
var inline = html
.replace(/<script src="slide.js"><\/script>/, '<script>'+jsmin(js)+'</script>')
.replace(/<script src="slide.js"><\/script>/, '<script>'+uglify(js, {fromString: true}).code+'</script>')
.replace(/<link .*href="slide.css">/, '<style>'+cssmin(css)+'</style>');
console.log(inline);
View
@@ -19,6 +19,6 @@
"devDependencies": {
"cssmin": "^0.4.3",
"jshint": "^2.9.2",
"jsmin": "^1.0.1"
"uglify-js": "^2.6.2"
}
}
View
@@ -5,19 +5,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Slide</title>
<style>*{margin:0;padding:0;box-sizing:border-box}#slide{display:none}.slide{white-space:nowrap}.slide-content{align-self:center}@media screen{body{position:absolute;top:50%;left:50%}.slide-4x3{width:1024px;height:768px;margin:-384px 0 0 -512px}.slide-16x9{width:1024px;height:576px;margin:-288px 0 0 -512px}.slide-16x10{width:1024px;height:640px;margin:-320px 0 0 -512px}.slide{position:absolute;width:100%;height:100%;display:flex;justify-content:center;overflow:hidden}}@media print{body{transform:none!important}h1{font-size:1.8rem;line-height:1.5;letter-spacing:-.05rem;font-weight:300}.slide-root{width:100%;display:flex;flex-wrap:wrap;align-items:stretch}.slide-content{transform:none!important}.slide{display:flex;justify-content:center;flex:1;padding:.5rem;margin:.5rem .5rem 4rem .5rem;border:1px solid rgba(0,0,0,0.2);visibility:visible!important}}</style>
<script>var INDENT_RE=/^(?:( )+|\t+)/;function trimIndent(s){var indent=(s.match(INDENT_RE)||[''])[0].length;if(indent>0){var trim=s.substring(0,indent);return s.replace(new RegExp(trim,'g'),'');}}
function renderSlide(root,slide,index){var lines=slide.split('\n');var emSpanStart=-1;var slideWrapper=document.createElement('div');var slideContent=document.createElement('div');var html='';slideWrapper.className='slide slide-'+index;slideContent.className='slide-content';for(var i=0;i<lines.length;i++){var line=lines[i];if(line.startsWith('#')){html=html+'<h1>'+line.substring(1)+'</h1>';}else if(line.startsWith(' ')||line.startsWith('\t')){html=html+'<pre>'+line.replace(/^( )|\t/,'')+'</pre>';}else{if(line.startsWith('.')){line=line.substring(1);}
for(var j=0;j<line.length;j++){var c=line.charAt(j);if(c=='*'){if(emSpanStart==-1){html=html+'<strong>';emSpanStart=html.length;}else{if(emSpanStart!=html.length){html=html+'</strong>';}else{html=html.substring(0,html.length-8)+'*';}
emSpanStart=-1;}}else{html=html+c;}}
html=html+'<br/>';}}
slideContent.innerHTML=html;slideWrapper.appendChild(slideContent);root.appendChild(slideWrapper);slideWrapper.style.visibility="hidden";}
function render(content){var root=document.createElement('div');root.className='slide-root';document.body.appendChild(root);content=trimIndent(content);var slides=content.split(/[\s+]\n/mg);for(var i=0;i<slides.length;i++){var slide=slides[i].trim();renderSlide(root,slide,i);}
return root;}
function resize(){var w=window.innerWidth;var h=window.innerHeight;var bw=document.body.offsetWidth;var bh=document.body.offsetHeight;var scale=((w/h<bw/bh)?w/bw:h/bh);document.body.style.transform='scale('+scale+')';}
var currentSlide=-1;function goTo(slideIndex){currentSlide=slideIndex;window.location.hash=slideIndex;var slides=document.querySelectorAll('.slide');for(var i=0;i<slides.length;i++){var el=slides[i];var slide=el.children[0];var scaleWidth=(el.offsetWidth*0.8/slide.offsetWidth);var scaleHeight=(el.offsetHeight*0.8/slide.offsetHeight);slide.style.transform='scale('+Math.min(scaleWidth,scaleHeight)+')';if(i==currentSlide){el.style.visibility='';}else{el.style.visibility='hidden';}}}
function next(){goTo(Math.min(currentSlide+1,document.querySelectorAll('.slide').length-1));}
function prev(){goTo(Math.max(currentSlide-1,0));}
window.onload=function(){resize();render(document.getElementById('slide').innerHTML);goTo(window.location.hash.substring(1)||0);window.onclick=next;window.onresize=resize;window.onkeydown=function(e){if(e.keyCode==39){next();}else if(e.keyCode==37){prev();}};};</script>
<script>function trimIndent(e){var t=(e.match(INDENT_RE)||[""])[0].length;if(t>0){var n=e.substring(0,t);return e.replace(new RegExp(n,"g"),"")}}function renderSlide(e,t,n){var i=t.split("\n"),r=-1,o=document.createElement("div"),d=document.createElement("div"),s="";o.className="slide slide-"+n,d.className="slide-content";for(var l=0;l<i.length;l++){var a=i[l];if(a.startsWith("#"))s=s+"<h1>"+a.substring(1)+"</h1>";else if(a.startsWith(" ")||a.startsWith(" "))s=s+"<pre>"+a.replace(/^( )|\t/,"")+"</pre>";else{a.startsWith(".")&&(a=a.substring(1));for(var c=0;c<a.length;c++){var h=a.charAt(c);"*"==h?-1==r?(s+="<strong>",r=s.length):(r!=s.length?s+="</strong>":s=s.substring(0,s.length-8)+"*",r=-1):s+=h}s+="<br/>"}}d.innerHTML=s,o.appendChild(d),e.appendChild(o),o.style.visibility="hidden"}function render(e){var t=document.createElement("div");t.className="slide-root",document.body.appendChild(t),e=trimIndent(e);for(var n=e.split(/[\s+]\n/gm),i=0;i<n.length;i++){var r=n[i].trim();renderSlide(t,r,i)}return t}function resize(){var e=window.innerWidth,t=window.innerHeight,n=document.body.offsetWidth,i=document.body.offsetHeight,r=n/i>e/t?e/n:t/i;document.body.style.transform="scale("+r+")"}function goTo(e){currentSlide=e,window.location.hash=e;for(var t=document.querySelectorAll(".slide"),n=0;n<t.length;n++){var i=t[n],r=i.children[0],o=.8*i.offsetWidth/r.offsetWidth,d=.8*i.offsetHeight/r.offsetHeight;r.style.transform="scale("+Math.min(o,d)+")",n==currentSlide?i.style.visibility="":i.style.visibility="hidden"}}function next(){goTo(Math.min(currentSlide+1,document.querySelectorAll(".slide").length-1))}function prev(){goTo(Math.max(currentSlide-1,0))}var INDENT_RE=/^(?:( )+|\t+)/,currentSlide=-1;window.onload=function(){resize(),render(document.getElementById("slide").innerHTML),goTo(window.location.hash.substring(1)||0),window.onclick=next,window.onresize=resize,window.onkeydown=function(e){39==e.keyCode?next():37==e.keyCode&&prev()}};</script>
<style media="screen">
@import url(https://fonts.googleapis.com/css?family=Lato:400,700&subset=latin,latin-ext);
@import url(https://fonts.googleapis.com/css?family=Oswald:400,700);

0 comments on commit 9fd2453

Please sign in to comment.