1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-04-27 12:31:58 +02:00

Started using es6

This commit is contained in:
Max Guglielmi 2014-11-16 01:34:32 +11:00
parent 4603ce4302
commit e8fba7cedd
27 changed files with 1000 additions and 1867 deletions

25
.jshintrc Normal file
View file

@ -0,0 +1,25 @@
{
// ["xxx"] is better written in dot notation
"-W069": true,
// Script URL
"-W107": true,
// Eval can be harmful
"-W061": true,
"-W041": true,
"curly": true,
//"eqeqeq": true,
"es3": true,
"esnext": true,
//"maxlen" : 80,
"globals": {
"module": true,
"require": true,
"define": true,
"window": true,
"document": true,
"escape": true,
"unescape": true,
"navigator": true
}
}

View file

@ -12,16 +12,7 @@ module.exports = function (grunt) {
jshint: {
src: ['Gruntfile.js', 'src/*.js'],
options: {
'-W069': true, // ['xxx'] is better written in dot notation
'-W107': true, // Script URL
'-W061': true, // Eval can be harmful
'-W041': true,
// options here to override JSHint defaults
globals: {
console: true/*,
module: true,
document: true*/
}
jshintrc: '.jshintrc'
}
},
@ -45,7 +36,7 @@ module.exports = function (grunt) {
'paths': {
'tf': '.'
},
include: ['../libs/almond/almond','core'],
include: ['../libs/almond/almond', 'core'],
out: 'dist/tablefilter.js',
wrap: {
startFile: "src/start.frag",
@ -127,8 +118,27 @@ module.exports = function (grunt) {
{ src: ['**'], cwd: '<%= source_folder %>TF_Themes/', dest: '<%= dist_folder %>TF_Themes/', expand: true }
]
}
}
},
'6to5': {
options: {
sourceMap: true,
modules: 'amd'
},
// dist: {
// files: {
// 'es6/modules/*.js': '<%= source_folder %>modules/'
// }
// }
build:{
files: [{
expand: true,
cwd: '<%= source_folder %>es6-modules',
src: ['**/*.js'],
dest: '<%= source_folder %>modules'
}]
}
}
});
// Load the plugins that provide the tasks we specified in package.json.
@ -140,10 +150,12 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-6to5');
// This is the default task being executed if Grunt
// is called without any further parameter.
grunt.registerTask('default', ['jshint', 'requirejs', 'concat', 'uglify', 'cssmin', 'copy', 'qunit']);
grunt.registerTask('dev', ['jshint', 'concat', 'cssmin', 'copy']);
grunt.registerTask('dev', ['jshint', '6to5', 'concat', 'cssmin', 'copy']);
grunt.registerTask('toes5', ['6to5']);
grunt.registerTask('test', ['qunit']);
};

View file

@ -1,71 +0,0 @@
/*------------------------------------------------------------------------
- HTML Table Filter Generator
- Alternating rows color feature v1.0
- By Max Guglielmi (tablefilter.free.fr)
- Licensed under the MIT License
-------------------------------------------------------------------------*/
TF.prototype.SetRowBg = function(rIndex,index)
/*====================================================
- sets row background color
- Params:
- rIndex: row index (numeric value)
- index: valid row collection index needed to
calculate bg color
=====================================================*/
{
if(!this.alternateBgs || isNaN(rIndex)) return;
var rows = this.tbl.rows;
var i = (index==undefined) ? rIndex : index;
this.RemoveRowBg(rIndex);
tf_AddClass(
rows[rIndex],
(i%2) ? this.rowBgEvenCssClass : this.rowBgOddCssClass
);
}
TF.prototype.RemoveRowBg = function(index)
/*====================================================
- removes row background color
- Params:
- index: row index (numeric value)
=====================================================*/
{
if(isNaN(index)) return;
var rows = this.tbl.rows;
tf_RemoveClass(rows[index],this.rowBgOddCssClass);
tf_RemoveClass(rows[index],this.rowBgEvenCssClass);
}
TF.prototype.SetAlternateRows = function()
/*====================================================
- alternates row colors for better readability
=====================================================*/
{
if( !this.hasGrid && !this.isFirstLoad ) return;
var rows = this.tbl.rows;
var noValidRowsIndex = this.validRowsIndex==null;
var beginIndex = (noValidRowsIndex) ? this.refRow : 0; //1st index
var indexLen = (noValidRowsIndex) // nb indexes
? (this.nbFilterableRows+beginIndex) : this.validRowsIndex.length;
var idx = 0;
for(var j=beginIndex; j<indexLen; j++)//alternates bg color
{
var rIndex = (noValidRowsIndex) ? j : this.validRowsIndex[j];
this.SetRowBg(rIndex,idx);
idx++;
}
}
TF.prototype.RemoveAlternateRows = function()
/*====================================================
- removes alternate row colors
=====================================================*/
{
if(!this.hasGrid) return;
var row = this.tbl.rows;
for(var i=this.refRow; i<this.nbRows; i++)
this.RemoveRowBg(i);
this.isStartBgAlternate = true;
}

View file

@ -1,271 +0,0 @@
/*------------------------------------------------------------------------
- HTML Table Filter Generator
- Columns Operations feature v1.0
- By Max Guglielmi (tablefilter.free.fr)
- Licensed under the MIT License
- Special credit to Nuovella Williams
-------------------------------------------------------------------------*/
TF.prototype.SetColOperation = function()
/*====================================================
- Calculates values of a column
- params are stored in 'colOperation' table's
attribute
- colOperation['id'] contains ids of elements
showing result (array)
- colOperation['col'] contains index of
columns (array)
- colOperation['operation'] contains operation
type (array, values: sum, mean)
- colOperation['write_method'] array defines
which method to use for displaying the
result (innerHTML, setValue, createTextNode).
Note that innerHTML is the default value.
- colOperation['tot_row_index'] defines in
which row results are displayed (integers array)
- changes made by nuovella:
(1) optimized the routine (now it will only
process each column once),
(2) added calculations for the median, lower and
upper quartile.
=====================================================*/
{
if( !this.isFirstLoad && !this.hasGrid ) return;
if(this.onBeforeOperation) this.onBeforeOperation.call(null,this);
var labelId = this.colOperation['id'];
var colIndex = this.colOperation['col'];
var operation = this.colOperation['operation'];
var outputType = this.colOperation['write_method'];
var totRowIndex = this.colOperation['tot_row_index'];
var excludeRow = this.colOperation['exclude_row'];
var decimalPrecision = this.colOperation['decimal_precision']!=undefined
? this.colOperation['decimal_precision'] : 2;
//nuovella: determine unique list of columns to operate on
var ucolIndex =[];
var ucolMax=0;
ucolIndex[ucolMax]=colIndex[0];
for(var i=1; i<colIndex.length; i++)
{
saved=0;
//see if colIndex[i] is already in the list of unique indexes
for(var j=0; j<=ucolMax; j++ )
{
if (ucolIndex[j]==colIndex[i])
saved=1;
}
if (saved==0)
{//if not saved then, save the index;
ucolMax++;
ucolIndex[ucolMax]=colIndex[i];
}
}// for i
if( (typeof labelId).tf_LCase()=='object'
&& (typeof colIndex).tf_LCase()=='object'
&& (typeof operation).tf_LCase()=='object' )
{
var row = this.tbl.rows;
var colvalues = [];
for(var ucol=0; ucol<=ucolMax; ucol++)
{
//this retrieves col values
//use ucolIndex because we only want to pass through this loop once for each column
//get the values in this unique column
colvalues.push( this.GetColValues(ucolIndex[ucol],true,excludeRow) );
//next: calculate all operations for this column
var result, nbvalues=0, temp;
var meanValue=0, sumValue=0, minValue=null, maxValue=null, q1Value=null, medValue=null, q3Value=null;
var meanFlag=0, sumFlag=0, minFlag=0, maxFlag=0, q1Flag=0, medFlag=0, q3Flag=0;
var theList=[];
var opsThisCol=[], decThisCol=[], labThisCol=[], oTypeThisCol=[];
var mThisCol=-1;
for(var i=0; i<colIndex.length; i++)
{
if (colIndex[i]==ucolIndex[ucol])
{
mThisCol++;
opsThisCol[mThisCol]=operation[i].tf_LCase();
decThisCol[mThisCol]=decimalPrecision[i];
labThisCol[mThisCol]=labelId[i];
oTypeThisCol = (outputType != undefined && (typeof outputType).tf_LCase()=='object')
? outputType[i] : null;
switch( opsThisCol[mThisCol] )
{
case 'mean':
meanFlag=1;
break;
case 'sum':
sumFlag=1;
break;
case 'min':
minFlag=1;
break;
case 'max':
maxFlag=1;
break;
case 'median':
medFlag=1;
break;
case 'q1':
q1Flag=1;
break;
case 'q3':
q3Flag=1;
break;
}
}
}
for(var j=0; j<colvalues[ucol].length; j++ )
{
if ((q1Flag==1)||(q3Flag==1) || (medFlag==1))
{//sort the list for calculation of median and quartiles
if (j<colvalues[ucol].length -1)
{
for(k=j+1;k<colvalues[ucol].length; k++) {
if( eval(colvalues[ucol][k]) < eval(colvalues[ucol][j]))
{
temp = colvalues[ucol][j];
colvalues[ucol][j] = colvalues[ucol][k];
colvalues[ucol][k] = temp;
}
}
}
}
var cvalue = parseFloat(colvalues[ucol][j]);
theList[j]=parseFloat( cvalue );
if( !isNaN(cvalue) )
{
nbvalues++;
if ((sumFlag==1)|| (meanFlag==1)) sumValue += parseFloat( cvalue );
if (minFlag==1)
{
if (minValue==null)
{
minValue = parseFloat( cvalue );
}
else minValue= parseFloat( cvalue )<minValue? parseFloat( cvalue ): minValue;
}
if (maxFlag==1) {
if (maxValue==null)
{maxValue = parseFloat( cvalue );}
else {maxValue= parseFloat( cvalue )>maxValue? parseFloat( cvalue ): maxValue;}
}
}
}//for j
if (meanFlag==1) meanValue = sumValue/nbvalues;
if (medFlag==1)
{
var aux = 0;
if(nbvalues%2 == 1)
{
aux = Math.floor(nbvalues/2);
medValue = theList[aux];
}
else medValue = (theList[nbvalues/2]+theList[((nbvalues/2)-1)])/2;
}
if (q1Flag==1)
{
var posa=0.0;
posa = Math.floor(nbvalues/4);
if (4*posa == nbvalues) {q1Value = (theList[posa-1] + theList[posa])/2;}
else {q1Value = theList[posa];}
}
if (q3Flag==1)
{
var posa=0.0;
var posb=0.0;
posa = Math.floor(nbvalues/4);
if (4*posa == nbvalues)
{
posb = 3*posa;
q3Value = (theList[posb] + theList[posb-1])/2;
}
else
q3Value = theList[nbvalues-posa-1];
}
for(var i=0; i<=mThisCol; i++ )
{
switch( opsThisCol[i] )
{
case 'mean':
result=meanValue;
break;
case 'sum':
result=sumValue;
break;
case 'min':
result=minValue;
break;
case 'max':
result=maxValue;
break;
case 'median':
result=medValue;
break;
case 'q1':
result=q1Value;
break;
case 'q3':
result=q3Value;
break;
}
var precision = decThisCol[i]!=undefined && !isNaN( decThisCol[i] )
? decThisCol[i] : 2;
if(oTypeThisCol!=null && result)
{//if outputType is defined
result = result.toFixed( precision );
if( tf_Id( labThisCol[i] )!=undefined )
{
switch( oTypeThisCol.tf_LCase() )
{
case 'innerhtml':
if (isNaN(result) || !isFinite(result) || (nbvalues==0))
tf_Id( labThisCol[i] ).innerHTML = '.';
else
tf_Id( labThisCol[i] ).innerHTML = result;
break;
case 'setvalue':
tf_Id( labThisCol[i] ).value = result;
break;
case 'createtextnode':
var oldnode = tf_Id( labThisCol[i] ).firstChild;
var txtnode = tf_CreateText( result );
tf_Id( labThisCol[i] ).replaceChild( txtnode,oldnode );
break;
}//switch
}
} else {
try
{
if (isNaN(result) || !isFinite(result) || (nbvalues==0))
tf_Id( labThisCol[i] ).innerHTML = '.';
else
tf_Id( labThisCol[i] ).innerHTML = result.toFixed( precision );
} catch(e){ }//catch
}//else
}//for i
//eventual row(s) with result are always visible
if(totRowIndex!=undefined && row[totRowIndex[ucol]])
row[totRowIndex[ucol]].style.display = '';
}//for ucol
}//if typeof
if(this.onAfterOperation) this.onAfterOperation.call(null,this);
}

View file

