Loading ...
Sorry, an error occurred while loading the content.

Re: Dialog with embedded body javascript

Expand Messages
  • suggs_is_ard
    Hi Caridy, I believe I ve found the solution. I decided to delve in to the dipsatcher code to trace the code execution and discovered the problem. It seems
    Message 1 of 10 , Apr 1, 2009
    • 0 Attachment
      Hi Caridy,

      I believe I've found the solution. I decided to delve in to the dipsatcher code to trace the code execution and discovered the problem. It seems the "dispatch" method is only designed to execute a script once with the following conditional

      if ((_hashtable[i].status == constants.DISPATCHED) && !config.override)

      If it detects a previous successful execution of a script uri then it discards it. This meant that reciprocal calls to a script are ignored. As soon as I removed this conditional my script executes every single time perfectly!

      A big thanks for all your help,

      All the best

      Mike


      --- In ydn-javascript@yahoogroups.com, "Caridy Patino" <caridy@...> wrote:
      >
      > Hello Mike,
      >
      > Sorry for the delay.
      >
      > About the code, did you try to put the dispatcher process after the render process? This can have different result depending of the way you create the dialog (from markup or from JS).
      >
      > Also, can you post a working test case to dig a little bit in this issue?
      >
      > Best Regards,
      > Caridy
      >
      > --- In ydn-javascript@yahoogroups.com, "suggs_is_ard" <suggs_is_ard@> wrote:
      > >
      > > Hi Caridy,
      > >
      > > Just had an interesting development.
      > >
      > > Previously when closing the dialog i was using hide(), then re-creating it by overwriting the variable with a new constructor each time...that only executed script once (without dispacher and in FF) as expected BUT if i change hide() to destroy() then it executes every time (again without dispatcher and only in FF - obviously nothing in IE)
      > >
      > > HOWEVER, when i use dispatcher it only executes the once as before! Weird! Some of the code i'm using is below;
      > >
      > >
      > >
      > > myDialog = new YAHOO.widget.Dialog("myDialog", {
      > > fixedcenter:true,
      > > zindex:10,
      > > modal:true,
      > > effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25},
      > > hideaftersubmit: false
      > > });
      > >
      > >
      > >
      > > myDialog.setBody("");
      > > YAHOO.plugin.Dispatcher.process(myDialog.body, xmlHttp.responseText);
      > > myDialog.render(document.body);
      > > myDialog.show();
      > >
      > > I had to manually set body to blank in order to overwrite it, but script is only run the once.
      > >
      > > Kind regards,
      > >
      > > Mike
      > >
      > >
      > >
      > > --- In ydn-javascript@yahoogroups.com, "Caridy Patino" <caridy@> wrote:
      > > >
      > > > Hi Mike,
      > > >
      > > > Yes, that's what I was expecting. Considering that IE will never execute js blocks injected thru innerHTML.
      > > >
      > > > But, if you are using dispatcher, then you should drive all the injection thru the dispatcher.fetch or dispatcher.process, and you should not inject it into the dialog during the creation of render process. this will warranty a single time execution.
      > > >
      > > > About the issue when you hide/show/create a dialog. Are you destroying/creating the dialog again? or are you showing/hiding the dialog? Can I see your code? or a test case?
      > > >
      > > > Best Regards,
      > > > Caridy
      > > >
      > > > --- In ydn-javascript@yahoogroups.com, "suggs_is_ard" <suggs_is_ard@> wrote:
      > > > >
      > > > > Hey,
      > > > >
      > > > > Yea I did. FF executes, IE doesnt (without dispatcher). But I've also implemented the dispatcher as well so then FF executes it twice, and IE once. Make sense? This is what you'd expect
      > > > >
      > > > > The problem arises if I call hide() on the dialog then try to open it again (the code simply creates a new dialog as before) only this time there is no execution of javascript, whether I use the dispatcher or not. I'm assuming the issue arises because of this hide and recreate but not sure why that would be.
      > > > >
      > > > > Kind regards,
      > > > >
      > > > > Mike
      > > > >
      > > > >
      > > > > --- In ydn-javascript@yahoogroups.com, "Caridy Patino" <caridy@> wrote:
      > > > > >
      > > > > > Hey,
      > > > > >
      > > > > > Did you test it in other browsers? I'm pretty sure that using innerHTML to inject JS blocks will not work on a-grade browsers. That's why I'm recommending you the dispatcher.
      > > > > >
      > > > > > Best Regards,
      > > > > > Caridy
      > > > > >
      > > > > > --- In ydn-javascript@yahoogroups.com, "suggs_is_ard" <suggs_is_ard@> wrote:
      > > > > > >
      > > > > > > Hi Caridy,
      > > > > > >
      > > > > > > Thanks for the prompt reply.
      > > > > > >
      > > > > > > I started playing with the Process function after posting my problem and indeed managed to get it to execute the script. One main issue I'm having though is the following:
      > > > > > >
      > > > > > > 1. Click "opendialog" button which opens a new dialog and assigns the content of a XHR response to the body and executes any javascript present.
      > > > > > >
      > > > > > > 2. Close the dialog (using hide() function)
      > > > > > >
      > > > > > > 3. Click "opendialog" button again which should repeat step 1 BUT this time around no javascript is executed. The XHR response has exactly the same code as before.
      > > > > > >
      > > > > > > Thanks once again for your initial reply, any thoughts about this at all? I'm a bit stumped.
      > > > > > >
      > > > > > > Thanks
      > > > > > >
      > > > > > >
      > > > > > > --- In ydn-javascript@yahoogroups.com, "Caridy Patino" <caridy@> wrote:
      > > > > > > >
      > > > > > > > Hello,
      > > > > > > >
      > > > > > > > There are few factors here:
      > > > > > > >
      > > > > > > > 1. injecting content in a dialog will not always execute the JS, because the dialog uses innerHTML to inject the new content within the body, and some a-grade browsers strip out JS before insert it into the dom.
      > > > > > > >
      > > > > > > > 2. if you have a custom body for the dialog (content loaded thru AJAX), you can inject it everytime you renderer the dialog using this:
      > > > > > > >
      > > > > > > > var callback = function (o) {
      > > > > > > > YAHOO.plugin.Dispatcher.process(myDialog.body, o.responseText);
      > > > > > > > }
      > > > > > > > // your AJAX call here
      > > > > > > >
      > > > > > > > And this method will be a callback method for your AJAX call.
      > > > > > > >
      > > > > > > > In this case, the dispatcher plugin will actually handle the content, injecting the code into the body of the dialog without the JS chunks, and then executing those js chunks.
      > > > > > > >
      > > > > > > > More information about the dispatcher here:
      > > > > > > > http://bubbling-library.com/eng/api/docs/plugins/dispatcher
      > > > > > > >
      > > > > > > > You can also use the fetch method, if you want to delegate the AJAX process to the dispatcher. At the end it will use YUI Connection Manager as well, and your code will be less complex:
      > > > > > > >
      > > > > > > > YAHOO.plugin.Dispatcher.fetch(myDialog.body, 'myurl');
      > > > > > > >
      > > > > > > > But in this case, it will loads the content of the body everytime you render the dialog.
      > > > > > > >
      > > > > > > > Just let me know if you need help.
      > > > > > > >
      > > > > > > > Best Regards,
      > > > > > > > Caridy
      > > > > > > >
      > > > > > > > --- In ydn-javascript@yahoogroups.com, "suggs_is_ard" <suggs_is_ard@> wrote:
      > > > > > > > >
      > > > > > > > > Hi,
      > > > > > > > >
      > > > > > > > > I'm pulling in the content of a page via XHR and assigning the content to the body of a Dialog object and displaying it. The page being pulled in contains additional javascript (alert statements for debugging) and successfully executes the first time round but if the (modal) dialog is closed then re-opened the javascript is no longer executed.
      > > > > > > > >
      > > > > > > > > Every "open" call overwrites the same dialog and sets the HTML body (this always returns the correct code) but for some reason the script is executed on first pass but not again (when the body is set again with the same code).
      > > > > > > > >
      > > > > > > > > Can anyone help me make sense of this please? I hope I've made the situation clear enough.
      > > > > > > > >
      > > > > > > > > Thanks in advance
      > > > > > > > >
      > > > > > > >
      > > > > > >
      > > > > >
      > > > >
      > > >
      > >
      >
    • Caridy Patino
      Hey Mike, Now it makes sense to me hehehehe. You never mentioned that you include external JS that are not cacheable. Here is the normal solution:
      Message 2 of 10 , Apr 1, 2009
      • 0 Attachment
        Hey Mike,

        Now it makes sense to me hehehehe.

        You never mentioned that you include external JS that are not cacheable.

        Here is the normal solution:

        YAHOO.plugin.Dispatcher.process(myDialog.body, xmlHttp.responseText, {
        override: true
        });

        Usually, the dispatcher assumes that all the external JS should be executed only once, and the dispatcher uses a hash table to avoid multiple executions. An example of this approach is the inclusion of a YUI component in the content, and in this case, the component should not be loaded multiple times. Anyway, I added the "override" configuration attribute. So you can keep using the official dispatcher copy, you just need to add a 3rd argument with the configuration.

        Best Regards,
        Caridy

        --- In ydn-javascript@yahoogroups.com, "suggs_is_ard" <suggs_is_ard@...> wrote:
        >
        > Hi Caridy,
        >
        > I believe I've found the solution. I decided to delve in to the dipsatcher code to trace the code execution and discovered the problem. It seems the "dispatch" method is only designed to execute a script once with the following conditional
        >
        > if ((_hashtable[i].status == constants.DISPATCHED) && !config.override)
        >
        > If it detects a previous successful execution of a script uri then it discards it. This meant that reciprocal calls to a script are ignored. As soon as I removed this conditional my script executes every single time perfectly!
        >
        > A big thanks for all your help,
        >
        > All the best
        >
        > Mike
        >
        >
        > --- In ydn-javascript@yahoogroups.com, "Caridy Patino" <caridy@> wrote:
        > >
        > > Hello Mike,
        > >
        > > Sorry for the delay.
        > >
        > > About the code, did you try to put the dispatcher process after the render process? This can have different result depending of the way you create the dialog (from markup or from JS).
        > >
        > > Also, can you post a working test case to dig a little bit in this issue?
        > >
        > > Best Regards,
        > > Caridy
        > >
        > > --- In ydn-javascript@yahoogroups.com, "suggs_is_ard" <suggs_is_ard@> wrote:
        > > >
        > > > Hi Caridy,
        > > >
        > > > Just had an interesting development.
        > > >
        > > > Previously when closing the dialog i was using hide(), then re-creating it by overwriting the variable with a new constructor each time...that only executed script once (without dispacher and in FF) as expected BUT if i change hide() to destroy() then it executes every time (again without dispatcher and only in FF - obviously nothing in IE)
        > > >
        > > > HOWEVER, when i use dispatcher it only executes the once as before! Weird! Some of the code i'm using is below;
        > > >
        > > >
        > > >
        > > > myDialog = new YAHOO.widget.Dialog("myDialog", {
        > > > fixedcenter:true,
        > > > zindex:10,
        > > > modal:true,
        > > > effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25},
        > > > hideaftersubmit: false
        > > > });
        > > >
        > > >
        > > >
        > > > myDialog.setBody("");
        > > > YAHOO.plugin.Dispatcher.process(myDialog.body, xmlHttp.responseText);
        > > > myDialog.render(document.body);
        > > > myDialog.show();
        > > >
        > > > I had to manually set body to blank in order to overwrite it, but script is only run the once.
        > > >
        > > > Kind regards,
        > > >
        > > > Mike
        > > >
        > > >
        > > >
        > > > --- In ydn-javascript@yahoogroups.com, "Caridy Patino" <caridy@> wrote:
        > > > >
        > > > > Hi Mike,
        > > > >
        > > > > Yes, that's what I was expecting. Considering that IE will never execute js blocks injected thru innerHTML.
        > > > >
        > > > > But, if you are using dispatcher, then you should drive all the injection thru the dispatcher.fetch or dispatcher.process, and you should not inject it into the dialog during the creation of render process. this will warranty a single time execution.
        > > > >
        > > > > About the issue when you hide/show/create a dialog. Are you destroying/creating the dialog again? or are you showing/hiding the dialog? Can I see your code? or a test case?
        > > > >
        > > > > Best Regards,
        > > > > Caridy
        > > > >
        > > > > --- In ydn-javascript@yahoogroups.com, "suggs_is_ard" <suggs_is_ard@> wrote:
        > > > > >
        > > > > > Hey,
        > > > > >
        > > > > > Yea I did. FF executes, IE doesnt (without dispatcher). But I've also implemented the dispatcher as well so then FF executes it twice, and IE once. Make sense? This is what you'd expect
        > > > > >
        > > > > > The problem arises if I call hide() on the dialog then try to open it again (the code simply creates a new dialog as before) only this time there is no execution of javascript, whether I use the dispatcher or not. I'm assuming the issue arises because of this hide and recreate but not sure why that would be.
        > > > > >
        > > > > > Kind regards,
        > > > > >
        > > > > > Mike
        > > > > >
        > > > > >
        > > > > > --- In ydn-javascript@yahoogroups.com, "Caridy Patino" <caridy@> wrote:
        > > > > > >
        > > > > > > Hey,
        > > > > > >
        > > > > > > Did you test it in other browsers? I'm pretty sure that using innerHTML to inject JS blocks will not work on a-grade browsers. That's why I'm recommending you the dispatcher.
        > > > > > >
        > > > > > > Best Regards,
        > > > > > > Caridy
        > > > > > >
        > > > > > > --- In ydn-javascript@yahoogroups.com, "suggs_is_ard" <suggs_is_ard@> wrote:
        > > > > > > >
        > > > > > > > Hi Caridy,
        > > > > > > >
        > > > > > > > Thanks for the prompt reply.
        > > > > > > >
        > > > > > > > I started playing with the Process function after posting my problem and indeed managed to get it to execute the script. One main issue I'm having though is the following:
        > > > > > > >
        > > > > > > > 1. Click "opendialog" button which opens a new dialog and assigns the content of a XHR response to the body and executes any javascript present.
        > > > > > > >
        > > > > > > > 2. Close the dialog (using hide() function)
        > > > > > > >
        > > > > > > > 3. Click "opendialog" button again which should repeat step 1 BUT this time around no javascript is executed. The XHR response has exactly the same code as before.
        > > > > > > >
        > > > > > > > Thanks once again for your initial reply, any thoughts about this at all? I'm a bit stumped.
        > > > > > > >
        > > > > > > > Thanks
        > > > > > > >
        > > > > > > >
        > > > > > > > --- In ydn-javascript@yahoogroups.com, "Caridy Patino" <caridy@> wrote:
        > > > > > > > >
        > > > > > > > > Hello,
        > > > > > > > >
        > > > > > > > > There are few factors here:
        > > > > > > > >
        > > > > > > > > 1. injecting content in a dialog will not always execute the JS, because the dialog uses innerHTML to inject the new content within the body, and some a-grade browsers strip out JS before insert it into the dom.
        > > > > > > > >
        > > > > > > > > 2. if you have a custom body for the dialog (content loaded thru AJAX), you can inject it everytime you renderer the dialog using this:
        > > > > > > > >
        > > > > > > > > var callback = function (o) {
        > > > > > > > > YAHOO.plugin.Dispatcher.process(myDialog.body, o.responseText);
        > > > > > > > > }
        > > > > > > > > // your AJAX call here
        > > > > > > > >
        > > > > > > > > And this method will be a callback method for your AJAX call.
        > > > > > > > >
        > > > > > > > > In this case, the dispatcher plugin will actually handle the content, injecting the code into the body of the dialog without the JS chunks, and then executing those js chunks.
        > > > > > > > >
        > > > > > > > > More information about the dispatcher here:
        > > > > > > > > http://bubbling-library.com/eng/api/docs/plugins/dispatcher
        > > > > > > > >
        > > > > > > > > You can also use the fetch method, if you want to delegate the AJAX process to the dispatcher. At the end it will use YUI Connection Manager as well, and your code will be less complex:
        > > > > > > > >
        > > > > > > > > YAHOO.plugin.Dispatcher.fetch(myDialog.body, 'myurl');
        > > > > > > > >
        > > > > > > > > But in this case, it will loads the content of the body everytime you render the dialog.
        > > > > > > > >
        > > > > > > > > Just let me know if you need help.
        > > > > > > > >
        > > > > > > > > Best Regards,
        > > > > > > > > Caridy
        > > > > > > > >
        > > > > > > > > --- In ydn-javascript@yahoogroups.com, "suggs_is_ard" <suggs_is_ard@> wrote:
        > > > > > > > > >
        > > > > > > > > > Hi,
        > > > > > > > > >
        > > > > > > > > > I'm pulling in the content of a page via XHR and assigning the content to the body of a Dialog object and displaying it. The page being pulled in contains additional javascript (alert statements for debugging) and successfully executes the first time round but if the (modal) dialog is closed then re-opened the javascript is no longer executed.
        > > > > > > > > >
        > > > > > > > > > Every "open" call overwrites the same dialog and sets the HTML body (this always returns the correct code) but for some reason the script is executed on first pass but not again (when the body is set again with the same code).
        > > > > > > > > >
        > > > > > > > > > Can anyone help me make sense of this please? I hope I've made the situation clear enough.
        > > > > > > > > >
        > > > > > > > > > Thanks in advance
        > > > > > > > > >
        > > > > > > > >
        > > > > > > >
        > > > > > >
        > > > > >
        > > > >
        > > >
        > >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.