Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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