1 (edited by clyrrad 2009-08-28 4:42:34 PM)

Topic: An Example Of Using XAJAX With Greybox

Its easy enough to have Greybox call functions in the parent window by using the syntax parent.parent.myFunction(), but what about if you want to go the other way around?  What if you want to have your parent xajax code be able to update elements in your Greybox?  I'll show you how to do this.

Greybox uses a nested IFRAME, so the trick here is to get into the nested IFRAME.  The first problem is that the outer IFRAME does not have an "id" attribute, so we need to add it programatically.   All of the magic happens in the begin() function.  In the example below we have a div in the Greybox called "lnpCityByCountry" and we want to update it via our function foo()

class myClass{
    //-------------------------------------------------------------------------
    public function foo()
    {
        $this->begin('GB_frame','GB_outer_frame');
        $objResponse->assign("lnpCityByCountry","innerHTML","testing 123");
        $this->end();
       
        return $objResponse;
    }
    //-------------------------------------------------------------------------
    private function begin($iframe,$outer_frame="")
    {
        global $objResponse;

        if ($outer_frame != "")
        {
            $objResponse->script("document.getElementsByTagName('IFRAME')[0].setAttribute('id','$outer_frame');");
            $objResponse->script("var theFrame = xajax.$('".$outer_frame."''); xajax.config.baseDocument = (theFrame.contentDocument || theFrame.contentWindow.document);");
        }
        $objResponse->script("var theFrame = xajax.$('".$iframe."'); xajax.config.baseDocument = (theFrame.contentDocument || theFrame.contentWindow.document);");
    }
    //-------------------------------------------------------------------------
    private function end()
    {
        global $objResponse;
        $objResponse->script("xajax.config.baseDocument = document;");
    }
    //-------------------------------------------------------------------------
}