1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-17 22:06:41 +02:00
TableFilter/dist/tablefilter/1.js
2015-05-16 00:26:21 +10:00

3 lines
32 KiB
JavaScript

webpackJsonp([1],{1:function(t,e,s){function i(t){return s(r(t))}function r(t){return n[t]||function(){throw new Error("Cannot find module '"+t+"'.")}()}var n={"./array":7,"./array.js":7,"./cookie":5,"./cookie.js":5,"./date":8,"./date.js":8,"./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":24,"./helpers.js":24,"./modules/alternateRows":21,"./modules/alternateRows.js":21,"./modules/checkList":15,"./modules/checkList.js":15,"./modules/clearButton":19,"./modules/clearButton.js":19,"./modules/colOps":22,"./modules/colOps.js":22,"./modules/dropdown":14,"./modules/dropdown.js":14,"./modules/gridLayout":10,"./modules/gridLayout.js":10,"./modules/help":20,"./modules/help.js":20,"./modules/highlightKeywords":12,"./modules/highlightKeywords.js":12,"./modules/loader":11,"./modules/loader.js":11,"./modules/paging":18,"./modules/paging.js":18,"./modules/popupFilter":13,"./modules/popupFilter.js":13,"./modules/rowsCounter":16,"./modules/rowsCounter.js":16,"./modules/statusBar":17,"./modules/statusBar.js":17,"./modules/store":9,"./modules/store.js":9,"./sort":23,"./sort.js":23,"./string":4,"./string.js":4,"./types":6,"./types.js":6};i.keys=function(){return Object.keys(n)},i.resolve=r,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")},r=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 n=s(3),l=s(6),a=s(2),o=s(24),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 r=s,a=e.config();this.initialized=!1,this.extName=r.name,this.extDesc=r.description,this.spanEl=null,this.btnEl=null,this.contEl=null,this.tickToHide=r.tick_to_hide===!1?!1:!0,this.manager=r.manager===!1?!1:!0,this.headersTbl=r.headers_table||!1,this.headersIndex=r.headers_index||1,this.contElTgtId=r.container_target_id||null,this.headersText=r.headers_text||null,this.btnTgtId=r.btn_target_id||null,this.btnText=r.btn_text||"Columns&#9660;",this.btnHtml=r.btn_html||null,this.btnCssClass=r.btn_css_class||"colVis",this.btnCloseText=r.btn_close_text||"Close",this.btnCloseHtml=r.btn_close_html||null,this.btnCloseCssClass=r.btn_close_css_class||this.btnCssClass,this.path=r.path||e.extensionsPath+"colsVisibility/",this.stylesheet=r.stylesheet||"colsVisibility.css",this.prfx="colVis_",this.spanCssClass=r.span_css_class||"colVisSpan",this.prfxCont=this.prfx+"Cont_",this.contCssClass=r.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=r.text||(this.tickToHide?"Hide: ":"Show: "),this.atStart=r.at_start||null,this.enableHover=Boolean(r.enable_hover),this.enableTickAll=Boolean(r.enable_tick_all),this.tickAllText=r.tick_all_text||"Select all:",this.hiddenCols=[],this.tblHasColTag=n.Dom.tag(e.tbl,"col").length>0,this.onLoaded=l.Types.isFn(r.on_loaded)?r.on_loaded:null,this.onBeforeOpen=l.Types.isFn(r.on_before_open)?r.on_before_open:null,this.onAfterOpen=l.Types.isFn(r.on_after_open)?r.on_after_open:null,this.onBeforeClose=l.Types.isFn(r.on_before_close)?r.on_before_close:null,this.onAfterClose=l.Types.isFn(r.on_after_close)?r.on_after_close:null,this.onBeforeColHidden=l.Types.isFn(r.on_before_col_hidden)?r.on_before_col_hidden:null,this.onAfterColHidden=l.Types.isFn(r.on_after_col_hidden)?r.on_after_col_hidden:null,this.onBeforeColDisplayed=l.Types.isFn(r.on_before_col_displayed)?r.on_before_col_displayed:null,this.onAfterColDisplayed=l.Types.isFn(r.on_after_col_displayed)?r.on_after_col_displayed:null,e.gridLayout&&(this.headersTbl=e.Cpt.gridLayout.headTbl,this.headersIndex=0,this.onAfterColDisplayed=function(){},this.onAfterColHidden=function(){}),e["import"](r.name+"Style",e.basePath+this.stylesheet,null,"link"),this.tf=e}return r(t,[{key:"toggle",value:function(){var t=this.contEl.style.display,e=this.onBeforeOpen,s=this.onBeforeClose,i=this.onAfterOpen,r=this.onAfterClose;e&&"inline"!==t&&e.call(null,this),s&&"inline"===t&&s.call(null,this),this.contEl.style.display="inline"===t?"none":"inline",i&&"inline"!==t&&i.call(null,this),r&&"inline"===t&&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?n.Dom.addClass(e,this.listSlcItemCssClass):n.Dom.removeClass(e,this.listSlcItemCssClass);var r=!1;(this.tickToHide&&s||!this.tickToHide&&!s)&&(r=!0),this.setHidden(i,r)}}},{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=n.Dom.create("span",["id",this.prfx+e.id]);s.className=this.spanCssClass,this.btnTgtId||e.setToolbar();var i=this.btnTgtId?n.Dom.id(this.btnTgtId):e.rDiv;if(this.btnTgtId)i.appendChild(s);else{var r=i.firstChild;r.parentNode.insertBefore(s,r)}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=n.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?n.Dom.id(this.contElTgtId):n.Dom.create("div",["id",this.prfxCont+e.id]);s.className=this.contCssClass;var i=n.Dom.create("p");i.innerHTML=this.text,s.appendChild(i);var r=n.Dom.create("ul",["id","ul"+this.extName+"_"+e.id]);r.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=n.Dom.createCheckItem("col__"+e.id,this.tickAllText,this.tickAllText);n.Dom.addClass(d,this.listItemCssClass),r.appendChild(d),d.check.checked=!this.tickToHide,a.Event.add(d.check,"click",function(){for(var t=0;t<h.cells.length;t++){var s=n.Dom.id("col_"+t+"_"+e.id);s&&d.check.checked!==s.checked&&(s.click(),s.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=n.Dom.createCheckItem("col_"+c+"_"+e.id,u,u);n.Dom.addClass(f,this.listItemCssClass),this.tickToHide||n.Dom.addClass(f,this.listSlcItemCssClass),r.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=n.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=n.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(r),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=n.Dom.id("col_"+m[b]+"_"+e.id);C&&C.click()}}},{key:"setHidden",value:function(t,e){var s=this.tf,i=s.tbl;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 r=this.hiddenCols;if(e)-1===r.indexOf(t)&&this.hiddenCols.push(t);else{var n=h.Arr.indexByValue(r,t,!0);-1!==r.indexOf(t)&&this.hiddenCols.splice(n,1)}var l,a,d;if(this.onAfterColHidden&&e){if(s.gridLayout)if(l=s.Cpt.gridLayout,a=l.headTbl,d=l.gridColElms,o.Helpers.isIE())i.style.width=a.clientWidth+"px";else{for(var c=a.rows[this.headersIndex].cells,p=0,u=0;u<s.nbCells;u++)if("none"===c[u].style.display){var f=parseInt(c[u].style.width,10);c[u].style.width=0,p+=f}var g=parseInt(a.style.width,10);a.style.width=g-p+"px",i.style.width=a.style.width,d[t].style.display="none"}this.onAfterColHidden.call(null,this,t)}if(this.onAfterColDisplayed&&!e){if(s.gridLayout){l=s.Cpt.gridLayout,a=l.headTbl,d=l.gridColElms,d[t].style.display="";var v=parseInt(d[t].style.width,10),m=s.getHeaderElement(t);m.style.width=v+"px",a.style.width=parseInt(a.style.width,10)+v+"px",s.tbl.style.width=a.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=n.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=n.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&&(n.Dom.id(this.contElTgtId)?n.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 n.Dom.getText(s)}}return""}},{key:"_hideCells",value:function(t,e,s){for(var i=0;i<t.rows.length;i++){var r=t.rows[i],n=r.cells[e];n&&(n.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 r(t){return C.Helpers.removeNbFormat(t,"eu")}function n(t,e){return b.DateHelper.format(t,e)}function l(t){return n(t,"DMY")}function a(t){return n(t,"MDY")}function o(t){return n(t,"YMD")}function h(t){return n(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(8),C=s(24),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,r=function(e,s,i){f.Types.isUndef(i)&&(i=!1);var r=t.Cpt.alternateRows,n=r.oddCss,l=r.evenCss;g.Dom.removeClass(e,n),g.Dom.removeClass(e,l),i||g.Dom.addClass(e,s%2?n:l)},n=t.refRow;n<t.nbRows;n++){var l=e[n].getAttribute("validRow");t.paging&&""===e[n].style.display?(r(e[n],i),i++):"true"!==l&&null!==l||""!==e[n].style.display?r(e[n],i,!0):(r(e[n],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 r=i.tHead.rows[i.headersRow].cells;i.sortTypes=s||[];for(var n,l,a=r.length,o=0;a>o;o++)l=r[o],null!==i.sortTypes[o]&&"None"!==i.sortTypes[o]?(l.style.cursor="pointer",n=g.Dom.create("img",["src",t.sortImgPath+t.sortImgBlank]),l.appendChild(n),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,r,n=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=n.tHead.rows[n.headersRow].cells,i=s.length}for(var o=0;i>o;o++){var h=s[o].getAttribute("_sortType");null!==h&&"None"!==h&&(r=s[o].lastChild||s[o],"img"!==r.nodeName.toLowerCase()&&(r=g.Dom.create("img",["src",t.sortImgPath+t.sortImgBlank]),s[o].appendChild(r)),o===n.sortColumn?r.className=t.sortImgClassName+" "+(this.descending?t.sortImgDescClassName:t.sortImgAscClassName):r.className=t.sortImgClassName)}},SortableTable.prototype.getRowValue=function(t,e,s){var i=this,r=i._sortTypeInfo[e];if(r&&r.getRowValue)return r.getRowValue(t,s);var n=t.cells[s],l=SortableTable.getInnerText(n);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,n=s.sortTypes,p=[],u=0;u<e.nbCells;u++){var f;null!==n&&null!=n[u]?(f=n[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",r),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),r=g.Dom.tag(i,"img");1===r.length&&i.removeChild(r[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 r=s(26),n=i(r);e["default"]=n["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';
}});