@ -1,163 +0,0 @@
/*------------------------------------------------------------------------
- HTML Table Filter Generator
- Remember values features (cookies) v1.1
- By Max Guglielmi (tablefilter.free.fr)
- Licensed under the MIT License
-------------------------------------------------------------------------*/
TF.prototype.RememberFiltersValue = function( name )
/*==============================================
- stores filters' values in a cookie
when Filter() method is called
- Params:
- name: cookie name (string)
- credits to Florent Hirchy
===============================================*/
{
var flt_values = [];
for(var i=0; i<this.fltIds.length; i++)
{//creates an array with filters' values
value = this.GetFilterValue(i);
if (value == '') value = ' ';
flt_values.push(value);
}
flt_values.push(this.fltIds.length); //adds array size
tf_WriteCookie(
name,
flt_values.join(this.separator),
this.cookieDuration
); //writes cookie
}
TF.prototype.RememberPageNb = function( name )
/*==============================================
- stores page number value in a cookie
when ChangePage method is called
- Params:
- name: cookie name (string)
===============================================*/
{
tf_WriteCookie(
name,
this.currentPageNb,
this.cookieDuration
); //writes cookie
}
TF.prototype.RememberPageLength = function( name )
/*==============================================
- stores page length value in a cookie
when ChangePageLength method is called
- Params:
- name: cookie name (string)
===============================================*/
{
tf_WriteCookie(
name,
this.resultsPerPageSlc.selectedIndex,
this.cookieDuration
); //writes cookie
}
TF.prototype.ResetValues = function()
{
this.EvtManager(this.Evt.name.resetvalues);
}
TF.prototype._ResetValues = function()
/*==============================================
- re-sets grid values when page is
re-loaded. It invokes ResetGridValues,
ResetPage and ResetPageLength methods
- Params:
- name: cookie name (string)
===============================================*/
{
if(this.rememberGridValues && this.fillSlcOnDemand) //only fillSlcOnDemand
this.ResetGridValues(this.fltsValuesCookie);
if(this.rememberPageLen) this.ResetPageLength( this.pgLenCookie );
if(this.rememberPageNb) this.ResetPage( this.pgNbCookie );
}
TF.prototype.ResetGridValues = function( name )
/*==============================================
- re-sets filters' values when page is
re-loaded if load on demand is enabled
- Params:
- name: cookie name (string)
- credits to Florent Hirchy
===============================================*/
{
if(!this.fillSlcOnDemand) return;
var flts = tf_ReadCookie(name); //reads the cookie
var reg = new RegExp(this.separator,'g');
var flts_values = flts.split(reg); //creates an array with filters' values
var slcFltsIndex = this.GetFiltersByType(this.fltTypeSlc, true);
var multiFltsIndex = this.GetFiltersByType(this.fltTypeMulti, true);
if(flts_values[(flts_values.length-1)] == this.fltIds.length)
{//if the number of columns is the same as before page reload
for(var i=0; i<(flts_values.length - 1); i++)
{
if (flts_values[i]==' ') continue;
if(this['col'+i]==this.fltTypeSlc || this['col'+i]==this.fltTypeMulti)
{// if fillSlcOnDemand, drop-down needs to contain stored value(s) for filtering
var slc = tf_Id( this.fltIds[i] );
slc.options[0].selected = false;
if( slcFltsIndex.tf_Has(i) )
{//selects
var opt = tf_CreateOpt(flts_values[i],flts_values[i],true);
slc.appendChild(opt);
this.hasStoredValues = true;
}
if(multiFltsIndex.tf_Has(i))
{//multiple select
var s = flts_values[i].split(' '+this.orOperator+' ');
for(j=0; j<s.length; j++)
{
if(s[j]=='') continue;
var opt = tf_CreateOpt(s[j],s[j],true);
slc.appendChild(opt);
this.hasStoredValues = true;
if(tf_isIE)
{// IE multiple selection work-around
this.__deferMultipleSelection(slc,j,false);
hasStoredValues = false;
}
}
}// if multiFltsIndex
}
else if(this['col'+i]==this.fltTypeCheckList)
{
var divChk = this.checkListDiv[i];
divChk.title = divChk.innerHTML;
divChk.innerHTML = '';
var ul = tf_CreateElm('ul',['id',this.fltIds[i]],['colIndex',i]);
ul.className = this.checkListCssClass;
var li0 = tf_CreateCheckItem(this.fltIds[i]+'_0', '', this.displayAllText);
li0.className = this.checkListItemCssClass;
ul.appendChild(li0);
divChk.appendChild(ul);
var s = flts_values[i].split(' '+this.orOperator+' ');
for(j=0; j<s.length; j++)
{
if(s[j]=='') continue;
var li = tf_CreateCheckItem(this.fltIds[i]+'_'+(j+1), s[j], s[j]);
li.className = this.checkListItemCssClass;
ul.appendChild(li);
li.check.checked = true;
this.__setCheckListValues(li.check);
this.hasStoredValues = true;
}
}
}//end for
if(!this.hasStoredValues && this.paging) this.SetPagingInfo();
}//end if
}

View file

@ -1,53 +0,0 @@
/*------------------------------------------------------------------------
- HTML Table Filter Generator
- Extensions loading feature v1.0
- By Max Guglielmi (tablefilter.free.fr)
- Licensed under the MIT License
-------------------------------------------------------------------------*/
TF.prototype.LoadExtensions = function()
{
if(!this.Ext){
/*** TF extensions ***/
var o = this;
this.Ext = {
list: {},
add: function(extName, extDesc, extPath, extCallBack)
{
var file = extPath.split('/')[extPath.split('/').length-1];
var re = new RegExp(file);
var path = extPath.replace(re,'');
o.Ext.list[extName] = {
name: extName,
description: extDesc,
file: file,
path: path,
callback: extCallBack
};
}
};
}
this.EvtManager(this.Evt.name.loadextensions);
}
TF.prototype._LoadExtensions = function()
/*====================================================
- loads TF extensions
=====================================================*/
{
if(!this.hasExtensions) return;
if(tf_IsArray(this.extensions.name) && tf_IsArray(this.extensions.src)){
var ext = this.extensions;
for(var e=0; e<ext.name.length; e++){
var extPath = ext.src[e];
var extName = ext.name[e];
var extInit = (ext.initialize && ext.initialize[e]) ? ext.initialize[e] : null;
var extDesc = (ext.description && ext.description[e] ) ? ext.description[e] : null;
//Registers extension
this.Ext.add(extName, extDesc, extPath, extInit);
if(tf_IsImported(extPath)) extInit.call(null,this);
else this.IncludeFile(extName, extPath, extInit);
}
}
}

View file

@ -1,253 +0,0 @@
/*------------------------------------------------------------------------
- HTML Table Filter Generator
- ezEditTable Adapter v1.1
- By Max Guglielmi (tablefilter.free.fr)
- Licensed under the MIT License
-------------------------------------------------------------------------*/
TF.prototype.SetEditable = function()
/*====================================================
- Sets selection or edition features by loading
ezEditTable script by Max Guglielmi
=====================================================*/
{
if(!this.selectable && !this.editable){ return; }
var f = this.fObj;
this.ezEditTableConfig = f.ezEditTable_config!=undefined ? f.ezEditTable_config : {};
this.ezEditTableConfig.name = this.ezEditTableConfig['name']!=undefined ? f.ezEditTable_config.name : 'ezedittable';
this.ezEditTableConfig.src = this.ezEditTableConfig['src']!=undefined ? f.ezEditTable_config.src : this.basePath+'ezEditTable/ezEditTable.js';
//ezEditTable stylesheet not imported by default as filtergrid.css applies
this.ezEditTableConfig.loadStylesheet = this.ezEditTableConfig['loadStylesheet']!=undefined ? f.ezEditTable_config.loadStylesheet : false;
this.ezEditTableConfig.stylesheet = this.ezEditTableConfig['stylesheet']!=undefined ? f.ezEditTable_config.stylesheet : this.basePath+'ezEditTable/ezEditTable.css';
this.ezEditTableConfig.stylesheetName = this.ezEditTableConfig['stylesheetName']!=undefined ? f.ezEditTable_config.stylesheetName : 'ezEditTableCss';
this.ezEditTableConfig.err = 'Failed to instantiate EditTable object.\n"ezEditTable" module may not be available.';
if(tf_IsImported(this.ezEditTableConfig.src)){
this._EnableEditable();
} else {
this.IncludeFile(
this.ezEditTableConfig.name,
this.ezEditTableConfig.src,
this._EnableEditable
);
}
if(this.ezEditTableConfig.loadStylesheet && !tf_IsImported(this.ezEditTableConfig.stylesheet, 'link')){
this.IncludeFile(
this.ezEditTableConfig.stylesheetName,
this.ezEditTableConfig.stylesheet,
null, 'link'
);
}
}
TF.prototype.RemoveEditable = function()
/*====================================================
- Removes selection or edition features
=====================================================*/
{
if(this.ezEditTable){
if(this.selectable){
this.ezEditTable.Selection.ClearSelections();
this.ezEditTable.Selection.Remove();
}
if(this.editable) this.ezEditTable.Editable.Remove();
}
}
TF.prototype.ResetEditable = function()
/*====================================================
- Resets selection or edition features after
removal
=====================================================*/
{
if(this.ezEditTable){
if(this.selectable) this.ezEditTable.Selection.Set();
if(this.editable) this.ezEditTable.Editable.Set();
}
}
TF.prototype._EnableEditable = function(o)
{
if(!o) o = this;
//start row for EditTable constructor needs to be calculated
var startRow;
var thead = tf_Tag(o.tbl,'thead');
//if thead exists and startRow not specified, startRow is calculated automatically by EditTable
if(thead.length > 0 && !o.ezEditTableConfig.startRow) startRow = undefined;
//otherwise startRow config property if any or TableFilter refRow
else startRow = o.ezEditTableConfig.startRow || o.refRow;
//Enables scroll into view feature if not defined
o.ezEditTableConfig.scroll_into_view = o.ezEditTableConfig.scroll_into_view!=undefined ? o.ezEditTableConfig.scroll_into_view : true;
o.ezEditTableConfig.base_path = o.ezEditTableConfig.base_path!=undefined ? o.ezEditTableConfig.base_path : o.basePath + 'ezEditTable/';
o.ezEditTableConfig.editable = o.editable;
o.ezEditTableConfig.selection = o.selectable;
if(o.selectable)
o.ezEditTableConfig.default_selection = o.ezEditTableConfig.default_selection!=undefined ? o.ezEditTableConfig.default_selection : 'row';
//CSS Styles
o.ezEditTableConfig.active_cell_css = o.ezEditTableConfig.active_cell_css!=undefined ? o.ezEditTableConfig.active_cell_css : 'ezETSelectedCell';
o._lastValidRowIndex = 0;
o._lastRowIndex = 0;
if(o.selectable){
//Row navigation needs to be calculated according to TableFilter's validRowsIndex array
function onAfterSelection(et, selecteElm, e){
if(!o.validRowsIndex) return; //table is not filtered
var row = et.defaultSelection != 'row' ? selecteElm.parentNode : selecteElm;
var cell = selecteElm.nodeName=='TD' ? selecteElm : null; //cell for default_selection = 'both' or 'cell'
var keyCode = e != undefined ? et.Event.GetKey(e) : 0;
var isRowValid = o.validRowsIndex.tf_Has(row.rowIndex);
var nextRowIndex;
var d = (keyCode == 34 || keyCode == 33 ? (o.pagingLength || et.nbRowsPerPage) : 1); //pgup/pgdown keys
//If next row is not valid, next valid filtered row needs to be calculated
if(!isRowValid){
//Selection direction up/down
if(row.rowIndex>o._lastRowIndex){
if(row.rowIndex >= o.validRowsIndex[o.validRowsIndex.length-1]) //last row
nextRowIndex = o.validRowsIndex[o.validRowsIndex.length-1];
else{
var calcRowIndex = (o._lastValidRowIndex + d);
if(calcRowIndex > (o.validRowsIndex.length-1))
nextRowIndex = o.validRowsIndex[o.validRowsIndex.length-1];
else nextRowIndex = o.validRowsIndex[calcRowIndex];
}
} else{
if(row.rowIndex < o.validRowsIndex[0]) nextRowIndex = o.validRowsIndex[0];//first row
else{
var v = o.validRowsIndex[o._lastValidRowIndex - d];
nextRowIndex = v ? v : o.validRowsIndex[0];
}
}
o._lastRowIndex = row.rowIndex;
DoSelection(nextRowIndex);
} else{
//If filtered row is valid, special calculation for pgup/pgdown keys
if(keyCode!=34 && keyCode!=33){
o._lastValidRowIndex = o.validRowsIndex.tf_IndexByValue(row.rowIndex);
o._lastRowIndex = row.rowIndex;
} else {
if(keyCode == 34){ //pgdown
if((o._lastValidRowIndex + d) <= (o.validRowsIndex.length-1)) //last row
nextRowIndex = o.validRowsIndex[o._lastValidRowIndex + d];
else nextRowIndex = o.validRowsIndex[o.validRowsIndex.length-1];
} else { //pgup
if((o._lastValidRowIndex - d) < (o.validRowsIndex[0])) //first row
nextRowIndex = o.validRowsIndex[0];
else nextRowIndex = o.validRowsIndex[o._lastValidRowIndex - d];
}
o._lastRowIndex = nextRowIndex;
o._lastValidRowIndex = o.validRowsIndex.tf_IndexByValue(nextRowIndex);
DoSelection(nextRowIndex);
}
}
//Next valid filtered row needs to be selected
function DoSelection(nextRowIndex){
if(et.defaultSelection == 'row'){
et.Selection.SelectRowByIndex(nextRowIndex);
} else {
et.ClearSelections();
var cellIndex = selecteElm.cellIndex;
var row = o.tbl.rows[nextRowIndex];
if(et.defaultSelection == 'both') et.Selection.SelectRowByIndex(nextRowIndex);
if(row) et.Selection.SelectCell(row.cells[cellIndex]);
}
//Table is filtered
if(o.validRowsIndex.length != o.GetRowsNb()){
var row = o.tbl.rows[nextRowIndex];
if(row) row.scrollIntoView(false);
if(cell){
if(cell.cellIndex==(o.GetCellsNb()-1) && o.gridLayout) o.tblCont.scrollLeft = 100000000;
else if(cell.cellIndex==0 && o.gridLayout) o.tblCont.scrollLeft = 0;
else cell.scrollIntoView(false);
}
}
}
}
//Page navigation has to be enforced whenever selected row is out of the current page range
function onBeforeSelection(et, selecteElm, e){
var row = et.defaultSelection != 'row' ? selecteElm.parentNode : selecteElm;
if(o.paging){
if(o.nbPages>1){
et.nbRowsPerPage = o.pagingLength; //page length is re-assigned in case it has changed
var pagingEndRow = parseInt(o.startPagingRow) + parseInt(o.pagingLength);
var rowIndex = row.rowIndex;
if((rowIndex == o.validRowsIndex[o.validRowsIndex.length-1]) && o.currentPageNb!=o.nbPages) o.SetPage('last');
else if((rowIndex == o.validRowsIndex[0]) && o.currentPageNb!=1) o.SetPage('first');
else if(rowIndex > o.validRowsIndex[pagingEndRow-1] && rowIndex < o.validRowsIndex[o.validRowsIndex.length-1]) o.SetPage('next');
else if(rowIndex < o.validRowsIndex[o.startPagingRow] && rowIndex > o.validRowsIndex[0]) o.SetPage('previous');
}
}
}
//Selected row needs to be visible when paging is activated
if(o.paging){
o.onAfterChangePage = function(tf, i){
var row = tf.ezEditTable.Selection.GetActiveRow();
if(row) row.scrollIntoView(false);
var cell = tf.ezEditTable.Selection.GetActiveCell();
if(cell) cell.scrollIntoView(false);
}
}
//Rows navigation when rows are filtered is performed with the EditTable row selection callback events
if(o.ezEditTableConfig.default_selection=='row'){
var fnB = o.ezEditTableConfig.on_before_selected_row;
o.ezEditTableConfig.on_before_selected_row = function(){
onBeforeSelection(arguments[0], arguments[1], arguments[2]);
if(fnB) fnB.call(null, arguments[0], arguments[1], arguments[2]);
};
var fnA = o.ezEditTableConfig.on_after_selected_row;
o.ezEditTableConfig.on_after_selected_row = function(){
onAfterSelection(arguments[0], arguments[1], arguments[2]);
if(fnA) fnA.call(null, arguments[0], arguments[1], arguments[2]);
};
} else {
var fnB = o.ezEditTableConfig.on_before_selected_cell;
o.ezEditTableConfig.on_before_selected_cell = function(){
onBeforeSelection(arguments[0], arguments[1], arguments[2]);
if(fnB) fnB.call(null, arguments[0], arguments[1], arguments[2]);
};
var fnA = o.ezEditTableConfig.on_after_selected_cell;
o.ezEditTableConfig.on_after_selected_cell = function(){
onAfterSelection(arguments[0], arguments[1], arguments[2]);
if(fnA) fnA.call(null, arguments[0], arguments[1], arguments[2]);
};
}
}
if(o.editable){
//Added or removed rows, TF rows number needs to be re-calculated
var fnC = o.ezEditTableConfig.on_added_dom_row;
o.ezEditTableConfig.on_added_dom_row = function(){
o.nbFilterableRows++;
if(!o.paging){ o.RefreshNbRows(); }
else {
o.nbRows++; o.nbVisibleRows++; o.nbFilterableRows++;
o.paging=false; o.RemovePaging(); o.AddPaging(false);
}
if(o.alternateBgs) o.SetAlternateRows();
if(fnC) fnC.call(null, arguments[0], arguments[1], arguments[2]);
};
if(o.ezEditTableConfig.actions && o.ezEditTableConfig.actions['delete']){
var fnD = o.ezEditTableConfig.actions['delete'].on_after_submit;
o.ezEditTableConfig.actions['delete'].on_after_submit = function(){
o.nbFilterableRows--;
if(!o.paging){ o.RefreshNbRows(); }
else {
o.nbRows--; o.nbVisibleRows--; o.nbFilterableRows--;
o.paging=false; o.RemovePaging(); o.AddPaging(false);
}
if(o.alternateBgs) o.SetAlternateRows();
if(fnD) fnD.call(null, arguments[0], arguments[1]);
}
}
}
try{
o.ezEditTable = new EditTable(o.id, o.ezEditTableConfig, startRow);
o.ezEditTable.Init();
} catch(e) { alert(o.ezEditTableConfig.err); }
}

