How CustomEvent.observe works?

goswami_sudipta
Mega Expert

Hello--

I was reviewing one OoB code which resizes the iFrame's size based on user's interaction. The code is something like below

<script>

                      (function() {

                              CustomEvent.observe('content_frame.resized', contentFrameResized);

                              CustomEvent.observe('content_frame.loaded', contentFrameResized);

                              var isFirefox = navigator.userAgent.indexOf('Firefox') > -1;

                              function contentFrameResized(name, height) {

                                      if (!name)

                                              return;

                                      var f = $(name);

                                      if (!f)

                                              return;

                                      // avoid using an AND here

                                      if (!isFirefox || height == 10)

                                              _resize(f, height);

                                      else {

                                              // delay resize for firefox

                                              setTimeout(function() {

                                                      _resize(f, height);

                                              }, 0);                                              

                                      }

                              }

                              function _resize(f, height) {

                                      f.height = height;

                              }

                      })();

              </script>

I am curios to understand how "content_frame.resized" is attached to the iFrames.

Any pointer would be helpful.

Regards,

Sudipta

Brad Tilton (Cloud Sherpas)

3 REPLIES 3

Brad Tilton
ServiceNow Employee
ServiceNow Employee

It gets fired from the ui_page_footer ui macro that runs inside of the iframe.


Thanks Brad.



Could you please also let me know where the event "content_frame.resized" is defined.



Regards,


Sudipta


It gets fired from that same ui macro. In a new fuji instance it's on line 29:



window.parent.CustomEvent.fire('content_frame.resized', self.name, pageHeight);