Document id
Libbrowser.js -- class for Browser information
Libdata.js -- class of data manipulation and validation methods
Libdebug.js -- class for debugging methods and function
Libdynel.js -- Dynamic elements library
Liberror.js -- class for handling errors
Libevent.ja -- class of event manipulation methods
Libtime-bmt.js -- Biel Mean Time, Internet @time class
Libxml.js -- class for XML DOM and XSLT handling
$Id: js-tools.txt,v 1.6 2004/04/05 08:35:29 jaalto Exp $
This page contains manual pages from each Javascript (*.js) classs file. in alphabetical order. The tools started while doing a web research and fromt he need to handle XML somehow in the Web page. It turned out that Microsoft's ActiveX objects could read and manipulate XML DOM as laid out in W3C standard (Xlink, XPath, XPointer, XSL, XSLT).
Brief overview
There are several OO class packages to choose which you can plug into your web page. The selection and the features may be modest at the time of writing, but that's always so with pre-Alpha stage. Have patience and suggest code snippets to be included in the libraries and the features will grow.Generated documentation
This document is automatically generated from the Emacs lisp files with 2 small perl scripts: ripdoc.pl is available at http://cpan.perl.org/modules/by-authors/id/J/JA/JARIAALTO/ and the other is hosted at http://perl-text2html.sourceforge.net/
% ripdoc.pl `ls lib*.js|sort` | t2html.pl > js-tools.html
File id
Copyright: © 2002 Jari Aalto
Created: 2002-09-11
Keywords: www, html, javascript, object oriented class
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
http://www.gnu.org/copyleft/gpl.html
Install intructions
Include code via standard SCRIPT property:
src="libbrowser.js"Here is example after the library has been loaded:
var type = new LibBrowser(); if ( type.IE ) { // This is Internet explorer if ( type.version < 4 ) { alert( "Too old Browser" + type.version ); } }Available class attributes
- Mozilla boolean
- IE boolean
- info string, everything known about navigator
- version integer, browser version.
- jsversion string, javascript version, like "1.4"
Available methods
- Require(version,suppress,msg) Require browser VERSION. If SUPPRESS is true, discard any future errors by resetting window.onerror. If MESSAGE is true, notify user.
File id
Copyright: © 2002 Jari Aalto
Created: 2002-09-11
Keywords: www, html, javascript, object oriented class
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
http://www.gnu.org/copyleft/gpl.html
Install intructions
Include code via standard SCRIPT property:
src="libdata.js"Here is example code to demontrate the class in action:
var url = prompt('Enter URL','http://'); if ( ! isUrl(url) ) { alert( "URL not recognized. Please check. " + url); }Available class attributes
- error. Not yet used.
Available methods
Validation methods
- isNonZero(nbr) Check if NBR is non-zero. This can be used to check if input is a number.
- isNumber(str) Check that string contains only numbers.
- isNumberRange(val,low,high) Check that VAL is between LOW and HIGHT inclusive.
- isEmpty(str) Check if STR is empty, contains only whitespaces if if it number 0 or 0.0.
- isEmail(str) Check if the STR looks like email address.
- `isUrl(url, protocol)' Check that URL looks like URL and includes PROTOCOL (http:// or other access method).
Manipulation methods
- round(value,precision) Cut decimal number to PRECISION deciaml digits.
- trim(str) Remove whitespace from the beginning and end of string.
- convertCelciusFahrenheit(number,degreeC) convert between Celsius and Fahrenheit temperatures.
File id
Copyright: © 2002 Jari Aalto
Created: 2002-09-11
Keywords: www, html, javascript, object oriented class
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
http://www.gnu.org/copyleft/gpl.html
Install intructions
Include code via standard SCRIPT property:
src="libdebug.js"Here is example of the class in action:
debug = new LibDebug(); debug.level = 1; function myFunction(arg) { my id = "myFunction"; debug.writeln( id + " [INPUT] arg:" + arg ); my ret = arg * arg; debug.writeln( id + " [RETURN] arg:" + arg ); return ret; }Available class attributes
- level Set debug to LEVEL. If this is zero or null, then debug is not active.
Available methods
- write
- writeln
File id
Copyright: © 1996, 1997, 1998 O'Reilly & Associates.
Modifications 2002 Jari Aalto
From the origrinal DynEl.js file:
This example is from JavaScript: The Definitive Guide, 3rd Edition. That book and this example were Written by David Flanagan. They are Copyright (c) 1996, 1997, 1998 O'Reilly & Associates. This example is provided WITHOUT WARRANTY either expressed or implied. You may study, use, modify, and distribute it for any purpose, as long as this notice is retained.
Install intructions
Include code via standard SCRIPT property:
src="libdynel.js"Here is example of the class in action:
Available class attributes
- _eventmasks
Available methods
- output
- moveTo
- moveBy
- show
- hide
- setStackingOrder
- setBgColor
- setBgImage
- getX
- getY
- getWidth
- getHeight
- getStackingOrder
- setBody
- addEventHandler
- removeEventHandler
File id
Copyright: © 2002 Jari Aalto
Created: 2002-09-11
Keywords: www, html, javascript, object oriented class
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
http://www.gnu.org/copyleft/gpl.html
Install intructions
Include code via standard SCRIPT property:
src="liberror.js"Here is an example to demontrate the class in action:
var err = new LibError() function b() { window = null; // GENERATE ERROR } function a() { b(); } a();Here is output from separate window for the above error:
ERROR: Illegal assignment DOCUMENT: liberror.html LINE NUMBER: 14 BROWSER: appCodeName:Mozilla appMinorVersion:;Q321232; appName:Microsoft Internet Explorer appVersion:4.0 (compatible; MSIE 6.0; Windows NT 5.0; (R1 1.1)) cookieEnabled:true cpuClass:x86 mimeTypes:[object] onLine:true opsProfile:[object] platform:Win32 plugins:[object] systemLanguage:en-us userAgent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; (R1 1.1)) userLanguage:fi userProfile:[object] STACK TRACE: LibError.prototype.Report(msg, url, line) function b() function a()Description
It is hard to debug Javascript code, especially when the information displayed in the dialog cannot be saved easily. This class will open a new windows for every new error from where you can copy/paste any information.Due to restrictions in Javascript error data, the external file locations cannot be shown, for example when you include external code with:
<!-- inside file.html ---> <SCRIPT src="library.js"> // ... Whoops, error somewhere in library.js <SCRIPT>This error class would indicate error happening in file.html at line 100, when the error actually is inside library.js. It is unfortunate, but you usually can determine in which file the error is from the displayed call stack.
How to help to trace errors
The StackTrace() method can extract the function definition and call arguments of ewgular functions, but it cannot extract anonymous function information. This is simply because once the function has been created, Javascript does not maintain any "name" information. The function is anonymous. It will be quite hard to follow anonymous function call chains like
function(arg, str, me) function(obj, bool, this) ...Here is example to demntrate the problme with classes and their method definitions. The fuction "name" cannot be determined from these anonymous functions:
function MyClass() {} // Create OBJECT "MyClass" MyClass.method1 = function(arg1, arg2) // Anonymous function { alert( "MyClass.method1 called"); } alert( MyClass.method1 ) // You see "function(arg1, arg2)"If you want a more clear trace, define variable id into each method and function. Use this class definition instead:
Note: id variable must be the first variable definition in function.
function MyClass() {} // Create class OBJECT "MyClass" MyClass.method1 = function(arg1, arg2) { my id = "MyClass.method1"; // ADD THIS !! alert( id + " called"); } alert( MyClass.method1 ) // Now you see the ID variableIf you do this, define the id variable, this LibError class will automatically search the name of the function from that variable when the stack trace is printed. The search is done only if the function name would remain "anonymous".
Related links
- You can download Microsoft Javascript debugger at http://msdn.microsoft.com/scripting/debugger
File id
Copyright: © 2002 Jari Aalto
Created: 2002-09-11
Keywords: www, html, javascript, object oriented class
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
http://www.gnu.org/copyleft/gpl.html
Install intructions
Include code via standard SCRIPT property:
src="libevent.js"Here is example code to demontrate the class in action:
var ev = new LibEvent(); ev.rightClick("disable");Available class attributes
Available methods
File id
Copyright: © 2001-2004 Jari Aalto
Created: 2000-01-12
Keywords: www, html, javascript, object oriented class
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
http://www.gnu.org/copyleft/gpl.html
Install instructions
Include code via standard SCRIPT property:
src="libtime-bmt.js"Here is an example to demontrate the class in action:
var bmt = new LibTimeBMT(7000); // activate defaultStatus var bmtNow = bmt.time(); // time as decimal string var bmtString = bmt.timeString(); // time as stringDescription
This class implements Biel Mean Time (BMT) Internet @time clock. The Biel mean time is a universal way to indicate what is the current time, for any citizen around the world. Instaed of using and timezone + localtime, which causes one to compute the local time (like UTC+2 and 17:00), the BMT simply gives a value betbeen 0 .. 1000, which is the same for everyone.Let's say, you have a internation web page (your project, homepage) and you want to annoucne when you're available. You could say:
8.00 - 17.00 Pacific time"What", wonders the person around the other side of atlantic, or in the Japan. The issue is, that whaterver time you may annoucne, it cannot be grapsed to any other that to your local people. Others are forced to calculate what the time is on their local timezone. On the other hand, if you announce:
I'm on-line usually @300 .. @500That time is immediately clear to everyone who uses a BTM clock on their computer. Have a look at resources:
By loading this Javascrit class, the BMT time is autmatically displayed at the bottom of the browser; at the status bar. To incude the time to the HTML page the visitor entered, use this code:
document.write( bmt.time() );Available class attributes
NoneAvailable methods
- activate(interval) Start displaying BMT in status bar with INTERVAL milliseconds. The minimum interval is 1000.
- deactivate Stop displaying BMT time.
- time Return BMT time with two decimals. Number string "nnnn".
- timeString, same as time(), but with leading "@" as Internet time stamp "@nnnn.nn".
File id
Copyright: © 2002 Jari Aalto
Created: 2002-09-11
Keywords: www, html, javascript, object oriented class
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
http://www.gnu.org/copyleft/gpl.html
Install intructions
Include code via standard SCRIPT property:
src="libxml.js"Available class attributes
Available methods
Further reading
Much of the code is based on the articled listed below. Have a look:
This file has been automatically generated from plain text file
with Perl script t2html.pl v2005.0208
Last updated: 2005-04-01 09:19