1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-12 11:27:24 +02:00

Converted event.js module to es6

This commit is contained in:
Max Guglielmi 2014-11-22 19:06:08 +11:00
parent 1b3f91a32c
commit 5a72404bd6
8 changed files with 255 additions and 213 deletions

View file

@ -112,11 +112,6 @@ module.exports = function (grunt) {
sourceMap: true,
modules: 'amd'
},
// dist: {
// files: {
// 'es6/modules/*.js': '<%= source_folder %>modules/'
// }
// }
build:{
files: [{
expand: true,

3
TODO Normal file
View file

@ -0,0 +1,3 @@
- Initialise TableFilter object with a table DOM element
- Use DOM event listeners for DOM events

2
dist/filtergrid.css vendored
View file

@ -1,6 +1,6 @@
/*------------------------------------------------------------------------
- TableFilter stylesheet by Max Guglielmi
- (build date: Sun Nov 16 2014 12:22:04)
- (build date: Sat Nov 22 2014 16:50:14)
- Edit below for your projects' needs
------------------------------------------------------------------------*/

50
src-es6/event.js Normal file
View file

@ -0,0 +1,50 @@
/**
* DOM event utilities
*/
var Event = {
add: function(obj, type, func, capture){
if(obj.attachEvent){
obj.attachEvent('on'+type, func);
}
else if(obj.addEventListener){
obj.addEventListener(type, func,
(capture===undefined ? false : capture));
} else{
obj['on'+type] = func;
}
},
remove: function(obj, type, func, capture){
if(obj.detachEvent){
obj.detachEvent('on'+type,func);
}
else if(obj.removeEventListener){
obj.removeEventListener(type, func,
(capture===undefined ? false : capture));
} else {
obj['on'+type] = null;
}
},
stop: function(evt){
if(!evt){
evt = window.event;
}
if(evt.stopPropagation){
evt.stopPropagation();
} else {
evt.cancelBubble = true;
}
},
cancel: function(evt){
if(!evt){
evt = window.event;
}
if(evt.preventDefault) {
evt.preventDefault();
} else {
evt.returnValue = false;
}
}
};
exports.Event = Event;

View file

@ -12,7 +12,7 @@
define(function (require) {
var global = this,
evt = require('event'),
evt = require('event').Event,
dom = require('dom').Dom,
str = require('string').Str,
cookie = require('cookie').Cookie,
@ -1003,9 +1003,9 @@ TableFilter.prototype = {
if(this.popUpFilters){
this.headersRow++;
}
if(this.fixedHeaders){
this.SetFixedHeaders();
}
// if(this.fixedHeaders){
// this.SetFixedHeaders();
// }
fltrow.className = this.fltsRowCssClass;
//Disable for grid_layout
@ -1213,9 +1213,9 @@ TableFilter.prototype = {
if(this.statusBar){
this.SetStatusBar();
}
if(this.fixedHeaders && !this.isFirstLoad){
this.SetFixedHeaders();
}
// if(this.fixedHeaders && !this.isFirstLoad){
// this.SetFixedHeaders();
// }
if(this.paging){
this.SetPaging();
}
@ -1370,55 +1370,55 @@ TableFilter.prototype = {
this.IncludeFile(module.name, module.path, module.init);
},
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],
re = new RegExp(file),
path = extPath.replace(re,'');
o.Ext.list[extName] = {
name: extName,
description: extDesc,
file: file,
path: path,
callback: extCallBack
};
}
};
}
this.EvtManager(this.Evt.name.loadextensions);
},
// 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],
// re = new RegExp(file),
// path = extPath.replace(re,'');
// o.Ext.list[extName] = {
// name: extName,
// description: extDesc,
// file: file,
// path: path,
// callback: extCallBack
// };
// }
// };
// }
// this.EvtManager(this.Evt.name.loadextensions);
// },
/*====================================================
- loads TF extensions
=====================================================*/
_LoadExtensions : function(){
if(!this.hasExtensions || !types.isArray(this.extensions.name) ||
!types.isArray(this.extensions.src)){
return;
}
var ext = this.extensions;
for(var e=0; e<ext.name.length; e++){
var extPath = ext.src[e],
extName = ext.name[e],
extInit = (ext.initialize && ext.initialize[e]) ?
ext.initialize[e] : null,
extDesc = (ext.description && ext.description[e] ) ?
ext.description[e] : null;
// _LoadExtensions : function(){
// if(!this.hasExtensions || !types.isArray(this.extensions.name) ||
// !types.isArray(this.extensions.src)){
// return;
// }
// var ext = this.extensions;
// for(var e=0; e<ext.name.length; e++){
// var extPath = ext.src[e],
// extName = ext.name[e],
// extInit = (ext.initialize && ext.initialize[e]) ?
// ext.initialize[e] : null,
// extDesc = (ext.description && ext.description[e] ) ?
// ext.description[e] : null;
//Registers extension
this.Ext.add(extName, extDesc, extPath, extInit);
if(isImported(extPath)){
extInit.call(null,this);
} else {
this.IncludeFile(extName, extPath, extInit);
}
}
},
// //Registers extension
// this.Ext.add(extName, extDesc, extPath, extInit);
// if(isImported(extPath)){
// extInit.call(null,this);
// } else {
// this.IncludeFile(extName, extPath, extInit);
// }
// }
// },
LoadThemes: function(){
this.EvtManager(this.Evt.name.loadthemes);
@ -1533,9 +1533,9 @@ TableFilter.prototype = {
if(this.isExternalFlt && !this.popUpFilters){
this.RemoveExternalFlts();
}
if(this.fixedHeaders){
this.RemoveFixedHeaders();
}
// if(this.fixedHeaders){
// this.RemoveFixedHeaders();
// }
if(this.infDiv){
this.RemoveTopDiv();
}
@ -1615,9 +1615,9 @@ TableFilter.prototype = {
dom.id(this.toolBarTgtId).appendChild(infdiv);
}
//fixed headers
else if(this.fixedHeaders && this.contDiv){
this.contDiv.parentNode.insertBefore(infdiv, this.contDiv);
}
// else if(this.fixedHeaders && this.contDiv){
// this.contDiv.parentNode.insertBefore(infdiv, this.contDiv);
// }
//grid-layout
else if(this.gridLayout){
this.tblMainCont.appendChild(infdiv);
@ -4563,112 +4563,112 @@ TableFilter.prototype = {
/*====================================================
- CSS solution making headers fixed
=====================================================*/
SetFixedHeaders: function(){
if((!this.hasGrid && !this.isFirstLoad) || !this.fixedHeaders){
return;
}
if(this.contDiv){
return;
}
var thead = dom.tag(this.tbl,'thead');
if(thead.length===0){
return;
}
var tbody = dom.tag(this.tbl,'tbody');
//firefox returns tbody height
if(tbody[0].clientHeight!==0){
//previous values
this.prevTBodyH = tbody[0].clientHeight;
this.prevTBodyOverflow = tbody[0].style.overflow;
this.prevTBodyOverflowX = tbody[0].style.overflowX;
// SetFixedHeaders: function(){
// if((!this.hasGrid && !this.isFirstLoad) || !this.fixedHeaders){
// return;
// }
// if(this.contDiv){
// return;
// }
// var thead = dom.tag(this.tbl,'thead');
// if(thead.length===0){
// return;
// }
// var tbody = dom.tag(this.tbl,'tbody');
// //firefox returns tbody height
// if(tbody[0].clientHeight!==0){
// //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 = dom.create(
'div',['id',this.prfxContentDiv+this.id]);
contDiv.className = this.contDivCssClass;
this.tbl.parentNode.insertBefore(contDiv, this.tbl);
contDiv.appendChild(this.tbl);
this.contDiv = dom.id(this.prfxContentDiv+this.id);
//prevents headers moving during window scroll (IE)
this.contDiv.style.position = 'relative';
// 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 = dom.create(
// 'div',['id',this.prfxContentDiv+this.id]);
// contDiv.className = this.contDivCssClass;
// this.tbl.parentNode.insertBefore(contDiv, this.tbl);
// contDiv.appendChild(this.tbl);
// this.contDiv = dom.id(this.prfxContentDiv+this.id);
// //prevents headers moving during window scroll (IE)
// this.contDiv.style.position = 'relative';
var theadH = 0;
var theadTr = dom.tag(thead[0],'tr');
//css below emulates fixed headers on IE<=6
for(var i=0; i<theadTr.length; i++){
theadTr[i].style.cssText += 'position:relative; ' +
'top:expression(offsetParent.scrollTop);';
theadH += parseInt(theadTr[i].clientHeight, 10);
}
// var theadH = 0;
// var theadTr = dom.tag(thead[0],'tr');
// //css below emulates fixed headers on IE<=6
// for(var i=0; i<theadTr.length; i++){
// theadTr[i].style.cssText += 'position:relative; ' +
// 'top:expression(offsetParent.scrollTop);';
// theadH += parseInt(theadTr[i].clientHeight, 10);
// }
this.contDiv.style.height = (this.tBodyH+theadH)+'px';
// this.contDiv.style.height = (this.tBodyH+theadH)+'px';
var tfoot = dom.tag(this.tbl,'tfoot');
if(tfoot.length===0){
return;
}
// var tfoot = dom.tag(this.tbl,'tfoot');
// if(tfoot.length===0){
// return;
// }
var tfootTr = dom.tag(tfoot[0],'tr');
// var tfootTr = dom.tag(tfoot[0],'tr');
//css below emulates fixed footer on IE<=6
for(var j=0; j<tfootTr.length; j++){
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);';
}
}
},
// //css below emulates fixed footer on IE<=6
// for(var j=0; j<tfootTr.length; j++){
// 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);';
// }
// }
// },
/*====================================================
- Removes fixed headers
=====================================================*/
RemoveFixedHeaders: function(){
if(!this.hasGrid || !this.fixedHeaders ){
return;
}
// RemoveFixedHeaders: function(){
// if(!this.hasGrid || !this.fixedHeaders ){
// return;
// }
if(this.contDiv){
this.contDiv.parentNode.insertBefore(this.tbl, this.contDiv);
this.contDiv.parentNode.removeChild( this.contDiv );
this.contDiv = null;
var thead = dom.tag(this.tbl,'thead');
if(thead.length===0){
return;
}
var theadTr = dom.tag(thead[0],'tr');
if(theadTr.length===0){
return;
}
for(var i=0; i<theadTr.length; i++){
theadTr[i].style.cssText = '';
}
var tfoot = dom.tag(this.tbl,'tfoot');
if(tfoot.length===0){
return;
}
var tfootTr = dom.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 = dom.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;
}
},
// if(this.contDiv){
// this.contDiv.parentNode.insertBefore(this.tbl, this.contDiv);
// this.contDiv.parentNode.removeChild( this.contDiv );
// this.contDiv = null;
// var thead = dom.tag(this.tbl,'thead');
// if(thead.length===0){
// return;
// }
// var theadTr = dom.tag(thead[0],'tr');
// if(theadTr.length===0){
// return;
// }
// for(var i=0; i<theadTr.length; i++){
// theadTr[i].style.cssText = '';
// }
// var tfoot = dom.tag(this.tbl,'tfoot');
// if(tfoot.length===0){
// return;
// }
// var tfootTr = dom.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 = dom.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;
// }
// },
Filter: function(){
this.EvtManager(this.Evt.name.filter);

View file

@ -1,57 +1,50 @@
/**
* DOM event utilities
*/
define(["exports"], function (exports) {
"use strict";
define(function () {
'use strict';
/**
* DOM event utilities
*/
var Event = {};
var Event = {
add: function (obj, type, func, capture) {
if (obj.attachEvent) {
obj.attachEvent("on" + type, func);
} else if (obj.addEventListener) {
obj.addEventListener(type, func, (capture === undefined ? false : capture));
} else {
obj["on" + type] = func;
}
},
remove: function (obj, type, func, capture) {
if (obj.detachEvent) {
obj.detachEvent("on" + type, func);
} else if (obj.removeEventListener) {
obj.removeEventListener(type, func, (capture === undefined ? false : capture));
} else {
obj["on" + type] = null;
}
},
stop: function (evt) {
if (!evt) {
evt = window.event;
}
if (evt.stopPropagation) {
evt.stopPropagation();
} else {
evt.cancelBubble = true;
}
},
cancel: function (evt) {
if (!evt) {
evt = window.event;
}
if (evt.preventDefault) {
evt.preventDefault();
} else {
evt.returnValue = false;
}
}
};
Event.add = function(obj, type, func, capture){
if(obj.attachEvent){
obj.attachEvent('on'+type, func);
}
else if(obj.addEventListener){
obj.addEventListener(type, func,
(capture===undefined ? false : capture));
} else{
obj['on'+type] = func;
}
};
Event.remove = function(obj, type, func, capture){
if(obj.detachEvent){
obj.detachEvent('on'+type,func);
}
else if(obj.removeEventListener){
obj.removeEventListener(type, func,
(capture===undefined ? false : capture));
} else {
obj['on'+type] = null;
}
};
Event.stop = function(evt){
if(!evt){
evt = window.event;
}
if(evt.stopPropagation){
evt.stopPropagation();
} else {
evt.cancelBubble = true;
}
};
Event.cancel = function(evt){
if(!evt){
evt = window.event;
}
if(evt.preventDefault) {
evt.preventDefault();
} else {
evt.returnValue = false;
}
};
return Event;
});
exports.Event = Event;
});

1
src/event.js.map Normal file
View file

@ -0,0 +1 @@
{"version":3,"sources":["src-es6/event.js"],"names":[],"mappings":";;;;;;;AAIA,MAAI,KAAK,GAAG;AACR,OAAG,EAAE,UAAS,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAC;AACnC,UAAG,GAAG,CAAC,WAAW,EAAC;AACf,WAAG,CAAC,WAAW,CAAC,IAAI,GAAC,IAAI,EAAE,IAAI,CAAC,CAAC;OACpC,MACI,IAAG,GAAG,CAAC,gBAAgB,EAAC;AACzB,WAAG,CAAC,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAC3B,CAAC,OAAO,KAAG,SAAS,GAAG,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC;OAChD,MAAK;AACF,WAAG,CAAC,IAAI,GAAC,IAAI,CAAC,GAAG,IAAI,CAAC;OACzB;KACJ;AACD,UAAM,EAAE,UAAS,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAC;AACtC,UAAG,GAAG,CAAC,WAAW,EAAC;AACf,WAAG,CAAC,WAAW,CAAC,IAAI,GAAC,IAAI,EAAC,IAAI,CAAC,CAAC;OACnC,UACO,GAAG,CAAC,mBAAmB,EAAC;AAC5B,WAAG,CAAC,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAC9B,CAAC,OAAO,KAAG,SAAS,GAAG,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC;OAChD,MAAM;AACH,WAAG,CAAC,IAAI,GAAC,IAAI,CAAC,GAAG,IAAI,CAAC;OACzB;KACJ;AACD,QAAI,EAAE,UAAS,GAAG,EAAC;AACf,UAAG,CAAC,GAAG,EAAC;AACJ,WAAG,GAAG,MAAM,CAAC,KAAK,CAAC;OACtB;AACD,UAAG,GAAG,CAAC,eAAe,EAAC;AACnB,WAAG,CAAC,eAAe,EAAE,CAAC;OACzB,MAAM;AACH,WAAG,CAAC,YAAY,GAAG,IAAI,CAAC;OAC3B;KACJ;AACD,UAAM,EAAE,UAAS,GAAG,EAAC;AACjB,UAAG,CAAC,GAAG,EAAC;AACJ,WAAG,GAAG,MAAM,CAAC,KAAK,CAAC;OACtB;AACD,UAAG,GAAG,CAAC,cAAc,EAAE;AACnB,WAAG,CAAC,cAAc,EAAE,CAAC;OACxB,MAAM;AACH,WAAG,CAAC,WAAW,GAAG,KAAK,CAAC;OAC3B;KACJ;GACJ,CAAC;;AAEF,SAAO,CAAC,KAAK,GAAG,KAAK,CAAC","file":"src-es6/event.js","sourcesContent":["/**\r\n * DOM event utilities\r\n */\r\n\r\nvar Event = {\r\n add: function(obj, type, func, capture){\r\n if(obj.attachEvent){\r\n obj.attachEvent('on'+type, func);\r\n }\r\n else if(obj.addEventListener){\r\n obj.addEventListener(type, func,\r\n (capture===undefined ? false : capture));\r\n } else{\r\n obj['on'+type] = func;\r\n }\r\n },\r\n remove: function(obj, type, func, capture){\r\n if(obj.detachEvent){\r\n obj.detachEvent('on'+type,func);\r\n }\r\n else if(obj.removeEventListener){\r\n obj.removeEventListener(type, func,\r\n (capture===undefined ? false : capture));\r\n } else {\r\n obj['on'+type] = null;\r\n }\r\n },\r\n stop: function(evt){\r\n if(!evt){\r\n evt = window.event;\r\n }\r\n if(evt.stopPropagation){\r\n evt.stopPropagation();\r\n } else {\r\n evt.cancelBubble = true;\r\n }\r\n },\r\n cancel: function(evt){\r\n if(!evt){\r\n evt = window.event;\r\n }\r\n if(evt.preventDefault) {\r\n evt.preventDefault();\r\n } else {\r\n evt.returnValue = false;\r\n }\r\n }\r\n};\r\n\r\nexports.Event = Event;\r\n"]}

File diff suppressed because one or more lines are too long