select2.full.js 143 KB

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