* @before $.metadata.setType("elem", "script")
* @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
* @desc Reads metadata from a nested script element
*
* @param String type The encoding type
* @param String name The name of the attribute to be used to get metadata (optional)
* @cat Plugins/Metadata
* @descr Sets the type of encoding to be used when loading metadata for the first time
* @type undefined
* @see metadata()
*/
(function($) {
$.extend({
metadata : {
defaults : {
type: 'class',
name: 'metadata',
cre: /({.*})/,
single: 'metadata'
},
setType: function( type, name ){
this.defaults.type = type;
this.defaults.name = name;
},
get: function( elem, opts ){
var settings = $.extend({},this.defaults,opts);
// check for empty string in single property
if ( !settings.single.length ) settings.single = 'metadata';
var data = $.data(elem, settings.single);
// returned cached data if it already exists
if ( data ) return data;
data = "{}";
if ( settings.type == "class" ) {
var m = settings.cre.exec( elem.className );
if ( m )
data = m[1];
} else if ( settings.type == "elem" ) {
if( !elem.getElementsByTagName )
return undefined;
var e = elem.getElementsByTagName(settings.name);
if ( e.length )
data = $.trim(e[0].innerHTML);
} else if ( elem.getAttribute != undefined ) {
var attr = elem.getAttribute( settings.name );
if ( attr )
data = attr;
}
if ( data.indexOf( '{' ) <0 )
data = "{" + data + "}";
data = eval("(" + data + ")");
$.data( elem, settings.single, data );
return data;
}
}
});
/**
* Returns the metadata object for the first member of the jQuery object.
*
* @name metadata
* @descr Returns element's metadata object
* @param Object opts An object contianing settings to override the defaults
* @type jQuery
* @cat Plugins/Metadata
*/
$.fn.metadata = function( opts ){
return $.metadata.get( this[0], opts );
};
})(jQuery);/*
* File: jquery.dataTables.js
* Version: 1.7.5
* Description: Paginate, search and sort HTML tables
* Author: Allan Jardine (www.sprymedia.co.uk)
* Created: 28/3/2008
* Language: Javascript
* License: GPL v2 or BSD 3 point style
* Project: Mtaala
* Contact: allan.jardine@sprymedia.co.uk
*
* Copyright 2008-2010 Allan Jardine, all rights reserved.
*
* This source file is free software, under either the GPL v2 license or a
* BSD style license, as supplied with this software.
*
* This source file 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 license files for details.
*
* For details please refer to: http://www.datatables.net
*/
/*
* When considering jsLint, we need to allow eval() as it it is used for reading cookies and
* building the dynamic multi-column sort functions.
*/
/*jslint evil: true, undef: true, browser: true */
/*globals $, jQuery,_fnExternApiFunc,_fnInitalise,_fnInitComplete,_fnLanguageProcess,_fnAddColumn,_fnColumnOptions,_fnAddData,_fnGatherData,_fnDrawHead,_fnDraw,_fnReDraw,_fnAjaxUpdate,_fnAjaxUpdateDraw,_fnAddOptionsHtml,_fnFeatureHtmlTable,_fnScrollDraw,_fnAjustColumnSizing,_fnFeatureHtmlFilter,_fnFilterComplete,_fnFilterCustom,_fnFilterColumn,_fnFilter,_fnBuildSearchArray,_fnBuildSearchRow,_fnFilterCreateSearch,_fnDataToSearch,_fnSort,_fnSortAttachListener,_fnSortingClasses,_fnFeatureHtmlPaginate,_fnPageChange,_fnFeatureHtmlInfo,_fnUpdateInfo,_fnFeatureHtmlLength,_fnFeatureHtmlProcessing,_fnProcessingDisplay,_fnVisibleToColumnIndex,_fnColumnIndexToVisible,_fnNodeToDataIndex,_fnVisbleColumns,_fnCalculateEnd,_fnConvertToWidth,_fnCalculateColumnWidths,_fnScrollingWidthAdjust,_fnGetWidestNode,_fnGetMaxLenString,_fnStringToCss,_fnArrayCmp,_fnDetectType,_fnSettingsFromNode,_fnGetDataMaster,_fnGetTrNodes,_fnGetTdNodes,_fnEscapeRegex,_fnDeleteIndex,_fnReOrderIndex,_fnColumnOrdering,_fnLog,_fnClearTable,_fnSaveState,_fnLoadState,_fnCreateCookie,_fnReadCookie,_fnGetUniqueThs,_fnScrollBarWidth,_fnApplyToChildren,_fnMap*/
(function(jQuery, window, document) {
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Section - DataTables variables
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* Variable: dataTableSettings
* Purpose: Store the settings for each dataTables instance
* Scope: jQuery.fn
*/
jQuery.fn.dataTableSettings = [];
var _aoSettings = jQuery.fn.dataTableSettings; /* Short reference for fast internal lookup */
/*
* Variable: dataTableExt
* Purpose: Container for customisable parts of DataTables
* Scope: jQuery.fn
*/
jQuery.fn.dataTableExt = {};
var _oExt = jQuery.fn.dataTableExt;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Section - DataTables extensible objects
*
* The _oExt object is used to provide an area where user dfined plugins can be
* added to DataTables. The following properties of the object are used:
* oApi - Plug-in API functions
* aTypes - Auto-detection of types
* oSort - Sorting functions used by DataTables (based on the type)
* oPagination - Pagination functions for different input styles
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* Variable: sVersion
* Purpose: Version string for plug-ins to check compatibility
* Scope: jQuery.fn.dataTableExt
* Notes: Allowed format is a.b.c.d.e where:
* a:int, b:int, c:int, d:string(dev|beta), e:int. d and e are optional
*/
_oExt.sVersion = "1.7.5";
/*
* Variable: sErrMode
* Purpose: How should DataTables report an error. Can take the value 'alert' or 'throw'
* Scope: jQuery.fn.dataTableExt
*/
_oExt.sErrMode = "alert";
/*
* Variable: iApiIndex
* Purpose: Index for what 'this' index API functions should use
* Scope: jQuery.fn.dataTableExt
*/
_oExt.iApiIndex = 0;
/*
* Variable: oApi
* Purpose: Container for plugin API functions
* Scope: jQuery.fn.dataTableExt
*/
_oExt.oApi = { };
/*
* Variable: aFiltering
* Purpose: Container for plugin filtering functions
* Scope: jQuery.fn.dataTableExt
*/
_oExt.afnFiltering = [ ];
/*
* Variable: aoFeatures
* Purpose: Container for plugin function functions
* Scope: jQuery.fn.dataTableExt
* Notes: Array of objects with the following parameters:
* fnInit: Function for initialisation of Feature. Takes oSettings and returns node
* cFeature: Character that will be matched in sDom - case sensitive
* sFeature: Feature name - just for completeness :-)
*/
_oExt.aoFeatures = [ ];
/*
* Variable: ofnSearch
* Purpose: Container for custom filtering functions
* Scope: jQuery.fn.dataTableExt
* Notes: This is an object (the name should match the type) for custom filtering function,
* which can be used for live DOM checking or formatted text filtering
*/
_oExt.ofnSearch = { };
/*
* Variable: afnSortData
* Purpose: Container for custom sorting data source functions
* Scope: jQuery.fn.dataTableExt
* Notes: Array (associative) of functions which is run prior to a column of this
* 'SortDataType' being sorted upon.
* Function input parameters:
* object:oSettings- DataTables settings object
* int:iColumn - Target column number
* Return value: Array of data which exactly matched the full data set size for the column to
* be sorted upon
*/
_oExt.afnSortData = [ ];
/*
* Variable: oStdClasses
* Purpose: Storage for the various classes that DataTables uses
* Scope: jQuery.fn.dataTableExt
*/
_oExt.oStdClasses = {
/* Two buttons buttons */
"sPagePrevEnabled": "paginate_enabled_previous",
"sPagePrevDisabled": "paginate_disabled_previous",
"sPageNextEnabled": "paginate_enabled_next",
"sPageNextDisabled": "paginate_disabled_next",
"sPageJUINext": "",
"sPageJUIPrev": "",
/* Full numbers paging buttons */
"sPageButton": "paginate_button",
"sPageButtonActive": "paginate_active",
"sPageButtonStaticDisabled": "paginate_button",
"sPageFirst": "first",
"sPagePrevious": "previous",
"sPageNext": "next",
"sPageLast": "last",
/* Stripping classes */
"sStripOdd": "odd",
"sStripEven": "even",
/* Empty row */
"sRowEmpty": "dataTables_empty",
/* Features */
"sWrapper": "dataTables_wrapper",
"sFilter": "dataTables_filter",
"sInfo": "dataTables_info",
"sPaging": "dataTables_paginate paging_", /* Note that the type is postfixed */
"sLength": "dataTables_length",
"sProcessing": "dataTables_processing",
/* Sorting */
"sSortAsc": "sorting_asc",
"sSortDesc": "sorting_desc",
"sSortable": "sorting", /* Sortable in both directions */
"sSortableAsc": "sorting_asc_disabled",
"sSortableDesc": "sorting_desc_disabled",
"sSortableNone": "sorting_disabled",
"sSortColumn": "sorting_", /* Note that an int is postfixed for the sorting order */
"sSortJUIAsc": "",
"sSortJUIDesc": "",
"sSortJUI": "",
"sSortJUIAscAllowed": "",
"sSortJUIDescAllowed": "",
"sSortJUIWrapper": "",
/* Scrolling */
"sScrollWrapper": "dataTables_scroll",
"sScrollHead": "dataTables_scrollHead",
"sScrollHeadInner": "dataTables_scrollHeadInner",
"sScrollBody": "dataTables_scrollBody",
"sScrollFoot": "dataTables_scrollFoot",
"sScrollFootInner": "dataTables_scrollFootInner",
/* Misc */
"sFooterTH": ""
};
/*
* Variable: oJUIClasses
* Purpose: Storage for the various classes that DataTables uses - jQuery UI suitable
* Scope: jQuery.fn.dataTableExt
*/
_oExt.oJUIClasses = {
/* Two buttons buttons */
"sPagePrevEnabled": "fg-button ui-button ui-state-default ui-corner-left",
"sPagePrevDisabled": "fg-button ui-button ui-state-default ui-corner-left ui-state-disabled",
"sPageNextEnabled": "fg-button ui-button ui-state-default ui-corner-right",
"sPageNextDisabled": "fg-button ui-button ui-state-default ui-corner-right ui-state-disabled",
"sPageJUINext": "ui-icon ui-icon-circle-arrow-e",
"sPageJUIPrev": "ui-icon ui-icon-circle-arrow-w",
/* Full numbers paging buttons */
"sPageButton": "fg-button ui-button ui-state-default",
"sPageButtonActive": "fg-button ui-button ui-state-default ui-state-disabled",
"sPageButtonStaticDisabled": "fg-button ui-button ui-state-default ui-state-disabled",
"sPageFirst": "first ui-corner-tl ui-corner-bl",
"sPagePrevious": "previous",
"sPageNext": "next",
"sPageLast": "last ui-corner-tr ui-corner-br",
/* Stripping classes */
"sStripOdd": "odd",
"sStripEven": "even",
/* Empty row */
"sRowEmpty": "dataTables_empty",
/* Features */
"sWrapper": "dataTables_wrapper",
"sFilter": "dataTables_filter",
"sInfo": "dataTables_info",
"sPaging": "dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi "+
"ui-buttonset-multi paging_", /* Note that the type is postfixed */
"sLength": "dataTables_length",
"sProcessing": "dataTables_processing",
/* Sorting */
"sSortAsc": "ui-state-default",
"sSortDesc": "ui-state-default",
"sSortable": "ui-state-default",
"sSortableAsc": "ui-state-default",
"sSortableDesc": "ui-state-default",
"sSortableNone": "ui-state-default",
"sSortColumn": "sorting_", /* Note that an int is postfixed for the sorting order */
"sSortJUIAsc": "css_right ui-icon ui-icon-triangle-1-n",
"sSortJUIDesc": "css_right ui-icon ui-icon-triangle-1-s",
"sSortJUI": "css_right ui-icon ui-icon-carat-2-n-s",
"sSortJUIAscAllowed": "css_right ui-icon ui-icon-carat-1-n",
"sSortJUIDescAllowed": "css_right ui-icon ui-icon-carat-1-s",
"sSortJUIWrapper": "DataTables_sort_wrapper",
/* Scrolling */
"sScrollWrapper": "dataTables_scroll",
"sScrollHead": "dataTables_scrollHead ui-state-default",
"sScrollHeadInner": "dataTables_scrollHeadInner",
"sScrollBody": "dataTables_scrollBody",
"sScrollFoot": "dataTables_scrollFoot ui-state-default",
"sScrollFootInner": "dataTables_scrollFootInner",
/* Misc */
"sFooterTH": "ui-state-default"
};
/*
* Variable: oPagination
* Purpose: Container for the various type of pagination that dataTables supports
* Scope: jQuery.fn.dataTableExt
*/
_oExt.oPagination = {
/*
* Variable: two_button
* Purpose: Standard two button (forward/back) pagination
* Scope: jQuery.fn.dataTableExt.oPagination
*/
"two_button": {
/*
* Function: oPagination.two_button.fnInit
* Purpose: Initalise dom elements required for pagination with forward/back buttons only
* Returns: -
* Inputs: object:oSettings - dataTables settings object
* node:nPaging - the DIV which contains this pagination control
* function:fnCallbackDraw - draw function which must be called on update
*/
"fnInit": function ( oSettings, nPaging, fnCallbackDraw )
{
var nPrevious, nNext, nPreviousInner, nNextInner;
/* Store the next and previous elements in the oSettings object as they can be very
* usful for automation - particularly testing
*/
if ( !oSettings.bJUI )
{
nPrevious = document.createElement( 'div' );
nNext = document.createElement( 'div' );
}
else
{
nPrevious = document.createElement( 'a' );
nNext = document.createElement( 'a' );
nNextInner = document.createElement('span');
nNextInner.className = oSettings.oClasses.sPageJUINext;
nNext.appendChild( nNextInner );
nPreviousInner = document.createElement('span');
nPreviousInner.className = oSettings.oClasses.sPageJUIPrev;
nPrevious.appendChild( nPreviousInner );
}
nPrevious.className = oSettings.oClasses.sPagePrevDisabled;
nNext.className = oSettings.oClasses.sPageNextDisabled;
nPrevious.title = oSettings.oLanguage.oPaginate.sPrevious;
nNext.title = oSettings.oLanguage.oPaginate.sNext;
nPaging.appendChild( nPrevious );
nPaging.appendChild( nNext );
jQuery(nPrevious).click( function() {
if ( oSettings.oApi._fnPageChange( oSettings, "previous" ) )
{
/* Only draw when the page has actually changed */
fnCallbackDraw( oSettings );
}
} );
jQuery(nNext).click( function() {
if ( oSettings.oApi._fnPageChange( oSettings, "next" ) )
{
fnCallbackDraw( oSettings );
}
} );
/* Take the brutal approach to cancelling text selection */
jQuery(nPrevious).bind( 'selectstart', function () { return false; } );
jQuery(nNext).bind( 'selectstart', function () { return false; } );
/* ID the first elements only */
if ( oSettings.sTableId !== '' && typeof oSettings.aanFeatures.p == "undefined" )
{
nPaging.setAttribute( 'id', oSettings.sTableId+'_paginate' );
nPrevious.setAttribute( 'id', oSettings.sTableId+'_previous' );
nNext.setAttribute( 'id', oSettings.sTableId+'_next' );
}
},
/*
* Function: oPagination.two_button.fnUpdate
* Purpose: Update the two button pagination at the end of the draw
* Returns: -
* Inputs: object:oSettings - dataTables settings object
* function:fnCallbackDraw - draw function to call on page change
*/
"fnUpdate": function ( oSettings, fnCallbackDraw )
{
if ( !oSettings.aanFeatures.p )
{
return;
}
/* Loop over each instance of the pager */
var an = oSettings.aanFeatures.p;
for ( var i=0, iLen=an.length ; i= (iPages - iPageCountHalf))
{
iStartButton = iPages - iPageCount + 1;
iEndButton = iPages;
}
else
{
iStartButton = iCurrentPage - Math.ceil(iPageCount / 2) + 1;
iEndButton = iStartButton + iPageCount - 1;
}
}
}
/* Build the dynamic list */
for ( i=iStartButton ; i<=iEndButton ; i++ )
{
if ( iCurrentPage != i )
{
sList += ''+i+'';
}
else
{
sList += ''+i+'';
}
}
/* Loop over each instance of the pager */
var an = oSettings.aanFeatures.p;
var anButtons, anStatic, nPaginateList;
var fnClick = function() {
/* Use the information in the element to jump to the required page */
var iTarget = (this.innerHTML * 1) - 1;
oSettings._iDisplayStart = iTarget * oSettings._iDisplayLength;
fnCallbackDraw( oSettings );
return false;
};
var fnFalse = function () { return false; };
for ( i=0, iLen=an.length ; i y) ? 1 : 0));
},
"string-desc": function ( a, b )
{
var x = a.toLowerCase();
var y = b.toLowerCase();
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
},
/*
* html sorting (ignore html tags)
*/
"html-asc": function ( a, b )
{
var x = a.replace( /<.*?>/g, "" ).toLowerCase();
var y = b.replace( /<.*?>/g, "" ).toLowerCase();
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
},
"html-desc": function ( a, b )
{
var x = a.replace( /<.*?>/g, "" ).toLowerCase();
var y = b.replace( /<.*?>/g, "" ).toLowerCase();
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
},
/*
* date sorting
*/
"date-asc": function ( a, b )
{
var x = Date.parse( a );
var y = Date.parse( b );
if ( isNaN(x) || x==="" )
{
x = Date.parse( "01/01/1970 00:00:00" );
}
if ( isNaN(y) || y==="" )
{
y = Date.parse( "01/01/1970 00:00:00" );
}
return x - y;
},
"date-desc": function ( a, b )
{
var x = Date.parse( a );
var y = Date.parse( b );
if ( isNaN(x) || x==="" )
{
x = Date.parse( "01/01/1970 00:00:00" );
}
if ( isNaN(y) || y==="" )
{
y = Date.parse( "01/01/1970 00:00:00" );
}
return y - x;
},
/*
* numerical sorting
*/
"numeric-asc": function ( a, b )
{
var x = (a=="-" || a==="") ? 0 : a*1;
var y = (b=="-" || b==="") ? 0 : b*1;
return x - y;
},
"numeric-desc": function ( a, b )
{
var x = (a=="-" || a==="") ? 0 : a*1;
var y = (b=="-" || b==="") ? 0 : b*1;
return y - x;
}
};
/*
* Variable: aTypes
* Purpose: Container for the various type of type detection that dataTables supports
* Scope: jQuery.fn.dataTableExt
* Notes: The functions in this array are expected to parse a string to see if it is a data
* type that it recognises. If so then the function should return the name of the type (a
* corresponding sort function should be defined!), if the type is not recognised then the
* function should return null such that the parser and move on to check the next type.
* Note that ordering is important in this array - the functions are processed linearly,
* starting at index 0.
* Note that the input for these functions is always a string! It cannot be any other data
* type
*/
_oExt.aTypes = [
/*
* Function: -
* Purpose: Check to see if a string is numeric
* Returns: string:'numeric' or null
* Inputs: string:sText - string to check
*/
function ( sData )
{
/* Allow zero length strings as a number */
if ( sData.length === 0 )
{
return 'numeric';
}
var sValidFirstChars = "0123456789-";
var sValidChars = "0123456789.";
var Char;
var bDecimal = false;
/* Check for a valid first char (no period and allow negatives) */
Char = sData.charAt(0);
if (sValidFirstChars.indexOf(Char) == -1)
{
return null;
}
/* Check all the other characters are valid */
for ( var i=1 ; i') != -1 )
{
return 'html';
}
return null;
}
];
/*
* Function: fnVersionCheck
* Purpose: Check a version string against this version of DataTables. Useful for plug-ins
* Returns: bool:true -this version of DataTables is greater or equal to the required version
* false -this version of DataTales is not suitable
* Inputs: string:sVersion - the version to check against. May be in the following formats:
* "a", "a.b" or "a.b.c"
* Notes: This function will only check the first three parts of a version string. It is
* assumed that beta and dev versions will meet the requirements. This might change in future
*/
_oExt.fnVersionCheck = function( sVersion )
{
/* This is cheap, but very effective */
var fnZPad = function (Zpad, count)
{
while(Zpad.length < count) {
Zpad += '0';
}
return Zpad;
};
var aThis = _oExt.sVersion.split('.');
var aThat = sVersion.split('.');
var sThis = '', sThat = '';
for ( var i=0, iLen=aThat.length ; i= parseInt(sThat, 10);
};
/*
* Variable: _oExternConfig
* Purpose: Store information for DataTables to access globally about other instances
* Scope: jQuery.fn.dataTableExt
*/
_oExt._oExternConfig = {
/* int:iNextUnique - next unique number for an instance */
"iNextUnique": 0
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Section - DataTables prototype
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* Function: dataTable
* Purpose: DataTables information
* Returns: -
* Inputs: object:oInit - initalisation options for the table
*/
jQuery.fn.dataTable = function( oInit )
{
/*
* Function: classSettings
* Purpose: Settings container function for all 'class' properties which are required
* by dataTables
* Returns: -
* Inputs: -
*/
function classSettings ()
{
this.fnRecordsTotal = function ()
{
if ( this.oFeatures.bServerSide ) {
return parseInt(this._iRecordsTotal, 10);
} else {
return this.aiDisplayMaster.length;
}
};
this.fnRecordsDisplay = function ()
{
if ( this.oFeatures.bServerSide ) {
return parseInt(this._iRecordsDisplay, 10);
} else {
return this.aiDisplay.length;
}
};
this.fnDisplayEnd = function ()
{
if ( this.oFeatures.bServerSide ) {
if ( this.oFeatures.bPaginate === false || this._iDisplayLength == -1 ) {
return this._iDisplayStart+this.aiDisplay.length;
} else {
return Math.min( this._iDisplayStart+this._iDisplayLength,
this._iRecordsDisplay );
}
} else {
return this._iDisplayEnd;
}
};
/*
* Variable: oInstance
* Purpose: The DataTables object for this table
* Scope: jQuery.dataTable.classSettings
*/
this.oInstance = null;
/*
* Variable: sInstance
* Purpose: Unique idendifier for each instance of the DataTables object
* Scope: jQuery.dataTable.classSettings
*/
this.sInstance = null;
/*
* Variable: oFeatures
* Purpose: Indicate the enablement of key dataTable features
* Scope: jQuery.dataTable.classSettings
*/
this.oFeatures = {
"bPaginate": true,
"bLengthChange": true,
"bFilter": true,
"bSort": true,
"bInfo": true,
"bAutoWidth": true,
"bProcessing": false,
"bSortClasses": true,
"bStateSave": false,
"bServerSide": false
};
/*
* Variable: oScroll
* Purpose: Container for scrolling options
* Scope: jQuery.dataTable.classSettings
*/
this.oScroll = {
"sX": "",
"sXInner": "",
"sY": "",
"bCollapse": false,
"bInfinite": false,
"iLoadGap": 100,
"iBarWidth": 0,
"bAutoCss": true
};
/*
* Variable: aanFeatures
* Purpose: Array referencing the nodes which are used for the features
* Scope: jQuery.dataTable.classSettings
* Notes: The parameters of this object match what is allowed by sDom - i.e.
* 'l' - Length changing
* 'f' - Filtering input
* 't' - The table!
* 'i' - Information
* 'p' - Pagination
* 'r' - pRocessing
*/
this.aanFeatures = [];
/*
* Variable: oLanguage
* Purpose: Store the language strings used by dataTables
* Scope: jQuery.dataTable.classSettings
* Notes: The words in the format _VAR_ are variables which are dynamically replaced
* by javascript
*/
this.oLanguage = {
"sProcessing": "Processing...",
"sLengthMenu": IAJQGRIDLengthMenu,
"sZeroRecords": IAJQzerorecords,
"sEmptyTable": IAJQzerorecords,
"sInfo": IAJQGRIDrecordinfo,
"sInfoEmpty": IAJQzerorecords,
"sInfoFiltered": IAJQGRIDrecordfiltered,
"sInfoPostFix": "",
"sSearch": IAJQsearch,
"sUrl": "",
"oPaginate": {
"sFirst": "<<",
"sPrevious": "<",
"sNext": ">",
"sLast": ">>"
},
"fnInfoCallback": null
};
/*
* Variable: aoData
* Purpose: Store data information
* Scope: jQuery.dataTable.classSettings
* Notes: This is an array of objects with the following parameters:
* int: _iId - internal id for tracking
* array: _aData - internal data - used for sorting / filtering etc
* node: nTr - display node
* array node: _anHidden - hidden TD nodes
* string: _sRowStripe
*/
this.aoData = [];
/*
* Variable: aiDisplay
* Purpose: Array of indexes which are in the current display (after filtering etc)
* Scope: jQuery.dataTable.classSettings
*/
this.aiDisplay = [];
/*
* Variable: aiDisplayMaster
* Purpose: Array of indexes for display - no filtering
* Scope: jQuery.dataTable.classSettings
*/
this.aiDisplayMaster = [];
/*
* Variable: aoColumns
* Purpose: Store information about each column that is in use
* Scope: jQuery.dataTable.classSettings
*/
this.aoColumns = [];
/*
* Variable: iNextId
* Purpose: Store the next unique id to be used for a new row
* Scope: jQuery.dataTable.classSettings
*/
this.iNextId = 0;
/*
* Variable: asDataSearch
* Purpose: Search data array for regular expression searching
* Scope: jQuery.dataTable.classSettings
*/
this.asDataSearch = [];
/*
* Variable: oPreviousSearch
* Purpose: Store the previous search incase we want to force a re-search
* or compare the old search to a new one
* Scope: jQuery.dataTable.classSettings
*/
this.oPreviousSearch = {
"sSearch": "",
"bRegex": false,
"bSmart": true
};
/*
* Variable: aoPreSearchCols
* Purpose: Store the previous search for each column
* Scope: jQuery.dataTable.classSettings
*/
this.aoPreSearchCols = [];
/*
* Variable: aaSorting
* Purpose: Sorting information
* Scope: jQuery.dataTable.classSettings
* Notes: Index 0 - column number
* Index 1 - current sorting direction
* Index 2 - index of asSorting for this column
*/
this.aaSorting = [ [0, 'asc', 0] ];
/*
* Variable: aaSortingFixed
* Purpose: Sorting information that is always applied
* Scope: jQuery.dataTable.classSettings
*/
this.aaSortingFixed = null;
/*
* Variable: asStripClasses
* Purpose: Classes to use for the striping of a table
* Scope: jQuery.dataTable.classSettings
*/
this.asStripClasses = [];
/*
* Variable: asDestoryStrips
* Purpose: If restoring a table - we should restore it's striping classes as well
* Scope: jQuery.dataTable.classSettings
*/
this.asDestoryStrips = [];
/*
* Variable: sDestroyWidth
* Purpose: If restoring a table - we should restore it's width
* Scope: jQuery.dataTable.classSettings
*/
this.sDestroyWidth = 0;
/*
* Variable: fnRowCallback
* Purpose: Call this function every time a row is inserted (draw)
* Scope: jQuery.dataTable.classSettings
*/
this.fnRowCallback = null;
/*
* Variable: fnHeaderCallback
* Purpose: Callback function for the header on each draw
* Scope: jQuery.dataTable.classSettings
*/
this.fnHeaderCallback = null;
/*
* Variable: fnFooterCallback
* Purpose: Callback function for the footer on each draw
* Scope: jQuery.dataTable.classSettings
*/
this.fnFooterCallback = null;
/*
* Variable: aoDrawCallback
* Purpose: Array of callback functions for draw callback functions
* Scope: jQuery.dataTable.classSettings
* Notes: Each array element is an object with the following parameters:
* function:fn - function to call
* string:sName - name callback (feature). useful for arranging array
*/
this.aoDrawCallback = [];
/*
* Variable: fnInitComplete
* Purpose: Callback function for when the table has been initalised
* Scope: jQuery.dataTable.classSettings
*/
this.fnInitComplete = null;
/*
* Variable: sTableId
* Purpose: Cache the table ID for quick access
* Scope: jQuery.dataTable.classSettings
*/
this.sTableId = "";
/*
* Variable: nTable
* Purpose: Cache the table node for quick access
* Scope: jQuery.dataTable.classSettings
*/
this.nTable = null;
/*
* Variable: nTHead
* Purpose: Permanent ref to the thead element
* Scope: jQuery.dataTable.classSettings
*/
this.nTHead = null;
/*
* Variable: nTFoot
* Purpose: Permanent ref to the tfoot element - if it exists
* Scope: jQuery.dataTable.classSettings
*/
this.nTFoot = null;
/*
* Variable: nTBody
* Purpose: Permanent ref to the tbody element
* Scope: jQuery.dataTable.classSettings
*/
this.nTBody = null;
/*
* Variable: nTableWrapper
* Purpose: Cache the wrapper node (contains all DataTables controlled elements)
* Scope: jQuery.dataTable.classSettings
*/
this.nTableWrapper = null;
/*
* Variable: bInitialised
* Purpose: Indicate if all required information has been read in
* Scope: jQuery.dataTable.classSettings
*/
this.bInitialised = false;
/*
* Variable: aoOpenRows
* Purpose: Information about open rows
* Scope: jQuery.dataTable.classSettings
* Notes: Has the parameters 'nTr' and 'nParent'
*/
this.aoOpenRows = [];
/*
* Variable: sDom
* Purpose: Dictate the positioning that the created elements will take
* Scope: jQuery.dataTable.classSettings
* Notes:
* The following options are allowed:
* 'l' - Length changing
* 'f' - Filtering input
* 't' - The table!
* 'i' - Information
* 'p' - Pagination
* 'r' - pRocessing
* The following constants are allowed:
* 'H' - jQueryUI theme "header" classes
* 'F' - jQueryUI theme "footer" classes
* The following syntax is expected:
* '<' and '>' - div elements
* '<"class" and '>' - div with a class
* Examples:
* '<"wrapper"flipt>', 'ip>'
*/
this.sDom = 'lfrtip';
/*
* Variable: sPaginationType
* Purpose: Note which type of sorting should be used
* Scope: jQuery.dataTable.classSettings
*/
this.sPaginationType = "two_button";
/*
* Variable: iCookieDuration
* Purpose: The cookie duration (for bStateSave) in seconds - default 2 hours
* Scope: jQuery.dataTable.classSettings
*/
this.iCookieDuration = 60 * 60 * 2;
/*
* Variable: sCookiePrefix
* Purpose: The cookie name prefix
* Scope: jQuery.dataTable.classSettings
*/
this.sCookiePrefix = "SpryMedia_DataTables_";
/*
* Variable: fnCookieCallback
* Purpose: Callback function for cookie creation
* Scope: jQuery.dataTable.classSettings
*/
this.fnCookieCallback = null;
/*
* Variable: aoStateSave
* Purpose: Array of callback functions for state saving
* Scope: jQuery.dataTable.classSettings
* Notes: Each array element is an object with the following parameters:
* function:fn - function to call. Takes two parameters, oSettings and the JSON string to
* save that has been thus far created. Returns a JSON string to be inserted into a
* json object (i.e. '"param": [ 0, 1, 2]')
* string:sName - name of callback
*/
this.aoStateSave = [];
/*
* Variable: aoStateLoad
* Purpose: Array of callback functions for state loading
* Scope: jQuery.dataTable.classSettings
* Notes: Each array element is an object with the following parameters:
* function:fn - function to call. Takes two parameters, oSettings and the object stored.
* May return false to cancel state loading.
* string:sName - name of callback
*/
this.aoStateLoad = [];
/*
* Variable: oLoadedState
* Purpose: State that was loaded from the cookie. Useful for back reference
* Scope: jQuery.dataTable.classSettings
*/
this.oLoadedState = null;
/*
* Variable: sAjaxSource
* Purpose: Source url for AJAX data for the table
* Scope: jQuery.dataTable.classSettings
*/
this.sAjaxSource = null;
/*
* Variable: bAjaxDataGet
* Purpose: Note if draw should be blocked while getting data
* Scope: jQuery.dataTable.classSettings
*/
this.bAjaxDataGet = true;
/*
* Variable: fnServerData
* Purpose: Function to get the server-side data - can be overruled by the developer
* Scope: jQuery.dataTable.classSettings
*/
this.fnServerData = function ( url, data, callback ) {
jQuery.ajax( {
"url": url,
"data": data,
"success": callback,
"dataType": "json",
"cache": false,
"error": function (xhr, error, thrown) {
if ( error == "parsererror" ) {
alert( "DataTables warning: JSON data from server could not be parsed. "+
"This is caused by a JSON formatting error." );
}
}
} );
};
/*
* Variable: fnFormatNumber
* Purpose: Format numbers for display
* Scope: jQuery.dataTable.classSettings
*/
this.fnFormatNumber = function ( iIn )
{
if ( iIn < 1000 )
{
/* A small optimisation for what is likely to be the vast majority of use cases */
return iIn;
}
else
{
var s=(iIn+""), a=s.split(""), out="", iLen=s.length;
for ( var i=0 ; i= oSettings.aiDisplay.length )
{
oSettings._iDisplayStart -= oSettings._iDisplayLength;
if ( oSettings._iDisplayStart < 0 )
{
oSettings._iDisplayStart = 0;
}
}
if ( typeof bRedraw == 'undefined' || bRedraw )
{
_fnCalculateEnd( oSettings );
_fnDraw( oSettings );
}
return oData;
};
/*
* Function: fnClearTable
* Purpose: Quickly and simply clear a table
* Returns: -
* Inputs: bool:bRedraw - redraw the table or not - default true
* Notes: Thanks to Yekimov Denis for contributing the basis for this function!
*/
this.fnClearTable = function( bRedraw )
{
/* Find settings from table node */
var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
_fnClearTable( oSettings );
if ( typeof bRedraw == 'undefined' || bRedraw )
{
_fnDraw( oSettings );
}
};
/*
* Function: fnOpen
* Purpose: Open a display row (append a row after the row in question)
* Returns: node:nNewRow - the row opened
* Inputs: node:nTr - the table row to 'open'
* string:sHtml - the HTML to put into the row
* string:sClass - class to give the new TD cell
*/
this.fnOpen = function( nTr, sHtml, sClass )
{
/* Find settings from table node */
var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
/* the old open one if there is one */
this.fnClose( nTr );
var nNewRow = document.createElement("tr");
var nNewCell = document.createElement("td");
nNewRow.appendChild( nNewCell );
nNewCell.className = sClass;
nNewCell.colSpan = _fnVisbleColumns( oSettings );
nNewCell.innerHTML = sHtml;
/* If the nTr isn't on the page at the moment - then we don't insert at the moment */
var nTrs = jQuery('tr', oSettings.nTBody);
if ( jQuery.inArray(nTr, nTrs) != -1 )
{
jQuery(nNewRow).insertAfter(nTr);
}
oSettings.aoOpenRows.push( {
"nTr": nNewRow,
"nParent": nTr
} );
return nNewRow;
};
/*
* Function: fnClose
* Purpose: Close a display row
* Returns: int: 0 (success) or 1 (failed)
* Inputs: node:nTr - the table row to 'close'
*/
this.fnClose = function( nTr )
{
/* Find settings from table node */
var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
for ( var i=0 ; itr', oSettings.nTHead)[0];
var nTrFoot = jQuery('>tr', oSettings.nTFoot)[0];
var anTheadTh = [];
var anTfootTh = [];
for ( i=0 ; i= _fnVisbleColumns( oSettings ) )
{
nTrHead.appendChild( anTheadTh[iCol] );
anTrs = jQuery('>tr', oSettings.nTHead);
for ( i=1, iLen=anTrs.length ; itr', oSettings.nTFoot);
for ( i=1, iLen=anTrs.length ; itr', oSettings.nTHead);
for ( i=1, iLen=anTrs.length ; itr', oSettings.nTFoot);
for ( i=1, iLen=anTrs.length ; itd:eq('+iBefore+')',
oSettings.aoData[i].nTr)[0] );
}
}
oSettings.aoColumns[iCol].bVisible = true;
}
else
{
/* Remove a column from display */
nTrHead.removeChild( anTheadTh[iCol] );
for ( i=0, iLen=oSettings.aoColumns[iCol].anThExtra.length ; itr>td.'+oSettings.oClasses.sRowEmpty, oSettings.nTable).parent().remove();
/* When scrolling we had to break the table up - restore it */
if ( oSettings.nTable != oSettings.nTHead.parentNode )
{
jQuery('>thead', oSettings.nTable).remove();
oSettings.nTable.appendChild( oSettings.nTHead );
}
if ( oSettings.nTFoot && oSettings.nTable != oSettings.nTFoot.parentNode )
{
jQuery('>tfoot', oSettings.nTable).remove();
oSettings.nTable.appendChild( oSettings.nTFoot );
}
/* Remove the DataTables generated nodes, events and classes */
oSettings.nTable.parentNode.removeChild( oSettings.nTable );
jQuery(oSettings.nTableWrapper).remove();
oSettings.aaSorting = [];
oSettings.aaSortingFixed = [];
_fnSortingClasses( oSettings );
jQuery(_fnGetTrNodes( oSettings )).removeClass( oSettings.asStripClasses.join(' ') );
if ( !oSettings.bJUI )
{
jQuery('th', oSettings.nTHead).removeClass( [ _oExt.oStdClasses.sSortable,
_oExt.oStdClasses.sSortableAsc,
_oExt.oStdClasses.sSortableDesc,
_oExt.oStdClasses.sSortableNone ].join(' ')
);
}
else
{
jQuery('th', oSettings.nTHead).removeClass( [ _oExt.oStdClasses.sSortable,
_oExt.oJUIClasses.sSortableAsc,
_oExt.oJUIClasses.sSortableDesc,
_oExt.oJUIClasses.sSortableNone ].join(' ')
);
jQuery('th span', oSettings.nTHead).remove();
}
/* Add the TR elements back into the table in their original order */
nOrig.appendChild( oSettings.nTable );
for ( i=0, iLen=oSettings.aoData.length ; itr:even', nBody).addClass( oSettings.asDestoryStrips[0] );
jQuery('>tr:odd', nBody).addClass( oSettings.asDestoryStrips[1] );
/* Remove the settings object from the settings array */
for ( i=0, iLen=_aoSettings.length ; i=0 if successful (index of new aoData entry), -1 if failed
* Inputs: object:oSettings - dataTables settings object
* array:aData - data array to be added
* Notes: There are two basic methods for DataTables to get data to display - a JS array
* (which is dealt with by this function), and the DOM, which has it's own optimised
* function (_fnGatherData). Be careful to make the same changes here as there and vice-versa
*/
function _fnAddData ( oSettings, aDataSupplied )
{
/* Sanity check the length of the new array */
if ( aDataSupplied.length != oSettings.aoColumns.length &&
oSettings.iDrawError != oSettings.iDraw )
{
_fnLog( oSettings, 0, "Added data (size "+aDataSupplied.length+") does not match known "+
"number of columns ("+oSettings.aoColumns.length+")" );
oSettings.iDrawError = oSettings.iDraw;
return -1;
}
/* Create the object for storing information about this new row */
var aData = aDataSupplied.slice();
var iThisIndex = oSettings.aoData.length;
oSettings.aoData.push( {
"nTr": document.createElement('tr'),
"_iId": oSettings.iNextId++,
"_aData": aData,
"_anHidden": [],
"_sRowStripe": ''
} );
/* Create the cells */
var nTd, sThisType;
for ( var i=0 ; i= oSettings.fnRecordsDisplay()) ?
0 : oSettings.iInitDisplayStart;
}
oSettings.iInitDisplayStart = -1;
_fnCalculateEnd( oSettings );
}
/* If we are dealing with Ajax - do it here */
if ( !oSettings.bDestroying && oSettings.oFeatures.bServerSide &&
!_fnAjaxUpdate( oSettings ) )
{
return;
}
else if ( !oSettings.oFeatures.bServerSide )
{
oSettings.iDraw++;
}
if ( oSettings.aiDisplay.length !== 0 )
{
var iStart = oSettings._iDisplayStart;
var iEnd = oSettings._iDisplayEnd;
if ( oSettings.oFeatures.bServerSide )
{
iStart = 0;
iEnd = oSettings.aoData.length;
}
for ( var j=iStart ; jtr', oSettings.nTHead)[0],
_fnGetDataMaster( oSettings ), oSettings._iDisplayStart, oSettings.fnDisplayEnd(),
oSettings.aiDisplay );
}
if ( typeof oSettings.fnFooterCallback == 'function' )
{
oSettings.fnFooterCallback.call( oSettings.oInstance, jQuery('>tr', oSettings.nTFoot)[0],
_fnGetDataMaster( oSettings ), oSettings._iDisplayStart, oSettings.fnDisplayEnd(),
oSettings.aiDisplay );
}
/*
* Need to remove any old row from the display - note we can't just empty the tbody using
* jQuery().html('') since this will unbind the jQuery event handlers (even although the node
* still exists!) - equally we can't use innerHTML, since IE throws an exception.
*/
var
nAddFrag = document.createDocumentFragment(),
nRemoveFrag = document.createDocumentFragment(),
nBodyPar, nTrs;
if ( oSettings.nTBody )
{
nBodyPar = oSettings.nTBody.parentNode;
nRemoveFrag.appendChild( oSettings.nTBody );
/* When doing infinite scrolling, only remove child rows when sorting, filtering or start
* up. When not infinite scroll, always do it.
*/
if ( !oSettings.oScroll.bInfinite || !oSettings._bInitComplete ||
oSettings.bSorted || oSettings.bFiltered )
{
nTrs = oSettings.nTBody.childNodes;
for ( i=nTrs.length-1 ; i>=0 ; i-- )
{
nTrs[i].parentNode.removeChild( nTrs[i] );
}
}
/* Put the draw table into the dom */
for ( i=0, iLen=anRows.length ; i=0 ; i-- )
{
oSettings.aoDrawCallback[i].fn.call( oSettings.oInstance, oSettings );
}
/* Draw is complete, sorting and filtering must be as well */
oSettings.bSorted = false;
oSettings.bFiltered = false;
oSettings.bDrawing = false;
if ( oSettings.oFeatures.bServerSide )
{
_fnProcessingDisplay( oSettings, false );
if ( typeof oSettings._bInitComplete == 'undefined' )
{
_fnInitComplete( oSettings );
}
}
}
/*
* Function: _fnReDraw
* Purpose: Redraw the table - taking account of the various features which are enabled
* Returns: -
* Inputs: object:oSettings - dataTables settings object
*/
function _fnReDraw( oSettings )
{
if ( oSettings.oFeatures.bSort )
{
/* Sorting will refilter and draw for us */
_fnSort( oSettings, oSettings.oPreviousSearch );
}
else if ( oSettings.oFeatures.bFilter )
{
/* Filtering will redraw for us */
_fnFilterComplete( oSettings, oSettings.oPreviousSearch );
}
else
{
_fnCalculateEnd( oSettings );
_fnDraw( oSettings );
}
}
/*
* Function: _fnAjaxUpdate
* Purpose: Update the table using an Ajax call
* Returns: bool: block the table drawing or not
* Inputs: object:oSettings - dataTables settings object
*/
function _fnAjaxUpdate( oSettings )
{
if ( oSettings.bAjaxDataGet )
{
_fnProcessingDisplay( oSettings, true );
var iColumns = oSettings.aoColumns.length;
var aoData = [];
var i;
/* Paging and general */
oSettings.iDraw++;
aoData.push( { "name": "sEcho", "value": oSettings.iDraw } );
aoData.push( { "name": "iColumns", "value": iColumns } );
aoData.push( { "name": "sColumns", "value": _fnColumnOrdering(oSettings) } );
aoData.push( { "name": "iDisplayStart", "value": oSettings._iDisplayStart } );
aoData.push( { "name": "iDisplayLength", "value": oSettings.oFeatures.bPaginate !== false ?
oSettings._iDisplayLength : -1 } );
/* Filtering */
if ( oSettings.oFeatures.bFilter !== false )
{
aoData.push( { "name": "sSearch", "value": oSettings.oPreviousSearch.sSearch } );
aoData.push( { "name": "bRegex", "value": oSettings.oPreviousSearch.bRegex } );
for ( i=0 ; i' )
{
/* End container div */
nInsertNode = nInsertNode.parentNode;
}
else if ( cOption == 'l' && oSettings.oFeatures.bPaginate && oSettings.oFeatures.bLengthChange )
{
/* Length */
nTmp = _fnFeatureHtmlLength( oSettings );
iPushFeature = 1;
}
else if ( cOption == 'f' && oSettings.oFeatures.bFilter )
{
/* Filter */
nTmp = _fnFeatureHtmlFilter( oSettings );
iPushFeature = 1;
}
else if ( cOption == 'r' && oSettings.oFeatures.bProcessing )
{
/* pRocessing */
nTmp = _fnFeatureHtmlProcessing( oSettings );
iPushFeature = 1;
}
else if ( cOption == 't' )
{
/* Table */
nTmp = _fnFeatureHtmlTable( oSettings );
iPushFeature = 1;
}
else if ( cOption == 'i' && oSettings.oFeatures.bInfo )
{
/* Info */
nTmp = _fnFeatureHtmlInfo( oSettings );
iPushFeature = 1;
}
else if ( cOption == 'p' && oSettings.oFeatures.bPaginate )
{
/* Pagination */
nTmp = _fnFeatureHtmlPaginate( oSettings );
iPushFeature = 1;
}
else if ( _oExt.aoFeatures.length !== 0 )
{
/* Plug-in features */
var aoFeatures = _oExt.aoFeatures;
for ( var k=0, kLen=aoFeatures.length ; kcaption', oSettings.nTable);
for ( var i=0, iLen=nCaptions.length ; i
jQuery(oSettings.nTable).height() - oSettings.oScroll.iLoadGap )
{
/* Only do the redraw if we have to - we might be at the end of the data */
if ( oSettings.fnDisplayEnd() < oSettings.fnRecordsDisplay() )
{
_fnPageChange( oSettings, 'next' );
_fnCalculateEnd( oSettings );
_fnDraw( oSettings );
}
}
}
} );
}
oSettings.nScrollHead = nScrollHead;
oSettings.nScrollFoot = nScrollFoot;
return nScroller;
}
/*
* Function: _fnScrollDraw
* Purpose: Update the various tables for resizing
* Returns: node: - Node to add to the DOM
* Inputs: object:o - dataTables settings object
* Notes: It's a bit of a pig this function, but basically the idea to:
* 1. Re-create the table inside the scrolling div
* 2. Take live measurements from the DOM
* 3. Apply the measurements
* 4. Clean up
*/
function _fnScrollDraw ( o )
{
var
nScrollHeadInner = o.nScrollHead.getElementsByTagName('div')[0],
nScrollHeadTable = nScrollHeadInner.getElementsByTagName('table')[0],
nScrollBody = o.nTable.parentNode,
i, iLen, j, jLen, anHeadToSize, anHeadSizers, anFootSizers, anFootToSize, oStyle, iVis,
iWidth, aApplied=[], iSanityWidth;
/*
* 1. Re-create the table inside the scrolling div
*/
/* Remove the old minimised thead and tfoot elements in the inner table */
var nTheadSize = o.nTable.getElementsByTagName('thead');
if ( nTheadSize.length > 0 )
{
o.nTable.removeChild( nTheadSize[0] );
}
if ( o.nTFoot !== null )
{
/* Remove the old minimised footer element in the cloned header */
var nTfootSize = o.nTable.getElementsByTagName('tfoot');
if ( nTfootSize.length > 0 )
{
o.nTable.removeChild( nTfootSize[0] );
}
}
/* Clone the current header and footer elements and then place it into the inner table */
nTheadSize = o.nTHead.cloneNode(true);
o.nTable.insertBefore( nTheadSize, o.nTable.childNodes[0] );
if ( o.nTFoot !== null )
{
nTfootSize = o.nTFoot.cloneNode(true);
o.nTable.insertBefore( nTfootSize, o.nTable.childNodes[1] );
}
/*
* 2. Take live measurements from the DOM - do not alter the DOM itself!
*/
/* Remove old sizing and apply the calculated column widths
* Get the unique column headers in the newly created (cloned) header. We want to apply the
* calclated sizes to this header
*/
var nThs = _fnGetUniqueThs( nTheadSize );
for ( i=0, iLen=nThs.length ; i iSanityWidth-o.oScroll.iBarWidth )
{
/* Not possible to take account of it */
o.nTable.style.width = _fnStringToCss( iSanityWidth );
}
}
else
{
/* All else fails */
o.nTable.style.width = _fnStringToCss( iSanityWidth );
}
}
/* Recalculate the sanity width - now that we've applied the required width, before it was
* a temporary variable. This is required because the column width calculation is done
* before this table DOM is created.
*/
iSanityWidth = jQuery(o.nTable).outerWidth();
/* We want the hidden header to have zero height, so remove padding and borders. Then
* set the width based on the real headers
*/
anHeadToSize = o.nTHead.getElementsByTagName('tr');
anHeadSizers = nTheadSize.getElementsByTagName('tr');
_fnApplyToChildren( function(nSizer, nToSize) {
oStyle = nSizer.style;
oStyle.paddingTop = "0";
oStyle.paddingBottom = "0";
oStyle.borderTopWidth = "0";
oStyle.borderBottomWidth = "0";
oStyle.height = 0;
iWidth = jQuery(nSizer).width();
nToSize.style.width = _fnStringToCss( iWidth );
aApplied.push( iWidth );
}, anHeadSizers, anHeadToSize );
jQuery(anHeadSizers).height(0);
if ( o.nTFoot !== null )
{
/* Clone the current footer and then place it into the body table as a "hidden header" */
anFootSizers = nTfootSize.getElementsByTagName('tr');
anFootToSize = o.nTFoot.getElementsByTagName('tr');
_fnApplyToChildren( function(nSizer, nToSize) {
oStyle = nSizer.style;
oStyle.paddingTop = "0";
oStyle.paddingBottom = "0";
oStyle.borderTopWidth = "0";
oStyle.borderBottomWidth = "0";
iWidth = jQuery(nSizer).width();
nToSize.style.width = _fnStringToCss( iWidth );
aApplied.push( iWidth );
}, anFootSizers, anFootToSize );
jQuery(anFootSizers).height(0);
}
/*
* 3. Apply the measurements
*/
/* "Hide" the header and footer that we used for the sizing. We want to also fix their width
* to what they currently are
*/
_fnApplyToChildren( function(nSizer) {
nSizer.innerHTML = "";
nSizer.style.width = _fnStringToCss( aApplied.shift() );
}, anHeadSizers );
if ( o.nTFoot !== null )
{
_fnApplyToChildren( function(nSizer) {
nSizer.innerHTML = "";
nSizer.style.width = _fnStringToCss( aApplied.shift() );
}, anFootSizers );
}
/* Sanity check that the table is of a sensible width. If not then we are going to get
* misalignment
*/
if ( jQuery(o.nTable).outerWidth() < iSanityWidth )
{
if ( o.oScroll.sX === "" )
{
_fnLog( o, 1, "The table cannot fit into the current element which will cause column"+
" misalignment. It is suggested that you enable x-scrolling or increase the width"+
" the table has in which to be drawn" );
}
else if ( o.oScroll.sXInner !== "" )
{
_fnLog( o, 1, "The table cannot fit into the current element which will cause column"+
" misalignment. It is suggested that you increase the sScrollXInner property to"+
" allow it to draw in a larger area, or simply remove that parameter to allow"+
" automatic calculation" );
}
}
/*
* 4. Clean up
*/
if ( o.oScroll.sY === "" )
{
/* IE7< puts a vertical scrollbar in place (when it shouldn't be) due to subtracting
* the scrollbar height from the visible display, rather than adding it on. We need to
* set the height in order to sort this. Don't want to do it in any other browsers.
*/
if ( jQuery.browser.msie && jQuery.browser.version <= 7 )
{
nScrollBody.style.height = _fnStringToCss( o.nTable.offsetHeight+o.oScroll.iBarWidth );
}
}
if ( o.oScroll.sY !== "" && o.oScroll.bCollapse )
{
nScrollBody.style.height = _fnStringToCss( o.oScroll.sY );
var iExtra = (o.oScroll.sX !== "" && o.nTable.offsetWidth > nScrollBody.offsetWidth) ?
o.oScroll.iBarWidth : 0;
if ( o.nTable.offsetHeight < nScrollBody.offsetHeight )
{
nScrollBody.style.height = _fnStringToCss( jQuery(o.nTable).height()+iExtra );
}
}
/* Finally set the width's of the header and footer tables */
var iOuterWidth = jQuery(o.nTable).outerWidth();
nScrollHeadTable.style.width = _fnStringToCss( iOuterWidth );
nScrollHeadInner.style.width = _fnStringToCss( iOuterWidth+o.oScroll.iBarWidth );
nScrollHeadInner.parentNode.style.width = _fnStringToCss( jQuery(nScrollBody).width() );
if ( o.nTFoot !== null )
{
var
nScrollFootInner = o.nScrollFoot.getElementsByTagName('div')[0],
nScrollFootTable = nScrollFootInner.getElementsByTagName('table')[0];
nScrollFootInner.style.width = _fnStringToCss( o.nTable.offsetWidth+o.oScroll.iBarWidth );
nScrollFootTable.style.width = _fnStringToCss( o.nTable.offsetWidth );
}
/* If sorting or filtering has occured, jump the scrolling back to the top */
if ( o.bSorted || o.bFiltered )
{
nScrollBody.scrollTop = 0;
}
}
/*
* Function: _fnAjustColumnSizing
* Purpose: Ajust the table column widths for new data
* Returns: -
* Inputs: object:oSettings - dataTables settings object
* Notes: You would probably want to do a redraw after calling this function!
*/
function _fnAjustColumnSizing ( oSettings )
{
/* Not interested in doing column width calculation if autowidth is disabled */
if ( oSettings.oFeatures.bAutoWidth === false )
{
return false;
}
_fnCalculateColumnWidths( oSettings );
for ( var i=0 , iLen=oSettings.aoColumns.length ; i';
var jqFilter = jQuery("input", nFilter);
jqFilter.val( oSettings.oPreviousSearch.sSearch.replace('"','"') );
jqFilter.keyup( function(e) {
/* Update all other filter input elements for the new display */
var n = oSettings.aanFeatures.f;
for ( var i=0, iLen=n.length ; i=0 ; i-- )
{
var sData = _fnDataToSearch( oSettings.aoData[ oSettings.aiDisplay[i] ]._aData[iColumn],
oSettings.aoColumns[iColumn].sType );
if ( ! rpSearch.test( sData ) )
{
oSettings.aiDisplay.splice( i, 1 );
iIndexCorrector++;
}
}
}
/*
* Function: _fnFilter
* Purpose: Filter the data table based on user input and draw the table
* Returns: -
* Inputs: object:oSettings - dataTables settings object
* string:sInput - string to filter on
* int:iForce - optional - force a research of the master array (1) or not (undefined or 0)
* bool:bRegex - treat as a regular expression or not
* bool:bSmart - perform smart filtering or not
*/
function _fnFilter( oSettings, sInput, iForce, bRegex, bSmart )
{
var i;
var rpSearch = _fnFilterCreateSearch( sInput, bRegex, bSmart );
/* Check if we are forcing or not - optional parameter */
if ( typeof iForce == 'undefined' || iForce === null )
{
iForce = 0;
}
/* Need to take account of custom filtering functions - always filter */
if ( _oExt.afnFiltering.length !== 0 )
{
iForce = 1;
}
/*
* If the input is blank - we want the full data set
*/
if ( sInput.length <= 0 )
{
oSettings.aiDisplay.splice( 0, oSettings.aiDisplay.length);
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
}
else
{
/*
* We are starting a new search or the new search string is smaller
* then the old one (i.e. delete). Search from the master array
*/
if ( oSettings.aiDisplay.length == oSettings.aiDisplayMaster.length ||
oSettings.oPreviousSearch.sSearch.length > sInput.length || iForce == 1 ||
sInput.indexOf(oSettings.oPreviousSearch.sSearch) !== 0 )
{
/* Nuke the old display array - we are going to rebuild it */
oSettings.aiDisplay.splice( 0, oSettings.aiDisplay.length);
/* Force a rebuild of the search array */
_fnBuildSearchArray( oSettings, 1 );
/* Search through all records to populate the search array
* The the oSettings.aiDisplayMaster and asDataSearch arrays have 1 to 1
* mapping
*/
for ( i=0 ; i tag - remove it */
sSearch = sSearch.replace(/\n/g," ").replace(/\r/g,"");
}
return sSearch;
}
/*
* Function: _fnFilterCreateSearch
* Purpose: Build a regular expression object suitable for searching a table
* Returns: RegExp: - constructed object
* Inputs: string:sSearch - string to search for
* bool:bRegex - treat as a regular expression or not
* bool:bSmart - perform smart filtering or not
*/
function _fnFilterCreateSearch( sSearch, bRegex, bSmart )
{
var asSearch, sRegExpString;
if ( bSmart )
{
/* Generate the regular expression to use. Something along the lines of:
* ^(?=.*?\bone\b)(?=.*?\btwo\b)(?=.*?\bthree\b).*$
*/
asSearch = bRegex ? sSearch.split( ' ' ) : _fnEscapeRegex( sSearch ).split( ' ' );
sRegExpString = '^(?=.*?'+asSearch.join( ')(?=.*?' )+').*$';
return new RegExp( sRegExpString, "i" );
}
else
{
sSearch = bRegex ? sSearch : _fnEscapeRegex( sSearch );
return new RegExp( sSearch, "i" );
}
}
/*
* Function: _fnDataToSearch
* Purpose: Convert raw data into something that the user can search on
* Returns: string: - search string
* Inputs: string:sData - data to be modified
* string:sType - data type
*/
function _fnDataToSearch ( sData, sType )
{
if ( typeof _oExt.ofnSearch[sType] == "function" )
{
return _oExt.ofnSearch[sType]( sData );
}
else if ( sType == "html" )
{
return sData.replace(/\n/g," ").replace( /<.*?>/g, "" );
}
else if ( typeof sData == "string" )
{
return sData.replace(/\n/g," ");
}
return sData;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Section - Feature: Sorting
*/
/*
* Function: _fnSort
* Purpose: Change the order of the table
* Returns: -
* Inputs: object:oSettings - dataTables settings object
* bool:bApplyClasses - optional - should we apply classes or not
* Notes: We always sort the master array and then apply a filter again
* if it is needed. This probably isn't optimal - but atm I can't think
* of any other way which is (each has disadvantages). we want to sort aiDisplayMaster -
* but according to aoData[]._aData
*/
function _fnSort ( oSettings, bApplyClasses )
{
var
iDataSort, iDataType,
i, iLen, j, jLen,
aaSort = [],
aiOrig = [],
oSort = _oExt.oSort,
aoData = oSettings.aoData,
aoColumns = oSettings.aoColumns;
/* No sorting required if server-side or no sorting array */
if ( !oSettings.oFeatures.bServerSide &&
(oSettings.aaSorting.length !== 0 || oSettings.aaSortingFixed !== null) )
{
if ( oSettings.aaSortingFixed !== null )
{
aaSort = oSettings.aaSortingFixed.concat( oSettings.aaSorting );
}
else
{
aaSort = oSettings.aaSorting.slice();
}
/* If there is a sorting data type, and a fuction belonging to it, then we need to
* get the data from the developer's function and apply it for this column
*/
for ( i=0 ; i= iColumns )
{
for ( i=0 ; i=0 ?
oSettings._iDisplayStart - oSettings._iDisplayLength :
0;
/* Correct for underrun */
if ( oSettings._iDisplayStart < 0 )
{
oSettings._iDisplayStart = 0;
}
}
else if ( sAction == "next" )
{
if ( oSettings._iDisplayLength >= 0 )
{
/* Make sure we are not over running the display array */
if ( oSettings._iDisplayStart + oSettings._iDisplayLength < oSettings.fnRecordsDisplay() )
{
oSettings._iDisplayStart += oSettings._iDisplayLength;
}
}
else
{
oSettings._iDisplayStart = 0;
}
}
else if ( sAction == "last" )
{
if ( oSettings._iDisplayLength >= 0 )
{
var iPages = parseInt( (oSettings.fnRecordsDisplay()-1) / oSettings._iDisplayLength, 10 ) + 1;
oSettings._iDisplayStart = (iPages-1) * oSettings._iDisplayLength;
}
else
{
oSettings._iDisplayStart = 0;
}
}
else
{
_fnLog( oSettings, 0, "Unknown paging action: "+sAction );
}
return iOldStart != oSettings._iDisplayStart;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Section - Feature: HTML info
*/
/*
* Function: _fnFeatureHtmlInfo
* Purpose: Generate the node required for the info display
* Returns: node
* Inputs: object:oSettings - dataTables settings object
*/
function _fnFeatureHtmlInfo ( oSettings )
{
var nInfo = document.createElement( 'div' );
nInfo.className = oSettings.oClasses.sInfo;
/* Actions that are to be taken once only for this feature */
if ( typeof oSettings.aanFeatures.i == "undefined" )
{
/* Add draw callback */
oSettings.aoDrawCallback.push( {
"fn": _fnUpdateInfo,
"sName": "information"
} );
/* Add id */
if ( oSettings.sTableId !== '' )
{
nInfo.setAttribute( 'id', oSettings.sTableId+'_info' );
}
}
return nInfo;
}
/*
* Function: _fnUpdateInfo
* Purpose: Update the information elements in the display
* Returns: -
* Inputs: object:oSettings - dataTables settings object
*/
function _fnUpdateInfo ( oSettings )
{
/* Show information about the table */
if ( !oSettings.oFeatures.bInfo || oSettings.aanFeatures.i.length === 0 )
{
return;
}
var
iStart = oSettings._iDisplayStart+1, iEnd = oSettings.fnDisplayEnd(),
iMax = oSettings.fnRecordsTotal(), iTotal = oSettings.fnRecordsDisplay(),
sStart = oSettings.fnFormatNumber( iStart ), sEnd = oSettings.fnFormatNumber( iEnd ),
sMax = oSettings.fnFormatNumber( iMax ), sTotal = oSettings.fnFormatNumber( iTotal ),
sOut;
/* When infinite scrolling, we are always starting at 1. _iDisplayStart is used only
* internally
*/
if ( oSettings.oScroll.bInfinite )
{
sStart = oSettings.fnFormatNumber( 1 );
}
if ( oSettings.fnRecordsDisplay() === 0 &&
oSettings.fnRecordsDisplay() == oSettings.fnRecordsTotal() )
{
/* Empty record set */
sOut = oSettings.oLanguage.sInfoEmpty+ oSettings.oLanguage.sInfoPostFix;
}
else if ( oSettings.fnRecordsDisplay() === 0 )
{
/* Rmpty record set after filtering */
sOut = oSettings.oLanguage.sInfoEmpty +' '+
oSettings.oLanguage.sInfoFiltered.replace('_MAX_', sMax)+
oSettings.oLanguage.sInfoPostFix;
}
else if ( oSettings.fnRecordsDisplay() == oSettings.fnRecordsTotal() )
{
/* Normal record set */
sOut = oSettings.oLanguage.sInfo.
replace('_START_', sStart).
replace('_END_', sEnd).
replace('_TOTAL_', sTotal)+
oSettings.oLanguage.sInfoPostFix;
}
else
{
/* Record set after filtering */
sOut = oSettings.oLanguage.sInfo.
replace('_START_', sStart).
replace('_END_', sEnd).
replace('_TOTAL_', sTotal) +' '+
oSettings.oLanguage.sInfoFiltered.replace('_MAX_',
oSettings.fnFormatNumber(oSettings.fnRecordsTotal()))+
oSettings.oLanguage.sInfoPostFix;
}
if ( oSettings.oLanguage.fnInfoCallback !== null )
{
sOut = oSettings.oLanguage.fnInfoCallback( oSettings, iStart, iEnd, iMax, iTotal, sOut );
}
var n = oSettings.aanFeatures.i;
for ( var i=0, iLen=n.length ; i';
var i, iLen;
if ( oSettings.aLengthMenu.length == 2 && typeof oSettings.aLengthMenu[0] == 'object' &&
typeof oSettings.aLengthMenu[1] == 'object' )
{
for ( i=0, iLen=oSettings.aLengthMenu[0].length ; i'+
oSettings.aLengthMenu[1][i]+'';
}
}
else
{
for ( i=0, iLen=oSettings.aLengthMenu.length ; i'+
oSettings.aLengthMenu[i]+'';
}
}
sStdMenu += '';
var nLength = document.createElement( 'div' );
if ( oSettings.sTableId !== '' && typeof oSettings.aanFeatures.l == "undefined" )
{
nLength.setAttribute( 'id', oSettings.sTableId+'_length' );
}
nLength.className = oSettings.oClasses.sLength;
nLength.innerHTML = oSettings.oLanguage.sLengthMenu.replace( '_MENU_', sStdMenu );
/*
* Set the length to the current display length - thanks to Andrea Pavlovic for this fix,
* and Stefan Skopnik for fixing the fix!
*/
jQuery('select option[value="'+oSettings._iDisplayLength+'"]',nLength).attr("selected",true);
jQuery('select', nLength).change( function(e) {
var iVal = jQuery(this).val();
/* Update all other length options for the new display */
var n = oSettings.aanFeatures.l;
for ( i=0, iLen=n.length ; i oSettings.aiDisplay.length ||
oSettings._iDisplayLength == -1 )
{
oSettings._iDisplayEnd = oSettings.aiDisplay.length;
}
else
{
oSettings._iDisplayEnd = oSettings._iDisplayStart + oSettings._iDisplayLength;
}
}
}
/*
* Function: _fnConvertToWidth
* Purpose: Convert a CSS unit width to pixels (e.g. 2em)
* Returns: int:iWidth - width in pixels
* Inputs: string:sWidth - width to be converted
* node:nParent - parent to get the with for (required for
* relative widths) - optional
*/
function _fnConvertToWidth ( sWidth, nParent )
{
if ( !sWidth || sWidth === null || sWidth === '' )
{
return 0;
}
if ( typeof nParent == "undefined" )
{
nParent = document.getElementsByTagName('body')[0];
}
var iWidth;
var nTmp = document.createElement( "div" );
nTmp.style.width = sWidth;
nParent.appendChild( nTmp );
iWidth = nTmp.offsetWidth;
nParent.removeChild( nTmp );
return ( iWidth );
}
/*
* Function: _fnCalculateColumnWidths
* Purpose: Calculate the width of columns for the table
* Returns: -
* Inputs: object:oSettings - dataTables settings object
*/
function _fnCalculateColumnWidths ( oSettings )
{
var iTableWidth = oSettings.nTable.offsetWidth;
var iUserInputs = 0;
var iTmpWidth;
var iVisibleColumns = 0;
var iColums = oSettings.aoColumns.length;
var i;
var oHeaders = jQuery('th', oSettings.nTHead);
/* Convert any user input sizes into pixel sizes */
for ( i=0 ; itd', nCalcTmp);
}
jqColSizing.each( function (i) {
this.style.width = "";
var iIndex = _fnVisibleToColumnIndex( oSettings, i );
if ( iIndex !== null && oSettings.aoColumns[iIndex].sWidthOrig !== "" )
{
this.style.width = oSettings.aoColumns[iIndex].sWidthOrig;
}
} );
/* Find the biggest td for each column and put it into the table */
for ( i=0 ; itd", nCalcTmp);
if ( oNodes.length === 0 )
{
oNodes = jQuery("thead tr:eq(0)>th", nCalcTmp);
}
var iIndex, iCorrector = 0, iWidth;
for ( i=0 ; i 0 )
{
oSettings.aoColumns[i].sWidth = _fnStringToCss( iWidth );
}
iCorrector++;
}
}
oSettings.nTable.style.width = _fnStringToCss( jQuery(nCalcTmp).outerWidth() );
nCalcTmp.parentNode.removeChild( nCalcTmp );
}
}
/*
* Function: _fnScrollingWidthAdjust
* Purpose: Adjust a table's width to take account of scrolling
* Returns: -
* Inputs: object:oSettings - dataTables settings object
* node:n - table node
*/
function _fnScrollingWidthAdjust ( oSettings, n )
{
if ( oSettings.oScroll.sX === "" && oSettings.oScroll.sY !== "" )
{
/* When y-scrolling only, we want to remove the width of the scroll bar so the table
* + scroll bar will fit into the area avaialble.
*/
var iOrigWidth = jQuery(n).width();
n.style.width = _fnStringToCss( jQuery(n).outerWidth()-oSettings.oScroll.iBarWidth );
}
else if ( oSettings.oScroll.sX !== "" )
{
/* When x-scrolling both ways, fix the table at it's current size, without adjusting */
n.style.width = _fnStringToCss( jQuery(n).outerWidth() );
}
}
/*
* Function: _fnGetWidestNode
* Purpose: Get the widest node
* Returns: string: - max strlens for each column
* Inputs: object:oSettings - dataTables settings object
* int:iCol - column of interest
* boolean:bFast - Should we use fast (but non-accurate) calculation - optional,
* default true
* Notes: This operation is _expensive_ (!!!). It requires a lot of DOM interaction, but
* this is the only way to reliably get the widest string. For example 'mmm' would be wider
* than 'iiii' so we can't just ocunt characters. If this can be optimised it would be good
* to do so!
*/
function _fnGetWidestNode( oSettings, iCol, bFast )
{
/* Use fast not non-accurate calculate based on the strlen */
if ( typeof bFast == 'undefined' || bFast )
{
var iMaxLen = _fnGetMaxLenString( oSettings, iCol );
var iFastVis = _fnColumnIndexToVisible( oSettings, iCol);
if ( iMaxLen < 0 )
{
return null;
}
return oSettings.aoData[iMaxLen].nTr.getElementsByTagName('td')[iFastVis];
}
/* Use the slow approach, but get high quality answers - note that this code is not actually
* used by DataTables by default. If you want to use it you can alter the call to
* _fnGetWidestNode to pass 'false' as the third argument
*/
var
iMax = -1, i, iLen,
iMaxIndex = -1,
n = document.createElement('div');
n.style.visibility = "hidden";
n.style.position = "absolute";
document.body.appendChild( n );
for ( i=0, iLen=oSettings.aoData.length ; i iMax )
{
iMax = n.offsetWidth;
iMaxIndex = i;
}
}
document.body.removeChild( n );
if ( iMaxIndex >= 0 )
{
var iVis = _fnColumnIndexToVisible( oSettings, iCol);
var nRet = oSettings.aoData[iMaxIndex].nTr.getElementsByTagName('td')[iVis];
if ( nRet )
{
return nRet;
}
}
return null;
}
/*
* Function: _fnGetMaxLenString
* Purpose: Get the maximum strlen for each data column
* Returns: string: - max strlens for each column
* Inputs: object:oSettings - dataTables settings object
* int:iCol - column of interest
*/
function _fnGetMaxLenString( oSettings, iCol )
{
var iMax = -1;
var iMaxIndex = -1;
for ( var i=0 ; i iMax )
{
iMax = s.length;
iMaxIndex = i;
}
}
return iMaxIndex;
}
/*
* Function: _fnStringToCss
* Purpose: Append a CSS unit (only if required) to a string
* Returns: 0 if match, 1 if length is different, 2 if no match
* Inputs: array:aArray1 - first array
* array:aArray2 - second array
*/
function _fnStringToCss( s )
{
if ( s === null )
{
return "0px";
}
if ( typeof s == 'number' )
{
if ( s < 0 )
{
return "0px";
}
return s+"px";
}
/* Check if the last character is not 0-9 */
var c = s.charCodeAt( s.length-1 );
if (c < 0x30 || c > 0x39)
{
return s;
}
return s+"px";
}
/*
* Function: _fnArrayCmp
* Purpose: Compare two arrays
* Returns: 0 if match, 1 if length is different, 2 if no match
* Inputs: array:aArray1 - first array
* array:aArray2 - second array
*/
function _fnArrayCmp( aArray1, aArray2 )
{
if ( aArray1.length != aArray2.length )
{
return 1;
}
for ( var i=0 ; i iTarget )
{
a[i]--;
}
}
if ( iTargetIndex != -1 )
{
a.splice( iTargetIndex, 1 );
}
}
/*
* Function: _fnReOrderIndex
* Purpose: Figure out how to reorder a display list
* Returns: array int:aiReturn - index list for reordering
* Inputs: object:oSettings - dataTables settings object
*/
function _fnReOrderIndex ( oSettings, sColumns )
{
var aColumns = sColumns.split(',');
var aiReturn = [];
for ( var i=0, iLen=oSettings.aoColumns.length ; i 4096 ) /* Magic 10 for padding */
{
var aCookies =document.cookie.split(';');
for ( var i=0, iLen=aCookies.length ; itr', this);
for ( i=0, iLen=oSettings.asStripClasses.length ; i=0 ; i-- )
{
/* Each column def can target multiple columns, as it is an array */
var aTargets = oInit.aoColumnDefs[i].aTargets;
if ( !jQuery.isArray( aTargets ) )
{
_fnLog( oSettings, 1, 'aTargets must be an array of targets, not a '+(typeof aTargets) );
}
for ( j=0, jLen=aTargets.length ; j= 0 )
{
/* 0+ integer, left to right column counting. We add columns which are unknown
* automatically. Is this the right behaviour for this? We should at least
* log it in future. We cannot do this for the negative or class targets, only here.
*/
while( oSettings.aoColumns.length <= aTargets[j] )
{
_fnAddColumn( oSettings );
}
_fnColumnOptions( oSettings, aTargets[j], oInit.aoColumnDefs[i] );
}
else if ( typeof aTargets[j] == 'number' && aTargets[j] < 0 )
{
/* Negative integer, right to left column counting */
_fnColumnOptions( oSettings, oSettings.aoColumns.length+aTargets[j],
oInit.aoColumnDefs[i] );
}
else if ( typeof aTargets[j] == 'string' )
{
/* Class name matching on TH element */
for ( k=0, kLen=oSettings.aoColumns.length ; k= oSettings.aoColumns.length )
{
oSettings.aaSorting[i][0] = 0;
}
var oColumn = oSettings.aoColumns[ oSettings.aaSorting[i][0] ];
/* Add a default sorting index */
if ( typeof oSettings.aaSorting[i][2] == 'undefined' )
{
oSettings.aaSorting[i][2] = 0;
}
/* If aaSorting is not defined, then we use the first indicator in asSorting */
if ( typeof oInit.aaSorting == "undefined" &&
typeof oSettings.saved_aaSorting == "undefined" )
{
oSettings.aaSorting[i][1] = oColumn.asSorting[0];
}
/* Set the current sorting index based on aoColumns.asSorting */
for ( j=0, jLen=oColumn.asSorting.length ; j 0 )
{
oSettings.nTFoot = this.getElementsByTagName('tfoot')[0];
}
/* Check if there is data passing into the constructor */
if ( bUsePassedData )
{
for ( i=0 ; i "(GB)"
// 3. Add a question mark into the regular expression associated with
// Germany's number following the country code: i.e. "(DE)" -> "(DE)?"
var defCCode = "GB";
// Note - VAT codes without the "**" in the comment do not have check digit
// checking.
vatexp.push (/^(AT)U(\d{8})$/); //** Austria
vatexp.push (/^(BE)(\d{9,10})$/); //** Belgium
vatexp.push (/^(BG)(\d{9,10})$/); // Bulgaria
vatexp.push (/^(CY)(\d{8}[A-Z])$/); //** Cyprus
vatexp.push (/^(CZ)(\d{8,10})(\d{3})?$/); //** Czech Republic
vatexp.push (/^(DE)(\d{9})$/); //** Germany
vatexp.push (/^(DK)((\d{8}))$/); //** Denmark
vatexp.push (/^(EE)(\d{9})$/); //** Estonia
vatexp.push (/^(EL)(\d{8,9})$/); //** Greece
vatexp.push (/^(ES)([A-Z]\d{8})$/); //** Spain (1)
vatexp.push (/^(ES)(\d{8}[A-Z])$/); // Spain (2)
vatexp.push (/^(ES)([A-Z]\d{7}[A-Z])$/); //** Spain (3)
vatexp.push (/^(EU)(\d{9})$/); //** EU-type
vatexp.push (/^(FI)(\d{8})$/); //** Finland
vatexp.push (/^(FR)(\d{11})$/); //** France (1)
vatexp.push (/^(FR)[(A-H)|(J-N)|(P-Z)]\d{10}$/); // France (2)
vatexp.push (/^(FR)\d[(A-H)|(J-N)|(P-Z)]\d{9}$/); // France (3)
vatexp.push (/^(FR)[(A-H)|(J-N)|(P-Z)]{2}\d{9}$/); // France (4)
vatexp.push (/^(GB)?(\d{9})$/); //** UK (standard)
vatexp.push (/^(GB)?(\d{10})$/); //** UK (Commercial)
vatexp.push (/^(GB)?(\d{12})$/); //UK (IOM standard)
vatexp.push (/^(GB)?(\d{13})$/); //UK (IOM commercial)
vatexp.push (/^(GB)?(GD\d{3})$/); //** UK (Government)
vatexp.push (/^(GB)?(HA\d{3})$/); //** UK (Health authority)
vatexp.push (/^(GR)(\d{8,9})$/); //** Greece
vatexp.push (/^(HU)(\d{8})$/); //** Hungary
vatexp.push (/^(IE)(\d{7}[A-W])$/); //** Ireland (1)
vatexp.push (/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/); //** Ireland (2)
vatexp.push (/^(IT)(\d{11})$/); //** Italy
vatexp.push (/^(LV)(\d{11})$/); //** Latvia
vatexp.push (/^(LT)(\d{9}|\d{12})$/); //** Lithunia
vatexp.push (/^(LU)(\d{8})$/); //** Luxembourg
vatexp.push (/^(MT)(\d{8})$/); //** Malta
vatexp.push (/^(NL)(\d{9})B\d{2}$/); //** Netherlands
vatexp.push (/^(PL)(\d{10})$/); //** Poland
vatexp.push (/^(PT)(\d{9})$/); //** Portugal
vatexp.push (/^(RO)(\d{2,10})$/); //** Romania
vatexp.push (/^(SI)(\d{8})$/); //** Slovenia
vatexp.push (/^(SK)(\d{9}|\d{10})$/); // Slovakia Republic
vatexp.push (/^(SE)(\d{10}\d[1-4])$/); //** Sweden
// Load up the string to check
var VATNumber = toCheck.toUpperCase();
// Remove spaces from the VAT number to help validation
var chars = [" ","-",",","."];
for ( var i=0; i < chars.length; i++) {
while (VATNumber.indexOf(chars[i])!= -1) {
VATNumber = VATNumber.slice (0,VATNumber.indexOf(chars[i])) + VATNumber.slice (VATNumber.indexOf(chars[i])+1);
}
}
// Assume we're not going to find a valid VAT number
var valid = false;
// Check the string against the types of VAT numbers
for (i=0; i < vatexp.length; i++) {
if (vatexp[i].test(VATNumber)) {
var cCode = RegExp.$1; // Isolate country code
var cNumber = RegExp.$2; // Isolate the number
if (cCode.length == 0) cCode = defCCode; // Set up default country code
// Now look at the check digits for those countries we know about.
switch (cCode) {
case "AT":
valid = ATVATCheckDigit (cNumber);
break;
case "BE":
valid = BEVATCheckDigit (cNumber);
break;
case "BG":
// The SIMA validation rules are incorrect for Bulgarian numbers.
//valid = BGVATCheckDigit (cNumber)
valid = true;
break;
case "CY":
valid = CYVATCheckDigit (cNumber);
break;
case "CZ":
valid = CZVATCheckDigit (cNumber);
break;
case "DE":
valid = DEVATCheckDigit (cNumber);
break;
case "DK":
valid = DKVATCheckDigit (cNumber);
break;
case "EE":
valid = EEVATCheckDigit (cNumber);
break;
case "EL":
valid = ELVATCheckDigit (cNumber);
break;
case "ES":
valid = ESVATCheckDigit (cNumber);
break;
case "EU":
valid = EUVATCheckDigit (cNumber);
break;
case "FI":
valid = FIVATCheckDigit (cNumber);
break;
case "FR":
valid = FRVATCheckDigit (cNumber);
break;
case "GB":
valid = UKVATCheckDigit (cNumber);
break;
case "GR":
valid = ELVATCheckDigit (cNumber);
break;
case "HU":
valid = HUVATCheckDigit (cNumber);
break;
case "IE":
valid = IEVATCheckDigit (cNumber);
break;
case "IT":
valid = ITVATCheckDigit (cNumber);
break;
case "LT":
valid = LTVATCheckDigit (cNumber);
break;
case "LU":
valid = LUVATCheckDigit (cNumber);
break;
case "LV":
valid = LVVATCheckDigit (cNumber);
break;
case "MT":
valid = MTVATCheckDigit (cNumber);
break;
case "NL":
valid = NLVATCheckDigit (cNumber);
break;
case "PL":
valid = PLVATCheckDigit (cNumber);
break;
case "PT":
valid = PTVATCheckDigit (cNumber);
break;
case "RO":
valid = ROVATCheckDigit (cNumber);
break;
case "SE":
valid = SEVATCheckDigit (cNumber);
break;
case "SI":
valid = SIVATCheckDigit (cNumber);
break;
default:
valid = true;
}
// Load new VAT number back into the form element
if (valid) valid = VATNumber;
// We have found that the number is valid - break from loop
break;
}
}
// Return with either an error or the reformatted VAT number
return valid;
}
function ATVATCheckDigit (vatnumber) {
// Checks the check digits of an Austrian VAT number.
var total = 0;
var multipliers = [1,2,1,2,1,2,1];
var temp = 0;
// Extract the next digit and multiply by the appropriate multiplier.
for (var i = 0; i < 7; i++) {
temp = Number(vatnumber.charAt(i)) * multipliers[i];
if (temp > 9)
total = total + Math.floor(temp/10) + temp%10
else
total = total + temp;
}
// Establish check digit.
total = 10 - (total+4) % 10;
if (total == 10) total = 0;
// Compare it with the last character of the VAT number. If it is the same,
// then it's a valid check digit.
if (total == vatnumber.slice (7,8))
return true
else
return false;
}
function BEVATCheckDigit (vatnumber) {
// Checks the check digits of a Belgium VAT number.
// First character of 10 digit numbers should be 0
if (vatnumber.length == 10 && vatnumber.slice(0,1) != "0") return false;
// Nine digit numbers have a 0 inserted at the front.
if (vatnumber.length == 9) vatnumber = "0" + vatnumber;
// Modulus 97 check on last nine digits
if (97 - vatnumber.slice (0,8) % 97 == vatnumber.slice (8,10))
return true
else
return false;
}
function BGVATCheckDigit (vatnumber) {
// Check the check digit of 10 digit Bulgarian VAT numbers.
if (vatnumber.length != 10) return true;
var total = 0;
var multipliers = [4,3,2,7,6,5,4,3,2];
var temp = 0;
// Extract the next digit and multiply by the appropriate multiplier.
for (var i = 0; i < 9; i++) {
temp = temp + Number(vatnumber.charAt(i)) * multipliers[i];
}
// Establish check digit.
total = 11 - total % 11;
if (total == 10) total = 0;
if (total == 11) total = 1;
// Compare it with the last character of the VAT number. If it is the same,
// then it's a valid check digit.
if (total == vatnumber.slice (9,10))
return true
else
return false;
}
function CYVATCheckDigit (vatnumber) {
// Checks the check digits of a Cypriot VAT number.
// Extract the next digit and multiply by the counter.
var total = 0;
for (var i = 0; i < 8; i++) {
var temp = Number(vatnumber.charAt(i));
if (i % 2 == 0) {
switch (temp) {
case 0: temp = 1; break;
case 1: temp = 0; break;
case 2: temp = 5; break;
case 3: temp = 7; break;
case 4: temp = 9; break;
default: temp = temp*2 + 3;
}
}
total = total + temp;
}
// Establish check digit using modulus 26, and translate to char. equivalent.
total = total % 26;
total = String.fromCharCode(total+65);
// Check to see if the check digit given is correct
if (total == vatnumber.substr (8,1))
return true
else
return false;
}
function CZVATCheckDigit (vatnumber) {
// Checks the check digits of a Czech Republic VAT number.
var total = 0;
var multipliers = [8,7,6,5,4,3,2];
// Only do check digit validation for standard VAT numbers
if (vatnumber.length != 8) return true;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
// Establish check digit.
total = 11 - total % 11;
if (total == 10) total = 0;
if (total == 11) total = 1;
// Compare it with the last character of the VAT number. If it is the same,
// then it's a valid check digit.
if (total == vatnumber.slice (7,8))
return true
else
return false;
}
function DEVATCheckDigit (vatnumber) {
// Checks the check digits of a German VAT number.
var product = 10;
var sum = 0;
var checkdigit = 0;
for (var i = 0; i < 8; i++) {
// Extract the next digit and implement perculiar algorithm!.
sum = (Number(vatnumber.charAt(i)) + product) % 10;
if (sum == 0) {sum = 10};
product = (2 * sum) % 11;
}
// Establish check digit.
if (11 - product == 10) {checkdigit = 0} else {checkdigit = 11 - product};
// Compare it with the last two characters of the VAT number. If the same,
// then it is a valid check digit.
if (checkdigit == vatnumber.slice (8,9))
return true
else
return false;
}
function DKVATCheckDigit (vatnumber) {
// Checks the check digits of a Danish VAT number.
var total = 0;
var multipliers = [2,7,6,5,4,3,2,1];
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
// Establish check digit.
total = total % 11;
// The remainder should be 0 for it to be valid..
if (total == 0)
return true
else
return false;
}
function EEVATCheckDigit (vatnumber) {
// Checks the check digits of an Estonian VAT number.
var total = 0;
var multipliers = [3,7,1,3,7,1,3,7];
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
// Establish check digits using modulus 10.
total = 10 - total % 10;
if (total == 10) total = 0;
// Compare it with the last character of the VAT number. If it is the same,
// then it's a valid check digit.
if (total == vatnumber.slice (8,9))
return true
else
return false;
}
function ELVATCheckDigit (vatnumber) {
// Checks the check digits of a Greek VAT number.
var total = 0;
var multipliers = [256,128,64,32,16,8,4,2];
//eight character numbers should be prefixed with an 0.
if (vatnumber.length == 8) {vatnumber = "0" + vatnumber};
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
// Establish check digit.
total = total % 11;
if (total > 9) {total = 0;};
// Compare it with the last character of the VAT number. If it is the same,
// then it's a valid check digit.
if (total == vatnumber.slice (8,9))
return true
else
return false;
}
function ESVATCheckDigit (vatnumber) {
// Checks the check digits of a Spanish VAT number.
var total = 0;
var temp = 0;
var multipliers = [2,1,2,1,2,1,2];
var esexp = new Array ();
esexp.push (/^[A-H]\d{8}$/);
esexp.push (/^[N|P|Q|S]\d{7}[A-Z]$/);
esexp.push (/^[0-9]{8}[A-Z]$/);
var i = 0;
// With profit companies
if (esexp[0].test(vatnumber)) {
// Extract the next digit and multiply by the counter.
for (i = 0; i < 7; i++) {
temp = Number(vatnumber.charAt(i+1)) * multipliers[i];
if (temp > 9)
total = total + Math.floor(temp/10) + temp%10
else
total = total + temp;
}
// Now calculate the check digit itself.
total = 10 - total % 10;
if (total == 10) {total = 0;}
// Compare it with the last character of the VAT number. If it is the same,
// then it's a valid check digit.
if (total == vatnumber.slice (8,9))
return true
else
return false;
}
// Non-profit companies
else if (esexp[1].test(vatnumber)) {
// Extract the next digit and multiply by the counter.
for (i = 0; i < 7; i++) {
temp = Number(vatnumber.charAt(i+1)) * multipliers[i];
if (temp > 9)
total = total + Math.floor(temp/10) + temp%10
else
total = total + temp;
}
// Now calculate the check digit itself.
total = 10 - total % 10;
total = String.fromCharCode(total+64);
// Compare it with the last character of the VAT number. If it is the same,
// then it's a valid check digit.
if (total == vatnumber.slice (8,9))
return true
else
return false;
}
// Personal number (NIF)
else if (esexp[2].test(vatnumber)) {
return vatnumber.charAt(8) == 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(Number(vatnumber.substring(0, 8)) % 23);
}
else return true;
}
function EUVATCheckDigit (vatnumber) {
// We know litle about EU numbers apart from the fact that the first 3 digits
// represent the country, and that there are nine digits in total.
return true;
}
function FIVATCheckDigit (vatnumber) {
// Checks the check digits of a Finnish VAT number.
var total = 0;
var multipliers = [7,9,10,5,8,4,2];
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
// Establish check digit.
total = 11 - total % 11;
if (total > 9) {total = 0;};
// Compare it with the last character of the VAT number. If it is the same,
// then it's a valid check digit.
if (total == vatnumber.slice (7,8))
return true
else
return false;
}
function FRVATCheckDigit (vatnumber) {
// Checks the check digits of a French VAT number.
if (!(/^\d{11}$/).test(vatnumber)) return true;
// Extract the last nine digits as an integer.
var total = vatnumber.substring(2);
// Establish check digit.
total = (total*100+12) % 97;
// Compare it with the last character of the VAT number. If it is the same,
// then it's a valid check digit.
if (total == vatnumber.slice (0,2))
return true
else
return false;
}
function HUVATCheckDigit (vatnumber) {
// Checks the check digits of a Hungarian VAT number.
var total = 0;
var multipliers = [9,7,3,1,9,7,3];
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
// Establish check digit.
total = 10 - total % 10;
if (total == 10) total = 0;
// Compare it with the last character of the VAT number. If it is the same,
// then it's a valid check digit.
if (total == vatnumber.slice (7,8))
return true
else
return false;
}
function IEVATCheckDigit (vatnumber) {
// Checks the check digits of an Irish VAT number.
var total = 0;
var multipliers = [8,7,6,5,4,3,2];
// If the code is in the old format, we need to convert it to the new.
if (/^\d[A-Z\*\+]/.test(vatnumber)) {
vatnumber = "0" + vatnumber.substring(2,7) + vatnumber.substring(0,1) + vatnumber.substring(7,8);
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
// Establish check digit using modulus 23, and translate to char. equivalent.
total = total % 23;
if (total == 0)
total = "W"
else
total = String.fromCharCode(total+64);
// Compare it with the last character of the VAT number. If it is the same,
// then it's a valid check digit.
if (total == vatnumber.slice (7,8))
return true
else
return false;
}
function ITVATCheckDigit (vatnumber) {
// Checks the check digits of an Italian VAT number.
var total = 0;
var multipliers = [1,2,1,2,1,2,1,2,1,2];
var temp;
// The last three digits are the issuing office, and cannot exceed more 201
temp=Number(vatnumber.slice(0,7));
if (temp==0) return false;
temp=Number(vatnumber.slice(7,10));
if ((temp<1) || (temp>201)) return false;
// Extract the next digit and multiply by the appropriate
for (var i = 0; i < 10; i++) {
temp = Number(vatnumber.charAt(i)) * multipliers[i];
if (temp > 9)
total = total + Math.floor(temp/10) + temp%10
else
total = total + temp;
}
// Establish check digit.
total = 10 - total % 10;
if (total > 9) {total = 0;};
// Compare it with the last character of the VAT number. If it is the same,
// then it's a valid check digit.
if (total == vatnumber.slice (10,11))
return true
else
return false;
}
function LTVATCheckDigit (vatnumber) {
// Checks the check digits of a Lithuanian VAT number.
// Only do check digit validation for standard VAT numbers
if (vatnumber.length != 9) return true;
// Extract the next digit and multiply by the counter+1.
var total = 0;
for (var i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * (i+1);
// Can have a double check digit calculation!
if (total % 11 == 10) {
var multipliers = [3,4,5,6,7,8,9,1];
total = 0;
for (i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
}
// Establish check digit.
total = total % 11;
if (total == 10) {total = 0;};
// Compare it with the last character of the VAT number. If it is the same,
// then it's a valid check digit.
if (total == vatnumber.slice (8,9))
return true
else
return false;
}
function LUVATCheckDigit (vatnumber) {
// Checks the check digits of a Luxembourg VAT number.
if (vatnumber.slice (0,6) % 89 == vatnumber.slice (6,8))
return true
else
return false;
}
function LVVATCheckDigit (vatnumber) {
// Checks the check digits of a Latvian VAT number.
// Only check the legal bodies
if ((/^[0-3]/).test(vatnumber)) return true;
var total = 0;
var multipliers = [9,1,4,8,3,10,2,5,7,6];
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 10; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
// Establish check digits by getting modulus 11.
if (total%11 == 4 && vatnumber[0] ==9) total = total - 45;
if (total%11 == 4)
total = 4 - total%11
else if (total%11 > 4)
total = 14 - total%11
else if (total%11 < 4)
total = 3 - total%11;
// Compare it with the last character of the VAT number. If it is the same,
// then it's a valid check digit.
if (total == vatnumber.slice (10,11))
return true
else
return false;
}
function MTVATCheckDigit (vatnumber) {
// Checks the check digits of a Maltese VAT number.
var total = 0;
var multipliers = [3,4,6,7,8,9];
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 6; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
// Establish check digits by getting modulus 37.
total = 37 - total % 37;
// Compare it with the last character of the VAT number. If it is the same,
// then it's a valid check digit.
if (total == vatnumber.slice (6,8) * 1)
return true
else
return false;
}
function NLVATCheckDigit (vatnumber) {
// Checks the check digits of a Dutch VAT number.
var total = 0; //
var multipliers = [9,8,7,6,5,4,3,2];
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
// Establish check digits by getting modulus 11.
total = total % 11;
if (total > 9) {total = 0;};
// Compare it with the last character of the VAT number. If it is the same,
// then it's a valid check digit.
if (total == vatnumber.slice (8,9))
return true
else
return false;
}
function PLVATCheckDigit (vatnumber) {
// Checks the check digits of a Polish VAT number.
var total = 0;
var multipliers = [6,5,7,2,3,4,5,6,7];
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 9; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
// Establish check digits subtracting modulus 11 from 11.
total = total % 11;
if (total > 9) {total = 0;};
// Compare it with the last character of the VAT number. If it is the same, then it's a valid
// check digit.
if (total == vatnumber.slice (9,10))
return true
else
return false;
}
function PTVATCheckDigit (vatnumber) {
// Checks the check digits of a Portugese VAT number.
var total = 0;
var multipliers = [9,8,7,6,5,4,3,2];
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
// Establish check digits subtracting modulus 11 from 11.
total = 11 - total % 11;
if (total > 9) {total = 0;};
// Compare it with the last character of the VAT number. If it is the same, then it's a valid
// check digit.
if (total == vatnumber.slice (8,9))
return true
else
return false;
}
function ROVATCheckDigit (vatnumber) {
// Checks the check digits of a Romanian VAT number.
var multipliers = [7,5,3,2,1,7,5,3,2,1];
// Extract the next digit and multiply by the counter.
var VATlen = vatnumber.length;
multipliers = multipliers.slice (10-VATlen);
var total = 0;
for (var i = 0; i < vatnumber.length-1; i++) {
total = total + Number(vatnumber.charAt(i)) * multipliers[i];
}
// Establish check digits by getting modulus 11.
total = (10 * total) % 11;
if (total == 10) total = 0;
// Compare it with the last character of the VAT number. If it is the same, then it's a valid
// check digit.
if (total == vatnumber.slice (vatnumber.length-1, vatnumber.length))
return true
else
return false;
}
function SEVATCheckDigit (vatnumber) {
// Checks the check digits of a Swedish VAT number.
var total = 0;
var multipliers = [2,1,2,1,2,1,2,1,2];
var temp = 0;
// Extract the next digit and multiply by the appropriate multiplier.
for (var i = 0; i < 9; i++) {
temp = Number(vatnumber.charAt(i)) * multipliers[i];
if (temp > 9)
total = total + Math.floor(temp/10) + temp%10
else
total = total + temp;
}
// Establish check digits by subtracting mod 10 of total from 10.
total = 10 - (total % 10);
if (total == 10) total = 0;
// Compare it with the 10th character of the VAT number. If it is the same,
// then it's a valid check digit.
if (total == vatnumber.slice (9,10))
return true
else
return false;
}
function SKVATCheckDigit (vatnumber) {
// Checks the check digits of a Slovak VAT number.
var total = 0;
var multipliers = [8,7,6,5,4,3,2];
// Extract the next digit and multiply by the counter.
for (var i = 3; i < 9; i++) {
total = total + Number(vatnumber.charAt(i)) * multipliers[i-3];
}
// Establish check digits by getting modulus 11.
total = 11 - total % 11;
if (total > 9) total = total - 10;
// Compare it with the last character of the VAT number. If it is the same,
// then it's a valid check digit.
if (total == vatnumber.slice (9,10))
return true
else
return false;
}
function SIVATCheckDigit (vatnumber) {
// Checks the check digits of a Slovenian VAT number.
var total = 0;
var multipliers = [8,7,6,5,4,3,2];
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
// Establish check digits by subtracting 97 from total until negative.
total = 11 - total % 11;
if (total > 9) {total = 0;};
// Compare the number with the last character of the VAT number. If it is the
// same, then it's a valid check digit.
if (total == vatnumber.slice (7,8))
return true
else
return false;
}
function UKVATCheckDigit (vatnumber) {
// Checks the check digits of a UK VAT number.
var multipliers = [8,7,6,5,4,3,2];
// Government departments
if (vatnumber.substr(0,2) == 'GD') {
if (vatnumber.substr(2,3) < 500)
return true
else
return false;
}
// Health authorities
if (vatnumber.substr(0,2) == 'HA') {
if (vatnumber.substr(2,3) > 499)
return true
else
return false;
}
// Standard and commercial numbers
if (vatnumber.length == 9 || vatnumber.length == 10) {
var total = 0;
if (vatnumber.length == 10 && vatnumber.slice (9,10) != '3') return false;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
// Old numbers use a simple 97 modulus, but new numbers use an adaptation of that (less
// 55). Our VAT number could use either system, so we check it against both.
// Establish check digits by subtracting 97 from total until negative.
var cd = total;
while (cd > 0) {cd = cd - 97;}
// Get the absolute value and compare it with the last two characters of the
// VAT number. If the same, then it is a valid traditional check digit.
cd = Math.abs(cd);
if (cd == vatnumber.slice (7,9)) return true;
// Now try the new method by subtracting 55 from the check digit if we can - else add 42
if (cd >= 55)
cd = cd - 55
else
cd = cd + 42;
if (cd == vatnumber.slice (7,9))
return true
else
return false;
}
// We don't check 12 and 13 digit UK numbers - not only can we not find any,
// but the information found on the format is contradictory.
return true;
}
var passwordstrengthlevel = '';
jQuery.validator.setDefaults({
ignore: ':hidden',
rules: {
username: {
required: true,
minlength: 2,
remote: "./includes/scripts/ajax_affdetails.asp"
},
emailaddress: {
minlength: 2,
remote: "../includes/scripts/ajax_affdetails.asp"
},
verificationimg: {
minlength: 1,
remote: "./includes/scripts/ajax_affdetails.asp"
},
passwordretype: {
required: true,
equalTo: "#password"
}
},
messages:{
verificationimg:"Please enter the text as it appears in the image above."
},
/*submitHandler: function(form) {
alert("Validation has completed - submit form now");
form.submit();
},*/
// the errorPlacement has to take the table layout into account
errorPlacement: function(error, element) {
error.appendTo(jQuery("#" + element.attr('id') + "status"));
var thislabel = "#" + element.attr('id') + "req";
jQuery(thislabel).addClass("error");
var Adderrorfield = "";
if (element.attr('id') =="securityquestion"){ Adderrorfield = "securityquestioncustom";}
//if (element.attr('id') =="securityquestioncustom"){ Adderrorfield = "securityquestion";}
if (Adderrorfield.length>0){
error.appendTo(jQuery("#" + Adderrorfield + "status"));
var thislabel = "#" + Adderrorfield + "req";
jQuery(thislabel).addClass("error");
}
},
// set this class to error-labels to indicate valid fields
success: function(label) {
// set as text for IE
label.html(" ").addClass("checked");
var Adderrorfield = "";
if (label.attr('for') =="securityquestion"){ Adderrorfield = "securityquestioncustom";}
if (label.attr('for') =="securityquestioncustom"){ Adderrorfield = "securityquestion";}
if (Adderrorfield.length>0){
var thislabel = "#" + Adderrorfield + "status";
jQuery(thislabel).html(" ").addClass("checked");
}
}
});
jQuery.extend(jQuery.validator.messages, {
required: "JQvalrequired",
remote: "JQvalremote",
email: "JQvalemail",
url: "JQvalurl",
date: "JQvaldate",
dateISO: "JQvaldateISO",
number: "JQvalnumber",
digits: "JQvaldigits",
creditcard: "JQvalcreditcard",
equalTo: "JQvalequalrequired",
accept: "JQvalaccept",
maxlength: jQuery.validator.format("JQvalmaxlength"),
minlength: jQuery.validator.format("JQvalminlength"),
rangelength: jQuery.validator.format("JQvalrangelength"),
range: jQuery.validator.format("JQvalrange"),
max: jQuery.validator.format("JQvalmax"),
min: jQuery.validator.format("JQvalmin")
});
jQuery(function() {
// Add Program Specific validation
jQuery.validator.addMethod("alphaNumeric", function (value, element) {
return this.optional(element) || /^[0-9a-zA-Z ]+$/.test(value);
}, "JQvalalphanumeric"
);
jQuery.validator.addMethod("allowedstring", function(value, element) {
return this.optional(element) || (/^[a-zA-Z0-9 ._@#*&,\/-]+$/i.test(value));
},jQuery.validator.format("JQvalStringAllowedchar"," ._@#*&,\/-")
);
jQuery.validator.addMethod("isphone", function(value, element) {
return this.optional(element) || /^[ .+()0-9-]+$/.test(value);
},jQuery.validator.format("Please check the Phone number")
);
jQuery.validator.addMethod("isvat", function(value, element) {
return this.optional(element) || checkVATNumber (value);
},"jscheckvat"
);
jQuery.validator.addMethod("ispassword", function(value, element) {
if (passwordstrengthlevel>0) {
var checkstrength = testPassword(value);
if (passwordstrengthlevel> (checkstrength+1)){
return false;
} else{
return true;
}
} else{
return true;
}
}
,"The Password is too weak - try using both upper and lower case letters, numbers and include Characters like !@#$_~"
);
jQuery.validator.addMethod("securityquestions", function (value, element) {
var securityquestiondropdown = jQuery("#securityquestion").val();
var securityquestioncustom = jQuery("#securityquestioncustom").val();
if(securityquestiondropdown.length==0 && securityquestioncustom.length==0 ) {
return false;
}else {
return true;
}
}, "Please Select a Security Question."
);
jQuery.validator.addMethod("securityquestions2", function (value, element) {
var securityquestiondropdown = jQuery("#securityquestion").val();
var securityquestioncustom = jQuery("#securityquestioncustom").val();
if( ((securityquestiondropdown.length>0) || (securityquestioncustom.length>0)) && (value.length==0) ) {
return false;
}else {
return true;
}
}, "jschecksecurityquestionanswer"
);
});
// jQuery.validator.addClassRules
jQuery.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
while(x1 && m[1]!=''){o+=m[1];x+=m[1].length;
}else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;},
URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/;
while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){b=parseInt(m[1].substr(1),16);
t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;}
});
function testPassword(passwd) {
var description = new Array();
description[0] = "
Weakest
";
description[1] = "
Weak
";
description[2] = "
Improving
";
description[3] = "
Strong
";
description[4] = "
Strongest
";
description[5] = "
";
var intScore = 0;var strVerdict = 0;
passwd = jQuery.trim(passwd);
if (passwd.length==0 || !passwd.length) {intScore = -1;}
else if (passwd.length>0 && passwd.length<4){intScore = (intScore+1);}
else if (passwd.length>0 && passwd.length<5){intScore = (intScore+3);}
else if (passwd.length>4 && passwd.length<8){intScore = (intScore+6);}
else if (passwd.length>7 && passwd.length<12){intScore = (intScore+12);}
else if (passwd.length>11){intScore = (intScore+18);}
if (passwd.match(/[a-z]/)){intScore = (intScore+1);}
if (passwd.match(/[A-Z]/)){intScore = (intScore+5);}
if (passwd.match(/\d+/)){intScore = (intScore+5);}
if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/)){intScore = (intScore+5);}
if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/)){intScore = (intScore+5);}
if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)){intScore = (intScore+5);}
if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)){intScore = (intScore+2);}
if (passwd.match(/(\d.*\D)|(\D.*\d)/)){intScore = (intScore+2);}
if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/)){intScore = (intScore+2);}
if(intScore == -1){strVerdict = description[5];
}else if(intScore > -1 && intScore < 16){strVerdict = 0; //description[0];
}else if (intScore > 15 && intScore < 25){strVerdict = 1; // description[1];
}else if (intScore > 24 && intScore < 35){strVerdict = 2; // description[2];
}else if (intScore > 34 && intScore < 45){strVerdict = 3; // description[3];
}else{strVerdict = 4;} // description[4];}
document.getElementById("passtestindicator").innerHTML= (description[strVerdict]);
return strVerdict;
}
IAJQservertimeout = "ServerTimeout";
IAJQzerorecords ="no records were returned";
IAJQsearch ="search:";
IAJQGRIDLengthMenu ="GRIDLengthMenu";
IAJQGRIDrecordinfo ="GRIDrecordinfo";
IAJQGRIDrecordfiltered ="GRIDrecordfiltered";
'jquery.sexyselect - common languagestrings '
IAJQSELECTlistfilter ="SELECTlistfilter";
IAJQclear ="clear";