PageSourceSearch

https://www.tecfi.it/wp-content/plugins/contact_modules_cb//module_scripts.js?ver=1049064609

js tecfi.it collected 2026-10-09 03:08:32 UTC 5,621 bytes, 153 lines download raw bytes

1// let mainForm = document.querySelector('form')
2const addLoaderForm = (form) => {
3    let loader = form.querySelector('.form_loader')
4    if (loader == null && loader == undefined) return
5    // if (validateRequiredFields(form)) {
6    loader.style.display = 'block'
7    // }
8}
9
10function checkObjectInArray(arr, prop, value) {
11    for (var i = 0; i < arr.length; i++) {
12        if (arr[i][prop] === value) {
13            return true;
14        }
15    }
16    return false;
17}
18
19const previewImage = (input, validatedArray) => {
20    if (input == null && input == undefined) return
21    let maxSize = parseFloat(input.dataset.maxDim)
22    let maxNum = parseInt(input.dataset.numMax)
23    let files = Array.from(input.files)
24
25    let previewBox = input.closest('.is_file_upload').querySelector('.foto_preview')
26    // console.log(previewBox);
27
28    if (files.length > 0) {
29        let fileBuffer = new DataTransfer()
30        let imagesWrapper = document.createElement('div')
31        previewBox.append(imagesWrapper)
32        imagesWrapper.className = 'images_wrapper flex gap10'
33        files.forEach((file, index) => {
34            if (index >= maxNum) return
35            // console.log(file); // ANCHOR console.log
36            // return
37            if (file.size > (1048576 * maxSize)) {
38                alert(`Il file "${file.name}" supera la dimesione massima di ${maxSize} MB`)
39                return
40            }
41            if (validatedArray.length <= maxNum - 1) {
42                let isDuplicated = checkObjectInArray(validatedArray, 'name', file.name)
43                // console.log(isDuplicated); // ANCHOR console.log
44                if (isDuplicated == false) {
45                    validatedArray.push(file)
46                } else {
47                    alert(`Hai già caricato il file "${file.name}"`)
48                    return
49                }
50                let imageDiv = document.createElement('div')
51                let buttonDelete = document.createElement('button')
52                buttonDelete.innerHTML = '<ion-icon name="close-circle-outline"></ion-icon>'
53
54                buttonDelete.onclick = () => {
55                    let itemIndex = validatedArray.findIndex((item) => item.name == file.name)
56                    // console.log(itemIndex); // ANCHOR console.log
57                    validatedArray.splice(itemIndex, 1)
58                    // console.log(validatedArray); // ANCHOR console.log
59                    if (validatedArray.length < 1) previewBox.classList.remove('opened')
60                    imageDiv.remove()
61                }
62                imageDiv.classList.add('single_image_upload')
63                imageDiv.append(buttonDelete)
64                imageDiv.dataset.filename = file.name
65                let src = URL.createObjectURL(file)
66                imageDiv.style.backgroundImage = `url(${src})`
67                imagesWrapper.append(imageDiv)
68                previewBox.classList.add('opened')
69            } else {
70                alert(`Non è possibile aggiungere il file "${file.name}" perché si è superato il limite massimo di ${maxNum} files da caricare`)
71                /* let itemIndex = validatedArray.findIndex((item) => item.name == file.name)
72                console.log(itemIndex); // ANCHOR console.log
73                validatedArray.splice(itemIndex, 1) */
74            }
75
76        });
77
78        // console.log(validatedArray); // ANCHOR console.log
79        validatedArray.forEach(file => {
80            fileBuffer.items.add(file)
81        });
82        input.files = fileBuffer.files
83    }
84}
85const customFileUploadInit = (uploader) => {
86    let validatedFiles = []
87    if (uploader != null && uploader != undefined) {
88        uploader.addEventListener('change', (e) => {
89            previewImage(e.target, validatedFiles)
90        })
91    }
92}
93
94
95// let fotoUpload = document.querySelector('#foto')
96let fotoUploader = document.querySelectorAll('.module-file-loader')
97if (fotoUploader != null) {
98    fotoUploader.forEach(fotoUpload => {
99        customFileUploadInit(fotoUpload)
100    });
101}
102// console.log(fotoUpload);
103// customFileUploadInit(fotoUpload)
104
105const validateRequiredFields = (form) => {
106    let requiredFields = Array.from(form.querySelectorAll('[required]'))
107
108    requiredFields.map(f => {
109        if (f.type != 'checkbox') {
110            f.classList.remove('has_error')
111        } else {
112            f.closest('label').classList.remove('has_error')
113        }
114    })
115    //let missing = requiredFields.filter(f => f.checked == false || f.value == '')
116
117    let missing = []
118
119    requiredFields.forEach(field => {
120        if (field.type == 'checkbox') {
121            if (field.checked == false) { missing.push(field) }
122        } else {
123            if (field.value == '') { missing.push(field) }
124        }
125    });
126    // console.log(missing)
127    if (missing.length == 0) {
128        addLoaderForm(form)
129        return true
130    } else {
131        missing.map(m => {
132            if (m.type != 'checkbox') {
133                m.classList.add('has_error')
134            } else {
135                m.closest('label').classList.add('has_error')
136            }
137        })
138        return false
139    }
140}
141
142function onSubmit(token) {
143    // let button = document.querySelector(elementID)
144    // let formId = button.getAttribute('data-form-id');
145    // let form = document.getElementById(formId);
146    let form = document.querySelector('form#main_form')
147    // if (canSend)
148    if (validateRequiredFields(form)) {
149        form.submit();
150    }
151}
152
153

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.