JavaScript Libraries

The JavaScript libraries listed here are provided freely and may (and probably will) be modified. They are primarily examples of how to approach a problem, however, we do ask that if you use these libraries, or these ideas, that you refer to us in your documentation and notes.

Ajax

Required libraries

  • Cathmhaol.Event
  • Cathmhaol.Request
  • Cathmhaol.Response

Syntax

var oAjax = new Cathmhaol.Ajax([id]);

Previous Versions

Methods:

  • Cathmhaol.Request getRequest(integer index)
    Returns the Cathmhaol.Request object specified by the index. If no index is specified, the last Cathmhaol.Request is returned.
  • Cathmhaol.Response getResponse(integer index)
    Returns the Cathmhaol.Response object specified by the index. If no index is specified, the last Cathmhaol.Response is returned.
  • void send(string|node|Cathmhaol.Request resource, object[] elements, boolean async, string username, string password)
    Creates a Cathmhaol.Request object and sends it using the XmlHttpRequest object or the MSXML object.

Properties:

  • err
    The error object raised by the scripting engine.
    Type: error
  • id
    The unique identifier the object uses.
    Type: string
  • requests
    Array of requests.
    Type: Cathmhaol.Request[]
  • responses
    Array of responses.
    Type: Cathmhaol.Response[]
  • timeout
    The duration (in seconds) to wait for a response from the server.
    Type: float

Events:

  • exception
    Fired when a script exception occurs, populating the error object.
  • finished
    Fired when the timeout expires or a response is received.
  • error
    Fired when a the Cathmhaol.Response is ready and the HTTP status is not equal to 200.
  • loading
    Fired when a response is received and a Cathmhaol.Response object is being created.
  • ready
    Fired when the Cathmhaol.Response is ready and the HTTP status is equal to 200.
  • timedout
    Fired when the timeout expires.
  • waiting
    Fired when a request is sent.

Example

var oAJAX = new Cathmhaol.Ajax();
oAJAX.ready.listen( function() {
  document.write(oAJAX.getResponse().document);
  }
);

AjaxPool

Required libraries

  • Cathmhaol.Ajax

Syntax

var oAjax = new Cathmhaol.AjaxPool([numberOfConnections]);

Previous Versions

Methods:

  • void send(Cathmhaol.Request request, function callback, float wait)
    Queues a request and sends the request when the connection object is available.
    request
    The request to send.
    callback
    The JavaScript function to execute when the response returns.
    wait
    The number of seconds to wait before timeout.

Properties:

Events:

Example

var oConPool = new Cathmhaol.AjaxPool(); oConPool.send(oRequest, function(xhr) { /* handler for xhr.responseText */ }, .5);

Calendar

Required libraries

Syntax

Cathmhaol.Calendar;

Methods:

  • date dateAdd(Cathmhaol.Calendar.PERIOD interval, integer intervals, string|integer|date startDate)
    Returns a date that is the starting date with the specified number of intervals added. The interval must be one of the Cathmhaol.Calendar.PERIOD enumeration. The startDate may be a Date object or a string or integer that can be converted to a Date object. If a start date is not specified, the current system date is used.

    var d = Cathmhaol.Calendar.dateAdd(Cathmhaol.Calendar.MINUTE, 5, "1/1/1970 13:00:00"); // d = 1/1/1970 1:05:00 PM

  • float dateDiff(string interval, string|integer|date startDate, string|integer|date endDate)
    Returns a number of intervals between the starting date and the ending date. The interval must be one of the Cathmhaol.Calendar.PERIOD enumeration. The startDate and endDate may be a Date object or a string or integer that can be converted to a Date object. If a start date or an end date are not specified, the current system date is used.

    var d = Cathmhaol.Calendar.dateDiff(Cathmhaol.Calendar.MONTH, new Date(1970, 0, 1), "1/1/1971"); // d = 12

  • integer dayOfTheWeek(string|integer|date d)
    Returns an integer that represents the day of the week for the specified day. The specified day may be a Date object or a string or integer that can be converted to a Date object. If no date is specified, the current system date is used.

    var dow = Cathmhaol.Calendar.dayOfTheWeek(new Date(1970, 0, 1)); // dow = 4

  • integer daysInMonth(date d)
    Returns an integer that represents the number of days in the specified month. The specified day may be a Date object or a string or integer that can be converted to a Date object. If no date is specified, the current system date is used.

    var days = Cathmhaol.Calendar.daysInMonth(new Date(1970, 0, 1)); // days = 31

  • boolean isLeapYear(integer year)
    Returns true if the specified year contains a Leap Day.

    var bLeap = Cathmhaol.Calendar.isLeapYear(2008); // bLeap = true

  • boolean isSupportedLanguage(string languageCode)
    Returns true if the specified ISO 639-1 Alpha-3 language code is supported.

    var bSupported = Cathmhaol.Calendar.isSupportedLanguage("zh"); // bSupported = false

  • date ordinalDate(integer year, integer month, integer ordinalIndex, integer Weekday)
    Returns an ordinal date given a year, a zero-based month index, an ordinal index between 1 (first) and 5 (fifth), and a day of the week.

    var d = Cathmhaol.Calendar.ordinalDate(2008, 2, 5, Cathmhaol.Calendar.SUNDAY); // d = 30-MAR-08

  • string[] supportedLanguages()
    Returns a string array containing all the ISO 639-1 Alpha-3 language codes supported.

    var a = Cathmhaol.Calendar.supportedLanguages();

