No Description

admin-general.js 330KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791
  1. /********************************************
  2. * Copyright (c) 2020, Code Atlantic LLC
  3. ********************************************/
  4. (function($) {
  5. /**
  6. * Changes the current enabled state of supplied popup
  7. *
  8. * @param {number} popupID The ID for the popup.
  9. * @param {number} enabledState 1 for active, 0 for inactive.
  10. * @param {string} nonce The nonce for the action.
  11. */
  12. function changeEnabledState(popupID, enabledState, nonce) {
  13. $.ajax({
  14. type: "POST",
  15. dataType: "json",
  16. // eslint-disable-next-line no-undef
  17. url: ajaxurl,
  18. data: {
  19. action: "pum_save_enabled_state",
  20. nonce: nonce,
  21. popupID: popupID,
  22. enabled: enabledState
  23. }
  24. });
  25. }
  26. $(function() {
  27. $(".pum-enabled-toggle-button").on("change", function(e) {
  28. e.preventDefault();
  29. var $button = $(this);
  30. var newState = 0;
  31. if (true === e.target.checked) {
  32. newState = 1;
  33. }
  34. changeEnabledState(
  35. $button.data("popup-id"),
  36. newState,
  37. $button.data("nonce")
  38. );
  39. });
  40. });
  41. })(jQuery);
  42. /*******************************************************************************
  43. * Copyright (c) 2019, Code Atlantic LLC
  44. ******************************************************************************/
  45. (function($) {
  46. "use strict";
  47. var $alerts = $(".pum-alerts"),
  48. $noticeCounts = $(".pum-alert-count"),
  49. count = parseInt($noticeCounts.eq(0).text());
  50. function dismissAlert($alert, alertAction) {
  51. var dismissible = $alert.data("dismissible"),
  52. expires =
  53. dismissible === "1" || dismissible === 1 || dismissible === true
  54. ? null
  55. : dismissible;
  56. $.ajax({
  57. method: "POST",
  58. dataType: "json",
  59. url: ajaxurl,
  60. data: {
  61. action: "pum_alerts_action",
  62. nonce: window.pum_alerts_nonce,
  63. code: $alert.data("code"),
  64. expires: expires,
  65. pum_dismiss_alert: alertAction
  66. }
  67. });
  68. }
  69. function dismissReviewRequest(reason) {
  70. $.ajax({
  71. method: "POST",
  72. dataType: "json",
  73. url: ajaxurl,
  74. data: {
  75. action: "pum_review_action",
  76. nonce: window.pum_review_nonce,
  77. group: window.pum_review_trigger.group,
  78. code: window.pum_review_trigger.code,
  79. pri: window.pum_review_trigger.pri,
  80. reason: reason
  81. }
  82. });
  83. if (typeof window.pum_review_api_url !== "undefined") {
  84. $.ajax({
  85. method: "POST",
  86. dataType: "json",
  87. url: window.pum_review_api_url,
  88. data: {
  89. trigger_group: window.pum_review_trigger.group,
  90. trigger_code: window.pum_review_trigger.code,
  91. reason: reason,
  92. uuid: window.pum_review_uuid || null
  93. }
  94. });
  95. }
  96. }
  97. function checkRemoveAlerts() {
  98. if ($alerts.find(".pum-alert-holder").length === 0) {
  99. $alerts.slideUp(100, function() {
  100. $alerts.remove();
  101. });
  102. $("#menu-posts-popup .wp-menu-name .update-plugins").fadeOut();
  103. }
  104. }
  105. function removeAlert($alert) {
  106. count--;
  107. $noticeCounts.text(count);
  108. $alert.fadeTo(100, 0, function() {
  109. $alert.slideUp(100, function() {
  110. $alert.remove();
  111. checkRemoveAlerts();
  112. });
  113. });
  114. }
  115. $(document)
  116. .on("pumDismissAlert", checkRemoveAlerts)
  117. .on("click", ".pum-alert-holder .pum-dismiss", function(event) {
  118. var $this = $(this),
  119. $alert = $this.parents(".pum-alert-holder"),
  120. reason = $this.data("reason") || "maybe_later",
  121. alertAction = $(this).data("action") || "dismiss";
  122. // Prevent the PHP alert handler from also processing this.
  123. event.preventDefault();
  124. if ("review_request" !== $alert.data("code")) {
  125. dismissAlert($alert, alertAction);
  126. } else {
  127. dismissReviewRequest(reason);
  128. }
  129. removeAlert($alert);
  130. });
  131. })(jQuery);
  132. /*******************************************************************************
  133. * Copyright (c) 2019, Code Atlantic LLC
  134. ******************************************************************************/
  135. (function ($) {
  136. "use strict";
  137. var colorpicker = {
  138. init: function () {
  139. $('.pum-color-picker').filter(':not(.pum-color-picker-initialized)')
  140. .addClass('pum-color-picker-initialized')
  141. .wpColorPicker({
  142. change: function (event, ui) {
  143. $(event.target).trigger('colorchange', ui);
  144. },
  145. clear: function (event) {
  146. $(event.target).prev().trigger('colorchange').wpColorPicker('close');
  147. },
  148. hide: true
  149. });
  150. }
  151. };
  152. // Import this module.
  153. window.PUM_Admin = window.PUM_Admin || {};
  154. window.PUM_Admin.colorpicker = colorpicker;
  155. $(document)
  156. .on('click', '.iris-palette', function () {
  157. $(this).parents('.wp-picker-active').find('input.pum-color-picker').trigger('change');
  158. })
  159. .on('colorchange', function (event, ui) {
  160. var $input = $(event.target),
  161. color = '';
  162. if (ui !== undefined && ui.color !== undefined) {
  163. color = ui.color.toString();
  164. }
  165. $input.val(color).trigger('change');
  166. if ($('form#post input#post_type').val() === 'popup_theme') {
  167. PUM_Admin.utils.debounce(PUM_Admin.themeEditor.refresh_preview, 100);
  168. }
  169. })
  170. .on('pum_init', colorpicker.init);
  171. }(jQuery));
  172. /*******************************************************************************
  173. * Copyright (c) 2019, Code Atlantic LLC
  174. ******************************************************************************/
  175. (function ($) {
  176. "use strict";
  177. var forms = {
  178. init: function () {
  179. forms.checkDependencies();
  180. },
  181. /**
  182. * dependencies should look like this:
  183. *
  184. * {
  185. * field_name_1: value, // Select, radio etc.
  186. * field_name_2: true // Checkbox
  187. * }
  188. *
  189. * Support for Multiple possible values of one field
  190. *
  191. * {
  192. * field_name_1: [ value_1, value_2 ]
  193. * }
  194. *
  195. */
  196. checkDependencies: function ($dependent_fields) {
  197. var _fields = $($dependent_fields);
  198. // If no fields passed, only do those not already initialized.
  199. $dependent_fields = _fields.length ? _fields : $("[data-pum-dependencies]:not([data-pum-processed-dependencies])");
  200. $dependent_fields.each(function () {
  201. var $dependent = $(this),
  202. dependentID = $dependent.data('id'),
  203. // The dependency object for this field.
  204. dependencies = $dependent.data("pum-processed-dependencies") || {},
  205. // Total number of fields this :input is dependent on.
  206. requiredCount = Object.keys(dependencies).length,
  207. // Current count of fields this :input matched properly.
  208. count = 0,
  209. // An array of fields this :input is dependent on.
  210. dependentFields = $dependent.data("pum-dependent-fields"),
  211. // Early declarations.
  212. key;
  213. // Clean up & pre-process dependencies so we don't need to rebuild each time.
  214. if (!$dependent.data("pum-processed-dependencies")) {
  215. dependencies = $dependent.data("pum-dependencies");
  216. if (typeof dependencies === 'string') {
  217. dependencies = JSON.parse(dependencies);
  218. }
  219. // Convert each key to an array of acceptable values.
  220. for (key in dependencies) {
  221. if (dependencies.hasOwnProperty(key)) {
  222. if (typeof dependencies[key] === "string") {
  223. // Leave boolean values alone as they are for checkboxes or checking if an input has any value.
  224. if (dependencies[key].indexOf(',') !== -1) {
  225. dependencies[key] = dependencies[key].split(',');
  226. } else {
  227. dependencies[key] = [dependencies[key]];
  228. }
  229. } else if (typeof dependencies[key] === "number") {
  230. dependencies[key] = [dependencies[key]];
  231. }
  232. }
  233. }
  234. // Update cache & counts.
  235. requiredCount = Object.keys(dependencies).length;
  236. $dependent.data("pum-processed-dependencies", dependencies).attr("data-pum-processed-dependencies", dependencies);
  237. }
  238. if (!dependentFields) {
  239. dependentFields = $.map(dependencies, function (value, index) {
  240. var $wrapper = $('.pum-field[data-id="' + index + '"]');
  241. return $wrapper.length ? $wrapper.eq(0) : null;
  242. });
  243. $dependent.data("pum-dependent-fields", dependentFields);
  244. }
  245. $(dependentFields).each(function () {
  246. var $wrapper = $(this),
  247. $field = $wrapper.find(':input:first'),
  248. id = $wrapper.data("id"),
  249. value = $field.val(),
  250. required = dependencies[id],
  251. matched,
  252. // Used for limiting the fields that get updated when this field is changed.
  253. all_this_fields_dependents = $wrapper.data('pum-field-dependents') || [];
  254. if (all_this_fields_dependents.indexOf(dependentID) === -1) {
  255. all_this_fields_dependents.push(dependentID);
  256. $wrapper.data('pum-field-dependents', all_this_fields_dependents);
  257. }
  258. // If no required values found bail early.
  259. if (typeof required === 'undefined' || required === null) {
  260. $dependent.removeClass('pum-dependencies-met').hide(0).trigger('pumFormDependencyUnmet');
  261. // Effectively breaks the .each for this $dependent and hides it.
  262. return false;
  263. }
  264. if ($wrapper.hasClass('pum-field-radio')) {
  265. value = $wrapper.find(':input:checked').val();
  266. }
  267. if ($wrapper.hasClass('pum-field-multicheck')) {
  268. value = [];
  269. $wrapper.find(':checkbox:checked').each(function (i) {
  270. value[i] = $(this).val();
  271. if (typeof value[i] === 'string' && !isNaN(parseInt(value[i]))) {
  272. value[i] = parseInt(value[i]);
  273. }
  274. });
  275. }
  276. // Check if the value matches required values.
  277. if ($wrapper.hasClass('pum-field-select') || $wrapper.hasClass('pum-field-radio')) {
  278. matched = required && required.indexOf(value) !== -1;
  279. } else if ($wrapper.hasClass('pum-field-checkbox')) {
  280. matched = required === $field.is(':checked');
  281. } else if ($wrapper.hasClass('pum-field-multicheck')) {
  282. if (Array.isArray(required)) {
  283. matched = false;
  284. for (var i = 0; i < required.length; i++) {
  285. if (value.indexOf(required[i]) !== -1) {
  286. matched = true;
  287. }
  288. }
  289. } else {
  290. matched = value.indexOf(required) !== -1;
  291. }
  292. } else {
  293. matched = Array.isArray(required) ? required.indexOf(value) !== -1 : required == value;
  294. }
  295. if (matched) {
  296. count++;
  297. } else {
  298. $dependent.removeClass('pum-dependencies-met').hide(0).trigger('pumFormDependencyUnmet');
  299. // Effectively breaks the .each for this $dependent and hides it.
  300. return false;
  301. }
  302. if (count === requiredCount) {
  303. $dependent.addClass('pum-dependencies-met').show(0).trigger('pumFormDependencyMet');
  304. }
  305. });
  306. });
  307. },
  308. form_check: function () {
  309. $(document).trigger('pum_form_check');
  310. },
  311. is_field: function (data) {
  312. if (typeof data !== 'object') {
  313. return false;
  314. }
  315. var field_tests = [
  316. data.type === undefined && (data.label !== undefined || data.desc !== undefined),
  317. data.type !== undefined && typeof data.type === 'string'
  318. ];
  319. return field_tests.indexOf(true) >= 0;
  320. },
  321. flattenFields: function (data) {
  322. var form_fields = {},
  323. tabs = data.tabs || {},
  324. sections = data.sections || {},
  325. fields = data.fields || {};
  326. if (Object.keys(tabs).length && Object.keys(sections).length) {
  327. // Loop Tabs
  328. _.each(fields, function (subTabs, tabID) {
  329. // If not a valid tab or no subsections skip it.
  330. if (typeof subTabs !== 'object' || !Object.keys(subTabs).length) {
  331. return;
  332. }
  333. // Loop Tab Sections
  334. _.each(subTabs, function (subTabFields, subTabID) {
  335. // If not a valid subtab or no fields skip it.
  336. if (typeof subTabFields !== 'object' || !Object.keys(subTabFields).length) {
  337. return;
  338. }
  339. // Move single fields into the main subtab.
  340. if (forms.is_field(subTabFields)) {
  341. var newSubTabFields = {};
  342. newSubTabFields[subTabID] = subTabFields;
  343. subTabID = 'main';
  344. subTabFields = newSubTabFields;
  345. }
  346. // Loop Tab Section Fields
  347. _.each(subTabFields, function (field) {
  348. // Store the field by id for easy lookup later.
  349. form_fields[field.id] = field;
  350. });
  351. });
  352. });
  353. }
  354. else if (Object.keys(tabs).length) {
  355. // Loop Tabs
  356. _.each(fields, function (tabFields, tabID) {
  357. // If not a valid tab or no subsections skip it.
  358. if (typeof tabFields !== 'object' || !Object.keys(tabFields).length) {
  359. return;
  360. }
  361. // Loop Tab Fields
  362. _.each(tabFields, function (field) {
  363. // Store the field by id for easy lookup later.
  364. form_fields[field.id] = field;
  365. });
  366. });
  367. }
  368. else if (Object.keys(sections).length) {
  369. // Loop Sections
  370. _.each(fields, function (sectionFields, sectionID) {
  371. // Loop Tab Section Fields
  372. _.each(sectionFields, function (field) {
  373. // Store the field by id for easy lookup later.
  374. form_fields[field.id] = field;
  375. });
  376. });
  377. }
  378. else {
  379. fields = forms.parseFields(fields, values);
  380. // Replace the array with rendered fields.
  381. _.each(fields, function (field) {
  382. // Store the field by id for easy lookup later.
  383. form_fields[field.id] = field;
  384. });
  385. }
  386. return form_fields;
  387. },
  388. parseFields: function (fields, values) {
  389. values = values || {};
  390. _.each(fields, function (field, fieldID) {
  391. fields[fieldID] = PUM_Admin.models.field(field);
  392. if (typeof fields[fieldID].meta !== 'object') {
  393. fields[fieldID].meta = {};
  394. }
  395. if (undefined !== values[fieldID]) {
  396. fields[fieldID].value = values[fieldID];
  397. }
  398. if (fields[fieldID].id === '') {
  399. fields[fieldID].id = fieldID;
  400. }
  401. });
  402. return fields;
  403. },
  404. renderTab: function () {
  405. },
  406. renderSection: function () {
  407. },
  408. render: function (args, values, $container) {
  409. var form,
  410. sections = {},
  411. section = [],
  412. form_fields = {},
  413. data = $.extend(true, {
  414. id: "",
  415. tabs: {},
  416. sections: {},
  417. fields: {},
  418. maintabs: {},
  419. subtabs: {}
  420. }, args),
  421. maintabs = $.extend({
  422. id: data.id,
  423. classes: [],
  424. tabs: {},
  425. vertical: true,
  426. form: true,
  427. meta: {
  428. 'data-min-height': 250
  429. }
  430. }, data.maintabs),
  431. subtabs = $.extend({
  432. classes: ['link-tabs', 'sub-tabs'],
  433. tabs: {}
  434. }, data.subtabs),
  435. container_classes = ['pum-dynamic-form'];
  436. values = values || {};
  437. if (Object.keys(data.tabs).length && Object.keys(data.sections).length) {
  438. container_classes.push('tabbed-content');
  439. // Loop Tabs
  440. _.each(data.fields, function (subTabs, tabID) {
  441. // If not a valid tab or no subsections skip it.
  442. if (typeof subTabs !== 'object' || !Object.keys(subTabs).length) {
  443. return;
  444. }
  445. // Define this tab.
  446. if (undefined === maintabs.tabs[tabID]) {
  447. maintabs.tabs[tabID] = {
  448. label: data.tabs[tabID],
  449. content: ''
  450. };
  451. }
  452. // Define the sub tabs model.
  453. subtabs = $.extend(subtabs, {
  454. id: data.id + '-' + tabID + '-subtabs',
  455. tabs: {}
  456. });
  457. // Loop Tab Sections
  458. _.each(subTabs, function (subTabFields, subTabID) {
  459. // If not a valid subtab or no fields skip it.
  460. if (typeof subTabFields !== 'object' || !Object.keys(subTabFields).length) {
  461. return;
  462. }
  463. // Move single fields into the main subtab.
  464. if (forms.is_field(subTabFields)) {
  465. var newSubTabFields = {};
  466. newSubTabFields[subTabID] = subTabFields;
  467. subTabID = 'main';
  468. subTabFields = newSubTabFields;
  469. }
  470. // Define this subtab model.
  471. if (undefined === subtabs.tabs[subTabID]) {
  472. subtabs.tabs[subTabID] = {
  473. label: data.sections[tabID][subTabID],
  474. content: ''
  475. };
  476. }
  477. subTabFields = forms.parseFields(subTabFields, values);
  478. // Loop Tab Section Fields
  479. _.each(subTabFields, function (field) {
  480. // Store the field by id for easy lookup later.
  481. form_fields[field.id] = field;
  482. // Push rendered fields into the subtab content.
  483. subtabs.tabs[subTabID].content += PUM_Admin.templates.field(field);
  484. });
  485. // Remove any empty tabs.
  486. if ("" === subtabs.tabs[subTabID].content) {
  487. delete subtabs.tabs[subTabID];
  488. }
  489. });
  490. // If there are subtabs, then render them into the main tabs content, otherwise remove this main tab.
  491. if (Object.keys(subtabs.tabs).length) {
  492. maintabs.tabs[tabID].content = PUM_Admin.templates.tabs(subtabs);
  493. } else {
  494. delete maintabs.tabs[tabID];
  495. }
  496. });
  497. if (Object.keys(maintabs.tabs).length) {
  498. form = PUM_Admin.templates.tabs(maintabs);
  499. }
  500. } else if (Object.keys(data.tabs).length) {
  501. container_classes.push('tabbed-content');
  502. // Loop Tabs
  503. _.each(data.fields, function (tabFields, tabID) {
  504. // If not a valid tab or no subsections skip it.
  505. if (typeof tabFields !== 'object' || !Object.keys(tabFields).length) {
  506. return;
  507. }
  508. // Define this tab.
  509. if (undefined === maintabs.tabs[tabID]) {
  510. maintabs.tabs[tabID] = {
  511. label: data.tabs[tabID],
  512. content: ''
  513. };
  514. }
  515. section = [];
  516. tabFields = forms.parseFields(tabFields, values);
  517. // Loop Tab Fields
  518. _.each(tabFields, function (field) {
  519. // Store the field by id for easy lookup later.
  520. form_fields[field.id] = field;
  521. // Push rendered fields into the subtab content.
  522. section.push(PUM_Admin.templates.field(field));
  523. });
  524. // Push rendered tab into the tab.
  525. if (section.length) {
  526. // Push rendered sub tabs into the main tabs if not empty.
  527. maintabs.tabs[tabID].content = PUM_Admin.templates.section({
  528. fields: section
  529. });
  530. } else {
  531. delete (maintabs.tabs[tabID]);
  532. }
  533. });
  534. if (Object.keys(maintabs.tabs).length) {
  535. form = PUM_Admin.templates.tabs(maintabs);
  536. }
  537. } else if (Object.keys(data.sections).length) {
  538. // Loop Sections
  539. _.each(data.fields, function (sectionFields, sectionID) {
  540. section = [];
  541. section.push(PUM_Admin.templates.field({
  542. type: 'heading',
  543. desc: data.sections[sectionID] || ''
  544. }));
  545. sectionFields = forms.parseFields(sectionFields, values);
  546. // Loop Tab Section Fields
  547. _.each(sectionFields, function (field) {
  548. // Store the field by id for easy lookup later.
  549. form_fields[field.id] = field;
  550. // Push rendered fields into the section.
  551. section.push(PUM_Admin.templates.field(field));
  552. });
  553. // Push rendered sections into the form.
  554. form += PUM_Admin.templates.section({
  555. fields: section
  556. });
  557. });
  558. } else {
  559. data.fields = forms.parseFields(data.fields, values);
  560. // Replace the array with rendered fields.
  561. _.each(data.fields, function (field) {
  562. // Store the field by id for easy lookup later.
  563. form_fields[field.id] = field;
  564. // Push rendered fields into the section.
  565. section.push(PUM_Admin.templates.field(field));
  566. });
  567. // Render the section.
  568. form = PUM_Admin.templates.section({
  569. fields: section
  570. });
  571. }
  572. if ($container !== undefined && $container.length) {
  573. $container
  574. .addClass(container_classes.join(' '))
  575. .data('form_fields', form_fields)
  576. .html(form)
  577. .trigger('pum_init');
  578. }
  579. return form;
  580. },
  581. parseValues: function (values, fields) {
  582. fields = fields || false;
  583. if (!fields) {
  584. return values;
  585. }
  586. for (var key in fields) {
  587. if (!fields.hasOwnProperty(key)) {
  588. continue;
  589. }
  590. // Measure field value corrections.
  591. if (values.hasOwnProperty(key + "_unit")) {
  592. values[key] += values[key + "_unit"];
  593. delete values[key + "_unit"];
  594. }
  595. // If the value key is empty and a checkbox set it to false. Then return.
  596. if (typeof values[key] === 'undefined') {
  597. if (fields[key].type === 'checkbox') {
  598. values[key] = false;
  599. }
  600. continue;
  601. }
  602. if (fields[key].allow_html && !PUM_Admin.utils.htmlencoder.hasEncoded(values[key])) {
  603. values[key] = PUM_Admin.utils.htmlencoder.htmlEncode(values[key]);
  604. }
  605. }
  606. return values;
  607. }
  608. };
  609. // Import this module.
  610. window.PUM_Admin = window.PUM_Admin || {};
  611. window.PUM_Admin.forms = forms;
  612. $(document)
  613. .on('pum_init pum_form_check', function () {
  614. PUM_Admin.forms.init();
  615. })
  616. .on('pumFieldChanged', '.pum-field', function () {
  617. var $wrapper = $(this),
  618. dependent_field_ids = $wrapper.data('pum-field-dependents') || [],
  619. $fields_with_dependencies = $(),
  620. i;
  621. if (!dependent_field_ids || dependent_field_ids.length <= 0) {
  622. return;
  623. }
  624. for (i = 0; i < dependent_field_ids.length; i++) {
  625. $fields_with_dependencies = $fields_with_dependencies.add('.pum-field[data-id="' + dependent_field_ids[i] + '"]');
  626. }
  627. PUM_Admin.forms.checkDependencies($fields_with_dependencies);
  628. })
  629. .on('pumFieldChanged', '.pum-field-dynamic-desc', function () {
  630. var $this = $(this),
  631. $input = $this.find(':input'),
  632. $container = $this.parents('.pum-dynamic-form:first'),
  633. val = $input.val(),
  634. form_fields = $container.data('form_fields') || {},
  635. field = form_fields[$this.data('id')] || {},
  636. $desc = $this.find('.pum-desc'),
  637. desc = $this.data('pum-dynamic-desc');
  638. switch (field.type) {
  639. case 'radio':
  640. val = $this.find(':input:checked').val();
  641. break;
  642. }
  643. field.value = val;
  644. if (desc && desc.length) {
  645. $desc.html(PUM_Admin.templates.renderInline(desc, field));
  646. }
  647. })
  648. .on('change', '.pum-field-select select', function () {
  649. $(this).parents('.pum-field').trigger('pumFieldChanged');
  650. })
  651. .on('click', '.pum-field-checkbox input', function () {
  652. $(this).parents('.pum-field').trigger('pumFieldChanged');
  653. })
  654. .on('click', '.pum-field-multicheck input', function () {
  655. $(this).parents('.pum-field').trigger('pumFieldChanged');
  656. })
  657. .on('click', '.pum-field-radio input', function (event) {
  658. var $this = $(this),
  659. $selected = $this.parents('li'),
  660. $wrapper = $this.parents('.pum-field');
  661. $wrapper.trigger('pumFieldChanged');
  662. $wrapper.find('li.pum-selected').removeClass('pum-selected');
  663. $selected.addClass('pum-selected');
  664. });
  665. }(jQuery));
  666. function pumSelected(val1, val2, print) {
  667. "use strict";
  668. var selected = false;
  669. if (typeof val1 === 'object' && typeof val2 === 'string' && jQuery.inArray(val2, val1) !== -1) {
  670. selected = true;
  671. } else if (typeof val2 === 'object' && typeof val1 === 'string' && jQuery.inArray(val1, val2) !== -1) {
  672. selected = true;
  673. } else if (val1 === val2) {
  674. selected = true;
  675. }
  676. if (print !== undefined && print) {
  677. return selected ? ' selected="selected"' : '';
  678. }
  679. return selected;
  680. }
  681. function pumChecked(val1, val2, print) {
  682. "use strict";
  683. var checked = false;
  684. if (typeof val1 === 'object' && typeof val2 === 'string' && jQuery.inArray(val2, val1) !== -1) {
  685. checked = true;
  686. } else if (typeof val2 === 'object' && typeof val1 === 'string' && jQuery.inArray(val1, val2) !== -1) {
  687. checked = true;
  688. } else if (val1 === val2) {
  689. checked = true;
  690. }
  691. if (print !== undefined && print) {
  692. return checked ? ' checked="checked"' : '';
  693. }
  694. return checked;
  695. }
  696. /*******************************************************************************
  697. * Copyright (c) 2019, Code Atlantic LLC
  698. ******************************************************************************/
  699. (function ($) {
  700. "use strict";
  701. var $html = $('html'),
  702. $document = $(document),
  703. $top_level_elements,
  704. focusableElementsString = "a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, *[tabindex], *[contenteditable]",
  705. previouslyFocused,
  706. modals = {
  707. _current: null,
  708. // Accessibility: Checks focus events to ensure they stay inside the modal.
  709. forceFocus: function (event) {
  710. if (PUM_Admin.modals._current && !PUM_Admin.modals._current.contains(event.target)) {
  711. event.stopPropagation();
  712. PUM_Admin.modals._current.focus();
  713. }
  714. },
  715. trapEscapeKey: function (e) {
  716. if (e.keyCode === 27) {
  717. PUM_Admin.modals.closeAll();
  718. e.preventDefault();
  719. }
  720. },
  721. trapTabKey: function (e) {
  722. // if tab or shift-tab pressed
  723. if (e.keyCode === 9) {
  724. // get list of focusable items
  725. var focusableItems = PUM_Admin.modals._current.find('*').filter(focusableElementsString).filter(':visible'),
  726. // get currently focused item
  727. focusedItem = $(':focus'),
  728. // get the number of focusable items
  729. numberOfFocusableItems = focusableItems.length,
  730. // get the index of the currently focused item
  731. focusedItemIndex = focusableItems.index(focusedItem);
  732. if (e.shiftKey) {
  733. //back tab
  734. // if focused on first item and user preses back-tab, go to the last focusable item
  735. if (focusedItemIndex === 0) {
  736. focusableItems.get(numberOfFocusableItems - 1).focus();
  737. e.preventDefault();
  738. }
  739. } else {
  740. //forward tab
  741. // if focused on the last item and user preses tab, go to the first focusable item
  742. if (focusedItemIndex === numberOfFocusableItems - 1) {
  743. focusableItems.get(0).focus();
  744. e.preventDefault();
  745. }
  746. }
  747. }
  748. },
  749. setFocusToFirstItem: function () {
  750. // set focus to first focusable item
  751. PUM_Admin.modals._current.find('.pum-modal-content *').filter(focusableElementsString).filter(':visible').first().focus();
  752. },
  753. closeAll: function (callback) {
  754. $('.pum-modal-background')
  755. .off('keydown.pum_modal')
  756. .hide(0, function () {
  757. $('html').css({overflow: 'visible', width: 'auto'});
  758. if ($top_level_elements) {
  759. $top_level_elements.attr('aria-hidden', 'false');
  760. $top_level_elements = null;
  761. }
  762. // Accessibility: Focus back on the previously focused element.
  763. if (previouslyFocused.length) {
  764. previouslyFocused.focus();
  765. }
  766. // Accessibility: Clears the PUM_Admin.modals._current var.
  767. PUM_Admin.modals._current = null;
  768. // Accessibility: Removes the force focus check.
  769. $document.off('focus.pum_modal');
  770. if (undefined !== callback) {
  771. callback();
  772. }
  773. })
  774. .attr('aria-hidden', 'true');
  775. },
  776. show: function (modal, callback) {
  777. $('.pum-modal-background')
  778. .off('keydown.pum_modal')
  779. .hide(0)
  780. .attr('aria-hidden', 'true');
  781. $html
  782. .data('origwidth', $html.innerWidth())
  783. .css({overflow: 'hidden', 'width': $html.innerWidth()});
  784. // Accessibility: Sets the previous focus element.
  785. var $focused = $(':focus');
  786. if (!$focused.parents('.pum-modal-wrap').length) {
  787. previouslyFocused = $focused;
  788. }
  789. // Accessibility: Sets the current modal for focus checks.
  790. PUM_Admin.modals._current = $(modal);
  791. // Accessibility: Close on esc press.
  792. PUM_Admin.modals._current
  793. .on('keydown.pum_modal', function (e) {
  794. PUM_Admin.modals.trapEscapeKey(e);
  795. PUM_Admin.modals.trapTabKey(e);
  796. })
  797. .show(0, function () {
  798. $top_level_elements = $('body > *').filter(':visible').not(PUM_Admin.modals._current);
  799. $top_level_elements.attr('aria-hidden', 'true');
  800. PUM_Admin.modals._current
  801. .trigger('pum_init')
  802. // Accessibility: Add focus check that prevents tabbing outside of modal.
  803. .on('focus.pum_modal', PUM_Admin.modals.forceFocus);
  804. // Accessibility: Focus on the modal.
  805. PUM_Admin.modals.setFocusToFirstItem();
  806. if (undefined !== callback) {
  807. callback();
  808. }
  809. })
  810. .attr('aria-hidden', 'false');
  811. },
  812. remove: function (modal) {
  813. $(modal).remove();
  814. },
  815. replace: function (modal, replacement) {
  816. PUM_Admin.modals.remove($.trim(modal));
  817. $('body').append($.trim(replacement));
  818. },
  819. reload: function (modal, replacement, callback) {
  820. PUM_Admin.modals.replace(modal, replacement);
  821. PUM_Admin.modals.show(modal, callback);
  822. $(modal).trigger('pum_init');
  823. }
  824. };
  825. // Import this module.
  826. window.PUM_Admin = window.PUM_Admin || {};
  827. window.PUM_Admin.modals = modals;
  828. $(document).on('click', '.pum-modal-background, .pum-modal-wrap .cancel, .pum-modal-wrap .pum-modal-close', function (e) {
  829. var $target = $(e.target);
  830. if (/*$target.hasClass('pum-modal-background') || */$target.hasClass('cancel') || $target.hasClass('pum-modal-close') || $target.hasClass('submitdelete')) {
  831. PUM_Admin.modals.closeAll();
  832. e.preventDefault();
  833. e.stopPropagation();
  834. }
  835. });
  836. }(jQuery));
  837. /*******************************************************************************
  838. * Copyright (c) 2019, Code Atlantic LLC
  839. ******************************************************************************/
  840. (function ($) {
  841. "use strict";
  842. var models = {
  843. field: function (args) {
  844. return $.extend(true, {}, {
  845. type: 'text',
  846. id: '',
  847. id_prefix: '',
  848. name: '',
  849. label: null,
  850. placeholder: '',
  851. desc: null,
  852. dynamic_desc: null,
  853. size: 'regular',
  854. classes: [],
  855. dependencies: "",
  856. value: null,
  857. select2: false,
  858. allow_html: false,
  859. multiple: false,
  860. as_array: false,
  861. options: [],
  862. object_type: null,
  863. object_key: null,
  864. std: null,
  865. min: 0,
  866. max: 50,
  867. force_minmax: false,
  868. step: 1,
  869. unit: 'px',
  870. units: {},
  871. required: false,
  872. desc_position: 'bottom',
  873. meta: {}
  874. }, args);
  875. }
  876. };
  877. // Import this module.
  878. window.PUM_Admin = window.PUM_Admin || {};
  879. window.PUM_Admin.models = models;
  880. }(jQuery));
  881. /*******************************************************************************
  882. * Copyright (c) 2019, Code Atlantic LLC
  883. ******************************************************************************/
  884. (function ($) {
  885. 'use strict';
  886. var rangesliders = {
  887. cloneables: {
  888. slider: $('<input type="range" class="pum-range-slider" />'),
  889. plus: $('<button type="button" class="pum-range-plus">+</button>'),
  890. minus: $('<button type="button" class="pum-range-minus">-</button>')
  891. },
  892. init: function () {
  893. $('.pum-field-rangeslider:not(.pum-rangeslider-initialized)').each(function () {
  894. var $this = $(this).addClass('pum-rangeslider-initialized'),
  895. $input = $this.find('input.pum-range-manual'),
  896. $slider = rangesliders.cloneables.slider.clone(),
  897. $plus = rangesliders.cloneables.plus.clone(),
  898. $minus = rangesliders.cloneables.minus.clone(),
  899. settings = {
  900. force: $input.data('force-minmax'),
  901. min: parseInt($input.attr('min'), 10) || 0,
  902. max: parseInt($input.attr('max'), 10) || 100,
  903. step: parseInt($input.attr('step'), 10) || 1,
  904. value: parseInt($input.attr('value'), 10) || 0
  905. };
  906. if (settings.force && settings.value > settings.max) {
  907. settings.value = settings.max;
  908. $input.val(settings.value);
  909. }
  910. $slider.prop({
  911. min: settings.min || 0,
  912. max: (settings.force || (settings.max && settings.max > settings.value)) ? settings.max : settings.value *
  913. 1.5,
  914. step: settings.step || settings.value * 1.5 / 100,
  915. value: settings.value
  916. }).on('change input', function () {
  917. $input.trigger('input');
  918. });
  919. $input.next().after($minus, $plus);
  920. $input.before($slider);
  921. });
  922. }
  923. };
  924. // Import this module.
  925. window.PUM_Admin = window.PUM_Admin || {};
  926. window.PUM_Admin.rangesliders = rangesliders;
  927. $(document)
  928. .on('pum_init', PUM_Admin.rangesliders.init)
  929. /**
  930. * Updates the input field when the slider is used.
  931. */
  932. .on('input', '.pum-field-rangeslider.pum-rangeslider-initialized .pum-range-slider', function () {
  933. var $slider = $(this);
  934. $slider.siblings('.pum-range-manual').val($slider.val());
  935. })
  936. /**
  937. * Update sliders value, min, & max when manual entry is detected.
  938. */
  939. .on('change', '.pum-range-manual', function () {
  940. var $input = $(this),
  941. max = parseInt($input.prop('max'), 0),
  942. min = parseInt($input.prop('min'), 0),
  943. step = parseInt($input.prop('step'), 0),
  944. force = $input.data('force-minmax'),
  945. value = parseInt($input.val(), 0),
  946. $slider = $input.prev();
  947. if (isNaN(value)) {
  948. value = $slider.val();
  949. }
  950. if (force && value > max) {
  951. value = max;
  952. } else if (force && value < min) {
  953. value = min;
  954. }
  955. $input.val(value).trigger('input');
  956. $slider.prop({
  957. 'max': force || (max && max > value) ? max : value * 1.5,
  958. 'step': step || value * 1.5 / 100,
  959. 'value': value
  960. });
  961. })
  962. .on('click', '.pum-range-plus', function (event) {
  963. var $input = $(this).siblings('.pum-range-manual'),
  964. max = parseInt($input.prop('max'), 0),
  965. step = parseInt($input.prop('step'), 0),
  966. force = $input.data('force-minmax'),
  967. value = parseInt($input.val(), 0),
  968. $slider = $input.prev();
  969. event.preventDefault();
  970. value += step;
  971. if (isNaN(value)) {
  972. value = $slider.val();
  973. }
  974. if (force && value > max) {
  975. value = max;
  976. }
  977. $input.val(value).trigger('input');
  978. $slider.val(value);
  979. })
  980. .on('click', '.pum-range-minus', function (event) {
  981. var $input = $(this).siblings('.pum-range-manual'),
  982. min = parseInt($input.prop('min'), 0),
  983. step = parseInt($input.prop('step'), 0),
  984. force = $input.data('force-minmax'),
  985. value = parseInt($input.val(), 0),
  986. $slider = $input.prev();
  987. event.preventDefault();
  988. value -= step;
  989. if (isNaN(value)) {
  990. value = $slider.val();
  991. }
  992. if (force && value < min) {
  993. value = min;
  994. }
  995. $input.val(value).trigger('input');
  996. $slider.val(value);
  997. });
  998. }(jQuery));
  999. /*******************************************************************************
  1000. * Copyright (c) 2019, Code Atlantic LLC
  1001. ******************************************************************************/
  1002. (function ($) {
  1003. "use strict";
  1004. // Here because some plugins load additional copies, big no-no. This is the best we can do.
  1005. $.fn.pumselect2 = $.fn.pumselect2 || $.fn.select2;
  1006. var select2 = {
  1007. init: function () {
  1008. $('.pum-field-select2 select').filter(':not(.pumselect2-initialized)').each(function () {
  1009. var $this = $(this),
  1010. current = $this.data('current') || $this.val(),
  1011. object_type = $this.data('objecttype'),
  1012. object_key = $this.data('objectkey'),
  1013. object_excludes = $this.data('objectexcludes') || null,
  1014. options = {
  1015. width: '100%',
  1016. multiple: false,
  1017. dropdownParent: $this.parent()
  1018. };
  1019. if ($this.attr('multiple')) {
  1020. options.multiple = true;
  1021. }
  1022. if (object_type && object_key) {
  1023. options = $.extend(options, {
  1024. ajax: {
  1025. url: ajaxurl,
  1026. dataType: 'json',
  1027. delay: 250,
  1028. data: function (params) {
  1029. return {
  1030. s: params.term, // search term
  1031. paged: params.page,
  1032. action: "pum_object_search",
  1033. object_type: object_type,
  1034. object_key: object_key,
  1035. exclude: object_excludes
  1036. };
  1037. },
  1038. processResults: function (data, params) {
  1039. // parse the results into the format expected by Select2
  1040. // since we are using custom formatting functions we do not need to
  1041. // alter the remote JSON data, except to indicate that infinite
  1042. // scrolling can be used
  1043. params.page = params.page || 1;
  1044. return {
  1045. results: data.items,
  1046. pagination: {
  1047. more: (params.page * 10) < data.total_count
  1048. }
  1049. };
  1050. },
  1051. cache: true
  1052. },
  1053. cache: true,
  1054. escapeMarkup: function (markup) {
  1055. return markup;
  1056. }, // let our custom formatter work
  1057. maximumInputLength: 20,
  1058. closeOnSelect: !options.multiple,
  1059. templateResult: PUM_Admin.select2.formatObject,
  1060. templateSelection: PUM_Admin.select2.formatObjectSelection
  1061. });
  1062. }
  1063. $this
  1064. .addClass('pumselect2-initialized')
  1065. .pumselect2(options);
  1066. if (current !== null && current !== undefined) {
  1067. if (options.multiple && 'object' !== typeof current && current !== "") {
  1068. current = [current];
  1069. } else if (!options.multiple && current === '') {
  1070. current = null;
  1071. }
  1072. } else {
  1073. current = null;
  1074. }
  1075. if (object_type && object_key && current !== null && (typeof current === 'number' || current.length)) {
  1076. $.ajax({
  1077. url: ajaxurl,
  1078. data: {
  1079. action: "pum_object_search",
  1080. object_type: object_type,
  1081. object_key: object_key,
  1082. exclude: object_excludes,
  1083. include: current && current.length ? (typeof current === 'string' || typeof current === 'number') ? [current] : current : null
  1084. },
  1085. dataType: "json",
  1086. success: function (data) {
  1087. $.each(data.items, function (key, item) {
  1088. // Add any option that doesn't already exist
  1089. if (!$this.find('option[value="' + item.id + '"]').length) {
  1090. $this.prepend('<option value="' + item.id + '">' + item.text + '</option>');
  1091. }
  1092. });
  1093. // Update the options
  1094. $this.val(current).trigger('change');
  1095. }
  1096. });
  1097. } else if (current && ((options.multiple && current.length) || (!options.multiple && current !== ""))) {
  1098. $this.val(current).trigger('change');
  1099. } else if (current === null) {
  1100. $this.val(current).trigger('change');
  1101. }
  1102. });
  1103. },
  1104. formatObject: function (object) {
  1105. return object.text;
  1106. },
  1107. formatObjectSelection: function (object) {
  1108. return object.text || object.text;
  1109. }
  1110. };
  1111. // Import this module.
  1112. window.PUM_Admin = window.PUM_Admin || {};
  1113. window.PUM_Admin.select2 = select2;
  1114. $(document)
  1115. .on('pum_init', function () {
  1116. PUM_Admin.select2.init();
  1117. });
  1118. }(jQuery));
  1119. /*
  1120. * $$ Selector Cache
  1121. * Cache your selectors, without messy code.
  1122. * @author Stephen Kamenar
  1123. */
  1124. (function ($, undefined) {
  1125. // '#a': $('#a')
  1126. if (typeof window.$$ === 'function') {
  1127. return;
  1128. }
  1129. var cache = {},
  1130. cacheByContext = {}, // '#context': (a cache object for the element)
  1131. tmp, tmp2; // Here for performance/minification
  1132. window.$$ = function (selector, context) {
  1133. if (context) {
  1134. if (tmp = context.selector) {
  1135. context = tmp;
  1136. }
  1137. // tmp2 is contextCache
  1138. tmp2 = cacheByContext[context];
  1139. if (tmp2 === undefined) {
  1140. tmp2 = cacheByContext[context] = {};
  1141. }
  1142. tmp = tmp2[selector];
  1143. if (tmp !== undefined) {
  1144. return tmp;
  1145. }
  1146. return tmp2[selector] = $(selector, $$(context));
  1147. }
  1148. tmp = cache[selector];
  1149. if (tmp !== undefined) {
  1150. return tmp;
  1151. }
  1152. return cache[selector] = $(selector);
  1153. };
  1154. window.$$clear = function (selector, context) {
  1155. if (context) {
  1156. if (tmp = context.selector) {
  1157. context = tmp;
  1158. }
  1159. if (selector && (tmp = cacheByContext[context])) {
  1160. tmp[selector] = undefined;
  1161. }
  1162. cacheByContext[context] = undefined;
  1163. } else {
  1164. if (selector) {
  1165. cache[selector] = undefined;
  1166. cacheByContext[selector] = undefined;
  1167. } else {
  1168. cache = {};
  1169. cacheByContext = {};
  1170. }
  1171. }
  1172. };
  1173. window.$$fresh = function (selector, context) {
  1174. $$clear(selector, context);
  1175. return $$(selector, context);
  1176. };
  1177. }(jQuery));
  1178. /**
  1179. * jQuery serializeObject
  1180. * @copyright 2014, macek <paulmacek@gmail.com>
  1181. * @link https://github.com/macek/jquery-serialize-object
  1182. * @license BSD
  1183. * @version 2.5.0
  1184. */
  1185. (function (root, factory) {
  1186. // AMD
  1187. if (typeof define === "function" && define.amd) {
  1188. define(["exports", "jquery"], function (exports, $) {
  1189. return factory(exports, $);
  1190. });
  1191. }
  1192. // CommonJS
  1193. else if (typeof exports !== "undefined") {
  1194. var $ = require("jquery");
  1195. factory(exports, $);
  1196. }
  1197. // Browser
  1198. else {
  1199. factory(root, (root.jQuery || root.Zepto || root.ender || root.$));
  1200. }
  1201. }(this, function (exports, $) {
  1202. var patterns = {
  1203. validate: /^[a-z_][a-z0-9_]*(?:\[(?:\d*|[a-z0-9_]+)\])*$/i,
  1204. key: /[a-z0-9_]+|(?=\[\])/gi,
  1205. push: /^$/,
  1206. fixed: /^\d+$/,
  1207. named: /^[a-z0-9_]+$/i
  1208. };
  1209. function FormSerializer(helper, $form) {
  1210. // private variables
  1211. var data = {},
  1212. pushes = {};
  1213. // private API
  1214. function build(base, key, value) {
  1215. base[key] = value;
  1216. return base;
  1217. }
  1218. function makeObject(root, value) {
  1219. var keys = root.match(patterns.key), k,
  1220. field = document.querySelector('[name="' + root + '"]'),
  1221. type = false;
  1222. if ("INPUT" === field.tagName) {
  1223. type = field.type;
  1224. } else {
  1225. if ("SELECT" === field.tagName) {
  1226. type = 'select';
  1227. } else if ("TEXTAREA" === field.tagName) {
  1228. type = 'textarea';
  1229. }
  1230. }
  1231. if (['textarea', 'text'].indexOf(type) >= 0) {
  1232. try {
  1233. value = JSON.parse(value);
  1234. } catch (Error) {
  1235. }
  1236. }
  1237. // nest, nest, ..., nest
  1238. while ((k = keys.pop()) !== undefined) {
  1239. // foo[]
  1240. if (patterns.push.test(k)) {
  1241. var idx = incrementPush(root.replace(/\[\]$/, ''));
  1242. value = build([], idx, value);
  1243. }
  1244. // foo[n]
  1245. else if (patterns.fixed.test(k)) {
  1246. value = build([], k, value);
  1247. }
  1248. // foo; foo[bar]
  1249. else if (patterns.named.test(k)) {
  1250. value = build({}, k, value);
  1251. }
  1252. }
  1253. return value;
  1254. }
  1255. function incrementPush(key) {
  1256. if (pushes[key] === undefined) {
  1257. pushes[key] = 0;
  1258. }
  1259. return pushes[key]++;
  1260. }
  1261. function encode(pair) {
  1262. console.log(pair);
  1263. switch ($('[name="' + pair.name + '"]', $form).attr("type")) {
  1264. case "checkbox":
  1265. return pair.value === "1" ? true : pair.value;
  1266. default:
  1267. return pair.value;
  1268. }
  1269. }
  1270. function addPair(pair) {
  1271. if (!patterns.validate.test(pair.name)) return this;
  1272. var obj = makeObject(pair.name, encode(pair));
  1273. data = helper.extend(true, data, obj);
  1274. return this;
  1275. }
  1276. function addPairs(pairs) {
  1277. if (!helper.isArray(pairs)) {
  1278. throw new Error("formSerializer.addPairs expects an Array");
  1279. }
  1280. for (var i = 0, len = pairs.length; i < len; i++) {
  1281. this.addPair(pairs[i]);
  1282. }
  1283. return this;
  1284. }
  1285. function serialize() {
  1286. return data;
  1287. }
  1288. function serializeJSON() {
  1289. return JSON.stringify(serialize());
  1290. }
  1291. // public API
  1292. this.addPair = addPair;
  1293. this.addPairs = addPairs;
  1294. this.serialize = serialize;
  1295. this.serializeJSON = serializeJSON;
  1296. }
  1297. FormSerializer.patterns = patterns;
  1298. FormSerializer.serializeObject = function serializeObject() {
  1299. var serialized;
  1300. if (this.is('form')) {
  1301. serialized = this.serializeArray();
  1302. } else {
  1303. serialized = this.find(':input').serializeArray();
  1304. }
  1305. return new FormSerializer($, this)
  1306. .addPairs(serialized)
  1307. .serialize();
  1308. };
  1309. FormSerializer.serializeJSON = function serializeJSON() {
  1310. var serialized;
  1311. if (this.is('form')) {
  1312. serialized = this.serializeArray();
  1313. } else {
  1314. serialized = this.find(':input').serializeArray();
  1315. }
  1316. return new FormSerializer($, this)
  1317. .addPairs(serialized)
  1318. .serializeJSON();
  1319. };
  1320. if (typeof $.fn !== "undefined") {
  1321. $.fn.pumSerializeObject = FormSerializer.serializeObject;
  1322. $.fn.pumSerializeJSON = FormSerializer.serializeJSON;
  1323. }
  1324. exports.FormSerializer = FormSerializer;
  1325. return FormSerializer;
  1326. }));
  1327. /*******************************************************************************
  1328. * Copyright (c) 2019, Code Atlantic LLC
  1329. ******************************************************************************/
  1330. (function ($) {
  1331. "use strict";
  1332. var tabs = {
  1333. init: function () {
  1334. $('.pum-tabs-container').filter(':not(.pum-tabs-initialized)').each(function () {
  1335. var $this = $(this).addClass('pum-tabs-initialized'),
  1336. $tabList = $this.find('> ul.tabs'),
  1337. $firstTab = $tabList.find('> li:first'),
  1338. forceMinHeight = $this.data('min-height');
  1339. if ($this.hasClass('vertical-tabs')) {
  1340. var minHeight = forceMinHeight && forceMinHeight > 0 ? forceMinHeight : $tabList.eq(0).outerHeight(true);
  1341. $this.css({
  1342. minHeight: minHeight + 'px'
  1343. });
  1344. if ($this.parent().innerHeight < minHeight) {
  1345. $this.parent().css({
  1346. minHeight: minHeight + 'px'
  1347. });
  1348. }
  1349. }
  1350. // Trigger first tab.
  1351. $firstTab.trigger('click');
  1352. });
  1353. }
  1354. };
  1355. // Import this module.
  1356. window.PUM_Admin = window.PUM_Admin || {};
  1357. window.PUM_Admin.tabs = tabs;
  1358. $(document)
  1359. .on('pum_init', PUM_Admin.tabs.init)
  1360. .on('click', '.pum-tabs-initialized li.tab', function (e) {
  1361. var $this = $(this),
  1362. $container = $this.parents('.pum-tabs-container:first'),
  1363. $tabs = $container.find('> ul.tabs > li.tab'),
  1364. $tab_contents = $container.find('> div.tab-content'),
  1365. link = $this.find('a').attr('href');
  1366. $tabs.removeClass('active');
  1367. $tab_contents.removeClass('active');
  1368. $this.addClass('active');
  1369. $container.find('> div.tab-content' + link).addClass('active');
  1370. e.preventDefault();
  1371. });
  1372. }(jQuery));
  1373. /*******************************************************************************
  1374. * Copyright (c) 2019, Code Atlantic LLC
  1375. ******************************************************************************/
  1376. (function ($) {
  1377. "use strict";
  1378. var I10n = pum_admin_vars.I10n,
  1379. templates = {
  1380. render: function (template, data) {
  1381. var _template = wp.template(template);
  1382. data = data || {};
  1383. if (data.classes !== undefined && Array.isArray(data.classes)) {
  1384. data.classes = data.classes.join(' ');
  1385. }
  1386. // Prepare the meta data for templates.
  1387. data = PUM_Admin.templates.prepareMeta(data);
  1388. return _template(data);
  1389. },
  1390. renderInline: function (content, data) {
  1391. var options = {
  1392. evaluate: /<#([\s\S]+?)#>/g,
  1393. interpolate: /\{\{\{([\s\S]+?)\}\}\}/g,
  1394. escape: /\{\{([^\}]+?)\}\}(?!\})/g,
  1395. variable: 'data'
  1396. },
  1397. template = _.template(content, null, options);
  1398. return template(data);
  1399. },
  1400. shortcode: function (args) {
  1401. var data = $.extend(true, {}, {
  1402. tag: '',
  1403. meta: {},
  1404. has_content: false,
  1405. content: ''
  1406. }, args),
  1407. template = data.has_content ? 'pum-shortcode-w-content' : 'pum-shortcode';
  1408. return PUM_Admin.templates.render(template, data);
  1409. },
  1410. modal: function (args) {
  1411. var data = $.extend(true, {}, {
  1412. id: '',
  1413. title: '',
  1414. description: '',
  1415. classes: '',
  1416. save_button: I10n.save,
  1417. cancel_button: I10n.cancel,
  1418. content: ''
  1419. }, args);
  1420. return PUM_Admin.templates.render('pum-modal', data);
  1421. },
  1422. tabs: function (data) {
  1423. data = $.extend(true, {}, {
  1424. id: '',
  1425. vertical: false,
  1426. form: false,
  1427. classes: [],
  1428. tabs: {},
  1429. meta: {}
  1430. }, data);
  1431. if (typeof data.classes === 'string') {
  1432. data.classes = [data.classes];
  1433. }
  1434. if (data.form) {
  1435. data.classes.push('pum-tabbed-form');
  1436. }
  1437. data.meta['data-tab-count'] = Object.keys(data.tabs).length;
  1438. data.classes.push(data.vertical ? 'vertical-tabs' : 'horizontal-tabs');
  1439. data.classes = data.classes.join(' ');
  1440. return PUM_Admin.templates.render('pum-tabs', data);
  1441. },
  1442. section: function (args) {
  1443. var data = $.extend(true, {}, {
  1444. classes: [],
  1445. fields: []
  1446. }, args);
  1447. return PUM_Admin.templates.render('pum-field-section', data);
  1448. },
  1449. fieldArgs: function (args) {
  1450. var options = [],
  1451. data = $.extend(true, {}, PUM_Admin.models.field(args));
  1452. if (args.std !== undefined && args.type !== 'checkbox' && (data.value === null || data.value === false)) {
  1453. data.value = args.std;
  1454. }
  1455. if ('string' === typeof data.classes) {
  1456. data.classes = data.classes.split(' ');
  1457. }
  1458. if (args.class !== undefined) {
  1459. data.classes.push(args.class);
  1460. }
  1461. if (args.dependencies !== undefined && typeof args.dependencies === 'object') {
  1462. data.dependencies = JSON.stringify(args.dependencies);
  1463. }
  1464. if (data.required) {
  1465. data.meta.required = true;
  1466. data.classes.push('pum-required');
  1467. }
  1468. if (typeof data.dynamic_desc === 'string' && data.dynamic_desc.length) {
  1469. data.classes.push('pum-field-dynamic-desc');
  1470. data.desc = PUM_Admin.templates.renderInline(data.dynamic_desc, data);
  1471. }
  1472. if (data.allow_html) {
  1473. data.classes.push('pum-field-' + data.type + '--html');
  1474. if ( typeof data.value === 'string' && data.value !== '' && PUM_Admin.utils.htmlencoder.hasEncoded(data.value)) {
  1475. data.value = PUM_Admin.utils.htmlencoder.htmlDecode(data.value);
  1476. }
  1477. }
  1478. switch (args.type) {
  1479. case 'select':
  1480. case 'objectselect':
  1481. case 'postselect':
  1482. case 'taxonomyselect':
  1483. if (data.options !== undefined) {
  1484. _.each(data.options, function (label, value) {
  1485. var selected = false,
  1486. optgroup,
  1487. optgroup_options;
  1488. // Check if the label is an object. If so this is a optgroup and the label is sub options array.
  1489. // NOTE: The value in the case its an optgroup is the optgroup label.
  1490. if (typeof label !== 'object') {
  1491. if (data.value !== null) {
  1492. if (data.multiple && ((typeof data.value === 'string' && data.value == value) || (Array.isArray(data.value) && data.value.indexOf(value) !== -1) || (!Array.isArray(data.value) && typeof data.value === 'object' && Object.keys(data.value).length && data.value[value] !== undefined))) {
  1493. selected = 'selected';
  1494. } else if (!data.multiple && data.value == value) {
  1495. selected = 'selected';
  1496. }
  1497. }
  1498. options.push(
  1499. PUM_Admin.templates.prepareMeta({
  1500. label: label,
  1501. value: value,
  1502. meta: {
  1503. selected: selected
  1504. }
  1505. })
  1506. );
  1507. } else {
  1508. // Process Option Groups
  1509. // Swap label & value due to group labels being used as keys.
  1510. optgroup = value;
  1511. optgroup_options = [];
  1512. _.each(label, function (label, value) {
  1513. var selected = false;
  1514. if (data.value !== null) {
  1515. if (data.multiple && ((typeof data.value === 'string' && data.value == value) || (Array.isArray(data.value) && data.value.indexOf(value) !== -1) || (!Array.isArray(data.value) && typeof data.value === 'object' && Object.keys(data.value).length && data.value[value] !== undefined))) {
  1516. selected = 'selected';
  1517. } else if (!data.multiple && data.value == value) {
  1518. selected = 'selected';
  1519. }
  1520. }
  1521. optgroup_options.push(
  1522. PUM_Admin.templates.prepareMeta({
  1523. label: label,
  1524. value: value,
  1525. meta: {
  1526. selected: selected
  1527. }
  1528. })
  1529. );
  1530. });
  1531. options.push({
  1532. label: optgroup,
  1533. options: optgroup_options
  1534. });
  1535. }
  1536. });
  1537. data.options = options;
  1538. }
  1539. if (data.multiple) {
  1540. data.meta.multiple = true;
  1541. if (data.as_array) {
  1542. data.name += '[]';
  1543. }
  1544. if (!data.value || !data.value.length) {
  1545. data.value = [];
  1546. }
  1547. if (typeof data.value === 'string') {
  1548. data.value = [data.value];
  1549. }
  1550. }
  1551. if (args.type !== 'select') {
  1552. data.select2 = true;
  1553. data.classes.push('pum-field-objectselect');
  1554. data.classes.push(args.type === 'postselect' ? 'pum-field-postselect' : 'pum-field-taxonomyselect');
  1555. data.meta['data-objecttype'] = args.type === 'postselect' ? 'post_type' : 'taxonomy';
  1556. data.meta['data-objectkey'] = args.type === 'postselect' ? args.post_type : args.taxonomy;
  1557. data.meta['data-current'] = typeof data.value === 'object' || Array.isArray(data.value) ? JSON.stringify(data.value) : data.value;
  1558. }
  1559. if (data.select2) {
  1560. data.classes.push('pum-field-select2');
  1561. if (data.placeholder) {
  1562. data.meta['data-placeholder'] = data.placeholder;
  1563. }
  1564. }
  1565. break;
  1566. case 'radio':
  1567. if (data.options !== undefined) {
  1568. _.each(data.options, function (label, value) {
  1569. options.push(
  1570. PUM_Admin.templates.prepareMeta({
  1571. label: label,
  1572. value: value,
  1573. meta: {
  1574. checked: data.value === value
  1575. }
  1576. })
  1577. );
  1578. });
  1579. data.options = options;
  1580. }
  1581. break;
  1582. case 'multicheck':
  1583. if (data.options !== undefined) {
  1584. if (data.value === false || data.value === null) {
  1585. data.value = [];
  1586. }
  1587. if (typeof data.value === 'string' && data.value.indexOf(',')) {
  1588. data.value = data.value.split(',');
  1589. }
  1590. if (data.as_array) {
  1591. data.name += '[]';
  1592. }
  1593. _.each(data.options, function (label, value) {
  1594. options.push(
  1595. PUM_Admin.templates.prepareMeta({
  1596. label: label,
  1597. value: value,
  1598. meta: {
  1599. checked: (Array.isArray(data.value) && data.value.indexOf(value) !== -1) || (!Array.isArray(data.value) && typeof data.value === 'object' && Object.keys(data.value).length && data.value[value] !== undefined)
  1600. }
  1601. })
  1602. );
  1603. });
  1604. data.options = options;
  1605. }
  1606. break;
  1607. case 'checkbox':
  1608. switch (typeof data.value) {
  1609. case 'object':
  1610. if (Array.isArray(data.value) && data.value.length === 1 && data.value[0].toString() === '1') {
  1611. data.value = true;
  1612. data.meta.checked = true;
  1613. }
  1614. break;
  1615. case 'boolean':
  1616. if (data.value) {
  1617. data.meta.checked = true;
  1618. }
  1619. break;
  1620. case 'string':
  1621. if (data.value === 'true' || data.value === 'yes' || data.value === '1') {
  1622. data.meta.checked = true;
  1623. }
  1624. break;
  1625. case 'number':
  1626. if (parseInt(data.value, 10) === 1 || parseInt(data.value, 10) > 0) {
  1627. data.meta.checked = true;
  1628. }
  1629. }
  1630. break;
  1631. case 'rangeslider':
  1632. // data.meta.readonly = true;
  1633. data.meta.step = data.step;
  1634. data.meta.min = data.min;
  1635. data.meta.max = data.max;
  1636. data.meta['data-force-minmax'] = data.force_minmax.toString();
  1637. break;
  1638. case 'textarea':
  1639. data.meta.cols = data.cols;
  1640. data.meta.rows = data.rows;
  1641. break;
  1642. case 'measure':
  1643. if (typeof data.value === 'string' && data.value !== '') {
  1644. data.number = parseInt(data.value);
  1645. data.unitValue = data.value.replace(data.number, "");
  1646. data.value = data.number;
  1647. } else {
  1648. data.unitValue = null;
  1649. }
  1650. if (data.units !== undefined) {
  1651. _.each(data.units, function (label, value) {
  1652. var selected = false;
  1653. if (data.unitValue == value) {
  1654. selected = 'selected';
  1655. }
  1656. options.push(
  1657. PUM_Admin.templates.prepareMeta({
  1658. label: label,
  1659. value: value,
  1660. meta: {
  1661. selected: selected
  1662. }
  1663. })
  1664. );
  1665. });
  1666. data.units = options;
  1667. }
  1668. break;
  1669. case 'color':
  1670. if ( typeof data.value === 'string' && data.value !== '') {
  1671. data.meta['data-default-color'] = data.value;
  1672. }
  1673. break;
  1674. case 'license_key':
  1675. data.value = $.extend({
  1676. key: '',
  1677. license: {},
  1678. messages: [],
  1679. status: 'empty',
  1680. expires: false,
  1681. classes: false
  1682. }, data.value);
  1683. data.classes.push('pum-license-' + data.value.status + '-notice');
  1684. if (data.value.classes) {
  1685. data.classes.push(data.value.classes);
  1686. }
  1687. break;
  1688. }
  1689. return data;
  1690. },
  1691. field: function (args) {
  1692. var fieldTemplate,
  1693. data = PUM_Admin.templates.fieldArgs(args);
  1694. fieldTemplate = 'pum-field-' + data.type;
  1695. if (data.type === 'objectselfect' || data.type === 'postselect' || data.type === 'taxonomyselect') {
  1696. fieldTemplate = 'pum-field-select';
  1697. }
  1698. if (!$('#tmpl-' + fieldTemplate).length) {
  1699. console.warn('No field template found for type:' + data.type + ' fieldID: ' + data.id);
  1700. return '';
  1701. }
  1702. data.field = PUM_Admin.templates.render(fieldTemplate, data);
  1703. return PUM_Admin.templates.render('pum-field-wrapper', data);
  1704. },
  1705. prepareMeta: function (data) {
  1706. // Convert meta JSON to attribute string.
  1707. var _meta = [],
  1708. key;
  1709. for (key in data.meta) {
  1710. if (data.meta.hasOwnProperty(key)) {
  1711. // Boolean attributes can only require attribute key, not value.
  1712. if ('boolean' === typeof data.meta[key]) {
  1713. // Only set truthy boolean attributes.
  1714. if (data.meta[key]) {
  1715. _meta.push(_.escape(key));
  1716. }
  1717. } else {
  1718. _meta.push(_.escape(key) + '="' + _.escape(data.meta[key]) + '"');
  1719. }
  1720. }
  1721. }
  1722. data.meta = _meta.join(' ');
  1723. return data;
  1724. }
  1725. };
  1726. // Import this module.
  1727. window.PUM_Admin = window.PUM_Admin || {};
  1728. window.PUM_Admin.templates = templates;
  1729. }(window.jQuery));
  1730. /*******************************************************************************
  1731. * Copyright (c) 2019, Code Atlantic LLC
  1732. ******************************************************************************/
  1733. (function ($) {
  1734. "use strict";
  1735. String.prototype.capitalize = function () {
  1736. return this.charAt(0).toUpperCase() + this.slice(1);
  1737. };
  1738. var root = this,
  1739. inputTypes = 'color,date,datetime,datetime-local,email,hidden,month,number,password,range,search,tel,text,time,url,week'.split(','),
  1740. inputNodes = 'select,textarea'.split(','),
  1741. rName = /\[([^\]]*)\]/g;
  1742. // ugly hack for IE7-8
  1743. function isInArray(array, needle) {
  1744. return $.inArray(needle, array) !== -1;
  1745. }
  1746. function storeValue(container, parsedName, value) {
  1747. var part = parsedName[0];
  1748. if (parsedName.length > 1) {
  1749. if (!container[part]) {
  1750. // If the next part is eq to '' it means we are processing complex name (i.e. `some[]`)
  1751. // for this case we need to use Array instead of an Object for the index increment purpose
  1752. container[part] = parsedName[1] ? {} : [];
  1753. }
  1754. storeValue(container[part], parsedName.slice(1), value);
  1755. } else {
  1756. // Increment Array index for `some[]` case
  1757. if (!part) {
  1758. part = container.length;
  1759. }
  1760. container[part] = value;
  1761. }
  1762. }
  1763. /**
  1764. * A Javascript object to encode and/or decode html characters using HTML or Numeric entities that handles double or partial encoding
  1765. * Author: R Reid
  1766. * source: http://www.strictly-software.com/htmlencode
  1767. * Licences: GPL, The MIT License (MIT)
  1768. * Copyright: (c) 2011 Robert Reid - Strictly-Software.com
  1769. *
  1770. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  1771. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  1772. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  1773. *
  1774. * Revision:
  1775. * 2011-07-14, Jacques-Yves Bleau:
  1776. * - fixed conversion error with capitalized accentuated characters
  1777. * + converted arr1 and arr2 to object property to remove redundancy
  1778. *
  1779. * Revision:
  1780. * 2011-11-10, Ce-Yi Hio:
  1781. * - fixed conversion error with a number of capitalized entity characters
  1782. *
  1783. * Revision:
  1784. * 2011-11-10, Rob Reid:
  1785. * - changed array format
  1786. *
  1787. * Revision:
  1788. * 2012-09-23, Alex Oss:
  1789. * - replaced string concatonation in numEncode with string builder, push and join for peformance with ammendments by Rob Reid
  1790. */
  1791. var Encoder = {
  1792. // When encoding do we convert characters into html or numerical entities
  1793. EncodeType : "entity", // entity OR numerical
  1794. isEmpty : function(val){
  1795. if(val){
  1796. return ((val===null) || val.length==0 || /^\s+$/.test(val));
  1797. }else{
  1798. return true;
  1799. }
  1800. },
  1801. // arrays for conversion from HTML Entities to Numerical values
  1802. arr1: ['&nbsp;','&iexcl;','&cent;','&pound;','&curren;','&yen;','&brvbar;','&sect;','&uml;','&copy;','&ordf;','&laquo;','&not;','&shy;','&reg;','&macr;','&deg;','&plusmn;','&sup2;','&sup3;','&acute;','&micro;','&para;','&middot;','&cedil;','&sup1;','&ordm;','&raquo;','&frac14;','&frac12;','&frac34;','&iquest;','&Agrave;','&Aacute;','&Acirc;','&Atilde;','&Auml;','&Aring;','&AElig;','&Ccedil;','&Egrave;','&Eacute;','&Ecirc;','&Euml;','&Igrave;','&Iacute;','&Icirc;','&Iuml;','&ETH;','&Ntilde;','&Ograve;','&Oacute;','&Ocirc;','&Otilde;','&Ouml;','&times;','&Oslash;','&Ugrave;','&Uacute;','&Ucirc;','&Uuml;','&Yacute;','&THORN;','&szlig;','&agrave;','&aacute;','&acirc;','&atilde;','&auml;','&aring;','&aelig;','&ccedil;','&egrave;','&eacute;','&ecirc;','&euml;','&igrave;','&iacute;','&icirc;','&iuml;','&eth;','&ntilde;','&ograve;','&oacute;','&ocirc;','&otilde;','&ouml;','&divide;','&oslash;','&ugrave;','&uacute;','&ucirc;','&uuml;','&yacute;','&thorn;','&yuml;','&quot;','&amp;','&lt;','&gt;','&OElig;','&oelig;','&Scaron;','&scaron;','&Yuml;','&circ;','&tilde;','&ensp;','&emsp;','&thinsp;','&zwnj;','&zwj;','&lrm;','&rlm;','&ndash;','&mdash;','&lsquo;','&rsquo;','&sbquo;','&ldquo;','&rdquo;','&bdquo;','&dagger;','&Dagger;','&permil;','&lsaquo;','&rsaquo;','&euro;','&fnof;','&Alpha;','&Beta;','&Gamma;','&Delta;','&Epsilon;','&Zeta;','&Eta;','&Theta;','&Iota;','&Kappa;','&Lambda;','&Mu;','&Nu;','&Xi;','&Omicron;','&Pi;','&Rho;','&Sigma;','&Tau;','&Upsilon;','&Phi;','&Chi;','&Psi;','&Omega;','&alpha;','&beta;','&gamma;','&delta;','&epsilon;','&zeta;','&eta;','&theta;','&iota;','&kappa;','&lambda;','&mu;','&nu;','&xi;','&omicron;','&pi;','&rho;','&sigmaf;','&sigma;','&tau;','&upsilon;','&phi;','&chi;','&psi;','&omega;','&thetasym;','&upsih;','&piv;','&bull;','&hellip;','&prime;','&Prime;','&oline;','&frasl;','&weierp;','&image;','&real;','&trade;','&alefsym;','&larr;','&uarr;','&rarr;','&darr;','&harr;','&crarr;','&lArr;','&uArr;','&rArr;','&dArr;','&hArr;','&forall;','&part;','&exist;','&empty;','&nabla;','&isin;','&notin;','&ni;','&prod;','&sum;','&minus;','&lowast;','&radic;','&prop;','&infin;','&ang;','&and;','&or;','&cap;','&cup;','&int;','&there4;','&sim;','&cong;','&asymp;','&ne;','&equiv;','&le;','&ge;','&sub;','&sup;','&nsub;','&sube;','&supe;','&oplus;','&otimes;','&perp;','&sdot;','&lceil;','&rceil;','&lfloor;','&rfloor;','&lang;','&rang;','&loz;','&spades;','&clubs;','&hearts;','&diams;'],
  1803. arr2: ['&#160;','&#161;','&#162;','&#163;','&#164;','&#165;','&#166;','&#167;','&#168;','&#169;','&#170;','&#171;','&#172;','&#173;','&#174;','&#175;','&#176;','&#177;','&#178;','&#179;','&#180;','&#181;','&#182;','&#183;','&#184;','&#185;','&#186;','&#187;','&#188;','&#189;','&#190;','&#191;','&#192;','&#193;','&#194;','&#195;','&#196;','&#197;','&#198;','&#199;','&#200;','&#201;','&#202;','&#203;','&#204;','&#205;','&#206;','&#207;','&#208;','&#209;','&#210;','&#211;','&#212;','&#213;','&#214;','&#215;','&#216;','&#217;','&#218;','&#219;','&#220;','&#221;','&#222;','&#223;','&#224;','&#225;','&#226;','&#227;','&#228;','&#229;','&#230;','&#231;','&#232;','&#233;','&#234;','&#235;','&#236;','&#237;','&#238;','&#239;','&#240;','&#241;','&#242;','&#243;','&#244;','&#245;','&#246;','&#247;','&#248;','&#249;','&#250;','&#251;','&#252;','&#253;','&#254;','&#255;','&#34;','&#38;','&#60;','&#62;','&#338;','&#339;','&#352;','&#353;','&#376;','&#710;','&#732;','&#8194;','&#8195;','&#8201;','&#8204;','&#8205;','&#8206;','&#8207;','&#8211;','&#8212;','&#8216;','&#8217;','&#8218;','&#8220;','&#8221;','&#8222;','&#8224;','&#8225;','&#8240;','&#8249;','&#8250;','&#8364;','&#402;','&#913;','&#914;','&#915;','&#916;','&#917;','&#918;','&#919;','&#920;','&#921;','&#922;','&#923;','&#924;','&#925;','&#926;','&#927;','&#928;','&#929;','&#931;','&#932;','&#933;','&#934;','&#935;','&#936;','&#937;','&#945;','&#946;','&#947;','&#948;','&#949;','&#950;','&#951;','&#952;','&#953;','&#954;','&#955;','&#956;','&#957;','&#958;','&#959;','&#960;','&#961;','&#962;','&#963;','&#964;','&#965;','&#966;','&#967;','&#968;','&#969;','&#977;','&#978;','&#982;','&#8226;','&#8230;','&#8242;','&#8243;','&#8254;','&#8260;','&#8472;','&#8465;','&#8476;','&#8482;','&#8501;','&#8592;','&#8593;','&#8594;','&#8595;','&#8596;','&#8629;','&#8656;','&#8657;','&#8658;','&#8659;','&#8660;','&#8704;','&#8706;','&#8707;','&#8709;','&#8711;','&#8712;','&#8713;','&#8715;','&#8719;','&#8721;','&#8722;','&#8727;','&#8730;','&#8733;','&#8734;','&#8736;','&#8743;','&#8744;','&#8745;','&#8746;','&#8747;','&#8756;','&#8764;','&#8773;','&#8776;','&#8800;','&#8801;','&#8804;','&#8805;','&#8834;','&#8835;','&#8836;','&#8838;','&#8839;','&#8853;','&#8855;','&#8869;','&#8901;','&#8968;','&#8969;','&#8970;','&#8971;','&#9001;','&#9002;','&#9674;','&#9824;','&#9827;','&#9829;','&#9830;'],
  1804. // Convert HTML entities into numerical entities
  1805. HTML2Numerical : function(s){
  1806. return this.swapArrayVals(s,this.arr1,this.arr2);
  1807. },
  1808. // Convert Numerical entities into HTML entities
  1809. NumericalToHTML : function(s){
  1810. return this.swapArrayVals(s,this.arr2,this.arr1);
  1811. },
  1812. // Numerically encodes all unicode characters
  1813. numEncode : function(s){
  1814. if(this.isEmpty(s)) return "";
  1815. var a = [],
  1816. l = s.length;
  1817. for (var i=0;i<l;i++){
  1818. var c = s.charAt(i);
  1819. if (c < " " || c > "~"){
  1820. a.push("&#");
  1821. a.push(c.charCodeAt()); //numeric value of code point
  1822. a.push(";");
  1823. }else{
  1824. a.push(c);
  1825. }
  1826. }
  1827. return a.join("");
  1828. },
  1829. // HTML Decode numerical and HTML entities back to original values
  1830. htmlDecode : function(s){
  1831. var c,m,d = s;
  1832. if(this.isEmpty(d)) return "";
  1833. // convert HTML entites back to numerical entites first
  1834. d = this.HTML2Numerical(d);
  1835. // look for numerical entities &#34;
  1836. var arr=d.match(/&#[0-9]{1,5};/g);
  1837. // if no matches found in string then skip
  1838. if(arr!=null){
  1839. for(var x=0;x<arr.length;x++){
  1840. m = arr[x];
  1841. c = m.substring(2,m.length-1); //get numeric part which is refernce to unicode character
  1842. // if its a valid number we can decode
  1843. if(c >= -32768 && c <= 65535){
  1844. // decode every single match within string
  1845. d = d.replace(m, String.fromCharCode(c));
  1846. }else{
  1847. d = d.replace(m, ""); //invalid so replace with nada
  1848. }
  1849. }
  1850. }
  1851. return d;
  1852. },
  1853. // encode an input string into either numerical or HTML entities
  1854. htmlEncode : function(s,dbl){
  1855. if(this.isEmpty(s)) return "";
  1856. // do we allow double encoding? E.g will &amp; be turned into &amp;amp;
  1857. dbl = dbl || false; //default to prevent double encoding
  1858. // if allowing double encoding we do ampersands first
  1859. if(dbl){
  1860. if(this.EncodeType=="numerical"){
  1861. s = s.replace(/&/g, "&#38;");
  1862. }else{
  1863. s = s.replace(/&/g, "&amp;");
  1864. }
  1865. }
  1866. // convert the xss chars to numerical entities ' " < >
  1867. s = this.XSSEncode(s,false);
  1868. if(this.EncodeType=="numerical" || !dbl){
  1869. // Now call function that will convert any HTML entities to numerical codes
  1870. s = this.HTML2Numerical(s);
  1871. }
  1872. // Now encode all chars above 127 e.g unicode
  1873. s = this.numEncode(s);
  1874. // now we know anything that needs to be encoded has been converted to numerical entities we
  1875. // can encode any ampersands & that are not part of encoded entities
  1876. // to handle the fact that I need to do a negative check and handle multiple ampersands &&&
  1877. // I am going to use a placeholder
  1878. // if we don't want double encoded entities we ignore the & in existing entities
  1879. if(!dbl){
  1880. s = s.replace(/&#/g,"##AMPHASH##");
  1881. if(this.EncodeType=="numerical"){
  1882. s = s.replace(/&/g, "&#38;");
  1883. }else{
  1884. s = s.replace(/&/g, "&amp;");
  1885. }
  1886. s = s.replace(/##AMPHASH##/g,"&#");
  1887. }
  1888. // replace any malformed entities
  1889. s = s.replace(/&#\d*([^\d;]|$)/g, "$1");
  1890. if(!dbl){
  1891. // safety check to correct any double encoded &amp;
  1892. s = this.correctEncoding(s);
  1893. }
  1894. // now do we need to convert our numerical encoded string into entities
  1895. if(this.EncodeType=="entity"){
  1896. s = this.NumericalToHTML(s);
  1897. }
  1898. return s;
  1899. },
  1900. // Encodes the basic 4 characters used to malform HTML in XSS hacks
  1901. XSSEncode : function(s,en){
  1902. if(!this.isEmpty(s)){
  1903. en = en || true;
  1904. // do we convert to numerical or html entity?
  1905. if(en){
  1906. s = s.replace(/\'/g,"&#39;"); //no HTML equivalent as &apos is not cross browser supported
  1907. s = s.replace(/\"/g,"&quot;");
  1908. s = s.replace(/</g,"&lt;");
  1909. s = s.replace(/>/g,"&gt;");
  1910. }else{
  1911. s = s.replace(/\'/g,"&#39;"); //no HTML equivalent as &apos is not cross browser supported
  1912. s = s.replace(/\"/g,"&#34;");
  1913. s = s.replace(/</g,"&#60;");
  1914. s = s.replace(/>/g,"&#62;");
  1915. }
  1916. return s;
  1917. }else{
  1918. return "";
  1919. }
  1920. },
  1921. // returns true if a string contains html or numerical encoded entities
  1922. hasEncoded : function(s){
  1923. if(/&#[0-9]{1,5};/g.test(s)){
  1924. return true;
  1925. }else if(/&[A-Z]{2,6};/gi.test(s)){
  1926. return true;
  1927. }else{
  1928. return false;
  1929. }
  1930. },
  1931. // will remove any unicode characters
  1932. stripUnicode : function(s){
  1933. return s.replace(/[^\x20-\x7E]/g,"");
  1934. },
  1935. // corrects any double encoded &amp; entities e.g &amp;amp;
  1936. correctEncoding : function(s){
  1937. return s.replace(/(&amp;)(amp;)+/,"$1");
  1938. },
  1939. // Function to loop through an array swaping each item with the value from another array e.g swap HTML entities with Numericals
  1940. swapArrayVals : function(s,arr1,arr2){
  1941. if(this.isEmpty(s)) return "";
  1942. var re;
  1943. if(arr1 && arr2){
  1944. //ShowDebug("in swapArrayVals arr1.length = " + arr1.length + " arr2.length = " + arr2.length)
  1945. // array lengths must match
  1946. if(arr1.length == arr2.length){
  1947. for(var x=0,i=arr1.length;x<i;x++){
  1948. re = new RegExp(arr1[x], 'g');
  1949. s = s.replace(re,arr2[x]); //swap arr1 item with matching item from arr2
  1950. }
  1951. }
  1952. }
  1953. return s;
  1954. },
  1955. inArray : function( item, arr ) {
  1956. for ( var i = 0, x = arr.length; i < x; i++ ){
  1957. if ( arr[i] === item ){
  1958. return i;
  1959. }
  1960. }
  1961. return -1;
  1962. }
  1963. };
  1964. Encoder.EncodeType = "entity";
  1965. var utils = {
  1966. htmlencoder: Encoder,
  1967. convert_meta_to_object: function (data) {
  1968. var converted_data = {},
  1969. element,
  1970. property,
  1971. key;
  1972. for (key in data) {
  1973. if (data.hasOwnProperty(key)) {
  1974. element = key.split(/_(.+)?/)[0];
  1975. property = key.split(/_(.+)?/)[1];
  1976. if (converted_data[element] === undefined) {
  1977. converted_data[element] = {};
  1978. }
  1979. converted_data[element][property] = data[key];
  1980. }
  1981. }
  1982. return converted_data;
  1983. },
  1984. object_to_array: function (object) {
  1985. var array = [],
  1986. i;
  1987. // Convert facets to array (JSON.stringify breaks arrays).
  1988. if (typeof object === 'object') {
  1989. for (i in object) {
  1990. array.push(object[i]);
  1991. }
  1992. object = array;
  1993. }
  1994. return object;
  1995. },
  1996. checked: function (val1, val2, print) {
  1997. var checked = false;
  1998. if (typeof val1 === 'object' && typeof val2 === 'string' && jQuery.inArray(val2, val1) !== -1) {
  1999. checked = true;
  2000. } else if (typeof val2 === 'object' && typeof val1 === 'string' && jQuery.inArray(val1, val2) !== -1) {
  2001. checked = true;
  2002. } else if (val1 === val2) {
  2003. checked = true;
  2004. } else if (val1 == val2) {
  2005. checked = true;
  2006. }
  2007. if (print !== undefined && print) {
  2008. return checked ? ' checked="checked"' : '';
  2009. }
  2010. return checked;
  2011. },
  2012. selected: function (val1, val2, print) {
  2013. var selected = false;
  2014. if (typeof val1 === 'object' && typeof val2 === 'string' && jQuery.inArray(val2, val1) !== -1) {
  2015. selected = true;
  2016. } else if (typeof val2 === 'object' && typeof val1 === 'string' && jQuery.inArray(val1, val2) !== -1) {
  2017. selected = true;
  2018. } else if (val1 === val2) {
  2019. selected = true;
  2020. }
  2021. if (print !== undefined && print) {
  2022. return selected ? ' selected="selected"' : '';
  2023. }
  2024. return selected;
  2025. },
  2026. convert_hex: function (hex, opacity) {
  2027. if (undefined === hex) {
  2028. return '';
  2029. }
  2030. if (undefined === opacity) {
  2031. opacity = 100;
  2032. }
  2033. hex = hex.replace('#', '');
  2034. var r = parseInt(hex.substring(0, 2), 16),
  2035. g = parseInt(hex.substring(2, 4), 16),
  2036. b = parseInt(hex.substring(4, 6), 16),
  2037. result = 'rgba(' + r + ',' + g + ',' + b + ',' + opacity / 100 + ')';
  2038. return result;
  2039. },
  2040. debounce: function (callback, threshold) {
  2041. var timeout;
  2042. return function () {
  2043. var context = this, params = arguments;
  2044. window.clearTimeout(timeout);
  2045. timeout = window.setTimeout(function () {
  2046. callback.apply(context, params);
  2047. }, threshold);
  2048. };
  2049. },
  2050. throttle: function (callback, threshold) {
  2051. var suppress = false,
  2052. clear = function () {
  2053. suppress = false;
  2054. };
  2055. return function () {
  2056. if (!suppress) {
  2057. callback();
  2058. window.setTimeout(clear, threshold);
  2059. suppress = true;
  2060. }
  2061. };
  2062. },
  2063. serializeForm: function (options) {
  2064. $.extend({}, options);
  2065. var values = {},
  2066. settings = $.extend(true, {
  2067. include: [],
  2068. exclude: [],
  2069. includeByClass: ''
  2070. }, options);
  2071. this.find(':input').each(function () {
  2072. var parsedName;
  2073. // Apply simple checks and filters
  2074. if (!this.name || this.disabled ||
  2075. isInArray(settings.exclude, this.name) ||
  2076. (settings.include.length && !isInArray(settings.include, this.name)) ||
  2077. this.className.indexOf(settings.includeByClass) === -1) {
  2078. return;
  2079. }
  2080. // Parse complex names
  2081. // JS RegExp doesn't support "positive look behind" :( that's why so weird parsing is used
  2082. parsedName = this.name.replace(rName, '[$1').split('[');
  2083. if (!parsedName[0]) {
  2084. return;
  2085. }
  2086. if (this.checked ||
  2087. isInArray(inputTypes, this.type) ||
  2088. isInArray(inputNodes, this.nodeName.toLowerCase())) {
  2089. // Simulate control with a complex name (i.e. `some[]`)
  2090. // as it handled in the same way as Checkboxes should
  2091. if (this.type === 'checkbox') {
  2092. parsedName.push('');
  2093. }
  2094. // jQuery.val() is used to simplify of getting values
  2095. // from the custom controls (which follow jQuery .val() API) and Multiple Select
  2096. storeValue(values, parsedName, $(this).val());
  2097. }
  2098. });
  2099. return values;
  2100. }
  2101. };
  2102. // Import this module.
  2103. window.PUM_Admin = window.PUM_Admin || {};
  2104. window.PUM_Admin.utils = utils;
  2105. // @deprecated 1.7.0 Here for backward compatibility.
  2106. window.PUMUtils = utils;
  2107. $.fn.pumSerializeForm = utils.serializeForm;
  2108. }(jQuery));
  2109. /* jshint ignore:start */
  2110. /*!
  2111. * Select2 4.0.2
  2112. * https://select2.github.io
  2113. *
  2114. * Released under the MIT license
  2115. * https://github.com/select2/select2/blob/master/LICENSE.md
  2116. */
  2117. (function (factory) {
  2118. if (typeof define === 'function' && define.amd !== undefined && define.amd) {
  2119. // AMD. Register as an anonymous module.
  2120. define(['jquery'], factory);
  2121. } else if (typeof exports === 'object') {
  2122. // Node/CommonJS
  2123. factory(require('jquery'));
  2124. } else {
  2125. // Browser globals
  2126. factory(jQuery);
  2127. }
  2128. }(function (jQuery) {
  2129. // This is needed so we can catch the AMD loader configuration and use it
  2130. // The inner file should be wrapped (by `banner.start.js`) in a function that
  2131. // returns the AMD loader references.
  2132. var S2 =
  2133. (function () {
  2134. // Restore the Select2 AMD loader so it can be used
  2135. // Needed mostly in the language files, where the loader is not inserted
  2136. if (jQuery && jQuery.fn && jQuery.fn.pumselect2 && jQuery.fn.pumselect2.amd) {
  2137. var S2 = jQuery.fn.pumselect2.amd;
  2138. }
  2139. var S2;(function () { if (!S2 || !S2.requirejs) {
  2140. if (!S2) { S2 = {}; } else { require = S2; }
  2141. /**
  2142. * @license almond 0.3.1 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
  2143. * Available via the MIT or new BSD license.
  2144. * see: http://github.com/jrburke/almond for details
  2145. */
  2146. //Going sloppy to avoid 'use strict' string cost, but strict practices should
  2147. //be followed.
  2148. /*jslint sloppy: true */
  2149. /*global setTimeout: false */
  2150. var requirejs, require, define;
  2151. (function (undef) {
  2152. var main, req, makeMap, handlers,
  2153. defined = {},
  2154. waiting = {},
  2155. config = {},
  2156. defining = {},
  2157. hasOwn = Object.prototype.hasOwnProperty,
  2158. aps = [].slice,
  2159. jsSuffixRegExp = /\.js$/;
  2160. function hasProp(obj, prop) {
  2161. return hasOwn.call(obj, prop);
  2162. }
  2163. /**
  2164. * Given a relative module name, like ./something, normalize it to
  2165. * a real name that can be mapped to a path.
  2166. * @param {String} name the relative name
  2167. * @param {String} baseName a real name that the name arg is relative
  2168. * to.
  2169. * @returns {String} normalized name
  2170. */
  2171. function normalize(name, baseName) {
  2172. var nameParts, nameSegment, mapValue, foundMap, lastIndex,
  2173. foundI, foundStarMap, starI, i, j, part,
  2174. baseParts = baseName && baseName.split("/"),
  2175. map = config.map,
  2176. starMap = (map && map['*']) || {};
  2177. //Adjust any relative paths.
  2178. if (name && name.charAt(0) === ".") {
  2179. //If have a base name, try to normalize against it,
  2180. //otherwise, assume it is a top-level require that will
  2181. //be relative to baseUrl in the end.
  2182. if (baseName) {
  2183. name = name.split('/');
  2184. lastIndex = name.length - 1;
  2185. // Node .js allowance:
  2186. if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
  2187. name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
  2188. }
  2189. //Lop off the last part of baseParts, so that . matches the
  2190. //"directory" and not name of the baseName's module. For instance,
  2191. //baseName of "one/two/three", maps to "one/two/three.js", but we
  2192. //want the directory, "one/two" for this normalization.
  2193. name = baseParts.slice(0, baseParts.length - 1).concat(name);
  2194. //start trimDots
  2195. for (i = 0; i < name.length; i += 1) {
  2196. part = name[i];
  2197. if (part === ".") {
  2198. name.splice(i, 1);
  2199. i -= 1;
  2200. } else if (part === "..") {
  2201. if (i === 1 && (name[2] === '..' || name[0] === '..')) {
  2202. //End of the line. Keep at least one non-dot
  2203. //path segment at the front so it can be mapped
  2204. //correctly to disk. Otherwise, there is likely
  2205. //no path mapping for a path starting with '..'.
  2206. //This can still fail, but catches the most reasonable
  2207. //uses of ..
  2208. break;
  2209. } else if (i > 0) {
  2210. name.splice(i - 1, 2);
  2211. i -= 2;
  2212. }
  2213. }
  2214. }
  2215. //end trimDots
  2216. name = name.join("/");
  2217. } else if (name.indexOf('./') === 0) {
  2218. // No baseName, so this is ID is resolved relative
  2219. // to baseUrl, pull off the leading dot.
  2220. name = name.substring(2);
  2221. }
  2222. }
  2223. //Apply map config if available.
  2224. if ((baseParts || starMap) && map) {
  2225. nameParts = name.split('/');
  2226. for (i = nameParts.length; i > 0; i -= 1) {
  2227. nameSegment = nameParts.slice(0, i).join("/");
  2228. if (baseParts) {
  2229. //Find the longest baseName segment match in the config.
  2230. //So, do joins on the biggest to smallest lengths of baseParts.
  2231. for (j = baseParts.length; j > 0; j -= 1) {
  2232. mapValue = map[baseParts.slice(0, j).join('/')];
  2233. //baseName segment has config, find if it has one for
  2234. //this name.
  2235. if (mapValue) {
  2236. mapValue = mapValue[nameSegment];
  2237. if (mapValue) {
  2238. //Match, update name to the new value.
  2239. foundMap = mapValue;
  2240. foundI = i;
  2241. break;
  2242. }
  2243. }
  2244. }
  2245. }
  2246. if (foundMap) {
  2247. break;
  2248. }
  2249. //Check for a star map match, but just hold on to it,
  2250. //if there is a shorter segment match later in a matching
  2251. //config, then favor over this star map.
  2252. if (!foundStarMap && starMap && starMap[nameSegment]) {
  2253. foundStarMap = starMap[nameSegment];
  2254. starI = i;
  2255. }
  2256. }
  2257. if (!foundMap && foundStarMap) {
  2258. foundMap = foundStarMap;
  2259. foundI = starI;
  2260. }
  2261. if (foundMap) {
  2262. nameParts.splice(0, foundI, foundMap);
  2263. name = nameParts.join('/');
  2264. }
  2265. }
  2266. return name;
  2267. }
  2268. function makeRequire(relName, forceSync) {
  2269. return function () {
  2270. //A version of a require function that passes a moduleName
  2271. //value for items that may need to
  2272. //look up paths relative to the moduleName
  2273. var args = aps.call(arguments, 0);
  2274. //If first arg is not require('string'), and there is only
  2275. //one arg, it is the array form without a callback. Insert
  2276. //a null so that the following concat is correct.
  2277. if (typeof args[0] !== 'string' && args.length === 1) {
  2278. args.push(null);
  2279. }
  2280. return req.apply(undef, args.concat([relName, forceSync]));
  2281. };
  2282. }
  2283. function makeNormalize(relName) {
  2284. return function (name) {
  2285. return normalize(name, relName);
  2286. };
  2287. }
  2288. function makeLoad(depName) {
  2289. return function (value) {
  2290. defined[depName] = value;
  2291. };
  2292. }
  2293. function callDep(name) {
  2294. if (hasProp(waiting, name)) {
  2295. var args = waiting[name];
  2296. delete waiting[name];
  2297. defining[name] = true;
  2298. main.apply(undef, args);
  2299. }
  2300. if (!hasProp(defined, name) && !hasProp(defining, name)) {
  2301. throw new Error('No ' + name);
  2302. }
  2303. return defined[name];
  2304. }
  2305. //Turns a plugin!resource to [plugin, resource]
  2306. //with the plugin being undefined if the name
  2307. //did not have a plugin prefix.
  2308. function splitPrefix(name) {
  2309. var prefix,
  2310. index = name ? name.indexOf('!') : -1;
  2311. if (index > -1) {
  2312. prefix = name.substring(0, index);
  2313. name = name.substring(index + 1, name.length);
  2314. }
  2315. return [prefix, name];
  2316. }
  2317. /**
  2318. * Makes a name map, normalizing the name, and using a plugin
  2319. * for normalization if necessary. Grabs a ref to plugin
  2320. * too, as an optimization.
  2321. */
  2322. makeMap = function (name, relName) {
  2323. var plugin,
  2324. parts = splitPrefix(name),
  2325. prefix = parts[0];
  2326. name = parts[1];
  2327. if (prefix) {
  2328. prefix = normalize(prefix, relName);
  2329. plugin = callDep(prefix);
  2330. }
  2331. //Normalize according
  2332. if (prefix) {
  2333. if (plugin && plugin.normalize) {
  2334. name = plugin.normalize(name, makeNormalize(relName));
  2335. } else {
  2336. name = normalize(name, relName);
  2337. }
  2338. } else {
  2339. name = normalize(name, relName);
  2340. parts = splitPrefix(name);
  2341. prefix = parts[0];
  2342. name = parts[1];
  2343. if (prefix) {
  2344. plugin = callDep(prefix);
  2345. }
  2346. }
  2347. //Using ridiculous property names for space reasons
  2348. return {
  2349. f: prefix ? prefix + '!' + name : name, //fullName
  2350. n: name,
  2351. pr: prefix,
  2352. p: plugin
  2353. };
  2354. };
  2355. function makeConfig(name) {
  2356. return function () {
  2357. return (config && config.config && config.config[name]) || {};
  2358. };
  2359. }
  2360. handlers = {
  2361. require: function (name) {
  2362. return makeRequire(name);
  2363. },
  2364. exports: function (name) {
  2365. var e = defined[name];
  2366. if (typeof e !== 'undefined') {
  2367. return e;
  2368. } else {
  2369. return (defined[name] = {});
  2370. }
  2371. },
  2372. module: function (name) {
  2373. return {
  2374. id: name,
  2375. uri: '',
  2376. exports: defined[name],
  2377. config: makeConfig(name)
  2378. };
  2379. }
  2380. };
  2381. main = function (name, deps, callback, relName) {
  2382. var cjsModule, depName, ret, map, i,
  2383. args = [],
  2384. callbackType = typeof callback,
  2385. usingExports;
  2386. //Use name if no relName
  2387. relName = relName || name;
  2388. //Call the callback to define the module, if necessary.
  2389. if (callbackType === 'undefined' || callbackType === 'function') {
  2390. //Pull out the defined dependencies and pass the ordered
  2391. //values to the callback.
  2392. //Default to [require, exports, module] if no deps
  2393. deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
  2394. for (i = 0; i < deps.length; i += 1) {
  2395. map = makeMap(deps[i], relName);
  2396. depName = map.f;
  2397. //Fast path CommonJS standard dependencies.
  2398. if (depName === "require") {
  2399. args[i] = handlers.require(name);
  2400. } else if (depName === "exports") {
  2401. //CommonJS module spec 1.1
  2402. args[i] = handlers.exports(name);
  2403. usingExports = true;
  2404. } else if (depName === "module") {
  2405. //CommonJS module spec 1.1
  2406. cjsModule = args[i] = handlers.module(name);
  2407. } else if (hasProp(defined, depName) ||
  2408. hasProp(waiting, depName) ||
  2409. hasProp(defining, depName)) {
  2410. args[i] = callDep(depName);
  2411. } else if (map.p) {
  2412. map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {});
  2413. args[i] = defined[depName];
  2414. } else {
  2415. throw new Error(name + ' missing ' + depName);
  2416. }
  2417. }
  2418. ret = callback ? callback.apply(defined[name], args) : undefined;
  2419. if (name) {
  2420. //If setting exports via "module" is in play,
  2421. //favor that over return value and exports. After that,
  2422. //favor a non-undefined return value over exports use.
  2423. if (cjsModule && cjsModule.exports !== undef &&
  2424. cjsModule.exports !== defined[name]) {
  2425. defined[name] = cjsModule.exports;
  2426. } else if (ret !== undef || !usingExports) {
  2427. //Use the return value from the function.
  2428. defined[name] = ret;
  2429. }
  2430. }
  2431. } else if (name) {
  2432. //May just be an object definition for the module. Only
  2433. //worry about defining if have a module name.
  2434. defined[name] = callback;
  2435. }
  2436. };
  2437. requirejs = require = req = function (deps, callback, relName, forceSync, alt) {
  2438. if (typeof deps === "string") {
  2439. if (handlers[deps]) {
  2440. //callback in this case is really relName
  2441. return handlers[deps](callback);
  2442. }
  2443. //Just return the module wanted. In this scenario, the
  2444. //deps arg is the module name, and second arg (if passed)
  2445. //is just the relName.
  2446. //Normalize module name, if it contains . or ..
  2447. return callDep(makeMap(deps, callback).f);
  2448. } else if (!deps.splice) {
  2449. //deps is a config object, not an array.
  2450. config = deps;
  2451. if (config.deps) {
  2452. req(config.deps, config.callback);
  2453. }
  2454. if (!callback) {
  2455. return;
  2456. }
  2457. if (callback.splice) {
  2458. //callback is an array, which means it is a dependency list.
  2459. //Adjust args if there are dependencies
  2460. deps = callback;
  2461. callback = relName;
  2462. relName = null;
  2463. } else {
  2464. deps = undef;
  2465. }
  2466. }
  2467. //Support require(['a'])
  2468. callback = callback || function () {};
  2469. //If relName is a function, it is an errback handler,
  2470. //so remove it.
  2471. if (typeof relName === 'function') {
  2472. relName = forceSync;
  2473. forceSync = alt;
  2474. }
  2475. //Simulate async callback;
  2476. if (forceSync) {
  2477. main(undef, deps, callback, relName);
  2478. } else {
  2479. //Using a non-zero value because of concern for what old browsers
  2480. //do, and latest browsers "upgrade" to 4 if lower value is used:
  2481. //http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#dom-windowtimers-settimeout:
  2482. //If want a value immediately, use require('id') instead -- something
  2483. //that works in almond on the global level, but not guaranteed and
  2484. //unlikely to work in other AMD implementations.
  2485. setTimeout(function () {
  2486. main(undef, deps, callback, relName);
  2487. }, 4);
  2488. }
  2489. return req;
  2490. };
  2491. /**
  2492. * Just drops the config on the floor, but returns req in case
  2493. * the config return value is used.
  2494. */
  2495. req.config = function (cfg) {
  2496. return req(cfg);
  2497. };
  2498. /**
  2499. * Expose module registry for debugging and tooling
  2500. */
  2501. requirejs._defined = defined;
  2502. define = function (name, deps, callback) {
  2503. if (typeof name !== 'string') {
  2504. throw new Error('See almond README: incorrect module build, no module name');
  2505. }
  2506. //This module may not have dependencies
  2507. if (!deps.splice) {
  2508. //deps is not an array, so probably means
  2509. //an object literal or factory function for
  2510. //the value. Adjust args.
  2511. callback = deps;
  2512. deps = [];
  2513. }
  2514. if (!hasProp(defined, name) && !hasProp(waiting, name)) {
  2515. waiting[name] = [name, deps, callback];
  2516. }
  2517. };
  2518. define.amd = {
  2519. jQuery: true
  2520. };
  2521. }());
  2522. S2.requirejs = requirejs;S2.require = require;S2.define = define;
  2523. }
  2524. }());
  2525. S2.define("almond", function(){});
  2526. /* global jQuery:false, $:false */
  2527. S2.define('jquery',[],function () {
  2528. var _$ = jQuery || $;
  2529. if (_$ == null && console && console.error) {
  2530. console.error(
  2531. 'Select2: An instance of jQuery or a jQuery-compatible library was not ' +
  2532. 'found. Make sure that you are including jQuery before Select2 on your ' +
  2533. 'web page.'
  2534. );
  2535. }
  2536. return _$;
  2537. });
  2538. S2.define('pumselect2/utils',[
  2539. 'jquery'
  2540. ], function ($) {
  2541. var Utils = {};
  2542. Utils.Extend = function (ChildClass, SuperClass) {
  2543. var __hasProp = {}.hasOwnProperty;
  2544. function BaseConstructor () {
  2545. this.constructor = ChildClass;
  2546. }
  2547. for (var key in SuperClass) {
  2548. if (__hasProp.call(SuperClass, key)) {
  2549. ChildClass[key] = SuperClass[key];
  2550. }
  2551. }
  2552. BaseConstructor.prototype = SuperClass.prototype;
  2553. ChildClass.prototype = new BaseConstructor();
  2554. ChildClass.__super__ = SuperClass.prototype;
  2555. return ChildClass;
  2556. };
  2557. function getMethods (theClass) {
  2558. var proto = theClass.prototype;
  2559. var methods = [];
  2560. for (var methodName in proto) {
  2561. var m = proto[methodName];
  2562. if (typeof m !== 'function') {
  2563. continue;
  2564. }
  2565. if (methodName === 'constructor') {
  2566. continue;
  2567. }
  2568. methods.push(methodName);
  2569. }
  2570. return methods;
  2571. }
  2572. Utils.Decorate = function (SuperClass, DecoratorClass) {
  2573. var decoratedMethods = getMethods(DecoratorClass);
  2574. var superMethods = getMethods(SuperClass);
  2575. function DecoratedClass () {
  2576. var unshift = Array.prototype.unshift;
  2577. var argCount = DecoratorClass.prototype.constructor.length;
  2578. var calledConstructor = SuperClass.prototype.constructor;
  2579. if (argCount > 0) {
  2580. unshift.call(arguments, SuperClass.prototype.constructor);
  2581. calledConstructor = DecoratorClass.prototype.constructor;
  2582. }
  2583. calledConstructor.apply(this, arguments);
  2584. }
  2585. DecoratorClass.displayName = SuperClass.displayName;
  2586. function ctr () {
  2587. this.constructor = DecoratedClass;
  2588. }
  2589. DecoratedClass.prototype = new ctr();
  2590. for (var m = 0; m < superMethods.length; m++) {
  2591. var superMethod = superMethods[m];
  2592. DecoratedClass.prototype[superMethod] =
  2593. SuperClass.prototype[superMethod];
  2594. }
  2595. var calledMethod = function (methodName) {
  2596. // Stub out the original method if it's not decorating an actual method
  2597. var originalMethod = function () {};
  2598. if (methodName in DecoratedClass.prototype) {
  2599. originalMethod = DecoratedClass.prototype[methodName];
  2600. }
  2601. var decoratedMethod = DecoratorClass.prototype[methodName];
  2602. return function () {
  2603. var unshift = Array.prototype.unshift;
  2604. unshift.call(arguments, originalMethod);
  2605. return decoratedMethod.apply(this, arguments);
  2606. };
  2607. };
  2608. for (var d = 0; d < decoratedMethods.length; d++) {
  2609. var decoratedMethod = decoratedMethods[d];
  2610. DecoratedClass.prototype[decoratedMethod] = calledMethod(decoratedMethod);
  2611. }
  2612. return DecoratedClass;
  2613. };
  2614. var Observable = function () {
  2615. this.listeners = {};
  2616. };
  2617. Observable.prototype.on = function (event, callback) {
  2618. this.listeners = this.listeners || {};
  2619. if (event in this.listeners) {
  2620. this.listeners[event].push(callback);
  2621. } else {
  2622. this.listeners[event] = [callback];
  2623. }
  2624. };
  2625. Observable.prototype.trigger = function (event) {
  2626. var slice = Array.prototype.slice;
  2627. this.listeners = this.listeners || {};
  2628. if (event in this.listeners) {
  2629. this.invoke(this.listeners[event], slice.call(arguments, 1));
  2630. }
  2631. if ('*' in this.listeners) {
  2632. this.invoke(this.listeners['*'], arguments);
  2633. }
  2634. };
  2635. Observable.prototype.invoke = function (listeners, params) {
  2636. for (var i = 0, len = listeners.length; i < len; i++) {
  2637. listeners[i].apply(this, params);
  2638. }
  2639. };
  2640. Utils.Observable = Observable;
  2641. Utils.generateChars = function (length) {
  2642. var chars = '';
  2643. for (var i = 0; i < length; i++) {
  2644. var randomChar = Math.floor(Math.random() * 36);
  2645. chars += randomChar.toString(36);
  2646. }
  2647. return chars;
  2648. };
  2649. Utils.bind = function (func, context) {
  2650. return function () {
  2651. func.apply(context, arguments);
  2652. };
  2653. };
  2654. Utils._convertData = function (data) {
  2655. for (var originalKey in data) {
  2656. var keys = originalKey.split('-');
  2657. var dataLevel = data;
  2658. if (keys.length === 1) {
  2659. continue;
  2660. }
  2661. for (var k = 0; k < keys.length; k++) {
  2662. var key = keys[k];
  2663. // Lowercase the first letter
  2664. // By default, dash-separated becomes camelCase
  2665. key = key.substring(0, 1).toLowerCase() + key.substring(1);
  2666. if (!(key in dataLevel)) {
  2667. dataLevel[key] = {};
  2668. }
  2669. if (k == keys.length - 1) {
  2670. dataLevel[key] = data[originalKey];
  2671. }
  2672. dataLevel = dataLevel[key];
  2673. }
  2674. delete data[originalKey];
  2675. }
  2676. return data;
  2677. };
  2678. Utils.hasScroll = function (index, el) {
  2679. // Adapted from the function created by @ShadowScripter
  2680. // and adapted by @BillBarry on the Stack Exchange Code Review website.
  2681. // The original code can be found at
  2682. // http://codereview.stackexchange.com/q/13338
  2683. // and was designed to be used with the Sizzle selector engine.
  2684. var $el = $(el);
  2685. var overflowX = el.style.overflowX;
  2686. var overflowY = el.style.overflowY;
  2687. //Check both x and y declarations
  2688. if (overflowX === overflowY &&
  2689. (overflowY === 'hidden' || overflowY === 'visible')) {
  2690. return false;
  2691. }
  2692. if (overflowX === 'scroll' || overflowY === 'scroll') {
  2693. return true;
  2694. }
  2695. return ($el.innerHeight() < el.scrollHeight ||
  2696. $el.innerWidth() < el.scrollWidth);
  2697. };
  2698. Utils.escapeMarkup = function (markup) {
  2699. var replaceMap = {
  2700. '\\': '&#92;',
  2701. '&': '&amp;',
  2702. '<': '&lt;',
  2703. '>': '&gt;',
  2704. '"': '&quot;',
  2705. '\'': '&#39;',
  2706. '/': '&#47;'
  2707. };
  2708. // Do not try to escape the markup if it's not a string
  2709. if (typeof markup !== 'string') {
  2710. return markup;
  2711. }
  2712. return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
  2713. return replaceMap[match];
  2714. });
  2715. };
  2716. // Append an array of jQuery nodes to a given element.
  2717. Utils.appendMany = function ($element, $nodes) {
  2718. // jQuery 1.7.x does not support $.fn.append() with an array
  2719. // Fall back to a jQuery object collection using $.fn.add()
  2720. if ($.fn.jquery.substr(0, 3) === '1.7') {
  2721. var $jqNodes = $();
  2722. $.map($nodes, function (node) {
  2723. $jqNodes = $jqNodes.add(node);
  2724. });
  2725. $nodes = $jqNodes;
  2726. }
  2727. $element.append($nodes);
  2728. };
  2729. return Utils;
  2730. });
  2731. S2.define('pumselect2/results',[
  2732. 'jquery',
  2733. './utils'
  2734. ], function ($, Utils) {
  2735. function Results ($element, options, dataAdapter) {
  2736. this.$element = $element;
  2737. this.data = dataAdapter;
  2738. this.options = options;
  2739. Results.__super__.constructor.call(this);
  2740. }
  2741. Utils.Extend(Results, Utils.Observable);
  2742. Results.prototype.render = function () {
  2743. var $results = $(
  2744. '<ul class="pumselect2-results__options" role="tree"></ul>'
  2745. );
  2746. if (this.options.get('multiple')) {
  2747. $results.attr('aria-multiselectable', 'true');
  2748. }
  2749. this.$results = $results;
  2750. return $results;
  2751. };
  2752. Results.prototype.clear = function () {
  2753. this.$results.empty();
  2754. };
  2755. Results.prototype.displayMessage = function (params) {
  2756. var escapeMarkup = this.options.get('escapeMarkup');
  2757. this.clear();
  2758. this.hideLoading();
  2759. var $message = $(
  2760. '<li role="treeitem" aria-live="assertive"' +
  2761. ' class="pumselect2-results__option"></li>'
  2762. );
  2763. var message = this.options.get('translations').get(params.message);
  2764. $message.append(
  2765. escapeMarkup(
  2766. message(params.args)
  2767. )
  2768. );
  2769. $message[0].className += ' pumselect2-results__message';
  2770. this.$results.append($message);
  2771. };
  2772. Results.prototype.hideMessages = function () {
  2773. this.$results.find('.pumselect2-results__message').remove();
  2774. };
  2775. Results.prototype.append = function (data) {
  2776. this.hideLoading();
  2777. var $options = [];
  2778. if (data.results == null || data.results.length === 0) {
  2779. if (this.$results.children().length === 0) {
  2780. this.trigger('results:message', {
  2781. message: 'noResults'
  2782. });
  2783. }
  2784. return;
  2785. }
  2786. data.results = this.sort(data.results);
  2787. for (var d = 0; d < data.results.length; d++) {
  2788. var item = data.results[d];
  2789. var $option = this.option(item);
  2790. $options.push($option);
  2791. }
  2792. this.$results.append($options);
  2793. };
  2794. Results.prototype.position = function ($results, $dropdown) {
  2795. var $resultsContainer = $dropdown.find('.pumselect2-results');
  2796. $resultsContainer.append($results);
  2797. };
  2798. Results.prototype.sort = function (data) {
  2799. var sorter = this.options.get('sorter');
  2800. return sorter(data);
  2801. };
  2802. Results.prototype.setClasses = function () {
  2803. var self = this;
  2804. this.data.current(function (selected) {
  2805. var selectedIds = $.map(selected, function (s) {
  2806. return s.id.toString();
  2807. });
  2808. var $options = self.$results
  2809. .find('.pumselect2-results__option[aria-selected]');
  2810. $options.each(function () {
  2811. var $option = $(this);
  2812. var item = $.data(this, 'data');
  2813. // id needs to be converted to a string when comparing
  2814. var id = '' + item.id;
  2815. if ((item.element != null && item.element.selected) ||
  2816. (item.element == null && $.inArray(id, selectedIds) > -1)) {
  2817. $option.attr('aria-selected', 'true');
  2818. } else {
  2819. $option.attr('aria-selected', 'false');
  2820. }
  2821. });
  2822. var $selected = $options.filter('[aria-selected=true]');
  2823. // Check if there are any selected options
  2824. if ($selected.length > 0) {
  2825. // If there are selected options, highlight the first
  2826. $selected.first().trigger('mouseenter');
  2827. } else {
  2828. // If there are no selected options, highlight the first option
  2829. // in the dropdown
  2830. $options.first().trigger('mouseenter');
  2831. }
  2832. });
  2833. };
  2834. Results.prototype.showLoading = function (params) {
  2835. this.hideLoading();
  2836. var loadingMore = this.options.get('translations').get('searching');
  2837. var loading = {
  2838. disabled: true,
  2839. loading: true,
  2840. text: loadingMore(params)
  2841. };
  2842. var $loading = this.option(loading);
  2843. $loading.className += ' loading-results';
  2844. this.$results.prepend($loading);
  2845. };
  2846. Results.prototype.hideLoading = function () {
  2847. this.$results.find('.loading-results').remove();
  2848. };
  2849. Results.prototype.option = function (data) {
  2850. var option = document.createElement('li');
  2851. option.className = 'pumselect2-results__option';
  2852. var attrs = {
  2853. 'role': 'treeitem',
  2854. 'aria-selected': 'false'
  2855. };
  2856. if (data.disabled) {
  2857. delete attrs['aria-selected'];
  2858. attrs['aria-disabled'] = 'true';
  2859. }
  2860. if (data.id == null) {
  2861. delete attrs['aria-selected'];
  2862. }
  2863. if (data._resultId != null) {
  2864. option.id = data._resultId;
  2865. }
  2866. if (data.title) {
  2867. option.title = data.title;
  2868. }
  2869. if (data.children) {
  2870. attrs.role = 'group';
  2871. attrs['aria-label'] = data.text;
  2872. delete attrs['aria-selected'];
  2873. }
  2874. for (var attr in attrs) {
  2875. var val = attrs[attr];
  2876. option.setAttribute(attr, val);
  2877. }
  2878. if (data.children) {
  2879. var $option = $(option);
  2880. var label = document.createElement('strong');
  2881. label.className = 'pumselect2-results__group';
  2882. var $label = $(label);
  2883. this.template(data, label);
  2884. var $children = [];
  2885. for (var c = 0; c < data.children.length; c++) {
  2886. var child = data.children[c];
  2887. var $child = this.option(child);
  2888. $children.push($child);
  2889. }
  2890. var $childrenContainer = $('<ul></ul>', {
  2891. 'class': 'pumselect2-results__options pumselect2-results__options--nested'
  2892. });
  2893. $childrenContainer.append($children);
  2894. $option.append(label);
  2895. $option.append($childrenContainer);
  2896. } else {
  2897. this.template(data, option);
  2898. }
  2899. $.data(option, 'data', data);
  2900. return option;
  2901. };
  2902. Results.prototype.bind = function (container, $container) {
  2903. var self = this;
  2904. var id = container.id + '-results';
  2905. this.$results.attr('id', id);
  2906. container.on('results:all', function (params) {
  2907. self.clear();
  2908. self.append(params.data);
  2909. if (container.isOpen()) {
  2910. self.setClasses();
  2911. }
  2912. });
  2913. container.on('results:append', function (params) {
  2914. self.append(params.data);
  2915. if (container.isOpen()) {
  2916. self.setClasses();
  2917. }
  2918. });
  2919. container.on('query', function (params) {
  2920. self.hideMessages();
  2921. self.showLoading(params);
  2922. });
  2923. container.on('select', function () {
  2924. if (!container.isOpen()) {
  2925. return;
  2926. }
  2927. self.setClasses();
  2928. });
  2929. container.on('unselect', function () {
  2930. if (!container.isOpen()) {
  2931. return;
  2932. }
  2933. self.setClasses();
  2934. });
  2935. container.on('open', function () {
  2936. // When the dropdown is open, aria-expended="true"
  2937. self.$results.attr('aria-expanded', 'true');
  2938. self.$results.attr('aria-hidden', 'false');
  2939. self.setClasses();
  2940. self.ensureHighlightVisible();
  2941. });
  2942. container.on('close', function () {
  2943. // When the dropdown is closed, aria-expended="false"
  2944. self.$results.attr('aria-expanded', 'false');
  2945. self.$results.attr('aria-hidden', 'true');
  2946. self.$results.removeAttr('aria-activedescendant');
  2947. });
  2948. container.on('results:toggle', function () {
  2949. var $highlighted = self.getHighlightedResults();
  2950. if ($highlighted.length === 0) {
  2951. return;
  2952. }
  2953. $highlighted.trigger('mouseup');
  2954. });
  2955. container.on('results:select', function () {
  2956. var $highlighted = self.getHighlightedResults();
  2957. if ($highlighted.length === 0) {
  2958. return;
  2959. }
  2960. var data = $highlighted.data('data');
  2961. if ($highlighted.attr('aria-selected') == 'true') {
  2962. self.trigger('close', {});
  2963. } else {
  2964. self.trigger('select', {
  2965. data: data
  2966. });
  2967. }
  2968. });
  2969. container.on('results:previous', function () {
  2970. var $highlighted = self.getHighlightedResults();
  2971. var $options = self.$results.find('[aria-selected]');
  2972. var currentIndex = $options.index($highlighted);
  2973. // If we are already at te top, don't move further
  2974. if (currentIndex === 0) {
  2975. return;
  2976. }
  2977. var nextIndex = currentIndex - 1;
  2978. // If none are highlighted, highlight the first
  2979. if ($highlighted.length === 0) {
  2980. nextIndex = 0;
  2981. }
  2982. var $next = $options.eq(nextIndex);
  2983. $next.trigger('mouseenter');
  2984. var currentOffset = self.$results.offset().top;
  2985. var nextTop = $next.offset().top;
  2986. var nextOffset = self.$results.scrollTop() + (nextTop - currentOffset);
  2987. if (nextIndex === 0) {
  2988. self.$results.scrollTop(0);
  2989. } else if (nextTop - currentOffset < 0) {
  2990. self.$results.scrollTop(nextOffset);
  2991. }
  2992. });
  2993. container.on('results:next', function () {
  2994. var $highlighted = self.getHighlightedResults();
  2995. var $options = self.$results.find('[aria-selected]');
  2996. var currentIndex = $options.index($highlighted);
  2997. var nextIndex = currentIndex + 1;
  2998. // If we are at the last option, stay there
  2999. if (nextIndex >= $options.length) {
  3000. return;
  3001. }
  3002. var $next = $options.eq(nextIndex);
  3003. $next.trigger('mouseenter');
  3004. var currentOffset = self.$results.offset().top +
  3005. self.$results.outerHeight(false);
  3006. var nextBottom = $next.offset().top + $next.outerHeight(false);
  3007. var nextOffset = self.$results.scrollTop() + nextBottom - currentOffset;
  3008. if (nextIndex === 0) {
  3009. self.$results.scrollTop(0);
  3010. } else if (nextBottom > currentOffset) {
  3011. self.$results.scrollTop(nextOffset);
  3012. }
  3013. });
  3014. container.on('results:focus', function (params) {
  3015. params.element.addClass('pumselect2-results__option--highlighted');
  3016. });
  3017. container.on('results:message', function (params) {
  3018. self.displayMessage(params);
  3019. });
  3020. if ($.fn.mousewheel) {
  3021. this.$results.on('mousewheel', function (e) {
  3022. var top = self.$results.scrollTop();
  3023. var bottom = self.$results.get(0).scrollHeight - top + e.deltaY;
  3024. var isAtTop = e.deltaY > 0 && top - e.deltaY <= 0;
  3025. var isAtBottom = e.deltaY < 0 && bottom <= self.$results.height();
  3026. if (isAtTop) {
  3027. self.$results.scrollTop(0);
  3028. e.preventDefault();
  3029. e.stopPropagation();
  3030. } else if (isAtBottom) {
  3031. self.$results.scrollTop(
  3032. self.$results.get(0).scrollHeight - self.$results.height()
  3033. );
  3034. e.preventDefault();
  3035. e.stopPropagation();
  3036. }
  3037. });
  3038. }
  3039. this.$results.on('mouseup', '.pumselect2-results__option[aria-selected]',
  3040. function (evt) {
  3041. var $this = $(this);
  3042. var data = $this.data('data');
  3043. if ($this.attr('aria-selected') === 'true') {
  3044. if (self.options.get('multiple')) {
  3045. self.trigger('unselect', {
  3046. originalEvent: evt,
  3047. data: data
  3048. });
  3049. } else {
  3050. self.trigger('close', {});
  3051. }
  3052. return;
  3053. }
  3054. self.trigger('select', {
  3055. originalEvent: evt,
  3056. data: data
  3057. });
  3058. });
  3059. this.$results.on('mouseenter', '.pumselect2-results__option[aria-selected]',
  3060. function (evt) {
  3061. var data = $(this).data('data');
  3062. self.getHighlightedResults()
  3063. .removeClass('pumselect2-results__option--highlighted');
  3064. self.trigger('results:focus', {
  3065. data: data,
  3066. element: $(this)
  3067. });
  3068. });
  3069. };
  3070. Results.prototype.getHighlightedResults = function () {
  3071. var $highlighted = this.$results
  3072. .find('.pumselect2-results__option--highlighted');
  3073. return $highlighted;
  3074. };
  3075. Results.prototype.destroy = function () {
  3076. this.$results.remove();
  3077. };
  3078. Results.prototype.ensureHighlightVisible = function () {
  3079. var $highlighted = this.getHighlightedResults();
  3080. if ($highlighted.length === 0) {
  3081. return;
  3082. }
  3083. var $options = this.$results.find('[aria-selected]');
  3084. var currentIndex = $options.index($highlighted);
  3085. var currentOffset = this.$results.offset().top;
  3086. var nextTop = $highlighted.offset().top;
  3087. var nextOffset = this.$results.scrollTop() + (nextTop - currentOffset);
  3088. var offsetDelta = nextTop - currentOffset;
  3089. nextOffset -= $highlighted.outerHeight(false) * 2;
  3090. if (currentIndex <= 2) {
  3091. this.$results.scrollTop(0);
  3092. } else if (offsetDelta > this.$results.outerHeight() || offsetDelta < 0) {
  3093. this.$results.scrollTop(nextOffset);
  3094. }
  3095. };
  3096. Results.prototype.template = function (result, container) {
  3097. var template = this.options.get('templateResult');
  3098. var escapeMarkup = this.options.get('escapeMarkup');
  3099. var content = template(result, container);
  3100. if (content == null) {
  3101. container.style.display = 'none';
  3102. } else if (typeof content === 'string') {
  3103. container.innerHTML = escapeMarkup(content);
  3104. } else {
  3105. $(container).append(content);
  3106. }
  3107. };
  3108. return Results;
  3109. });
  3110. S2.define('pumselect2/keys',[
  3111. ], function () {
  3112. var KEYS = {
  3113. BACKSPACE: 8,
  3114. TAB: 9,
  3115. ENTER: 13,
  3116. SHIFT: 16,
  3117. CTRL: 17,
  3118. ALT: 18,
  3119. ESC: 27,
  3120. SPACE: 32,
  3121. PAGE_UP: 33,
  3122. PAGE_DOWN: 34,
  3123. END: 35,
  3124. HOME: 36,
  3125. LEFT: 37,
  3126. UP: 38,
  3127. RIGHT: 39,
  3128. DOWN: 40,
  3129. DELETE: 46
  3130. };
  3131. return KEYS;
  3132. });
  3133. S2.define('pumselect2/selection/base',[
  3134. 'jquery',
  3135. '../utils',
  3136. '../keys'
  3137. ], function ($, Utils, KEYS) {
  3138. function BaseSelection ($element, options) {
  3139. this.$element = $element;
  3140. this.options = options;
  3141. BaseSelection.__super__.constructor.call(this);
  3142. }
  3143. Utils.Extend(BaseSelection, Utils.Observable);
  3144. BaseSelection.prototype.render = function () {
  3145. var $selection = $(
  3146. '<span class="pumselect2-selection" role="combobox" ' +
  3147. ' aria-haspopup="true" aria-expanded="false">' +
  3148. '</span>'
  3149. );
  3150. this._tabindex = 0;
  3151. if (this.$element.data('old-tabindex') != null) {
  3152. this._tabindex = this.$element.data('old-tabindex');
  3153. } else if (this.$element.attr('tabindex') != null) {
  3154. this._tabindex = this.$element.attr('tabindex');
  3155. }
  3156. $selection.attr('title', this.$element.attr('title'));
  3157. $selection.attr('tabindex', this._tabindex);
  3158. this.$selection = $selection;
  3159. return $selection;
  3160. };
  3161. BaseSelection.prototype.bind = function (container, $container) {
  3162. var self = this;
  3163. var id = container.id + '-container';
  3164. var resultsId = container.id + '-results';
  3165. this.container = container;
  3166. this.$selection.on('focus', function (evt) {
  3167. self.trigger('focus', evt);
  3168. });
  3169. this.$selection.on('blur', function (evt) {
  3170. self._handleBlur(evt);
  3171. });
  3172. this.$selection.on('keydown', function (evt) {
  3173. self.trigger('keypress', evt);
  3174. if (evt.which === KEYS.SPACE) {
  3175. evt.preventDefault();
  3176. }
  3177. });
  3178. container.on('results:focus', function (params) {
  3179. self.$selection.attr('aria-activedescendant', params.data._resultId);
  3180. });
  3181. container.on('selection:update', function (params) {
  3182. self.update(params.data);
  3183. });
  3184. container.on('open', function () {
  3185. // When the dropdown is open, aria-expanded="true"
  3186. self.$selection.attr('aria-expanded', 'true');
  3187. self.$selection.attr('aria-owns', resultsId);
  3188. self._attachCloseHandler(container);
  3189. });
  3190. container.on('close', function () {
  3191. // When the dropdown is closed, aria-expanded="false"
  3192. self.$selection.attr('aria-expanded', 'false');
  3193. self.$selection.removeAttr('aria-activedescendant');
  3194. self.$selection.removeAttr('aria-owns');
  3195. self.$selection.focus();
  3196. self._detachCloseHandler(container);
  3197. });
  3198. container.on('enable', function () {
  3199. self.$selection.attr('tabindex', self._tabindex);
  3200. });
  3201. container.on('disable', function () {
  3202. self.$selection.attr('tabindex', '-1');
  3203. });
  3204. };
  3205. BaseSelection.prototype._handleBlur = function (evt) {
  3206. var self = this;
  3207. // This needs to be delayed as the active element is the body when the tab
  3208. // key is pressed, possibly along with others.
  3209. window.setTimeout(function () {
  3210. // Don't trigger `blur` if the focus is still in the selection
  3211. if (
  3212. (document.activeElement == self.$selection[0]) ||
  3213. ($.contains(self.$selection[0], document.activeElement))
  3214. ) {
  3215. return;
  3216. }
  3217. self.trigger('blur', evt);
  3218. }, 1);
  3219. };
  3220. BaseSelection.prototype._attachCloseHandler = function (container) {
  3221. var self = this;
  3222. $(document.body).on('mousedown.pumselect2.' + container.id, function (e) {
  3223. var $target = $(e.target);
  3224. var $select = $target.closest('.pumselect2');
  3225. var $all = $('.pumselect2.pumselect2-container--open');
  3226. $all.each(function () {
  3227. var $this = $(this);
  3228. if (this == $select[0]) {
  3229. return;
  3230. }
  3231. var $element = $this.data('element');
  3232. $element.pumselect2('close');
  3233. });
  3234. });
  3235. };
  3236. BaseSelection.prototype._detachCloseHandler = function (container) {
  3237. $(document.body).off('mousedown.pumselect2.' + container.id);
  3238. };
  3239. BaseSelection.prototype.position = function ($selection, $container) {
  3240. var $selectionContainer = $container.find('.selection');
  3241. $selectionContainer.append($selection);
  3242. };
  3243. BaseSelection.prototype.destroy = function () {
  3244. this._detachCloseHandler(this.container);
  3245. };
  3246. BaseSelection.prototype.update = function (data) {
  3247. throw new Error('The `update` method must be defined in child classes.');
  3248. };
  3249. return BaseSelection;
  3250. });
  3251. S2.define('pumselect2/selection/single',[
  3252. 'jquery',
  3253. './base',
  3254. '../utils',
  3255. '../keys'
  3256. ], function ($, BaseSelection, Utils, KEYS) {
  3257. function SingleSelection () {
  3258. SingleSelection.__super__.constructor.apply(this, arguments);
  3259. }
  3260. Utils.Extend(SingleSelection, BaseSelection);
  3261. SingleSelection.prototype.render = function () {
  3262. var $selection = SingleSelection.__super__.render.call(this);
  3263. $selection.addClass('pumselect2-selection--single');
  3264. $selection.html(
  3265. '<span class="pumselect2-selection__rendered"></span>' +
  3266. '<span class="pumselect2-selection__arrow" role="presentation">' +
  3267. '<b role="presentation"></b>' +
  3268. '</span>'
  3269. );
  3270. return $selection;
  3271. };
  3272. SingleSelection.prototype.bind = function (container, $container) {
  3273. var self = this;
  3274. SingleSelection.__super__.bind.apply(this, arguments);
  3275. var id = container.id + '-container';
  3276. this.$selection.find('.pumselect2-selection__rendered').attr('id', id);
  3277. this.$selection.attr('aria-labelledby', id);
  3278. this.$selection.on('mousedown', function (evt) {
  3279. // Only respond to left clicks
  3280. if (evt.which !== 1) {
  3281. return;
  3282. }
  3283. self.trigger('toggle', {
  3284. originalEvent: evt
  3285. });
  3286. });
  3287. this.$selection.on('focus', function (evt) {
  3288. // User focuses on the container
  3289. });
  3290. this.$selection.on('blur', function (evt) {
  3291. // User exits the container
  3292. });
  3293. container.on('selection:update', function (params) {
  3294. self.update(params.data);
  3295. });
  3296. };
  3297. SingleSelection.prototype.clear = function () {
  3298. this.$selection.find('.pumselect2-selection__rendered').empty();
  3299. };
  3300. SingleSelection.prototype.display = function (data, container) {
  3301. var template = this.options.get('templateSelection');
  3302. var escapeMarkup = this.options.get('escapeMarkup');
  3303. return escapeMarkup(template(data, container));
  3304. };
  3305. SingleSelection.prototype.selectionContainer = function () {
  3306. return $('<span></span>');
  3307. };
  3308. SingleSelection.prototype.update = function (data) {
  3309. if (data.length === 0) {
  3310. this.clear();
  3311. return;
  3312. }
  3313. var selection = data[0];
  3314. var $rendered = this.$selection.find('.pumselect2-selection__rendered');
  3315. var formatted = this.display(selection, $rendered);
  3316. $rendered.empty().append(formatted);
  3317. $rendered.prop('title', selection.title || selection.text);
  3318. };
  3319. return SingleSelection;
  3320. });
  3321. S2.define('pumselect2/selection/multiple',[
  3322. 'jquery',
  3323. './base',
  3324. '../utils'
  3325. ], function ($, BaseSelection, Utils) {
  3326. function MultipleSelection ($element, options) {
  3327. MultipleSelection.__super__.constructor.apply(this, arguments);
  3328. }
  3329. Utils.Extend(MultipleSelection, BaseSelection);
  3330. MultipleSelection.prototype.render = function () {
  3331. var $selection = MultipleSelection.__super__.render.call(this);
  3332. $selection.addClass('pumselect2-selection--multiple');
  3333. $selection.html(
  3334. '<ul class="pumselect2-selection__rendered"></ul>'
  3335. );
  3336. return $selection;
  3337. };
  3338. MultipleSelection.prototype.bind = function (container, $container) {
  3339. var self = this;
  3340. MultipleSelection.__super__.bind.apply(this, arguments);
  3341. this.$selection.on('click', function (evt) {
  3342. self.trigger('toggle', {
  3343. originalEvent: evt
  3344. });
  3345. });
  3346. this.$selection.on(
  3347. 'click',
  3348. '.pumselect2-selection__choice__remove',
  3349. function (evt) {
  3350. // Ignore the event if it is disabled
  3351. if (self.options.get('disabled')) {
  3352. return;
  3353. }
  3354. var $remove = $(this);
  3355. var $selection = $remove.parent();
  3356. var data = $selection.data('data');
  3357. self.trigger('unselect', {
  3358. originalEvent: evt,
  3359. data: data
  3360. });
  3361. }
  3362. );
  3363. };
  3364. MultipleSelection.prototype.clear = function () {
  3365. this.$selection.find('.pumselect2-selection__rendered').empty();
  3366. };
  3367. MultipleSelection.prototype.display = function (data, container) {
  3368. var template = this.options.get('templateSelection');
  3369. var escapeMarkup = this.options.get('escapeMarkup');
  3370. return escapeMarkup(template(data, container));
  3371. };
  3372. MultipleSelection.prototype.selectionContainer = function () {
  3373. var $container = $(
  3374. '<li class="pumselect2-selection__choice">' +
  3375. '<span class="pumselect2-selection__choice__remove" role="presentation">' +
  3376. '&times;' +
  3377. '</span>' +
  3378. '</li>'
  3379. );
  3380. return $container;
  3381. };
  3382. MultipleSelection.prototype.update = function (data) {
  3383. this.clear();
  3384. if (data.length === 0) {
  3385. return;
  3386. }
  3387. var $selections = [];
  3388. for (var d = 0; d < data.length; d++) {
  3389. var selection = data[d];
  3390. var $selection = this.selectionContainer();
  3391. var formatted = this.display(selection, $selection);
  3392. $selection.append(formatted);
  3393. $selection.prop('title', selection.title || selection.text);
  3394. $selection.data('data', selection);
  3395. $selections.push($selection);
  3396. }
  3397. var $rendered = this.$selection.find('.pumselect2-selection__rendered');
  3398. Utils.appendMany($rendered, $selections);
  3399. };
  3400. return MultipleSelection;
  3401. });
  3402. S2.define('pumselect2/selection/placeholder',[
  3403. '../utils'
  3404. ], function (Utils) {
  3405. function Placeholder (decorated, $element, options) {
  3406. this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
  3407. decorated.call(this, $element, options);
  3408. }
  3409. Placeholder.prototype.normalizePlaceholder = function (_, placeholder) {
  3410. if (typeof placeholder === 'string') {
  3411. placeholder = {
  3412. id: '',
  3413. text: placeholder
  3414. };
  3415. }
  3416. return placeholder;
  3417. };
  3418. Placeholder.prototype.createPlaceholder = function (decorated, placeholder) {
  3419. var $placeholder = this.selectionContainer();
  3420. $placeholder.html(this.display(placeholder));
  3421. $placeholder.addClass('pumselect2-selection__placeholder')
  3422. .removeClass('pumselect2-selection__choice');
  3423. return $placeholder;
  3424. };
  3425. Placeholder.prototype.update = function (decorated, data) {
  3426. var singlePlaceholder = (
  3427. data.length == 1 && data[0].id != this.placeholder.id
  3428. );
  3429. var multipleSelections = data.length > 1;
  3430. if (multipleSelections || singlePlaceholder) {
  3431. return decorated.call(this, data);
  3432. }
  3433. this.clear();
  3434. var $placeholder = this.createPlaceholder(this.placeholder);
  3435. this.$selection.find('.pumselect2-selection__rendered').append($placeholder);
  3436. };
  3437. return Placeholder;
  3438. });
  3439. S2.define('pumselect2/selection/allowClear',[
  3440. 'jquery',
  3441. '../keys'
  3442. ], function ($, KEYS) {
  3443. function AllowClear () { }
  3444. AllowClear.prototype.bind = function (decorated, container, $container) {
  3445. var self = this;
  3446. decorated.call(this, container, $container);
  3447. if (this.placeholder == null) {
  3448. if (this.options.get('debug') && window.console && console.error) {
  3449. console.error(
  3450. 'Select2: The `allowClear` option should be used in combination ' +
  3451. 'with the `placeholder` option.'
  3452. );
  3453. }
  3454. }
  3455. this.$selection.on('mousedown', '.pumselect2-selection__clear',
  3456. function (evt) {
  3457. self._handleClear(evt);
  3458. });
  3459. container.on('keypress', function (evt) {
  3460. self._handleKeyboardClear(evt, container);
  3461. });
  3462. };
  3463. AllowClear.prototype._handleClear = function (_, evt) {
  3464. // Ignore the event if it is disabled
  3465. if (this.options.get('disabled')) {
  3466. return;
  3467. }
  3468. var $clear = this.$selection.find('.pumselect2-selection__clear');
  3469. // Ignore the event if nothing has been selected
  3470. if ($clear.length === 0) {
  3471. return;
  3472. }
  3473. evt.stopPropagation();
  3474. var data = $clear.data('data');
  3475. for (var d = 0; d < data.length; d++) {
  3476. var unselectData = {
  3477. data: data[d]
  3478. };
  3479. // Trigger the `unselect` event, so people can prevent it from being
  3480. // cleared.
  3481. this.trigger('unselect', unselectData);
  3482. // If the event was prevented, don't clear it out.
  3483. if (unselectData.prevented) {
  3484. return;
  3485. }
  3486. }
  3487. this.$element.val(this.placeholder.id).trigger('change');
  3488. this.trigger('toggle', {});
  3489. };
  3490. AllowClear.prototype._handleKeyboardClear = function (_, evt, container) {
  3491. if (container.isOpen()) {
  3492. return;
  3493. }
  3494. if (evt.which == KEYS.DELETE || evt.which == KEYS.BACKSPACE) {
  3495. this._handleClear(evt);
  3496. }
  3497. };
  3498. AllowClear.prototype.update = function (decorated, data) {
  3499. decorated.call(this, data);
  3500. if (this.$selection.find('.pumselect2-selection__placeholder').length > 0 ||
  3501. data.length === 0) {
  3502. return;
  3503. }
  3504. var $remove = $(
  3505. '<span class="pumselect2-selection__clear">' +
  3506. '&times;' +
  3507. '</span>'
  3508. );
  3509. $remove.data('data', data);
  3510. this.$selection.find('.pumselect2-selection__rendered').prepend($remove);
  3511. };
  3512. return AllowClear;
  3513. });
  3514. S2.define('pumselect2/selection/search',[
  3515. 'jquery',
  3516. '../utils',
  3517. '../keys'
  3518. ], function ($, Utils, KEYS) {
  3519. function Search (decorated, $element, options) {
  3520. decorated.call(this, $element, options);
  3521. }
  3522. Search.prototype.render = function (decorated) {
  3523. var $search = $(
  3524. '<li class="pumselect2-search pumselect2-search--inline">' +
  3525. '<input class="pumselect2-search__field" type="search" tabindex="-1"' +
  3526. ' autocomplete="off" autocorrect="off" autocapitalize="off"' +
  3527. ' spellcheck="false" role="textbox" aria-autocomplete="list" />' +
  3528. '</li>'
  3529. );
  3530. this.$searchContainer = $search;
  3531. this.$search = $search.find('input');
  3532. var $rendered = decorated.call(this);
  3533. this._transferTabIndex();
  3534. return $rendered;
  3535. };
  3536. Search.prototype.bind = function (decorated, container, $container) {
  3537. var self = this;
  3538. decorated.call(this, container, $container);
  3539. container.on('open', function () {
  3540. self.$search.trigger('focus');
  3541. });
  3542. container.on('close', function () {
  3543. self.$search.val('');
  3544. self.$search.removeAttr('aria-activedescendant');
  3545. self.$search.trigger('focus');
  3546. });
  3547. container.on('enable', function () {
  3548. self.$search.prop('disabled', false);
  3549. self._transferTabIndex();
  3550. });
  3551. container.on('disable', function () {
  3552. self.$search.prop('disabled', true);
  3553. });
  3554. container.on('focus', function (evt) {
  3555. self.$search.trigger('focus');
  3556. });
  3557. container.on('results:focus', function (params) {
  3558. self.$search.attr('aria-activedescendant', params.id);
  3559. });
  3560. this.$selection.on('focusin', '.pumselect2-search--inline', function (evt) {
  3561. self.trigger('focus', evt);
  3562. });
  3563. this.$selection.on('focusout', '.pumselect2-search--inline', function (evt) {
  3564. self._handleBlur(evt);
  3565. });
  3566. this.$selection.on('keydown', '.pumselect2-search--inline', function (evt) {
  3567. evt.stopPropagation();
  3568. self.trigger('keypress', evt);
  3569. self._keyUpPrevented = evt.isDefaultPrevented();
  3570. var key = evt.which;
  3571. if (key === KEYS.BACKSPACE && self.$search.val() === '') {
  3572. var $previousChoice = self.$searchContainer
  3573. .prev('.pumselect2-selection__choice');
  3574. if ($previousChoice.length > 0) {
  3575. var item = $previousChoice.data('data');
  3576. self.searchRemoveChoice(item);
  3577. evt.preventDefault();
  3578. }
  3579. }
  3580. });
  3581. // Try to detect the IE version should the `documentMode` property that
  3582. // is stored on the document. This is only implemented in IE and is
  3583. // slightly cleaner than doing a user agent check.
  3584. // This property is not available in Edge, but Edge also doesn't have
  3585. // this bug.
  3586. var msie = document.documentMode;
  3587. var disableInputEvents = msie && msie <= 11;
  3588. // Workaround for browsers which do not support the `input` event
  3589. // This will prevent double-triggering of events for browsers which support
  3590. // both the `keyup` and `input` events.
  3591. this.$selection.on(
  3592. 'input.searchcheck',
  3593. '.pumselect2-search--inline',
  3594. function (evt) {
  3595. // IE will trigger the `input` event when a placeholder is used on a
  3596. // search box. To get around this issue, we are forced to ignore all
  3597. // `input` events in IE and keep using `keyup`.
  3598. if (disableInputEvents) {
  3599. self.$selection.off('input.search input.searchcheck');
  3600. return;
  3601. }
  3602. // Unbind the duplicated `keyup` event
  3603. self.$selection.off('keyup.search');
  3604. }
  3605. );
  3606. this.$selection.on(
  3607. 'keyup.search input.search',
  3608. '.pumselect2-search--inline',
  3609. function (evt) {
  3610. // IE will trigger the `input` event when a placeholder is used on a
  3611. // search box. To get around this issue, we are forced to ignore all
  3612. // `input` events in IE and keep using `keyup`.
  3613. if (disableInputEvents && evt.type === 'input') {
  3614. self.$selection.off('input.search input.searchcheck');
  3615. return;
  3616. }
  3617. var key = evt.which;
  3618. // We can freely ignore events from modifier keys
  3619. if (key == KEYS.SHIFT || key == KEYS.CTRL || key == KEYS.ALT) {
  3620. return;
  3621. }
  3622. // Tabbing will be handled during the `keydown` phase
  3623. if (key == KEYS.TAB) {
  3624. return;
  3625. }
  3626. self.handleSearch(evt);
  3627. }
  3628. );
  3629. };
  3630. /**
  3631. * This method will transfer the tabindex attribute from the rendered
  3632. * selection to the search box. This allows for the search box to be used as
  3633. * the primary focus instead of the selection container.
  3634. *
  3635. * @private
  3636. */
  3637. Search.prototype._transferTabIndex = function (decorated) {
  3638. this.$search.attr('tabindex', this.$selection.attr('tabindex'));
  3639. this.$selection.attr('tabindex', '-1');
  3640. };
  3641. Search.prototype.createPlaceholder = function (decorated, placeholder) {
  3642. this.$search.attr('placeholder', placeholder.text);
  3643. };
  3644. Search.prototype.update = function (decorated, data) {
  3645. var searchHadFocus = this.$search[0] == document.activeElement;
  3646. this.$search.attr('placeholder', '');
  3647. decorated.call(this, data);
  3648. this.$selection.find('.pumselect2-selection__rendered')
  3649. .append(this.$searchContainer);
  3650. this.resizeSearch();
  3651. if (searchHadFocus) {
  3652. this.$search.focus();
  3653. }
  3654. };
  3655. Search.prototype.handleSearch = function () {
  3656. this.resizeSearch();
  3657. if (!this._keyUpPrevented) {
  3658. var input = this.$search.val();
  3659. this.trigger('query', {
  3660. term: input
  3661. });
  3662. }
  3663. this._keyUpPrevented = false;
  3664. };
  3665. Search.prototype.searchRemoveChoice = function (decorated, item) {
  3666. this.trigger('unselect', {
  3667. data: item
  3668. });
  3669. this.$search.val(item.text);
  3670. this.handleSearch();
  3671. };
  3672. Search.prototype.resizeSearch = function () {
  3673. this.$search.css('width', '25px');
  3674. var width = '';
  3675. if (this.$search.attr('placeholder') !== '') {
  3676. width = this.$selection.find('.pumselect2-selection__rendered').innerWidth();
  3677. } else {
  3678. var minimumWidth = this.$search.val().length + 1;
  3679. width = (minimumWidth * 0.75) + 'em';
  3680. }
  3681. this.$search.css('width', width);
  3682. };
  3683. return Search;
  3684. });
  3685. S2.define('pumselect2/selection/eventRelay',[
  3686. 'jquery'
  3687. ], function ($) {
  3688. function EventRelay () { }
  3689. EventRelay.prototype.bind = function (decorated, container, $container) {
  3690. var self = this;
  3691. var relayEvents = [
  3692. 'open', 'opening',
  3693. 'close', 'closing',
  3694. 'select', 'selecting',
  3695. 'unselect', 'unselecting'
  3696. ];
  3697. var preventableEvents = ['opening', 'closing', 'selecting', 'unselecting'];
  3698. decorated.call(this, container, $container);
  3699. container.on('*', function (name, params) {
  3700. // Ignore events that should not be relayed
  3701. if ($.inArray(name, relayEvents) === -1) {
  3702. return;
  3703. }
  3704. // The parameters should always be an object
  3705. params = params || {};
  3706. // Generate the jQuery event for the Select2 event
  3707. var evt = $.Event('pumselect2:' + name, {
  3708. params: params
  3709. });
  3710. self.$element.trigger(evt);
  3711. // Only handle preventable events if it was one
  3712. if ($.inArray(name, preventableEvents) === -1) {
  3713. return;
  3714. }
  3715. params.prevented = evt.isDefaultPrevented();
  3716. });
  3717. };
  3718. return EventRelay;
  3719. });
  3720. S2.define('pumselect2/translation',[
  3721. 'jquery',
  3722. 'require'
  3723. ], function ($, require) {
  3724. function Translation (dict) {
  3725. this.dict = dict || {};
  3726. }
  3727. Translation.prototype.all = function () {
  3728. return this.dict;
  3729. };
  3730. Translation.prototype.get = function (key) {
  3731. return this.dict[key];
  3732. };
  3733. Translation.prototype.extend = function (translation) {
  3734. this.dict = $.extend({}, translation.all(), this.dict);
  3735. };
  3736. // Static functions
  3737. Translation._cache = {};
  3738. Translation.loadPath = function (path) {
  3739. if (!(path in Translation._cache)) {
  3740. var translations = require(path);
  3741. Translation._cache[path] = translations;
  3742. }
  3743. return new Translation(Translation._cache[path]);
  3744. };
  3745. return Translation;
  3746. });
  3747. S2.define('pumselect2/diacritics',[
  3748. ], function () {
  3749. var diacritics = {
  3750. '\u24B6': 'A',
  3751. '\uFF21': 'A',
  3752. '\u00C0': 'A',
  3753. '\u00C1': 'A',
  3754. '\u00C2': 'A',
  3755. '\u1EA6': 'A',
  3756. '\u1EA4': 'A',
  3757. '\u1EAA': 'A',
  3758. '\u1EA8': 'A',
  3759. '\u00C3': 'A',
  3760. '\u0100': 'A',
  3761. '\u0102': 'A',
  3762. '\u1EB0': 'A',
  3763. '\u1EAE': 'A',
  3764. '\u1EB4': 'A',
  3765. '\u1EB2': 'A',
  3766. '\u0226': 'A',
  3767. '\u01E0': 'A',
  3768. '\u00C4': 'A',
  3769. '\u01DE': 'A',
  3770. '\u1EA2': 'A',
  3771. '\u00C5': 'A',
  3772. '\u01FA': 'A',
  3773. '\u01CD': 'A',
  3774. '\u0200': 'A',
  3775. '\u0202': 'A',
  3776. '\u1EA0': 'A',
  3777. '\u1EAC': 'A',
  3778. '\u1EB6': 'A',
  3779. '\u1E00': 'A',
  3780. '\u0104': 'A',
  3781. '\u023A': 'A',
  3782. '\u2C6F': 'A',
  3783. '\uA732': 'AA',
  3784. '\u00C6': 'AE',
  3785. '\u01FC': 'AE',
  3786. '\u01E2': 'AE',
  3787. '\uA734': 'AO',
  3788. '\uA736': 'AU',
  3789. '\uA738': 'AV',
  3790. '\uA73A': 'AV',
  3791. '\uA73C': 'AY',
  3792. '\u24B7': 'B',
  3793. '\uFF22': 'B',
  3794. '\u1E02': 'B',
  3795. '\u1E04': 'B',
  3796. '\u1E06': 'B',
  3797. '\u0243': 'B',
  3798. '\u0182': 'B',
  3799. '\u0181': 'B',
  3800. '\u24B8': 'C',
  3801. '\uFF23': 'C',
  3802. '\u0106': 'C',
  3803. '\u0108': 'C',
  3804. '\u010A': 'C',
  3805. '\u010C': 'C',
  3806. '\u00C7': 'C',
  3807. '\u1E08': 'C',
  3808. '\u0187': 'C',
  3809. '\u023B': 'C',
  3810. '\uA73E': 'C',
  3811. '\u24B9': 'D',
  3812. '\uFF24': 'D',
  3813. '\u1E0A': 'D',
  3814. '\u010E': 'D',
  3815. '\u1E0C': 'D',
  3816. '\u1E10': 'D',
  3817. '\u1E12': 'D',
  3818. '\u1E0E': 'D',
  3819. '\u0110': 'D',
  3820. '\u018B': 'D',
  3821. '\u018A': 'D',
  3822. '\u0189': 'D',
  3823. '\uA779': 'D',
  3824. '\u01F1': 'DZ',
  3825. '\u01C4': 'DZ',
  3826. '\u01F2': 'Dz',
  3827. '\u01C5': 'Dz',
  3828. '\u24BA': 'E',
  3829. '\uFF25': 'E',
  3830. '\u00C8': 'E',
  3831. '\u00C9': 'E',
  3832. '\u00CA': 'E',
  3833. '\u1EC0': 'E',
  3834. '\u1EBE': 'E',
  3835. '\u1EC4': 'E',
  3836. '\u1EC2': 'E',
  3837. '\u1EBC': 'E',
  3838. '\u0112': 'E',
  3839. '\u1E14': 'E',
  3840. '\u1E16': 'E',
  3841. '\u0114': 'E',
  3842. '\u0116': 'E',
  3843. '\u00CB': 'E',
  3844. '\u1EBA': 'E',
  3845. '\u011A': 'E',
  3846. '\u0204': 'E',
  3847. '\u0206': 'E',
  3848. '\u1EB8': 'E',
  3849. '\u1EC6': 'E',
  3850. '\u0228': 'E',
  3851. '\u1E1C': 'E',
  3852. '\u0118': 'E',
  3853. '\u1E18': 'E',
  3854. '\u1E1A': 'E',
  3855. '\u0190': 'E',
  3856. '\u018E': 'E',
  3857. '\u24BB': 'F',
  3858. '\uFF26': 'F',
  3859. '\u1E1E': 'F',
  3860. '\u0191': 'F',
  3861. '\uA77B': 'F',
  3862. '\u24BC': 'G',
  3863. '\uFF27': 'G',
  3864. '\u01F4': 'G',
  3865. '\u011C': 'G',
  3866. '\u1E20': 'G',
  3867. '\u011E': 'G',
  3868. '\u0120': 'G',
  3869. '\u01E6': 'G',
  3870. '\u0122': 'G',
  3871. '\u01E4': 'G',
  3872. '\u0193': 'G',
  3873. '\uA7A0': 'G',
  3874. '\uA77D': 'G',
  3875. '\uA77E': 'G',
  3876. '\u24BD': 'H',
  3877. '\uFF28': 'H',
  3878. '\u0124': 'H',
  3879. '\u1E22': 'H',
  3880. '\u1E26': 'H',
  3881. '\u021E': 'H',
  3882. '\u1E24': 'H',
  3883. '\u1E28': 'H',
  3884. '\u1E2A': 'H',
  3885. '\u0126': 'H',
  3886. '\u2C67': 'H',
  3887. '\u2C75': 'H',
  3888. '\uA78D': 'H',
  3889. '\u24BE': 'I',
  3890. '\uFF29': 'I',
  3891. '\u00CC': 'I',
  3892. '\u00CD': 'I',
  3893. '\u00CE': 'I',
  3894. '\u0128': 'I',
  3895. '\u012A': 'I',
  3896. '\u012C': 'I',
  3897. '\u0130': 'I',
  3898. '\u00CF': 'I',
  3899. '\u1E2E': 'I',
  3900. '\u1EC8': 'I',
  3901. '\u01CF': 'I',
  3902. '\u0208': 'I',
  3903. '\u020A': 'I',
  3904. '\u1ECA': 'I',
  3905. '\u012E': 'I',
  3906. '\u1E2C': 'I',
  3907. '\u0197': 'I',
  3908. '\u24BF': 'J',
  3909. '\uFF2A': 'J',
  3910. '\u0134': 'J',
  3911. '\u0248': 'J',
  3912. '\u24C0': 'K',
  3913. '\uFF2B': 'K',
  3914. '\u1E30': 'K',
  3915. '\u01E8': 'K',
  3916. '\u1E32': 'K',
  3917. '\u0136': 'K',
  3918. '\u1E34': 'K',
  3919. '\u0198': 'K',
  3920. '\u2C69': 'K',
  3921. '\uA740': 'K',
  3922. '\uA742': 'K',
  3923. '\uA744': 'K',
  3924. '\uA7A2': 'K',
  3925. '\u24C1': 'L',
  3926. '\uFF2C': 'L',
  3927. '\u013F': 'L',
  3928. '\u0139': 'L',
  3929. '\u013D': 'L',
  3930. '\u1E36': 'L',
  3931. '\u1E38': 'L',
  3932. '\u013B': 'L',
  3933. '\u1E3C': 'L',
  3934. '\u1E3A': 'L',
  3935. '\u0141': 'L',
  3936. '\u023D': 'L',
  3937. '\u2C62': 'L',
  3938. '\u2C60': 'L',
  3939. '\uA748': 'L',
  3940. '\uA746': 'L',
  3941. '\uA780': 'L',
  3942. '\u01C7': 'LJ',
  3943. '\u01C8': 'Lj',
  3944. '\u24C2': 'M',
  3945. '\uFF2D': 'M',
  3946. '\u1E3E': 'M',
  3947. '\u1E40': 'M',
  3948. '\u1E42': 'M',
  3949. '\u2C6E': 'M',
  3950. '\u019C': 'M',
  3951. '\u24C3': 'N',
  3952. '\uFF2E': 'N',
  3953. '\u01F8': 'N',
  3954. '\u0143': 'N',
  3955. '\u00D1': 'N',
  3956. '\u1E44': 'N',
  3957. '\u0147': 'N',
  3958. '\u1E46': 'N',
  3959. '\u0145': 'N',
  3960. '\u1E4A': 'N',
  3961. '\u1E48': 'N',
  3962. '\u0220': 'N',
  3963. '\u019D': 'N',
  3964. '\uA790': 'N',
  3965. '\uA7A4': 'N',
  3966. '\u01CA': 'NJ',
  3967. '\u01CB': 'Nj',
  3968. '\u24C4': 'O',
  3969. '\uFF2F': 'O',
  3970. '\u00D2': 'O',
  3971. '\u00D3': 'O',
  3972. '\u00D4': 'O',
  3973. '\u1ED2': 'O',
  3974. '\u1ED0': 'O',
  3975. '\u1ED6': 'O',
  3976. '\u1ED4': 'O',
  3977. '\u00D5': 'O',
  3978. '\u1E4C': 'O',
  3979. '\u022C': 'O',
  3980. '\u1E4E': 'O',
  3981. '\u014C': 'O',
  3982. '\u1E50': 'O',
  3983. '\u1E52': 'O',
  3984. '\u014E': 'O',
  3985. '\u022E': 'O',
  3986. '\u0230': 'O',
  3987. '\u00D6': 'O',
  3988. '\u022A': 'O',
  3989. '\u1ECE': 'O',
  3990. '\u0150': 'O',
  3991. '\u01D1': 'O',
  3992. '\u020C': 'O',
  3993. '\u020E': 'O',
  3994. '\u01A0': 'O',
  3995. '\u1EDC': 'O',
  3996. '\u1EDA': 'O',
  3997. '\u1EE0': 'O',
  3998. '\u1EDE': 'O',
  3999. '\u1EE2': 'O',
  4000. '\u1ECC': 'O',
  4001. '\u1ED8': 'O',
  4002. '\u01EA': 'O',
  4003. '\u01EC': 'O',
  4004. '\u00D8': 'O',
  4005. '\u01FE': 'O',
  4006. '\u0186': 'O',
  4007. '\u019F': 'O',
  4008. '\uA74A': 'O',
  4009. '\uA74C': 'O',
  4010. '\u01A2': 'OI',
  4011. '\uA74E': 'OO',
  4012. '\u0222': 'OU',
  4013. '\u24C5': 'P',
  4014. '\uFF30': 'P',
  4015. '\u1E54': 'P',
  4016. '\u1E56': 'P',
  4017. '\u01A4': 'P',
  4018. '\u2C63': 'P',
  4019. '\uA750': 'P',
  4020. '\uA752': 'P',
  4021. '\uA754': 'P',
  4022. '\u24C6': 'Q',
  4023. '\uFF31': 'Q',
  4024. '\uA756': 'Q',
  4025. '\uA758': 'Q',
  4026. '\u024A': 'Q',
  4027. '\u24C7': 'R',
  4028. '\uFF32': 'R',
  4029. '\u0154': 'R',
  4030. '\u1E58': 'R',
  4031. '\u0158': 'R',
  4032. '\u0210': 'R',
  4033. '\u0212': 'R',
  4034. '\u1E5A': 'R',
  4035. '\u1E5C': 'R',
  4036. '\u0156': 'R',
  4037. '\u1E5E': 'R',
  4038. '\u024C': 'R',
  4039. '\u2C64': 'R',
  4040. '\uA75A': 'R',
  4041. '\uA7A6': 'R',
  4042. '\uA782': 'R',
  4043. '\u24C8': 'S',
  4044. '\uFF33': 'S',
  4045. '\u1E9E': 'S',
  4046. '\u015A': 'S',
  4047. '\u1E64': 'S',
  4048. '\u015C': 'S',
  4049. '\u1E60': 'S',
  4050. '\u0160': 'S',
  4051. '\u1E66': 'S',
  4052. '\u1E62': 'S',
  4053. '\u1E68': 'S',
  4054. '\u0218': 'S',
  4055. '\u015E': 'S',
  4056. '\u2C7E': 'S',
  4057. '\uA7A8': 'S',
  4058. '\uA784': 'S',
  4059. '\u24C9': 'T',
  4060. '\uFF34': 'T',
  4061. '\u1E6A': 'T',
  4062. '\u0164': 'T',
  4063. '\u1E6C': 'T',
  4064. '\u021A': 'T',
  4065. '\u0162': 'T',
  4066. '\u1E70': 'T',
  4067. '\u1E6E': 'T',
  4068. '\u0166': 'T',
  4069. '\u01AC': 'T',
  4070. '\u01AE': 'T',
  4071. '\u023E': 'T',
  4072. '\uA786': 'T',
  4073. '\uA728': 'TZ',
  4074. '\u24CA': 'U',
  4075. '\uFF35': 'U',
  4076. '\u00D9': 'U',
  4077. '\u00DA': 'U',
  4078. '\u00DB': 'U',
  4079. '\u0168': 'U',
  4080. '\u1E78': 'U',
  4081. '\u016A': 'U',
  4082. '\u1E7A': 'U',
  4083. '\u016C': 'U',
  4084. '\u00DC': 'U',
  4085. '\u01DB': 'U',
  4086. '\u01D7': 'U',
  4087. '\u01D5': 'U',
  4088. '\u01D9': 'U',
  4089. '\u1EE6': 'U',
  4090. '\u016E': 'U',
  4091. '\u0170': 'U',
  4092. '\u01D3': 'U',
  4093. '\u0214': 'U',
  4094. '\u0216': 'U',
  4095. '\u01AF': 'U',
  4096. '\u1EEA': 'U',
  4097. '\u1EE8': 'U',
  4098. '\u1EEE': 'U',
  4099. '\u1EEC': 'U',
  4100. '\u1EF0': 'U',
  4101. '\u1EE4': 'U',
  4102. '\u1E72': 'U',
  4103. '\u0172': 'U',
  4104. '\u1E76': 'U',
  4105. '\u1E74': 'U',
  4106. '\u0244': 'U',
  4107. '\u24CB': 'V',
  4108. '\uFF36': 'V',
  4109. '\u1E7C': 'V',
  4110. '\u1E7E': 'V',
  4111. '\u01B2': 'V',
  4112. '\uA75E': 'V',
  4113. '\u0245': 'V',
  4114. '\uA760': 'VY',
  4115. '\u24CC': 'W',
  4116. '\uFF37': 'W',
  4117. '\u1E80': 'W',
  4118. '\u1E82': 'W',
  4119. '\u0174': 'W',
  4120. '\u1E86': 'W',
  4121. '\u1E84': 'W',
  4122. '\u1E88': 'W',
  4123. '\u2C72': 'W',
  4124. '\u24CD': 'X',
  4125. '\uFF38': 'X',
  4126. '\u1E8A': 'X',
  4127. '\u1E8C': 'X',
  4128. '\u24CE': 'Y',
  4129. '\uFF39': 'Y',
  4130. '\u1EF2': 'Y',
  4131. '\u00DD': 'Y',
  4132. '\u0176': 'Y',
  4133. '\u1EF8': 'Y',
  4134. '\u0232': 'Y',
  4135. '\u1E8E': 'Y',
  4136. '\u0178': 'Y',
  4137. '\u1EF6': 'Y',
  4138. '\u1EF4': 'Y',
  4139. '\u01B3': 'Y',
  4140. '\u024E': 'Y',
  4141. '\u1EFE': 'Y',
  4142. '\u24CF': 'Z',
  4143. '\uFF3A': 'Z',
  4144. '\u0179': 'Z',
  4145. '\u1E90': 'Z',
  4146. '\u017B': 'Z',
  4147. '\u017D': 'Z',
  4148. '\u1E92': 'Z',
  4149. '\u1E94': 'Z',
  4150. '\u01B5': 'Z',
  4151. '\u0224': 'Z',
  4152. '\u2C7F': 'Z',
  4153. '\u2C6B': 'Z',
  4154. '\uA762': 'Z',
  4155. '\u24D0': 'a',
  4156. '\uFF41': 'a',
  4157. '\u1E9A': 'a',
  4158. '\u00E0': 'a',
  4159. '\u00E1': 'a',
  4160. '\u00E2': 'a',
  4161. '\u1EA7': 'a',
  4162. '\u1EA5': 'a',
  4163. '\u1EAB': 'a',
  4164. '\u1EA9': 'a',
  4165. '\u00E3': 'a',
  4166. '\u0101': 'a',
  4167. '\u0103': 'a',
  4168. '\u1EB1': 'a',
  4169. '\u1EAF': 'a',
  4170. '\u1EB5': 'a',
  4171. '\u1EB3': 'a',
  4172. '\u0227': 'a',
  4173. '\u01E1': 'a',
  4174. '\u00E4': 'a',
  4175. '\u01DF': 'a',
  4176. '\u1EA3': 'a',
  4177. '\u00E5': 'a',
  4178. '\u01FB': 'a',
  4179. '\u01CE': 'a',
  4180. '\u0201': 'a',
  4181. '\u0203': 'a',
  4182. '\u1EA1': 'a',
  4183. '\u1EAD': 'a',
  4184. '\u1EB7': 'a',
  4185. '\u1E01': 'a',
  4186. '\u0105': 'a',
  4187. '\u2C65': 'a',
  4188. '\u0250': 'a',
  4189. '\uA733': 'aa',
  4190. '\u00E6': 'ae',
  4191. '\u01FD': 'ae',
  4192. '\u01E3': 'ae',
  4193. '\uA735': 'ao',
  4194. '\uA737': 'au',
  4195. '\uA739': 'av',
  4196. '\uA73B': 'av',
  4197. '\uA73D': 'ay',
  4198. '\u24D1': 'b',
  4199. '\uFF42': 'b',
  4200. '\u1E03': 'b',
  4201. '\u1E05': 'b',
  4202. '\u1E07': 'b',
  4203. '\u0180': 'b',
  4204. '\u0183': 'b',
  4205. '\u0253': 'b',
  4206. '\u24D2': 'c',
  4207. '\uFF43': 'c',
  4208. '\u0107': 'c',
  4209. '\u0109': 'c',
  4210. '\u010B': 'c',
  4211. '\u010D': 'c',
  4212. '\u00E7': 'c',
  4213. '\u1E09': 'c',
  4214. '\u0188': 'c',
  4215. '\u023C': 'c',
  4216. '\uA73F': 'c',
  4217. '\u2184': 'c',
  4218. '\u24D3': 'd',
  4219. '\uFF44': 'd',
  4220. '\u1E0B': 'd',
  4221. '\u010F': 'd',
  4222. '\u1E0D': 'd',
  4223. '\u1E11': 'd',
  4224. '\u1E13': 'd',
  4225. '\u1E0F': 'd',
  4226. '\u0111': 'd',
  4227. '\u018C': 'd',
  4228. '\u0256': 'd',
  4229. '\u0257': 'd',
  4230. '\uA77A': 'd',
  4231. '\u01F3': 'dz',
  4232. '\u01C6': 'dz',
  4233. '\u24D4': 'e',
  4234. '\uFF45': 'e',
  4235. '\u00E8': 'e',
  4236. '\u00E9': 'e',
  4237. '\u00EA': 'e',
  4238. '\u1EC1': 'e',
  4239. '\u1EBF': 'e',
  4240. '\u1EC5': 'e',
  4241. '\u1EC3': 'e',
  4242. '\u1EBD': 'e',
  4243. '\u0113': 'e',
  4244. '\u1E15': 'e',
  4245. '\u1E17': 'e',
  4246. '\u0115': 'e',
  4247. '\u0117': 'e',
  4248. '\u00EB': 'e',
  4249. '\u1EBB': 'e',
  4250. '\u011B': 'e',
  4251. '\u0205': 'e',
  4252. '\u0207': 'e',
  4253. '\u1EB9': 'e',
  4254. '\u1EC7': 'e',
  4255. '\u0229': 'e',
  4256. '\u1E1D': 'e',
  4257. '\u0119': 'e',
  4258. '\u1E19': 'e',
  4259. '\u1E1B': 'e',
  4260. '\u0247': 'e',
  4261. '\u025B': 'e',
  4262. '\u01DD': 'e',
  4263. '\u24D5': 'f',
  4264. '\uFF46': 'f',
  4265. '\u1E1F': 'f',
  4266. '\u0192': 'f',
  4267. '\uA77C': 'f',
  4268. '\u24D6': 'g',
  4269. '\uFF47': 'g',
  4270. '\u01F5': 'g',
  4271. '\u011D': 'g',
  4272. '\u1E21': 'g',
  4273. '\u011F': 'g',
  4274. '\u0121': 'g',
  4275. '\u01E7': 'g',
  4276. '\u0123': 'g',
  4277. '\u01E5': 'g',
  4278. '\u0260': 'g',
  4279. '\uA7A1': 'g',
  4280. '\u1D79': 'g',
  4281. '\uA77F': 'g',
  4282. '\u24D7': 'h',
  4283. '\uFF48': 'h',
  4284. '\u0125': 'h',
  4285. '\u1E23': 'h',
  4286. '\u1E27': 'h',
  4287. '\u021F': 'h',
  4288. '\u1E25': 'h',
  4289. '\u1E29': 'h',
  4290. '\u1E2B': 'h',
  4291. '\u1E96': 'h',
  4292. '\u0127': 'h',
  4293. '\u2C68': 'h',
  4294. '\u2C76': 'h',
  4295. '\u0265': 'h',
  4296. '\u0195': 'hv',
  4297. '\u24D8': 'i',
  4298. '\uFF49': 'i',
  4299. '\u00EC': 'i',
  4300. '\u00ED': 'i',
  4301. '\u00EE': 'i',
  4302. '\u0129': 'i',
  4303. '\u012B': 'i',
  4304. '\u012D': 'i',
  4305. '\u00EF': 'i',
  4306. '\u1E2F': 'i',
  4307. '\u1EC9': 'i',
  4308. '\u01D0': 'i',
  4309. '\u0209': 'i',
  4310. '\u020B': 'i',
  4311. '\u1ECB': 'i',
  4312. '\u012F': 'i',
  4313. '\u1E2D': 'i',
  4314. '\u0268': 'i',
  4315. '\u0131': 'i',
  4316. '\u24D9': 'j',
  4317. '\uFF4A': 'j',
  4318. '\u0135': 'j',
  4319. '\u01F0': 'j',
  4320. '\u0249': 'j',
  4321. '\u24DA': 'k',
  4322. '\uFF4B': 'k',
  4323. '\u1E31': 'k',
  4324. '\u01E9': 'k',
  4325. '\u1E33': 'k',
  4326. '\u0137': 'k',
  4327. '\u1E35': 'k',
  4328. '\u0199': 'k',
  4329. '\u2C6A': 'k',
  4330. '\uA741': 'k',
  4331. '\uA743': 'k',
  4332. '\uA745': 'k',
  4333. '\uA7A3': 'k',
  4334. '\u24DB': 'l',
  4335. '\uFF4C': 'l',
  4336. '\u0140': 'l',
  4337. '\u013A': 'l',
  4338. '\u013E': 'l',
  4339. '\u1E37': 'l',
  4340. '\u1E39': 'l',
  4341. '\u013C': 'l',
  4342. '\u1E3D': 'l',
  4343. '\u1E3B': 'l',
  4344. '\u017F': 'l',
  4345. '\u0142': 'l',
  4346. '\u019A': 'l',
  4347. '\u026B': 'l',
  4348. '\u2C61': 'l',
  4349. '\uA749': 'l',
  4350. '\uA781': 'l',
  4351. '\uA747': 'l',
  4352. '\u01C9': 'lj',
  4353. '\u24DC': 'm',
  4354. '\uFF4D': 'm',
  4355. '\u1E3F': 'm',
  4356. '\u1E41': 'm',
  4357. '\u1E43': 'm',
  4358. '\u0271': 'm',
  4359. '\u026F': 'm',
  4360. '\u24DD': 'n',
  4361. '\uFF4E': 'n',
  4362. '\u01F9': 'n',
  4363. '\u0144': 'n',
  4364. '\u00F1': 'n',
  4365. '\u1E45': 'n',
  4366. '\u0148': 'n',
  4367. '\u1E47': 'n',
  4368. '\u0146': 'n',
  4369. '\u1E4B': 'n',
  4370. '\u1E49': 'n',
  4371. '\u019E': 'n',
  4372. '\u0272': 'n',
  4373. '\u0149': 'n',
  4374. '\uA791': 'n',
  4375. '\uA7A5': 'n',
  4376. '\u01CC': 'nj',
  4377. '\u24DE': 'o',
  4378. '\uFF4F': 'o',
  4379. '\u00F2': 'o',
  4380. '\u00F3': 'o',
  4381. '\u00F4': 'o',
  4382. '\u1ED3': 'o',
  4383. '\u1ED1': 'o',
  4384. '\u1ED7': 'o',
  4385. '\u1ED5': 'o',
  4386. '\u00F5': 'o',
  4387. '\u1E4D': 'o',
  4388. '\u022D': 'o',
  4389. '\u1E4F': 'o',
  4390. '\u014D': 'o',
  4391. '\u1E51': 'o',
  4392. '\u1E53': 'o',
  4393. '\u014F': 'o',
  4394. '\u022F': 'o',
  4395. '\u0231': 'o',
  4396. '\u00F6': 'o',
  4397. '\u022B': 'o',
  4398. '\u1ECF': 'o',
  4399. '\u0151': 'o',
  4400. '\u01D2': 'o',
  4401. '\u020D': 'o',
  4402. '\u020F': 'o',
  4403. '\u01A1': 'o',
  4404. '\u1EDD': 'o',
  4405. '\u1EDB': 'o',
  4406. '\u1EE1': 'o',
  4407. '\u1EDF': 'o',
  4408. '\u1EE3': 'o',
  4409. '\u1ECD': 'o',
  4410. '\u1ED9': 'o',
  4411. '\u01EB': 'o',
  4412. '\u01ED': 'o',
  4413. '\u00F8': 'o',
  4414. '\u01FF': 'o',
  4415. '\u0254': 'o',
  4416. '\uA74B': 'o',
  4417. '\uA74D': 'o',
  4418. '\u0275': 'o',
  4419. '\u01A3': 'oi',
  4420. '\u0223': 'ou',
  4421. '\uA74F': 'oo',
  4422. '\u24DF': 'p',
  4423. '\uFF50': 'p',
  4424. '\u1E55': 'p',
  4425. '\u1E57': 'p',
  4426. '\u01A5': 'p',
  4427. '\u1D7D': 'p',
  4428. '\uA751': 'p',
  4429. '\uA753': 'p',
  4430. '\uA755': 'p',
  4431. '\u24E0': 'q',
  4432. '\uFF51': 'q',
  4433. '\u024B': 'q',
  4434. '\uA757': 'q',
  4435. '\uA759': 'q',
  4436. '\u24E1': 'r',
  4437. '\uFF52': 'r',
  4438. '\u0155': 'r',
  4439. '\u1E59': 'r',
  4440. '\u0159': 'r',
  4441. '\u0211': 'r',
  4442. '\u0213': 'r',
  4443. '\u1E5B': 'r',
  4444. '\u1E5D': 'r',
  4445. '\u0157': 'r',
  4446. '\u1E5F': 'r',
  4447. '\u024D': 'r',
  4448. '\u027D': 'r',
  4449. '\uA75B': 'r',
  4450. '\uA7A7': 'r',
  4451. '\uA783': 'r',
  4452. '\u24E2': 's',
  4453. '\uFF53': 's',
  4454. '\u00DF': 's',
  4455. '\u015B': 's',
  4456. '\u1E65': 's',
  4457. '\u015D': 's',
  4458. '\u1E61': 's',
  4459. '\u0161': 's',
  4460. '\u1E67': 's',
  4461. '\u1E63': 's',
  4462. '\u1E69': 's',
  4463. '\u0219': 's',
  4464. '\u015F': 's',
  4465. '\u023F': 's',
  4466. '\uA7A9': 's',
  4467. '\uA785': 's',
  4468. '\u1E9B': 's',
  4469. '\u24E3': 't',
  4470. '\uFF54': 't',
  4471. '\u1E6B': 't',
  4472. '\u1E97': 't',
  4473. '\u0165': 't',
  4474. '\u1E6D': 't',
  4475. '\u021B': 't',
  4476. '\u0163': 't',
  4477. '\u1E71': 't',
  4478. '\u1E6F': 't',
  4479. '\u0167': 't',
  4480. '\u01AD': 't',
  4481. '\u0288': 't',
  4482. '\u2C66': 't',
  4483. '\uA787': 't',
  4484. '\uA729': 'tz',
  4485. '\u24E4': 'u',
  4486. '\uFF55': 'u',
  4487. '\u00F9': 'u',
  4488. '\u00FA': 'u',
  4489. '\u00FB': 'u',
  4490. '\u0169': 'u',
  4491. '\u1E79': 'u',
  4492. '\u016B': 'u',
  4493. '\u1E7B': 'u',
  4494. '\u016D': 'u',
  4495. '\u00FC': 'u',
  4496. '\u01DC': 'u',
  4497. '\u01D8': 'u',
  4498. '\u01D6': 'u',
  4499. '\u01DA': 'u',
  4500. '\u1EE7': 'u',
  4501. '\u016F': 'u',
  4502. '\u0171': 'u',
  4503. '\u01D4': 'u',
  4504. '\u0215': 'u',
  4505. '\u0217': 'u',
  4506. '\u01B0': 'u',
  4507. '\u1EEB': 'u',
  4508. '\u1EE9': 'u',
  4509. '\u1EEF': 'u',
  4510. '\u1EED': 'u',
  4511. '\u1EF1': 'u',
  4512. '\u1EE5': 'u',
  4513. '\u1E73': 'u',
  4514. '\u0173': 'u',
  4515. '\u1E77': 'u',
  4516. '\u1E75': 'u',
  4517. '\u0289': 'u',
  4518. '\u24E5': 'v',
  4519. '\uFF56': 'v',
  4520. '\u1E7D': 'v',
  4521. '\u1E7F': 'v',
  4522. '\u028B': 'v',
  4523. '\uA75F': 'v',
  4524. '\u028C': 'v',
  4525. '\uA761': 'vy',
  4526. '\u24E6': 'w',
  4527. '\uFF57': 'w',
  4528. '\u1E81': 'w',
  4529. '\u1E83': 'w',
  4530. '\u0175': 'w',
  4531. '\u1E87': 'w',
  4532. '\u1E85': 'w',
  4533. '\u1E98': 'w',
  4534. '\u1E89': 'w',
  4535. '\u2C73': 'w',
  4536. '\u24E7': 'x',
  4537. '\uFF58': 'x',
  4538. '\u1E8B': 'x',
  4539. '\u1E8D': 'x',
  4540. '\u24E8': 'y',
  4541. '\uFF59': 'y',
  4542. '\u1EF3': 'y',
  4543. '\u00FD': 'y',
  4544. '\u0177': 'y',
  4545. '\u1EF9': 'y',
  4546. '\u0233': 'y',
  4547. '\u1E8F': 'y',
  4548. '\u00FF': 'y',
  4549. '\u1EF7': 'y',
  4550. '\u1E99': 'y',
  4551. '\u1EF5': 'y',
  4552. '\u01B4': 'y',
  4553. '\u024F': 'y',
  4554. '\u1EFF': 'y',
  4555. '\u24E9': 'z',
  4556. '\uFF5A': 'z',
  4557. '\u017A': 'z',
  4558. '\u1E91': 'z',
  4559. '\u017C': 'z',
  4560. '\u017E': 'z',
  4561. '\u1E93': 'z',
  4562. '\u1E95': 'z',
  4563. '\u01B6': 'z',
  4564. '\u0225': 'z',
  4565. '\u0240': 'z',
  4566. '\u2C6C': 'z',
  4567. '\uA763': 'z',
  4568. '\u0386': '\u0391',
  4569. '\u0388': '\u0395',
  4570. '\u0389': '\u0397',
  4571. '\u038A': '\u0399',
  4572. '\u03AA': '\u0399',
  4573. '\u038C': '\u039F',
  4574. '\u038E': '\u03A5',
  4575. '\u03AB': '\u03A5',
  4576. '\u038F': '\u03A9',
  4577. '\u03AC': '\u03B1',
  4578. '\u03AD': '\u03B5',
  4579. '\u03AE': '\u03B7',
  4580. '\u03AF': '\u03B9',
  4581. '\u03CA': '\u03B9',
  4582. '\u0390': '\u03B9',
  4583. '\u03CC': '\u03BF',
  4584. '\u03CD': '\u03C5',
  4585. '\u03CB': '\u03C5',
  4586. '\u03B0': '\u03C5',
  4587. '\u03C9': '\u03C9',
  4588. '\u03C2': '\u03C3'
  4589. };
  4590. return diacritics;
  4591. });
  4592. S2.define('pumselect2/data/base',[
  4593. '../utils'
  4594. ], function (Utils) {
  4595. function BaseAdapter ($element, options) {
  4596. BaseAdapter.__super__.constructor.call(this);
  4597. }
  4598. Utils.Extend(BaseAdapter, Utils.Observable);
  4599. BaseAdapter.prototype.current = function (callback) {
  4600. throw new Error('The `current` method must be defined in child classes.');
  4601. };
  4602. BaseAdapter.prototype.query = function (params, callback) {
  4603. throw new Error('The `query` method must be defined in child classes.');
  4604. };
  4605. BaseAdapter.prototype.bind = function (container, $container) {
  4606. // Can be implemented in subclasses
  4607. };
  4608. BaseAdapter.prototype.destroy = function () {
  4609. // Can be implemented in subclasses
  4610. };
  4611. BaseAdapter.prototype.generateResultId = function (container, data) {
  4612. var id = container.id + '-result-';
  4613. id += Utils.generateChars(4);
  4614. if (data.id != null) {
  4615. id += '-' + data.id.toString();
  4616. } else {
  4617. id += '-' + Utils.generateChars(4);
  4618. }
  4619. return id;
  4620. };
  4621. return BaseAdapter;
  4622. });
  4623. S2.define('pumselect2/data/select',[
  4624. './base',
  4625. '../utils',
  4626. 'jquery'
  4627. ], function (BaseAdapter, Utils, $) {
  4628. function SelectAdapter ($element, options) {
  4629. this.$element = $element;
  4630. this.options = options;
  4631. SelectAdapter.__super__.constructor.call(this);
  4632. }
  4633. Utils.Extend(SelectAdapter, BaseAdapter);
  4634. SelectAdapter.prototype.current = function (callback) {
  4635. var data = [];
  4636. var self = this;
  4637. this.$element.find(':selected').each(function () {
  4638. var $option = $(this);
  4639. var option = self.item($option);
  4640. data.push(option);
  4641. });
  4642. callback(data);
  4643. };
  4644. SelectAdapter.prototype.select = function (data) {
  4645. var self = this;
  4646. data.selected = true;
  4647. // If data.element is a DOM node, use it instead
  4648. if ($(data.element).is('option')) {
  4649. data.element.selected = true;
  4650. this.$element.trigger('change');
  4651. return;
  4652. }
  4653. if (this.$element.prop('multiple')) {
  4654. this.current(function (currentData) {
  4655. var val = [];
  4656. data = [data];
  4657. data.push.apply(data, currentData);
  4658. for (var d = 0; d < data.length; d++) {
  4659. var id = data[d].id;
  4660. if ($.inArray(id, val) === -1) {
  4661. val.push(id);
  4662. }
  4663. }
  4664. self.$element.val(val);
  4665. self.$element.trigger('change');
  4666. });
  4667. } else {
  4668. var val = data.id;
  4669. this.$element.val(val);
  4670. this.$element.trigger('change');
  4671. }
  4672. };
  4673. SelectAdapter.prototype.unselect = function (data) {
  4674. var self = this;
  4675. if (!this.$element.prop('multiple')) {
  4676. return;
  4677. }
  4678. data.selected = false;
  4679. if ($(data.element).is('option')) {
  4680. data.element.selected = false;
  4681. this.$element.trigger('change');
  4682. return;
  4683. }
  4684. this.current(function (currentData) {
  4685. var val = [];
  4686. for (var d = 0; d < currentData.length; d++) {
  4687. var id = currentData[d].id;
  4688. if (id !== data.id && $.inArray(id, val) === -1) {
  4689. val.push(id);
  4690. }
  4691. }
  4692. self.$element.val(val);
  4693. self.$element.trigger('change');
  4694. });
  4695. };
  4696. SelectAdapter.prototype.bind = function (container, $container) {
  4697. var self = this;
  4698. this.container = container;
  4699. container.on('select', function (params) {
  4700. self.select(params.data);
  4701. });
  4702. container.on('unselect', function (params) {
  4703. self.unselect(params.data);
  4704. });
  4705. };
  4706. SelectAdapter.prototype.destroy = function () {
  4707. // Remove anything added to child elements
  4708. this.$element.find('*').each(function () {
  4709. // Remove any custom data set by Select2
  4710. $.removeData(this, 'data');
  4711. });
  4712. };
  4713. SelectAdapter.prototype.query = function (params, callback) {
  4714. var data = [];
  4715. var self = this;
  4716. var $options = this.$element.children();
  4717. $options.each(function () {
  4718. var $option = $(this);
  4719. if (!$option.is('option') && !$option.is('optgroup')) {
  4720. return;
  4721. }
  4722. var option = self.item($option);
  4723. var matches = self.matches(params, option);
  4724. if (matches !== null) {
  4725. data.push(matches);
  4726. }
  4727. });
  4728. callback({
  4729. results: data
  4730. });
  4731. };
  4732. SelectAdapter.prototype.addOptions = function ($options) {
  4733. Utils.appendMany(this.$element, $options);
  4734. };
  4735. SelectAdapter.prototype.option = function (data) {
  4736. var option;
  4737. if (data.children) {
  4738. option = document.createElement('optgroup');
  4739. option.label = data.text;
  4740. } else {
  4741. option = document.createElement('option');
  4742. if (option.textContent !== undefined) {
  4743. option.textContent = data.text;
  4744. } else {
  4745. option.innerText = data.text;
  4746. }
  4747. }
  4748. if (data.id) {
  4749. option.value = data.id;
  4750. }
  4751. if (data.disabled) {
  4752. option.disabled = true;
  4753. }
  4754. if (data.selected) {
  4755. option.selected = true;
  4756. }
  4757. if (data.title) {
  4758. option.title = data.title;
  4759. }
  4760. var $option = $(option);
  4761. var normalizedData = this._normalizeItem(data);
  4762. normalizedData.element = option;
  4763. // Override the option's data with the combined data
  4764. $.data(option, 'data', normalizedData);
  4765. return $option;
  4766. };
  4767. SelectAdapter.prototype.item = function ($option) {
  4768. var data = {};
  4769. data = $.data($option[0], 'data');
  4770. if (data != null) {
  4771. return data;
  4772. }
  4773. if ($option.is('option')) {
  4774. data = {
  4775. id: $option.val(),
  4776. text: $option.text(),
  4777. disabled: $option.prop('disabled'),
  4778. selected: $option.prop('selected'),
  4779. title: $option.prop('title')
  4780. };
  4781. } else if ($option.is('optgroup')) {
  4782. data = {
  4783. text: $option.prop('label'),
  4784. children: [],
  4785. title: $option.prop('title')
  4786. };
  4787. var $children = $option.children('option');
  4788. var children = [];
  4789. for (var c = 0; c < $children.length; c++) {
  4790. var $child = $($children[c]);
  4791. var child = this.item($child);
  4792. children.push(child);
  4793. }
  4794. data.children = children;
  4795. }
  4796. data = this._normalizeItem(data);
  4797. data.element = $option[0];
  4798. $.data($option[0], 'data', data);
  4799. return data;
  4800. };
  4801. SelectAdapter.prototype._normalizeItem = function (item) {
  4802. if (!$.isPlainObject(item)) {
  4803. item = {
  4804. id: item,
  4805. text: item
  4806. };
  4807. }
  4808. item = $.extend({}, {
  4809. text: ''
  4810. }, item);
  4811. var defaults = {
  4812. selected: false,
  4813. disabled: false
  4814. };
  4815. if (item.id != null) {
  4816. item.id = item.id.toString();
  4817. }
  4818. if (item.text != null) {
  4819. item.text = item.text.toString();
  4820. }
  4821. if (item._resultId == null && item.id && this.container != null) {
  4822. item._resultId = this.generateResultId(this.container, item);
  4823. }
  4824. return $.extend({}, defaults, item);
  4825. };
  4826. SelectAdapter.prototype.matches = function (params, data) {
  4827. var matcher = this.options.get('matcher');
  4828. return matcher(params, data);
  4829. };
  4830. return SelectAdapter;
  4831. });
  4832. S2.define('pumselect2/data/array',[
  4833. './select',
  4834. '../utils',
  4835. 'jquery'
  4836. ], function (SelectAdapter, Utils, $) {
  4837. function ArrayAdapter ($element, options) {
  4838. var data = options.get('data') || [];
  4839. ArrayAdapter.__super__.constructor.call(this, $element, options);
  4840. this.addOptions(this.convertToOptions(data));
  4841. }
  4842. Utils.Extend(ArrayAdapter, SelectAdapter);
  4843. ArrayAdapter.prototype.select = function (data) {
  4844. var $option = this.$element.find('option').filter(function (i, elm) {
  4845. return elm.value == data.id.toString();
  4846. });
  4847. if ($option.length === 0) {
  4848. $option = this.option(data);
  4849. this.addOptions($option);
  4850. }
  4851. ArrayAdapter.__super__.select.call(this, data);
  4852. };
  4853. ArrayAdapter.prototype.convertToOptions = function (data) {
  4854. var self = this;
  4855. var $existing = this.$element.find('option');
  4856. var existingIds = $existing.map(function () {
  4857. return self.item($(this)).id;
  4858. }).get();
  4859. var $options = [];
  4860. // Filter out all items except for the one passed in the argument
  4861. function onlyItem (item) {
  4862. return function () {
  4863. return $(this).val() == item.id;
  4864. };
  4865. }
  4866. for (var d = 0; d < data.length; d++) {
  4867. var item = this._normalizeItem(data[d]);
  4868. // Skip items which were pre-loaded, only merge the data
  4869. if ($.inArray(item.id, existingIds) >= 0) {
  4870. var $existingOption = $existing.filter(onlyItem(item));
  4871. var existingData = this.item($existingOption);
  4872. var newData = $.extend(true, {}, item, existingData);
  4873. var $newOption = this.option(newData);
  4874. $existingOption.replaceWith($newOption);
  4875. continue;
  4876. }
  4877. var $option = this.option(item);
  4878. if (item.children) {
  4879. var $children = this.convertToOptions(item.children);
  4880. Utils.appendMany($option, $children);
  4881. }
  4882. $options.push($option);
  4883. }
  4884. return $options;
  4885. };
  4886. return ArrayAdapter;
  4887. });
  4888. S2.define('pumselect2/data/ajax',[
  4889. './array',
  4890. '../utils',
  4891. 'jquery'
  4892. ], function (ArrayAdapter, Utils, $) {
  4893. function AjaxAdapter ($element, options) {
  4894. this.ajaxOptions = this._applyDefaults(options.get('ajax'));
  4895. if (this.ajaxOptions.processResults != null) {
  4896. this.processResults = this.ajaxOptions.processResults;
  4897. }
  4898. AjaxAdapter.__super__.constructor.call(this, $element, options);
  4899. }
  4900. Utils.Extend(AjaxAdapter, ArrayAdapter);
  4901. AjaxAdapter.prototype._applyDefaults = function (options) {
  4902. var defaults = {
  4903. data: function (params) {
  4904. return $.extend({}, params, {
  4905. q: params.term
  4906. });
  4907. },
  4908. transport: function (params, success, failure) {
  4909. var $request = $.ajax(params);
  4910. $request.then(success);
  4911. $request.fail(failure);
  4912. return $request;
  4913. }
  4914. };
  4915. return $.extend({}, defaults, options, true);
  4916. };
  4917. AjaxAdapter.prototype.processResults = function (results) {
  4918. return results;
  4919. };
  4920. AjaxAdapter.prototype.query = function (params, callback) {
  4921. var matches = [];
  4922. var self = this;
  4923. if (this._request != null) {
  4924. // JSONP requests cannot always be aborted
  4925. if ($.isFunction(this._request.abort)) {
  4926. this._request.abort();
  4927. }
  4928. this._request = null;
  4929. }
  4930. var options = $.extend({
  4931. type: 'GET'
  4932. }, this.ajaxOptions);
  4933. if (typeof options.url === 'function') {
  4934. options.url = options.url.call(this.$element, params);
  4935. }
  4936. if (typeof options.data === 'function') {
  4937. options.data = options.data.call(this.$element, params);
  4938. }
  4939. function request () {
  4940. var $request = options.transport(options, function (data) {
  4941. var results = self.processResults(data, params);
  4942. if (self.options.get('debug') && window.console && console.error) {
  4943. // Check to make sure that the response included a `results` key.
  4944. if (!results || !results.results || !$.isArray(results.results)) {
  4945. console.error(
  4946. 'Select2: The AJAX results did not return an array in the ' +
  4947. '`results` key of the response.'
  4948. );
  4949. }
  4950. }
  4951. callback(results);
  4952. }, function () {
  4953. self.trigger('results:message', {
  4954. message: 'errorLoading'
  4955. });
  4956. });
  4957. self._request = $request;
  4958. }
  4959. if (this.ajaxOptions.delay && params.term !== '') {
  4960. if (this._queryTimeout) {
  4961. window.clearTimeout(this._queryTimeout);
  4962. }
  4963. this._queryTimeout = window.setTimeout(request, this.ajaxOptions.delay);
  4964. } else {
  4965. request();
  4966. }
  4967. };
  4968. return AjaxAdapter;
  4969. });
  4970. S2.define('pumselect2/data/tags',[
  4971. 'jquery'
  4972. ], function ($) {
  4973. function Tags (decorated, $element, options) {
  4974. var tags = options.get('tags');
  4975. var createTag = options.get('createTag');
  4976. if (createTag !== undefined) {
  4977. this.createTag = createTag;
  4978. }
  4979. var insertTag = options.get('insertTag');
  4980. if (insertTag !== undefined) {
  4981. this.insertTag = insertTag;
  4982. }
  4983. decorated.call(this, $element, options);
  4984. if ($.isArray(tags)) {
  4985. for (var t = 0; t < tags.length; t++) {
  4986. var tag = tags[t];
  4987. var item = this._normalizeItem(tag);
  4988. var $option = this.option(item);
  4989. this.$element.append($option);
  4990. }
  4991. }
  4992. }
  4993. Tags.prototype.query = function (decorated, params, callback) {
  4994. var self = this;
  4995. this._removeOldTags();
  4996. if (params.term == null || params.page != null) {
  4997. decorated.call(this, params, callback);
  4998. return;
  4999. }
  5000. function wrapper (obj, child) {
  5001. var data = obj.results;
  5002. for (var i = 0; i < data.length; i++) {
  5003. var option = data[i];
  5004. var checkChildren = (
  5005. option.children != null &&
  5006. !wrapper({
  5007. results: option.children
  5008. }, true)
  5009. );
  5010. var checkText = option.text === params.term;
  5011. if (checkText || checkChildren) {
  5012. if (child) {
  5013. return false;
  5014. }
  5015. obj.data = data;
  5016. callback(obj);
  5017. return;
  5018. }
  5019. }
  5020. if (child) {
  5021. return true;
  5022. }
  5023. var tag = self.createTag(params);
  5024. if (tag != null) {
  5025. var $option = self.option(tag);
  5026. $option.attr('data-pumselect2-tag', true);
  5027. self.addOptions([$option]);
  5028. self.insertTag(data, tag);
  5029. }
  5030. obj.results = data;
  5031. callback(obj);
  5032. }
  5033. decorated.call(this, params, wrapper);
  5034. };
  5035. Tags.prototype.createTag = function (decorated, params) {
  5036. var term = $.trim(params.term);
  5037. if (term === '') {
  5038. return null;
  5039. }
  5040. return {
  5041. id: term,
  5042. text: term
  5043. };
  5044. };
  5045. Tags.prototype.insertTag = function (_, data, tag) {
  5046. data.unshift(tag);
  5047. };
  5048. Tags.prototype._removeOldTags = function (_) {
  5049. var tag = this._lastTag;
  5050. var $options = this.$element.find('option[data-pumselect2-tag]');
  5051. $options.each(function () {
  5052. if (this.selected) {
  5053. return;
  5054. }
  5055. $(this).remove();
  5056. });
  5057. };
  5058. return Tags;
  5059. });
  5060. S2.define('pumselect2/data/tokenizer',[
  5061. 'jquery'
  5062. ], function ($) {
  5063. function Tokenizer (decorated, $element, options) {
  5064. var tokenizer = options.get('tokenizer');
  5065. if (tokenizer !== undefined) {
  5066. this.tokenizer = tokenizer;
  5067. }
  5068. decorated.call(this, $element, options);
  5069. }
  5070. Tokenizer.prototype.bind = function (decorated, container, $container) {
  5071. decorated.call(this, container, $container);
  5072. this.$search = container.dropdown.$search || container.selection.$search ||
  5073. $container.find('.pumselect2-search__field');
  5074. };
  5075. Tokenizer.prototype.query = function (decorated, params, callback) {
  5076. var self = this;
  5077. function select (data) {
  5078. self.trigger('select', {
  5079. data: data
  5080. });
  5081. }
  5082. params.term = params.term || '';
  5083. var tokenData = this.tokenizer(params, this.options, select);
  5084. if (tokenData.term !== params.term) {
  5085. // Replace the search term if we have the search box
  5086. if (this.$search.length) {
  5087. this.$search.val(tokenData.term);
  5088. this.$search.focus();
  5089. }
  5090. params.term = tokenData.term;
  5091. }
  5092. decorated.call(this, params, callback);
  5093. };
  5094. Tokenizer.prototype.tokenizer = function (_, params, options, callback) {
  5095. var separators = options.get('tokenSeparators') || [];
  5096. var term = params.term;
  5097. var i = 0;
  5098. var createTag = this.createTag || function (params) {
  5099. return {
  5100. id: params.term,
  5101. text: params.term
  5102. };
  5103. };
  5104. while (i < term.length) {
  5105. var termChar = term[i];
  5106. if ($.inArray(termChar, separators) === -1) {
  5107. i++;
  5108. continue;
  5109. }
  5110. var part = term.substr(0, i);
  5111. var partParams = $.extend({}, params, {
  5112. term: part
  5113. });
  5114. var data = createTag(partParams);
  5115. if (data == null) {
  5116. i++;
  5117. continue;
  5118. }
  5119. callback(data);
  5120. // Reset the term to not include the tokenized portion
  5121. term = term.substr(i + 1) || '';
  5122. i = 0;
  5123. }
  5124. return {
  5125. term: term
  5126. };
  5127. };
  5128. return Tokenizer;
  5129. });
  5130. S2.define('pumselect2/data/minimumInputLength',[
  5131. ], function () {
  5132. function MinimumInputLength (decorated, $e, options) {
  5133. this.minimumInputLength = options.get('minimumInputLength');
  5134. decorated.call(this, $e, options);
  5135. }
  5136. MinimumInputLength.prototype.query = function (decorated, params, callback) {
  5137. params.term = params.term || '';
  5138. if (params.term.length < this.minimumInputLength) {
  5139. this.trigger('results:message', {
  5140. message: 'inputTooShort',
  5141. args: {
  5142. minimum: this.minimumInputLength,
  5143. input: params.term,
  5144. params: params
  5145. }
  5146. });
  5147. return;
  5148. }
  5149. decorated.call(this, params, callback);
  5150. };
  5151. return MinimumInputLength;
  5152. });
  5153. S2.define('pumselect2/data/maximumInputLength',[
  5154. ], function () {
  5155. function MaximumInputLength (decorated, $e, options) {
  5156. this.maximumInputLength = options.get('maximumInputLength');
  5157. decorated.call(this, $e, options);
  5158. }
  5159. MaximumInputLength.prototype.query = function (decorated, params, callback) {
  5160. params.term = params.term || '';
  5161. if (this.maximumInputLength > 0 &&
  5162. params.term.length > this.maximumInputLength) {
  5163. this.trigger('results:message', {
  5164. message: 'inputTooLong',
  5165. args: {
  5166. maximum: this.maximumInputLength,
  5167. input: params.term,
  5168. params: params
  5169. }
  5170. });
  5171. return;
  5172. }
  5173. decorated.call(this, params, callback);
  5174. };
  5175. return MaximumInputLength;
  5176. });
  5177. S2.define('pumselect2/data/maximumSelectionLength',[
  5178. ], function (){
  5179. function MaximumSelectionLength (decorated, $e, options) {
  5180. this.maximumSelectionLength = options.get('maximumSelectionLength');
  5181. decorated.call(this, $e, options);
  5182. }
  5183. MaximumSelectionLength.prototype.query =
  5184. function (decorated, params, callback) {
  5185. var self = this;
  5186. this.current(function (currentData) {
  5187. var count = currentData != null ? currentData.length : 0;
  5188. if (self.maximumSelectionLength > 0 &&
  5189. count >= self.maximumSelectionLength) {
  5190. self.trigger('results:message', {
  5191. message: 'maximumSelected',
  5192. args: {
  5193. maximum: self.maximumSelectionLength
  5194. }
  5195. });
  5196. return;
  5197. }
  5198. decorated.call(self, params, callback);
  5199. });
  5200. };
  5201. return MaximumSelectionLength;
  5202. });
  5203. S2.define('pumselect2/dropdown',[
  5204. 'jquery',
  5205. './utils'
  5206. ], function ($, Utils) {
  5207. function Dropdown ($element, options) {
  5208. this.$element = $element;
  5209. this.options = options;
  5210. Dropdown.__super__.constructor.call(this);
  5211. }
  5212. Utils.Extend(Dropdown, Utils.Observable);
  5213. Dropdown.prototype.render = function () {
  5214. var $dropdown = $(
  5215. '<span class="pumselect2-dropdown">' +
  5216. '<span class="pumselect2-results"></span>' +
  5217. '</span>'
  5218. );
  5219. $dropdown.attr('dir', this.options.get('dir'));
  5220. this.$dropdown = $dropdown;
  5221. return $dropdown;
  5222. };
  5223. Dropdown.prototype.bind = function () {
  5224. // Should be implemented in subclasses
  5225. };
  5226. Dropdown.prototype.position = function ($dropdown, $container) {
  5227. // Should be implmented in subclasses
  5228. };
  5229. Dropdown.prototype.destroy = function () {
  5230. // Remove the dropdown from the DOM
  5231. this.$dropdown.remove();
  5232. };
  5233. return Dropdown;
  5234. });
  5235. S2.define('pumselect2/dropdown/search',[
  5236. 'jquery',
  5237. '../utils'
  5238. ], function ($, Utils) {
  5239. function Search () { }
  5240. Search.prototype.render = function (decorated) {
  5241. var $rendered = decorated.call(this);
  5242. var $search = $(
  5243. '<span class="pumselect2-search pumselect2-search--dropdown">' +
  5244. '<input class="pumselect2-search__field" type="search" tabindex="-1"' +
  5245. ' autocomplete="off" autocorrect="off" autocapitalize="off"' +
  5246. ' spellcheck="false" role="textbox" />' +
  5247. '</span>'
  5248. );
  5249. this.$searchContainer = $search;
  5250. this.$search = $search.find('input');
  5251. $rendered.prepend($search);
  5252. return $rendered;
  5253. };
  5254. Search.prototype.bind = function (decorated, container, $container) {
  5255. var self = this;
  5256. decorated.call(this, container, $container);
  5257. this.$search.on('keydown', function (evt) {
  5258. self.trigger('keypress', evt);
  5259. self._keyUpPrevented = evt.isDefaultPrevented();
  5260. });
  5261. // Workaround for browsers which do not support the `input` event
  5262. // This will prevent double-triggering of events for browsers which support
  5263. // both the `keyup` and `input` events.
  5264. this.$search.on('input', function (evt) {
  5265. // Unbind the duplicated `keyup` event
  5266. $(this).off('keyup');
  5267. });
  5268. this.$search.on('keyup input', function (evt) {
  5269. self.handleSearch(evt);
  5270. });
  5271. container.on('open', function () {
  5272. self.$search.attr('tabindex', 0);
  5273. self.$search.focus();
  5274. window.setTimeout(function () {
  5275. self.$search.focus();
  5276. }, 0);
  5277. });
  5278. container.on('close', function () {
  5279. self.$search.attr('tabindex', -1);
  5280. self.$search.val('');
  5281. });
  5282. container.on('results:all', function (params) {
  5283. if (params.query.term == null || params.query.term === '') {
  5284. var showSearch = self.showSearch(params);
  5285. if (showSearch) {
  5286. self.$searchContainer.removeClass('pumselect2-search--hide');
  5287. } else {
  5288. self.$searchContainer.addClass('pumselect2-search--hide');
  5289. }
  5290. }
  5291. });
  5292. };
  5293. Search.prototype.handleSearch = function (evt) {
  5294. if (!this._keyUpPrevented) {
  5295. var input = this.$search.val();
  5296. this.trigger('query', {
  5297. term: input
  5298. });
  5299. }
  5300. this._keyUpPrevented = false;
  5301. };
  5302. Search.prototype.showSearch = function (_, params) {
  5303. return true;
  5304. };
  5305. return Search;
  5306. });
  5307. S2.define('pumselect2/dropdown/hidePlaceholder',[
  5308. ], function () {
  5309. function HidePlaceholder (decorated, $element, options, dataAdapter) {
  5310. this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
  5311. decorated.call(this, $element, options, dataAdapter);
  5312. }
  5313. HidePlaceholder.prototype.append = function (decorated, data) {
  5314. data.results = this.removePlaceholder(data.results);
  5315. decorated.call(this, data);
  5316. };
  5317. HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) {
  5318. if (typeof placeholder === 'string') {
  5319. placeholder = {
  5320. id: '',
  5321. text: placeholder
  5322. };
  5323. }
  5324. return placeholder;
  5325. };
  5326. HidePlaceholder.prototype.removePlaceholder = function (_, data) {
  5327. var modifiedData = data.slice(0);
  5328. for (var d = data.length - 1; d >= 0; d--) {
  5329. var item = data[d];
  5330. if (this.placeholder.id === item.id) {
  5331. modifiedData.splice(d, 1);
  5332. }
  5333. }
  5334. return modifiedData;
  5335. };
  5336. return HidePlaceholder;
  5337. });
  5338. S2.define('pumselect2/dropdown/infiniteScroll',[
  5339. 'jquery'
  5340. ], function ($) {
  5341. function InfiniteScroll (decorated, $element, options, dataAdapter) {
  5342. this.lastParams = {};
  5343. decorated.call(this, $element, options, dataAdapter);
  5344. this.$loadingMore = this.createLoadingMore();
  5345. this.loading = false;
  5346. }
  5347. InfiniteScroll.prototype.append = function (decorated, data) {
  5348. this.$loadingMore.remove();
  5349. this.loading = false;
  5350. decorated.call(this, data);
  5351. if (this.showLoadingMore(data)) {
  5352. this.$results.append(this.$loadingMore);
  5353. }
  5354. };
  5355. InfiniteScroll.prototype.bind = function (decorated, container, $container) {
  5356. var self = this;
  5357. decorated.call(this, container, $container);
  5358. container.on('query', function (params) {
  5359. self.lastParams = params;
  5360. self.loading = true;
  5361. });
  5362. container.on('query:append', function (params) {
  5363. self.lastParams = params;
  5364. self.loading = true;
  5365. });
  5366. this.$results.on('scroll', function () {
  5367. var isLoadMoreVisible = $.contains(
  5368. document.documentElement,
  5369. self.$loadingMore[0]
  5370. );
  5371. if (self.loading || !isLoadMoreVisible) {
  5372. return;
  5373. }
  5374. var currentOffset = self.$results.offset().top +
  5375. self.$results.outerHeight(false);
  5376. var loadingMoreOffset = self.$loadingMore.offset().top +
  5377. self.$loadingMore.outerHeight(false);
  5378. if (currentOffset + 50 >= loadingMoreOffset) {
  5379. self.loadMore();
  5380. }
  5381. });
  5382. };
  5383. InfiniteScroll.prototype.loadMore = function () {
  5384. this.loading = true;
  5385. var params = $.extend({}, {page: 1}, this.lastParams);
  5386. params.page++;
  5387. this.trigger('query:append', params);
  5388. };
  5389. InfiniteScroll.prototype.showLoadingMore = function (_, data) {
  5390. return data.pagination && data.pagination.more;
  5391. };
  5392. InfiniteScroll.prototype.createLoadingMore = function () {
  5393. var $option = $(
  5394. '<li ' +
  5395. 'class="pumselect2-results__option pumselect2-results__option--load-more"' +
  5396. 'role="treeitem" aria-disabled="true"></li>'
  5397. );
  5398. var message = this.options.get('translations').get('loadingMore');
  5399. $option.html(message(this.lastParams));
  5400. return $option;
  5401. };
  5402. return InfiniteScroll;
  5403. });
  5404. S2.define('pumselect2/dropdown/attachBody',[
  5405. 'jquery',
  5406. '../utils'
  5407. ], function ($, Utils) {
  5408. function AttachBody (decorated, $element, options) {
  5409. this.$dropdownParent = options.get('dropdownParent') || $(document.body);
  5410. decorated.call(this, $element, options);
  5411. }
  5412. AttachBody.prototype.bind = function (decorated, container, $container) {
  5413. var self = this;
  5414. var setupResultsEvents = false;
  5415. decorated.call(this, container, $container);
  5416. container.on('open', function () {
  5417. self._showDropdown();
  5418. self._attachPositioningHandler(container);
  5419. if (!setupResultsEvents) {
  5420. setupResultsEvents = true;
  5421. container.on('results:all', function () {
  5422. self._positionDropdown();
  5423. self._resizeDropdown();
  5424. });
  5425. container.on('results:append', function () {
  5426. self._positionDropdown();
  5427. self._resizeDropdown();
  5428. });
  5429. }
  5430. });
  5431. container.on('close', function () {
  5432. self._hideDropdown();
  5433. self._detachPositioningHandler(container);
  5434. });
  5435. this.$dropdownContainer.on('mousedown', function (evt) {
  5436. evt.stopPropagation();
  5437. });
  5438. };
  5439. AttachBody.prototype.destroy = function (decorated) {
  5440. decorated.call(this);
  5441. this.$dropdownContainer.remove();
  5442. };
  5443. AttachBody.prototype.position = function (decorated, $dropdown, $container) {
  5444. // Clone all of the container classes
  5445. $dropdown.attr('class', $container.attr('class'));
  5446. $dropdown.removeClass('pumselect2');
  5447. $dropdown.addClass('pumselect2-container--open');
  5448. $dropdown.css({
  5449. position: 'absolute',
  5450. top: -999999
  5451. });
  5452. this.$container = $container;
  5453. };
  5454. AttachBody.prototype.render = function (decorated) {
  5455. var $container = $('<span></span>');
  5456. var $dropdown = decorated.call(this);
  5457. $container.append($dropdown);
  5458. this.$dropdownContainer = $container;
  5459. return $container;
  5460. };
  5461. AttachBody.prototype._hideDropdown = function (decorated) {
  5462. this.$dropdownContainer.detach();
  5463. };
  5464. AttachBody.prototype._attachPositioningHandler =
  5465. function (decorated, container) {
  5466. var self = this;
  5467. var scrollEvent = 'scroll.pumselect2.' + container.id;
  5468. var resizeEvent = 'resize.pumselect2.' + container.id;
  5469. var orientationEvent = 'orientationchange.pumselect2.' + container.id;
  5470. var $watchers = this.$container.parents().filter(Utils.hasScroll);
  5471. $watchers.each(function () {
  5472. $(this).data('pumselect2-scroll-position', {
  5473. x: $(this).scrollLeft(),
  5474. y: $(this).scrollTop()
  5475. });
  5476. });
  5477. $watchers.on(scrollEvent, function (ev) {
  5478. var position = $(this).data('pumselect2-scroll-position');
  5479. $(this).scrollTop(position.y);
  5480. });
  5481. $(window).on(scrollEvent + ' ' + resizeEvent + ' ' + orientationEvent,
  5482. function (e) {
  5483. self._positionDropdown();
  5484. self._resizeDropdown();
  5485. });
  5486. };
  5487. AttachBody.prototype._detachPositioningHandler =
  5488. function (decorated, container) {
  5489. var scrollEvent = 'scroll.pumselect2.' + container.id;
  5490. var resizeEvent = 'resize.pumselect2.' + container.id;
  5491. var orientationEvent = 'orientationchange.pumselect2.' + container.id;
  5492. var $watchers = this.$container.parents().filter(Utils.hasScroll);
  5493. $watchers.off(scrollEvent);
  5494. $(window).off(scrollEvent + ' ' + resizeEvent + ' ' + orientationEvent);
  5495. };
  5496. AttachBody.prototype._positionDropdown = function () {
  5497. var $window = $(window);
  5498. var isCurrentlyAbove = this.$dropdown.hasClass('pumselect2-dropdown--above');
  5499. var isCurrentlyBelow = this.$dropdown.hasClass('pumselect2-dropdown--below');
  5500. var newDirection = null;
  5501. var offset = this.$container.offset();
  5502. offset.bottom = offset.top + this.$container.outerHeight(false);
  5503. var container = {
  5504. height: this.$container.outerHeight(false)
  5505. };
  5506. container.top = offset.top;
  5507. container.bottom = offset.top + container.height;
  5508. var dropdown = {
  5509. height: this.$dropdown.outerHeight(false)
  5510. };
  5511. var viewport = {
  5512. top: $window.scrollTop(),
  5513. bottom: $window.scrollTop() + $window.height()
  5514. };
  5515. var enoughRoomAbove = viewport.top < (offset.top - dropdown.height);
  5516. var enoughRoomBelow = viewport.bottom > (offset.bottom + dropdown.height);
  5517. var css = {
  5518. left: offset.left,
  5519. top: container.bottom
  5520. };
  5521. // Determine what the parent element is to use for calciulating the offset
  5522. var $offsetParent = this.$dropdownParent;
  5523. // For statically positoned elements, we need to get the element
  5524. // that is determining the offset
  5525. if ($offsetParent.css('position') === 'static') {
  5526. $offsetParent = $offsetParent.offsetParent();
  5527. }
  5528. var parentOffset = $offsetParent.offset();
  5529. css.top -= parentOffset.top;
  5530. css.left -= parentOffset.left;
  5531. if (!isCurrentlyAbove && !isCurrentlyBelow) {
  5532. newDirection = 'below';
  5533. }
  5534. if (!enoughRoomBelow && enoughRoomAbove && !isCurrentlyAbove) {
  5535. newDirection = 'above';
  5536. } else if (!enoughRoomAbove && enoughRoomBelow && isCurrentlyAbove) {
  5537. newDirection = 'below';
  5538. }
  5539. if (newDirection == 'above' ||
  5540. (isCurrentlyAbove && newDirection !== 'below')) {
  5541. css.top = container.top - dropdown.height;
  5542. }
  5543. if (newDirection != null) {
  5544. this.$dropdown
  5545. .removeClass('pumselect2-dropdown--below pumselect2-dropdown--above')
  5546. .addClass('pumselect2-dropdown--' + newDirection);
  5547. this.$container
  5548. .removeClass('pumselect2-container--below pumselect2-container--above')
  5549. .addClass('pumselect2-container--' + newDirection);
  5550. }
  5551. this.$dropdownContainer.css(css);
  5552. };
  5553. AttachBody.prototype._resizeDropdown = function () {
  5554. var css = {
  5555. width: this.$container.outerWidth(false) + 'px'
  5556. };
  5557. if (this.options.get('dropdownAutoWidth')) {
  5558. css.minWidth = css.width;
  5559. css.width = 'auto';
  5560. }
  5561. this.$dropdown.css(css);
  5562. };
  5563. AttachBody.prototype._showDropdown = function (decorated) {
  5564. this.$dropdownContainer.appendTo(this.$dropdownParent);
  5565. this._positionDropdown();
  5566. this._resizeDropdown();
  5567. };
  5568. return AttachBody;
  5569. });
  5570. S2.define('pumselect2/dropdown/minimumResultsForSearch',[
  5571. ], function () {
  5572. function countResults (data) {
  5573. var count = 0;
  5574. for (var d = 0; d < data.length; d++) {
  5575. var item = data[d];
  5576. if (item.children) {
  5577. count += countResults(item.children);
  5578. } else {
  5579. count++;
  5580. }
  5581. }
  5582. return count;
  5583. }
  5584. function MinimumResultsForSearch (decorated, $element, options, dataAdapter) {
  5585. this.minimumResultsForSearch = options.get('minimumResultsForSearch');
  5586. if (this.minimumResultsForSearch < 0) {
  5587. this.minimumResultsForSearch = Infinity;
  5588. }
  5589. decorated.call(this, $element, options, dataAdapter);
  5590. }
  5591. MinimumResultsForSearch.prototype.showSearch = function (decorated, params) {
  5592. if (countResults(params.data.results) < this.minimumResultsForSearch) {
  5593. return false;
  5594. }
  5595. return decorated.call(this, params);
  5596. };
  5597. return MinimumResultsForSearch;
  5598. });
  5599. S2.define('pumselect2/dropdown/selectOnClose',[
  5600. ], function () {
  5601. function SelectOnClose () { }
  5602. SelectOnClose.prototype.bind = function (decorated, container, $container) {
  5603. var self = this;
  5604. decorated.call(this, container, $container);
  5605. container.on('close', function () {
  5606. self._handleSelectOnClose();
  5607. });
  5608. };
  5609. SelectOnClose.prototype._handleSelectOnClose = function () {
  5610. var $highlightedResults = this.getHighlightedResults();
  5611. // Only select highlighted results
  5612. if ($highlightedResults.length < 1) {
  5613. return;
  5614. }
  5615. var data = $highlightedResults.data('data');
  5616. // Don't re-select already selected resulte
  5617. if (
  5618. (data.element != null && data.element.selected) ||
  5619. (data.element == null && data.selected)
  5620. ) {
  5621. return;
  5622. }
  5623. this.trigger('select', {
  5624. data: data
  5625. });
  5626. };
  5627. return SelectOnClose;
  5628. });
  5629. S2.define('pumselect2/dropdown/closeOnSelect',[
  5630. ], function () {
  5631. function CloseOnSelect () { }
  5632. CloseOnSelect.prototype.bind = function (decorated, container, $container) {
  5633. var self = this;
  5634. decorated.call(this, container, $container);
  5635. container.on('select', function (evt) {
  5636. self._selectTriggered(evt);
  5637. });
  5638. container.on('unselect', function (evt) {
  5639. self._selectTriggered(evt);
  5640. });
  5641. };
  5642. CloseOnSelect.prototype._selectTriggered = function (_, evt) {
  5643. var originalEvent = evt.originalEvent;
  5644. // Don't close if the control key is being held
  5645. if (originalEvent && originalEvent.ctrlKey) {
  5646. return;
  5647. }
  5648. this.trigger('close', {});
  5649. };
  5650. return CloseOnSelect;
  5651. });
  5652. S2.define('pumselect2/i18n/en',[],function () {
  5653. // English
  5654. return {
  5655. errorLoading: function () {
  5656. return 'The results could not be loaded.';
  5657. },
  5658. inputTooLong: function (args) {
  5659. var overChars = args.input.length - args.maximum;
  5660. var message = 'Please delete ' + overChars + ' character';
  5661. if (overChars != 1) {
  5662. message += 's';
  5663. }
  5664. return message;
  5665. },
  5666. inputTooShort: function (args) {
  5667. var remainingChars = args.minimum - args.input.length;
  5668. var message = 'Please enter ' + remainingChars + ' or more characters';
  5669. return message;
  5670. },
  5671. loadingMore: function () {
  5672. return 'Loading more results…';
  5673. },
  5674. maximumSelected: function (args) {
  5675. var message = 'You can only select ' + args.maximum + ' item';
  5676. if (args.maximum != 1) {
  5677. message += 's';
  5678. }
  5679. return message;
  5680. },
  5681. noResults: function () {
  5682. return 'No results found';
  5683. },
  5684. searching: function () {
  5685. return 'Searching…';
  5686. }
  5687. };
  5688. });
  5689. S2.define('pumselect2/defaults',[
  5690. 'jquery',
  5691. 'require',
  5692. './results',
  5693. './selection/single',
  5694. './selection/multiple',
  5695. './selection/placeholder',
  5696. './selection/allowClear',
  5697. './selection/search',
  5698. './selection/eventRelay',
  5699. './utils',
  5700. './translation',
  5701. './diacritics',
  5702. './data/select',
  5703. './data/array',
  5704. './data/ajax',
  5705. './data/tags',
  5706. './data/tokenizer',
  5707. './data/minimumInputLength',
  5708. './data/maximumInputLength',
  5709. './data/maximumSelectionLength',
  5710. './dropdown',
  5711. './dropdown/search',
  5712. './dropdown/hidePlaceholder',
  5713. './dropdown/infiniteScroll',
  5714. './dropdown/attachBody',
  5715. './dropdown/minimumResultsForSearch',
  5716. './dropdown/selectOnClose',
  5717. './dropdown/closeOnSelect',
  5718. './i18n/en'
  5719. ], function ($, require,
  5720. ResultsList,
  5721. SingleSelection, MultipleSelection, Placeholder, AllowClear,
  5722. SelectionSearch, EventRelay,
  5723. Utils, Translation, DIACRITICS,
  5724. SelectData, ArrayData, AjaxData, Tags, Tokenizer,
  5725. MinimumInputLength, MaximumInputLength, MaximumSelectionLength,
  5726. Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
  5727. AttachBody, MinimumResultsForSearch, SelectOnClose, CloseOnSelect,
  5728. EnglishTranslation) {
  5729. function Defaults () {
  5730. this.reset();
  5731. }
  5732. Defaults.prototype.apply = function (options) {
  5733. options = $.extend(true, {}, this.defaults, options);
  5734. if (options.dataAdapter == null) {
  5735. if (options.ajax != null) {
  5736. options.dataAdapter = AjaxData;
  5737. } else if (options.data != null) {
  5738. options.dataAdapter = ArrayData;
  5739. } else {
  5740. options.dataAdapter = SelectData;
  5741. }
  5742. if (options.minimumInputLength > 0) {
  5743. options.dataAdapter = Utils.Decorate(
  5744. options.dataAdapter,
  5745. MinimumInputLength
  5746. );
  5747. }
  5748. if (options.maximumInputLength > 0) {
  5749. options.dataAdapter = Utils.Decorate(
  5750. options.dataAdapter,
  5751. MaximumInputLength
  5752. );
  5753. }
  5754. if (options.maximumSelectionLength > 0) {
  5755. options.dataAdapter = Utils.Decorate(
  5756. options.dataAdapter,
  5757. MaximumSelectionLength
  5758. );
  5759. }
  5760. if (options.tags) {
  5761. options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
  5762. }
  5763. if (options.tokenSeparators != null || options.tokenizer != null) {
  5764. options.dataAdapter = Utils.Decorate(
  5765. options.dataAdapter,
  5766. Tokenizer
  5767. );
  5768. }
  5769. if (options.query != null) {
  5770. var Query = require(options.amdBase + 'compat/query');
  5771. options.dataAdapter = Utils.Decorate(
  5772. options.dataAdapter,
  5773. Query
  5774. );
  5775. }
  5776. if (options.initSelection != null) {
  5777. var InitSelection = require(options.amdBase + 'compat/initSelection');
  5778. options.dataAdapter = Utils.Decorate(
  5779. options.dataAdapter,
  5780. InitSelection
  5781. );
  5782. }
  5783. }
  5784. if (options.resultsAdapter == null) {
  5785. options.resultsAdapter = ResultsList;
  5786. if (options.ajax != null) {
  5787. options.resultsAdapter = Utils.Decorate(
  5788. options.resultsAdapter,
  5789. InfiniteScroll
  5790. );
  5791. }
  5792. if (options.placeholder != null) {
  5793. options.resultsAdapter = Utils.Decorate(
  5794. options.resultsAdapter,
  5795. HidePlaceholder
  5796. );
  5797. }
  5798. if (options.selectOnClose) {
  5799. options.resultsAdapter = Utils.Decorate(
  5800. options.resultsAdapter,
  5801. SelectOnClose
  5802. );
  5803. }
  5804. }
  5805. if (options.dropdownAdapter == null) {
  5806. if (options.multiple) {
  5807. options.dropdownAdapter = Dropdown;
  5808. } else {
  5809. var SearchableDropdown = Utils.Decorate(Dropdown, DropdownSearch);
  5810. options.dropdownAdapter = SearchableDropdown;
  5811. }
  5812. if (options.minimumResultsForSearch !== 0) {
  5813. options.dropdownAdapter = Utils.Decorate(
  5814. options.dropdownAdapter,
  5815. MinimumResultsForSearch
  5816. );
  5817. }
  5818. if (options.closeOnSelect) {
  5819. options.dropdownAdapter = Utils.Decorate(
  5820. options.dropdownAdapter,
  5821. CloseOnSelect
  5822. );
  5823. }
  5824. if (
  5825. options.dropdownCssClass != null ||
  5826. options.dropdownCss != null ||
  5827. options.adaptDropdownCssClass != null
  5828. ) {
  5829. var DropdownCSS = require(options.amdBase + 'compat/dropdownCss');
  5830. options.dropdownAdapter = Utils.Decorate(
  5831. options.dropdownAdapter,
  5832. DropdownCSS
  5833. );
  5834. }
  5835. options.dropdownAdapter = Utils.Decorate(
  5836. options.dropdownAdapter,
  5837. AttachBody
  5838. );
  5839. }
  5840. if (options.selectionAdapter == null) {
  5841. if (options.multiple) {
  5842. options.selectionAdapter = MultipleSelection;
  5843. } else {
  5844. options.selectionAdapter = SingleSelection;
  5845. }
  5846. // Add the placeholder mixin if a placeholder was specified
  5847. if (options.placeholder != null) {
  5848. options.selectionAdapter = Utils.Decorate(
  5849. options.selectionAdapter,
  5850. Placeholder
  5851. );
  5852. }
  5853. if (options.allowClear) {
  5854. options.selectionAdapter = Utils.Decorate(
  5855. options.selectionAdapter,
  5856. AllowClear
  5857. );
  5858. }
  5859. if (options.multiple) {
  5860. options.selectionAdapter = Utils.Decorate(
  5861. options.selectionAdapter,
  5862. SelectionSearch
  5863. );
  5864. }
  5865. if (
  5866. options.containerCssClass != null ||
  5867. options.containerCss != null ||
  5868. options.adaptContainerCssClass != null
  5869. ) {
  5870. var ContainerCSS = require(options.amdBase + 'compat/containerCss');
  5871. options.selectionAdapter = Utils.Decorate(
  5872. options.selectionAdapter,
  5873. ContainerCSS
  5874. );
  5875. }
  5876. options.selectionAdapter = Utils.Decorate(
  5877. options.selectionAdapter,
  5878. EventRelay
  5879. );
  5880. }
  5881. if (typeof options.language === 'string') {
  5882. // Check if the language is specified with a region
  5883. if (options.language.indexOf('-') > 0) {
  5884. // Extract the region information if it is included
  5885. var languageParts = options.language.split('-');
  5886. var baseLanguage = languageParts[0];
  5887. options.language = [options.language, baseLanguage];
  5888. } else {
  5889. options.language = [options.language];
  5890. }
  5891. }
  5892. if ($.isArray(options.language)) {
  5893. var languages = new Translation();
  5894. options.language.push('en');
  5895. var languageNames = options.language;
  5896. for (var l = 0; l < languageNames.length; l++) {
  5897. var name = languageNames[l];
  5898. var language = {};
  5899. try {
  5900. // Try to load it with the original name
  5901. language = Translation.loadPath(name);
  5902. } catch (e) {
  5903. try {
  5904. // If we couldn't load it, check if it wasn't the full path
  5905. name = this.defaults.amdLanguageBase + name;
  5906. language = Translation.loadPath(name);
  5907. } catch (ex) {
  5908. // The translation could not be loaded at all. Sometimes this is
  5909. // because of a configuration problem, other times this can be
  5910. // because of how Select2 helps load all possible translation files.
  5911. if (options.debug && window.console && console.warn) {
  5912. console.warn(
  5913. 'Select2: The language file for "' + name + '" could not be ' +
  5914. 'automatically loaded. A fallback will be used instead.'
  5915. );
  5916. }
  5917. continue;
  5918. }
  5919. }
  5920. languages.extend(language);
  5921. }
  5922. options.translations = languages;
  5923. } else {
  5924. var baseTranslation = Translation.loadPath(
  5925. this.defaults.amdLanguageBase + 'en'
  5926. );
  5927. var customTranslation = new Translation(options.language);
  5928. customTranslation.extend(baseTranslation);
  5929. options.translations = customTranslation;
  5930. }
  5931. return options;
  5932. };
  5933. Defaults.prototype.reset = function () {
  5934. function stripDiacritics (text) {
  5935. // Used 'uni range + named function' from http://jsperf.com/diacritics/18
  5936. function match(a) {
  5937. return DIACRITICS[a] || a;
  5938. }
  5939. return text.replace(/[^\u0000-\u007E]/g, match);
  5940. }
  5941. function matcher (params, data) {
  5942. // Always return the object if there is nothing to compare
  5943. if ($.trim(params.term) === '') {
  5944. return data;
  5945. }
  5946. // Do a recursive check for options with children
  5947. if (data.children && data.children.length > 0) {
  5948. // Clone the data object if there are children
  5949. // This is required as we modify the object to remove any non-matches
  5950. var match = $.extend(true, {}, data);
  5951. // Check each child of the option
  5952. for (var c = data.children.length - 1; c >= 0; c--) {
  5953. var child = data.children[c];
  5954. var matches = matcher(params, child);
  5955. // If there wasn't a match, remove the object in the array
  5956. if (matches == null) {
  5957. match.children.splice(c, 1);
  5958. }
  5959. }
  5960. // If any children matched, return the new object
  5961. if (match.children.length > 0) {
  5962. return match;
  5963. }
  5964. // If there were no matching children, check just the plain object
  5965. return matcher(params, match);
  5966. }
  5967. var original = stripDiacritics(data.text).toUpperCase();
  5968. var term = stripDiacritics(params.term).toUpperCase();
  5969. // Check if the text contains the term
  5970. if (original.indexOf(term) > -1) {
  5971. return data;
  5972. }
  5973. // If it doesn't contain the term, don't return anything
  5974. return null;
  5975. }
  5976. this.defaults = {
  5977. amdBase: './',
  5978. amdLanguageBase: './i18n/',
  5979. closeOnSelect: true,
  5980. debug: false,
  5981. dropdownAutoWidth: false,
  5982. escapeMarkup: Utils.escapeMarkup,
  5983. language: EnglishTranslation,
  5984. matcher: matcher,
  5985. minimumInputLength: 0,
  5986. maximumInputLength: 0,
  5987. maximumSelectionLength: 0,
  5988. minimumResultsForSearch: 0,
  5989. selectOnClose: false,
  5990. sorter: function (data) {
  5991. return data;
  5992. },
  5993. templateResult: function (result) {
  5994. return result.text;
  5995. },
  5996. templateSelection: function (selection) {
  5997. return selection.text;
  5998. },
  5999. theme: 'default',
  6000. width: 'resolve'
  6001. };
  6002. };
  6003. Defaults.prototype.set = function (key, value) {
  6004. var camelKey = $.camelCase(key);
  6005. var data = {};
  6006. data[camelKey] = value;
  6007. var convertedData = Utils._convertData(data);
  6008. $.extend(this.defaults, convertedData);
  6009. };
  6010. var defaults = new Defaults();
  6011. return defaults;
  6012. });
  6013. S2.define('pumselect2/options',[
  6014. 'require',
  6015. 'jquery',
  6016. './defaults',
  6017. './utils'
  6018. ], function (require, $, Defaults, Utils) {
  6019. function Options (options, $element) {
  6020. this.options = options;
  6021. if ($element != null) {
  6022. this.fromElement($element);
  6023. }
  6024. this.options = Defaults.apply(this.options);
  6025. if ($element && $element.is('input')) {
  6026. var InputCompat = require(this.get('amdBase') + 'compat/inputData');
  6027. this.options.dataAdapter = Utils.Decorate(
  6028. this.options.dataAdapter,
  6029. InputCompat
  6030. );
  6031. }
  6032. }
  6033. Options.prototype.fromElement = function ($e) {
  6034. var excludedData = ['pumselect2'];
  6035. if (this.options.multiple == null) {
  6036. this.options.multiple = $e.prop('multiple');
  6037. }
  6038. if (this.options.disabled == null) {
  6039. this.options.disabled = $e.prop('disabled');
  6040. }
  6041. if (this.options.language == null) {
  6042. if ($e.prop('lang')) {
  6043. this.options.language = $e.prop('lang').toLowerCase();
  6044. } else if ($e.closest('[lang]').prop('lang')) {
  6045. this.options.language = $e.closest('[lang]').prop('lang');
  6046. }
  6047. }
  6048. if (this.options.dir == null) {
  6049. if ($e.prop('dir')) {
  6050. this.options.dir = $e.prop('dir');
  6051. } else if ($e.closest('[dir]').prop('dir')) {
  6052. this.options.dir = $e.closest('[dir]').prop('dir');
  6053. } else {
  6054. this.options.dir = 'ltr';
  6055. }
  6056. }
  6057. $e.prop('disabled', this.options.disabled);
  6058. $e.prop('multiple', this.options.multiple);
  6059. if ($e.data('pumselect2Tags')) {
  6060. if (this.options.debug && window.console && console.warn) {
  6061. console.warn(
  6062. 'Select2: The `data-pumselect2-tags` attribute has been changed to ' +
  6063. 'use the `data-data` and `data-tags="true"` attributes and will be ' +
  6064. 'removed in future versions of Select2.'
  6065. );
  6066. }
  6067. $e.data('data', $e.data('pumselect2Tags'));
  6068. $e.data('tags', true);
  6069. }
  6070. if ($e.data('ajaxUrl')) {
  6071. if (this.options.debug && window.console && console.warn) {
  6072. console.warn(
  6073. 'Select2: The `data-ajax-url` attribute has been changed to ' +
  6074. '`data-ajax--url` and support for the old attribute will be removed' +
  6075. ' in future versions of Select2.'
  6076. );
  6077. }
  6078. $e.attr('ajax--url', $e.data('ajaxUrl'));
  6079. $e.data('ajax--url', $e.data('ajaxUrl'));
  6080. }
  6081. var dataset = {};
  6082. // Prefer the element's `dataset` attribute if it exists
  6083. // jQuery 1.x does not correctly handle data attributes with multiple dashes
  6084. if ($.fn.jquery && $.fn.jquery.substr(0, 2) == '1.' && $e[0].dataset) {
  6085. dataset = $.extend(true, {}, $e[0].dataset, $e.data());
  6086. } else {
  6087. dataset = $e.data();
  6088. }
  6089. var data = $.extend(true, {}, dataset);
  6090. data = Utils._convertData(data);
  6091. for (var key in data) {
  6092. if ($.inArray(key, excludedData) > -1) {
  6093. continue;
  6094. }
  6095. if ($.isPlainObject(this.options[key])) {
  6096. $.extend(this.options[key], data[key]);
  6097. } else {
  6098. this.options[key] = data[key];
  6099. }
  6100. }
  6101. return this;
  6102. };
  6103. Options.prototype.get = function (key) {
  6104. return this.options[key];
  6105. };
  6106. Options.prototype.set = function (key, val) {
  6107. this.options[key] = val;
  6108. };
  6109. return Options;
  6110. });
  6111. S2.define('pumselect2/core',[
  6112. 'jquery',
  6113. './options',
  6114. './utils',
  6115. './keys'
  6116. ], function ($, Options, Utils, KEYS) {
  6117. var Select2 = function ($element, options) {
  6118. if ($element.data('pumselect2') != null) {
  6119. $element.data('pumselect2').destroy();
  6120. }
  6121. this.$element = $element;
  6122. this.id = this._generateId($element);
  6123. options = options || {};
  6124. this.options = new Options(options, $element);
  6125. Select2.__super__.constructor.call(this);
  6126. // Set up the tabindex
  6127. var tabindex = $element.attr('tabindex') || 0;
  6128. $element.data('old-tabindex', tabindex);
  6129. $element.attr('tabindex', '-1');
  6130. // Set up containers and adapters
  6131. var DataAdapter = this.options.get('dataAdapter');
  6132. this.dataAdapter = new DataAdapter($element, this.options);
  6133. var $container = this.render();
  6134. this._placeContainer($container);
  6135. var SelectionAdapter = this.options.get('selectionAdapter');
  6136. this.selection = new SelectionAdapter($element, this.options);
  6137. this.$selection = this.selection.render();
  6138. this.selection.position(this.$selection, $container);
  6139. var DropdownAdapter = this.options.get('dropdownAdapter');
  6140. this.dropdown = new DropdownAdapter($element, this.options);
  6141. this.$dropdown = this.dropdown.render();
  6142. this.dropdown.position(this.$dropdown, $container);
  6143. var ResultsAdapter = this.options.get('resultsAdapter');
  6144. this.results = new ResultsAdapter($element, this.options, this.dataAdapter);
  6145. this.$results = this.results.render();
  6146. this.results.position(this.$results, this.$dropdown);
  6147. // Bind events
  6148. var self = this;
  6149. // Bind the container to all of the adapters
  6150. this._bindAdapters();
  6151. // Register any DOM event handlers
  6152. this._registerDomEvents();
  6153. // Register any internal event handlers
  6154. this._registerDataEvents();
  6155. this._registerSelectionEvents();
  6156. this._registerDropdownEvents();
  6157. this._registerResultsEvents();
  6158. this._registerEvents();
  6159. // Set the initial state
  6160. this.dataAdapter.current(function (initialData) {
  6161. self.trigger('selection:update', {
  6162. data: initialData
  6163. });
  6164. });
  6165. // Hide the original select
  6166. $element.addClass('pumselect2-hidden-accessible');
  6167. $element.attr('aria-hidden', 'true');
  6168. // Synchronize any monitored attributes
  6169. this._syncAttributes();
  6170. $element.data('pumselect2', this);
  6171. };
  6172. Utils.Extend(Select2, Utils.Observable);
  6173. Select2.prototype._generateId = function ($element) {
  6174. var id = '';
  6175. if ($element.attr('id') != null) {
  6176. id = $element.attr('id');
  6177. } else if ($element.attr('name') != null) {
  6178. id = $element.attr('name') + '-' + Utils.generateChars(2);
  6179. } else {
  6180. id = Utils.generateChars(4);
  6181. }
  6182. id = id.replace(/(:|\.|\[|\]|,)/g, '');
  6183. id = 'pumselect2-' + id;
  6184. return id;
  6185. };
  6186. Select2.prototype._placeContainer = function ($container) {
  6187. $container.insertAfter(this.$element);
  6188. var width = this._resolveWidth(this.$element, this.options.get('width'));
  6189. if (width != null) {
  6190. $container.css('width', width);
  6191. }
  6192. };
  6193. Select2.prototype._resolveWidth = function ($element, method) {
  6194. var WIDTH = /^width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/i;
  6195. if (method == 'resolve') {
  6196. var styleWidth = this._resolveWidth($element, 'style');
  6197. if (styleWidth != null) {
  6198. return styleWidth;
  6199. }
  6200. return this._resolveWidth($element, 'element');
  6201. }
  6202. if (method == 'element') {
  6203. var elementWidth = $element.outerWidth(false);
  6204. if (elementWidth <= 0) {
  6205. return 'auto';
  6206. }
  6207. return elementWidth + 'px';
  6208. }
  6209. if (method == 'style') {
  6210. var style = $element.attr('style');
  6211. if (typeof(style) !== 'string') {
  6212. return null;
  6213. }
  6214. var attrs = style.split(';');
  6215. for (var i = 0, l = attrs.length; i < l; i = i + 1) {
  6216. var attr = attrs[i].replace(/\s/g, '');
  6217. var matches = attr.match(WIDTH);
  6218. if (matches !== null && matches.length >= 1) {
  6219. return matches[1];
  6220. }
  6221. }
  6222. return null;
  6223. }
  6224. return method;
  6225. };
  6226. Select2.prototype._bindAdapters = function () {
  6227. this.dataAdapter.bind(this, this.$container);
  6228. this.selection.bind(this, this.$container);
  6229. this.dropdown.bind(this, this.$container);
  6230. this.results.bind(this, this.$container);
  6231. };
  6232. Select2.prototype._registerDomEvents = function () {
  6233. var self = this;
  6234. this.$element.on('change.pumselect2', function () {
  6235. self.dataAdapter.current(function (data) {
  6236. self.trigger('selection:update', {
  6237. data: data
  6238. });
  6239. });
  6240. });
  6241. this._sync = Utils.bind(this._syncAttributes, this);
  6242. if (this.$element[0].attachEvent) {
  6243. this.$element[0].attachEvent('onpropertychange', this._sync);
  6244. }
  6245. var observer = window.MutationObserver ||
  6246. window.WebKitMutationObserver ||
  6247. window.MozMutationObserver
  6248. ;
  6249. if (observer != null) {
  6250. this._observer = new observer(function (mutations) {
  6251. $.each(mutations, self._sync);
  6252. });
  6253. this._observer.observe(this.$element[0], {
  6254. attributes: true,
  6255. subtree: false
  6256. });
  6257. } else if (this.$element[0].addEventListener) {
  6258. this.$element[0].addEventListener('DOMAttrModified', self._sync, false);
  6259. }
  6260. };
  6261. Select2.prototype._registerDataEvents = function () {
  6262. var self = this;
  6263. this.dataAdapter.on('*', function (name, params) {
  6264. self.trigger(name, params);
  6265. });
  6266. };
  6267. Select2.prototype._registerSelectionEvents = function () {
  6268. var self = this;
  6269. var nonRelayEvents = ['toggle', 'focus'];
  6270. this.selection.on('toggle', function () {
  6271. self.toggleDropdown();
  6272. });
  6273. this.selection.on('focus', function (params) {
  6274. self.focus(params);
  6275. });
  6276. this.selection.on('*', function (name, params) {
  6277. if ($.inArray(name, nonRelayEvents) !== -1) {
  6278. return;
  6279. }
  6280. self.trigger(name, params);
  6281. });
  6282. };
  6283. Select2.prototype._registerDropdownEvents = function () {
  6284. var self = this;
  6285. this.dropdown.on('*', function (name, params) {
  6286. self.trigger(name, params);
  6287. });
  6288. };
  6289. Select2.prototype._registerResultsEvents = function () {
  6290. var self = this;
  6291. this.results.on('*', function (name, params) {
  6292. self.trigger(name, params);
  6293. });
  6294. };
  6295. Select2.prototype._registerEvents = function () {
  6296. var self = this;
  6297. this.on('open', function () {
  6298. self.$container.addClass('pumselect2-container--open');
  6299. });
  6300. this.on('close', function () {
  6301. self.$container.removeClass('pumselect2-container--open');
  6302. });
  6303. this.on('enable', function () {
  6304. self.$container.removeClass('pumselect2-container--disabled');
  6305. });
  6306. this.on('disable', function () {
  6307. self.$container.addClass('pumselect2-container--disabled');
  6308. });
  6309. this.on('blur', function () {
  6310. self.$container.removeClass('pumselect2-container--focus');
  6311. });
  6312. this.on('query', function (params) {
  6313. if (!self.isOpen()) {
  6314. self.trigger('open', {});
  6315. }
  6316. this.dataAdapter.query(params, function (data) {
  6317. self.trigger('results:all', {
  6318. data: data,
  6319. query: params
  6320. });
  6321. });
  6322. });
  6323. this.on('query:append', function (params) {
  6324. this.dataAdapter.query(params, function (data) {
  6325. self.trigger('results:append', {
  6326. data: data,
  6327. query: params
  6328. });
  6329. });
  6330. });
  6331. this.on('keypress', function (evt) {
  6332. var key = evt.which;
  6333. if (self.isOpen()) {
  6334. if (key === KEYS.ESC || key === KEYS.TAB ||
  6335. (key === KEYS.UP && evt.altKey)) {
  6336. self.close();
  6337. evt.preventDefault();
  6338. } else if (key === KEYS.ENTER) {
  6339. self.trigger('results:select', {});
  6340. evt.preventDefault();
  6341. } else if ((key === KEYS.SPACE && evt.ctrlKey)) {
  6342. self.trigger('results:toggle', {});
  6343. evt.preventDefault();
  6344. } else if (key === KEYS.UP) {
  6345. self.trigger('results:previous', {});
  6346. evt.preventDefault();
  6347. } else if (key === KEYS.DOWN) {
  6348. self.trigger('results:next', {});
  6349. evt.preventDefault();
  6350. }
  6351. } else {
  6352. if (key === KEYS.ENTER || key === KEYS.SPACE ||
  6353. (key === KEYS.DOWN && evt.altKey)) {
  6354. self.open();
  6355. evt.preventDefault();
  6356. }
  6357. }
  6358. });
  6359. };
  6360. Select2.prototype._syncAttributes = function () {
  6361. this.options.set('disabled', this.$element.prop('disabled'));
  6362. if (this.options.get('disabled')) {
  6363. if (this.isOpen()) {
  6364. this.close();
  6365. }
  6366. this.trigger('disable', {});
  6367. } else {
  6368. this.trigger('enable', {});
  6369. }
  6370. };
  6371. /**
  6372. * Override the trigger method to automatically trigger pre-events when
  6373. * there are events that can be prevented.
  6374. */
  6375. Select2.prototype.trigger = function (name, args) {
  6376. var actualTrigger = Select2.__super__.trigger;
  6377. var preTriggerMap = {
  6378. 'open': 'opening',
  6379. 'close': 'closing',
  6380. 'select': 'selecting',
  6381. 'unselect': 'unselecting'
  6382. };
  6383. if (args === undefined) {
  6384. args = {};
  6385. }
  6386. if (name in preTriggerMap) {
  6387. var preTriggerName = preTriggerMap[name];
  6388. var preTriggerArgs = {
  6389. prevented: false,
  6390. name: name,
  6391. args: args
  6392. };
  6393. actualTrigger.call(this, preTriggerName, preTriggerArgs);
  6394. if (preTriggerArgs.prevented) {
  6395. args.prevented = true;
  6396. return;
  6397. }
  6398. }
  6399. actualTrigger.call(this, name, args);
  6400. };
  6401. Select2.prototype.toggleDropdown = function () {
  6402. if (this.options.get('disabled')) {
  6403. return;
  6404. }
  6405. if (this.isOpen()) {
  6406. this.close();
  6407. } else {
  6408. this.open();
  6409. }
  6410. };
  6411. Select2.prototype.open = function () {
  6412. if (this.isOpen()) {
  6413. return;
  6414. }
  6415. this.trigger('query', {});
  6416. };
  6417. Select2.prototype.close = function () {
  6418. if (!this.isOpen()) {
  6419. return;
  6420. }
  6421. this.trigger('close', {});
  6422. };
  6423. Select2.prototype.isOpen = function () {
  6424. return this.$container.hasClass('pumselect2-container--open');
  6425. };
  6426. Select2.prototype.hasFocus = function () {
  6427. return this.$container.hasClass('pumselect2-container--focus');
  6428. };
  6429. Select2.prototype.focus = function (data) {
  6430. // No need to re-trigger focus events if we are already focused
  6431. if (this.hasFocus()) {
  6432. return;
  6433. }
  6434. this.$container.addClass('pumselect2-container--focus');
  6435. this.trigger('focus', {});
  6436. };
  6437. Select2.prototype.enable = function (args) {
  6438. if (this.options.get('debug') && window.console && console.warn) {
  6439. console.warn(
  6440. 'Select2: The `pumselect2("enable")` method has been deprecated and will' +
  6441. ' be removed in later Select2 versions. Use $element.prop("disabled")' +
  6442. ' instead.'
  6443. );
  6444. }
  6445. if (args == null || args.length === 0) {
  6446. args = [true];
  6447. }
  6448. var disabled = !args[0];
  6449. this.$element.prop('disabled', disabled);
  6450. };
  6451. Select2.prototype.data = function () {
  6452. if (this.options.get('debug') &&
  6453. arguments.length > 0 && window.console && console.warn) {
  6454. console.warn(
  6455. 'Select2: Data can no longer be set using `pumselect2("data")`. You ' +
  6456. 'should consider setting the value instead using `$element.val()`.'
  6457. );
  6458. }
  6459. var data = [];
  6460. this.dataAdapter.current(function (currentData) {
  6461. data = currentData;
  6462. });
  6463. return data;
  6464. };
  6465. Select2.prototype.val = function (args) {
  6466. if (this.options.get('debug') && window.console && console.warn) {
  6467. console.warn(
  6468. 'Select2: The `pumselect2("val")` method has been deprecated and will be' +
  6469. ' removed in later Select2 versions. Use $element.val() instead.'
  6470. );
  6471. }
  6472. if (args == null || args.length === 0) {
  6473. return this.$element.val();
  6474. }
  6475. var newVal = args[0];
  6476. if ($.isArray(newVal)) {
  6477. newVal = $.map(newVal, function (obj) {
  6478. return obj.toString();
  6479. });
  6480. }
  6481. this.$element.val(newVal).trigger('change');
  6482. };
  6483. Select2.prototype.destroy = function () {
  6484. this.$container.remove();
  6485. if (this.$element[0].detachEvent) {
  6486. this.$element[0].detachEvent('onpropertychange', this._sync);
  6487. }
  6488. if (this._observer != null) {
  6489. this._observer.disconnect();
  6490. this._observer = null;
  6491. } else if (this.$element[0].removeEventListener) {
  6492. this.$element[0]
  6493. .removeEventListener('DOMAttrModified', this._sync, false);
  6494. }
  6495. this._sync = null;
  6496. this.$element.off('.pumselect2');
  6497. this.$element.attr('tabindex', this.$element.data('old-tabindex'));
  6498. this.$element.removeClass('pumselect2-hidden-accessible');
  6499. this.$element.attr('aria-hidden', 'false');
  6500. this.$element.removeData('pumselect2');
  6501. this.dataAdapter.destroy();
  6502. this.selection.destroy();
  6503. this.dropdown.destroy();
  6504. this.results.destroy();
  6505. this.dataAdapter = null;
  6506. this.selection = null;
  6507. this.dropdown = null;
  6508. this.results = null;
  6509. };
  6510. Select2.prototype.render = function () {
  6511. var $container = $(
  6512. '<span class="pumselect2 pumselect2-container">' +
  6513. '<span class="selection"></span>' +
  6514. '<span class="dropdown-wrapper" aria-hidden="true"></span>' +
  6515. '</span>'
  6516. );
  6517. $container.attr('dir', this.options.get('dir'));
  6518. this.$container = $container;
  6519. this.$container.addClass('pumselect2-container--' + this.options.get('theme'));
  6520. $container.data('element', this.$element);
  6521. return $container;
  6522. };
  6523. return Select2;
  6524. });
  6525. S2.define('pumselect2/compat/utils',[
  6526. 'jquery'
  6527. ], function ($) {
  6528. function syncCssClasses ($dest, $src, adapter) {
  6529. var classes, replacements = [], adapted;
  6530. classes = $.trim($dest.attr('class'));
  6531. if (classes) {
  6532. classes = '' + classes; // for IE which returns object
  6533. $(classes.split(/\s+/)).each(function () {
  6534. // Save all Select2 classes
  6535. if (this.indexOf('pumselect2-') === 0) {
  6536. replacements.push(this);
  6537. }
  6538. });
  6539. }
  6540. classes = $.trim($src.attr('class'));
  6541. if (classes) {
  6542. classes = '' + classes; // for IE which returns object
  6543. $(classes.split(/\s+/)).each(function () {
  6544. // Only adapt non-Select2 classes
  6545. if (this.indexOf('pumselect2-') !== 0) {
  6546. adapted = adapter(this);
  6547. if (adapted != null) {
  6548. replacements.push(adapted);
  6549. }
  6550. }
  6551. });
  6552. }
  6553. $dest.attr('class', replacements.join(' '));
  6554. }
  6555. return {
  6556. syncCssClasses: syncCssClasses
  6557. };
  6558. });
  6559. S2.define('pumselect2/compat/containerCss',[
  6560. 'jquery',
  6561. './utils'
  6562. ], function ($, CompatUtils) {
  6563. // No-op CSS adapter that discards all classes by default
  6564. function _containerAdapter (clazz) {
  6565. return null;
  6566. }
  6567. function ContainerCSS () { }
  6568. ContainerCSS.prototype.render = function (decorated) {
  6569. var $container = decorated.call(this);
  6570. var containerCssClass = this.options.get('containerCssClass') || '';
  6571. if ($.isFunction(containerCssClass)) {
  6572. containerCssClass = containerCssClass(this.$element);
  6573. }
  6574. var containerCssAdapter = this.options.get('adaptContainerCssClass');
  6575. containerCssAdapter = containerCssAdapter || _containerAdapter;
  6576. if (containerCssClass.indexOf(':all:') !== -1) {
  6577. containerCssClass = containerCssClass.replace(':all:', '');
  6578. var _cssAdapter = containerCssAdapter;
  6579. containerCssAdapter = function (clazz) {
  6580. var adapted = _cssAdapter(clazz);
  6581. if (adapted != null) {
  6582. // Append the old one along with the adapted one
  6583. return adapted + ' ' + clazz;
  6584. }
  6585. return clazz;
  6586. };
  6587. }
  6588. var containerCss = this.options.get('containerCss') || {};
  6589. if ($.isFunction(containerCss)) {
  6590. containerCss = containerCss(this.$element);
  6591. }
  6592. CompatUtils.syncCssClasses($container, this.$element, containerCssAdapter);
  6593. $container.css(containerCss);
  6594. $container.addClass(containerCssClass);
  6595. return $container;
  6596. };
  6597. return ContainerCSS;
  6598. });
  6599. S2.define('pumselect2/compat/dropdownCss',[
  6600. 'jquery',
  6601. './utils'
  6602. ], function ($, CompatUtils) {
  6603. // No-op CSS adapter that discards all classes by default
  6604. function _dropdownAdapter (clazz) {
  6605. return null;
  6606. }
  6607. function DropdownCSS () { }
  6608. DropdownCSS.prototype.render = function (decorated) {
  6609. var $dropdown = decorated.call(this);
  6610. var dropdownCssClass = this.options.get('dropdownCssClass') || '';
  6611. if ($.isFunction(dropdownCssClass)) {
  6612. dropdownCssClass = dropdownCssClass(this.$element);
  6613. }
  6614. var dropdownCssAdapter = this.options.get('adaptDropdownCssClass');
  6615. dropdownCssAdapter = dropdownCssAdapter || _dropdownAdapter;
  6616. if (dropdownCssClass.indexOf(':all:') !== -1) {
  6617. dropdownCssClass = dropdownCssClass.replace(':all:', '');
  6618. var _cssAdapter = dropdownCssAdapter;
  6619. dropdownCssAdapter = function (clazz) {
  6620. var adapted = _cssAdapter(clazz);
  6621. if (adapted != null) {
  6622. // Append the old one along with the adapted one
  6623. return adapted + ' ' + clazz;
  6624. }
  6625. return clazz;
  6626. };
  6627. }
  6628. var dropdownCss = this.options.get('dropdownCss') || {};
  6629. if ($.isFunction(dropdownCss)) {
  6630. dropdownCss = dropdownCss(this.$element);
  6631. }
  6632. CompatUtils.syncCssClasses($dropdown, this.$element, dropdownCssAdapter);
  6633. $dropdown.css(dropdownCss);
  6634. $dropdown.addClass(dropdownCssClass);
  6635. return $dropdown;
  6636. };
  6637. return DropdownCSS;
  6638. });
  6639. S2.define('pumselect2/compat/initSelection',[
  6640. 'jquery'
  6641. ], function ($) {
  6642. function InitSelection (decorated, $element, options) {
  6643. if (options.get('debug') && window.console && console.warn) {
  6644. console.warn(
  6645. 'Select2: The `initSelection` option has been deprecated in favor' +
  6646. ' of a custom data adapter that overrides the `current` method. ' +
  6647. 'This method is now called multiple times instead of a single ' +
  6648. 'time when the instance is initialized. Support will be removed ' +
  6649. 'for the `initSelection` option in future versions of Select2'
  6650. );
  6651. }
  6652. this.initSelection = options.get('initSelection');
  6653. this._isInitialized = false;
  6654. decorated.call(this, $element, options);
  6655. }
  6656. InitSelection.prototype.current = function (decorated, callback) {
  6657. var self = this;
  6658. if (this._isInitialized) {
  6659. decorated.call(this, callback);
  6660. return;
  6661. }
  6662. this.initSelection.call(null, this.$element, function (data) {
  6663. self._isInitialized = true;
  6664. if (!$.isArray(data)) {
  6665. data = [data];
  6666. }
  6667. callback(data);
  6668. });
  6669. };
  6670. return InitSelection;
  6671. });
  6672. S2.define('pumselect2/compat/inputData',[
  6673. 'jquery'
  6674. ], function ($) {
  6675. function InputData (decorated, $element, options) {
  6676. this._currentData = [];
  6677. this._valueSeparator = options.get('valueSeparator') || ',';
  6678. if ($element.prop('type') === 'hidden') {
  6679. if (options.get('debug') && console && console.warn) {
  6680. console.warn(
  6681. 'Select2: Using a hidden input with Select2 is no longer ' +
  6682. 'supported and may stop working in the future. It is recommended ' +
  6683. 'to use a `<select>` element instead.'
  6684. );
  6685. }
  6686. }
  6687. decorated.call(this, $element, options);
  6688. }
  6689. InputData.prototype.current = function (_, callback) {
  6690. function getSelected (data, selectedIds) {
  6691. var selected = [];
  6692. if (data.selected || $.inArray(data.id, selectedIds) !== -1) {
  6693. data.selected = true;
  6694. selected.push(data);
  6695. } else {
  6696. data.selected = false;
  6697. }
  6698. if (data.children) {
  6699. selected.push.apply(selected, getSelected(data.children, selectedIds));
  6700. }
  6701. return selected;
  6702. }
  6703. var selected = [];
  6704. for (var d = 0; d < this._currentData.length; d++) {
  6705. var data = this._currentData[d];
  6706. selected.push.apply(
  6707. selected,
  6708. getSelected(
  6709. data,
  6710. this.$element.val().split(
  6711. this._valueSeparator
  6712. )
  6713. )
  6714. );
  6715. }
  6716. callback(selected);
  6717. };
  6718. InputData.prototype.select = function (_, data) {
  6719. if (!this.options.get('multiple')) {
  6720. this.current(function (allData) {
  6721. $.map(allData, function (data) {
  6722. data.selected = false;
  6723. });
  6724. });
  6725. this.$element.val(data.id);
  6726. this.$element.trigger('change');
  6727. } else {
  6728. var value = this.$element.val();
  6729. value += this._valueSeparator + data.id;
  6730. this.$element.val(value);
  6731. this.$element.trigger('change');
  6732. }
  6733. };
  6734. InputData.prototype.unselect = function (_, data) {
  6735. var self = this;
  6736. data.selected = false;
  6737. this.current(function (allData) {
  6738. var values = [];
  6739. for (var d = 0; d < allData.length; d++) {
  6740. var item = allData[d];
  6741. if (data.id == item.id) {
  6742. continue;
  6743. }
  6744. values.push(item.id);
  6745. }
  6746. self.$element.val(values.join(self._valueSeparator));
  6747. self.$element.trigger('change');
  6748. });
  6749. };
  6750. InputData.prototype.query = function (_, params, callback) {
  6751. var results = [];
  6752. for (var d = 0; d < this._currentData.length; d++) {
  6753. var data = this._currentData[d];
  6754. var matches = this.matches(params, data);
  6755. if (matches !== null) {
  6756. results.push(matches);
  6757. }
  6758. }
  6759. callback({
  6760. results: results
  6761. });
  6762. };
  6763. InputData.prototype.addOptions = function (_, $options) {
  6764. var options = $.map($options, function ($option) {
  6765. return $.data($option[0], 'data');
  6766. });
  6767. this._currentData.push.apply(this._currentData, options);
  6768. };
  6769. return InputData;
  6770. });
  6771. S2.define('pumselect2/compat/matcher',[
  6772. 'jquery'
  6773. ], function ($) {
  6774. function oldMatcher (matcher) {
  6775. function wrappedMatcher (params, data) {
  6776. var match = $.extend(true, {}, data);
  6777. if (params.term == null || $.trim(params.term) === '') {
  6778. return match;
  6779. }
  6780. if (data.children) {
  6781. for (var c = data.children.length - 1; c >= 0; c--) {
  6782. var child = data.children[c];
  6783. // Check if the child object matches
  6784. // The old matcher returned a boolean true or false
  6785. var doesMatch = matcher(params.term, child.text, child);
  6786. // If the child didn't match, pop it off
  6787. if (!doesMatch) {
  6788. match.children.splice(c, 1);
  6789. }
  6790. }
  6791. if (match.children.length > 0) {
  6792. return match;
  6793. }
  6794. }
  6795. if (matcher(params.term, data.text, data)) {
  6796. return match;
  6797. }
  6798. return null;
  6799. }
  6800. return wrappedMatcher;
  6801. }
  6802. return oldMatcher;
  6803. });
  6804. S2.define('pumselect2/compat/query',[
  6805. ], function () {
  6806. function Query (decorated, $element, options) {
  6807. if (options.get('debug') && window.console && console.warn) {
  6808. console.warn(
  6809. 'Select2: The `query` option has been deprecated in favor of a ' +
  6810. 'custom data adapter that overrides the `query` method. Support ' +
  6811. 'will be removed for the `query` option in future versions of ' +
  6812. 'Select2.'
  6813. );
  6814. }
  6815. decorated.call(this, $element, options);
  6816. }
  6817. Query.prototype.query = function (_, params, callback) {
  6818. params.callback = callback;
  6819. var query = this.options.get('query');
  6820. query.call(null, params);
  6821. };
  6822. return Query;
  6823. });
  6824. S2.define('pumselect2/dropdown/attachContainer',[
  6825. ], function () {
  6826. function AttachContainer (decorated, $element, options) {
  6827. decorated.call(this, $element, options);
  6828. }
  6829. AttachContainer.prototype.position =
  6830. function (decorated, $dropdown, $container) {
  6831. var $dropdownContainer = $container.find('.dropdown-wrapper');
  6832. $dropdownContainer.append($dropdown);
  6833. $dropdown.addClass('pumselect2-dropdown--below');
  6834. $container.addClass('pumselect2-container--below');
  6835. };
  6836. return AttachContainer;
  6837. });
  6838. S2.define('pumselect2/dropdown/stopPropagation',[
  6839. ], function () {
  6840. function StopPropagation () { }
  6841. StopPropagation.prototype.bind = function (decorated, container, $container) {
  6842. decorated.call(this, container, $container);
  6843. var stoppedEvents = [
  6844. 'blur',
  6845. 'change',
  6846. 'click',
  6847. 'dblclick',
  6848. 'focus',
  6849. 'focusin',
  6850. 'focusout',
  6851. 'input',
  6852. 'keydown',
  6853. 'keyup',
  6854. 'keypress',
  6855. 'mousedown',
  6856. 'mouseenter',
  6857. 'mouseleave',
  6858. 'mousemove',
  6859. 'mouseover',
  6860. 'mouseup',
  6861. 'search',
  6862. 'touchend',
  6863. 'touchstart'
  6864. ];
  6865. this.$dropdown.on(stoppedEvents.join(' '), function (evt) {
  6866. evt.stopPropagation();
  6867. });
  6868. };
  6869. return StopPropagation;
  6870. });
  6871. S2.define('pumselect2/selection/stopPropagation',[
  6872. ], function () {
  6873. function StopPropagation () { }
  6874. StopPropagation.prototype.bind = function (decorated, container, $container) {
  6875. decorated.call(this, container, $container);
  6876. var stoppedEvents = [
  6877. 'blur',
  6878. 'change',
  6879. 'click',
  6880. 'dblclick',
  6881. 'focus',
  6882. 'focusin',
  6883. 'focusout',
  6884. 'input',
  6885. 'keydown',
  6886. 'keyup',
  6887. 'keypress',
  6888. 'mousedown',
  6889. 'mouseenter',
  6890. 'mouseleave',
  6891. 'mousemove',
  6892. 'mouseover',
  6893. 'mouseup',
  6894. 'search',
  6895. 'touchend',
  6896. 'touchstart'
  6897. ];
  6898. this.$selection.on(stoppedEvents.join(' '), function (evt) {
  6899. evt.stopPropagation();
  6900. });
  6901. };
  6902. return StopPropagation;
  6903. });
  6904. /*!
  6905. * jQuery Mousewheel 3.1.13
  6906. *
  6907. * Copyright jQuery Foundation and other contributors
  6908. * Released under the MIT license
  6909. * http://jquery.org/license
  6910. */
  6911. (function (factory) {
  6912. if ( typeof S2.define === 'function' && S2.define.amd ) {
  6913. // AMD. Register as an anonymous module.
  6914. S2.define('jquery-mousewheel',['jquery'], factory);
  6915. } else if (typeof exports === 'object') {
  6916. // Node/CommonJS style for Browserify
  6917. module.exports = factory;
  6918. } else {
  6919. // Browser globals
  6920. factory(jQuery);
  6921. }
  6922. }(function ($) {
  6923. var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'],
  6924. toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ?
  6925. ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'],
  6926. slice = Array.prototype.slice,
  6927. nullLowestDeltaTimeout, lowestDelta;
  6928. if ( $.event.fixHooks ) {
  6929. for ( var i = toFix.length; i; ) {
  6930. $.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks;
  6931. }
  6932. }
  6933. var special = $.event.special.mousewheel = {
  6934. version: '3.1.12',
  6935. setup: function() {
  6936. if ( this.addEventListener ) {
  6937. for ( var i = toBind.length; i; ) {
  6938. this.addEventListener( toBind[--i], handler, false );
  6939. }
  6940. } else {
  6941. this.onmousewheel = handler;
  6942. }
  6943. // Store the line height and page height for this particular element
  6944. $.data(this, 'mousewheel-line-height', special.getLineHeight(this));
  6945. $.data(this, 'mousewheel-page-height', special.getPageHeight(this));
  6946. },
  6947. teardown: function() {
  6948. if ( this.removeEventListener ) {
  6949. for ( var i = toBind.length; i; ) {
  6950. this.removeEventListener( toBind[--i], handler, false );
  6951. }
  6952. } else {
  6953. this.onmousewheel = null;
  6954. }
  6955. // Clean up the data we added to the element
  6956. $.removeData(this, 'mousewheel-line-height');
  6957. $.removeData(this, 'mousewheel-page-height');
  6958. },
  6959. getLineHeight: function(elem) {
  6960. var $elem = $(elem),
  6961. $parent = $elem['offsetParent' in $.fn ? 'offsetParent' : 'parent']();
  6962. if (!$parent.length) {
  6963. $parent = $('body');
  6964. }
  6965. return parseInt($parent.css('fontSize'), 10) || parseInt($elem.css('fontSize'), 10) || 16;
  6966. },
  6967. getPageHeight: function(elem) {
  6968. return $(elem).height();
  6969. },
  6970. settings: {
  6971. adjustOldDeltas: true, // see shouldAdjustOldDeltas() below
  6972. normalizeOffset: true // calls getBoundingClientRect for each event
  6973. }
  6974. };
  6975. $.fn.extend({
  6976. mousewheel: function(fn) {
  6977. return fn ? this.bind('mousewheel', fn) : this.trigger('mousewheel');
  6978. },
  6979. unmousewheel: function(fn) {
  6980. return this.unbind('mousewheel', fn);
  6981. }
  6982. });
  6983. function handler(event) {
  6984. var orgEvent = event || window.event,
  6985. args = slice.call(arguments, 1),
  6986. delta = 0,
  6987. deltaX = 0,
  6988. deltaY = 0,
  6989. absDelta = 0,
  6990. offsetX = 0,
  6991. offsetY = 0;
  6992. event = $.event.fix(orgEvent);
  6993. event.type = 'mousewheel';
  6994. // Old school scrollwheel delta
  6995. if ( 'detail' in orgEvent ) { deltaY = orgEvent.detail * -1; }
  6996. if ( 'wheelDelta' in orgEvent ) { deltaY = orgEvent.wheelDelta; }
  6997. if ( 'wheelDeltaY' in orgEvent ) { deltaY = orgEvent.wheelDeltaY; }
  6998. if ( 'wheelDeltaX' in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; }
  6999. // Firefox < 17 horizontal scrolling related to DOMMouseScroll event
  7000. if ( 'axis' in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
  7001. deltaX = deltaY * -1;
  7002. deltaY = 0;
  7003. }
  7004. // Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy
  7005. delta = deltaY === 0 ? deltaX : deltaY;
  7006. // New school wheel delta (wheel event)
  7007. if ( 'deltaY' in orgEvent ) {
  7008. deltaY = orgEvent.deltaY * -1;
  7009. delta = deltaY;
  7010. }
  7011. if ( 'deltaX' in orgEvent ) {
  7012. deltaX = orgEvent.deltaX;
  7013. if ( deltaY === 0 ) { delta = deltaX * -1; }
  7014. }
  7015. // No change actually happened, no reason to go any further
  7016. if ( deltaY === 0 && deltaX === 0 ) { return; }
  7017. // Need to convert lines and pages to pixels if we aren't already in pixels
  7018. // There are three delta modes:
  7019. // * deltaMode 0 is by pixels, nothing to do
  7020. // * deltaMode 1 is by lines
  7021. // * deltaMode 2 is by pages
  7022. if ( orgEvent.deltaMode === 1 ) {
  7023. var lineHeight = $.data(this, 'mousewheel-line-height');
  7024. delta *= lineHeight;
  7025. deltaY *= lineHeight;
  7026. deltaX *= lineHeight;
  7027. } else if ( orgEvent.deltaMode === 2 ) {
  7028. var pageHeight = $.data(this, 'mousewheel-page-height');
  7029. delta *= pageHeight;
  7030. deltaY *= pageHeight;
  7031. deltaX *= pageHeight;
  7032. }
  7033. // Store lowest absolute delta to normalize the delta values
  7034. absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );
  7035. if ( !lowestDelta || absDelta < lowestDelta ) {
  7036. lowestDelta = absDelta;
  7037. // Adjust older deltas if necessary
  7038. if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
  7039. lowestDelta /= 40;
  7040. }
  7041. }
  7042. // Adjust older deltas if necessary
  7043. if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
  7044. // Divide all the things by 40!
  7045. delta /= 40;
  7046. deltaX /= 40;
  7047. deltaY /= 40;
  7048. }
  7049. // Get a whole, normalized value for the deltas
  7050. delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);
  7051. deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);
  7052. deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);
  7053. // Normalise offsetX and offsetY properties
  7054. if ( special.settings.normalizeOffset && this.getBoundingClientRect ) {
  7055. var boundingRect = this.getBoundingClientRect();
  7056. offsetX = event.clientX - boundingRect.left;
  7057. offsetY = event.clientY - boundingRect.top;
  7058. }
  7059. // Add information to the event object
  7060. event.deltaX = deltaX;
  7061. event.deltaY = deltaY;
  7062. event.deltaFactor = lowestDelta;
  7063. event.offsetX = offsetX;
  7064. event.offsetY = offsetY;
  7065. // Go ahead and set deltaMode to 0 since we converted to pixels
  7066. // Although this is a little odd since we overwrite the deltaX/Y
  7067. // properties with normalized deltas.
  7068. event.deltaMode = 0;
  7069. // Add event and delta to the front of the arguments
  7070. args.unshift(event, delta, deltaX, deltaY);
  7071. // Clearout lowestDelta after sometime to better
  7072. // handle multiple device types that give different
  7073. // a different lowestDelta
  7074. // Ex: trackpad = 3 and mouse wheel = 120
  7075. if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); }
  7076. nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200);
  7077. return ($.event.dispatch || $.event.handle).apply(this, args);
  7078. }
  7079. function nullLowestDelta() {
  7080. lowestDelta = null;
  7081. }
  7082. function shouldAdjustOldDeltas(orgEvent, absDelta) {
  7083. // If this is an older event and the delta is divisable by 120,
  7084. // then we are assuming that the browser is treating this as an
  7085. // older mouse wheel event and that we should divide the deltas
  7086. // by 40 to try and get a more usable deltaFactor.
  7087. // Side note, this actually impacts the reported scroll distance
  7088. // in older browsers and can cause scrolling to be slower than native.
  7089. // Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false.
  7090. return special.settings.adjustOldDeltas && orgEvent.type === 'mousewheel' && absDelta % 120 === 0;
  7091. }
  7092. }));
  7093. S2.define('jquery.pumselect2',[
  7094. 'jquery',
  7095. 'jquery-mousewheel',
  7096. './pumselect2/core',
  7097. './pumselect2/defaults'
  7098. ], function ($, _, Select2, Defaults) {
  7099. if ($.fn.pumselect2 == null) {
  7100. // All methods that should return the element
  7101. var thisMethods = ['open', 'close', 'destroy'];
  7102. $.fn.pumselect2 = function (options) {
  7103. options = options || {};
  7104. if (typeof options === 'object') {
  7105. this.each(function () {
  7106. var instanceOptions = $.extend(true, {}, options);
  7107. var instance = new Select2($(this), instanceOptions);
  7108. });
  7109. return this;
  7110. } else if (typeof options === 'string') {
  7111. var ret;
  7112. this.each(function () {
  7113. var instance = $(this).data('pumselect2');
  7114. if (instance == null && window.console && console.error) {
  7115. console.error(
  7116. 'The pumselect2(\'' + options + '\') method was called on an ' +
  7117. 'element that is not using Select2.'
  7118. );
  7119. }
  7120. var args = Array.prototype.slice.call(arguments, 1);
  7121. ret = instance[options].apply(instance, args);
  7122. });
  7123. // Check if we should be returning `this`
  7124. if ($.inArray(options, thisMethods) > -1) {
  7125. return this;
  7126. }
  7127. return ret;
  7128. } else {
  7129. throw new Error('Invalid arguments for Select2: ' + options);
  7130. }
  7131. };
  7132. }
  7133. if ($.fn.pumselect2.defaults == null) {
  7134. $.fn.pumselect2.defaults = Defaults;
  7135. }
  7136. return Select2;
  7137. });
  7138. // Return the AMD loader configuration so it can be used outside of this file
  7139. return {
  7140. define: S2.define,
  7141. require: S2.require
  7142. };
  7143. }());
  7144. // Autoload the jQuery bindings
  7145. // We know that all of the modules exist above this, so we're safe
  7146. var pumselect2 = S2.require('jquery.pumselect2');
  7147. // Hold the AMD module references on the jQuery function that was just loaded
  7148. // This allows Select2 to use the internal loader outside of this file, such
  7149. // as in the language files.
  7150. jQuery.fn.pumselect2.amd = S2;
  7151. // Return the Select2 instance for anyone who is importing it.
  7152. return pumselect2;
  7153. }));