Pass: 0

Events

…at a Pronto level

Pronto events exposed by the plugin:

  • pronto.request – Fired before new Pronto request is made
  • pronto.beforeload – Fired before new Pronto request is loaded
  • pronto.load – Fired after new Pronto request is loaded
  • pronto.render – Fired after new Pronto request is rendered
  • pronto.submit – Fired when a “form” button is pressed
  • pronto.error – Fired when $.ajax() fails
  • pronto.idle – Fired on specified interval of user inactivity
  • pronto.active – Fired when user becomes active (again)

Events passed to the client from Pronto

The originary event is passed back from Pronto to the client in the first four cases.
You can access it like this:

 window.addEventListener('pronto.render', function(event){
    var target = event.data.target || event.data.srcElement; //intermediate data attribute
})

In case of a pronto.error:
The error value of the failed central fetch() call is passed back to the client.

Your own events

…might need some tweaking, if they don’t work at first with Ajaxify:

  • events attached to e.g. the document might only fire once
  • attach to e.g. the body instead, if you would like them to fire each time around

That is due to the fact, that the content elements only are swapped and e.g. the document remains the same.

59 thoughts on “Events”

  1. Oh okay.. am trying to see how get page works.

    Will “a” be the URL of page I want to get??

    Also am trying to use the ajaxify.pronto(0, URL) in a pronto.request event but there seems to be an infinite loop or something.

    Also is there a way to get the current page url and probably add some parameters to it, such that I can use ajaxify.getPage or ajaxify.pronto to navigate there??

  2. Hi, am using this plug-in on my development environment specifically for WordPress plugin development.
    Everything works perfectly but there is a catch due to my requirement, I want to prevent a URL from loading based of some results from is such as ( on form submit I want to use jQuery validate to validate the form and if not validated it should load the action or send this request).
    I was able to do this before using this plug-in and I think the issue is I don’t know the right event to call that on such that if the validation failed nothing will happen.

    1. Hi there,

      Thanks for your quite extensive explanation of your use case and what’s going wrong.

      Well ideally, all you would have to do is change the registration of your event listener to the native:

      • window.addEventListener(...)

      …specifying the exact same event…

      …as explained on this same page.

      But I’m pretty sure, that you have understood that.

      Regarding the timing of the Pronto events – they are listed in chronological order – that’s to say:

      pronto.request – Fired before new Pronto request is made
      pronto.beforeload – Fired before new Pronto request is loaded
      pronto.load – Fired after new Pronto request is loaded
      pronto.render – Fired after new Pronto request is rendered

      …but I’m sure that you have realised that as well.

      What happens exactly, when you change the event handler registration to:

      • window.addEventListener()

      ?

      Thanks and regards

      1. Thanks for the swift reply.

        window.addEventListener(“pronto.request”, (e) => {….})

        in the code above I want to stop/intercept the request, such that I will be able to cancel the request if certain conditions were not fulfilled.

        Tried e.preventDefault() but I found out that it seems the event is not cancelable as it has ‘cancelable set to false in the event property’.

        so what is the possible way of intercepting the request.

        1. Your event handler registration looks alright.
          I suppose you’ve tried hooking into all of the other Pronto events?

          So it seems that you would like to stop the complete loading of Pronto, in case your form validation fails, right?
          Nobody has queried me to cancel the whole current Pronto request before – very interesting!
          I’m thinking about it and will let you know, if I can think of some way to perform the cancellation of the current load.

          You mentioned, that it seemed to work with the jQuery version of Ajaxify, right?
          I always try to examine, what’s the same and what’s different.
          Maybe you can illustrate that a bit?

          Finally, do you have a link to your test site or would you like it to be handled discretely?
          If so, we can continue via email in the background, if you prefer?

          1. Thanks.

            To your first question yes have tried other events ex ‘pronto.submit’ but I don’t still get to cancel the request.

            To your second question, yes I want to stop the loading of pronto if the form validation failed.

            To your third question, No I haven’t tried jQuery Ajaxify, what I meant is that when I perform an ajax request using jQuery the validation works the way I want.

            As am currently working on my local environment, I don’t have a test site right now but I can see to that if need be.

          2. Yea thanks.
            ajaxify.pronto(0, URL); , will help me to jump to a different page I think I can hack around this.

            Just a suggestion probably there could be an event or action that can be trigger or called to cancel pronto based on true or false value.

          3. Yes, that might work. Just found out, that there actually also is a direct way to abort the request:

            • ajaxify.getPage("a");

            You might want to try calling that in your event handler…

            (But I can’t guarantee that that will work. Also maybe due to timing issues)

Leave a Reply to Jarvis S Cancel reply

Your email address will not be published.

Show Buttons
Hide Buttons