Skip to content

Instantly share code, notes, and snippets.

onDataReturnInitializeTable : function(sRequest, oResponse, oPayload) {
if((this instanceof DT) && this._sId) {
this.initializeTable();
this.onDataReturnSetRows(sRequest,oResponse,oPayload);
}
}
function format_number(n,prec,dec,sep) {
// Original by Luke Smith (http://lucassmith.name)
n = !isFinite(+n) ? 0 : +n;
prec = !isFinite(+prec) ? 2 : Math.abs(prec);
sep = sep == undefined ? ',' : sep;
var s = n.toFixed(prec),
abs = Math.abs(n).toFixed(prec),
_, i;
@lsmith
lsmith / typeof.js
Created January 16, 2009 16:53
JavaScript function to serve as a replacement for native typeof that returns more useful values. Example usage page at http://lucassmith.name/pub/typeof.html
var _toS = Object.prototype.toString,
_types = {
'undefined' : 'undefined',
'number' : 'number',
'boolean' : 'boolean',
'string' : 'string',
'[object Function]' : 'function',
'[object RegExp]' : 'regexp',
'[object Array]' : 'array',
'[object Date]' : 'date',
// Use case:
var myDataTable = new YAHOO.widget.DataTable(id,cols,source,{
paginator : YAHOO.foo.createPaginator({ containers : "bar" })
});
// Method definition
YAHOO.namespace('foo').createPaginator = function (cfg) {
return new YAHOO.widget.Paginator(
// Merge configuration from cfg into some defaults
YAHOO.lang.merge({
/**
* Takes a native JavaScript Number and formats to string for display to user.
*
* @method format
* @param nData {Number} Number.
* @param oConfig {Object} (Optional) Optional configuration values:
* <dl>
* <dt>prefix {String}</dd>
* <dd>String prepended before each number, like a currency designator "$"</dd>
* <dt>decimalPlaces {Number}</dd>
YAHOO.widget.Slider.prototype.setStartSliderState = function() {
this.logger.log("Fixing state");
this.setThumbCenterPoint();
this.baselinePos = getXY(this.getEl());
this.thumb.startOffset = this.thumb.getOffsetFromParent(this.baselinePos);
// Declare the DS config during construction. Also leverage the inline override
// support to replace the DS native setInterval implementation with a custom function
// that takes a function ref to generate the url sent
var ds = new YAHOO.util.DataSource(url, {
responseType : YAHOO.util.DataSource.TYPE_JSON,
responseSchema : {
resultsList : 'Results',
fields : [ 'foo','bar','baz' ],
},
setInterval : unction(ms, reqBuilder, callback) {
function formatNumber(n) {
if (!isFinite(n)) {
return n;
}
var s = ""+n, abs = Math.abs(n), _, i;
if (abs >= 1000) {
_ = (""+abs).split(/\./);
i = _[0].length % 3 || 3;
// Converts the content inside <script src="script2style.js">YOUR CSS</script>
// into a style block that will only be applied if js is turned on
(function () {
var d = document,
scripts = d.getElementsByTagName('script'),
me = scripts[scripts.length - 1],
head = d.getElementsByTagName('head')[0],
content = me.innerHTML.replace(/@import\((.*?)\);?/m,function (m,href) {
// Adds n weekdays to Date d. Weekdays are Mon-Fri. Holidays are not accounted for.
// Adding 0 days to a weekend day will return Monday's Date.
function addWeekdays(d,n) {
d = new Date(d.getTime());
var day = d.getDay();
d.setDate(
d.getDate() + n +
(day === 6 ? 2 : +!day) +