selfcontained[web development]

Articles tagged with "slikcalc" (4)

slikcalc 1.1 release

Thursday September 11, 2008
By Brad Harris

I've just released a new build of slikcalc - javascript calculator library that includes a few small bug fixes, and some shortcuts to the API. The new API for creating calculators looks as follows:

var columnCalc1 = slikcalc.create('column', {
    total: { id: 'cc-1-total' },
    registerListeners: true,
    calcOnLoad: true
});

as opposed to:

var columnCalc1 = new slikcalc.ColumnCalc({
    total: { id: 'cc-1-total' },
    registerListeners: true,
    calcOnLoad: true
});

Its a small change, but I think it's easier to use. Of course, the old way will still work, so existing code will not break with the addition to the API. Some other additions include a new, fully commented debug version of the code, along with using YUI compressor for the minified version, which shaved off a few kb from previous versions. Full documentation is also included in the download. Take a look and feel free to comment with any feedback.

Format Currency in Javascript (simplified)

Tuesday April 22, 2008
By Brad Harris

While working on slikcalc, I was trying to find the easiest way to format a number for currency. I had found some implementations that were pretty complex, using regex and absolute values, and thought there had to be a simpler way. This is what I came up with and it works in all the browsers I've tested (IE 6/7, Firefox 2 (windows & mac), Opera 9 (windows and mac).

function formatCurrency(num) {
    num = isNaN(num) || num === '' || num === null ? 0.00 : num;
    return parseFloat(num).toFixed(2);
}

Just thought I'd share for anyone working with something similar.

Slikcalc - Easy Javascript Calculations

Tuesday March 18, 2008
By Brad Harris

Slikcalc - Easy Javascript Calculations

I've put together a small javascript library that greatly simplifies creating dynamic javascript calculators. It works great for just about anything, ranging from calculating columns of values, to a complex custom formula. You can even write your own calculators and plug them into the framework with little effort. Calculations update automatically as the user types in their values.

Check out the details on the library, and download it from github

var columnCalc1 = new slikcalc.ColumnCalc({
    total: { id: 'cc-1-total' },
    registerListeners: true,
    calcOnLoad: true
});
columnCalc1.addRow({ id: 'cc-1-1' });
columnCalc1.addRow({ id: 'cc-1-2' });
columnCalc1.addRow({
    id: 'cc-1-3',
    checkbox: { id: 'cc-1-3-c' }
});

A few key features of Slikcalc:

  • Slikcalc works with popular Javascript libraries, including YUI, jQuery, Dojo, Mootools and Prototype. Adding support for new libraries is very simple as well.

  • Slikcalc handles attaching your event listeners for when the users type in values, click checkboxes, and when the page loads.

  • Slikcalc provides a simple interface for chaining multiple calculators so one can fire another, and so on.