Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

preventDefault during pagebeforecreate event throws error #4459

Closed
jhr007 opened this Issue · 4 comments

3 participants

@jhr007

I'm trying to preventDefault the page from being enhanced on "pagebeforecreate", until web database has a chance to run a callback that adds elements. Was hoping a pause here... and when ready a pageshow/initialize would apply the jquerymobile touch and show it.

http://jsfiddle.net/jhr007/tgZTJ/

safari says: TypeError: 'undefined' is not an object (evaluating 'e[0][a.expando]')

chrome says: Uncaught TypeError: Cannot read property 'jQuery17109778191314544529' of undefined jqm1.1.0 line: 5110

(The lines help w readability)


$.widget._createSubPages -------------------------------------------------------->jquery.mobile-1.1.0.js:5110
$.widget.refresh -------------------------------------------------------->query.mobile-1.1.0.js:4944
$.widget._create -------------------------------------------------------->query.mobile-1.1.0.js:4829
$.Widget._createWidget -------------------------------------------------------->query.mobile-1.1.0.js:1062
$.widget._createWidget -------------------------------------------------------->query.mobile-1.1.0.js:1179
$.widget.$.(anonymous function).(anonymous function) -------------------------------------------------------->query.mobile-1.1.0.js:963
$.widget.bridge.$.fn.(anonymous function) -------------------------------------------------------->query.mobile-1.1.0.js:1025
jQuery.extend.each -------------------------------------------------------->query.js:658
jQuery.fn.jQuery.each -------------------------------------------------------->query.js:271
$.widget.bridge.$.fn.(anonymous function) -------------------------------------------------------->query.mobile-1.1.0.js:1020
$.widget.enhance -------------------------------------------------------->query.mobile-1.1.0.js:1225
$.widget.enhanceWithin -------------------------------------------------------->query.mobile-1.1.0.js:1204
$.widget.options.theme -------------------------------------------------------->query.mobile-1.1.0.js:5195
jQuery.event.dispatch -------------------------------------------------------->query.js:3256
jQuery.event.add.elemData.handle.eventHandle -------------------------------------------------------->query.js:2875
jQuery.event.trigger -------------------------------------------------------->query.js:3144
jQuery.fn.extend.trigger -------------------------------------------------------->query.js:3781
jQuery.extend.each -------------------------------------------------------->query.js:658
jQuery.fn.jQuery.each -------------------------------------------------------->query.js:271
jQuery.fn.extend.trigger -------------------------------------------------------->query.js:3780
$.Widget._trigger -------------------------------------------------------->query.mobile-1.1.0.js:1160
$.Widget._createWidget -------------------------------------------------------->query.mobile-1.1.0.js:1063
$.widget._createWidget -------------------------------------------------------->query.mobile-1.1.0.js:1179
$.widget.$.(anonymous function).(anonymous function) -------------------------------------------------------->query.mobile-1.1.0.js:963
$.widget.bridge.$.fn.(anonymous function) -------------------------------------------------------->query.mobile-1.1.0.js:1025
jQuery.extend.each -------------------------------------------------------->query.js:658
jQuery.fn.jQuery.each -------------------------------------------------------->query.js:271
$.widget.bridge.$.fn.(anonymous function) -------------------------------------------------------->query.mobile-1.1.0.js:1020
enhancePage -------------------------------------------------------->query.mobile-1.1.0.js:2848
$.mobile.loadPage.$.ajax.success -------------------------------------------------------->query.mobile-1.1.0.js:3131
jQuery.Callbacks.fire -------------------------------------------------------->query.js:1046
jQuery.Callbacks.self.fireWith -------------------------------------------------------->query.js:1164
done -------------------------------------------------------->query.js:7399
jQuery.ajaxTransport.send.callback

@MauriceG

Hi!
Please take a look at http://jquerymobile.com/test/docs/api/events.html -> pagebeforeload
Maurice

@jaspermdegroot
Collaborator

@jhr007

See the page in the docs @MauriceG pointed you at. It shows you on which events you can call preventDefault.
In general there is no need to create a pause when you bind to the pagebeforecreate event to manipulate the content. If for some reason this doesn't work for your specific use case, binding to the pagebeforeload event like Maurce suggested could be the solution.

Since this doesn't concern a bug I am closing the issue and would like to refer you to the jQuery forum where you can ask for help.

@jhr007

Reopen as a feature request, and a document issue...

On Meta, 50,000 feet level, I'm trying to do a simple html insert into a dom before enhancements. This case being special because I'd like to stop flow, and pick it back up later, which apparently someone writing the docs thought this need might arise (or am I misreading?).

and prevent the auto-initializations from occuring.

http://jquerymobile.com/test/docs/api/events.html -> Page initialization events


Internally, jQuery Mobile auto-initializes plugins based on the markup conventions found in a given "page". For example, an input element with a type of range will automatically generate a custom slider control.

This auto-initialization is controlled by the "page" plugin, which dispatches events before and after it executes, allowing you to manipulate a page either pre-or-post initialization, or even provide your own intialization(<-- spelling) behavior and prevent the auto-initializations from occuring.

Note that by binding to pagebeforecreate, you can manipulate markup before jQuery Mobile's default widgets are auto-initialized. For example, say you want to add data-attributes via JavaScript instead of in the HTML source, this is the event you'd use. ...

@jaspermdegroot
Collaborator

Closing because this was an issue with our old docs. If you still see an issue with our new API docs please report it here https://github.com/jquery/api.jquerymobile.com/issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.