XML
  Home arrow XML arrow Page 2 - Back to XUL: JavaScript Logic
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Back to XUL: JavaScript Logic
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2006-02-06

    Table of Contents:
  • Back to XUL: JavaScript Logic
  • Scripting the Menubar: Close, Exit and New
  • Scripting the Menubar: Open
  • Scripting the Menubar: Save

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Back to XUL: JavaScript Logic - Scripting the Menubar: Close, Exit and New


    (Page 2 of 4 )

    Next we need to add the behavior to our menubar. We’ll go through the menus one at a time and script each menu action.  The File menu contains the Open and Save actions, both of which require a lot of effort and the use of XPCOM, so for the time being, we will leave these and come back to them later. 

    The first action we will script then is the Close action:

    function closeFile() {
      var editor = document.getElementById('mainContent');
      editor.setAttribute('src', 'about:blank');
    }

    Calling the window.close() method will close the whole application rather than just the currently open page, so we can set the src of the editor element to "about:blank," which will effectively generate a blank page.  The call to this function is added to the Close menuitem:

    oncommand="closeFile()"

    Next, we need to wire up the Exit action.  In the JavaScript file add:

    function closeApp() {
      window.close();
    }

    Then, to the Exit menuitem element add:

    oncommand="closeApp()"

    As you can see, this action is extremely simple; because we set the editor type as content-primary, we can treat it as the main window and simply call the window.close method to quit the whole application.

    The New menu contains a sub-menu giving the user a choice of new files.  We can cheat here to save time and effort by using a series of template files, one for each of the options.  To open a new XUL file, we just open (or re-open) the xul.txt file:

    function newXul() {
      var editor = document.getElementById('mainContent');
      editor.setAttribute('src', 'xul.txt');
    }

    Add the call to this function in the JavaScript file, and don’t forget to add the oncommand event handler:

    oncommand="newXul()"

    Similarly, the new HTML and new XML document menu actions are done under exactly the same premise:

    function newHtm() {
      var editor = document.getElementById('mainContent');
      editor.setAttribute('src', 'htm.txt');
    }
    function newXml() {
      var editor = document.getElementById('mainContent');
      editor.setAttribute('src', 'xml.txt');
    }
    function newRdf() {
      var editor = document.getElementById('mainContent');
      editor.setAttribute('src', 'rdf.txt');
    }

    You should be able to guess how and where to put the event handlers for these.  If not, each oncommand goes at the end of the menuitem that calls the required function:

    oncommand="newHtm()"
    oncommand="newXml()"
    oncommand="newRdf()"

    The text files used for these functions can just sit in the main content folder alongside the other interface files.  This is a great way to set up the new files because it gives you precise control over what appears in the new document, and saves on using lots of document.writeLn() methods to generate the template text.

    More XML Articles
    More By Dan Wellman


       · Hi everyone,This article is where things start to get interesting because it...
     

    XML ARTICLES

    - Datatypes and More in RELAX NG
    - Providing Options in RELAX NG
    - An Introduction to RELAX NG
    - Path, Predicates, and XQuery
    - Using Predicates with XQuery
    - Navigating Input Documents Using Paths
    - XML Basics
    - Introduction to XPath
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE
    - UI Design with Java and XML Toolkits
    - Displaying ADO Retrieved Data with XML Islan...
    - Widget Walkthrough
    - Introduction to Widgets
    - The Why and How of XML Data Islands






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT