select2.full.js 169 KB

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