Properties:

  • DAYS
    An associative array containing day names objects. The key in the associative array is a language code (e.g. English is "en", Spanish is "es", and German is "de"). The member is an 7-member array containing a day name objects with a longName property and a shortName property.
  • FRIDAY
    Integer representing the day of the week, i.e. 5.
  • MONDAY
    Integer representing the day of the week, i.e. 1.
  • MONTHS
    An associative array containing month names. The key in the associative array is a language code (e.g. English is "en", Spanish is "es", and German is "de"). The member is an 12-member array containing month names.
  • PERIOD
    An enumeration consisting of
    • DAY
    • HOUR
    • MINUTE
    • MONTH
    • QUARTER
    • SECOND
    • WEEK
    • YEAR
    with each enumerated value possessing the properties code, abbreviation, and name.
  • SATURDAY
    Integer representing the day of the week, i.e. 6.
  • SUNDAY
    Integer representing the day of the week, i.e. 0.
  • THURSDAY
    Integer representing the day of the week, i.e. 4.
  • TUESDAY
    Integer representing the day of the week, i.e. 2.
  • WEDNESDAY
    Integer representing the day of the week, i.e. 3.

DateInput

Required libraries

  • Cathmhaol.Calendar

Syntax

var oDateInput = new Cathmhaol.DateInput(string|node htmlInput[, date value[, string|node helper[, string languageCode]]]);

Methods:

  • void close()
    Closes and destroys the DateInput object.

  • date getDate()
    Returns the date currently selected.

  • string getLanguageCode()
    Returns a string that contains the language code being used.

  • string[] getLanguageCodes()
    Returns an string array containing all the supported language codes. Supported language codes are limited to those supported in the Cathmhaol.Calendar object.

  • void setLanguageCode(string languageCode)
    Sets the language code in the Calendar object if the value passed in the languageCode is supported. The default value of the language code is "en".

    var oCalendar = new Cathmhaol.Calendar(new Date(2008, 1, 1));
    oCalendar.setLanguageCode("es");
    var lang = oCalendar.getLanguageCode(); // lang = "es"

  • void show(integer top, integer left)
    Displays the DateInput object at the specified coordinates.

Properties:

  • firstDay
    Integer representing the first day of the week, e.g. Cathmhaol.Calendar.SUNDAY.

Example

window.onload = function() {
  var oBirthdayHelp = new Cathmhaol.DateInput("birthday");
  var oAnniversaryHelp = new Cathmhaol.DateInput("anniversary", "1/1/1970");
  var oDateHelp = new Cathmhaol.DateInput("birthday", "", '<img src="http://www.cathmhaol.com/images/calendar.gif">');
}

A full-page, basic example can be found here.

Email

Required libraries

Syntax

var oEmail = new Cathmhaol.Email();

Methods:

  • void addRecipient(emailAddress)
    Adds the email address to the list of recipients.
  • string getRecipients()
    Returns the list of recipients as a semi-colon separated string (e.g. info@mailinator.com;moreinfo@mailinator.com).
  • void send()
    Opens the email in the installed email client using a mailto link.

Properties:

  • body
    The body of the email.
    Type: String
  • subject
    The subject of the email.
    Type: String

Example

var oEmail = new Cathmhaol.Email();
oEmail.addRecipient("info@mailinator.com");
oEmail.addRecipient("spoof@mailinator.com");
oEmail.body = "This is a test";
oEmail.subject = "Test";
oEmail.send();

Error

Required libraries

Syntax

var oDebug = new Cathmhaol.Error();

