4

I want to load drupal form in a popup, i create this function and it works just fine, the problem is that it takes forever to load ( more then 8s ).My question is how to optimize this code so that it load faster.

        // Attach a click listener to add alert button.
          var tab=[] ;
          var bundles=[] ;
          var views ;
          $( "tr" ).change(function() {
              $.each($("tr.selected"), function(i, obj) { 
                  tab.push($(this).find('#views_alert_link').attr('data-id'));    
                  views = $(this).find('#views_alert_link').attr('data-views');
                  bundles.push($(this).find('#views_alert_link').attr('data-bundle'));
              });
          });
          

        // setTimeout(function(){
            $('#edit-add-alert').once().click(function() {
                        var url = '/content/sitewide_alert/add?bundle=';
                        $.colorbox({href: url,
                            onComplete: function() {
                                $('div#edit-start-date-wrapper').hide(); 
                                $('div#edit-end-date-wrapper').hide(); 
                                $('input#edit-scheduled-alert-value').change(function(){
                                    if(this.checked) {
                                        $('div#edit-start-date-wrapper').show(); 
                                        $('div#edit-end-date-wrapper').show(); 
                                    } else {
                                        $('div#edit-start-date-wrapper').hide(); 
                                        $('div#edit-end-date-wrapper').hide(); 
                                    } 
                                });
                            }
                        }); 
                if (tab.length) {   
                    const allEqual = arr => arr.every( v => v === arr[0] )
                    if (allEqual( bundles )) {
                    }else{
                        alert('veuillez choisir des contenus ayant le meme type!')
                    }
                }else{
                    alert('Pas de contenu couché pour ajouter une alerte!');
                }

            });

            $('div#alert_data>img').each(function(index) {
                tippy($(this)[0], {
                  content: '<strong>'+ $(this).attr('data-title') +'</strong><br><p>'+ $(this).attr('data-description') +'</p>',
                  allowHTML: true,
              });
            });

0 Answers0