View file

@ -1,95 +0,0 @@
/*------------------------------------------------------------------------
- HTML Table Filter Generator
- Fixed headers feature v1.0 - Deprecated!
- By Max Guglielmi (tablefilter.free.fr)
- Licensed under the MIT License
-------------------------------------------------------------------------*/
TF.prototype.SetFixedHeaders = function()
/*====================================================
- CSS solution making headers fixed
=====================================================*/
{
if((!this.hasGrid && !this.isFirstLoad) || !this.fixedHeaders) return;
if(this.contDiv) return;
var thead = tf_Tag(this.tbl,'thead');
if( thead.length==0 ) return;
var tbody = tf_Tag(this.tbl,'tbody');
if( tbody[0].clientHeight!=0 )
{//firefox returns tbody height
//previous values
this.prevTBodyH = tbody[0].clientHeight;
this.prevTBodyOverflow = tbody[0].style.overflow;
this.prevTBodyOverflowX = tbody[0].style.overflowX;
tbody[0].style.height = this.tBodyH+'px';
tbody[0].style.overflow = 'auto';
tbody[0].style.overflowX = 'hidden';
} else { //IE returns 0
// cont div is added to emulate fixed headers behaviour
var contDiv = tf_CreateElm( 'div',['id',this.prfxContentDiv+this.id] );
contDiv.className = this.contDivCssClass;
this.tbl.parentNode.insertBefore(contDiv, this.tbl);
contDiv.appendChild(this.tbl);
this.contDiv = tf_Id(this.prfxContentDiv+this.id);
//prevents headers moving during window scroll (IE)
this.contDiv.style.position = 'relative';
var theadH = 0;
var theadTr = tf_Tag(thead[0],'tr');
for(var i=0; i<theadTr.length; i++)
{//css below emulates fixed headers on IE<=6
theadTr[i].style.cssText += 'position:relative; ' +
'top:expression(offsetParent.scrollTop);';
theadH += parseInt(theadTr[i].clientHeight);
}
this.contDiv.style.height = (this.tBodyH+theadH)+'px';
var tfoot = tf_Tag(this.tbl,'tfoot');
if( tfoot.length==0 ) return;
var tfootTr = tf_Tag(tfoot[0],'tr');
for(var j=0; j<tfootTr.length; j++)//css below emulates fixed footer on IE<=6
tfootTr[j].style.cssText += 'position:relative; overflow-x: hidden; ' +
'top: expression(parentNode.parentNode.offsetHeight >= ' +
'offsetParent.offsetHeight ? 0 - parentNode.parentNode.offsetHeight + '+
'offsetParent.offsetHeight + offsetParent.scrollTop : 0);';
}
}
TF.prototype.RemoveFixedHeaders = function()
/*====================================================
- Removes fixed headers
=====================================================*/
{
if(!this.hasGrid || !this.fixedHeaders ) return;
if( this.contDiv )//IE additional div
{
this.contDiv.parentNode.insertBefore(this.tbl, this.contDiv);
this.contDiv.parentNode.removeChild( this.contDiv );
this.contDiv = null;
var thead = tf_Tag(this.tbl,'thead');
if( thead.length==0 ) return;
var theadTr = tf_Tag(thead[0],'tr');
if( theadTr.length==0 ) return;
for(var i=0; i<theadTr.length; i++)
theadTr[i].style.cssText = '';
var tfoot = tf_Tag(this.tbl,'tfoot');
if( tfoot.length==0 ) return;
var tfootTr = tf_Tag(tfoot[0],'tr');
for(var j=0; j<tfootTr.length; j++)
{
tfootTr[j].style.position = 'relative';
tfootTr[j].style.top = '';
tfootTr[j].style.overeflowX = '';
}
} else {
var tbody = tf_Tag(this.tbl,'tbody');
if( tbody.length==0 ) return;
tbody[0].style.height = this.prevTBodyH+'px';
tbody[0].style.overflow = this.prevTBodyOverflow;
tbody[0].style.overflowX = this.prevTBodyOverflowX;
}
}

View file

