Search code examples
javascriptdwr

how to customize dwr.util.useLoadingMessage() in DWR?


I have to customize the dwr.util.useLoadingMessage(), now it is coming in upper right corner with a red background. now i have to change this to middle of the screen.

i have googled it but couldn't get the exact solution thanks in advance.


Solution

  • I have customized it like this. downloaded and included the dwr util.js in the project and modified the loadingMessage like this

    dwr.util.useLoadingMessage = function(message) {
      var loadingMessage;
      if (message) loadingMessage = message;
      else loadingMessage = "Loading";
      dwr.engine.setPreHook(function() {
        var disabledZone = dwr.util.byId('disabledZone');
        if (!disabledZone) {
          disabledZone = document.createElement('div');
          disabledZone.setAttribute('id', 'disabledZone');
          disabledZone.style.position = "absolute";
          disabledZone.style.zIndex = "1005";
          disabledZone.style.left = "0px";
          disabledZone.style.top = "0px";
          disabledZone.style.width = "100%";
          disabledZone.style.height = "100%";
          // IE need a background color to block click. Use an invisible background.
          if (window.ActiveXObject) {
            disabledZone.style.background = "white";
            disabledZone.style.filter = "alpha(opacity=0)";
          }
          document.body.appendChild(disabledZone);
          var messageZone = document.createElement('div');
          messageZone.setAttribute('id', 'messageZone');
          messageZone.style.position = "absolute";
          messageZone.style.top = "350px";
          messageZone.style.right = "600px";
          messageZone.style.background = "red";
          messageZone.style.color = "white";
          messageZone.style.fontFamily = "Arial,Helvetica,sans-serif";
          messageZone.style.padding = "4px";
          messageZone.style.zIndex = "1005";
          document.body.appendChild(messageZone);
          var text = document.createTextNode(loadingMessage);
          messageZone.appendChild(text);
          dwr.util._disabledZoneUseCount = 1;
        }
        else {
          dwr.util.byId('messageZone').innerHTML = loadingMessage;
          disabledZone.style.visibility = 'visible';
          dwr.util._disabledZoneUseCount++;
          dwr.util.byId('messageZone').style.visibility = 'visible';
        }
      });
      dwr.engine.setPostHook(function() {
        dwr.util._disabledZoneUseCount--;
        if (dwr.util._disabledZoneUseCount == 0) {
          dwr.util.byId('disabledZone').style.visibility = 'hidden';
          dwr.util.byId('messageZone').style.visibility = 'hidden';
        }
      });
    };