From 9550cf65f7f1f53a43d3cb8f2e1b1a8dc9f85a51 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Tue, 1 Dec 2015 08:33:23 +0000 Subject: [PATCH] Moved general utils into another file --- static/src/js/app.js | 20 +++----------------- static/src/js/utils.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 17 deletions(-) create mode 100644 static/src/js/utils.js diff --git a/static/src/js/app.js b/static/src/js/app.js index cf35219..7d93c95 100644 --- a/static/src/js/app.js +++ b/static/src/js/app.js @@ -1,25 +1,11 @@ /* global $ */ +require('./utils.js'); + var React = require('react'); var ProjectImagesTypes = require('./components/project-images-types'); var ProjectImagesMain = require('./components/project-images-main'); -$(function() { // https://css-tricks.com/snippets/jquery/smooth-scrolling/ - $('a[href*=#]:not([href=#])').click(function() { - if (location.pathname.replace(/^\//, '') === this.pathname.replace(/^\//, '') - && location.hostname === this.hostname) { - var target = $(this.hash); - target = target.length ? target : $('[name=' + this.hash.slice(1) + ']'); - if (target.length) { - $('html,body').animate({ - scrollTop: target.offset().top - }, 1000); - return false; - } - } - }); -}); - -if ($('body').hasClass('index')) { +if ($('body').hasClass('index')) { // Render components on index React.render(, document.getElementById('project-images-types')); React.render(, document.getElementById('project-images-main')); } diff --git a/static/src/js/utils.js b/static/src/js/utils.js new file mode 100644 index 0000000..3b7ba93 --- /dev/null +++ b/static/src/js/utils.js @@ -0,0 +1,16 @@ +/* global $ */ +$(function() { // https://css-tricks.com/snippets/jquery/smooth-scrolling/ + $('a[href*=#]:not([href=#])').click(function() { + if (location.pathname.replace(/^\//, '') === this.pathname.replace(/^\//, '') + && location.hostname === this.hostname) { + var target = $(this.hash); + target = target.length ? target : $('[name=' + this.hash.slice(1) + ']'); + if (target.length) { + $('html,body').animate({ + scrollTop: target.offset().top + }, 1000); + return false; + } + } + }); +});