select2.js 133 KB

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