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';
// Пакеты, использующиеся при обработке
......@@ -8,7 +10,6 @@ const del = require('del');
const pug = require('gulp-pug');
const through2 = require('through2');
const rename = require('gulp-rename');
const replace = require('gulp-replace');
const getClassesFromHtml = require('get-classes-from-html');
const browserSync = require('browser-sync').create();
const debug = require('gulp-debug');
......@@ -34,7 +35,6 @@ const ghpages = require('gh-pages');
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 nth = {};
nth.config = require('./config.js');
......@@ -139,7 +139,7 @@ function generateSvgSprite(cb) {
let spriteSvgPath = `${dir.blocks}sprite-svg/svg/`;
if(nth.config.alwaysAddBlocks.indexOf('sprite-svg') > -1 && fileExist(spriteSvgPath)) {
return src(spriteSvgPath + '*.svg')
.pipe(svgmin(function (file) {
.pipe(svgmin(function () {
return { plugins: [{ cleanupIDs: { minify: true } }] }
}))
.pipe(svgstore({ inlineSvg: true }))
......@@ -236,7 +236,7 @@ exports.compileSass = compileSass;
function writeJsRequiresFile(cb) {
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) {
jsRequires += `require('${src}');\n`;
});
......@@ -338,7 +338,7 @@ function serve() {
// Страницы: удаление
watch([`${dir.src}pages/**/*.pug`], { delay: 100 })
// TODO попробовать с events: ['unlink']
.on('unlink', function(path, stats) {
.on('unlink', function(path) {
let filePathInBuildDir = path.replace(`${dir.src}pages/`, dir.build).replace('.pug', '.html');
fs.unlink(filePathInBuildDir, (err) => {
if (err) throw err;
......@@ -528,17 +528,3 @@ function getDirectories(ext) {
function getArraysDiff(a1, a2) {
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 @@
},
"scripts": {
"test:style": "stylelint \"src/**/*.scss\" --syntax=scss",
"test:js": "eslint src/blocks/**/*.js src/js/**/*.js",
"start": "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",
"build": "cross-env NODE_ENV=production npm start build",
"deploy": "cross-env ./node_modules/.bin/gulp build && cross-env ./node_modules/.bin/gulp deploy",
"build": "cross-env npm start build",
"lint-staged": "lint-staged"
},
"browserslist": [
......@@ -23,19 +24,22 @@
"lint-staged": {
"*.{js,pug,md}": "editorconfig-cli",
"*.pug": "pug-lint",
"*.scss": "stylelint --syntax=scss"
"*.scss": "stylelint --syntax=scss",
"*.js": "eslint"
},
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"@htmlacademy/editorconfig-cli": "^1.0.0",
"autoprefixer": "^9.3.1",
"babel-eslint": "^8.2.6",
"babel-loader": "^8.0.4",
"browser-sync": "^2.18.8",
"cpy": "^7.0.1",
"cross-env": "^5.0.0",
"css-mqpacker": "^7.0.0",
"del": "^3.0.0",
"eslint": "^4.19.1",
"get-classes-from-html": "^1.0.1",
"gh-pages": "^2.0.1",
"gulp": "^4.0.0",
......@@ -48,7 +52,6 @@
"gulp-pretty-html": "^2.0.9",
"gulp-pug": "^4.0.1",
"gulp-rename": "^1.2.2",
"gulp-replace": "^1.0.0",
"gulp-sass": "^4.0.1",
"gulp-sourcemaps": "^2.4.1",
"gulp-svgmin": "^2.1.0",
......
/* global document */
var baron = require('baron');
document.addEventListener('DOMContentLoaded', function(){
......
/* global require */
require('../main-nav/main-nav.js');
require('../burger/burger.js');
require('../field-text/field-text.js');
......
/* global document */
document.addEventListener('DOMContentLoaded', function(){
function $$(selector, context) {
......@@ -11,13 +13,14 @@ document.addEventListener('DOMContentLoaded', function(){
for (var i = 0; i < burgers.length; i++) {
var burger = burgers[i];
burger.addEventListener('click', showBurgerTarget);
function showBurgerTarget() {
var targetId = this.getAttribute('data-target-id');
var targetClassToggle = this.getAttribute('data-target-class-toggle');
if (targetId && targetClassToggle) {
this.classList.toggle('burger--close');
document.getElementById(targetId).classList.toggle(targetClassToggle);
}
}
function showBurgerTarget() {
var targetId = this.getAttribute('data-target-id');
var targetClassToggle = this.getAttribute('data-target-class-toggle');
if (targetId && targetClassToggle) {
this.classList.toggle('burger--close');
document.getElementById(targetId).classList.toggle(targetClassToggle);
}
}
......
/* global document */
const closest = require('closest');
/*
......@@ -6,29 +8,26 @@ const closest = require('closest');
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])' );
Array.prototype.forEach.call( inputs, function( input )
{
var label = closest(input, '.field-file').querySelector( '.field-file__name-text' ),
labelVal = label.innerHTML;
var label = closest(input, '.field-file').querySelector( '.field-file__name-text' ),
labelVal = label.innerHTML;
input.addEventListener( 'change', function( e ) {
var fileName = '';
if( this.files && this.files.length > 1 ) {
fileName = ( this.getAttribute( 'data-multiple-caption' ) || '' ).replace( '{count}', this.files.length );
}
else {
fileName = e.target.value.split( '\\' ).pop();
}
input.addEventListener( 'change', function( e ) {
var fileName = '';
if( this.files && this.files.length > 1 ) {
fileName = ( this.getAttribute( 'data-multiple-caption' ) || '' ).replace( '{count}', this.files.length );
}
else {
fileName = e.target.value.split( '\\' ).pop();
}
if( fileName ) {
label.innerHTML = fileName;
}
else {
label.innerHTML = labelVal;
}
});
if( fileName ) {
label.innerHTML = fileName;
}
else {
label.innerHTML = labelVal;
}
});
}());
});
......@@ -22,7 +22,7 @@ if (typeof Object.assign != 'function') {
const Choices = require('choices.js');
const choices = new Choices('.field-select__select', {
new Choices('.field-select__select', {
searchEnabled: false,
placeholderValue: 'Выберите',
});
/* global document */
const autosize = require('autosize');
autosize(document.querySelectorAll('textarea'));
/* global document Element */
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 */
/**
* Get all of an element's parent elements up the DOM tree
......@@ -49,7 +52,7 @@ document.addEventListener('DOMContentLoaded', function(){
function(s) {
var matches = (this.document || this.ownerDocument).querySelectorAll(s),
i = matches.length;
while (--i >= 0 && matches.item(i) !== this) {}
while (--i >= 0 && matches.item(i) !== this) {} // eslint-disable-line
return i > -1;
};
}
......
/* global document window console */
var $ = require('jquery');
// Демо событий модальных окон
$(document).ready(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(){
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(){
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(){
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');
document.addEventListener('DOMContentLoaded', function(){
......
/* global document */
document.addEventListener('DOMContentLoaded', function(){
document.addEventListener('click', function(event) {
......
/* global document window performance requestAnimationFrame */
document.addEventListener('DOMContentLoaded', function(){
var links = document.querySelectorAll('[href^="#"][data-scroll-link]');
......
/* global document window history location Element */
document.addEventListener('DOMContentLoaded', function(){
if(location.hash) {
......
/* global document window performance requestAnimationFrame */
document.addEventListener('DOMContentLoaded', function(){
if(document.getElementById('to-top')) {
......@@ -22,31 +24,31 @@ document.addEventListener('DOMContentLoaded', function(){
window.addEventListener('scroll', 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) {
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);
}
});
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) {
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