0

Is it good/bad practice to use deep nested options when creation a jquery.ui.widget

Something like the below? If a user wanted to say after initialization change the option for height in outContainer css, would they have to replace the entire css object within options?

options: {
    views: null,
    transitionTypes: {
        showView: { transition:slide, mode:show},
        hideView: { transition:slide, mode:hide}
    },
    css: {
        outContainer: {
            height: '0',
            display: 'none'
         }
    }

}

2 Answers 2

1

Yes. http://jsfiddle.net/joeflateau/tryTT/

Sign up to request clarification or add additional context in comments.

Comments

0

I'd rather have a good sectioned options-object than a large list. Beware of setting good default values though, so you don't have to pass a large object to the plugin on init...

As for the manipulating object afterwards: I'd let the dev manipulate a set of "public" properties and then do a "redraw" of the plugin (not a total new object, but merely a soft re-init).

object.css.outContainer.height = "100";
object.redraw();

3 Comments

That's a good idea actually but is there any reason why you should NOT bypass the options infrastructure provided by jquery.ui.widget?
I looked into the widget factory, as I haven't worked with it a lot.. and you can work with the _refresh to update the properties in an elegant way. Joe Flateau made a nice example of it with the _create method. I suggest you implement the _refresh method aswell, so can alter an object dynamically AND have the widget sort it out immediately. My solution is more for a custom plugin than the widget factory.
Appearently the Widget has some $.extend(true, obja, objb) like functionality and Joe's fiddle proves this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.