Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export const pageScript = (path, fn) => (...args) => {
- $(document).on('turbolinks:load', () => {
- const pageID = $('body').attr('id');
- const map = {
- string: () => pageID === path,
- object: () => path.some(x => x === pageID)
- };
- const isAllow = map[typeof path]();
- return isAllow ? fn(...args) : null;
- });
- };
- // usage:
- // homeIndex.js
- const homeIndex = () => {
- alert(`I'm home page specific logic`);
- }
- export default pageScript('home-index', homeIndex);
Add Comment
Please, Sign In to add comment