@ -1,307 +0,0 @@
/*------------------------------------------------------------------------
- HTML Table Filter Generator
- Grid Layout feature v1.2
- By Max Guglielmi (tablefilter.free.fr)
- Licensed under the MIT License
-------------------------------------------------------------------------*/
TF.prototype.SetGridLayout = function()
/*====================================================
- generates a grid with fixed headers
=====================================================*/
{
if(!this.gridLayout) return;
var f = this.fObj;
this.gridWidth = f.grid_width!=undefined ? f.grid_width : null; //defines grid width
this.gridHeight = f.grid_height!=undefined ? f.grid_height : null; //defines grid height
this.gridMainContCssClass = f.grid_cont_css_class!=undefined //defines css class for main container
? f.grid_cont_css_class : 'grd_Cont';
this.gridContCssClass = f.grid_tbl_cont_css_class!=undefined //defines css class for div containing table
? f.grid_tbl_cont_css_class : 'grd_tblCont';
this.gridHeadContCssClass = f.grid_tblHead_cont_css_class!=undefined //defines css class for div containing headers' table
? f.grid_tblHead_cont_css_class : 'grd_headTblCont';
this.gridInfDivCssClass = f.grid_inf_grid_css_class!=undefined //defines css class for div containing rows counter, paging etc.
? f.grid_inf_grid_css_class : 'grd_inf';
this.gridHeadRowIndex = f.grid_headers_row_index!=undefined //defines which row contains column headers
? f.grid_headers_row_index : 0;
this.gridHeadRows = f.grid_headers_rows!=undefined //array of headers row indexes to be placed in header table
? f.grid_headers_rows : [0];
this.gridEnableFilters = f.grid_enable_default_filters!=undefined
? f.grid_enable_default_filters : true; //generate filters in table headers
this.gridDefaultColWidth = f.grid_default_col_width!=undefined
? f.grid_default_col_width : '100px'; //default col width
this.gridEnableColResizer = f.grid_enable_cols_resizer!=undefined
? f.grid_enable_cols_resizer : true; //enables/disables columns resizer
this.gridColResizerPath = f.grid_cont_col_resizer_path!=undefined //defines col resizer script path
? f.grid_cont_col_resizer_path : this.basePath+'TFExt_ColsResizer/TFExt_ColsResizer.js';
if(!this.hasColWidth){// in case column widths are not set default width 100px
this.colWidth = [];
for(var k=0; k<this.nbCells; k++){
var colW, cell = this.tbl.rows[this.gridHeadRowIndex].cells[k];
if(cell.width!='') colW = cell.width;
else if(cell.style.width!='') colW = parseInt(cell.style.width);
else colW = this.gridDefaultColWidth;
this.colWidth[k] = colW;
}
this.hasColWidth = true;
}
this.SetColWidths(this.gridHeadRowIndex);
var tblW;//initial table width
if(this.tbl.width!='') tblW = this.tbl.width;
else if(this.tbl.style.width!='') tblW = parseInt(this.tbl.style.width);
else tblW = this.tbl.clientWidth;
//Main container: it will contain all the elements
this.tblMainCont = tf_CreateElm('div',['id', this.prfxMainTblCont + this.id]);
this.tblMainCont.className = this.gridMainContCssClass;
if(this.gridWidth) this.tblMainCont.style.width = this.gridWidth;
this.tbl.parentNode.insertBefore(this.tblMainCont, this.tbl);
//Table container: div wrapping content table
this.tblCont = tf_CreateElm('div',['id', this.prfxTblCont + this.id]);
this.tblCont.className = this.gridContCssClass;
if(this.gridWidth) this.tblCont.style.width = this.gridWidth;
if(this.gridHeight) this.tblCont.style.height = this.gridHeight;
this.tbl.parentNode.insertBefore(this.tblCont, this.tbl);
var t = this.tbl.parentNode.removeChild(this.tbl);
this.tblCont.appendChild(t);
//In case table width is expressed in %
if(this.tbl.style.width == '')
this.tbl.style.width = (this.__containsStr('%',tblW)
? this.tbl.clientWidth : tblW) + 'px';
var d = this.tblCont.parentNode.removeChild(this.tblCont);
this.tblMainCont.appendChild(d);
//Headers table container: div wrapping headers table
this.headTblCont = tf_CreateElm('div',['id', this.prfxHeadTblCont + this.id]);
this.headTblCont.className = this.gridHeadContCssClass;
if(this.gridWidth) this.headTblCont.style.width = this.gridWidth;
//Headers table
this.headTbl = tf_CreateElm('table',['id', this.prfxHeadTbl + this.id]);
var tH = tf_CreateElm('tHead'); //IE<7 needs it
//1st row should be headers row, ids are added if not set
//Those ids are used by the sort feature
var hRow = this.tbl.rows[this.gridHeadRowIndex];
var sortTriggers = [];
for(var n=0; n<this.nbCells; n++){
var cell = hRow.cells[n];
var thId = cell.getAttribute('id');
if(!thId || thId==''){
thId = this.prfxGridTh+n+'_'+this.id
cell.setAttribute('id', thId);
}
sortTriggers.push(thId);
}
//Filters row is created
var filtersRow = tf_CreateElm('tr');
if(this.gridEnableFilters && this.fltGrid){
this.externalFltTgtIds = [];
for(var j=0; j<this.nbCells; j++)
{
var fltTdId = this.prfxFlt+j+ this.prfxGridFltTd +this.id;
var c = tf_CreateElm(this.fltCellTag, ['id', fltTdId]);
filtersRow.appendChild(c);
this.externalFltTgtIds[j] = fltTdId;
}
}
//Headers row are moved from content table to headers table
for(var i=0; i<this.gridHeadRows.length; i++)
{
var headRow = this.tbl.rows[this.gridHeadRows[0]];
tH.appendChild(headRow);
}
this.headTbl.appendChild(tH);
if(this.filtersRowIndex == 0) tH.insertBefore(filtersRow,hRow);
else tH.appendChild(filtersRow);
this.headTblCont.appendChild(this.headTbl);
this.tblCont.parentNode.insertBefore(this.headTblCont, this.tblCont);
//THead needs to be removed in content table for sort feature
var thead = tf_Tag(this.tbl,'thead');
if( thead.length>0 ) this.tbl.removeChild(thead[0]);
//Headers table style
this.headTbl.style.width = this.tbl.style.width;
this.headTbl.style.tableLayout = 'fixed';
this.tbl.style.tableLayout = 'fixed';
this.headTbl.cellPadding = this.tbl.cellPadding;
this.headTbl.cellSpacing = this.tbl.cellSpacing;
//Headers container width
this.headTblCont.style.width = this.tblCont.clientWidth+'px';
//content table without headers needs col widths to be reset
this.SetColWidths();
this.tbl.style.width = '';
if(tf_isIE || tf_isIE7) this.headTbl.style.width = '';
//scroll synchronisation
var o = this; //TF object
this.tblCont.onscroll = function(){
o.headTblCont.scrollLeft = this.scrollLeft;
var _o = this; //this = scroll element
//New pointerX calc taking into account scrollLeft
if(!o.isPointerXOverwritten){
try{
TF.Evt.pointerX = function(e)
{
e = e || window.event;
var scrollLeft = tf_StandardBody().scrollLeft + _o.scrollLeft;
return (e.pageX + _o.scrollLeft) || (e.clientX + scrollLeft);
}
o.isPointerXOverwritten = true;
} catch(ee) {
o.isPointerXOverwritten = false;
}
}
}
/*** Default behaviours activation ***/
var f = this.fObj==undefined ? {} : this.fObj;
//Sort is enabled if not specified in config object
if(f.sort != false){
this.sort = true;
this.sortConfig.asyncSort = true;
this.sortConfig.triggerIds = sortTriggers;
}
if(this.gridEnableColResizer){
if(!this.hasExtensions){
this.extensions = {
name:['ColumnsResizer_'+this.id],
src:[this.gridColResizerPath],
description:['Columns Resizing'],
initialize:[function(o){ o.SetColsResizer('ColumnsResizer_'+o.id); }]
}
this.hasExtensions = true;
} else {
if(!this.__containsStr('colsresizer',this.extensions.src.toString().tf_LCase())){
this.extensions.name.push('ColumnsResizer_'+this.id);
this.extensions.src.push(this.gridColResizerPath);
this.extensions.description.push('Columns Resizing');
this.extensions.initialize.push(function(o){o.SetColsResizer('ColumnsResizer_'+o.id);});
}
}
}
//Default columns resizer properties for grid layout
f.col_resizer_cols_headers_table = this.headTbl.getAttribute('id');
f.col_resizer_cols_headers_index = this.gridHeadRowIndex;
f.col_resizer_width_adjustment = 0;
f.col_enable_text_ellipsis = false;
//Cols generation for all browsers excepted IE<=7
o.tblHasColTag = (tf_Tag(o.tbl,'col').length > 0) ? true : false;
if(!tf_isIE && !tf_isIE7){
//Col elements are enough to keep column widths after sorting and filtering
function createColTags(o)
{
if(!o) return;
for(var k=(o.nbCells-1); k>=0; k--)
{
var col = tf_CreateElm( 'col', ['id', o.id+'_col_'+k]);
o.tbl.firstChild.parentNode.insertBefore(col,o.tbl.firstChild);
col.style.width = o.colWidth[k];
o.gridColElms[k] = col;
}
o.tblHasColTag = true;
}
if(!o.tblHasColTag) createColTags(o);
else{
var cols = tf_Tag(o.tbl,'col');
for(var i=0; i<o.nbCells; i++){
cols[i].setAttribute('id', o.id+'_col_'+i);
cols[i].style.width = o.colWidth[i];
o.gridColElms.push(cols[i]);
}
}
}
//IE <= 7 needs an additional row for widths as col element width is not enough...
if(tf_isIE || tf_isIE7){
var tbody = tf_Tag(o.tbl,'tbody'), r;
if( tbody.length>0 ) r = tbody[0].insertRow(0);
else r = o.tbl.insertRow(0);
r.style.height = '0px';
for(var i=0; i<o.nbCells; i++){
var col = tf_CreateElm('td', ['id', o.id+'_col_'+i]);
col.style.width = o.colWidth[i];
o.tbl.rows[1].cells[i].style.width = '';
r.appendChild(col);
o.gridColElms.push(col);
}
this.hasGridWidthsRow = true;
//Data table row with widths expressed
o.leadColWidthsRow = o.tbl.rows[0];
o.leadColWidthsRow.setAttribute('validRow','false');
var beforeSortFn = tf_IsFn(f.on_before_sort) ? f.on_before_sort : null;
f.on_before_sort = function(o,colIndex){
o.leadColWidthsRow.setAttribute('validRow','false');
if(beforeSortFn!=null) beforeSortFn.call(null,o,colIndex);
}
var afterSortFn = tf_IsFn(f.on_after_sort) ? f.on_after_sort : null;
f.on_after_sort = function(o,colIndex){
if(o.leadColWidthsRow.rowIndex != 0){
var r = o.leadColWidthsRow;
if( tbody.length>0 )
tbody[0].moveRow(o.leadColWidthsRow.rowIndex, 0);
else o.tbl.moveRow(o.leadColWidthsRow.rowIndex, 0);
}
if(afterSortFn!=null) afterSortFn.call(null,o,colIndex);
}
}
var afterColResizedFn = tf_IsFn(f.on_after_col_resized) ? f.on_after_col_resized : null;
f.on_after_col_resized = function(o,colIndex){
if(colIndex==undefined) return;
var w = o.crWColsRow.cells[colIndex].style.width;
var col = o.gridColElms[colIndex];
col.style.width = w;
var thCW = o.crWColsRow.cells[colIndex].clientWidth;
var tdCW = o.crWRowDataTbl.cells[colIndex].clientWidth;
if(tf_isIE || tf_isIE7)
o.tbl.style.width = o.headTbl.clientWidth+'px';
if(thCW != tdCW && !tf_isIE && !tf_isIE7)
o.headTbl.style.width = o.tbl.clientWidth+'px';
if(afterColResizedFn!=null) afterColResizedFn.call(null,o,colIndex);
}
if(this.tbl.clientWidth != this.headTbl.clientWidth)
this.tbl.style.width = this.headTbl.clientWidth+'px';
}
TF.prototype.RemoveGridLayout = function()
/*====================================================
- removes the grid layout
=====================================================*/
{
if(!this.gridLayout) return;
var t = this.tbl.parentNode.removeChild(this.tbl);
this.tblMainCont.parentNode.insertBefore(t, this.tblMainCont);
this.tblMainCont.parentNode.removeChild( this.tblMainCont );
this.tblMainCont = null;
this.headTblCont = null;
this.headTbl = null;
this.tblCont = null;
this.tbl.outerHTML = this.sourceTblHtml;
this.tbl = tf_Id(this.id); //needed to keep reference
}

View file

@ -1,97 +0,0 @@
/*------------------------------------------------------------------------
- HTML Table Filter Generator
- Highlight keywords feature v1.2
- By Max Guglielmi (tablefilter.free.fr)
- Licensed under the MIT License
-------------------------------------------------------------------------*/
TF.prototype.UnhighlightAll = function()
/*====================================================
- removes keyword highlighting
=====================================================*/
{
if( this.highlightKeywords && this.searchArgs!=null ){
for(var y=0; y<this.searchArgs.length; y++){
tf_UnhighlightWord(this, this.searchArgs[y], this.highlightCssClass);
}
this.highlightedNodes = [];
}
}
function tf_HighlightWord( node,word,cssClass,o )
/*====================================================
- highlights keyword found in passed node
- accepts the following params:
- node
- word to search
- css class name for highlighting
=====================================================*/
{
// Iterate into this nodes childNodes
if(node.hasChildNodes)
for( var i=0; i<node.childNodes.length; i++ )
tf_HighlightWord(node.childNodes[i],word,cssClass,o);
// And do this node itself
if(node.nodeType == 3)
{ // text node
var tempNodeVal = node.nodeValue.tf_LCase();
var tempWordVal = word.tf_LCase();
if(tempNodeVal.indexOf(tempWordVal) != -1)
{
var pn = node.parentNode;
if(pn && pn.className != cssClass)
{
// word has not already been highlighted!
var nv = node.nodeValue;
var ni = tempNodeVal.indexOf(tempWordVal);
// Create a load of replacement nodes
var before = tf_CreateText(nv.substr(0,ni));
var docWordVal = nv.substr(ni,word.length);
var after = tf_CreateText(nv.substr(ni+word.length));
var hiwordtext = tf_CreateText(docWordVal);
var hiword = tf_CreateElm('span');
hiword.className = cssClass;
hiword.appendChild(hiwordtext);
pn.insertBefore(before,node);
pn.insertBefore(hiword,node);
pn.insertBefore(after,node);
pn.removeChild(node);
o.highlightedNodes.push(hiword.firstChild);
}
}
}// if node.nodeType == 3
}
function tf_UnhighlightWord( o,word,cssClass )
/*====================================================
- removes highlights found in passed node
- accepts the following params:
- node
- word to search
- css class name for highlighting
=====================================================*/
{
var arrRemove = [];
for(var i=0; i<o.highlightedNodes.length; i++){
var n = o.highlightedNodes[i];
if(!n){ continue; }
var tempNodeVal = n.nodeValue.tf_LCase();
var tempWordVal = word.tf_LCase();
if(tempNodeVal.indexOf(tempWordVal) != -1){
var pn = n.parentNode;
if(pn && pn.className == cssClass){
var prevSib = pn.previousSibling;
var nextSib = pn.nextSibling;
if(!prevSib || !nextSib){ continue; }
nextSib.nodeValue = prevSib.nodeValue + n.nodeValue + nextSib.nodeValue;
prevSib.nodeValue = '';
n.nodeValue = '';
arrRemove.push(i);
}
}
}
for(var k=0; k<arrRemove.length; k++){
o.highlightedNodes.splice(arrRemove[k], 1);
}
}

View file

