Commit 7d048064 authored by Nikolay Gromov's avatar Nikolay Gromov

Впилил линтер JS

parent 5b3006c7
/* global exports process console __dirname Buffer */
/* eslint-disable no-console */
'use strict'; 'use strict';
// Пакеты, использующиеся при обработке // Пакеты, использующиеся при обработке
...@@ -8,7 +10,6 @@ const del = require('del'); ...@@ -8,7 +10,6 @@ const del = require('del');
const pug = require('gulp-pug'); const pug = require('gulp-pug');
const through2 = require('through2'); const through2 = require('through2');
const rename = require('gulp-rename'); const rename = require('gulp-rename');
const replace = require('gulp-replace');
const getClassesFromHtml = require('get-classes-from-html'); const getClassesFromHtml = require('get-classes-from-html');
const browserSync = require('browser-sync').create(); const browserSync = require('browser-sync').create();
const debug = require('gulp-debug'); const debug = require('gulp-debug');
...@@ -34,7 +35,6 @@ const ghpages = require('gh-pages'); ...@@ -34,7 +35,6 @@ const ghpages = require('gh-pages');
const path = require('path'); const path = require('path');
// Глобальные настройки этого запуска // Глобальные настройки этого запуска
const isDev = !process.env.NODE_ENV || process.env.NODE_ENV == 'dev';
const buildLibrary = process.env.BUILD_LIBRARY == 'yes' ? true : false; const buildLibrary = process.env.BUILD_LIBRARY == 'yes' ? true : false;
const nth = {}; const nth = {};
nth.config = require('./config.js'); nth.config = require('./config.js');
...@@ -139,7 +139,7 @@ function generateSvgSprite(cb) { ...@@ -139,7 +139,7 @@ function generateSvgSprite(cb) {
let spriteSvgPath = `${dir.blocks}sprite-svg/svg/`; let spriteSvgPath = `${dir.blocks}sprite-svg/svg/`;
if(nth.config.alwaysAddBlocks.indexOf('sprite-svg') > -1 && fileExist(spriteSvgPath)) { if(nth.config.alwaysAddBlocks.indexOf('sprite-svg') > -1 && fileExist(spriteSvgPath)) {
return src(spriteSvgPath + '*.svg') return src(spriteSvgPath + '*.svg')
.pipe(svgmin(function (file) { .pipe(svgmin(function () {
return { plugins: [{ cleanupIDs: { minify: true } }] } return { plugins: [{ cleanupIDs: { minify: true } }] }
})) }))
.pipe(svgstore({ inlineSvg: true })) .pipe(svgstore({ inlineSvg: true }))
...@@ -236,7 +236,7 @@ exports.compileSass = compileSass; ...@@ -236,7 +236,7 @@ exports.compileSass = compileSass;
function writeJsRequiresFile(cb) { function writeJsRequiresFile(cb) {
let msg = `\n/*!*${doNotEditMsg.replace(/\n /gm,'\n * ').replace(/\n\n$/,'\n */\n\n')}`; let msg = `\n/*!*${doNotEditMsg.replace(/\n /gm,'\n * ').replace(/\n\n$/,'\n */\n\n')}`;
let jsRequires = msg; let jsRequires = msg + '/* global require */\n\n';
nth.config.addJsBefore.forEach(function(src) { nth.config.addJsBefore.forEach(function(src) {
jsRequires += `require('${src}');\n`; jsRequires += `require('${src}');\n`;
}); });
...@@ -338,7 +338,7 @@ function serve() { ...@@ -338,7 +338,7 @@ function serve() {
// Страницы: удаление // Страницы: удаление
watch([`${dir.src}pages/**/*.pug`], { delay: 100 }) watch([`${dir.src}pages/**/*.pug`], { delay: 100 })
// TODO попробовать с events: ['unlink'] // TODO попробовать с events: ['unlink']
.on('unlink', function(path, stats) { .on('unlink', function(path) {
let filePathInBuildDir = path.replace(`${dir.src}pages/`, dir.build).replace('.pug', '.html'); let filePathInBuildDir = path.replace(`${dir.src}pages/`, dir.build).replace('.pug', '.html');
fs.unlink(filePathInBuildDir, (err) => { fs.unlink(filePathInBuildDir, (err) => {
if (err) throw err; if (err) throw err;
...@@ -528,17 +528,3 @@ function getDirectories(ext) { ...@@ -528,17 +528,3 @@ function getDirectories(ext) {
function getArraysDiff(a1, a2) { function getArraysDiff(a1, a2) {
return a1.filter(i=>!a2.includes(i)).concat(a2.filter(i=>!a1.includes(i))) return a1.filter(i=>!a2.includes(i)).concat(a2.filter(i=>!a1.includes(i)))
} }
/**
* Уникализация массива
* @param {array} arr Массив, в котором могут быть неуникальные элементы
* @return {array} Массив без повторов
*/
function uniqueArray(arr) {
var obj = {};
for (var i = 0; i < arr.length; i++) {
var str = arr[i];
obj[str] = true;
}
return Object.keys(obj);
}
...@@ -10,10 +10,11 @@ ...@@ -10,10 +10,11 @@
}, },
"scripts": { "scripts": {
"test:style": "stylelint \"src/**/*.scss\" --syntax=scss", "test:style": "stylelint \"src/**/*.scss\" --syntax=scss",
"test:js": "eslint src/blocks/**/*.js src/js/**/*.js",
"start": "gulp", "start": "gulp",
"wlib": "cross-env BUILD_LIBRARY=yes gulp", "wlib": "cross-env BUILD_LIBRARY=yes gulp",
"deploy": "cross-env NODE_ENV=production ./node_modules/.bin/gulp build && cross-env ./node_modules/.bin/gulp deploy", "deploy": "cross-env ./node_modules/.bin/gulp build && cross-env ./node_modules/.bin/gulp deploy",
"build": "cross-env NODE_ENV=production npm start build", "build": "cross-env npm start build",
"lint-staged": "lint-staged" "lint-staged": "lint-staged"
}, },
"browserslist": [ "browserslist": [
...@@ -23,19 +24,22 @@ ...@@ -23,19 +24,22 @@
"lint-staged": { "lint-staged": {
"*.{js,pug,md}": "editorconfig-cli", "*.{js,pug,md}": "editorconfig-cli",
"*.pug": "pug-lint", "*.pug": "pug-lint",
"*.scss": "stylelint --syntax=scss" "*.scss": "stylelint --syntax=scss",
"*.js": "eslint"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.2.2", "@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3", "@babel/preset-env": "^7.2.3",
"@htmlacademy/editorconfig-cli": "^1.0.0", "@htmlacademy/editorconfig-cli": "^1.0.0",
"autoprefixer": "^9.3.1", "autoprefixer": "^9.3.1",
"babel-eslint": "^8.2.6",
"babel-loader": "^8.0.4", "babel-loader": "^8.0.4",
"browser-sync": "^2.18.8", "browser-sync": "^2.18.8",
"cpy": "^7.0.1", "cpy": "^7.0.1",
"cross-env": "^5.0.0", "cross-env": "^5.0.0",
"css-mqpacker": "^7.0.0", "css-mqpacker": "^7.0.0",
"del": "^3.0.0", "del": "^3.0.0",
"eslint": "^4.19.1",
"get-classes-from-html": "^1.0.1", "get-classes-from-html": "^1.0.1",
"gh-pages": "^2.0.1", "gh-pages": "^2.0.1",
"gulp": "^4.0.0", "gulp": "^4.0.0",
...@@ -48,7 +52,6 @@ ...@@ -48,7 +52,6 @@
"gulp-pretty-html": "^2.0.9", "gulp-pretty-html": "^2.0.9",
"gulp-pug": "^4.0.1", "gulp-pug": "^4.0.1",
"gulp-rename": "^1.2.2", "gulp-rename": "^1.2.2",
"gulp-replace": "^1.0.0",
"gulp-sass": "^4.0.1", "gulp-sass": "^4.0.1",
"gulp-sourcemaps": "^2.4.1", "gulp-sourcemaps": "^2.4.1",
"gulp-svgmin": "^2.1.0", "gulp-svgmin": "^2.1.0",
......
/* global document */
var baron = require('baron'); var baron = require('baron');
document.addEventListener('DOMContentLoaded', function(){ document.addEventListener('DOMContentLoaded', function(){
......
/* global require */
require('../main-nav/main-nav.js'); require('../main-nav/main-nav.js');
require('../burger/burger.js'); require('../burger/burger.js');
require('../field-text/field-text.js'); require('../field-text/field-text.js');
......
/* global document */
document.addEventListener('DOMContentLoaded', function(){ document.addEventListener('DOMContentLoaded', function(){
function $$(selector, context) { function $$(selector, context) {
...@@ -11,13 +13,14 @@ document.addEventListener('DOMContentLoaded', function(){ ...@@ -11,13 +13,14 @@ document.addEventListener('DOMContentLoaded', function(){
for (var i = 0; i < burgers.length; i++) { for (var i = 0; i < burgers.length; i++) {
var burger = burgers[i]; var burger = burgers[i];
burger.addEventListener('click', showBurgerTarget); burger.addEventListener('click', showBurgerTarget);
function showBurgerTarget() { }
var targetId = this.getAttribute('data-target-id');
var targetClassToggle = this.getAttribute('data-target-class-toggle'); function showBurgerTarget() {
if (targetId && targetClassToggle) { var targetId = this.getAttribute('data-target-id');
this.classList.toggle('burger--close'); var targetClassToggle = this.getAttribute('data-target-class-toggle');
document.getElementById(targetId).classList.toggle(targetClassToggle); if (targetId && targetClassToggle) {
} this.classList.toggle('burger--close');
document.getElementById(targetId).classList.toggle(targetClassToggle);
} }
} }
......
/* global document */
const closest = require('closest'); const closest = require('closest');
/* /*
...@@ -6,29 +8,26 @@ const closest = require('closest'); ...@@ -6,29 +8,26 @@ const closest = require('closest');
Available for use under the MIT License Available for use under the MIT License
*/ */
;( function () var inputs = document.querySelectorAll( '.field-file__input:not([disabled])' );
Array.prototype.forEach.call( inputs, function( input )
{ {
var inputs = document.querySelectorAll( '.field-file__input:not([disabled])' ); var label = closest(input, '.field-file').querySelector( '.field-file__name-text' ),
Array.prototype.forEach.call( inputs, function( input ) labelVal = label.innerHTML;
{
var label = closest(input, '.field-file').querySelector( '.field-file__name-text' ),
labelVal = label.innerHTML;
input.addEventListener( 'change', function( e ) { input.addEventListener( 'change', function( e ) {
var fileName = ''; var fileName = '';
if( this.files && this.files.length > 1 ) { if( this.files && this.files.length > 1 ) {
fileName = ( this.getAttribute( 'data-multiple-caption' ) || '' ).replace( '{count}', this.files.length ); fileName = ( this.getAttribute( 'data-multiple-caption' ) || '' ).replace( '{count}', this.files.length );
} }
else { else {
fileName = e.target.value.split( '\\' ).pop(); fileName = e.target.value.split( '\\' ).pop();
} }
if( fileName ) { if( fileName ) {
label.innerHTML = fileName; label.innerHTML = fileName;
} }
else { else {
label.innerHTML = labelVal; label.innerHTML = labelVal;
} }
});
}); });
}()); });
...@@ -22,7 +22,7 @@ if (typeof Object.assign != 'function') { ...@@ -22,7 +22,7 @@ if (typeof Object.assign != 'function') {
const Choices = require('choices.js'); const Choices = require('choices.js');
const choices = new Choices('.field-select__select', { new Choices('.field-select__select', {
searchEnabled: false, searchEnabled: false,
placeholderValue: 'Выберите', placeholderValue: 'Выберите',
}); });
/* global document */
const autosize = require('autosize'); const autosize = require('autosize');
autosize(document.querySelectorAll('textarea')); autosize(document.querySelectorAll('textarea'));
/* global document Element */
document.addEventListener('DOMContentLoaded', function(){ document.addEventListener('DOMContentLoaded', function(){
// Добавление/удаление модификаторов при фокусировке на ссылочном элементе // Добавление/удаление модификаторов при фокусировке на ссылочном элементе
...@@ -29,6 +31,7 @@ document.addEventListener('DOMContentLoaded', function(){ ...@@ -29,6 +31,7 @@ document.addEventListener('DOMContentLoaded', function(){
// eslint-disable
/*! getParents.js | (c) 2017 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/getParents */ /*! getParents.js | (c) 2017 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/getParents */
/** /**
* Get all of an element's parent elements up the DOM tree * Get all of an element's parent elements up the DOM tree
...@@ -49,7 +52,7 @@ document.addEventListener('DOMContentLoaded', function(){ ...@@ -49,7 +52,7 @@ document.addEventListener('DOMContentLoaded', function(){
function(s) { function(s) {
var matches = (this.document || this.ownerDocument).querySelectorAll(s), var matches = (this.document || this.ownerDocument).querySelectorAll(s),
i = matches.length; i = matches.length;
while (--i >= 0 && matches.item(i) !== this) {} while (--i >= 0 && matches.item(i) !== this) {} // eslint-disable-line
return i > -1; return i > -1;
}; };
} }
......
/* global document window console */
var $ = require('jquery'); var $ = require('jquery');
// Демо событий модальных окон // Демо событий модальных окон
$(document).ready(function(){ $(document).ready(function(){
$('#modal-demo-01').on('show.nth.modal', function(){ $('#modal-demo-01').on('show.nth.modal', function(){
console.log('Модальное окно #modal-demo-01: сработало событие show.nth.modal'); console.log('Модальное окно #modal-demo-01: сработало событие show.nth.modal'); // eslint-disable-line no-console
}); });
$('#modal-demo-01').on('shown.nth.modal', function(){ $('#modal-demo-01').on('shown.nth.modal', function(){
console.log('Модальное окно #modal-demo-01: сработало событие shown.nth.modal'); console.log('Модальное окно #modal-demo-01: сработало событие shown.nth.modal'); // eslint-disable-line no-console
}); });
$('#modal-demo-01').on('hide.nth.modal', function(){ $('#modal-demo-01').on('hide.nth.modal', function(){
console.log('Модальное окно #modal-demo-01: сработало событие hide.nth.modal'); console.log('Модальное окно #modal-demo-01: сработало событие hide.nth.modal'); // eslint-disable-line no-console
}); });
$('#modal-demo-01').on('hidden.nth.modal', function(){ $('#modal-demo-01').on('hidden.nth.modal', function(){
console.log('Модальное окно #modal-demo-01: сработало событие hidden.nth.modal'); console.log('Модальное окно #modal-demo-01: сработало событие hidden.nth.modal'); // eslint-disable-line no-console
}); });
}); });
......
/* global document */
var objectFitImages = require('object-fit-images'); var objectFitImages = require('object-fit-images');
document.addEventListener('DOMContentLoaded', function(){ document.addEventListener('DOMContentLoaded', function(){
......
/* global document */
document.addEventListener('DOMContentLoaded', function(){ document.addEventListener('DOMContentLoaded', function(){
document.addEventListener('click', function(event) { document.addEventListener('click', function(event) {
......
/* global document window performance requestAnimationFrame */
document.addEventListener('DOMContentLoaded', function(){ document.addEventListener('DOMContentLoaded', function(){
var links = document.querySelectorAll('[href^="#"][data-scroll-link]'); var links = document.querySelectorAll('[href^="#"][data-scroll-link]');
......
/* global document window history location Element */
document.addEventListener('DOMContentLoaded', function(){ document.addEventListener('DOMContentLoaded', function(){
if(location.hash) { if(location.hash) {
......
/* global document window performance requestAnimationFrame */
document.addEventListener('DOMContentLoaded', function(){ document.addEventListener('DOMContentLoaded', function(){
if(document.getElementById('to-top')) { if(document.getElementById('to-top')) {
...@@ -22,31 +24,31 @@ document.addEventListener('DOMContentLoaded', function(){ ...@@ -22,31 +24,31 @@ document.addEventListener('DOMContentLoaded', function(){
window.addEventListener('scroll', visibilityToggle); window.addEventListener('scroll', visibilityToggle);
visibilityToggle(); visibilityToggle();
function visibilityToggle() { }
if(window.pageYOffset >= 500) {
document.getElementById('to-top').classList.add('to-top--visible');
}
else {
document.getElementById('to-top').classList.remove('to-top--visible');
}
}
function animate(_ref) { function visibilityToggle() {
var timing = _ref.timing, if(window.pageYOffset >= 500) {
draw = _ref.draw, document.getElementById('to-top').classList.add('to-top--visible');
duration = _ref.duration; }
var start = performance.now(); else {
requestAnimationFrame(function animate(time) { document.getElementById('to-top').classList.remove('to-top--visible');
var timeFraction = (time - start) / duration;
if (timeFraction > 1) timeFraction = 1;
var progress = timing(timeFraction);
draw(progress);
if (timeFraction < 1) {
requestAnimationFrame(animate);
}
});
} }
}
function animate(_ref) {
var timing = _ref.timing,
draw = _ref.draw,
duration = _ref.duration;
var start = performance.now();
requestAnimationFrame(function animate(time) {
var timeFraction = (time - start) / duration;
if (timeFraction > 1) timeFraction = 1;
var progress = timing(timeFraction);
draw(progress);
if (timeFraction < 1) {
requestAnimationFrame(animate);
}
});
} }
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment