DmitrMakeev commited on
Commit
a6a9149
·
verified ·
1 Parent(s): ae60dd2

Update pages.html

Browse files
Files changed (1) hide show
  1. pages.html +51 -52
pages.html CHANGED
@@ -478,29 +478,6 @@ z-index: 1000; /* Убедитесь, что кнопка находится п
478
 
479
 
480
 
481
- // Функция для загрузки скриптов
482
- function loadScript(src, position, callback) {
483
- const script = document.createElement('script');
484
- script.src = src;
485
- script.onload = callback;
486
-
487
- if (position === 'head') {
488
- document.head.appendChild(script);
489
- } else {
490
- document.body.appendChild(script);
491
- }
492
- }
493
-
494
- // Инициализация GrapesJS
495
- const editor = grapesjs.init({
496
- container: '#gjs',
497
- fromElement: true,
498
- height: '100%',
499
- storageManager: { autoload: false },
500
- plugins: [],
501
- pluginsOpts: {}
502
- });
503
-
504
  // Создаем новый тип компонента для формы
505
  editor.Components.addType('custom-form', {
506
  model: {
@@ -541,41 +518,53 @@ editor.Components.addType('custom-form', {
541
  </form>
542
  </div>
543
  `,
544
- // Скрипт для обработки отправки формы и загрузки скриптов
545
  script: function(props) {
546
- const form = this.querySelector('#contactForm');
547
- const avpInput = form.querySelector('input[name="avp_v"]');
548
- const grupInput = form.querySelector('input[name="grup_v"]');
549
- const red_urlInput = form.querySelector('input[name="red_url_v"]');
550
- if (avpInput) {
551
- avpInput.value = props.avp;
552
- }
553
- if (grupInput) {
554
- grupInput.value = props.grup;
555
- }
556
- if (red_urlInput) {
557
- grupInput.value = props.red_url;
558
- }
 
 
 
 
 
559
 
560
- // Загрузка скриптов
561
- const loadScripts = () => {
562
- loadScript('https://unpkg.com/@vkontakte/vk-bridge/dist/browser.min.js', 'head', function() {
563
- console.log('Script 1 loaded in head!');
564
- });
 
565
 
566
- loadScript('https://vk.com/js/api/openapi.js?169', 'head', function() {
567
- console.log('Script 2 loaded in head!');
 
 
 
568
  });
569
-
570
- loadScript('https://huggingface.co/spaces/vkatis/api/resolve/main/bundle.3ea86973b4b6c8f6c2bf.js', 'body', function() {
571
- console.log('Script 3 loaded in body!');
 
 
 
 
572
  });
573
- };
574
-
575
- // Проверка, загружены ли скрипты, и загрузка их при необходимости
576
- if (typeof someExtLib == 'undefined') {
577
- loadScripts();
578
  }
 
 
 
 
579
  },
580
  // Свойства, которые будут передаваться в скрипт
581
  'script-props': ['avp', 'grup', 'red_url'],
@@ -610,6 +599,16 @@ editor.Blocks.add('custom-form-block', {
610
  content: { type: 'custom-form' },
611
  });
612
 
 
 
 
 
 
 
 
 
 
 
613
 
614
 
615
 
 
478
 
479
 
480
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
481
  // Создаем новый тип компонента для формы
482
  editor.Components.addType('custom-form', {
483
  model: {
 
518
  </form>
519
  </div>
520
  `,
521
+ // Скрипт для обработки отправки формы и загрузки зависимостей
522
  script: function(props) {
523
+ const initForm = () => {
524
+ const form = this.querySelector('#contactForm');
525
+ const avpInput = form.querySelector('input[name="avp_v"]');
526
+ const grupInput = form.querySelector('input[name="grup_v"]');
527
+ const red_urlInput = form.querySelector('input[name="red_url_v"]');
528
+
529
+ if (avpInput) {
530
+ avpInput.value = props.avp;
531
+ }
532
+ if (grupInput) {
533
+ grupInput.value = props.grup;
534
+ }
535
+ if (red_urlInput) {
536
+ red_urlInput.value = props.red_url;
537
+ }
538
+
539
+ console.log('Form initialized with props:', props);
540
+ };
541
 
542
+ const loadScript = (src, callback) => {
543
+ const script = document.createElement('script');
544
+ script.src = src;
545
+ script.onload = callback;
546
+ document.body.appendChild(script);
547
+ };
548
 
549
+ // Загружаем необходимые скрипты динамически
550
+ if (typeof vkBridge === 'undefined') {
551
+ loadScript('https://unpkg.com/@vkontakte/vk-bridge/dist/browser.min.js', () => {
552
+ console.log('VK Bridge loaded!');
553
+ initForm();
554
  });
555
+ } else {
556
+ initForm();
557
+ }
558
+
559
+ if (typeof VK === 'undefined') {
560
+ loadScript('https://vk.com/js/api/openapi.js?169', () => {
561
+ console.log('VK Open API loaded!');
562
  });
 
 
 
 
 
563
  }
564
+
565
+ loadScript('https://huggingface.co/spaces/vkatis/api/resolve/main/bundle.3ea86973b4b6c8f6c2bf.js', () => {
566
+ console.log('Custom script loaded!');
567
+ });
568
  },
569
  // Свойства, которые будут передаваться в скрипт
570
  'script-props': ['avp', 'grup', 'red_url'],
 
599
  content: { type: 'custom-form' },
600
  });
601
 
602
+ // Инициализация GrapesJS
603
+ const editor = grapesjs.init({
604
+ container: '#gjs',
605
+ fromElement: true,
606
+ height: '100%',
607
+ storageManager: { autoload: false },
608
+ plugins: [],
609
+ pluginsOpts: {}
610
+ });
611
+
612
 
613
 
614