@ -1,72 +0,0 @@
/*------------------------------------------------------------------------
- HTML Table Filter Generator
- Loader feature v1.1
- By Max Guglielmi (tablefilter.free.fr)
- Licensed under the MIT License
-------------------------------------------------------------------------*/
TF.prototype.SetLoader = function()
/*====================================================
- generates loader div
=====================================================*/
{
if( this.loaderDiv!=null ) return;
var f = this.fObj;
this.loaderTgtId = f.loader_target_id!=undefined //id of container element
? f.loader_target_id : null;
this.loaderDiv = null; //div containing loader
this.loaderText = f.loader_text!=undefined ? f.loader_text : 'Loading...'; //defines loader text
this.loaderHtml = f.loader_html!=undefined ? f.loader_html : null; //defines loader innerHtml
this.loaderCssClass = f.loader_css_class!=undefined //defines css class for loader div
? f.loader_css_class : 'loader';
this.loaderCloseDelay = 200; //delay for hiding loader
this.onShowLoader = tf_IsFn(f.on_show_loader) //calls function before loader is displayed
? f.on_show_loader : null;
this.onHideLoader = tf_IsFn(f.on_hide_loader) //calls function after loader is closed
? f.on_hide_loader : null;
var containerDiv = tf_CreateElm( 'div',['id',this.prfxLoader+this.id] );
containerDiv.className = this.loaderCssClass;// for ie<=6
//containerDiv.style.display = 'none';
var targetEl = (this.loaderTgtId==null)
? (this.gridLayout ? this.tblCont : this.tbl.parentNode) : tf_Id( this.loaderTgtId );
if(this.loaderTgtId==null) targetEl.insertBefore(containerDiv, this.tbl);
else targetEl.appendChild( containerDiv );
this.loaderDiv = tf_Id(this.prfxLoader+this.id);
if(this.loaderHtml==null)
this.loaderDiv.appendChild( tf_CreateText(this.loaderText) );
else this.loaderDiv.innerHTML = this.loaderHtml;
}
TF.prototype.RemoveLoader = function()
/*====================================================
- removes loader div
=====================================================*/
{
if( this.loaderDiv==null ) return;
var targetEl = (this.loaderTgtId==null)
? (this.gridLayout ? this.tblCont : this.tbl.parentNode) : tf_Id( this.loaderTgtId );
targetEl.removeChild(this.loaderDiv);
this.loaderDiv = null;
}
TF.prototype.ShowLoader = function(p)
/*====================================================
- displays/hides loader div
=====================================================*/
{
if(!this.loader || !this.loaderDiv) return;
if(this.loaderDiv.style.display==p) return;
var o = this;
function displayLoader(){
if(!o.loaderDiv) return;
if(o.onShowLoader && p!='none')
o.onShowLoader.call(null,o);
o.loaderDiv.style.display = p;
if(o.onHideLoader && p=='none')
o.onHideLoader.call(null,o);
}
var t = (p=='none') ? this.loaderCloseDelay : 1;
window.setTimeout(displayLoader,t);
}

2
dist/filtergrid.css vendored
View file

@ -1,6 +1,6 @@
/*------------------------------------------------------------------------
- TableFilter stylesheet by Max Guglielmi
- (build date: Sat Nov 15 2014 19:34:47)
- (build date: Sun Nov 16 2014 01:27:22)
- Edit below for your projects' needs
------------------------------------------------------------------------*/

10
dist/tablefilter.js vendored

File diff suppressed because one or more lines are too long

View file

