public/assets/plugins/pickletree/pickletree.js
/**
   * this method will contains static events for tree
   */
this method will contains static events for tree
this method will contains static events for tree
staticEvents() {
    this.main_container.addEventListener('click', (e) => {
      let elm = e.target;
      document.querySelectorAll('.treemenuCont').forEach((menu) => {
        menu.outerHTML = '';
      });
      if (elm.classList.contains('menuIcon')) {
        setTimeout(() => {
          this.getMenu(e.target, this.getNode(elm.id.split('node_')[1]));
        }, 10);
      }
    });
    if (this.config.drag) {
      this.invalid_area = {
        container: null,
        top: 0,
        left: 0,
        right: 0,
        bottom: 0,
      };
      this.main_container.addEventListener('dragstart', async (e) => {
        this.invalid_area.container = document.getElementById(
          this.target + 'node_' + e.target.id.split('node_')[1]
        );
        this.invalid_area.top =
          this.invalid_area.container.getBoundingClientRect().top;
        this.invalid_area.left =
          this.invalid_area.container.getBoundingClientRect().left;
        this.invalid_area.right =
          this.invalid_area.left + this.invalid_area.container.offsetWidth;
        this.invalid_area.bottom =
          this.invalid_area.top + this.invalid_area.container.offsetHeight;
        setTimeout(() => {
          this.invalid_area.container.classList.add('valid');
          this._lock();
        }, 300);
        if (this.dragCallback) {
          this.dragCallback(
            this.nodeList[parseInt(e.target.id.split('node_')[1])]
          );
        }
      });
      this.main_container.addEventListener('drag', (e) => {
      });
      this.main_container.addEventListener('dragend', async (e) => {
        this.invalid_area.container.classList.remove('invalid');
        this.invalid_area.container.classList.remove('valid');
        this._lock(false);
        this.clearDebris();
        const node = this.nodeList[parseInt(e.target.id.split('node_')[1])];
        if (!this.invalid_area.valid) {
          node.parent = { id: 0 };
        } else {
          node.old_parent = node.parent;
          const drop = this.getNode(this.drag_target);
          if (
            this.drag_target === parseInt(e.target.id.split('node_')[1]) ||
            this.drag_target === undefined ||
            drop === undefined ||
            drop.parent.value === node.value
          ) {
            node.parent = { id: 0 };
          } else {
            node.parent = drop;
          }
        }
        node.updateNode();
        if (this.dropCallback) {
          this.dropCallback(node);
        }
      });
      this.main_container.addEventListener('dragenter', (e) => {
        this.clearDebris();
        try {
          let target = {
            left: e.target.getBoundingClientRect().left,
            top: e.target.getBoundingClientRect().top,
          };
          if (
            target.top > this.invalid_area.top &&
            target.top < this.invalid_area.bottom &&
            target.left > this.invalid_area.left &&
            target.left < this.invalid_area.right
          ) {
            this.invalid_area.valid = false;
            this.invalid_area.container.classList.add('invalid');
            this.invalid_area.container.classList.remove('valid');
          } else {
            this.invalid_area.valid = true;
            this.invalid_area.container.classList.remove('invalid');
            this.invalid_area.container.classList.add('valid');
          }
          if (e.target.classList) {
            if (e.target.classList.contains('drop_target')) {
              e.target.classList.add('drag_triggered');
              this.drag_target = parseInt(e.target.id.split('node_')[1]);
            }
          }
        } catch (e) {
          this.drag_target = undefined;
        }
      });
    }
  }
staticEvents ( ) { this . main_container . addEventListener ( 'click' , ( e ) => { let elm = e . target ; document . querySelectorAll ( '.treemenuCont' ) . forEach ( ( menu ) => { menu . outerHTML = '' ; } ) ; if ( elm . classList . contains ( 'menuIcon' ) ) { setTimeout ( ( ) => { this . getMenu ( e . target , this . getNode ( elm . id . split ( 'node_' ) [ 1 ] ) ) ; } , 10 ) ; } } ) ; if ( this . config . drag ) { this . invalid_area = { container : null , top : 0 , left : 0 , right : 0 , bottom : 0 , } ; this . main_container . addEventListener ( 'dragstart' , async ( e ) => { this . invalid_area . container = document . getElementById ( this . target + 'node_' + e . target . id . split ( 'node_' ) [ 1 ] ) ; this . invalid_area . top = this . invalid_area . container . getBoundingClientRect ( ) . top ; this . invalid_area . left = this . invalid_area . container . getBoundingClientRect ( ) . left ; this . invalid_area . right = this . invalid_area . left + this . invalid_area . container . offsetWidth ; this . invalid_area . bottom = this . invalid_area . top + this . invalid_area . container . offsetHeight ; setTimeout ( ( ) => { this . invalid_area . container . classList . add ( 'valid' ) ; this . _lock ( ) ; } , 300 ) ; if ( this . dragCallback ) { this . dragCallback ( this . nodeList [ parseInt ( e . target . id . split ( 'node_' ) [ 1 ] ) ] ) ; } } ) ; this . main_container . addEventListener ( 'drag' , ( e ) => { } ) ; this . main_container . addEventListener ( 'dragend' , async ( e ) => { this . invalid_area . container . classList . remove ( 'invalid' ) ; this . invalid_area . container . classList . remove ( 'valid' ) ; this . _lock ( false ) ; this . clearDebris ( ) ; const node = this . nodeList [ parseInt ( e . target . id . split ( 'node_' ) [ 1 ] ) ] ; if ( ! this . invalid_area . valid ) { node . parent = { id : 0 } ; } else { node . old_parent = node . parent ; const drop = this . getNode ( this . drag_target ) ; if ( this . drag_target === parseInt ( e . target . id . split ( 'node_' ) [ 1 ] ) || this . drag_target === undefined || drop === undefined || drop . parent . value === node . value ) { node . parent = { id : 0 } ; } else { node . parent = drop ; } } node . updateNode ( ) ; if ( this . dropCallback ) { this . dropCallback ( node ) ; } } ) ; this . main_container . addEventListener ( 'dragenter' , ( e ) => { this . clearDebris ( ) ; try { let target = { left : e . target . getBoundingClientRect ( ) . left , top : e . target . getBoundingClientRect ( ) . top , } ; if ( target . top > this . invalid_area . top && target . top < this . invalid_area . bottom && target . left > this . invalid_area . left && target . left < this . invalid_area . right ) { this . invalid_area . valid = false ; this . invalid_area . container . classList . add ( 'invalid' ) ; this . invalid_area . container . classList . remove ( 'valid' ) ; } else { this . invalid_area . valid = true ; this . invalid_area . container . classList . remove ( 'invalid' ) ; this . invalid_area . container . classList . add ( 'valid' ) ; } if ( e . target . classList ) { if ( e . target . classList . contains ( 'drop_target' ) ) { e . target . classList . add ( 'drag_triggered' ) ; this . drag_target = parseInt ( e . target . id . split ( 'node_' ) [ 1 ] ) ; } } } catch ( e ) { this . drag_target = undefined ; } } ) ; } }
this method will contains static events for tree
this method will contains static events for tree
//close menu //close all first //menu toggle event for node //drag - drop events //drag start //give border to container //container //drag callback //draging //console.log('drag happenign'); //drag end //console.log('drag end') //remove border to container //make all elements pointer clean //clear old targets //get node //check is valid //set old parent for cleaning //this means it dragged to outside //drop callback //drag location //console.log('drag enter') //check position is valid //this is for updating node parent to current //console.log('dragging have exception..');