select2.js 139 KB

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