Browse Source

Minified js (#485)

no issue

- Added a `js` task to run on the gulp build process and minifies our js files
- Changed the required scripts in `default.hbs` to use the minified js files in `/built/`
- Moved existing `js` tasks from `zip` task
master
Aileen Nowak 1 year ago
committed by John O'Nolan
parent
commit
bef56a2294
8 changed files with 28 additions and 11 deletions
  1. +2
    -0
      assets/built/infinitescroll.js
  2. +1
    -0
      assets/built/infinitescroll.js.map
  3. +2
    -0
      assets/built/jquery.fitvids.js
  4. +1
    -0
      assets/built/jquery.fitvids.js.map
  5. +1
    -1
      assets/built/screen.css
  6. +1
    -1
      assets/built/screen.css.map
  7. +2
    -2
      default.hbs
  8. +18
    -7
      gulpfile.js

+ 2
- 0
assets/built/infinitescroll.js View File

@@ -0,0 +1,2 @@
$(function(t){var o=1,r=window.location.pathname,a=t(document),s=t(".post-feed"),c=300,l=!1,w=!1,d=window.scrollY,v=window.innerHeight,u=a.height();function f(){d=window.scrollY,e()}function g(){v=window.innerHeight,u=a.height(),e()}function e(){l||requestAnimationFrame(n),l=!0}function n(){var e,n;if(n=/(?:page\/)(\d)(?:\/)$/i,(e=(e=r).replace(/#(.*)$/g,"").replace("////g","/")).match(n)&&(o=parseInt(e.match(n)[1]),e=e.replace(n,"")),r=e,!w)if(d+v<=u-c)l=!1;else{if(o>=maxPages)return window.removeEventListener("scroll",f,{passive:!0}),void window.removeEventListener("resize",g);w=!0;var i=r+"page/"+(o+=1)+"/";t.get(i,function(e){var n=document.createRange().createContextualFragment(e).querySelectorAll(".post");n.length&&[].forEach.call(n,function(e){s[0].appendChild(e)})}).fail(function(e){404===e.status&&(window.removeEventListener("scroll",f,{passive:!0}),window.removeEventListener("resize",g))}).always(function(){u=a.height(),l=w=!1})}}window.addEventListener("scroll",f,{passive:!0}),window.addEventListener("resize",g),n()});
//# sourceMappingURL=infinitescroll.js.map

+ 1
- 0
assets/built/infinitescroll.js.map
File diff suppressed because it is too large
View File


+ 2
- 0
assets/built/jquery.fitvids.js View File

@@ -0,0 +1,2 @@
!function(d){"use strict";d.fn.fitVids=function(t){var i={customSelector:null,ignore:null};if(!document.getElementById("fit-vids-style")){var e=document.head||document.getElementsByTagName("head")[0],r=document.createElement("div");r.innerHTML='<p>x</p><style id="fit-vids-style">.fluid-width-video-container{flex-grow: 1;width:100%;}.fluid-width-video-wrapper{width:100%;position:relative;padding:0;}.fluid-width-video-wrapper iframe,.fluid-width-video-wrapper object,.fluid-width-video-wrapper embed {position:absolute;top:0;left:0;width:100%;height:100%;}</style>',e.appendChild(r.childNodes[1])}return t&&d.extend(i,t),this.each(function(){var t=['iframe[src*="player.vimeo.com"]','iframe[src*="youtube.com"]','iframe[src*="youtube-nocookie.com"]','iframe[src*="kickstarter.com"][src*="video.html"]',"object","embed"];i.customSelector&&t.push(i.customSelector);var r=".fitvidsignore";i.ignore&&(r=r+", "+i.ignore);var e=d(this).find(t.join(","));(e=(e=e.not("object object")).not(r)).each(function(){var t=d(this);if(!(0<t.parents(r).length||"embed"===this.tagName.toLowerCase()&&t.parent("object").length||t.parent(".fluid-width-video-wrapper").length)){t.css("height")||t.css("width")||!isNaN(t.attr("height"))&&!isNaN(t.attr("width"))||(t.attr("height",9),t.attr("width",16));var e=("object"===this.tagName.toLowerCase()||t.attr("height")&&!isNaN(parseInt(t.attr("height"),10))?parseInt(t.attr("height"),10):t.height())/(isNaN(parseInt(t.attr("width"),10))?t.width():parseInt(t.attr("width"),10));if(!t.attr("name")){var i="fitvid"+d.fn.fitVids._count;t.attr("name",i),d.fn.fitVids._count++}t.wrap('<div class="fluid-width-video-container"><div class="fluid-width-video-wrapper"></div></div>').parent(".fluid-width-video-wrapper").css("padding-top",100*e+"%"),t.removeAttr("height").removeAttr("width")}})})},d.fn.fitVids._count=0}(window.jQuery||window.Zepto);
//# sourceMappingURL=jquery.fitvids.js.map

+ 1
- 0
assets/built/jquery.fitvids.js.map
File diff suppressed because it is too large
View File


+ 1
- 1
assets/built/screen.css
File diff suppressed because it is too large
View File


+ 1
- 1
assets/built/screen.css.map
File diff suppressed because it is too large
View File


+ 2
- 2
default.hbs View File

@@ -73,7 +73,7 @@
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous">
</script>
<script type="text/javascript" src="{{asset "js/jquery.fitvids.js"}}"></script>
<script type="text/javascript" src="{{asset "built/jquery.fitvids.js"}}"></script>

{{#if pagination.pages}}
<script>
@@ -82,7 +82,7 @@
// we reached the last page already.
var maxPages = parseInt('{{pagination.pages}}');
</script>
<script src="{{asset "js/infinitescroll.js"}}"></script>
<script src="{{asset "built//infinitescroll.js"}}"></script>
{{/if}}

{{!-- The #block helper will pull in data from the #contentFor other template files. In this case, there's some JavaScript which we only want to use in post.hbs, but it needs to be included down here, after jQuery has already loaded. --}}


+ 18
- 7
gulpfile.js View File

@@ -26,10 +26,12 @@ var nodemonServerInit = function () {
livereload.listen(1234);
};

gulp.task('build', ['css'], function (/* cb */) {
gulp.task('build', ['css', 'js'], function (/* cb */) {
return nodemonServerInit();
});

gulp.task('generate', ['css', 'js']);

gulp.task('css', function () {
var processors = [
easyimport,
@@ -48,25 +50,34 @@ gulp.task('css', function () {
.pipe(livereload());
});

gulp.task('js', function () {
var jsFilter = filter(['**/*.js'], {restore: true});

return gulp.src('assets/js/*.js')
.on('error', swallowError)
.pipe(sourcemaps.init())
.pipe(jsFilter)
.pipe(uglify())
.pipe(jsFilter.restore)
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('assets/built/'))
.pipe(livereload());
});

gulp.task('watch', function () {
gulp.watch('assets/css/**', ['css']);
});

gulp.task('zip', ['css'], function () {
gulp.task('zip', ['css', 'js'], function () {
var targetDir = 'dist/';
var themeName = require('./package.json').name;
var filename = themeName + '.zip';

var jsFilter = filter(['**/*.js'], {restore: true});

return gulp.src([
'**',
'!node_modules', '!node_modules/**',
'!dist', '!dist/**'
])
.pipe(jsFilter)
.pipe(uglify())
.pipe(jsFilter.restore)
.pipe(zip(filename))
.pipe(gulp.dest(targetDir));
});


Loading…
Cancel
Save