views:

466

answers:

3

Hello, I copied an example from the dojo site using Borderlayout. However, when I load in the browser , the entire data is shown for all the section . Then after a few second the content is refersh and the data is displayed correctly.

here is code that i copied . Thanks for your help

<head>
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dijit/themes/tundra/tundra.css"&gt;
    <style type="text/css">
        body, html { font-family:helvetica,arial,sans-serif; font-size:90%; }
    </style>
    <style type="text/css">
        html, body { width: 100%; height: 100%; margin: 0; } #borderContainer
        { width: 100%; height: 100%; }
    </style>
</head>

<body class="tundra ">
    <div dojoType="dijit.layout.BorderContainer" design="sidebar" gutters="true"
    liveSplitters="true" id="borderContainer">
        <div dojoType="dijit.layout.ContentPane" splitter="true" region="leading"
        style="width: 100px;">
            Hi
        </div>
        <div dojoType="dijit.layout.ContentPane" splitter="true" region="center">
            Hi, I'm center
        </div>
    </div>
</body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojo/dojo.xd.js"
djConfig="parseOnLoad: true">
</script>
<script type="text/javascript">
    dojo.require("dijit.layout.ContentPane");
    dojo.require("dijit.layout.BorderContainer");
</script>
<!-- NOTE: the following script tag is not intended for usage in real
world!! it is part of the CodeGlass and you should just remove it when
you use the code -->
<script type="text/javascript">
    dojo.addOnLoad(function() {
        if (window.pub) {
            window.pub();
        }
    });
</script>

A: 

This looks a bit upside down : you should put your javascripts in the head section and load the dojo libraries in first place. That's not your problem though.

What happens is that when the page loads, dojo loads all the modules that you "dojo.require", then parses all your tags containing the attribute "dojoType" and processes them for rendering, and this takes time.

So the flickering that you're seeing is the difference between the page before and after the widgets are parsed.

You should add a preloader div and hide it once the page is parsed (see this example).

This is what it would look like for your example :

<html>
    <head>

        <title>Preloader example</title>

        <!– every Dijit component needs a theme –>
        <link rel="stylesheet"
                href="http://o.aolcdn.com/dojo/1.4/dijit/themes/soria/soria.css"&gt;
        <style type="text/css">
                #preloader,
                body, html {
                        width:100%; height:100%; margin:0; padding:0;
                }
               #preloader {
                                  width:100%; height:100%; margin:0; padding:0;
                                  background:#fff
                                    url(’http://search.nj.com/media/images/loading.gif’)
                                    no-repeat center center;
                                    position:absolute;
                                    z-index:999;
                                }
                #borderContainer {
                        width:100%; height:100%;
                }


        </style>

        <!– load Dojo, and all the required modules –>
        <script src="http://o.aolcdn.com/dojo/1.4/dojo/dojo.xd.js"&gt;&lt;/script&gt;
        <script type="text/javascript">
                var hideLoader = function(){
                                dojo.fadeOut({
                                        node:"preloader",
                                        onEnd: function(){
                                                dojo.style("preloader", "display", "none");
                                        }
                                }).play();
                        }
                        dojo.addOnLoad(function(){
                                // after page load, load more stuff (spinner is already spinning)
                                dojo.require("dijit.layout.BorderContainer");
                                dojo.require("dijit.layout.ContentPane");
                                dojo.require("dojo.parser");

                                // notice the second onLoad here:
                                dojo.addOnLoad(function(){
                                        dojo.parser.parse();
                                        hideLoader();
                                });
                        });

        </script>
    </head>
    <body class="soria">
        <div id="preloader"></div>
        <div dojoType="dijit.layout.BorderContainer" id="borderContainer" design="sidebar" gutters="true" liveSplitters="true">
                <div dojoType="dijit.layout.ContentPane" splitter="true" region="leading" style="width: 100px;">Hi</div>
                <div dojoType="dijit.layout.ContentPane" splitter="true" region="center">I'm Center</div>
        </div>
    </body>
</html>
Philippe
A: 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojo/dojo.xd.js"&gt;&lt;/script&gt;

if(dojo.isIE){
    addEvent(window, 'load', function(event) {
        dojo.parser.parse();
    });
}else{
    dojo.addOnLoad(function(){
        dojo.addOnLoad(function(){
            dojo.parser.parse();
        });
    });
}
function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}

disable parseOnLoad and manually add event to parse widgets for ie.

coolnalu
A: 

coolnalu's script to manually load widgets for IE worked great!

nightynate