I am creating an application that includes the creation of several unique โwidgetsโ, and itโs hard for me to understand the practice of encapsulating the logic of these user interface components using jQuery. These are basically disposable components that are not reused in several places in the application.
I experimented with a lowpro plugin , and although it allows more or less of what I want, I feel m goes against the "jQuery path" using it.
To provide some context, here is an abbreviated extract from what I wrote using lowpro. This is a sortable list that may include other items. When it is initialized empty, it shows a placeholder.
FieldList = $.klass({ initialize: function() { this.placeholder = $('#get-started-placeholder'); if (this.items().length == 0) { this.deactivateList(); } else { this.activateList(); } }, items: function() { return this.element.children('li:visible'); }, deactivateList: function() { this.element.hide(); this.element.sortable('destroy'); this.placeholder.show(); var instance = this; this.placeholder.droppable({ hoverClass: 'hovered', drop: function(e, ui) { instance.receiveFirstField(ui.helper); } }); }, activateList: function() { this.placeholder.hide(); this.placeholder.droppable('destroy'); this.element.show(); var instance = this; this.element.sortable({ placeholder: 'placeholder', forcePlaceholderSize: false, tolerance: 'pointer', handle: 'h4', opacity: 0.9, zIndex: 90, stop: function(e, ui) { instance.receiveField(ui.item); } }); }, receiveFirstField: function(element) { ... this.activateList(); }, receiveField: function(element) { ... } }); $(function() { $('ol#fields').attach(FieldList); }
Please note that here I have a bit of state, and some instance methods that I would like to make private, etc. So, any jQuery profiles that can tell me how they will do this, without relying on something like lowpro, which possibly javsacript into something that shouldn't be? I have a feeling that there is a clean way to do something like this using the module template that I saw in this thread but the parts are not going for me.
Thanks!
jquery
Brent dillingham
source share