useControls() {
    var triggers = [...$("#galler_buttons > a")];
    triggers.forEach(control => {
      control.addEventListener('click', e => {
        e.preventDefault();

        if (control.className == 'gallery-controls-add') {
          const newItem = document.createElement('img');
          const latestItem = this.carouselArray.length;
          const latestIndex = this.carouselArray.findIndex(item => item.getAttribute('data-index') == this.carouselArray.length)+1;

          // Assign the necessary properties for new gallery item
          Object.assign(newItem,{
            className: 'gallery-item',
            src: `http://fakeimg.pl/300/?text=${this.carouselArray.length+1}`
          });
          newItem.setAttribute('data-index', this.carouselArray.length+1);

          // Then add it to the carouselArray and update the gallery
          this.carouselArray.splice(latestIndex, 0, newItem);
          document.querySelector(`[data-index="${latestItem}"]`).after(newItem);
          this.updateGallery();

        } else {
          this.setCurrentState(control);
        }

      });
    });
  }
// Add a click event listener to trigger setCurrentState method to rearrange carousel
Add a click event listener to trigger setCurrentState method to rearrange carousel
Add a click event listener to trigger setCurrentState method to rearrange carousel
useControls() {
    var triggers = [...$("#galler_buttons > a")];
    triggers.forEach(control => {
      control.addEventListener('click', e => {
        e.preventDefault();
        if (control.className == 'gallery-controls-add') {
          const newItem = document.createElement('img');
          const latestItem = this.carouselArray.length;
          const latestIndex = this.carouselArray.findIndex(item => item.getAttribute('data-index') == this.carouselArray.length)+1;
          Object.assign(newItem,{
            className: 'gallery-item',
            src: `http://fakeimg.pl/300/?text=${this.carouselArray.length+1}`
          });
          newItem.setAttribute('data-index', this.carouselArray.length+1);
          this.carouselArray.splice(latestIndex, 0, newItem);
          document.querySelector(`[data-index="${latestItem}"]`).after(newItem);
          this.updateGallery();
        } else {
          this.setCurrentState(control);
        }
      });
    });
  }
useControls ( ) { var triggers = [ ... $ ( "#galler_buttons > a" ) ] ; triggers . forEach ( control => { control . addEventListener ( 'click' , e => { e . preventDefault ( ) ; if ( control . className == 'gallery-controls-add' ) { const newItem = document . createElement ( 'img' ) ; const latestItem = this . carouselArray . length ; const latestIndex = this . carouselArray . findIndex ( item => item . getAttribute ( 'data-index' ) == this . carouselArray . length ) + 1 ; Object . assign ( newItem , { className : 'gallery-item' , src : ` ${ this . carouselArray . length + 1 } ` } ) ; newItem . setAttribute ( 'data-index' , this . carouselArray . length + 1 ) ; this . carouselArray . splice ( latestIndex , 0 , newItem ) ; document . querySelector ( ` ${ latestItem } ` ) . after ( newItem ) ; this . updateGallery ( ) ; } else { this . setCurrentState ( control ) ; } } ) ; } ) ; }
Add a click event listener to trigger setCurrentState method to rearrange carousel
Add a click event listener to trigger setCurrentState method to rearrange carousel
// Assign the necessary properties for new gallery item // Then add it to the carouselArray and update the gallery