whoami1337 1 anno fa
parent
commit
6e5e5d871a
5 ha cambiato i file con 2 aggiunte e 240 eliminazioni
  1. 1 0
      README.md
  2. 1 12
      src/index.ts
  3. 0 147
      src/modules/parsing.module.ts
  4. 0 40
      src/modules/popup.module.ts
  5. 0 41
      src/modules/toast.module.ts

+ 1 - 0
README.md

@@ -0,0 +1 @@
+# ADMEFINE Исходники счетчика

+ 1 - 12
src/index.ts

@@ -1,12 +1,11 @@
 /**
- * ADMEFINE METRIKA./modules/api.module
+ * ADMEFINE METRIKA
  * 2023
  * 0.0.1
  */
 
 import { getUrl, getQuery, initUTM } from "@/modules/url.module";
 import { sendLead } from "./modules/api.module";
-import { parsingForms } from "./modules/parsing.module";
 
 interface IInitProps {
   isLoadForm: boolean;
@@ -15,21 +14,11 @@ interface IInitProps {
 
 
 const init = (props: IInitProps) => {
-  let withDefaults: IInitProps = {
-    isLoadForm: props?.isLoadForm || true,
-    formSuccessPopupText: props?.formSuccessPopupText || 'Спасибо, ваша заявка была отправлена!'
-  }
   // init utm
   initUTM();
-
-  // load parsing forms
-  if(withDefaults.isLoadForm) {
-    parsingForms(withDefaults);
-  }
 }
 
 window.AMF_METRIKA = window.AMF_METRIKA || {};
-
 window.AMF_METRIKA = {
   init,
   methods: {

+ 0 - 147
src/modules/parsing.module.ts

@@ -1,147 +0,0 @@
-import { sendLead } from "./api.module";
-import toast from './toast.module';
-import popup from './popup.module';
-
-let config: any = null;
-
-export function parsingForms(configInit: any) {
-  config = configInit;
-  getAllForms();
-}
-type FieldType = 'text' | 'password' | 'email' | 'number' | 'checkbox' | 'radio' | 'date' | 'file' | 'submit';
-
-type Field = {
-  name: string;
-  type: FieldType;
-  value: string | boolean | File | null;
-  required: boolean;
-};
-
-type FormInfo = {
-  form: HTMLFormElement;
-  fields: Field[];
-};
-
-function handleSubmit(event: Event, form: HTMLFormElement, fields: Field[]) {
-  event.preventDefault(); // Prevent the form from actually submitting
-
-  // Custom processing here, e.g., send data via AJAX
-  console.log(`Form submitted: ${form.id}`);
-  console.log('Fields:', fields);
-
-  const makeData: any = {};
-
-  for(const field of fields) {
-    makeData[field.name] = field.value;
-  }
-
-  sendLead(makeData)
-  .then(() => {
-    popup.show(config?.formSuccessPopupText)
-
-    setTimeout(() => {
-      clearForm(form);
-      popup.hide();
-    }, 3000);
-  })
-  .catch((err) => {
-    toast.error(err);
-  })
-}
-
-function clearForm(form: HTMLFormElement): void {
-  const elements = form.elements;
-
-  for (let i = 0; i < elements.length; i++) {
-    const element = elements[i] as HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
-    const elementType = element.type.toLowerCase();
-
-    switch (elementType) {
-      case 'text':
-      case 'password':
-      case 'email':
-      case 'tel':
-      case 'url':
-      case 'search':
-      case 'number':
-      case 'date':
-      case 'datetime-local':
-      case 'time':
-      case 'month':
-      case 'week':
-      case 'color':
-      case 'range':
-        (element as HTMLInputElement).value = '';
-        break;
-      case 'checkbox':
-      case 'radio':
-        (element as HTMLInputElement).checked = false;
-        break;
-      case 'select-one':
-      case 'select-multiple':
-        (element as HTMLSelectElement).selectedIndex = -1;
-        break;
-      case 'textarea':
-        (element as HTMLTextAreaElement).value = '';
-        break;
-      default:
-        break;
-    }
-  }
-}
-
-function getAllForms(): FormInfo[] {
-  const forms = Array.from(document.forms);
-  const formInfos: FormInfo[] = [];
-  // const requiredFields = ['name', 'phone', 'email'];
-  const requiredFields = ['name', 'phone'];
-
-  forms.forEach((form) => {
-    const fields: Field[] = [];
-    Array.from(form.elements).forEach((element) => {
-      if (element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement) {
-        let value: string | boolean | File | null = element.value;
-        const fieldType = element.type as FieldType;
-        const isRequired = requiredFields.includes(element.name);
-        if (fieldType === 'checkbox' || fieldType === 'radio') {
-          value = (element as HTMLInputElement).checked;
-        }
-
-        if(fieldType === 'submit') return;
-        //  else if (fieldType === 'file') {
-        //   value = (element as HTMLInputElement).files ? (element as HTMLInputElement).files[0] : null;
-        // }
-
-        const field: Field = {
-          name: element.name,
-          type: fieldType,
-          value: value,
-          required: isRequired,
-        };
-
-        fields.push(field);
-
-        // Add reactive update by input event
-        element.addEventListener('input', () => {
-          if (fieldType === 'checkbox' || fieldType === 'radio') {
-            field.value = (element as HTMLInputElement).checked;
-          } else {
-            field.value = element.value;
-          }
-        });
-       
-        if (isRequired) {
-          element.required = true;
-        }
-      }
-    });
-
-
-    formInfos.push({ form, fields });
-
-    // Attach the handleSubmit function to the form's submit event
-    form.addEventListener('submit', (event) => handleSubmit(event, form, fields));
-  });
-
-  return formInfos;
-}

+ 0 - 40
src/modules/popup.module.ts

@@ -1,40 +0,0 @@
-import '@/css/popup.css'
-
-class Popup {
-  private overlay: HTMLElement;
-  private popup: HTMLElement;
-
-  constructor() {
-    this.overlay = document.createElement('div');
-    this.overlay.classList.add('overlay');
-    document.body.appendChild(this.overlay);
-
-    this.popup = document.createElement('div');
-    this.popup.classList.add('popup');
-    document.body.appendChild(this.popup);
-
-    this.overlay.addEventListener('click', () => {
-      this.hide();
-    });
-  }
-
-  show(content: string | HTMLElement): void {
-    if (typeof content === 'string') {
-      this.popup.innerHTML = content;
-    } else {
-      this.popup.innerHTML = '';
-      this.popup.appendChild(content);
-    }
-
-    this.overlay.classList.add('show');
-    this.popup.classList.add('show');
-  }
-
-  hide(): void {
-    this.overlay.classList.remove('show');
-    this.popup.classList.remove('show');
-  }
-}
-
-const popup = new Popup();
-export default popup;

+ 0 - 41
src/modules/toast.module.ts

@@ -1,41 +0,0 @@
-import '@/css/toast.css';
-
-class Toast {
-  private toastContainer: HTMLDivElement;
-
-  constructor() {
-    this.toastContainer = document.createElement("div");
-    this.toastContainer.classList.add("toast-container");
-    document.body.appendChild(this.toastContainer);
-  }
-
-  private show(message: string, type: string, duration: number = 3000): void {
-    const toast = document.createElement("div");
-    toast.classList.add("toast", type);
-
-    toast.innerHTML = message;
-    this.toastContainer.appendChild(toast);
-
-    setTimeout(() => {
-      toast.classList.add("show");
-    }, 100);
-
-    setTimeout(() => {
-      toast.classList.remove("show");
-      setTimeout(() => {
-        this.toastContainer.removeChild(toast);
-      }, 500);
-    }, duration);
-  }
-
-  success(message: string, duration?: number): void {
-    this.show(message, "success", duration);
-  }
-
-  error(message: string, duration?: number): void {
-    this.show(message, "error", duration);
-  }
-}
-
-const toast = new Toast();
-export default toast;