BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

jquery.tablesorter.js 229KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099
  1. /*** This file is dynamically generated ***
  2. █████▄ ▄████▄ █████▄ ▄████▄ ██████ ███████▄ ▄████▄ █████▄ ██ ██████ ██ ██
  3. ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██▄▄ ██▄▄██
  4. ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██▀▀ ▀▀▀██
  5. █████▀ ▀████▀ ██ ██ ▀████▀ ██ ██ ██ ██ ▀████▀ █████▀ ██ ██ █████▀
  6. */
  7. /*! tablesorter (FORK) - updated 2019-12-01 (v2.31.2)*/
  8. /* Includes widgets ( storage,uitheme,columns,filter,stickyHeaders,resizable,saveSort ) */
  9. (function(factory){if (typeof define === 'function' && define.amd){define(['jquery'], factory);} else if (typeof module === 'object' && typeof module.exports === 'object'){module.exports = factory(require('jquery'));} else {factory(jQuery);}}(function(jQuery) {
  10. /*! TableSorter (FORK) v2.31.2 *//*
  11. * Client-side table sorting with ease!
  12. * @requires jQuery v1.2.6+
  13. *
  14. * Copyright (c) 2007 Christian Bach
  15. * fork maintained by Rob Garrison
  16. *
  17. * Examples and original docs at: http://tablesorter.com
  18. * Dual licensed under the MIT and GPL licenses:
  19. * http://www.opensource.org/licenses/mit-license.php
  20. * http://www.gnu.org/licenses/gpl.html
  21. *
  22. * @type jQuery
  23. * @name tablesorter (FORK)
  24. * @cat Plugins/Tablesorter
  25. * @author Christian Bach - christian.bach@polyester.se
  26. * @contributor Rob Garrison - https://github.com/Mottie/tablesorter
  27. * @docs (fork) - https://mottie.github.io/tablesorter/docs/
  28. */
  29. /*jshint browser:true, jquery:true, unused:false, expr: true */
  30. ;( function( $ ) {
  31. 'use strict';
  32. var ts = $.tablesorter = {
  33. version : '2.31.2',
  34. parsers : [],
  35. widgets : [],
  36. defaults : {
  37. // *** appearance
  38. theme : 'default', // adds tablesorter-{theme} to the table for styling
  39. widthFixed : false, // adds colgroup to fix widths of columns
  40. showProcessing : false, // show an indeterminate timer icon in the header when the table is sorted or filtered.
  41. headerTemplate : '{content}',// header layout template (HTML ok); {content} = innerHTML, {icon} = <i/> // class from cssIcon
  42. onRenderTemplate : null, // function( index, template ) { return template; }, // template is a string
  43. onRenderHeader : null, // function( index ) {}, // nothing to return
  44. // *** functionality
  45. cancelSelection : true, // prevent text selection in the header
  46. tabIndex : true, // add tabindex to header for keyboard accessibility
  47. dateFormat : 'mmddyyyy', // other options: 'ddmmyyy' or 'yyyymmdd'
  48. sortMultiSortKey : 'shiftKey', // key used to select additional columns
  49. sortResetKey : 'ctrlKey', // key used to remove sorting on a column
  50. usNumberFormat : true, // false for German '1.234.567,89' or French '1 234 567,89'
  51. delayInit : false, // if false, the parsed table contents will not update until the first sort
  52. serverSideSorting: false, // if true, server-side sorting should be performed because client-side sorting will be disabled, but the ui and events will still be used.
  53. resort : true, // default setting to trigger a resort after an 'update', 'addRows', 'updateCell', etc has completed
  54. // *** sort options
  55. headers : {}, // set sorter, string, empty, locked order, sortInitialOrder, filter, etc.
  56. ignoreCase : true, // ignore case while sorting
  57. sortForce : null, // column(s) first sorted; always applied
  58. sortList : [], // Initial sort order; applied initially; updated when manually sorted
  59. sortAppend : null, // column(s) sorted last; always applied
  60. sortStable : false, // when sorting two rows with exactly the same content, the original sort order is maintained
  61. sortInitialOrder : 'asc', // sort direction on first click
  62. sortLocaleCompare: false, // replace equivalent character (accented characters)
  63. sortReset : false, // third click on the header will reset column to default - unsorted
  64. sortRestart : false, // restart sort to 'sortInitialOrder' when clicking on previously unsorted columns
  65. emptyTo : 'bottom', // sort empty cell to bottom, top, none, zero, emptyMax, emptyMin
  66. stringTo : 'max', // sort strings in numerical column as max, min, top, bottom, zero
  67. duplicateSpan : true, // colspan cells in the tbody will have duplicated content in the cache for each spanned column
  68. textExtraction : 'basic', // text extraction method/function - function( node, table, cellIndex ) {}
  69. textAttribute : 'data-text',// data-attribute that contains alternate cell text (used in default textExtraction function)
  70. textSorter : null, // choose overall or specific column sorter function( a, b, direction, table, columnIndex ) [alt: ts.sortText]
  71. numberSorter : null, // choose overall numeric sorter function( a, b, direction, maxColumnValue )
  72. // *** widget options
  73. initWidgets : true, // apply widgets on tablesorter initialization
  74. widgetClass : 'widget-{name}', // table class name template to match to include a widget
  75. widgets : [], // method to add widgets, e.g. widgets: ['zebra']
  76. widgetOptions : {
  77. zebra : [ 'even', 'odd' ] // zebra widget alternating row class names
  78. },
  79. // *** callbacks
  80. initialized : null, // function( table ) {},
  81. // *** extra css class names
  82. tableClass : '',
  83. cssAsc : '',
  84. cssDesc : '',
  85. cssNone : '',
  86. cssHeader : '',
  87. cssHeaderRow : '',
  88. cssProcessing : '', // processing icon applied to header during sort/filter
  89. cssChildRow : 'tablesorter-childRow', // class name indiciating that a row is to be attached to its parent
  90. cssInfoBlock : 'tablesorter-infoOnly', // don't sort tbody with this class name (only one class name allowed here!)
  91. cssNoSort : 'tablesorter-noSort', // class name added to element inside header; clicking on it won't cause a sort
  92. cssIgnoreRow : 'tablesorter-ignoreRow',// header row to ignore; cells within this row will not be added to c.$headers
  93. cssIcon : 'tablesorter-icon', // if this class does not exist, the {icon} will not be added from the headerTemplate
  94. cssIconNone : '', // class name added to the icon when there is no column sort
  95. cssIconAsc : '', // class name added to the icon when the column has an ascending sort
  96. cssIconDesc : '', // class name added to the icon when the column has a descending sort
  97. cssIconDisabled : '', // class name added to the icon when the column has a disabled sort
  98. // *** events
  99. pointerClick : 'click',
  100. pointerDown : 'mousedown',
  101. pointerUp : 'mouseup',
  102. // *** selectors
  103. selectorHeaders : '> thead th, > thead td',
  104. selectorSort : 'th, td', // jQuery selector of content within selectorHeaders that is clickable to trigger a sort
  105. selectorRemove : '.remove-me',
  106. // *** advanced
  107. debug : false,
  108. // *** Internal variables
  109. headerList: [],
  110. empties: {},
  111. strings: {},
  112. parsers: [],
  113. // *** parser options for validator; values must be falsy!
  114. globalize: 0,
  115. imgAttr: 0
  116. // removed: widgetZebra: { css: ['even', 'odd'] }
  117. },
  118. // internal css classes - these will ALWAYS be added to
  119. // the table and MUST only contain one class name - fixes #381
  120. css : {
  121. table : 'tablesorter',
  122. cssHasChild: 'tablesorter-hasChildRow',
  123. childRow : 'tablesorter-childRow',
  124. colgroup : 'tablesorter-colgroup',
  125. header : 'tablesorter-header',
  126. headerRow : 'tablesorter-headerRow',
  127. headerIn : 'tablesorter-header-inner',
  128. icon : 'tablesorter-icon',
  129. processing : 'tablesorter-processing',
  130. sortAsc : 'tablesorter-headerAsc',
  131. sortDesc : 'tablesorter-headerDesc',
  132. sortNone : 'tablesorter-headerUnSorted'
  133. },
  134. // labels applied to sortable headers for accessibility (aria) support
  135. language : {
  136. sortAsc : 'Ascending sort applied, ',
  137. sortDesc : 'Descending sort applied, ',
  138. sortNone : 'No sort applied, ',
  139. sortDisabled : 'sorting is disabled',
  140. nextAsc : 'activate to apply an ascending sort',
  141. nextDesc : 'activate to apply a descending sort',
  142. nextNone : 'activate to remove the sort'
  143. },
  144. regex : {
  145. templateContent : /\{content\}/g,
  146. templateIcon : /\{icon\}/g,
  147. templateName : /\{name\}/i,
  148. spaces : /\s+/g,
  149. nonWord : /\W/g,
  150. formElements : /(input|select|button|textarea)/i,
  151. // *** sort functions ***
  152. // regex used in natural sort
  153. // chunk/tokenize numbers & letters
  154. chunk : /(^([+\-]?(?:\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)?$|^0x[0-9a-f]+$|\d+)/gi,
  155. // replace chunks @ ends
  156. chunks : /(^\\0|\\0$)/,
  157. hex : /^0x[0-9a-f]+$/i,
  158. // *** formatFloat ***
  159. comma : /,/g,
  160. digitNonUS : /[\s|\.]/g,
  161. digitNegativeTest : /^\s*\([.\d]+\)/,
  162. digitNegativeReplace : /^\s*\(([.\d]+)\)/,
  163. // *** isDigit ***
  164. digitTest : /^[\-+(]?\d+[)]?$/,
  165. digitReplace : /[,.'"\s]/g
  166. },
  167. // digit sort, text location
  168. string : {
  169. max : 1,
  170. min : -1,
  171. emptymin : 1,
  172. emptymax : -1,
  173. zero : 0,
  174. none : 0,
  175. 'null' : 0,
  176. top : true,
  177. bottom : false
  178. },
  179. keyCodes : {
  180. enter : 13
  181. },
  182. // placeholder date parser data (globalize)
  183. dates : {},
  184. // These methods can be applied on table.config instance
  185. instanceMethods : {},
  186. /*
  187. ▄█████ ██████ ██████ ██ ██ █████▄
  188. ▀█▄ ██▄▄ ██ ██ ██ ██▄▄██
  189. ▀█▄ ██▀▀ ██ ██ ██ ██▀▀▀
  190. █████▀ ██████ ██ ▀████▀ ██
  191. */
  192. setup : function( table, c ) {
  193. // if no thead or tbody, or tablesorter is already present, quit
  194. if ( !table || !table.tHead || table.tBodies.length === 0 || table.hasInitialized === true ) {
  195. if ( ts.debug(c, 'core') ) {
  196. if ( table.hasInitialized ) {
  197. console.warn( 'Stopping initialization. Tablesorter has already been initialized' );
  198. } else {
  199. console.error( 'Stopping initialization! No table, thead or tbody', table );
  200. }
  201. }
  202. return;
  203. }
  204. var tmp = '',
  205. $table = $( table ),
  206. meta = $.metadata;
  207. // initialization flag
  208. table.hasInitialized = false;
  209. // table is being processed flag
  210. table.isProcessing = true;
  211. // make sure to store the config object
  212. table.config = c;
  213. // save the settings where they read
  214. $.data( table, 'tablesorter', c );
  215. if ( ts.debug(c, 'core') ) {
  216. console[ console.group ? 'group' : 'log' ]( 'Initializing tablesorter v' + ts.version );
  217. $.data( table, 'startoveralltimer', new Date() );
  218. }
  219. // removing this in version 3 (only supports jQuery 1.7+)
  220. c.supportsDataObject = ( function( version ) {
  221. version[ 0 ] = parseInt( version[ 0 ], 10 );
  222. return ( version[ 0 ] > 1 ) || ( version[ 0 ] === 1 && parseInt( version[ 1 ], 10 ) >= 4 );
  223. })( $.fn.jquery.split( '.' ) );
  224. // ensure case insensitivity
  225. c.emptyTo = c.emptyTo.toLowerCase();
  226. c.stringTo = c.stringTo.toLowerCase();
  227. c.last = { sortList : [], clickedIndex : -1 };
  228. // add table theme class only if there isn't already one there
  229. if ( !/tablesorter\-/.test( $table.attr( 'class' ) ) ) {
  230. tmp = ( c.theme !== '' ? ' tablesorter-' + c.theme : '' );
  231. }
  232. // give the table a unique id, which will be used in namespace binding
  233. if ( !c.namespace ) {
  234. c.namespace = '.tablesorter' + Math.random().toString( 16 ).slice( 2 );
  235. } else {
  236. // make sure namespace starts with a period & doesn't have weird characters
  237. c.namespace = '.' + c.namespace.replace( ts.regex.nonWord, '' );
  238. }
  239. c.table = table;
  240. c.$table = $table
  241. // add namespace to table to allow bindings on extra elements to target
  242. // the parent table (e.g. parser-input-select)
  243. .addClass( ts.css.table + ' ' + c.tableClass + tmp + ' ' + c.namespace.slice(1) )
  244. .attr( 'role', 'grid' );
  245. c.$headers = $table.find( c.selectorHeaders );
  246. c.$table.children().children( 'tr' ).attr( 'role', 'row' );
  247. c.$tbodies = $table.children( 'tbody:not(.' + c.cssInfoBlock + ')' ).attr({
  248. 'aria-live' : 'polite',
  249. 'aria-relevant' : 'all'
  250. });
  251. if ( c.$table.children( 'caption' ).length ) {
  252. tmp = c.$table.children( 'caption' )[ 0 ];
  253. if ( !tmp.id ) { tmp.id = c.namespace.slice( 1 ) + 'caption'; }
  254. c.$table.attr( 'aria-labelledby', tmp.id );
  255. }
  256. c.widgetInit = {}; // keep a list of initialized widgets
  257. // change textExtraction via data-attribute
  258. c.textExtraction = c.$table.attr( 'data-text-extraction' ) || c.textExtraction || 'basic';
  259. // build headers
  260. ts.buildHeaders( c );
  261. // fixate columns if the users supplies the fixedWidth option
  262. // do this after theme has been applied
  263. ts.fixColumnWidth( table );
  264. // add widgets from class name
  265. ts.addWidgetFromClass( table );
  266. // add widget options before parsing (e.g. grouping widget has parser settings)
  267. ts.applyWidgetOptions( table );
  268. // try to auto detect column type, and store in tables config
  269. ts.setupParsers( c );
  270. // start total row count at zero
  271. c.totalRows = 0;
  272. // only validate options while debugging. See #1528
  273. if (c.debug) {
  274. ts.validateOptions( c );
  275. }
  276. // build the cache for the tbody cells
  277. // delayInit will delay building the cache until the user starts a sort
  278. if ( !c.delayInit ) { ts.buildCache( c ); }
  279. // bind all header events and methods
  280. ts.bindEvents( table, c.$headers, true );
  281. ts.bindMethods( c );
  282. // get sort list from jQuery data or metadata
  283. // in jQuery < 1.4, an error occurs when calling $table.data()
  284. if ( c.supportsDataObject && typeof $table.data().sortlist !== 'undefined' ) {
  285. c.sortList = $table.data().sortlist;
  286. } else if ( meta && ( $table.metadata() && $table.metadata().sortlist ) ) {
  287. c.sortList = $table.metadata().sortlist;
  288. }
  289. // apply widget init code
  290. ts.applyWidget( table, true );
  291. // if user has supplied a sort list to constructor
  292. if ( c.sortList.length > 0 ) {
  293. // save sortList before any sortAppend is added
  294. c.last.sortList = c.sortList;
  295. ts.sortOn( c, c.sortList, {}, !c.initWidgets );
  296. } else {
  297. ts.setHeadersCss( c );
  298. if ( c.initWidgets ) {
  299. // apply widget format
  300. ts.applyWidget( table, false );
  301. }
  302. }
  303. // show processesing icon
  304. if ( c.showProcessing ) {
  305. $table
  306. .unbind( 'sortBegin' + c.namespace + ' sortEnd' + c.namespace )
  307. .bind( 'sortBegin' + c.namespace + ' sortEnd' + c.namespace, function( e ) {
  308. clearTimeout( c.timerProcessing );
  309. ts.isProcessing( table );
  310. if ( e.type === 'sortBegin' ) {
  311. c.timerProcessing = setTimeout( function() {
  312. ts.isProcessing( table, true );
  313. }, 500 );
  314. }
  315. });
  316. }
  317. // initialized
  318. table.hasInitialized = true;
  319. table.isProcessing = false;
  320. if ( ts.debug(c, 'core') ) {
  321. console.log( 'Overall initialization time:' + ts.benchmark( $.data( table, 'startoveralltimer' ) ) );
  322. if ( ts.debug(c, 'core') && console.groupEnd ) { console.groupEnd(); }
  323. }
  324. $table.triggerHandler( 'tablesorter-initialized', table );
  325. if ( typeof c.initialized === 'function' ) {
  326. c.initialized( table );
  327. }
  328. },
  329. bindMethods : function( c ) {
  330. var $table = c.$table,
  331. namespace = c.namespace,
  332. events = ( 'sortReset update updateRows updateAll updateHeaders addRows updateCell updateComplete ' +
  333. 'sorton appendCache updateCache applyWidgetId applyWidgets refreshWidgets destroy mouseup ' +
  334. 'mouseleave ' ).split( ' ' )
  335. .join( namespace + ' ' );
  336. // apply easy methods that trigger bound events
  337. $table
  338. .unbind( events.replace( ts.regex.spaces, ' ' ) )
  339. .bind( 'sortReset' + namespace, function( e, callback ) {
  340. e.stopPropagation();
  341. // using this.config to ensure functions are getting a non-cached version of the config
  342. ts.sortReset( this.config, function( table ) {
  343. if (table.isApplyingWidgets) {
  344. // multiple triggers in a row... filterReset, then sortReset - see #1361
  345. // wait to update widgets
  346. setTimeout( function() {
  347. ts.applyWidget( table, '', callback );
  348. }, 100 );
  349. } else {
  350. ts.applyWidget( table, '', callback );
  351. }
  352. });
  353. })
  354. .bind( 'updateAll' + namespace, function( e, resort, callback ) {
  355. e.stopPropagation();
  356. ts.updateAll( this.config, resort, callback );
  357. })
  358. .bind( 'update' + namespace + ' updateRows' + namespace, function( e, resort, callback ) {
  359. e.stopPropagation();
  360. ts.update( this.config, resort, callback );
  361. })
  362. .bind( 'updateHeaders' + namespace, function( e, callback ) {
  363. e.stopPropagation();
  364. ts.updateHeaders( this.config, callback );
  365. })
  366. .bind( 'updateCell' + namespace, function( e, cell, resort, callback ) {
  367. e.stopPropagation();
  368. ts.updateCell( this.config, cell, resort, callback );
  369. })
  370. .bind( 'addRows' + namespace, function( e, $row, resort, callback ) {
  371. e.stopPropagation();
  372. ts.addRows( this.config, $row, resort, callback );
  373. })
  374. .bind( 'updateComplete' + namespace, function() {
  375. this.isUpdating = false;
  376. })
  377. .bind( 'sorton' + namespace, function( e, list, callback, init ) {
  378. e.stopPropagation();
  379. ts.sortOn( this.config, list, callback, init );
  380. })
  381. .bind( 'appendCache' + namespace, function( e, callback, init ) {
  382. e.stopPropagation();
  383. ts.appendCache( this.config, init );
  384. if ( $.isFunction( callback ) ) {
  385. callback( this );
  386. }
  387. })
  388. // $tbodies variable is used by the tbody sorting widget
  389. .bind( 'updateCache' + namespace, function( e, callback, $tbodies ) {
  390. e.stopPropagation();
  391. ts.updateCache( this.config, callback, $tbodies );
  392. })
  393. .bind( 'applyWidgetId' + namespace, function( e, id ) {
  394. e.stopPropagation();
  395. ts.applyWidgetId( this, id );
  396. })
  397. .bind( 'applyWidgets' + namespace, function( e, callback ) {
  398. e.stopPropagation();
  399. // apply widgets (false = not initializing)
  400. ts.applyWidget( this, false, callback );
  401. })
  402. .bind( 'refreshWidgets' + namespace, function( e, all, dontapply ) {
  403. e.stopPropagation();
  404. ts.refreshWidgets( this, all, dontapply );
  405. })
  406. .bind( 'removeWidget' + namespace, function( e, name, refreshing ) {
  407. e.stopPropagation();
  408. ts.removeWidget( this, name, refreshing );
  409. })
  410. .bind( 'destroy' + namespace, function( e, removeClasses, callback ) {
  411. e.stopPropagation();
  412. ts.destroy( this, removeClasses, callback );
  413. })
  414. .bind( 'resetToLoadState' + namespace, function( e ) {
  415. e.stopPropagation();
  416. // remove all widgets
  417. ts.removeWidget( this, true, false );
  418. var tmp = $.extend( true, {}, c.originalSettings );
  419. // restore original settings; this clears out current settings, but does not clear
  420. // values saved to storage.
  421. c = $.extend( true, {}, ts.defaults, tmp );
  422. c.originalSettings = tmp;
  423. this.hasInitialized = false;
  424. // setup the entire table again
  425. ts.setup( this, c );
  426. });
  427. },
  428. bindEvents : function( table, $headers, core ) {
  429. table = $( table )[ 0 ];
  430. var tmp,
  431. c = table.config,
  432. namespace = c.namespace,
  433. downTarget = null;
  434. if ( core !== true ) {
  435. $headers.addClass( namespace.slice( 1 ) + '_extra_headers' );
  436. tmp = ts.getClosest( $headers, 'table' );
  437. if ( tmp.length && tmp[ 0 ].nodeName === 'TABLE' && tmp[ 0 ] !== table ) {
  438. $( tmp[ 0 ] ).addClass( namespace.slice( 1 ) + '_extra_table' );
  439. }
  440. }
  441. tmp = ( c.pointerDown + ' ' + c.pointerUp + ' ' + c.pointerClick + ' sort keyup ' )
  442. .replace( ts.regex.spaces, ' ' )
  443. .split( ' ' )
  444. .join( namespace + ' ' );
  445. // apply event handling to headers and/or additional headers (stickyheaders, scroller, etc)
  446. $headers
  447. // http://stackoverflow.com/questions/5312849/jquery-find-self;
  448. .find( c.selectorSort )
  449. .add( $headers.filter( c.selectorSort ) )
  450. .unbind( tmp )
  451. .bind( tmp, function( e, external ) {
  452. var $cell, cell, temp,
  453. $target = $( e.target ),
  454. // wrap event type in spaces, so the match doesn't trigger on inner words
  455. type = ' ' + e.type + ' ';
  456. // only recognize left clicks
  457. if ( ( ( e.which || e.button ) !== 1 && !type.match( ' ' + c.pointerClick + ' | sort | keyup ' ) ) ||
  458. // allow pressing enter
  459. ( type === ' keyup ' && e.which !== ts.keyCodes.enter ) ||
  460. // allow triggering a click event (e.which is undefined) & ignore physical clicks
  461. ( type.match( ' ' + c.pointerClick + ' ' ) && typeof e.which !== 'undefined' ) ) {
  462. return;
  463. }
  464. // ignore mouseup if mousedown wasn't on the same target
  465. if ( type.match( ' ' + c.pointerUp + ' ' ) && downTarget !== e.target && external !== true ) {
  466. return;
  467. }
  468. // set target on mousedown
  469. if ( type.match( ' ' + c.pointerDown + ' ' ) ) {
  470. downTarget = e.target;
  471. // preventDefault needed or jQuery v1.3.2 and older throws an
  472. // "Uncaught TypeError: handler.apply is not a function" error
  473. temp = $target.jquery.split( '.' );
  474. if ( temp[ 0 ] === '1' && temp[ 1 ] < 4 ) { e.preventDefault(); }
  475. return;
  476. }
  477. downTarget = null;
  478. $cell = ts.getClosest( $( this ), '.' + ts.css.header );
  479. // prevent sort being triggered on form elements
  480. if ( ts.regex.formElements.test( e.target.nodeName ) ||
  481. // nosort class name, or elements within a nosort container
  482. $target.hasClass( c.cssNoSort ) || $target.parents( '.' + c.cssNoSort ).length > 0 ||
  483. // disabled cell directly clicked
  484. $cell.hasClass( 'sorter-false' ) ||
  485. // elements within a button
  486. $target.parents( 'button' ).length > 0 ) {
  487. return !c.cancelSelection;
  488. }
  489. if ( c.delayInit && ts.isEmptyObject( c.cache ) ) {
  490. ts.buildCache( c );
  491. }
  492. // use column index from data-attribute or index of current row; fixes #1116
  493. c.last.clickedIndex = $cell.attr( 'data-column' ) || $cell.index();
  494. cell = c.$headerIndexed[ c.last.clickedIndex ][0];
  495. if ( cell && !cell.sortDisabled ) {
  496. ts.initSort( c, cell, e );
  497. }
  498. });
  499. if ( c.cancelSelection ) {
  500. // cancel selection
  501. $headers
  502. .attr( 'unselectable', 'on' )
  503. .bind( 'selectstart', false )
  504. .css({
  505. 'user-select' : 'none',
  506. 'MozUserSelect' : 'none' // not needed for jQuery 1.8+
  507. });
  508. }
  509. },
  510. buildHeaders : function( c ) {
  511. var $temp, icon, timer, indx;
  512. c.headerList = [];
  513. c.headerContent = [];
  514. c.sortVars = [];
  515. if ( ts.debug(c, 'core') ) {
  516. timer = new Date();
  517. }
  518. // children tr in tfoot - see issue #196 & #547
  519. // don't pass table.config to computeColumnIndex here - widgets (math) pass it to "quickly" index tbody cells
  520. c.columns = ts.computeColumnIndex( c.$table.children( 'thead, tfoot' ).children( 'tr' ) );
  521. // add icon if cssIcon option exists
  522. icon = c.cssIcon ?
  523. '<i class="' + ( c.cssIcon === ts.css.icon ? ts.css.icon : c.cssIcon + ' ' + ts.css.icon ) + '"></i>' :
  524. '';
  525. // redefine c.$headers here in case of an updateAll that replaces or adds an entire header cell - see #683
  526. c.$headers = $( $.map( c.$table.find( c.selectorHeaders ), function( elem, index ) {
  527. var configHeaders, header, column, template, tmp,
  528. $elem = $( elem );
  529. // ignore cell (don't add it to c.$headers) if row has ignoreRow class
  530. if ( ts.getClosest( $elem, 'tr' ).hasClass( c.cssIgnoreRow ) ) { return; }
  531. // transfer data-column to element if not th/td - #1459
  532. if ( !/(th|td)/i.test( elem.nodeName ) ) {
  533. tmp = ts.getClosest( $elem, 'th, td' );
  534. $elem.attr( 'data-column', tmp.attr( 'data-column' ) );
  535. }
  536. // make sure to get header cell & not column indexed cell
  537. configHeaders = ts.getColumnData( c.table, c.headers, index, true );
  538. // save original header content
  539. c.headerContent[ index ] = $elem.html();
  540. // if headerTemplate is empty, don't reformat the header cell
  541. if ( c.headerTemplate !== '' && !$elem.find( '.' + ts.css.headerIn ).length ) {
  542. // set up header template
  543. template = c.headerTemplate
  544. .replace( ts.regex.templateContent, $elem.html() )
  545. .replace( ts.regex.templateIcon, $elem.find( '.' + ts.css.icon ).length ? '' : icon );
  546. if ( c.onRenderTemplate ) {
  547. header = c.onRenderTemplate.apply( $elem, [ index, template ] );
  548. // only change t if something is returned
  549. if ( header && typeof header === 'string' ) {
  550. template = header;
  551. }
  552. }
  553. $elem.html( '<div class="' + ts.css.headerIn + '">' + template + '</div>' ); // faster than wrapInner
  554. }
  555. if ( c.onRenderHeader ) {
  556. c.onRenderHeader.apply( $elem, [ index, c, c.$table ] );
  557. }
  558. column = parseInt( $elem.attr( 'data-column' ), 10 );
  559. elem.column = column;
  560. tmp = ts.getOrder( ts.getData( $elem, configHeaders, 'sortInitialOrder' ) || c.sortInitialOrder );
  561. // this may get updated numerous times if there are multiple rows
  562. c.sortVars[ column ] = {
  563. count : -1, // set to -1 because clicking on the header automatically adds one
  564. order : tmp ?
  565. ( c.sortReset ? [ 1, 0, 2 ] : [ 1, 0 ] ) : // desc, asc, unsorted
  566. ( c.sortReset ? [ 0, 1, 2 ] : [ 0, 1 ] ), // asc, desc, unsorted
  567. lockedOrder : false,
  568. sortedBy : ''
  569. };
  570. tmp = ts.getData( $elem, configHeaders, 'lockedOrder' ) || false;
  571. if ( typeof tmp !== 'undefined' && tmp !== false ) {
  572. c.sortVars[ column ].lockedOrder = true;
  573. c.sortVars[ column ].order = ts.getOrder( tmp ) ? [ 1, 1 ] : [ 0, 0 ];
  574. }
  575. // add cell to headerList
  576. c.headerList[ index ] = elem;
  577. $elem.addClass( ts.css.header + ' ' + c.cssHeader );
  578. // add to parent in case there are multiple rows
  579. ts.getClosest( $elem, 'tr' )
  580. .addClass( ts.css.headerRow + ' ' + c.cssHeaderRow )
  581. .attr( 'role', 'row' );
  582. // allow keyboard cursor to focus on element
  583. if ( c.tabIndex ) {
  584. $elem.attr( 'tabindex', 0 );
  585. }
  586. return elem;
  587. }) );
  588. // cache headers per column
  589. c.$headerIndexed = [];
  590. for ( indx = 0; indx < c.columns; indx++ ) {
  591. // colspan in header making a column undefined
  592. if ( ts.isEmptyObject( c.sortVars[ indx ] ) ) {
  593. c.sortVars[ indx ] = {};
  594. }
  595. // Use c.$headers.parent() in case selectorHeaders doesn't point to the th/td
  596. $temp = c.$headers.filter( '[data-column="' + indx + '"]' );
  597. // target sortable column cells, unless there are none, then use non-sortable cells
  598. // .last() added in jQuery 1.4; use .filter(':last') to maintain compatibility with jQuery v1.2.6
  599. c.$headerIndexed[ indx ] = $temp.length ?
  600. $temp.not( '.sorter-false' ).length ?
  601. $temp.not( '.sorter-false' ).filter( ':last' ) :
  602. $temp.filter( ':last' ) :
  603. $();
  604. }
  605. c.$table.find( c.selectorHeaders ).attr({
  606. scope: 'col',
  607. role : 'columnheader'
  608. });
  609. // enable/disable sorting
  610. ts.updateHeader( c );
  611. if ( ts.debug(c, 'core') ) {
  612. console.log( 'Built headers:' + ts.benchmark( timer ) );
  613. console.log( c.$headers );
  614. }
  615. },
  616. // Use it to add a set of methods to table.config which will be available for all tables.
  617. // This should be done before table initialization
  618. addInstanceMethods : function( methods ) {
  619. $.extend( ts.instanceMethods, methods );
  620. },
  621. /*
  622. █████▄ ▄████▄ █████▄ ▄█████ ██████ █████▄ ▄█████
  623. ██▄▄██ ██▄▄██ ██▄▄██ ▀█▄ ██▄▄ ██▄▄██ ▀█▄
  624. ██▀▀▀ ██▀▀██ ██▀██ ▀█▄ ██▀▀ ██▀██ ▀█▄
  625. ██ ██ ██ ██ ██ █████▀ ██████ ██ ██ █████▀
  626. */
  627. setupParsers : function( c, $tbodies ) {
  628. var rows, list, span, max, colIndex, indx, header, configHeaders,
  629. noParser, parser, extractor, time, tbody, len,
  630. table = c.table,
  631. tbodyIndex = 0,
  632. debug = ts.debug(c, 'core'),
  633. debugOutput = {};
  634. // update table bodies in case we start with an empty table
  635. c.$tbodies = c.$table.children( 'tbody:not(.' + c.cssInfoBlock + ')' );
  636. tbody = typeof $tbodies === 'undefined' ? c.$tbodies : $tbodies;
  637. len = tbody.length;
  638. if ( len === 0 ) {
  639. return debug ? console.warn( 'Warning: *Empty table!* Not building a parser cache' ) : '';
  640. } else if ( debug ) {
  641. time = new Date();
  642. console[ console.group ? 'group' : 'log' ]( 'Detecting parsers for each column' );
  643. }
  644. list = {
  645. extractors: [],
  646. parsers: []
  647. };
  648. while ( tbodyIndex < len ) {
  649. rows = tbody[ tbodyIndex ].rows;
  650. if ( rows.length ) {
  651. colIndex = 0;
  652. max = c.columns;
  653. for ( indx = 0; indx < max; indx++ ) {
  654. header = c.$headerIndexed[ colIndex ];
  655. if ( header && header.length ) {
  656. // get column indexed table cell; adding true parameter fixes #1362 but
  657. // it would break backwards compatibility...
  658. configHeaders = ts.getColumnData( table, c.headers, colIndex ); // , true );
  659. // get column parser/extractor
  660. extractor = ts.getParserById( ts.getData( header, configHeaders, 'extractor' ) );
  661. parser = ts.getParserById( ts.getData( header, configHeaders, 'sorter' ) );
  662. noParser = ts.getData( header, configHeaders, 'parser' ) === 'false';
  663. // empty cells behaviour - keeping emptyToBottom for backwards compatibility
  664. c.empties[colIndex] = (
  665. ts.getData( header, configHeaders, 'empty' ) ||
  666. c.emptyTo || ( c.emptyToBottom ? 'bottom' : 'top' ) ).toLowerCase();
  667. // text strings behaviour in numerical sorts
  668. c.strings[colIndex] = (
  669. ts.getData( header, configHeaders, 'string' ) ||
  670. c.stringTo ||
  671. 'max' ).toLowerCase();
  672. if ( noParser ) {
  673. parser = ts.getParserById( 'no-parser' );
  674. }
  675. if ( !extractor ) {
  676. // For now, maybe detect someday
  677. extractor = false;
  678. }
  679. if ( !parser ) {
  680. parser = ts.detectParserForColumn( c, rows, -1, colIndex );
  681. }
  682. if ( debug ) {
  683. debugOutput[ '(' + colIndex + ') ' + header.text() ] = {
  684. parser : parser.id,
  685. extractor : extractor ? extractor.id : 'none',
  686. string : c.strings[ colIndex ],
  687. empty : c.empties[ colIndex ]
  688. };
  689. }
  690. list.parsers[ colIndex ] = parser;
  691. list.extractors[ colIndex ] = extractor;
  692. span = header[ 0 ].colSpan - 1;
  693. if ( span > 0 ) {
  694. colIndex += span;
  695. max += span;
  696. while ( span + 1 > 0 ) {
  697. // set colspan columns to use the same parsers & extractors
  698. list.parsers[ colIndex - span ] = parser;
  699. list.extractors[ colIndex - span ] = extractor;
  700. span--;
  701. }
  702. }
  703. }
  704. colIndex++;
  705. }
  706. }
  707. tbodyIndex += ( list.parsers.length ) ? len : 1;
  708. }
  709. if ( debug ) {
  710. if ( !ts.isEmptyObject( debugOutput ) ) {
  711. console[ console.table ? 'table' : 'log' ]( debugOutput );
  712. } else {
  713. console.warn( ' No parsers detected!' );
  714. }
  715. console.log( 'Completed detecting parsers' + ts.benchmark( time ) );
  716. if ( console.groupEnd ) { console.groupEnd(); }
  717. }
  718. c.parsers = list.parsers;
  719. c.extractors = list.extractors;
  720. },
  721. addParser : function( parser ) {
  722. var indx,
  723. len = ts.parsers.length,
  724. add = true;
  725. for ( indx = 0; indx < len; indx++ ) {
  726. if ( ts.parsers[ indx ].id.toLowerCase() === parser.id.toLowerCase() ) {
  727. add = false;
  728. }
  729. }
  730. if ( add ) {
  731. ts.parsers[ ts.parsers.length ] = parser;
  732. }
  733. },
  734. getParserById : function( name ) {
  735. /*jshint eqeqeq:false */ // eslint-disable-next-line eqeqeq
  736. if ( name == 'false' ) { return false; }
  737. var indx,
  738. len = ts.parsers.length;
  739. for ( indx = 0; indx < len; indx++ ) {
  740. if ( ts.parsers[ indx ].id.toLowerCase() === ( name.toString() ).toLowerCase() ) {
  741. return ts.parsers[ indx ];
  742. }
  743. }
  744. return false;
  745. },
  746. detectParserForColumn : function( c, rows, rowIndex, cellIndex ) {
  747. var cur, $node, row,
  748. indx = ts.parsers.length,
  749. node = false,
  750. nodeValue = '',
  751. debug = ts.debug(c, 'core'),
  752. keepLooking = true;
  753. while ( nodeValue === '' && keepLooking ) {
  754. rowIndex++;
  755. row = rows[ rowIndex ];
  756. // stop looking after 50 empty rows
  757. if ( row && rowIndex < 50 ) {
  758. if ( row.className.indexOf( ts.cssIgnoreRow ) < 0 ) {
  759. node = rows[ rowIndex ].cells[ cellIndex ];
  760. nodeValue = ts.getElementText( c, node, cellIndex );
  761. $node = $( node );
  762. if ( debug ) {
  763. console.log( 'Checking if value was empty on row ' + rowIndex + ', column: ' +
  764. cellIndex + ': "' + nodeValue + '"' );
  765. }
  766. }
  767. } else {
  768. keepLooking = false;
  769. }
  770. }
  771. while ( --indx >= 0 ) {
  772. cur = ts.parsers[ indx ];
  773. // ignore the default text parser because it will always be true
  774. if ( cur && cur.id !== 'text' && cur.is && cur.is( nodeValue, c.table, node, $node ) ) {
  775. return cur;
  776. }
  777. }
  778. // nothing found, return the generic parser (text)
  779. return ts.getParserById( 'text' );
  780. },
  781. getElementText : function( c, node, cellIndex ) {
  782. if ( !node ) { return ''; }
  783. var tmp,
  784. extract = c.textExtraction || '',
  785. // node could be a jquery object
  786. // http://jsperf.com/jquery-vs-instanceof-jquery/2
  787. $node = node.jquery ? node : $( node );
  788. if ( typeof extract === 'string' ) {
  789. // check data-attribute first when set to 'basic'; don't use node.innerText - it's really slow!
  790. // http://www.kellegous.com/j/2013/02/27/innertext-vs-textcontent/
  791. if ( extract === 'basic' && typeof ( tmp = $node.attr( c.textAttribute ) ) !== 'undefined' ) {
  792. return $.trim( tmp );
  793. }
  794. return $.trim( node.textContent || $node.text() );
  795. } else {
  796. if ( typeof extract === 'function' ) {
  797. return $.trim( extract( $node[ 0 ], c.table, cellIndex ) );
  798. } else if ( typeof ( tmp = ts.getColumnData( c.table, extract, cellIndex ) ) === 'function' ) {
  799. return $.trim( tmp( $node[ 0 ], c.table, cellIndex ) );
  800. }
  801. }
  802. // fallback
  803. return $.trim( $node[ 0 ].textContent || $node.text() );
  804. },
  805. // centralized function to extract/parse cell contents
  806. getParsedText : function( c, cell, colIndex, txt ) {
  807. if ( typeof txt === 'undefined' ) {
  808. txt = ts.getElementText( c, cell, colIndex );
  809. }
  810. // if no parser, make sure to return the txt
  811. var val = '' + txt,
  812. parser = c.parsers[ colIndex ],
  813. extractor = c.extractors[ colIndex ];
  814. if ( parser ) {
  815. // do extract before parsing, if there is one
  816. if ( extractor && typeof extractor.format === 'function' ) {
  817. txt = extractor.format( txt, c.table, cell, colIndex );
  818. }
  819. // allow parsing if the string is empty, previously parsing would change it to zero,
  820. // in case the parser needs to extract data from the table cell attributes
  821. val = parser.id === 'no-parser' ? '' :
  822. // make sure txt is a string (extractor may have converted it)
  823. parser.format( '' + txt, c.table, cell, colIndex );
  824. if ( c.ignoreCase && typeof val === 'string' ) {
  825. val = val.toLowerCase();
  826. }
  827. }
  828. return val;
  829. },
  830. /*
  831. ▄████▄ ▄████▄ ▄████▄ ██ ██ ██████
  832. ██ ▀▀ ██▄▄██ ██ ▀▀ ██▄▄██ ██▄▄
  833. ██ ▄▄ ██▀▀██ ██ ▄▄ ██▀▀██ ██▀▀
  834. ▀████▀ ██ ██ ▀████▀ ██ ██ ██████
  835. */
  836. buildCache : function( c, callback, $tbodies ) {
  837. var cache, val, txt, rowIndex, colIndex, tbodyIndex, $tbody, $row,
  838. cols, $cells, cell, cacheTime, totalRows, rowData, prevRowData,
  839. colMax, span, cacheIndex, hasParser, max, len, index,
  840. table = c.table,
  841. parsers = c.parsers,
  842. debug = ts.debug(c, 'core');
  843. // update tbody variable
  844. c.$tbodies = c.$table.children( 'tbody:not(.' + c.cssInfoBlock + ')' );
  845. $tbody = typeof $tbodies === 'undefined' ? c.$tbodies : $tbodies,
  846. c.cache = {};
  847. c.totalRows = 0;
  848. // if no parsers found, return - it's an empty table.
  849. if ( !parsers ) {
  850. return debug ? console.warn( 'Warning: *Empty table!* Not building a cache' ) : '';
  851. }
  852. if ( debug ) {
  853. cacheTime = new Date();
  854. }
  855. // processing icon
  856. if ( c.showProcessing ) {
  857. ts.isProcessing( table, true );
  858. }
  859. for ( tbodyIndex = 0; tbodyIndex < $tbody.length; tbodyIndex++ ) {
  860. colMax = []; // column max value per tbody
  861. cache = c.cache[ tbodyIndex ] = {
  862. normalized: [] // array of normalized row data; last entry contains 'rowData' above
  863. // colMax: # // added at the end
  864. };
  865. totalRows = ( $tbody[ tbodyIndex ] && $tbody[ tbodyIndex ].rows.length ) || 0;
  866. for ( rowIndex = 0; rowIndex < totalRows; ++rowIndex ) {
  867. rowData = {
  868. // order: original row order #
  869. // $row : jQuery Object[]
  870. child: [], // child row text (filter widget)
  871. raw: [] // original row text
  872. };
  873. /** Add the table data to main data array */
  874. $row = $( $tbody[ tbodyIndex ].rows[ rowIndex ] );
  875. cols = [];
  876. // ignore "remove-me" rows
  877. if ( $row.hasClass( c.selectorRemove.slice(1) ) ) {
  878. continue;
  879. }
  880. // if this is a child row, add it to the last row's children and continue to the next row
  881. // ignore child row class, if it is the first row
  882. if ( $row.hasClass( c.cssChildRow ) && rowIndex !== 0 ) {
  883. len = cache.normalized.length - 1;
  884. prevRowData = cache.normalized[ len ][ c.columns ];
  885. prevRowData.$row = prevRowData.$row.add( $row );
  886. // add 'hasChild' class name to parent row
  887. if ( !$row.prev().hasClass( c.cssChildRow ) ) {
  888. $row.prev().addClass( ts.css.cssHasChild );
  889. }
  890. // save child row content (un-parsed!)
  891. $cells = $row.children( 'th, td' );
  892. len = prevRowData.child.length;
  893. prevRowData.child[ len ] = [];
  894. // child row content does not account for colspans/rowspans; so indexing may be off
  895. cacheIndex = 0;
  896. max = c.columns;
  897. for ( colIndex = 0; colIndex < max; colIndex++ ) {
  898. cell = $cells[ colIndex ];
  899. if ( cell ) {
  900. prevRowData.child[ len ][ colIndex ] = ts.getParsedText( c, cell, colIndex );
  901. span = $cells[ colIndex ].colSpan - 1;
  902. if ( span > 0 ) {
  903. cacheIndex += span;
  904. max += span;
  905. }
  906. }
  907. cacheIndex++;
  908. }
  909. // go to the next for loop
  910. continue;
  911. }
  912. rowData.$row = $row;
  913. rowData.order = rowIndex; // add original row position to rowCache
  914. cacheIndex = 0;
  915. max = c.columns;
  916. for ( colIndex = 0; colIndex < max; ++colIndex ) {
  917. cell = $row[ 0 ].cells[ colIndex ];
  918. if ( cell && cacheIndex < c.columns ) {
  919. hasParser = typeof parsers[ cacheIndex ] !== 'undefined';
  920. if ( !hasParser && debug ) {
  921. console.warn( 'No parser found for row: ' + rowIndex + ', column: ' + colIndex +
  922. '; cell containing: "' + $(cell).text() + '"; does it have a header?' );
  923. }
  924. val = ts.getElementText( c, cell, cacheIndex );
  925. rowData.raw[ cacheIndex ] = val; // save original row text
  926. // save raw column text even if there is no parser set
  927. txt = ts.getParsedText( c, cell, cacheIndex, val );
  928. cols[ cacheIndex ] = txt;
  929. if ( hasParser && ( parsers[ cacheIndex ].type || '' ).toLowerCase() === 'numeric' ) {
  930. // determine column max value (ignore sign)
  931. colMax[ cacheIndex ] = Math.max( Math.abs( txt ) || 0, colMax[ cacheIndex ] || 0 );
  932. }
  933. // allow colSpan in tbody
  934. span = cell.colSpan - 1;
  935. if ( span > 0 ) {
  936. index = 0;
  937. while ( index <= span ) {
  938. // duplicate text (or not) to spanned columns
  939. // instead of setting duplicate span to empty string, use textExtraction to try to get a value
  940. // see http://stackoverflow.com/q/36449711/145346
  941. txt = c.duplicateSpan || index === 0 ?
  942. val :
  943. typeof c.textExtraction !== 'string' ?
  944. ts.getElementText( c, cell, cacheIndex + index ) || '' :
  945. '';
  946. rowData.raw[ cacheIndex + index ] = txt;
  947. cols[ cacheIndex + index ] = txt;
  948. index++;
  949. }
  950. cacheIndex += span;
  951. max += span;
  952. }
  953. }
  954. cacheIndex++;
  955. }
  956. // ensure rowData is always in the same location (after the last column)
  957. cols[ c.columns ] = rowData;
  958. cache.normalized[ cache.normalized.length ] = cols;
  959. }
  960. cache.colMax = colMax;
  961. // total up rows, not including child rows
  962. c.totalRows += cache.normalized.length;
  963. }
  964. if ( c.showProcessing ) {
  965. ts.isProcessing( table ); // remove processing icon
  966. }
  967. if ( debug ) {
  968. len = Math.min( 5, c.cache[ 0 ].normalized.length );
  969. console[ console.group ? 'group' : 'log' ]( 'Building cache for ' + c.totalRows +
  970. ' rows (showing ' + len + ' rows in log) and ' + c.columns + ' columns' +
  971. ts.benchmark( cacheTime ) );
  972. val = {};
  973. for ( colIndex = 0; colIndex < c.columns; colIndex++ ) {
  974. for ( cacheIndex = 0; cacheIndex < len; cacheIndex++ ) {
  975. if ( !val[ 'row: ' + cacheIndex ] ) {
  976. val[ 'row: ' + cacheIndex ] = {};
  977. }
  978. val[ 'row: ' + cacheIndex ][ c.$headerIndexed[ colIndex ].text() ] =
  979. c.cache[ 0 ].normalized[ cacheIndex ][ colIndex ];
  980. }
  981. }
  982. console[ console.table ? 'table' : 'log' ]( val );
  983. if ( console.groupEnd ) { console.groupEnd(); }
  984. }
  985. if ( $.isFunction( callback ) ) {
  986. callback( table );
  987. }
  988. },
  989. getColumnText : function( table, column, callback, rowFilter ) {
  990. table = $( table )[0];
  991. var tbodyIndex, rowIndex, cache, row, tbodyLen, rowLen, raw, parsed, $cell, result,
  992. hasCallback = typeof callback === 'function',
  993. allColumns = column === 'all',
  994. data = { raw : [], parsed: [], $cell: [] },
  995. c = table.config;
  996. if ( ts.isEmptyObject( c ) ) {
  997. if ( ts.debug(c, 'core') ) {
  998. console.warn( 'No cache found - aborting getColumnText function!' );
  999. }
  1000. } else {
  1001. tbodyLen = c.$tbodies.length;
  1002. for ( tbodyIndex = 0; tbodyIndex < tbodyLen; tbodyIndex++ ) {
  1003. cache = c.cache[ tbodyIndex ].normalized;
  1004. rowLen = cache.length;
  1005. for ( rowIndex = 0; rowIndex < rowLen; rowIndex++ ) {
  1006. row = cache[ rowIndex ];
  1007. if ( rowFilter && !row[ c.columns ].$row.is( rowFilter ) ) {
  1008. continue;
  1009. }
  1010. result = true;
  1011. parsed = ( allColumns ) ? row.slice( 0, c.columns ) : row[ column ];
  1012. row = row[ c.columns ];
  1013. raw = ( allColumns ) ? row.raw : row.raw[ column ];
  1014. $cell = ( allColumns ) ? row.$row.children() : row.$row.children().eq( column );
  1015. if ( hasCallback ) {
  1016. result = callback({
  1017. tbodyIndex : tbodyIndex,
  1018. rowIndex : rowIndex,
  1019. parsed : parsed,
  1020. raw : raw,
  1021. $row : row.$row,
  1022. $cell : $cell
  1023. });
  1024. }
  1025. if ( result !== false ) {
  1026. data.parsed[ data.parsed.length ] = parsed;
  1027. data.raw[ data.raw.length ] = raw;
  1028. data.$cell[ data.$cell.length ] = $cell;
  1029. }
  1030. }
  1031. }
  1032. // return everything
  1033. return data;
  1034. }
  1035. },
  1036. /*
  1037. ██ ██ █████▄ █████▄ ▄████▄ ██████ ██████
  1038. ██ ██ ██▄▄██ ██ ██ ██▄▄██ ██ ██▄▄
  1039. ██ ██ ██▀▀▀ ██ ██ ██▀▀██ ██ ██▀▀
  1040. ▀████▀ ██ █████▀ ██ ██ ██ ██████
  1041. */
  1042. setHeadersCss : function( c ) {
  1043. var indx, column,
  1044. list = c.sortList,
  1045. len = list.length,
  1046. none = ts.css.sortNone + ' ' + c.cssNone,
  1047. css = [ ts.css.sortAsc + ' ' + c.cssAsc, ts.css.sortDesc + ' ' + c.cssDesc ],
  1048. cssIcon = [ c.cssIconAsc, c.cssIconDesc, c.cssIconNone ],
  1049. aria = [ 'ascending', 'descending' ],
  1050. updateColumnSort = function($el, index) {
  1051. $el
  1052. .removeClass( none )
  1053. .addClass( css[ index ] )
  1054. .attr( 'aria-sort', aria[ index ] )
  1055. .find( '.' + ts.css.icon )
  1056. .removeClass( cssIcon[ 2 ] )
  1057. .addClass( cssIcon[ index ] );
  1058. },
  1059. // find the footer
  1060. $extras = c.$table
  1061. .find( 'tfoot tr' )
  1062. .children( 'td, th' )
  1063. .add( $( c.namespace + '_extra_headers' ) )
  1064. .removeClass( css.join( ' ' ) ),
  1065. // remove all header information
  1066. $sorted = c.$headers
  1067. .add( $( 'thead ' + c.namespace + '_extra_headers' ) )
  1068. .removeClass( css.join( ' ' ) )
  1069. .addClass( none )
  1070. .attr( 'aria-sort', 'none' )
  1071. .find( '.' + ts.css.icon )
  1072. .removeClass( cssIcon.join( ' ' ) )
  1073. .end();
  1074. // add css none to all sortable headers
  1075. $sorted
  1076. .not( '.sorter-false' )
  1077. .find( '.' + ts.css.icon )
  1078. .addClass( cssIcon[ 2 ] );
  1079. // add disabled css icon class
  1080. if ( c.cssIconDisabled ) {
  1081. $sorted
  1082. .filter( '.sorter-false' )
  1083. .find( '.' + ts.css.icon )
  1084. .addClass( c.cssIconDisabled );
  1085. }
  1086. for ( indx = 0; indx < len; indx++ ) {
  1087. // direction = 2 means reset!
  1088. if ( list[ indx ][ 1 ] !== 2 ) {
  1089. // multicolumn sorting updating - see #1005
  1090. // .not(function() {}) needs jQuery 1.4
  1091. // filter(function(i, el) {}) <- el is undefined in jQuery v1.2.6
  1092. $sorted = c.$headers.filter( function( i ) {
  1093. // only include headers that are in the sortList (this includes colspans)
  1094. var include = true,
  1095. $el = c.$headers.eq( i ),
  1096. col = parseInt( $el.attr( 'data-column' ), 10 ),
  1097. end = col + ts.getClosest( $el, 'th, td' )[0].colSpan;
  1098. for ( ; col < end; col++ ) {
  1099. include = include ? include || ts.isValueInArray( col, c.sortList ) > -1 : false;
  1100. }
  1101. return include;
  1102. });
  1103. // choose the :last in case there are nested columns
  1104. $sorted = $sorted
  1105. .not( '.sorter-false' )
  1106. .filter( '[data-column="' + list[ indx ][ 0 ] + '"]' + ( len === 1 ? ':last' : '' ) );
  1107. if ( $sorted.length ) {
  1108. for ( column = 0; column < $sorted.length; column++ ) {
  1109. if ( !$sorted[ column ].sortDisabled ) {
  1110. updateColumnSort( $sorted.eq( column ), list[ indx ][ 1 ] );
  1111. }
  1112. }
  1113. }
  1114. // add sorted class to footer & extra headers, if they exist
  1115. if ( $extras.length ) {
  1116. updateColumnSort( $extras.filter( '[data-column="' + list[ indx ][ 0 ] + '"]' ), list[ indx ][ 1 ] );
  1117. }
  1118. }
  1119. }
  1120. // add verbose aria labels
  1121. len = c.$headers.length;
  1122. for ( indx = 0; indx < len; indx++ ) {
  1123. ts.setColumnAriaLabel( c, c.$headers.eq( indx ) );
  1124. }
  1125. },
  1126. getClosest : function( $el, selector ) {
  1127. // jQuery v1.2.6 doesn't have closest()
  1128. if ( $.fn.closest ) {
  1129. return $el.closest( selector );
  1130. }
  1131. return $el.is( selector ) ?
  1132. $el :
  1133. $el.parents( selector ).filter( ':first' );
  1134. },
  1135. // nextSort (optional), lets you disable next sort text
  1136. setColumnAriaLabel : function( c, $header, nextSort ) {
  1137. if ( $header.length ) {
  1138. var column = parseInt( $header.attr( 'data-column' ), 10 ),
  1139. vars = c.sortVars[ column ],
  1140. tmp = $header.hasClass( ts.css.sortAsc ) ?
  1141. 'sortAsc' :
  1142. $header.hasClass( ts.css.sortDesc ) ? 'sortDesc' : 'sortNone',
  1143. txt = $.trim( $header.text() ) + ': ' + ts.language[ tmp ];
  1144. if ( $header.hasClass( 'sorter-false' ) || nextSort === false ) {
  1145. txt += ts.language.sortDisabled;
  1146. } else {
  1147. tmp = ( vars.count + 1 ) % vars.order.length;
  1148. nextSort = vars.order[ tmp ];
  1149. // if nextSort
  1150. txt += ts.language[ nextSort === 0 ? 'nextAsc' : nextSort === 1 ? 'nextDesc' : 'nextNone' ];
  1151. }
  1152. $header.attr( 'aria-label', txt );
  1153. if (vars.sortedBy) {
  1154. $header.attr( 'data-sortedBy', vars.sortedBy );
  1155. } else {
  1156. $header.removeAttr('data-sortedBy');
  1157. }
  1158. }
  1159. },
  1160. updateHeader : function( c ) {
  1161. var index, isDisabled, $header, col,
  1162. table = c.table,
  1163. len = c.$headers.length;
  1164. for ( index = 0; index < len; index++ ) {
  1165. $header = c.$headers.eq( index );
  1166. col = ts.getColumnData( table, c.headers, index, true );
  1167. // add 'sorter-false' class if 'parser-false' is set
  1168. isDisabled = ts.getData( $header, col, 'sorter' ) === 'false' || ts.getData( $header, col, 'parser' ) === 'false';
  1169. ts.setColumnSort( c, $header, isDisabled );
  1170. }
  1171. },
  1172. setColumnSort : function( c, $header, isDisabled ) {
  1173. var id = c.table.id;
  1174. $header[ 0 ].sortDisabled = isDisabled;
  1175. $header[ isDisabled ? 'addClass' : 'removeClass' ]( 'sorter-false' )
  1176. .attr( 'aria-disabled', '' + isDisabled );
  1177. // disable tab index on disabled cells
  1178. if ( c.tabIndex ) {
  1179. if ( isDisabled ) {
  1180. $header.removeAttr( 'tabindex' );
  1181. } else {
  1182. $header.attr( 'tabindex', '0' );
  1183. }
  1184. }
  1185. // aria-controls - requires table ID
  1186. if ( id ) {
  1187. if ( isDisabled ) {
  1188. $header.removeAttr( 'aria-controls' );
  1189. } else {
  1190. $header.attr( 'aria-controls', id );
  1191. }
  1192. }
  1193. },
  1194. updateHeaderSortCount : function( c, list ) {
  1195. var col, dir, group, indx, primary, temp, val, order,
  1196. sortList = list || c.sortList,
  1197. len = sortList.length;
  1198. c.sortList = [];
  1199. for ( indx = 0; indx < len; indx++ ) {
  1200. val = sortList[ indx ];
  1201. // ensure all sortList values are numeric - fixes #127
  1202. col = parseInt( val[ 0 ], 10 );
  1203. // prevents error if sorton array is wrong
  1204. if ( col < c.columns ) {
  1205. // set order if not already defined - due to colspan header without associated header cell
  1206. // adding this check prevents a javascript error
  1207. if ( !c.sortVars[ col ].order ) {
  1208. if ( ts.getOrder( c.sortInitialOrder ) ) {
  1209. order = c.sortReset ? [ 1, 0, 2 ] : [ 1, 0 ];
  1210. } else {
  1211. order = c.sortReset ? [ 0, 1, 2 ] : [ 0, 1 ];
  1212. }
  1213. c.sortVars[ col ].order = order;
  1214. c.sortVars[ col ].count = 0;
  1215. }
  1216. order = c.sortVars[ col ].order;
  1217. dir = ( '' + val[ 1 ] ).match( /^(1|d|s|o|n)/ );
  1218. dir = dir ? dir[ 0 ] : '';
  1219. // 0/(a)sc (default), 1/(d)esc, (s)ame, (o)pposite, (n)ext
  1220. switch ( dir ) {
  1221. case '1' : case 'd' : // descending
  1222. dir = 1;
  1223. break;
  1224. case 's' : // same direction (as primary column)
  1225. // if primary sort is set to 's', make it ascending
  1226. dir = primary || 0;
  1227. break;
  1228. case 'o' :
  1229. temp = order[ ( primary || 0 ) % order.length ];
  1230. // opposite of primary column; but resets if primary resets
  1231. dir = temp === 0 ? 1 : temp === 1 ? 0 : 2;
  1232. break;
  1233. case 'n' :
  1234. dir = order[ ( ++c.sortVars[ col ].count ) % order.length ];
  1235. break;
  1236. default : // ascending
  1237. dir = 0;
  1238. break;
  1239. }
  1240. primary = indx === 0 ? dir : primary;
  1241. group = [ col, parseInt( dir, 10 ) || 0 ];
  1242. c.sortList[ c.sortList.length ] = group;
  1243. dir = $.inArray( group[ 1 ], order ); // fixes issue #167
  1244. c.sortVars[ col ].count = dir >= 0 ? dir : group[ 1 ] % order.length;
  1245. }
  1246. }
  1247. },
  1248. updateAll : function( c, resort, callback ) {
  1249. var table = c.table;
  1250. table.isUpdating = true;
  1251. ts.refreshWidgets( table, true, true );
  1252. ts.buildHeaders( c );
  1253. ts.bindEvents( table, c.$headers, true );
  1254. ts.bindMethods( c );
  1255. ts.commonUpdate( c, resort, callback );
  1256. },
  1257. update : function( c, resort, callback ) {
  1258. var table = c.table;
  1259. table.isUpdating = true;
  1260. // update sorting (if enabled/disabled)
  1261. ts.updateHeader( c );
  1262. ts.commonUpdate( c, resort, callback );
  1263. },
  1264. // simple header update - see #989
  1265. updateHeaders : function( c, callback ) {
  1266. c.table.isUpdating = true;
  1267. ts.buildHeaders( c );
  1268. ts.bindEvents( c.table, c.$headers, true );
  1269. ts.resortComplete( c, callback );
  1270. },
  1271. updateCell : function( c, cell, resort, callback ) {
  1272. // updateCell for child rows is a mess - we'll ignore them for now
  1273. // eventually I'll break out the "update" row cache code to make everything consistent
  1274. if ( $( cell ).closest( 'tr' ).hasClass( c.cssChildRow ) ) {
  1275. console.warn('Tablesorter Warning! "updateCell" for child row content has been disabled, use "update" instead');
  1276. return;
  1277. }
  1278. if ( ts.isEmptyObject( c.cache ) ) {
  1279. // empty table, do an update instead - fixes #1099
  1280. ts.updateHeader( c );
  1281. ts.commonUpdate( c, resort, callback );
  1282. return;
  1283. }
  1284. c.table.isUpdating = true;
  1285. c.$table.find( c.selectorRemove ).remove();
  1286. // get position from the dom
  1287. var tmp, indx, row, icell, cache, len,
  1288. $tbodies = c.$tbodies,
  1289. $cell = $( cell ),
  1290. // update cache - format: function( s, table, cell, cellIndex )
  1291. // no closest in jQuery v1.2.6
  1292. tbodyIndex = $tbodies.index( ts.getClosest( $cell, 'tbody' ) ),
  1293. tbcache = c.cache[ tbodyIndex ],
  1294. $row = ts.getClosest( $cell, 'tr' );
  1295. cell = $cell[ 0 ]; // in case cell is a jQuery object
  1296. // tbody may not exist if update is initialized while tbody is removed for processing
  1297. if ( $tbodies.length && tbodyIndex >= 0 ) {
  1298. row = $tbodies.eq( tbodyIndex ).find( 'tr' ).not( '.' + c.cssChildRow ).index( $row );
  1299. cache = tbcache.normalized[ row ];
  1300. len = $row[ 0 ].cells.length;
  1301. if ( len !== c.columns ) {
  1302. // colspan in here somewhere!
  1303. icell = 0;
  1304. tmp = false;
  1305. for ( indx = 0; indx < len; indx++ ) {
  1306. if ( !tmp && $row[ 0 ].cells[ indx ] !== cell ) {
  1307. icell += $row[ 0 ].cells[ indx ].colSpan;
  1308. } else {
  1309. tmp = true;
  1310. }
  1311. }
  1312. } else {
  1313. icell = $cell.index();
  1314. }
  1315. tmp = ts.getElementText( c, cell, icell ); // raw
  1316. cache[ c.columns ].raw[ icell ] = tmp;
  1317. tmp = ts.getParsedText( c, cell, icell, tmp );
  1318. cache[ icell ] = tmp; // parsed
  1319. if ( ( c.parsers[ icell ].type || '' ).toLowerCase() === 'numeric' ) {
  1320. // update column max value (ignore sign)
  1321. tbcache.colMax[ icell ] = Math.max( Math.abs( tmp ) || 0, tbcache.colMax[ icell ] || 0 );
  1322. }
  1323. tmp = resort !== 'undefined' ? resort : c.resort;
  1324. if ( tmp !== false ) {
  1325. // widgets will be reapplied
  1326. ts.checkResort( c, tmp, callback );
  1327. } else {
  1328. // don't reapply widgets is resort is false, just in case it causes
  1329. // problems with element focus
  1330. ts.resortComplete( c, callback );
  1331. }
  1332. } else {
  1333. if ( ts.debug(c, 'core') ) {
  1334. console.error( 'updateCell aborted, tbody missing or not within the indicated table' );
  1335. }
  1336. c.table.isUpdating = false;
  1337. }
  1338. },
  1339. addRows : function( c, $row, resort, callback ) {
  1340. var txt, val, tbodyIndex, rowIndex, rows, cellIndex, len, order,
  1341. cacheIndex, rowData, cells, cell, span,
  1342. // allow passing a row string if only one non-info tbody exists in the table
  1343. valid = typeof $row === 'string' && c.$tbodies.length === 1 && /<tr/.test( $row || '' ),
  1344. table = c.table;
  1345. if ( valid ) {
  1346. $row = $( $row );
  1347. c.$tbodies.append( $row );
  1348. } else if (
  1349. !$row ||
  1350. // row is a jQuery object?
  1351. !( $row instanceof $ ) ||
  1352. // row contained in the table?
  1353. ( ts.getClosest( $row, 'table' )[ 0 ] !== c.table )
  1354. ) {
  1355. if ( ts.debug(c, 'core') ) {
  1356. console.error( 'addRows method requires (1) a jQuery selector reference to rows that have already ' +
  1357. 'been added to the table, or (2) row HTML string to be added to a table with only one tbody' );
  1358. }
  1359. return false;
  1360. }
  1361. table.isUpdating = true;
  1362. if ( ts.isEmptyObject( c.cache ) ) {
  1363. // empty table, do an update instead - fixes #450
  1364. ts.updateHeader( c );
  1365. ts.commonUpdate( c, resort, callback );
  1366. } else {
  1367. rows = $row.filter( 'tr' ).attr( 'role', 'row' ).length;
  1368. tbodyIndex = c.$tbodies.index( $row.parents( 'tbody' ).filter( ':first' ) );
  1369. // fixes adding rows to an empty table - see issue #179
  1370. if ( !( c.parsers && c.parsers.length ) ) {
  1371. ts.setupParsers( c );
  1372. }
  1373. // add each row
  1374. for ( rowIndex = 0; rowIndex < rows; rowIndex++ ) {
  1375. cacheIndex = 0;
  1376. len = $row[ rowIndex ].cells.length;
  1377. order = c.cache[ tbodyIndex ].normalized.length;
  1378. cells = [];
  1379. rowData = {
  1380. child : [],
  1381. raw : [],
  1382. $row : $row.eq( rowIndex ),
  1383. order : order
  1384. };
  1385. // add each cell
  1386. for ( cellIndex = 0; cellIndex < len; cellIndex++ ) {
  1387. cell = $row[ rowIndex ].cells[ cellIndex ];
  1388. txt = ts.getElementText( c, cell, cacheIndex );
  1389. rowData.raw[ cacheIndex ] = txt;
  1390. val = ts.getParsedText( c, cell, cacheIndex, txt );
  1391. cells[ cacheIndex ] = val;
  1392. if ( ( c.parsers[ cacheIndex ].type || '' ).toLowerCase() === 'numeric' ) {
  1393. // update column max value (ignore sign)
  1394. c.cache[ tbodyIndex ].colMax[ cacheIndex ] =
  1395. Math.max( Math.abs( val ) || 0, c.cache[ tbodyIndex ].colMax[ cacheIndex ] || 0 );
  1396. }
  1397. span = cell.colSpan - 1;
  1398. if ( span > 0 ) {
  1399. cacheIndex += span;
  1400. }
  1401. cacheIndex++;
  1402. }
  1403. // add the row data to the end
  1404. cells[ c.columns ] = rowData;
  1405. // update cache
  1406. c.cache[ tbodyIndex ].normalized[ order ] = cells;
  1407. }
  1408. // resort using current settings
  1409. ts.checkResort( c, resort, callback );
  1410. }
  1411. },
  1412. updateCache : function( c, callback, $tbodies ) {
  1413. // rebuild parsers
  1414. if ( !( c.parsers && c.parsers.length ) ) {
  1415. ts.setupParsers( c, $tbodies );
  1416. }
  1417. // rebuild the cache map
  1418. ts.buildCache( c, callback, $tbodies );
  1419. },
  1420. // init flag (true) used by pager plugin to prevent widget application
  1421. // renamed from appendToTable
  1422. appendCache : function( c, init ) {
  1423. var parsed, totalRows, $tbody, $curTbody, rowIndex, tbodyIndex, appendTime,
  1424. table = c.table,
  1425. $tbodies = c.$tbodies,
  1426. rows = [],
  1427. cache = c.cache;
  1428. // empty table - fixes #206/#346
  1429. if ( ts.isEmptyObject( cache ) ) {
  1430. // run pager appender in case the table was just emptied
  1431. return c.appender ? c.appender( table, rows ) :
  1432. table.isUpdating ? c.$table.triggerHandler( 'updateComplete', table ) : ''; // Fixes #532
  1433. }
  1434. if ( ts.debug(c, 'core') ) {
  1435. appendTime = new Date();
  1436. }
  1437. for ( tbodyIndex = 0; tbodyIndex < $tbodies.length; tbodyIndex++ ) {
  1438. $tbody = $tbodies.eq( tbodyIndex );
  1439. if ( $tbody.length ) {
  1440. // detach tbody for manipulation
  1441. $curTbody = ts.processTbody( table, $tbody, true );
  1442. parsed = cache[ tbodyIndex ].normalized;
  1443. totalRows = parsed.length;
  1444. for ( rowIndex = 0; rowIndex < totalRows; rowIndex++ ) {
  1445. rows[rows.length] = parsed[ rowIndex ][ c.columns ].$row;
  1446. // removeRows used by the pager plugin; don't render if using ajax - fixes #411
  1447. if ( !c.appender || ( c.pager && !c.pager.removeRows && !c.pager.ajax ) ) {
  1448. $curTbody.append( parsed[ rowIndex ][ c.columns ].$row );
  1449. }
  1450. }
  1451. // restore tbody
  1452. ts.processTbody( table, $curTbody, false );
  1453. }
  1454. }
  1455. if ( c.appender ) {
  1456. c.appender( table, rows );
  1457. }
  1458. if ( ts.debug(c, 'core') ) {
  1459. console.log( 'Rebuilt table' + ts.benchmark( appendTime ) );
  1460. }
  1461. // apply table widgets; but not before ajax completes
  1462. if ( !init && !c.appender ) {
  1463. ts.applyWidget( table );
  1464. }
  1465. if ( table.isUpdating ) {
  1466. c.$table.triggerHandler( 'updateComplete', table );
  1467. }
  1468. },
  1469. commonUpdate : function( c, resort, callback ) {
  1470. // remove rows/elements before update
  1471. c.$table.find( c.selectorRemove ).remove();
  1472. // rebuild parsers
  1473. ts.setupParsers( c );
  1474. // rebuild the cache map
  1475. ts.buildCache( c );
  1476. ts.checkResort( c, resort, callback );
  1477. },
  1478. /*
  1479. ▄█████ ▄████▄ █████▄ ██████ ██ █████▄ ▄████▄
  1480. ▀█▄ ██ ██ ██▄▄██ ██ ██ ██ ██ ██ ▄▄▄
  1481. ▀█▄ ██ ██ ██▀██ ██ ██ ██ ██ ██ ▀██
  1482. █████▀ ▀████▀ ██ ██ ██ ██ ██ ██ ▀████▀
  1483. */
  1484. initSort : function( c, cell, event ) {
  1485. if ( c.table.isUpdating ) {
  1486. // let any updates complete before initializing a sort
  1487. return setTimeout( function() {
  1488. ts.initSort( c, cell, event );
  1489. }, 50 );
  1490. }
  1491. var arry, indx, headerIndx, dir, temp, tmp, $header,
  1492. notMultiSort = !event[ c.sortMultiSortKey ],
  1493. table = c.table,
  1494. len = c.$headers.length,
  1495. th = ts.getClosest( $( cell ), 'th, td' ),
  1496. col = parseInt( th.attr( 'data-column' ), 10 ),
  1497. sortedBy = event.type === 'mouseup' ? 'user' : event.type,
  1498. order = c.sortVars[ col ].order;
  1499. th = th[0];
  1500. // Only call sortStart if sorting is enabled
  1501. c.$table.triggerHandler( 'sortStart', table );
  1502. // get current column sort order
  1503. tmp = ( c.sortVars[ col ].count + 1 ) % order.length;
  1504. c.sortVars[ col ].count = event[ c.sortResetKey ] ? 2 : tmp;
  1505. // reset all sorts on non-current column - issue #30
  1506. if ( c.sortRestart ) {
  1507. for ( headerIndx = 0; headerIndx < len; headerIndx++ ) {
  1508. $header = c.$headers.eq( headerIndx );
  1509. tmp = parseInt( $header.attr( 'data-column' ), 10 );
  1510. // only reset counts on columns that weren't just clicked on and if not included in a multisort
  1511. if ( col !== tmp && ( notMultiSort || $header.hasClass( ts.css.sortNone ) ) ) {
  1512. c.sortVars[ tmp ].count = -1;
  1513. }
  1514. }
  1515. }
  1516. // user only wants to sort on one column
  1517. if ( notMultiSort ) {
  1518. $.each( c.sortVars, function( i ) {
  1519. c.sortVars[ i ].sortedBy = '';
  1520. });
  1521. // flush the sort list
  1522. c.sortList = [];
  1523. c.last.sortList = [];
  1524. if ( c.sortForce !== null ) {
  1525. arry = c.sortForce;
  1526. for ( indx = 0; indx < arry.length; indx++ ) {
  1527. if ( arry[ indx ][ 0 ] !== col ) {
  1528. c.sortList[ c.sortList.length ] = arry[ indx ];
  1529. c.sortVars[ arry[ indx ][ 0 ] ].sortedBy = 'sortForce';
  1530. }
  1531. }
  1532. }
  1533. // add column to sort list
  1534. dir = order[ c.sortVars[ col ].count ];
  1535. if ( dir < 2 ) {
  1536. c.sortList[ c.sortList.length ] = [ col, dir ];
  1537. c.sortVars[ col ].sortedBy = sortedBy;
  1538. // add other columns if header spans across multiple
  1539. if ( th.colSpan > 1 ) {
  1540. for ( indx = 1; indx < th.colSpan; indx++ ) {
  1541. c.sortList[ c.sortList.length ] = [ col + indx, dir ];
  1542. // update count on columns in colSpan
  1543. c.sortVars[ col + indx ].count = $.inArray( dir, order );
  1544. c.sortVars[ col + indx ].sortedBy = sortedBy;
  1545. }
  1546. }
  1547. }
  1548. // multi column sorting
  1549. } else {
  1550. // get rid of the sortAppend before adding more - fixes issue #115 & #523
  1551. c.sortList = $.extend( [], c.last.sortList );
  1552. // the user has clicked on an already sorted column
  1553. if ( ts.isValueInArray( col, c.sortList ) >= 0 ) {
  1554. // reverse the sorting direction
  1555. c.sortVars[ col ].sortedBy = sortedBy;
  1556. for ( indx = 0; indx < c.sortList.length; indx++ ) {
  1557. tmp = c.sortList[ indx ];
  1558. if ( tmp[ 0 ] === col ) {
  1559. // order.count seems to be incorrect when compared to cell.count
  1560. tmp[ 1 ] = order[ c.sortVars[ col ].count ];
  1561. if ( tmp[1] === 2 ) {
  1562. c.sortList.splice( indx, 1 );
  1563. c.sortVars[ col ].count = -1;
  1564. }
  1565. }
  1566. }
  1567. } else {
  1568. // add column to sort list array
  1569. dir = order[ c.sortVars[ col ].count ];
  1570. c.sortVars[ col ].sortedBy = sortedBy;
  1571. if ( dir < 2 ) {
  1572. c.sortList[ c.sortList.length ] = [ col, dir ];
  1573. // add other columns if header spans across multiple
  1574. if ( th.colSpan > 1 ) {
  1575. for ( indx = 1; indx < th.colSpan; indx++ ) {
  1576. c.sortList[ c.sortList.length ] = [ col + indx, dir ];
  1577. // update count on columns in colSpan
  1578. c.sortVars[ col + indx ].count = $.inArray( dir, order );
  1579. c.sortVars[ col + indx ].sortedBy = sortedBy;
  1580. }
  1581. }
  1582. }
  1583. }
  1584. }
  1585. // save sort before applying sortAppend
  1586. c.last.sortList = $.extend( [], c.sortList );
  1587. if ( c.sortList.length && c.sortAppend ) {
  1588. arry = $.isArray( c.sortAppend ) ? c.sortAppend : c.sortAppend[ c.sortList[ 0 ][ 0 ] ];
  1589. if ( !ts.isEmptyObject( arry ) ) {
  1590. for ( indx = 0; indx < arry.length; indx++ ) {
  1591. if ( arry[ indx ][ 0 ] !== col && ts.isValueInArray( arry[ indx ][ 0 ], c.sortList ) < 0 ) {
  1592. dir = arry[ indx ][ 1 ];
  1593. temp = ( '' + dir ).match( /^(a|d|s|o|n)/ );
  1594. if ( temp ) {
  1595. tmp = c.sortList[ 0 ][ 1 ];
  1596. switch ( temp[ 0 ] ) {
  1597. case 'd' :
  1598. dir = 1;
  1599. break;
  1600. case 's' :
  1601. dir = tmp;
  1602. break;
  1603. case 'o' :
  1604. dir = tmp === 0 ? 1 : 0;
  1605. break;
  1606. case 'n' :
  1607. dir = ( tmp + 1 ) % order.length;
  1608. break;
  1609. default:
  1610. dir = 0;
  1611. break;
  1612. }
  1613. }
  1614. c.sortList[ c.sortList.length ] = [ arry[ indx ][ 0 ], dir ];
  1615. c.sortVars[ arry[ indx ][ 0 ] ].sortedBy = 'sortAppend';
  1616. }
  1617. }
  1618. }
  1619. }
  1620. // sortBegin event triggered immediately before the sort
  1621. c.$table.triggerHandler( 'sortBegin', table );
  1622. // setTimeout needed so the processing icon shows up
  1623. setTimeout( function() {
  1624. // set css for headers
  1625. ts.setHeadersCss( c );
  1626. ts.multisort( c );
  1627. ts.appendCache( c );
  1628. c.$table.triggerHandler( 'sortBeforeEnd', table );
  1629. c.$table.triggerHandler( 'sortEnd', table );
  1630. }, 1 );
  1631. },
  1632. // sort multiple columns
  1633. multisort : function( c ) { /*jshint loopfunc:true */
  1634. var tbodyIndex, sortTime, colMax, rows, tmp,
  1635. table = c.table,
  1636. sorter = [],
  1637. dir = 0,
  1638. textSorter = c.textSorter || '',
  1639. sortList = c.sortList,
  1640. sortLen = sortList.length,
  1641. len = c.$tbodies.length;
  1642. if ( c.serverSideSorting || ts.isEmptyObject( c.cache ) ) {
  1643. // empty table - fixes #206/#346
  1644. return;
  1645. }
  1646. if ( ts.debug(c, 'core') ) { sortTime = new Date(); }
  1647. // cache textSorter to optimize speed
  1648. if ( typeof textSorter === 'object' ) {
  1649. colMax = c.columns;
  1650. while ( colMax-- ) {
  1651. tmp = ts.getColumnData( table, textSorter, colMax );
  1652. if ( typeof tmp === 'function' ) {
  1653. sorter[ colMax ] = tmp;
  1654. }
  1655. }
  1656. }
  1657. for ( tbodyIndex = 0; tbodyIndex < len; tbodyIndex++ ) {
  1658. colMax = c.cache[ tbodyIndex ].colMax;
  1659. rows = c.cache[ tbodyIndex ].normalized;
  1660. rows.sort( function( a, b ) {
  1661. var sortIndex, num, col, order, sort, x, y;
  1662. // rows is undefined here in IE, so don't use it!
  1663. for ( sortIndex = 0; sortIndex < sortLen; sortIndex++ ) {
  1664. col = sortList[ sortIndex ][ 0 ];
  1665. order = sortList[ sortIndex ][ 1 ];
  1666. // sort direction, true = asc, false = desc
  1667. dir = order === 0;
  1668. if ( c.sortStable && a[ col ] === b[ col ] && sortLen === 1 ) {
  1669. return a[ c.columns ].order - b[ c.columns ].order;
  1670. }
  1671. // fallback to natural sort since it is more robust
  1672. num = /n/i.test( ts.getSortType( c.parsers, col ) );
  1673. if ( num && c.strings[ col ] ) {
  1674. // sort strings in numerical columns
  1675. if ( typeof ( ts.string[ c.strings[ col ] ] ) === 'boolean' ) {
  1676. num = ( dir ? 1 : -1 ) * ( ts.string[ c.strings[ col ] ] ? -1 : 1 );
  1677. } else {
  1678. num = ( c.strings[ col ] ) ? ts.string[ c.strings[ col ] ] || 0 : 0;
  1679. }
  1680. // fall back to built-in numeric sort
  1681. // var sort = $.tablesorter['sort' + s]( a[col], b[col], dir, colMax[col], table );
  1682. sort = c.numberSorter ? c.numberSorter( a[ col ], b[ col ], dir, colMax[ col ], table ) :
  1683. ts[ 'sortNumeric' + ( dir ? 'Asc' : 'Desc' ) ]( a[ col ], b[ col ], num, colMax[ col ], col, c );
  1684. } else {
  1685. // set a & b depending on sort direction
  1686. x = dir ? a : b;
  1687. y = dir ? b : a;
  1688. // text sort function
  1689. if ( typeof textSorter === 'function' ) {
  1690. // custom OVERALL text sorter
  1691. sort = textSorter( x[ col ], y[ col ], dir, col, table );
  1692. } else if ( typeof sorter[ col ] === 'function' ) {
  1693. // custom text sorter for a SPECIFIC COLUMN
  1694. sort = sorter[ col ]( x[ col ], y[ col ], dir, col, table );
  1695. } else {
  1696. // fall back to natural sort
  1697. sort = ts[ 'sortNatural' + ( dir ? 'Asc' : 'Desc' ) ]( a[ col ] || '', b[ col ] || '', col, c );
  1698. }
  1699. }
  1700. if ( sort ) { return sort; }
  1701. }
  1702. return a[ c.columns ].order - b[ c.columns ].order;
  1703. });
  1704. }
  1705. if ( ts.debug(c, 'core') ) {
  1706. console.log( 'Applying sort ' + sortList.toString() + ts.benchmark( sortTime ) );
  1707. }
  1708. },
  1709. resortComplete : function( c, callback ) {
  1710. if ( c.table.isUpdating ) {
  1711. c.$table.triggerHandler( 'updateComplete', c.table );
  1712. }
  1713. if ( $.isFunction( callback ) ) {
  1714. callback( c.table );
  1715. }
  1716. },
  1717. checkResort : function( c, resort, callback ) {
  1718. var sortList = $.isArray( resort ) ? resort : c.sortList,
  1719. // if no resort parameter is passed, fallback to config.resort (true by default)
  1720. resrt = typeof resort === 'undefined' ? c.resort : resort;
  1721. // don't try to resort if the table is still processing
  1722. // this will catch spamming of the updateCell method
  1723. if ( resrt !== false && !c.serverSideSorting && !c.table.isProcessing ) {
  1724. if ( sortList.length ) {
  1725. ts.sortOn( c, sortList, function() {
  1726. ts.resortComplete( c, callback );
  1727. }, true );
  1728. } else {
  1729. ts.sortReset( c, function() {
  1730. ts.resortComplete( c, callback );
  1731. ts.applyWidget( c.table, false );
  1732. } );
  1733. }
  1734. } else {
  1735. ts.resortComplete( c, callback );
  1736. ts.applyWidget( c.table, false );
  1737. }
  1738. },
  1739. sortOn : function( c, list, callback, init ) {
  1740. var indx,
  1741. table = c.table;
  1742. c.$table.triggerHandler( 'sortStart', table );
  1743. for (indx = 0; indx < c.columns; indx++) {
  1744. c.sortVars[ indx ].sortedBy = ts.isValueInArray( indx, list ) > -1 ? 'sorton' : '';
  1745. }
  1746. // update header count index
  1747. ts.updateHeaderSortCount( c, list );
  1748. // set css for headers
  1749. ts.setHeadersCss( c );
  1750. // fixes #346
  1751. if ( c.delayInit && ts.isEmptyObject( c.cache ) ) {
  1752. ts.buildCache( c );
  1753. }
  1754. c.$table.triggerHandler( 'sortBegin', table );
  1755. // sort the table and append it to the dom
  1756. ts.multisort( c );
  1757. ts.appendCache( c, init );
  1758. c.$table.triggerHandler( 'sortBeforeEnd', table );
  1759. c.$table.triggerHandler( 'sortEnd', table );
  1760. ts.applyWidget( table );
  1761. if ( $.isFunction( callback ) ) {
  1762. callback( table );
  1763. }
  1764. },
  1765. sortReset : function( c, callback ) {
  1766. c.sortList = [];
  1767. var indx;
  1768. for (indx = 0; indx < c.columns; indx++) {
  1769. c.sortVars[ indx ].count = -1;
  1770. c.sortVars[ indx ].sortedBy = '';
  1771. }
  1772. ts.setHeadersCss( c );
  1773. ts.multisort( c );
  1774. ts.appendCache( c );
  1775. if ( $.isFunction( callback ) ) {
  1776. callback( c.table );
  1777. }
  1778. },
  1779. getSortType : function( parsers, column ) {
  1780. return ( parsers && parsers[ column ] ) ? parsers[ column ].type || '' : '';
  1781. },
  1782. getOrder : function( val ) {
  1783. // look for 'd' in 'desc' order; return true
  1784. return ( /^d/i.test( val ) || val === 1 );
  1785. },
  1786. // Natural sort - https://github.com/overset/javascript-natural-sort (date sorting removed)
  1787. sortNatural : function( a, b ) {
  1788. if ( a === b ) { return 0; }
  1789. a = ( a || '' ).toString();
  1790. b = ( b || '' ).toString();
  1791. var aNum, bNum, aFloat, bFloat, indx, max,
  1792. regex = ts.regex;
  1793. // first try and sort Hex codes
  1794. if ( regex.hex.test( b ) ) {
  1795. aNum = parseInt( a.match( regex.hex ), 16 );
  1796. bNum = parseInt( b.match( regex.hex ), 16 );
  1797. if ( aNum < bNum ) { return -1; }
  1798. if ( aNum > bNum ) { return 1; }
  1799. }
  1800. // chunk/tokenize
  1801. aNum = a.replace( regex.chunk, '\\0$1\\0' ).replace( regex.chunks, '' ).split( '\\0' );
  1802. bNum = b.replace( regex.chunk, '\\0$1\\0' ).replace( regex.chunks, '' ).split( '\\0' );
  1803. max = Math.max( aNum.length, bNum.length );
  1804. // natural sorting through split numeric strings and default strings
  1805. for ( indx = 0; indx < max; indx++ ) {
  1806. // find floats not starting with '0', string or 0 if not defined
  1807. aFloat = isNaN( aNum[ indx ] ) ? aNum[ indx ] || 0 : parseFloat( aNum[ indx ] ) || 0;
  1808. bFloat = isNaN( bNum[ indx ] ) ? bNum[ indx ] || 0 : parseFloat( bNum[ indx ] ) || 0;
  1809. // handle numeric vs string comparison - number < string - (Kyle Adams)
  1810. if ( isNaN( aFloat ) !== isNaN( bFloat ) ) { return isNaN( aFloat ) ? 1 : -1; }
  1811. // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
  1812. if ( typeof aFloat !== typeof bFloat ) {
  1813. aFloat += '';
  1814. bFloat += '';
  1815. }
  1816. if ( aFloat < bFloat ) { return -1; }
  1817. if ( aFloat > bFloat ) { return 1; }
  1818. }
  1819. return 0;
  1820. },
  1821. sortNaturalAsc : function( a, b, col, c ) {
  1822. if ( a === b ) { return 0; }
  1823. var empty = ts.string[ ( c.empties[ col ] || c.emptyTo ) ];
  1824. if ( a === '' && empty !== 0 ) { return typeof empty === 'boolean' ? ( empty ? -1 : 1 ) : -empty || -1; }
  1825. if ( b === '' && empty !== 0 ) { return typeof empty === 'boolean' ? ( empty ? 1 : -1 ) : empty || 1; }
  1826. return ts.sortNatural( a, b );
  1827. },
  1828. sortNaturalDesc : function( a, b, col, c ) {
  1829. if ( a === b ) { return 0; }
  1830. var empty = ts.string[ ( c.empties[ col ] || c.emptyTo ) ];
  1831. if ( a === '' && empty !== 0 ) { return typeof empty === 'boolean' ? ( empty ? -1 : 1 ) : empty || 1; }
  1832. if ( b === '' && empty !== 0 ) { return typeof empty === 'boolean' ? ( empty ? 1 : -1 ) : -empty || -1; }
  1833. return ts.sortNatural( b, a );
  1834. },
  1835. // basic alphabetical sort
  1836. sortText : function( a, b ) {
  1837. return a > b ? 1 : ( a < b ? -1 : 0 );
  1838. },
  1839. // return text string value by adding up ascii value
  1840. // so the text is somewhat sorted when using a digital sort
  1841. // this is NOT an alphanumeric sort
  1842. getTextValue : function( val, num, max ) {
  1843. if ( max ) {
  1844. // make sure the text value is greater than the max numerical value (max)
  1845. var indx,
  1846. len = val ? val.length : 0,
  1847. n = max + num;
  1848. for ( indx = 0; indx < len; indx++ ) {
  1849. n += val.charCodeAt( indx );
  1850. }
  1851. return num * n;
  1852. }
  1853. return 0;
  1854. },
  1855. sortNumericAsc : function( a, b, num, max, col, c ) {
  1856. if ( a === b ) { return 0; }
  1857. var empty = ts.string[ ( c.empties[ col ] || c.emptyTo ) ];
  1858. if ( a === '' && empty !== 0 ) { return typeof empty === 'boolean' ? ( empty ? -1 : 1 ) : -empty || -1; }
  1859. if ( b === '' && empty !== 0 ) { return typeof empty === 'boolean' ? ( empty ? 1 : -1 ) : empty || 1; }
  1860. if ( isNaN( a ) ) { a = ts.getTextValue( a, num, max ); }
  1861. if ( isNaN( b ) ) { b = ts.getTextValue( b, num, max ); }
  1862. return a - b;
  1863. },
  1864. sortNumericDesc : function( a, b, num, max, col, c ) {
  1865. if ( a === b ) { return 0; }
  1866. var empty = ts.string[ ( c.empties[ col ] || c.emptyTo ) ];
  1867. if ( a === '' && empty !== 0 ) { return typeof empty === 'boolean' ? ( empty ? -1 : 1 ) : empty || 1; }
  1868. if ( b === '' && empty !== 0 ) { return typeof empty === 'boolean' ? ( empty ? 1 : -1 ) : -empty || -1; }
  1869. if ( isNaN( a ) ) { a = ts.getTextValue( a, num, max ); }
  1870. if ( isNaN( b ) ) { b = ts.getTextValue( b, num, max ); }
  1871. return b - a;
  1872. },
  1873. sortNumeric : function( a, b ) {
  1874. return a - b;
  1875. },
  1876. /*
  1877. ██ ██ ██ ██ █████▄ ▄████▄ ██████ ██████ ▄█████
  1878. ██ ██ ██ ██ ██ ██ ██ ▄▄▄ ██▄▄ ██ ▀█▄
  1879. ██ ██ ██ ██ ██ ██ ██ ▀██ ██▀▀ ██ ▀█▄
  1880. ███████▀ ██ █████▀ ▀████▀ ██████ ██ █████▀
  1881. */
  1882. addWidget : function( widget ) {
  1883. if ( widget.id && !ts.isEmptyObject( ts.getWidgetById( widget.id ) ) ) {
  1884. console.warn( '"' + widget.id + '" widget was loaded more than once!' );
  1885. }
  1886. ts.widgets[ ts.widgets.length ] = widget;
  1887. },
  1888. hasWidget : function( $table, name ) {
  1889. $table = $( $table );
  1890. return $table.length && $table[ 0 ].config && $table[ 0 ].config.widgetInit[ name ] || false;
  1891. },
  1892. getWidgetById : function( name ) {
  1893. var indx, widget,
  1894. len = ts.widgets.length;
  1895. for ( indx = 0; indx < len; indx++ ) {
  1896. widget = ts.widgets[ indx ];
  1897. if ( widget && widget.id && widget.id.toLowerCase() === name.toLowerCase() ) {
  1898. return widget;
  1899. }
  1900. }
  1901. },
  1902. applyWidgetOptions : function( table ) {
  1903. var indx, widget, wo,
  1904. c = table.config,
  1905. len = c.widgets.length;
  1906. if ( len ) {
  1907. for ( indx = 0; indx < len; indx++ ) {
  1908. widget = ts.getWidgetById( c.widgets[ indx ] );
  1909. if ( widget && widget.options ) {
  1910. wo = $.extend( true, {}, widget.options );
  1911. c.widgetOptions = $.extend( true, wo, c.widgetOptions );
  1912. // add widgetOptions to defaults for option validator
  1913. $.extend( true, ts.defaults.widgetOptions, widget.options );
  1914. }
  1915. }
  1916. }
  1917. },
  1918. addWidgetFromClass : function( table ) {
  1919. var len, indx,
  1920. c = table.config,
  1921. // look for widgets to apply from table class
  1922. // don't match from 'ui-widget-content'; use \S instead of \w to include widgets
  1923. // with dashes in the name, e.g. "widget-test-2" extracts out "test-2"
  1924. regex = '^' + c.widgetClass.replace( ts.regex.templateName, '(\\S+)+' ) + '$',
  1925. widgetClass = new RegExp( regex, 'g' ),
  1926. // split up table class (widget id's can include dashes) - stop using match
  1927. // otherwise only one widget gets extracted, see #1109
  1928. widgets = ( table.className || '' ).split( ts.regex.spaces );
  1929. if ( widgets.length ) {
  1930. len = widgets.length;
  1931. for ( indx = 0; indx < len; indx++ ) {
  1932. if ( widgets[ indx ].match( widgetClass ) ) {
  1933. c.widgets[ c.widgets.length ] = widgets[ indx ].replace( widgetClass, '$1' );
  1934. }
  1935. }
  1936. }
  1937. },
  1938. applyWidgetId : function( table, id, init ) {
  1939. table = $(table)[0];
  1940. var applied, time, name,
  1941. c = table.config,
  1942. wo = c.widgetOptions,
  1943. debug = ts.debug(c, 'core'),
  1944. widget = ts.getWidgetById( id );
  1945. if ( widget ) {
  1946. name = widget.id;
  1947. applied = false;
  1948. // add widget name to option list so it gets reapplied after sorting, filtering, etc
  1949. if ( $.inArray( name, c.widgets ) < 0 ) {
  1950. c.widgets[ c.widgets.length ] = name;
  1951. }
  1952. if ( debug ) { time = new Date(); }
  1953. if ( init || !( c.widgetInit[ name ] ) ) {
  1954. // set init flag first to prevent calling init more than once (e.g. pager)
  1955. c.widgetInit[ name ] = true;
  1956. if ( table.hasInitialized ) {
  1957. // don't reapply widget options on tablesorter init
  1958. ts.applyWidgetOptions( table );
  1959. }
  1960. if ( typeof widget.init === 'function' ) {
  1961. applied = true;
  1962. if ( debug ) {
  1963. console[ console.group ? 'group' : 'log' ]( 'Initializing ' + name + ' widget' );
  1964. }
  1965. widget.init( table, widget, c, wo );
  1966. }
  1967. }
  1968. if ( !init && typeof widget.format === 'function' ) {
  1969. applied = true;
  1970. if ( debug ) {
  1971. console[ console.group ? 'group' : 'log' ]( 'Updating ' + name + ' widget' );
  1972. }
  1973. widget.format( table, c, wo, false );
  1974. }
  1975. if ( debug ) {
  1976. if ( applied ) {
  1977. console.log( 'Completed ' + ( init ? 'initializing ' : 'applying ' ) + name + ' widget' + ts.benchmark( time ) );
  1978. if ( console.groupEnd ) { console.groupEnd(); }
  1979. }
  1980. }
  1981. }
  1982. },
  1983. applyWidget : function( table, init, callback ) {
  1984. table = $( table )[ 0 ]; // in case this is called externally
  1985. var indx, len, names, widget, time,
  1986. c = table.config,
  1987. debug = ts.debug(c, 'core'),
  1988. widgets = [];
  1989. // prevent numerous consecutive widget applications
  1990. if ( init !== false && table.hasInitialized && ( table.isApplyingWidgets || table.isUpdating ) ) {
  1991. return;
  1992. }
  1993. if ( debug ) { time = new Date(); }
  1994. ts.addWidgetFromClass( table );
  1995. // prevent "tablesorter-ready" from firing multiple times in a row
  1996. clearTimeout( c.timerReady );
  1997. if ( c.widgets.length ) {
  1998. table.isApplyingWidgets = true;
  1999. // ensure unique widget ids
  2000. c.widgets = $.grep( c.widgets, function( val, index ) {
  2001. return $.inArray( val, c.widgets ) === index;
  2002. });
  2003. names = c.widgets || [];
  2004. len = names.length;
  2005. // build widget array & add priority as needed
  2006. for ( indx = 0; indx < len; indx++ ) {
  2007. widget = ts.getWidgetById( names[ indx ] );
  2008. if ( widget && widget.id ) {
  2009. // set priority to 10 if not defined
  2010. if ( !widget.priority ) { widget.priority = 10; }
  2011. widgets[ indx ] = widget;
  2012. } else if ( debug ) {
  2013. console.warn( '"' + names[ indx ] + '" was enabled, but the widget code has not been loaded!' );
  2014. }
  2015. }
  2016. // sort widgets by priority
  2017. widgets.sort( function( a, b ) {
  2018. return a.priority < b.priority ? -1 : a.priority === b.priority ? 0 : 1;
  2019. });
  2020. // add/update selected widgets
  2021. len = widgets.length;
  2022. if ( debug ) {
  2023. console[ console.group ? 'group' : 'log' ]( 'Start ' + ( init ? 'initializing' : 'applying' ) + ' widgets' );
  2024. }
  2025. for ( indx = 0; indx < len; indx++ ) {
  2026. widget = widgets[ indx ];
  2027. if ( widget && widget.id ) {
  2028. ts.applyWidgetId( table, widget.id, init );
  2029. }
  2030. }
  2031. if ( debug && console.groupEnd ) { console.groupEnd(); }
  2032. }
  2033. c.timerReady = setTimeout( function() {
  2034. table.isApplyingWidgets = false;
  2035. $.data( table, 'lastWidgetApplication', new Date() );
  2036. c.$table.triggerHandler( 'tablesorter-ready' );
  2037. // callback executed on init only
  2038. if ( !init && typeof callback === 'function' ) {
  2039. callback( table );
  2040. }
  2041. if ( debug ) {
  2042. widget = c.widgets.length;
  2043. console.log( 'Completed ' +
  2044. ( init === true ? 'initializing ' : 'applying ' ) + widget +
  2045. ' widget' + ( widget !== 1 ? 's' : '' ) + ts.benchmark( time ) );
  2046. }
  2047. }, 10 );
  2048. },
  2049. removeWidget : function( table, name, refreshing ) {
  2050. table = $( table )[ 0 ];
  2051. var index, widget, indx, len,
  2052. c = table.config;
  2053. // if name === true, add all widgets from $.tablesorter.widgets
  2054. if ( name === true ) {
  2055. name = [];
  2056. len = ts.widgets.length;
  2057. for ( indx = 0; indx < len; indx++ ) {
  2058. widget = ts.widgets[ indx ];
  2059. if ( widget && widget.id ) {
  2060. name[ name.length ] = widget.id;
  2061. }
  2062. }
  2063. } else {
  2064. // name can be either an array of widgets names,
  2065. // or a space/comma separated list of widget names
  2066. name = ( $.isArray( name ) ? name.join( ',' ) : name || '' ).toLowerCase().split( /[\s,]+/ );
  2067. }
  2068. len = name.length;
  2069. for ( index = 0; index < len; index++ ) {
  2070. widget = ts.getWidgetById( name[ index ] );
  2071. indx = $.inArray( name[ index ], c.widgets );
  2072. // don't remove the widget from config.widget if refreshing
  2073. if ( indx >= 0 && refreshing !== true ) {
  2074. c.widgets.splice( indx, 1 );
  2075. }
  2076. if ( widget && widget.remove ) {
  2077. if ( ts.debug(c, 'core') ) {
  2078. console.log( ( refreshing ? 'Refreshing' : 'Removing' ) + ' "' + name[ index ] + '" widget' );
  2079. }
  2080. widget.remove( table, c, c.widgetOptions, refreshing );
  2081. c.widgetInit[ name[ index ] ] = false;
  2082. }
  2083. }
  2084. c.$table.triggerHandler( 'widgetRemoveEnd', table );
  2085. },
  2086. refreshWidgets : function( table, doAll, dontapply ) {
  2087. table = $( table )[ 0 ]; // see issue #243
  2088. var indx, widget,
  2089. c = table.config,
  2090. curWidgets = c.widgets,
  2091. widgets = ts.widgets,
  2092. len = widgets.length,
  2093. list = [],
  2094. callback = function( table ) {
  2095. $( table ).triggerHandler( 'refreshComplete' );
  2096. };
  2097. // remove widgets not defined in config.widgets, unless doAll is true
  2098. for ( indx = 0; indx < len; indx++ ) {
  2099. widget = widgets[ indx ];
  2100. if ( widget && widget.id && ( doAll || $.inArray( widget.id, curWidgets ) < 0 ) ) {
  2101. list[ list.length ] = widget.id;
  2102. }
  2103. }
  2104. ts.removeWidget( table, list.join( ',' ), true );
  2105. if ( dontapply !== true ) {
  2106. // call widget init if
  2107. ts.applyWidget( table, doAll || false, callback );
  2108. if ( doAll ) {
  2109. // apply widget format
  2110. ts.applyWidget( table, false, callback );
  2111. }
  2112. } else {
  2113. callback( table );
  2114. }
  2115. },
  2116. /*
  2117. ██ ██ ██████ ██ ██ ██ ██████ ██ ██████ ▄█████
  2118. ██ ██ ██ ██ ██ ██ ██ ██ ██▄▄ ▀█▄
  2119. ██ ██ ██ ██ ██ ██ ██ ██ ██▀▀ ▀█▄
  2120. ▀████▀ ██ ██ ██████ ██ ██ ██ ██████ █████▀
  2121. */
  2122. benchmark : function( diff ) {
  2123. return ( ' (' + ( new Date().getTime() - diff.getTime() ) + ' ms)' );
  2124. },
  2125. // deprecated ts.log
  2126. log : function() {
  2127. console.log( arguments );
  2128. },
  2129. debug : function(c, name) {
  2130. return c && (
  2131. c.debug === true ||
  2132. typeof c.debug === 'string' && c.debug.indexOf(name) > -1
  2133. );
  2134. },
  2135. // $.isEmptyObject from jQuery v1.4
  2136. isEmptyObject : function( obj ) {
  2137. /*jshint forin: false */
  2138. for ( var name in obj ) {
  2139. return false;
  2140. }
  2141. return true;
  2142. },
  2143. isValueInArray : function( column, arry ) {
  2144. var indx,
  2145. len = arry && arry.length || 0;
  2146. for ( indx = 0; indx < len; indx++ ) {
  2147. if ( arry[ indx ][ 0 ] === column ) {
  2148. return indx;
  2149. }
  2150. }
  2151. return -1;
  2152. },
  2153. formatFloat : function( str, table ) {
  2154. if ( typeof str !== 'string' || str === '' ) { return str; }
  2155. // allow using formatFloat without a table; defaults to US number format
  2156. var num,
  2157. usFormat = table && table.config ? table.config.usNumberFormat !== false :
  2158. typeof table !== 'undefined' ? table : true;
  2159. if ( usFormat ) {
  2160. // US Format - 1,234,567.89 -> 1234567.89
  2161. str = str.replace( ts.regex.comma, '' );
  2162. } else {
  2163. // German Format = 1.234.567,89 -> 1234567.89
  2164. // French Format = 1 234 567,89 -> 1234567.89
  2165. str = str.replace( ts.regex.digitNonUS, '' ).replace( ts.regex.comma, '.' );
  2166. }
  2167. if ( ts.regex.digitNegativeTest.test( str ) ) {
  2168. // make (#) into a negative number -> (10) = -10
  2169. str = str.replace( ts.regex.digitNegativeReplace, '-$1' );
  2170. }
  2171. num = parseFloat( str );
  2172. // return the text instead of zero
  2173. return isNaN( num ) ? $.trim( str ) : num;
  2174. },
  2175. isDigit : function( str ) {
  2176. // replace all unwanted chars and match
  2177. return isNaN( str ) ?
  2178. ts.regex.digitTest.test( str.toString().replace( ts.regex.digitReplace, '' ) ) :
  2179. str !== '';
  2180. },
  2181. // computeTableHeaderCellIndexes from:
  2182. // http://www.javascripttoolbox.com/lib/table/examples.php
  2183. // http://www.javascripttoolbox.com/temp/table_cellindex.html
  2184. computeColumnIndex : function( $rows, c ) {
  2185. var i, j, k, l, cell, cells, rowIndex, rowSpan, colSpan, firstAvailCol,
  2186. // total columns has been calculated, use it to set the matrixrow
  2187. columns = c && c.columns || 0,
  2188. matrix = [],
  2189. matrixrow = new Array( columns );
  2190. for ( i = 0; i < $rows.length; i++ ) {
  2191. cells = $rows[ i ].cells;
  2192. for ( j = 0; j < cells.length; j++ ) {
  2193. cell = cells[ j ];
  2194. rowIndex = i;
  2195. rowSpan = cell.rowSpan || 1;
  2196. colSpan = cell.colSpan || 1;
  2197. if ( typeof matrix[ rowIndex ] === 'undefined' ) {
  2198. matrix[ rowIndex ] = [];
  2199. }
  2200. // Find first available column in the first row
  2201. for ( k = 0; k < matrix[ rowIndex ].length + 1; k++ ) {
  2202. if ( typeof matrix[ rowIndex ][ k ] === 'undefined' ) {
  2203. firstAvailCol = k;
  2204. break;
  2205. }
  2206. }
  2207. // jscs:disable disallowEmptyBlocks
  2208. if ( columns && cell.cellIndex === firstAvailCol ) {
  2209. // don't to anything
  2210. } else if ( cell.setAttribute ) {
  2211. // jscs:enable disallowEmptyBlocks
  2212. // add data-column (setAttribute = IE8+)
  2213. cell.setAttribute( 'data-column', firstAvailCol );
  2214. } else {
  2215. // remove once we drop support for IE7 - 1/12/2016
  2216. $( cell ).attr( 'data-column', firstAvailCol );
  2217. }
  2218. for ( k = rowIndex; k < rowIndex + rowSpan; k++ ) {
  2219. if ( typeof matrix[ k ] === 'undefined' ) {
  2220. matrix[ k ] = [];
  2221. }
  2222. matrixrow = matrix[ k ];
  2223. for ( l = firstAvailCol; l < firstAvailCol + colSpan; l++ ) {
  2224. matrixrow[ l ] = 'x';
  2225. }
  2226. }
  2227. }
  2228. }
  2229. ts.checkColumnCount($rows, matrix, matrixrow.length);
  2230. return matrixrow.length;
  2231. },
  2232. checkColumnCount : function($rows, matrix, columns) {
  2233. // this DOES NOT report any tbody column issues, except for the math and
  2234. // and column selector widgets
  2235. var i, len,
  2236. valid = true,
  2237. cells = [];
  2238. for ( i = 0; i < matrix.length; i++ ) {
  2239. // some matrix entries are undefined when testing the footer because
  2240. // it is using the rowIndex property
  2241. if ( matrix[i] ) {
  2242. len = matrix[i].length;
  2243. if ( matrix[i].length !== columns ) {
  2244. valid = false;
  2245. break;
  2246. }
  2247. }
  2248. }
  2249. if ( !valid ) {
  2250. $rows.each( function( indx, el ) {
  2251. var cell = el.parentElement.nodeName;
  2252. if ( cells.indexOf( cell ) < 0 ) {
  2253. cells.push( cell );
  2254. }
  2255. });
  2256. console.error(
  2257. 'Invalid or incorrect number of columns in the ' +
  2258. cells.join( ' or ' ) + '; expected ' + columns +
  2259. ', but found ' + len + ' columns'
  2260. );
  2261. }
  2262. },
  2263. // automatically add a colgroup with col elements set to a percentage width
  2264. fixColumnWidth : function( table ) {
  2265. table = $( table )[ 0 ];
  2266. var overallWidth, percent, $tbodies, len, index,
  2267. c = table.config,
  2268. $colgroup = c.$table.children( 'colgroup' );
  2269. // remove plugin-added colgroup, in case we need to refresh the widths
  2270. if ( $colgroup.length && $colgroup.hasClass( ts.css.colgroup ) ) {
  2271. $colgroup.remove();
  2272. }
  2273. if ( c.widthFixed && c.$table.children( 'colgroup' ).length === 0 ) {
  2274. $colgroup = $( '<colgroup class="' + ts.css.colgroup + '">' );
  2275. overallWidth = c.$table.width();
  2276. // only add col for visible columns - fixes #371
  2277. $tbodies = c.$tbodies.find( 'tr:first' ).children( ':visible' );
  2278. len = $tbodies.length;
  2279. for ( index = 0; index < len; index++ ) {
  2280. percent = parseInt( ( $tbodies.eq( index ).width() / overallWidth ) * 1000, 10 ) / 10 + '%';
  2281. $colgroup.append( $( '<col>' ).css( 'width', percent ) );
  2282. }
  2283. c.$table.prepend( $colgroup );
  2284. }
  2285. },
  2286. // get sorter, string, empty, etc options for each column from
  2287. // jQuery data, metadata, header option or header class name ('sorter-false')
  2288. // priority = jQuery data > meta > headers option > header class name
  2289. getData : function( header, configHeader, key ) {
  2290. var meta, cl4ss,
  2291. val = '',
  2292. $header = $( header );
  2293. if ( !$header.length ) { return ''; }
  2294. meta = $.metadata ? $header.metadata() : false;
  2295. cl4ss = ' ' + ( $header.attr( 'class' ) || '' );
  2296. if ( typeof $header.data( key ) !== 'undefined' ||
  2297. typeof $header.data( key.toLowerCase() ) !== 'undefined' ) {
  2298. // 'data-lockedOrder' is assigned to 'lockedorder'; but 'data-locked-order' is assigned to 'lockedOrder'
  2299. // 'data-sort-initial-order' is assigned to 'sortInitialOrder'
  2300. val += $header.data( key ) || $header.data( key.toLowerCase() );
  2301. } else if ( meta && typeof meta[ key ] !== 'undefined' ) {
  2302. val += meta[ key ];
  2303. } else if ( configHeader && typeof configHeader[ key ] !== 'undefined' ) {
  2304. val += configHeader[ key ];
  2305. } else if ( cl4ss !== ' ' && cl4ss.match( ' ' + key + '-' ) ) {
  2306. // include sorter class name 'sorter-text', etc; now works with 'sorter-my-custom-parser'
  2307. val = cl4ss.match( new RegExp( '\\s' + key + '-([\\w-]+)' ) )[ 1 ] || '';
  2308. }
  2309. return $.trim( val );
  2310. },
  2311. getColumnData : function( table, obj, indx, getCell, $headers ) {
  2312. if ( typeof obj !== 'object' || obj === null ) {
  2313. return obj;
  2314. }
  2315. table = $( table )[ 0 ];
  2316. var $header, key,
  2317. c = table.config,
  2318. $cells = ( $headers || c.$headers ),
  2319. // c.$headerIndexed is not defined initially
  2320. $cell = c.$headerIndexed && c.$headerIndexed[ indx ] ||
  2321. $cells.find( '[data-column="' + indx + '"]:last' );
  2322. if ( typeof obj[ indx ] !== 'undefined' ) {
  2323. return getCell ? obj[ indx ] : obj[ $cells.index( $cell ) ];
  2324. }
  2325. for ( key in obj ) {
  2326. if ( typeof key === 'string' ) {
  2327. $header = $cell
  2328. // header cell with class/id
  2329. .filter( key )
  2330. // find elements within the header cell with cell/id
  2331. .add( $cell.find( key ) );
  2332. if ( $header.length ) {
  2333. return obj[ key ];
  2334. }
  2335. }
  2336. }
  2337. return;
  2338. },
  2339. // *** Process table ***
  2340. // add processing indicator
  2341. isProcessing : function( $table, toggle, $headers ) {
  2342. $table = $( $table );
  2343. var c = $table[ 0 ].config,
  2344. // default to all headers
  2345. $header = $headers || $table.find( '.' + ts.css.header );
  2346. if ( toggle ) {
  2347. // don't use sortList if custom $headers used
  2348. if ( typeof $headers !== 'undefined' && c.sortList.length > 0 ) {
  2349. // get headers from the sortList
  2350. $header = $header.filter( function() {
  2351. // get data-column from attr to keep compatibility with jQuery 1.2.6
  2352. return this.sortDisabled ?
  2353. false :
  2354. ts.isValueInArray( parseFloat( $( this ).attr( 'data-column' ) ), c.sortList ) >= 0;
  2355. });
  2356. }
  2357. $table.add( $header ).addClass( ts.css.processing + ' ' + c.cssProcessing );
  2358. } else {
  2359. $table.add( $header ).removeClass( ts.css.processing + ' ' + c.cssProcessing );
  2360. }
  2361. },
  2362. // detach tbody but save the position
  2363. // don't use tbody because there are portions that look for a tbody index (updateCell)
  2364. processTbody : function( table, $tb, getIt ) {
  2365. table = $( table )[ 0 ];
  2366. if ( getIt ) {
  2367. table.isProcessing = true;
  2368. $tb.before( '<colgroup class="tablesorter-savemyplace"/>' );
  2369. return $.fn.detach ? $tb.detach() : $tb.remove();
  2370. }
  2371. var holdr = $( table ).find( 'colgroup.tablesorter-savemyplace' );
  2372. $tb.insertAfter( holdr );
  2373. holdr.remove();
  2374. table.isProcessing = false;
  2375. },
  2376. clearTableBody : function( table ) {
  2377. $( table )[ 0 ].config.$tbodies.children().detach();
  2378. },
  2379. // used when replacing accented characters during sorting
  2380. characterEquivalents : {
  2381. 'a' : '\u00e1\u00e0\u00e2\u00e3\u00e4\u0105\u00e5', // áàâãäąå
  2382. 'A' : '\u00c1\u00c0\u00c2\u00c3\u00c4\u0104\u00c5', // ÁÀÂÃÄĄÅ
  2383. 'c' : '\u00e7\u0107\u010d', // çćč
  2384. 'C' : '\u00c7\u0106\u010c', // ÇĆČ
  2385. 'e' : '\u00e9\u00e8\u00ea\u00eb\u011b\u0119', // éèêëěę
  2386. 'E' : '\u00c9\u00c8\u00ca\u00cb\u011a\u0118', // ÉÈÊËĚĘ
  2387. 'i' : '\u00ed\u00ec\u0130\u00ee\u00ef\u0131', // íìİîïı
  2388. 'I' : '\u00cd\u00cc\u0130\u00ce\u00cf', // ÍÌİÎÏ
  2389. 'o' : '\u00f3\u00f2\u00f4\u00f5\u00f6\u014d', // óòôõöō
  2390. 'O' : '\u00d3\u00d2\u00d4\u00d5\u00d6\u014c', // ÓÒÔÕÖŌ
  2391. 'ss': '\u00df', // ß (s sharp)
  2392. 'SS': '\u1e9e', // ẞ (Capital sharp s)
  2393. 'u' : '\u00fa\u00f9\u00fb\u00fc\u016f', // úùûüů
  2394. 'U' : '\u00da\u00d9\u00db\u00dc\u016e' // ÚÙÛÜŮ
  2395. },
  2396. replaceAccents : function( str ) {
  2397. var chr,
  2398. acc = '[',
  2399. eq = ts.characterEquivalents;
  2400. if ( !ts.characterRegex ) {
  2401. ts.characterRegexArray = {};
  2402. for ( chr in eq ) {
  2403. if ( typeof chr === 'string' ) {
  2404. acc += eq[ chr ];
  2405. ts.characterRegexArray[ chr ] = new RegExp( '[' + eq[ chr ] + ']', 'g' );
  2406. }
  2407. }
  2408. ts.characterRegex = new RegExp( acc + ']' );
  2409. }
  2410. if ( ts.characterRegex.test( str ) ) {
  2411. for ( chr in eq ) {
  2412. if ( typeof chr === 'string' ) {
  2413. str = str.replace( ts.characterRegexArray[ chr ], chr );
  2414. }
  2415. }
  2416. }
  2417. return str;
  2418. },
  2419. validateOptions : function( c ) {
  2420. var setting, setting2, typ, timer,
  2421. // ignore options containing an array
  2422. ignore = 'headers sortForce sortList sortAppend widgets'.split( ' ' ),
  2423. orig = c.originalSettings;
  2424. if ( orig ) {
  2425. if ( ts.debug(c, 'core') ) {
  2426. timer = new Date();
  2427. }
  2428. for ( setting in orig ) {
  2429. typ = typeof ts.defaults[setting];
  2430. if ( typ === 'undefined' ) {
  2431. console.warn( 'Tablesorter Warning! "table.config.' + setting + '" option not recognized' );
  2432. } else if ( typ === 'object' ) {
  2433. for ( setting2 in orig[setting] ) {
  2434. typ = ts.defaults[setting] && typeof ts.defaults[setting][setting2];
  2435. if ( $.inArray( setting, ignore ) < 0 && typ === 'undefined' ) {
  2436. console.warn( 'Tablesorter Warning! "table.config.' + setting + '.' + setting2 + '" option not recognized' );
  2437. }
  2438. }
  2439. }
  2440. }
  2441. if ( ts.debug(c, 'core') ) {
  2442. console.log( 'validate options time:' + ts.benchmark( timer ) );
  2443. }
  2444. }
  2445. },
  2446. // restore headers
  2447. restoreHeaders : function( table ) {
  2448. var index, $cell,
  2449. c = $( table )[ 0 ].config,
  2450. $headers = c.$table.find( c.selectorHeaders ),
  2451. len = $headers.length;
  2452. // don't use c.$headers here in case header cells were swapped
  2453. for ( index = 0; index < len; index++ ) {
  2454. $cell = $headers.eq( index );
  2455. // only restore header cells if it is wrapped
  2456. // because this is also used by the updateAll method
  2457. if ( $cell.find( '.' + ts.css.headerIn ).length ) {
  2458. $cell.html( c.headerContent[ index ] );
  2459. }
  2460. }
  2461. },
  2462. destroy : function( table, removeClasses, callback ) {
  2463. table = $( table )[ 0 ];
  2464. if ( !table.hasInitialized ) { return; }
  2465. // remove all widgets
  2466. ts.removeWidget( table, true, false );
  2467. var events,
  2468. $t = $( table ),
  2469. c = table.config,
  2470. $h = $t.find( 'thead:first' ),
  2471. $r = $h.find( 'tr.' + ts.css.headerRow ).removeClass( ts.css.headerRow + ' ' + c.cssHeaderRow ),
  2472. $f = $t.find( 'tfoot:first > tr' ).children( 'th, td' );
  2473. if ( removeClasses === false && $.inArray( 'uitheme', c.widgets ) >= 0 ) {
  2474. // reapply uitheme classes, in case we want to maintain appearance
  2475. $t.triggerHandler( 'applyWidgetId', [ 'uitheme' ] );
  2476. $t.triggerHandler( 'applyWidgetId', [ 'zebra' ] );
  2477. }
  2478. // remove widget added rows, just in case
  2479. $h.find( 'tr' ).not( $r ).remove();
  2480. // disable tablesorter - not using .unbind( namespace ) because namespacing was
  2481. // added in jQuery v1.4.3 - see http://api.jquery.com/event.namespace/
  2482. events = 'sortReset update updateRows updateAll updateHeaders updateCell addRows updateComplete sorton ' +
  2483. 'appendCache updateCache applyWidgetId applyWidgets refreshWidgets removeWidget destroy mouseup mouseleave ' +
  2484. 'keypress sortBegin sortEnd resetToLoadState '.split( ' ' )
  2485. .join( c.namespace + ' ' );
  2486. $t
  2487. .removeData( 'tablesorter' )
  2488. .unbind( events.replace( ts.regex.spaces, ' ' ) );
  2489. c.$headers
  2490. .add( $f )
  2491. .removeClass( [ ts.css.header, c.cssHeader, c.cssAsc, c.cssDesc, ts.css.sortAsc, ts.css.sortDesc, ts.css.sortNone ].join( ' ' ) )
  2492. .removeAttr( 'data-column' )
  2493. .removeAttr( 'aria-label' )
  2494. .attr( 'aria-disabled', 'true' );
  2495. $r
  2496. .find( c.selectorSort )
  2497. .unbind( ( 'mousedown mouseup keypress '.split( ' ' ).join( c.namespace + ' ' ) ).replace( ts.regex.spaces, ' ' ) );
  2498. ts.restoreHeaders( table );
  2499. $t.toggleClass( ts.css.table + ' ' + c.tableClass + ' tablesorter-' + c.theme, removeClasses === false );
  2500. $t.removeClass(c.namespace.slice(1));
  2501. // clear flag in case the plugin is initialized again
  2502. table.hasInitialized = false;
  2503. delete table.config.cache;
  2504. if ( typeof callback === 'function' ) {
  2505. callback( table );
  2506. }
  2507. if ( ts.debug(c, 'core') ) {
  2508. console.log( 'tablesorter has been removed' );
  2509. }
  2510. }
  2511. };
  2512. $.fn.tablesorter = function( settings ) {
  2513. return this.each( function() {
  2514. var table = this,
  2515. // merge & extend config options
  2516. c = $.extend( true, {}, ts.defaults, settings, ts.instanceMethods );
  2517. // save initial settings
  2518. c.originalSettings = settings;
  2519. // create a table from data (build table widget)
  2520. if ( !table.hasInitialized && ts.buildTable && this.nodeName !== 'TABLE' ) {
  2521. // return the table (in case the original target is the table's container)
  2522. ts.buildTable( table, c );
  2523. } else {
  2524. ts.setup( table, c );
  2525. }
  2526. });
  2527. };
  2528. // set up debug logs
  2529. if ( !( window.console && window.console.log ) ) {
  2530. // access $.tablesorter.logs for browsers that don't have a console...
  2531. ts.logs = [];
  2532. /*jshint -W020 */
  2533. console = {};
  2534. console.log = console.warn = console.error = console.table = function() {
  2535. var arg = arguments.length > 1 ? arguments : arguments[0];
  2536. ts.logs[ ts.logs.length ] = { date: Date.now(), log: arg };
  2537. };
  2538. }
  2539. // add default parsers
  2540. ts.addParser({
  2541. id : 'no-parser',
  2542. is : function() {
  2543. return false;
  2544. },
  2545. format : function() {
  2546. return '';
  2547. },
  2548. type : 'text'
  2549. });
  2550. ts.addParser({
  2551. id : 'text',
  2552. is : function() {
  2553. return true;
  2554. },
  2555. format : function( str, table ) {
  2556. var c = table.config;
  2557. if ( str ) {
  2558. str = $.trim( c.ignoreCase ? str.toLocaleLowerCase() : str );
  2559. str = c.sortLocaleCompare ? ts.replaceAccents( str ) : str;
  2560. }
  2561. return str;
  2562. },
  2563. type : 'text'
  2564. });
  2565. ts.regex.nondigit = /[^\w,. \-()]/g;
  2566. ts.addParser({
  2567. id : 'digit',
  2568. is : function( str ) {
  2569. return ts.isDigit( str );
  2570. },
  2571. format : function( str, table ) {
  2572. var num = ts.formatFloat( ( str || '' ).replace( ts.regex.nondigit, '' ), table );
  2573. return str && typeof num === 'number' ? num :
  2574. str ? $.trim( str && table.config.ignoreCase ? str.toLocaleLowerCase() : str ) : str;
  2575. },
  2576. type : 'numeric'
  2577. });
  2578. ts.regex.currencyReplace = /[+\-,. ]/g;
  2579. ts.regex.currencyTest = /^\(?\d+[\u00a3$\u20ac\u00a4\u00a5\u00a2?.]|[\u00a3$\u20ac\u00a4\u00a5\u00a2?.]\d+\)?$/;
  2580. ts.addParser({
  2581. id : 'currency',
  2582. is : function( str ) {
  2583. str = ( str || '' ).replace( ts.regex.currencyReplace, '' );
  2584. // test for £$€¤¥¢
  2585. return ts.regex.currencyTest.test( str );
  2586. },
  2587. format : function( str, table ) {
  2588. var num = ts.formatFloat( ( str || '' ).replace( ts.regex.nondigit, '' ), table );
  2589. return str && typeof num === 'number' ? num :
  2590. str ? $.trim( str && table.config.ignoreCase ? str.toLocaleLowerCase() : str ) : str;
  2591. },
  2592. type : 'numeric'
  2593. });
  2594. // too many protocols to add them all https://en.wikipedia.org/wiki/URI_scheme
  2595. // now, this regex can be updated before initialization
  2596. ts.regex.urlProtocolTest = /^(https?|ftp|file):\/\//;
  2597. ts.regex.urlProtocolReplace = /(https?|ftp|file):\/\/(www\.)?/;
  2598. ts.addParser({
  2599. id : 'url',
  2600. is : function( str ) {
  2601. return ts.regex.urlProtocolTest.test( str );
  2602. },
  2603. format : function( str ) {
  2604. return str ? $.trim( str.replace( ts.regex.urlProtocolReplace, '' ) ) : str;
  2605. },
  2606. type : 'text'
  2607. });
  2608. ts.regex.dash = /-/g;
  2609. ts.regex.isoDate = /^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}/;
  2610. ts.addParser({
  2611. id : 'isoDate',
  2612. is : function( str ) {
  2613. return ts.regex.isoDate.test( str );
  2614. },
  2615. format : function( str ) {
  2616. var date = str ? new Date( str.replace( ts.regex.dash, '/' ) ) : str;
  2617. return date instanceof Date && isFinite( date ) ? date.getTime() : str;
  2618. },
  2619. type : 'numeric'
  2620. });
  2621. ts.regex.percent = /%/g;
  2622. ts.regex.percentTest = /(\d\s*?%|%\s*?\d)/;
  2623. ts.addParser({
  2624. id : 'percent',
  2625. is : function( str ) {
  2626. return ts.regex.percentTest.test( str ) && str.length < 15;
  2627. },
  2628. format : function( str, table ) {
  2629. return str ? ts.formatFloat( str.replace( ts.regex.percent, '' ), table ) : str;
  2630. },
  2631. type : 'numeric'
  2632. });
  2633. // added image parser to core v2.17.9
  2634. ts.addParser({
  2635. id : 'image',
  2636. is : function( str, table, node, $node ) {
  2637. return $node.find( 'img' ).length > 0;
  2638. },
  2639. format : function( str, table, cell ) {
  2640. return $( cell ).find( 'img' ).attr( table.config.imgAttr || 'alt' ) || str;
  2641. },
  2642. parsed : true, // filter widget flag
  2643. type : 'text'
  2644. });
  2645. ts.regex.dateReplace = /(\S)([AP]M)$/i; // used by usLongDate & time parser
  2646. ts.regex.usLongDateTest1 = /^[A-Z]{3,10}\.?\s+\d{1,2},?\s+(\d{4})(\s+\d{1,2}:\d{2}(:\d{2})?(\s+[AP]M)?)?$/i;
  2647. ts.regex.usLongDateTest2 = /^\d{1,2}\s+[A-Z]{3,10}\s+\d{4}/i;
  2648. ts.addParser({
  2649. id : 'usLongDate',
  2650. is : function( str ) {
  2651. // two digit years are not allowed cross-browser
  2652. // Jan 01, 2013 12:34:56 PM or 01 Jan 2013
  2653. return ts.regex.usLongDateTest1.test( str ) || ts.regex.usLongDateTest2.test( str );
  2654. },
  2655. format : function( str ) {
  2656. var date = str ? new Date( str.replace( ts.regex.dateReplace, '$1 $2' ) ) : str;
  2657. return date instanceof Date && isFinite( date ) ? date.getTime() : str;
  2658. },
  2659. type : 'numeric'
  2660. });
  2661. // testing for ##-##-#### or ####-##-##, so it's not perfect; time can be included
  2662. ts.regex.shortDateTest = /(^\d{1,2}[\/\s]\d{1,2}[\/\s]\d{4})|(^\d{4}[\/\s]\d{1,2}[\/\s]\d{1,2})/;
  2663. // escaped "-" because JSHint in Firefox was showing it as an error
  2664. ts.regex.shortDateReplace = /[\-.,]/g;
  2665. // XXY covers MDY & DMY formats
  2666. ts.regex.shortDateXXY = /(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{4})/;
  2667. ts.regex.shortDateYMD = /(\d{4})[\/\s](\d{1,2})[\/\s](\d{1,2})/;
  2668. ts.convertFormat = function( dateString, format ) {
  2669. dateString = ( dateString || '' )
  2670. .replace( ts.regex.spaces, ' ' )
  2671. .replace( ts.regex.shortDateReplace, '/' );
  2672. if ( format === 'mmddyyyy' ) {
  2673. dateString = dateString.replace( ts.regex.shortDateXXY, '$3/$1/$2' );
  2674. } else if ( format === 'ddmmyyyy' ) {
  2675. dateString = dateString.replace( ts.regex.shortDateXXY, '$3/$2/$1' );
  2676. } else if ( format === 'yyyymmdd' ) {
  2677. dateString = dateString.replace( ts.regex.shortDateYMD, '$1/$2/$3' );
  2678. }
  2679. var date = new Date( dateString );
  2680. return date instanceof Date && isFinite( date ) ? date.getTime() : '';
  2681. };
  2682. ts.addParser({
  2683. id : 'shortDate', // 'mmddyyyy', 'ddmmyyyy' or 'yyyymmdd'
  2684. is : function( str ) {
  2685. str = ( str || '' ).replace( ts.regex.spaces, ' ' ).replace( ts.regex.shortDateReplace, '/' );
  2686. return ts.regex.shortDateTest.test( str );
  2687. },
  2688. format : function( str, table, cell, cellIndex ) {
  2689. if ( str ) {
  2690. var c = table.config,
  2691. $header = c.$headerIndexed[ cellIndex ],
  2692. format = $header.length && $header.data( 'dateFormat' ) ||
  2693. ts.getData( $header, ts.getColumnData( table, c.headers, cellIndex ), 'dateFormat' ) ||
  2694. c.dateFormat;
  2695. // save format because getData can be slow...
  2696. if ( $header.length ) {
  2697. $header.data( 'dateFormat', format );
  2698. }
  2699. return ts.convertFormat( str, format ) || str;
  2700. }
  2701. return str;
  2702. },
  2703. type : 'numeric'
  2704. });
  2705. // match 24 hour time & 12 hours time + am/pm - see http://regexr.com/3c3tk
  2706. ts.regex.timeTest = /^(0?[1-9]|1[0-2]):([0-5]\d)(\s[AP]M)$|^((?:[01]\d|[2][0-4]):[0-5]\d)$/i;
  2707. ts.regex.timeMatch = /(0?[1-9]|1[0-2]):([0-5]\d)(\s[AP]M)|((?:[01]\d|[2][0-4]):[0-5]\d)/i;
  2708. ts.addParser({
  2709. id : 'time',
  2710. is : function( str ) {
  2711. return ts.regex.timeTest.test( str );
  2712. },
  2713. format : function( str ) {
  2714. // isolate time... ignore month, day and year
  2715. var temp,
  2716. timePart = ( str || '' ).match( ts.regex.timeMatch ),
  2717. orig = new Date( str ),
  2718. // no time component? default to 00:00 by leaving it out, but only if str is defined
  2719. time = str && ( timePart !== null ? timePart[ 0 ] : '00:00 AM' ),
  2720. date = time ? new Date( '2000/01/01 ' + time.replace( ts.regex.dateReplace, '$1 $2' ) ) : time;
  2721. if ( date instanceof Date && isFinite( date ) ) {
  2722. temp = orig instanceof Date && isFinite( orig ) ? orig.getTime() : 0;
  2723. // if original string was a valid date, add it to the decimal so the column sorts in some kind of order
  2724. // luckily new Date() ignores the decimals
  2725. return temp ? parseFloat( date.getTime() + '.' + orig.getTime() ) : date.getTime();
  2726. }
  2727. return str;
  2728. },
  2729. type : 'numeric'
  2730. });
  2731. ts.addParser({
  2732. id : 'metadata',
  2733. is : function() {
  2734. return false;
  2735. },
  2736. format : function( str, table, cell ) {
  2737. var c = table.config,
  2738. p = ( !c.parserMetadataName ) ? 'sortValue' : c.parserMetadataName;
  2739. return $( cell ).metadata()[ p ];
  2740. },
  2741. type : 'numeric'
  2742. });
  2743. /*
  2744. ██████ ██████ █████▄ █████▄ ▄████▄
  2745. ▄█▀ ██▄▄ ██▄▄██ ██▄▄██ ██▄▄██
  2746. ▄█▀ ██▀▀ ██▀▀██ ██▀▀█ ██▀▀██
  2747. ██████ ██████ █████▀ ██ ██ ██ ██
  2748. */
  2749. // add default widgets
  2750. ts.addWidget({
  2751. id : 'zebra',
  2752. priority : 90,
  2753. format : function( table, c, wo ) {
  2754. var $visibleRows, $row, count, isEven, tbodyIndex, rowIndex, len,
  2755. child = new RegExp( c.cssChildRow, 'i' ),
  2756. $tbodies = c.$tbodies.add( $( c.namespace + '_extra_table' ).children( 'tbody:not(.' + c.cssInfoBlock + ')' ) );
  2757. for ( tbodyIndex = 0; tbodyIndex < $tbodies.length; tbodyIndex++ ) {
  2758. // loop through the visible rows
  2759. count = 0;
  2760. $visibleRows = $tbodies.eq( tbodyIndex ).children( 'tr:visible' ).not( c.selectorRemove );
  2761. len = $visibleRows.length;
  2762. for ( rowIndex = 0; rowIndex < len; rowIndex++ ) {
  2763. $row = $visibleRows.eq( rowIndex );
  2764. // style child rows the same way the parent row was styled
  2765. if ( !child.test( $row[ 0 ].className ) ) { count++; }
  2766. isEven = ( count % 2 === 0 );
  2767. $row
  2768. .removeClass( wo.zebra[ isEven ? 1 : 0 ] )
  2769. .addClass( wo.zebra[ isEven ? 0 : 1 ] );
  2770. }
  2771. }
  2772. },
  2773. remove : function( table, c, wo, refreshing ) {
  2774. if ( refreshing ) { return; }
  2775. var tbodyIndex, $tbody,
  2776. $tbodies = c.$tbodies,
  2777. toRemove = ( wo.zebra || [ 'even', 'odd' ] ).join( ' ' );
  2778. for ( tbodyIndex = 0; tbodyIndex < $tbodies.length; tbodyIndex++ ) {
  2779. $tbody = ts.processTbody( table, $tbodies.eq( tbodyIndex ), true ); // remove tbody
  2780. $tbody.children().removeClass( toRemove );
  2781. ts.processTbody( table, $tbody, false ); // restore tbody
  2782. }
  2783. }
  2784. });
  2785. })( jQuery );
  2786. /*! Widget: storage - updated 2018-03-18 (v2.30.0) */
  2787. /*global JSON:false */
  2788. ;(function ($, window, document) {
  2789. 'use strict';
  2790. var ts = $.tablesorter || {};
  2791. // update defaults for validator; these values must be falsy!
  2792. $.extend(true, ts.defaults, {
  2793. fixedUrl: '',
  2794. widgetOptions: {
  2795. storage_fixedUrl: '',
  2796. storage_group: '',
  2797. storage_page: '',
  2798. storage_storageType: '',
  2799. storage_tableId: '',
  2800. storage_useSessionStorage: ''
  2801. }
  2802. });
  2803. // *** Store data in local storage, with a cookie fallback ***
  2804. /* IE7 needs JSON library for JSON.stringify - (http://caniuse.com/#search=json)
  2805. if you need it, then include https://github.com/douglascrockford/JSON-js
  2806. $.parseJSON is not available is jQuery versions older than 1.4.1, using older
  2807. versions will only allow storing information for one page at a time
  2808. // *** Save data (JSON format only) ***
  2809. // val must be valid JSON... use http://jsonlint.com/ to ensure it is valid
  2810. var val = { "mywidget" : "data1" }; // valid JSON uses double quotes
  2811. // $.tablesorter.storage(table, key, val);
  2812. $.tablesorter.storage(table, 'tablesorter-mywidget', val);
  2813. // *** Get data: $.tablesorter.storage(table, key); ***
  2814. v = $.tablesorter.storage(table, 'tablesorter-mywidget');
  2815. // val may be empty, so also check for your data
  2816. val = (v && v.hasOwnProperty('mywidget')) ? v.mywidget : '';
  2817. alert(val); // 'data1' if saved, or '' if not
  2818. */
  2819. ts.storage = function(table, key, value, options) {
  2820. table = $(table)[0];
  2821. var cookieIndex, cookies, date,
  2822. hasStorage = false,
  2823. values = {},
  2824. c = table.config,
  2825. wo = c && c.widgetOptions,
  2826. debug = ts.debug(c, 'storage'),
  2827. storageType = (
  2828. ( options && options.storageType ) || ( wo && wo.storage_storageType )
  2829. ).toString().charAt(0).toLowerCase(),
  2830. // deprecating "useSessionStorage"; any storageType setting overrides it
  2831. session = storageType ? '' :
  2832. ( options && options.useSessionStorage ) || ( wo && wo.storage_useSessionStorage ),
  2833. $table = $(table),
  2834. // id from (1) options ID, (2) table 'data-table-group' attribute, (3) widgetOptions.storage_tableId,
  2835. // (4) table ID, then (5) table index
  2836. id = options && options.id ||
  2837. $table.attr( options && options.group || wo && wo.storage_group || 'data-table-group') ||
  2838. wo && wo.storage_tableId || table.id || $('.tablesorter').index( $table ),
  2839. // url from (1) options url, (2) table 'data-table-page' attribute, (3) widgetOptions.storage_fixedUrl,
  2840. // (4) table.config.fixedUrl (deprecated), then (5) window location path
  2841. url = options && options.url ||
  2842. $table.attr(options && options.page || wo && wo.storage_page || 'data-table-page') ||
  2843. wo && wo.storage_fixedUrl || c && c.fixedUrl || window.location.pathname;
  2844. // skip if using cookies
  2845. if (storageType !== 'c') {
  2846. storageType = (storageType === 's' || session) ? 'sessionStorage' : 'localStorage';
  2847. // https://gist.github.com/paulirish/5558557
  2848. if (storageType in window) {
  2849. try {
  2850. window[storageType].setItem('_tmptest', 'temp');
  2851. hasStorage = true;
  2852. window[storageType].removeItem('_tmptest');
  2853. } catch (error) {
  2854. console.warn( storageType + ' is not supported in this browser' );
  2855. }
  2856. }
  2857. }
  2858. if (debug) {
  2859. console.log('Storage >> Using', hasStorage ? storageType : 'cookies');
  2860. }
  2861. // *** get value ***
  2862. if ($.parseJSON) {
  2863. if (hasStorage) {
  2864. values = $.parseJSON( window[storageType][key] || 'null' ) || {};
  2865. } else {
  2866. // old browser, using cookies
  2867. cookies = document.cookie.split(/[;\s|=]/);
  2868. // add one to get from the key to the value
  2869. cookieIndex = $.inArray(key, cookies) + 1;
  2870. values = (cookieIndex !== 0) ? $.parseJSON(cookies[cookieIndex] || 'null') || {} : {};
  2871. }
  2872. }
  2873. // allow value to be an empty string too
  2874. if (typeof value !== 'undefined' && window.JSON && JSON.hasOwnProperty('stringify')) {
  2875. // add unique identifiers = url pathname > table ID/index on page > data
  2876. if (!values[url]) {
  2877. values[url] = {};
  2878. }
  2879. values[url][id] = value;
  2880. // *** set value ***
  2881. if (hasStorage) {
  2882. window[storageType][key] = JSON.stringify(values);
  2883. } else {
  2884. date = new Date();
  2885. date.setTime(date.getTime() + (31536e+6)); // 365 days
  2886. document.cookie = key + '=' + (JSON.stringify(values)).replace(/\"/g, '\"') + '; expires=' + date.toGMTString() + '; path=/';
  2887. }
  2888. } else {
  2889. return values && values[url] ? values[url][id] : '';
  2890. }
  2891. };
  2892. })(jQuery, window, document);
  2893. /*! Widget: uitheme - updated 2018-03-18 (v2.30.0) */
  2894. ;(function ($) {
  2895. 'use strict';
  2896. var ts = $.tablesorter || {};
  2897. ts.themes = {
  2898. 'bootstrap' : {
  2899. table : 'table table-bordered table-striped',
  2900. caption : 'caption',
  2901. // header class names
  2902. header : 'bootstrap-header', // give the header a gradient background (theme.bootstrap_2.css)
  2903. sortNone : '',
  2904. sortAsc : '',
  2905. sortDesc : '',
  2906. active : '', // applied when column is sorted
  2907. hover : '', // custom css required - a defined bootstrap style may not override other classes
  2908. // icon class names
  2909. icons : '', // add 'bootstrap-icon-white' to make them white; this icon class is added to the <i> in the header
  2910. iconSortNone : 'bootstrap-icon-unsorted', // class name added to icon when column is not sorted
  2911. iconSortAsc : 'glyphicon glyphicon-chevron-up', // class name added to icon when column has ascending sort
  2912. iconSortDesc : 'glyphicon glyphicon-chevron-down', // class name added to icon when column has descending sort
  2913. filterRow : '', // filter row class
  2914. footerRow : '',
  2915. footerCells : '',
  2916. even : '', // even row zebra striping
  2917. odd : '' // odd row zebra striping
  2918. },
  2919. 'jui' : {
  2920. table : 'ui-widget ui-widget-content ui-corner-all', // table classes
  2921. caption : 'ui-widget-content',
  2922. // header class names
  2923. header : 'ui-widget-header ui-corner-all ui-state-default', // header classes
  2924. sortNone : '',
  2925. sortAsc : '',
  2926. sortDesc : '',
  2927. active : 'ui-state-active', // applied when column is sorted
  2928. hover : 'ui-state-hover', // hover class
  2929. // icon class names
  2930. icons : 'ui-icon', // icon class added to the <i> in the header
  2931. iconSortNone : 'ui-icon-carat-2-n-s ui-icon-caret-2-n-s', // class name added to icon when column is not sorted
  2932. iconSortAsc : 'ui-icon-carat-1-n ui-icon-caret-1-n', // class name added to icon when column has ascending sort
  2933. iconSortDesc : 'ui-icon-carat-1-s ui-icon-caret-1-s', // class name added to icon when column has descending sort
  2934. filterRow : '',
  2935. footerRow : '',
  2936. footerCells : '',
  2937. even : 'ui-widget-content', // even row zebra striping
  2938. odd : 'ui-state-default' // odd row zebra striping
  2939. }
  2940. };
  2941. $.extend(ts.css, {
  2942. wrapper : 'tablesorter-wrapper' // ui theme & resizable
  2943. });
  2944. ts.addWidget({
  2945. id: 'uitheme',
  2946. priority: 10,
  2947. format: function(table, c, wo) {
  2948. var i, tmp, hdr, icon, time, $header, $icon, $tfoot, $h, oldtheme, oldremove, oldIconRmv, hasOldTheme,
  2949. themesAll = ts.themes,
  2950. $table = c.$table.add( $( c.namespace + '_extra_table' ) ),
  2951. $headers = c.$headers.add( $( c.namespace + '_extra_headers' ) ),
  2952. theme = c.theme || 'jui',
  2953. themes = themesAll[theme] || {},
  2954. remove = $.trim( [ themes.sortNone, themes.sortDesc, themes.sortAsc, themes.active ].join( ' ' ) ),
  2955. iconRmv = $.trim( [ themes.iconSortNone, themes.iconSortDesc, themes.iconSortAsc ].join( ' ' ) ),
  2956. debug = ts.debug(c, 'uitheme');
  2957. if (debug) { time = new Date(); }
  2958. // initialization code - run once
  2959. if (!$table.hasClass('tablesorter-' + theme) || c.theme !== c.appliedTheme || !wo.uitheme_applied) {
  2960. wo.uitheme_applied = true;
  2961. oldtheme = themesAll[c.appliedTheme] || {};
  2962. hasOldTheme = !$.isEmptyObject(oldtheme);
  2963. oldremove = hasOldTheme ? [ oldtheme.sortNone, oldtheme.sortDesc, oldtheme.sortAsc, oldtheme.active ].join( ' ' ) : '';
  2964. oldIconRmv = hasOldTheme ? [ oldtheme.iconSortNone, oldtheme.iconSortDesc, oldtheme.iconSortAsc ].join( ' ' ) : '';
  2965. if (hasOldTheme) {
  2966. wo.zebra[0] = $.trim( ' ' + wo.zebra[0].replace(' ' + oldtheme.even, '') );
  2967. wo.zebra[1] = $.trim( ' ' + wo.zebra[1].replace(' ' + oldtheme.odd, '') );
  2968. c.$tbodies.children().removeClass( [ oldtheme.even, oldtheme.odd ].join(' ') );
  2969. }
  2970. // update zebra stripes
  2971. if (themes.even) { wo.zebra[0] += ' ' + themes.even; }
  2972. if (themes.odd) { wo.zebra[1] += ' ' + themes.odd; }
  2973. // add caption style
  2974. $table.children('caption')
  2975. .removeClass(oldtheme.caption || '')
  2976. .addClass(themes.caption);
  2977. // add table/footer class names
  2978. $tfoot = $table
  2979. // remove other selected themes
  2980. .removeClass( (c.appliedTheme ? 'tablesorter-' + (c.appliedTheme || '') : '') + ' ' + (oldtheme.table || '') )
  2981. .addClass('tablesorter-' + theme + ' ' + (themes.table || '')) // add theme widget class name
  2982. .children('tfoot');
  2983. c.appliedTheme = c.theme;
  2984. if ($tfoot.length) {
  2985. $tfoot
  2986. // if oldtheme.footerRow or oldtheme.footerCells are undefined, all class names are removed
  2987. .children('tr').removeClass(oldtheme.footerRow || '').addClass(themes.footerRow)
  2988. .children('th, td').removeClass(oldtheme.footerCells || '').addClass(themes.footerCells);
  2989. }
  2990. // update header classes
  2991. $headers
  2992. .removeClass( (hasOldTheme ? [ oldtheme.header, oldtheme.hover, oldremove ].join(' ') : '') || '' )
  2993. .addClass(themes.header)
  2994. .not('.sorter-false')
  2995. .unbind('mouseenter.tsuitheme mouseleave.tsuitheme')
  2996. .bind('mouseenter.tsuitheme mouseleave.tsuitheme', function(event) {
  2997. // toggleClass with switch added in jQuery 1.3
  2998. $(this)[ event.type === 'mouseenter' ? 'addClass' : 'removeClass' ](themes.hover || '');
  2999. });
  3000. $headers.each(function() {
  3001. var $this = $(this);
  3002. if (!$this.find('.' + ts.css.wrapper).length) {
  3003. // Firefox needs this inner div to position the icon & resizer correctly
  3004. $this.wrapInner('<div class="' + ts.css.wrapper + '" style="position:relative;height:100%;width:100%"></div>');
  3005. }
  3006. });
  3007. if (c.cssIcon) {
  3008. // if c.cssIcon is '', then no <i> is added to the header
  3009. $headers
  3010. .find('.' + ts.css.icon)
  3011. .removeClass(hasOldTheme ? [ oldtheme.icons, oldIconRmv ].join(' ') : '')
  3012. .addClass(themes.icons || '');
  3013. }
  3014. // filter widget initializes after uitheme
  3015. if (ts.hasWidget( c.table, 'filter' )) {
  3016. tmp = function() {
  3017. $table.children('thead').children('.' + ts.css.filterRow)
  3018. .removeClass(hasOldTheme ? oldtheme.filterRow || '' : '')
  3019. .addClass(themes.filterRow || '');
  3020. };
  3021. if (wo.filter_initialized) {
  3022. tmp();
  3023. } else {
  3024. $table.one('filterInit', function() {
  3025. tmp();
  3026. });
  3027. }
  3028. }
  3029. }
  3030. for (i = 0; i < c.columns; i++) {
  3031. $header = c.$headers
  3032. .add($(c.namespace + '_extra_headers'))
  3033. .not('.sorter-false')
  3034. .filter('[data-column="' + i + '"]');
  3035. $icon = (ts.css.icon) ? $header.find('.' + ts.css.icon) : $();
  3036. $h = $headers.not('.sorter-false').filter('[data-column="' + i + '"]:last');
  3037. if ($h.length) {
  3038. $header.removeClass(remove);
  3039. $icon.removeClass(iconRmv);
  3040. if ($h[0].sortDisabled) {
  3041. // no sort arrows for disabled columns!
  3042. $icon.removeClass(themes.icons || '');
  3043. } else {
  3044. hdr = themes.sortNone;
  3045. icon = themes.iconSortNone;
  3046. if ($h.hasClass(ts.css.sortAsc)) {
  3047. hdr = [ themes.sortAsc, themes.active ].join(' ');
  3048. icon = themes.iconSortAsc;
  3049. } else if ($h.hasClass(ts.css.sortDesc)) {
  3050. hdr = [ themes.sortDesc, themes.active ].join(' ');
  3051. icon = themes.iconSortDesc;
  3052. }
  3053. $header.addClass(hdr);
  3054. $icon.addClass(icon || '');
  3055. }
  3056. }
  3057. }
  3058. if (debug) {
  3059. console.log('uitheme >> Applied ' + theme + ' theme' + ts.benchmark(time));
  3060. }
  3061. },
  3062. remove: function(table, c, wo, refreshing) {
  3063. if (!wo.uitheme_applied) { return; }
  3064. var $table = c.$table,
  3065. theme = c.appliedTheme || 'jui',
  3066. themes = ts.themes[ theme ] || ts.themes.jui,
  3067. $headers = $table.children('thead').children(),
  3068. remove = themes.sortNone + ' ' + themes.sortDesc + ' ' + themes.sortAsc,
  3069. iconRmv = themes.iconSortNone + ' ' + themes.iconSortDesc + ' ' + themes.iconSortAsc;
  3070. $table.removeClass('tablesorter-' + theme + ' ' + themes.table);
  3071. wo.uitheme_applied = false;
  3072. if (refreshing) { return; }
  3073. $table.find(ts.css.header).removeClass(themes.header);
  3074. $headers
  3075. .unbind('mouseenter.tsuitheme mouseleave.tsuitheme') // remove hover
  3076. .removeClass(themes.hover + ' ' + remove + ' ' + themes.active)
  3077. .filter('.' + ts.css.filterRow)
  3078. .removeClass(themes.filterRow);
  3079. $headers.find('.' + ts.css.icon).removeClass(themes.icons + ' ' + iconRmv);
  3080. }
  3081. });
  3082. })(jQuery);
  3083. /*! Widget: columns - updated 5/24/2017 (v2.28.11) */
  3084. ;(function ($) {
  3085. 'use strict';
  3086. var ts = $.tablesorter || {};
  3087. ts.addWidget({
  3088. id: 'columns',
  3089. priority: 65,
  3090. options : {
  3091. columns : [ 'primary', 'secondary', 'tertiary' ]
  3092. },
  3093. format: function(table, c, wo) {
  3094. var $tbody, tbodyIndex, $rows, rows, $row, $cells, remove, indx,
  3095. $table = c.$table,
  3096. $tbodies = c.$tbodies,
  3097. sortList = c.sortList,
  3098. len = sortList.length,
  3099. // removed c.widgetColumns support
  3100. css = wo && wo.columns || [ 'primary', 'secondary', 'tertiary' ],
  3101. last = css.length - 1;
  3102. remove = css.join(' ');
  3103. // check if there is a sort (on initialization there may not be one)
  3104. for (tbodyIndex = 0; tbodyIndex < $tbodies.length; tbodyIndex++ ) {
  3105. $tbody = ts.processTbody(table, $tbodies.eq(tbodyIndex), true); // detach tbody
  3106. $rows = $tbody.children('tr');
  3107. // loop through the visible rows
  3108. $rows.each(function() {
  3109. $row = $(this);
  3110. if (this.style.display !== 'none') {
  3111. // remove all columns class names
  3112. $cells = $row.children().removeClass(remove);
  3113. // add appropriate column class names
  3114. if (sortList && sortList[0]) {
  3115. // primary sort column class
  3116. $cells.eq(sortList[0][0]).addClass(css[0]);
  3117. if (len > 1) {
  3118. for (indx = 1; indx < len; indx++) {
  3119. // secondary, tertiary, etc sort column classes
  3120. $cells.eq(sortList[indx][0]).addClass( css[indx] || css[last] );
  3121. }
  3122. }
  3123. }
  3124. }
  3125. });
  3126. ts.processTbody(table, $tbody, false);
  3127. }
  3128. // add classes to thead and tfoot
  3129. rows = wo.columns_thead !== false ? [ 'thead tr' ] : [];
  3130. if (wo.columns_tfoot !== false) {
  3131. rows.push('tfoot tr');
  3132. }
  3133. if (rows.length) {
  3134. $rows = $table.find( rows.join(',') ).children().removeClass(remove);
  3135. if (len) {
  3136. for (indx = 0; indx < len; indx++) {
  3137. // add primary. secondary, tertiary, etc sort column classes
  3138. $rows.filter('[data-column="' + sortList[indx][0] + '"]').addClass(css[indx] || css[last]);
  3139. }
  3140. }
  3141. }
  3142. },
  3143. remove: function(table, c, wo) {
  3144. var tbodyIndex, $tbody,
  3145. $tbodies = c.$tbodies,
  3146. remove = (wo.columns || [ 'primary', 'secondary', 'tertiary' ]).join(' ');
  3147. c.$headers.removeClass(remove);
  3148. c.$table.children('tfoot').children('tr').children('th, td').removeClass(remove);
  3149. for (tbodyIndex = 0; tbodyIndex < $tbodies.length; tbodyIndex++ ) {
  3150. $tbody = ts.processTbody(table, $tbodies.eq(tbodyIndex), true); // remove tbody
  3151. $tbody.children('tr').each(function() {
  3152. $(this).children().removeClass(remove);
  3153. });
  3154. ts.processTbody(table, $tbody, false); // restore tbody
  3155. }
  3156. }
  3157. });
  3158. })(jQuery);
  3159. /*! Widget: filter - updated 2018-03-18 (v2.30.0) *//*
  3160. * Requires tablesorter v2.8+ and jQuery 1.7+
  3161. * by Rob Garrison
  3162. */
  3163. ;( function ( $ ) {
  3164. 'use strict';
  3165. var tsf, tsfRegex,
  3166. ts = $.tablesorter || {},
  3167. tscss = ts.css,
  3168. tskeyCodes = ts.keyCodes;
  3169. $.extend( tscss, {
  3170. filterRow : 'tablesorter-filter-row',
  3171. filter : 'tablesorter-filter',
  3172. filterDisabled : 'disabled',
  3173. filterRowHide : 'hideme'
  3174. });
  3175. $.extend( tskeyCodes, {
  3176. backSpace : 8,
  3177. escape : 27,
  3178. space : 32,
  3179. left : 37,
  3180. down : 40
  3181. });
  3182. ts.addWidget({
  3183. id: 'filter',
  3184. priority: 50,
  3185. options : {
  3186. filter_cellFilter : '', // css class name added to the filter cell ( string or array )
  3187. filter_childRows : false, // if true, filter includes child row content in the search
  3188. filter_childByColumn : false, // ( filter_childRows must be true ) if true = search child rows by column; false = search all child row text grouped
  3189. filter_childWithSibs : true, // if true, include matching child row siblings
  3190. filter_columnAnyMatch: true, // if true, allows using '#:{query}' in AnyMatch searches ( column:query )
  3191. filter_columnFilters : true, // if true, a filter will be added to the top of each table column
  3192. filter_cssFilter : '', // css class name added to the filter row & each input in the row ( tablesorter-filter is ALWAYS added )
  3193. filter_defaultAttrib : 'data-value', // data attribute in the header cell that contains the default filter value
  3194. filter_defaultFilter : {}, // add a default column filter type '~{query}' to make fuzzy searches default; '{q1} AND {q2}' to make all searches use a logical AND.
  3195. filter_excludeFilter : {}, // filters to exclude, per column
  3196. filter_external : '', // jQuery selector string ( or jQuery object ) of external filters
  3197. filter_filteredRow : 'filtered', // class added to filtered rows; define in css with "display:none" to hide the filtered-out rows
  3198. filter_filterLabel : 'Filter "{{label}}" column by...', // Aria-label added to filter input/select; see #1495
  3199. filter_formatter : null, // add custom filter elements to the filter row
  3200. filter_functions : null, // add custom filter functions using this option
  3201. filter_hideEmpty : true, // hide filter row when table is empty
  3202. filter_hideFilters : false, // collapse filter row when mouse leaves the area
  3203. filter_ignoreCase : true, // if true, make all searches case-insensitive
  3204. filter_liveSearch : true, // if true, search column content while the user types ( with a delay )
  3205. filter_matchType : { 'input': 'exact', 'select': 'exact' }, // global query settings ('exact' or 'match'); overridden by "filter-match" or "filter-exact" class
  3206. filter_onlyAvail : 'filter-onlyAvail', // a header with a select dropdown & this class name will only show available ( visible ) options within the drop down
  3207. filter_placeholder : { search : '', select : '' }, // default placeholder text ( overridden by any header 'data-placeholder' setting )
  3208. filter_reset : null, // jQuery selector string of an element used to reset the filters
  3209. filter_resetOnEsc : true, // Reset filter input when the user presses escape - normalized across browsers
  3210. filter_saveFilters : false, // Use the $.tablesorter.storage utility to save the most recent filters
  3211. filter_searchDelay : 300, // typing delay in milliseconds before starting a search
  3212. filter_searchFiltered: true, // allow searching through already filtered rows in special circumstances; will speed up searching in large tables if true
  3213. filter_selectSource : null, // include a function to return an array of values to be added to the column filter select
  3214. filter_selectSourceSeparator : '|', // filter_selectSource array text left of the separator is added to the option value, right into the option text
  3215. filter_serversideFiltering : false, // if true, must perform server-side filtering b/c client-side filtering is disabled, but the ui and events will still be used.
  3216. filter_startsWith : false, // if true, filter start from the beginning of the cell contents
  3217. filter_useParsedData : false // filter all data using parsed content
  3218. },
  3219. format: function( table, c, wo ) {
  3220. if ( !c.$table.hasClass( 'hasFilters' ) ) {
  3221. tsf.init( table, c, wo );
  3222. }
  3223. },
  3224. remove: function( table, c, wo, refreshing ) {
  3225. var tbodyIndex, $tbody,
  3226. $table = c.$table,
  3227. $tbodies = c.$tbodies,
  3228. events = (
  3229. 'addRows updateCell update updateRows updateComplete appendCache filterReset ' +
  3230. 'filterAndSortReset filterFomatterUpdate filterEnd search stickyHeadersInit '
  3231. ).split( ' ' ).join( c.namespace + 'filter ' );
  3232. $table
  3233. .removeClass( 'hasFilters' )
  3234. // add filter namespace to all BUT search
  3235. .unbind( events.replace( ts.regex.spaces, ' ' ) )
  3236. // remove the filter row even if refreshing, because the column might have been moved
  3237. .find( '.' + tscss.filterRow ).remove();
  3238. wo.filter_initialized = false;
  3239. if ( refreshing ) { return; }
  3240. for ( tbodyIndex = 0; tbodyIndex < $tbodies.length; tbodyIndex++ ) {
  3241. $tbody = ts.processTbody( table, $tbodies.eq( tbodyIndex ), true ); // remove tbody
  3242. $tbody.children().removeClass( wo.filter_filteredRow ).show();
  3243. ts.processTbody( table, $tbody, false ); // restore tbody
  3244. }
  3245. if ( wo.filter_reset ) {
  3246. $( document ).undelegate( wo.filter_reset, 'click' + c.namespace + 'filter' );
  3247. }
  3248. }
  3249. });
  3250. tsf = ts.filter = {
  3251. // regex used in filter 'check' functions - not for general use and not documented
  3252. regex: {
  3253. regex : /^\/((?:\\\/|[^\/])+)\/([migyu]{0,5})?$/, // regex to test for regex
  3254. child : /tablesorter-childRow/, // child row class name; this gets updated in the script
  3255. filtered : /filtered/, // filtered (hidden) row class name; updated in the script
  3256. type : /undefined|number/, // check type
  3257. exact : /(^[\"\'=]+)|([\"\'=]+$)/g, // exact match (allow '==')
  3258. operators : /[<>=]/g, // replace operators
  3259. query : '(q|query)', // replace filter queries
  3260. wild01 : /\?/g, // wild card match 0 or 1
  3261. wild0More : /\*/g, // wild care match 0 or more
  3262. quote : /\"/g,
  3263. isNeg1 : /(>=?\s*-\d)/,
  3264. isNeg2 : /(<=?\s*\d)/
  3265. },
  3266. // function( c, data ) { }
  3267. // c = table.config
  3268. // data.$row = jQuery object of the row currently being processed
  3269. // data.$cells = jQuery object of all cells within the current row
  3270. // data.filters = array of filters for all columns ( some may be undefined )
  3271. // data.filter = filter for the current column
  3272. // data.iFilter = same as data.filter, except lowercase ( if wo.filter_ignoreCase is true )
  3273. // data.exact = table cell text ( or parsed data if column parser enabled; may be a number & not a string )
  3274. // data.iExact = same as data.exact, except lowercase ( if wo.filter_ignoreCase is true; may be a number & not a string )
  3275. // data.cache = table cell text from cache, so it has been parsed ( & in all lower case if c.ignoreCase is true )
  3276. // data.cacheArray = An array of parsed content from each table cell in the row being processed
  3277. // data.index = column index; table = table element ( DOM )
  3278. // data.parsed = array ( by column ) of boolean values ( from filter_useParsedData or 'filter-parsed' class )
  3279. types: {
  3280. or : function( c, data, vars ) {
  3281. // look for "|", but not if it is inside of a regular expression
  3282. if ( ( tsfRegex.orTest.test( data.iFilter ) || tsfRegex.orSplit.test( data.filter ) ) &&
  3283. // this test for regex has potential to slow down the overall search
  3284. !tsfRegex.regex.test( data.filter ) ) {
  3285. var indx, filterMatched, query, regex,
  3286. // duplicate data but split filter
  3287. data2 = $.extend( {}, data ),
  3288. filter = data.filter.split( tsfRegex.orSplit ),
  3289. iFilter = data.iFilter.split( tsfRegex.orSplit ),
  3290. len = filter.length;
  3291. for ( indx = 0; indx < len; indx++ ) {
  3292. data2.nestedFilters = true;
  3293. data2.filter = '' + ( tsf.parseFilter( c, filter[ indx ], data ) || '' );
  3294. data2.iFilter = '' + ( tsf.parseFilter( c, iFilter[ indx ], data ) || '' );
  3295. query = '(' + ( tsf.parseFilter( c, data2.filter, data ) || '' ) + ')';
  3296. try {
  3297. // use try/catch, because query may not be a valid regex if "|" is contained within a partial regex search,
  3298. // e.g "/(Alex|Aar" -> Uncaught SyntaxError: Invalid regular expression: /(/(Alex)/: Unterminated group
  3299. regex = new RegExp( data.isMatch ? query : '^' + query + '$', c.widgetOptions.filter_ignoreCase ? 'i' : '' );
  3300. // filterMatched = data2.filter === '' && indx > 0 ? true
  3301. // look for an exact match with the 'or' unless the 'filter-match' class is found
  3302. filterMatched = regex.test( data2.exact ) || tsf.processTypes( c, data2, vars );
  3303. if ( filterMatched ) {
  3304. return filterMatched;
  3305. }
  3306. } catch ( error ) {
  3307. return null;
  3308. }
  3309. }
  3310. // may be null from processing types
  3311. return filterMatched || false;
  3312. }
  3313. return null;
  3314. },
  3315. // Look for an AND or && operator ( logical and )
  3316. and : function( c, data, vars ) {
  3317. if ( tsfRegex.andTest.test( data.filter ) ) {
  3318. var indx, filterMatched, result, query, regex,
  3319. // duplicate data but split filter
  3320. data2 = $.extend( {}, data ),
  3321. filter = data.filter.split( tsfRegex.andSplit ),
  3322. iFilter = data.iFilter.split( tsfRegex.andSplit ),
  3323. len = filter.length;
  3324. for ( indx = 0; indx < len; indx++ ) {
  3325. data2.nestedFilters = true;
  3326. data2.filter = '' + ( tsf.parseFilter( c, filter[ indx ], data ) || '' );
  3327. data2.iFilter = '' + ( tsf.parseFilter( c, iFilter[ indx ], data ) || '' );
  3328. query = ( '(' + ( tsf.parseFilter( c, data2.filter, data ) || '' ) + ')' )
  3329. // replace wild cards since /(a*)/i will match anything
  3330. .replace( tsfRegex.wild01, '\\S{1}' ).replace( tsfRegex.wild0More, '\\S*' );
  3331. try {
  3332. // use try/catch just in case RegExp is invalid
  3333. regex = new RegExp( data.isMatch ? query : '^' + query + '$', c.widgetOptions.filter_ignoreCase ? 'i' : '' );
  3334. // look for an exact match with the 'and' unless the 'filter-match' class is found
  3335. result = ( regex.test( data2.exact ) || tsf.processTypes( c, data2, vars ) );
  3336. if ( indx === 0 ) {
  3337. filterMatched = result;
  3338. } else {
  3339. filterMatched = filterMatched && result;
  3340. }
  3341. } catch ( error ) {
  3342. return null;
  3343. }
  3344. }
  3345. // may be null from processing types
  3346. return filterMatched || false;
  3347. }
  3348. return null;
  3349. },
  3350. // Look for regex
  3351. regex: function( c, data ) {
  3352. if ( tsfRegex.regex.test( data.filter ) ) {
  3353. var matches,
  3354. // cache regex per column for optimal speed
  3355. regex = data.filter_regexCache[ data.index ] || tsfRegex.regex.exec( data.filter ),
  3356. isRegex = regex instanceof RegExp;
  3357. try {
  3358. if ( !isRegex ) {
  3359. // force case insensitive search if ignoreCase option set?
  3360. // if ( c.ignoreCase && !regex[2] ) { regex[2] = 'i'; }
  3361. data.filter_regexCache[ data.index ] = regex = new RegExp( regex[1], regex[2] );
  3362. }
  3363. matches = regex.test( data.exact );
  3364. } catch ( error ) {
  3365. matches = false;
  3366. }
  3367. return matches;
  3368. }
  3369. return null;
  3370. },
  3371. // Look for operators >, >=, < or <=
  3372. operators: function( c, data ) {
  3373. // ignore empty strings... because '' < 10 is true
  3374. if ( tsfRegex.operTest.test( data.iFilter ) && data.iExact !== '' ) {
  3375. var cachedValue, result, txt,
  3376. table = c.table,
  3377. parsed = data.parsed[ data.index ],
  3378. query = ts.formatFloat( data.iFilter.replace( tsfRegex.operators, '' ), table ),
  3379. parser = c.parsers[ data.index ] || {},
  3380. savedSearch = query;
  3381. // parse filter value in case we're comparing numbers ( dates )
  3382. if ( parsed || parser.type === 'numeric' ) {
  3383. txt = $.trim( '' + data.iFilter.replace( tsfRegex.operators, '' ) );
  3384. result = tsf.parseFilter( c, txt, data, true );
  3385. query = ( typeof result === 'number' && result !== '' && !isNaN( result ) ) ? result : query;
  3386. }
  3387. // iExact may be numeric - see issue #149;
  3388. // check if cached is defined, because sometimes j goes out of range? ( numeric columns )
  3389. if ( ( parsed || parser.type === 'numeric' ) && !isNaN( query ) &&
  3390. typeof data.cache !== 'undefined' ) {
  3391. cachedValue = data.cache;
  3392. } else {
  3393. txt = isNaN( data.iExact ) ? data.iExact.replace( ts.regex.nondigit, '' ) : data.iExact;
  3394. cachedValue = ts.formatFloat( txt, table );
  3395. }
  3396. if ( tsfRegex.gtTest.test( data.iFilter ) ) {
  3397. result = tsfRegex.gteTest.test( data.iFilter ) ? cachedValue >= query : cachedValue > query;
  3398. } else if ( tsfRegex.ltTest.test( data.iFilter ) ) {
  3399. result = tsfRegex.lteTest.test( data.iFilter ) ? cachedValue <= query : cachedValue < query;
  3400. }
  3401. // keep showing all rows if nothing follows the operator
  3402. if ( !result && savedSearch === '' ) {
  3403. result = true;
  3404. }
  3405. return result;
  3406. }
  3407. return null;
  3408. },
  3409. // Look for a not match
  3410. notMatch: function( c, data ) {
  3411. if ( tsfRegex.notTest.test( data.iFilter ) ) {
  3412. var indx,
  3413. txt = data.iFilter.replace( '!', '' ),
  3414. filter = tsf.parseFilter( c, txt, data ) || '';
  3415. if ( tsfRegex.exact.test( filter ) ) {
  3416. // look for exact not matches - see #628
  3417. filter = filter.replace( tsfRegex.exact, '' );
  3418. return filter === '' ? true : $.trim( filter ) !== data.iExact;
  3419. } else {
  3420. indx = data.iExact.search( $.trim( filter ) );
  3421. return filter === '' ? true :
  3422. // return true if not found
  3423. data.anyMatch ? indx < 0 :
  3424. // return false if found
  3425. !( c.widgetOptions.filter_startsWith ? indx === 0 : indx >= 0 );
  3426. }
  3427. }
  3428. return null;
  3429. },
  3430. // Look for quotes or equals to get an exact match; ignore type since iExact could be numeric
  3431. exact: function( c, data ) {
  3432. /*jshint eqeqeq:false */
  3433. if ( tsfRegex.exact.test( data.iFilter ) ) {
  3434. var txt = data.iFilter.replace( tsfRegex.exact, '' ),
  3435. filter = tsf.parseFilter( c, txt, data ) || '';
  3436. // eslint-disable-next-line eqeqeq
  3437. return data.anyMatch ? $.inArray( filter, data.rowArray ) >= 0 : filter == data.iExact;
  3438. }
  3439. return null;
  3440. },
  3441. // Look for a range ( using ' to ' or ' - ' ) - see issue #166; thanks matzhu!
  3442. range : function( c, data ) {
  3443. if ( tsfRegex.toTest.test( data.iFilter ) ) {
  3444. var result, tmp, range1, range2,
  3445. table = c.table,
  3446. index = data.index,
  3447. parsed = data.parsed[index],
  3448. // make sure the dash is for a range and not indicating a negative number
  3449. query = data.iFilter.split( tsfRegex.toSplit );
  3450. tmp = query[0].replace( ts.regex.nondigit, '' ) || '';
  3451. range1 = ts.formatFloat( tsf.parseFilter( c, tmp, data ), table );
  3452. tmp = query[1].replace( ts.regex.nondigit, '' ) || '';
  3453. range2 = ts.formatFloat( tsf.parseFilter( c, tmp, data ), table );
  3454. // parse filter value in case we're comparing numbers ( dates )
  3455. if ( parsed || c.parsers[ index ].type === 'numeric' ) {
  3456. result = c.parsers[ index ].format( '' + query[0], table, c.$headers.eq( index ), index );
  3457. range1 = ( result !== '' && !isNaN( result ) ) ? result : range1;
  3458. result = c.parsers[ index ].format( '' + query[1], table, c.$headers.eq( index ), index );
  3459. range2 = ( result !== '' && !isNaN( result ) ) ? result : range2;
  3460. }
  3461. if ( ( parsed || c.parsers[ index ].type === 'numeric' ) && !isNaN( range1 ) && !isNaN( range2 ) ) {
  3462. result = data.cache;
  3463. } else {
  3464. tmp = isNaN( data.iExact ) ? data.iExact.replace( ts.regex.nondigit, '' ) : data.iExact;
  3465. result = ts.formatFloat( tmp, table );
  3466. }
  3467. if ( range1 > range2 ) {
  3468. tmp = range1; range1 = range2; range2 = tmp; // swap
  3469. }
  3470. return ( result >= range1 && result <= range2 ) || ( range1 === '' || range2 === '' );
  3471. }
  3472. return null;
  3473. },
  3474. // Look for wild card: ? = single, * = multiple, or | = logical OR
  3475. wild : function( c, data ) {
  3476. if ( tsfRegex.wildOrTest.test( data.iFilter ) ) {
  3477. var query = '' + ( tsf.parseFilter( c, data.iFilter, data ) || '' );
  3478. // look for an exact match with the 'or' unless the 'filter-match' class is found
  3479. if ( !tsfRegex.wildTest.test( query ) && data.nestedFilters ) {
  3480. query = data.isMatch ? query : '^(' + query + ')$';
  3481. }
  3482. // parsing the filter may not work properly when using wildcards =/
  3483. try {
  3484. return new RegExp(
  3485. query.replace( tsfRegex.wild01, '\\S{1}' ).replace( tsfRegex.wild0More, '\\S*' ),
  3486. c.widgetOptions.filter_ignoreCase ? 'i' : ''
  3487. )
  3488. .test( data.exact );
  3489. } catch ( error ) {
  3490. return null;
  3491. }
  3492. }
  3493. return null;
  3494. },
  3495. // fuzzy text search; modified from https://github.com/mattyork/fuzzy ( MIT license )
  3496. fuzzy: function( c, data ) {
  3497. if ( tsfRegex.fuzzyTest.test( data.iFilter ) ) {
  3498. var indx,
  3499. patternIndx = 0,
  3500. len = data.iExact.length,
  3501. txt = data.iFilter.slice( 1 ),
  3502. pattern = tsf.parseFilter( c, txt, data ) || '';
  3503. for ( indx = 0; indx < len; indx++ ) {
  3504. if ( data.iExact[ indx ] === pattern[ patternIndx ] ) {
  3505. patternIndx += 1;
  3506. }
  3507. }
  3508. return patternIndx === pattern.length;
  3509. }
  3510. return null;
  3511. }
  3512. },
  3513. init: function( table ) {
  3514. // filter language options
  3515. ts.language = $.extend( true, {}, {
  3516. to : 'to',
  3517. or : 'or',
  3518. and : 'and'
  3519. }, ts.language );
  3520. var options, string, txt, $header, column, val, fxn, noSelect,
  3521. c = table.config,
  3522. wo = c.widgetOptions,
  3523. processStr = function(prefix, str, suffix) {
  3524. str = str.trim();
  3525. // don't include prefix/suffix if str is empty
  3526. return str === '' ? '' : (prefix || '') + str + (suffix || '');
  3527. };
  3528. c.$table.addClass( 'hasFilters' );
  3529. c.lastSearch = [];
  3530. // define timers so using clearTimeout won't cause an undefined error
  3531. wo.filter_searchTimer = null;
  3532. wo.filter_initTimer = null;
  3533. wo.filter_formatterCount = 0;
  3534. wo.filter_formatterInit = [];
  3535. wo.filter_anyColumnSelector = '[data-column="all"],[data-column="any"]';
  3536. wo.filter_multipleColumnSelector = '[data-column*="-"],[data-column*=","]';
  3537. val = '\\{' + tsfRegex.query + '\\}';
  3538. $.extend( tsfRegex, {
  3539. child : new RegExp( c.cssChildRow ),
  3540. filtered : new RegExp( wo.filter_filteredRow ),
  3541. alreadyFiltered : new RegExp( '(\\s+(-' + processStr('|', ts.language.or) + processStr('|', ts.language.to) + ')\\s+)', 'i' ),
  3542. toTest : new RegExp( '\\s+(-' + processStr('|', ts.language.to) + ')\\s+', 'i' ),
  3543. toSplit : new RegExp( '(?:\\s+(?:-' + processStr('|', ts.language.to) + ')\\s+)', 'gi' ),
  3544. andTest : new RegExp( '\\s+(' + processStr('', ts.language.and, '|') + '&&)\\s+', 'i' ),
  3545. andSplit : new RegExp( '(?:\\s+(?:' + processStr('', ts.language.and, '|') + '&&)\\s+)', 'gi' ),
  3546. orTest : new RegExp( '(\\|' + processStr('|\\s+', ts.language.or, '\\s+') + ')', 'i' ),
  3547. orSplit : new RegExp( '(?:\\|' + processStr('|\\s+(?:', ts.language.or, ')\\s+') + ')', 'gi' ),
  3548. iQuery : new RegExp( val, 'i' ),
  3549. igQuery : new RegExp( val, 'ig' ),
  3550. operTest : /^[<>]=?/,
  3551. gtTest : />/,
  3552. gteTest : />=/,
  3553. ltTest : /</,
  3554. lteTest : /<=/,
  3555. notTest : /^\!/,
  3556. wildOrTest : /[\?\*\|]/,
  3557. wildTest : /\?\*/,
  3558. fuzzyTest : /^~/,
  3559. exactTest : /[=\"\|!]/
  3560. });
  3561. // don't build filter row if columnFilters is false or all columns are set to 'filter-false'
  3562. // see issue #156
  3563. val = c.$headers.filter( '.filter-false, .parser-false' ).length;
  3564. if ( wo.filter_columnFilters !== false && val !== c.$headers.length ) {
  3565. // build filter row
  3566. tsf.buildRow( table, c, wo );
  3567. }
  3568. txt = 'addRows updateCell update updateRows updateComplete appendCache filterReset ' +
  3569. 'filterAndSortReset filterResetSaved filterEnd search '.split( ' ' ).join( c.namespace + 'filter ' );
  3570. c.$table.bind( txt, function( event, filter ) {
  3571. val = wo.filter_hideEmpty &&
  3572. $.isEmptyObject( c.cache ) &&
  3573. !( c.delayInit && event.type === 'appendCache' );
  3574. // hide filter row using the 'filtered' class name
  3575. c.$table.find( '.' + tscss.filterRow ).toggleClass( wo.filter_filteredRow, val ); // fixes #450
  3576. if ( !/(search|filter)/.test( event.type ) ) {
  3577. event.stopPropagation();
  3578. tsf.buildDefault( table, true );
  3579. }
  3580. // Add filterAndSortReset - see #1361
  3581. if ( event.type === 'filterReset' || event.type === 'filterAndSortReset' ) {
  3582. c.$table.find( '.' + tscss.filter ).add( wo.filter_$externalFilters ).val( '' );
  3583. if ( event.type === 'filterAndSortReset' ) {
  3584. ts.sortReset( this.config, function() {
  3585. tsf.searching( table, [] );
  3586. });
  3587. } else {
  3588. tsf.searching( table, [] );
  3589. }
  3590. } else if ( event.type === 'filterResetSaved' ) {
  3591. ts.storage( table, 'tablesorter-filters', '' );
  3592. } else if ( event.type === 'filterEnd' ) {
  3593. tsf.buildDefault( table, true );
  3594. } else {
  3595. // send false argument to force a new search; otherwise if the filter hasn't changed,
  3596. // it will return
  3597. filter = event.type === 'search' ? filter :
  3598. event.type === 'updateComplete' ? c.$table.data( 'lastSearch' ) : '';
  3599. if ( /(update|add)/.test( event.type ) && event.type !== 'updateComplete' ) {
  3600. // force a new search since content has changed
  3601. c.lastCombinedFilter = null;
  3602. c.lastSearch = [];
  3603. // update filterFormatters after update (& small delay) - Fixes #1237
  3604. setTimeout(function() {
  3605. c.$table.triggerHandler( 'filterFomatterUpdate' );
  3606. }, 100);
  3607. }
  3608. // pass true ( skipFirst ) to prevent the tablesorter.setFilters function from skipping the first
  3609. // input ensures all inputs are updated when a search is triggered on the table
  3610. // $( 'table' ).trigger( 'search', [...] );
  3611. tsf.searching( table, filter, true );
  3612. }
  3613. return false;
  3614. });
  3615. // reset button/link
  3616. if ( wo.filter_reset ) {
  3617. if ( wo.filter_reset instanceof $ ) {
  3618. // reset contains a jQuery object, bind to it
  3619. wo.filter_reset.click( function() {
  3620. c.$table.triggerHandler( 'filterReset' );
  3621. });
  3622. } else if ( $( wo.filter_reset ).length ) {
  3623. // reset is a jQuery selector, use event delegation
  3624. $( document )
  3625. .undelegate( wo.filter_reset, 'click' + c.namespace + 'filter' )
  3626. .delegate( wo.filter_reset, 'click' + c.namespace + 'filter', function() {
  3627. // trigger a reset event, so other functions ( filter_formatter ) know when to reset
  3628. c.$table.triggerHandler( 'filterReset' );
  3629. });
  3630. }
  3631. }
  3632. if ( wo.filter_functions ) {
  3633. for ( column = 0; column < c.columns; column++ ) {
  3634. fxn = ts.getColumnData( table, wo.filter_functions, column );
  3635. if ( fxn ) {
  3636. // remove 'filter-select' from header otherwise the options added here are replaced with
  3637. // all options
  3638. $header = c.$headerIndexed[ column ].removeClass( 'filter-select' );
  3639. // don't build select if 'filter-false' or 'parser-false' set
  3640. noSelect = !( $header.hasClass( 'filter-false' ) || $header.hasClass( 'parser-false' ) );
  3641. options = '';
  3642. if ( fxn === true && noSelect ) {
  3643. tsf.buildSelect( table, column );
  3644. } else if ( typeof fxn === 'object' && noSelect ) {
  3645. // add custom drop down list
  3646. for ( string in fxn ) {
  3647. if ( typeof string === 'string' ) {
  3648. options += options === '' ?
  3649. '<option value="">' +
  3650. ( $header.data( 'placeholder' ) ||
  3651. $header.attr( 'data-placeholder' ) ||
  3652. wo.filter_placeholder.select ||
  3653. ''
  3654. ) +
  3655. '</option>' : '';
  3656. val = string;
  3657. txt = string;
  3658. if ( string.indexOf( wo.filter_selectSourceSeparator ) >= 0 ) {
  3659. val = string.split( wo.filter_selectSourceSeparator );
  3660. txt = val[1];
  3661. val = val[0];
  3662. }
  3663. options += '<option ' +
  3664. ( txt === val ? '' : 'data-function-name="' + string + '" ' ) +
  3665. 'value="' + val + '">' + txt + '</option>';
  3666. }
  3667. }
  3668. c.$table
  3669. .find( 'thead' )
  3670. .find( 'select.' + tscss.filter + '[data-column="' + column + '"]' )
  3671. .append( options );
  3672. txt = wo.filter_selectSource;
  3673. fxn = typeof txt === 'function' ? true : ts.getColumnData( table, txt, column );
  3674. if ( fxn ) {
  3675. // updating so the extra options are appended
  3676. tsf.buildSelect( c.table, column, '', true, $header.hasClass( wo.filter_onlyAvail ) );
  3677. }
  3678. }
  3679. }
  3680. }
  3681. }
  3682. // not really updating, but if the column has both the 'filter-select' class &
  3683. // filter_functions set to true, it would append the same options twice.
  3684. tsf.buildDefault( table, true );
  3685. tsf.bindSearch( table, c.$table.find( '.' + tscss.filter ), true );
  3686. if ( wo.filter_external ) {
  3687. tsf.bindSearch( table, wo.filter_external );
  3688. }
  3689. if ( wo.filter_hideFilters ) {
  3690. tsf.hideFilters( c );
  3691. }
  3692. // show processing icon
  3693. if ( c.showProcessing ) {
  3694. txt = 'filterStart filterEnd '.split( ' ' ).join( c.namespace + 'filter-sp ' );
  3695. c.$table
  3696. .unbind( txt.replace( ts.regex.spaces, ' ' ) )
  3697. .bind( txt, function( event, columns ) {
  3698. // only add processing to certain columns to all columns
  3699. $header = ( columns ) ?
  3700. c.$table
  3701. .find( '.' + tscss.header )
  3702. .filter( '[data-column]' )
  3703. .filter( function() {
  3704. return columns[ $( this ).data( 'column' ) ] !== '';
  3705. }) : '';
  3706. ts.isProcessing( table, event.type === 'filterStart', columns ? $header : '' );
  3707. });
  3708. }
  3709. // set filtered rows count ( intially unfiltered )
  3710. c.filteredRows = c.totalRows;
  3711. // add default values
  3712. txt = 'tablesorter-initialized pagerBeforeInitialized '.split( ' ' ).join( c.namespace + 'filter ' );
  3713. c.$table
  3714. .unbind( txt.replace( ts.regex.spaces, ' ' ) )
  3715. .bind( txt, function() {
  3716. tsf.completeInit( this );
  3717. });
  3718. // if filter widget is added after pager has initialized; then set filter init flag
  3719. if ( c.pager && c.pager.initialized && !wo.filter_initialized ) {
  3720. c.$table.triggerHandler( 'filterFomatterUpdate' );
  3721. setTimeout( function() {
  3722. tsf.filterInitComplete( c );
  3723. }, 100 );
  3724. } else if ( !wo.filter_initialized ) {
  3725. tsf.completeInit( table );
  3726. }
  3727. },
  3728. completeInit: function( table ) {
  3729. // redefine 'c' & 'wo' so they update properly inside this callback
  3730. var c = table.config,
  3731. wo = c.widgetOptions,
  3732. filters = tsf.setDefaults( table, c, wo ) || [];
  3733. if ( filters.length ) {
  3734. // prevent delayInit from triggering a cache build if filters are empty
  3735. if ( !( c.delayInit && filters.join( '' ) === '' ) ) {
  3736. ts.setFilters( table, filters, true );
  3737. }
  3738. }
  3739. c.$table.triggerHandler( 'filterFomatterUpdate' );
  3740. // trigger init after setTimeout to prevent multiple filterStart/End/Init triggers
  3741. setTimeout( function() {
  3742. if ( !wo.filter_initialized ) {
  3743. tsf.filterInitComplete( c );
  3744. }
  3745. }, 100 );
  3746. },
  3747. // $cell parameter, but not the config, is passed to the filter_formatters,
  3748. // so we have to work with it instead
  3749. formatterUpdated: function( $cell, column ) {
  3750. // prevent error if $cell is undefined - see #1056
  3751. var $table = $cell && $cell.closest( 'table' );
  3752. var config = $table.length && $table[0].config,
  3753. wo = config && config.widgetOptions;
  3754. if ( wo && !wo.filter_initialized ) {
  3755. // add updates by column since this function
  3756. // may be called numerous times before initialization
  3757. wo.filter_formatterInit[ column ] = 1;
  3758. }
  3759. },
  3760. filterInitComplete: function( c ) {
  3761. var indx, len,
  3762. wo = c.widgetOptions,
  3763. count = 0,
  3764. completed = function() {
  3765. wo.filter_initialized = true;
  3766. // update lastSearch - it gets cleared often
  3767. c.lastSearch = c.$table.data( 'lastSearch' );
  3768. c.$table.triggerHandler( 'filterInit', c );
  3769. tsf.findRows( c.table, c.lastSearch || [] );
  3770. if (ts.debug(c, 'filter')) {
  3771. console.log('Filter >> Widget initialized');
  3772. }
  3773. };
  3774. if ( $.isEmptyObject( wo.filter_formatter ) ) {
  3775. completed();
  3776. } else {
  3777. len = wo.filter_formatterInit.length;
  3778. for ( indx = 0; indx < len; indx++ ) {
  3779. if ( wo.filter_formatterInit[ indx ] === 1 ) {
  3780. count++;
  3781. }
  3782. }
  3783. clearTimeout( wo.filter_initTimer );
  3784. if ( !wo.filter_initialized && count === wo.filter_formatterCount ) {
  3785. // filter widget initialized
  3786. completed();
  3787. } else if ( !wo.filter_initialized ) {
  3788. // fall back in case a filter_formatter doesn't call
  3789. // $.tablesorter.filter.formatterUpdated( $cell, column ), and the count is off
  3790. wo.filter_initTimer = setTimeout( function() {
  3791. completed();
  3792. }, 500 );
  3793. }
  3794. }
  3795. },
  3796. // encode or decode filters for storage; see #1026
  3797. processFilters: function( filters, encode ) {
  3798. var indx,
  3799. // fixes #1237; previously returning an encoded "filters" value
  3800. result = [],
  3801. mode = encode ? encodeURIComponent : decodeURIComponent,
  3802. len = filters.length;
  3803. for ( indx = 0; indx < len; indx++ ) {
  3804. if ( filters[ indx ] ) {
  3805. result[ indx ] = mode( filters[ indx ] );
  3806. }
  3807. }
  3808. return result;
  3809. },
  3810. setDefaults: function( table, c, wo ) {
  3811. var isArray, saved, indx, col, $filters,
  3812. // get current ( default ) filters
  3813. filters = ts.getFilters( table ) || [];
  3814. if ( wo.filter_saveFilters && ts.storage ) {
  3815. saved = ts.storage( table, 'tablesorter-filters' ) || [];
  3816. isArray = $.isArray( saved );
  3817. // make sure we're not just getting an empty array
  3818. if ( !( isArray && saved.join( '' ) === '' || !isArray ) ) {
  3819. filters = tsf.processFilters( saved );
  3820. }
  3821. }
  3822. // if no filters saved, then check default settings
  3823. if ( filters.join( '' ) === '' ) {
  3824. // allow adding default setting to external filters
  3825. $filters = c.$headers.add( wo.filter_$externalFilters )
  3826. .filter( '[' + wo.filter_defaultAttrib + ']' );
  3827. for ( indx = 0; indx <= c.columns; indx++ ) {
  3828. // include data-column='all' external filters
  3829. col = indx === c.columns ? 'all' : indx;
  3830. filters[ indx ] = $filters
  3831. .filter( '[data-column="' + col + '"]' )
  3832. .attr( wo.filter_defaultAttrib ) || filters[indx] || '';
  3833. }
  3834. }
  3835. c.$table.data( 'lastSearch', filters );
  3836. return filters;
  3837. },
  3838. parseFilter: function( c, filter, data, parsed ) {
  3839. return parsed || data.parsed[ data.index ] ?
  3840. c.parsers[ data.index ].format( filter, c.table, [], data.index ) :
  3841. filter;
  3842. },
  3843. buildRow: function( table, c, wo ) {
  3844. var $filter, col, column, $header, makeSelect, disabled, name, ffxn, tmp,
  3845. // c.columns defined in computeThIndexes()
  3846. cellFilter = wo.filter_cellFilter,
  3847. columns = c.columns,
  3848. arry = $.isArray( cellFilter ),
  3849. buildFilter = '<tr role="search" class="' + tscss.filterRow + ' ' + c.cssIgnoreRow + '">';
  3850. for ( column = 0; column < columns; column++ ) {
  3851. if ( c.$headerIndexed[ column ].length ) {
  3852. // account for entire column set with colspan. See #1047
  3853. tmp = c.$headerIndexed[ column ] && c.$headerIndexed[ column ][0].colSpan || 0;
  3854. if ( tmp > 1 ) {
  3855. buildFilter += '<td data-column="' + column + '-' + ( column + tmp - 1 ) + '" colspan="' + tmp + '"';
  3856. } else {
  3857. buildFilter += '<td data-column="' + column + '"';
  3858. }
  3859. if ( arry ) {
  3860. buildFilter += ( cellFilter[ column ] ? ' class="' + cellFilter[ column ] + '"' : '' );
  3861. } else {
  3862. buildFilter += ( cellFilter !== '' ? ' class="' + cellFilter + '"' : '' );
  3863. }
  3864. buildFilter += '></td>';
  3865. }
  3866. }
  3867. c.$filters = $( buildFilter += '</tr>' )
  3868. .appendTo( c.$table.children( 'thead' ).eq( 0 ) )
  3869. .children( 'td' );
  3870. // build each filter input
  3871. for ( column = 0; column < columns; column++ ) {
  3872. disabled = false;
  3873. // assuming last cell of a column is the main column
  3874. $header = c.$headerIndexed[ column ];
  3875. if ( $header && $header.length ) {
  3876. // $filter = c.$filters.filter( '[data-column="' + column + '"]' );
  3877. $filter = tsf.getColumnElm( c, c.$filters, column );
  3878. ffxn = ts.getColumnData( table, wo.filter_functions, column );
  3879. makeSelect = ( wo.filter_functions && ffxn && typeof ffxn !== 'function' ) ||
  3880. $header.hasClass( 'filter-select' );
  3881. // get data from jQuery data, metadata, headers option or header class name
  3882. col = ts.getColumnData( table, c.headers, column );
  3883. disabled = ts.getData( $header[0], col, 'filter' ) === 'false' ||
  3884. ts.getData( $header[0], col, 'parser' ) === 'false';
  3885. if ( makeSelect ) {
  3886. buildFilter = $( '<select>' ).appendTo( $filter );
  3887. } else {
  3888. ffxn = ts.getColumnData( table, wo.filter_formatter, column );
  3889. if ( ffxn ) {
  3890. wo.filter_formatterCount++;
  3891. buildFilter = ffxn( $filter, column );
  3892. // no element returned, so lets go find it
  3893. if ( buildFilter && buildFilter.length === 0 ) {
  3894. buildFilter = $filter.children( 'input' );
  3895. }
  3896. // element not in DOM, so lets attach it
  3897. if ( buildFilter && ( buildFilter.parent().length === 0 ||
  3898. ( buildFilter.parent().length && buildFilter.parent()[0] !== $filter[0] ) ) ) {
  3899. $filter.append( buildFilter );
  3900. }
  3901. } else {
  3902. buildFilter = $( '<input type="search">' ).appendTo( $filter );
  3903. }
  3904. if ( buildFilter ) {
  3905. tmp = $header.data( 'placeholder' ) ||
  3906. $header.attr( 'data-placeholder' ) ||
  3907. wo.filter_placeholder.search || '';
  3908. buildFilter.attr( 'placeholder', tmp );
  3909. }
  3910. }
  3911. if ( buildFilter ) {
  3912. // add filter class name
  3913. name = ( $.isArray( wo.filter_cssFilter ) ?
  3914. ( typeof wo.filter_cssFilter[column] !== 'undefined' ? wo.filter_cssFilter[column] || '' : '' ) :
  3915. wo.filter_cssFilter ) || '';
  3916. // copy data-column from table cell (it will include colspan)
  3917. buildFilter.addClass( tscss.filter + ' ' + name );
  3918. name = wo.filter_filterLabel;
  3919. tmp = name.match(/{{([^}]+?)}}/g);
  3920. if (!tmp) {
  3921. tmp = [ '{{label}}' ];
  3922. }
  3923. $.each(tmp, function(indx, attr) {
  3924. var regex = new RegExp(attr, 'g'),
  3925. data = $header.attr('data-' + attr.replace(/{{|}}/g, '')),
  3926. text = typeof data === 'undefined' ? $header.text() : data;
  3927. name = name.replace( regex, $.trim( text ) );
  3928. });
  3929. buildFilter.attr({
  3930. 'data-column': $filter.attr( 'data-column' ),
  3931. 'aria-label': name
  3932. });
  3933. if ( disabled ) {
  3934. buildFilter.attr( 'placeholder', '' ).addClass( tscss.filterDisabled )[0].disabled = true;
  3935. }
  3936. }
  3937. }
  3938. }
  3939. },
  3940. bindSearch: function( table, $el, internal ) {
  3941. table = $( table )[0];
  3942. $el = $( $el ); // allow passing a selector string
  3943. if ( !$el.length ) { return; }
  3944. var tmp,
  3945. c = table.config,
  3946. wo = c.widgetOptions,
  3947. namespace = c.namespace + 'filter',
  3948. $ext = wo.filter_$externalFilters;
  3949. if ( internal !== true ) {
  3950. // save anyMatch element
  3951. tmp = wo.filter_anyColumnSelector + ',' + wo.filter_multipleColumnSelector;
  3952. wo.filter_$anyMatch = $el.filter( tmp );
  3953. if ( $ext && $ext.length ) {
  3954. wo.filter_$externalFilters = wo.filter_$externalFilters.add( $el );
  3955. } else {
  3956. wo.filter_$externalFilters = $el;
  3957. }
  3958. // update values ( external filters added after table initialization )
  3959. ts.setFilters( table, c.$table.data( 'lastSearch' ) || [], internal === false );
  3960. }
  3961. // unbind events
  3962. tmp = ( 'keypress keyup keydown search change input '.split( ' ' ).join( namespace + ' ' ) );
  3963. $el
  3964. // use data attribute instead of jQuery data since the head is cloned without including
  3965. // the data/binding
  3966. .attr( 'data-lastSearchTime', new Date().getTime() )
  3967. .unbind( tmp.replace( ts.regex.spaces, ' ' ) )
  3968. .bind( 'keydown' + namespace, function( event ) {
  3969. if ( event.which === tskeyCodes.escape && !table.config.widgetOptions.filter_resetOnEsc ) {
  3970. // prevent keypress event
  3971. return false;
  3972. }
  3973. })
  3974. .bind( 'keyup' + namespace, function( event ) {
  3975. wo = table.config.widgetOptions; // make sure "wo" isn't cached
  3976. var column = parseInt( $( this ).attr( 'data-column' ), 10 ),
  3977. liveSearch = typeof wo.filter_liveSearch === 'boolean' ? wo.filter_liveSearch :
  3978. ts.getColumnData( table, wo.filter_liveSearch, column );
  3979. if ( typeof liveSearch === 'undefined' ) {
  3980. liveSearch = wo.filter_liveSearch.fallback || false;
  3981. }
  3982. $( this ).attr( 'data-lastSearchTime', new Date().getTime() );
  3983. // emulate what webkit does.... escape clears the filter
  3984. if ( event.which === tskeyCodes.escape ) {
  3985. // make sure to restore the last value on escape
  3986. this.value = wo.filter_resetOnEsc ? '' : c.lastSearch[column];
  3987. // don't return if the search value is empty ( all rows need to be revealed )
  3988. } else if ( this.value !== '' && (
  3989. // liveSearch can contain a min value length; ignore arrow and meta keys, but allow backspace
  3990. ( typeof liveSearch === 'number' && this.value.length < liveSearch ) ||
  3991. // let return & backspace continue on, but ignore arrows & non-valid characters
  3992. ( event.which !== tskeyCodes.enter && event.which !== tskeyCodes.backSpace &&
  3993. ( event.which < tskeyCodes.space || ( event.which >= tskeyCodes.left && event.which <= tskeyCodes.down ) ) ) ) ) {
  3994. return;
  3995. // live search
  3996. } else if ( liveSearch === false ) {
  3997. if ( this.value !== '' && event.which !== tskeyCodes.enter ) {
  3998. return;
  3999. }
  4000. }
  4001. // change event = no delay; last true flag tells getFilters to skip newest timed input
  4002. tsf.searching( table, true, true, column );
  4003. })
  4004. // include change for select - fixes #473
  4005. .bind( 'search change keypress input blur '.split( ' ' ).join( namespace + ' ' ), function( event ) {
  4006. // don't get cached data, in case data-column changes dynamically
  4007. var column = parseInt( $( this ).attr( 'data-column' ), 10 ),
  4008. eventType = event.type,
  4009. liveSearch = typeof wo.filter_liveSearch === 'boolean' ?
  4010. wo.filter_liveSearch :
  4011. ts.getColumnData( table, wo.filter_liveSearch, column );
  4012. if ( table.config.widgetOptions.filter_initialized &&
  4013. // immediate search if user presses enter
  4014. ( event.which === tskeyCodes.enter ||
  4015. // immediate search if a "search" or "blur" is triggered on the input
  4016. ( eventType === 'search' || eventType === 'blur' ) ||
  4017. // change & input events must be ignored if liveSearch !== true
  4018. ( eventType === 'change' || eventType === 'input' ) &&
  4019. // prevent search if liveSearch is a number
  4020. ( liveSearch === true || liveSearch !== true && event.target.nodeName !== 'INPUT' ) &&
  4021. // don't allow 'change' or 'input' event to process if the input value
  4022. // is the same - fixes #685
  4023. this.value !== c.lastSearch[column]
  4024. )
  4025. ) {
  4026. event.preventDefault();
  4027. // init search with no delay
  4028. $( this ).attr( 'data-lastSearchTime', new Date().getTime() );
  4029. tsf.searching( table, eventType !== 'keypress' || event.which === tskeyCodes.enter, true, column );
  4030. }
  4031. });
  4032. },
  4033. searching: function( table, filter, skipFirst, column ) {
  4034. var liveSearch,
  4035. wo = table.config.widgetOptions;
  4036. if (typeof column === 'undefined') {
  4037. // no delay
  4038. liveSearch = false;
  4039. } else {
  4040. liveSearch = typeof wo.filter_liveSearch === 'boolean' ?
  4041. wo.filter_liveSearch :
  4042. // get column setting, or set to fallback value, or default to false
  4043. ts.getColumnData( table, wo.filter_liveSearch, column );
  4044. if ( typeof liveSearch === 'undefined' ) {
  4045. liveSearch = wo.filter_liveSearch.fallback || false;
  4046. }
  4047. }
  4048. clearTimeout( wo.filter_searchTimer );
  4049. if ( typeof filter === 'undefined' || filter === true ) {
  4050. // delay filtering
  4051. wo.filter_searchTimer = setTimeout( function() {
  4052. tsf.checkFilters( table, filter, skipFirst );
  4053. }, liveSearch ? wo.filter_searchDelay : 10 );
  4054. } else {
  4055. // skip delay
  4056. tsf.checkFilters( table, filter, skipFirst );
  4057. }
  4058. },
  4059. equalFilters: function (c, filter1, filter2) {
  4060. var indx,
  4061. f1 = [],
  4062. f2 = [],
  4063. len = c.columns + 1; // add one to include anyMatch filter
  4064. filter1 = $.isArray(filter1) ? filter1 : [];
  4065. filter2 = $.isArray(filter2) ? filter2 : [];
  4066. for (indx = 0; indx < len; indx++) {
  4067. f1[indx] = filter1[indx] || '';
  4068. f2[indx] = filter2[indx] || '';
  4069. }
  4070. return f1.join(',') === f2.join(',');
  4071. },
  4072. checkFilters: function( table, filter, skipFirst ) {
  4073. var c = table.config,
  4074. wo = c.widgetOptions,
  4075. filterArray = $.isArray( filter ),
  4076. filters = ( filterArray ) ? filter : ts.getFilters( table, true ),
  4077. currentFilters = filters || []; // current filter values
  4078. // prevent errors if delay init is set
  4079. if ( $.isEmptyObject( c.cache ) ) {
  4080. // update cache if delayInit set & pager has initialized ( after user initiates a search )
  4081. if ( c.delayInit && ( !c.pager || c.pager && c.pager.initialized ) ) {
  4082. ts.updateCache( c, function() {
  4083. tsf.checkFilters( table, false, skipFirst );
  4084. });
  4085. }
  4086. return;
  4087. }
  4088. // add filter array back into inputs
  4089. if ( filterArray ) {
  4090. ts.setFilters( table, filters, false, skipFirst !== true );
  4091. if ( !wo.filter_initialized ) {
  4092. c.lastSearch = [];
  4093. c.lastCombinedFilter = '';
  4094. }
  4095. }
  4096. if ( wo.filter_hideFilters ) {
  4097. // show/hide filter row as needed
  4098. c.$table
  4099. .find( '.' + tscss.filterRow )
  4100. .triggerHandler( tsf.hideFiltersCheck( c ) ? 'mouseleave' : 'mouseenter' );
  4101. }
  4102. // return if the last search is the same; but filter === false when updating the search
  4103. // see example-widget-filter.html filter toggle buttons
  4104. if ( tsf.equalFilters(c, c.lastSearch, currentFilters) ) {
  4105. if ( filter !== false ) {
  4106. return;
  4107. } else {
  4108. // force filter refresh
  4109. c.lastCombinedFilter = '';
  4110. c.lastSearch = [];
  4111. }
  4112. }
  4113. // define filter inside it is false
  4114. filters = filters || [];
  4115. // convert filters to strings - see #1070
  4116. filters = Array.prototype.map ?
  4117. filters.map( String ) :
  4118. // for IE8 & older browsers - maybe not the best method
  4119. filters.join( '\ufffd' ).split( '\ufffd' );
  4120. if ( wo.filter_initialized ) {
  4121. c.$table.triggerHandler( 'filterStart', [ filters ] );
  4122. }
  4123. if ( c.showProcessing ) {
  4124. // give it time for the processing icon to kick in
  4125. setTimeout( function() {
  4126. tsf.findRows( table, filters, currentFilters );
  4127. return false;
  4128. }, 30 );
  4129. } else {
  4130. tsf.findRows( table, filters, currentFilters );
  4131. return false;
  4132. }
  4133. },
  4134. hideFiltersCheck: function( c ) {
  4135. if (typeof c.widgetOptions.filter_hideFilters === 'function') {
  4136. var val = c.widgetOptions.filter_hideFilters( c );
  4137. if (typeof val === 'boolean') {
  4138. return val;
  4139. }
  4140. }
  4141. return ts.getFilters( c.$table ).join( '' ) === '';
  4142. },
  4143. hideFilters: function( c, $table ) {
  4144. var timer;
  4145. ( $table || c.$table )
  4146. .find( '.' + tscss.filterRow )
  4147. .addClass( tscss.filterRowHide )
  4148. .bind( 'mouseenter mouseleave', function( e ) {
  4149. // save event object - http://bugs.jquery.com/ticket/12140
  4150. var event = e,
  4151. $row = $( this );
  4152. clearTimeout( timer );
  4153. timer = setTimeout( function() {
  4154. if ( /enter|over/.test( event.type ) ) {
  4155. $row.removeClass( tscss.filterRowHide );
  4156. } else {
  4157. // don't hide if input has focus
  4158. // $( ':focus' ) needs jQuery 1.6+
  4159. if ( $( document.activeElement ).closest( 'tr' )[0] !== $row[0] ) {
  4160. // don't hide row if any filter has a value
  4161. $row.toggleClass( tscss.filterRowHide, tsf.hideFiltersCheck( c ) );
  4162. }
  4163. }
  4164. }, 200 );
  4165. })
  4166. .find( 'input, select' ).bind( 'focus blur', function( e ) {
  4167. var event = e,
  4168. $row = $( this ).closest( 'tr' );
  4169. clearTimeout( timer );
  4170. timer = setTimeout( function() {
  4171. clearTimeout( timer );
  4172. // don't hide row if any filter has a value
  4173. $row.toggleClass( tscss.filterRowHide, tsf.hideFiltersCheck( c ) && event.type !== 'focus' );
  4174. }, 200 );
  4175. });
  4176. },
  4177. defaultFilter: function( filter, mask ) {
  4178. if ( filter === '' ) { return filter; }
  4179. var regex = tsfRegex.iQuery,
  4180. maskLen = mask.match( tsfRegex.igQuery ).length,
  4181. query = maskLen > 1 ? $.trim( filter ).split( /\s/ ) : [ $.trim( filter ) ],
  4182. len = query.length - 1,
  4183. indx = 0,
  4184. val = mask;
  4185. if ( len < 1 && maskLen > 1 ) {
  4186. // only one 'word' in query but mask has >1 slots
  4187. query[1] = query[0];
  4188. }
  4189. // replace all {query} with query words...
  4190. // if query = 'Bob', then convert mask from '!{query}' to '!Bob'
  4191. // if query = 'Bob Joe Frank', then convert mask '{q} OR {q}' to 'Bob OR Joe OR Frank'
  4192. while ( regex.test( val ) ) {
  4193. val = val.replace( regex, query[indx++] || '' );
  4194. if ( regex.test( val ) && indx < len && ( query[indx] || '' ) !== '' ) {
  4195. val = mask.replace( regex, val );
  4196. }
  4197. }
  4198. return val;
  4199. },
  4200. getLatestSearch: function( $input ) {
  4201. if ( $input ) {
  4202. return $input.sort( function( a, b ) {
  4203. return $( b ).attr( 'data-lastSearchTime' ) - $( a ).attr( 'data-lastSearchTime' );
  4204. });
  4205. }
  4206. return $input || $();
  4207. },
  4208. findRange: function( c, val, ignoreRanges ) {
  4209. // look for multiple columns '1-3,4-6,8' in data-column
  4210. var temp, ranges, range, start, end, singles, i, indx, len,
  4211. columns = [];
  4212. if ( /^[0-9]+$/.test( val ) ) {
  4213. // always return an array
  4214. return [ parseInt( val, 10 ) ];
  4215. }
  4216. // process column range
  4217. if ( !ignoreRanges && /-/.test( val ) ) {
  4218. ranges = val.match( /(\d+)\s*-\s*(\d+)/g );
  4219. len = ranges ? ranges.length : 0;
  4220. for ( indx = 0; indx < len; indx++ ) {
  4221. range = ranges[indx].split( /\s*-\s*/ );
  4222. start = parseInt( range[0], 10 ) || 0;
  4223. end = parseInt( range[1], 10 ) || ( c.columns - 1 );
  4224. if ( start > end ) {
  4225. temp = start; start = end; end = temp; // swap
  4226. }
  4227. if ( end >= c.columns ) {
  4228. end = c.columns - 1;
  4229. }
  4230. for ( ; start <= end; start++ ) {
  4231. columns[ columns.length ] = start;
  4232. }
  4233. // remove processed range from val
  4234. val = val.replace( ranges[ indx ], '' );
  4235. }
  4236. }
  4237. // process single columns
  4238. if ( !ignoreRanges && /,/.test( val ) ) {
  4239. singles = val.split( /\s*,\s*/ );
  4240. len = singles.length;
  4241. for ( i = 0; i < len; i++ ) {
  4242. if ( singles[ i ] !== '' ) {
  4243. indx = parseInt( singles[ i ], 10 );
  4244. if ( indx < c.columns ) {
  4245. columns[ columns.length ] = indx;
  4246. }
  4247. }
  4248. }
  4249. }
  4250. // return all columns
  4251. if ( !columns.length ) {
  4252. for ( indx = 0; indx < c.columns; indx++ ) {
  4253. columns[ columns.length ] = indx;
  4254. }
  4255. }
  4256. return columns;
  4257. },
  4258. getColumnElm: function( c, $elements, column ) {
  4259. // data-column may contain multiple columns '1-3,5-6,8'
  4260. // replaces: c.$filters.filter( '[data-column="' + column + '"]' );
  4261. return $elements.filter( function() {
  4262. var cols = tsf.findRange( c, $( this ).attr( 'data-column' ) );
  4263. return $.inArray( column, cols ) > -1;
  4264. });
  4265. },
  4266. multipleColumns: function( c, $input ) {
  4267. // look for multiple columns '1-3,4-6,8' in data-column
  4268. var wo = c.widgetOptions,
  4269. // only target 'all' column inputs on initialization
  4270. // & don't target 'all' column inputs if they don't exist
  4271. targets = wo.filter_initialized || !$input.filter( wo.filter_anyColumnSelector ).length,
  4272. val = $.trim( tsf.getLatestSearch( $input ).attr( 'data-column' ) || '' );
  4273. return tsf.findRange( c, val, !targets );
  4274. },
  4275. processTypes: function( c, data, vars ) {
  4276. var ffxn,
  4277. filterMatched = null,
  4278. matches = null;
  4279. for ( ffxn in tsf.types ) {
  4280. if ( $.inArray( ffxn, vars.excludeMatch ) < 0 && matches === null ) {
  4281. matches = tsf.types[ffxn]( c, data, vars );
  4282. if ( matches !== null ) {
  4283. data.matchedOn = ffxn;
  4284. filterMatched = matches;
  4285. }
  4286. }
  4287. }
  4288. return filterMatched;
  4289. },
  4290. matchType: function( c, columnIndex ) {
  4291. var isMatch,
  4292. wo = c.widgetOptions,
  4293. $el = c.$headerIndexed[ columnIndex ];
  4294. // filter-exact > filter-match > filter_matchType for type
  4295. if ( $el.hasClass( 'filter-exact' ) ) {
  4296. isMatch = false;
  4297. } else if ( $el.hasClass( 'filter-match' ) ) {
  4298. isMatch = true;
  4299. } else {
  4300. // filter-select is not applied when filter_functions are used, so look for a select
  4301. if ( wo.filter_columnFilters ) {
  4302. $el = c.$filters
  4303. .find( '.' + tscss.filter )
  4304. .add( wo.filter_$externalFilters )
  4305. .filter( '[data-column="' + columnIndex + '"]' );
  4306. } else if ( wo.filter_$externalFilters ) {
  4307. $el = wo.filter_$externalFilters.filter( '[data-column="' + columnIndex + '"]' );
  4308. }
  4309. isMatch = $el.length ?
  4310. c.widgetOptions.filter_matchType[ ( $el[ 0 ].nodeName || '' ).toLowerCase() ] === 'match' :
  4311. // default to exact, if no inputs found
  4312. false;
  4313. }
  4314. return isMatch;
  4315. },
  4316. processRow: function( c, data, vars ) {
  4317. var result, filterMatched,
  4318. fxn, ffxn, txt,
  4319. wo = c.widgetOptions,
  4320. showRow = true,
  4321. hasAnyMatchInput = wo.filter_$anyMatch && wo.filter_$anyMatch.length,
  4322. // if wo.filter_$anyMatch data-column attribute is changed dynamically
  4323. // we don't want to do an "anyMatch" search on one column using data
  4324. // for the entire row - see #998
  4325. columnIndex = wo.filter_$anyMatch && wo.filter_$anyMatch.length ?
  4326. // look for multiple columns '1-3,4-6,8'
  4327. tsf.multipleColumns( c, wo.filter_$anyMatch ) :
  4328. [];
  4329. data.$cells = data.$row.children();
  4330. data.matchedOn = null;
  4331. if ( data.anyMatchFlag && columnIndex.length > 1 || ( data.anyMatchFilter && !hasAnyMatchInput ) ) {
  4332. data.anyMatch = true;
  4333. data.isMatch = true;
  4334. data.rowArray = data.$cells.map( function( i ) {
  4335. if ( $.inArray( i, columnIndex ) > -1 || ( data.anyMatchFilter && !hasAnyMatchInput ) ) {
  4336. if ( data.parsed[ i ] ) {
  4337. txt = data.cacheArray[ i ];
  4338. } else {
  4339. txt = data.rawArray[ i ];
  4340. txt = $.trim( wo.filter_ignoreCase ? txt.toLowerCase() : txt );
  4341. if ( c.sortLocaleCompare ) {
  4342. txt = ts.replaceAccents( txt );
  4343. }
  4344. }
  4345. return txt;
  4346. }
  4347. }).get();
  4348. data.filter = data.anyMatchFilter;
  4349. data.iFilter = data.iAnyMatchFilter;
  4350. data.exact = data.rowArray.join( ' ' );
  4351. data.iExact = wo.filter_ignoreCase ? data.exact.toLowerCase() : data.exact;
  4352. data.cache = data.cacheArray.slice( 0, -1 ).join( ' ' );
  4353. vars.excludeMatch = vars.noAnyMatch;
  4354. filterMatched = tsf.processTypes( c, data, vars );
  4355. if ( filterMatched !== null ) {
  4356. showRow = filterMatched;
  4357. } else {
  4358. if ( wo.filter_startsWith ) {
  4359. showRow = false;
  4360. // data.rowArray may not contain all columns
  4361. columnIndex = Math.min( c.columns, data.rowArray.length );
  4362. while ( !showRow && columnIndex > 0 ) {
  4363. columnIndex--;
  4364. showRow = showRow || data.rowArray[ columnIndex ].indexOf( data.iFilter ) === 0;
  4365. }
  4366. } else {
  4367. showRow = ( data.iExact + data.childRowText ).indexOf( data.iFilter ) >= 0;
  4368. }
  4369. }
  4370. data.anyMatch = false;
  4371. // no other filters to process
  4372. if ( data.filters.join( '' ) === data.filter ) {
  4373. return showRow;
  4374. }
  4375. }
  4376. for ( columnIndex = 0; columnIndex < c.columns; columnIndex++ ) {
  4377. data.filter = data.filters[ columnIndex ];
  4378. data.index = columnIndex;
  4379. // filter types to exclude, per column
  4380. vars.excludeMatch = vars.excludeFilter[ columnIndex ];
  4381. // ignore if filter is empty or disabled
  4382. if ( data.filter ) {
  4383. data.cache = data.cacheArray[ columnIndex ];
  4384. result = data.parsed[ columnIndex ] ? data.cache : data.rawArray[ columnIndex ] || '';
  4385. data.exact = c.sortLocaleCompare ? ts.replaceAccents( result ) : result; // issue #405
  4386. data.iExact = !tsfRegex.type.test( typeof data.exact ) && wo.filter_ignoreCase ?
  4387. data.exact.toLowerCase() : data.exact;
  4388. data.isMatch = tsf.matchType( c, columnIndex );
  4389. result = showRow; // if showRow is true, show that row
  4390. // in case select filter option has a different value vs text 'a - z|A through Z'
  4391. ffxn = wo.filter_columnFilters ?
  4392. c.$filters.add( wo.filter_$externalFilters )
  4393. .filter( '[data-column="' + columnIndex + '"]' )
  4394. .find( 'select option:selected' )
  4395. .attr( 'data-function-name' ) || '' : '';
  4396. // replace accents - see #357
  4397. if ( c.sortLocaleCompare ) {
  4398. data.filter = ts.replaceAccents( data.filter );
  4399. }
  4400. // replace column specific default filters - see #1088
  4401. if ( wo.filter_defaultFilter && tsfRegex.iQuery.test( vars.defaultColFilter[ columnIndex ] ) ) {
  4402. data.filter = tsf.defaultFilter( data.filter, vars.defaultColFilter[ columnIndex ] );
  4403. }
  4404. // data.iFilter = case insensitive ( if wo.filter_ignoreCase is true ),
  4405. // data.filter = case sensitive
  4406. data.iFilter = wo.filter_ignoreCase ? ( data.filter || '' ).toLowerCase() : data.filter;
  4407. fxn = vars.functions[ columnIndex ];
  4408. filterMatched = null;
  4409. if ( fxn ) {
  4410. if ( typeof fxn === 'function' ) {
  4411. // filter callback( exact cell content, parser normalized content,
  4412. // filter input value, column index, jQuery row object )
  4413. filterMatched = fxn( data.exact, data.cache, data.filter, columnIndex, data.$row, c, data );
  4414. } else if ( typeof fxn[ ffxn || data.filter ] === 'function' ) {
  4415. // selector option function
  4416. txt = ffxn || data.filter;
  4417. filterMatched =
  4418. fxn[ txt ]( data.exact, data.cache, data.filter, columnIndex, data.$row, c, data );
  4419. }
  4420. }
  4421. if ( filterMatched === null ) {
  4422. // cycle through the different filters
  4423. // filters return a boolean or null if nothing matches
  4424. filterMatched = tsf.processTypes( c, data, vars );
  4425. // select with exact match; ignore "and" or "or" within the text; fixes #1486
  4426. txt = fxn === true && (data.matchedOn === 'and' || data.matchedOn === 'or');
  4427. if ( filterMatched !== null && !txt) {
  4428. result = filterMatched;
  4429. // Look for match, and add child row data for matching
  4430. } else {
  4431. // check fxn (filter-select in header) after filter types are checked
  4432. // without this, the filter + jQuery UI selectmenu demo was breaking
  4433. if ( fxn === true ) {
  4434. // default selector uses exact match unless 'filter-match' class is found
  4435. result = data.isMatch ?
  4436. // data.iExact may be a number
  4437. ( '' + data.iExact ).search( data.iFilter ) >= 0 :
  4438. data.filter === data.exact;
  4439. } else {
  4440. txt = ( data.iExact + data.childRowText ).indexOf( tsf.parseFilter( c, data.iFilter, data ) );
  4441. result = ( ( !wo.filter_startsWith && txt >= 0 ) || ( wo.filter_startsWith && txt === 0 ) );
  4442. }
  4443. }
  4444. } else {
  4445. result = filterMatched;
  4446. }
  4447. showRow = ( result ) ? showRow : false;
  4448. }
  4449. }
  4450. return showRow;
  4451. },
  4452. findRows: function( table, filters, currentFilters ) {
  4453. if (
  4454. tsf.equalFilters(table.config, table.config.lastSearch, currentFilters) ||
  4455. !table.config.widgetOptions.filter_initialized
  4456. ) {
  4457. return;
  4458. }
  4459. var len, norm_rows, rowData, $rows, $row, rowIndex, tbodyIndex, $tbody, columnIndex,
  4460. isChild, childRow, lastSearch, showRow, showParent, time, val, indx,
  4461. notFiltered, searchFiltered, query, injected, res, id, txt,
  4462. storedFilters = $.extend( [], filters ),
  4463. c = table.config,
  4464. wo = c.widgetOptions,
  4465. debug = ts.debug(c, 'filter'),
  4466. // data object passed to filters; anyMatch is a flag for the filters
  4467. data = {
  4468. anyMatch: false,
  4469. filters: filters,
  4470. // regex filter type cache
  4471. filter_regexCache : []
  4472. },
  4473. vars = {
  4474. // anyMatch really screws up with these types of filters
  4475. noAnyMatch: [ 'range', 'operators' ],
  4476. // cache filter variables that use ts.getColumnData in the main loop
  4477. functions : [],
  4478. excludeFilter : [],
  4479. defaultColFilter : [],
  4480. defaultAnyFilter : ts.getColumnData( table, wo.filter_defaultFilter, c.columns, true ) || ''
  4481. };
  4482. // parse columns after formatter, in case the class is added at that point
  4483. data.parsed = [];
  4484. for ( columnIndex = 0; columnIndex < c.columns; columnIndex++ ) {
  4485. data.parsed[ columnIndex ] = wo.filter_useParsedData ||
  4486. // parser has a "parsed" parameter
  4487. ( c.parsers && c.parsers[ columnIndex ] && c.parsers[ columnIndex ].parsed ||
  4488. // getData may not return 'parsed' if other 'filter-' class names exist
  4489. // ( e.g. <th class="filter-select filter-parsed"> )
  4490. ts.getData && ts.getData( c.$headerIndexed[ columnIndex ],
  4491. ts.getColumnData( table, c.headers, columnIndex ), 'filter' ) === 'parsed' ||
  4492. c.$headerIndexed[ columnIndex ].hasClass( 'filter-parsed' ) );
  4493. vars.functions[ columnIndex ] =
  4494. ts.getColumnData( table, wo.filter_functions, columnIndex ) ||
  4495. c.$headerIndexed[ columnIndex ].hasClass( 'filter-select' );
  4496. vars.defaultColFilter[ columnIndex ] =
  4497. ts.getColumnData( table, wo.filter_defaultFilter, columnIndex ) || '';
  4498. vars.excludeFilter[ columnIndex ] =
  4499. ( ts.getColumnData( table, wo.filter_excludeFilter, columnIndex, true ) || '' ).split( /\s+/ );
  4500. }
  4501. if ( debug ) {
  4502. console.log( 'Filter >> Starting filter widget search', filters );
  4503. time = new Date();
  4504. }
  4505. // filtered rows count
  4506. c.filteredRows = 0;
  4507. c.totalRows = 0;
  4508. currentFilters = ( storedFilters || [] );
  4509. for ( tbodyIndex = 0; tbodyIndex < c.$tbodies.length; tbodyIndex++ ) {
  4510. $tbody = ts.processTbody( table, c.$tbodies.eq( tbodyIndex ), true );
  4511. // skip child rows & widget added ( removable ) rows - fixes #448 thanks to @hempel!
  4512. // $rows = $tbody.children( 'tr' ).not( c.selectorRemove );
  4513. columnIndex = c.columns;
  4514. // convert stored rows into a jQuery object
  4515. norm_rows = c.cache[ tbodyIndex ].normalized;
  4516. $rows = $( $.map( norm_rows, function( el ) {
  4517. return el[ columnIndex ].$row.get();
  4518. }) );
  4519. if ( currentFilters.join('') === '' || wo.filter_serversideFiltering ) {
  4520. $rows
  4521. .removeClass( wo.filter_filteredRow )
  4522. .not( '.' + c.cssChildRow )
  4523. .css( 'display', '' );
  4524. } else {
  4525. // filter out child rows
  4526. $rows = $rows.not( '.' + c.cssChildRow );
  4527. len = $rows.length;
  4528. if ( ( wo.filter_$anyMatch && wo.filter_$anyMatch.length ) ||
  4529. typeof filters[c.columns] !== 'undefined' ) {
  4530. data.anyMatchFlag = true;
  4531. data.anyMatchFilter = '' + (
  4532. filters[ c.columns ] ||
  4533. wo.filter_$anyMatch && tsf.getLatestSearch( wo.filter_$anyMatch ).val() ||
  4534. ''
  4535. );
  4536. if ( wo.filter_columnAnyMatch ) {
  4537. // specific columns search
  4538. query = data.anyMatchFilter.split( tsfRegex.andSplit );
  4539. injected = false;
  4540. for ( indx = 0; indx < query.length; indx++ ) {
  4541. res = query[ indx ].split( ':' );
  4542. if ( res.length > 1 ) {
  4543. // make the column a one-based index ( non-developers start counting from one :P )
  4544. if ( isNaN( res[0] ) ) {
  4545. $.each( c.headerContent, function( i, txt ) {
  4546. // multiple matches are possible
  4547. if ( txt.toLowerCase().indexOf( res[0] ) > -1 ) {
  4548. id = i;
  4549. filters[ id ] = res[1];
  4550. }
  4551. });
  4552. } else {
  4553. id = parseInt( res[0], 10 ) - 1;
  4554. }
  4555. if ( id >= 0 && id < c.columns ) { // if id is an integer
  4556. filters[ id ] = res[1];
  4557. query.splice( indx, 1 );
  4558. indx--;
  4559. injected = true;
  4560. }
  4561. }
  4562. }
  4563. if ( injected ) {
  4564. data.anyMatchFilter = query.join( ' && ' );
  4565. }
  4566. }
  4567. }
  4568. // optimize searching only through already filtered rows - see #313
  4569. searchFiltered = wo.filter_searchFiltered;
  4570. lastSearch = c.lastSearch || c.$table.data( 'lastSearch' ) || [];
  4571. if ( searchFiltered ) {
  4572. // cycle through all filters; include last ( columnIndex + 1 = match any column ). Fixes #669
  4573. for ( indx = 0; indx < columnIndex + 1; indx++ ) {
  4574. val = filters[indx] || '';
  4575. // break out of loop if we've already determined not to search filtered rows
  4576. if ( !searchFiltered ) { indx = columnIndex; }
  4577. // search already filtered rows if...
  4578. searchFiltered = searchFiltered && lastSearch.length &&
  4579. // there are no changes from beginning of filter
  4580. val.indexOf( lastSearch[indx] || '' ) === 0 &&
  4581. // if there is NOT a logical 'or', or range ( 'to' or '-' ) in the string
  4582. !tsfRegex.alreadyFiltered.test( val ) &&
  4583. // if we are not doing exact matches, using '|' ( logical or ) or not '!'
  4584. !tsfRegex.exactTest.test( val ) &&
  4585. // don't search only filtered if the value is negative
  4586. // ( '> -10' => '> -100' will ignore hidden rows )
  4587. !( tsfRegex.isNeg1.test( val ) || tsfRegex.isNeg2.test( val ) ) &&
  4588. // if filtering using a select without a 'filter-match' class ( exact match ) - fixes #593
  4589. !( val !== '' && c.$filters && c.$filters.filter( '[data-column="' + indx + '"]' ).find( 'select' ).length &&
  4590. !tsf.matchType( c, indx ) );
  4591. }
  4592. }
  4593. notFiltered = $rows.not( '.' + wo.filter_filteredRow ).length;
  4594. // can't search when all rows are hidden - this happens when looking for exact matches
  4595. if ( searchFiltered && notFiltered === 0 ) { searchFiltered = false; }
  4596. if ( debug ) {
  4597. console.log( 'Filter >> Searching through ' +
  4598. ( searchFiltered && notFiltered < len ? notFiltered : 'all' ) + ' rows' );
  4599. }
  4600. if ( data.anyMatchFlag ) {
  4601. if ( c.sortLocaleCompare ) {
  4602. // replace accents
  4603. data.anyMatchFilter = ts.replaceAccents( data.anyMatchFilter );
  4604. }
  4605. if ( wo.filter_defaultFilter && tsfRegex.iQuery.test( vars.defaultAnyFilter ) ) {
  4606. data.anyMatchFilter = tsf.defaultFilter( data.anyMatchFilter, vars.defaultAnyFilter );
  4607. // clear search filtered flag because default filters are not saved to the last search
  4608. searchFiltered = false;
  4609. }
  4610. // make iAnyMatchFilter lowercase unless both filter widget & core ignoreCase options are true
  4611. // when c.ignoreCase is true, the cache contains all lower case data
  4612. data.iAnyMatchFilter = !( wo.filter_ignoreCase && c.ignoreCase ) ?
  4613. data.anyMatchFilter :
  4614. data.anyMatchFilter.toLowerCase();
  4615. }
  4616. // loop through the rows
  4617. for ( rowIndex = 0; rowIndex < len; rowIndex++ ) {
  4618. txt = $rows[ rowIndex ].className;
  4619. // the first row can never be a child row
  4620. isChild = rowIndex && tsfRegex.child.test( txt );
  4621. // skip child rows & already filtered rows
  4622. if ( isChild || ( searchFiltered && tsfRegex.filtered.test( txt ) ) ) {
  4623. continue;
  4624. }
  4625. data.$row = $rows.eq( rowIndex );
  4626. data.rowIndex = rowIndex;
  4627. data.cacheArray = norm_rows[ rowIndex ];
  4628. rowData = data.cacheArray[ c.columns ];
  4629. data.rawArray = rowData.raw;
  4630. data.childRowText = '';
  4631. if ( !wo.filter_childByColumn ) {
  4632. txt = '';
  4633. // child row cached text
  4634. childRow = rowData.child;
  4635. // so, if 'table.config.widgetOptions.filter_childRows' is true and there is
  4636. // a match anywhere in the child row, then it will make the row visible
  4637. // checked here so the option can be changed dynamically
  4638. for ( indx = 0; indx < childRow.length; indx++ ) {
  4639. txt += ' ' + childRow[indx].join( ' ' ) || '';
  4640. }
  4641. data.childRowText = wo.filter_childRows ?
  4642. ( wo.filter_ignoreCase ? txt.toLowerCase() : txt ) :
  4643. '';
  4644. }
  4645. showRow = false;
  4646. showParent = tsf.processRow( c, data, vars );
  4647. $row = rowData.$row;
  4648. // don't pass reference to val
  4649. val = showParent ? true : false;
  4650. childRow = rowData.$row.filter( ':gt(0)' );
  4651. if ( wo.filter_childRows && childRow.length ) {
  4652. if ( wo.filter_childByColumn ) {
  4653. if ( !wo.filter_childWithSibs ) {
  4654. // hide all child rows
  4655. childRow.addClass( wo.filter_filteredRow );
  4656. // if only showing resulting child row, only include parent
  4657. $row = $row.eq( 0 );
  4658. }
  4659. // cycle through each child row
  4660. for ( indx = 0; indx < childRow.length; indx++ ) {
  4661. data.$row = childRow.eq( indx );
  4662. data.cacheArray = rowData.child[ indx ];
  4663. data.rawArray = data.cacheArray;
  4664. val = tsf.processRow( c, data, vars );
  4665. // use OR comparison on child rows
  4666. showRow = showRow || val;
  4667. if ( !wo.filter_childWithSibs && val ) {
  4668. childRow.eq( indx ).removeClass( wo.filter_filteredRow );
  4669. }
  4670. }
  4671. }
  4672. // keep parent row match even if no child matches... see #1020
  4673. showRow = showRow || showParent;
  4674. } else {
  4675. showRow = val;
  4676. }
  4677. $row
  4678. .toggleClass( wo.filter_filteredRow, !showRow )[0]
  4679. .display = showRow ? '' : 'none';
  4680. }
  4681. }
  4682. c.filteredRows += $rows.not( '.' + wo.filter_filteredRow ).length;
  4683. c.totalRows += $rows.length;
  4684. ts.processTbody( table, $tbody, false );
  4685. }
  4686. // lastCombinedFilter is no longer used internally
  4687. c.lastCombinedFilter = storedFilters.join(''); // save last search
  4688. // don't save 'filters' directly since it may have altered ( AnyMatch column searches )
  4689. c.lastSearch = storedFilters;
  4690. c.$table.data( 'lastSearch', storedFilters );
  4691. if ( wo.filter_saveFilters && ts.storage ) {
  4692. ts.storage( table, 'tablesorter-filters', tsf.processFilters( storedFilters, true ) );
  4693. }
  4694. if ( debug ) {
  4695. console.log( 'Filter >> Completed search' + ts.benchmark(time) );
  4696. }
  4697. if ( wo.filter_initialized ) {
  4698. c.$table.triggerHandler( 'filterBeforeEnd', c );
  4699. c.$table.triggerHandler( 'filterEnd', c );
  4700. }
  4701. setTimeout( function() {
  4702. ts.applyWidget( c.table ); // make sure zebra widget is applied
  4703. }, 0 );
  4704. },
  4705. getOptionSource: function( table, column, onlyAvail ) {
  4706. table = $( table )[0];
  4707. var c = table.config,
  4708. wo = c.widgetOptions,
  4709. arry = false,
  4710. source = wo.filter_selectSource,
  4711. last = c.$table.data( 'lastSearch' ) || [],
  4712. fxn = typeof source === 'function' ? true : ts.getColumnData( table, source, column );
  4713. if ( onlyAvail && last[column] !== '' ) {
  4714. onlyAvail = false;
  4715. }
  4716. // filter select source option
  4717. if ( fxn === true ) {
  4718. // OVERALL source
  4719. arry = source( table, column, onlyAvail );
  4720. } else if ( fxn instanceof $ || ( $.type( fxn ) === 'string' && fxn.indexOf( '</option>' ) >= 0 ) ) {
  4721. // selectSource is a jQuery object or string of options
  4722. return fxn;
  4723. } else if ( $.isArray( fxn ) ) {
  4724. arry = fxn;
  4725. } else if ( $.type( source ) === 'object' && fxn ) {
  4726. // custom select source function for a SPECIFIC COLUMN
  4727. arry = fxn( table, column, onlyAvail );
  4728. // abort - updating the selects from an external method
  4729. if (arry === null) {
  4730. return null;
  4731. }
  4732. }
  4733. if ( arry === false ) {
  4734. // fall back to original method
  4735. arry = tsf.getOptions( table, column, onlyAvail );
  4736. }
  4737. return tsf.processOptions( table, column, arry );
  4738. },
  4739. processOptions: function( table, column, arry ) {
  4740. if ( !$.isArray( arry ) ) {
  4741. return false;
  4742. }
  4743. table = $( table )[0];
  4744. var cts, txt, indx, len, parsedTxt, str,
  4745. c = table.config,
  4746. validColumn = typeof column !== 'undefined' && column !== null && column >= 0 && column < c.columns,
  4747. direction = validColumn ? c.$headerIndexed[ column ].hasClass( 'filter-select-sort-desc' ) : false,
  4748. parsed = [];
  4749. // get unique elements and sort the list
  4750. // if $.tablesorter.sortText exists ( not in the original tablesorter ),
  4751. // then natural sort the list otherwise use a basic sort
  4752. arry = $.grep( arry, function( value, indx ) {
  4753. if ( value.text ) {
  4754. return true;
  4755. }
  4756. return $.inArray( value, arry ) === indx;
  4757. });
  4758. if ( validColumn && c.$headerIndexed[ column ].hasClass( 'filter-select-nosort' ) ) {
  4759. // unsorted select options
  4760. return arry;
  4761. } else {
  4762. len = arry.length;
  4763. // parse select option values
  4764. for ( indx = 0; indx < len; indx++ ) {
  4765. txt = arry[ indx ];
  4766. // check for object
  4767. str = txt.text ? txt.text : txt;
  4768. // sortNatural breaks if you don't pass it strings
  4769. parsedTxt = ( validColumn && c.parsers && c.parsers.length &&
  4770. c.parsers[ column ].format( str, table, [], column ) || str ).toString();
  4771. parsedTxt = c.widgetOptions.filter_ignoreCase ? parsedTxt.toLowerCase() : parsedTxt;
  4772. // parse array data using set column parser; this DOES NOT pass the original
  4773. // table cell to the parser format function
  4774. if ( txt.text ) {
  4775. txt.parsed = parsedTxt;
  4776. parsed[ parsed.length ] = txt;
  4777. } else {
  4778. parsed[ parsed.length ] = {
  4779. text : txt,
  4780. // check parser length - fixes #934
  4781. parsed : parsedTxt
  4782. };
  4783. }
  4784. }
  4785. // sort parsed select options
  4786. cts = c.textSorter || '';
  4787. parsed.sort( function( a, b ) {
  4788. var x = direction ? b.parsed : a.parsed,
  4789. y = direction ? a.parsed : b.parsed;
  4790. if ( validColumn && typeof cts === 'function' ) {
  4791. // custom OVERALL text sorter
  4792. return cts( x, y, true, column, table );
  4793. } else if ( validColumn && typeof cts === 'object' && cts.hasOwnProperty( column ) ) {
  4794. // custom text sorter for a SPECIFIC COLUMN
  4795. return cts[column]( x, y, true, column, table );
  4796. } else if ( ts.sortNatural ) {
  4797. // fall back to natural sort
  4798. return ts.sortNatural( x, y );
  4799. }
  4800. // using an older version! do a basic sort
  4801. return true;
  4802. });
  4803. // rebuild arry from sorted parsed data
  4804. arry = [];
  4805. len = parsed.length;
  4806. for ( indx = 0; indx < len; indx++ ) {
  4807. arry[ arry.length ] = parsed[indx];
  4808. }
  4809. return arry;
  4810. }
  4811. },
  4812. getOptions: function( table, column, onlyAvail ) {
  4813. table = $( table )[0];
  4814. var rowIndex, tbodyIndex, len, row, cache, indx, child, childLen,
  4815. c = table.config,
  4816. wo = c.widgetOptions,
  4817. arry = [];
  4818. for ( tbodyIndex = 0; tbodyIndex < c.$tbodies.length; tbodyIndex++ ) {
  4819. cache = c.cache[tbodyIndex];
  4820. len = c.cache[tbodyIndex].normalized.length;
  4821. // loop through the rows
  4822. for ( rowIndex = 0; rowIndex < len; rowIndex++ ) {
  4823. // get cached row from cache.row ( old ) or row data object
  4824. // ( new; last item in normalized array )
  4825. row = cache.row ?
  4826. cache.row[ rowIndex ] :
  4827. cache.normalized[ rowIndex ][ c.columns ].$row[0];
  4828. // check if has class filtered
  4829. if ( onlyAvail && row.className.match( wo.filter_filteredRow ) ) {
  4830. continue;
  4831. }
  4832. // get non-normalized cell content
  4833. if ( wo.filter_useParsedData ||
  4834. c.parsers[column].parsed ||
  4835. c.$headerIndexed[column].hasClass( 'filter-parsed' ) ) {
  4836. arry[ arry.length ] = '' + cache.normalized[ rowIndex ][ column ];
  4837. // child row parsed data
  4838. if ( wo.filter_childRows && wo.filter_childByColumn ) {
  4839. childLen = cache.normalized[ rowIndex ][ c.columns ].$row.length - 1;
  4840. for ( indx = 0; indx < childLen; indx++ ) {
  4841. arry[ arry.length ] = '' + cache.normalized[ rowIndex ][ c.columns ].child[ indx ][ column ];
  4842. }
  4843. }
  4844. } else {
  4845. // get raw cached data instead of content directly from the cells
  4846. arry[ arry.length ] = cache.normalized[ rowIndex ][ c.columns ].raw[ column ];
  4847. // child row unparsed data
  4848. if ( wo.filter_childRows && wo.filter_childByColumn ) {
  4849. childLen = cache.normalized[ rowIndex ][ c.columns ].$row.length;
  4850. for ( indx = 1; indx < childLen; indx++ ) {
  4851. child = cache.normalized[ rowIndex ][ c.columns ].$row.eq( indx ).children().eq( column );
  4852. arry[ arry.length ] = '' + ts.getElementText( c, child, column );
  4853. }
  4854. }
  4855. }
  4856. }
  4857. }
  4858. return arry;
  4859. },
  4860. buildSelect: function( table, column, arry, updating, onlyAvail ) {
  4861. table = $( table )[0];
  4862. column = parseInt( column, 10 );
  4863. if ( !table.config.cache || $.isEmptyObject( table.config.cache ) ) {
  4864. return;
  4865. }
  4866. var indx, val, txt, t, $filters, $filter, option,
  4867. c = table.config,
  4868. wo = c.widgetOptions,
  4869. node = c.$headerIndexed[ column ],
  4870. // t.data( 'placeholder' ) won't work in jQuery older than 1.4.3
  4871. options = '<option value="">' +
  4872. ( node.data( 'placeholder' ) ||
  4873. node.attr( 'data-placeholder' ) ||
  4874. wo.filter_placeholder.select || ''
  4875. ) + '</option>',
  4876. // Get curent filter value
  4877. currentValue = c.$table
  4878. .find( 'thead' )
  4879. .find( 'select.' + tscss.filter + '[data-column="' + column + '"]' )
  4880. .val();
  4881. // nothing included in arry ( external source ), so get the options from
  4882. // filter_selectSource or column data
  4883. if ( typeof arry === 'undefined' || arry === '' ) {
  4884. arry = tsf.getOptionSource( table, column, onlyAvail );
  4885. // abort, selects are updated by an external method
  4886. if (arry === null) {
  4887. return;
  4888. }
  4889. }
  4890. if ( $.isArray( arry ) ) {
  4891. // build option list
  4892. for ( indx = 0; indx < arry.length; indx++ ) {
  4893. option = arry[ indx ];
  4894. if ( option.text ) {
  4895. // OBJECT!! add data-function-name in case the value is set in filter_functions
  4896. option['data-function-name'] = typeof option.value === 'undefined' ? option.text : option.value;
  4897. // support jQuery < v1.8, otherwise the below code could be shortened to
  4898. // options += $( '<option>', option )[ 0 ].outerHTML;
  4899. options += '<option';
  4900. for ( val in option ) {
  4901. if ( option.hasOwnProperty( val ) && val !== 'text' ) {
  4902. options += ' ' + val + '="' + option[ val ].replace( tsfRegex.quote, '&quot;' ) + '"';
  4903. }
  4904. }
  4905. if ( !option.value ) {
  4906. options += ' value="' + option.text.replace( tsfRegex.quote, '&quot;' ) + '"';
  4907. }
  4908. options += '>' + option.text.replace( tsfRegex.quote, '&quot;' ) + '</option>';
  4909. // above code is needed in jQuery < v1.8
  4910. // make sure we don't turn an object into a string (objects without a "text" property)
  4911. } else if ( '' + option !== '[object Object]' ) {
  4912. txt = option = ( '' + option ).replace( tsfRegex.quote, '&quot;' );
  4913. val = txt;
  4914. // allow including a symbol in the selectSource array
  4915. // 'a-z|A through Z' so that 'a-z' becomes the option value
  4916. // and 'A through Z' becomes the option text
  4917. if ( txt.indexOf( wo.filter_selectSourceSeparator ) >= 0 ) {
  4918. t = txt.split( wo.filter_selectSourceSeparator );
  4919. val = t[0];
  4920. txt = t[1];
  4921. }
  4922. // replace quotes - fixes #242 & ignore empty strings
  4923. // see http://stackoverflow.com/q/14990971/145346
  4924. options += option !== '' ?
  4925. '<option ' +
  4926. ( val === txt ? '' : 'data-function-name="' + option + '" ' ) +
  4927. 'value="' + val + '">' + txt +
  4928. '</option>' : '';
  4929. }
  4930. }
  4931. // clear arry so it doesn't get appended twice
  4932. arry = [];
  4933. }
  4934. // update all selects in the same column ( clone thead in sticky headers &
  4935. // any external selects ) - fixes 473
  4936. $filters = ( c.$filters ? c.$filters : c.$table.children( 'thead' ) )
  4937. .find( '.' + tscss.filter );
  4938. if ( wo.filter_$externalFilters ) {
  4939. $filters = $filters && $filters.length ?
  4940. $filters.add( wo.filter_$externalFilters ) :
  4941. wo.filter_$externalFilters;
  4942. }
  4943. $filter = $filters.filter( 'select[data-column="' + column + '"]' );
  4944. // make sure there is a select there!
  4945. if ( $filter.length ) {
  4946. $filter[ updating ? 'html' : 'append' ]( options );
  4947. if ( !$.isArray( arry ) ) {
  4948. // append options if arry is provided externally as a string or jQuery object
  4949. // options ( default value ) was already added
  4950. $filter.append( arry ).val( currentValue );
  4951. }
  4952. $filter.val( currentValue );
  4953. }
  4954. },
  4955. buildDefault: function( table, updating ) {
  4956. var columnIndex, $header, noSelect,
  4957. c = table.config,
  4958. wo = c.widgetOptions,
  4959. columns = c.columns;
  4960. // build default select dropdown
  4961. for ( columnIndex = 0; columnIndex < columns; columnIndex++ ) {
  4962. $header = c.$headerIndexed[columnIndex];
  4963. noSelect = !( $header.hasClass( 'filter-false' ) || $header.hasClass( 'parser-false' ) );
  4964. // look for the filter-select class; build/update it if found
  4965. if ( ( $header.hasClass( 'filter-select' ) ||
  4966. ts.getColumnData( table, wo.filter_functions, columnIndex ) === true ) && noSelect ) {
  4967. tsf.buildSelect( table, columnIndex, '', updating, $header.hasClass( wo.filter_onlyAvail ) );
  4968. }
  4969. }
  4970. }
  4971. };
  4972. // filter regex variable
  4973. tsfRegex = tsf.regex;
  4974. ts.getFilters = function( table, getRaw, setFilters, skipFirst ) {
  4975. var i, $filters, $column, cols,
  4976. filters = [],
  4977. c = table ? $( table )[0].config : '',
  4978. wo = c ? c.widgetOptions : '';
  4979. if ( ( getRaw !== true && wo && !wo.filter_columnFilters ) ||
  4980. // setFilters called, but last search is exactly the same as the current
  4981. // fixes issue #733 & #903 where calling update causes the input values to reset
  4982. ( $.isArray(setFilters) && tsf.equalFilters(c, setFilters, c.lastSearch) )
  4983. ) {
  4984. return $( table ).data( 'lastSearch' ) || [];
  4985. }
  4986. if ( c ) {
  4987. if ( c.$filters ) {
  4988. $filters = c.$filters.find( '.' + tscss.filter );
  4989. }
  4990. if ( wo.filter_$externalFilters ) {
  4991. $filters = $filters && $filters.length ?
  4992. $filters.add( wo.filter_$externalFilters ) :
  4993. wo.filter_$externalFilters;
  4994. }
  4995. if ( $filters && $filters.length ) {
  4996. filters = setFilters || [];
  4997. for ( i = 0; i < c.columns + 1; i++ ) {
  4998. cols = ( i === c.columns ?
  4999. // 'all' columns can now include a range or set of columms ( data-column='0-2,4,6-7' )
  5000. wo.filter_anyColumnSelector + ',' + wo.filter_multipleColumnSelector :
  5001. '[data-column="' + i + '"]' );
  5002. $column = $filters.filter( cols );
  5003. if ( $column.length ) {
  5004. // move the latest search to the first slot in the array
  5005. $column = tsf.getLatestSearch( $column );
  5006. if ( $.isArray( setFilters ) ) {
  5007. // skip first ( latest input ) to maintain cursor position while typing
  5008. if ( skipFirst && $column.length > 1 ) {
  5009. $column = $column.slice( 1 );
  5010. }
  5011. if ( i === c.columns ) {
  5012. // prevent data-column='all' from filling data-column='0,1' ( etc )
  5013. cols = $column.filter( wo.filter_anyColumnSelector );
  5014. $column = cols.length ? cols : $column;
  5015. }
  5016. $column
  5017. .val( setFilters[ i ] )
  5018. // must include a namespace here; but not c.namespace + 'filter'?
  5019. .trigger( 'change' + c.namespace );
  5020. } else {
  5021. filters[i] = $column.val() || '';
  5022. // don't change the first... it will move the cursor
  5023. if ( i === c.columns ) {
  5024. // don't update range columns from 'all' setting
  5025. $column
  5026. .slice( 1 )
  5027. .filter( '[data-column*="' + $column.attr( 'data-column' ) + '"]' )
  5028. .val( filters[ i ] );
  5029. } else {
  5030. $column
  5031. .slice( 1 )
  5032. .val( filters[ i ] );
  5033. }
  5034. }
  5035. // save any match input dynamically
  5036. if ( i === c.columns && $column.length ) {
  5037. wo.filter_$anyMatch = $column;
  5038. }
  5039. }
  5040. }
  5041. }
  5042. }
  5043. return filters;
  5044. };
  5045. ts.setFilters = function( table, filter, apply, skipFirst ) {
  5046. var c = table ? $( table )[0].config : '',
  5047. valid = ts.getFilters( table, true, filter, skipFirst );
  5048. // default apply to "true"
  5049. if ( typeof apply === 'undefined' ) {
  5050. apply = true;
  5051. }
  5052. if ( c && apply ) {
  5053. // ensure new set filters are applied, even if the search is the same
  5054. c.lastCombinedFilter = null;
  5055. c.lastSearch = [];
  5056. tsf.searching( c.table, filter, skipFirst );
  5057. c.$table.triggerHandler( 'filterFomatterUpdate' );
  5058. }
  5059. return valid.length !== 0;
  5060. };
  5061. })( jQuery );
  5062. /*! Widget: stickyHeaders - updated 9/27/2017 (v2.29.0) *//*
  5063. * Requires tablesorter v2.8+ and jQuery 1.4.3+
  5064. * by Rob Garrison
  5065. */
  5066. ;(function ($, window) {
  5067. 'use strict';
  5068. var ts = $.tablesorter || {};
  5069. $.extend(ts.css, {
  5070. sticky : 'tablesorter-stickyHeader', // stickyHeader
  5071. stickyVis : 'tablesorter-sticky-visible',
  5072. stickyHide: 'tablesorter-sticky-hidden',
  5073. stickyWrap: 'tablesorter-sticky-wrapper'
  5074. });
  5075. // Add a resize event to table headers
  5076. ts.addHeaderResizeEvent = function(table, disable, settings) {
  5077. table = $(table)[0]; // make sure we're using a dom element
  5078. if ( !table.config ) { return; }
  5079. var defaults = {
  5080. timer : 250
  5081. },
  5082. options = $.extend({}, defaults, settings),
  5083. c = table.config,
  5084. wo = c.widgetOptions,
  5085. checkSizes = function( triggerEvent ) {
  5086. var index, headers, $header, sizes, width, height,
  5087. len = c.$headers.length;
  5088. wo.resize_flag = true;
  5089. headers = [];
  5090. for ( index = 0; index < len; index++ ) {
  5091. $header = c.$headers.eq( index );
  5092. sizes = $header.data( 'savedSizes' ) || [ 0, 0 ]; // fixes #394
  5093. width = $header[0].offsetWidth;
  5094. height = $header[0].offsetHeight;
  5095. if ( width !== sizes[0] || height !== sizes[1] ) {
  5096. $header.data( 'savedSizes', [ width, height ] );
  5097. headers.push( $header[0] );
  5098. }
  5099. }
  5100. if ( headers.length && triggerEvent !== false ) {
  5101. c.$table.triggerHandler( 'resize', [ headers ] );
  5102. }
  5103. wo.resize_flag = false;
  5104. };
  5105. clearInterval(wo.resize_timer);
  5106. if (disable) {
  5107. wo.resize_flag = false;
  5108. return false;
  5109. }
  5110. checkSizes( false );
  5111. wo.resize_timer = setInterval(function() {
  5112. if (wo.resize_flag) { return; }
  5113. checkSizes();
  5114. }, options.timer);
  5115. };
  5116. function getStickyOffset(c, wo) {
  5117. var $el = isNaN(wo.stickyHeaders_offset) ? $(wo.stickyHeaders_offset) : [];
  5118. return $el.length ?
  5119. $el.height() || 0 :
  5120. parseInt(wo.stickyHeaders_offset, 10) || 0;
  5121. }
  5122. // Sticky headers based on this awesome article:
  5123. // http://css-tricks.com/13465-persistent-headers/
  5124. // and https://github.com/jmosbech/StickyTableHeaders by Jonas Mosbech
  5125. // **************************
  5126. ts.addWidget({
  5127. id: 'stickyHeaders',
  5128. priority: 54, // sticky widget must be initialized after the filter & before pager widget!
  5129. options: {
  5130. stickyHeaders : '', // extra class name added to the sticky header row
  5131. stickyHeaders_appendTo : null, // jQuery selector or object to phycially attach the sticky headers
  5132. stickyHeaders_attachTo : null, // jQuery selector or object to attach scroll listener to (overridden by xScroll & yScroll settings)
  5133. stickyHeaders_xScroll : null, // jQuery selector or object to monitor horizontal scroll position (defaults: xScroll > attachTo > window)
  5134. stickyHeaders_yScroll : null, // jQuery selector or object to monitor vertical scroll position (defaults: yScroll > attachTo > window)
  5135. stickyHeaders_offset : 0, // number or jquery selector targeting the position:fixed element
  5136. stickyHeaders_filteredToTop: true, // scroll table top into view after filtering
  5137. stickyHeaders_cloneId : '-sticky', // added to table ID, if it exists
  5138. stickyHeaders_addResizeEvent : true, // trigger 'resize' event on headers
  5139. stickyHeaders_includeCaption : true, // if false and a caption exist, it won't be included in the sticky header
  5140. stickyHeaders_zIndex : 2 // The zIndex of the stickyHeaders, allows the user to adjust this to their needs
  5141. },
  5142. format: function(table, c, wo) {
  5143. // filter widget doesn't initialize on an empty table. Fixes #449
  5144. if ( c.$table.hasClass('hasStickyHeaders') || ($.inArray('filter', c.widgets) >= 0 && !c.$table.hasClass('hasFilters')) ) {
  5145. return;
  5146. }
  5147. var index, len, $t,
  5148. $table = c.$table,
  5149. // add position: relative to attach element, hopefully it won't cause trouble.
  5150. $attach = $(wo.stickyHeaders_attachTo || wo.stickyHeaders_appendTo),
  5151. namespace = c.namespace + 'stickyheaders ',
  5152. // element to watch for the scroll event
  5153. $yScroll = $(wo.stickyHeaders_yScroll || wo.stickyHeaders_attachTo || window),
  5154. $xScroll = $(wo.stickyHeaders_xScroll || wo.stickyHeaders_attachTo || window),
  5155. $thead = $table.children('thead:first'),
  5156. $header = $thead.children('tr').not('.sticky-false').children(),
  5157. $tfoot = $table.children('tfoot'),
  5158. stickyOffset = getStickyOffset(c, wo),
  5159. // is this table nested? If so, find parent sticky header wrapper (div, not table)
  5160. $nestedSticky = $table.parent().closest('.' + ts.css.table).hasClass('hasStickyHeaders') ?
  5161. $table.parent().closest('table.tablesorter')[0].config.widgetOptions.$sticky.parent() : [],
  5162. nestedStickyTop = $nestedSticky.length ? $nestedSticky.height() : 0,
  5163. // clone table, then wrap to make sticky header
  5164. $stickyTable = wo.$sticky = $table.clone()
  5165. .addClass('containsStickyHeaders ' + ts.css.sticky + ' ' + wo.stickyHeaders + ' ' + c.namespace.slice(1) + '_extra_table' )
  5166. .wrap('<div class="' + ts.css.stickyWrap + '">'),
  5167. $stickyWrap = $stickyTable.parent()
  5168. .addClass(ts.css.stickyHide)
  5169. .css({
  5170. position : $attach.length ? 'absolute' : 'fixed',
  5171. padding : parseInt( $stickyTable.parent().parent().css('padding-left'), 10 ),
  5172. top : stickyOffset + nestedStickyTop,
  5173. left : 0,
  5174. visibility : 'hidden',
  5175. zIndex : wo.stickyHeaders_zIndex || 2
  5176. }),
  5177. $stickyThead = $stickyTable.children('thead:first'),
  5178. $stickyCells,
  5179. laststate = '',
  5180. setWidth = function($orig, $clone) {
  5181. var index, width, border, $cell, $this,
  5182. $cells = $orig.filter(':visible'),
  5183. len = $cells.length;
  5184. for ( index = 0; index < len; index++ ) {
  5185. $cell = $clone.filter(':visible').eq(index);
  5186. $this = $cells.eq(index);
  5187. // code from https://github.com/jmosbech/StickyTableHeaders
  5188. if ($this.css('box-sizing') === 'border-box') {
  5189. width = $this.outerWidth();
  5190. } else {
  5191. if ($cell.css('border-collapse') === 'collapse') {
  5192. if (window.getComputedStyle) {
  5193. width = parseFloat( window.getComputedStyle($this[0], null).width );
  5194. } else {
  5195. // ie8 only
  5196. border = parseFloat( $this.css('border-width') );
  5197. width = $this.outerWidth() - parseFloat( $this.css('padding-left') ) - parseFloat( $this.css('padding-right') ) - border;
  5198. }
  5199. } else {
  5200. width = $this.width();
  5201. }
  5202. }
  5203. $cell.css({
  5204. 'width': width,
  5205. 'min-width': width,
  5206. 'max-width': width
  5207. });
  5208. }
  5209. },
  5210. getLeftPosition = function(yWindow) {
  5211. if (yWindow === false && $nestedSticky.length) {
  5212. return $table.position().left;
  5213. }
  5214. return $attach.length ?
  5215. parseInt($attach.css('padding-left'), 10) || 0 :
  5216. $table.offset().left - parseInt($table.css('margin-left'), 10) - $(window).scrollLeft();
  5217. },
  5218. resizeHeader = function() {
  5219. $stickyWrap.css({
  5220. left : getLeftPosition(),
  5221. width: $table.outerWidth()
  5222. });
  5223. setWidth( $table, $stickyTable );
  5224. setWidth( $header, $stickyCells );
  5225. },
  5226. scrollSticky = function( resizing ) {
  5227. if (!$table.is(':visible')) { return; } // fixes #278
  5228. // Detect nested tables - fixes #724
  5229. nestedStickyTop = $nestedSticky.length ? $nestedSticky.offset().top - $yScroll.scrollTop() + $nestedSticky.height() : 0;
  5230. var tmp,
  5231. offset = $table.offset(),
  5232. stickyOffset = getStickyOffset(c, wo),
  5233. yWindow = $.isWindow( $yScroll[0] ), // $.isWindow needs jQuery 1.4.3
  5234. yScroll = yWindow ?
  5235. $yScroll.scrollTop() :
  5236. // use parent sticky position if nested AND inside of a scrollable element - see #1512
  5237. $nestedSticky.length ? parseInt($nestedSticky[0].style.top, 10) : $yScroll.offset().top,
  5238. attachTop = $attach.length ? yScroll : $yScroll.scrollTop(),
  5239. captionHeight = wo.stickyHeaders_includeCaption ? 0 : $table.children( 'caption' ).height() || 0,
  5240. scrollTop = attachTop + stickyOffset + nestedStickyTop - captionHeight,
  5241. tableHeight = $table.height() - ($stickyWrap.height() + ($tfoot.height() || 0)) - captionHeight,
  5242. isVisible = ( scrollTop > offset.top ) && ( scrollTop < offset.top + tableHeight ) ? 'visible' : 'hidden',
  5243. state = isVisible === 'visible' ? ts.css.stickyVis : ts.css.stickyHide,
  5244. needsUpdating = !$stickyWrap.hasClass( state ),
  5245. cssSettings = { visibility : isVisible };
  5246. if ($attach.length) {
  5247. // attached sticky headers always need updating
  5248. needsUpdating = true;
  5249. cssSettings.top = yWindow ? scrollTop - $attach.offset().top : $attach.scrollTop();
  5250. }
  5251. // adjust when scrolling horizontally - fixes issue #143
  5252. tmp = getLeftPosition(yWindow);
  5253. if (tmp !== parseInt($stickyWrap.css('left'), 10)) {
  5254. needsUpdating = true;
  5255. cssSettings.left = tmp;
  5256. }
  5257. cssSettings.top = ( cssSettings.top || 0 ) +
  5258. // If nested AND inside of a scrollable element, only add parent sticky height
  5259. (!yWindow && $nestedSticky.length ? $nestedSticky.height() : stickyOffset + nestedStickyTop);
  5260. if (needsUpdating) {
  5261. $stickyWrap
  5262. .removeClass( ts.css.stickyVis + ' ' + ts.css.stickyHide )
  5263. .addClass( state )
  5264. .css(cssSettings);
  5265. }
  5266. if (isVisible !== laststate || resizing) {
  5267. // make sure the column widths match
  5268. resizeHeader();
  5269. laststate = isVisible;
  5270. }
  5271. };
  5272. // only add a position relative if a position isn't already defined
  5273. if ($attach.length && !$attach.css('position')) {
  5274. $attach.css('position', 'relative');
  5275. }
  5276. // fix clone ID, if it exists - fixes #271
  5277. if ($stickyTable.attr('id')) { $stickyTable[0].id += wo.stickyHeaders_cloneId; }
  5278. // clear out cloned table, except for sticky header
  5279. // include caption & filter row (fixes #126 & #249) - don't remove cells to get correct cell indexing
  5280. $stickyTable.find('> thead:gt(0), tr.sticky-false').hide();
  5281. $stickyTable.find('> tbody, > tfoot').remove();
  5282. $stickyTable.find('caption').toggle(wo.stickyHeaders_includeCaption);
  5283. // issue #172 - find td/th in sticky header
  5284. $stickyCells = $stickyThead.children().children();
  5285. $stickyTable.css({ height:0, width:0, margin: 0 });
  5286. // remove resizable block
  5287. $stickyCells.find('.' + ts.css.resizer).remove();
  5288. // update sticky header class names to match real header after sorting
  5289. $table
  5290. .addClass('hasStickyHeaders')
  5291. .bind('pagerComplete' + namespace, function() {
  5292. resizeHeader();
  5293. });
  5294. ts.bindEvents(table, $stickyThead.children().children('.' + ts.css.header));
  5295. if (wo.stickyHeaders_appendTo) {
  5296. $(wo.stickyHeaders_appendTo).append( $stickyWrap );
  5297. } else {
  5298. // add stickyheaders AFTER the table. If the table is selected by ID, the original one (first) will be returned.
  5299. $table.after( $stickyWrap );
  5300. }
  5301. // onRenderHeader is defined, we need to do something about it (fixes #641)
  5302. if (c.onRenderHeader) {
  5303. $t = $stickyThead.children('tr').children();
  5304. len = $t.length;
  5305. for ( index = 0; index < len; index++ ) {
  5306. // send second parameter
  5307. c.onRenderHeader.apply( $t.eq( index ), [ index, c, $stickyTable ] );
  5308. }
  5309. }
  5310. // make it sticky!
  5311. $xScroll.add($yScroll)
  5312. .unbind( ('scroll resize '.split(' ').join( namespace )).replace(/\s+/g, ' ') )
  5313. .bind('scroll resize '.split(' ').join( namespace ), function( event ) {
  5314. scrollSticky( event.type === 'resize' );
  5315. });
  5316. c.$table
  5317. .unbind('stickyHeadersUpdate' + namespace)
  5318. .bind('stickyHeadersUpdate' + namespace, function() {
  5319. scrollSticky( true );
  5320. });
  5321. if (wo.stickyHeaders_addResizeEvent) {
  5322. ts.addHeaderResizeEvent(table);
  5323. }
  5324. // look for filter widget
  5325. if ($table.hasClass('hasFilters') && wo.filter_columnFilters) {
  5326. // scroll table into view after filtering, if sticky header is active - #482
  5327. $table.bind('filterEnd' + namespace, function() {
  5328. // $(':focus') needs jQuery 1.6+
  5329. var $td = $(document.activeElement).closest('td'),
  5330. column = $td.parent().children().index($td);
  5331. // only scroll if sticky header is active
  5332. if ($stickyWrap.hasClass(ts.css.stickyVis) && wo.stickyHeaders_filteredToTop) {
  5333. // scroll to original table (not sticky clone)
  5334. window.scrollTo(0, $table.position().top);
  5335. // give same input/select focus; check if c.$filters exists; fixes #594
  5336. if (column >= 0 && c.$filters) {
  5337. c.$filters.eq(column).find('a, select, input').filter(':visible').focus();
  5338. }
  5339. }
  5340. });
  5341. ts.filter.bindSearch( $table, $stickyCells.find('.' + ts.css.filter) );
  5342. // support hideFilters
  5343. if (wo.filter_hideFilters) {
  5344. ts.filter.hideFilters(c, $stickyTable);
  5345. }
  5346. }
  5347. // resize table (Firefox)
  5348. if (wo.stickyHeaders_addResizeEvent) {
  5349. $table.bind('resize' + c.namespace + 'stickyheaders', function() {
  5350. resizeHeader();
  5351. });
  5352. }
  5353. // make sure sticky is visible if page is partially scrolled
  5354. scrollSticky( true );
  5355. $table.triggerHandler('stickyHeadersInit');
  5356. },
  5357. remove: function(table, c, wo) {
  5358. var namespace = c.namespace + 'stickyheaders ';
  5359. c.$table
  5360. .removeClass('hasStickyHeaders')
  5361. .unbind( ('pagerComplete resize filterEnd stickyHeadersUpdate '.split(' ').join(namespace)).replace(/\s+/g, ' ') )
  5362. .next('.' + ts.css.stickyWrap).remove();
  5363. if (wo.$sticky && wo.$sticky.length) { wo.$sticky.remove(); } // remove cloned table
  5364. $(window)
  5365. .add(wo.stickyHeaders_xScroll)
  5366. .add(wo.stickyHeaders_yScroll)
  5367. .add(wo.stickyHeaders_attachTo)
  5368. .unbind( ('scroll resize '.split(' ').join(namespace)).replace(/\s+/g, ' ') );
  5369. ts.addHeaderResizeEvent(table, true);
  5370. }
  5371. });
  5372. })(jQuery, window);
  5373. /*! Widget: resizable - updated 2018-03-26 (v2.30.2) */
  5374. /*jshint browser:true, jquery:true, unused:false */
  5375. ;(function ($, window) {
  5376. 'use strict';
  5377. var ts = $.tablesorter || {};
  5378. $.extend(ts.css, {
  5379. resizableContainer : 'tablesorter-resizable-container',
  5380. resizableHandle : 'tablesorter-resizable-handle',
  5381. resizableNoSelect : 'tablesorter-disableSelection',
  5382. resizableStorage : 'tablesorter-resizable'
  5383. });
  5384. // Add extra scroller css
  5385. $(function() {
  5386. var s = '<style>' +
  5387. 'body.' + ts.css.resizableNoSelect + ' { -ms-user-select: none; -moz-user-select: -moz-none;' +
  5388. '-khtml-user-select: none; -webkit-user-select: none; user-select: none; }' +
  5389. '.' + ts.css.resizableContainer + ' { position: relative; height: 1px; }' +
  5390. // make handle z-index > than stickyHeader z-index, so the handle stays above sticky header
  5391. '.' + ts.css.resizableHandle + ' { position: absolute; display: inline-block; width: 8px;' +
  5392. 'top: 1px; cursor: ew-resize; z-index: 3; user-select: none; -moz-user-select: none; }' +
  5393. '</style>';
  5394. $('head').append(s);
  5395. });
  5396. ts.resizable = {
  5397. init : function( c, wo ) {
  5398. if ( c.$table.hasClass( 'hasResizable' ) ) { return; }
  5399. c.$table.addClass( 'hasResizable' );
  5400. var noResize, $header, column, storedSizes, tmp,
  5401. $table = c.$table,
  5402. $parent = $table.parent(),
  5403. marginTop = parseInt( $table.css( 'margin-top' ), 10 ),
  5404. // internal variables
  5405. vars = wo.resizable_vars = {
  5406. useStorage : ts.storage && wo.resizable !== false,
  5407. $wrap : $parent,
  5408. mouseXPosition : 0,
  5409. $target : null,
  5410. $next : null,
  5411. overflow : $parent.css('overflow') === 'auto' ||
  5412. $parent.css('overflow') === 'scroll' ||
  5413. $parent.css('overflow-x') === 'auto' ||
  5414. $parent.css('overflow-x') === 'scroll',
  5415. storedSizes : []
  5416. };
  5417. // set default widths
  5418. ts.resizableReset( c.table, true );
  5419. // now get measurements!
  5420. vars.tableWidth = $table.width();
  5421. // attempt to autodetect
  5422. vars.fullWidth = Math.abs( $parent.width() - vars.tableWidth ) < 20;
  5423. /*
  5424. // Hacky method to determine if table width is set to 'auto'
  5425. // http://stackoverflow.com/a/20892048/145346
  5426. if ( !vars.fullWidth ) {
  5427. tmp = $table.width();
  5428. $header = $table.wrap('<span>').parent(); // temp variable
  5429. storedSizes = parseInt( $table.css( 'margin-left' ), 10 ) || 0;
  5430. $table.css( 'margin-left', storedSizes + 50 );
  5431. vars.tableWidth = $header.width() > tmp ? 'auto' : tmp;
  5432. $table.css( 'margin-left', storedSizes ? storedSizes : '' );
  5433. $header = null;
  5434. $table.unwrap('<span>');
  5435. }
  5436. */
  5437. if ( vars.useStorage && vars.overflow ) {
  5438. // save table width
  5439. ts.storage( c.table, 'tablesorter-table-original-css-width', vars.tableWidth );
  5440. tmp = ts.storage( c.table, 'tablesorter-table-resized-width' ) || 'auto';
  5441. ts.resizable.setWidth( $table, tmp, true );
  5442. }
  5443. wo.resizable_vars.storedSizes = storedSizes = ( vars.useStorage ?
  5444. ts.storage( c.table, ts.css.resizableStorage ) :
  5445. [] ) || [];
  5446. ts.resizable.setWidths( c, wo, storedSizes );
  5447. ts.resizable.updateStoredSizes( c, wo );
  5448. wo.$resizable_container = $( '<div class="' + ts.css.resizableContainer + '">' )
  5449. .css({ top : marginTop })
  5450. .insertBefore( $table );
  5451. // add container
  5452. for ( column = 0; column < c.columns; column++ ) {
  5453. $header = c.$headerIndexed[ column ];
  5454. tmp = ts.getColumnData( c.table, c.headers, column );
  5455. noResize = ts.getData( $header, tmp, 'resizable' ) === 'false';
  5456. if ( !noResize ) {
  5457. $( '<div class="' + ts.css.resizableHandle + '">' )
  5458. .appendTo( wo.$resizable_container )
  5459. .attr({
  5460. 'data-column' : column,
  5461. 'unselectable' : 'on'
  5462. })
  5463. .data( 'header', $header )
  5464. .bind( 'selectstart', false );
  5465. }
  5466. }
  5467. ts.resizable.bindings( c, wo );
  5468. },
  5469. updateStoredSizes : function( c, wo ) {
  5470. var column, $header,
  5471. len = c.columns,
  5472. vars = wo.resizable_vars;
  5473. vars.storedSizes = [];
  5474. for ( column = 0; column < len; column++ ) {
  5475. $header = c.$headerIndexed[ column ];
  5476. vars.storedSizes[ column ] = $header.is(':visible') ? $header.width() : 0;
  5477. }
  5478. },
  5479. setWidth : function( $el, width, overflow ) {
  5480. // overflow tables need min & max width set as well
  5481. $el.css({
  5482. 'width' : width,
  5483. 'min-width' : overflow ? width : '',
  5484. 'max-width' : overflow ? width : ''
  5485. });
  5486. },
  5487. setWidths : function( c, wo, storedSizes ) {
  5488. var column, $temp,
  5489. vars = wo.resizable_vars,
  5490. $extra = $( c.namespace + '_extra_headers' ),
  5491. $col = c.$table.children( 'colgroup' ).children( 'col' );
  5492. storedSizes = storedSizes || vars.storedSizes || [];
  5493. // process only if table ID or url match
  5494. if ( storedSizes.length ) {
  5495. for ( column = 0; column < c.columns; column++ ) {
  5496. // set saved resizable widths
  5497. ts.resizable.setWidth( c.$headerIndexed[ column ], storedSizes[ column ], vars.overflow );
  5498. if ( $extra.length ) {
  5499. // stickyHeaders needs to modify min & max width as well
  5500. $temp = $extra.eq( column ).add( $col.eq( column ) );
  5501. ts.resizable.setWidth( $temp, storedSizes[ column ], vars.overflow );
  5502. }
  5503. }
  5504. $temp = $( c.namespace + '_extra_table' );
  5505. if ( $temp.length && !ts.hasWidget( c.table, 'scroller' ) ) {
  5506. ts.resizable.setWidth( $temp, c.$table.outerWidth(), vars.overflow );
  5507. }
  5508. }
  5509. },
  5510. setHandlePosition : function( c, wo ) {
  5511. var startPosition,
  5512. tableHeight = c.$table.height(),
  5513. $handles = wo.$resizable_container.children(),
  5514. handleCenter = Math.floor( $handles.width() / 2 );
  5515. if ( ts.hasWidget( c.table, 'scroller' ) ) {
  5516. tableHeight = 0;
  5517. c.$table.closest( '.' + ts.css.scrollerWrap ).children().each(function() {
  5518. var $this = $(this);
  5519. // center table has a max-height set
  5520. tableHeight += $this.filter('[style*="height"]').length ? $this.height() : $this.children('table').height();
  5521. });
  5522. }
  5523. if ( !wo.resizable_includeFooter && c.$table.children('tfoot').length ) {
  5524. tableHeight -= c.$table.children('tfoot').height();
  5525. }
  5526. // subtract out table left position from resizable handles. Fixes #864
  5527. // jQuery v3.3.0+ appears to include the start position with the $header.position().left; see #1544
  5528. startPosition = parseFloat($.fn.jquery) >= 3.3 ? 0 : c.$table.position().left;
  5529. $handles.each( function() {
  5530. var $this = $(this),
  5531. column = parseInt( $this.attr( 'data-column' ), 10 ),
  5532. columns = c.columns - 1,
  5533. $header = $this.data( 'header' );
  5534. if ( !$header ) { return; } // see #859
  5535. if (
  5536. !$header.is(':visible') ||
  5537. ( !wo.resizable_addLastColumn && ts.resizable.checkVisibleColumns(c, column) )
  5538. ) {
  5539. $this.hide();
  5540. } else if ( column < columns || column === columns && wo.resizable_addLastColumn ) {
  5541. $this.css({
  5542. display: 'inline-block',
  5543. height : tableHeight,
  5544. left : $header.position().left - startPosition + $header.outerWidth() - handleCenter
  5545. });
  5546. }
  5547. });
  5548. },
  5549. // Fixes #1485
  5550. checkVisibleColumns: function( c, column ) {
  5551. var i,
  5552. len = 0;
  5553. for ( i = column + 1; i < c.columns; i++ ) {
  5554. len += c.$headerIndexed[i].is( ':visible' ) ? 1 : 0;
  5555. }
  5556. return len === 0;
  5557. },
  5558. // prevent text selection while dragging resize bar
  5559. toggleTextSelection : function( c, wo, toggle ) {
  5560. var namespace = c.namespace + 'tsresize';
  5561. wo.resizable_vars.disabled = toggle;
  5562. $( 'body' ).toggleClass( ts.css.resizableNoSelect, toggle );
  5563. if ( toggle ) {
  5564. $( 'body' )
  5565. .attr( 'unselectable', 'on' )
  5566. .bind( 'selectstart' + namespace, false );
  5567. } else {
  5568. $( 'body' )
  5569. .removeAttr( 'unselectable' )
  5570. .unbind( 'selectstart' + namespace );
  5571. }
  5572. },
  5573. bindings : function( c, wo ) {
  5574. var namespace = c.namespace + 'tsresize';
  5575. wo.$resizable_container.children().bind( 'mousedown', function( event ) {
  5576. // save header cell and mouse position
  5577. var column,
  5578. vars = wo.resizable_vars,
  5579. $extras = $( c.namespace + '_extra_headers' ),
  5580. $header = $( event.target ).data( 'header' );
  5581. column = parseInt( $header.attr( 'data-column' ), 10 );
  5582. vars.$target = $header = $header.add( $extras.filter('[data-column="' + column + '"]') );
  5583. vars.target = column;
  5584. // if table is not as wide as it's parent, then resize the table
  5585. vars.$next = event.shiftKey || wo.resizable_targetLast ?
  5586. $header.parent().children().not( '.resizable-false' ).filter( ':last' ) :
  5587. $header.nextAll( ':not(.resizable-false)' ).eq( 0 );
  5588. column = parseInt( vars.$next.attr( 'data-column' ), 10 );
  5589. vars.$next = vars.$next.add( $extras.filter('[data-column="' + column + '"]') );
  5590. vars.next = column;
  5591. vars.mouseXPosition = event.pageX;
  5592. ts.resizable.updateStoredSizes( c, wo );
  5593. ts.resizable.toggleTextSelection(c, wo, true );
  5594. });
  5595. $( document )
  5596. .bind( 'mousemove' + namespace, function( event ) {
  5597. var vars = wo.resizable_vars;
  5598. // ignore mousemove if no mousedown
  5599. if ( !vars.disabled || vars.mouseXPosition === 0 || !vars.$target ) { return; }
  5600. if ( wo.resizable_throttle ) {
  5601. clearTimeout( vars.timer );
  5602. vars.timer = setTimeout( function() {
  5603. ts.resizable.mouseMove( c, wo, event );
  5604. }, isNaN( wo.resizable_throttle ) ? 5 : wo.resizable_throttle );
  5605. } else {
  5606. ts.resizable.mouseMove( c, wo, event );
  5607. }
  5608. })
  5609. .bind( 'mouseup' + namespace, function() {
  5610. if (!wo.resizable_vars.disabled) { return; }
  5611. ts.resizable.toggleTextSelection( c, wo, false );
  5612. ts.resizable.stopResize( c, wo );
  5613. ts.resizable.setHandlePosition( c, wo );
  5614. });
  5615. // resizeEnd event triggered by scroller widget
  5616. $( window ).bind( 'resize' + namespace + ' resizeEnd' + namespace, function() {
  5617. ts.resizable.setHandlePosition( c, wo );
  5618. });
  5619. // right click to reset columns to default widths
  5620. c.$table
  5621. .bind( 'columnUpdate pagerComplete resizableUpdate '.split( ' ' ).join( namespace + ' ' ), function() {
  5622. ts.resizable.setHandlePosition( c, wo );
  5623. })
  5624. .bind( 'resizableReset' + namespace, function() {
  5625. ts.resizableReset( c.table );
  5626. })
  5627. .find( 'thead:first' )
  5628. .add( $( c.namespace + '_extra_table' ).find( 'thead:first' ) )
  5629. .bind( 'contextmenu' + namespace, function() {
  5630. // $.isEmptyObject() needs jQuery 1.4+; allow right click if already reset
  5631. var allowClick = wo.resizable_vars.storedSizes.length === 0;
  5632. ts.resizableReset( c.table );
  5633. ts.resizable.setHandlePosition( c, wo );
  5634. wo.resizable_vars.storedSizes = [];
  5635. return allowClick;
  5636. });
  5637. },
  5638. mouseMove : function( c, wo, event ) {
  5639. if ( wo.resizable_vars.mouseXPosition === 0 || !wo.resizable_vars.$target ) { return; }
  5640. // resize columns
  5641. var column,
  5642. total = 0,
  5643. vars = wo.resizable_vars,
  5644. $next = vars.$next,
  5645. tar = vars.storedSizes[ vars.target ],
  5646. leftEdge = event.pageX - vars.mouseXPosition;
  5647. if ( vars.overflow ) {
  5648. if ( tar + leftEdge > 0 ) {
  5649. vars.storedSizes[ vars.target ] += leftEdge;
  5650. ts.resizable.setWidth( vars.$target, vars.storedSizes[ vars.target ], true );
  5651. // update the entire table width
  5652. for ( column = 0; column < c.columns; column++ ) {
  5653. total += vars.storedSizes[ column ];
  5654. }
  5655. ts.resizable.setWidth( c.$table.add( $( c.namespace + '_extra_table' ) ), total );
  5656. }
  5657. if ( !$next.length ) {
  5658. // if expanding right-most column, scroll the wrapper
  5659. vars.$wrap[0].scrollLeft = c.$table.width();
  5660. }
  5661. } else if ( vars.fullWidth ) {
  5662. vars.storedSizes[ vars.target ] += leftEdge;
  5663. vars.storedSizes[ vars.next ] -= leftEdge;
  5664. ts.resizable.setWidths( c, wo );
  5665. } else {
  5666. vars.storedSizes[ vars.target ] += leftEdge;
  5667. ts.resizable.setWidths( c, wo );
  5668. }
  5669. vars.mouseXPosition = event.pageX;
  5670. // dynamically update sticky header widths
  5671. c.$table.triggerHandler('stickyHeadersUpdate');
  5672. },
  5673. stopResize : function( c, wo ) {
  5674. var vars = wo.resizable_vars;
  5675. ts.resizable.updateStoredSizes( c, wo );
  5676. if ( vars.useStorage ) {
  5677. // save all column widths
  5678. ts.storage( c.table, ts.css.resizableStorage, vars.storedSizes );
  5679. ts.storage( c.table, 'tablesorter-table-resized-width', c.$table.width() );
  5680. }
  5681. vars.mouseXPosition = 0;
  5682. vars.$target = vars.$next = null;
  5683. // will update stickyHeaders, just in case, see #912
  5684. c.$table.triggerHandler('stickyHeadersUpdate');
  5685. c.$table.triggerHandler('resizableComplete');
  5686. }
  5687. };
  5688. // this widget saves the column widths if
  5689. // $.tablesorter.storage function is included
  5690. // **************************
  5691. ts.addWidget({
  5692. id: 'resizable',
  5693. priority: 40,
  5694. options: {
  5695. resizable : true, // save column widths to storage
  5696. resizable_addLastColumn : false,
  5697. resizable_includeFooter: true,
  5698. resizable_widths : [],
  5699. resizable_throttle : false, // set to true (5ms) or any number 0-10 range
  5700. resizable_targetLast : false
  5701. },
  5702. init: function(table, thisWidget, c, wo) {
  5703. ts.resizable.init( c, wo );
  5704. },
  5705. format: function( table, c, wo ) {
  5706. ts.resizable.setHandlePosition( c, wo );
  5707. },
  5708. remove: function( table, c, wo, refreshing ) {
  5709. if (wo.$resizable_container) {
  5710. var namespace = c.namespace + 'tsresize';
  5711. c.$table.add( $( c.namespace + '_extra_table' ) )
  5712. .removeClass('hasResizable')
  5713. .children( 'thead' )
  5714. .unbind( 'contextmenu' + namespace );
  5715. wo.$resizable_container.remove();
  5716. ts.resizable.toggleTextSelection( c, wo, false );
  5717. ts.resizableReset( table, refreshing );
  5718. $( document ).unbind( 'mousemove' + namespace + ' mouseup' + namespace );
  5719. }
  5720. }
  5721. });
  5722. ts.resizableReset = function( table, refreshing ) {
  5723. $( table ).each(function() {
  5724. var index, $t,
  5725. c = this.config,
  5726. wo = c && c.widgetOptions,
  5727. vars = wo.resizable_vars;
  5728. if ( table && c && c.$headerIndexed.length ) {
  5729. // restore the initial table width
  5730. if ( vars.overflow && vars.tableWidth ) {
  5731. ts.resizable.setWidth( c.$table, vars.tableWidth, true );
  5732. if ( vars.useStorage ) {
  5733. ts.storage( table, 'tablesorter-table-resized-width', vars.tableWidth );
  5734. }
  5735. }
  5736. for ( index = 0; index < c.columns; index++ ) {
  5737. $t = c.$headerIndexed[ index ];
  5738. if ( wo.resizable_widths && wo.resizable_widths[ index ] ) {
  5739. ts.resizable.setWidth( $t, wo.resizable_widths[ index ], vars.overflow );
  5740. } else if ( !$t.hasClass( 'resizable-false' ) ) {
  5741. // don't clear the width of any column that is not resizable
  5742. ts.resizable.setWidth( $t, '', vars.overflow );
  5743. }
  5744. }
  5745. // reset stickyHeader widths
  5746. c.$table.triggerHandler( 'stickyHeadersUpdate' );
  5747. if ( ts.storage && !refreshing ) {
  5748. ts.storage( this, ts.css.resizableStorage, [] );
  5749. }
  5750. }
  5751. });
  5752. };
  5753. })( jQuery, window );
  5754. /*! Widget: saveSort - updated 2018-03-19 (v2.30.1) *//*
  5755. * Requires tablesorter v2.16+
  5756. * by Rob Garrison
  5757. */
  5758. ;(function ($) {
  5759. 'use strict';
  5760. var ts = $.tablesorter || {};
  5761. function getStoredSortList(c) {
  5762. var stored = ts.storage( c.table, 'tablesorter-savesort' );
  5763. return (stored && stored.hasOwnProperty('sortList') && $.isArray(stored.sortList)) ? stored.sortList : [];
  5764. }
  5765. function sortListChanged(c, sortList) {
  5766. return (sortList || getStoredSortList(c)).join(',') !== c.sortList.join(',');
  5767. }
  5768. // this widget saves the last sort only if the
  5769. // saveSort widget option is true AND the
  5770. // $.tablesorter.storage function is included
  5771. // **************************
  5772. ts.addWidget({
  5773. id: 'saveSort',
  5774. priority: 20,
  5775. options: {
  5776. saveSort : true
  5777. },
  5778. init: function(table, thisWidget, c, wo) {
  5779. // run widget format before all other widgets are applied to the table
  5780. thisWidget.format(table, c, wo, true);
  5781. },
  5782. format: function(table, c, wo, init) {
  5783. var time,
  5784. $table = c.$table,
  5785. saveSort = wo.saveSort !== false, // make saveSort active/inactive; default to true
  5786. sortList = { 'sortList' : c.sortList },
  5787. debug = ts.debug(c, 'saveSort');
  5788. if (debug) {
  5789. time = new Date();
  5790. }
  5791. if ($table.hasClass('hasSaveSort')) {
  5792. if (saveSort && table.hasInitialized && ts.storage && sortListChanged(c)) {
  5793. ts.storage( table, 'tablesorter-savesort', sortList );
  5794. if (debug) {
  5795. console.log('saveSort >> Saving last sort: ' + c.sortList + ts.benchmark(time));
  5796. }
  5797. }
  5798. } else {
  5799. // set table sort on initial run of the widget
  5800. $table.addClass('hasSaveSort');
  5801. sortList = '';
  5802. // get data
  5803. if (ts.storage) {
  5804. sortList = getStoredSortList(c);
  5805. if (debug) {
  5806. console.log('saveSort >> Last sort loaded: "' + sortList + '"' + ts.benchmark(time));
  5807. }
  5808. $table.bind('saveSortReset', function(event) {
  5809. event.stopPropagation();
  5810. ts.storage( table, 'tablesorter-savesort', '' );
  5811. });
  5812. }
  5813. // init is true when widget init is run, this will run this widget before all other widgets have initialized
  5814. // this method allows using this widget in the original tablesorter plugin; but then it will run all widgets twice.
  5815. if (init && sortList && sortList.length > 0) {
  5816. c.sortList = sortList;
  5817. } else if (table.hasInitialized && sortList && sortList.length > 0) {
  5818. // update sort change
  5819. if (sortListChanged(c, sortList)) {
  5820. ts.sortOn(c, sortList);
  5821. }
  5822. }
  5823. }
  5824. },
  5825. remove: function(table, c) {
  5826. c.$table.removeClass('hasSaveSort');
  5827. // clear storage
  5828. if (ts.storage) { ts.storage( table, 'tablesorter-savesort', '' ); }
  5829. }
  5830. });
  5831. })(jQuery);
  5832. return jQuery.tablesorter;}));