Andrew Allbright
Andrew Allbright

Reputation: 3839

What is the thing in jQuery Mobile that is reading "data-..." and replacing with DOM elements?

jQuery mobile is reading through and replacing my DOM with it's own DOM. I have the source of jQuery and jQuery Mobile open; where can I find the thing that is doing the reading and replacing?

The reason I want to learn about this feature is because I'm asynchronously injecting my own DOM and I want to run the jQuery Mobile "compiler" again so it renders my new DOM in jQuery Mobile's style.

Upvotes: 0

Views: 57

Answers (1)

frequent
frequent

Reputation: 28513

The thing is not easy to pin down. From JQM 1.4 you can have a look at all JQM content widgets and check out which functions are run when widget option enhanced is not set - usually that should be inside an _enhance()

As for reading and writing data-foo, at the end of the day it will be your JavaScript get/setAttribute methods with some modifications for namespaces.

If you inject your own DOM, you can either - inject pre-enhanced markup ~ no data-attributes, but finished contents (you should leave data- attributes should you want to change any widget options - inject non-enhanced markup = just plain HTML with data-attributes.

In both cases you will need to call enhanceWithin() on the parent(!) which includes your dynamically added content. In the first case, JQM then only creates the widget objects. In the 2nd case, JQM creates the necessary markup and widget objects (slower).

Upvotes: 2

Related Questions