1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-15 21:06:44 +02:00
TableFilter/dist/tablefilter/1.js
2015-05-14 20:08:19 +10:00

3 lines
32 KiB
JavaScript

webpackJsonp([1],{1:function(t,e,s){function i(t){return s(n(t))}function n(t){return r[t]||function(){throw new Error("Cannot find module '"+t+"'.")}()}var r={"./array":7,"./array.js":7,"./cookie":5,"./cookie.js":5,"./date":9,"./date.js":9,"./dom":3,"./dom.js":3,"./event":2,"./event.js":2,"./extensions/colsVisibility/colsVisibility":25,"./extensions/colsVisibility/colsVisibility.js":25,"./extensions/sort/adapterSortabletable":26,"./extensions/sort/adapterSortabletable.js":26,"./extensions/sort/sort":27,"./extensions/sort/sort.js":27,"./helpers":8,"./helpers.js":8,"./modules/alternateRows":23,"./modules/alternateRows.js":23,"./modules/checkList":17,"./modules/checkList.js":17,"./modules/clearButton":21,"./modules/clearButton.js":21,"./modules/colOps":24,"./modules/colOps.js":24,"./modules/dropdown":16,"./modules/dropdown.js":16,"./modules/gridLayout":12,"./modules/gridLayout.js":12,"./modules/help":22,"./modules/help.js":22,"./modules/highlightKeywords":14,"./modules/highlightKeywords.js":14,"./modules/loader":13,"./modules/loader.js":13,"./modules/paging":20,"./modules/paging.js":20,"./modules/popupFilter":15,"./modules/popupFilter.js":15,"./modules/rowsCounter":18,"./modules/rowsCounter.js":18,"./modules/statusBar":19,"./modules/statusBar.js":19,"./modules/store":11,"./modules/store.js":11,"./sort":10,"./sort.js":10,"./string":4,"./string.js":4,"./types":6,"./types.js":6};i.keys=function(){return Object.keys(r)},i.resolve=n,t.exports=i,i.id=1},25:function(t,e,s){"use strict";var i=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},n=function(){function t(t,e){for(var s=0;s<e.length;s++){var i=e[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,s,i){return s&&t(e.prototype,s),i&&t(e,i),e}}();Object.defineProperty(e,"__esModule",{value:!0});var r=s(3),l=s(6),a=s(2),o=s(8),h=s(7),d=function(){function t(e){var s=void 0===arguments[1]?{name:"colsVisibility",description:"Columns visibility manager"}:arguments[1];i(this,t);var n=s,a=e.config();this.initialized=!1,this.extName=n.name,this.extDesc=n.description,this.spanEl=null,this.btnEl=null,this.contEl=null,this.tickToHide=n.tick_to_hide===!1?!1:!0,this.manager=n.manager===!1?!1:!0,this.headersTbl=n.headers_table||!1,this.headersIndex=n.headers_index||1,this.contElTgtId=n.container_target_id||null,this.headersText=n.headers_text||null,this.btnTgtId=n.btn_target_id||null,this.btnText=n.btn_text||"Columns&#9660;",this.btnHtml=n.btn_html||null,this.btnCssClass=n.btn_css_class||"colVis",this.btnCloseText=n.btn_close_text||"Close",this.btnCloseHtml=n.btn_close_html||null,this.btnCloseCssClass=n.btn_close_css_class||this.btnCssClass,this.path=n.path||e.extensionsPath+"colsVisibility/",this.stylesheet=n.stylesheet||"colsVisibility.css",this.prfx="colVis_",this.spanCssClass=n.span_css_class||"colVisSpan",this.prfxCont=this.prfx+"Cont_",this.contCssClass=n.cont_css_class||"colVisCont",this.listCssClass=a.list_css_class||"cols_checklist",this.listItemCssClass=a.checklist_item_css_class||"cols_checklist_item",this.listSlcItemCssClass=a.checklist_selected_item_css_class||"cols_checklist_slc_item",this.text=n.text||(this.tickToHide?"Hide: ":"Show: "),this.atStart=n.at_start||null,this.enableHover=Boolean(n.enable_hover),this.enableTickAll=Boolean(n.enable_tick_all),this.tickAllText=n.tick_all_text||"Select all:",this.hiddenCols=[],this.tblHasColTag=r.Dom.tag(e.tbl,"col").length>0,this.onLoaded=l.Types.isFn(n.on_loaded)?n.on_loaded:null,this.onBeforeOpen=l.Types.isFn(n.on_before_open)?n.on_before_open:null,this.onAfterOpen=l.Types.isFn(n.on_after_open)?n.on_after_open:null,this.onBeforeClose=l.Types.isFn(n.on_before_close)?n.on_before_close:null,this.onAfterClose=l.Types.isFn(n.on_after_close)?n.on_after_close:null,this.onBeforeColHidden=l.Types.isFn(n.on_before_col_hidden)?n.on_before_col_hidden:null,this.onAfterColHidden=l.Types.isFn(n.on_after_col_hidden)?n.on_after_col_hidden:null,this.onBeforeColDisplayed=l.Types.isFn(n.on_before_col_displayed)?n.on_before_col_displayed:null,this.onAfterColDisplayed=l.Types.isFn(n.on_after_col_displayed)?n.on_after_col_displayed:null,e.gridLayout&&(this.headersTbl=e.Cpt.gridLayout.headTbl,this.headersIndex=0,this.onAfterColDisplayed=function(){},this.onAfterColHidden=function(){}),e.includeFile(n.name+"Style",e.basePath+this.stylesheet,null,"link"),this.tf=e}return n(t,[{key:"toggle",value:function(t){var e=(this.tf,this.contEl.style.display),s=this.onBeforeOpen,i=this.onBeforeClose,n=this.onAfterOpen,r=this.onAfterClose;s&&"inline"!==e&&s.call(null,this),i&&"inline"===e&&i.call(null,this),this.contEl.style.display="inline"===e?"none":"inline",n&&"inline"!==e&&n.call(null,this),r&&"inline"===e&&r.call(null,this)}},{key:"checkItem",value:function(t){var e=t.parentNode;if(e&&t){var s=t.firstChild.checked,i=t.firstChild.getAttribute("id").split("_")[1];i=parseInt(i,10),s?r.Dom.addClass(e,this.listSlcItemCssClass):r.Dom.removeClass(e,this.listSlcItemCssClass);var n=!1;(this.tickToHide&&s||!this.tickToHide&&!s)&&(n=!0),this.setHidden(i,n)}}},{key:"init",value:function(){this.manager&&(this.buildBtn(),this.buildManager(),this.initialized=!0)}},{key:"buildBtn",value:function(){var t=this;if(!this.btnEl){var e=this.tf,s=r.Dom.create("span",["id",this.prfx+e.id]);s.className=this.spanCssClass,this.btnTgtId||e.setToolbar();var i=this.btnTgtId?r.Dom.id(this.btnTgtId):e.rDiv;if(this.btnTgtId)i.appendChild(s);else{var n=i.firstChild;n.parentNode.insertBefore(s,n)}if(this.btnHtml){s.innerHTML=this.btnHtml;var l=s.firstChild;this.enableHover?a.Event.add(l,"mouseover",function(e){t.toggle(e)}):a.Event.add(l,"click",function(e){t.toggle(e)})}else{var o=r.Dom.create("a",["href","javascript:;"]);o.className=this.btnCssClass,o.title=this.extDesc,o.innerHTML=this.btnText,s.appendChild(o),this.enableHover?a.Event.add(o,"mouseover",function(e){t.toggle(e)}):a.Event.add(o,"click",function(e){t.toggle(e)})}this.spanEl=s,this.btnEl=this.spanEl.firstChild,this.onLoaded&&this.onLoaded.call(null,this)}}},{key:"buildManager",value:function(){var t=this,e=this.tf,s=this.contElTgtId?r.Dom.id(this.contElTgtId):r.Dom.create("div",["id",this.prfxCont+e.id]);s.className=this.contCssClass;var i=r.Dom.create("p");i.innerHTML=this.text,s.appendChild(i);var n=r.Dom.create("ul",["id","ul"+this.extName+"_"+e.id]);n.className=this.listCssClass;var l=this.headersTbl?this.headersTbl:e.tbl,o=this.headersTbl?this.headersIndex:e.getHeadersRowIndex(),h=l.rows[o];if(this.enableTickAll){var d=r.Dom.createCheckItem("col__"+e.id,this.tickAllText,this.tickAllText);r.Dom.addClass(d,this.listItemCssClass),n.appendChild(d),d.check.checked=!this.tickToHide,a.Event.add(d.check,"click",function(t){for(var s=0;s<h.cells.length;s++){var i=r.Dom.id("col_"+s+"_"+e.id);i&&d.check.checked!==i.checked&&(i.click(),i.checked=d.check.checked)}})}for(var c=0;c<h.cells.length;c++){var p=h.cells[c],u=this.headersText&&this.headersText[c]?this.headersText[c]:this._getHeaderText(p),f=r.Dom.createCheckItem("col_"+c+"_"+e.id,u,u);r.Dom.addClass(f,this.listItemCssClass),this.tickToHide||r.Dom.addClass(f,this.listSlcItemCssClass),n.appendChild(f),this.tickToHide||(f.check.checked=!0),a.Event.add(f.check,"click",function(e){var s=a.Event.target(e),i=s.parentNode;t.checkItem(i)})}var g,v=r.Dom.create("p",["align","center"]);if(this.btnCloseHtml?(v.innerHTML=this.btnCloseHtml,g=v.firstChild,a.Event.add(g,"click",function(e){t.toggle(e)})):(g=r.Dom.create("a",["href","javascript:;"]),g.className=this.btnCloseCssClass,g.innerHTML=this.btnCloseText,a.Event.add(g,"click",function(e){t.toggle(e)}),v.appendChild(g)),s.appendChild(n),s.appendChild(v),this.btnEl.parentNode.insertBefore(s,this.btnEl),this.contEl=s,this.atStart)for(var m=this.atStart,b=0;b<m.length;b++){var C=r.Dom.id("col_"+m[b]+"_"+e.id);C&&C.click()}}},{key:"setHidden",value:function(t,e){{var s=this.tf,i=s.tbl;r.Dom.tag(i,"col")[t]}this.onBeforeColHidden&&e&&this.onBeforeColHidden.call(null,this,t),this.onBeforeColDisplayed&&!e&&this.onBeforeColDisplayed.call(null,this,t),this._hideCells(i,t,e),this.headersTbl&&this._hideCells(this.headersTbl,t,e);var n=this.hiddenCols;if(e)-1===n.indexOf(t)&&this.hiddenCols.push(t);else{var l=h.Arr.indexByValue(n,t,!0);-1!==n.indexOf(t)&&this.hiddenCols.splice(l,1)}var a,d,c;if(this.onAfterColHidden&&e){if(s.gridLayout)if(a=s.Cpt.gridLayout,d=a.headTbl,c=a.gridColElms,o.Helpers.isIE())i.style.width=d.clientWidth+"px";else{for(var p=d.rows[this.headersIndex].cells,u=0,f=0;f<s.nbCells;f++)if("none"===p[f].style.display){var g=parseInt(p[f].style.width,10);p[f].style.width=0,u+=g}var v=parseInt(d.style.width,10);d.style.width=v-u+"px",i.style.width=d.style.width,c[t].style.display="none"}this.onAfterColHidden.call(null,this,t)}if(this.onAfterColDisplayed&&!e){if(s.gridLayout){a=s.Cpt.gridLayout,d=a.headTbl,c=a.gridColElms,c[t].style.display="";var m=parseInt(c[t].style.width,10),b=s.getHeaderElement(t);b.style.width=m+"px",d.style.width=parseInt(d.style.width,10)+m+"px",s.tbl.style.width=d.style.width}this.onAfterColDisplayed.call(null,this,t)}}},{key:"showCol",value:function(t){if(void 0!==t&&this.isColHidden(t))if(this.manager&&this.contEl){var e=r.Dom.id("col_"+t+"_"+this.tf.id);e&&e.click()}else this.setHidden(t,!1)}},{key:"hideCol",value:function(t){if(void 0!==t&&!this.isColHidden(t))if(this.manager&&this.contEl){var e=r.Dom.id("col_"+t+"_"+this.tf.id);e&&e.click()}else this.setHidden(t,!0)}},{key:"isColHidden",value:function(t){return-1!==this.hiddenCols.indexOf(t)?!0:!1}},{key:"toggleCol",value:function(t){void 0===t||this.isColHidden(t)?this.showCol(t):this.hideCol(t)}},{key:"getHiddenCols",value:function(){return this.hiddenCols}},{key:"destroy",value:function(){this.btnEl&&this.contEl&&(r.Dom.id(this.contElTgtId)?r.Dom.id(this.contElTgtId).innerHTML="":(this.contEl.innerHTML="",this.contEl.parentNode.removeChild(this.contEl),this.contEl=null),this.btnEl.innerHTML="",this.btnEl.parentNode.removeChild(this.btnEl),this.btnEl=null,this.initialized=!1)}},{key:"_getHeaderText",value:function(t){if(!t.hasChildNodes)return"";for(var e=0;e<t.childNodes.length;e++){var s=t.childNodes[e];if(3===s.nodeType)return s.nodeValue;if(1===s.nodeType){if(s.id&&-1!==s.id.indexOf("popUp"))continue;return r.Dom.getText(s)}}return""}},{key:"_hideCells",value:function(t,e,s){for(var i=0;i<t.rows.length;i++){var n=t.rows[i],r=n.cells[e];r&&(r.style.display=s?"none":"")}}}]),t}();e["default"]=d,t.exports=e["default"]},26:function(t,e,s){"use strict";function i(t){return C.Helpers.removeNbFormat(t,"us")}function n(t){return C.Helpers.removeNbFormat(t,"eu")}function r(t,e){return b.DateHelper.format(t,e)}function l(t){return r(t,"DMY")}function a(t){return r(t,"MDY")}function o(t){return r(t,"YMD")}function h(t){return r(t,"DDMMMYYYY")}function d(t){var e=t.split(".");for(var s in e){for(var i=e[s];3>i.length;)i="0"+i;e[s]=i}return e.join(".")}function c(t,e){var s=d(t.value.toLowerCase()),i=d(e.value.toLowerCase());return s==i?0:i>s?-1:1}var p=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},u=function(){function t(t,e){for(var s=0;s<e.length;s++){var i=e[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,s,i){return s&&t(e.prototype,s),i&&t(e,i),e}}();Object.defineProperty(e,"__esModule",{value:!0});var f=s(6),g=s(3),v=s(7),m=s(2),b=s(9),C=s(8),y=function(){function t(e){p(this,t);var s=e.config();this.isPaged=!1,this.sorted=!1,this.sortImgPath=s.sort_images_path||e.themesPath,this.sortImgBlank=s.sort_image_blank||"blank.png",this.sortImgClassName=s.sort_image_class_name||"sort-arrow",this.sortImgAscClassName=s.sort_image_asc_class_name||"ascending",this.sortImgDescClassName=s.sort_image_desc_class_name||"descending",this.sortCustomKey=s.sort_custom_key||"data-tf-sortKey",this.onSortLoaded=f.Types.isFn(s.on_sort_loaded)?s.on_sort_loaded:null,this.onBeforeSort=f.Types.isFn(s.on_before_sort)?s.on_before_sort:null,this.onAfterSort=f.Types.isFn(s.on_after_sort)?s.on_after_sort:null,this.tf=e}return u(t,[{key:"init",value:function(){var t=this.tf,e=t.sortConfig,s=this;if(f.Types.isUndef(SortableTable))throw new Error("SortableTable class not found.");this.overrideSortableTable(),this.setSortTypes(),e.sortCol&&this.stt.sort(e.sortCol[0],e.sortCol[1]),t.isSortEnabled=!0,this.onSortLoaded&&this.onSortLoaded.call(null,t,this),this.stt.onbeforesort=function(){this.onBeforeSort&&this.onBeforeSort.call(null,t,this.stt.sortColumn),t.performSort(),t.paging&&(s.isPaged=!0,t.paging=!1,t.Cpt.paging.destroy())},this.stt.onsort=function(){if(s.sorted=!0,t.alternateBgs)for(var e=t.tbl.rows,i=0,n=function(e,s,i){f.Types.isUndef(i)&&(i=!1);var n=t.Cpt.alternateRows,r=n.oddCss,l=n.evenCss;g.Dom.removeClass(e,r),g.Dom.removeClass(e,l),i||g.Dom.addClass(e,s%2?r:l)},r=t.refRow;r<t.nbRows;r++){var l=e[r].getAttribute("validRow");t.paging&&""===e[r].style.display?(n(e[r],i),i++):"true"!==l&&null!==l||""!==e[r].style.display?n(e[r],i,!0):(n(e[r],i),i++)}if(s.isPaged){var a=t.Cpt.paging,o=t.config();if(a.hasResultsPerPage){var h=a.resultsPerPageSlc;o.paging_length=h.options[h.selectedIndex].value}a.addPaging(!1),a.setPage(a.currentPageNb),s.isPaged=!1}s.onAfterSort&&s.onAfterSort.call(null,t,t.stt.sortColumn)}}},{key:"sortByColumnIndex",value:function(t){this.stt.sort(t)}},{key:"overrideSortableTable",value:function(){var t=this,e=this.tf;SortableTable.prototype.headerOnclick=function(t){if(e.sort){for(var s=t.target||t.srcElement;"TD"!==s.tagName&&"TH"!==s.tagName;)s=s.parentNode;this.sort(SortableTable.msie?SortableTable.getCellIndex(s):s.cellIndex)}},SortableTable.getCellIndex=function(t){var e,s=t.parentNode.cells,i=s.length;for(e=0;s[e]!=t&&i>e;e++);return e},SortableTable.prototype.initHeader=function(s){var i=this;if(i.tHead){i.headersRow=e.headersRow;{var n=i.tHead.rows[i.headersRow].cells;i.tHead.ownerDocument||i.tHead.document}i.sortTypes=s||[];for(var r,l,a=n.length,o=0;a>o;o++)l=n[o],null!==i.sortTypes[o]&&"None"!==i.sortTypes[o]?(l.style.cursor="pointer",r=g.Dom.create("img",["src",t.sortImgPath+t.sortImgBlank]),l.appendChild(r),null!==i.sortTypes[o]&&l.setAttribute("_sortType",i.sortTypes[o]),m.Event.add(l,"click",i._headerOnclick)):(l.setAttribute("_sortType",s[o]),l._sortType="None");i.updateHeaderArrows()}},SortableTable.prototype.updateHeaderArrows=function(){var s,i,n,r=this;if(e.sortConfig.asyncSort&&null!==e.sortConfig.triggerIds){var l=e.sortConfig.triggerIds;s=[],i=l.length;for(var a=0;a<l.length;a++)s.push(g.Dom.id(l[a]))}else{if(!this.tHead)return;s=r.tHead.rows[r.headersRow].cells,i=s.length}for(var o=0;i>o;o++){var h=s[o].getAttribute("_sortType");null!==h&&"None"!==h&&(n=s[o].lastChild||s[o],"img"!==n.nodeName.toLowerCase()&&(n=g.Dom.create("img",["src",t.sortImgPath+t.sortImgBlank]),s[o].appendChild(n)),o===r.sortColumn?n.className=t.sortImgClassName+" "+(this.descending?t.sortImgDescClassName:t.sortImgAscClassName):n.className=t.sortImgClassName)}},SortableTable.prototype.getRowValue=function(t,e,s){var i=this,n=i._sortTypeInfo[e];if(n&&n.getRowValue)return n.getRowValue(t,s);var r=t.cells[s],l=SortableTable.getInnerText(r);return i.getValueFromString(l,e)},SortableTable.getInnerText=function(e){return e?e.getAttribute(t.sortCustomKey)?e.getAttribute(t.sortCustomKey):g.Dom.getText(e):void 0}}},{key:"addSortType",value:function(){SortableTable.prototype.addSortType(arguments[0],arguments[1],arguments[2],arguments[3])}},{key:"setSortTypes",value:function(){for(var t=this,e=this.tf,s=e.sortConfig,r=s.sortTypes,p=[],u=0;u<e.nbCells;u++){var f;null!==r&&null!=r[u]?(f=r[u].toLowerCase(),"none"===f&&(f="None")):f=e.hasColNbFormat&&null!==e.colNbFormat[u]?e.colNbFormat[u].toLowerCase():e.hasColDateType&&null!==e.colDateType[u]?e.colDateType[u].toLowerCase()+"date":"String",p.push(f)}if(this.addSortType("number",Number),this.addSortType("caseinsensitivestring",SortableTable.toUpperCase),this.addSortType("date",SortableTable.toDate),this.addSortType("string"),this.addSortType("us",i),this.addSortType("eu",n),this.addSortType("dmydate",l),this.addSortType("ymddate",o),this.addSortType("mdydate",a),this.addSortType("ddmmmyyyydate",h),this.addSortType("ipaddress",d,c),this.stt=new SortableTable(e.tbl,p),s.asyncSort&&null!==s.triggerIds)for(var b=s.triggerIds,C=0;C<b.length;C++)if(null!==b[C]){var y=g.Dom.id(b[C]);y&&(y.style.cursor="pointer",m.Event.add(y,"click",function(e){var s=e.target;t.tf.sort&&t.stt.asyncSort(v.Arr.indexByValue(b,s.id,!0))}),y.setAttribute("_sortType",p[C]))}}},{key:"destroy",value:function(){var t=this.tf;t.sort=!1,this.sorted=!1,this.stt.destroy();for(var e=t.getFiltersId(),s=0;s<e.length;s++){var i=t.getHeaderElement(s),n=g.Dom.tag(i,"img");1===n.length&&i.removeChild(n[0])}}}]),t}();e["default"]=y,t.exports=e["default"]},27:function(t,e,s){"use strict";var i=function(t){return t&&t.__esModule?t:{"default":t}};Object.defineProperty(e,"__esModule",{value:!0}),s(28);var n=s(26),r=i(n);e["default"]=r["default"],t.exports=e["default"]},28:function(t,e,s){s(29)(s(30))},29:function(t,e,s){t.exports=function(t){"function"==typeof execScript?execScript(t):eval.call(null,t)}},30:function(t,e,s){t.exports='/*----------------------------------------------------------------------------\\\r\n| Sortable Table 1.12 |\r\n|-----------------------------------------------------------------------------|\r\n| Created by Erik Arvidsson |\r\n| (http://webfx.eae.net/contact.html#erik) |\r\n| For WebFX (http://webfx.eae.net/) |\r\n|-----------------------------------------------------------------------------|\r\n| A DOM 1 based script that allows an ordinary HTML table to be sortable. |\r\n|-----------------------------------------------------------------------------|\r\n| Copyright (c) 1998 - 2006 Erik Arvidsson |\r\n|-----------------------------------------------------------------------------|\r\n| Licensed under the Apache License, Version 2.0 (the "License"); you may not |\r\n| use this file except in compliance with the License. You may obtain a copy |\r\n| of the License at http://www.apache.org/licenses/LICENSE-2.0 |\r\n| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |\r\n| Unless required by applicable law or agreed to in writing, software |\r\n| distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |\r\n| WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |\r\n| License for the specific language governing permissions and limitations |\r\n| under the License. |\r\n|-----------------------------------------------------------------------------|\r\n| 2003-01-10 | First version |\r\n| 2003-01-19 | Minor changes to the date parsing |\r\n| 2003-01-28 | JScript 5.0 fixes (no support for \'in\' operator) |\r\n| 2003-02-01 | Sloppy typo like error fixed in getInnerText |\r\n| 2003-07-04 | Added workaround for IE cellIndex bug. |\r\n| 2003-11-09 | The bDescending argument to sort was not correctly working |\r\n| | Using onclick DOM0 event if no support for addEventListener |\r\n| | or attachEvent |\r\n| 2004-01-13 | Adding addSortType and removeSortType which makes it a lot |\r\n| | easier to add new, custom sort types. |\r\n| 2004-01-27 | Switch to use descending = false as the default sort order. |\r\n| | Change defaultDescending to suit your needs. |\r\n| 2004-03-14 | Improved sort type None look and feel a bit |\r\n| 2004-08-26 | Made the handling of tBody and tHead more flexible. Now you |\r\n| | can use another tHead or no tHead, and you can chose some |\r\n| | other tBody. |\r\n| 2006-04-25 | Changed license to Apache Software License 2.0 |\r\n|-----------------------------------------------------------------------------|\r\n| Created 2003-01-10 | All changes are in the log above. | Updated 2006-04-25 |\r\n\\----------------------------------------------------------------------------*/\r\n\r\n\r\nfunction SortableTable(oTable, oSortTypes) {\r\n\r\n this.sortTypes = oSortTypes || [];\r\n\r\n this.sortColumn = null;\r\n this.descending = null;\r\n\r\n var oThis = this;\r\n this._headerOnclick = function (e) {\r\n oThis.headerOnclick(e);\r\n };\r\n\r\n if (oTable) {\r\n this.setTable( oTable );\r\n this.document = oTable.ownerDocument || oTable.document;\r\n }\r\n else {\r\n this.document = document;\r\n }\r\n\r\n\r\n // only IE needs this\r\n var win = this.document.defaultView || this.document.parentWindow;\r\n this._onunload = function () {\r\n oThis.destroy();\r\n };\r\n if (win && typeof win.attachEvent != "undefined") {\r\n win.attachEvent("onunload", this._onunload);\r\n }\r\n}\r\n\r\nSortableTable.gecko = navigator.product == "Gecko";\r\nSortableTable.msie = /msie/i.test(navigator.userAgent);\r\n// Mozilla is faster when doing the DOM manipulations on\r\n// an orphaned element. MSIE is not\r\nSortableTable.removeBeforeSort = SortableTable.gecko;\r\n\r\nSortableTable.prototype.onsort = function () {};\r\n\r\n// default sort order. true -> descending, false -> ascending\r\nSortableTable.prototype.defaultDescending = false;\r\n\r\n// shared between all instances. This is intentional to allow external files\r\n// to modify the prototype\r\nSortableTable.prototype._sortTypeInfo = {};\r\n\r\nSortableTable.prototype.setTable = function (oTable) {\r\n if ( this.tHead )\r\n this.uninitHeader();\r\n this.element = oTable;\r\n this.setTHead( oTable.tHead );\r\n this.setTBody( oTable.tBodies[0] );\r\n};\r\n\r\nSortableTable.prototype.setTHead = function (oTHead) {\r\n if (this.tHead && this.tHead != oTHead )\r\n this.uninitHeader();\r\n this.tHead = oTHead;\r\n this.initHeader( this.sortTypes );\r\n};\r\n\r\nSortableTable.prototype.setTBody = function (oTBody) {\r\n this.tBody = oTBody;\r\n};\r\n\r\nSortableTable.prototype.setSortTypes = function ( oSortTypes ) {\r\n if ( this.tHead )\r\n this.uninitHeader();\r\n this.sortTypes = oSortTypes || [];\r\n if ( this.tHead )\r\n this.initHeader( this.sortTypes );\r\n};\r\n\r\n// adds arrow containers and events\r\n// also binds sort type to the header cells so that reordering columns does\r\n// not break the sort types\r\nSortableTable.prototype.initHeader = function (oSortTypes) {\r\n if (!this.tHead) return;\r\n var cells = this.tHead.rows[0].cells;\r\n var doc = this.tHead.ownerDocument || this.tHead.document;\r\n this.sortTypes = oSortTypes || [];\r\n var l = cells.length;\r\n var img, c;\r\n for (var i = 0; i < l; i++) {\r\n c = cells[i];\r\n if (this.sortTypes[i] != null && this.sortTypes[i] != "None") {\r\n img = doc.createElement("IMG");\r\n img.src = "images/blank.png";\r\n c.appendChild(img);\r\n if (this.sortTypes[i] != null)\r\n c._sortType = this.sortTypes[i];\r\n if (typeof c.addEventListener != "undefined")\r\n c.addEventListener("click", this._headerOnclick, false);\r\n else if (typeof c.attachEvent != "undefined")\r\n c.attachEvent("onclick", this._headerOnclick);\r\n else\r\n c.onclick = this._headerOnclick;\r\n }\r\n else\r\n {\r\n c.setAttribute( "_sortType", oSortTypes[i] );\r\n c._sortType = "None";\r\n }\r\n }\r\n this.updateHeaderArrows();\r\n};\r\n\r\n// remove arrows and events\r\nSortableTable.prototype.uninitHeader = function () {\r\n if (!this.tHead) return;\r\n var cells = this.tHead.rows[0].cells;\r\n var l = cells.length;\r\n var c;\r\n for (var i = 0; i < l; i++) {\r\n c = cells[i];\r\n if (c._sortType != null && c._sortType != "None") {\r\n c.removeChild(c.lastChild);\r\n if (typeof c.removeEventListener != "undefined")\r\n c.removeEventListener("click", this._headerOnclick, false);\r\n else if (typeof c.detachEvent != "undefined")\r\n c.detachEvent("onclick", this._headerOnclick);\r\n c._sortType = null;\r\n c.removeAttribute( "_sortType" );\r\n }\r\n }\r\n};\r\n\r\nSortableTable.prototype.updateHeaderArrows = function () {\r\n if (!this.tHead) return;\r\n var cells = this.tHead.rows[0].cells;\r\n var l = cells.length;\r\n var img;\r\n for (var i = 0; i < l; i++) {\r\n if (cells[i]._sortType != null && cells[i]._sortType != "None") {\r\n img = cells[i].lastChild;\r\n if (i == this.sortColumn)\r\n img.className = "sort-arrow " + (this.descending ? "descending" : "ascending");\r\n else\r\n img.className = "sort-arrow";\r\n }\r\n }\r\n};\r\n\r\nSortableTable.prototype.headerOnclick = function (e) {\r\n // find TD element\r\n var el = e.target || e.srcElement;\r\n while (el.tagName != "TD")\r\n el = el.parentNode;\r\n\r\n this.sort(SortableTable.msie ? SortableTable.getCellIndex(el) : el.cellIndex);\r\n};\r\n\r\n// IE returns wrong cellIndex when columns are hidden\r\nSortableTable.getCellIndex = function (oTd) {\r\n var cells = oTd.parentNode.childNodes\r\n var l = cells.length;\r\n var i;\r\n for (i = 0; cells[i] != oTd && i < l; i++)\r\n ;\r\n return i;\r\n};\r\n\r\nSortableTable.prototype.getSortType = function (nColumn) {\r\n return this.sortTypes[nColumn] || "String";\r\n};\r\n\r\n// only nColumn is required\r\n// if bDescending is left out the old value is taken into account\r\n// if sSortType is left out the sort type is found from the sortTypes array\r\n\r\nSortableTable.prototype.sort = function (nColumn, bDescending, sSortType) {\r\n if (!this.tBody) return;\r\n if (sSortType == null)\r\n sSortType = this.getSortType(nColumn);\r\n\r\n // exit if None\r\n if (sSortType == "None")\r\n return;\r\n\r\n if (bDescending == null) {\r\n if (this.sortColumn != nColumn)\r\n this.descending = this.defaultDescending;\r\n else\r\n this.descending = !this.descending;\r\n }\r\n else\r\n this.descending = bDescending;\r\n\r\n this.sortColumn = nColumn;\r\n\r\n if (typeof this.onbeforesort == "function")\r\n this.onbeforesort();\r\n\r\n var f = this.getSortFunction(sSortType, nColumn);\r\n var a = this.getCache(sSortType, nColumn);\r\n var tBody = this.tBody;\r\n\r\n a.sort(f);\r\n\r\n if (this.descending)\r\n a.reverse();\r\n\r\n if (SortableTable.removeBeforeSort) {\r\n // remove from doc\r\n var nextSibling = tBody.nextSibling;\r\n var p = tBody.parentNode;\r\n p.removeChild(tBody);\r\n }\r\n\r\n // insert in the new order\r\n var l = a.length;\r\n for (var i = 0; i < l; i++)\r\n tBody.appendChild(a[i].element);\r\n\r\n if (SortableTable.removeBeforeSort) {\r\n // insert into doc\r\n p.insertBefore(tBody, nextSibling);\r\n }\r\n\r\n this.updateHeaderArrows();\r\n\r\n this.destroyCache(a);\r\n\r\n if (typeof this.onsort == "function")\r\n this.onsort();\r\n};\r\n\r\nSortableTable.prototype.asyncSort = function (nColumn, bDescending, sSortType) {\r\n var oThis = this;\r\n this._asyncsort = function () {\r\n oThis.sort(nColumn, bDescending, sSortType);\r\n };\r\n window.setTimeout(this._asyncsort, 1);\r\n};\r\n\r\nSortableTable.prototype.getCache = function (sType, nColumn) {\r\n if (!this.tBody) return [];\r\n var rows = this.tBody.rows;\r\n var l = rows.length;\r\n var a = new Array(l);\r\n var r;\r\n for (var i = 0; i < l; i++) {\r\n r = rows[i];\r\n a[i] = {\r\n value: this.getRowValue(r, sType, nColumn),\r\n element: r\r\n };\r\n };\r\n return a;\r\n};\r\n\r\nSortableTable.prototype.destroyCache = function (oArray) {\r\n var l = oArray.length;\r\n for (var i = 0; i < l; i++) {\r\n oArray[i].value = null;\r\n oArray[i].element = null;\r\n oArray[i] = null;\r\n }\r\n};\r\n\r\nSortableTable.prototype.getRowValue = function (oRow, sType, nColumn) {\r\n // if we have defined a custom getRowValue use that\r\n if (this._sortTypeInfo[sType] && this._sortTypeInfo[sType].getRowValue)\r\n return this._sortTypeInfo[sType].getRowValue(oRow, nColumn);\r\n\r\n var s;\r\n var c = oRow.cells[nColumn];\r\n if (typeof c.innerText != "undefined")\r\n s = c.innerText;\r\n else\r\n s = SortableTable.getInnerText(c);\r\n return this.getValueFromString(s, sType);\r\n};\r\n\r\nSortableTable.getInnerText = function (oNode) {\r\n var s = "";\r\n var cs = oNode.childNodes;\r\n var l = cs.length;\r\n for (var i = 0; i < l; i++) {\r\n switch (cs[i].nodeType) {\r\n case 1: //ELEMENT_NODE\r\n s += SortableTable.getInnerText(cs[i]);\r\n break;\r\n case 3: //TEXT_NODE\r\n s += cs[i].nodeValue;\r\n break;\r\n }\r\n }\r\n return s;\r\n};\r\n\r\nSortableTable.prototype.getValueFromString = function (sText, sType) {\r\n if (this._sortTypeInfo[sType])\r\n return this._sortTypeInfo[sType].getValueFromString( sText );\r\n return sText;\r\n /*\r\n switch (sType) {\r\n case "Number":\r\n return Number(sText);\r\n case "CaseInsensitiveString":\r\n return sText.toUpperCase();\r\n case "Date":\r\n var parts = sText.split("-");\r\n var d = new Date(0);\r\n d.setFullYear(parts[0]);\r\n d.setDate(parts[2]);\r\n d.setMonth(parts[1] - 1);\r\n return d.valueOf();\r\n }\r\n return sText;\r\n */\r\n };\r\n\r\nSortableTable.prototype.getSortFunction = function (sType, nColumn) {\r\n if (this._sortTypeInfo[sType])\r\n return this._sortTypeInfo[sType].compare;\r\n return SortableTable.basicCompare;\r\n};\r\n\r\nSortableTable.prototype.destroy = function () {\r\n this.uninitHeader();\r\n var win = this.document.parentWindow;\r\n if (win && typeof win.detachEvent != "undefined") { // only IE needs this\r\n win.detachEvent("onunload", this._onunload);\r\n }\r\n this._onunload = null;\r\n this.element = null;\r\n this.tHead = null;\r\n this.tBody = null;\r\n this.document = null;\r\n this._headerOnclick = null;\r\n this.sortTypes = null;\r\n this._asyncsort = null;\r\n this.onsort = null;\r\n};\r\n\r\n// Adds a sort type to all instance of SortableTable\r\n// sType : String - the identifier of the sort type\r\n// fGetValueFromString : function ( s : string ) : T - A function that takes a\r\n// string and casts it to a desired format. If left out the string is just\r\n// returned\r\n// fCompareFunction : function ( n1 : T, n2 : T ) : Number - A normal JS sort\r\n// compare function. Takes two values and compares them. If left out less than,\r\n// <, compare is used\r\n// fGetRowValue : function( oRow : HTMLTRElement, nColumn : int ) : T - A function\r\n// that takes the row and the column index and returns the value used to compare.\r\n// If left out then the innerText is first taken for the cell and then the\r\n// fGetValueFromString is used to convert that string the desired value and type\r\n\r\nSortableTable.prototype.addSortType = function (sType, fGetValueFromString, fCompareFunction, fGetRowValue) {\r\n this._sortTypeInfo[sType] = {\r\n type: sType,\r\n getValueFromString: fGetValueFromString || SortableTable.idFunction,\r\n compare: fCompareFunction || SortableTable.basicCompare,\r\n getRowValue: fGetRowValue\r\n };\r\n};\r\n\r\n// this removes the sort type from all instances of SortableTable\r\nSortableTable.prototype.removeSortType = function (sType) {\r\n delete this._sortTypeInfo[sType];\r\n};\r\n\r\nSortableTable.basicCompare = function compare(n1, n2) {\r\n if (n1.value < n2.value)\r\n return -1;\r\n if (n2.value < n1.value)\r\n return 1;\r\n return 0;\r\n};\r\n\r\nSortableTable.idFunction = function (x) {\r\n return x;\r\n};\r\n\r\nSortableTable.toUpperCase = function (s) {\r\n return s.toUpperCase();\r\n};\r\n\r\nSortableTable.toDate = function (s) {\r\n var parts = s.split("-");\r\n var d = new Date(0);\r\n d.setFullYear(parts[0]);\r\n d.setDate(parts[2]);\r\n d.setMonth(parts[1] - 1);\r\n return d.valueOf();\r\n};\r\n\r\n\r\n// add sort types\r\nSortableTable.prototype.addSortType("Number", Number);\r\nSortableTable.prototype.addSortType("CaseInsensitiveString", SortableTable.toUpperCase);\r\nSortableTable.prototype.addSortType("Date", SortableTable.toDate);\r\nSortableTable.prototype.addSortType("String");\r\n// None is a special case\r\n';
}});