Creating a Message

As we just discussed, there are three different message types that we can create within a gadget, each of which has its own specific expiration criteria. Let’s go over them in more depth.

Dismissible messages

The dismissible message window is a standard alert that, if it’s not programmatically set to close, requires the user to interact with the window dismiss controls (generally an “x” in the top-right corner) to close it. These messages are generally developed to alert the user of changes within the gadget—such as new messages for her, or profile detail changes requesting an accept or cancel action from her.

We can create a dismissible mini-message simply by following the requirements described previously:

<Module title="Gadget to display a mini-message">
   <ModulePrefs>
      <Require feature="minimessage" />
   </ModulePrefs>
   <Content view="canvas">
      <![CDATA[
      <div id="msgDisplay"></div>

      <script type="text/javascript">
      //message dismissal callback
      function msgCallback(){
         document.getElementById("msgDisplay").innerHTML = "Message window closed";
      }

      //create new dismissible mini-message
      var message = new gadgets.MiniMessage(__MODULE_ID__);
      message.createDismissibleMessage("My dismissible mini-message", msgCallback);
      </script>
      ]]>
   </Content>
</Module>

We add in our Require element to enable the minimessage JavaScript ...

Get Programming Social Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.