Geen omschrijving

select2.js 162KB

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