I am a software developer. My main skill is in javascript where I have created various scripts and jQuery widgets for clients with very complex requirements.
I have got to a point now in my widget library where I need to create a control widget. This control widget needs to be able to create any type of widget I require based on a String in the "type" option.
Now this works fine to create the widget and it works perfectly well, until I want to change option values in the dynamically created widget. All I get is a error saying that "myWidget" has not been initialised.
I am wondering if there is any plans to provide an alternative to the _on function? What I need is similar to the _on function except that I need certain events to be handled regardless of their disabled state.
What I have is a parent widget that controls translations of my child widgets. What I want to happen is when the parent widget triggers an event to say the language has been changed, for all the child widgets they need to process this request and update their internal translations and any visible text to the new language.
When I create a widget that has deep set object literal options, and if I try to apply the widget to multiple divs, each div contains its values and the values of all the preceding instance's values as well.
e.g.
$widget("test.me", {
options: {
subOption: {
values: []
}
},
_create: function() {
var _this = this;
$.each(this.options.subOption.values, function (i, value) {
alert(value);
}
}
});
when this is put on multiple elements with different values I am getting non-instance specific concat'd version of this option array.
Is there any way to find out what widgets are on an element? I have a function that takes a parameter that could be one of 3 widgets that I have written, but I need to do slightly different things depending on what widget has been initialized on the elements. Another use i have is to be able to list what widgets I have put on an element (e.g. button && tooltip)
I am hoping for something like:
var blnIsInstanceOfWidget = $.instanceof(element, $.widget);
I have been trying to find a way around this obscure problem for the last few weeks and I am hoping someone here can help or tell me what I am doing wrong.
I am using the Widget Factory to create widgets using inheritance. Basically each layer of my inheritance hierarchy has only a single task. my base class is in charge of logging, the next layer is in charge of my translations, etc... until I get to the top layer which is a widget to display my content.
In my translation layer I currently have a private variable that contains all my required translations with a function to pull the correct translation based on what locale the page is using. This works fine for a single instance or widget. But if I add another instance to the page of a different type of widget (so the translations are different) then the first widget does not have the correct translations any more.
very simply I am showing here the various variable options I can think of. When you press the button the second instance calls the doAlerts() and alertValues() function and has the correct values. But when the first instance calls them it seems that the private and public "Object" variables contain the value of the second widget. However, as the options are also an object I would have expected that to do the same, but that value seems to be fine (however I do not wish to put my object in here as it should not be available for the callee to edit).
Is there something I am missing here? or am I going to have to fall back to adding it to the options (maybe prefixed with an underscore)?