Methods:

  • void clear()
    Sets the description and source to empty strings and the errNumber to 0.
  • void raise(object err, string source, integer errorNumber)
    Sets the description to the description of the err object, the source, and the errorNumber.
  • void show()
    Shows the current error.

Properties:

  • description
    The string representing the description given for the error raised.
    Type: String
  • errNumber
    The number assigned to the error raised.
    Type: Number
  • source
    The string description of the source of the error raised.
    Type: String

Example

this._oErr = new Cathmhaol.Error();

...

this._oErr.description = "Unable to open connection";
this._oErr.errNumber = -1;
this._oErr.source = "AJAX request";
this._oErr.show();

EventHandler

Required libraries

Syntax

var oEventHandler = new Cathmhaol.EventHandler();

Methods:

  • void add(iNode object, string eventType, object eventHandler)
    Adds the JavaScript function or command string passed in eventHandler to the DOM node passed as the object for the eventType.

Properties:

Example

var BEHAVIOR = new Cathmhaol.EventHandler();
BEHAVIOR.add(window, "load", window_onload);

var BEHAVIOR = new Cathmhaol.EventHandler();
BEHAVIOR.add(oNode, "blur", "alert('Hello world!');");

Event

Required libraries

Syntax

var event = new Cathmhaol.Event();

Methods:

  • void subscribe(function handler[, object scope[, boolean adjust]])
    Adds the JavaScript function as a handler when the event is triggered.
  • void trigger([variant args])
    Triggers the events and passes the provided arguments (optional) into the handlers.
  • void unsubscribe()
    Removes all handlers from the event.

Properties:

Example

myobject = function() {
};
myobject.prototype = {
  aborted: new Cathmhaol.Event(),
  _stateChange: function(newState) {
    if (newState == "aborted") {
      this.aborted.trigger();
    }
  }
};

var o = new myobject();
o.aborted.subscribe(function() {
    alert("Oops! We aborted.");
  }, o, true);

Financial

Required libraries

Syntax

Cathmhaol.Financial;

Methods:

  • object[] amortize(float principal, float apr, integer years, boolean balloonPayment)
    Returns an array that contains the amortization schedule for a given amount with a given annual percentage rate over a period of years. The array contains a Amortization Payment object with the properties payment, principal, interest, and balance. The balance is computed after the payment.
  • integer breakEvenPoint(float fixedCost, float sellingPrice, float variableCost)
    Returns the number of units that must be sold at the specified selling price given the fixed cost and variable cost associated with production and sale of the units.
  • float compoundInterest(float principal, float apr, integer periods)
    Returns the amount of interest compounded on the princicpal given the interest rate and the number of periods.
  • string formatDecimal(float amount, integer precision)
    Formats a float to the specified precision and returns a string
    var s = Cathmhaol.Financial.formatDecimal(1000, 2) // s = "1000.00"
  • float futureValue(float payment, float apr, integer numberOfPayments)
    Returns the future value of periodic payments given the amount of the payment, the rate of interest, and the number of payments.
  • float mean(float[] data)
    Returns the mean of the values presented in the data collection.
  • float median(float[] data)
    Returns the median of the values presented in the data collection, or the value that falls directly between the highest and lowest values.
  • string ruleOfSeventyTwo(float amount, boolean returnPercentage)
    Returns a string that will contain either the percentage or the number of years required to double your investment (e.g. "7%" or "7 years"). If bReturnPercentage is true, the result will be expressed as a percentage, otherwise, the result will be the number of years required.
  • float standardDeviation(float[] data)
    Returns the standard deviation of the values presented in the data collection.
  • float zScore(float earnings, float netSales, float marketValueOfEquity, float workingCapital, float retainedEarnings, float totalAssets, float totalLiabilities)
    Returns the Altman Z-Score that is used as a predictor of bankruptcy. A score of 2.99+ indicates business is sound, while a score between 1.81 and 2.98 indicates caution and 1.80 and below indicates that a business is in trouble.

Properties:

Example

/* calculate the amortization for a $7000 note with 6.75% interest for three years with a balloon payment */
var aAmortization = Cathmhaol.Financial.amortize(7000, 6.75, 3, true);

Gps

Required libraries

Syntax

Cathmhaol.Gps;

Methods:

  • double distance(Cathmhaol.Gps.Location start, Cathmhaol.Gps.Location stop)
    Returns the number of kilometers between the two coordinates.

    var d = Cathmhaol.Gps.distance(work, home); // d = 11.690123

  • double kilometers(double miles)
    Returns the number of kilometers for the specified number of miles.

    var d = Cathmhaol.Gps.kilometers(6.2); // d = 10

  • double miles(double kilometers)
    Returns the number of miles for the specified number of kilometers.

    var d = Cathmhaol.Gps.miles(10); // d = 6.2

