This repository has been archived by the owner on Aug 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Moving away from Grunt & Babel. - JavaScript ES2015 and ES2015 modules - JavaScript sourcemaps
- Loading branch information
Showing
4 changed files
with
99 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import $ from 'jquery'; | ||
import debug from 'debug'; | ||
|
||
export function emptyLinks() { | ||
const log = debug('theme:emptyLinks'); | ||
const links = $('a[href=""], a[href="#"]').toArray(); | ||
log(`There are ${links.length} empty links on this page`, links); | ||
} | ||
|
||
export function externalLinks() { | ||
const log = debug('theme:externalLinks'); | ||
const $links = $('a[href]:not([target])').filter((i, link) => { | ||
const href = $(link).attr('href').trim(); | ||
const isEmpty = href === ''; | ||
const isLocal = href.indexOf(document.location.origin) === 0; | ||
const isAnchor = href.indexOf('#') === 0; | ||
|
||
if (isEmpty || isLocal || isAnchor) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}); | ||
|
||
$links.attr('target', '_blank'); | ||
log(`There are ${$links.length} external links on this page`, $links); | ||
} | ||
|
||
export default { | ||
emptyLinks : emptyLinks, | ||
externalLinks: externalLinks | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
(function ($, $window, $document, $body, Site, Modernizr, _) { | ||
// external scripts | ||
import $ from 'jquery'; | ||
import debug from 'debug'; | ||
|
||
$.extend(Site, { | ||
// DOM ready code | ||
init: function () { | ||
// example of ES2015 modules loading & tree shaking | ||
import { emptyLinks } from './links'; | ||
|
||
}, | ||
const $window = $(window); | ||
const $document = $(document); | ||
|
||
// window on load code | ||
load: function () { | ||
class Site { | ||
constructor() { | ||
$document.ready(() => this.domReady()); | ||
$window.on('load', () => this.windowLoad()); | ||
} | ||
|
||
} | ||
}); | ||
domReady() { | ||
const log = debug('theme:domReady'); | ||
log('dom.ready'); | ||
} | ||
|
||
// Make our namespace globally accessible | ||
window.Site = Site; | ||
windowLoad() { | ||
const log = debug('theme:windowLoad'); | ||
log('window.onload'); | ||
|
||
// Run initialization script on DOM ready | ||
$document.on('ready', Site.init); | ||
// example of ES2015 modules loading & tree shaking | ||
emptyLinks(); | ||
} | ||
} | ||
|
||
// Defer scripts to window on load event | ||
$window.on('load', Site.load); | ||
|
||
})(window.jQuery, window.jQuery(window), window.jQuery(document), window.jQuery(document.body), window.Site || {}, window.Modernizr, window._); | ||
//# sourceMappingURL=site.js.map | ||
export default Site; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const gulp = require('gulp'); | ||
const gp = require('gulp-load-plugins')(); | ||
|
||
gulp.task('rollup', function() { | ||
const es2015 = require('rollup-plugin-buble'); | ||
const uglify = require('rollup-plugin-uglify'); | ||
|
||
gulp.src(__dirname + '/assets/js/site.js') | ||
.pipe(gp.sourcemaps.init()) | ||
.pipe(gp.rollup({ | ||
format: 'umd', | ||
globals: { | ||
debug: 'debug', | ||
jquery: 'jQuery', | ||
modernizr: 'Modernizr' | ||
}, | ||
moduleName: 'Site', | ||
sourceMap: true, | ||
plugins: [ | ||
es2015(), | ||
uglify() | ||
] | ||
})) | ||
.pipe(gp.size({ | ||
showFiles: true, | ||
title: 'JavaScript' | ||
})) | ||
.pipe(gp.sourcemaps.write('.')) | ||
.pipe(gulp.dest(__dirname + '/assets/dist')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters