Sunday, May 5, 2013

My first Dojo module!

define(["dojo/dom"], function(dom){
   return {
      myThing: function(id){
         var node = dom.byId(id);
         node.innerHTML = "Tom!"
      }
   };
});

 
 

What is above gets used as seen below. This is my own warping of the canned Hello Dojo tutorial. Below "dojo/tom" means "look in the dojo folder for tom.js" and above "dojo/dom" means "look in the dojo folder for dom.js." The word "Hello" below will get swapped out with "Tom!" That is all this does. I ran the HTML below through IIS under a fake subdomain I faked at the hosts file as the tutorial suggested that might be better than run trying to run an HTML file out of a folder standalone.

<!DOCTYPE html>
<html>
<head>
   <meta charset="utf-8">
   <title>Tutorial: Hello Dojo!</title>
</head>
<body>
   <h1 id="greeting">Hello</h1>
   <script src="/dojo/dojo.js" data-dojo-config="async: true"></script>
   <script>
      require(["dojo/tom"], function(myModule){
         myModule.myThing("greeting");
      });
   </script>
</body>
</html>

No comments:

Post a Comment