Be careful with custom jquery plugin event listeners.

Reading time ~1 minute

A developer will run into a bunch of different issues when working in a team environment.  Merge fails, stepping on code changes, and disagreements on..well pretty much everything…come to mind.

One would think that javascript would be slightly more immune to these types of collaborative problems but I still manage to run into issues.  We’ve been really good about namespacing and using closures in our front end code.  We hate polluting the DOM.  But a recent issue cropped up that I’d like to bring awareness to.

We have been using Colorbox as the jquery plugin of choice for our modals.  We have different modals that we use and occasionally one area of the site will have multiple triggers to multiple windows.  We noticed that there were some artifacts in the background of the modal that were other modals that we *thought* weren’t being triggered.  When I dug into the code I found that there were global event listeners that were custom to the Colorbox plugin that were being used in the code.  cbox_complete, cbox_cleanup, etc are all GLOBAL EVENT LISTENERS…when you read the dox you need to mentally map event listeners like that with other document bound listeners like keyup, mouseup, etc.  Those global events will trigger other events that you may not realize.

So if you must use global event listeners, do so with caution.  Also, check the dox.  Maybe there are instance specific methods you can call.  That way, your code will play nice with everyone. :)

Writing Node.js Apps from Scratch

Satirical posts regarding the bloat of modern day apps are a hot topic of both memes and [dev discussion boards](… Continue reading

Servicing Your Actual Customer

Published on May 26, 2016

Testing your APIs with Cucumber

Published on August 02, 2015