diff --git a/_js/app.js b/_js/app.js index 44aa04163..921be9230 100644 --- a/_js/app.js +++ b/_js/app.js @@ -6,5 +6,10 @@ window.Prism = require('prismjs') require('sanitize.css') require('prismjs/plugins/line-highlight/prism-line-highlight.css') +// Behaviors that need to go first +require('./behaviors/main-body') + +// All the others function requireAll (r) { r.keys().forEach(r) } +requireAll(require.context('./initializers/', true, /\.js$/)) requireAll(require.context('./behaviors/', true, /\.js$/)) diff --git a/_js/behaviors/h3-section-list.js b/_js/behaviors/h3-section-list.js new file mode 100644 index 000000000..20a50aa0b --- /dev/null +++ b/_js/behaviors/h3-section-list.js @@ -0,0 +1,15 @@ +import $ from 'jquery' +import Isotope from 'isotope-layout/dist/isotope.pkgd.js' + +/* + * Behavior: Isotope + */ + +$(function () { + $('[data-js-h3-section-list]').each(function () { + var iso = new Isotope(this, { + itemSelector: '.h3-section', + transitionDuration: 0 + }) + }) +}) diff --git a/_js/behaviors/main-body.js b/_js/behaviors/main-body.js new file mode 100644 index 000000000..287526915 --- /dev/null +++ b/_js/behaviors/main-body.js @@ -0,0 +1,11 @@ +import $ from 'jquery' +import wrapify from '../wrapify' + +/* + * Behavior: Wrapping + */ + +$(function () { + const $root = $('[data-js-main-body]') + wrapify($root) +}) diff --git a/_js/behaviors/no-preview.js b/_js/behaviors/no-preview.js index 15b15380b..4bf5fe67c 100644 --- a/_js/behaviors/no-preview.js +++ b/_js/behaviors/no-preview.js @@ -1,11 +1,14 @@ import $ from 'jquery' +import ready from 'dom101/ready' +import remove from 'dom101/remove' +import onmount from 'onmount' /* - * Behavior: [data-js-no-preview] + * Behavior: Things to remove when preview mode is on */ -$(function () { +onmount('[data-js-no-preview]', function (b) { if (~window.location.search.indexOf('preview=1')) { - $('[data-js-no-preview]').remove() + remove(this) } }) diff --git a/_js/initializers/onmount.js b/_js/initializers/onmount.js new file mode 100644 index 000000000..5e8787d09 --- /dev/null +++ b/_js/initializers/onmount.js @@ -0,0 +1,4 @@ +import ready from 'dom101/ready' +import onmount from 'onmount' + +ready(() => { onmount() }) diff --git a/_js/wrapify/index.js b/_js/wrapify/index.js new file mode 100644 index 000000000..d7ce38d0d --- /dev/null +++ b/_js/wrapify/index.js @@ -0,0 +1,62 @@ +import $ from 'jquery' + +/* + * Wraps h2 sections into h2-section. + * Wraps h3 sections into h3-section. + */ + +export default function wrapify ($root) { + const $h2sections = groupify($root, { + tag: 'h2', + wrapper: '