@ -3,6 +3,7 @@
"version": "3.0.0",
"devDependencies": {
"grunt": "~0.4.0",
"grunt-6to5": "^1.0.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-cssmin": "~0.6.1",

View file

@ -723,7 +723,9 @@ function TableFilter(id) {
- onkeyup event for text filters
=====================================================*/
_OnKeyUp: function(e) {
if(!o.onKeyUp) return;
if(!o.onKeyUp){
return;
}
var _evt = e || global.event;
var key = o.Evt.getKeyCode(_evt);
o.isUserTyping = false;
@ -769,8 +771,12 @@ function TableFilter(id) {
dom.addClass(this, o.inpWatermarkCssClass);
}
if(o.ezEditTable){
if(o.editable) o.ezEditTable.Editable.Set();
if(o.selectable) o.ezEditTable.Selection.Set();
if(o.editable){
o.ezEditTable.Editable.Set();
}
if(o.selectable){
o.ezEditTable.Selection.Set();
}
}
},
/*====================================================
@ -799,8 +805,12 @@ function TableFilter(id) {
evt.stop(_evt);
}
if(o.ezEditTable){
if(o.editable) o.ezEditTable.Editable.Remove();
if(o.selectable) o.ezEditTable.Selection.Remove();
if(o.editable){
o.ezEditTable.Editable.Remove();
}
if(o.selectable){
o.ezEditTable.Selection.Remove();
}
}
},
/*====================================================
@ -909,7 +919,9 @@ TableFilter.prototype = {
behaviours and layout
=====================================================*/
init: function(){
if(this.hasGrid) return;
if(this.hasGrid){
return;
}
if(this.gridLayout){
this.refRow = this.startRow===null ? 0 : this.startRow;
}
@ -941,7 +953,7 @@ TableFilter.prototype = {
}
if(this.loader){
var Loader = require('modules/loader');
var Loader = require('modules/loader').Loader;
this.Cpt.loader = new Loader(this);
}
@ -1217,12 +1229,12 @@ TableFilter.prototype = {
}
if(this.alternateBgs && this.isStartBgAlternate){
//1st time only if no paging and rememberGridValues
var AlternateRows = require('modules/alternateRows');
var AlternateRows = require('modules/alternateRows').AlternateRows;
this.Cpt.alternateRows = new AlternateRows(this);
this.Cpt.alternateRows.set();
}
if(this.hasColOperation){
var ColOps = require('modules/colOps');
var ColOps = require('modules/colOps').ColOps;
this.Cpt.colOps = new ColOps(this);
this.Cpt.colOps.set();
}
@ -2179,7 +2191,9 @@ TableFilter.prototype = {
o.ChangePage(prevIndex);
},
last: function(){
if(o.Evt._Paging.lastEvt) o.Evt._Paging.lastEvt();
if(o.Evt._Paging.lastEvt){
o.Evt._Paging.lastEvt();
}
o.ChangePage(o.Evt._Paging.nbOpts());
},
first: function(){
@ -2725,7 +2739,9 @@ TableFilter.prototype = {
helpdiv.className = this.helpInstrContCssClass;
helpdiv.ondblclick = this.Evt._OnHelpBtnClick;
} else {
if(this.helpInstrContTgtId) divContainer.appendChild(helpdiv);
if(this.helpInstrContTgtId){
divContainer.appendChild(helpdiv);
}
helpdiv.innerHTML = this.helpInstrHtml;
if(!this.helpInstrContTgtId){
helpdiv.className = this.helpInstrContCssClass;
@ -3023,7 +3039,9 @@ TableFilter.prototype = {
if(this.sortSlc && !isCustomSlc){
if (!matchCase){
optArray.sort(ignoreCaseSort);
if(excludedOpts) excludedOpts.sort(ignoreCaseSort);
if(excludedOpts){
excludedOpts.sort(ignoreCaseSort);
}
} else {
optArray.sort();
if(excludedOpts){ excludedOpts.sort(); }
@ -3184,11 +3202,15 @@ TableFilter.prototype = {
global.setTimeout(function(){
slc.options[0].selected = false;
if(slc.options[index].value==='')
if(slc.options[index].value===''){
slc.options[index].selected = false;
else
slc.options[index].selected = true;
if(doFilter) o.Filter();
}
else{
slc.options[index].selected = true;
if(doFilter){
o.Filter();
}
}
}, 0.1);
},
@ -4649,7 +4671,9 @@ TableFilter.prototype = {
}
}//end for
if(!this.hasStoredValues && this.paging) this.SetPagingInfo();
if(!this.hasStoredValues && this.paging){
this.SetPagingInfo();
}
}//end if
},
@ -4723,7 +4747,9 @@ TableFilter.prototype = {
- Removes fixed headers
=====================================================*/
RemoveFixedHeaders: function(){
if(!this.hasGrid || !this.fixedHeaders ) return;
if(!this.hasGrid || !this.fixedHeaders ){
return;
}
if(this.contDiv){
this.contDiv.parentNode.insertBefore(this.tbl, this.contDiv);

View file

@ -0,0 +1,99 @@
import * as dom from '../dom';
export class AlternateRows{
/**
* Alternating rows color
* @param {Object} tf TableFilter instance
*/
constructor(tf) {
var f = tf.fObj;
//defines css class for even rows
this.evenCss = f.even_row_css_class || 'even';
//defines css class for odd rows
this.oddCss = f.odd_row_css_class || 'odd';
this.tf = tf;
}
/**
* Sets alternating rows color
*/
set() {
if(!this.tf.hasGrid && !this.tf.isFirstLoad){
return;
}
var rows = this.tf.tbl.rows;
var noValidRowsIndex = this.tf.validRowsIndex===null;
//1st index
var beginIndex = noValidRowsIndex ? this.tf.refRow : 0;
// nb indexes
var indexLen = noValidRowsIndex ?
this.tf.nbFilterableRows+beginIndex :
this.tf.validRowsIndex.length;
var idx = 0;
//alternates bg color
for(var j=beginIndex; j<indexLen; j++){
var rowIdx = noValidRowsIndex ? j : this.tf.validRowsIndex[j];
this.setRowBg(rowIdx, idx);
idx++;
}
}
/**
* Sets row background color
* @param {Number} rowIdx Row index
* @param {Number} idx Valid rows collection index needed to calculate bg
* color
*/
setRowBg(rowIdx, idx) {
if(!this.tf.alternateBgs || isNaN(rowIdx)){
return;
}
var rows = this.tf.tbl.rows;
var i = !idx ? rowIdx : idx;
this.removeRowBg(rowIdx);
dom.addClass(
rows[rowIdx],
(i%2) ? this.evenCss : this.oddCss
);
}
/**
* Removes row background color
* @param {Number} idx Row index
*/
removeRowBg(idx) {
if(isNaN(idx)){
return;
}
var rows = this.tf.tbl.rows;
dom.removeClass(rows[idx], this.oddCss);
dom.removeClass(rows[idx], this.evenCss);
}
/**
* Removes all row background color
*/
remove() {
if(!this.tf.hasGrid){
return;
}
var row = this.tf.tbl.rows;
for(var i=this.tf.refRow; i<this.tf.nbRows; i++){
this.removeRowBg(i);
}
this.tf.isStartBgAlternate = true;
}
enable() {
this.tf.alternateBgs = true;
}
disable() {
this.tf.alternateBgs = false;
}
}

301
src/es6-modules/colOps.js Normal file
View file

@ -0,0 +1,301 @@
import * as dom from '../dom';
import * as str from '../string';
export class ColOps{
/**
* Column calculations
* @param {Object} tf TableFilter instance
*/
constructor(tf) {
var f = tf.fObj;
this.colOperation = f.col_operation;
this.tf = tf;
}
/**
* Calculates columns' values
* Configuration options are stored in 'colOperation' property
* - 'id' contains ids of elements showing result (array)
* - 'col' contains the columns' indexes (array)
* - 'operation' contains operation type (array, values: 'sum', 'mean',
* 'min', 'max', 'median', 'q1', 'q3')
* - 'write_method' array defines which method to use for displaying the
* result (innerHTML, setValue, createTextNode) - default: 'innerHTML'
* - 'tot_row_index' defines in which row results are displayed
* (integers array)
*
* - changes made by Nuovella:
* (1) optimized the routine (now it will only process each column once),
* (2) added calculations for the median, lower and upper quartile.
*/
set() {
if(!this.tf.isFirstLoad && !this.tf.hasGrid){
return;
}
if(this.tf.onBeforeOperation){
this.tf.onBeforeOperation.call(null, this.tf);
}
var colOperation = this.colOperation,
labelId = colOperation.id,
colIndex = colOperation.col,
operation = colOperation.operation,
outputType = colOperation.write_method,
totRowIndex = colOperation.tot_row_index,
excludeRow = colOperation.exclude_row,
decimalPrecision = colOperation.decimal_precision !== undefined ?
colOperation.decimal_precision : 2;
//nuovella: determine unique list of columns to operate on
var ucolIndex = [],
ucolMax = 0;
ucolIndex[ucolMax] = colIndex[0];
for(var ii=1; ii<colIndex.length; ii++){
var saved = 0;
//see if colIndex[ii] is already in the list of unique indexes
for(var jj=0; jj<=ucolMax; jj++){
if(ucolIndex[jj] === colIndex[ii]){
saved = 1;
}
}
//if not saved then, save the index;
if (saved === 0){
ucolMax++;
ucolIndex[ucolMax] = colIndex[ii];
}
}
if(str.lower(typeof labelId)=='object' &&
str.lower(typeof colIndex)=='object' &&
str.lower(typeof operation)=='object'){
var row = this.tf.tbl.rows,
colvalues = [];
for(var ucol=0; ucol<=ucolMax; ucol++){
//this retrieves col values
//use ucolIndex because we only want to pass through this loop
//once for each column get the values in this unique column
colvalues.push(
this.tf.GetColValues(ucolIndex[ucol], true, excludeRow));
//next: calculate all operations for this column
var result,
nbvalues=0,
temp,
meanValue=0,
sumValue=0,
minValue=null,
maxValue=null,
q1Value=null,
medValue=null,
q3Value=null,
meanFlag=0,
sumFlag=0,
minFlag=0,
maxFlag=0,
q1Flag=0,
medFlag=0,
q3Flag=0,
theList=[],
opsThisCol=[],
decThisCol=[],
labThisCol=[],
oTypeThisCol=[],
mThisCol=-1;
for(var k=0; k<colIndex.length; k++){
if(colIndex[k] === ucolIndex[ucol]){
mThisCol++;
opsThisCol[mThisCol]=str.lower(operation[k]);
decThisCol[mThisCol]=decimalPrecision[k];
labThisCol[mThisCol]=labelId[k];
oTypeThisCol = outputType !== undefined &&
str.lower(typeof outputType)==='object' ?
outputType[k] : null;
switch(opsThisCol[mThisCol]){
case 'mean':
meanFlag=1;
break;
case 'sum':
sumFlag=1;
break;
case 'min':
minFlag=1;
break;
case 'max':
maxFlag=1;
break;
case 'median':
medFlag=1;
break;
case 'q1':
q1Flag=1;
break;
case 'q3':
q3Flag=1;
break;
}
}
}
for(var j=0; j<colvalues[ucol].length; j++){
//sort the list for calculation of median and quartiles
if((q1Flag==1)|| (q3Flag==1) || (medFlag==1)){
if (j<colvalues[ucol].length -1){
for(k=j+1; k<colvalues[ucol].length; k++) {
if(eval(colvalues[ucol][k]) <
eval(colvalues[ucol][j])){
temp = colvalues[ucol][j];
colvalues[ucol][j] = colvalues[ucol][k];
colvalues[ucol][k] = temp;
}
}
}
}
var cvalue = parseFloat(colvalues[ucol][j]);
theList[j] = parseFloat(cvalue);
if(!isNaN(cvalue)){
nbvalues++;
if(sumFlag===1 || meanFlag===1){
sumValue += parseFloat( cvalue );
}
if(minFlag===1){
if(minValue===null){
minValue = parseFloat( cvalue );
} else{
minValue = parseFloat( cvalue ) < minValue ?
parseFloat( cvalue ): minValue;
}
}
if(maxFlag===1){
if (maxValue===null){
maxValue = parseFloat( cvalue );
} else {
maxValue = parseFloat( cvalue ) > maxValue ?
parseFloat( cvalue ): maxValue;
}
}
}
}//for j
if(meanFlag===1){
meanValue = sumValue/nbvalues;
}
if(medFlag===1){
var aux = 0;
if(nbvalues%2 === 1){
aux = Math.floor(nbvalues/2);
medValue = theList[aux];
} else{
medValue =
(theList[nbvalues/2] + theList[((nbvalues/2)-1)])/2;
}
}
var posa;
if(q1Flag===1){
posa=0.0;
posa = Math.floor(nbvalues/4);
if(4*posa == nbvalues){
q1Value = (theList[posa-1] + theList[posa])/2;
} else {
q1Value = theList[posa];
}
}
if (q3Flag===1){
posa=0.0;
var posb=0.0;
posa = Math.floor(nbvalues/4);
if (4*posa === nbvalues){
posb = 3*posa;
q3Value = (theList[posb] + theList[posb-1])/2;
} else {
q3Value = theList[nbvalues-posa-1];
}
}
for(var i=0; i<=mThisCol; i++){
switch( opsThisCol[i] ){
case 'mean':
result=meanValue;
break;
case 'sum':
result=sumValue;
break;
case 'min':
result=minValue;
break;
case 'max':
result=maxValue;
break;
case 'median':
result=medValue;
break;
case 'q1':
result=q1Value;
break;
case 'q3':
result=q3Value;
break;
}
var precision = !isNaN(decThisCol[i]) ? decThisCol[i] : 2;
//if outputType is defined
if(oTypeThisCol && result){
result = result.toFixed( precision );
if(dom.id(labThisCol[i])){
switch( str.lower(oTypeThisCol) ){
case 'innerhtml':
if (isNaN(result) || !isFinite(result) ||
nbvalues===0){
dom.id(labThisCol[i]).innerHTML = '.';
} else{
dom.id(labThisCol[i]).innerHTML = result;
}
break;
case 'setvalue':
dom.id( labThisCol[i] ).value = result;
break;
case 'createtextnode':
var oldnode = dom.id(labThisCol[i])
.firstChild;
var txtnode = dom.text(result);
dom.id(labThisCol[i])
.replaceChild(txtnode, oldnode);
break;
}//switch
}
} else {
try{
if(isNaN(result) || !isFinite(result) ||
nbvalues===0){
dom.id(labThisCol[i]).innerHTML = '.';
} else {
dom.id(labThisCol[i]).innerHTML =
result.toFixed(precision);
}
} catch(e) {}//catch
}//else
}//for i
// row(s) with result are always visible
var totRow = totRowIndex && totRowIndex[ucol] ?
row[totRowIndex[ucol]] : null;
if(totRow){
totRow.style.display = '';
}
}//for ucol
}//if typeof
if(this.tf.onAfterOperation){
this.tf.onAfterOperation.call(null, this.tf);
}
}
}

91
src/es6-modules/loader.js Normal file
View file

@ -0,0 +1,91 @@
import * as dom from '../dom';
import * as types from '../types';
var global = window;
/**
* Loading message/spinner
* @param {Object} tf TableFilter instance
*/
export class Loader{
constructor(tf){
// TableFilter configuration
var f = tf.fObj;
//id of container element
tf.loaderTgtId = f.loader_target_id || null;
//div containing loader
tf.loaderDiv = null;
//defines loader text
tf.loaderText = f.loader_text || 'Loading...';
//defines loader innerHtml
tf.loaderHtml = f.loader_html || null;
//defines css class for loader div
tf.loaderCssClass = f.loader_css_class || 'loader';
//delay for hiding loader
tf.loaderCloseDelay = 200;
//callback function before loader is displayed
tf.onShowLoader = types.isFn(f.on_show_loader) ?
f.on_show_loader : null;
//callback function after loader is closed
tf.onHideLoader = types.isFn(f.on_hide_loader) ?
f.on_hide_loader : null;
this.tf = tf;
var containerDiv = dom.create('div', ['id', tf.prfxLoader+tf.id]);
containerDiv.className = tf.loaderCssClass;
var targetEl = !tf.loaderTgtId ?
(tf.gridLayout ? tf.tblCont : tf.tbl.parentNode) :
dom.id(tf.loaderTgtId);
if(!tf.loaderTgtId){
targetEl.insertBefore(containerDiv, tf.tbl);
} else {
targetEl.appendChild(containerDiv);
}
tf.loaderDiv = dom.id(tf.prfxLoader+tf.id);
if(!tf.loaderHtml){
tf.loaderDiv.appendChild(dom.text(tf.loaderText));
} else {
tf.loaderDiv.innerHTML = tf.loaderHtml;
}
}
show(p) {
if(!this.tf.loader || !this.tf.loaderDiv ||
this.tf.loaderDiv.style.display===p){
return;
}
var o = this.tf;
function displayLoader(){
if(!o.loaderDiv){
return;
}
if(o.onShowLoader && p!=='none'){
o.onShowLoader.call(null, o);
}
o.loaderDiv.style.display = p;
if(o.onHideLoader && p==='none'){
o.onHideLoader.call(null, o);
}
}
var t = p==='none' ? this.tf.loaderCloseDelay : 1;
global.setTimeout(displayLoader, t);
}
remove(){
if(!this.tf.loaderDiv){
return;
}
var targetEl = !this.tf.loaderTgtId ?
(this.tf.gridLayout ? this.tf.tblCont : this.tf.tbl.parentNode):
dom.id(this.tf.loaderTgtId);
targetEl.removeChild(this.tf.loaderDiv);
this.tf.loaderDiv = null;
}
}

View file

@ -1,98 +1,98 @@
define(['../dom'], function (dom) {
'use strict';
define(["exports", "../dom"], function (exports, _dom) {
"use strict";
/**
* Alternating rows color
* @param {Object} tf TableFilter instance
*/
function AlternateRows(tf) {
var f = tf.fObj;
//defines css class for even rows
this.evenCss = f.even_row_css_class || 'even';
//defines css class for odd rows
this.oddCss = f.odd_row_css_class || 'odd';
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
this.tf = tf;
}
var dom = _dom;
var AlternateRows = (function () {
var AlternateRows = function AlternateRows(tf) {
var f = tf.fObj;
//defines css class for even rows
this.evenCss = f.even_row_css_class || "even";
//defines css class for odd rows
this.oddCss = f.odd_row_css_class || "odd";
/**
* Sets alternating rows color
*/
AlternateRows.prototype.set = function() {
if(!this.tf.hasGrid && !this.tf.isFirstLoad){
this.tf = tf;
};
_classProps(AlternateRows, null, {
set: {
writable: true,
value: function () {
if (!this.tf.hasGrid && !this.tf.isFirstLoad) {
return;
}
var rows = this.tf.tbl.rows;
var noValidRowsIndex = this.tf.validRowsIndex===null;
//1st index
var beginIndex = noValidRowsIndex ? this.tf.refRow : 0;
// nb indexes
var indexLen = noValidRowsIndex ?
this.tf.nbFilterableRows+beginIndex :
this.tf.validRowsIndex.length;
var idx = 0;
}
var rows = this.tf.tbl.rows;
var noValidRowsIndex = this.tf.validRowsIndex === null;
//1st index
var beginIndex = noValidRowsIndex ? this.tf.refRow : 0;
// nb indexes
var indexLen = noValidRowsIndex ? this.tf.nbFilterableRows + beginIndex : this.tf.validRowsIndex.length;
var idx = 0;
//alternates bg color
for(var j=beginIndex; j<indexLen; j++){
//alternates bg color
for (var j = beginIndex; j < indexLen; j++) {
var rowIdx = noValidRowsIndex ? j : this.tf.validRowsIndex[j];
this.setRowBg(rowIdx, idx);
idx++;
}
}
};
/**
* Sets row background color
* @param {Number} rowIdx Row index
* @param {Number} idx Valid rows collection index needed to calculate bg
* color
*/
AlternateRows.prototype.setRowBg = function(rowIdx, idx) {
if(!this.tf.alternateBgs || isNaN(rowIdx)){
},
setRowBg: {
writable: true,
value: function (rowIdx, idx) {
if (!this.tf.alternateBgs || isNaN(rowIdx)) {
return;
}
var rows = this.tf.tbl.rows;
var i = !idx ? rowIdx : idx;
this.removeRowBg(rowIdx);
dom.addClass(rows[rowIdx], (i % 2) ? this.evenCss : this.oddCss);
}
var rows = this.tf.tbl.rows;
var i = !idx ? rowIdx : idx;
this.removeRowBg(rowIdx);
dom.addClass(
rows[rowIdx],
(i%2) ? this.evenCss : this.oddCss
);
};
/**
* Removes row background color
* @param {Number} idx Row index
*/
AlternateRows.prototype.removeRowBg = function(idx) {
if(isNaN(idx)){
},
removeRowBg: {
writable: true,
value: function (idx) {
if (isNaN(idx)) {
return;
}
var rows = this.tf.tbl.rows;
dom.removeClass(rows[idx], this.oddCss);
dom.removeClass(rows[idx], this.evenCss);
}
var rows = this.tf.tbl.rows;
dom.removeClass(rows[idx], this.oddCss);
dom.removeClass(rows[idx], this.evenCss);
};
/**
* Removes all row background color
*/
AlternateRows.prototype.remove = function() {
if(!this.tf.hasGrid){
},
remove: {
writable: true,
value: function () {
if (!this.tf.hasGrid) {
return;
}
var row = this.tf.tbl.rows;
for(var i=this.tf.refRow; i<this.tf.nbRows; i++){
}
var row = this.tf.tbl.rows;
for (var i = this.tf.refRow; i < this.tf.nbRows; i++) {
this.removeRowBg(i);
}
this.tf.isStartBgAlternate = true;
}
this.tf.isStartBgAlternate = true;
};
AlternateRows.prototype.enable = function() {
this.tf.alternateBgs = true;
};
AlternateRows.prototype.disable = function() {
this.tf.alternateBgs = false;
};
},
enable: {
writable: true,
value: function () {
this.tf.alternateBgs = true;
}
},
disable: {
writable: true,
value: function () {
this.tf.alternateBgs = false;
}
}
});
return AlternateRows;
});
})();
exports.AlternateRows = AlternateRows;
});

View file

@ -0,0 +1 @@
{"version":3,"sources":["src/es6-modules/alternateRows.js"],"names":[],"mappings":";;;;;;;;MAAY,GAAG;MAEF,aAAa;QAAb,aAAa,GAMX,SANF,aAAa,CAMV,EAAE,EAAE;AACZ,UAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;;AAEhB,UAAI,CAAC,OAAO,GAAG,CAAC,CAAC,kBAAkB,IAAI,MAAM,CAAC;;AAE9C,UAAI,CAAC,MAAM,GAAG,CAAC,CAAC,iBAAiB,IAAI,KAAK,CAAC;;AAE3C,UAAI,CAAC,EAAE,GAAG,EAAE,CAAC;KAChB;;gBAdQ,aAAa;AAmBtB,SAAG;;eAAA,YAAG;AACF,cAAG,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,EAAC;AACxC,mBAAO;WACV;AACD,cAAI,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC;AAC5B,cAAI,gBAAgB,GAAG,IAAI,CAAC,EAAE,CAAC,cAAc,KAAG,IAAI,CAAC;;AAErD,cAAI,UAAU,GAAG,gBAAgB,GAAG,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;;AAEvD,cAAI,QAAQ,GAAG,gBAAgB,GACvB,IAAI,CAAC,EAAE,CAAC,gBAAgB,GAAC,UAAU,GACnC,IAAI,CAAC,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC;AACtC,cAAI,GAAG,GAAG,CAAC,CAAC;;;AAGZ,eAAI,IAAI,CAAC,GAAC,UAAU,EAAE,CAAC,GAAC,QAAQ,EAAE,CAAC,EAAE,EAAC;AAClC;AACA;AACA;WACH;SACJ;;AAQD,cAAQ;;eAAA,UAAC,MAAM,EAAE,GAAG,EAAE;AAClB,cAAG,CAAC,IAAI,CAAC,EAAE,CAAC,YAAY,IAAI,KAAK,CAAC,MAAM,CAAC,EAAC;AACtC,mBAAO;WACV;AACD,cAAI,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC;AAC5B,cAAI,CAAC,GAAG,CAAC,GAAG,GAAG,MAAM,GAAG,GAAG,CAAC;AAC5B,cAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AACzB,aAAG,CAAC,QAAQ,CACR,IAAI,CAAC,MAAM,CAAC,EACZ,CAAC,CAAC,GAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CACrC,CAAC;SACL;;AAMD,iBAAW;;eAAA,UAAC,GAAG,EAAE;AACb,cAAG,KAAK,CAAC,GAAG,CAAC,EAAC;AACV,mBAAO;WACV;AACD,cAAI,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC;AAC5B,aAAG,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;AACxC,aAAG,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;SAC5C;;AAKD,YAAM;;eAAA,YAAG;AACL,cAAG,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAC;AAChB,mBAAO;WACV;AACD,cAAI,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC;AAC3B,eAAI,IAAI,CAAC,GAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,GAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAC;AAC5C,gBAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;WACvB;AACD,cAAI,CAAC,EAAE,CAAC,kBAAkB,GAAG,IAAI,CAAC;SACrC;;AAED,YAAM;;eAAA,YAAG;AACL,cAAI,CAAC,EAAE,CAAC,YAAY,GAAG,IAAI,CAAC;SAC/B;;AAED,aAAO;;eAAA,YAAG;AACN,cAAI,CAAC,EAAE,CAAC,YAAY,GAAG,KAAK,CAAC;SAChC;;;;WA7FQ,aAAa;;;UAAb,aAAa,GAAb,aAAa","file":"src/es6-modules/alternateRows.js","sourcesContent":["import * as dom from '../dom';\r\n\r\nexport class AlternateRows{\r\n\r\n /**\r\n * Alternating rows color\r\n * @param {Object} tf TableFilter instance\r\n */\r\n constructor(tf) {\r\n var f = tf.fObj;\r\n //defines css class for even rows\r\n this.evenCss = f.even_row_css_class || 'even';\r\n //defines css class for odd rows\r\n this.oddCss = f.odd_row_css_class || 'odd';\r\n\r\n this.tf = tf;\r\n }\r\n\r\n /**\r\n * Sets alternating rows color\r\n */\r\n set() {\r\n if(!this.tf.hasGrid && !this.tf.isFirstLoad){\r\n return;\r\n }\r\n var rows = this.tf.tbl.rows;\r\n var noValidRowsIndex = this.tf.validRowsIndex===null;\r\n //1st index\r\n var beginIndex = noValidRowsIndex ? this.tf.refRow : 0;\r\n // nb indexes\r\n var indexLen = noValidRowsIndex ?\r\n this.tf.nbFilterableRows+beginIndex :\r\n this.tf.validRowsIndex.length;\r\n var idx = 0;\r\n\r\n //alternates bg color\r\n for(var j=beginIndex; j<indexLen; j++){\r\n var rowIdx = noValidRowsIndex ? j : this.tf.validRowsIndex[j];\r\n this.setRowBg(rowIdx, idx);\r\n idx++;\r\n }\r\n }\r\n\r\n /**\r\n * Sets row background color\r\n * @param {Number} rowIdx Row index\r\n * @param {Number} idx Valid rows collection index needed to calculate bg\r\n * color\r\n */\r\n setRowBg(rowIdx, idx) {\r\n if(!this.tf.alternateBgs || isNaN(rowIdx)){\r\n return;\r\n }\r\n var rows = this.tf.tbl.rows;\r\n var i = !idx ? rowIdx : idx;\r\n this.removeRowBg(rowIdx);\r\n dom.addClass(\r\n rows[rowIdx],\r\n (i%2) ? this.evenCss : this.oddCss\r\n );\r\n }\r\n\r\n /**\r\n * Removes row background color\r\n * @param {Number} idx Row index\r\n */\r\n removeRowBg(idx) {\r\n if(isNaN(idx)){\r\n return;\r\n }\r\n var rows = this.tf.tbl.rows;\r\n dom.removeClass(rows[idx], this.oddCss);\r\n dom.removeClass(rows[idx], this.evenCss);\r\n }\r\n\r\n /**\r\n * Removes all row background color\r\n */\r\n remove() {\r\n if(!this.tf.hasGrid){\r\n return;\r\n }\r\n var row = this.tf.tbl.rows;\r\n for(var i=this.tf.refRow; i<this.tf.nbRows; i++){\r\n this.removeRowBg(i);\r\n }\r\n this.tf.isStartBgAlternate = true;\r\n }\r\n\r\n enable() {\r\n this.tf.alternateBgs = true;\r\n }\r\n\r\n disable() {\r\n this.tf.alternateBgs = false;\r\n }\r\n\r\n}\r\n\r\n"]}

View file

@ -1,300 +1,249 @@
define(['../dom', '../string'], function (dom, str) {
'use strict';
define(["exports", "../dom", "../string"], function (exports, _dom, _string) {
"use strict";
/**
* Column calculations
* @param {Object} tf TableFilter instance
*/
function ColOps(tf) {
var f = tf.fObj;
this.colOperation = f.col_operation;
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
this.tf = tf;
}
var dom = _dom;
var str = _string;
var ColOps = (function () {
var ColOps = function ColOps(tf) {
var f = tf.fObj;
this.colOperation = f.col_operation;
/**
* Calculates columns' values
* Configuration options are stored in 'colOperation' property
* - 'id' contains ids of elements showing result (array)
* - 'col' contains the columns' indexes (array)
* - 'operation' contains operation type (array, values: 'sum', 'mean',
* 'min', 'max', 'median', 'q1', 'q3')
* - 'write_method' array defines which method to use for displaying the
* result (innerHTML, setValue, createTextNode) - default: 'innerHTML'
* - 'tot_row_index' defines in which row results are displayed
* (integers array)
*
* - changes made by Nuovella:
* (1) optimized the routine (now it will only process each column once),
* (2) added calculations for the median, lower and upper quartile.
*/
ColOps.prototype.set = function() {
if(!this.tf.isFirstLoad && !this.tf.hasGrid){
return;
}
if(this.tf.onBeforeOperation){
this.tf.onBeforeOperation.call(null, this.tf);
}
var colOperation = this.colOperation,
labelId = colOperation.id,
colIndex = colOperation.col,
operation = colOperation.operation,
outputType = colOperation.write_method,
totRowIndex = colOperation.tot_row_index,
excludeRow = colOperation.exclude_row,
decimalPrecision = colOperation.decimal_precision !== undefined ?
colOperation.decimal_precision : 2;
//nuovella: determine unique list of columns to operate on
var ucolIndex = [],
ucolMax = 0;
ucolIndex[ucolMax] = colIndex[0];
for(var ii=1; ii<colIndex.length; ii++){
var saved = 0;
//see if colIndex[ii] is already in the list of unique indexes
for(var jj=0; jj<=ucolMax; jj++){
if(ucolIndex[jj] === colIndex[ii]){
saved = 1;
}
}
//if not saved then, save the index;
if (saved === 0){
ucolMax++;
ucolIndex[ucolMax] = colIndex[ii];
}
}
if(str.lower(typeof labelId)=='object' &&
str.lower(typeof colIndex)=='object' &&
str.lower(typeof operation)=='object'){
var row = this.tf.tbl.rows,
colvalues = [];
for(var ucol=0; ucol<=ucolMax; ucol++){
//this retrieves col values
//use ucolIndex because we only want to pass through this loop
//once for each column get the values in this unique column
colvalues.push(
this.tf.GetColValues(ucolIndex[ucol], true, excludeRow));
//next: calculate all operations for this column
var result,
nbvalues=0,
temp,
meanValue=0,
sumValue=0,
minValue=null,
maxValue=null,
q1Value=null,
medValue=null,
q3Value=null,
meanFlag=0,
sumFlag=0,
minFlag=0,
maxFlag=0,
q1Flag=0,
medFlag=0,
q3Flag=0,
theList=[],
opsThisCol=[],
decThisCol=[],
labThisCol=[],
oTypeThisCol=[],
mThisCol=-1;
for(var k=0; k<colIndex.length; k++){
if(colIndex[k] === ucolIndex[ucol]){
mThisCol++;
opsThisCol[mThisCol]=str.lower(operation[k]);
decThisCol[mThisCol]=decimalPrecision[k];
labThisCol[mThisCol]=labelId[k];
oTypeThisCol = outputType !== undefined &&
str.lower(typeof outputType)==='object' ?
outputType[k] : null;
switch(opsThisCol[mThisCol]){
case 'mean':
meanFlag=1;
break;
case 'sum':
sumFlag=1;
break;
case 'min':
minFlag=1;
break;
case 'max':
maxFlag=1;
break;
case 'median':
medFlag=1;
break;
case 'q1':
q1Flag=1;
break;
case 'q3':
q3Flag=1;
break;
}
}
}
for(var j=0; j<colvalues[ucol].length; j++){
//sort the list for calculation of median and quartiles
if((q1Flag==1)|| (q3Flag==1) || (medFlag==1)){
if (j<colvalues[ucol].length -1){
for(k=j+1; k<colvalues[ucol].length; k++) {
if(eval(colvalues[ucol][k]) <
eval(colvalues[ucol][j])){
temp = colvalues[ucol][j];
colvalues[ucol][j] = colvalues[ucol][k];
colvalues[ucol][k] = temp;
}
}
}
}
var cvalue = parseFloat(colvalues[ucol][j]);
theList[j] = parseFloat(cvalue);
if(!isNaN(cvalue)){
nbvalues++;
if(sumFlag===1 || meanFlag===1){
sumValue += parseFloat( cvalue );
}
if(minFlag===1){
if(minValue===null){
minValue = parseFloat( cvalue );
} else{
minValue = parseFloat( cvalue ) < minValue ?
parseFloat( cvalue ): minValue;
}
}
if(maxFlag===1){
if (maxValue===null){
maxValue = parseFloat( cvalue );
} else {
maxValue = parseFloat( cvalue ) > maxValue ?
parseFloat( cvalue ): maxValue;
}
}
}
}//for j
if(meanFlag===1){
meanValue = sumValue/nbvalues;
}
if(medFlag===1){
var aux = 0;
if(nbvalues%2 === 1){
aux = Math.floor(nbvalues/2);
medValue = theList[aux];
} else{
medValue =
(theList[nbvalues/2] + theList[((nbvalues/2)-1)])/2;
}
}
var posa;
if(q1Flag===1){
posa=0.0;
posa = Math.floor(nbvalues/4);
if(4*posa == nbvalues){
q1Value = (theList[posa-1] + theList[posa])/2;
} else {
q1Value = theList[posa];
}
}
if (q3Flag===1){
posa=0.0;
var posb=0.0;
posa = Math.floor(nbvalues/4);
if (4*posa === nbvalues){
posb = 3*posa;
q3Value = (theList[posb] + theList[posb-1])/2;
} else {
q3Value = theList[nbvalues-posa-1];
}
}
for(var i=0; i<=mThisCol; i++){
switch( opsThisCol[i] ){
case 'mean':
result=meanValue;
break;
case 'sum':
result=sumValue;
break;
case 'min':
result=minValue;
break;
case 'max':
result=maxValue;
break;
case 'median':
result=medValue;
break;
case 'q1':
result=q1Value;
break;
case 'q3':
result=q3Value;
break;
}
var precision = !isNaN(decThisCol[i]) ? decThisCol[i] : 2;
//if outputType is defined
if(oTypeThisCol && result){
result = result.toFixed( precision );
if(dom.id(labThisCol[i])){
switch( str.lower(oTypeThisCol) ){
case 'innerhtml':
if (isNaN(result) || !isFinite(result) ||
nbvalues===0){
dom.id(labThisCol[i]).innerHTML = '.';
} else{
dom.id(labThisCol[i]).innerHTML = result;
}
break;
case 'setvalue':
dom.id( labThisCol[i] ).value = result;
break;
case 'createtextnode':
var oldnode = dom.id(labThisCol[i])
.firstChild;
var txtnode = dom.text(result);
dom.id(labThisCol[i])
.replaceChild(txtnode, oldnode);
break;
}//switch
}
} else {
try{
if(isNaN(result) || !isFinite(result) ||
nbvalues===0){
dom.id(labThisCol[i]).innerHTML = '.';
} else {
dom.id(labThisCol[i]).innerHTML =
result.toFixed(precision);
}
} catch(e) {}//catch
}//else
}//for i
// row(s) with result are always visible
var totRow = totRowIndex && totRowIndex[ucol] ?
row[totRowIndex[ucol]] : null;
if(totRow){
totRow.style.display = '';
}
}//for ucol
}//if typeof
if(this.tf.onAfterOperation){
this.tf.onAfterOperation.call(null, this.tf);
}
this.tf = tf;
};
_classProps(ColOps, null, {
set: {
writable: true,
value: function () {
if (!this.tf.isFirstLoad && !this.tf.hasGrid) {
return;
}
if (this.tf.onBeforeOperation) {
this.tf.onBeforeOperation.call(null, this.tf);
}
var colOperation = this.colOperation, labelId = colOperation.id, colIndex = colOperation.col, operation = colOperation.operation, outputType = colOperation.write_method, totRowIndex = colOperation.tot_row_index, excludeRow = colOperation.exclude_row, decimalPrecision = colOperation.decimal_precision !== undefined ? colOperation.decimal_precision : 2;
//nuovella: determine unique list of columns to operate on
var ucolIndex = [], ucolMax = 0;
ucolIndex[ucolMax] = colIndex[0];
for (var ii = 1; ii < colIndex.length; ii++) {
var saved = 0;
//see if colIndex[ii] is already in the list of unique indexes
for (var jj = 0; jj <= ucolMax; jj++) {
if (ucolIndex[jj] === colIndex[ii]) {
saved = 1;
}
}
//if not saved then, save the index;
if (saved === 0) {
ucolMax++;
ucolIndex[ucolMax] = colIndex[ii];
}
}
if (str.lower(typeof labelId) == "object" && str.lower(typeof colIndex) == "object" && str.lower(typeof operation) == "object") {
var row = this.tf.tbl.rows, colvalues = [];
for (var ucol = 0; ucol <= ucolMax; ucol++) {
//this retrieves col values
//use ucolIndex because we only want to pass through this loop
//once for each column get the values in this unique column
colvalues.push(this.tf.GetColValues(ucolIndex[ucol], true, excludeRow));
//next: calculate all operations for this column
var result, nbvalues = 0, temp, meanValue = 0, sumValue = 0, minValue = null, maxValue = null, q1Value = null, medValue = null, q3Value = null, meanFlag = 0, sumFlag = 0, minFlag = 0, maxFlag = 0, q1Flag = 0, medFlag = 0, q3Flag = 0, theList = [], opsThisCol = [], decThisCol = [], labThisCol = [], oTypeThisCol = [], mThisCol = -1;
for (var k = 0; k < colIndex.length; k++) {
if (colIndex[k] === ucolIndex[ucol]) {
mThisCol++;
opsThisCol[mThisCol] = str.lower(operation[k]);
decThisCol[mThisCol] = decimalPrecision[k];
labThisCol[mThisCol] = labelId[k];
oTypeThisCol = outputType !== undefined && str.lower(typeof outputType) === "object" ? outputType[k] : null;
switch (opsThisCol[mThisCol]) {
case "mean":
meanFlag = 1;
break;
case "sum":
sumFlag = 1;
break;
case "min":
minFlag = 1;
break;
case "max":
maxFlag = 1;
break;
case "median":
medFlag = 1;
break;
case "q1":
q1Flag = 1;
break;
case "q3":
q3Flag = 1;
break;
}
}
}
for (var j = 0; j < colvalues[ucol].length; j++) {
//sort the list for calculation of median and quartiles
if ((q1Flag == 1) || (q3Flag == 1) || (medFlag == 1)) {
if (j < colvalues[ucol].length - 1) {
for (k = j + 1; k < colvalues[ucol].length; k++) {
if (eval(colvalues[ucol][k]) < eval(colvalues[ucol][j])) {
temp = colvalues[ucol][j];
colvalues[ucol][j] = colvalues[ucol][k];
colvalues[ucol][k] = temp;
}
}
}
}
var cvalue = parseFloat(colvalues[ucol][j]);
theList[j] = parseFloat(cvalue);
if (!isNaN(cvalue)) {
nbvalues++;
if (sumFlag === 1 || meanFlag === 1) {
sumValue += parseFloat(cvalue);
}
if (minFlag === 1) {
if (minValue === null) {
minValue = parseFloat(cvalue);
} else {
minValue = parseFloat(cvalue) < minValue ? parseFloat(cvalue) : minValue;
}
}
if (maxFlag === 1) {
if (maxValue === null) {
maxValue = parseFloat(cvalue);
} else {
maxValue = parseFloat(cvalue) > maxValue ? parseFloat(cvalue) : maxValue;
}
}
}
} //for j
if (meanFlag === 1) {
meanValue = sumValue / nbvalues;
}
if (medFlag === 1) {
var aux = 0;
if (nbvalues % 2 === 1) {
aux = Math.floor(nbvalues / 2);
medValue = theList[aux];
} else {
medValue = (theList[nbvalues / 2] + theList[((nbvalues / 2) - 1)]) / 2;
}
}
var posa;
if (q1Flag === 1) {
posa = 0;
posa = Math.floor(nbvalues / 4);
if (4 * posa == nbvalues) {
q1Value = (theList[posa - 1] + theList[posa]) / 2;
} else {
q1Value = theList[posa];
}
}
if (q3Flag === 1) {
posa = 0;
var posb = 0;
posa = Math.floor(nbvalues / 4);
if (4 * posa === nbvalues) {
posb = 3 * posa;
q3Value = (theList[posb] + theList[posb - 1]) / 2;
} else {
q3Value = theList[nbvalues - posa - 1];
}
}
for (var i = 0; i <= mThisCol; i++) {
switch (opsThisCol[i]) {
case "mean":
result = meanValue;
break;
case "sum":
result = sumValue;
break;
case "min":
result = minValue;
break;
case "max":
result = maxValue;
break;
case "median":
result = medValue;
break;
case "q1":
result = q1Value;
break;
case "q3":
result = q3Value;
break;
}
var precision = !isNaN(decThisCol[i]) ? decThisCol[i] : 2;
//if outputType is defined
if (oTypeThisCol && result) {
result = result.toFixed(precision);
if (dom.id(labThisCol[i])) {
switch (str.lower(oTypeThisCol)) {
case "innerhtml":
if (isNaN(result) || !isFinite(result) || nbvalues === 0) {
dom.id(labThisCol[i]).innerHTML = ".";
} else {
dom.id(labThisCol[i]).innerHTML = result;
}
break;
case "setvalue":
dom.id(labThisCol[i]).value = result;
break;
case "createtextnode":
var oldnode = dom.id(labThisCol[i]).firstChild;
var txtnode = dom.text(result);
dom.id(labThisCol[i]).replaceChild(txtnode, oldnode);
break;
} //switch
}
} else {
try {
if (isNaN(result) || !isFinite(result) || nbvalues === 0) {
dom.id(labThisCol[i]).innerHTML = ".";
} else {
dom.id(labThisCol[i]).innerHTML = result.toFixed(precision);
}
} catch (e) {} //catch
} //else
} //for i
// row(s) with result are always visible
var totRow = totRowIndex && totRowIndex[ucol] ? row[totRowIndex[ucol]] : null;
if (totRow) {
totRow.style.display = "";
}
} //for ucol
} //if typeof
if (this.tf.onAfterOperation) {
this.tf.onAfterOperation.call(null, this.tf);
}
}
}
});
return ColOps;
})();
exports.ColOps = ColOps;
});

File diff suppressed because one or more lines are too long

View file

@ -1,90 +1,98 @@
define(['../dom', '../types'], function (dom, types) {
'use strict';
define(["exports", "../dom", "../types"], function (exports, _dom, _types) {
"use strict";
var global = window;
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
/**
* Loading message/spinner
* @param {Object} tf TableFilter instance
*/
function Loader(tf){
var dom = _dom;
var types = _types;
// TableFilter configuration
var f = tf.fObj;
//id of container element
tf.loaderTgtId = f.loader_target_id || null;
//div containing loader
tf.loaderDiv = null;
//defines loader text
tf.loaderText = f.loader_text || 'Loading...';
//defines loader innerHtml
tf.loaderHtml = f.loader_html || null;
//defines css class for loader div
tf.loaderCssClass = f.loader_css_class || 'loader';
//delay for hiding loader
tf.loaderCloseDelay = 200;
//callback function before loader is displayed
tf.onShowLoader = types.isFn(f.on_show_loader) ?
f.on_show_loader : null;
//callback function after loader is closed
tf.onHideLoader = types.isFn(f.on_hide_loader) ?
f.on_hide_loader : null;
this.tf = tf;
var global = window;
var containerDiv = dom.create('div', ['id', tf.prfxLoader+tf.id]);
containerDiv.className = tf.loaderCssClass;
var Loader = (function () {
var Loader = function Loader(tf) {
// TableFilter configuration
var f = tf.fObj;
//id of container element
tf.loaderTgtId = f.loader_target_id || null;
//div containing loader
tf.loaderDiv = null;
//defines loader text
tf.loaderText = f.loader_text || "Loading...";
//defines loader innerHtml
tf.loaderHtml = f.loader_html || null;
//defines css class for loader div
tf.loaderCssClass = f.loader_css_class || "loader";
//delay for hiding loader
tf.loaderCloseDelay = 200;
//callback function before loader is displayed
tf.onShowLoader = types.isFn(f.on_show_loader) ? f.on_show_loader : null;
//callback function after loader is closed
tf.onHideLoader = types.isFn(f.on_hide_loader) ? f.on_hide_loader : null;
var targetEl = !tf.loaderTgtId ?
(tf.gridLayout ? tf.tblCont : tf.tbl.parentNode) :
dom.id(tf.loaderTgtId);
if(!tf.loaderTgtId){
targetEl.insertBefore(containerDiv, tf.tbl);
} else {
targetEl.appendChild(containerDiv);
}
tf.loaderDiv = dom.id(tf.prfxLoader+tf.id);
if(!tf.loaderHtml){
tf.loaderDiv.appendChild(dom.text(tf.loaderText));
} else {
tf.loaderDiv.innerHTML = tf.loaderHtml;
}
}
this.tf = tf;
Loader.prototype.show = function(p) {
if(!this.tf.loader || !this.tf.loaderDiv ||
this.tf.loaderDiv.style.display===p){
var containerDiv = dom.create("div", ["id", tf.prfxLoader + tf.id]);
containerDiv.className = tf.loaderCssClass;
var targetEl = !tf.loaderTgtId ? (tf.gridLayout ? tf.tblCont : tf.tbl.parentNode) : dom.id(tf.loaderTgtId);
if (!tf.loaderTgtId) {
targetEl.insertBefore(containerDiv, tf.tbl);
} else {
targetEl.appendChild(containerDiv);
}
tf.loaderDiv = dom.id(tf.prfxLoader + tf.id);
if (!tf.loaderHtml) {
tf.loaderDiv.appendChild(dom.text(tf.loaderText));
} else {
tf.loaderDiv.innerHTML = tf.loaderHtml;
}
};
_classProps(Loader, null, {
show: {
writable: true,
value: function (p) {
if (!this.tf.loader || !this.tf.loaderDiv || this.tf.loaderDiv.style.display === p) {
return;
}
var o = this.tf;
}
var o = this.tf;
function displayLoader(){
if(!o.loaderDiv){
return;
function displayLoader() {
if (!o.loaderDiv) {
return;
}
if(o.onShowLoader && p!=='none'){
o.onShowLoader.call(null, o);
if (o.onShowLoader && p !== "none") {
o.onShowLoader.call(null, o);
}
o.loaderDiv.style.display = p;
if(o.onHideLoader && p==='none'){
o.onHideLoader.call(null, o);
if (o.onHideLoader && p === "none") {
o.onHideLoader.call(null, o);
}
}
var t = p === "none" ? this.tf.loaderCloseDelay : 1;
global.setTimeout(displayLoader, t);
}
var t = p==='none' ? this.tf.loaderCloseDelay : 1;
global.setTimeout(displayLoader, t);
};
Loader.prototype.remove = function() {
if(!this.tf.loaderDiv){
},
remove: {
writable: true,
value: function () {
if (!this.tf.loaderDiv) {
return;
}
var targetEl = !this.tf.loaderTgtId ? (this.tf.gridLayout ? this.tf.tblCont : this.tf.tbl.parentNode) : dom.id(this.tf.loaderTgtId);
targetEl.removeChild(this.tf.loaderDiv);
this.tf.loaderDiv = null;
}
var targetEl = !this.tf.loaderTgtId ?
(this.tf.gridLayout ? this.tf.tblCont : this.tf.tbl.parentNode) :
dom.id(this.tf.loaderTgtId);
targetEl.removeChild(this.tf.loaderDiv);
this.tf.loaderDiv = null;
};
}
});
return Loader;
return Loader;
})();
exports.Loader = Loader;
});

File diff suppressed because one or more lines are too long

View file

@ -3,7 +3,7 @@ requirejs(['test-config', '../src/core'], function(config, TableFilter){
QUnit.start();
var dom = require('dom'),
AlternateRows = require('modules/alternateRows');
AlternateRows = require('modules/alternateRows').AlternateRows;
var tf = new TableFilter('demo', {
alternate_rows: true

View file

@ -3,7 +3,7 @@ requirejs(['test-config', '../src/core'], function(config, TableFilter){
QUnit.start();
var dom = require('dom'),
ColOps = require('modules/colOps');
ColOps = require('modules/colOps').ColOps;
var table = document.getElementById('demo');
var totRowIndex = table.getElementsByTagName('tr').length;

View file

@ -3,7 +3,7 @@ requirejs(['test-config', '../src/core'], function(config, TableFilter){
QUnit.start();
var dom = require('dom'),
Loader = require('modules/loader');
Loader = require('modules/loader').Loader;
var tf = new TableFilter('demo', {
loader: true