select2.js 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275
  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 ($.inArray(id, selectedIds) > -1) {
  681. $option.attr('aria-selected', 'true');
  682. } else {
  683. $option.attr('aria-selected', 'false');
  684. }
  685. });
  686. var $selected = $options.filter('[aria-selected=true]');
  687. // Check if there are any selected options
  688. if ($selected.length > 0) {
  689. // If there are selected options, highlight the first
  690. $selected.first().trigger('mouseenter');
  691. } else {
  692. // If there are no selected options, highlight the first option
  693. // in the dropdown
  694. $options.first().trigger('mouseenter');
  695. }
  696. });
  697. };
  698. Results.prototype.showLoading = function (params) {
  699. this.hideLoading();
  700. var loadingMore = this.options.get('translations').get('searching');
  701. var loading = {
  702. disabled: true,
  703. loading: true,
  704. text: loadingMore(params)
  705. };
  706. var $loading = this.option(loading);
  707. $loading.className += ' loading-results';
  708. this.$results.prepend($loading);
  709. };
  710. Results.prototype.hideLoading = function () {
  711. this.$results.find('.loading-results').remove();
  712. };
  713. Results.prototype.option = function (data) {
  714. var option = document.createElement('li');
  715. option.className = 'select2-results__option';
  716. var attrs = {
  717. 'role': 'treeitem',
  718. 'aria-selected': 'false'
  719. };
  720. if (data.disabled) {
  721. delete attrs['aria-selected'];
  722. attrs['aria-disabled'] = 'true';
  723. }
  724. if (data.id == null) {
  725. delete attrs['aria-selected'];
  726. }
  727. if (data._resultId != null) {
  728. option.id = data._resultId;
  729. }
  730. if (data.title) {
  731. option.title = data.title;
  732. }
  733. if (data.children) {
  734. attrs.role = 'group';
  735. attrs['aria-label'] = data.text;
  736. delete attrs['aria-selected'];
  737. }
  738. for (var attr in attrs) {
  739. var val = attrs[attr];
  740. option.setAttribute(attr, val);
  741. }
  742. if (data.children) {
  743. var $option = $(option);
  744. var label = document.createElement('strong');
  745. label.className = 'select2-results__group';
  746. var $label = $(label);
  747. this.template(data, label);
  748. var $children = [];
  749. for (var c = 0; c < data.children.length; c++) {
  750. var child = data.children[c];
  751. var $child = this.option(child);
  752. $children.push($child);
  753. }
  754. var $childrenContainer = $('<ul></ul>', {
  755. 'class': 'select2-results__options select2-results__options--nested'
  756. });
  757. $childrenContainer.append($children);
  758. $option.append(label);
  759. $option.append($childrenContainer);
  760. } else {
  761. this.template(data, option);
  762. }
  763. $.data(option, 'data', data);
  764. return option;
  765. };
  766. Results.prototype.bind = function (container, $container) {
  767. var self = this;
  768. var id = container.id + '-results';
  769. this.$results.attr('id', id);
  770. container.on('results:all', function (params) {
  771. self.clear();
  772. self.append(params.data);
  773. if (container.isOpen()) {
  774. self.setClasses();
  775. }
  776. });
  777. container.on('results:append', function (params) {
  778. self.append(params.data);
  779. if (container.isOpen()) {
  780. self.setClasses();
  781. }
  782. });
  783. container.on('query', function (params) {
  784. self.showLoading(params);
  785. });
  786. container.on('select', function () {
  787. if (!container.isOpen()) {
  788. return;
  789. }
  790. self.setClasses();
  791. });
  792. container.on('unselect', function () {
  793. if (!container.isOpen()) {
  794. return;
  795. }
  796. self.setClasses();
  797. });
  798. container.on('open', function () {
  799. // When the dropdown is open, aria-expended="true"
  800. self.$results.attr('aria-expanded', 'true');
  801. self.$results.attr('aria-hidden', 'false');
  802. self.setClasses();
  803. self.ensureHighlightVisible();
  804. });
  805. container.on('close', function () {
  806. // When the dropdown is closed, aria-expended="false"
  807. self.$results.attr('aria-expanded', 'false');
  808. self.$results.attr('aria-hidden', 'true');
  809. self.$results.removeAttr('aria-activedescendant');
  810. });
  811. container.on('results:toggle', function () {
  812. var $highlighted = self.getHighlightedResults();
  813. if ($highlighted.length === 0) {
  814. return;
  815. }
  816. $highlighted.trigger('mouseup');
  817. });
  818. container.on('results:select', function () {
  819. var $highlighted = self.getHighlightedResults();
  820. if ($highlighted.length === 0) {
  821. return;
  822. }
  823. var data = $highlighted.data('data');
  824. if ($highlighted.attr('aria-selected') == 'true') {
  825. self.trigger('close');
  826. } else {
  827. self.trigger('select', {
  828. data: data
  829. });
  830. }
  831. });
  832. container.on('results:previous', function () {
  833. var $highlighted = self.getHighlightedResults();
  834. var $options = self.$results.find('[aria-selected]');
  835. var currentIndex = $options.index($highlighted);
  836. // If we are already at te top, don't move further
  837. if (currentIndex === 0) {
  838. return;
  839. }
  840. var nextIndex = currentIndex - 1;
  841. // If none are highlighted, highlight the first
  842. if ($highlighted.length === 0) {
  843. nextIndex = 0;
  844. }
  845. var $next = $options.eq(nextIndex);
  846. $next.trigger('mouseenter');
  847. var currentOffset = self.$results.offset().top;
  848. var nextTop = $next.offset().top;
  849. var nextOffset = self.$results.scrollTop() + (nextTop - currentOffset);
  850. if (nextIndex === 0) {
  851. self.$results.scrollTop(0);
  852. } else if (nextTop - currentOffset < 0) {
  853. self.$results.scrollTop(nextOffset);
  854. }
  855. });
  856. container.on('results:next', function () {
  857. var $highlighted = self.getHighlightedResults();
  858. var $options = self.$results.find('[aria-selected]');
  859. var currentIndex = $options.index($highlighted);
  860. var nextIndex = currentIndex + 1;
  861. // If we are at the last option, stay there
  862. if (nextIndex >= $options.length) {
  863. return;
  864. }
  865. var $next = $options.eq(nextIndex);
  866. $next.trigger('mouseenter');
  867. var currentOffset = self.$results.offset().top +
  868. self.$results.outerHeight(false);
  869. var nextBottom = $next.offset().top + $next.outerHeight(false);
  870. var nextOffset = self.$results.scrollTop() + nextBottom - currentOffset;
  871. if (nextIndex === 0) {
  872. self.$results.scrollTop(0);
  873. } else if (nextBottom > currentOffset) {
  874. self.$results.scrollTop(nextOffset);
  875. }
  876. });
  877. container.on('results:focus', function (params) {
  878. params.element.addClass('select2-results__option--highlighted');
  879. });
  880. container.on('results:message', function (params) {
  881. self.displayMessage(params);
  882. });
  883. if ($.fn.mousewheel) {
  884. this.$results.on('mousewheel', function (e) {
  885. var top = self.$results.scrollTop();
  886. var bottom = (
  887. self.$results.get(0).scrollHeight -
  888. self.$results.scrollTop() +
  889. e.deltaY
  890. );
  891. var isAtTop = e.deltaY > 0 && top - e.deltaY <= 0;
  892. var isAtBottom = e.deltaY < 0 && bottom <= self.$results.height();
  893. if (isAtTop) {
  894. self.$results.scrollTop(0);
  895. e.preventDefault();
  896. e.stopPropagation();
  897. } else if (isAtBottom) {
  898. self.$results.scrollTop(
  899. self.$results.get(0).scrollHeight - self.$results.height()
  900. );
  901. e.preventDefault();
  902. e.stopPropagation();
  903. }
  904. });
  905. }
  906. this.$results.on('mouseup', '.select2-results__option[aria-selected]',
  907. function (evt) {
  908. var $this = $(this);
  909. var data = $this.data('data');
  910. if ($this.attr('aria-selected') === 'true') {
  911. if (self.options.get('multiple')) {
  912. self.trigger('unselect', {
  913. originalEvent: evt,
  914. data: data
  915. });
  916. } else {
  917. self.trigger('close');
  918. }
  919. return;
  920. }
  921. self.trigger('select', {
  922. originalEvent: evt,
  923. data: data
  924. });
  925. });
  926. this.$results.on('mouseenter', '.select2-results__option[aria-selected]',
  927. function (evt) {
  928. var data = $(this).data('data');
  929. self.getHighlightedResults()
  930. .removeClass('select2-results__option--highlighted');
  931. self.trigger('results:focus', {
  932. data: data,
  933. element: $(this)
  934. });
  935. });
  936. };
  937. Results.prototype.getHighlightedResults = function () {
  938. var $highlighted = this.$results
  939. .find('.select2-results__option--highlighted');
  940. return $highlighted;
  941. };
  942. Results.prototype.destroy = function () {
  943. this.$results.remove();
  944. };
  945. Results.prototype.ensureHighlightVisible = function () {
  946. var $highlighted = this.getHighlightedResults();
  947. if ($highlighted.length === 0) {
  948. return;
  949. }
  950. var $options = this.$results.find('[aria-selected]');
  951. var currentIndex = $options.index($highlighted);
  952. var currentOffset = this.$results.offset().top;
  953. var nextTop = $highlighted.offset().top;
  954. var nextOffset = this.$results.scrollTop() + (nextTop - currentOffset);
  955. var offsetDelta = nextTop - currentOffset;
  956. nextOffset -= $highlighted.outerHeight(false) * 2;
  957. if (currentIndex <= 2) {
  958. this.$results.scrollTop(0);
  959. } else if (offsetDelta > this.$results.outerHeight() || offsetDelta < 0) {
  960. this.$results.scrollTop(nextOffset);
  961. }
  962. };
  963. Results.prototype.template = function (result, container) {
  964. var template = this.options.get('templateResult');
  965. var escapeMarkup = this.options.get('escapeMarkup');
  966. var content = template(result);
  967. if (content == null) {
  968. container.style.display = 'none';
  969. } else if (typeof content === 'string') {
  970. container.innerHTML = escapeMarkup(content);
  971. } else {
  972. $(container).append(content);
  973. }
  974. };
  975. return Results;
  976. });
  977. S2.define('select2/keys',[
  978. ], function () {
  979. var KEYS = {
  980. BACKSPACE: 8,
  981. TAB: 9,
  982. ENTER: 13,
  983. SHIFT: 16,
  984. CTRL: 17,
  985. ALT: 18,
  986. ESC: 27,
  987. SPACE: 32,
  988. PAGE_UP: 33,
  989. PAGE_DOWN: 34,
  990. END: 35,
  991. HOME: 36,
  992. LEFT: 37,
  993. UP: 38,
  994. RIGHT: 39,
  995. DOWN: 40,
  996. DELETE: 46
  997. };
  998. return KEYS;
  999. });
  1000. S2.define('select2/selection/base',[
  1001. 'jquery',
  1002. '../utils',
  1003. '../keys'
  1004. ], function ($, Utils, KEYS) {
  1005. function BaseSelection ($element, options) {
  1006. this.$element = $element;
  1007. this.options = options;
  1008. BaseSelection.__super__.constructor.call(this);
  1009. }
  1010. Utils.Extend(BaseSelection, Utils.Observable);
  1011. BaseSelection.prototype.render = function () {
  1012. var $selection = $(
  1013. '<span class="select2-selection" role="combobox" ' +
  1014. 'aria-autocomplete="list" aria-haspopup="true" aria-expanded="false">' +
  1015. '</span>'
  1016. );
  1017. this._tabindex = 0;
  1018. if (this.$element.data('old-tabindex') != null) {
  1019. this._tabindex = this.$element.data('old-tabindex');
  1020. } else if (this.$element.attr('tabindex') != null) {
  1021. this._tabindex = this.$element.attr('tabindex');
  1022. }
  1023. $selection.attr('title', this.$element.attr('title'));
  1024. $selection.attr('tabindex', this._tabindex);
  1025. this.$selection = $selection;
  1026. return $selection;
  1027. };
  1028. BaseSelection.prototype.bind = function (container, $container) {
  1029. var self = this;
  1030. var id = container.id + '-container';
  1031. var resultsId = container.id + '-results';
  1032. this.container = container;
  1033. this.$selection.on('focus', function (evt) {
  1034. self.trigger('focus', evt);
  1035. });
  1036. this.$selection.on('blur', function (evt) {
  1037. self.trigger('blur', evt);
  1038. });
  1039. this.$selection.on('keydown', function (evt) {
  1040. self.trigger('keypress', evt);
  1041. if (evt.which === KEYS.SPACE) {
  1042. evt.preventDefault();
  1043. }
  1044. });
  1045. container.on('results:focus', function (params) {
  1046. self.$selection.attr('aria-activedescendant', params.data._resultId);
  1047. });
  1048. container.on('selection:update', function (params) {
  1049. self.update(params.data);
  1050. });
  1051. container.on('open', function () {
  1052. // When the dropdown is open, aria-expanded="true"
  1053. self.$selection.attr('aria-expanded', 'true');
  1054. self.$selection.attr('aria-owns', resultsId);
  1055. self._attachCloseHandler(container);
  1056. });
  1057. container.on('close', function () {
  1058. // When the dropdown is closed, aria-expanded="false"
  1059. self.$selection.attr('aria-expanded', 'false');
  1060. self.$selection.removeAttr('aria-activedescendant');
  1061. self.$selection.removeAttr('aria-owns');
  1062. self.$selection.focus();
  1063. self._detachCloseHandler(container);
  1064. });
  1065. container.on('enable', function () {
  1066. self.$selection.attr('tabindex', self._tabindex);
  1067. });
  1068. container.on('disable', function () {
  1069. self.$selection.attr('tabindex', '-1');
  1070. });
  1071. };
  1072. BaseSelection.prototype._attachCloseHandler = function (container) {
  1073. var self = this;
  1074. $(document.body).on('mousedown.select2.' + container.id, function (e) {
  1075. var $target = $(e.target);
  1076. var $select = $target.closest('.select2');
  1077. var $all = $('.select2.select2-container--open');
  1078. $all.each(function () {
  1079. var $this = $(this);
  1080. if (this == $select[0]) {
  1081. return;
  1082. }
  1083. var $element = $this.data('element');
  1084. $element.select2('close');
  1085. });
  1086. });
  1087. };
  1088. BaseSelection.prototype._detachCloseHandler = function (container) {
  1089. $(document.body).off('mousedown.select2.' + container.id);
  1090. };
  1091. BaseSelection.prototype.position = function ($selection, $container) {
  1092. var $selectionContainer = $container.find('.selection');
  1093. $selectionContainer.append($selection);
  1094. };
  1095. BaseSelection.prototype.destroy = function () {
  1096. this._detachCloseHandler(this.container);
  1097. };
  1098. BaseSelection.prototype.update = function (data) {
  1099. throw new Error('The `update` method must be defined in child classes.');
  1100. };
  1101. return BaseSelection;
  1102. });
  1103. S2.define('select2/selection/single',[
  1104. 'jquery',
  1105. './base',
  1106. '../utils',
  1107. '../keys'
  1108. ], function ($, BaseSelection, Utils, KEYS) {
  1109. function SingleSelection () {
  1110. SingleSelection.__super__.constructor.apply(this, arguments);
  1111. }
  1112. Utils.Extend(SingleSelection, BaseSelection);
  1113. SingleSelection.prototype.render = function () {
  1114. var $selection = SingleSelection.__super__.render.call(this);
  1115. $selection.addClass('select2-selection--single');
  1116. $selection.html(
  1117. '<span class="select2-selection__rendered"></span>' +
  1118. '<span class="select2-selection__arrow" role="presentation">' +
  1119. '<b role="presentation"></b>' +
  1120. '</span>'
  1121. );
  1122. return $selection;
  1123. };
  1124. SingleSelection.prototype.bind = function (container, $container) {
  1125. var self = this;
  1126. SingleSelection.__super__.bind.apply(this, arguments);
  1127. var id = container.id + '-container';
  1128. this.$selection.find('.select2-selection__rendered').attr('id', id);
  1129. this.$selection.attr('aria-labelledby', id);
  1130. this.$selection.on('mousedown', function (evt) {
  1131. // Only respond to left clicks
  1132. if (evt.which !== 1) {
  1133. return;
  1134. }
  1135. self.trigger('toggle', {
  1136. originalEvent: evt
  1137. });
  1138. });
  1139. this.$selection.on('focus', function (evt) {
  1140. // User focuses on the container
  1141. });
  1142. this.$selection.on('blur', function (evt) {
  1143. // User exits the container
  1144. });
  1145. container.on('selection:update', function (params) {
  1146. self.update(params.data);
  1147. });
  1148. };
  1149. SingleSelection.prototype.clear = function () {
  1150. this.$selection.find('.select2-selection__rendered').empty();
  1151. };
  1152. SingleSelection.prototype.display = function (data) {
  1153. var template = this.options.get('templateSelection');
  1154. var escapeMarkup = this.options.get('escapeMarkup');
  1155. return escapeMarkup(template(data));
  1156. };
  1157. SingleSelection.prototype.selectionContainer = function () {
  1158. return $('<span></span>');
  1159. };
  1160. SingleSelection.prototype.update = function (data) {
  1161. if (data.length === 0) {
  1162. this.clear();
  1163. return;
  1164. }
  1165. var selection = data[0];
  1166. var formatted = this.display(selection);
  1167. var $rendered = this.$selection.find('.select2-selection__rendered');
  1168. $rendered.empty().append(formatted);
  1169. $rendered.prop('title', selection.title || selection.text);
  1170. };
  1171. return SingleSelection;
  1172. });
  1173. S2.define('select2/selection/multiple',[
  1174. 'jquery',
  1175. './base',
  1176. '../utils'
  1177. ], function ($, BaseSelection, Utils) {
  1178. function MultipleSelection ($element, options) {
  1179. MultipleSelection.__super__.constructor.apply(this, arguments);
  1180. }
  1181. Utils.Extend(MultipleSelection, BaseSelection);
  1182. MultipleSelection.prototype.render = function () {
  1183. var $selection = MultipleSelection.__super__.render.call(this);
  1184. $selection.addClass('select2-selection--multiple');
  1185. $selection.html(
  1186. '<ul class="select2-selection__rendered"></ul>'
  1187. );
  1188. return $selection;
  1189. };
  1190. MultipleSelection.prototype.bind = function (container, $container) {
  1191. var self = this;
  1192. MultipleSelection.__super__.bind.apply(this, arguments);
  1193. this.$selection.on('click', function (evt) {
  1194. self.trigger('toggle', {
  1195. originalEvent: evt
  1196. });
  1197. });
  1198. this.$selection.on('click', '.select2-selection__choice__remove',
  1199. function (evt) {
  1200. var $remove = $(this);
  1201. var $selection = $remove.parent();
  1202. var data = $selection.data('data');
  1203. self.trigger('unselect', {
  1204. originalEvent: evt,
  1205. data: data
  1206. });
  1207. });
  1208. };
  1209. MultipleSelection.prototype.clear = function () {
  1210. this.$selection.find('.select2-selection__rendered').empty();
  1211. };
  1212. MultipleSelection.prototype.display = function (data) {
  1213. var template = this.options.get('templateSelection');
  1214. var escapeMarkup = this.options.get('escapeMarkup');
  1215. return escapeMarkup(template(data));
  1216. };
  1217. MultipleSelection.prototype.selectionContainer = function () {
  1218. var $container = $(
  1219. '<li class="select2-selection__choice">' +
  1220. '<span class="select2-selection__choice__remove" role="presentation">' +
  1221. '&times;' +
  1222. '</span>' +
  1223. '</li>'
  1224. );
  1225. return $container;
  1226. };
  1227. MultipleSelection.prototype.update = function (data) {
  1228. this.clear();
  1229. if (data.length === 0) {
  1230. return;
  1231. }
  1232. var $selections = $();
  1233. for (var d = 0; d < data.length; d++) {
  1234. var selection = data[d];
  1235. var formatted = this.display(selection);
  1236. var $selection = this.selectionContainer();
  1237. $selection.append(formatted);
  1238. $selection.prop('title', selection.title || selection.text);
  1239. $selection.data('data', selection);
  1240. $selections = $selections.add($selection);
  1241. }
  1242. this.$selection.find('.select2-selection__rendered').append($selections);
  1243. };
  1244. return MultipleSelection;
  1245. });
  1246. S2.define('select2/selection/placeholder',[
  1247. '../utils'
  1248. ], function (Utils) {
  1249. function Placeholder (decorated, $element, options) {
  1250. this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
  1251. decorated.call(this, $element, options);
  1252. }
  1253. Placeholder.prototype.normalizePlaceholder = function (_, placeholder) {
  1254. if (typeof placeholder === 'string') {
  1255. placeholder = {
  1256. id: '',
  1257. text: placeholder
  1258. };
  1259. }
  1260. return placeholder;
  1261. };
  1262. Placeholder.prototype.createPlaceholder = function (decorated, placeholder) {
  1263. var $placeholder = this.selectionContainer();
  1264. $placeholder.html(this.display(placeholder));
  1265. $placeholder.addClass('select2-selection__placeholder')
  1266. .removeClass('select2-selection__choice');
  1267. return $placeholder;
  1268. };
  1269. Placeholder.prototype.update = function (decorated, data) {
  1270. var singlePlaceholder = (
  1271. data.length == 1 && data[0].id != this.placeholder.id
  1272. );
  1273. var multipleSelections = data.length > 1;
  1274. if (multipleSelections || singlePlaceholder) {
  1275. return decorated.call(this, data);
  1276. }
  1277. this.clear();
  1278. var $placeholder = this.createPlaceholder(this.placeholder);
  1279. this.$selection.find('.select2-selection__rendered').append($placeholder);
  1280. };
  1281. return Placeholder;
  1282. });
  1283. S2.define('select2/selection/allowClear',[
  1284. 'jquery'
  1285. ], function ($) {
  1286. function AllowClear () { }
  1287. AllowClear.prototype.bind = function (decorated, container, $container) {
  1288. var self = this;
  1289. decorated.call(this, container, $container);
  1290. if (self.placeholder == null) {
  1291. if (self.options.get('debug') && window.console && console.error) {
  1292. console.error(
  1293. 'Select2: The `allowClear` option should be used in combination ' +
  1294. 'with the `placeholder` option.'
  1295. );
  1296. }
  1297. }
  1298. this.$selection.on('mousedown', '.select2-selection__clear',
  1299. function (evt) {
  1300. // Ignore the event if it is disabled
  1301. if (self.options.get('disabled')) {
  1302. return;
  1303. }
  1304. evt.stopPropagation();
  1305. var data = $(this).data('data');
  1306. for (var d = 0; d < data.length; d++) {
  1307. var unselectData = {
  1308. data: data[d]
  1309. };
  1310. // Trigger the `unselect` event, so people can prevent it from being
  1311. // cleared.
  1312. self.trigger('unselect', unselectData);
  1313. // If the event was prevented, don't clear it out.
  1314. if (unselectData.prevented) {
  1315. return;
  1316. }
  1317. }
  1318. self.$element.val(self.placeholder.id).trigger('change');
  1319. self.trigger('toggle');
  1320. });
  1321. };
  1322. AllowClear.prototype.update = function (decorated, data) {
  1323. decorated.call(this, data);
  1324. if (this.$selection.find('.select2-selection__placeholder').length > 0 ||
  1325. data.length === 0) {
  1326. return;
  1327. }
  1328. var $remove = $(
  1329. '<span class="select2-selection__clear">' +
  1330. '&times;' +
  1331. '</span>'
  1332. );
  1333. $remove.data('data', data);
  1334. this.$selection.find('.select2-selection__rendered').prepend($remove);
  1335. };
  1336. return AllowClear;
  1337. });
  1338. S2.define('select2/selection/search',[
  1339. 'jquery',
  1340. '../utils',
  1341. '../keys'
  1342. ], function ($, Utils, KEYS) {
  1343. function Search (decorated, $element, options) {
  1344. decorated.call(this, $element, options);
  1345. }
  1346. Search.prototype.render = function (decorated) {
  1347. var $search = $(
  1348. '<li class="select2-search select2-search--inline">' +
  1349. '<input class="select2-search__field" type="search" tabindex="-1"' +
  1350. ' autocomplete="off" autocorrect="off" autocapitalize="off"' +
  1351. ' spellcheck="false" role="textbox" />' +
  1352. '</li>'
  1353. );
  1354. this.$searchContainer = $search;
  1355. this.$search = $search.find('input');
  1356. var $rendered = decorated.call(this);
  1357. return $rendered;
  1358. };
  1359. Search.prototype.bind = function (decorated, container, $container) {
  1360. var self = this;
  1361. decorated.call(this, container, $container);
  1362. container.on('open', function () {
  1363. self.$search.attr('tabindex', 0);
  1364. self.$search.focus();
  1365. });
  1366. container.on('close', function () {
  1367. self.$search.attr('tabindex', -1);
  1368. self.$search.val('');
  1369. self.$search.focus();
  1370. });
  1371. container.on('enable', function () {
  1372. self.$search.prop('disabled', false);
  1373. });
  1374. container.on('disable', function () {
  1375. self.$search.prop('disabled', true);
  1376. });
  1377. this.$selection.on('focusin', '.select2-search--inline', function (evt) {
  1378. self.trigger('focus', evt);
  1379. });
  1380. this.$selection.on('focusout', '.select2-search--inline', function (evt) {
  1381. self.trigger('blur', evt);
  1382. });
  1383. this.$selection.on('keydown', '.select2-search--inline', function (evt) {
  1384. evt.stopPropagation();
  1385. self.trigger('keypress', evt);
  1386. self._keyUpPrevented = evt.isDefaultPrevented();
  1387. var key = evt.which;
  1388. if (key === KEYS.BACKSPACE && self.$search.val() === '') {
  1389. var $previousChoice = self.$searchContainer
  1390. .prev('.select2-selection__choice');
  1391. if ($previousChoice.length > 0) {
  1392. var item = $previousChoice.data('data');
  1393. self.searchRemoveChoice(item);
  1394. }
  1395. }
  1396. });
  1397. // Workaround for browsers which do not support the `input` event
  1398. // This will prevent double-triggering of events for browsers which support
  1399. // both the `keyup` and `input` events.
  1400. this.$selection.on('input', '.select2-search--inline', function (evt) {
  1401. // Unbind the duplicated `keyup` event
  1402. self.$selection.off('keyup.search');
  1403. });
  1404. this.$selection.on('keyup.search input', '.select2-search--inline',
  1405. function (evt) {
  1406. self.handleSearch(evt);
  1407. });
  1408. };
  1409. Search.prototype.createPlaceholder = function (decorated, placeholder) {
  1410. this.$search.attr('placeholder', placeholder.text);
  1411. };
  1412. Search.prototype.update = function (decorated, data) {
  1413. this.$search.attr('placeholder', '');
  1414. decorated.call(this, data);
  1415. this.$selection.find('.select2-selection__rendered')
  1416. .append(this.$searchContainer);
  1417. this.resizeSearch();
  1418. };
  1419. Search.prototype.handleSearch = function () {
  1420. this.resizeSearch();
  1421. if (!this._keyUpPrevented) {
  1422. var input = this.$search.val();
  1423. this.trigger('query', {
  1424. term: input
  1425. });
  1426. }
  1427. this._keyUpPrevented = false;
  1428. };
  1429. Search.prototype.searchRemoveChoice = function (decorated, item) {
  1430. this.trigger('unselect', {
  1431. data: item
  1432. });
  1433. this.trigger('open');
  1434. this.$search.val(item.text + ' ');
  1435. };
  1436. Search.prototype.resizeSearch = function () {
  1437. this.$search.css('width', '25px');
  1438. var width = '';
  1439. if (this.$search.attr('placeholder') !== '') {
  1440. width = this.$selection.find('.select2-selection__rendered').innerWidth();
  1441. } else {
  1442. var minimumWidth = this.$search.val().length + 1;
  1443. width = (minimumWidth * 0.75) + 'em';
  1444. }
  1445. this.$search.css('width', width);
  1446. };
  1447. return Search;
  1448. });
  1449. S2.define('select2/selection/eventRelay',[
  1450. 'jquery'
  1451. ], function ($) {
  1452. function EventRelay () { }
  1453. EventRelay.prototype.bind = function (decorated, container, $container) {
  1454. var self = this;
  1455. var relayEvents = [
  1456. 'open', 'opening',
  1457. 'close', 'closing',
  1458. 'select', 'selecting',
  1459. 'unselect', 'unselecting'
  1460. ];
  1461. var preventableEvents = ['opening', 'closing', 'selecting', 'unselecting'];
  1462. decorated.call(this, container, $container);
  1463. container.on('*', function (name, params) {
  1464. // Ignore events that should not be relayed
  1465. if ($.inArray(name, relayEvents) === -1) {
  1466. return;
  1467. }
  1468. // The parameters should always be an object
  1469. params = params || {};
  1470. // Generate the jQuery event for the Select2 event
  1471. var evt = $.Event('select2:' + name, {
  1472. params: params
  1473. });
  1474. self.$element.trigger(evt);
  1475. // Only handle preventable events if it was one
  1476. if ($.inArray(name, preventableEvents) === -1) {
  1477. return;
  1478. }
  1479. params.prevented = evt.isDefaultPrevented();
  1480. });
  1481. };
  1482. return EventRelay;
  1483. });
  1484. S2.define('select2/translation',[
  1485. 'jquery',
  1486. 'require'
  1487. ], function ($, require) {
  1488. function Translation (dict) {
  1489. this.dict = dict || {};
  1490. }
  1491. Translation.prototype.all = function () {
  1492. return this.dict;
  1493. };
  1494. Translation.prototype.get = function (key) {
  1495. return this.dict[key];
  1496. };
  1497. Translation.prototype.extend = function (translation) {
  1498. this.dict = $.extend({}, translation.all(), this.dict);
  1499. };
  1500. // Static functions
  1501. Translation._cache = {};
  1502. Translation.loadPath = function (path) {
  1503. if (!(path in Translation._cache)) {
  1504. var translations = require(path);
  1505. Translation._cache[path] = translations;
  1506. }
  1507. return new Translation(Translation._cache[path]);
  1508. };
  1509. return Translation;
  1510. });
  1511. S2.define('select2/diacritics',[
  1512. ], function () {
  1513. var diacritics = {
  1514. '\u24B6': 'A',
  1515. '\uFF21': 'A',
  1516. '\u00C0': 'A',
  1517. '\u00C1': 'A',
  1518. '\u00C2': 'A',
  1519. '\u1EA6': 'A',
  1520. '\u1EA4': 'A',
  1521. '\u1EAA': 'A',
  1522. '\u1EA8': 'A',
  1523. '\u00C3': 'A',
  1524. '\u0100': 'A',
  1525. '\u0102': 'A',
  1526. '\u1EB0': 'A',
  1527. '\u1EAE': 'A',
  1528. '\u1EB4': 'A',
  1529. '\u1EB2': 'A',
  1530. '\u0226': 'A',
  1531. '\u01E0': 'A',
  1532. '\u00C4': 'A',
  1533. '\u01DE': 'A',
  1534. '\u1EA2': 'A',
  1535. '\u00C5': 'A',
  1536. '\u01FA': 'A',
  1537. '\u01CD': 'A',
  1538. '\u0200': 'A',
  1539. '\u0202': 'A',
  1540. '\u1EA0': 'A',
  1541. '\u1EAC': 'A',
  1542. '\u1EB6': 'A',
  1543. '\u1E00': 'A',
  1544. '\u0104': 'A',
  1545. '\u023A': 'A',
  1546. '\u2C6F': 'A',
  1547. '\uA732': 'AA',
  1548. '\u00C6': 'AE',
  1549. '\u01FC': 'AE',
  1550. '\u01E2': 'AE',
  1551. '\uA734': 'AO',
  1552. '\uA736': 'AU',
  1553. '\uA738': 'AV',
  1554. '\uA73A': 'AV',
  1555. '\uA73C': 'AY',
  1556. '\u24B7': 'B',
  1557. '\uFF22': 'B',
  1558. '\u1E02': 'B',
  1559. '\u1E04': 'B',
  1560. '\u1E06': 'B',
  1561. '\u0243': 'B',
  1562. '\u0182': 'B',
  1563. '\u0181': 'B',
  1564. '\u24B8': 'C',
  1565. '\uFF23': 'C',
  1566. '\u0106': 'C',
  1567. '\u0108': 'C',
  1568. '\u010A': 'C',
  1569. '\u010C': 'C',
  1570. '\u00C7': 'C',
  1571. '\u1E08': 'C',
  1572. '\u0187': 'C',
  1573. '\u023B': 'C',
  1574. '\uA73E': 'C',
  1575. '\u24B9': 'D',
  1576. '\uFF24': 'D',
  1577. '\u1E0A': 'D',
  1578. '\u010E': 'D',
  1579. '\u1E0C': 'D',
  1580. '\u1E10': 'D',
  1581. '\u1E12': 'D',
  1582. '\u1E0E': 'D',
  1583. '\u0110': 'D',
  1584. '\u018B': 'D',
  1585. '\u018A': 'D',
  1586. '\u0189': 'D',
  1587. '\uA779': 'D',
  1588. '\u01F1': 'DZ',
  1589. '\u01C4': 'DZ',
  1590. '\u01F2': 'Dz',
  1591. '\u01C5': 'Dz',
  1592. '\u24BA': 'E',
  1593. '\uFF25': 'E',
  1594. '\u00C8': 'E',
  1595. '\u00C9': 'E',
  1596. '\u00CA': 'E',
  1597. '\u1EC0': 'E',
  1598. '\u1EBE': 'E',
  1599. '\u1EC4': 'E',
  1600. '\u1EC2': 'E',
  1601. '\u1EBC': 'E',
  1602. '\u0112': 'E',
  1603. '\u1E14': 'E',
  1604. '\u1E16': 'E',
  1605. '\u0114': 'E',
  1606. '\u0116': 'E',
  1607. '\u00CB': 'E',
  1608. '\u1EBA': 'E',
  1609. '\u011A': 'E',
  1610. '\u0204': 'E',
  1611. '\u0206': 'E',
  1612. '\u1EB8': 'E',
  1613. '\u1EC6': 'E',
  1614. '\u0228': 'E',
  1615. '\u1E1C': 'E',
  1616. '\u0118': 'E',
  1617. '\u1E18': 'E',
  1618. '\u1E1A': 'E',
  1619. '\u0190': 'E',
  1620. '\u018E': 'E',
  1621. '\u24BB': 'F',
  1622. '\uFF26': 'F',
  1623. '\u1E1E': 'F',
  1624. '\u0191': 'F',
  1625. '\uA77B': 'F',
  1626. '\u24BC': 'G',
  1627. '\uFF27': 'G',
  1628. '\u01F4': 'G',
  1629. '\u011C': 'G',
  1630. '\u1E20': 'G',
  1631. '\u011E': 'G',
  1632. '\u0120': 'G',
  1633. '\u01E6': 'G',
  1634. '\u0122': 'G',
  1635. '\u01E4': 'G',
  1636. '\u0193': 'G',
  1637. '\uA7A0': 'G',
  1638. '\uA77D': 'G',
  1639. '\uA77E': 'G',
  1640. '\u24BD': 'H',
  1641. '\uFF28': 'H',
  1642. '\u0124': 'H',
  1643. '\u1E22': 'H',
  1644. '\u1E26': 'H',
  1645. '\u021E': 'H',
  1646. '\u1E24': 'H',
  1647. '\u1E28': 'H',
  1648. '\u1E2A': 'H',
  1649. '\u0126': 'H',
  1650. '\u2C67': 'H',
  1651. '\u2C75': 'H',
  1652. '\uA78D': 'H',
  1653. '\u24BE': 'I',
  1654. '\uFF29': 'I',
  1655. '\u00CC': 'I',
  1656. '\u00CD': 'I',
  1657. '\u00CE': 'I',
  1658. '\u0128': 'I',
  1659. '\u012A': 'I',
  1660. '\u012C': 'I',
  1661. '\u0130': 'I',
  1662. '\u00CF': 'I',
  1663. '\u1E2E': 'I',
  1664. '\u1EC8': 'I',
  1665. '\u01CF': 'I',
  1666. '\u0208': 'I',
  1667. '\u020A': 'I',
  1668. '\u1ECA': 'I',
  1669. '\u012E': 'I',
  1670. '\u1E2C': 'I',
  1671. '\u0197': 'I',
  1672. '\u24BF': 'J',
  1673. '\uFF2A': 'J',
  1674. '\u0134': 'J',
  1675. '\u0248': 'J',
  1676. '\u24C0': 'K',
  1677. '\uFF2B': 'K',
  1678. '\u1E30': 'K',
  1679. '\u01E8': 'K',
  1680. '\u1E32': 'K',
  1681. '\u0136': 'K',
  1682. '\u1E34': 'K',
  1683. '\u0198': 'K',
  1684. '\u2C69': 'K',
  1685. '\uA740': 'K',
  1686. '\uA742': 'K',
  1687. '\uA744': 'K',
  1688. '\uA7A2': 'K',
  1689. '\u24C1': 'L',
  1690. '\uFF2C': 'L',
  1691. '\u013F': 'L',
  1692. '\u0139': 'L',
  1693. '\u013D': 'L',
  1694. '\u1E36': 'L',
  1695. '\u1E38': 'L',
  1696. '\u013B': 'L',
  1697. '\u1E3C': 'L',
  1698. '\u1E3A': 'L',
  1699. '\u0141': 'L',
  1700. '\u023D': 'L',
  1701. '\u2C62': 'L',
  1702. '\u2C60': 'L',
  1703. '\uA748': 'L',
  1704. '\uA746': 'L',
  1705. '\uA780': 'L',
  1706. '\u01C7': 'LJ',
  1707. '\u01C8': 'Lj',
  1708. '\u24C2': 'M',
  1709. '\uFF2D': 'M',
  1710. '\u1E3E': 'M',
  1711. '\u1E40': 'M',
  1712. '\u1E42': 'M',
  1713. '\u2C6E': 'M',
  1714. '\u019C': 'M',
  1715. '\u24C3': 'N',
  1716. '\uFF2E': 'N',
  1717. '\u01F8': 'N',
  1718. '\u0143': 'N',
  1719. '\u00D1': 'N',
  1720. '\u1E44': 'N',
  1721. '\u0147': 'N',
  1722. '\u1E46': 'N',
  1723. '\u0145': 'N',
  1724. '\u1E4A': 'N',
  1725. '\u1E48': 'N',
  1726. '\u0220': 'N',
  1727. '\u019D': 'N',
  1728. '\uA790': 'N',
  1729. '\uA7A4': 'N',
  1730. '\u01CA': 'NJ',
  1731. '\u01CB': 'Nj',
  1732. '\u24C4': 'O',
  1733. '\uFF2F': 'O',
  1734. '\u00D2': 'O',
  1735. '\u00D3': 'O',
  1736. '\u00D4': 'O',
  1737. '\u1ED2': 'O',
  1738. '\u1ED0': 'O',
  1739. '\u1ED6': 'O',
  1740. '\u1ED4': 'O',
  1741. '\u00D5': 'O',
  1742. '\u1E4C': 'O',
  1743. '\u022C': 'O',
  1744. '\u1E4E': 'O',
  1745. '\u014C': 'O',
  1746. '\u1E50': 'O',
  1747. '\u1E52': 'O',
  1748. '\u014E': 'O',
  1749. '\u022E': 'O',
  1750. '\u0230': 'O',
  1751. '\u00D6': 'O',
  1752. '\u022A': 'O',
  1753. '\u1ECE': 'O',
  1754. '\u0150': 'O',
  1755. '\u01D1': 'O',
  1756. '\u020C': 'O',
  1757. '\u020E': 'O',
  1758. '\u01A0': 'O',
  1759. '\u1EDC': 'O',
  1760. '\u1EDA': 'O',
  1761. '\u1EE0': 'O',
  1762. '\u1EDE': 'O',
  1763. '\u1EE2': 'O',
  1764. '\u1ECC': 'O',
  1765. '\u1ED8': 'O',
  1766. '\u01EA': 'O',
  1767. '\u01EC': 'O',
  1768. '\u00D8': 'O',
  1769. '\u01FE': 'O',
  1770. '\u0186': 'O',
  1771. '\u019F': 'O',
  1772. '\uA74A': 'O',
  1773. '\uA74C': 'O',
  1774. '\u01A2': 'OI',
  1775. '\uA74E': 'OO',
  1776. '\u0222': 'OU',
  1777. '\u24C5': 'P',
  1778. '\uFF30': 'P',
  1779. '\u1E54': 'P',
  1780. '\u1E56': 'P',
  1781. '\u01A4': 'P',
  1782. '\u2C63': 'P',
  1783. '\uA750': 'P',
  1784. '\uA752': 'P',
  1785. '\uA754': 'P',
  1786. '\u24C6': 'Q',
  1787. '\uFF31': 'Q',
  1788. '\uA756': 'Q',
  1789. '\uA758': 'Q',
  1790. '\u024A': 'Q',
  1791. '\u24C7': 'R',
  1792. '\uFF32': 'R',
  1793. '\u0154': 'R',
  1794. '\u1E58': 'R',
  1795. '\u0158': 'R',
  1796. '\u0210': 'R',
  1797. '\u0212': 'R',
  1798. '\u1E5A': 'R',
  1799. '\u1E5C': 'R',
  1800. '\u0156': 'R',
  1801. '\u1E5E': 'R',
  1802. '\u024C': 'R',
  1803. '\u2C64': 'R',
  1804. '\uA75A': 'R',
  1805. '\uA7A6': 'R',
  1806. '\uA782': 'R',
  1807. '\u24C8': 'S',
  1808. '\uFF33': 'S',
  1809. '\u1E9E': 'S',
  1810. '\u015A': 'S',
  1811. '\u1E64': 'S',
  1812. '\u015C': 'S',
  1813. '\u1E60': 'S',
  1814. '\u0160': 'S',
  1815. '\u1E66': 'S',
  1816. '\u1E62': 'S',
  1817. '\u1E68': 'S',
  1818. '\u0218': 'S',
  1819. '\u015E': 'S',
  1820. '\u2C7E': 'S',
  1821. '\uA7A8': 'S',
  1822. '\uA784': 'S',
  1823. '\u24C9': 'T',
  1824. '\uFF34': 'T',
  1825. '\u1E6A': 'T',
  1826. '\u0164': 'T',
  1827. '\u1E6C': 'T',
  1828. '\u021A': 'T',
  1829. '\u0162': 'T',
  1830. '\u1E70': 'T',
  1831. '\u1E6E': 'T',
  1832. '\u0166': 'T',
  1833. '\u01AC': 'T',
  1834. '\u01AE': 'T',
  1835. '\u023E': 'T',
  1836. '\uA786': 'T',
  1837. '\uA728': 'TZ',
  1838. '\u24CA': 'U',
  1839. '\uFF35': 'U',
  1840. '\u00D9': 'U',
  1841. '\u00DA': 'U',
  1842. '\u00DB': 'U',
  1843. '\u0168': 'U',
  1844. '\u1E78': 'U',
  1845. '\u016A': 'U',
  1846. '\u1E7A': 'U',
  1847. '\u016C': 'U',
  1848. '\u00DC': 'U',
  1849. '\u01DB': 'U',
  1850. '\u01D7': 'U',
  1851. '\u01D5': 'U',
  1852. '\u01D9': 'U',
  1853. '\u1EE6': 'U',
  1854. '\u016E': 'U',
  1855. '\u0170': 'U',
  1856. '\u01D3': 'U',
  1857. '\u0214': 'U',
  1858. '\u0216': 'U',
  1859. '\u01AF': 'U',
  1860. '\u1EEA': 'U',
  1861. '\u1EE8': 'U',
  1862. '\u1EEE': 'U',
  1863. '\u1EEC': 'U',
  1864. '\u1EF0': 'U',
  1865. '\u1EE4': 'U',
  1866. '\u1E72': 'U',
  1867. '\u0172': 'U',
  1868. '\u1E76': 'U',
  1869. '\u1E74': 'U',
  1870. '\u0244': 'U',
  1871. '\u24CB': 'V',
  1872. '\uFF36': 'V',
  1873. '\u1E7C': 'V',
  1874. '\u1E7E': 'V',
  1875. '\u01B2': 'V',
  1876. '\uA75E': 'V',
  1877. '\u0245': 'V',
  1878. '\uA760': 'VY',
  1879. '\u24CC': 'W',
  1880. '\uFF37': 'W',
  1881. '\u1E80': 'W',
  1882. '\u1E82': 'W',
  1883. '\u0174': 'W',
  1884. '\u1E86': 'W',
  1885. '\u1E84': 'W',
  1886. '\u1E88': 'W',
  1887. '\u2C72': 'W',
  1888. '\u24CD': 'X',
  1889. '\uFF38': 'X',
  1890. '\u1E8A': 'X',
  1891. '\u1E8C': 'X',
  1892. '\u24CE': 'Y',
  1893. '\uFF39': 'Y',
  1894. '\u1EF2': 'Y',
  1895. '\u00DD': 'Y',
  1896. '\u0176': 'Y',
  1897. '\u1EF8': 'Y',
  1898. '\u0232': 'Y',
  1899. '\u1E8E': 'Y',
  1900. '\u0178': 'Y',
  1901. '\u1EF6': 'Y',
  1902. '\u1EF4': 'Y',
  1903. '\u01B3': 'Y',
  1904. '\u024E': 'Y',
  1905. '\u1EFE': 'Y',
  1906. '\u24CF': 'Z',
  1907. '\uFF3A': 'Z',
  1908. '\u0179': 'Z',
  1909. '\u1E90': 'Z',
  1910. '\u017B': 'Z',
  1911. '\u017D': 'Z',
  1912. '\u1E92': 'Z',
  1913. '\u1E94': 'Z',
  1914. '\u01B5': 'Z',
  1915. '\u0224': 'Z',
  1916. '\u2C7F': 'Z',
  1917. '\u2C6B': 'Z',
  1918. '\uA762': 'Z',
  1919. '\u24D0': 'a',
  1920. '\uFF41': 'a',
  1921. '\u1E9A': 'a',
  1922. '\u00E0': 'a',
  1923. '\u00E1': 'a',
  1924. '\u00E2': 'a',
  1925. '\u1EA7': 'a',
  1926. '\u1EA5': 'a',
  1927. '\u1EAB': 'a',
  1928. '\u1EA9': 'a',
  1929. '\u00E3': 'a',
  1930. '\u0101': 'a',
  1931. '\u0103': 'a',
  1932. '\u1EB1': 'a',
  1933. '\u1EAF': 'a',
  1934. '\u1EB5': 'a',
  1935. '\u1EB3': 'a',
  1936. '\u0227': 'a',
  1937. '\u01E1': 'a',
  1938. '\u00E4': 'a',
  1939. '\u01DF': 'a',
  1940. '\u1EA3': 'a',
  1941. '\u00E5': 'a',
  1942. '\u01FB': 'a',
  1943. '\u01CE': 'a',
  1944. '\u0201': 'a',
  1945. '\u0203': 'a',
  1946. '\u1EA1': 'a',
  1947. '\u1EAD': 'a',
  1948. '\u1EB7': 'a',
  1949. '\u1E01': 'a',
  1950. '\u0105': 'a',
  1951. '\u2C65': 'a',
  1952. '\u0250': 'a',
  1953. '\uA733': 'aa',
  1954. '\u00E6': 'ae',
  1955. '\u01FD': 'ae',
  1956. '\u01E3': 'ae',
  1957. '\uA735': 'ao',
  1958. '\uA737': 'au',
  1959. '\uA739': 'av',
  1960. '\uA73B': 'av',
  1961. '\uA73D': 'ay',
  1962. '\u24D1': 'b',
  1963. '\uFF42': 'b',
  1964. '\u1E03': 'b',
  1965. '\u1E05': 'b',
  1966. '\u1E07': 'b',
  1967. '\u0180': 'b',
  1968. '\u0183': 'b',
  1969. '\u0253': 'b',
  1970. '\u24D2': 'c',
  1971. '\uFF43': 'c',
  1972. '\u0107': 'c',
  1973. '\u0109': 'c',
  1974. '\u010B': 'c',
  1975. '\u010D': 'c',
  1976. '\u00E7': 'c',
  1977. '\u1E09': 'c',
  1978. '\u0188': 'c',
  1979. '\u023C': 'c',
  1980. '\uA73F': 'c',
  1981. '\u2184': 'c',
  1982. '\u24D3': 'd',
  1983. '\uFF44': 'd',
  1984. '\u1E0B': 'd',
  1985. '\u010F': 'd',
  1986. '\u1E0D': 'd',
  1987. '\u1E11': 'd',
  1988. '\u1E13': 'd',
  1989. '\u1E0F': 'd',
  1990. '\u0111': 'd',
  1991. '\u018C': 'd',
  1992. '\u0256': 'd',
  1993. '\u0257': 'd',
  1994. '\uA77A': 'd',
  1995. '\u01F3': 'dz',
  1996. '\u01C6': 'dz',
  1997. '\u24D4': 'e',
  1998. '\uFF45': 'e',
  1999. '\u00E8': 'e',
  2000. '\u00E9': 'e',
  2001. '\u00EA': 'e',
  2002. '\u1EC1': 'e',
  2003. '\u1EBF': 'e',
  2004. '\u1EC5': 'e',
  2005. '\u1EC3': 'e',
  2006. '\u1EBD': 'e',
  2007. '\u0113': 'e',
  2008. '\u1E15': 'e',
  2009. '\u1E17': 'e',
  2010. '\u0115': 'e',
  2011. '\u0117': 'e',
  2012. '\u00EB': 'e',
  2013. '\u1EBB': 'e',
  2014. '\u011B': 'e',
  2015. '\u0205': 'e',
  2016. '\u0207': 'e',
  2017. '\u1EB9': 'e',
  2018. '\u1EC7': 'e',
  2019. '\u0229': 'e',
  2020. '\u1E1D': 'e',
  2021. '\u0119': 'e',
  2022. '\u1E19': 'e',
  2023. '\u1E1B': 'e',
  2024. '\u0247': 'e',
  2025. '\u025B': 'e',
  2026. '\u01DD': 'e',
  2027. '\u24D5': 'f',
  2028. '\uFF46': 'f',
  2029. '\u1E1F': 'f',
  2030. '\u0192': 'f',
  2031. '\uA77C': 'f',
  2032. '\u24D6': 'g',
  2033. '\uFF47': 'g',
  2034. '\u01F5': 'g',
  2035. '\u011D': 'g',
  2036. '\u1E21': 'g',
  2037. '\u011F': 'g',
  2038. '\u0121': 'g',
  2039. '\u01E7': 'g',
  2040. '\u0123': 'g',
  2041. '\u01E5': 'g',
  2042. '\u0260': 'g',
  2043. '\uA7A1': 'g',
  2044. '\u1D79': 'g',
  2045. '\uA77F': 'g',
  2046. '\u24D7': 'h',
  2047. '\uFF48': 'h',
  2048. '\u0125': 'h',
  2049. '\u1E23': 'h',
  2050. '\u1E27': 'h',
  2051. '\u021F': 'h',
  2052. '\u1E25': 'h',
  2053. '\u1E29': 'h',
  2054. '\u1E2B': 'h',
  2055. '\u1E96': 'h',
  2056. '\u0127': 'h',
  2057. '\u2C68': 'h',
  2058. '\u2C76': 'h',
  2059. '\u0265': 'h',
  2060. '\u0195': 'hv',
  2061. '\u24D8': 'i',
  2062. '\uFF49': 'i',
  2063. '\u00EC': 'i',
  2064. '\u00ED': 'i',
  2065. '\u00EE': 'i',
  2066. '\u0129': 'i',
  2067. '\u012B': 'i',
  2068. '\u012D': 'i',
  2069. '\u00EF': 'i',
  2070. '\u1E2F': 'i',
  2071. '\u1EC9': 'i',
  2072. '\u01D0': 'i',
  2073. '\u0209': 'i',
  2074. '\u020B': 'i',
  2075. '\u1ECB': 'i',
  2076. '\u012F': 'i',
  2077. '\u1E2D': 'i',
  2078. '\u0268': 'i',
  2079. '\u0131': 'i',
  2080. '\u24D9': 'j',
  2081. '\uFF4A': 'j',
  2082. '\u0135': 'j',
  2083. '\u01F0': 'j',
  2084. '\u0249': 'j',
  2085. '\u24DA': 'k',
  2086. '\uFF4B': 'k',
  2087. '\u1E31': 'k',
  2088. '\u01E9': 'k',
  2089. '\u1E33': 'k',
  2090. '\u0137': 'k',
  2091. '\u1E35': 'k',
  2092. '\u0199': 'k',
  2093. '\u2C6A': 'k',
  2094. '\uA741': 'k',
  2095. '\uA743': 'k',
  2096. '\uA745': 'k',
  2097. '\uA7A3': 'k',
  2098. '\u24DB': 'l',
  2099. '\uFF4C': 'l',
  2100. '\u0140': 'l',
  2101. '\u013A': 'l',
  2102. '\u013E': 'l',
  2103. '\u1E37': 'l',
  2104. '\u1E39': 'l',
  2105. '\u013C': 'l',
  2106. '\u1E3D': 'l',
  2107. '\u1E3B': 'l',
  2108. '\u017F': 'l',
  2109. '\u0142': 'l',
  2110. '\u019A': 'l',
  2111. '\u026B': 'l',
  2112. '\u2C61': 'l',
  2113. '\uA749': 'l',
  2114. '\uA781': 'l',
  2115. '\uA747': 'l',
  2116. '\u01C9': 'lj',
  2117. '\u24DC': 'm',
  2118. '\uFF4D': 'm',
  2119. '\u1E3F': 'm',
  2120. '\u1E41': 'm',
  2121. '\u1E43': 'm',
  2122. '\u0271': 'm',
  2123. '\u026F': 'm',
  2124. '\u24DD': 'n',
  2125. '\uFF4E': 'n',
  2126. '\u01F9': 'n',
  2127. '\u0144': 'n',
  2128. '\u00F1': 'n',
  2129. '\u1E45': 'n',
  2130. '\u0148': 'n',
  2131. '\u1E47': 'n',
  2132. '\u0146': 'n',
  2133. '\u1E4B': 'n',
  2134. '\u1E49': 'n',
  2135. '\u019E': 'n',
  2136. '\u0272': 'n',
  2137. '\u0149': 'n',
  2138. '\uA791': 'n',
  2139. '\uA7A5': 'n',
  2140. '\u01CC': 'nj',
  2141. '\u24DE': 'o',
  2142. '\uFF4F': 'o',
  2143. '\u00F2': 'o',
  2144. '\u00F3': 'o',
  2145. '\u00F4': 'o',
  2146. '\u1ED3': 'o',
  2147. '\u1ED1': 'o',
  2148. '\u1ED7': 'o',
  2149. '\u1ED5': 'o',
  2150. '\u00F5': 'o',
  2151. '\u1E4D': 'o',
  2152. '\u022D': 'o',
  2153. '\u1E4F': 'o',
  2154. '\u014D': 'o',
  2155. '\u1E51': 'o',
  2156. '\u1E53': 'o',
  2157. '\u014F': 'o',
  2158. '\u022F': 'o',
  2159. '\u0231': 'o',
  2160. '\u00F6': 'o',
  2161. '\u022B': 'o',
  2162. '\u1ECF': 'o',
  2163. '\u0151': 'o',
  2164. '\u01D2': 'o',
  2165. '\u020D': 'o',
  2166. '\u020F': 'o',
  2167. '\u01A1': 'o',
  2168. '\u1EDD': 'o',
  2169. '\u1EDB': 'o',
  2170. '\u1EE1': 'o',
  2171. '\u1EDF': 'o',
  2172. '\u1EE3': 'o',
  2173. '\u1ECD': 'o',
  2174. '\u1ED9': 'o',
  2175. '\u01EB': 'o',
  2176. '\u01ED': 'o',
  2177. '\u00F8': 'o',
  2178. '\u01FF': 'o',
  2179. '\u0254': 'o',
  2180. '\uA74B': 'o',
  2181. '\uA74D': 'o',
  2182. '\u0275': 'o',
  2183. '\u01A3': 'oi',
  2184. '\u0223': 'ou',
  2185. '\uA74F': 'oo',
  2186. '\u24DF': 'p',
  2187. '\uFF50': 'p',
  2188. '\u1E55': 'p',
  2189. '\u1E57': 'p',
  2190. '\u01A5': 'p',
  2191. '\u1D7D': 'p',
  2192. '\uA751': 'p',
  2193. '\uA753': 'p',
  2194. '\uA755': 'p',
  2195. '\u24E0': 'q',
  2196. '\uFF51': 'q',
  2197. '\u024B': 'q',
  2198. '\uA757': 'q',
  2199. '\uA759': 'q',
  2200. '\u24E1': 'r',
  2201. '\uFF52': 'r',
  2202. '\u0155': 'r',
  2203. '\u1E59': 'r',
  2204. '\u0159': 'r',
  2205. '\u0211': 'r',
  2206. '\u0213': 'r',
  2207. '\u1E5B': 'r',
  2208. '\u1E5D': 'r',
  2209. '\u0157': 'r',
  2210. '\u1E5F': 'r',
  2211. '\u024D': 'r',
  2212. '\u027D': 'r',
  2213. '\uA75B': 'r',
  2214. '\uA7A7': 'r',
  2215. '\uA783': 'r',
  2216. '\u24E2': 's',
  2217. '\uFF53': 's',
  2218. '\u00DF': 's',
  2219. '\u015B': 's',
  2220. '\u1E65': 's',
  2221. '\u015D': 's',
  2222. '\u1E61': 's',
  2223. '\u0161': 's',
  2224. '\u1E67': 's',
  2225. '\u1E63': 's',
  2226. '\u1E69': 's',
  2227. '\u0219': 's',
  2228. '\u015F': 's',
  2229. '\u023F': 's',
  2230. '\uA7A9': 's',
  2231. '\uA785': 's',
  2232. '\u1E9B': 's',
  2233. '\u24E3': 't',
  2234. '\uFF54': 't',
  2235. '\u1E6B': 't',
  2236. '\u1E97': 't',
  2237. '\u0165': 't',
  2238. '\u1E6D': 't',
  2239. '\u021B': 't',
  2240. '\u0163': 't',
  2241. '\u1E71': 't',
  2242. '\u1E6F': 't',
  2243. '\u0167': 't',
  2244. '\u01AD': 't',
  2245. '\u0288': 't',
  2246. '\u2C66': 't',
  2247. '\uA787': 't',
  2248. '\uA729': 'tz',
  2249. '\u24E4': 'u',
  2250. '\uFF55': 'u',
  2251. '\u00F9': 'u',
  2252. '\u00FA': 'u',
  2253. '\u00FB': 'u',
  2254. '\u0169': 'u',
  2255. '\u1E79': 'u',
  2256. '\u016B': 'u',
  2257. '\u1E7B': 'u',
  2258. '\u016D': 'u',
  2259. '\u00FC': 'u',
  2260. '\u01DC': 'u',
  2261. '\u01D8': 'u',
  2262. '\u01D6': 'u',
  2263. '\u01DA': 'u',
  2264. '\u1EE7': 'u',
  2265. '\u016F': 'u',
  2266. '\u0171': 'u',
  2267. '\u01D4': 'u',
  2268. '\u0215': 'u',
  2269. '\u0217': 'u',
  2270. '\u01B0': 'u',
  2271. '\u1EEB': 'u',
  2272. '\u1EE9': 'u',
  2273. '\u1EEF': 'u',
  2274. '\u1EED': 'u',
  2275. '\u1EF1': 'u',
  2276. '\u1EE5': 'u',
  2277. '\u1E73': 'u',
  2278. '\u0173': 'u',
  2279. '\u1E77': 'u',
  2280. '\u1E75': 'u',
  2281. '\u0289': 'u',
  2282. '\u24E5': 'v',
  2283. '\uFF56': 'v',
  2284. '\u1E7D': 'v',
  2285. '\u1E7F': 'v',
  2286. '\u028B': 'v',
  2287. '\uA75F': 'v',
  2288. '\u028C': 'v',
  2289. '\uA761': 'vy',
  2290. '\u24E6': 'w',
  2291. '\uFF57': 'w',
  2292. '\u1E81': 'w',
  2293. '\u1E83': 'w',
  2294. '\u0175': 'w',
  2295. '\u1E87': 'w',
  2296. '\u1E85': 'w',
  2297. '\u1E98': 'w',
  2298. '\u1E89': 'w',
  2299. '\u2C73': 'w',
  2300. '\u24E7': 'x',
  2301. '\uFF58': 'x',
  2302. '\u1E8B': 'x',
  2303. '\u1E8D': 'x',
  2304. '\u24E8': 'y',
  2305. '\uFF59': 'y',
  2306. '\u1EF3': 'y',
  2307. '\u00FD': 'y',
  2308. '\u0177': 'y',
  2309. '\u1EF9': 'y',
  2310. '\u0233': 'y',
  2311. '\u1E8F': 'y',
  2312. '\u00FF': 'y',
  2313. '\u1EF7': 'y',
  2314. '\u1E99': 'y',
  2315. '\u1EF5': 'y',
  2316. '\u01B4': 'y',
  2317. '\u024F': 'y',
  2318. '\u1EFF': 'y',
  2319. '\u24E9': 'z',
  2320. '\uFF5A': 'z',
  2321. '\u017A': 'z',
  2322. '\u1E91': 'z',
  2323. '\u017C': 'z',
  2324. '\u017E': 'z',
  2325. '\u1E93': 'z',
  2326. '\u1E95': 'z',
  2327. '\u01B6': 'z',
  2328. '\u0225': 'z',
  2329. '\u0240': 'z',
  2330. '\u2C6C': 'z',
  2331. '\uA763': 'z',
  2332. '\u0386': '\u0391',
  2333. '\u0388': '\u0395',
  2334. '\u0389': '\u0397',
  2335. '\u038A': '\u0399',
  2336. '\u03AA': '\u0399',
  2337. '\u038C': '\u039F',
  2338. '\u038E': '\u03A5',
  2339. '\u03AB': '\u03A5',
  2340. '\u038F': '\u03A9',
  2341. '\u03AC': '\u03B1',
  2342. '\u03AD': '\u03B5',
  2343. '\u03AE': '\u03B7',
  2344. '\u03AF': '\u03B9',
  2345. '\u03CA': '\u03B9',
  2346. '\u0390': '\u03B9',
  2347. '\u03CC': '\u03BF',
  2348. '\u03CD': '\u03C5',
  2349. '\u03CB': '\u03C5',
  2350. '\u03B0': '\u03C5',
  2351. '\u03C9': '\u03C9',
  2352. '\u03C2': '\u03C3'
  2353. };
  2354. return diacritics;
  2355. });
  2356. S2.define('select2/data/base',[
  2357. '../utils'
  2358. ], function (Utils) {
  2359. function BaseAdapter ($element, options) {
  2360. BaseAdapter.__super__.constructor.call(this);
  2361. }
  2362. Utils.Extend(BaseAdapter, Utils.Observable);
  2363. BaseAdapter.prototype.current = function (callback) {
  2364. throw new Error('The `current` method must be defined in child classes.');
  2365. };
  2366. BaseAdapter.prototype.query = function (params, callback) {
  2367. throw new Error('The `query` method must be defined in child classes.');
  2368. };
  2369. BaseAdapter.prototype.bind = function (container, $container) {
  2370. // Can be implemented in subclasses
  2371. };
  2372. BaseAdapter.prototype.destroy = function () {
  2373. // Can be implemented in subclasses
  2374. };
  2375. BaseAdapter.prototype.generateResultId = function (container, data) {
  2376. var id = container.id + '-result-';
  2377. id += Utils.generateChars(4);
  2378. if (data.id != null) {
  2379. id += '-' + data.id.toString();
  2380. } else {
  2381. id += '-' + Utils.generateChars(4);
  2382. }
  2383. return id;
  2384. };
  2385. return BaseAdapter;
  2386. });
  2387. S2.define('select2/data/select',[
  2388. './base',
  2389. '../utils',
  2390. 'jquery'
  2391. ], function (BaseAdapter, Utils, $) {
  2392. function SelectAdapter ($element, options) {
  2393. this.$element = $element;
  2394. this.options = options;
  2395. SelectAdapter.__super__.constructor.call(this);
  2396. }
  2397. Utils.Extend(SelectAdapter, BaseAdapter);
  2398. SelectAdapter.prototype.current = function (callback) {
  2399. var data = [];
  2400. var self = this;
  2401. this.$element.find(':selected').each(function () {
  2402. var $option = $(this);
  2403. var option = self.item($option);
  2404. data.push(option);
  2405. });
  2406. callback(data);
  2407. };
  2408. SelectAdapter.prototype.select = function (data) {
  2409. var self = this;
  2410. // If data.element is a DOM nose, use it instead
  2411. if ($(data.element).is('option')) {
  2412. data.element.selected = true;
  2413. this.$element.trigger('change');
  2414. return;
  2415. }
  2416. if (this.$element.prop('multiple')) {
  2417. this.current(function (currentData) {
  2418. var val = [];
  2419. data = [data];
  2420. data.push.apply(data, currentData);
  2421. for (var d = 0; d < data.length; d++) {
  2422. var id = data[d].id;
  2423. if ($.inArray(id, val) === -1) {
  2424. val.push(id);
  2425. }
  2426. }
  2427. self.$element.val(val);
  2428. self.$element.trigger('change');
  2429. });
  2430. } else {
  2431. var val = data.id;
  2432. this.$element.val(val);
  2433. this.$element.trigger('change');
  2434. }
  2435. };
  2436. SelectAdapter.prototype.unselect = function (data) {
  2437. var self = this;
  2438. if (!this.$element.prop('multiple')) {
  2439. return;
  2440. }
  2441. if ($(data.element).is('option')) {
  2442. data.element.selected = false;
  2443. this.$element.trigger('change');
  2444. return;
  2445. }
  2446. this.current(function (currentData) {
  2447. var val = [];
  2448. for (var d = 0; d < currentData.length; d++) {
  2449. var id = currentData[d].id;
  2450. if (id !== data.id && $.inArray(id, val) === -1) {
  2451. val.push(id);
  2452. }
  2453. }
  2454. self.$element.val(val);
  2455. self.$element.trigger('change');
  2456. });
  2457. };
  2458. SelectAdapter.prototype.bind = function (container, $container) {
  2459. var self = this;
  2460. this.container = container;
  2461. container.on('select', function (params) {
  2462. self.select(params.data);
  2463. });
  2464. container.on('unselect', function (params) {
  2465. self.unselect(params.data);
  2466. });
  2467. };
  2468. SelectAdapter.prototype.destroy = function () {
  2469. // Remove anything added to child elements
  2470. this.$element.find('*').each(function () {
  2471. // Remove any custom data set by Select2
  2472. $.removeData(this, 'data');
  2473. });
  2474. };
  2475. SelectAdapter.prototype.query = function (params, callback) {
  2476. var data = [];
  2477. var self = this;
  2478. var $options = this.$element.children();
  2479. $options.each(function () {
  2480. var $option = $(this);
  2481. if (!$option.is('option') && !$option.is('optgroup')) {
  2482. return;
  2483. }
  2484. var option = self.item($option);
  2485. var matches = self.matches(params, option);
  2486. if (matches !== null) {
  2487. data.push(matches);
  2488. }
  2489. });
  2490. callback({
  2491. results: data
  2492. });
  2493. };
  2494. SelectAdapter.prototype.addOptions = function ($options) {
  2495. this.$element.append($options);
  2496. };
  2497. SelectAdapter.prototype.option = function (data) {
  2498. var option;
  2499. if (data.children) {
  2500. option = document.createElement('optgroup');
  2501. option.label = data.text;
  2502. } else {
  2503. option = document.createElement('option');
  2504. if (option.textContent !== undefined) {
  2505. option.textContent = data.text;
  2506. } else {
  2507. option.innerText = data.text;
  2508. }
  2509. }
  2510. if (data.id) {
  2511. option.value = data.id;
  2512. }
  2513. if (data.disabled) {
  2514. option.disabled = true;
  2515. }
  2516. if (data.selected) {
  2517. option.selected = true;
  2518. }
  2519. if (data.title) {
  2520. option.title = data.title;
  2521. }
  2522. var $option = $(option);
  2523. var normalizedData = this._normalizeItem(data);
  2524. normalizedData.element = option;
  2525. // Override the option's data with the combined data
  2526. $.data(option, 'data', normalizedData);
  2527. return $option;
  2528. };
  2529. SelectAdapter.prototype.item = function ($option) {
  2530. var data = {};
  2531. data = $.data($option[0], 'data');
  2532. if (data != null) {
  2533. return data;
  2534. }
  2535. if ($option.is('option')) {
  2536. data = {
  2537. id: $option.val(),
  2538. text: $option.text(),
  2539. disabled: $option.prop('disabled'),
  2540. selected: $option.prop('selected'),
  2541. title: $option.prop('title')
  2542. };
  2543. } else if ($option.is('optgroup')) {
  2544. data = {
  2545. text: $option.prop('label'),
  2546. children: [],
  2547. title: $option.prop('title')
  2548. };
  2549. var $children = $option.children('option');
  2550. var children = [];
  2551. for (var c = 0; c < $children.length; c++) {
  2552. var $child = $($children[c]);
  2553. var child = this.item($child);
  2554. children.push(child);
  2555. }
  2556. data.children = children;
  2557. }
  2558. data = this._normalizeItem(data);
  2559. data.element = $option[0];
  2560. $.data($option[0], 'data', data);
  2561. return data;
  2562. };
  2563. SelectAdapter.prototype._normalizeItem = function (item) {
  2564. if (!$.isPlainObject(item)) {
  2565. item = {
  2566. id: item,
  2567. text: item
  2568. };
  2569. }
  2570. item = $.extend({}, {
  2571. text: ''
  2572. }, item);
  2573. var defaults = {
  2574. selected: false,
  2575. disabled: false
  2576. };
  2577. if (item.id != null) {
  2578. item.id = item.id.toString();
  2579. }
  2580. if (item.text != null) {
  2581. item.text = item.text.toString();
  2582. }
  2583. if (item._resultId == null && item.id && this.container != null) {
  2584. item._resultId = this.generateResultId(this.container, item);
  2585. }
  2586. return $.extend({}, defaults, item);
  2587. };
  2588. SelectAdapter.prototype.matches = function (params, data) {
  2589. var matcher = this.options.get('matcher');
  2590. return matcher(params, data);
  2591. };
  2592. return SelectAdapter;
  2593. });
  2594. S2.define('select2/data/array',[
  2595. './select',
  2596. '../utils',
  2597. 'jquery'
  2598. ], function (SelectAdapter, Utils, $) {
  2599. function ArrayAdapter ($element, options) {
  2600. var data = options.get('data') || [];
  2601. ArrayAdapter.__super__.constructor.call(this, $element, options);
  2602. this.addOptions(this.convertToOptions(data));
  2603. }
  2604. Utils.Extend(ArrayAdapter, SelectAdapter);
  2605. ArrayAdapter.prototype.select = function (data) {
  2606. var $option = this.$element.find('option[value="' + data.id + '"]');
  2607. if ($option.length === 0) {
  2608. $option = this.option(data);
  2609. this.addOptions($option);
  2610. }
  2611. ArrayAdapter.__super__.select.call(this, data);
  2612. };
  2613. ArrayAdapter.prototype.convertToOptions = function (data) {
  2614. var self = this;
  2615. var $existing = this.$element.find('option');
  2616. var existingIds = $existing.map(function () {
  2617. return self.item($(this)).id;
  2618. }).get();
  2619. var $options = $();
  2620. // Filter out all items except for the one passed in the argument
  2621. function onlyItem (item) {
  2622. return function () {
  2623. return $(this).val() == item.id;
  2624. };
  2625. }
  2626. for (var d = 0; d < data.length; d++) {
  2627. var item = this._normalizeItem(data[d]);
  2628. // Skip items which were pre-loaded, only merge the data
  2629. if ($.inArray(item.id, existingIds) >= 0) {
  2630. var $existingOption = $existing.filter(onlyItem(item));
  2631. var existingData = this.item($existingOption);
  2632. var newData = $.extend(true, {}, existingData, item);
  2633. var $newOption = this.option(existingData);
  2634. $existingOption.replaceWith($newOption);
  2635. continue;
  2636. }
  2637. var $option = this.option(item);
  2638. if (item.children) {
  2639. var $children = this.convertToOptions(item.children);
  2640. $option.append($children);
  2641. }
  2642. $options = $options.add($option);
  2643. }
  2644. return $options;
  2645. };
  2646. return ArrayAdapter;
  2647. });
  2648. S2.define('select2/data/ajax',[
  2649. './array',
  2650. '../utils',
  2651. 'jquery'
  2652. ], function (ArrayAdapter, Utils, $) {
  2653. function AjaxAdapter ($element, options) {
  2654. this.ajaxOptions = this._applyDefaults(options.get('ajax'));
  2655. if (this.ajaxOptions.processResults != null) {
  2656. this.processResults = this.ajaxOptions.processResults;
  2657. }
  2658. ArrayAdapter.__super__.constructor.call(this, $element, options);
  2659. }
  2660. Utils.Extend(AjaxAdapter, ArrayAdapter);
  2661. AjaxAdapter.prototype._applyDefaults = function (options) {
  2662. var defaults = {
  2663. data: function (params) {
  2664. return {
  2665. q: params.term
  2666. };
  2667. },
  2668. transport: function (params, success, failure) {
  2669. var $request = $.ajax(params);
  2670. $request.then(success);
  2671. $request.fail(failure);
  2672. return $request;
  2673. }
  2674. };
  2675. return $.extend({}, defaults, options, true);
  2676. };
  2677. AjaxAdapter.prototype.processResults = function (results) {
  2678. return results;
  2679. };
  2680. AjaxAdapter.prototype.query = function (params, callback) {
  2681. var matches = [];
  2682. var self = this;
  2683. if (this._request) {
  2684. this._request.abort();
  2685. this._request = null;
  2686. }
  2687. var options = $.extend({
  2688. type: 'GET'
  2689. }, this.ajaxOptions);
  2690. if (typeof options.url === 'function') {
  2691. options.url = options.url(params);
  2692. }
  2693. if (typeof options.data === 'function') {
  2694. options.data = options.data(params);
  2695. }
  2696. function request () {
  2697. var $request = options.transport(options, function (data) {
  2698. var results = self.processResults(data, params);
  2699. if (self.options.get('debug') && window.console && console.error) {
  2700. // Check to make sure that the response included a `results` key.
  2701. if (!results || !results.results || !$.isArray(results.results)) {
  2702. console.error(
  2703. 'Select2: The AJAX results did not return an array in the ' +
  2704. '`results` key of the response.'
  2705. );
  2706. }
  2707. }
  2708. callback(results);
  2709. }, function () {
  2710. // TODO: Handle AJAX errors
  2711. });
  2712. self._request = $request;
  2713. }
  2714. if (this.ajaxOptions.delay && params.term !== '') {
  2715. if (this._queryTimeout) {
  2716. window.clearTimeout(this._queryTimeout);
  2717. }
  2718. this._queryTimeout = window.setTimeout(request, this.ajaxOptions.delay);
  2719. } else {
  2720. request();
  2721. }
  2722. };
  2723. return AjaxAdapter;
  2724. });
  2725. S2.define('select2/data/tags',[
  2726. 'jquery'
  2727. ], function ($) {
  2728. function Tags (decorated, $element, options) {
  2729. var tags = options.get('tags');
  2730. var createTag = options.get('createTag');
  2731. if (createTag !== undefined) {
  2732. this.createTag = createTag;
  2733. }
  2734. decorated.call(this, $element, options);
  2735. if ($.isArray(tags)) {
  2736. for (var t = 0; t < tags.length; t++) {
  2737. var tag = tags[t];
  2738. var item = this._normalizeItem(tag);
  2739. var $option = this.option(item);
  2740. this.$element.append($option);
  2741. }
  2742. }
  2743. }
  2744. Tags.prototype.query = function (decorated, params, callback) {
  2745. var self = this;
  2746. this._removeOldTags();
  2747. if (params.term == null || params.page != null) {
  2748. decorated.call(this, params, callback);
  2749. return;
  2750. }
  2751. function wrapper (obj, child) {
  2752. var data = obj.results;
  2753. for (var i = 0; i < data.length; i++) {
  2754. var option = data[i];
  2755. var checkChildren = (
  2756. option.children != null &&
  2757. !wrapper({
  2758. results: option.children
  2759. }, true)
  2760. );
  2761. var checkText = option.text === params.term;
  2762. if (checkText || checkChildren) {
  2763. if (child) {
  2764. return false;
  2765. }
  2766. obj.data = data;
  2767. callback(obj);
  2768. return;
  2769. }
  2770. }
  2771. if (child) {
  2772. return true;
  2773. }
  2774. var tag = self.createTag(params);
  2775. if (tag != null) {
  2776. var $option = self.option(tag);
  2777. $option.attr('data-select2-tag', true);
  2778. self.addOptions($option);
  2779. self.insertTag(data, tag);
  2780. }
  2781. obj.results = data;
  2782. callback(obj);
  2783. }
  2784. decorated.call(this, params, wrapper);
  2785. };
  2786. Tags.prototype.createTag = function (decorated, params) {
  2787. var term = $.trim(params.term);
  2788. if (term === '') {
  2789. return null;
  2790. }
  2791. return {
  2792. id: term,
  2793. text: term
  2794. };
  2795. };
  2796. Tags.prototype.insertTag = function (_, data, tag) {
  2797. data.unshift(tag);
  2798. };
  2799. Tags.prototype._removeOldTags = function (_) {
  2800. var tag = this._lastTag;
  2801. var $options = this.$element.find('option[data-select2-tag]');
  2802. $options.each(function () {
  2803. if (this.selected) {
  2804. return;
  2805. }
  2806. $(this).remove();
  2807. });
  2808. };
  2809. return Tags;
  2810. });
  2811. S2.define('select2/data/tokenizer',[
  2812. 'jquery'
  2813. ], function ($) {
  2814. function Tokenizer (decorated, $element, options) {
  2815. var tokenizer = options.get('tokenizer');
  2816. if (tokenizer !== undefined) {
  2817. this.tokenizer = tokenizer;
  2818. }
  2819. decorated.call(this, $element, options);
  2820. }
  2821. Tokenizer.prototype.bind = function (decorated, container, $container) {
  2822. decorated.call(this, container, $container);
  2823. this.$search = container.dropdown.$search || container.selection.$search ||
  2824. $container.find('.select2-search__field');
  2825. };
  2826. Tokenizer.prototype.query = function (decorated, params, callback) {
  2827. var self = this;
  2828. function select (data) {
  2829. self.select(data);
  2830. }
  2831. params.term = params.term || '';
  2832. var tokenData = this.tokenizer(params, this.options, select);
  2833. if (tokenData.term !== params.term) {
  2834. // Replace the search term if we have the search box
  2835. if (this.$search.length) {
  2836. this.$search.val(tokenData.term);
  2837. this.$search.focus();
  2838. }
  2839. params.term = tokenData.term;
  2840. }
  2841. decorated.call(this, params, callback);
  2842. };
  2843. Tokenizer.prototype.tokenizer = function (_, params, options, callback) {
  2844. var separators = options.get('tokenSeparators') || [];
  2845. var term = params.term;
  2846. var i = 0;
  2847. var createTag = this.createTag || function (params) {
  2848. return {
  2849. id: params.term,
  2850. text: params.term
  2851. };
  2852. };
  2853. while (i < term.length) {
  2854. var termChar = term[i];
  2855. if ($.inArray(termChar, separators) === -1) {
  2856. i++;
  2857. continue;
  2858. }
  2859. var part = term.substr(0, i);
  2860. var partParams = $.extend({}, params, {
  2861. term: part
  2862. });
  2863. var data = createTag(partParams);
  2864. callback(data);
  2865. // Reset the term to not include the tokenized portion
  2866. term = term.substr(i + 1) || '';
  2867. i = 0;
  2868. }
  2869. return {
  2870. term: term
  2871. };
  2872. };
  2873. return Tokenizer;
  2874. });
  2875. S2.define('select2/data/minimumInputLength',[
  2876. ], function () {
  2877. function MinimumInputLength (decorated, $e, options) {
  2878. this.minimumInputLength = options.get('minimumInputLength');
  2879. decorated.call(this, $e, options);
  2880. }
  2881. MinimumInputLength.prototype.query = function (decorated, params, callback) {
  2882. params.term = params.term || '';
  2883. if (params.term.length < this.minimumInputLength) {
  2884. this.trigger('results:message', {
  2885. message: 'inputTooShort',
  2886. args: {
  2887. minimum: this.minimumInputLength,
  2888. input: params.term,
  2889. params: params
  2890. }
  2891. });
  2892. return;
  2893. }
  2894. decorated.call(this, params, callback);
  2895. };
  2896. return MinimumInputLength;
  2897. });
  2898. S2.define('select2/data/maximumInputLength',[
  2899. ], function () {
  2900. function MaximumInputLength (decorated, $e, options) {
  2901. this.maximumInputLength = options.get('maximumInputLength');
  2902. decorated.call(this, $e, options);
  2903. }
  2904. MaximumInputLength.prototype.query = function (decorated, params, callback) {
  2905. params.term = params.term || '';
  2906. if (this.maximumInputLength > 0 &&
  2907. params.term.length > this.maximumInputLength) {
  2908. this.trigger('results:message', {
  2909. message: 'inputTooLong',
  2910. args: {
  2911. maximum: this.maximumInputLength,
  2912. input: params.term,
  2913. params: params
  2914. }
  2915. });
  2916. return;
  2917. }
  2918. decorated.call(this, params, callback);
  2919. };
  2920. return MaximumInputLength;
  2921. });
  2922. S2.define('select2/data/maximumSelectionLength',[
  2923. ], function (){
  2924. function MaximumSelectionLength (decorated, $e, options) {
  2925. this.maximumSelectionLength = options.get('maximumSelectionLength');
  2926. decorated.call(this, $e, options);
  2927. }
  2928. MaximumSelectionLength.prototype.query =
  2929. function (decorated, params, callback) {
  2930. var self = this;
  2931. this.current(function (currentData) {
  2932. var count = currentData != null ? currentData.length : 0;
  2933. if (self.maximumSelectionLength > 0 &&
  2934. count >= self.maximumSelectionLength) {
  2935. self.trigger('results:message', {
  2936. message: 'maximumSelected',
  2937. args: {
  2938. maximum: self.maximumSelectionLength
  2939. }
  2940. });
  2941. return;
  2942. }
  2943. decorated.call(self, params, callback);
  2944. });
  2945. };
  2946. return MaximumSelectionLength;
  2947. });
  2948. S2.define('select2/dropdown',[
  2949. 'jquery',
  2950. './utils'
  2951. ], function ($, Utils) {
  2952. function Dropdown ($element, options) {
  2953. this.$element = $element;
  2954. this.options = options;
  2955. Dropdown.__super__.constructor.call(this);
  2956. }
  2957. Utils.Extend(Dropdown, Utils.Observable);
  2958. Dropdown.prototype.render = function () {
  2959. var $dropdown = $(
  2960. '<span class="select2-dropdown">' +
  2961. '<span class="select2-results"></span>' +
  2962. '</span>'
  2963. );
  2964. $dropdown.attr('dir', this.options.get('dir'));
  2965. this.$dropdown = $dropdown;
  2966. return $dropdown;
  2967. };
  2968. Dropdown.prototype.position = function ($dropdown, $container) {
  2969. // Should be implmented in subclasses
  2970. };
  2971. Dropdown.prototype.destroy = function () {
  2972. // Remove the dropdown from the DOM
  2973. this.$dropdown.remove();
  2974. };
  2975. return Dropdown;
  2976. });
  2977. S2.define('select2/dropdown/search',[
  2978. 'jquery',
  2979. '../utils'
  2980. ], function ($, Utils) {
  2981. function Search () { }
  2982. Search.prototype.render = function (decorated) {
  2983. var $rendered = decorated.call(this);
  2984. var $search = $(
  2985. '<span class="select2-search select2-search--dropdown">' +
  2986. '<input class="select2-search__field" type="search" tabindex="-1"' +
  2987. ' autocomplete="off" autocorrect="off" autocapitalize="off"' +
  2988. ' spellcheck="false" role="textbox" />' +
  2989. '</span>'
  2990. );
  2991. this.$searchContainer = $search;
  2992. this.$search = $search.find('input');
  2993. $rendered.prepend($search);
  2994. return $rendered;
  2995. };
  2996. Search.prototype.bind = function (decorated, container, $container) {
  2997. var self = this;
  2998. decorated.call(this, container, $container);
  2999. this.$search.on('keydown', function (evt) {
  3000. self.trigger('keypress', evt);
  3001. self._keyUpPrevented = evt.isDefaultPrevented();
  3002. });
  3003. // Workaround for browsers which do not support the `input` event
  3004. // This will prevent double-triggering of events for browsers which support
  3005. // both the `keyup` and `input` events.
  3006. this.$search.on('input', function (evt) {
  3007. // Unbind the duplicated `keyup` event
  3008. $(this).off('keyup');
  3009. });
  3010. this.$search.on('keyup input', function (evt) {
  3011. self.handleSearch(evt);
  3012. });
  3013. container.on('open', function () {
  3014. self.$search.attr('tabindex', 0);
  3015. self.$search.focus();
  3016. window.setTimeout(function () {
  3017. self.$search.focus();
  3018. }, 0);
  3019. });
  3020. container.on('close', function () {
  3021. self.$search.attr('tabindex', -1);
  3022. self.$search.val('');
  3023. });
  3024. container.on('results:all', function (params) {
  3025. if (params.query.term == null || params.query.term === '') {
  3026. var showSearch = self.showSearch(params);
  3027. if (showSearch) {
  3028. self.$searchContainer.removeClass('select2-search--hide');
  3029. } else {
  3030. self.$searchContainer.addClass('select2-search--hide');
  3031. }
  3032. }
  3033. });
  3034. };
  3035. Search.prototype.handleSearch = function (evt) {
  3036. if (!this._keyUpPrevented) {
  3037. var input = this.$search.val();
  3038. this.trigger('query', {
  3039. term: input
  3040. });
  3041. }
  3042. this._keyUpPrevented = false;
  3043. };
  3044. Search.prototype.showSearch = function (_, params) {
  3045. return true;
  3046. };
  3047. return Search;
  3048. });
  3049. S2.define('select2/dropdown/hidePlaceholder',[
  3050. ], function () {
  3051. function HidePlaceholder (decorated, $element, options, dataAdapter) {
  3052. this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
  3053. decorated.call(this, $element, options, dataAdapter);
  3054. }
  3055. HidePlaceholder.prototype.append = function (decorated, data) {
  3056. data.results = this.removePlaceholder(data.results);
  3057. decorated.call(this, data);
  3058. };
  3059. HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) {
  3060. if (typeof placeholder === 'string') {
  3061. placeholder = {
  3062. id: '',
  3063. text: placeholder
  3064. };
  3065. }
  3066. return placeholder;
  3067. };
  3068. HidePlaceholder.prototype.removePlaceholder = function (_, data) {
  3069. var modifiedData = data.slice(0);
  3070. for (var d = data.length - 1; d >= 0; d--) {
  3071. var item = data[d];
  3072. if (this.placeholder.id === item.id) {
  3073. modifiedData.splice(d, 1);
  3074. }
  3075. }
  3076. return modifiedData;
  3077. };
  3078. return HidePlaceholder;
  3079. });
  3080. S2.define('select2/dropdown/infiniteScroll',[
  3081. 'jquery'
  3082. ], function ($) {
  3083. function InfiniteScroll (decorated, $element, options, dataAdapter) {
  3084. this.lastParams = {};
  3085. decorated.call(this, $element, options, dataAdapter);
  3086. this.$loadingMore = this.createLoadingMore();
  3087. this.loading = false;
  3088. }
  3089. InfiniteScroll.prototype.append = function (decorated, data) {
  3090. this.$loadingMore.remove();
  3091. this.loading = false;
  3092. decorated.call(this, data);
  3093. if (this.showLoadingMore(data)) {
  3094. this.$results.append(this.$loadingMore);
  3095. }
  3096. };
  3097. InfiniteScroll.prototype.bind = function (decorated, container, $container) {
  3098. var self = this;
  3099. decorated.call(this, container, $container);
  3100. container.on('query', function (params) {
  3101. self.lastParams = params;
  3102. self.loading = true;
  3103. });
  3104. container.on('query:append', function (params) {
  3105. self.lastParams = params;
  3106. self.loading = true;
  3107. });
  3108. this.$results.on('scroll', function () {
  3109. var isLoadMoreVisible = $.contains(
  3110. document.documentElement,
  3111. self.$loadingMore[0]
  3112. );
  3113. if (self.loading || !isLoadMoreVisible) {
  3114. return;
  3115. }
  3116. var currentOffset = self.$results.offset().top +
  3117. self.$results.outerHeight(false);
  3118. var loadingMoreOffset = self.$loadingMore.offset().top +
  3119. self.$loadingMore.outerHeight(false);
  3120. if (currentOffset + 50 >= loadingMoreOffset) {
  3121. self.loadMore();
  3122. }
  3123. });
  3124. };
  3125. InfiniteScroll.prototype.loadMore = function () {
  3126. this.loading = true;
  3127. var params = $.extend({}, {page: 1}, this.lastParams);
  3128. params.page++;
  3129. this.trigger('query:append', params);
  3130. };
  3131. InfiniteScroll.prototype.showLoadingMore = function (_, data) {
  3132. return data.pagination && data.pagination.more;
  3133. };
  3134. InfiniteScroll.prototype.createLoadingMore = function () {
  3135. var $option = $(
  3136. '<li class="option load-more" role="treeitem"></li>'
  3137. );
  3138. var message = this.options.get('translations').get('loadingMore');
  3139. $option.html(message(this.lastParams));
  3140. return $option;
  3141. };
  3142. return InfiniteScroll;
  3143. });
  3144. S2.define('select2/dropdown/attachBody',[
  3145. 'jquery',
  3146. '../utils'
  3147. ], function ($, Utils) {
  3148. function AttachBody (decorated, $element, options) {
  3149. this.$dropdownParent = options.get('dropdownParent') || document.body;
  3150. decorated.call(this, $element, options);
  3151. }
  3152. AttachBody.prototype.bind = function (decorated, container, $container) {
  3153. var self = this;
  3154. var setupResultsEvents = false;
  3155. decorated.call(this, container, $container);
  3156. container.on('open', function () {
  3157. self._showDropdown();
  3158. self._attachPositioningHandler(container);
  3159. if (!setupResultsEvents) {
  3160. setupResultsEvents = true;
  3161. container.on('results:all', function () {
  3162. self._positionDropdown();
  3163. self._resizeDropdown();
  3164. });
  3165. container.on('results:append', function () {
  3166. self._positionDropdown();
  3167. self._resizeDropdown();
  3168. });
  3169. }
  3170. });
  3171. container.on('close', function () {
  3172. self._hideDropdown();
  3173. self._detachPositioningHandler(container);
  3174. });
  3175. this.$dropdownContainer.on('mousedown', function (evt) {
  3176. evt.stopPropagation();
  3177. });
  3178. };
  3179. AttachBody.prototype.position = function (decorated, $dropdown, $container) {
  3180. // Clone all of the container classes
  3181. $dropdown.attr('class', $container.attr('class'));
  3182. $dropdown.removeClass('select2');
  3183. $dropdown.addClass('select2-container--open');
  3184. $dropdown.css({
  3185. position: 'absolute',
  3186. top: -999999
  3187. });
  3188. this.$container = $container;
  3189. };
  3190. AttachBody.prototype.render = function (decorated) {
  3191. var $container = $('<span></span>');
  3192. var $dropdown = decorated.call(this);
  3193. $container.append($dropdown);
  3194. this.$dropdownContainer = $container;
  3195. return $container;
  3196. };
  3197. AttachBody.prototype._hideDropdown = function (decorated) {
  3198. this.$dropdownContainer.detach();
  3199. };
  3200. AttachBody.prototype._attachPositioningHandler = function (container) {
  3201. var self = this;
  3202. var scrollEvent = 'scroll.select2.' + container.id;
  3203. var resizeEvent = 'resize.select2.' + container.id;
  3204. var orientationEvent = 'orientationchange.select2.' + container.id;
  3205. var $watchers = this.$container.parents().filter(Utils.hasScroll);
  3206. $watchers.each(function () {
  3207. $(this).data('select2-scroll-position', {
  3208. x: $(this).scrollLeft(),
  3209. y: $(this).scrollTop()
  3210. });
  3211. });
  3212. $watchers.on(scrollEvent, function (ev) {
  3213. var position = $(this).data('select2-scroll-position');
  3214. $(this).scrollTop(position.y);
  3215. });
  3216. $(window).on(scrollEvent + ' ' + resizeEvent + ' ' + orientationEvent,
  3217. function (e) {
  3218. self._positionDropdown();
  3219. self._resizeDropdown();
  3220. });
  3221. };
  3222. AttachBody.prototype._detachPositioningHandler = function (container) {
  3223. var scrollEvent = 'scroll.select2.' + container.id;
  3224. var resizeEvent = 'resize.select2.' + container.id;
  3225. var orientationEvent = 'orientationchange.select2.' + container.id;
  3226. var $watchers = this.$container.parents().filter(Utils.hasScroll);
  3227. $watchers.off(scrollEvent);
  3228. $(window).off(scrollEvent + ' ' + resizeEvent + ' ' + orientationEvent);
  3229. };
  3230. AttachBody.prototype._positionDropdown = function () {
  3231. var $window = $(window);
  3232. var isCurrentlyAbove = this.$dropdown.hasClass('select2-dropdown--above');
  3233. var isCurrentlyBelow = this.$dropdown.hasClass('select2-dropdown--below');
  3234. var newDirection = null;
  3235. var position = this.$container.position();
  3236. var offset = this.$container.offset();
  3237. offset.bottom = offset.top + this.$container.outerHeight(false);
  3238. var container = {
  3239. height: this.$container.outerHeight(false)
  3240. };
  3241. container.top = offset.top;
  3242. container.bottom = offset.top + container.height;
  3243. var dropdown = {
  3244. height: this.$dropdown.outerHeight(false)
  3245. };
  3246. var viewport = {
  3247. top: $window.scrollTop(),
  3248. bottom: $window.scrollTop() + $window.height()
  3249. };
  3250. var enoughRoomAbove = viewport.top < (offset.top - dropdown.height);
  3251. var enoughRoomBelow = viewport.bottom > (offset.bottom + dropdown.height);
  3252. var css = {
  3253. left: offset.left,
  3254. top: container.bottom
  3255. };
  3256. if (!isCurrentlyAbove && !isCurrentlyBelow) {
  3257. newDirection = 'below';
  3258. }
  3259. if (!enoughRoomBelow && enoughRoomAbove && !isCurrentlyAbove) {
  3260. newDirection = 'above';
  3261. } else if (!enoughRoomAbove && enoughRoomBelow && isCurrentlyAbove) {
  3262. newDirection = 'below';
  3263. }
  3264. if (newDirection == 'above' ||
  3265. (isCurrentlyAbove && newDirection !== 'below')) {
  3266. css.top = container.top - dropdown.height;
  3267. }
  3268. if (newDirection != null) {
  3269. this.$dropdown
  3270. .removeClass('select2-dropdown--below select2-dropdown--above')
  3271. .addClass('select2-dropdown--' + newDirection);
  3272. this.$container
  3273. .removeClass('select2-container--below select2-container--above')
  3274. .addClass('select2-container--' + newDirection);
  3275. }
  3276. this.$dropdownContainer.css(css);
  3277. };
  3278. AttachBody.prototype._resizeDropdown = function () {
  3279. this.$dropdownContainer.width();
  3280. this.$dropdown.css({
  3281. width: this.$container.outerWidth(false) + 'px'
  3282. });
  3283. };
  3284. AttachBody.prototype._showDropdown = function (decorated) {
  3285. this.$dropdownContainer.appendTo(this.$dropdownParent);
  3286. this._positionDropdown();
  3287. this._resizeDropdown();
  3288. };
  3289. return AttachBody;
  3290. });
  3291. S2.define('select2/dropdown/minimumResultsForSearch',[
  3292. ], function () {
  3293. function countResults (data) {
  3294. var count = 0;
  3295. for (var d = 0; d < data.length; d++) {
  3296. var item = data[d];
  3297. if (item.children) {
  3298. count += countResults(item.children);
  3299. } else {
  3300. count++;
  3301. }
  3302. }
  3303. return count;
  3304. }
  3305. function MinimumResultsForSearch (decorated, $element, options, dataAdapter) {
  3306. this.minimumResultsForSearch = options.get('minimumResultsForSearch');
  3307. if (this.minimumResultsForSearch < 0) {
  3308. this.minimumResultsForSearch = Infinity;
  3309. }
  3310. decorated.call(this, $element, options, dataAdapter);
  3311. }
  3312. MinimumResultsForSearch.prototype.showSearch = function (decorated, params) {
  3313. if (countResults(params.data.results) < this.minimumResultsForSearch) {
  3314. return false;
  3315. }
  3316. return decorated.call(this, params);
  3317. };
  3318. return MinimumResultsForSearch;
  3319. });
  3320. S2.define('select2/dropdown/selectOnClose',[
  3321. ], function () {
  3322. function SelectOnClose () { }
  3323. SelectOnClose.prototype.bind = function (decorated, container, $container) {
  3324. var self = this;
  3325. decorated.call(this, container, $container);
  3326. container.on('close', function () {
  3327. self._handleSelectOnClose();
  3328. });
  3329. };
  3330. SelectOnClose.prototype._handleSelectOnClose = function () {
  3331. var $highlightedResults = this.getHighlightedResults();
  3332. if ($highlightedResults.length < 1) {
  3333. return;
  3334. }
  3335. $highlightedResults.trigger('mouseup');
  3336. };
  3337. return SelectOnClose;
  3338. });
  3339. S2.define('select2/dropdown/closeOnSelect',[
  3340. ], function () {
  3341. function CloseOnSelect () { }
  3342. CloseOnSelect.prototype.bind = function (decorated, container, $container) {
  3343. var self = this;
  3344. decorated.call(this, container, $container);
  3345. container.on('select', function (evt) {
  3346. self._selectTriggered(evt);
  3347. });
  3348. container.on('unselect', function (evt) {
  3349. self._selectTriggered(evt);
  3350. });
  3351. };
  3352. CloseOnSelect.prototype._selectTriggered = function (_, evt) {
  3353. var originalEvent = evt.originalEvent;
  3354. // Don't close if the control key is being held
  3355. if (originalEvent && originalEvent.ctrlKey) {
  3356. return;
  3357. }
  3358. this.trigger('close');
  3359. };
  3360. return CloseOnSelect;
  3361. });
  3362. S2.define('select2/i18n/en',[],function () {
  3363. // English
  3364. return {
  3365. errorLoading: function () {
  3366. return 'The results could not be loaded.';
  3367. },
  3368. inputTooLong: function (args) {
  3369. var overChars = args.input.length - args.maximum;
  3370. var message = 'Please delete ' + overChars + ' character';
  3371. if (overChars != 1) {
  3372. message += 's';
  3373. }
  3374. return message;
  3375. },
  3376. inputTooShort: function (args) {
  3377. var remainingChars = args.minimum - args.input.length;
  3378. var message = 'Please enter ' + remainingChars + ' or more characters';
  3379. return message;
  3380. },
  3381. loadingMore: function () {
  3382. return 'Loading more results…';
  3383. },
  3384. maximumSelected: function (args) {
  3385. var message = 'You can only select ' + args.maximum + ' item';
  3386. if (args.maximum != 1) {
  3387. message += 's';
  3388. }
  3389. return message;
  3390. },
  3391. noResults: function () {
  3392. return 'No results found';
  3393. },
  3394. searching: function () {
  3395. return 'Searching…';
  3396. }
  3397. };
  3398. });
  3399. S2.define('select2/defaults',[
  3400. 'jquery',
  3401. 'require',
  3402. './results',
  3403. './selection/single',
  3404. './selection/multiple',
  3405. './selection/placeholder',
  3406. './selection/allowClear',
  3407. './selection/search',
  3408. './selection/eventRelay',
  3409. './utils',
  3410. './translation',
  3411. './diacritics',
  3412. './data/select',
  3413. './data/array',
  3414. './data/ajax',
  3415. './data/tags',
  3416. './data/tokenizer',
  3417. './data/minimumInputLength',
  3418. './data/maximumInputLength',
  3419. './data/maximumSelectionLength',
  3420. './dropdown',
  3421. './dropdown/search',
  3422. './dropdown/hidePlaceholder',
  3423. './dropdown/infiniteScroll',
  3424. './dropdown/attachBody',
  3425. './dropdown/minimumResultsForSearch',
  3426. './dropdown/selectOnClose',
  3427. './dropdown/closeOnSelect',
  3428. './i18n/en'
  3429. ], function ($, require,
  3430. ResultsList,
  3431. SingleSelection, MultipleSelection, Placeholder, AllowClear,
  3432. SelectionSearch, EventRelay,
  3433. Utils, Translation, DIACRITICS,
  3434. SelectData, ArrayData, AjaxData, Tags, Tokenizer,
  3435. MinimumInputLength, MaximumInputLength, MaximumSelectionLength,
  3436. Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
  3437. AttachBody, MinimumResultsForSearch, SelectOnClose, CloseOnSelect,
  3438. EnglishTranslation) {
  3439. function Defaults () {
  3440. this.reset();
  3441. }
  3442. Defaults.prototype.apply = function (options) {
  3443. options = $.extend({}, this.defaults, options);
  3444. if (options.dataAdapter == null) {
  3445. if (options.ajax != null) {
  3446. options.dataAdapter = AjaxData;
  3447. } else if (options.data != null) {
  3448. options.dataAdapter = ArrayData;
  3449. } else {
  3450. options.dataAdapter = SelectData;
  3451. }
  3452. if (options.minimumInputLength > 0) {
  3453. options.dataAdapter = Utils.Decorate(
  3454. options.dataAdapter,
  3455. MinimumInputLength
  3456. );
  3457. }
  3458. if (options.maximumInputLength > 0) {
  3459. options.dataAdapter = Utils.Decorate(
  3460. options.dataAdapter,
  3461. MaximumInputLength
  3462. );
  3463. }
  3464. if (options.maximumSelectionLength > 0) {
  3465. options.dataAdapter = Utils.Decorate(
  3466. options.dataAdapter,
  3467. MaximumSelectionLength
  3468. );
  3469. }
  3470. if (options.tags) {
  3471. options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
  3472. }
  3473. if (options.tokenSeparators != null || options.tokenizer != null) {
  3474. options.dataAdapter = Utils.Decorate(
  3475. options.dataAdapter,
  3476. Tokenizer
  3477. );
  3478. }
  3479. if (options.query != null) {
  3480. var Query = require(options.amdBase + 'compat/query');
  3481. options.dataAdapter = Utils.Decorate(
  3482. options.dataAdapter,
  3483. Query
  3484. );
  3485. }
  3486. if (options.initSelection != null) {
  3487. var InitSelection = require(options.amdBase + 'compat/initSelection');
  3488. options.dataAdapter = Utils.Decorate(
  3489. options.dataAdapter,
  3490. InitSelection
  3491. );
  3492. }
  3493. }
  3494. if (options.resultsAdapter == null) {
  3495. options.resultsAdapter = ResultsList;
  3496. if (options.ajax != null) {
  3497. options.resultsAdapter = Utils.Decorate(
  3498. options.resultsAdapter,
  3499. InfiniteScroll
  3500. );
  3501. }
  3502. if (options.placeholder != null) {
  3503. options.resultsAdapter = Utils.Decorate(
  3504. options.resultsAdapter,
  3505. HidePlaceholder
  3506. );
  3507. }
  3508. if (options.selectOnClose) {
  3509. options.resultsAdapter = Utils.Decorate(
  3510. options.resultsAdapter,
  3511. SelectOnClose
  3512. );
  3513. }
  3514. }
  3515. if (options.dropdownAdapter == null) {
  3516. if (options.multiple) {
  3517. options.dropdownAdapter = Dropdown;
  3518. } else {
  3519. var SearchableDropdown = Utils.Decorate(Dropdown, DropdownSearch);
  3520. options.dropdownAdapter = SearchableDropdown;
  3521. }
  3522. if (options.minimumResultsForSearch !== 0) {
  3523. options.dropdownAdapter = Utils.Decorate(
  3524. options.dropdownAdapter,
  3525. MinimumResultsForSearch
  3526. );
  3527. }
  3528. if (options.closeOnSelect) {
  3529. options.dropdownAdapter = Utils.Decorate(
  3530. options.dropdownAdapter,
  3531. CloseOnSelect
  3532. );
  3533. }
  3534. options.dropdownAdapter = Utils.Decorate(
  3535. options.dropdownAdapter,
  3536. AttachBody
  3537. );
  3538. }
  3539. if (options.selectionAdapter == null) {
  3540. if (options.multiple) {
  3541. options.selectionAdapter = MultipleSelection;
  3542. } else {
  3543. options.selectionAdapter = SingleSelection;
  3544. }
  3545. // Add the placeholder mixin if a placeholder was specified
  3546. if (options.placeholder != null) {
  3547. options.selectionAdapter = Utils.Decorate(
  3548. options.selectionAdapter,
  3549. Placeholder
  3550. );
  3551. }
  3552. if (options.allowClear) {
  3553. options.selectionAdapter = Utils.Decorate(
  3554. options.selectionAdapter,
  3555. AllowClear
  3556. );
  3557. }
  3558. if (options.multiple) {
  3559. options.selectionAdapter = Utils.Decorate(
  3560. options.selectionAdapter,
  3561. SelectionSearch
  3562. );
  3563. }
  3564. options.selectionAdapter = Utils.Decorate(
  3565. options.selectionAdapter,
  3566. EventRelay
  3567. );
  3568. }
  3569. if (typeof options.language === 'string') {
  3570. // Check if the language is specified with a region
  3571. if (options.language.indexOf('-') > 0) {
  3572. // Extract the region information if it is included
  3573. var languageParts = options.language.split('-');
  3574. var baseLanguage = languageParts[0];
  3575. options.language = [options.language, baseLanguage];
  3576. } else {
  3577. options.language = [options.language];
  3578. }
  3579. }
  3580. if ($.isArray(options.language)) {
  3581. var languages = new Translation();
  3582. options.language.push('en');
  3583. var languageNames = options.language;
  3584. for (var l = 0; l < languageNames.length; l++) {
  3585. var name = languageNames[l];
  3586. var language = {};
  3587. try {
  3588. // Try to load it with the original name
  3589. language = Translation.loadPath(name);
  3590. } catch (e) {
  3591. try {
  3592. // If we couldn't load it, check if it wasn't the full path
  3593. name = this.defaults.amdLanguageBase + name;
  3594. language = Translation.loadPath(name);
  3595. } catch (ex) {
  3596. // The translation could not be loaded at all. Sometimes this is
  3597. // because of a configuration problem, other times this can be
  3598. // because of how Select2 helps load all possible translation files.
  3599. if (options.debug && window.console && console.warn) {
  3600. console.warn(
  3601. 'Select2: The language file for "' + name + '" could not be ' +
  3602. 'automatically loaded. A fallback will be used instead.'
  3603. );
  3604. }
  3605. continue;
  3606. }
  3607. }
  3608. languages.extend(language);
  3609. }
  3610. options.translations = languages;
  3611. } else {
  3612. options.translations = new Translation(options.language);
  3613. }
  3614. return options;
  3615. };
  3616. Defaults.prototype.reset = function () {
  3617. function stripDiacritics (text) {
  3618. // Used 'uni range + named function' from http://jsperf.com/diacritics/18
  3619. function match(a) {
  3620. return DIACRITICS[a] || a;
  3621. }
  3622. return text.replace(/[^\u0000-\u007E]/g, match);
  3623. }
  3624. function matcher (params, data) {
  3625. // Always return the object if there is nothing to compare
  3626. if ($.trim(params.term) === '') {
  3627. return data;
  3628. }
  3629. // Do a recursive check for options with children
  3630. if (data.children && data.children.length > 0) {
  3631. // Clone the data object if there are children
  3632. // This is required as we modify the object to remove any non-matches
  3633. var match = $.extend(true, {}, data);
  3634. // Check each child of the option
  3635. for (var c = data.children.length - 1; c >= 0; c--) {
  3636. var child = data.children[c];
  3637. var matches = matcher(params, child);
  3638. // If there wasn't a match, remove the object in the array
  3639. if (matches == null) {
  3640. match.children.splice(c, 1);
  3641. }
  3642. }
  3643. // If any children matched, return the new object
  3644. if (match.children.length > 0) {
  3645. return match;
  3646. }
  3647. // If there were no matching children, check just the plain object
  3648. return matcher(params, match);
  3649. }
  3650. var original = stripDiacritics(data.text).toUpperCase();
  3651. var term = stripDiacritics(params.term).toUpperCase();
  3652. // Check if the text contains the term
  3653. if (original.indexOf(term) > -1) {
  3654. return data;
  3655. }
  3656. // If it doesn't contain the term, don't return anything
  3657. return null;
  3658. }
  3659. this.defaults = {
  3660. amdBase: './',
  3661. amdLanguageBase: './i18n/',
  3662. closeOnSelect: true,
  3663. debug: false,
  3664. escapeMarkup: Utils.escapeMarkup,
  3665. language: EnglishTranslation,
  3666. matcher: matcher,
  3667. minimumInputLength: 0,
  3668. maximumInputLength: 0,
  3669. maximumSelectionLength: 0,
  3670. minimumResultsForSearch: 0,
  3671. selectOnClose: false,
  3672. sorter: function (data) {
  3673. return data;
  3674. },
  3675. templateResult: function (result) {
  3676. return result.text;
  3677. },
  3678. templateSelection: function (selection) {
  3679. return selection.text;
  3680. },
  3681. theme: 'default',
  3682. width: 'resolve'
  3683. };
  3684. };
  3685. Defaults.prototype.set = function (key, value) {
  3686. var camelKey = $.camelCase(key);
  3687. var data = {};
  3688. data[camelKey] = value;
  3689. var convertedData = Utils._convertData(data);
  3690. $.extend(this.defaults, convertedData);
  3691. };
  3692. var defaults = new Defaults();
  3693. return defaults;
  3694. });
  3695. S2.define('select2/options',[
  3696. 'jquery',
  3697. './defaults',
  3698. './utils'
  3699. ], function ($, Defaults, Utils) {
  3700. function Options (options, $element) {
  3701. this.options = options;
  3702. if ($element != null) {
  3703. this.fromElement($element);
  3704. }
  3705. this.options = Defaults.apply(this.options);
  3706. if ($element && $element.is('input')) {
  3707. var InputCompat = require(this.get('amdBase') + 'compat/inputData');
  3708. this.options.dataAdapter = Utils.Decorate(
  3709. this.options.dataAdapter,
  3710. InputCompat
  3711. );
  3712. }
  3713. }
  3714. Options.prototype.fromElement = function ($e) {
  3715. var excludedData = ['select2'];
  3716. if (this.options.multiple == null) {
  3717. this.options.multiple = $e.prop('multiple');
  3718. }
  3719. if (this.options.disabled == null) {
  3720. this.options.disabled = $e.prop('disabled');
  3721. }
  3722. if (this.options.language == null) {
  3723. if ($e.prop('lang')) {
  3724. this.options.language = $e.prop('lang').toLowerCase();
  3725. } else if ($e.closest('[lang]').prop('lang')) {
  3726. this.options.language = $e.closest('[lang]').prop('lang');
  3727. }
  3728. }
  3729. if (this.options.dir == null) {
  3730. if ($e.prop('dir')) {
  3731. this.options.dir = $e.prop('dir');
  3732. } else if ($e.closest('[dir]').prop('dir')) {
  3733. this.options.dir = $e.closest('[dir]').prop('dir');
  3734. } else {
  3735. this.options.dir = 'ltr';
  3736. }
  3737. }
  3738. $e.prop('disabled', this.options.disabled);
  3739. $e.prop('multiple', this.options.multiple);
  3740. if ($e.data('select2Tags')) {
  3741. if (this.options.debug && window.console && console.warn) {
  3742. console.warn(
  3743. 'Select2: The `data-select2-tags` attribute has been changed to ' +
  3744. 'use the `data-data` and `data-tags="true"` attributes and will be ' +
  3745. 'removed in future versions of Select2.'
  3746. );
  3747. }
  3748. $e.data('data', $e.data('select2Tags'));
  3749. $e.data('tags', true);
  3750. }
  3751. if ($e.data('ajaxUrl')) {
  3752. if (this.options.debug && window.console && console.warn) {
  3753. console.warn(
  3754. 'Select2: The `data-ajax-url` attribute has been changed to ' +
  3755. '`data-ajax--url` and support for the old attribute will be removed' +
  3756. ' in future versions of Select2.'
  3757. );
  3758. }
  3759. $e.attr('ajax--url', $e.data('ajaxUrl'));
  3760. $e.data('ajax--url', $e.data('ajaxUrl'));
  3761. }
  3762. var dataset = {};
  3763. // Prefer the element's `dataset` attribute if it exists
  3764. // jQuery 1.x does not correctly handle data attributes with multiple dashes
  3765. if ($.fn.jquery && $.fn.jquery.substr(0, 2) == '1.' && $e[0].dataset) {
  3766. dataset = $.extend(true, {}, $e[0].dataset, $e.data());
  3767. } else {
  3768. dataset = $e.data();
  3769. }
  3770. var data = $.extend(true, {}, dataset);
  3771. data = Utils._convertData(data);
  3772. for (var key in data) {
  3773. if ($.inArray(key, excludedData) > -1) {
  3774. continue;
  3775. }
  3776. if ($.isPlainObject(this.options[key])) {
  3777. $.extend(this.options[key], data[key]);
  3778. } else {
  3779. this.options[key] = data[key];
  3780. }
  3781. }
  3782. return this;
  3783. };
  3784. Options.prototype.get = function (key) {
  3785. return this.options[key];
  3786. };
  3787. Options.prototype.set = function (key, val) {
  3788. this.options[key] = val;
  3789. };
  3790. return Options;
  3791. });
  3792. S2.define('select2/core',[
  3793. 'jquery',
  3794. './options',
  3795. './utils',
  3796. './keys'
  3797. ], function ($, Options, Utils, KEYS) {
  3798. var Select2 = function ($element, options) {
  3799. if ($element.data('select2') != null) {
  3800. $element.data('select2').destroy();
  3801. }
  3802. this.$element = $element;
  3803. this.id = this._generateId($element);
  3804. options = options || {};
  3805. this.options = new Options(options, $element);
  3806. Select2.__super__.constructor.call(this);
  3807. // Set up the tabindex
  3808. var tabindex = $element.attr('tabindex') || 0;
  3809. $element.data('old-tabindex', tabindex);
  3810. $element.attr('tabindex', '-1');
  3811. // Set up containers and adapters
  3812. var DataAdapter = this.options.get('dataAdapter');
  3813. this.dataAdapter = new DataAdapter($element, this.options);
  3814. var $container = this.render();
  3815. this._placeContainer($container);
  3816. var SelectionAdapter = this.options.get('selectionAdapter');
  3817. this.selection = new SelectionAdapter($element, this.options);
  3818. this.$selection = this.selection.render();
  3819. this.selection.position(this.$selection, $container);
  3820. var DropdownAdapter = this.options.get('dropdownAdapter');
  3821. this.dropdown = new DropdownAdapter($element, this.options);
  3822. this.$dropdown = this.dropdown.render();
  3823. this.dropdown.position(this.$dropdown, $container);
  3824. var ResultsAdapter = this.options.get('resultsAdapter');
  3825. this.results = new ResultsAdapter($element, this.options, this.dataAdapter);
  3826. this.$results = this.results.render();
  3827. this.results.position(this.$results, this.$dropdown);
  3828. // Bind events
  3829. var self = this;
  3830. // Bind the container to all of the adapters
  3831. this._bindAdapters();
  3832. // Register any DOM event handlers
  3833. this._registerDomEvents();
  3834. // Register any internal event handlers
  3835. this._registerDataEvents();
  3836. this._registerSelectionEvents();
  3837. this._registerDropdownEvents();
  3838. this._registerResultsEvents();
  3839. this._registerEvents();
  3840. // Set the initial state
  3841. this.dataAdapter.current(function (initialData) {
  3842. self.trigger('selection:update', {
  3843. data: initialData
  3844. });
  3845. });
  3846. // Hide the original select
  3847. $element.hide();
  3848. // Synchronize any monitored attributes
  3849. this._syncAttributes();
  3850. $element.data('select2', this);
  3851. };
  3852. Utils.Extend(Select2, Utils.Observable);
  3853. Select2.prototype._generateId = function ($element) {
  3854. var id = '';
  3855. if ($element.attr('id') != null) {
  3856. id = $element.attr('id');
  3857. } else if ($element.attr('name') != null) {
  3858. id = $element.attr('name') + '-' + Utils.generateChars(2);
  3859. } else {
  3860. id = Utils.generateChars(4);
  3861. }
  3862. id = 'select2-' + id;
  3863. return id;
  3864. };
  3865. Select2.prototype._placeContainer = function ($container) {
  3866. $container.insertAfter(this.$element);
  3867. var width = this._resolveWidth(this.$element, this.options.get('width'));
  3868. if (width != null) {
  3869. $container.css('width', width);
  3870. }
  3871. };
  3872. Select2.prototype._resolveWidth = function ($element, method) {
  3873. var WIDTH = /^width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/i;
  3874. if (method == 'resolve') {
  3875. var styleWidth = this._resolveWidth($element, 'style');
  3876. if (styleWidth != null) {
  3877. return styleWidth;
  3878. }
  3879. return this._resolveWidth($element, 'element');
  3880. }
  3881. if (method == 'element') {
  3882. var elementWidth = $element.outerWidth(false);
  3883. if (elementWidth <= 0) {
  3884. return 'auto';
  3885. }
  3886. return elementWidth + 'px';
  3887. }
  3888. if (method == 'style') {
  3889. var style = $element.attr('style');
  3890. if (typeof(style) !== 'string') {
  3891. return null;
  3892. }
  3893. var attrs = style.split(';');
  3894. for (var i = 0, l = attrs.length; i < l; i = i + 1) {
  3895. var attr = attrs[i].replace(/\s/g, '');
  3896. var matches = attr.match(WIDTH);
  3897. if (matches !== null && matches.length >= 1) {
  3898. return matches[1];
  3899. }
  3900. }
  3901. return null;
  3902. }
  3903. return method;
  3904. };
  3905. Select2.prototype._bindAdapters = function () {
  3906. this.dataAdapter.bind(this, this.$container);
  3907. this.selection.bind(this, this.$container);
  3908. this.dropdown.bind(this, this.$container);
  3909. this.results.bind(this, this.$container);
  3910. };
  3911. Select2.prototype._registerDomEvents = function () {
  3912. var self = this;
  3913. this.$element.on('change.select2', function () {
  3914. self.dataAdapter.current(function (data) {
  3915. self.trigger('selection:update', {
  3916. data: data
  3917. });
  3918. });
  3919. });
  3920. this._sync = Utils.bind(this._syncAttributes, this);
  3921. if (this.$element[0].attachEvent) {
  3922. this.$element[0].attachEvent('onpropertychange', this._sync);
  3923. }
  3924. var observer = window.MutationObserver ||
  3925. window.WebKitMutationObserver ||
  3926. window.MozMutationObserver
  3927. ;
  3928. if (observer != null) {
  3929. this._observer = new observer(function (mutations) {
  3930. $.each(mutations, self._sync);
  3931. });
  3932. this._observer.observe(this.$element[0], {
  3933. attributes: true,
  3934. subtree: false
  3935. });
  3936. } else if (this.$element[0].addEventListener) {
  3937. this.$element[0].addEventListener('DOMAttrModified', self._sync, false);
  3938. }
  3939. };
  3940. Select2.prototype._registerDataEvents = function () {
  3941. var self = this;
  3942. this.dataAdapter.on('*', function (name, params) {
  3943. self.trigger(name, params);
  3944. });
  3945. };
  3946. Select2.prototype._registerSelectionEvents = function () {
  3947. var self = this;
  3948. var nonRelayEvents = ['toggle'];
  3949. this.selection.on('toggle', function () {
  3950. self.toggleDropdown();
  3951. });
  3952. this.selection.on('*', function (name, params) {
  3953. if ($.inArray(name, nonRelayEvents) !== -1) {
  3954. return;
  3955. }
  3956. self.trigger(name, params);
  3957. });
  3958. };
  3959. Select2.prototype._registerDropdownEvents = function () {
  3960. var self = this;
  3961. this.dropdown.on('*', function (name, params) {
  3962. self.trigger(name, params);
  3963. });
  3964. };
  3965. Select2.prototype._registerResultsEvents = function () {
  3966. var self = this;
  3967. this.results.on('*', function (name, params) {
  3968. self.trigger(name, params);
  3969. });
  3970. };
  3971. Select2.prototype._registerEvents = function () {
  3972. var self = this;
  3973. this.on('open', function () {
  3974. self.$container.addClass('select2-container--open');
  3975. });
  3976. this.on('close', function () {
  3977. self.$container.removeClass('select2-container--open');
  3978. });
  3979. this.on('enable', function () {
  3980. self.$container.removeClass('select2-container--disabled');
  3981. });
  3982. this.on('disable', function () {
  3983. self.$container.addClass('select2-container--disabled');
  3984. });
  3985. this.on('focus', function () {
  3986. self.$container.addClass('select2-container--focus');
  3987. });
  3988. this.on('blur', function () {
  3989. self.$container.removeClass('select2-container--focus');
  3990. });
  3991. this.on('query', function (params) {
  3992. if (!self.isOpen()) {
  3993. self.trigger('open');
  3994. }
  3995. this.dataAdapter.query(params, function (data) {
  3996. self.trigger('results:all', {
  3997. data: data,
  3998. query: params
  3999. });
  4000. });
  4001. });
  4002. this.on('query:append', function (params) {
  4003. this.dataAdapter.query(params, function (data) {
  4004. self.trigger('results:append', {
  4005. data: data,
  4006. query: params
  4007. });
  4008. });
  4009. });
  4010. this.on('keypress', function (evt) {
  4011. var key = evt.which;
  4012. if (self.isOpen()) {
  4013. if (key === KEYS.ENTER) {
  4014. self.trigger('results:select');
  4015. evt.preventDefault();
  4016. } else if ((key === KEYS.SPACE && evt.ctrlKey)) {
  4017. self.trigger('results:toggle');
  4018. evt.preventDefault();
  4019. } else if (key === KEYS.UP) {
  4020. self.trigger('results:previous');
  4021. evt.preventDefault();
  4022. } else if (key === KEYS.DOWN) {
  4023. self.trigger('results:next');
  4024. evt.preventDefault();
  4025. } else if (key === KEYS.ESC || key === KEYS.TAB) {
  4026. self.close();
  4027. evt.preventDefault();
  4028. }
  4029. } else {
  4030. if (key === KEYS.ENTER || key === KEYS.SPACE ||
  4031. ((key === KEYS.DOWN || key === KEYS.UP) && evt.altKey)) {
  4032. self.open();
  4033. evt.preventDefault();
  4034. }
  4035. }
  4036. });
  4037. };
  4038. Select2.prototype._syncAttributes = function () {
  4039. this.options.set('disabled', this.$element.prop('disabled'));
  4040. if (this.options.get('disabled')) {
  4041. if (this.isOpen()) {
  4042. this.close();
  4043. }
  4044. this.trigger('disable');
  4045. } else {
  4046. this.trigger('enable');
  4047. }
  4048. };
  4049. /**
  4050. * Override the trigger method to automatically trigger pre-events when
  4051. * there are events that can be prevented.
  4052. */
  4053. Select2.prototype.trigger = function (name, args) {
  4054. var actualTrigger = Select2.__super__.trigger;
  4055. var preTriggerMap = {
  4056. 'open': 'opening',
  4057. 'close': 'closing',
  4058. 'select': 'selecting',
  4059. 'unselect': 'unselecting'
  4060. };
  4061. if (name in preTriggerMap) {
  4062. var preTriggerName = preTriggerMap[name];
  4063. var preTriggerArgs = {
  4064. prevented: false,
  4065. name: name,
  4066. args: args
  4067. };
  4068. actualTrigger.call(this, preTriggerName, preTriggerArgs);
  4069. if (preTriggerArgs.prevented) {
  4070. args.prevented = true;
  4071. return;
  4072. }
  4073. }
  4074. actualTrigger.call(this, name, args);
  4075. };
  4076. Select2.prototype.toggleDropdown = function () {
  4077. if (this.options.get('disabled')) {
  4078. return;
  4079. }
  4080. if (this.isOpen()) {
  4081. this.close();
  4082. } else {
  4083. this.open();
  4084. }
  4085. };
  4086. Select2.prototype.open = function () {
  4087. if (this.isOpen()) {
  4088. return;
  4089. }
  4090. this.trigger('query', {});
  4091. this.trigger('open');
  4092. };
  4093. Select2.prototype.close = function () {
  4094. if (!this.isOpen()) {
  4095. return;
  4096. }
  4097. this.trigger('close');
  4098. };
  4099. Select2.prototype.isOpen = function () {
  4100. return this.$container.hasClass('select2-container--open');
  4101. };
  4102. Select2.prototype.enable = function (args) {
  4103. if (this.options.get('debug') && window.console && console.warn) {
  4104. console.warn(
  4105. 'Select2: The `select2("enable")` method has been deprecated and will' +
  4106. ' be removed in later Select2 versions. Use $element.prop("disabled")' +
  4107. ' instead.'
  4108. );
  4109. }
  4110. if (args == null || args.length === 0) {
  4111. args = [true];
  4112. }
  4113. var disabled = !args[0];
  4114. this.$element.prop('disabled', disabled);
  4115. };
  4116. Select2.prototype.data = function () {
  4117. if (this.options.get('debug') &&
  4118. arguments.length > 0 && window.console && console.warn) {
  4119. console.warn(
  4120. 'Select2: Data can no longer be set using `select2("data")`. You ' +
  4121. 'should consider setting the value instead using `$element.val()`.'
  4122. );
  4123. }
  4124. var data = [];
  4125. this.dataAdapter.current(function (currentData) {
  4126. data = currentData;
  4127. });
  4128. return data;
  4129. };
  4130. Select2.prototype.val = function (args) {
  4131. if (this.options.get('debug') && window.console && console.warn) {
  4132. console.warn(
  4133. 'Select2: The `select2("val")` method has been deprecated and will be' +
  4134. ' removed in later Select2 versions. Use $element.val() instead.'
  4135. );
  4136. }
  4137. if (args == null || args.length === 0) {
  4138. return this.$element.val();
  4139. }
  4140. var newVal = args[0];
  4141. if ($.isArray(newVal)) {
  4142. newVal = $.map(newVal, function (obj) {
  4143. return obj.toString();
  4144. });
  4145. }
  4146. this.$element.val(newVal).trigger('change');
  4147. };
  4148. Select2.prototype.destroy = function () {
  4149. this.$container.remove();
  4150. if (this.$element[0].detachEvent) {
  4151. this.$element[0].detachEvent('onpropertychange', this._sync);
  4152. }
  4153. if (this._observer != null) {
  4154. this._observer.disconnect();
  4155. this._observer = null;
  4156. } else if (this.$element[0].removeEventListener) {
  4157. this.$element[0]
  4158. .removeEventListener('DOMAttrModified', this._sync, false);
  4159. }
  4160. this._sync = null;
  4161. this.$element.off('.select2');
  4162. this.$element.attr('tabindex', this.$element.data('old-tabindex'));
  4163. this.$element.show();
  4164. this.$element.removeData('select2');
  4165. this.dataAdapter.destroy();
  4166. this.selection.destroy();
  4167. this.dropdown.destroy();
  4168. this.results.destroy();
  4169. this.dataAdapter = null;
  4170. this.selection = null;
  4171. this.dropdown = null;
  4172. this.results = null;
  4173. };
  4174. Select2.prototype.render = function () {
  4175. var $container = $(
  4176. '<span class="select2 select2-container">' +
  4177. '<span class="selection"></span>' +
  4178. '<span class="dropdown-wrapper" aria-hidden="true"></span>' +
  4179. '</span>'
  4180. );
  4181. $container.attr('dir', this.options.get('dir'));
  4182. this.$container = $container;
  4183. this.$container.addClass('select2-container--' + this.options.get('theme'));
  4184. $container.data('element', this.$element);
  4185. return $container;
  4186. };
  4187. return Select2;
  4188. });
  4189. S2.define('jquery.select2',[
  4190. 'jquery',
  4191. './select2/core',
  4192. './select2/defaults'
  4193. ], function ($, Select2, Defaults) {
  4194. // Force jQuery.mousewheel to be loaded if it hasn't already
  4195. try {
  4196. require('jquery.mousewheel');
  4197. } catch (Exception) { }
  4198. if ($.fn.select2 == null) {
  4199. $.fn.select2 = function (options) {
  4200. options = options || {};
  4201. if (typeof options === 'object') {
  4202. this.each(function () {
  4203. var instanceOptions = $.extend({}, options, true);
  4204. var instance = new Select2($(this), instanceOptions);
  4205. });
  4206. return this;
  4207. } else if (typeof options === 'string') {
  4208. var instance = this.data('select2');
  4209. var args = Array.prototype.slice.call(arguments, 1);
  4210. return instance[options](args);
  4211. } else {
  4212. throw new Error('Invalid arguments for Select2: ' + options);
  4213. }
  4214. };
  4215. }
  4216. if ($.fn.select2.defaults == null) {
  4217. $.fn.select2.defaults = Defaults;
  4218. }
  4219. return Select2;
  4220. });
  4221. // Return the AMD loader configuration so it can be used outside of this file
  4222. return {
  4223. define: S2.define,
  4224. require: S2.require
  4225. };
  4226. }());
  4227. // Autoload the jQuery bindings
  4228. // We know that all of the modules exist above this, so we're safe
  4229. var select2 = S2.require('jquery.select2');
  4230. // Hold the AMD module references on the jQuery function that was just loaded
  4231. // This allows Select2 to use the internal loader outside of this file, such
  4232. // as in the language files.
  4233. $.fn.select2.amd = S2;
  4234. // Return the Select2 instance for anyone who is importing it.
  4235. return select2;
  4236. }));