Guest User

Untitled

a guest
May 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. export const pageScript = (path, fn) => (...args) => {
  2. $(document).on('turbolinks:load', () => {
  3. const pageID = $('body').attr('id');
  4. const map = {
  5. string: () => pageID === path,
  6. object: () => path.some(x => x === pageID)
  7. };
  8. const isAllow = map[typeof path]();
  9. return isAllow ? fn(...args) : null;
  10. });
  11. };
  12.  
  13. // usage:
  14. // homeIndex.js
  15. const homeIndex = () => {
  16. alert(`I'm home page specific logic`);
  17. }
  18.  
  19. export default pageScript('home-index', homeIndex);
Add Comment
Please, Sign In to add comment