select2.js 139 KB

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