Skip to content

Commit

Permalink
Use ES2015 modules for core JS
Browse files Browse the repository at this point in the history
  • Loading branch information
thomastuts committed Nov 5, 2020
1 parent 448cd3f commit 6e90a89
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
3 changes: 1 addition & 2 deletions core/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import './prototype-nav';
import './styleguide-code-samples';
import './styleguide-typography';
import './styleguide-search';
import rememberScroll from './styleguide-remember-scroll';

window.$ = $;

const rememberScroll = require('./styleguide-remember-scroll');

rememberScroll('#__prototype-nav');
rememberScroll('.br-styleguide-content');
rememberScroll('.br-styleguide-navigation-holder');
7 changes: 4 additions & 3 deletions core/js/prototype-nav.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const $ = require('jquery');
const packageJson = require('../../package.json');
const config = require('../discovery/config');
import $ from 'jquery';

import packageJson from '../../package.json';
import config from '../discovery/config';

const ACTIVATION_KEYCODE = 77; // 'M' key or 'B' key for Windows
const ACTIVATION_KEYCODE_WINDOWS = 66; // 'M' key or 'B' key for Windows
Expand Down
14 changes: 7 additions & 7 deletions core/js/styleguide-code-samples.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const $ = require('jquery');
const Clipboard = require('clipboard');
const Codemirror = require('codemirror');
const config = require('../discovery/config');
//require('codemirror/mode/javascript/javascript');
require('codemirror/mode/pug/pug');
require('codemirror/mode/xml/xml');
import $ from 'jquery';
import Clipboard from 'clipboard';
import Codemirror from 'codemirror';
import 'codemirror/mode/pug/pug';
import 'codemirror/mode/xml/xml';

import config from '../discovery/config';

const $codeHolders = $('.br-sample-code');
const $codeBlocks = $('.br-sample-markup');
Expand Down
9 changes: 4 additions & 5 deletions core/js/styleguide-remember-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ for (var selector in scrollPositions) {
$(selector).scrollTop(+scrollPositions[selector]);
}

// Export function to store selector in map
module.exports = function (selector) {
scrollPositions[selector] = $(selector).scrollTop() || 0;
};

// Save positions on unload
window.onbeforeunload = function () {
for (var selector in scrollPositions) {
scrollPositions[selector] = $(selector).scrollTop() || 0;
}
sessionStorage.setItem(SCROLL_STORAGE_KEY, JSON.stringify(scrollPositions));
};

export default function (selector) {
scrollPositions[selector] = $(selector).scrollTop() || 0;
}
2 changes: 1 addition & 1 deletion core/js/styleguide-search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const $ = require('jquery');
import $ from 'jquery';

$('#styleguideSearch').on('input', function(e) {

Expand Down
4 changes: 2 additions & 2 deletions core/js/styleguide-typography.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const $ = require('jquery');
import $ from 'jquery';

const $typographyEntries = $('#component-typography tbody tr');

Expand All @@ -17,4 +17,4 @@ on_resize(function() {
calculateFontSizes();
});

calculateFontSizes();
calculateFontSizes();

1 comment on commit 6e90a89

@Wolfr
Copy link
Contributor

@Wolfr Wolfr commented on 6e90a89 Nov 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeehaw!

Please sign in to comment.