Can someone please tell me what is wrong with this code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js" integrity="sha256-4iQZ6BVL4qNKlQ27TExEhBN1HFPvAvAMbFavKKosSWQ=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.27/moment-timezone-with-data-10-year-range.min.js" integrity="sha256-9x/X+/cyuorK/e3qq0k4nugZUecitOwz67xXtZ7sWME=" crossorigin="anonymous"></script>
<script src="https://www.ghostplugins.dev/assets/helpers/flat-picker/flatpickr.js"></script>
<script> if(Y.all('#add-to-custom').size() > 0){
Y.one('body').addClass('page-with-customizer');
Y.all('.product-quantity-input input, .ProductItem-details input').each(function(node){
node.setAttribute('min', 6);
node.setAttribute('value', 6);
//onkeyup="if(this.value > 5) this.value = null;"
});
Y.all('#add-to-custom').each(function(node,i){
node.on('click', function(){
var countProducts = 0;
Y.all('.product-block.selected-product').each(function(node,i){
countProducts++;
});
console.log(countProducts+ ' here is products');
if(countProducts > 0){
Y.one('.adding-message').addClass('active-message');
for (var start = 0; start < countProducts; start++){
setTimeout(function () {
// Y.one('.product-block.selected-product .sqs-add-to-cart-button:not(.clicked)').simulate('click');
}, 500 * start);
setTimeout(function () {
Y.one('.adding-message').removeClass('active-message');
Y.one('.added-message').addClass('active-message');
},500*countProducts);
}
}else{
// alert('Please select your products');
}
});
});
Y.all('.product-block.selected-product .sqs-add-to-cart-button:not(.clicked)').each(function(node){
node.on('click', function(event){
event.preventDefault();
event.stopPropagation();
})
});
}
YUI().use('node-event-simulate', 'node', 'event', function() {
Y.on("load", function(){
if(Y.all('#item-5e56c2e6a6cc764ba8a8eb78').size() || Y.all('#item-5e56bd17bd4edd3bdfb0dbcc').size() || Y.all('#item-5e56aaacdd4cda3aa2f23dbe').size()){
Y.one('.sqs-add-to-cart-button').on('click', function(){
console.log('init')
// Y.one('#item-5e56c2e6a6cc764ba8a8eb78 .sqs-add-to-cart-button').simulate('click');
setTimeout(function(){
var itemFl1 = new flatpickr('.form-wrapper .form-item:nth-child(2) input', {
altInput: true,
altFormat: "d / m / y",
defaultDate: new Date().fp_incr(2),
dateFormat: "Y-M-D",
minDate: new Date().fp_incr(2),
maxDate: new Date().fp_incr(60) // 14 days from now
});
Y.one('.flatpickr-input').remove();
},1000)
})
}
if(Y.all('#collection-5e690772c104fd669e8d0e89').size()){
var getDate = document.querySelector('[data-form-id="5f3fc664aa34794fc9c0f0d6"] .form-item');
/* fix calendar */
/* initialize date picker */
var aa = flatpickr('[data-form-id="5f3e4d84017d4545d29d5d44"] input#text-yui_3_17_2_1_1598029558294_14455-field',{
altInput: true,
altFormat: "d / m / y",
defaultDate: new Date().fp_incr(2),
dateFormat: "Y-M-D",
minDate: new Date().fp_incr(2),
maxDate: new Date().fp_incr(60) // 14 days from now
});
console.log(moment(new Date()).add(4,'days').format('YYYY-MM-DD'))
var append = Y.one('#block-yui_3_17_2_1_1597918173330_12816')
Y.one('#collection-5e690772c104fd669e8d0e89').prepend('<div class="modal"><div class="modal-content"><span class="close"></span><div class="if-less"><p>* If less than 48hours, please call us directly to place an order <a href="tel:1300-233-784">1300-233-784</a></p></div></div></div>')
Y.one('#collection-5e690772c104fd669e8d0e89 .modal .modal-content').prepend(append);
/* modal styles */
Y.all('.modal .close').on('click',function() {
Y.all('.modal').removeClass('anim-modal');
setTimeout(function(){
Y.all('.modal').removeClass('open-modal')
},300)
})
Y.one(window).on('click', function(event) {
if (event.target == Y.one('.modal')) {
Y.all('.modal').removeClass('anim-modal');
setTimeout(function(){
Y.all('.modal').removeClass('open-modal')
},300)
}
})
/*create an array with fields*/
var fields = {
firstName: '',
lastName: '',
dateOfPick: '',
timeOfPick: '',
phone: '',
location: ''
};
Y.all('.flatpickr-day').each(function(){
var curItem = this;
})
Y.all('.product-block.selected-product .sqs-add-to-cart-button').on('click', function(){
var curItem = this;
this.on('click', function(){
setTimeout(function(){
curItem.ancestor('.product-block').removeClass('selected-product');
},300)
});
})
/*allow to input only numbers*/
/* Y.one('[data-form-id="5f3e4d84017d4545d29d5d44"] [data-title="Areacode"]').on('keypress',function (e) {
//if the letter is not digit then display error and don't type anything
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
return false;
}
});*/
/*open light box*/
Y.all('#add-to-custom').each(function(node){
node.on('click', function(){
if(Y.all('.product-block.selected-product').size()){
Y.all('.modal').addClass('open-modal');
setTimeout(function(){
Y.all('.modal').addClass('anim-modal')
},300)
//}
}else{
Y.one('#add-to-custom').set('text', 'PLEASE SELECT PRODUCTS...');
setTimeout(function(){
Y.one('#add-to-custom').set('text', 'ADD TO CART SELECTED ITEMS') ;
},800)
}
})
})
/*add fake button to form*/
Y.all('[data-form-id="5f3e4d84017d4545d29d5d44"]').append('<div class="fake-button">Add to Cart</div>');
Y.all('[data-form-id="5f3e4d84017d4545d29d5d44"]').prepend('<div class="form-error" style="opacity: 0">Please Fill The From Correctly</div>')
/*save all fields*/
Y.one('[data-form-id="5f3e4d84017d4545d29d5d44"] .fake-button').on('click', function(e){
fields.firstName = Y.one('[data-form-id="5f3e4d84017d4545d29d5d44"] [data-title="First"]').get('value');
fields.lastName = Y.one('[data-form-id="5f3e4d84017d4545d29d5d44"] [data-title="Last"]').get('value');
fields.dateOfPick = Y.one('[data-form-id="5f3e4d84017d4545d29d5d44"] .form-item:nth-child(2) input.form-control').get('value');
fields.timeOfPick = Y.one('[data-form-id="5f3e4d84017d4545d29d5d44"] .form-item:nth-child(3) input').get('value');
// fields.phone = Y.one('[data-form-id="5f3e4d84017d4545d29d5d44"] [data-title="Areacode"]').get('value') + ' ' + Y.one('[data-form-id="5f3e4d84017d4545d29d5d44"] [data-title="Prefix"]').get('value') + ' ' + Y.one('[data-form-id="5f3e4d84017d4545d29d5d44"] [data-title="Line"]').get('value');
fields.phone = Y.one('[data-form-id="5f3e4d84017d4545d29d5d44"] .form-item:nth-child(4) input').get('value');
fields.location = Y.one('[data-form-id="5f3e4d84017d4545d29d5d44"] .select select').get('value');
console.log(fields)
})
Y.all('[data-form-id="5f3e4d84017d4545d29d5d44"] .fake-button').on('click', function(node){
var countProducts = 0;
Y.all('.product-block.selected-product').each(function(node,i){
countProducts++;
});
/*check if fields are filled*/
if( Y.one('[data-form-id="5f3e4d84017d4545d29d5d44"] [data-title="First"]').get('value') && Y.one('[data-form-id="5f3e4d84017d4545d29d5d44"] [data-title="Last"]').get('value') && Y.one('[data-form-id="5f3e4d84017d4545d29d5d44"] .form-item:nth-child(4) input').get('value') && Y.one('[data-form-id="5f3e4d84017d4545d29d5d44"] #text-yui_3_17_2_1_1597935617253_30876-field').get('value') ){
Y.one('[data-form-id="5f3e4d84017d4545d29d5d44"] .form-error').setStyle('opacity', 0);
Y.one('.modal .close').simulate('click');
// Y.all('.sqs-modal-lightbox-content').setStyle('display', 'none');
Y.one('body').addClass('fake-clicked');
/*go through all items and fill them*/
if(countProducts > 0){
for (var start = 0; start < countProducts; start++){
setTimeout(function(){
//magic
Y.one('.product-block.selected-product').one('.sqs-add-to-cart-button').simulate('click');
var timerId = setInterval(function() {
if(Y.one('html').hasClass('sqs-modal-lightbox-open')){
//тут робити двіж
// setTimeout(function(){
Y.all('.lightbox-content .form-wrapper [data-title="First"]').set('value', fields.firstName);
Y.all('.lightbox-content .form-wrapper [data-title="Last"]').set('value', fields.lastName);
Y.all('.lightbox-content .form-wrapper .form-item:nth-child(2) input').set('value', fields.dateOfPick);
Y.all('.lightbox-content .form-wrapper .form-item:nth-child(3) input').set('value', fields.timeOfPick);
Y.all('.lightbox-content .form-wrapper:not([data-form-id="5f3e4d84017d4545d29d5d44"]) .form-item:nth-child(4) input').set('value', fields.phone);
Y.all('.lightbox-content .form-wrapper .select select').set('value', fields.location);
//},100)
//setTimeout(function(){
Y.one('.lightbox-content .button.sqs-system-button.sqs-editable-button').simulate('click');
if(Y.all('.product-block.selected-product').size()){
console.log('adding...');
/*add overlay*/
Y.one('#add-to-custom').set('text', 'ADDING...');
Y.all('.loading-overlay').addClass('active-overlay')
setTimeout(function(){
Y.all('.loading-overlay').addClass('active-overlay-anim')
},300)
/*fin add overlay*/
}else{
/*add overlay*/
Y.one('#add-to-custom').set('text', 'ADDING...');
Y.all('.loading-overlay').removeClass('active-overlay-anim')
setTimeout(function(){
Y.all('.loading-overlay').removeClass('active-overlay')
},300)
/*fin add overlay*/
setTimeout(function(){
Y.one('#add-to-custom').set('text', 'ADD TO CART SELECTED ITEMS');
}, 3000)
}
clearInterval(timerId);
}else{
}
}, 200);
//fin magic
}, 2500 * start);
}
}
/*fin fill*/
}else{
Y.one('[data-form-id="5f3e4d84017d4545d29d5d44"] .form-error').setStyle('opacity', 1)
}
/*fin checking*/
})
}
})
})
if(Y.all('#collection-5e56aa478291701b1d724a48').size() > 0 || Y.all('#collection-5e690772c104fd669e8d0e89').size() > 0 || Y.all('#item-5e56aaacdd4cda3aa2f23dbe').size() > 0 || Y.all('#item-5e56bd17bd4edd3bdfb0dbcc').size() > 0 || Y.all('#item-5e56c2e6a6cc764ba8a8eb78').size() > 0 ){
var limitMessage = '<div class="limit-message"><span>6 person minimum</span></div>'
Y.all('.product-quantity-input input').each(function(node){
node.on('click',function(event){
event.preventDefault();
event.stopPropagation();
})
node.setAttribute('onChange','if(this.value < 6){this.value = 6;this.classList.add("show-limit");}else{this.classList.remove("show-limit");}');
Y.Node.create(limitMessage).appendTo(node.ancestor('.product-quantity-input'));
});
Y.all('.sqs-block.product-block').each(function(node){
node.on('click', function(){
console.log('puzda')
node.toggleClass('selected-product')
});
});
}
if(Y.all('#item-5e56aaacdd4cda3aa2f23dbe').size() > 0 || Y.all('#item-5e56bd17bd4edd3bdfb0dbcc').size() > 0 || Y.all('#item-5e56c2e6a6cc764ba8a8eb78').size() > 0){
Y.all('.ProductItem-details input').each(function(node){
node.setAttribute('min', 6);
node.setAttribute('value', 6);
//onkeyup="if(this.value > 5) this.value = null;"
});
}
/*
setTimeout(function(){
if(Y.all('.item-quantity').size() > 0){
Y.all('.QuantityInput-stopped-2BFKB div').each(function(node){
node.setAttribute('data-value', 10);
node.set('value', 10);
});
}
}, 1000);
*/
</script>
<script>
var addToCartBut = document.querySelectorAll('.sqs-add-to-cart-button.use-form')[0];
var htmlElem = document.querySelectorAll('html')[0];
addToCartBut.addEventListener('click', event => {
console.log('clicked');
var timerId = setInterval(function() {
if(htmlElem.classList.contains('sqs-modal-lightbox-open')){
var giftField1 = Y.one('[data-form-id="5ddbf1bad3cf323322927f5f"] .field-list .form-item.name');
var giftField2 = Y.one('[data-form-id="5ddbf1bad3cf323322927f5f"] .field-list .form-item.textarea');
var giftDropdown = document.querySelectorAll('[data-form-id="5ddbf1bad3cf323322927f5f"] .field-list .form-item.select select')[0];
//gift
giftDropdown.addEventListener("change", function() {
if(giftDropdown.value == "Yes"){
giftField1.setAttribute('show-field', 'true');
giftField2.setAttribute('show-field', 'true');
}else{
giftField1.setAttribute('show-field', 'false');
giftField2.setAttribute('show-field', 'false');
}
});
clearInterval(timerId);
}else{
console.log('?');
}
}, 1500);
});
</script>
<script>
if(Y.all('#collection-5e56aa478291701b1d724a48').size() > 0 || Y.all('#collection-5e690772c104fd669e8d0e89').size() > 0){
Y.all('.product-quantity-input input').each(function(node){
node.setAttribute('min', 6);
node.setAttribute('value', 6);
node.addClass('input-testing');
});
}
if(Y.all('.product-price .sqs-money-native').size() > 0){
Y.all('.sqs-money-native').each(function(thisNode){
var itemPrice = +thisNode.get('text');
thisNode.setAttribute('data-base-price', itemPrice);
});
function updatePrice(){
Y.all('.sqs-money-native').each(function(thisNode){
if(Y.all('.ProductItem-summary').size() > 0){
var inputValue = thisNode.ancestor('.ProductItem-summary').all('.product-quantity-input input').get('value')[0];
}else{
var inputValue = thisNode.ancestor('.product-block').all('.product-quantity-input input').get('value')[0];
}
var itemPrice = +thisNode.getAttribute('data-base-price');
console.log(itemPrice+ ' item price');
console.log(inputValue+ ' inputValue');
thisNode.set('text', itemPrice*inputValue);
});
}
updatePrice();
Y.all('.product-quantity-input input').on('change', function (e) {
updatePrice();
});
}
</script>
<script>
if(Y.all('#collection-5e56aa478291701b1d724a48').size() > 0){
Y.all('.ProductList-item[data-item-id="5e56aebb672e82723830d78c"] a').each(function(thisNode){
thisNode.set('href', '/create-your-own');
});
}
</script>
<script>
var collectionId = '/5e56aa478291701b1d724a48/';
if(Y.all('#sqs-cart-container').size() > 0){
function cartLimitStuff(){
Y.all('.CartTableRow-cartItemList-qrq0l').each(function(nodeElement){
var bgImage = nodeElement.one('.CartTableRow-imageBg-97RUm').getStyle('background-image');
if(bgImage.indexOf(collectionId) !== -1){
nodeElement.addClass('catering-element');
}
});
Y.all('.catering-element .item-quantity').each(function(nodeInput){
//var limit = Y.Node.create('');
nodeInput.append('<p class="limit">6 person minimum</p>')
console.log(nodeInput.get('value'));
if(nodeInput.get('value') < 6){
nodeInput.set('value', 6);
}
nodeInput.setAttribute('min', 6);
nodeInput.setAttribute('onChange','if(this.value < 6){this.value = 6;}');
});
}
var timerId = setInterval(function() {
if(Y.all('.CartTableRow-cartItemList-qrq0l').size() > 0){
clearInterval(timerId);
cartLimitStuff();
}else{
console.log('?');
}
}, 500);
}
</script>
<style>
body.fake-clicked .sqs-modal-lightbox-content{
}
.form-error{
-webkit-transition: all .3s ease-out !important;
-moz-transition: all .3s ease-out !important;
-o-transition: all .3s ease-out !important;
transition: all .3s ease-out !important;
border-radius: 2px;
background: #cc3b3b url(//assets.squarespace.com/universal/images-v6/standard/icon_close_7_light.png) no-repeat 9px 50%;
color: #fff;
display: inline-block;
font-size: 13px;
line-height: 23px;
margin: 12px 0;
padding: 5px 15px 3px 25px;
}
[data-form-id="5f3e4d84017d4545d29d5d44"]{
margin-top: 17px !important;
}
[data-form-id="5f3e4d84017d4545d29d5d44"] .button.sqs-system-button{
display: none;
}
.fake-button{
display: inline-block;
width: auto;
height: auto;
padding: 1em 2.5em;
color: #fff;
background-color: #272727;
border-width: 0;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 12px;
line-height: 1em;
font-weight: normal;
font-style: normal;
text-transform: uppercase;
letter-spacing: 0px;
text-align: center;
text-decoration: none;
cursor: pointer;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
font-size: 14px;
text-transform: none;
}
</style>