Properties:

  • EARTH_RADIUS
    The estimated radius of the Earth at the equator.

Example

var oHome = new Cathmhaol.Gps.Location(new Cathmhaol.Gps.Latitude(33, 50, 40), new Cathmhaol.Gps.Longitude(-111, 50, 40));
var oWork = new Cathmhaol.Gps.Location(new Cathmhaol.Gps.Latitude(33, 59, 59), new Cathmhaol.Gps.Longitude(-111, 59, 59));
var commuteInMiles = Cathmhaol.Gps.miles(Cathmhaol.Gps.distance(oHome, oWork));

XhrWindow

Required libraries

Syntax

var oXhrWindow = new Cathmhaol.XhrWindow();

Methods:

  • void back()
    Displays the previous page in the modal window.
  • void cancel(xmlHttpRequest xhr)
    Cancels the process and closes the modal window. If executeFirst is true, the event is called before the modal window is closed, otherwise, the event is triggered after the modal window is closed.
  • void close()
    Destroys the modal window.
  • void end(xmlHttpRequest xhr)
    Ends the process and closes the modal window. If executeFirst is true, the event is called before the modal window is closed, otherwise, the event is triggered after the modal window is closed.
  • void forward()
    Displays the next page in the modal window.
  • void reset()
    Removes content from the header, body, buttons, and footer sections and hides the modal window.
  • void setBody(string html)
    Sets the content body.
  • void setButtons()
    Adds the buttons to the modal window.
  • void setContent(string header, string body, object[] buttons, string footer)
    Sets the content of the modal window. The buttons array should contain a "button" object that contains a DOM Node that is a button (with name, type, and value or innerHTML properties) and a handler that is a JavaScript function.
  • void setFooter(string html)
    Sets the content of the footer.
  • void setHeader(string html)
    Sets the content of the header.
  • void show()
    Shows the object
  • void start(node oForm)
    Starts the process using the specified form. Forms posted from within the modal window will also contain a CGI variable "post_type" that will contain the word "xhr_window". This CGI variable can then be evaluated in the query string or in the request object.

Properties:

  • allowClose
    Enables the close button
    Type: Boolean
    Default: true
  • allowPaging
    Enables the page back and page forward buttons.
    Type: Boolean
    Default: true
  • async
    Use XmlHttpRequest in asynchronous mode.
    Type: Boolean
    Default: true
  • backgroundColor
    The background color of the modal window. Uses CSS format.
    Type: String
    Default: #fff
  • border
    The border to give to the modal window. Uses CSS border property shorthand.
    Type: String
    Default: 1px solid #000
  • color
    Text color
    Type: String
    Default: #000
  • errorMessageTimeout
    The number of seconds to display the modal window when the XHR call fails.
    Type: Number
    Default: 5
  • executeFirst
    Boolean to indicate whether the function to be executed when the processes is ended should be executed before the modal window is closed.
    Type: Boolean
    Default: false
  • fontBody
    The font family to be used for the body of the modal window.
    Type: String
    Default: Times New Roman
  • fontFooter
    The font family to be used for the footer of the modal window.
    Type: String
    Default: Arial
  • fontHeader
    The font family to be used for the header of the modal window.
    Type: String
    Default: Arial
  • height
    The height of the panel. Height can be specified in pixels or as a percentage.
    Type: String
    Default: 400px
  • id
    The id of the panel
    Type: String
  • left
    The left border of the modal window
    Type: String
  • onCancel
    Event handler to call when canceling.
    Type: Function
  • onEnd
    Event handler to call when ending.
    Type: Function
  • onFail
    Event handler to call when when the XHR fails.
    Type: Function
  • padding
    Internal padding of the modal window. Uses CSS format.
    Type: String
    Default: 10px
  • timeout
    The number of milliseconds to wait for a response.
    Type: Number
  • top
    The top border of the modal window. Uses CSS format.
    Type: String
    Default: 100px
  • width
    The width of the panel. Width can be specified in pixels or as a percentage.
    Type: String
    Default: 400px

Example

function oForm_onSubmit() {
  var oForm = document.getElementById("frmMain");
  var oPanel = new Cathmhaol.XhrWindow();
  oPanel.onCancel = function() { alert("Canceling"); }
  oPanel.onEnd = function() { alert("Ending"); }
  oPanel.onFail = function() { alert("Error"); }
  oPanel.start(oForm);
  return false;
}

A full-page, basic example can be found here.