home *** CD-ROM | disk | FTP | other *** search
/ ftp.swcp.com / ftp.swcp.com.zip / ftp.swcp.com / mac / mozilla-mac-0.9.sea.hqx / mozilla-mac-0.9 / res / strres-test.js < prev    next >
Text File  |  2001-05-05  |  4KB  |  133 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is Mozilla Communicator client code, released March
  14.  * 31, 1998.
  15.  *
  16.  * The Initial Developer of the Original Code is Netscape Communications
  17.  * Corporation. Portions created by Netscape are
  18.  * Copyright (C) 1998 Netscape Communications Corporation. All
  19.  * Rights Reserved.
  20.  *
  21.  * Contributor(s): 
  22.  */
  23.  
  24. var browser;
  25. var dialog;
  26.  
  27. function onLoad() {
  28.     dialog = new Object;
  29.     dialog.input     = document.getElementById( "dialog.input" );
  30.     dialog.ok        = document.getElementById( "dialog.ok" );
  31.     dialog.test        = document.getElementById( "dialog.test" );
  32.     dialog.testLabel        = document.getElementById( "dialog.testLabel" );
  33.     dialog.cancel    = document.getElementById( "dialog.cancel" );
  34.     dialog.help      = document.getElementById( "dialog.help" );
  35.     dialog.newWindow = document.getElementById( "dialog.newWindow" );
  36.  
  37.     browser = XPAppCoresManager.Find( window.arguments[0] );
  38.     if ( !browser ) {
  39.         dump( "unable to get browser app core\n" );
  40.         window.close();
  41.         return;
  42.     }
  43.  
  44.     /* Give input field the focus. */
  45.     dialog.input.focus();
  46. }
  47.  
  48. function onTyping( key ) {
  49.    // Look for enter key...
  50.    if ( key == 13 ) {
  51.       // If ok button not disabled, go for it.
  52.       if ( !dialog.ok.disabled ) {
  53.          open();
  54.       }
  55.    } else {
  56.       // Check for valid input.
  57.       if ( dialog.input.value == "" ) {
  58.          // No input, disable ok button if enabled.
  59.          if ( !dialog.ok.disabled ) {
  60.             dialog.ok.setAttribute( "disabled", "" );
  61.          }
  62.       } else {
  63.          // Input, enable ok button if disabled.
  64.          if ( dialog.ok.disabled ) {
  65.             dialog.ok.removeAttribute( "disabled" );
  66.          }
  67.       }
  68.    }
  69. }
  70.  
  71. function open() {
  72.    if ( dialog.ok.disabled ) {
  73.       return;
  74.    }
  75.  
  76.     var url = dialog.input.value;
  77.  
  78.     if ( !dialog.newWindow.checked ) {
  79.         /* Load url in opener. */
  80.         browser.loadUrl( url );
  81.     } else {
  82.         /* User wants new window. */
  83.         window.openDialog( "chrome:/navigator/content/", "_blank", "chrome,dialog=no,all", url );
  84.     }
  85.  
  86.     /* Close dialog. */
  87.     window.close();
  88. }
  89.  
  90. function choose() {
  91.     /* Use existing browser "open" logic. */
  92.     browser.openWindow();
  93.     window.close();
  94. }
  95.  
  96. function cancel() {
  97.     window.close();
  98. }
  99.  
  100. function help() {
  101.     if ( dialog.help.disabled ) {
  102.         return;
  103.     }
  104.     dump( "openLocation::help() not implemented\n" );
  105. }
  106.  
  107. function strresTest() {
  108.   var Bundle = srGetStrBundle("resource:/res/strres.properties");
  109.   var    ostr1 = Bundle.GetStringFromName("file");
  110.   dump("\n--** JS strBundle GetStringFromName file=" + ostr1 +
  111.       "len=" + ostr1.length + "**--\n");
  112.   var    ostr2 = Bundle.GetStringFromID(123);
  113.   dump("\n--** JS strBundle GetStringFromID 123=" + ostr2 + 
  114.       "len=" + ostr2.length + "**--\n");
  115.  
  116.   var    ostr3 = Bundle.GetStringFromName("loyal");
  117.   dump("\n--** JS strBundle GetStringFromName loyal=" + ostr3 + 
  118.        "len=" + ostr3.length + "**--\n");
  119.   
  120.   var    ostr4 = Bundle.GetStringFromName("trout");
  121.   dump("\n--** JS strBundle GetStringFromName eutf8=" + ostr4 +
  122.        "len=" + ostr4.length + "**--\n");
  123.   var    ostr5 = "\u88e6\ue3bb\u8b82"; /* µê╗πéï */
  124.   dump("\n--** JS strBundle GetStringFromName escaped=" + ostr5 +
  125.        "len=" + ostr5.length + "**--\n");
  126.  
  127.  
  128.   /* utf-8 \u9cdf\u9b5a */
  129.   dialog.ok.setAttribute("value", ostr2); 
  130.   dialog.test.setAttribute("value", ostr3); 
  131.   dialog.cancel.setAttribute("value", ostr4); 
  132. }
  133.