Max SchmittMS
27th August 2013

jQuery Component for Crafty

I'm currently working on a little puzzle-game called pozzle, which uses the Crafty engine. Today I'm working on cleaning up my UI-code.

Here is a little jQuery component, that makes a jQuery-wrapper of the entity's DOM-element available. You call it by using this.$element, where this refers to your entity with the JQuery component attached.

Crafty.c('JQuery', {
init: function() {
this.requires('DOM')
this._rebindJQuerySelector()
this.bind('Change', this._rebindJQuerySelector)
},
remove: function() {
this.unbind('Change', this._rebindJQuerySelector)
},
_rebindJQuerySelector: function() {
this.$element = $(this._element)
}
})
Image of my head

About the author

Hi, I’m Max! I'm a fullstack JavaScript developer living in Berlin.

When I’m not working on one of my personal projects, writing blog posts or making YouTube videos, I help my clients bring their ideas to life as a freelance web developer.

If you need help on a project, please reach out and let's work together.

To stay updated with new blog posts, follow me on Twitter or subscribe to my RSS feed.