select2.js 132 KB

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