Commit fec3d546 authored by Nikolay Gromov's avatar Nikolay Gromov

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

parent fe88f97d
/* eslint-disable */
'use strict';
// Генератор файлов блока
......@@ -39,7 +40,7 @@ if (blockName) {
}
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') {
......
/* global document */
const ready = require('../../js/documentReady.js');
const baron = require('baron');
var baron = require('baron');
document.addEventListener('DOMContentLoaded', function(){
ready(function(){
baron({
root: '#baron-demo',
......
/* global document */
document.addEventListener('DOMContentLoaded', function(){
const ready = require('../../js/documentReady.js');
ready(function(){
function $$(selector, context) {
context = context || document;
......
/* global document */
const closest = require('closest');
const ready = require('../../js/documentReady.js');
/*
Форма: работа стилизованного input[type="file"]
Автор: Osvaldas Valutis, www.osvaldas.info (адаптировано под используемую разметку)
Available for use under the MIT License
*/
ready(function(){
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;
/*
Форма: работа стилизованного input[type="file"]
Автор: Osvaldas Valutis, www.osvaldas.info (адаптировано под используемую разметку)
Available for use under the MIT License
*/
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();
}
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;
if( fileName ) {
label.innerHTML = fileName;
}
else {
label.innerHTML = labelVal;
}
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 (typeof Object.assign != 'function') {
Object.assign = function(target) {
'use strict';
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
const ready = require('../../js/documentReady.js');
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];
ready(function(){
if (typeof Object.assign != 'function') {
Object.assign = function(target) {
'use strict';
if (target == null) {
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 */
const autosize = require('autosize');
const ready = require('../../js/documentReady.js');
autosize(document.querySelectorAll('textarea'));
ready(function(){
autosize(document.querySelectorAll('textarea'));
});
/* global document Element */
document.addEventListener('DOMContentLoaded', function(){
const ready = require('../../js/documentReady.js');
ready(function(){
// Добавление/удаление модификаторов при фокусировке на ссылочном элементе
var linkClassName = 'main-nav__link';
......
/* global document window console */
var $ = require('jquery');
const $ = require('jquery');
// Демо событий модальных окон
$(document).ready(function(){
......
/* global document */
const objectFitImages = require('object-fit-images');
const ready = require('../../js/documentReady.js');
var objectFitImages = require('object-fit-images');
document.addEventListener('DOMContentLoaded', function(){
ready(function(){
objectFitImages();
});
/* global document */
document.addEventListener('DOMContentLoaded', function(){
const ready = require('../../js/documentReady.js');
ready(function(){
document.addEventListener('click', function(event) {
if(event.target.dataset.toggle === 'off-canvas') {
......@@ -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() {
document.getElementById('off-canvas').classList.toggle('off-canvas--open');
}
......
/* 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]');
for (var i = 0; i < links.length; i++) {
......
/* global document window performance requestAnimationFrame */
document.addEventListener('DOMContentLoaded', function(){
const ready = require('../../js/documentReady.js');
ready(function(){
if(document.getElementById('to-top')) {
......
// var ready = require('./documentReady.js');
// const ready = require('./documentReady.js');
// ready(function(){
// console.log('DOM героически построен!');
// });
// var $ = require('jquery');
// const $ = require('jquery');
// $( 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