select2.js 134 KB

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