select2.full.js 164 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614
  1. /*!
  2. * Select2 4.0.6-rc.1
  3. * https://select2.github.io
  4. *
  5. * Released under the MIT license
  6. * https://github.com/select2/select2/blob/master/LICENSE.md
  7. */
  8. ;(function (factory) {
  9. if (typeof define === 'function' && define.amd) {
  10. // AMD. Register as an anonymous module.
  11. define(['jquery'], factory);
  12. } else if (typeof module === 'object' && module.exports) {
  13. // Node/CommonJS
  14. module.exports = function (root, jQuery) {
  15. if (jQuery === undefined) {
  16. // require('jQuery') returns a factory that requires window to
  17. // build a jQuery instance, we normalize how we use modules
  18. // that require this pattern but the window provided is a noop
  19. // if it's defined (how jquery works)
  20. if (typeof window !== 'undefined') {
  21. jQuery = require('jquery');
  22. }
  23. else {
  24. jQuery = require('jquery')(root);
  25. }
  26. }
  27. factory(jQuery);
  28. return jQuery;
  29. };
  30. } else {
  31. // Browser globals
  32. factory(jQuery);
  33. }
  34. } (function (jQuery) {
  35. // This is needed so we can catch the AMD loader configuration and use it
  36. // The inner file should be wrapped (by `banner.start.js`) in a function that
  37. // returns the AMD loader references.
  38. var S2 =(function () {
  39. // Restore the Select2 AMD loader so it can be used
  40. // Needed mostly in the language files, where the loader is not inserted
  41. if (jQuery && jQuery.fn && jQuery.fn.select2 && jQuery.fn.select2.amd) {
  42. var S2 = jQuery.fn.select2.amd;
  43. }
  44. var S2;(function () { if (!S2 || !S2.requirejs) {
  45. if (!S2) { S2 = {}; } else { require = S2; }
  46. /**
  47. * @license almond 0.3.3 Copyright jQuery Foundation and other contributors.
  48. * Released under MIT license, http://github.com/requirejs/almond/LICENSE
  49. */
  50. //Going sloppy to avoid 'use strict' string cost, but strict practices should
  51. //be followed.
  52. /*global setTimeout: false */
  53. var requirejs, require, define;
  54. (function (undef) {
  55. var main, req, makeMap, handlers,
  56. defined = {},
  57. waiting = {},
  58. config = {},
  59. defining = {},
  60. hasOwn = Object.prototype.hasOwnProperty,
  61. aps = [].slice,
  62. jsSuffixRegExp = /\.js$/;
  63. function hasProp(obj, prop) {
  64. return hasOwn.call(obj, prop);
  65. }
  66. /**
  67. * Given a relative module name, like ./something, normalize it to
  68. * a real name that can be mapped to a path.
  69. * @param {String} name the relative name
  70. * @param {String} baseName a real name that the name arg is relative
  71. * to.
  72. * @returns {String} normalized name
  73. */
  74. function normalize(name, baseName) {
  75. var nameParts, nameSegment, mapValue, foundMap, lastIndex,
  76. foundI, foundStarMap, starI, i, j, part, normalizedBaseParts,
  77. baseParts = baseName && baseName.split("/"),
  78. map = config.map,
  79. starMap = (map && map['*']) || {};
  80. //Adjust any relative paths.
  81. if (name) {
  82. name = name.split('/');
  83. lastIndex = name.length - 1;
  84. // If wanting node ID compatibility, strip .js from end
  85. // of IDs. Have to do this here, and not in nameToUrl
  86. // because node allows either .js or non .js to map
  87. // to same file.
  88. if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
  89. name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
  90. }
  91. // Starts with a '.' so need the baseName
  92. if (name[0].charAt(0) === '.' && baseParts) {
  93. //Convert baseName to array, and lop off the last part,
  94. //so that . matches that 'directory' and not name of the baseName's
  95. //module. For instance, baseName of 'one/two/three', maps to
  96. //'one/two/three.js', but we want the directory, 'one/two' for
  97. //this normalization.
  98. normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
  99. name = normalizedBaseParts.concat(name);
  100. }
  101. //start trimDots
  102. for (i = 0; i < name.length; i++) {
  103. part = name[i];
  104. if (part === '.') {
  105. name.splice(i, 1);
  106. i -= 1;
  107. } else if (part === '..') {
  108. // If at the start, or previous value is still ..,
  109. // keep them so that when converted to a path it may
  110. // still work when converted to a path, even though
  111. // as an ID it is less than ideal. In larger point
  112. // releases, may be better to just kick out an error.
  113. if (i === 0 || (i === 1 && name[2] === '..') || name[i - 1] === '..') {
  114. continue;
  115. } else if (i > 0) {
  116. name.splice(i - 1, 2);
  117. i -= 2;
  118. }
  119. }
  120. }
  121. //end trimDots
  122. name = name.join('/');
  123. }
  124. //Apply map config if available.
  125. if ((baseParts || starMap) && map) {
  126. nameParts = name.split('/');
  127. for (i = nameParts.length; i > 0; i -= 1) {
  128. nameSegment = nameParts.slice(0, i).join("/");
  129. if (baseParts) {
  130. //Find the longest baseName segment match in the config.
  131. //So, do joins on the biggest to smallest lengths of baseParts.
  132. for (j = baseParts.length; j > 0; j -= 1) {
  133. mapValue = map[baseParts.slice(0, j).join('/')];
  134. //baseName segment has config, find if it has one for
  135. //this name.
  136. if (mapValue) {
  137. mapValue = mapValue[nameSegment];
  138. if (mapValue) {
  139. //Match, update name to the new value.
  140. foundMap = mapValue;
  141. foundI = i;
  142. break;
  143. }
  144. }
  145. }
  146. }
  147. if (foundMap) {
  148. break;
  149. }
  150. //Check for a star map match, but just hold on to it,
  151. //if there is a shorter segment match later in a matching
  152. //config, then favor over this star map.
  153. if (!foundStarMap && starMap && starMap[nameSegment]) {
  154. foundStarMap = starMap[nameSegment];
  155. starI = i;
  156. }
  157. }
  158. if (!foundMap && foundStarMap) {
  159. foundMap = foundStarMap;
  160. foundI = starI;
  161. }
  162. if (foundMap) {
  163. nameParts.splice(0, foundI, foundMap);
  164. name = nameParts.join('/');
  165. }
  166. }
  167. return name;
  168. }
  169. function makeRequire(relName, forceSync) {
  170. return function () {
  171. //A version of a require function that passes a moduleName
  172. //value for items that may need to
  173. //look up paths relative to the moduleName
  174. var args = aps.call(arguments, 0);
  175. //If first arg is not require('string'), and there is only
  176. //one arg, it is the array form without a callback. Insert
  177. //a null so that the following concat is correct.
  178. if (typeof args[0] !== 'string' && args.length === 1) {
  179. args.push(null);
  180. }
  181. return req.apply(undef, args.concat([relName, forceSync]));
  182. };
  183. }
  184. function makeNormalize(relName) {
  185. return function (name) {
  186. return normalize(name, relName);
  187. };
  188. }
  189. function makeLoad(depName) {
  190. return function (value) {
  191. defined[depName] = value;
  192. };
  193. }
  194. function callDep(name) {
  195. if (hasProp(waiting, name)) {
  196. var args = waiting[name];
  197. delete waiting[name];
  198. defining[name] = true;
  199. main.apply(undef, args);
  200. }
  201. if (!hasProp(defined, name) && !hasProp(defining, name)) {
  202. throw new Error('No ' + name);
  203. }
  204. return defined[name];
  205. }
  206. //Turns a plugin!resource to [plugin, resource]
  207. //with the plugin being undefined if the name
  208. //did not have a plugin prefix.
  209. function splitPrefix(name) {
  210. var prefix,
  211. index = name ? name.indexOf('!') : -1;
  212. if (index > -1) {
  213. prefix = name.substring(0, index);
  214. name = name.substring(index + 1, name.length);
  215. }
  216. return [prefix, name];
  217. }
  218. //Creates a parts array for a relName where first part is plugin ID,
  219. //second part is resource ID. Assumes relName has already been normalized.
  220. function makeRelParts(relName) {
  221. return relName ? splitPrefix(relName) : [];
  222. }
  223. /**
  224. * Makes a name map, normalizing the name, and using a plugin
  225. * for normalization if necessary. Grabs a ref to plugin
  226. * too, as an optimization.
  227. */
  228. makeMap = function (name, relParts) {
  229. var plugin,
  230. parts = splitPrefix(name),
  231. prefix = parts[0],
  232. relResourceName = relParts[1];
  233. name = parts[1];
  234. if (prefix) {
  235. prefix = normalize(prefix, relResourceName);
  236. plugin = callDep(prefix);
  237. }
  238. //Normalize according
  239. if (prefix) {
  240. if (plugin && plugin.normalize) {
  241. name = plugin.normalize(name, makeNormalize(relResourceName));
  242. } else {
  243. name = normalize(name, relResourceName);
  244. }
  245. } else {
  246. name = normalize(name, relResourceName);
  247. parts = splitPrefix(name);
  248. prefix = parts[0];
  249. name = parts[1];
  250. if (prefix) {
  251. plugin = callDep(prefix);
  252. }
  253. }
  254. //Using ridiculous property names for space reasons
  255. return {
  256. f: prefix ? prefix + '!' + name : name, //fullName
  257. n: name,
  258. pr: prefix,
  259. p: plugin
  260. };
  261. };
  262. function makeConfig(name) {
  263. return function () {
  264. return (config && config.config && config.config[name]) || {};
  265. };
  266. }
  267. handlers = {
  268. require: function (name) {
  269. return makeRequire(name);
  270. },
  271. exports: function (name) {
  272. var e = defined[name];
  273. if (typeof e !== 'undefined') {
  274. return e;
  275. } else {
  276. return (defined[name] = {});
  277. }
  278. },
  279. module: function (name) {
  280. return {
  281. id: name,
  282. uri: '',
  283. exports: defined[name],
  284. config: makeConfig(name)
  285. };
  286. }
  287. };
  288. main = function (name, deps, callback, relName) {
  289. var cjsModule, depName, ret, map, i, relParts,
  290. args = [],
  291. callbackType = typeof callback,
  292. usingExports;
  293. //Use name if no relName
  294. relName = relName || name;
  295. relParts = makeRelParts(relName);
  296. //Call the callback to define the module, if necessary.
  297. if (callbackType === 'undefined' || callbackType === 'function') {
  298. //Pull out the defined dependencies and pass the ordered
  299. //values to the callback.
  300. //Default to [require, exports, module] if no deps
  301. deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
  302. for (i = 0; i < deps.length; i += 1) {
  303. map = makeMap(deps[i], relParts);
  304. depName = map.f;
  305. //Fast path CommonJS standard dependencies.
  306. if (depName === "require") {
  307. args[i] = handlers.require(name);
  308. } else if (depName === "exports") {
  309. //CommonJS module spec 1.1
  310. args[i] = handlers.exports(name);
  311. usingExports = true;
  312. } else if (depName === "module") {
  313. //CommonJS module spec 1.1
  314. cjsModule = args[i] = handlers.module(name);
  315. } else if (hasProp(defined, depName) ||
  316. hasProp(waiting, depName) ||
  317. hasProp(defining, depName)) {
  318. args[i] = callDep(depName);
  319. } else if (map.p) {
  320. map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {});
  321. args[i] = defined[depName];
  322. } else {
  323. throw new Error(name + ' missing ' + depName);
  324. }
  325. }
  326. ret = callback ? callback.apply(defined[name], args) : undefined;
  327. if (name) {
  328. //If setting exports via "module" is in play,
  329. //favor that over return value and exports. After that,
  330. //favor a non-undefined return value over exports use.
  331. if (cjsModule && cjsModule.exports !== undef &&
  332. cjsModule.exports !== defined[name]) {
  333. defined[name] = cjsModule.exports;
  334. } else if (ret !== undef || !usingExports) {
  335. //Use the return value from the function.
  336. defined[name] = ret;
  337. }
  338. }
  339. } else if (name) {
  340. //May just be an object definition for the module. Only
  341. //worry about defining if have a module name.
  342. defined[name] = callback;
  343. }
  344. };
  345. requirejs = require = req = function (deps, callback, relName, forceSync, alt) {
  346. if (typeof deps === "string") {
  347. if (handlers[deps]) {
  348. //callback in this case is really relName
  349. return handlers[deps](callback);
  350. }
  351. //Just return the module wanted. In this scenario, the
  352. //deps arg is the module name, and second arg (if passed)
  353. //is just the relName.
  354. //Normalize module name, if it contains . or ..
  355. return callDep(makeMap(deps, makeRelParts(callback)).f);
  356. } else if (!deps.splice) {
  357. //deps is a config object, not an array.
  358. config = deps;
  359. if (config.deps) {
  360. req(config.deps, config.callback);
  361. }
  362. if (!callback) {
  363. return;
  364. }
  365. if (callback.splice) {
  366. //callback is an array, which means it is a dependency list.
  367. //Adjust args if there are dependencies
  368. deps = callback;
  369. callback = relName;
  370. relName = null;
  371. } else {
  372. deps = undef;
  373. }
  374. }
  375. //Support require(['a'])
  376. callback = callback || function () {};
  377. //If relName is a function, it is an errback handler,
  378. //so remove it.
  379. if (typeof relName === 'function') {
  380. relName = forceSync;
  381. forceSync = alt;
  382. }
  383. //Simulate async callback;
  384. if (forceSync) {
  385. main(undef, deps, callback, relName);
  386. } else {
  387. //Using a non-zero value because of concern for what old browsers
  388. //do, and latest browsers "upgrade" to 4 if lower value is used:
  389. //http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#dom-windowtimers-settimeout:
  390. //If want a value immediately, use require('id') instead -- something
  391. //that works in almond on the global level, but not guaranteed and
  392. //unlikely to work in other AMD implementations.
  393. setTimeout(function () {
  394. main(undef, deps, callback, relName);
  395. }, 4);
  396. }
  397. return req;
  398. };
  399. /**
  400. * Just drops the config on the floor, but returns req in case
  401. * the config return value is used.
  402. */
  403. req.config = function (cfg) {
  404. return req(cfg);
  405. };
  406. /**
  407. * Expose module registry for debugging and tooling
  408. */
  409. requirejs._defined = defined;
  410. define = function (name, deps, callback) {
  411. if (typeof name !== 'string') {
  412. throw new Error('See almond README: incorrect module build, no module name');
  413. }
  414. //This module may not have dependencies
  415. if (!deps.splice) {
  416. //deps is not an array, so probably means
  417. //an object literal or factory function for
  418. //the value. Adjust args.
  419. callback = deps;
  420. deps = [];
  421. }
  422. if (!hasProp(defined, name) && !hasProp(waiting, name)) {
  423. waiting[name] = [name, deps, callback];
  424. }
  425. };
  426. define.amd = {
  427. jQuery: true
  428. };
  429. }());
  430. S2.requirejs = requirejs;S2.require = require;S2.define = define;
  431. }
  432. }());
  433. S2.define("almond", function(){});
  434. /* global jQuery:false, $:false */
  435. S2.define('jquery',[],function () {
  436. var _$ = jQuery || $;
  437. if (_$ == null && console && console.error) {
  438. console.error(
  439. 'Select2: An instance of jQuery or a jQuery-compatible library was not ' +
  440. 'found. Make sure that you are including jQuery before Select2 on your ' +
  441. 'web page.'
  442. );
  443. }
  444. return _$;
  445. });
  446. S2.define('select2/utils',[
  447. 'jquery'
  448. ], function ($) {
  449. var Utils = {};
  450. Utils.Extend = function (ChildClass, SuperClass) {
  451. var __hasProp = {}.hasOwnProperty;
  452. function BaseConstructor () {
  453. this.constructor = ChildClass;
  454. }
  455. for (var key in SuperClass) {
  456. if (__hasProp.call(SuperClass, key)) {
  457. ChildClass[key] = SuperClass[key];
  458. }
  459. }
  460. BaseConstructor.prototype = SuperClass.prototype;
  461. ChildClass.prototype = new BaseConstructor();
  462. ChildClass.__super__ = SuperClass.prototype;
  463. return ChildClass;
  464. };
  465. function getMethods (theClass) {
  466. var proto = theClass.prototype;
  467. var methods = [];
  468. for (var methodName in proto) {
  469. var m = proto[methodName];
  470. if (typeof m !== 'function') {
  471. continue;
  472. }
  473. if (methodName === 'constructor') {
  474. continue;
  475. }
  476. methods.push(methodName);
  477. }
  478. return methods;
  479. }
  480. Utils.Decorate = function (SuperClass, DecoratorClass) {
  481. var decoratedMethods = getMethods(DecoratorClass);
  482. var superMethods = getMethods(SuperClass);
  483. function DecoratedClass () {
  484. var unshift = Array.prototype.unshift;
  485. var argCount = DecoratorClass.prototype.constructor.length;
  486. var calledConstructor = SuperClass.prototype.constructor;
  487. if (argCount > 0) {
  488. unshift.call(arguments, SuperClass.prototype.constructor);
  489. calledConstructor = DecoratorClass.prototype.constructor;
  490. }
  491. calledConstructor.apply(this, arguments);
  492. }
  493. DecoratorClass.displayName = SuperClass.displayName;
  494. function ctr () {
  495. this.constructor = DecoratedClass;
  496. }
  497. DecoratedClass.prototype = new ctr();
  498. for (var m = 0; m < superMethods.length; m++) {
  499. var superMethod = superMethods[m];
  500. DecoratedClass.prototype[superMethod] =
  501. SuperClass.prototype[superMethod];
  502. }
  503. var calledMethod = function (methodName) {
  504. // Stub out the original method if it's not decorating an actual method
  505. var originalMethod = function () {};
  506. if (methodName in DecoratedClass.prototype) {
  507. originalMethod = DecoratedClass.prototype[methodName];
  508. }
  509. var decoratedMethod = DecoratorClass.prototype[methodName];
  510. return function () {
  511. var unshift = Array.prototype.unshift;
  512. unshift.call(arguments, originalMethod);
  513. return decoratedMethod.apply(this, arguments);
  514. };
  515. };
  516. for (var d = 0; d < decoratedMethods.length; d++) {
  517. var decoratedMethod = decoratedMethods[d];
  518. DecoratedClass.prototype[decoratedMethod] = calledMethod(decoratedMethod);
  519. }
  520. return DecoratedClass;
  521. };
  522. var Observable = function () {
  523. this.listeners = {};
  524. };
  525. Observable.prototype.on = function (event, callback) {
  526. this.listeners = this.listeners || {};
  527. if (event in this.listeners) {
  528. this.listeners[event].push(callback);
  529. } else {
  530. this.listeners[event] = [callback];
  531. }
  532. };
  533. Observable.prototype.trigger = function (event) {
  534. var slice = Array.prototype.slice;
  535. var params = slice.call(arguments, 1);
  536. this.listeners = this.listeners || {};
  537. // Params should always come in as an array
  538. if (params == null) {
  539. params = [];
  540. }
  541. // If there are no arguments to the event, use a temporary object
  542. if (params.length === 0) {
  543. params.push({});
  544. }
  545. // Set the `_type` of the first object to the event
  546. params[0]._type = event;
  547. if (event in this.listeners) {
  548. this.invoke(this.listeners[event], slice.call(arguments, 1));
  549. }
  550. if ('*' in this.listeners) {
  551. this.invoke(this.listeners['*'], arguments);
  552. }
  553. };
  554. Observable.prototype.invoke = function (listeners, params) {
  555. for (var i = 0, len = listeners.length; i < len; i++) {
  556. listeners[i].apply(this, params);
  557. }
  558. };
  559. Utils.Observable = Observable;
  560. Utils.generateChars = function (length) {
  561. var chars = '';
  562. for (var i = 0; i < length; i++) {
  563. var randomChar = Math.floor(Math.random() * 36);
  564. chars += randomChar.toString(36);
  565. }
  566. return chars;
  567. };
  568. Utils.bind = function (func, context) {
  569. return function () {
  570. func.apply(context, arguments);
  571. };
  572. };
  573. Utils._convertData = function (data) {
  574. for (var originalKey in data) {
  575. var keys = originalKey.split('-');
  576. var dataLevel = data;
  577. if (keys.length === 1) {
  578. continue;
  579. }
  580. for (var k = 0; k < keys.length; k++) {
  581. var key = keys[k];
  582. // Lowercase the first letter
  583. // By default, dash-separated becomes camelCase
  584. key = key.substring(0, 1).toLowerCase() + key.substring(1);
  585. if (!(key in dataLevel)) {
  586. dataLevel[key] = {};
  587. }
  588. if (k == keys.length - 1) {
  589. dataLevel[key] = data[originalKey];
  590. }
  591. dataLevel = dataLevel[key];
  592. }
  593. delete data[originalKey];
  594. }
  595. return data;
  596. };
  597. Utils.hasScroll = function (index, el) {
  598. // Adapted from the function created by @ShadowScripter
  599. // and adapted by @BillBarry on the Stack Exchange Code Review website.
  600. // The original code can be found at
  601. // http://codereview.stackexchange.com/q/13338
  602. // and was designed to be used with the Sizzle selector engine.
  603. var $el = $(el);
  604. var overflowX = el.style.overflowX;
  605. var overflowY = el.style.overflowY;
  606. //Check both x and y declarations
  607. if (overflowX === overflowY &&
  608. (overflowY === 'hidden' || overflowY === 'visible')) {
  609. return false;
  610. }
  611. if (overflowX === 'scroll' || overflowY === 'scroll') {
  612. return true;
  613. }
  614. return ($el.innerHeight() < el.scrollHeight ||
  615. $el.innerWidth() < el.scrollWidth);
  616. };
  617. Utils.escapeMarkup = function (markup) {
  618. var replaceMap = {
  619. '\\': '&#92;',
  620. '&': '&amp;',
  621. '<': '&lt;',
  622. '>': '&gt;',
  623. '"': '&quot;',
  624. '\'': '&#39;',
  625. '/': '&#47;'
  626. };
  627. // Do not try to escape the markup if it's not a string
  628. if (typeof markup !== 'string') {
  629. return markup;
  630. }
  631. return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
  632. return replaceMap[match];
  633. });
  634. };
  635. // Append an array of jQuery nodes to a given element.
  636. Utils.appendMany = function ($element, $nodes) {
  637. // jQuery 1.7.x does not support $.fn.append() with an array
  638. // Fall back to a jQuery object collection using $.fn.add()
  639. if ($.fn.jquery.substr(0, 3) === '1.7') {
  640. var $jqNodes = $();
  641. $.map($nodes, function (node) {
  642. $jqNodes = $jqNodes.add(node);
  643. });
  644. $nodes = $jqNodes;
  645. }
  646. $element.append($nodes);
  647. };
  648. // Cache objects in Utils.__cache instead of $.data (see #4346)
  649. Utils.__cache = {};
  650. var id = 0;
  651. Utils.GetUniqueElementId = function (element) {
  652. // Get a unique element Id. If element has no id,
  653. // creates a new unique number, stores it in the id
  654. // attribute and returns the new id.
  655. // If an id already exists, it simply returns it.
  656. var select2Id = element.getAttribute('data-select2-id');
  657. if (select2Id == null) {
  658. // If element has id, use it.
  659. if (element.id) {
  660. select2Id = element.id;
  661. element.setAttribute('data-select2-id', select2Id);
  662. } else {
  663. element.setAttribute('data-select2-id', ++id);
  664. select2Id = id.toString();
  665. }
  666. }
  667. return select2Id;
  668. };
  669. Utils.StoreData = function (element, name, value) {
  670. // Stores an item in the cache for a specified element.
  671. // name is the cache key.
  672. var id = Utils.GetUniqueElementId(element);
  673. if (!Utils.__cache[id]) {
  674. Utils.__cache[id] = {};
  675. }
  676. Utils.__cache[id][name] = value;
  677. };
  678. Utils.GetData = function (element, name) {
  679. // Retrieves a value from the cache by its key (name)
  680. // name is optional. If no name specified, return
  681. // all cache items for the specified element.
  682. // and for a specified element.
  683. var id = Utils.GetUniqueElementId(element);
  684. if (name) {
  685. if (Utils.__cache[id]) {
  686. return Utils.__cache[id][name] != null ?
  687. Utils.__cache[id][name]:
  688. $(element).data(name); // Fallback to HTML5 data attribs.
  689. }
  690. return $(element).data(name); // Fallback to HTML5 data attribs.
  691. } else {
  692. return Utils.__cache[id];
  693. }
  694. };
  695. Utils.RemoveData = function (element) {
  696. // Removes all cached items for a specified element.
  697. var id = Utils.GetUniqueElementId(element);
  698. if (Utils.__cache[id] != null) {
  699. delete Utils.__cache[id];
  700. }
  701. };
  702. return Utils;
  703. });
  704. S2.define('select2/results',[
  705. 'jquery',
  706. './utils'
  707. ], function ($, Utils) {
  708. function Results ($element, options, dataAdapter) {
  709. this.$element = $element;
  710. this.data = dataAdapter;
  711. this.options = options;
  712. Results.__super__.constructor.call(this);
  713. }
  714. Utils.Extend(Results, Utils.Observable);
  715. Results.prototype.render = function () {
  716. var $results = $(
  717. '<ul class="select2-results__options" role="tree"></ul>'
  718. );
  719. if (this.options.get('multiple')) {
  720. $results.attr('aria-multiselectable', 'true');
  721. }
  722. this.$results = $results;
  723. return $results;
  724. };
  725. Results.prototype.clear = function () {
  726. this.$results.empty();
  727. };
  728. Results.prototype.displayMessage = function (params) {
  729. var escapeMarkup = this.options.get('escapeMarkup');
  730. this.clear();
  731. this.hideLoading();
  732. var $message = $(
  733. '<li role="treeitem" aria-live="assertive"' +
  734. ' class="select2-results__option"></li>'
  735. );
  736. var message = this.options.get('translations').get(params.message);
  737. $message.append(
  738. escapeMarkup(
  739. message(params.args)
  740. )
  741. );
  742. $message[0].className += ' select2-results__message';
  743. this.$results.append($message);
  744. };
  745. Results.prototype.hideMessages = function () {
  746. this.$results.find('.select2-results__message').remove();
  747. };
  748. Results.prototype.append = function (data) {
  749. this.hideLoading();
  750. var $options = [];
  751. if (data.results == null || data.results.length === 0) {
  752. if (this.$results.children().length === 0) {
  753. this.trigger('results:message', {
  754. message: 'noResults'
  755. });
  756. }
  757. return;
  758. }
  759. data.results = this.sort(data.results);
  760. for (var d = 0; d < data.results.length; d++) {
  761. var item = data.results[d];
  762. var $option = this.option(item);
  763. $options.push($option);
  764. }
  765. this.$results.append($options);
  766. };
  767. Results.prototype.position = function ($results, $dropdown) {
  768. var $resultsContainer = $dropdown.find('.select2-results');
  769. $resultsContainer.append($results);
  770. };
  771. Results.prototype.sort = function (data) {
  772. var sorter = this.options.get('sorter');
  773. return sorter(data);
  774. };
  775. Results.prototype.highlightFirstItem = function () {
  776. var $options = this.$results
  777. .find('.select2-results__option[aria-selected]');
  778. var $selected = $options.filter('[aria-selected=true]');
  779. // Check if there are any selected options
  780. if ($selected.length > 0) {
  781. // If there are selected options, highlight the first
  782. $selected.first().trigger('mouseenter');
  783. } else {
  784. // If there are no selected options, highlight the first option
  785. // in the dropdown
  786. $options.first().trigger('mouseenter');
  787. }
  788. this.ensureHighlightVisible();
  789. };
  790. Results.prototype.setClasses = function () {
  791. var self = this;
  792. this.data.current(function (selected) {
  793. var selectedIds = $.map(selected, function (s) {
  794. return s.id.toString();
  795. });
  796. var $options = self.$results
  797. .find('.select2-results__option[aria-selected]');
  798. $options.each(function () {
  799. var $option = $(this);
  800. var item = Utils.GetData(this, 'data');
  801. // id needs to be converted to a string when comparing
  802. var id = '' + item.id;
  803. if ((item.element != null && item.element.selected) ||
  804. (item.element == null && $.inArray(id, selectedIds) > -1)) {
  805. $option.attr('aria-selected', 'true');
  806. } else {
  807. $option.attr('aria-selected', 'false');
  808. }
  809. });
  810. });
  811. };
  812. Results.prototype.showLoading = function (params) {
  813. this.hideLoading();
  814. var loadingMore = this.options.get('translations').get('searching');
  815. var loading = {
  816. disabled: true,
  817. loading: true,
  818. text: loadingMore(params)
  819. };
  820. var $loading = this.option(loading);
  821. $loading.className += ' loading-results';
  822. this.$results.prepend($loading);
  823. };
  824. Results.prototype.hideLoading = function () {
  825. this.$results.find('.loading-results').remove();
  826. };
  827. Results.prototype.option = function (data) {
  828. var option = document.createElement('li');
  829. option.className = 'select2-results__option';
  830. var attrs = {
  831. 'role': 'treeitem',
  832. 'aria-selected': 'false'
  833. };
  834. if (data.disabled) {
  835. delete attrs['aria-selected'];
  836. attrs['aria-disabled'] = 'true';
  837. }
  838. if (data.id == null) {
  839. delete attrs['aria-selected'];
  840. }
  841. if (data._resultId != null) {
  842. option.id = data._resultId;
  843. }
  844. if (data.title) {
  845. option.title = data.title;
  846. }
  847. if (data.children) {
  848. attrs.role = 'group';
  849. attrs['aria-label'] = data.text;
  850. delete attrs['aria-selected'];
  851. }
  852. for (var attr in attrs) {
  853. var val = attrs[attr];
  854. option.setAttribute(attr, val);
  855. }
  856. if (data.children) {
  857. var $option = $(option);
  858. var label = document.createElement('strong');
  859. label.className = 'select2-results__group';
  860. var $label = $(label);
  861. this.template(data, label);
  862. var $children = [];
  863. for (var c = 0; c < data.children.length; c++) {
  864. var child = data.children[c];
  865. var $child = this.option(child);
  866. $children.push($child);
  867. }
  868. var $childrenContainer = $('<ul></ul>', {
  869. 'class': 'select2-results__options select2-results__options--nested'
  870. });
  871. $childrenContainer.append($children);
  872. $option.append(label);
  873. $option.append($childrenContainer);
  874. } else {
  875. this.template(data, option);
  876. }
  877. Utils.StoreData(option, 'data', data);
  878. return option;
  879. };
  880. Results.prototype.bind = function (container, $container) {
  881. var self = this;
  882. var id = container.id + '-results';
  883. this.$results.attr('id', id);
  884. container.on('results:all', function (params) {
  885. self.clear();
  886. self.append(params.data);
  887. if (container.isOpen()) {
  888. self.setClasses();
  889. self.highlightFirstItem();
  890. }
  891. });
  892. container.on('results:append', function (params) {
  893. self.append(params.data);
  894. if (container.isOpen()) {
  895. self.setClasses();
  896. }
  897. });
  898. container.on('query', function (params) {
  899. self.hideMessages();
  900. self.showLoading(params);
  901. });
  902. container.on('select', function () {
  903. if (!container.isOpen()) {
  904. return;
  905. }
  906. self.setClasses();
  907. self.highlightFirstItem();
  908. });
  909. container.on('unselect', function () {
  910. if (!container.isOpen()) {
  911. return;
  912. }
  913. self.setClasses();
  914. self.highlightFirstItem();
  915. });
  916. container.on('open', function () {
  917. // When the dropdown is open, aria-expended="true"
  918. self.$results.attr('aria-expanded', 'true');
  919. self.$results.attr('aria-hidden', 'false');
  920. self.setClasses();
  921. self.ensureHighlightVisible();
  922. });
  923. container.on('close', function () {
  924. // When the dropdown is closed, aria-expended="false"
  925. self.$results.attr('aria-expanded', 'false');
  926. self.$results.attr('aria-hidden', 'true');
  927. self.$results.removeAttr('aria-activedescendant');
  928. });
  929. container.on('results:toggle', function () {
  930. var $highlighted = self.getHighlightedResults();
  931. if ($highlighted.length === 0) {
  932. return;
  933. }
  934. $highlighted.trigger('mouseup');
  935. });
  936. container.on('results:select', function () {
  937. var $highlighted = self.getHighlightedResults();
  938. if ($highlighted.length === 0) {
  939. return;
  940. }
  941. var data = Utils.GetData($highlighted[0], 'data');
  942. if ($highlighted.attr('aria-selected') == 'true') {
  943. self.trigger('close', {});
  944. } else {
  945. self.trigger('select', {
  946. data: data
  947. });
  948. }
  949. });
  950. container.on('results:previous', function () {
  951. var $highlighted = self.getHighlightedResults();
  952. var $options = self.$results.find('[aria-selected]');
  953. var currentIndex = $options.index($highlighted);
  954. // If we are already at te top, don't move further
  955. // If no options, currentIndex will be -1
  956. if (currentIndex <= 0) {
  957. return;
  958. }
  959. var nextIndex = currentIndex - 1;
  960. // If none are highlighted, highlight the first
  961. if ($highlighted.length === 0) {
  962. nextIndex = 0;
  963. }
  964. var $next = $options.eq(nextIndex);
  965. $next.trigger('mouseenter');
  966. var currentOffset = self.$results.offset().top;
  967. var nextTop = $next.offset().top;
  968. var nextOffset = self.$results.scrollTop() + (nextTop - currentOffset);
  969. if (nextIndex === 0) {
  970. self.$results.scrollTop(0);
  971. } else if (nextTop - currentOffset < 0) {
  972. self.$results.scrollTop(nextOffset);
  973. }
  974. });
  975. container.on('results:next', function () {
  976. var $highlighted = self.getHighlightedResults();
  977. var $options = self.$results.find('[aria-selected]');
  978. var currentIndex = $options.index($highlighted);
  979. var nextIndex = currentIndex + 1;
  980. // If we are at the last option, stay there
  981. if (nextIndex >= $options.length) {
  982. return;
  983. }
  984. var $next = $options.eq(nextIndex);
  985. $next.trigger('mouseenter');
  986. var currentOffset = self.$results.offset().top +
  987. self.$results.outerHeight(false);
  988. var nextBottom = $next.offset().top + $next.outerHeight(false);
  989. var nextOffset = self.$results.scrollTop() + nextBottom - currentOffset;
  990. if (nextIndex === 0) {
  991. self.$results.scrollTop(0);
  992. } else if (nextBottom > currentOffset) {
  993. self.$results.scrollTop(nextOffset);
  994. }
  995. });
  996. container.on('results:focus', function (params) {
  997. params.element.addClass('select2-results__option--highlighted');
  998. });
  999. container.on('results:message', function (params) {
  1000. self.displayMessage(params);
  1001. });
  1002. if ($.fn.mousewheel) {
  1003. this.$results.on('mousewheel', function (e) {
  1004. var top = self.$results.scrollTop();
  1005. var bottom = self.$results.get(0).scrollHeight - top + e.deltaY;
  1006. var isAtTop = e.deltaY > 0 && top - e.deltaY <= 0;
  1007. var isAtBottom = e.deltaY < 0 && bottom <= self.$results.height();
  1008. if (isAtTop) {
  1009. self.$results.scrollTop(0);
  1010. e.preventDefault();
  1011. e.stopPropagation();
  1012. } else if (isAtBottom) {
  1013. self.$results.scrollTop(
  1014. self.$results.get(0).scrollHeight - self.$results.height()
  1015. );
  1016. e.preventDefault();
  1017. e.stopPropagation();
  1018. }
  1019. });
  1020. }
  1021. this.$results.on('mouseup', '.select2-results__option[aria-selected]',
  1022. function (evt) {
  1023. var $this = $(this);
  1024. var data = Utils.GetData(this, 'data');
  1025. if ($this.attr('aria-selected') === 'true') {
  1026. if (self.options.get('multiple')) {
  1027. self.trigger('unselect', {
  1028. originalEvent: evt,
  1029. data: data
  1030. });
  1031. } else {
  1032. self.trigger('close', {});
  1033. }
  1034. return;
  1035. }
  1036. self.trigger('select', {
  1037. originalEvent: evt,
  1038. data: data
  1039. });
  1040. });
  1041. this.$results.on('mouseenter', '.select2-results__option[aria-selected]',
  1042. function (evt) {
  1043. var data = Utils.GetData(this, 'data');
  1044. self.getHighlightedResults()
  1045. .removeClass('select2-results__option--highlighted');
  1046. self.trigger('results:focus', {
  1047. data: data,
  1048. element: $(this)
  1049. });
  1050. });
  1051. };
  1052. Results.prototype.getHighlightedResults = function () {
  1053. var $highlighted = this.$results
  1054. .find('.select2-results__option--highlighted');
  1055. return $highlighted;
  1056. };
  1057. Results.prototype.destroy = function () {
  1058. this.$results.remove();
  1059. };
  1060. Results.prototype.ensureHighlightVisible = function () {
  1061. var $highlighted = this.getHighlightedResults();
  1062. if ($highlighted.length === 0) {
  1063. return;
  1064. }
  1065. var $options = this.$results.find('[aria-selected]');
  1066. var currentIndex = $options.index($highlighted);
  1067. var currentOffset = this.$results.offset().top;
  1068. var nextTop = $highlighted.offset().top;
  1069. var nextOffset = this.$results.scrollTop() + (nextTop - currentOffset);
  1070. var offsetDelta = nextTop - currentOffset;
  1071. nextOffset -= $highlighted.outerHeight(false) * 2;
  1072. if (currentIndex <= 2) {
  1073. this.$results.scrollTop(0);
  1074. } else if (offsetDelta > this.$results.outerHeight() || offsetDelta < 0) {
  1075. this.$results.scrollTop(nextOffset);
  1076. }
  1077. };
  1078. Results.prototype.template = function (result, container) {
  1079. var template = this.options.get('templateResult');
  1080. var escapeMarkup = this.options.get('escapeMarkup');
  1081. var content = template(result, container);
  1082. if (content == null) {
  1083. container.style.display = 'none';
  1084. } else if (typeof content === 'string') {
  1085. container.innerHTML = escapeMarkup(content);
  1086. } else {
  1087. $(container).append(content);
  1088. }
  1089. };
  1090. return Results;
  1091. });
  1092. S2.define('select2/keys',[
  1093. ], function () {
  1094. var KEYS = {
  1095. BACKSPACE: 8,
  1096. TAB: 9,
  1097. ENTER: 13,
  1098. SHIFT: 16,
  1099. CTRL: 17,
  1100. ALT: 18,
  1101. ESC: 27,
  1102. SPACE: 32,
  1103. PAGE_UP: 33,
  1104. PAGE_DOWN: 34,
  1105. END: 35,
  1106. HOME: 36,
  1107. LEFT: 37,
  1108. UP: 38,
  1109. RIGHT: 39,
  1110. DOWN: 40,
  1111. DELETE: 46
  1112. };
  1113. return KEYS;
  1114. });
  1115. S2.define('select2/selection/base',[
  1116. 'jquery',
  1117. '../utils',
  1118. '../keys'
  1119. ], function ($, Utils, KEYS) {
  1120. function BaseSelection ($element, options) {
  1121. this.$element = $element;
  1122. this.options = options;
  1123. BaseSelection.__super__.constructor.call(this);
  1124. }
  1125. Utils.Extend(BaseSelection, Utils.Observable);
  1126. BaseSelection.prototype.render = function () {
  1127. var $selection = $(
  1128. '<span class="select2-selection" role="combobox" ' +
  1129. ' aria-haspopup="true" aria-expanded="false">' +
  1130. '</span>'
  1131. );
  1132. this._tabindex = 0;
  1133. if (Utils.GetData(this.$element[0], 'old-tabindex') != null) {
  1134. this._tabindex = Utils.GetData(this.$element[0], 'old-tabindex');
  1135. } else if (this.$element.attr('tabindex') != null) {
  1136. this._tabindex = this.$element.attr('tabindex');
  1137. }
  1138. $selection.attr('title', this.$element.attr('title'));
  1139. $selection.attr('tabindex', this._tabindex);
  1140. this.$selection = $selection;
  1141. return $selection;
  1142. };
  1143. BaseSelection.prototype.bind = function (container, $container) {
  1144. var self = this;
  1145. var id = container.id + '-container';
  1146. var resultsId = container.id + '-results';
  1147. this.container = container;
  1148. this.$selection.on('focus', function (evt) {
  1149. //console.log("focus");
  1150. self.trigger('focus', evt);
  1151. });
  1152. this.$selection.on('blur', function (evt) {
  1153. //console.log("blur");
  1154. self._handleBlur(evt);
  1155. });
  1156. this.$selection.on('keydown', function (evt) {
  1157. //console.log("keydown");
  1158. self.trigger('keypress', evt);
  1159. if (evt.which === KEYS.SPACE) {
  1160. evt.preventDefault();
  1161. }
  1162. });
  1163. container.on('results:focus', function (params) {
  1164. self.$selection.attr('aria-activedescendant', params.data._resultId);
  1165. });
  1166. container.on('selection:update', function (params) {
  1167. self.update(params.data);
  1168. });
  1169. container.on('open', function () {
  1170. // When the dropdown is open, aria-expanded="true"
  1171. self.$selection.attr('aria-expanded', 'true');
  1172. self.$selection.attr('aria-owns', resultsId);
  1173. self._attachCloseHandler(container);
  1174. });
  1175. container.on('close', function () {
  1176. // When the dropdown is closed, aria-expanded="false"
  1177. self.$selection.attr('aria-expanded', 'false');
  1178. self.$selection.removeAttr('aria-activedescendant');
  1179. self.$selection.removeAttr('aria-owns');
  1180. self.$selection.focus();
  1181. window.setTimeout(function () {
  1182. self.$selection.focus();
  1183. }, 0);
  1184. self._detachCloseHandler(container);
  1185. });
  1186. container.on('enable', function () {
  1187. self.$selection.attr('tabindex', self._tabindex);
  1188. });
  1189. container.on('disable', function () {
  1190. self.$selection.attr('tabindex', '-1');
  1191. });
  1192. };
  1193. BaseSelection.prototype._handleBlur = function (evt) {
  1194. var self = this;
  1195. // This needs to be delayed as the active element is the body when the tab
  1196. // key is pressed, possibly along with others.
  1197. window.setTimeout(function () {
  1198. // Don't trigger `blur` if the focus is still in the selection
  1199. if (
  1200. (document.activeElement == self.$selection[0]) ||
  1201. ($.contains(self.$selection[0], document.activeElement))
  1202. ) {
  1203. return;
  1204. }
  1205. self.trigger('blur', evt);
  1206. }, 1);
  1207. };
  1208. BaseSelection.prototype._attachCloseHandler = function (container) {
  1209. var self = this;
  1210. $(document.body).on('mousedown.select2.' + container.id, function (e) {
  1211. var $target = $(e.target);
  1212. var $select = $target.closest('.select2');
  1213. var $all = $('.select2.select2-container--open');
  1214. $all.each(function () {
  1215. var $this = $(this);
  1216. if (this == $select[0]) {
  1217. return;
  1218. }
  1219. var $element = Utils.GetData(this, 'element');
  1220. $element.select2('close');
  1221. });
  1222. });
  1223. };
  1224. BaseSelection.prototype._detachCloseHandler = function (container) {
  1225. $(document.body).off('mousedown.select2.' + container.id);
  1226. };
  1227. BaseSelection.prototype.position = function ($selection, $container) {
  1228. var $selectionContainer = $container.find('.selection');
  1229. $selectionContainer.append($selection);
  1230. };
  1231. BaseSelection.prototype.destroy = function () {
  1232. this._detachCloseHandler(this.container);
  1233. };
  1234. BaseSelection.prototype.update = function (data) {
  1235. throw new Error('The `update` method must be defined in child classes.');
  1236. };
  1237. return BaseSelection;
  1238. });
  1239. S2.define('select2/selection/single',[
  1240. 'jquery',
  1241. './base',
  1242. '../utils',
  1243. '../keys'
  1244. ], function ($, BaseSelection, Utils, KEYS) {
  1245. function SingleSelection () {
  1246. SingleSelection.__super__.constructor.apply(this, arguments);
  1247. }
  1248. Utils.Extend(SingleSelection, BaseSelection);
  1249. SingleSelection.prototype.render = function () {
  1250. var $selection = SingleSelection.__super__.render.call(this);
  1251. $selection.addClass('select2-selection--single');
  1252. $selection.html(
  1253. '<span class="select2-selection__rendered"></span>' +
  1254. '<span class="select2-selection__arrow" role="presentation">' +
  1255. '<b role="presentation"></b>' +
  1256. '</span>'
  1257. );
  1258. return $selection;
  1259. };
  1260. SingleSelection.prototype.bind = function (container, $container) {
  1261. var self = this;
  1262. SingleSelection.__super__.bind.apply(this, arguments);
  1263. var id = container.id + '-container';
  1264. this.$selection.find('.select2-selection__rendered')
  1265. .attr('id', id)
  1266. .attr('role', 'textbox')
  1267. .attr('aria-readonly', 'true');
  1268. this.$selection.attr('aria-labelledby', id);
  1269. this.$selection.on('mousedown', function (evt) {
  1270. // Only respond to left clicks
  1271. if (evt.which !== 1) {
  1272. return;
  1273. }
  1274. self.trigger('toggle', {
  1275. originalEvent: evt
  1276. });
  1277. });
  1278. this.$selection.on('focus', function (evt) {
  1279. // User focuses on the container
  1280. });
  1281. this.$selection.on('blur', function (evt) {
  1282. // User exits the container
  1283. });
  1284. container.on('focus', function (evt) {
  1285. if (!container.isOpen()) {
  1286. self.$selection.focus();
  1287. }
  1288. });
  1289. };
  1290. SingleSelection.prototype.clear = function () {
  1291. var $rendered = this.$selection.find('.select2-selection__rendered');
  1292. $rendered.empty();
  1293. $rendered.removeAttr('title'); // clear tooltip on empty
  1294. };
  1295. SingleSelection.prototype.display = function (data, container) {
  1296. var template = this.options.get('templateSelection');
  1297. var escapeMarkup = this.options.get('escapeMarkup');
  1298. return escapeMarkup(template(data, container));
  1299. };
  1300. SingleSelection.prototype.selectionContainer = function () {
  1301. return $('<span></span>');
  1302. };
  1303. SingleSelection.prototype.update = function (data) {
  1304. if (data.length === 0) {
  1305. this.clear();
  1306. return;
  1307. }
  1308. var selection = data[0];
  1309. var $rendered = this.$selection.find('.select2-selection__rendered');
  1310. var formatted = this.display(selection, $rendered);
  1311. $rendered.empty().append(formatted);
  1312. $rendered.attr('title', selection.title || selection.text);
  1313. };
  1314. return SingleSelection;
  1315. });
  1316. S2.define('select2/selection/multiple',[
  1317. 'jquery',
  1318. './base',
  1319. '../utils'
  1320. ], function ($, BaseSelection, Utils) {
  1321. function MultipleSelection ($element, options) {
  1322. MultipleSelection.__super__.constructor.apply(this, arguments);
  1323. }
  1324. Utils.Extend(MultipleSelection, BaseSelection);
  1325. MultipleSelection.prototype.render = function () {
  1326. var $selection = MultipleSelection.__super__.render.call(this);
  1327. $selection.addClass('select2-selection--multiple');
  1328. $selection.html(
  1329. '<ul class="select2-selection__rendered"></ul>'
  1330. );
  1331. return $selection;
  1332. };
  1333. MultipleSelection.prototype.bind = function (container, $container) {
  1334. var self = this;
  1335. MultipleSelection.__super__.bind.apply(this, arguments);
  1336. this.$selection.on('click', function (evt) {
  1337. self.trigger('toggle', {
  1338. originalEvent: evt
  1339. });
  1340. });
  1341. this.$selection.on(
  1342. 'click',
  1343. '.select2-selection__choice__remove',
  1344. function (evt) {
  1345. // Ignore the event if it is disabled
  1346. if (self.options.get('disabled')) {
  1347. return;
  1348. }
  1349. var $remove = $(this);
  1350. var $selection = $remove.parent();
  1351. var data = Utils.GetData($selection[0], 'data');
  1352. self.trigger('unselect', {
  1353. originalEvent: evt,
  1354. data: data
  1355. });
  1356. }
  1357. );
  1358. this.$selection.on(
  1359. 'mouseover',
  1360. '.select2-selection__choice',
  1361. function (evt) {
  1362. var userInfoAjaxUrl = self.options.get('userInfoAjaxUrl');
  1363. var el = this;
  1364. console.log(userInfoAjaxUrl);
  1365. if (userInfoAjaxUrl!=null && userInfoAjaxUrl.length>0) {
  1366. var data = Utils.GetData($(el)[0], 'data');
  1367. //console.log(data);
  1368. if($(el).data("loaded")==null){
  1369. $(el).attr("title","加载中,请移开鼠标稍后再试");
  1370. $.ajax({
  1371. type: "post",
  1372. contenttype: "application/json",
  1373. url: userInfoAjaxUrl,
  1374. data: { userId: data.id },
  1375. datatype: 'json',
  1376. success: function (result) {
  1377. $(el).attr("title",result);
  1378. $(el).data("loaded",true);
  1379. }
  1380. });
  1381. }
  1382. }
  1383. }
  1384. );
  1385. };
  1386. MultipleSelection.prototype.clear = function () {
  1387. var $rendered = this.$selection.find('.select2-selection__rendered');
  1388. $rendered.empty();
  1389. $rendered.removeAttr('title');
  1390. };
  1391. MultipleSelection.prototype.display = function (data, container) {
  1392. var template = this.options.get('templateSelection');
  1393. var escapeMarkup = this.options.get('escapeMarkup');
  1394. return escapeMarkup(template(data, container));
  1395. };
  1396. MultipleSelection.prototype.selectionContainer = function () {
  1397. var $container = $(
  1398. '<li class="select2-selection__choice">' +
  1399. '&nbsp;<span class="select2-selection__choice__remove" role="presentation">' +
  1400. '&times;' +
  1401. '</span>' +
  1402. '</li>'
  1403. );
  1404. return $container;
  1405. };
  1406. MultipleSelection.prototype.update = function (data) {
  1407. this.clear();
  1408. if (data.length === 0) {
  1409. return;
  1410. }
  1411. var $selections = [];
  1412. for (var d = 0; d < data.length; d++) {
  1413. var selection = data[d];
  1414. var $selection = this.selectionContainer();
  1415. var formatted = this.display(selection, $selection);
  1416. $selection.prepend(formatted); //append
  1417. $selection.attr('title', selection.title || selection.text);
  1418. Utils.StoreData($selection[0], 'data', selection);
  1419. $selections.push($selection);
  1420. }
  1421. var $rendered = this.$selection.find('.select2-selection__rendered');
  1422. Utils.appendMany($rendered, $selections);
  1423. };
  1424. return MultipleSelection;
  1425. });
  1426. S2.define('select2/selection/placeholder',[
  1427. '../utils'
  1428. ], function (Utils) {
  1429. function Placeholder (decorated, $element, options) {
  1430. this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
  1431. decorated.call(this, $element, options);
  1432. }
  1433. Placeholder.prototype.normalizePlaceholder = function (_, placeholder) {
  1434. if (typeof placeholder === 'string') {
  1435. placeholder = {
  1436. id: '',
  1437. text: placeholder
  1438. };
  1439. }
  1440. return placeholder;
  1441. };
  1442. Placeholder.prototype.createPlaceholder = function (decorated, placeholder) {
  1443. var $placeholder = this.selectionContainer();
  1444. $placeholder.html(this.display(placeholder));
  1445. $placeholder.addClass('select2-selection__placeholder')
  1446. .removeClass('select2-selection__choice');
  1447. return $placeholder;
  1448. };
  1449. Placeholder.prototype.update = function (decorated, data) {
  1450. var singlePlaceholder = (
  1451. data.length == 1 && data[0].id != this.placeholder.id
  1452. );
  1453. var multipleSelections = data.length > 1;
  1454. if (multipleSelections || singlePlaceholder) {
  1455. return decorated.call(this, data);
  1456. }
  1457. this.clear();
  1458. var $placeholder = this.createPlaceholder(this.placeholder);
  1459. this.$selection.find('.select2-selection__rendered').append($placeholder);
  1460. };
  1461. return Placeholder;
  1462. });
  1463. S2.define('select2/selection/allowClear',[
  1464. 'jquery',
  1465. '../keys',
  1466. '../utils'
  1467. ], function ($, KEYS, Utils) {
  1468. function AllowClear () { }
  1469. AllowClear.prototype.bind = function (decorated, container, $container) {
  1470. var self = this;
  1471. decorated.call(this, container, $container);
  1472. if (this.placeholder == null) {
  1473. if (this.options.get('debug') && window.console && console.error) {
  1474. console.error(
  1475. 'Select2: The `allowClear` option should be used in combination ' +
  1476. 'with the `placeholder` option.'
  1477. );
  1478. }
  1479. }
  1480. this.$selection.on('mousedown', '.select2-selection__clear',
  1481. function (evt) {
  1482. self._handleClear(evt);
  1483. });
  1484. container.on('keypress', function (evt) {
  1485. self._handleKeyboardClear(evt, container);
  1486. });
  1487. };
  1488. AllowClear.prototype._handleClear = function (_, evt) {
  1489. // Ignore the event if it is disabled
  1490. if (this.options.get('disabled')) {
  1491. return;
  1492. }
  1493. var $clear = this.$selection.find('.select2-selection__clear');
  1494. // Ignore the event if nothing has been selected
  1495. if ($clear.length === 0) {
  1496. return;
  1497. }
  1498. evt.stopPropagation();
  1499. var data = Utils.GetData($clear[0], 'data');
  1500. var previousVal = this.$element.val();
  1501. this.$element.val(this.placeholder.id);
  1502. var unselectData = {
  1503. data: data
  1504. };
  1505. this.trigger('clear', unselectData);
  1506. if (unselectData.prevented) {
  1507. this.$element.val(previousVal);
  1508. return;
  1509. }
  1510. for (var d = 0; d < data.length; d++) {
  1511. unselectData = {
  1512. data: data[d]
  1513. };
  1514. // Trigger the `unselect` event, so people can prevent it from being
  1515. // cleared.
  1516. this.trigger('unselect', unselectData);
  1517. // If the event was prevented, don't clear it out.
  1518. if (unselectData.prevented) {
  1519. this.$element.val(previousVal);
  1520. return;
  1521. }
  1522. }
  1523. this.$element.trigger('change');
  1524. this.trigger('toggle', {});
  1525. };
  1526. AllowClear.prototype._handleKeyboardClear = function (_, evt, container) {
  1527. if (container.isOpen()) {
  1528. return;
  1529. }
  1530. if (evt.which == KEYS.DELETE || evt.which == KEYS.BACKSPACE) {
  1531. this._handleClear(evt);
  1532. }
  1533. };
  1534. AllowClear.prototype.update = function (decorated, data) {
  1535. decorated.call(this, data);
  1536. if (this.$selection.find('.select2-selection__placeholder').length > 0 ||
  1537. data.length === 0) {
  1538. return;
  1539. }
  1540. var $remove = $(
  1541. '<span class="select2-selection__clear">' +
  1542. '&times;' +
  1543. '</span>'
  1544. );
  1545. Utils.StoreData($remove[0], 'data', data);
  1546. this.$selection.find('.select2-selection__rendered').prepend($remove);
  1547. };
  1548. return AllowClear;
  1549. });
  1550. S2.define('select2/selection/search',[
  1551. 'jquery',
  1552. '../utils',
  1553. '../keys'
  1554. ], function ($, Utils, KEYS) {
  1555. function Search (decorated, $element, options) {
  1556. decorated.call(this, $element, options);
  1557. }
  1558. Search.prototype.render = function (decorated) {
  1559. var $search = $(
  1560. '<li class="select2-search select2-search--inline">' +
  1561. '<input class="select2-search__field" type="search" tabindex="-1"' +
  1562. ' autocomplete="off" autocorrect="off" autocapitalize="none"' +
  1563. ' spellcheck="false" role="textbox" aria-autocomplete="list" />' +
  1564. '</li>'
  1565. );
  1566. this.$searchContainer = $search;
  1567. this.$search = $search.find('input');
  1568. var $rendered = decorated.call(this);
  1569. this._transferTabIndex();
  1570. return $rendered;
  1571. };
  1572. Search.prototype.bind = function (decorated, container, $container) {
  1573. var self = this;
  1574. decorated.call(this, container, $container);
  1575. container.on('open', function () {
  1576. self.$search.trigger('focus');
  1577. });
  1578. container.on('close', function () {
  1579. if(self.$element.children("option:selected").length>0){
  1580. self.$search.val('');
  1581. }
  1582. self.$search.removeAttr('aria-activedescendant');
  1583. self.$search.trigger('focus');
  1584. });
  1585. container.on('enable', function () {
  1586. self.$search.prop('disabled', false);
  1587. self._transferTabIndex();
  1588. });
  1589. container.on('disable', function () {
  1590. self.$search.prop('disabled', true);
  1591. });
  1592. container.on('focus', function (evt) {
  1593. self.$search.trigger('focus');
  1594. });
  1595. container.on('results:focus', function (params) {
  1596. self.$search.attr('aria-activedescendant', params.id);
  1597. });
  1598. this.$selection.on('focusin', '.select2-search--inline', function (evt) {
  1599. self.trigger('focus', evt);
  1600. });
  1601. this.$selection.on('focusout', '.select2-search--inline', function (evt) {
  1602. self._handleBlur(evt);
  1603. });
  1604. this.$selection.on('keydown', '.select2-search--inline', function (evt) {
  1605. evt.stopPropagation();
  1606. self.trigger('keypress', evt);
  1607. self._keyUpPrevented = evt.isDefaultPrevented();
  1608. var key = evt.which;
  1609. if (key === KEYS.BACKSPACE && self.$search.val() === '') {
  1610. var $previousChoice = self.$searchContainer
  1611. .prev('.select2-selection__choice');
  1612. if ($previousChoice.length > 0) {
  1613. var item = Utils.GetData($previousChoice[0], 'data');
  1614. self.searchRemoveChoice(item);
  1615. evt.preventDefault();
  1616. }
  1617. }
  1618. });
  1619. // Try to detect the IE version should the `documentMode` property that
  1620. // is stored on the document. This is only implemented in IE and is
  1621. // slightly cleaner than doing a user agent check.
  1622. // This property is not available in Edge, but Edge also doesn't have
  1623. // this bug.
  1624. var msie = document.documentMode;
  1625. var disableInputEvents = msie && msie <= 11;
  1626. // Workaround for browsers which do not support the `input` event
  1627. // This will prevent double-triggering of events for browsers which support
  1628. // both the `keyup` and `input` events.
  1629. this.$selection.on(
  1630. 'input.searchcheck',
  1631. '.select2-search--inline',
  1632. function (evt) {
  1633. // IE will trigger the `input` event when a placeholder is used on a
  1634. // search box. To get around this issue, we are forced to ignore all
  1635. // `input` events in IE and keep using `keyup`.
  1636. if (disableInputEvents) {
  1637. self.$selection.off('input.search input.searchcheck');
  1638. return;
  1639. }
  1640. // Unbind the duplicated `keyup` event
  1641. self.$selection.off('keyup.search');
  1642. }
  1643. );
  1644. this.$selection.on(
  1645. 'keyup.search input.search',
  1646. '.select2-search--inline',
  1647. function (evt) {
  1648. // IE will trigger the `input` event when a placeholder is used on a
  1649. // search box. To get around this issue, we are forced to ignore all
  1650. // `input` events in IE and keep using `keyup`.
  1651. if (disableInputEvents && evt.type === 'input') {
  1652. self.$selection.off('input.search input.searchcheck');
  1653. return;
  1654. }
  1655. var key = evt.which;
  1656. // We can freely ignore events from modifier keys
  1657. if (key == KEYS.SHIFT || key == KEYS.CTRL || key == KEYS.ALT) {
  1658. return;
  1659. }
  1660. // Tabbing will be handled during the `keydown` phase
  1661. if (key == KEYS.TAB) {
  1662. return;
  1663. }
  1664. self.handleSearch(evt);
  1665. }
  1666. );
  1667. };
  1668. /**
  1669. * This method will transfer the tabindex attribute from the rendered
  1670. * selection to the search box. This allows for the search box to be used as
  1671. * the primary focus instead of the selection container.
  1672. *
  1673. * @private
  1674. */
  1675. Search.prototype._transferTabIndex = function (decorated) {
  1676. this.$search.attr('tabindex', this.$selection.attr('tabindex'));
  1677. this.$selection.attr('tabindex', '-1');
  1678. };
  1679. Search.prototype.createPlaceholder = function (decorated, placeholder) {
  1680. this.$search.attr('placeholder', placeholder.text);
  1681. };
  1682. Search.prototype.update = function (decorated, data) {
  1683. var searchHadFocus = this.$search[0] == document.activeElement;
  1684. this.$search.attr('placeholder', '');
  1685. decorated.call(this, data);
  1686. this.$selection.find('.select2-selection__rendered')
  1687. .append(this.$searchContainer);
  1688. this.resizeSearch();
  1689. if (searchHadFocus) {
  1690. var isTagInput = this.$element.find('[data-select2-tag]').length;
  1691. if (isTagInput) {
  1692. // fix IE11 bug where tag input lost focus
  1693. this.$element.focus();
  1694. } else {
  1695. this.$search.focus();
  1696. }
  1697. }
  1698. };
  1699. Search.prototype.handleSearch = function () {
  1700. this.resizeSearch();
  1701. if (!this._keyUpPrevented) {
  1702. var input = this.$search.val();
  1703. this.trigger('query', {
  1704. term: input
  1705. });
  1706. }
  1707. this._keyUpPrevented = false;
  1708. };
  1709. Search.prototype.searchRemoveChoice = function (decorated, item) {
  1710. this.trigger('unselect', {
  1711. data: item
  1712. });
  1713. // this.$search.val(item.text);
  1714. var self = this;
  1715. setTimeout(function () {
  1716. self.$selection.find('.select2-selection__rendered li:last-child input').focus();
  1717. });
  1718. this.handleSearch();
  1719. };
  1720. Search.prototype.resizeSearch = function () {
  1721. this.$search.css('width', '25px');
  1722. var width = '';
  1723. if (this.$search.attr('placeholder') !== '') {
  1724. width = this.$selection.find('.select2-selection__rendered').innerWidth();
  1725. } else {
  1726. var minimumWidth = this.$search.val().length + 1;
  1727. width = (minimumWidth * 0.75) + 'em';
  1728. }
  1729. this.$search.css('width', width);
  1730. };
  1731. return Search;
  1732. });
  1733. S2.define('select2/selection/eventRelay',[
  1734. 'jquery'
  1735. ], function ($) {
  1736. function EventRelay () { }
  1737. EventRelay.prototype.bind = function (decorated, container, $container) {
  1738. var self = this;
  1739. var relayEvents = [
  1740. 'open', 'opening',
  1741. 'close', 'closing',
  1742. 'select', 'selecting',
  1743. 'unselect', 'unselecting',
  1744. 'clear', 'clearing'
  1745. ];
  1746. var preventableEvents = [
  1747. 'opening', 'closing', 'selecting', 'unselecting', 'clearing'
  1748. ];
  1749. decorated.call(this, container, $container);
  1750. container.on('*', function (name, params) {
  1751. // Ignore events that should not be relayed
  1752. if ($.inArray(name, relayEvents) === -1) {
  1753. return;
  1754. }
  1755. // The parameters should always be an object
  1756. params = params || {};
  1757. // Generate the jQuery event for the Select2 event
  1758. var evt = $.Event('select2:' + name, {
  1759. params: params
  1760. });
  1761. self.$element.trigger(evt);
  1762. // Only handle preventable events if it was one
  1763. if ($.inArray(name, preventableEvents) === -1) {
  1764. return;
  1765. }
  1766. params.prevented = evt.isDefaultPrevented();
  1767. });
  1768. };
  1769. return EventRelay;
  1770. });
  1771. S2.define('select2/translation',[
  1772. 'jquery',
  1773. 'require'
  1774. ], function ($, require) {
  1775. function Translation (dict) {
  1776. this.dict = dict || {};
  1777. }
  1778. Translation.prototype.all = function () {
  1779. return this.dict;
  1780. };
  1781. Translation.prototype.get = function (key) {
  1782. return this.dict[key];
  1783. };
  1784. Translation.prototype.extend = function (translation) {
  1785. this.dict = $.extend({}, translation.all(), this.dict);
  1786. };
  1787. // Static functions
  1788. Translation._cache = {};
  1789. Translation.loadPath = function (path) {
  1790. if (!(path in Translation._cache)) {
  1791. var translations = require(path);
  1792. Translation._cache[path] = translations;
  1793. }
  1794. return new Translation(Translation._cache[path]);
  1795. };
  1796. return Translation;
  1797. });
  1798. S2.define('select2/diacritics',[
  1799. ], function () {
  1800. var diacritics = {
  1801. '\u24B6': 'A',
  1802. '\uFF21': 'A',
  1803. '\u00C0': 'A',
  1804. '\u00C1': 'A',
  1805. '\u00C2': 'A',
  1806. '\u1EA6': 'A',
  1807. '\u1EA4': 'A',
  1808. '\u1EAA': 'A',
  1809. '\u1EA8': 'A',
  1810. '\u00C3': 'A',
  1811. '\u0100': 'A',
  1812. '\u0102': 'A',
  1813. '\u1EB0': 'A',
  1814. '\u1EAE': 'A',
  1815. '\u1EB4': 'A',
  1816. '\u1EB2': 'A',
  1817. '\u0226': 'A',
  1818. '\u01E0': 'A',
  1819. '\u00C4': 'A',
  1820. '\u01DE': 'A',
  1821. '\u1EA2': 'A',
  1822. '\u00C5': 'A',
  1823. '\u01FA': 'A',
  1824. '\u01CD': 'A',
  1825. '\u0200': 'A',
  1826. '\u0202': 'A',
  1827. '\u1EA0': 'A',
  1828. '\u1EAC': 'A',
  1829. '\u1EB6': 'A',
  1830. '\u1E00': 'A',
  1831. '\u0104': 'A',
  1832. '\u023A': 'A',
  1833. '\u2C6F': 'A',
  1834. '\uA732': 'AA',
  1835. '\u00C6': 'AE',
  1836. '\u01FC': 'AE',
  1837. '\u01E2': 'AE',
  1838. '\uA734': 'AO',
  1839. '\uA736': 'AU',
  1840. '\uA738': 'AV',
  1841. '\uA73A': 'AV',
  1842. '\uA73C': 'AY',
  1843. '\u24B7': 'B',
  1844. '\uFF22': 'B',
  1845. '\u1E02': 'B',
  1846. '\u1E04': 'B',
  1847. '\u1E06': 'B',
  1848. '\u0243': 'B',
  1849. '\u0182': 'B',
  1850. '\u0181': 'B',
  1851. '\u24B8': 'C',
  1852. '\uFF23': 'C',
  1853. '\u0106': 'C',
  1854. '\u0108': 'C',
  1855. '\u010A': 'C',
  1856. '\u010C': 'C',
  1857. '\u00C7': 'C',
  1858. '\u1E08': 'C',
  1859. '\u0187': 'C',
  1860. '\u023B': 'C',
  1861. '\uA73E': 'C',
  1862. '\u24B9': 'D',
  1863. '\uFF24': 'D',
  1864. '\u1E0A': 'D',
  1865. '\u010E': 'D',
  1866. '\u1E0C': 'D',
  1867. '\u1E10': 'D',
  1868. '\u1E12': 'D',
  1869. '\u1E0E': 'D',
  1870. '\u0110': 'D',
  1871. '\u018B': 'D',
  1872. '\u018A': 'D',
  1873. '\u0189': 'D',
  1874. '\uA779': 'D',
  1875. '\u01F1': 'DZ',
  1876. '\u01C4': 'DZ',
  1877. '\u01F2': 'Dz',
  1878. '\u01C5': 'Dz',
  1879. '\u24BA': 'E',
  1880. '\uFF25': 'E',
  1881. '\u00C8': 'E',
  1882. '\u00C9': 'E',
  1883. '\u00CA': 'E',
  1884. '\u1EC0': 'E',
  1885. '\u1EBE': 'E',
  1886. '\u1EC4': 'E',
  1887. '\u1EC2': 'E',
  1888. '\u1EBC': 'E',
  1889. '\u0112': 'E',
  1890. '\u1E14': 'E',
  1891. '\u1E16': 'E',
  1892. '\u0114': 'E',
  1893. '\u0116': 'E',
  1894. '\u00CB': 'E',
  1895. '\u1EBA': 'E',
  1896. '\u011A': 'E',
  1897. '\u0204': 'E',
  1898. '\u0206': 'E',
  1899. '\u1EB8': 'E',
  1900. '\u1EC6': 'E',
  1901. '\u0228': 'E',
  1902. '\u1E1C': 'E',
  1903. '\u0118': 'E',
  1904. '\u1E18': 'E',
  1905. '\u1E1A': 'E',
  1906. '\u0190': 'E',
  1907. '\u018E': 'E',
  1908. '\u24BB': 'F',
  1909. '\uFF26': 'F',
  1910. '\u1E1E': 'F',
  1911. '\u0191': 'F',
  1912. '\uA77B': 'F',
  1913. '\u24BC': 'G',
  1914. '\uFF27': 'G',
  1915. '\u01F4': 'G',
  1916. '\u011C': 'G',
  1917. '\u1E20': 'G',
  1918. '\u011E': 'G',
  1919. '\u0120': 'G',
  1920. '\u01E6': 'G',
  1921. '\u0122': 'G',
  1922. '\u01E4': 'G',
  1923. '\u0193': 'G',
  1924. '\uA7A0': 'G',
  1925. '\uA77D': 'G',
  1926. '\uA77E': 'G',
  1927. '\u24BD': 'H',
  1928. '\uFF28': 'H',
  1929. '\u0124': 'H',
  1930. '\u1E22': 'H',
  1931. '\u1E26': 'H',
  1932. '\u021E': 'H',
  1933. '\u1E24': 'H',
  1934. '\u1E28': 'H',
  1935. '\u1E2A': 'H',
  1936. '\u0126': 'H',
  1937. '\u2C67': 'H',
  1938. '\u2C75': 'H',
  1939. '\uA78D': 'H',
  1940. '\u24BE': 'I',
  1941. '\uFF29': 'I',
  1942. '\u00CC': 'I',
  1943. '\u00CD': 'I',
  1944. '\u00CE': 'I',
  1945. '\u0128': 'I',
  1946. '\u012A': 'I',
  1947. '\u012C': 'I',
  1948. '\u0130': 'I',
  1949. '\u00CF': 'I',
  1950. '\u1E2E': 'I',
  1951. '\u1EC8': 'I',
  1952. '\u01CF': 'I',
  1953. '\u0208': 'I',
  1954. '\u020A': 'I',
  1955. '\u1ECA': 'I',
  1956. '\u012E': 'I',
  1957. '\u1E2C': 'I',
  1958. '\u0197': 'I',
  1959. '\u24BF': 'J',
  1960. '\uFF2A': 'J',
  1961. '\u0134': 'J',
  1962. '\u0248': 'J',
  1963. '\u24C0': 'K',
  1964. '\uFF2B': 'K',
  1965. '\u1E30': 'K',
  1966. '\u01E8': 'K',
  1967. '\u1E32': 'K',
  1968. '\u0136': 'K',
  1969. '\u1E34': 'K',
  1970. '\u0198': 'K',
  1971. '\u2C69': 'K',
  1972. '\uA740': 'K',
  1973. '\uA742': 'K',
  1974. '\uA744': 'K',
  1975. '\uA7A2': 'K',
  1976. '\u24C1': 'L',
  1977. '\uFF2C': 'L',
  1978. '\u013F': 'L',
  1979. '\u0139': 'L',
  1980. '\u013D': 'L',
  1981. '\u1E36': 'L',
  1982. '\u1E38': 'L',
  1983. '\u013B': 'L',
  1984. '\u1E3C': 'L',
  1985. '\u1E3A': 'L',
  1986. '\u0141': 'L',
  1987. '\u023D': 'L',
  1988. '\u2C62': 'L',
  1989. '\u2C60': 'L',
  1990. '\uA748': 'L',
  1991. '\uA746': 'L',
  1992. '\uA780': 'L',
  1993. '\u01C7': 'LJ',
  1994. '\u01C8': 'Lj',
  1995. '\u24C2': 'M',
  1996. '\uFF2D': 'M',
  1997. '\u1E3E': 'M',
  1998. '\u1E40': 'M',
  1999. '\u1E42': 'M',
  2000. '\u2C6E': 'M',
  2001. '\u019C': 'M',
  2002. '\u24C3': 'N',
  2003. '\uFF2E': 'N',
  2004. '\u01F8': 'N',
  2005. '\u0143': 'N',
  2006. '\u00D1': 'N',
  2007. '\u1E44': 'N',
  2008. '\u0147': 'N',
  2009. '\u1E46': 'N',
  2010. '\u0145': 'N',
  2011. '\u1E4A': 'N',
  2012. '\u1E48': 'N',
  2013. '\u0220': 'N',
  2014. '\u019D': 'N',
  2015. '\uA790': 'N',
  2016. '\uA7A4': 'N',
  2017. '\u01CA': 'NJ',
  2018. '\u01CB': 'Nj',
  2019. '\u24C4': 'O',
  2020. '\uFF2F': 'O',
  2021. '\u00D2': 'O',
  2022. '\u00D3': 'O',
  2023. '\u00D4': 'O',
  2024. '\u1ED2': 'O',
  2025. '\u1ED0': 'O',
  2026. '\u1ED6': 'O',
  2027. '\u1ED4': 'O',
  2028. '\u00D5': 'O',
  2029. '\u1E4C': 'O',
  2030. '\u022C': 'O',
  2031. '\u1E4E': 'O',
  2032. '\u014C': 'O',
  2033. '\u1E50': 'O',
  2034. '\u1E52': 'O',
  2035. '\u014E': 'O',
  2036. '\u022E': 'O',
  2037. '\u0230': 'O',
  2038. '\u00D6': 'O',
  2039. '\u022A': 'O',
  2040. '\u1ECE': 'O',
  2041. '\u0150': 'O',
  2042. '\u01D1': 'O',
  2043. '\u020C': 'O',
  2044. '\u020E': 'O',
  2045. '\u01A0': 'O',
  2046. '\u1EDC': 'O',
  2047. '\u1EDA': 'O',
  2048. '\u1EE0': 'O',
  2049. '\u1EDE': 'O',
  2050. '\u1EE2': 'O',
  2051. '\u1ECC': 'O',
  2052. '\u1ED8': 'O',
  2053. '\u01EA': 'O',
  2054. '\u01EC': 'O',
  2055. '\u00D8': 'O',
  2056. '\u01FE': 'O',
  2057. '\u0186': 'O',
  2058. '\u019F': 'O',
  2059. '\uA74A': 'O',
  2060. '\uA74C': 'O',
  2061. '\u01A2': 'OI',
  2062. '\uA74E': 'OO',
  2063. '\u0222': 'OU',
  2064. '\u24C5': 'P',
  2065. '\uFF30': 'P',
  2066. '\u1E54': 'P',
  2067. '\u1E56': 'P',
  2068. '\u01A4': 'P',
  2069. '\u2C63': 'P',
  2070. '\uA750': 'P',
  2071. '\uA752': 'P',
  2072. '\uA754': 'P',
  2073. '\u24C6': 'Q',
  2074. '\uFF31': 'Q',
  2075. '\uA756': 'Q',
  2076. '\uA758': 'Q',
  2077. '\u024A': 'Q',
  2078. '\u24C7': 'R',
  2079. '\uFF32': 'R',
  2080. '\u0154': 'R',
  2081. '\u1E58': 'R',
  2082. '\u0158': 'R',
  2083. '\u0210': 'R',
  2084. '\u0212': 'R',
  2085. '\u1E5A': 'R',
  2086. '\u1E5C': 'R',
  2087. '\u0156': 'R',
  2088. '\u1E5E': 'R',
  2089. '\u024C': 'R',
  2090. '\u2C64': 'R',
  2091. '\uA75A': 'R',
  2092. '\uA7A6': 'R',
  2093. '\uA782': 'R',
  2094. '\u24C8': 'S',
  2095. '\uFF33': 'S',
  2096. '\u1E9E': 'S',
  2097. '\u015A': 'S',
  2098. '\u1E64': 'S',
  2099. '\u015C': 'S',
  2100. '\u1E60': 'S',
  2101. '\u0160': 'S',
  2102. '\u1E66': 'S',
  2103. '\u1E62': 'S',
  2104. '\u1E68': 'S',
  2105. '\u0218': 'S',
  2106. '\u015E': 'S',
  2107. '\u2C7E': 'S',
  2108. '\uA7A8': 'S',
  2109. '\uA784': 'S',
  2110. '\u24C9': 'T',
  2111. '\uFF34': 'T',
  2112. '\u1E6A': 'T',
  2113. '\u0164': 'T',
  2114. '\u1E6C': 'T',
  2115. '\u021A': 'T',
  2116. '\u0162': 'T',
  2117. '\u1E70': 'T',
  2118. '\u1E6E': 'T',
  2119. '\u0166': 'T',
  2120. '\u01AC': 'T',
  2121. '\u01AE': 'T',
  2122. '\u023E': 'T',
  2123. '\uA786': 'T',
  2124. '\uA728': 'TZ',
  2125. '\u24CA': 'U',
  2126. '\uFF35': 'U',
  2127. '\u00D9': 'U',
  2128. '\u00DA': 'U',
  2129. '\u00DB': 'U',
  2130. '\u0168': 'U',
  2131. '\u1E78': 'U',
  2132. '\u016A': 'U',
  2133. '\u1E7A': 'U',
  2134. '\u016C': 'U',
  2135. '\u00DC': 'U',
  2136. '\u01DB': 'U',
  2137. '\u01D7': 'U',
  2138. '\u01D5': 'U',
  2139. '\u01D9': 'U',
  2140. '\u1EE6': 'U',
  2141. '\u016E': 'U',
  2142. '\u0170': 'U',
  2143. '\u01D3': 'U',
  2144. '\u0214': 'U',
  2145. '\u0216': 'U',
  2146. '\u01AF': 'U',
  2147. '\u1EEA': 'U',
  2148. '\u1EE8': 'U',
  2149. '\u1EEE': 'U',
  2150. '\u1EEC': 'U',
  2151. '\u1EF0': 'U',
  2152. '\u1EE4': 'U',
  2153. '\u1E72': 'U',
  2154. '\u0172': 'U',
  2155. '\u1E76': 'U',
  2156. '\u1E74': 'U',
  2157. '\u0244': 'U',
  2158. '\u24CB': 'V',
  2159. '\uFF36': 'V',
  2160. '\u1E7C': 'V',
  2161. '\u1E7E': 'V',
  2162. '\u01B2': 'V',
  2163. '\uA75E': 'V',
  2164. '\u0245': 'V',
  2165. '\uA760': 'VY',
  2166. '\u24CC': 'W',
  2167. '\uFF37': 'W',
  2168. '\u1E80': 'W',
  2169. '\u1E82': 'W',
  2170. '\u0174': 'W',
  2171. '\u1E86': 'W',
  2172. '\u1E84': 'W',
  2173. '\u1E88': 'W',
  2174. '\u2C72': 'W',
  2175. '\u24CD': 'X',
  2176. '\uFF38': 'X',
  2177. '\u1E8A': 'X',
  2178. '\u1E8C': 'X',
  2179. '\u24CE': 'Y',
  2180. '\uFF39': 'Y',
  2181. '\u1EF2': 'Y',
  2182. '\u00DD': 'Y',
  2183. '\u0176': 'Y',
  2184. '\u1EF8': 'Y',
  2185. '\u0232': 'Y',
  2186. '\u1E8E': 'Y',
  2187. '\u0178': 'Y',
  2188. '\u1EF6': 'Y',
  2189. '\u1EF4': 'Y',
  2190. '\u01B3': 'Y',
  2191. '\u024E': 'Y',
  2192. '\u1EFE': 'Y',
  2193. '\u24CF': 'Z',
  2194. '\uFF3A': 'Z',
  2195. '\u0179': 'Z',
  2196. '\u1E90': 'Z',
  2197. '\u017B': 'Z',
  2198. '\u017D': 'Z',
  2199. '\u1E92': 'Z',
  2200. '\u1E94': 'Z',
  2201. '\u01B5': 'Z',
  2202. '\u0224': 'Z',
  2203. '\u2C7F': 'Z',
  2204. '\u2C6B': 'Z',
  2205. '\uA762': 'Z',
  2206. '\u24D0': 'a',
  2207. '\uFF41': 'a',
  2208. '\u1E9A': 'a',
  2209. '\u00E0': 'a',
  2210. '\u00E1': 'a',
  2211. '\u00E2': 'a',
  2212. '\u1EA7': 'a',
  2213. '\u1EA5': 'a',
  2214. '\u1EAB': 'a',
  2215. '\u1EA9': 'a',
  2216. '\u00E3': 'a',
  2217. '\u0101': 'a',
  2218. '\u0103': 'a',
  2219. '\u1EB1': 'a',
  2220. '\u1EAF': 'a',
  2221. '\u1EB5': 'a',
  2222. '\u1EB3': 'a',
  2223. '\u0227': 'a',
  2224. '\u01E1': 'a',
  2225. '\u00E4': 'a',
  2226. '\u01DF': 'a',
  2227. '\u1EA3': 'a',
  2228. '\u00E5': 'a',
  2229. '\u01FB': 'a',
  2230. '\u01CE': 'a',
  2231. '\u0201': 'a',
  2232. '\u0203': 'a',
  2233. '\u1EA1': 'a',
  2234. '\u1EAD': 'a',
  2235. '\u1EB7': 'a',
  2236. '\u1E01': 'a',
  2237. '\u0105': 'a',
  2238. '\u2C65': 'a',
  2239. '\u0250': 'a',
  2240. '\uA733': 'aa',
  2241. '\u00E6': 'ae',
  2242. '\u01FD': 'ae',
  2243. '\u01E3': 'ae',
  2244. '\uA735': 'ao',
  2245. '\uA737': 'au',
  2246. '\uA739': 'av',
  2247. '\uA73B': 'av',
  2248. '\uA73D': 'ay',
  2249. '\u24D1': 'b',
  2250. '\uFF42': 'b',
  2251. '\u1E03': 'b',
  2252. '\u1E05': 'b',
  2253. '\u1E07': 'b',
  2254. '\u0180': 'b',
  2255. '\u0183': 'b',
  2256. '\u0253': 'b',
  2257. '\u24D2': 'c',
  2258. '\uFF43': 'c',
  2259. '\u0107': 'c',
  2260. '\u0109': 'c',
  2261. '\u010B': 'c',
  2262. '\u010D': 'c',
  2263. '\u00E7': 'c',
  2264. '\u1E09': 'c',
  2265. '\u0188': 'c',
  2266. '\u023C': 'c',
  2267. '\uA73F': 'c',
  2268. '\u2184': 'c',
  2269. '\u24D3': 'd',
  2270. '\uFF44': 'd',
  2271. '\u1E0B': 'd',
  2272. '\u010F': 'd',
  2273. '\u1E0D': 'd',
  2274. '\u1E11': 'd',
  2275. '\u1E13': 'd',
  2276. '\u1E0F': 'd',
  2277. '\u0111': 'd',
  2278. '\u018C': 'd',
  2279. '\u0256': 'd',
  2280. '\u0257': 'd',
  2281. '\uA77A': 'd',
  2282. '\u01F3': 'dz',
  2283. '\u01C6': 'dz',
  2284. '\u24D4': 'e',
  2285. '\uFF45': 'e',
  2286. '\u00E8': 'e',
  2287. '\u00E9': 'e',
  2288. '\u00EA': 'e',
  2289. '\u1EC1': 'e',
  2290. '\u1EBF': 'e',
  2291. '\u1EC5': 'e',
  2292. '\u1EC3': 'e',
  2293. '\u1EBD': 'e',
  2294. '\u0113': 'e',
  2295. '\u1E15': 'e',
  2296. '\u1E17': 'e',
  2297. '\u0115': 'e',
  2298. '\u0117': 'e',
  2299. '\u00EB': 'e',
  2300. '\u1EBB': 'e',
  2301. '\u011B': 'e',
  2302. '\u0205': 'e',
  2303. '\u0207': 'e',
  2304. '\u1EB9': 'e',
  2305. '\u1EC7': 'e',
  2306. '\u0229': 'e',
  2307. '\u1E1D': 'e',
  2308. '\u0119': 'e',
  2309. '\u1E19': 'e',
  2310. '\u1E1B': 'e',
  2311. '\u0247': 'e',
  2312. '\u025B': 'e',
  2313. '\u01DD': 'e',
  2314. '\u24D5': 'f',
  2315. '\uFF46': 'f',
  2316. '\u1E1F': 'f',
  2317. '\u0192': 'f',
  2318. '\uA77C': 'f',
  2319. '\u24D6': 'g',
  2320. '\uFF47': 'g',
  2321. '\u01F5': 'g',
  2322. '\u011D': 'g',
  2323. '\u1E21': 'g',
  2324. '\u011F': 'g',
  2325. '\u0121': 'g',
  2326. '\u01E7': 'g',
  2327. '\u0123': 'g',
  2328. '\u01E5': 'g',
  2329. '\u0260': 'g',
  2330. '\uA7A1': 'g',
  2331. '\u1D79': 'g',
  2332. '\uA77F': 'g',
  2333. '\u24D7': 'h',
  2334. '\uFF48': 'h',
  2335. '\u0125': 'h',
  2336. '\u1E23': 'h',
  2337. '\u1E27': 'h',
  2338. '\u021F': 'h',
  2339. '\u1E25': 'h',
  2340. '\u1E29': 'h',
  2341. '\u1E2B': 'h',
  2342. '\u1E96': 'h',
  2343. '\u0127': 'h',
  2344. '\u2C68': 'h',
  2345. '\u2C76': 'h',
  2346. '\u0265': 'h',
  2347. '\u0195': 'hv',
  2348. '\u24D8': 'i',
  2349. '\uFF49': 'i',
  2350. '\u00EC': 'i',
  2351. '\u00ED': 'i',
  2352. '\u00EE': 'i',
  2353. '\u0129': 'i',
  2354. '\u012B': 'i',
  2355. '\u012D': 'i',
  2356. '\u00EF': 'i',
  2357. '\u1E2F': 'i',
  2358. '\u1EC9': 'i',
  2359. '\u01D0': 'i',
  2360. '\u0209': 'i',
  2361. '\u020B': 'i',
  2362. '\u1ECB': 'i',
  2363. '\u012F': 'i',
  2364. '\u1E2D': 'i',
  2365. '\u0268': 'i',
  2366. '\u0131': 'i',
  2367. '\u24D9': 'j',
  2368. '\uFF4A': 'j',
  2369. '\u0135': 'j',
  2370. '\u01F0': 'j',
  2371. '\u0249': 'j',
  2372. '\u24DA': 'k',
  2373. '\uFF4B': 'k',
  2374. '\u1E31': 'k',
  2375. '\u01E9': 'k',
  2376. '\u1E33': 'k',
  2377. '\u0137': 'k',
  2378. '\u1E35': 'k',
  2379. '\u0199': 'k',
  2380. '\u2C6A': 'k',
  2381. '\uA741': 'k',
  2382. '\uA743': 'k',
  2383. '\uA745': 'k',
  2384. '\uA7A3': 'k',
  2385. '\u24DB': 'l',
  2386. '\uFF4C': 'l',
  2387. '\u0140': 'l',
  2388. '\u013A': 'l',
  2389. '\u013E': 'l',
  2390. '\u1E37': 'l',
  2391. '\u1E39': 'l',
  2392. '\u013C': 'l',
  2393. '\u1E3D': 'l',
  2394. '\u1E3B': 'l',
  2395. '\u017F': 'l',
  2396. '\u0142': 'l',
  2397. '\u019A': 'l',
  2398. '\u026B': 'l',
  2399. '\u2C61': 'l',
  2400. '\uA749': 'l',
  2401. '\uA781': 'l',
  2402. '\uA747': 'l',
  2403. '\u01C9': 'lj',
  2404. '\u24DC': 'm',
  2405. '\uFF4D': 'm',
  2406. '\u1E3F': 'm',
  2407. '\u1E41': 'm',
  2408. '\u1E43': 'm',
  2409. '\u0271': 'm',
  2410. '\u026F': 'm',
  2411. '\u24DD': 'n',
  2412. '\uFF4E': 'n',
  2413. '\u01F9': 'n',
  2414. '\u0144': 'n',
  2415. '\u00F1': 'n',
  2416. '\u1E45': 'n',
  2417. '\u0148': 'n',
  2418. '\u1E47': 'n',
  2419. '\u0146': 'n',
  2420. '\u1E4B': 'n',
  2421. '\u1E49': 'n',
  2422. '\u019E': 'n',
  2423. '\u0272': 'n',
  2424. '\u0149': 'n',
  2425. '\uA791': 'n',
  2426. '\uA7A5': 'n',
  2427. '\u01CC': 'nj',
  2428. '\u24DE': 'o',
  2429. '\uFF4F': 'o',
  2430. '\u00F2': 'o',
  2431. '\u00F3': 'o',
  2432. '\u00F4': 'o',
  2433. '\u1ED3': 'o',
  2434. '\u1ED1': 'o',
  2435. '\u1ED7': 'o',
  2436. '\u1ED5': 'o',
  2437. '\u00F5': 'o',
  2438. '\u1E4D': 'o',
  2439. '\u022D': 'o',
  2440. '\u1E4F': 'o',
  2441. '\u014D': 'o',
  2442. '\u1E51': 'o',
  2443. '\u1E53': 'o',
  2444. '\u014F': 'o',
  2445. '\u022F': 'o',
  2446. '\u0231': 'o',
  2447. '\u00F6': 'o',
  2448. '\u022B': 'o',
  2449. '\u1ECF': 'o',
  2450. '\u0151': 'o',
  2451. '\u01D2': 'o',
  2452. '\u020D': 'o',
  2453. '\u020F': 'o',
  2454. '\u01A1': 'o',
  2455. '\u1EDD': 'o',
  2456. '\u1EDB': 'o',
  2457. '\u1EE1': 'o',
  2458. '\u1EDF': 'o',
  2459. '\u1EE3': 'o',
  2460. '\u1ECD': 'o',
  2461. '\u1ED9': 'o',
  2462. '\u01EB': 'o',
  2463. '\u01ED': 'o',
  2464. '\u00F8': 'o',
  2465. '\u01FF': 'o',
  2466. '\u0254': 'o',
  2467. '\uA74B': 'o',
  2468. '\uA74D': 'o',
  2469. '\u0275': 'o',
  2470. '\u01A3': 'oi',
  2471. '\u0223': 'ou',
  2472. '\uA74F': 'oo',
  2473. '\u24DF': 'p',
  2474. '\uFF50': 'p',
  2475. '\u1E55': 'p',
  2476. '\u1E57': 'p',
  2477. '\u01A5': 'p',
  2478. '\u1D7D': 'p',
  2479. '\uA751': 'p',
  2480. '\uA753': 'p',
  2481. '\uA755': 'p',
  2482. '\u24E0': 'q',
  2483. '\uFF51': 'q',
  2484. '\u024B': 'q',
  2485. '\uA757': 'q',
  2486. '\uA759': 'q',
  2487. '\u24E1': 'r',
  2488. '\uFF52': 'r',
  2489. '\u0155': 'r',
  2490. '\u1E59': 'r',
  2491. '\u0159': 'r',
  2492. '\u0211': 'r',
  2493. '\u0213': 'r',
  2494. '\u1E5B': 'r',
  2495. '\u1E5D': 'r',
  2496. '\u0157': 'r',
  2497. '\u1E5F': 'r',
  2498. '\u024D': 'r',
  2499. '\u027D': 'r',
  2500. '\uA75B': 'r',
  2501. '\uA7A7': 'r',
  2502. '\uA783': 'r',
  2503. '\u24E2': 's',
  2504. '\uFF53': 's',
  2505. '\u00DF': 's',
  2506. '\u015B': 's',
  2507. '\u1E65': 's',
  2508. '\u015D': 's',
  2509. '\u1E61': 's',
  2510. '\u0161': 's',
  2511. '\u1E67': 's',
  2512. '\u1E63': 's',
  2513. '\u1E69': 's',
  2514. '\u0219': 's',
  2515. '\u015F': 's',
  2516. '\u023F': 's',
  2517. '\uA7A9': 's',
  2518. '\uA785': 's',
  2519. '\u1E9B': 's',
  2520. '\u24E3': 't',
  2521. '\uFF54': 't',
  2522. '\u1E6B': 't',
  2523. '\u1E97': 't',
  2524. '\u0165': 't',
  2525. '\u1E6D': 't',
  2526. '\u021B': 't',
  2527. '\u0163': 't',
  2528. '\u1E71': 't',
  2529. '\u1E6F': 't',
  2530. '\u0167': 't',
  2531. '\u01AD': 't',
  2532. '\u0288': 't',
  2533. '\u2C66': 't',
  2534. '\uA787': 't',
  2535. '\uA729': 'tz',
  2536. '\u24E4': 'u',
  2537. '\uFF55': 'u',
  2538. '\u00F9': 'u',
  2539. '\u00FA': 'u',
  2540. '\u00FB': 'u',
  2541. '\u0169': 'u',
  2542. '\u1E79': 'u',
  2543. '\u016B': 'u',
  2544. '\u1E7B': 'u',
  2545. '\u016D': 'u',
  2546. '\u00FC': 'u',
  2547. '\u01DC': 'u',
  2548. '\u01D8': 'u',
  2549. '\u01D6': 'u',
  2550. '\u01DA': 'u',
  2551. '\u1EE7': 'u',
  2552. '\u016F': 'u',
  2553. '\u0171': 'u',
  2554. '\u01D4': 'u',
  2555. '\u0215': 'u',
  2556. '\u0217': 'u',
  2557. '\u01B0': 'u',
  2558. '\u1EEB': 'u',
  2559. '\u1EE9': 'u',
  2560. '\u1EEF': 'u',
  2561. '\u1EED': 'u',
  2562. '\u1EF1': 'u',
  2563. '\u1EE5': 'u',
  2564. '\u1E73': 'u',
  2565. '\u0173': 'u',
  2566. '\u1E77': 'u',
  2567. '\u1E75': 'u',
  2568. '\u0289': 'u',
  2569. '\u24E5': 'v',
  2570. '\uFF56': 'v',
  2571. '\u1E7D': 'v',
  2572. '\u1E7F': 'v',
  2573. '\u028B': 'v',
  2574. '\uA75F': 'v',
  2575. '\u028C': 'v',
  2576. '\uA761': 'vy',
  2577. '\u24E6': 'w',
  2578. '\uFF57': 'w',
  2579. '\u1E81': 'w',
  2580. '\u1E83': 'w',
  2581. '\u0175': 'w',
  2582. '\u1E87': 'w',
  2583. '\u1E85': 'w',
  2584. '\u1E98': 'w',
  2585. '\u1E89': 'w',
  2586. '\u2C73': 'w',
  2587. '\u24E7': 'x',
  2588. '\uFF58': 'x',
  2589. '\u1E8B': 'x',
  2590. '\u1E8D': 'x',
  2591. '\u24E8': 'y',
  2592. '\uFF59': 'y',
  2593. '\u1EF3': 'y',
  2594. '\u00FD': 'y',
  2595. '\u0177': 'y',
  2596. '\u1EF9': 'y',
  2597. '\u0233': 'y',
  2598. '\u1E8F': 'y',
  2599. '\u00FF': 'y',
  2600. '\u1EF7': 'y',
  2601. '\u1E99': 'y',
  2602. '\u1EF5': 'y',
  2603. '\u01B4': 'y',
  2604. '\u024F': 'y',
  2605. '\u1EFF': 'y',
  2606. '\u24E9': 'z',
  2607. '\uFF5A': 'z',
  2608. '\u017A': 'z',
  2609. '\u1E91': 'z',
  2610. '\u017C': 'z',
  2611. '\u017E': 'z',
  2612. '\u1E93': 'z',
  2613. '\u1E95': 'z',
  2614. '\u01B6': 'z',
  2615. '\u0225': 'z',
  2616. '\u0240': 'z',
  2617. '\u2C6C': 'z',
  2618. '\uA763': 'z',
  2619. '\u0386': '\u0391',
  2620. '\u0388': '\u0395',
  2621. '\u0389': '\u0397',
  2622. '\u038A': '\u0399',
  2623. '\u03AA': '\u0399',
  2624. '\u038C': '\u039F',
  2625. '\u038E': '\u03A5',
  2626. '\u03AB': '\u03A5',
  2627. '\u038F': '\u03A9',
  2628. '\u03AC': '\u03B1',
  2629. '\u03AD': '\u03B5',
  2630. '\u03AE': '\u03B7',
  2631. '\u03AF': '\u03B9',
  2632. '\u03CA': '\u03B9',
  2633. '\u0390': '\u03B9',
  2634. '\u03CC': '\u03BF',
  2635. '\u03CD': '\u03C5',
  2636. '\u03CB': '\u03C5',
  2637. '\u03B0': '\u03C5',
  2638. '\u03C9': '\u03C9',
  2639. '\u03C2': '\u03C3'
  2640. };
  2641. return diacritics;
  2642. });
  2643. S2.define('select2/data/base',[
  2644. '../utils'
  2645. ], function (Utils) {
  2646. function BaseAdapter ($element, options) {
  2647. BaseAdapter.__super__.constructor.call(this);
  2648. }
  2649. Utils.Extend(BaseAdapter, Utils.Observable);
  2650. BaseAdapter.prototype.current = function (callback) {
  2651. throw new Error('The `current` method must be defined in child classes.');
  2652. };
  2653. BaseAdapter.prototype.query = function (params, callback) {
  2654. throw new Error('The `query` method must be defined in child classes.');
  2655. };
  2656. BaseAdapter.prototype.bind = function (container, $container) {
  2657. // Can be implemented in subclasses
  2658. };
  2659. BaseAdapter.prototype.destroy = function () {
  2660. // Can be implemented in subclasses
  2661. };
  2662. BaseAdapter.prototype.generateResultId = function (container, data) {
  2663. var id = container.id + '-result-';
  2664. id += Utils.generateChars(4);
  2665. if (data.id != null) {
  2666. id += '-' + data.id.toString();
  2667. } else {
  2668. id += '-' + Utils.generateChars(4);
  2669. }
  2670. return id;
  2671. };
  2672. return BaseAdapter;
  2673. });
  2674. S2.define('select2/data/select',[
  2675. './base',
  2676. '../utils',
  2677. 'jquery'
  2678. ], function (BaseAdapter, Utils, $) {
  2679. function SelectAdapter ($element, options) {
  2680. this.$element = $element;
  2681. this.options = options;
  2682. SelectAdapter.__super__.constructor.call(this);
  2683. }
  2684. Utils.Extend(SelectAdapter, BaseAdapter);
  2685. SelectAdapter.prototype.current = function (callback) {
  2686. var data = [];
  2687. var self = this;
  2688. this.$element.find(':selected').each(function () {
  2689. var $option = $(this);
  2690. var option = self.item($option);
  2691. data.push(option);
  2692. });
  2693. callback(data);
  2694. };
  2695. SelectAdapter.prototype.select = function (data) {
  2696. var self = this;
  2697. data.selected = true;
  2698. // If data.element is a DOM node, use it instead
  2699. if ($(data.element).is('option')) {
  2700. data.element.selected = true;
  2701. this.$element.trigger('change');
  2702. return;
  2703. }
  2704. if (this.$element.prop('multiple')) {
  2705. this.current(function (currentData) {
  2706. var val = [];
  2707. data = [data];
  2708. data.push.apply(data, currentData);
  2709. for (var d = 0; d < data.length; d++) {
  2710. var id = data[d].id;
  2711. if ($.inArray(id, val) === -1) {
  2712. val.push(id);
  2713. }
  2714. }
  2715. self.$element.val(val);
  2716. self.$element.trigger('change');
  2717. });
  2718. } else {
  2719. var val = data.id;
  2720. this.$element.val(val);
  2721. this.$element.trigger('change');
  2722. }
  2723. };
  2724. SelectAdapter.prototype.unselect = function (data) {
  2725. var self = this;
  2726. if (!this.$element.prop('multiple')) {
  2727. return;
  2728. }
  2729. data.selected = false;
  2730. if ($(data.element).is('option')) {
  2731. data.element.selected = false;
  2732. this.$element.trigger('change');
  2733. return;
  2734. }
  2735. this.current(function (currentData) {
  2736. var val = [];
  2737. for (var d = 0; d < currentData.length; d++) {
  2738. var id = currentData[d].id;
  2739. if (id !== data.id && $.inArray(id, val) === -1) {
  2740. val.push(id);
  2741. }
  2742. }
  2743. self.$element.val(val);
  2744. self.$element.trigger('change');
  2745. });
  2746. };
  2747. SelectAdapter.prototype.bind = function (container, $container) {
  2748. var self = this;
  2749. this.container = container;
  2750. container.on('select', function (params) {
  2751. self.select(params.data);
  2752. });
  2753. container.on('unselect', function (params) {
  2754. self.unselect(params.data);
  2755. });
  2756. };
  2757. SelectAdapter.prototype.destroy = function () {
  2758. // Remove anything added to child elements
  2759. this.$element.find('*').each(function () {
  2760. // Remove any custom data set by Select2
  2761. Utils.RemoveData(this);
  2762. });
  2763. };
  2764. SelectAdapter.prototype.query = function (params, callback) {
  2765. var data = [];
  2766. var self = this;
  2767. var $options = this.$element.children();
  2768. $options.each(function () {
  2769. var $option = $(this);
  2770. if (!$option.is('option') && !$option.is('optgroup')) {
  2771. return;
  2772. }
  2773. var option = self.item($option);
  2774. var matches = self.matches(params, option);
  2775. if (matches !== null) {
  2776. data.push(matches);
  2777. }
  2778. });
  2779. callback({
  2780. results: data
  2781. });
  2782. };
  2783. SelectAdapter.prototype.addOptions = function ($options) {
  2784. Utils.appendMany(this.$element, $options);
  2785. };
  2786. SelectAdapter.prototype.option = function (data) {
  2787. var option;
  2788. if (data.children) {
  2789. option = document.createElement('optgroup');
  2790. option.label = data.text;
  2791. } else {
  2792. option = document.createElement('option');
  2793. if (option.textContent !== undefined) {
  2794. option.textContent = data.text;
  2795. } else {
  2796. option.innerText = data.text;
  2797. }
  2798. }
  2799. if (data.id !== undefined) {
  2800. option.value = data.id;
  2801. }
  2802. if (data.disabled) {
  2803. option.disabled = true;
  2804. }
  2805. if (data.selected) {
  2806. option.selected = true;
  2807. }
  2808. if (data.title) {
  2809. option.title = data.title;
  2810. }
  2811. var $option = $(option);
  2812. var normalizedData = this._normalizeItem(data);
  2813. normalizedData.element = option;
  2814. // Override the option's data with the combined data
  2815. Utils.StoreData(option, 'data', normalizedData);
  2816. return $option;
  2817. };
  2818. SelectAdapter.prototype.item = function ($option) {
  2819. var data = {};
  2820. data = Utils.GetData($option[0], 'data');
  2821. if (data != null) {
  2822. return data;
  2823. }
  2824. if ($option.is('option')) {
  2825. data = {
  2826. id: $option.val(),
  2827. text: $option.text(),
  2828. disabled: $option.prop('disabled'),
  2829. selected: $option.prop('selected'),
  2830. title: $option.prop('title')
  2831. };
  2832. } else if ($option.is('optgroup')) {
  2833. data = {
  2834. text: $option.prop('label'),
  2835. children: [],
  2836. title: $option.prop('title')
  2837. };
  2838. var $children = $option.children('option');
  2839. var children = [];
  2840. for (var c = 0; c < $children.length; c++) {
  2841. var $child = $($children[c]);
  2842. var child = this.item($child);
  2843. children.push(child);
  2844. }
  2845. data.children = children;
  2846. }
  2847. data = this._normalizeItem(data);
  2848. data.element = $option[0];
  2849. Utils.StoreData($option[0], 'data', data);
  2850. return data;
  2851. };
  2852. SelectAdapter.prototype._normalizeItem = function (item) {
  2853. if (item !== Object(item)) {
  2854. item = {
  2855. id: item,
  2856. text: item
  2857. };
  2858. }
  2859. item = $.extend({}, {
  2860. text: ''
  2861. }, item);
  2862. var defaults = {
  2863. selected: false,
  2864. disabled: false
  2865. };
  2866. if (item.id != null) {
  2867. item.id = item.id.toString();
  2868. }
  2869. if (item.text != null) {
  2870. item.text = item.text.toString();
  2871. }
  2872. if (item._resultId == null && item.id && this.container != null) {
  2873. item._resultId = this.generateResultId(this.container, item);
  2874. }
  2875. return $.extend({}, defaults, item);
  2876. };
  2877. SelectAdapter.prototype.matches = function (params, data) {
  2878. var matcher = this.options.get('matcher');
  2879. return matcher(params, data);
  2880. };
  2881. return SelectAdapter;
  2882. });
  2883. S2.define('select2/data/array',[
  2884. './select',
  2885. '../utils',
  2886. 'jquery'
  2887. ], function (SelectAdapter, Utils, $) {
  2888. function ArrayAdapter ($element, options) {
  2889. var data = options.get('data') || [];
  2890. ArrayAdapter.__super__.constructor.call(this, $element, options);
  2891. this.addOptions(this.convertToOptions(data));
  2892. }
  2893. Utils.Extend(ArrayAdapter, SelectAdapter);
  2894. ArrayAdapter.prototype.select = function (data) {
  2895. var $option = this.$element.find('option').filter(function (i, elm) {
  2896. return elm.value == data.id.toString();
  2897. });
  2898. if ($option.length === 0) {
  2899. $option = this.option(data);
  2900. this.addOptions($option);
  2901. }
  2902. ArrayAdapter.__super__.select.call(this, data);
  2903. };
  2904. ArrayAdapter.prototype.convertToOptions = function (data) {
  2905. var self = this;
  2906. var $existing = this.$element.find('option');
  2907. var existingIds = $existing.map(function () {
  2908. return self.item($(this)).id;
  2909. }).get();
  2910. var $options = [];
  2911. // Filter out all items except for the one passed in the argument
  2912. function onlyItem (item) {
  2913. return function () {
  2914. return $(this).val() == item.id;
  2915. };
  2916. }
  2917. for (var d = 0; d < data.length; d++) {
  2918. var item = this._normalizeItem(data[d]);
  2919. // Skip items which were pre-loaded, only merge the data
  2920. if ($.inArray(item.id, existingIds) >= 0) {
  2921. var $existingOption = $existing.filter(onlyItem(item));
  2922. var existingData = this.item($existingOption);
  2923. var newData = $.extend(true, {}, item, existingData);
  2924. var $newOption = this.option(newData);
  2925. $existingOption.replaceWith($newOption);
  2926. continue;
  2927. }
  2928. var $option = this.option(item);
  2929. if (item.children) {
  2930. var $children = this.convertToOptions(item.children);
  2931. Utils.appendMany($option, $children);
  2932. }
  2933. $options.push($option);
  2934. }
  2935. return $options;
  2936. };
  2937. return ArrayAdapter;
  2938. });
  2939. S2.define('select2/data/ajax',[
  2940. './array',
  2941. '../utils',
  2942. 'jquery'
  2943. ], function (ArrayAdapter, Utils, $) {
  2944. function AjaxAdapter ($element, options) {
  2945. this.ajaxOptions = this._applyDefaults(options.get('ajax'));
  2946. if (this.ajaxOptions.processResults != null) {
  2947. this.processResults = this.ajaxOptions.processResults;
  2948. }
  2949. AjaxAdapter.__super__.constructor.call(this, $element, options);
  2950. }
  2951. Utils.Extend(AjaxAdapter, ArrayAdapter);
  2952. AjaxAdapter.prototype._applyDefaults = function (options) {
  2953. var defaults = {
  2954. data: function (params) {
  2955. return $.extend({}, params, {
  2956. q: params.term
  2957. });
  2958. },
  2959. transport: function (params, success, failure) {
  2960. var $request = $.ajax(params);
  2961. $request.then(success);
  2962. $request.fail(failure);
  2963. return $request;
  2964. }
  2965. };
  2966. return $.extend({}, defaults, options, true);
  2967. };
  2968. AjaxAdapter.prototype.processResults = function (results) {
  2969. return results;
  2970. };
  2971. AjaxAdapter.prototype.query = function (params, callback) {
  2972. var matches = [];
  2973. var self = this;
  2974. if (this._request != null) {
  2975. // JSONP requests cannot always be aborted
  2976. if ($.isFunction(this._request.abort)) {
  2977. this._request.abort();
  2978. }
  2979. this._request = null;
  2980. }
  2981. var options = $.extend({
  2982. type: 'GET'
  2983. }, this.ajaxOptions);
  2984. if (typeof options.url === 'function') {
  2985. options.url = options.url.call(this.$element, params);
  2986. }
  2987. if (typeof options.data === 'function') {
  2988. options.data = options.data.call(this.$element, params);
  2989. }
  2990. function request () {
  2991. var $request = options.transport(options, function (data) {
  2992. var results = self.processResults(data, params);
  2993. if (self.options.get('debug') && window.console && console.error) {
  2994. // Check to make sure that the response included a `results` key.
  2995. if (!results || !results.results || !$.isArray(results.results)) {
  2996. console.error(
  2997. 'Select2: The AJAX results did not return an array in the ' +
  2998. '`results` key of the response.'
  2999. );
  3000. }
  3001. }
  3002. callback(results);
  3003. }, function () {
  3004. // Attempt to detect if a request was aborted
  3005. // Only works if the transport exposes a status property
  3006. if ('status' in $request &&
  3007. ($request.status === 0 || $request.status === '0')) {
  3008. return;
  3009. }
  3010. self.trigger('results:message', {
  3011. message: 'errorLoading'
  3012. });
  3013. });
  3014. self._request = $request;
  3015. }
  3016. if (this.ajaxOptions.delay && params.term != null) {
  3017. if (this._queryTimeout) {
  3018. window.clearTimeout(this._queryTimeout);
  3019. }
  3020. this._queryTimeout = window.setTimeout(request, this.ajaxOptions.delay);
  3021. } else {
  3022. request();
  3023. }
  3024. };
  3025. return AjaxAdapter;
  3026. });
  3027. S2.define('select2/data/tags',[
  3028. 'jquery'
  3029. ], function ($) {
  3030. function Tags (decorated, $element, options) {
  3031. var tags = options.get('tags');
  3032. var createTag = options.get('createTag');
  3033. if (createTag !== undefined) {
  3034. this.createTag = createTag;
  3035. }
  3036. var insertTag = options.get('insertTag');
  3037. if (insertTag !== undefined) {
  3038. this.insertTag = insertTag;
  3039. }
  3040. decorated.call(this, $element, options);
  3041. if ($.isArray(tags)) {
  3042. for (var t = 0; t < tags.length; t++) {
  3043. var tag = tags[t];
  3044. var item = this._normalizeItem(tag);
  3045. var $option = this.option(item);
  3046. this.$element.append($option);
  3047. }
  3048. }
  3049. }
  3050. Tags.prototype.query = function (decorated, params, callback) {
  3051. var self = this;
  3052. this._removeOldTags();
  3053. if (params.term == null || params.page != null) {
  3054. decorated.call(this, params, callback);
  3055. return;
  3056. }
  3057. function wrapper (obj, child) {
  3058. var data = obj.results;
  3059. for (var i = 0; i < data.length; i++) {
  3060. var option = data[i];
  3061. var checkChildren = (
  3062. option.children != null &&
  3063. !wrapper({
  3064. results: option.children
  3065. }, true)
  3066. );
  3067. var optionText = (option.text || '').toUpperCase();
  3068. var paramsTerm = (params.term || '').toUpperCase();
  3069. var checkText = optionText === paramsTerm;
  3070. if (checkText || checkChildren) {
  3071. if (child) {
  3072. return false;
  3073. }
  3074. obj.data = data;
  3075. callback(obj);
  3076. return;
  3077. }
  3078. }
  3079. if (child) {
  3080. return true;
  3081. }
  3082. var tag = self.createTag(params);
  3083. if (tag != null) {
  3084. var $option = self.option(tag);
  3085. $option.attr('data-select2-tag', true);
  3086. self.addOptions([$option]);
  3087. self.insertTag(data, tag);
  3088. }
  3089. obj.results = data;
  3090. callback(obj);
  3091. }
  3092. decorated.call(this, params, wrapper);
  3093. };
  3094. Tags.prototype.createTag = function (decorated, params) {
  3095. var term = $.trim(params.term);
  3096. if (term === '') {
  3097. return null;
  3098. }
  3099. return {
  3100. id: term,
  3101. text: term
  3102. };
  3103. };
  3104. Tags.prototype.insertTag = function (_, data, tag) {
  3105. data.unshift(tag);
  3106. };
  3107. Tags.prototype._removeOldTags = function (_) {
  3108. var tag = this._lastTag;
  3109. var $options = this.$element.find('option[data-select2-tag]');
  3110. $options.each(function () {
  3111. if (this.selected) {
  3112. return;
  3113. }
  3114. $(this).remove();
  3115. });
  3116. };
  3117. return Tags;
  3118. });
  3119. S2.define('select2/data/tokenizer',[
  3120. 'jquery'
  3121. ], function ($) {
  3122. function Tokenizer (decorated, $element, options) {
  3123. var tokenizer = options.get('tokenizer');
  3124. if (tokenizer !== undefined) {
  3125. this.tokenizer = tokenizer;
  3126. }
  3127. decorated.call(this, $element, options);
  3128. }
  3129. Tokenizer.prototype.bind = function (decorated, container, $container) {
  3130. decorated.call(this, container, $container);
  3131. this.$search = container.dropdown.$search || container.selection.$search ||
  3132. $container.find('.select2-search__field');
  3133. };
  3134. Tokenizer.prototype.query = function (decorated, params, callback) {
  3135. var self = this;
  3136. function createAndSelect (data) {
  3137. // Normalize the data object so we can use it for checks
  3138. var item = self._normalizeItem(data);
  3139. // Check if the data object already exists as a tag
  3140. // Select it if it doesn't
  3141. var $existingOptions = self.$element.find('option').filter(function () {
  3142. return $(this).val() === item.id;
  3143. });
  3144. // If an existing option wasn't found for it, create the option
  3145. if (!$existingOptions.length) {
  3146. var $option = self.option(item);
  3147. $option.attr('data-select2-tag', true);
  3148. self._removeOldTags();
  3149. self.addOptions([$option]);
  3150. }
  3151. // Select the item, now that we know there is an option for it
  3152. select(item);
  3153. }
  3154. function select (data) {
  3155. self.trigger('select', {
  3156. data: data
  3157. });
  3158. }
  3159. params.term = params.term || '';
  3160. var tokenData = this.tokenizer(params, this.options, createAndSelect);
  3161. if (tokenData.term !== params.term) {
  3162. // Replace the search term if we have the search box
  3163. if (this.$search.length) {
  3164. this.$search.val(tokenData.term);
  3165. this.$search.focus();
  3166. }
  3167. params.term = tokenData.term;
  3168. }
  3169. decorated.call(this, params, callback);
  3170. };
  3171. Tokenizer.prototype.tokenizer = function (_, params, options, callback) {
  3172. var separators = options.get('tokenSeparators') || [];
  3173. var term = params.term;
  3174. var i = 0;
  3175. var createTag = this.createTag || function (params) {
  3176. return {
  3177. id: params.term,
  3178. text: params.term
  3179. };
  3180. };
  3181. while (i < term.length) {
  3182. var termChar = term[i];
  3183. if ($.inArray(termChar, separators) === -1) {
  3184. i++;
  3185. continue;
  3186. }
  3187. var part = term.substr(0, i);
  3188. var partParams = $.extend({}, params, {
  3189. term: part
  3190. });
  3191. var data = createTag(partParams);
  3192. if (data == null) {
  3193. i++;
  3194. continue;
  3195. }
  3196. callback(data);
  3197. // Reset the term to not include the tokenized portion
  3198. term = term.substr(i + 1) || '';
  3199. i = 0;
  3200. }
  3201. return {
  3202. term: term
  3203. };
  3204. };
  3205. return Tokenizer;
  3206. });
  3207. S2.define('select2/data/minimumInputLength',[
  3208. ], function () {
  3209. function MinimumInputLength (decorated, $e, options) {
  3210. this.minimumInputLength = options.get('minimumInputLength');
  3211. decorated.call(this, $e, options);
  3212. }
  3213. MinimumInputLength.prototype.query = function (decorated, params, callback) {
  3214. params.term = params.term || '';
  3215. if (params.term.length < this.minimumInputLength) {
  3216. this.trigger('results:message', {
  3217. message: 'inputTooShort',
  3218. args: {
  3219. minimum: this.minimumInputLength,
  3220. input: params.term,
  3221. params: params
  3222. }
  3223. });
  3224. return;
  3225. }
  3226. decorated.call(this, params, callback);
  3227. };
  3228. return MinimumInputLength;
  3229. });
  3230. S2.define('select2/data/maximumInputLength',[
  3231. ], function () {
  3232. function MaximumInputLength (decorated, $e, options) {
  3233. this.maximumInputLength = options.get('maximumInputLength');
  3234. decorated.call(this, $e, options);
  3235. }
  3236. MaximumInputLength.prototype.query = function (decorated, params, callback) {
  3237. params.term = params.term || '';
  3238. if (this.maximumInputLength > 0 &&
  3239. params.term.length > this.maximumInputLength) {
  3240. this.trigger('results:message', {
  3241. message: 'inputTooLong',
  3242. args: {
  3243. maximum: this.maximumInputLength,
  3244. input: params.term,
  3245. params: params
  3246. }
  3247. });
  3248. return;
  3249. }
  3250. decorated.call(this, params, callback);
  3251. };
  3252. return MaximumInputLength;
  3253. });
  3254. S2.define('select2/data/maximumSelectionLength',[
  3255. ], function (){
  3256. function MaximumSelectionLength (decorated, $e, options) {
  3257. this.maximumSelectionLength = options.get('maximumSelectionLength');
  3258. decorated.call(this, $e, options);
  3259. }
  3260. MaximumSelectionLength.prototype.query =
  3261. function (decorated, params, callback) {
  3262. var self = this;
  3263. this.current(function (currentData) {
  3264. var count = currentData != null ? currentData.length : 0;
  3265. if (self.maximumSelectionLength > 0 &&
  3266. count >= self.maximumSelectionLength) {
  3267. self.trigger('results:message', {
  3268. message: 'maximumSelected',
  3269. args: {
  3270. maximum: self.maximumSelectionLength
  3271. }
  3272. });
  3273. return;
  3274. }
  3275. decorated.call(self, params, callback);
  3276. });
  3277. };
  3278. return MaximumSelectionLength;
  3279. });
  3280. S2.define('select2/dropdown',[
  3281. 'jquery',
  3282. './utils'
  3283. ], function ($, Utils) {
  3284. function Dropdown ($element, options) {
  3285. this.$element = $element;
  3286. this.options = options;
  3287. Dropdown.__super__.constructor.call(this);
  3288. }
  3289. Utils.Extend(Dropdown, Utils.Observable);
  3290. Dropdown.prototype.render = function () {
  3291. var $dropdown = $(
  3292. '<span class="select2-dropdown">' +
  3293. '<span class="select2-results"></span>' +
  3294. '</span>'
  3295. );
  3296. $dropdown.attr('dir', this.options.get('dir'));
  3297. this.$dropdown = $dropdown;
  3298. return $dropdown;
  3299. };
  3300. Dropdown.prototype.bind = function () {
  3301. // Should be implemented in subclasses
  3302. };
  3303. Dropdown.prototype.position = function ($dropdown, $container) {
  3304. // Should be implmented in subclasses
  3305. };
  3306. Dropdown.prototype.destroy = function () {
  3307. // Remove the dropdown from the DOM
  3308. this.$dropdown.remove();
  3309. };
  3310. return Dropdown;
  3311. });
  3312. S2.define('select2/dropdown/search',[
  3313. 'jquery',
  3314. '../utils'
  3315. ], function ($, Utils) {
  3316. function Search () { }
  3317. Search.prototype.render = function (decorated) {
  3318. var $rendered = decorated.call(this);
  3319. var $search = $(
  3320. '<span class="select2-search select2-search--dropdown">' +
  3321. '<input class="select2-search__field" type="search" tabindex="-1"' +
  3322. ' autocomplete="off" autocorrect="off" autocapitalize="none"' +
  3323. ' spellcheck="false" role="textbox" />' +
  3324. '</span>'
  3325. );
  3326. this.$searchContainer = $search;
  3327. this.$search = $search.find('input');
  3328. $rendered.prepend($search);
  3329. return $rendered;
  3330. };
  3331. Search.prototype.bind = function (decorated, container, $container) {
  3332. var self = this;
  3333. decorated.call(this, container, $container);
  3334. this.$search.on('keydown', function (evt) {
  3335. self.trigger('keypress', evt);
  3336. self._keyUpPrevented = evt.isDefaultPrevented();
  3337. });
  3338. // Workaround for browsers which do not support the `input` event
  3339. // This will prevent double-triggering of events for browsers which support
  3340. // both the `keyup` and `input` events.
  3341. this.$search.on('input', function (evt) {
  3342. // Unbind the duplicated `keyup` event
  3343. $(this).off('keyup');
  3344. });
  3345. this.$search.on('keyup input', function (evt) {
  3346. self.handleSearch(evt);
  3347. });
  3348. container.on('open', function () {
  3349. self.$search.attr('tabindex', 0);
  3350. self.$search.focus();
  3351. window.setTimeout(function () {
  3352. self.$search.focus();
  3353. }, 0);
  3354. });
  3355. container.on('close', function () {
  3356. self.$search.attr('tabindex', -1);
  3357. //self.$search.val('');
  3358. self.$search.blur();
  3359. });
  3360. container.on('focus', function () {
  3361. if (!container.isOpen()) {
  3362. self.$search.focus();
  3363. }
  3364. });
  3365. container.on('results:all', function (params) {
  3366. if (params.query.term == null || params.query.term === '') {
  3367. var showSearch = self.showSearch(params);
  3368. if (showSearch) {
  3369. self.$searchContainer.removeClass('select2-search--hide');
  3370. } else {
  3371. self.$searchContainer.addClass('select2-search--hide');
  3372. }
  3373. }
  3374. });
  3375. };
  3376. Search.prototype.handleSearch = function (evt) {
  3377. if (!this._keyUpPrevented) {
  3378. var input = this.$search.val();
  3379. this.trigger('query', {
  3380. term: input
  3381. });
  3382. }
  3383. this._keyUpPrevented = false;
  3384. };
  3385. Search.prototype.showSearch = function (_, params) {
  3386. return true;
  3387. };
  3388. return Search;
  3389. });
  3390. S2.define('select2/dropdown/hidePlaceholder',[
  3391. ], function () {
  3392. function HidePlaceholder (decorated, $element, options, dataAdapter) {
  3393. this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
  3394. decorated.call(this, $element, options, dataAdapter);
  3395. }
  3396. HidePlaceholder.prototype.append = function (decorated, data) {
  3397. data.results = this.removePlaceholder(data.results);
  3398. decorated.call(this, data);
  3399. };
  3400. HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) {
  3401. if (typeof placeholder === 'string') {
  3402. placeholder = {
  3403. id: '',
  3404. text: placeholder
  3405. };
  3406. }
  3407. return placeholder;
  3408. };
  3409. HidePlaceholder.prototype.removePlaceholder = function (_, data) {
  3410. var modifiedData = data.slice(0);
  3411. for (var d = data.length - 1; d >= 0; d--) {
  3412. var item = data[d];
  3413. if (this.placeholder.id === item.id) {
  3414. modifiedData.splice(d, 1);
  3415. }
  3416. }
  3417. return modifiedData;
  3418. };
  3419. return HidePlaceholder;
  3420. });
  3421. S2.define('select2/dropdown/infiniteScroll',[
  3422. 'jquery'
  3423. ], function ($) {
  3424. function InfiniteScroll (decorated, $element, options, dataAdapter) {
  3425. this.lastParams = {};
  3426. decorated.call(this, $element, options, dataAdapter);
  3427. this.$loadingMore = this.createLoadingMore();
  3428. this.loading = false;
  3429. }
  3430. InfiniteScroll.prototype.append = function (decorated, data) {
  3431. this.$loadingMore.remove();
  3432. this.loading = false;
  3433. decorated.call(this, data);
  3434. if (this.showLoadingMore(data)) {
  3435. this.$results.append(this.$loadingMore);
  3436. }
  3437. };
  3438. InfiniteScroll.prototype.bind = function (decorated, container, $container) {
  3439. var self = this;
  3440. decorated.call(this, container, $container);
  3441. container.on('query', function (params) {
  3442. self.lastParams = params;
  3443. self.loading = true;
  3444. });
  3445. container.on('query:append', function (params) {
  3446. self.lastParams = params;
  3447. self.loading = true;
  3448. });
  3449. this.$results.on('scroll', function () {
  3450. var isLoadMoreVisible = $.contains(
  3451. document.documentElement,
  3452. self.$loadingMore[0]
  3453. );
  3454. if (self.loading || !isLoadMoreVisible) {
  3455. return;
  3456. }
  3457. var currentOffset = self.$results.offset().top +
  3458. self.$results.outerHeight(false);
  3459. var loadingMoreOffset = self.$loadingMore.offset().top +
  3460. self.$loadingMore.outerHeight(false);
  3461. if (currentOffset + 50 >= loadingMoreOffset) {
  3462. self.loadMore();
  3463. }
  3464. });
  3465. };
  3466. InfiniteScroll.prototype.loadMore = function () {
  3467. this.loading = true;
  3468. var params = $.extend({}, {page: 1}, this.lastParams);
  3469. params.page++;
  3470. this.trigger('query:append', params);
  3471. };
  3472. InfiniteScroll.prototype.showLoadingMore = function (_, data) {
  3473. return data.pagination && data.pagination.more;
  3474. };
  3475. InfiniteScroll.prototype.createLoadingMore = function () {
  3476. var $option = $(
  3477. '<li ' +
  3478. 'class="select2-results__option select2-results__option--load-more"' +
  3479. 'role="treeitem" aria-disabled="true"></li>'
  3480. );
  3481. var message = this.options.get('translations').get('loadingMore');
  3482. $option.html(message(this.lastParams));
  3483. return $option;
  3484. };
  3485. return InfiniteScroll;
  3486. });
  3487. S2.define('select2/dropdown/attachBody',[
  3488. 'jquery',
  3489. '../utils'
  3490. ], function ($, Utils) {
  3491. function AttachBody (decorated, $element, options) {
  3492. this.$dropdownParent = options.get('dropdownParent') || $(document.body);
  3493. decorated.call(this, $element, options);
  3494. }
  3495. AttachBody.prototype.bind = function (decorated, container, $container) {
  3496. var self = this;
  3497. var setupResultsEvents = false;
  3498. decorated.call(this, container, $container);
  3499. container.on('open', function () {
  3500. self._showDropdown();
  3501. self._attachPositioningHandler(container);
  3502. if (!setupResultsEvents) {
  3503. setupResultsEvents = true;
  3504. container.on('results:all', function () {
  3505. self._positionDropdown();
  3506. self._resizeDropdown();
  3507. });
  3508. container.on('results:append', function () {
  3509. self._positionDropdown();
  3510. self._resizeDropdown();
  3511. });
  3512. }
  3513. });
  3514. container.on('close', function () {
  3515. self._hideDropdown();
  3516. self._detachPositioningHandler(container);
  3517. });
  3518. this.$dropdownContainer.on('mousedown', function (evt) {
  3519. evt.stopPropagation();
  3520. });
  3521. };
  3522. AttachBody.prototype.destroy = function (decorated) {
  3523. decorated.call(this);
  3524. this.$dropdownContainer.remove();
  3525. };
  3526. AttachBody.prototype.position = function (decorated, $dropdown, $container) {
  3527. // Clone all of the container classes
  3528. $dropdown.attr('class', $container.attr('class'));
  3529. $dropdown.removeClass('select2');
  3530. $dropdown.addClass('select2-container--open');
  3531. $dropdown.css({
  3532. position: 'absolute',
  3533. top: -999999
  3534. });
  3535. this.$container = $container;
  3536. };
  3537. AttachBody.prototype.render = function (decorated) {
  3538. var $container = $('<span></span>');
  3539. var $dropdown = decorated.call(this);
  3540. $container.append($dropdown);
  3541. this.$dropdownContainer = $container;
  3542. return $container;
  3543. };
  3544. AttachBody.prototype._hideDropdown = function (decorated) {
  3545. this.$dropdownContainer.detach();
  3546. };
  3547. AttachBody.prototype._attachPositioningHandler =
  3548. function (decorated, container) {
  3549. var self = this;
  3550. var scrollEvent = 'scroll.select2.' + container.id;
  3551. var resizeEvent = 'resize.select2.' + container.id;
  3552. var orientationEvent = 'orientationchange.select2.' + container.id;
  3553. var $watchers = this.$container.parents().filter(Utils.hasScroll);
  3554. $watchers.each(function () {
  3555. Utils.StoreData(this, 'select2-scroll-position', {
  3556. x: $(this).scrollLeft(),
  3557. y: $(this).scrollTop()
  3558. });
  3559. });
  3560. $watchers.on(scrollEvent, function (ev) {
  3561. var position = Utils.GetData(this, 'select2-scroll-position');
  3562. $(this).scrollTop(position.y);
  3563. });
  3564. $(window).on(scrollEvent + ' ' + resizeEvent + ' ' + orientationEvent,
  3565. function (e) {
  3566. self._positionDropdown();
  3567. self._resizeDropdown();
  3568. });
  3569. };
  3570. AttachBody.prototype._detachPositioningHandler =
  3571. function (decorated, container) {
  3572. var scrollEvent = 'scroll.select2.' + container.id;
  3573. var resizeEvent = 'resize.select2.' + container.id;
  3574. var orientationEvent = 'orientationchange.select2.' + container.id;
  3575. var $watchers = this.$container.parents().filter(Utils.hasScroll);
  3576. $watchers.off(scrollEvent);
  3577. $(window).off(scrollEvent + ' ' + resizeEvent + ' ' + orientationEvent);
  3578. };
  3579. AttachBody.prototype._positionDropdown = function () {
  3580. var $window = $(window);
  3581. var isCurrentlyAbove = this.$dropdown.hasClass('select2-dropdown--above');
  3582. var isCurrentlyBelow = this.$dropdown.hasClass('select2-dropdown--below');
  3583. var newDirection = null;
  3584. var offset = this.$container.offset();
  3585. offset.bottom = offset.top + this.$container.outerHeight(false);
  3586. var container = {
  3587. height: this.$container.outerHeight(false)
  3588. };
  3589. container.top = offset.top;
  3590. container.bottom = offset.top + container.height;
  3591. var dropdown = {
  3592. height: this.$dropdown.outerHeight(false)
  3593. };
  3594. var viewport = {
  3595. top: $window.scrollTop(),
  3596. bottom: $window.scrollTop() + $window.height()
  3597. };
  3598. var enoughRoomAbove = viewport.top < (offset.top - dropdown.height);
  3599. var enoughRoomBelow = viewport.bottom > (offset.bottom + dropdown.height);
  3600. var css = {
  3601. left: offset.left,
  3602. top: container.bottom
  3603. };
  3604. // Determine what the parent element is to use for calciulating the offset
  3605. var $offsetParent = this.$dropdownParent;
  3606. // For statically positoned elements, we need to get the element
  3607. // that is determining the offset
  3608. if ($offsetParent.css('position') === 'static') {
  3609. $offsetParent = $offsetParent.offsetParent();
  3610. }
  3611. var parentOffset = $offsetParent.offset();
  3612. css.top -= parentOffset.top;
  3613. css.left -= parentOffset.left;
  3614. if (!isCurrentlyAbove && !isCurrentlyBelow) {
  3615. newDirection = 'below';
  3616. }
  3617. if (!enoughRoomBelow && enoughRoomAbove && !isCurrentlyAbove) {
  3618. newDirection = 'above';
  3619. } else if (!enoughRoomAbove && enoughRoomBelow && isCurrentlyAbove) {
  3620. newDirection = 'below';
  3621. }
  3622. if (newDirection == 'above' ||
  3623. (isCurrentlyAbove && newDirection !== 'below')) {
  3624. css.top = container.top - parentOffset.top - dropdown.height;
  3625. }
  3626. if (newDirection != null) {
  3627. this.$dropdown
  3628. .removeClass('select2-dropdown--below select2-dropdown--above')
  3629. .addClass('select2-dropdown--' + newDirection);
  3630. this.$container
  3631. .removeClass('select2-container--below select2-container--above')
  3632. .addClass('select2-container--' + newDirection);
  3633. }
  3634. this.$dropdownContainer.css(css);
  3635. };
  3636. AttachBody.prototype._resizeDropdown = function () {
  3637. var css = {
  3638. width: this.$container.outerWidth(false) + 'px'
  3639. };
  3640. if (this.options.get('dropdownAutoWidth')) {
  3641. css.minWidth = css.width;
  3642. css.position = 'relative';
  3643. css.width = 'auto';
  3644. }
  3645. this.$dropdown.css(css);
  3646. };
  3647. AttachBody.prototype._showDropdown = function (decorated) {
  3648. this.$dropdownContainer.appendTo(this.$dropdownParent);
  3649. this._positionDropdown();
  3650. this._resizeDropdown();
  3651. };
  3652. return AttachBody;
  3653. });
  3654. S2.define('select2/dropdown/minimumResultsForSearch',[
  3655. ], function () {
  3656. function countResults (data) {
  3657. var count = 0;
  3658. for (var d = 0; d < data.length; d++) {
  3659. var item = data[d];
  3660. if (item.children) {
  3661. count += countResults(item.children);
  3662. } else {
  3663. count++;
  3664. }
  3665. }
  3666. return count;
  3667. }
  3668. function MinimumResultsForSearch (decorated, $element, options, dataAdapter) {
  3669. this.minimumResultsForSearch = options.get('minimumResultsForSearch');
  3670. if (this.minimumResultsForSearch < 0) {
  3671. this.minimumResultsForSearch = Infinity;
  3672. }
  3673. decorated.call(this, $element, options, dataAdapter);
  3674. }
  3675. MinimumResultsForSearch.prototype.showSearch = function (decorated, params) {
  3676. if (countResults(params.data.results) < this.minimumResultsForSearch) {
  3677. return false;
  3678. }
  3679. return decorated.call(this, params);
  3680. };
  3681. return MinimumResultsForSearch;
  3682. });
  3683. S2.define('select2/dropdown/selectOnClose',[
  3684. '../utils'
  3685. ], function (Utils) {
  3686. function SelectOnClose () { }
  3687. SelectOnClose.prototype.bind = function (decorated, container, $container) {
  3688. var self = this;
  3689. decorated.call(this, container, $container);
  3690. container.on('close', function (params) {
  3691. self._handleSelectOnClose(params);
  3692. });
  3693. };
  3694. SelectOnClose.prototype._handleSelectOnClose = function (_, params) {
  3695. if (params && params.originalSelect2Event != null) {
  3696. var event = params.originalSelect2Event;
  3697. // Don't select an item if the close event was triggered from a select or
  3698. // unselect event
  3699. if (event._type === 'select' || event._type === 'unselect') {
  3700. return;
  3701. }
  3702. }
  3703. var $highlightedResults = this.getHighlightedResults();
  3704. // Only select highlighted results
  3705. if ($highlightedResults.length < 1) {
  3706. return;
  3707. }
  3708. var data = Utils.GetData($highlightedResults[0], 'data');
  3709. // Don't re-select already selected resulte
  3710. if (
  3711. (data.element != null && data.element.selected) ||
  3712. (data.element == null && data.selected)
  3713. ) {
  3714. return;
  3715. }
  3716. this.trigger('select', {
  3717. data: data
  3718. });
  3719. };
  3720. return SelectOnClose;
  3721. });
  3722. S2.define('select2/dropdown/closeOnSelect',[
  3723. ], function () {
  3724. function CloseOnSelect () { }
  3725. CloseOnSelect.prototype.bind = function (decorated, container, $container) {
  3726. var self = this;
  3727. decorated.call(this, container, $container);
  3728. container.on('select', function (evt) {
  3729. self._selectTriggered(evt);
  3730. });
  3731. container.on('unselect', function (evt) {
  3732. self._selectTriggered(evt);
  3733. });
  3734. };
  3735. CloseOnSelect.prototype._selectTriggered = function (_, evt) {
  3736. var originalEvent = evt.originalEvent;
  3737. // Don't close if the control key is being held
  3738. if (originalEvent && originalEvent.ctrlKey) {
  3739. return;
  3740. }
  3741. this.trigger('close', {
  3742. originalEvent: originalEvent,
  3743. originalSelect2Event: evt
  3744. });
  3745. };
  3746. return CloseOnSelect;
  3747. });
  3748. S2.define('select2/i18n/en',[],function () {
  3749. // English
  3750. return {
  3751. errorLoading: function () {
  3752. return 'The results could not be loaded.';
  3753. },
  3754. inputTooLong: function (args) {
  3755. var overChars = args.input.length - args.maximum;
  3756. var message = 'Please delete ' + overChars + ' character';
  3757. if (overChars != 1) {
  3758. message += 's';
  3759. }
  3760. return message;
  3761. },
  3762. inputTooShort: function (args) {
  3763. var remainingChars = args.minimum - args.input.length;
  3764. var message = 'Please enter ' + remainingChars + ' or more characters';
  3765. return message;
  3766. },
  3767. loadingMore: function () {
  3768. return 'Loading more results…';
  3769. },
  3770. maximumSelected: function (args) {
  3771. var message = 'You can only select ' + args.maximum + ' item';
  3772. if (args.maximum != 1) {
  3773. message += 's';
  3774. }
  3775. return message;
  3776. },
  3777. noResults: function () {
  3778. return 'No results found';
  3779. },
  3780. searching: function () {
  3781. return 'Searching…';
  3782. }
  3783. };
  3784. });
  3785. S2.define('select2/defaults',[
  3786. 'jquery',
  3787. 'require',
  3788. './results',
  3789. './selection/single',
  3790. './selection/multiple',
  3791. './selection/placeholder',
  3792. './selection/allowClear',
  3793. './selection/search',
  3794. './selection/eventRelay',
  3795. './utils',
  3796. './translation',
  3797. './diacritics',
  3798. './data/select',
  3799. './data/array',
  3800. './data/ajax',
  3801. './data/tags',
  3802. './data/tokenizer',
  3803. './data/minimumInputLength',
  3804. './data/maximumInputLength',
  3805. './data/maximumSelectionLength',
  3806. './dropdown',
  3807. './dropdown/search',
  3808. './dropdown/hidePlaceholder',
  3809. './dropdown/infiniteScroll',
  3810. './dropdown/attachBody',
  3811. './dropdown/minimumResultsForSearch',
  3812. './dropdown/selectOnClose',
  3813. './dropdown/closeOnSelect',
  3814. './i18n/en'
  3815. ], function ($, require,
  3816. ResultsList,
  3817. SingleSelection, MultipleSelection, Placeholder, AllowClear,
  3818. SelectionSearch, EventRelay,
  3819. Utils, Translation, DIACRITICS,
  3820. SelectData, ArrayData, AjaxData, Tags, Tokenizer,
  3821. MinimumInputLength, MaximumInputLength, MaximumSelectionLength,
  3822. Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
  3823. AttachBody, MinimumResultsForSearch, SelectOnClose, CloseOnSelect,
  3824. EnglishTranslation) {
  3825. function Defaults () {
  3826. this.reset();
  3827. }
  3828. Defaults.prototype.apply = function (options) {
  3829. options = $.extend(true, {}, this.defaults, options);
  3830. if (options.dataAdapter == null) {
  3831. if (options.ajax != null) {
  3832. options.dataAdapter = AjaxData;
  3833. } else if (options.data != null) {
  3834. options.dataAdapter = ArrayData;
  3835. } else {
  3836. options.dataAdapter = SelectData;
  3837. }
  3838. if (options.minimumInputLength > 0) {
  3839. options.dataAdapter = Utils.Decorate(
  3840. options.dataAdapter,
  3841. MinimumInputLength
  3842. );
  3843. }
  3844. if (options.maximumInputLength > 0) {
  3845. options.dataAdapter = Utils.Decorate(
  3846. options.dataAdapter,
  3847. MaximumInputLength
  3848. );
  3849. }
  3850. if (options.maximumSelectionLength > 0) {
  3851. options.dataAdapter = Utils.Decorate(
  3852. options.dataAdapter,
  3853. MaximumSelectionLength
  3854. );
  3855. }
  3856. if (options.tags) {
  3857. options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
  3858. }
  3859. if (options.tokenSeparators != null || options.tokenizer != null) {
  3860. options.dataAdapter = Utils.Decorate(
  3861. options.dataAdapter,
  3862. Tokenizer
  3863. );
  3864. }
  3865. if (options.query != null) {
  3866. var Query = require(options.amdBase + 'compat/query');
  3867. options.dataAdapter = Utils.Decorate(
  3868. options.dataAdapter,
  3869. Query
  3870. );
  3871. }
  3872. if (options.initSelection != null) {
  3873. var InitSelection = require(options.amdBase + 'compat/initSelection');
  3874. options.dataAdapter = Utils.Decorate(
  3875. options.dataAdapter,
  3876. InitSelection
  3877. );
  3878. }
  3879. }
  3880. if (options.resultsAdapter == null) {
  3881. options.resultsAdapter = ResultsList;
  3882. if (options.ajax != null) {
  3883. options.resultsAdapter = Utils.Decorate(
  3884. options.resultsAdapter,
  3885. InfiniteScroll
  3886. );
  3887. }
  3888. if (options.placeholder != null) {
  3889. options.resultsAdapter = Utils.Decorate(
  3890. options.resultsAdapter,
  3891. HidePlaceholder
  3892. );
  3893. }
  3894. if (options.selectOnClose) {
  3895. options.resultsAdapter = Utils.Decorate(
  3896. options.resultsAdapter,
  3897. SelectOnClose
  3898. );
  3899. }
  3900. }
  3901. if (options.dropdownAdapter == null) {
  3902. if (options.multiple) {
  3903. options.dropdownAdapter = Dropdown;
  3904. } else {
  3905. var SearchableDropdown = Utils.Decorate(Dropdown, DropdownSearch);
  3906. options.dropdownAdapter = SearchableDropdown;
  3907. }
  3908. if (options.minimumResultsForSearch !== 0) {
  3909. options.dropdownAdapter = Utils.Decorate(
  3910. options.dropdownAdapter,
  3911. MinimumResultsForSearch
  3912. );
  3913. }
  3914. if (options.closeOnSelect) {
  3915. options.dropdownAdapter = Utils.Decorate(
  3916. options.dropdownAdapter,
  3917. CloseOnSelect
  3918. );
  3919. }
  3920. if (
  3921. options.dropdownCssClass != null ||
  3922. options.dropdownCss != null ||
  3923. options.adaptDropdownCssClass != null
  3924. ) {
  3925. var DropdownCSS = require(options.amdBase + 'compat/dropdownCss');
  3926. options.dropdownAdapter = Utils.Decorate(
  3927. options.dropdownAdapter,
  3928. DropdownCSS
  3929. );
  3930. }
  3931. options.dropdownAdapter = Utils.Decorate(
  3932. options.dropdownAdapter,
  3933. AttachBody
  3934. );
  3935. }
  3936. if (options.selectionAdapter == null) {
  3937. if (options.multiple) {
  3938. options.selectionAdapter = MultipleSelection;
  3939. } else {
  3940. options.selectionAdapter = SingleSelection;
  3941. }
  3942. // Add the placeholder mixin if a placeholder was specified
  3943. if (options.placeholder != null) {
  3944. options.selectionAdapter = Utils.Decorate(
  3945. options.selectionAdapter,
  3946. Placeholder
  3947. );
  3948. }
  3949. if (options.allowClear) {
  3950. options.selectionAdapter = Utils.Decorate(
  3951. options.selectionAdapter,
  3952. AllowClear
  3953. );
  3954. }
  3955. if (options.multiple) {
  3956. options.selectionAdapter = Utils.Decorate(
  3957. options.selectionAdapter,
  3958. SelectionSearch
  3959. );
  3960. }
  3961. if (
  3962. options.containerCssClass != null ||
  3963. options.containerCss != null ||
  3964. options.adaptContainerCssClass != null
  3965. ) {
  3966. var ContainerCSS = require(options.amdBase + 'compat/containerCss');
  3967. options.selectionAdapter = Utils.Decorate(
  3968. options.selectionAdapter,
  3969. ContainerCSS
  3970. );
  3971. }
  3972. options.selectionAdapter = Utils.Decorate(
  3973. options.selectionAdapter,
  3974. EventRelay
  3975. );
  3976. }
  3977. if (typeof options.language === 'string') {
  3978. // Check if the language is specified with a region
  3979. if (options.language.indexOf('-') > 0) {
  3980. // Extract the region information if it is included
  3981. var languageParts = options.language.split('-');
  3982. var baseLanguage = languageParts[0];
  3983. options.language = [options.language, baseLanguage];
  3984. } else {
  3985. options.language = [options.language];
  3986. }
  3987. }
  3988. if ($.isArray(options.language)) {
  3989. var languages = new Translation();
  3990. options.language.push('en');
  3991. var languageNames = options.language;
  3992. for (var l = 0; l < languageNames.length; l++) {
  3993. var name = languageNames[l];
  3994. var language = {};
  3995. try {
  3996. // Try to load it with the original name
  3997. language = Translation.loadPath(name);
  3998. } catch (e) {
  3999. try {
  4000. // If we couldn't load it, check if it wasn't the full path
  4001. name = this.defaults.amdLanguageBase + name;
  4002. language = Translation.loadPath(name);
  4003. } catch (ex) {
  4004. // The translation could not be loaded at all. Sometimes this is
  4005. // because of a configuration problem, other times this can be
  4006. // because of how Select2 helps load all possible translation files.
  4007. if (options.debug && window.console && console.warn) {
  4008. console.warn(
  4009. 'Select2: The language file for "' + name + '" could not be ' +
  4010. 'automatically loaded. A fallback will be used instead.'
  4011. );
  4012. }
  4013. continue;
  4014. }
  4015. }
  4016. languages.extend(language);
  4017. }
  4018. options.translations = languages;
  4019. } else {
  4020. var baseTranslation = Translation.loadPath(
  4021. this.defaults.amdLanguageBase + 'en'
  4022. );
  4023. var customTranslation = new Translation(options.language);
  4024. customTranslation.extend(baseTranslation);
  4025. options.translations = customTranslation;
  4026. }
  4027. return options;
  4028. };
  4029. Defaults.prototype.reset = function () {
  4030. function stripDiacritics (text) {
  4031. // Used 'uni range + named function' from http://jsperf.com/diacritics/18
  4032. function match(a) {
  4033. return DIACRITICS[a] || a;
  4034. }
  4035. return text.replace(/[^\u0000-\u007E]/g, match);
  4036. }
  4037. function matcher (params, data) {
  4038. // Always return the object if there is nothing to compare
  4039. if ($.trim(params.term) === '') {
  4040. return data;
  4041. }
  4042. // Do a recursive check for options with children
  4043. if (data.children && data.children.length > 0) {
  4044. // Clone the data object if there are children
  4045. // This is required as we modify the object to remove any non-matches
  4046. var match = $.extend(true, {}, data);
  4047. // Check each child of the option
  4048. for (var c = data.children.length - 1; c >= 0; c--) {
  4049. var child = data.children[c];
  4050. var matches = matcher(params, child);
  4051. // If there wasn't a match, remove the object in the array
  4052. if (matches == null) {
  4053. match.children.splice(c, 1);
  4054. }
  4055. }
  4056. // If any children matched, return the new object
  4057. if (match.children.length > 0) {
  4058. return match;
  4059. }
  4060. // If there were no matching children, check just the plain object
  4061. return matcher(params, match);
  4062. }
  4063. var original = stripDiacritics(data.text).toUpperCase();
  4064. var term = stripDiacritics(params.term).toUpperCase();
  4065. // Check if the text contains the term
  4066. if (original.indexOf(term) > -1) {
  4067. return data;
  4068. }
  4069. // If it doesn't contain the term, don't return anything
  4070. return null;
  4071. }
  4072. this.defaults = {
  4073. amdBase: './',
  4074. amdLanguageBase: './i18n/',
  4075. closeOnSelect: true,
  4076. debug: false,
  4077. dropdownAutoWidth: false,
  4078. escapeMarkup: Utils.escapeMarkup,
  4079. language: EnglishTranslation,
  4080. matcher: matcher,
  4081. minimumInputLength: 0,
  4082. maximumInputLength: 0,
  4083. maximumSelectionLength: 0,
  4084. minimumResultsForSearch: 0,
  4085. selectOnClose: false,
  4086. sorter: function (data) {
  4087. return data;
  4088. },
  4089. templateResult: function (result) {
  4090. return result.text;
  4091. },
  4092. templateSelection: function (selection) {
  4093. return selection.text;
  4094. },
  4095. theme: 'default',
  4096. width: 'resolve'
  4097. };
  4098. };
  4099. Defaults.prototype.set = function (key, value) {
  4100. var camelKey = $.camelCase(key);
  4101. var data = {};
  4102. data[camelKey] = value;
  4103. var convertedData = Utils._convertData(data);
  4104. $.extend(true, this.defaults, convertedData);
  4105. };
  4106. var defaults = new Defaults();
  4107. return defaults;
  4108. });
  4109. S2.define('select2/options',[
  4110. 'require',
  4111. 'jquery',
  4112. './defaults',
  4113. './utils'
  4114. ], function (require, $, Defaults, Utils) {
  4115. function Options (options, $element) {
  4116. this.options = options;
  4117. if ($element != null) {
  4118. this.fromElement($element);
  4119. }
  4120. this.options = Defaults.apply(this.options);
  4121. if ($element && $element.is('input')) {
  4122. var InputCompat = require(this.get('amdBase') + 'compat/inputData');
  4123. this.options.dataAdapter = Utils.Decorate(
  4124. this.options.dataAdapter,
  4125. InputCompat
  4126. );
  4127. }
  4128. }
  4129. Options.prototype.fromElement = function ($e) {
  4130. var excludedData = ['select2'];
  4131. if (this.options.multiple == null) {
  4132. this.options.multiple = $e.prop('multiple');
  4133. }
  4134. if (this.options.disabled == null) {
  4135. this.options.disabled = $e.prop('disabled');
  4136. }
  4137. if (this.options.language == null) {
  4138. if ($e.prop('lang')) {
  4139. this.options.language = $e.prop('lang').toLowerCase();
  4140. } else if ($e.closest('[lang]').prop('lang')) {
  4141. this.options.language = $e.closest('[lang]').prop('lang');
  4142. }
  4143. }
  4144. if (this.options.dir == null) {
  4145. if ($e.prop('dir')) {
  4146. this.options.dir = $e.prop('dir');
  4147. } else if ($e.closest('[dir]').prop('dir')) {
  4148. this.options.dir = $e.closest('[dir]').prop('dir');
  4149. } else {
  4150. this.options.dir = 'ltr';
  4151. }
  4152. }
  4153. $e.prop('disabled', this.options.disabled);
  4154. $e.prop('multiple', this.options.multiple);
  4155. if (Utils.GetData($e[0], 'select2Tags')) {
  4156. if (this.options.debug && window.console && console.warn) {
  4157. console.warn(
  4158. 'Select2: The `data-select2-tags` attribute has been changed to ' +
  4159. 'use the `data-data` and `data-tags="true"` attributes and will be ' +
  4160. 'removed in future versions of Select2.'
  4161. );
  4162. }
  4163. Utils.StoreData($e[0], 'data', Utils.GetData($e[0], 'select2Tags'));
  4164. Utils.StoreData($e[0], 'tags', true);
  4165. }
  4166. if (Utils.GetData($e[0], 'ajaxUrl')) {
  4167. if (this.options.debug && window.console && console.warn) {
  4168. console.warn(
  4169. 'Select2: The `data-ajax-url` attribute has been changed to ' +
  4170. '`data-ajax--url` and support for the old attribute will be removed' +
  4171. ' in future versions of Select2.'
  4172. );
  4173. }
  4174. $e.attr('ajax--url', Utils.GetData($e[0], 'ajaxUrl'));
  4175. Utils.StoreData($e[0], 'ajax-Url', Utils.GetData($e[0], 'ajaxUrl'));
  4176. }
  4177. var dataset = {};
  4178. // Prefer the element's `dataset` attribute if it exists
  4179. // jQuery 1.x does not correctly handle data attributes with multiple dashes
  4180. if ($.fn.jquery && $.fn.jquery.substr(0, 2) == '1.' && $e[0].dataset) {
  4181. dataset = $.extend(true, {}, $e[0].dataset, Utils.GetData($e[0]));
  4182. } else {
  4183. dataset = Utils.GetData($e[0]);
  4184. }
  4185. var data = $.extend(true, {}, dataset);
  4186. data = Utils._convertData(data);
  4187. for (var key in data) {
  4188. if ($.inArray(key, excludedData) > -1) {
  4189. continue;
  4190. }
  4191. if ($.isPlainObject(this.options[key])) {
  4192. $.extend(this.options[key], data[key]);
  4193. } else {
  4194. this.options[key] = data[key];
  4195. }
  4196. }
  4197. return this;
  4198. };
  4199. Options.prototype.get = function (key) {
  4200. return this.options[key];
  4201. };
  4202. Options.prototype.set = function (key, val) {
  4203. this.options[key] = val;
  4204. };
  4205. return Options;
  4206. });
  4207. S2.define('select2/core',[
  4208. 'jquery',
  4209. './options',
  4210. './utils',
  4211. './keys'
  4212. ], function ($, Options, Utils, KEYS) {
  4213. var Select2 = function ($element, options) {
  4214. if (Utils.GetData($element[0], 'select2') != null) {
  4215. Utils.GetData($element[0], 'select2').destroy();
  4216. }
  4217. this.$element = $element;
  4218. this.id = this._generateId($element);
  4219. options = options || {};
  4220. this.options = new Options(options, $element);
  4221. Select2.__super__.constructor.call(this);
  4222. // Set up the tabindex
  4223. var tabindex = $element.attr('tabindex') || 0;
  4224. Utils.StoreData($element[0], 'old-tabindex', tabindex);
  4225. $element.attr('tabindex', '-1');
  4226. // Set up containers and adapters
  4227. var DataAdapter = this.options.get('dataAdapter');
  4228. this.dataAdapter = new DataAdapter($element, this.options);
  4229. var $container = this.render();
  4230. this._placeContainer($container);
  4231. var SelectionAdapter = this.options.get('selectionAdapter');
  4232. this.selection = new SelectionAdapter($element, this.options);
  4233. this.$selection = this.selection.render();
  4234. this.selection.position(this.$selection, $container);
  4235. var DropdownAdapter = this.options.get('dropdownAdapter');
  4236. this.dropdown = new DropdownAdapter($element, this.options);
  4237. this.$dropdown = this.dropdown.render();
  4238. this.dropdown.position(this.$dropdown, $container);
  4239. var ResultsAdapter = this.options.get('resultsAdapter');
  4240. this.results = new ResultsAdapter($element, this.options, this.dataAdapter);
  4241. this.$results = this.results.render();
  4242. this.results.position(this.$results, this.$dropdown);
  4243. // Bind events
  4244. var self = this;
  4245. // Bind the container to all of the adapters
  4246. this._bindAdapters();
  4247. // Register any DOM event handlers
  4248. this._registerDomEvents();
  4249. // Register any internal event handlers
  4250. this._registerDataEvents();
  4251. this._registerSelectionEvents();
  4252. this._registerDropdownEvents();
  4253. this._registerResultsEvents();
  4254. this._registerEvents();
  4255. // Set the initial state
  4256. this.dataAdapter.current(function (initialData) {
  4257. self.trigger('selection:update', {
  4258. data: initialData
  4259. });
  4260. });
  4261. // Hide the original select
  4262. $element.addClass('select2-hidden-accessible');
  4263. $element.attr('aria-hidden', 'true');
  4264. // Synchronize any monitored attributes
  4265. this._syncAttributes();
  4266. Utils.StoreData($element[0], 'select2', this);
  4267. // Ensure backwards compatibility with $element.data('select2').
  4268. $element.data('select2', this);
  4269. };
  4270. Utils.Extend(Select2, Utils.Observable);
  4271. Select2.prototype._generateId = function ($element) {
  4272. var id = '';
  4273. if ($element.attr('id') != null) {
  4274. id = $element.attr('id');
  4275. } else if ($element.attr('name') != null) {
  4276. id = $element.attr('name') + '-' + Utils.generateChars(2);
  4277. } else {
  4278. id = Utils.generateChars(4);
  4279. }
  4280. id = id.replace(/(:|\.|\[|\]|,)/g, '');
  4281. id = 'select2-' + id;
  4282. return id;
  4283. };
  4284. Select2.prototype._placeContainer = function ($container) {
  4285. $container.insertAfter(this.$element);
  4286. var width = this._resolveWidth(this.$element, this.options.get('width'));
  4287. if (width != null) {
  4288. $container.css('width', width);
  4289. }
  4290. };
  4291. Select2.prototype._resolveWidth = function ($element, method) {
  4292. var WIDTH = /^width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/i;
  4293. if (method == 'resolve') {
  4294. var styleWidth = this._resolveWidth($element, 'style');
  4295. if (styleWidth != null) {
  4296. return styleWidth;
  4297. }
  4298. return this._resolveWidth($element, 'element');
  4299. }
  4300. if (method == 'element') {
  4301. var elementWidth = $element.outerWidth(false);
  4302. if (elementWidth <= 0) {
  4303. return 'auto';
  4304. }
  4305. return elementWidth + 'px';
  4306. }
  4307. if (method == 'style') {
  4308. var style = $element.attr('style');
  4309. if (typeof(style) !== 'string') {
  4310. return null;
  4311. }
  4312. var attrs = style.split(';');
  4313. for (var i = 0, l = attrs.length; i < l; i = i + 1) {
  4314. var attr = attrs[i].replace(/\s/g, '');
  4315. var matches = attr.match(WIDTH);
  4316. if (matches !== null && matches.length >= 1) {
  4317. return matches[1];
  4318. }
  4319. }
  4320. return null;
  4321. }
  4322. return method;
  4323. };
  4324. Select2.prototype._bindAdapters = function () {
  4325. this.dataAdapter.bind(this, this.$container);
  4326. this.selection.bind(this, this.$container);
  4327. this.dropdown.bind(this, this.$container);
  4328. this.results.bind(this, this.$container);
  4329. };
  4330. Select2.prototype._registerDomEvents = function () {
  4331. var self = this;
  4332. this.$element.on('change.select2', function () {
  4333. self.dataAdapter.current(function (data) {
  4334. self.trigger('selection:update', {
  4335. data: data
  4336. });
  4337. });
  4338. });
  4339. this.$element.on('focus.select2', function (evt) {
  4340. self.trigger('focus', evt);
  4341. });
  4342. this._syncA = Utils.bind(this._syncAttributes, this);
  4343. this._syncS = Utils.bind(this._syncSubtree, this);
  4344. if (this.$element[0].attachEvent) {
  4345. this.$element[0].attachEvent('onpropertychange', this._syncA);
  4346. }
  4347. var observer = window.MutationObserver ||
  4348. window.WebKitMutationObserver ||
  4349. window.MozMutationObserver
  4350. ;
  4351. if (observer != null) {
  4352. this._observer = new observer(function (mutations) {
  4353. $.each(mutations, self._syncA);
  4354. $.each(mutations, self._syncS);
  4355. });
  4356. this._observer.observe(this.$element[0], {
  4357. attributes: true,
  4358. childList: true,
  4359. subtree: false
  4360. });
  4361. } else if (this.$element[0].addEventListener) {
  4362. this.$element[0].addEventListener(
  4363. 'DOMAttrModified',
  4364. self._syncA,
  4365. false
  4366. );
  4367. this.$element[0].addEventListener(
  4368. 'DOMNodeInserted',
  4369. self._syncS,
  4370. false
  4371. );
  4372. this.$element[0].addEventListener(
  4373. 'DOMNodeRemoved',
  4374. self._syncS,
  4375. false
  4376. );
  4377. }
  4378. };
  4379. Select2.prototype._registerDataEvents = function () {
  4380. var self = this;
  4381. this.dataAdapter.on('*', function (name, params) {
  4382. self.trigger(name, params);
  4383. });
  4384. };
  4385. Select2.prototype._registerSelectionEvents = function () {
  4386. var self = this;
  4387. var nonRelayEvents = ['toggle', 'focus'];
  4388. this.selection.on('toggle', function () {
  4389. self.toggleDropdown();
  4390. });
  4391. this.selection.on('focus', function (params) {
  4392. self.focus(params);
  4393. });
  4394. this.selection.on('*', function (name, params) {
  4395. if ($.inArray(name, nonRelayEvents) !== -1) {
  4396. return;
  4397. }
  4398. self.trigger(name, params);
  4399. });
  4400. };
  4401. Select2.prototype._registerDropdownEvents = function () {
  4402. var self = this;
  4403. this.dropdown.on('*', function (name, params) {
  4404. self.trigger(name, params);
  4405. });
  4406. };
  4407. Select2.prototype._registerResultsEvents = function () {
  4408. var self = this;
  4409. this.results.on('*', function (name, params) {
  4410. self.trigger(name, params);
  4411. });
  4412. };
  4413. Select2.prototype._registerEvents = function () {
  4414. var self = this;
  4415. this.on('open', function () {
  4416. self.$container.addClass('select2-container--open');
  4417. });
  4418. this.on('close', function () {
  4419. self.$container.removeClass('select2-container--open');
  4420. });
  4421. this.on('enable', function () {
  4422. self.$container.removeClass('select2-container--disabled');
  4423. });
  4424. this.on('disable', function () {
  4425. self.$container.addClass('select2-container--disabled');
  4426. });
  4427. this.on('blur', function () {
  4428. self.$container.removeClass('select2-container--focus');
  4429. });
  4430. this.on('query', function (params) {
  4431. console.log("query" + JSON.stringify(params));
  4432. if (!self.isOpen()) {
  4433. self.trigger('open', {});
  4434. }
  4435. this.dataAdapter.query(params, function (data) {
  4436. self.trigger('results:all', {
  4437. data: data,
  4438. query: params
  4439. });
  4440. });
  4441. });
  4442. this.on('query:append', function (params) {
  4443. this.dataAdapter.query(params, function (data) {
  4444. self.trigger('results:append', {
  4445. data: data,
  4446. query: params
  4447. });
  4448. });
  4449. });
  4450. this.on('keypress', function (evt) {
  4451. var key = evt.which;
  4452. if (self.isOpen()) {
  4453. if (key === KEYS.ESC || key === KEYS.TAB ||
  4454. (key === KEYS.UP && evt.altKey)) {
  4455. self.close();
  4456. evt.preventDefault();
  4457. } else if (key === KEYS.ENTER) {
  4458. self.trigger('results:select', {});
  4459. evt.preventDefault();
  4460. } else if ((key === KEYS.SPACE && evt.ctrlKey)) {
  4461. self.trigger('results:toggle', {});
  4462. evt.preventDefault();
  4463. } else if (key === KEYS.UP) {
  4464. self.trigger('results:previous', {});
  4465. evt.preventDefault();
  4466. } else if (key === KEYS.DOWN) {
  4467. self.trigger('results:next', {});
  4468. evt.preventDefault();
  4469. }
  4470. } else {
  4471. if (key === KEYS.ENTER || key === KEYS.SPACE ||
  4472. (key === KEYS.DOWN && evt.altKey)) {
  4473. self.open();
  4474. evt.preventDefault();
  4475. }
  4476. }
  4477. });
  4478. };
  4479. Select2.prototype._syncAttributes = function () {
  4480. this.options.set('disabled', this.$element.prop('disabled'));
  4481. if (this.options.get('disabled')) {
  4482. if (this.isOpen()) {
  4483. this.close();
  4484. }
  4485. this.trigger('disable', {});
  4486. } else {
  4487. this.trigger('enable', {});
  4488. }
  4489. };
  4490. Select2.prototype._syncSubtree = function (evt, mutations) {
  4491. var changed = false;
  4492. var self = this;
  4493. // Ignore any mutation events raised for elements that aren't options or
  4494. // optgroups. This handles the case when the select element is destroyed
  4495. if (
  4496. evt && evt.target && (
  4497. evt.target.nodeName !== 'OPTION' && evt.target.nodeName !== 'OPTGROUP'
  4498. )
  4499. ) {
  4500. return;
  4501. }
  4502. if (!mutations) {
  4503. // If mutation events aren't supported, then we can only assume that the
  4504. // change affected the selections
  4505. changed = true;
  4506. } else if (mutations.addedNodes && mutations.addedNodes.length > 0) {
  4507. for (var n = 0; n < mutations.addedNodes.length; n++) {
  4508. var node = mutations.addedNodes[n];
  4509. if (node.selected) {
  4510. changed = true;
  4511. }
  4512. }
  4513. } else if (mutations.removedNodes && mutations.removedNodes.length > 0) {
  4514. changed = true;
  4515. }
  4516. // Only re-pull the data if we think there is a change
  4517. if (changed) {
  4518. this.dataAdapter.current(function (currentData) {
  4519. self.trigger('selection:update', {
  4520. data: currentData
  4521. });
  4522. });
  4523. }
  4524. };
  4525. /**
  4526. * Override the trigger method to automatically trigger pre-events when
  4527. * there are events that can be prevented.
  4528. */
  4529. Select2.prototype.trigger = function (name, args) {
  4530. var actualTrigger = Select2.__super__.trigger;
  4531. var preTriggerMap = {
  4532. 'open': 'opening',
  4533. 'close': 'closing',
  4534. 'select': 'selecting',
  4535. 'unselect': 'unselecting',
  4536. 'clear': 'clearing'
  4537. };
  4538. if (args === undefined) {
  4539. args = {};
  4540. }
  4541. if (name in preTriggerMap) {
  4542. var preTriggerName = preTriggerMap[name];
  4543. var preTriggerArgs = {
  4544. prevented: false,
  4545. name: name,
  4546. args: args
  4547. };
  4548. actualTrigger.call(this, preTriggerName, preTriggerArgs);
  4549. if (preTriggerArgs.prevented) {
  4550. args.prevented = true;
  4551. return;
  4552. }
  4553. }
  4554. actualTrigger.call(this, name, args);
  4555. };
  4556. Select2.prototype.toggleDropdown = function () {
  4557. if (this.options.get('disabled')) {
  4558. return;
  4559. }
  4560. if (this.isOpen()) {
  4561. this.close();
  4562. } else {
  4563. this.open();
  4564. }
  4565. };
  4566. Select2.prototype.open = function () {
  4567. if (this.isOpen()) {
  4568. return;
  4569. }
  4570. var searchField = this.$container.find(".select2-search__field");
  4571. console.log($(searchField).val());
  4572. //select2下拉框关闭后再开启,根据当前查询框中内容初始化
  4573. this.trigger('query', {
  4574. term : (searchField).val()
  4575. });
  4576. };
  4577. Select2.prototype.close = function () {
  4578. if (!this.isOpen()) {
  4579. return;
  4580. }
  4581. this.trigger('close', {});
  4582. };
  4583. Select2.prototype.isOpen = function () {
  4584. return this.$container.hasClass('select2-container--open');
  4585. };
  4586. Select2.prototype.hasFocus = function () {
  4587. return this.$container.hasClass('select2-container--focus');
  4588. };
  4589. Select2.prototype.focus = function (data) {
  4590. // No need to re-trigger focus events if we are already focused
  4591. if (this.hasFocus()) {
  4592. return;
  4593. }
  4594. this.$container.addClass('select2-container--focus');
  4595. this.trigger('focus', {});
  4596. };
  4597. Select2.prototype.enable = function (args) {
  4598. if (this.options.get('debug') && window.console && console.warn) {
  4599. console.warn(
  4600. 'Select2: The `select2("enable")` method has been deprecated and will' +
  4601. ' be removed in later Select2 versions. Use $element.prop("disabled")' +
  4602. ' instead.'
  4603. );
  4604. }
  4605. if (args == null || args.length === 0) {
  4606. args = [true];
  4607. }
  4608. var disabled = !args[0];
  4609. this.$element.prop('disabled', disabled);
  4610. };
  4611. Select2.prototype.data = function () {
  4612. if (this.options.get('debug') &&
  4613. arguments.length > 0 && window.console && console.warn) {
  4614. console.warn(
  4615. 'Select2: Data can no longer be set using `select2("data")`. You ' +
  4616. 'should consider setting the value instead using `$element.val()`.'
  4617. );
  4618. }
  4619. var data = [];
  4620. this.dataAdapter.current(function (currentData) {
  4621. data = currentData;
  4622. });
  4623. return data;
  4624. };
  4625. Select2.prototype.val = function (args) {
  4626. if (this.options.get('debug') && window.console && console.warn) {
  4627. console.warn(
  4628. 'Select2: The `select2("val")` method has been deprecated and will be' +
  4629. ' removed in later Select2 versions. Use $element.val() instead.'
  4630. );
  4631. }
  4632. if (args == null || args.length === 0) {
  4633. return this.$element.val();
  4634. }
  4635. var newVal = args[0];
  4636. if ($.isArray(newVal)) {
  4637. newVal = $.map(newVal, function (obj) {
  4638. return obj.toString();
  4639. });
  4640. }
  4641. this.$element.val(newVal).trigger('change');
  4642. };
  4643. Select2.prototype.destroy = function () {
  4644. this.$container.remove();
  4645. if (this.$element[0].detachEvent) {
  4646. this.$element[0].detachEvent('onpropertychange', this._syncA);
  4647. }
  4648. if (this._observer != null) {
  4649. this._observer.disconnect();
  4650. this._observer = null;
  4651. } else if (this.$element[0].removeEventListener) {
  4652. this.$element[0]
  4653. .removeEventListener('DOMAttrModified', this._syncA, false);
  4654. this.$element[0]
  4655. .removeEventListener('DOMNodeInserted', this._syncS, false);
  4656. this.$element[0]
  4657. .removeEventListener('DOMNodeRemoved', this._syncS, false);
  4658. }
  4659. this._syncA = null;
  4660. this._syncS = null;
  4661. this.$element.off('.select2');
  4662. this.$element.attr('tabindex',
  4663. Utils.GetData(this.$element[0], 'old-tabindex'));
  4664. this.$element.removeClass('select2-hidden-accessible');
  4665. this.$element.attr('aria-hidden', 'false');
  4666. Utils.RemoveData(this.$element[0]);
  4667. this.$element.removeData('select2');
  4668. this.dataAdapter.destroy();
  4669. this.selection.destroy();
  4670. this.dropdown.destroy();
  4671. this.results.destroy();
  4672. this.dataAdapter = null;
  4673. this.selection = null;
  4674. this.dropdown = null;
  4675. this.results = null;
  4676. };
  4677. Select2.prototype.render = function () {
  4678. var $container = $(
  4679. '<span class="select2 select2-container">' +
  4680. '<span class="selection"></span>' +
  4681. '<span class="dropdown-wrapper" aria-hidden="true"></span>' +
  4682. '</span>'
  4683. );
  4684. $container.attr('dir', this.options.get('dir'));
  4685. this.$container = $container;
  4686. this.$container.addClass('select2-container--' + this.options.get('theme'));
  4687. Utils.StoreData($container[0], 'element', this.$element);
  4688. return $container;
  4689. };
  4690. return Select2;
  4691. });
  4692. S2.define('select2/compat/utils',[
  4693. 'jquery'
  4694. ], function ($) {
  4695. function syncCssClasses ($dest, $src, adapter) {
  4696. var classes, replacements = [], adapted;
  4697. classes = $.trim($dest.attr('class'));
  4698. if (classes) {
  4699. classes = '' + classes; // for IE which returns object
  4700. $(classes.split(/\s+/)).each(function () {
  4701. // Save all Select2 classes
  4702. if (this.indexOf('select2-') === 0) {
  4703. replacements.push(this);
  4704. }
  4705. });
  4706. }
  4707. classes = $.trim($src.attr('class'));
  4708. if (classes) {
  4709. classes = '' + classes; // for IE which returns object
  4710. $(classes.split(/\s+/)).each(function () {
  4711. // Only adapt non-Select2 classes
  4712. if (this.indexOf('select2-') !== 0) {
  4713. adapted = adapter(this);
  4714. if (adapted != null) {
  4715. replacements.push(adapted);
  4716. }
  4717. }
  4718. });
  4719. }
  4720. $dest.attr('class', replacements.join(' '));
  4721. }
  4722. return {
  4723. syncCssClasses: syncCssClasses
  4724. };
  4725. });
  4726. S2.define('select2/compat/containerCss',[
  4727. 'jquery',
  4728. './utils'
  4729. ], function ($, CompatUtils) {
  4730. // No-op CSS adapter that discards all classes by default
  4731. function _containerAdapter (clazz) {
  4732. return null;
  4733. }
  4734. function ContainerCSS () { }
  4735. ContainerCSS.prototype.render = function (decorated) {
  4736. var $container = decorated.call(this);
  4737. var containerCssClass = this.options.get('containerCssClass') || '';
  4738. if ($.isFunction(containerCssClass)) {
  4739. containerCssClass = containerCssClass(this.$element);
  4740. }
  4741. var containerCssAdapter = this.options.get('adaptContainerCssClass');
  4742. containerCssAdapter = containerCssAdapter || _containerAdapter;
  4743. if (containerCssClass.indexOf(':all:') !== -1) {
  4744. containerCssClass = containerCssClass.replace(':all:', '');
  4745. var _cssAdapter = containerCssAdapter;
  4746. containerCssAdapter = function (clazz) {
  4747. var adapted = _cssAdapter(clazz);
  4748. if (adapted != null) {
  4749. // Append the old one along with the adapted one
  4750. return adapted + ' ' + clazz;
  4751. }
  4752. return clazz;
  4753. };
  4754. }
  4755. var containerCss = this.options.get('containerCss') || {};
  4756. if ($.isFunction(containerCss)) {
  4757. containerCss = containerCss(this.$element);
  4758. }
  4759. CompatUtils.syncCssClasses($container, this.$element, containerCssAdapter);
  4760. $container.css(containerCss);
  4761. $container.addClass(containerCssClass);
  4762. return $container;
  4763. };
  4764. return ContainerCSS;
  4765. });
  4766. S2.define('select2/compat/dropdownCss',[
  4767. 'jquery',
  4768. './utils'
  4769. ], function ($, CompatUtils) {
  4770. // No-op CSS adapter that discards all classes by default
  4771. function _dropdownAdapter (clazz) {
  4772. return null;
  4773. }
  4774. function DropdownCSS () { }
  4775. DropdownCSS.prototype.render = function (decorated) {
  4776. var $dropdown = decorated.call(this);
  4777. var dropdownCssClass = this.options.get('dropdownCssClass') || '';
  4778. if ($.isFunction(dropdownCssClass)) {
  4779. dropdownCssClass = dropdownCssClass(this.$element);
  4780. }
  4781. var dropdownCssAdapter = this.options.get('adaptDropdownCssClass');
  4782. dropdownCssAdapter = dropdownCssAdapter || _dropdownAdapter;
  4783. if (dropdownCssClass.indexOf(':all:') !== -1) {
  4784. dropdownCssClass = dropdownCssClass.replace(':all:', '');
  4785. var _cssAdapter = dropdownCssAdapter;
  4786. dropdownCssAdapter = function (clazz) {
  4787. var adapted = _cssAdapter(clazz);
  4788. if (adapted != null) {
  4789. // Append the old one along with the adapted one
  4790. return adapted + ' ' + clazz;
  4791. }
  4792. return clazz;
  4793. };
  4794. }
  4795. var dropdownCss = this.options.get('dropdownCss') || {};
  4796. if ($.isFunction(dropdownCss)) {
  4797. dropdownCss = dropdownCss(this.$element);
  4798. }
  4799. CompatUtils.syncCssClasses($dropdown, this.$element, dropdownCssAdapter);
  4800. $dropdown.css(dropdownCss);
  4801. $dropdown.addClass(dropdownCssClass);
  4802. return $dropdown;
  4803. };
  4804. return DropdownCSS;
  4805. });
  4806. S2.define('select2/compat/initSelection',[
  4807. 'jquery'
  4808. ], function ($) {
  4809. function InitSelection (decorated, $element, options) {
  4810. if (options.get('debug') && window.console && console.warn) {
  4811. console.warn(
  4812. 'Select2: The `initSelection` option has been deprecated in favor' +
  4813. ' of a custom data adapter that overrides the `current` method. ' +
  4814. 'This method is now called multiple times instead of a single ' +
  4815. 'time when the instance is initialized. Support will be removed ' +
  4816. 'for the `initSelection` option in future versions of Select2'
  4817. );
  4818. }
  4819. this.initSelection = options.get('initSelection');
  4820. this._isInitialized = false;
  4821. decorated.call(this, $element, options);
  4822. }
  4823. InitSelection.prototype.current = function (decorated, callback) {
  4824. var self = this;
  4825. if (this._isInitialized) {
  4826. decorated.call(this, callback);
  4827. return;
  4828. }
  4829. this.initSelection.call(null, this.$element, function (data) {
  4830. self._isInitialized = true;
  4831. if (!$.isArray(data)) {
  4832. data = [data];
  4833. }
  4834. callback(data);
  4835. });
  4836. };
  4837. return InitSelection;
  4838. });
  4839. S2.define('select2/compat/inputData',[
  4840. 'jquery',
  4841. '../utils'
  4842. ], function ($, Utils) {
  4843. function InputData (decorated, $element, options) {
  4844. this._currentData = [];
  4845. this._valueSeparator = options.get('valueSeparator') || ',';
  4846. if ($element.prop('type') === 'hidden') {
  4847. if (options.get('debug') && console && console.warn) {
  4848. console.warn(
  4849. 'Select2: Using a hidden input with Select2 is no longer ' +
  4850. 'supported and may stop working in the future. It is recommended ' +
  4851. 'to use a `<select>` element instead.'
  4852. );
  4853. }
  4854. }
  4855. decorated.call(this, $element, options);
  4856. }
  4857. InputData.prototype.current = function (_, callback) {
  4858. function getSelected (data, selectedIds) {
  4859. var selected = [];
  4860. if (data.selected || $.inArray(data.id, selectedIds) !== -1) {
  4861. data.selected = true;
  4862. selected.push(data);
  4863. } else {
  4864. data.selected = false;
  4865. }
  4866. if (data.children) {
  4867. selected.push.apply(selected, getSelected(data.children, selectedIds));
  4868. }
  4869. return selected;
  4870. }
  4871. var selected = [];
  4872. for (var d = 0; d < this._currentData.length; d++) {
  4873. var data = this._currentData[d];
  4874. selected.push.apply(
  4875. selected,
  4876. getSelected(
  4877. data,
  4878. this.$element.val().split(
  4879. this._valueSeparator
  4880. )
  4881. )
  4882. );
  4883. }
  4884. callback(selected);
  4885. };
  4886. InputData.prototype.select = function (_, data) {
  4887. if (!this.options.get('multiple')) {
  4888. this.current(function (allData) {
  4889. $.map(allData, function (data) {
  4890. data.selected = false;
  4891. });
  4892. });
  4893. this.$element.val(data.id);
  4894. this.$element.trigger('change');
  4895. } else {
  4896. var value = this.$element.val();
  4897. value += this._valueSeparator + data.id;
  4898. this.$element.val(value);
  4899. this.$element.trigger('change');
  4900. }
  4901. };
  4902. InputData.prototype.unselect = function (_, data) {
  4903. var self = this;
  4904. data.selected = false;
  4905. this.current(function (allData) {
  4906. var values = [];
  4907. for (var d = 0; d < allData.length; d++) {
  4908. var item = allData[d];
  4909. if (data.id == item.id) {
  4910. continue;
  4911. }
  4912. values.push(item.id);
  4913. }
  4914. self.$element.val(values.join(self._valueSeparator));
  4915. self.$element.trigger('change');
  4916. });
  4917. };
  4918. InputData.prototype.query = function (_, params, callback) {
  4919. var results = [];
  4920. for (var d = 0; d < this._currentData.length; d++) {
  4921. var data = this._currentData[d];
  4922. var matches = this.matches(params, data);
  4923. if (matches !== null) {
  4924. results.push(matches);
  4925. }
  4926. }
  4927. callback({
  4928. results: results
  4929. });
  4930. };
  4931. InputData.prototype.addOptions = function (_, $options) {
  4932. var options = $.map($options, function ($option) {
  4933. return Utils.GetData($option[0], 'data');
  4934. });
  4935. this._currentData.push.apply(this._currentData, options);
  4936. };
  4937. return InputData;
  4938. });
  4939. S2.define('select2/compat/matcher',[
  4940. 'jquery'
  4941. ], function ($) {
  4942. function oldMatcher (matcher) {
  4943. function wrappedMatcher (params, data) {
  4944. var match = $.extend(true, {}, data);
  4945. if (params.term == null || $.trim(params.term) === '') {
  4946. return match;
  4947. }
  4948. if (data.children) {
  4949. for (var c = data.children.length - 1; c >= 0; c--) {
  4950. var child = data.children[c];
  4951. // Check if the child object matches
  4952. // The old matcher returned a boolean true or false
  4953. var doesMatch = matcher(params.term, child.text, child);
  4954. // If the child didn't match, pop it off
  4955. if (!doesMatch) {
  4956. match.children.splice(c, 1);
  4957. }
  4958. }
  4959. if (match.children.length > 0) {
  4960. return match;
  4961. }
  4962. }
  4963. if (matcher(params.term, data.text, data)) {
  4964. return match;
  4965. }
  4966. return null;
  4967. }
  4968. return wrappedMatcher;
  4969. }
  4970. return oldMatcher;
  4971. });
  4972. S2.define('select2/compat/query',[
  4973. ], function () {
  4974. function Query (decorated, $element, options) {
  4975. if (options.get('debug') && window.console && console.warn) {
  4976. console.warn(
  4977. 'Select2: The `query` option has been deprecated in favor of a ' +
  4978. 'custom data adapter that overrides the `query` method. Support ' +
  4979. 'will be removed for the `query` option in future versions of ' +
  4980. 'Select2.'
  4981. );
  4982. }
  4983. decorated.call(this, $element, options);
  4984. }
  4985. Query.prototype.query = function (_, params, callback) {
  4986. params.callback = callback;
  4987. var query = this.options.get('query');
  4988. query.call(null, params);
  4989. };
  4990. return Query;
  4991. });
  4992. S2.define('select2/dropdown/attachContainer',[
  4993. ], function () {
  4994. function AttachContainer (decorated, $element, options) {
  4995. decorated.call(this, $element, options);
  4996. }
  4997. AttachContainer.prototype.position =
  4998. function (decorated, $dropdown, $container) {
  4999. var $dropdownContainer = $container.find('.dropdown-wrapper');
  5000. $dropdownContainer.append($dropdown);
  5001. $dropdown.addClass('select2-dropdown--below');
  5002. $container.addClass('select2-container--below');
  5003. };
  5004. return AttachContainer;
  5005. });
  5006. S2.define('select2/dropdown/stopPropagation',[
  5007. ], function () {
  5008. function StopPropagation () { }
  5009. StopPropagation.prototype.bind = function (decorated, container, $container) {
  5010. decorated.call(this, container, $container);
  5011. var stoppedEvents = [
  5012. 'blur',
  5013. 'change',
  5014. 'click',
  5015. 'dblclick',
  5016. 'focus',
  5017. 'focusin',
  5018. 'focusout',
  5019. 'input',
  5020. 'keydown',
  5021. 'keyup',
  5022. 'keypress',
  5023. 'mousedown',
  5024. 'mouseenter',
  5025. 'mouseleave',
  5026. 'mousemove',
  5027. 'mouseover',
  5028. 'mouseup',
  5029. 'search',
  5030. 'touchend',
  5031. 'touchstart'
  5032. ];
  5033. this.$dropdown.on(stoppedEvents.join(' '), function (evt) {
  5034. evt.stopPropagation();
  5035. });
  5036. };
  5037. return StopPropagation;
  5038. });
  5039. S2.define('select2/selection/stopPropagation',[
  5040. ], function () {
  5041. function StopPropagation () { }
  5042. StopPropagation.prototype.bind = function (decorated, container, $container) {
  5043. decorated.call(this, container, $container);
  5044. var stoppedEvents = [
  5045. 'blur',
  5046. 'change',
  5047. 'click',
  5048. 'dblclick',
  5049. 'focus',
  5050. 'focusin',
  5051. 'focusout',
  5052. 'input',
  5053. 'keydown',
  5054. 'keyup',
  5055. 'keypress',
  5056. 'mousedown',
  5057. 'mouseenter',
  5058. 'mouseleave',
  5059. 'mousemove',
  5060. 'mouseover',
  5061. 'mouseup',
  5062. 'search',
  5063. 'touchend',
  5064. 'touchstart'
  5065. ];
  5066. this.$selection.on(stoppedEvents.join(' '), function (evt) {
  5067. evt.stopPropagation();
  5068. });
  5069. };
  5070. return StopPropagation;
  5071. });
  5072. /*!
  5073. * jQuery Mousewheel 3.1.13
  5074. *
  5075. * Copyright jQuery Foundation and other contributors
  5076. * Released under the MIT license
  5077. * http://jquery.org/license
  5078. */
  5079. (function (factory) {
  5080. if ( typeof S2.define === 'function' && S2.define.amd ) {
  5081. // AMD. Register as an anonymous module.
  5082. S2.define('jquery-mousewheel',['jquery'], factory);
  5083. } else if (typeof exports === 'object') {
  5084. // Node/CommonJS style for Browserify
  5085. module.exports = factory;
  5086. } else {
  5087. // Browser globals
  5088. factory(jQuery);
  5089. }
  5090. }(function ($) {
  5091. var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'],
  5092. toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ?
  5093. ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'],
  5094. slice = Array.prototype.slice,
  5095. nullLowestDeltaTimeout, lowestDelta;
  5096. if ( $.event.fixHooks ) {
  5097. for ( var i = toFix.length; i; ) {
  5098. $.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks;
  5099. }
  5100. }
  5101. var special = $.event.special.mousewheel = {
  5102. version: '3.1.12',
  5103. setup: function() {
  5104. if ( this.addEventListener ) {
  5105. for ( var i = toBind.length; i; ) {
  5106. this.addEventListener( toBind[--i], handler, false );
  5107. }
  5108. } else {
  5109. this.onmousewheel = handler;
  5110. }
  5111. // Store the line height and page height for this particular element
  5112. $.data(this, 'mousewheel-line-height', special.getLineHeight(this));
  5113. $.data(this, 'mousewheel-page-height', special.getPageHeight(this));
  5114. },
  5115. teardown: function() {
  5116. if ( this.removeEventListener ) {
  5117. for ( var i = toBind.length; i; ) {
  5118. this.removeEventListener( toBind[--i], handler, false );
  5119. }
  5120. } else {
  5121. this.onmousewheel = null;
  5122. }
  5123. // Clean up the data we added to the element
  5124. $.removeData(this, 'mousewheel-line-height');
  5125. $.removeData(this, 'mousewheel-page-height');
  5126. },
  5127. getLineHeight: function(elem) {
  5128. var $elem = $(elem),
  5129. $parent = $elem['offsetParent' in $.fn ? 'offsetParent' : 'parent']();
  5130. if (!$parent.length) {
  5131. $parent = $('body');
  5132. }
  5133. return parseInt($parent.css('fontSize'), 10) || parseInt($elem.css('fontSize'), 10) || 16;
  5134. },
  5135. getPageHeight: function(elem) {
  5136. return $(elem).height();
  5137. },
  5138. settings: {
  5139. adjustOldDeltas: true, // see shouldAdjustOldDeltas() below
  5140. normalizeOffset: true // calls getBoundingClientRect for each event
  5141. }
  5142. };
  5143. $.fn.extend({
  5144. mousewheel: function(fn) {
  5145. return fn ? this.bind('mousewheel', fn) : this.trigger('mousewheel');
  5146. },
  5147. unmousewheel: function(fn) {
  5148. return this.unbind('mousewheel', fn);
  5149. }
  5150. });
  5151. function handler(event) {
  5152. var orgEvent = event || window.event,
  5153. args = slice.call(arguments, 1),
  5154. delta = 0,
  5155. deltaX = 0,
  5156. deltaY = 0,
  5157. absDelta = 0,
  5158. offsetX = 0,
  5159. offsetY = 0;
  5160. event = $.event.fix(orgEvent);
  5161. event.type = 'mousewheel';
  5162. // Old school scrollwheel delta
  5163. if ( 'detail' in orgEvent ) { deltaY = orgEvent.detail * -1; }
  5164. if ( 'wheelDelta' in orgEvent ) { deltaY = orgEvent.wheelDelta; }
  5165. if ( 'wheelDeltaY' in orgEvent ) { deltaY = orgEvent.wheelDeltaY; }
  5166. if ( 'wheelDeltaX' in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; }
  5167. // Firefox < 17 horizontal scrolling related to DOMMouseScroll event
  5168. if ( 'axis' in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
  5169. deltaX = deltaY * -1;
  5170. deltaY = 0;
  5171. }
  5172. // Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy
  5173. delta = deltaY === 0 ? deltaX : deltaY;
  5174. // New school wheel delta (wheel event)
  5175. if ( 'deltaY' in orgEvent ) {
  5176. deltaY = orgEvent.deltaY * -1;
  5177. delta = deltaY;
  5178. }
  5179. if ( 'deltaX' in orgEvent ) {
  5180. deltaX = orgEvent.deltaX;
  5181. if ( deltaY === 0 ) { delta = deltaX * -1; }
  5182. }
  5183. // No change actually happened, no reason to go any further
  5184. if ( deltaY === 0 && deltaX === 0 ) { return; }
  5185. // Need to convert lines and pages to pixels if we aren't already in pixels
  5186. // There are three delta modes:
  5187. // * deltaMode 0 is by pixels, nothing to do
  5188. // * deltaMode 1 is by lines
  5189. // * deltaMode 2 is by pages
  5190. if ( orgEvent.deltaMode === 1 ) {
  5191. var lineHeight = $.data(this, 'mousewheel-line-height');
  5192. delta *= lineHeight;
  5193. deltaY *= lineHeight;
  5194. deltaX *= lineHeight;
  5195. } else if ( orgEvent.deltaMode === 2 ) {
  5196. var pageHeight = $.data(this, 'mousewheel-page-height');
  5197. delta *= pageHeight;
  5198. deltaY *= pageHeight;
  5199. deltaX *= pageHeight;
  5200. }
  5201. // Store lowest absolute delta to normalize the delta values
  5202. absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );
  5203. if ( !lowestDelta || absDelta < lowestDelta ) {
  5204. lowestDelta = absDelta;
  5205. // Adjust older deltas if necessary
  5206. if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
  5207. lowestDelta /= 40;
  5208. }
  5209. }
  5210. // Adjust older deltas if necessary
  5211. if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
  5212. // Divide all the things by 40!
  5213. delta /= 40;
  5214. deltaX /= 40;
  5215. deltaY /= 40;
  5216. }
  5217. // Get a whole, normalized value for the deltas
  5218. delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);
  5219. deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);
  5220. deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);
  5221. // Normalise offsetX and offsetY properties
  5222. if ( special.settings.normalizeOffset && this.getBoundingClientRect ) {
  5223. var boundingRect = this.getBoundingClientRect();
  5224. offsetX = event.clientX - boundingRect.left;
  5225. offsetY = event.clientY - boundingRect.top;
  5226. }
  5227. // Add information to the event object
  5228. event.deltaX = deltaX;
  5229. event.deltaY = deltaY;
  5230. event.deltaFactor = lowestDelta;
  5231. event.offsetX = offsetX;
  5232. event.offsetY = offsetY;
  5233. // Go ahead and set deltaMode to 0 since we converted to pixels
  5234. // Although this is a little odd since we overwrite the deltaX/Y
  5235. // properties with normalized deltas.
  5236. event.deltaMode = 0;
  5237. // Add event and delta to the front of the arguments
  5238. args.unshift(event, delta, deltaX, deltaY);
  5239. // Clearout lowestDelta after sometime to better
  5240. // handle multiple device types that give different
  5241. // a different lowestDelta
  5242. // Ex: trackpad = 3 and mouse wheel = 120
  5243. if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); }
  5244. nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200);
  5245. return ($.event.dispatch || $.event.handle).apply(this, args);
  5246. }
  5247. function nullLowestDelta() {
  5248. lowestDelta = null;
  5249. }
  5250. function shouldAdjustOldDeltas(orgEvent, absDelta) {
  5251. // If this is an older event and the delta is divisable by 120,
  5252. // then we are assuming that the browser is treating this as an
  5253. // older mouse wheel event and that we should divide the deltas
  5254. // by 40 to try and get a more usable deltaFactor.
  5255. // Side note, this actually impacts the reported scroll distance
  5256. // in older browsers and can cause scrolling to be slower than native.
  5257. // Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false.
  5258. return special.settings.adjustOldDeltas && orgEvent.type === 'mousewheel' && absDelta % 120 === 0;
  5259. }
  5260. }));
  5261. S2.define('jquery.select2',[
  5262. 'jquery',
  5263. 'jquery-mousewheel',
  5264. './select2/core',
  5265. './select2/defaults',
  5266. './select2/utils'
  5267. ], function ($, _, Select2, Defaults, Utils) {
  5268. if ($.fn.select2 == null) {
  5269. // All methods that should return the element
  5270. var thisMethods = ['open', 'close', 'destroy'];
  5271. $.fn.select2 = function (options) {
  5272. options = options || {};
  5273. if (typeof options === 'object') {
  5274. this.each(function () {
  5275. var instanceOptions = $.extend(true, {}, options);
  5276. var instance = new Select2($(this), instanceOptions);
  5277. });
  5278. return this;
  5279. } else if (typeof options === 'string') {
  5280. var ret;
  5281. var args = Array.prototype.slice.call(arguments, 1);
  5282. this.each(function () {
  5283. var instance = Utils.GetData(this, 'select2');
  5284. if (instance == null && window.console && console.error) {
  5285. console.error(
  5286. 'The select2(\'' + options + '\') method was called on an ' +
  5287. 'element that is not using Select2.'
  5288. );
  5289. }
  5290. ret = instance[options].apply(instance, args);
  5291. });
  5292. // Check if we should be returning `this`
  5293. if ($.inArray(options, thisMethods) > -1) {
  5294. return this;
  5295. }
  5296. return ret;
  5297. } else {
  5298. throw new Error('Invalid arguments for Select2: ' + options);
  5299. }
  5300. };
  5301. }
  5302. if ($.fn.select2.defaults == null) {
  5303. $.fn.select2.defaults = Defaults;
  5304. }
  5305. return Select2;
  5306. });
  5307. // Return the AMD loader configuration so it can be used outside of this file
  5308. return {
  5309. define: S2.define,
  5310. require: S2.require
  5311. };
  5312. }());
  5313. // Autoload the jQuery bindings
  5314. // We know that all of the modules exist above this, so we're safe
  5315. var select2 = S2.require('jquery.select2');
  5316. // Hold the AMD module references on the jQuery function that was just loaded
  5317. // This allows Select2 to use the internal loader outside of this file, such
  5318. // as in the language files.
  5319. jQuery.fn.select2.amd = S2;
  5320. // Return the Select2 instance for anyone who is importing it.
  5321. return select2;
  5322. }));