I
I
Ivan Simonov2020-05-10 16:07:07
JavaScript
Ivan Simonov, 2020-05-10 16:07:07

How to create a plugin?

Hello
Created my first plugin (bike) - code

Now like this

const select = new Select(
      document.querySelector('.select'),
      'Selected items',
      '../select.json'    
    );


Please tell me how to make it look like this
const select = new Select({
    selector: '.select',
    label: 'Selected items',
    url: '../select.json',
    onOpen() {
      console.log('open')
    },
   onClose(){
     console.log('close')
   }
  });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-05-10
@ivan00007

class Select {
  constructor({
    selector,
    label,
    url,
    onOpen,
    onClose
  }) {
    this.container = document.querySelector(selector);
    this.label = label;
    this.url = url;
    this._onOpen = onOpen;
    this._onClose = onClose;

    ...
  }

  ...

  open() {
    ...

    if (this._onOpen !== undefined) {
      this._onOpen();
    }
  }

  close() {
    ...

    if (this._onClose !== undefined) {
      this._onClose();
    }
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question