nipplejs icon indicating copy to clipboard operation
nipplejs copied to clipboard

Add support for overwriting the buildEl function

Open vladfr opened this issue 5 years ago • 4 comments

I needed to customize the HTML of the nipple elements, so I'm adding support to overwrite the buildEl function. Any suggestions on how this could be improved are welcome.

vladfr avatar Feb 07 '19 19:02 vladfr

If you could add some documentation on how to use this, it would be 👌

yoannmoinet avatar Feb 14 '19 09:02 yoannmoinet

Hey @yoannmoinet, thanks! Added more checks, and added it in the Readme. I can't get all tests to pass, but most fail on the current master as well. I'll try to add a test for a simple className added via buildEl, and maybe I'll have time for an example as well.

One idea I had was to change this into a hook function? Instead of overwriting the whole buildEl(), I could add another function that gets called right after it?

// nipple.js:43
    this.buildEl()
        .stylize();

// would become:
    
    this.buildEl();
    if (this.options.dataOnly === false) {
          this.collection.afterBuildEl();
    }
    this.stylize();

WDYT?

vladfr avatar Feb 16 '19 12:02 vladfr

Sorry for the delay @vladfr (started a new job in January). I'll have a better look at this because this is a great idea, but I'm not sure about the implementation. I feel like it's a bit complicated for a dev to implement a full function just to have his own element.

I'll figure something out.

yoannmoinet avatar Mar 11 '19 08:03 yoannmoinet

Hi,

Yes I hear you. That's why I didn't really push for it... It did the trick as a hack, but indeed it should be done more cleanly.

On Mon, Mar 11, 2019, 10:30 Yoann Moinet [email protected] wrote:

Sorry for the delay @vladfr https://github.com/vladfr (started a new job in January). I'll have a better look at this because this is a great idea, but I'm not sure about the implementation. I feel like it's a bit complicated for a dev to implement a full function just to have his own element.

I'll figure something out.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/yoannmoinet/nipplejs/pull/98#issuecomment-471447295, or mute the thread https://github.com/notifications/unsubscribe-auth/AAM-hzuZ4dCG89TkS2JnuE1aGnv-_p5jks5vVhQ8gaJpZM4aobrK .

vladfr avatar Mar 11 '19 12:03 vladfr