<?xml version="1.0" encoding="UTF-8"?>
<wiki>
  <body>&lt;p&gt;[[Sandals.js]] is the interface to [[BeachHouse]].&lt;/p&gt;
&lt;h1&gt;Global objects&lt;/h1&gt;
&lt;p&gt;Sandals creates a few global objects. One of them is &lt;code&gt;app&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;app&lt;/code&gt; object contains:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;code&gt;name&lt;/code&gt;, the name of the application window&lt;/li&gt;
	&lt;li&gt;&lt;code&gt;location&lt;/code&gt;, the location where the application is running&lt;/li&gt;
	&lt;li&gt;&lt;code&gt;started&lt;/code&gt;, tells us whether or not the application is running&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The other global object is &lt;code&gt;Sandals&lt;/code&gt; where the important Sandals functions and objects are stored.&lt;/p&gt;
&lt;h1&gt;Creating a Sandals.js Application&lt;/h1&gt;
&lt;p&gt;The following is a list of steps to create the starting point for a Sandals.js application.&lt;/p&gt;
&lt;p&gt;Load the Sandals.js interface file:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
    load(&amp;#8220;sandals.js&amp;#8221;);&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Use the JavaScript &lt;code&gt;with&lt;/code&gt; statement with the global &lt;code&gt;Sandals&lt;/code&gt; object&lt;sup class=&quot;footnote&quot;&gt;&lt;a href=&quot;#fn1&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
    with (Sandals) {&lt;br /&gt;
      // Next step goes here&lt;br /&gt;
    }&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;(&lt;a href=&quot;http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Statements:with&quot;&gt;Click here for information on the with statement&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;Within the body of the &lt;code&gt;with&lt;/code&gt; statement, call the &lt;code&gt;go&lt;/code&gt; function of the &lt;code&gt;Sandals&lt;/code&gt; object with a function as an argument.&lt;/p&gt;
&lt;p&gt;Whatever function you pass to &lt;code&gt;go&lt;/code&gt;, it should accept no arguments:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
    go(function () {&lt;br /&gt;
         // Next step goes here&lt;br /&gt;
       }&lt;br /&gt;
      );&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Write up the body of the function. In this function, you have access to the global &lt;code&gt;app&lt;/code&gt; object and any other variables in the global &lt;code&gt;Sandals&lt;/code&gt; object:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
    para(&amp;#8220;Woah, Sandals.js works!&amp;#8221;);&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The final result looks like this:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
    load(&amp;#8220;sandals.js&amp;#8221;);&lt;br /&gt;
    with (Sandals) {&lt;br /&gt;
    go(function () {&lt;br /&gt;
         para(&amp;#8220;Woah, Sandals.js works!&amp;#8221;);&lt;br /&gt;
       }&lt;br /&gt;
      );&lt;br /&gt;
    )&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;An alternative way of writing out this example application (it uses a global function and passes it to &lt;code&gt;Sandals.go&lt;/code&gt;.):&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
function para_test() {&lt;br /&gt;
  with (Sandals) {&lt;br /&gt;
    para(&amp;#8220;Woah, Sandals.js works!&amp;#8221;);&lt;br /&gt;
  }&lt;br /&gt;
  // The above with can be re-written as:&lt;br /&gt;
  // Sandals.para(&amp;#8220;Woah, Sandals.js works!&amp;#8221;);&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;load(&amp;#8220;sandals.js&amp;#8221;);&lt;br /&gt;
Sandals.go(para_test);&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;p class=&quot;footnote&quot; id=&quot;fn1&quot;&gt;&lt;sup&gt;1&lt;/sup&gt; The &lt;code&gt;with (Sandals) { ... }&lt;/code&gt; needs to be used with the &lt;code&gt;Sandals&lt;/code&gt; global object because it contains the toolkit functions. If you didn&amp;#8217;t use the &lt;code&gt;with&lt;/code&gt; and you wanted to create a paragraph with some inserted text you would have to write &lt;code&gt;Sandals.para(Sandals.ins(&quot;Inserted text&quot;), &quot;...more text&quot;)&lt;/code&gt;. If you &lt;strong&gt;really&lt;/strong&gt; want to, you can have Sandals turn all of its functions into global functions with the &lt;code&gt;Sandals_to_global&lt;/code&gt; function.&lt;/p&gt;</body>
  <created-at type="datetime">2008-07-25T16:08:59-07:00</created-at>
  <id type="integer">39630</id>
  <permalink>usingsandals-js</permalink>
  <repository-id type="integer">37072</repository-id>
  <title>UsingSandals.js</title>
  <updated-at type="datetime">2008-07-25T17:53:59-07:00</updated-at>
  <user-id type="integer">13960</user-id>
</wiki>
