weixin_33691598 2009-01-28 10:37 采纳率: 0%
浏览 57

Dojo“加载”消息

I'm new to Dojo, so I need a little help.

Some of my links takes a while (when the user clicks, it takes several seconds before the page starts loading), and I'd like to add a "loading"-message.

I can do it the "old fashion way", but I want to learn the new, easier, smarter Dojo-way.

Exactly how it works is not important right now, but I imagine something like this:

A rectangle appears in the middle of the browser-windows. (Not the middle of the document.) It has an animated gif, and a message like "Please wait...".

All other elements are disabled, maybe "faded out" a bit. Maybe a big white 50% transparent rectangle, which sits between the "loading"-message and the rest of the document.

  • 写回答

5条回答 默认 最新

  • weixin_33671935 2009-01-28 17:55
    关注

    What you are describing assumes that dojo itself has already been loaded by the time that the modal dijit.Dialog appears with the loading message.

    Now, normally, dojo starts executing once your page is fully loaded, and you would normally put your dojo code inside an anonymous function passed as parameter of dojo.addOnLoad().

    That entails that the remaining part of your page (what you call your "links") will have to be loaded through ajax (using, for instance, dijit.layout.ContentPane). That way, dojo can execute before the content is downloaded, and your "waiting" message can appear earlier.

    It might look like this:

    <html>
    
    <head>
    <link rel="stylesheet" href="/dojo/dijit/themes/tundra/tundra.css" type="text/css" media="screen" />
    <script type="text/javascript" src="/dojo/dojo.js" djConfig="parseOnLoad:true"></script>
    /* make sure that you shrinksafe together your libraries and dojo's for faster loading... */
    <script type="text/javascript" src="/dojo/yourOwnDojoCompressedScripts.js"></script>
    <script type="text/javascript">
       var dialog;
       dojo.addOnLoad(function(){
          dojo.require("dijit.layout.ContentPane");
          dojo.require("dijit.Dialog");
          dialog = new dijit.Dialog();
          dialog.setContent("<p>This page will be available in a tick!</p>");
          dialog.show();
       });
    </script>
    </head>
    
    <body class="tundra">
       <div id="delayedContent" 
            dojoType="dijit.layout.ContentPane" 
            href="/myContentUrl"
            onLoad="dialog.hide()">
       </div>
    </body>
    
    </html>
    

    The only flaw in that plan is dojo itself: expect your shrinksafed library to weigh over 90K (possibly up to 300K, depending on how much stuff you put in there). On a slow connection, that still takes a noticeable amount of time to download. That said, we're talking of a static 90K --- the same user will download it only once per session, and even less often than that if you take the time to set appropriate cache/expire headers when those static files are served.

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)