Commit fec3d546 authored by Nikolay Gromov's avatar Nikolay Gromov

Рефакторинг JS

parent fe88f97d
/* eslint-disable */
'use strict'; 'use strict';
// Генератор файлов блока // Генератор файлов блока
...@@ -39,7 +40,7 @@ if (blockName) { ...@@ -39,7 +40,7 @@ if (blockName) {
} }
else if (extension === 'js') { else if (extension === 'js') {
fileContent = `// document.addEventListener(\'DOMContentLoaded\', function(){});\n// (function(){\n// код\n// }());\n`; fileContent = `/* global document */\n\n// const ready = require('../../js/documentReady.js');\n\n// ready(function(){\n// \n// });\n`;
} }
else if (extension === 'md') { else if (extension === 'md') {
......
/* global document */ const ready = require('../../js/documentReady.js');
const baron = require('baron');
var baron = require('baron'); ready(function(){
document.addEventListener('DOMContentLoaded', function(){
baron({ baron({
root: '#baron-demo', root: '#baron-demo',
......
/* global document */ /* global document */
document.addEventListener('DOMContentLoaded', function(){ const ready = require('../../js/documentReady.js');
ready(function(){
function $$(selector, context) { function $$(selector, context) {
context = context || document; context = context || document;
......
/* global document */ /* global document */
const closest = require('closest'); const closest = require('closest');
const ready = require('../../js/documentReady.js');
/* ready(function(){
Форма: работа стилизованного input[type="file"]
Автор: Osvaldas Valutis, www.osvaldas.info (адаптировано под используемую разметку)
Available for use under the MIT License
*/
var inputs = document.querySelectorAll( '.field-file__input:not([disabled])' ); /*
Array.prototype.forEach.call( inputs, function( input ) Форма: работа стилизованного input[type="file"]
{ Автор: Osvaldas Valutis, www.osvaldas.info (адаптировано под используемую разметку)
var label = closest(input, '.field-file').querySelector( '.field-file__name-text' ), Available for use under the MIT License
labelVal = label.innerHTML; */
input.addEventListener( 'change', function( e ) { var inputs = document.querySelectorAll( '.field-file__input:not([disabled])' );
var fileName = ''; Array.prototype.forEach.call( inputs, function( input )
if( this.files && this.files.length > 1 ) { {
fileName = ( this.getAttribute( 'data-multiple-caption' ) || '' ).replace( '{count}', this.files.length ); var label = closest(input, '.field-file').querySelector( '.field-file__name-text' ),
} labelVal = label.innerHTML;
else {
fileName = e.target.value.split( '\\' ).pop();
}
if( fileName ) { input.addEventListener( 'change', function( e ) {
label.innerHTML = fileName; var fileName = '';
} if( this.files && this.files.length > 1 ) {
else { fileName = ( this.getAttribute( 'data-multiple-caption' ) || '' ).replace( '{count}', this.files.length );
label.innerHTML = labelVal; }
} else {
fileName = e.target.value.split( '\\' ).pop();
}
if( fileName ) {
label.innerHTML = fileName;
}
else {
label.innerHTML = labelVal;
}
});
}); });
}); });
if (typeof Object.assign != 'function') { const ready = require('../../js/documentReady.js');
Object.assign = function(target) {
'use strict';
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
target = Object(target); ready(function(){
for (var index = 1; index < arguments.length; index++) {
var source = arguments[index]; if (typeof Object.assign != 'function') {
if (source != null) { Object.assign = function(target) {
for (var key in source) { 'use strict';
if (Object.prototype.hasOwnProperty.call(source, key)) { if (target == null) {
target[key] = source[key]; throw new TypeError('Cannot convert undefined or null to object');
}
target = Object(target);
for (var index = 1; index < arguments.length; index++) {
var source = arguments[index];
if (source != null) {
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
} }
} }
} }
} return target;
return target; };
}; }
}
const Choices = require('choices.js');
const Choices = require('choices.js'); new Choices('.field-select__select', {
searchEnabled: false,
placeholderValue: 'Выберите',
});
new Choices('.field-select__select', {
searchEnabled: false,
placeholderValue: 'Выберите',
}); });
/* global document */ /* global document */
const autosize = require('autosize'); const autosize = require('autosize');
const ready = require('../../js/documentReady.js');
autosize(document.querySelectorAll('textarea')); ready(function(){
autosize(document.querySelectorAll('textarea'));
});
/* global document Element */ /* global document Element */
document.addEventListener('DOMContentLoaded', function(){ const ready = require('../../js/documentReady.js');
ready(function(){
// Добавление/удаление модификаторов при фокусировке на ссылочном элементе // Добавление/удаление модификаторов при фокусировке на ссылочном элементе
var linkClassName = 'main-nav__link'; var linkClassName = 'main-nav__link';
......
/* global document window console */ /* global document window console */
var $ = require('jquery'); const $ = require('jquery');
// Демо событий модальных окон // Демо событий модальных окон
$(document).ready(function(){ $(document).ready(function(){
......
/* global document */ const objectFitImages = require('object-fit-images');
const ready = require('../../js/documentReady.js');
var objectFitImages = require('object-fit-images'); ready(function(){
document.addEventListener('DOMContentLoaded', function(){
objectFitImages(); objectFitImages();
}); });
/* global document */ /* global document */
document.addEventListener('DOMContentLoaded', function(){ const ready = require('../../js/documentReady.js');
ready(function(){
document.addEventListener('click', function(event) { document.addEventListener('click', function(event) {
if(event.target.dataset.toggle === 'off-canvas') { if(event.target.dataset.toggle === 'off-canvas') {
...@@ -13,47 +15,6 @@ document.addEventListener('DOMContentLoaded', function(){ ...@@ -13,47 +15,6 @@ document.addEventListener('DOMContentLoaded', function(){
} }
}); });
// реакция на свайп
// document.addEventListener('touchstart', handleTouchStart, false);
// document.addEventListener('touchmove', handleTouchMove, false);
// var xDown = null;
// var yDown = null;
// function handleTouchStart(evt) {
// xDown = evt.touches[0].clientX;
// yDown = evt.touches[0].clientY;
// };
// function handleTouchMove(evt) {
// if ( ! xDown || ! yDown ) {
// return;
// }
// var xUp = evt.touches[0].clientX;
// var yUp = evt.touches[0].clientY;
// var xDiff = xDown - xUp;
// var yDiff = yDown - yUp;
// if(Math.abs( xDiff )+Math.abs( yDiff )>100){ //to deal with to short swipes
// if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {/*most significant*/
// if ( xDiff > 0 ) {/* left swipe */
// document.getElementById('off-canvas').classList.remove('off-canvas--open');
// } else {/* right swipe */
// document.getElementById('off-canvas').classList.add('off-canvas--open');
// }
// }
// // else {
// // if ( yDiff > 0 ) {/* up swipe */
// // alert('Up!');
// // } else { /* down swipe */
// // alert('Down!');
// // }
// // }
// /* reset values */
// xDown = null;
// yDown = null;
// }
// };
function offCanvasToggle() { function offCanvasToggle() {
document.getElementById('off-canvas').classList.toggle('off-canvas--open'); document.getElementById('off-canvas').classList.toggle('off-canvas--open');
} }
......
/* global document window performance requestAnimationFrame */ /* global document window performance requestAnimationFrame */
document.addEventListener('DOMContentLoaded', function(){ const ready = require('../../js/documentReady.js');
ready(function(){
var links = document.querySelectorAll('[href^="#"][data-scroll-link]'); var links = document.querySelectorAll('[href^="#"][data-scroll-link]');
for (var i = 0; i < links.length; i++) { for (var i = 0; i < links.length; i++) {
......
/* global document window performance requestAnimationFrame */ /* global document window performance requestAnimationFrame */
document.addEventListener('DOMContentLoaded', function(){ const ready = require('../../js/documentReady.js');
ready(function(){
if(document.getElementById('to-top')) { if(document.getElementById('to-top')) {
......
// var ready = require('./documentReady.js'); // const ready = require('./documentReady.js');
// ready(function(){ // ready(function(){
// console.log('DOM героически построен!'); // console.log('DOM героически построен!');
// }); // });
// var $ = require('jquery'); // const $ = require('jquery');
// $( document ).ready(function() {}); // $( document ).ready(function() {});
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