tablesorter/dist/js/parsers/parser-input-select.min.js
2015-10-31 11:06:09 -05:00

59 lines
4.8 KiB
JavaScript

/*! Parser: input & select - updated 10/31/2015 (v2.24.0) */
/*
* for jQuery 1.7+ & tablesorter 2.7.11+
* Demo: http://mottie.github.com/tablesorter/docs/example-widget-grouping.html
*/
/*jshint browser: true, jquery:true, unused:false */
!function(a){"use strict";var b=function(a,b,c){};
// Custom parser for parsing input values
// updated dynamically using the 'change' function below
a.tablesorter.addParser({id:"inputs",is:function(){return!1},format:function(b,c,d){var e=a(d).find("input");return e.length?e.val():b},parsed:!0,// filter widget flag
type:"text"}),a.tablesorter.addParser({id:"inputs-numeric",is:function(){return!1},format:function(b,c,d){var e=a(d).find("input"),f=e.length?e.val():b,g=a.tablesorter.formatFloat((f||"").replace(/[^\w,. \-()]/g,""),c);return b&&"number"==typeof g?g:b?a.trim(b&&c.config.ignoreCase?b.toLocaleLowerCase():b):b},parsed:!0,// filter widget flag
type:"numeric"}),
// Custom parser for including checkbox status if using the grouping widget
// updated dynamically using the 'change' function below
a.tablesorter.addParser({id:"checkbox",is:function(){return!1},format:function(b,c,d,e){var f=a(d),g=f.closest("tr"),h=c.config.widgetOptions,i=c.config.checkboxClass||"checked",
// returning plain language here because this is what is shown in the
// group headers - change it as desired
j=h.group_checkbox?h.group_checkbox:["checked","unchecked"],k=f.find('input[type="checkbox"]'),l=k.length?k[0].checked:"";
// adding class to row, indicating that a checkbox is checked; includes
// a column index in case more than one checkbox happens to be in a row
// don't remove checked class if other columns have a check
return g.toggleClass(i+"-"+e,l),l?g.addClass(i):g.length&&!(g[0].className||"").match(i+"-")&&g.removeClass(i),k.length?j[l?0:1]:b},parsed:!0,// filter widget flag
type:"text"}),
// Custom parser which returns the currently selected options
// updated dynamically using the 'change' function below
a.tablesorter.addParser({id:"select",is:function(){return!1},format:function(b,c,d){var e=a(d).find("select");return e.length?e.val():b},parsed:!0,// filter widget flag
type:"text"}),
// Select parser to get the selected text
a.tablesorter.addParser({id:"select-text",is:function(){return!1},format:function(b,c,d){var e=a(d).find("select");return e.length?e.find("option:selected").text()||"":b},parsed:!0,// filter widget flag
type:"text"}),
// Custom parser for parsing textarea values
// updated dynamically using the 'change' function below
a.tablesorter.addParser({id:"textarea",is:function(){return!1},format:function(b,c,d){var e=a(d).find("textarea");return e.length?e.val():b},parsed:!0,// filter widget flag
type:"text"}),
// update select and all input types in the tablesorter cache when the change event fires.
// This method only works with jQuery 1.7+
// you can change it to use delegate (v1.4.3+) or live (v1.3+) as desired
// if this code interferes somehow, target the specific table $('#mytable'), instead of $('table')
a(function(){a("table").on("tablesorter-initialized updateComplete",function(){var c=".parser-forms",d=function(b){
// make sure we restore original values (trigger blur)
// isTbody is needed to prevent the select from closing in IE
// see https://connect.microsoft.com/IE/feedbackdetail/view/962618/
b&&a(":focus").blur()};
// bind to .tablesorter (default class name)
a(this).children("tbody").off(c).on("mouseleave"+c,function(a){d("TBODY"===a.target.nodeName)}).on("focus"+c,"select, input, textarea",function(){a(this).data("ts-original-value",this.value)}).on("blur"+c,"input, textarea",function(){
// restore input value;
// 'change' is triggered before 'blur' so this doesn't replace the new update with the original
this.value=a(this).data("ts-original-value")}).on("change keyup ".split(" ").join(c+" "),"select, input, textarea",function(c){if(27===c.which)
// escape: restore original value
return void(this.value=a(this).data("ts-original-value"));
// Update cell cache using... select: change, input: enter or textarea: alt + enter
if("change"===c.type||"keyup"===c.type&&13===c.which&&("INPUT"===c.target.nodeName||"TEXTAREA"===c.target.nodeName&&c.altKey)){var d,e=a(c.target),f=e.closest("td"),g=f.closest("table"),h=f[0].cellIndex,i=g[0].config||!1,j=i&&i.$headerIndexed&&i.$headerIndexed[h]||[],k=e.val();
// abort if not a tablesorter table, or don't use updateCell if column is set
// to 'sorter-false' and 'filter-false', or column is set to 'parser-false'
if(j.length&&(j.hasClass("parser-false")||j.hasClass("sorter-false")&&j.hasClass("filter-false")))return;
// ignore change event if nothing changed
(i&&k!==e.data("ts-original-value")||"checkbox"===c.target.type)&&(e.data("ts-original-value",k),
// pass undefined resort value so it falls back to config.resort setting
a.tablesorter.updateCell(i,f,d,function(){b(c,g,e)}))}})})})}(jQuery);