select2.js 139 KB

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