Açıklama Yok

media-views.js 268KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543
  1. /******/ (function(modules) { // webpackBootstrap
  2. /******/ // The module cache
  3. /******/ var installedModules = {};
  4. /******/
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/
  8. /******/ // Check if module is in cache
  9. /******/ if(installedModules[moduleId]) {
  10. /******/ return installedModules[moduleId].exports;
  11. /******/ }
  12. /******/ // Create a new module (and put it into the cache)
  13. /******/ var module = installedModules[moduleId] = {
  14. /******/ i: moduleId,
  15. /******/ l: false,
  16. /******/ exports: {}
  17. /******/ };
  18. /******/
  19. /******/ // Execute the module function
  20. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  21. /******/
  22. /******/ // Flag the module as loaded
  23. /******/ module.l = true;
  24. /******/
  25. /******/ // Return the exports of the module
  26. /******/ return module.exports;
  27. /******/ }
  28. /******/
  29. /******/
  30. /******/ // expose the modules object (__webpack_modules__)
  31. /******/ __webpack_require__.m = modules;
  32. /******/
  33. /******/ // expose the module cache
  34. /******/ __webpack_require__.c = installedModules;
  35. /******/
  36. /******/ // define getter function for harmony exports
  37. /******/ __webpack_require__.d = function(exports, name, getter) {
  38. /******/ if(!__webpack_require__.o(exports, name)) {
  39. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  40. /******/ }
  41. /******/ };
  42. /******/
  43. /******/ // define __esModule on exports
  44. /******/ __webpack_require__.r = function(exports) {
  45. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  46. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  47. /******/ }
  48. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  49. /******/ };
  50. /******/
  51. /******/ // create a fake namespace object
  52. /******/ // mode & 1: value is a module id, require it
  53. /******/ // mode & 2: merge all properties of value into the ns
  54. /******/ // mode & 4: return value when already ns object
  55. /******/ // mode & 8|1: behave like require
  56. /******/ __webpack_require__.t = function(value, mode) {
  57. /******/ if(mode & 1) value = __webpack_require__(value);
  58. /******/ if(mode & 8) return value;
  59. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  60. /******/ var ns = Object.create(null);
  61. /******/ __webpack_require__.r(ns);
  62. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  63. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  64. /******/ return ns;
  65. /******/ };
  66. /******/
  67. /******/ // getDefaultExport function for compatibility with non-harmony modules
  68. /******/ __webpack_require__.n = function(module) {
  69. /******/ var getter = module && module.__esModule ?
  70. /******/ function getDefault() { return module['default']; } :
  71. /******/ function getModuleExports() { return module; };
  72. /******/ __webpack_require__.d(getter, 'a', getter);
  73. /******/ return getter;
  74. /******/ };
  75. /******/
  76. /******/ // Object.prototype.hasOwnProperty.call
  77. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  78. /******/
  79. /******/ // __webpack_public_path__
  80. /******/ __webpack_require__.p = "";
  81. /******/
  82. /******/
  83. /******/ // Load entry module and return exports
  84. /******/ return __webpack_require__(__webpack_require__.s = 3);
  85. /******/ })
  86. /************************************************************************/
  87. /******/ ({
  88. /***/ "+B8m":
  89. /***/ (function(module, exports) {
  90. var AttachmentDisplay = wp.media.view.Settings.AttachmentDisplay,
  91. EmbedImage;
  92. /**
  93. * wp.media.view.EmbedImage
  94. *
  95. * @memberOf wp.media.view
  96. *
  97. * @class
  98. * @augments wp.media.view.Settings.AttachmentDisplay
  99. * @augments wp.media.view.Settings
  100. * @augments wp.media.View
  101. * @augments wp.Backbone.View
  102. * @augments Backbone.View
  103. */
  104. EmbedImage = AttachmentDisplay.extend(/** @lends wp.media.view.EmbedImage.prototype */{
  105. className: 'embed-media-settings',
  106. template: wp.template('embed-image-settings'),
  107. initialize: function() {
  108. /**
  109. * Call `initialize` directly on parent class with passed arguments
  110. */
  111. AttachmentDisplay.prototype.initialize.apply( this, arguments );
  112. this.listenTo( this.model, 'change:url', this.updateImage );
  113. },
  114. updateImage: function() {
  115. this.$('img').attr( 'src', this.model.get('url') );
  116. }
  117. });
  118. module.exports = EmbedImage;
  119. /***/ }),
  120. /***/ "+mQJ":
  121. /***/ (function(module, exports) {
  122. var View = wp.media.View,
  123. $ = jQuery,
  124. l10n = wp.media.view.l10n,
  125. EmbedUrl;
  126. /**
  127. * wp.media.view.EmbedUrl
  128. *
  129. * @memberOf wp.media.view
  130. *
  131. * @class
  132. * @augments wp.media.View
  133. * @augments wp.Backbone.View
  134. * @augments Backbone.View
  135. */
  136. EmbedUrl = View.extend(/** @lends wp.media.view.EmbedUrl.prototype */{
  137. tagName: 'span',
  138. className: 'embed-url',
  139. events: {
  140. 'input': 'url'
  141. },
  142. initialize: function() {
  143. this.$input = $( '<input id="embed-url-field" type="url" />' )
  144. .attr( 'aria-label', l10n.insertFromUrlTitle )
  145. .val( this.model.get('url') );
  146. this.input = this.$input[0];
  147. this.spinner = $('<span class="spinner" />')[0];
  148. this.$el.append([ this.input, this.spinner ]);
  149. this.listenTo( this.model, 'change:url', this.render );
  150. if ( this.model.get( 'url' ) ) {
  151. _.delay( _.bind( function () {
  152. this.model.trigger( 'change:url' );
  153. }, this ), 500 );
  154. }
  155. },
  156. /**
  157. * @return {wp.media.view.EmbedUrl} Returns itself to allow chaining.
  158. */
  159. render: function() {
  160. var $input = this.$input;
  161. if ( $input.is(':focus') ) {
  162. return;
  163. }
  164. this.input.value = this.model.get('url') || 'http://';
  165. /**
  166. * Call `render` directly on parent class with passed arguments
  167. */
  168. View.prototype.render.apply( this, arguments );
  169. return this;
  170. },
  171. url: function( event ) {
  172. var url = event.target.value || '';
  173. this.model.set( 'url', url.trim() );
  174. }
  175. });
  176. module.exports = EmbedUrl;
  177. /***/ }),
  178. /***/ "04Ix":
  179. /***/ (function(module, exports) {
  180. var _n = wp.i18n._n,
  181. sprintf = wp.i18n.sprintf,
  182. Selection;
  183. /**
  184. * wp.media.view.Selection
  185. *
  186. * @memberOf wp.media.view
  187. *
  188. * @class
  189. * @augments wp.media.View
  190. * @augments wp.Backbone.View
  191. * @augments Backbone.View
  192. */
  193. Selection = wp.media.View.extend(/** @lends wp.media.view.Selection.prototype */{
  194. tagName: 'div',
  195. className: 'media-selection',
  196. template: wp.template('media-selection'),
  197. events: {
  198. 'click .edit-selection': 'edit',
  199. 'click .clear-selection': 'clear'
  200. },
  201. initialize: function() {
  202. _.defaults( this.options, {
  203. editable: false,
  204. clearable: true
  205. });
  206. /**
  207. * @member {wp.media.view.Attachments.Selection}
  208. */
  209. this.attachments = new wp.media.view.Attachments.Selection({
  210. controller: this.controller,
  211. collection: this.collection,
  212. selection: this.collection,
  213. model: new Backbone.Model()
  214. });
  215. this.views.set( '.selection-view', this.attachments );
  216. this.collection.on( 'add remove reset', this.refresh, this );
  217. this.controller.on( 'content:activate', this.refresh, this );
  218. },
  219. ready: function() {
  220. this.refresh();
  221. },
  222. refresh: function() {
  223. // If the selection hasn't been rendered, bail.
  224. if ( ! this.$el.children().length ) {
  225. return;
  226. }
  227. var collection = this.collection,
  228. editing = 'edit-selection' === this.controller.content.mode();
  229. // If nothing is selected, display nothing.
  230. this.$el.toggleClass( 'empty', ! collection.length );
  231. this.$el.toggleClass( 'one', 1 === collection.length );
  232. this.$el.toggleClass( 'editing', editing );
  233. this.$( '.count' ).text(
  234. /* translators: %s: Number of selected media attachments. */
  235. sprintf( _n( '%s item selected', '%s items selected', collection.length ), collection.length )
  236. );
  237. },
  238. edit: function( event ) {
  239. event.preventDefault();
  240. if ( this.options.editable ) {
  241. this.options.editable.call( this, this.collection );
  242. }
  243. },
  244. clear: function( event ) {
  245. event.preventDefault();
  246. this.collection.reset();
  247. // Move focus to the modal.
  248. this.controller.modal.focusManager.focus();
  249. }
  250. });
  251. module.exports = Selection;
  252. /***/ }),
  253. /***/ "1S4+":
  254. /***/ (function(module, exports) {
  255. var $ = jQuery,
  256. AttachmentFilters;
  257. /**
  258. * wp.media.view.AttachmentFilters
  259. *
  260. * @memberOf wp.media.view
  261. *
  262. * @class
  263. * @augments wp.media.View
  264. * @augments wp.Backbone.View
  265. * @augments Backbone.View
  266. */
  267. AttachmentFilters = wp.media.View.extend(/** @lends wp.media.view.AttachmentFilters.prototype */{
  268. tagName: 'select',
  269. className: 'attachment-filters',
  270. id: 'media-attachment-filters',
  271. events: {
  272. change: 'change'
  273. },
  274. keys: [],
  275. initialize: function() {
  276. this.createFilters();
  277. _.extend( this.filters, this.options.filters );
  278. // Build `<option>` elements.
  279. this.$el.html( _.chain( this.filters ).map( function( filter, value ) {
  280. return {
  281. el: $( '<option></option>' ).val( value ).html( filter.text )[0],
  282. priority: filter.priority || 50
  283. };
  284. }, this ).sortBy('priority').pluck('el').value() );
  285. this.listenTo( this.model, 'change', this.select );
  286. this.select();
  287. },
  288. /**
  289. * @abstract
  290. */
  291. createFilters: function() {
  292. this.filters = {};
  293. },
  294. /**
  295. * When the selected filter changes, update the Attachment Query properties to match.
  296. */
  297. change: function() {
  298. var filter = this.filters[ this.el.value ];
  299. if ( filter ) {
  300. this.model.set( filter.props );
  301. }
  302. },
  303. select: function() {
  304. var model = this.model,
  305. value = 'all',
  306. props = model.toJSON();
  307. _.find( this.filters, function( filter, id ) {
  308. var equal = _.all( filter.props, function( prop, key ) {
  309. return prop === ( _.isUndefined( props[ key ] ) ? null : props[ key ] );
  310. });
  311. if ( equal ) {
  312. return value = id;
  313. }
  314. });
  315. this.$el.val( value );
  316. }
  317. });
  318. module.exports = AttachmentFilters;
  319. /***/ }),
  320. /***/ "2AvB":
  321. /***/ (function(module, exports) {
  322. var Settings = wp.media.view.Settings,
  323. AttachmentDisplay;
  324. /**
  325. * wp.media.view.Settings.AttachmentDisplay
  326. *
  327. * @memberOf wp.media.view.Settings
  328. *
  329. * @class
  330. * @augments wp.media.view.Settings
  331. * @augments wp.media.View
  332. * @augments wp.Backbone.View
  333. * @augments Backbone.View
  334. */
  335. AttachmentDisplay = Settings.extend(/** @lends wp.media.view.Settings.AttachmentDisplay.prototype */{
  336. className: 'attachment-display-settings',
  337. template: wp.template('attachment-display-settings'),
  338. initialize: function() {
  339. var attachment = this.options.attachment;
  340. _.defaults( this.options, {
  341. userSettings: false
  342. });
  343. // Call 'initialize' directly on the parent class.
  344. Settings.prototype.initialize.apply( this, arguments );
  345. this.listenTo( this.model, 'change:link', this.updateLinkTo );
  346. if ( attachment ) {
  347. attachment.on( 'change:uploading', this.render, this );
  348. }
  349. },
  350. dispose: function() {
  351. var attachment = this.options.attachment;
  352. if ( attachment ) {
  353. attachment.off( null, null, this );
  354. }
  355. /**
  356. * call 'dispose' directly on the parent class
  357. */
  358. Settings.prototype.dispose.apply( this, arguments );
  359. },
  360. /**
  361. * @return {wp.media.view.AttachmentDisplay} Returns itself to allow chaining.
  362. */
  363. render: function() {
  364. var attachment = this.options.attachment;
  365. if ( attachment ) {
  366. _.extend( this.options, {
  367. sizes: attachment.get('sizes'),
  368. type: attachment.get('type')
  369. });
  370. }
  371. /**
  372. * call 'render' directly on the parent class
  373. */
  374. Settings.prototype.render.call( this );
  375. this.updateLinkTo();
  376. return this;
  377. },
  378. updateLinkTo: function() {
  379. var linkTo = this.model.get('link'),
  380. $input = this.$('.link-to-custom'),
  381. attachment = this.options.attachment;
  382. if ( 'none' === linkTo || 'embed' === linkTo || ( ! attachment && 'custom' !== linkTo ) ) {
  383. $input.closest( '.setting' ).addClass( 'hidden' );
  384. return;
  385. }
  386. if ( attachment ) {
  387. if ( 'post' === linkTo ) {
  388. $input.val( attachment.get('link') );
  389. } else if ( 'file' === linkTo ) {
  390. $input.val( attachment.get('url') );
  391. } else if ( ! this.model.get('linkUrl') ) {
  392. $input.val('http://');
  393. }
  394. $input.prop( 'readonly', 'custom' !== linkTo );
  395. }
  396. $input.closest( '.setting' ).removeClass( 'hidden' );
  397. if ( $input.length ) {
  398. $input[0].scrollIntoView();
  399. }
  400. }
  401. });
  402. module.exports = AttachmentDisplay;
  403. /***/ }),
  404. /***/ "2NU8":
  405. /***/ (function(module, exports) {
  406. var View = wp.media.View,
  407. Toolbar;
  408. /**
  409. * wp.media.view.Toolbar
  410. *
  411. * A toolbar which consists of a primary and a secondary section. Each sections
  412. * can be filled with views.
  413. *
  414. * @memberOf wp.media.view
  415. *
  416. * @class
  417. * @augments wp.media.View
  418. * @augments wp.Backbone.View
  419. * @augments Backbone.View
  420. */
  421. Toolbar = View.extend(/** @lends wp.media.view.Toolbar.prototype */{
  422. tagName: 'div',
  423. className: 'media-toolbar',
  424. initialize: function() {
  425. var state = this.controller.state(),
  426. selection = this.selection = state.get('selection'),
  427. library = this.library = state.get('library');
  428. this._views = {};
  429. // The toolbar is composed of two `PriorityList` views.
  430. this.primary = new wp.media.view.PriorityList();
  431. this.secondary = new wp.media.view.PriorityList();
  432. this.primary.$el.addClass('media-toolbar-primary search-form');
  433. this.secondary.$el.addClass('media-toolbar-secondary');
  434. this.views.set([ this.secondary, this.primary ]);
  435. if ( this.options.items ) {
  436. this.set( this.options.items, { silent: true });
  437. }
  438. if ( ! this.options.silent ) {
  439. this.render();
  440. }
  441. if ( selection ) {
  442. selection.on( 'add remove reset', this.refresh, this );
  443. }
  444. if ( library ) {
  445. library.on( 'add remove reset', this.refresh, this );
  446. }
  447. },
  448. /**
  449. * @return {wp.media.view.Toolbar} Returns itsef to allow chaining
  450. */
  451. dispose: function() {
  452. if ( this.selection ) {
  453. this.selection.off( null, null, this );
  454. }
  455. if ( this.library ) {
  456. this.library.off( null, null, this );
  457. }
  458. /**
  459. * call 'dispose' directly on the parent class
  460. */
  461. return View.prototype.dispose.apply( this, arguments );
  462. },
  463. ready: function() {
  464. this.refresh();
  465. },
  466. /**
  467. * @param {string} id
  468. * @param {Backbone.View|Object} view
  469. * @param {Object} [options={}]
  470. * @return {wp.media.view.Toolbar} Returns itself to allow chaining.
  471. */
  472. set: function( id, view, options ) {
  473. var list;
  474. options = options || {};
  475. // Accept an object with an `id` : `view` mapping.
  476. if ( _.isObject( id ) ) {
  477. _.each( id, function( view, id ) {
  478. this.set( id, view, { silent: true });
  479. }, this );
  480. } else {
  481. if ( ! ( view instanceof Backbone.View ) ) {
  482. view.classes = [ 'media-button-' + id ].concat( view.classes || [] );
  483. view = new wp.media.view.Button( view ).render();
  484. }
  485. view.controller = view.controller || this.controller;
  486. this._views[ id ] = view;
  487. list = view.options.priority < 0 ? 'secondary' : 'primary';
  488. this[ list ].set( id, view, options );
  489. }
  490. if ( ! options.silent ) {
  491. this.refresh();
  492. }
  493. return this;
  494. },
  495. /**
  496. * @param {string} id
  497. * @return {wp.media.view.Button}
  498. */
  499. get: function( id ) {
  500. return this._views[ id ];
  501. },
  502. /**
  503. * @param {string} id
  504. * @param {Object} options
  505. * @return {wp.media.view.Toolbar} Returns itself to allow chaining.
  506. */
  507. unset: function( id, options ) {
  508. delete this._views[ id ];
  509. this.primary.unset( id, options );
  510. this.secondary.unset( id, options );
  511. if ( ! options || ! options.silent ) {
  512. this.refresh();
  513. }
  514. return this;
  515. },
  516. refresh: function() {
  517. var state = this.controller.state(),
  518. library = state.get('library'),
  519. selection = state.get('selection');
  520. _.each( this._views, function( button ) {
  521. if ( ! button.model || ! button.options || ! button.options.requires ) {
  522. return;
  523. }
  524. var requires = button.options.requires,
  525. disabled = false;
  526. // Prevent insertion of attachments if any of them are still uploading.
  527. if ( selection && selection.models ) {
  528. disabled = _.some( selection.models, function( attachment ) {
  529. return attachment.get('uploading') === true;
  530. });
  531. }
  532. if ( requires.selection && selection && ! selection.length ) {
  533. disabled = true;
  534. } else if ( requires.library && library && ! library.length ) {
  535. disabled = true;
  536. }
  537. button.model.set( 'disabled', disabled );
  538. });
  539. }
  540. });
  541. module.exports = Toolbar;
  542. /***/ }),
  543. /***/ "2jku":
  544. /***/ (function(module, exports) {
  545. /**
  546. * wp.media.view.Attachment.Library
  547. *
  548. * @memberOf wp.media.view.Attachment
  549. *
  550. * @class
  551. * @augments wp.media.view.Attachment
  552. * @augments wp.media.View
  553. * @augments wp.Backbone.View
  554. * @augments Backbone.View
  555. */
  556. var Library = wp.media.view.Attachment.extend(/** @lends wp.media.view.Attachment.Library.prototype */{
  557. buttons: {
  558. check: true
  559. }
  560. });
  561. module.exports = Library;
  562. /***/ }),
  563. /***/ 3:
  564. /***/ (function(module, exports, __webpack_require__) {
  565. module.exports = __webpack_require__("tg/Y");
  566. /***/ }),
  567. /***/ "3nJM":
  568. /***/ (function(module, exports) {
  569. var $ = jQuery;
  570. /**
  571. * wp.media.view.FocusManager
  572. *
  573. * @memberOf wp.media.view
  574. *
  575. * @class
  576. * @augments wp.media.View
  577. * @augments wp.Backbone.View
  578. * @augments Backbone.View
  579. */
  580. var FocusManager = wp.media.View.extend(/** @lends wp.media.view.FocusManager.prototype */{
  581. events: {
  582. 'keydown': 'focusManagementMode'
  583. },
  584. /**
  585. * Initializes the Focus Manager.
  586. *
  587. * @param {Object} options The Focus Manager options.
  588. *
  589. * @since 5.3.0
  590. *
  591. * @return {void}
  592. */
  593. initialize: function( options ) {
  594. this.mode = options.mode || 'constrainTabbing';
  595. this.tabsAutomaticActivation = options.tabsAutomaticActivation || false;
  596. },
  597. /**
  598. * Determines which focus management mode to use.
  599. *
  600. * @since 5.3.0
  601. *
  602. * @param {Object} event jQuery event object.
  603. *
  604. * @return {void}
  605. */
  606. focusManagementMode: function( event ) {
  607. if ( this.mode === 'constrainTabbing' ) {
  608. this.constrainTabbing( event );
  609. }
  610. if ( this.mode === 'tabsNavigation' ) {
  611. this.tabsNavigation( event );
  612. }
  613. },
  614. /**
  615. * Gets all the tabbable elements.
  616. *
  617. * @since 5.3.0
  618. *
  619. * @return {Object} A jQuery collection of tabbable elements.
  620. */
  621. getTabbables: function() {
  622. // Skip the file input added by Plupload.
  623. return this.$( ':tabbable' ).not( '.moxie-shim input[type="file"]' );
  624. },
  625. /**
  626. * Moves focus to the modal dialog.
  627. *
  628. * @since 3.5.0
  629. *
  630. * @return {void}
  631. */
  632. focus: function() {
  633. this.$( '.media-modal' ).trigger( 'focus' );
  634. },
  635. /**
  636. * Constrains navigation with the Tab key within the media view element.
  637. *
  638. * @since 4.0.0
  639. *
  640. * @param {Object} event A keydown jQuery event.
  641. *
  642. * @return {void}
  643. */
  644. constrainTabbing: function( event ) {
  645. var tabbables;
  646. // Look for the tab key.
  647. if ( 9 !== event.keyCode ) {
  648. return;
  649. }
  650. tabbables = this.getTabbables();
  651. // Keep tab focus within media modal while it's open.
  652. if ( tabbables.last()[0] === event.target && ! event.shiftKey ) {
  653. tabbables.first().focus();
  654. return false;
  655. } else if ( tabbables.first()[0] === event.target && event.shiftKey ) {
  656. tabbables.last().focus();
  657. return false;
  658. }
  659. },
  660. /**
  661. * Hides from assistive technologies all the body children.
  662. *
  663. * Sets an `aria-hidden="true"` attribute on all the body children except
  664. * the provided element and other elements that should not be hidden.
  665. *
  666. * The reason why we use `aria-hidden` is that `aria-modal="true"` is buggy
  667. * in Safari 11.1 and support is spotty in other browsers. Also, `aria-modal="true"`
  668. * prevents the `wp.a11y.speak()` ARIA live regions to work as they're outside
  669. * of the modal dialog and get hidden from assistive technologies.
  670. *
  671. * @since 5.2.3
  672. *
  673. * @param {Object} visibleElement The jQuery object representing the element that should not be hidden.
  674. *
  675. * @return {void}
  676. */
  677. setAriaHiddenOnBodyChildren: function( visibleElement ) {
  678. var bodyChildren,
  679. self = this;
  680. if ( this.isBodyAriaHidden ) {
  681. return;
  682. }
  683. // Get all the body children.
  684. bodyChildren = document.body.children;
  685. // Loop through the body children and hide the ones that should be hidden.
  686. _.each( bodyChildren, function( element ) {
  687. // Don't hide the modal element.
  688. if ( element === visibleElement[0] ) {
  689. return;
  690. }
  691. // Determine the body children to hide.
  692. if ( self.elementShouldBeHidden( element ) ) {
  693. element.setAttribute( 'aria-hidden', 'true' );
  694. // Store the hidden elements.
  695. self.ariaHiddenElements.push( element );
  696. }
  697. } );
  698. this.isBodyAriaHidden = true;
  699. },
  700. /**
  701. * Unhides from assistive technologies all the body children.
  702. *
  703. * Makes visible again to assistive technologies all the body children
  704. * previously hidden and stored in this.ariaHiddenElements.
  705. *
  706. * @since 5.2.3
  707. *
  708. * @return {void}
  709. */
  710. removeAriaHiddenFromBodyChildren: function() {
  711. _.each( this.ariaHiddenElements, function( element ) {
  712. element.removeAttribute( 'aria-hidden' );
  713. } );
  714. this.ariaHiddenElements = [];
  715. this.isBodyAriaHidden = false;
  716. },
  717. /**
  718. * Determines if the passed element should not be hidden from assistive technologies.
  719. *
  720. * @since 5.2.3
  721. *
  722. * @param {Object} element The DOM element that should be checked.
  723. *
  724. * @return {boolean} Whether the element should not be hidden from assistive technologies.
  725. */
  726. elementShouldBeHidden: function( element ) {
  727. var role = element.getAttribute( 'role' ),
  728. liveRegionsRoles = [ 'alert', 'status', 'log', 'marquee', 'timer' ];
  729. /*
  730. * Don't hide scripts, elements that already have `aria-hidden`, and
  731. * ARIA live regions.
  732. */
  733. return ! (
  734. element.tagName === 'SCRIPT' ||
  735. element.hasAttribute( 'aria-hidden' ) ||
  736. element.hasAttribute( 'aria-live' ) ||
  737. liveRegionsRoles.indexOf( role ) !== -1
  738. );
  739. },
  740. /**
  741. * Whether the body children are hidden from assistive technologies.
  742. *
  743. * @since 5.2.3
  744. */
  745. isBodyAriaHidden: false,
  746. /**
  747. * Stores an array of DOM elements that should be hidden from assistive
  748. * technologies, for example when the media modal dialog opens.
  749. *
  750. * @since 5.2.3
  751. */
  752. ariaHiddenElements: [],
  753. /**
  754. * Holds the jQuery collection of ARIA tabs.
  755. *
  756. * @since 5.3.0
  757. */
  758. tabs: $(),
  759. /**
  760. * Sets up tabs in an ARIA tabbed interface.
  761. *
  762. * @since 5.3.0
  763. *
  764. * @param {Object} event jQuery event object.
  765. *
  766. * @return {void}
  767. */
  768. setupAriaTabs: function() {
  769. this.tabs = this.$( '[role="tab"]' );
  770. // Set up initial attributes.
  771. this.tabs.attr( {
  772. 'aria-selected': 'false',
  773. tabIndex: '-1'
  774. } );
  775. // Set up attributes on the initially active tab.
  776. this.tabs.filter( '.active' )
  777. .removeAttr( 'tabindex' )
  778. .attr( 'aria-selected', 'true' );
  779. },
  780. /**
  781. * Enables arrows navigation within the ARIA tabbed interface.
  782. *
  783. * @since 5.3.0
  784. *
  785. * @param {Object} event jQuery event object.
  786. *
  787. * @return {void}
  788. */
  789. tabsNavigation: function( event ) {
  790. var orientation = 'horizontal',
  791. keys = [ 32, 35, 36, 37, 38, 39, 40 ];
  792. // Return if not Spacebar, End, Home, or Arrow keys.
  793. if ( keys.indexOf( event.which ) === -1 ) {
  794. return;
  795. }
  796. // Determine navigation direction.
  797. if ( this.$el.attr( 'aria-orientation' ) === 'vertical' ) {
  798. orientation = 'vertical';
  799. }
  800. // Make Up and Down arrow keys do nothing with horizontal tabs.
  801. if ( orientation === 'horizontal' && [ 38, 40 ].indexOf( event.which ) !== -1 ) {
  802. return;
  803. }
  804. // Make Left and Right arrow keys do nothing with vertical tabs.
  805. if ( orientation === 'vertical' && [ 37, 39 ].indexOf( event.which ) !== -1 ) {
  806. return;
  807. }
  808. this.switchTabs( event, this.tabs );
  809. },
  810. /**
  811. * Switches tabs in the ARIA tabbed interface.
  812. *
  813. * @since 5.3.0
  814. *
  815. * @param {Object} event jQuery event object.
  816. *
  817. * @return {void}
  818. */
  819. switchTabs: function( event ) {
  820. var key = event.which,
  821. index = this.tabs.index( $( event.target ) ),
  822. newIndex;
  823. switch ( key ) {
  824. // Space bar: Activate current targeted tab.
  825. case 32: {
  826. this.activateTab( this.tabs[ index ] );
  827. break;
  828. }
  829. // End key: Activate last tab.
  830. case 35: {
  831. event.preventDefault();
  832. this.activateTab( this.tabs[ this.tabs.length - 1 ] );
  833. break;
  834. }
  835. // Home key: Activate first tab.
  836. case 36: {
  837. event.preventDefault();
  838. this.activateTab( this.tabs[ 0 ] );
  839. break;
  840. }
  841. // Left and up keys: Activate previous tab.
  842. case 37:
  843. case 38: {
  844. event.preventDefault();
  845. newIndex = ( index - 1 ) < 0 ? this.tabs.length - 1 : index - 1;
  846. this.activateTab( this.tabs[ newIndex ] );
  847. break;
  848. }
  849. // Right and down keys: Activate next tab.
  850. case 39:
  851. case 40: {
  852. event.preventDefault();
  853. newIndex = ( index + 1 ) === this.tabs.length ? 0 : index + 1;
  854. this.activateTab( this.tabs[ newIndex ] );
  855. break;
  856. }
  857. }
  858. },
  859. /**
  860. * Sets a single tab to be focusable and semantically selected.
  861. *
  862. * @since 5.3.0
  863. *
  864. * @param {Object} tab The tab DOM element.
  865. *
  866. * @return {void}
  867. */
  868. activateTab: function( tab ) {
  869. if ( ! tab ) {
  870. return;
  871. }
  872. // The tab is a DOM element: no need for jQuery methods.
  873. tab.focus();
  874. // Handle automatic activation.
  875. if ( this.tabsAutomaticActivation ) {
  876. tab.removeAttribute( 'tabindex' );
  877. tab.setAttribute( 'aria-selected', 'true' );
  878. tab.click();
  879. return;
  880. }
  881. // Handle manual activation.
  882. $( tab ).on( 'click', function() {
  883. tab.removeAttribute( 'tabindex' );
  884. tab.setAttribute( 'aria-selected', 'true' );
  885. } );
  886. }
  887. });
  888. module.exports = FocusManager;
  889. /***/ }),
  890. /***/ "4jjk":
  891. /***/ (function(module, exports) {
  892. var l10n = wp.media.view.l10n,
  893. Uploaded;
  894. /**
  895. * wp.media.view.AttachmentFilters.Uploaded
  896. *
  897. * @memberOf wp.media.view.AttachmentFilters
  898. *
  899. * @class
  900. * @augments wp.media.view.AttachmentFilters
  901. * @augments wp.media.View
  902. * @augments wp.Backbone.View
  903. * @augments Backbone.View
  904. */
  905. Uploaded = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.AttachmentFilters.Uploaded.prototype */{
  906. createFilters: function() {
  907. var type = this.model.get('type'),
  908. types = wp.media.view.settings.mimeTypes,
  909. uid = window.userSettings ? parseInt( window.userSettings.uid, 10 ) : 0,
  910. text;
  911. if ( types && type ) {
  912. text = types[ type ];
  913. }
  914. this.filters = {
  915. all: {
  916. text: text || l10n.allMediaItems,
  917. props: {
  918. uploadedTo: null,
  919. orderby: 'date',
  920. order: 'DESC',
  921. author: null
  922. },
  923. priority: 10
  924. },
  925. uploaded: {
  926. text: l10n.uploadedToThisPost,
  927. props: {
  928. uploadedTo: wp.media.view.settings.post.id,
  929. orderby: 'menuOrder',
  930. order: 'ASC',
  931. author: null
  932. },
  933. priority: 20
  934. },
  935. unattached: {
  936. text: l10n.unattached,
  937. props: {
  938. uploadedTo: 0,
  939. orderby: 'menuOrder',
  940. order: 'ASC',
  941. author: null
  942. },
  943. priority: 50
  944. }
  945. };
  946. if ( uid ) {
  947. this.filters.mine = {
  948. text: l10n.mine,
  949. props: {
  950. orderby: 'date',
  951. order: 'DESC',
  952. author: uid
  953. },
  954. priority: 50
  955. };
  956. }
  957. }
  958. });
  959. module.exports = Uploaded;
  960. /***/ }),
  961. /***/ "4tHu":
  962. /***/ (function(module, exports) {
  963. var l10n = wp.media.view.l10n,
  964. EditImage;
  965. /**
  966. * wp.media.controller.EditImage
  967. *
  968. * A state for editing (cropping, etc.) an image.
  969. *
  970. * @memberOf wp.media.controller
  971. *
  972. * @class
  973. * @augments wp.media.controller.State
  974. * @augments Backbone.Model
  975. *
  976. * @param {object} attributes The attributes hash passed to the state.
  977. * @param {wp.media.model.Attachment} attributes.model The attachment.
  978. * @param {string} [attributes.id=edit-image] Unique identifier.
  979. * @param {string} [attributes.title=Edit Image] Title for the state. Displays in the media menu and the frame's title region.
  980. * @param {string} [attributes.content=edit-image] Initial mode for the content region.
  981. * @param {string} [attributes.toolbar=edit-image] Initial mode for the toolbar region.
  982. * @param {string} [attributes.menu=false] Initial mode for the menu region.
  983. * @param {string} [attributes.url] Unused. @todo Consider removal.
  984. */
  985. EditImage = wp.media.controller.State.extend(/** @lends wp.media.controller.EditImage.prototype */{
  986. defaults: {
  987. id: 'edit-image',
  988. title: l10n.editImage,
  989. menu: false,
  990. toolbar: 'edit-image',
  991. content: 'edit-image',
  992. url: ''
  993. },
  994. /**
  995. * Activates a frame for editing a featured image.
  996. *
  997. * @since 3.9.0
  998. *
  999. * @return {void}
  1000. */
  1001. activate: function() {
  1002. this.frame.on( 'toolbar:render:edit-image', _.bind( this.toolbar, this ) );
  1003. },
  1004. /**
  1005. * Deactivates a frame for editing a featured image.
  1006. *
  1007. * @since 3.9.0
  1008. *
  1009. * @return {void}
  1010. */
  1011. deactivate: function() {
  1012. this.frame.off( 'toolbar:render:edit-image' );
  1013. },
  1014. /**
  1015. * Adds a toolbar with a back button.
  1016. *
  1017. * When the back button is pressed it checks whether there is a previous state.
  1018. * In case there is a previous state it sets that previous state otherwise it
  1019. * closes the frame.
  1020. *
  1021. * @since 3.9.0
  1022. *
  1023. * @return {void}
  1024. */
  1025. toolbar: function() {
  1026. var frame = this.frame,
  1027. lastState = frame.lastState(),
  1028. previous = lastState && lastState.id;
  1029. frame.toolbar.set( new wp.media.view.Toolbar({
  1030. controller: frame,
  1031. items: {
  1032. back: {
  1033. style: 'primary',
  1034. text: l10n.back,
  1035. priority: 20,
  1036. click: function() {
  1037. if ( previous ) {
  1038. frame.setState( previous );
  1039. } else {
  1040. frame.close();
  1041. }
  1042. }
  1043. }
  1044. }
  1045. }) );
  1046. }
  1047. });
  1048. module.exports = EditImage;
  1049. /***/ }),
  1050. /***/ "6B7g":
  1051. /***/ (function(module, exports) {
  1052. var Select = wp.media.view.MediaFrame.Select,
  1053. Library = wp.media.controller.Library,
  1054. l10n = wp.media.view.l10n,
  1055. Post;
  1056. /**
  1057. * wp.media.view.MediaFrame.Post
  1058. *
  1059. * The frame for manipulating media on the Edit Post page.
  1060. *
  1061. * @memberOf wp.media.view.MediaFrame
  1062. *
  1063. * @class
  1064. * @augments wp.media.view.MediaFrame.Select
  1065. * @augments wp.media.view.MediaFrame
  1066. * @augments wp.media.view.Frame
  1067. * @augments wp.media.View
  1068. * @augments wp.Backbone.View
  1069. * @augments Backbone.View
  1070. * @mixes wp.media.controller.StateMachine
  1071. */
  1072. Post = Select.extend(/** @lends wp.media.view.MediaFrame.Post.prototype */{
  1073. initialize: function() {
  1074. this.counts = {
  1075. audio: {
  1076. count: wp.media.view.settings.attachmentCounts.audio,
  1077. state: 'playlist'
  1078. },
  1079. video: {
  1080. count: wp.media.view.settings.attachmentCounts.video,
  1081. state: 'video-playlist'
  1082. }
  1083. };
  1084. _.defaults( this.options, {
  1085. multiple: true,
  1086. editing: false,
  1087. state: 'insert',
  1088. metadata: {}
  1089. });
  1090. // Call 'initialize' directly on the parent class.
  1091. Select.prototype.initialize.apply( this, arguments );
  1092. this.createIframeStates();
  1093. },
  1094. /**
  1095. * Create the default states.
  1096. */
  1097. createStates: function() {
  1098. var options = this.options;
  1099. this.states.add([
  1100. // Main states.
  1101. new Library({
  1102. id: 'insert',
  1103. title: l10n.insertMediaTitle,
  1104. priority: 20,
  1105. toolbar: 'main-insert',
  1106. filterable: 'all',
  1107. library: wp.media.query( options.library ),
  1108. multiple: options.multiple ? 'reset' : false,
  1109. editable: true,
  1110. // If the user isn't allowed to edit fields,
  1111. // can they still edit it locally?
  1112. allowLocalEdits: true,
  1113. // Show the attachment display settings.
  1114. displaySettings: true,
  1115. // Update user settings when users adjust the
  1116. // attachment display settings.
  1117. displayUserSettings: true
  1118. }),
  1119. new Library({
  1120. id: 'gallery',
  1121. title: l10n.createGalleryTitle,
  1122. priority: 40,
  1123. toolbar: 'main-gallery',
  1124. filterable: 'uploaded',
  1125. multiple: 'add',
  1126. editable: false,
  1127. library: wp.media.query( _.defaults({
  1128. type: 'image'
  1129. }, options.library ) )
  1130. }),
  1131. // Embed states.
  1132. new wp.media.controller.Embed( { metadata: options.metadata } ),
  1133. new wp.media.controller.EditImage( { model: options.editImage } ),
  1134. // Gallery states.
  1135. new wp.media.controller.GalleryEdit({
  1136. library: options.selection,
  1137. editing: options.editing,
  1138. menu: 'gallery'
  1139. }),
  1140. new wp.media.controller.GalleryAdd(),
  1141. new Library({
  1142. id: 'playlist',
  1143. title: l10n.createPlaylistTitle,
  1144. priority: 60,
  1145. toolbar: 'main-playlist',
  1146. filterable: 'uploaded',
  1147. multiple: 'add',
  1148. editable: false,
  1149. library: wp.media.query( _.defaults({
  1150. type: 'audio'
  1151. }, options.library ) )
  1152. }),
  1153. // Playlist states.
  1154. new wp.media.controller.CollectionEdit({
  1155. type: 'audio',
  1156. collectionType: 'playlist',
  1157. title: l10n.editPlaylistTitle,
  1158. SettingsView: wp.media.view.Settings.Playlist,
  1159. library: options.selection,
  1160. editing: options.editing,
  1161. menu: 'playlist',
  1162. dragInfoText: l10n.playlistDragInfo,
  1163. dragInfo: false
  1164. }),
  1165. new wp.media.controller.CollectionAdd({
  1166. type: 'audio',
  1167. collectionType: 'playlist',
  1168. title: l10n.addToPlaylistTitle
  1169. }),
  1170. new Library({
  1171. id: 'video-playlist',
  1172. title: l10n.createVideoPlaylistTitle,
  1173. priority: 60,
  1174. toolbar: 'main-video-playlist',
  1175. filterable: 'uploaded',
  1176. multiple: 'add',
  1177. editable: false,
  1178. library: wp.media.query( _.defaults({
  1179. type: 'video'
  1180. }, options.library ) )
  1181. }),
  1182. new wp.media.controller.CollectionEdit({
  1183. type: 'video',
  1184. collectionType: 'playlist',
  1185. title: l10n.editVideoPlaylistTitle,
  1186. SettingsView: wp.media.view.Settings.Playlist,
  1187. library: options.selection,
  1188. editing: options.editing,
  1189. menu: 'video-playlist',
  1190. dragInfoText: l10n.videoPlaylistDragInfo,
  1191. dragInfo: false
  1192. }),
  1193. new wp.media.controller.CollectionAdd({
  1194. type: 'video',
  1195. collectionType: 'playlist',
  1196. title: l10n.addToVideoPlaylistTitle
  1197. })
  1198. ]);
  1199. if ( wp.media.view.settings.post.featuredImageId ) {
  1200. this.states.add( new wp.media.controller.FeaturedImage() );
  1201. }
  1202. },
  1203. bindHandlers: function() {
  1204. var handlers, checkCounts;
  1205. Select.prototype.bindHandlers.apply( this, arguments );
  1206. this.on( 'activate', this.activate, this );
  1207. // Only bother checking media type counts if one of the counts is zero.
  1208. checkCounts = _.find( this.counts, function( type ) {
  1209. return type.count === 0;
  1210. } );
  1211. if ( typeof checkCounts !== 'undefined' ) {
  1212. this.listenTo( wp.media.model.Attachments.all, 'change:type', this.mediaTypeCounts );
  1213. }
  1214. this.on( 'menu:create:gallery', this.createMenu, this );
  1215. this.on( 'menu:create:playlist', this.createMenu, this );
  1216. this.on( 'menu:create:video-playlist', this.createMenu, this );
  1217. this.on( 'toolbar:create:main-insert', this.createToolbar, this );
  1218. this.on( 'toolbar:create:main-gallery', this.createToolbar, this );
  1219. this.on( 'toolbar:create:main-playlist', this.createToolbar, this );
  1220. this.on( 'toolbar:create:main-video-playlist', this.createToolbar, this );
  1221. this.on( 'toolbar:create:featured-image', this.featuredImageToolbar, this );
  1222. this.on( 'toolbar:create:main-embed', this.mainEmbedToolbar, this );
  1223. handlers = {
  1224. menu: {
  1225. 'default': 'mainMenu',
  1226. 'gallery': 'galleryMenu',
  1227. 'playlist': 'playlistMenu',
  1228. 'video-playlist': 'videoPlaylistMenu'
  1229. },
  1230. content: {
  1231. 'embed': 'embedContent',
  1232. 'edit-image': 'editImageContent',
  1233. 'edit-selection': 'editSelectionContent'
  1234. },
  1235. toolbar: {
  1236. 'main-insert': 'mainInsertToolbar',
  1237. 'main-gallery': 'mainGalleryToolbar',
  1238. 'gallery-edit': 'galleryEditToolbar',
  1239. 'gallery-add': 'galleryAddToolbar',
  1240. 'main-playlist': 'mainPlaylistToolbar',
  1241. 'playlist-edit': 'playlistEditToolbar',
  1242. 'playlist-add': 'playlistAddToolbar',
  1243. 'main-video-playlist': 'mainVideoPlaylistToolbar',
  1244. 'video-playlist-edit': 'videoPlaylistEditToolbar',
  1245. 'video-playlist-add': 'videoPlaylistAddToolbar'
  1246. }
  1247. };
  1248. _.each( handlers, function( regionHandlers, region ) {
  1249. _.each( regionHandlers, function( callback, handler ) {
  1250. this.on( region + ':render:' + handler, this[ callback ], this );
  1251. }, this );
  1252. }, this );
  1253. },
  1254. activate: function() {
  1255. // Hide menu items for states tied to particular media types if there are no items.
  1256. _.each( this.counts, function( type ) {
  1257. if ( type.count < 1 ) {
  1258. this.menuItemVisibility( type.state, 'hide' );
  1259. }
  1260. }, this );
  1261. },
  1262. mediaTypeCounts: function( model, attr ) {
  1263. if ( typeof this.counts[ attr ] !== 'undefined' && this.counts[ attr ].count < 1 ) {
  1264. this.counts[ attr ].count++;
  1265. this.menuItemVisibility( this.counts[ attr ].state, 'show' );
  1266. }
  1267. },
  1268. // Menus.
  1269. /**
  1270. * @param {wp.Backbone.View} view
  1271. */
  1272. mainMenu: function( view ) {
  1273. view.set({
  1274. 'library-separator': new wp.media.View({
  1275. className: 'separator',
  1276. priority: 100,
  1277. attributes: {
  1278. role: 'presentation'
  1279. }
  1280. })
  1281. });
  1282. },
  1283. menuItemVisibility: function( state, visibility ) {
  1284. var menu = this.menu.get();
  1285. if ( visibility === 'hide' ) {
  1286. menu.hide( state );
  1287. } else if ( visibility === 'show' ) {
  1288. menu.show( state );
  1289. }
  1290. },
  1291. /**
  1292. * @param {wp.Backbone.View} view
  1293. */
  1294. galleryMenu: function( view ) {
  1295. var lastState = this.lastState(),
  1296. previous = lastState && lastState.id,
  1297. frame = this;
  1298. view.set({
  1299. cancel: {
  1300. text: l10n.cancelGalleryTitle,
  1301. priority: 20,
  1302. click: function() {
  1303. if ( previous ) {
  1304. frame.setState( previous );
  1305. } else {
  1306. frame.close();
  1307. }
  1308. // Move focus to the modal after canceling a Gallery.
  1309. this.controller.modal.focusManager.focus();
  1310. }
  1311. },
  1312. separateCancel: new wp.media.View({
  1313. className: 'separator',
  1314. priority: 40
  1315. })
  1316. });
  1317. },
  1318. playlistMenu: function( view ) {
  1319. var lastState = this.lastState(),
  1320. previous = lastState && lastState.id,
  1321. frame = this;
  1322. view.set({
  1323. cancel: {
  1324. text: l10n.cancelPlaylistTitle,
  1325. priority: 20,
  1326. click: function() {
  1327. if ( previous ) {
  1328. frame.setState( previous );
  1329. } else {
  1330. frame.close();
  1331. }
  1332. // Move focus to the modal after canceling an Audio Playlist.
  1333. this.controller.modal.focusManager.focus();
  1334. }
  1335. },
  1336. separateCancel: new wp.media.View({
  1337. className: 'separator',
  1338. priority: 40
  1339. })
  1340. });
  1341. },
  1342. videoPlaylistMenu: function( view ) {
  1343. var lastState = this.lastState(),
  1344. previous = lastState && lastState.id,
  1345. frame = this;
  1346. view.set({
  1347. cancel: {
  1348. text: l10n.cancelVideoPlaylistTitle,
  1349. priority: 20,
  1350. click: function() {
  1351. if ( previous ) {
  1352. frame.setState( previous );
  1353. } else {
  1354. frame.close();
  1355. }
  1356. // Move focus to the modal after canceling a Video Playlist.
  1357. this.controller.modal.focusManager.focus();
  1358. }
  1359. },
  1360. separateCancel: new wp.media.View({
  1361. className: 'separator',
  1362. priority: 40
  1363. })
  1364. });
  1365. },
  1366. // Content.
  1367. embedContent: function() {
  1368. var view = new wp.media.view.Embed({
  1369. controller: this,
  1370. model: this.state()
  1371. }).render();
  1372. this.content.set( view );
  1373. },
  1374. editSelectionContent: function() {
  1375. var state = this.state(),
  1376. selection = state.get('selection'),
  1377. view;
  1378. view = new wp.media.view.AttachmentsBrowser({
  1379. controller: this,
  1380. collection: selection,
  1381. selection: selection,
  1382. model: state,
  1383. sortable: true,
  1384. search: false,
  1385. date: false,
  1386. dragInfo: true,
  1387. AttachmentView: wp.media.view.Attachments.EditSelection
  1388. }).render();
  1389. view.toolbar.set( 'backToLibrary', {
  1390. text: l10n.returnToLibrary,
  1391. priority: -100,
  1392. click: function() {
  1393. this.controller.content.mode('browse');
  1394. // Move focus to the modal when jumping back from Edit Selection to Add Media view.
  1395. this.controller.modal.focusManager.focus();
  1396. }
  1397. });
  1398. // Browse our library of attachments.
  1399. this.content.set( view );
  1400. // Trigger the controller to set focus.
  1401. this.trigger( 'edit:selection', this );
  1402. },
  1403. editImageContent: function() {
  1404. var image = this.state().get('image'),
  1405. view = new wp.media.view.EditImage( { model: image, controller: this } ).render();
  1406. this.content.set( view );
  1407. // After creating the wrapper view, load the actual editor via an Ajax call.
  1408. view.loadEditor();
  1409. },
  1410. // Toolbars.
  1411. /**
  1412. * @param {wp.Backbone.View} view
  1413. */
  1414. selectionStatusToolbar: function( view ) {
  1415. var editable = this.state().get('editable');
  1416. view.set( 'selection', new wp.media.view.Selection({
  1417. controller: this,
  1418. collection: this.state().get('selection'),
  1419. priority: -40,
  1420. // If the selection is editable, pass the callback to
  1421. // switch the content mode.
  1422. editable: editable && function() {
  1423. this.controller.content.mode('edit-selection');
  1424. }
  1425. }).render() );
  1426. },
  1427. /**
  1428. * @param {wp.Backbone.View} view
  1429. */
  1430. mainInsertToolbar: function( view ) {
  1431. var controller = this;
  1432. this.selectionStatusToolbar( view );
  1433. view.set( 'insert', {
  1434. style: 'primary',
  1435. priority: 80,
  1436. text: l10n.insertIntoPost,
  1437. requires: { selection: true },
  1438. /**
  1439. * @ignore
  1440. *
  1441. * @fires wp.media.controller.State#insert
  1442. */
  1443. click: function() {
  1444. var state = controller.state(),
  1445. selection = state.get('selection');
  1446. controller.close();
  1447. state.trigger( 'insert', selection ).reset();
  1448. }
  1449. });
  1450. },
  1451. /**
  1452. * @param {wp.Backbone.View} view
  1453. */
  1454. mainGalleryToolbar: function( view ) {
  1455. var controller = this;
  1456. this.selectionStatusToolbar( view );
  1457. view.set( 'gallery', {
  1458. style: 'primary',
  1459. text: l10n.createNewGallery,
  1460. priority: 60,
  1461. requires: { selection: true },
  1462. click: function() {
  1463. var selection = controller.state().get('selection'),
  1464. edit = controller.state('gallery-edit'),
  1465. models = selection.where({ type: 'image' });
  1466. edit.set( 'library', new wp.media.model.Selection( models, {
  1467. props: selection.props.toJSON(),
  1468. multiple: true
  1469. }) );
  1470. // Jump to Edit Gallery view.
  1471. this.controller.setState( 'gallery-edit' );
  1472. // Move focus to the modal after jumping to Edit Gallery view.
  1473. this.controller.modal.focusManager.focus();
  1474. }
  1475. });
  1476. },
  1477. mainPlaylistToolbar: function( view ) {
  1478. var controller = this;
  1479. this.selectionStatusToolbar( view );
  1480. view.set( 'playlist', {
  1481. style: 'primary',
  1482. text: l10n.createNewPlaylist,
  1483. priority: 100,
  1484. requires: { selection: true },
  1485. click: function() {
  1486. var selection = controller.state().get('selection'),
  1487. edit = controller.state('playlist-edit'),
  1488. models = selection.where({ type: 'audio' });
  1489. edit.set( 'library', new wp.media.model.Selection( models, {
  1490. props: selection.props.toJSON(),
  1491. multiple: true
  1492. }) );
  1493. // Jump to Edit Audio Playlist view.
  1494. this.controller.setState( 'playlist-edit' );
  1495. // Move focus to the modal after jumping to Edit Audio Playlist view.
  1496. this.controller.modal.focusManager.focus();
  1497. }
  1498. });
  1499. },
  1500. mainVideoPlaylistToolbar: function( view ) {
  1501. var controller = this;
  1502. this.selectionStatusToolbar( view );
  1503. view.set( 'video-playlist', {
  1504. style: 'primary',
  1505. text: l10n.createNewVideoPlaylist,
  1506. priority: 100,
  1507. requires: { selection: true },
  1508. click: function() {
  1509. var selection = controller.state().get('selection'),
  1510. edit = controller.state('video-playlist-edit'),
  1511. models = selection.where({ type: 'video' });
  1512. edit.set( 'library', new wp.media.model.Selection( models, {
  1513. props: selection.props.toJSON(),
  1514. multiple: true
  1515. }) );
  1516. // Jump to Edit Video Playlist view.
  1517. this.controller.setState( 'video-playlist-edit' );
  1518. // Move focus to the modal after jumping to Edit Video Playlist view.
  1519. this.controller.modal.focusManager.focus();
  1520. }
  1521. });
  1522. },
  1523. featuredImageToolbar: function( toolbar ) {
  1524. this.createSelectToolbar( toolbar, {
  1525. text: l10n.setFeaturedImage,
  1526. state: this.options.state
  1527. });
  1528. },
  1529. mainEmbedToolbar: function( toolbar ) {
  1530. toolbar.view = new wp.media.view.Toolbar.Embed({
  1531. controller: this
  1532. });
  1533. },
  1534. galleryEditToolbar: function() {
  1535. var editing = this.state().get('editing');
  1536. this.toolbar.set( new wp.media.view.Toolbar({
  1537. controller: this,
  1538. items: {
  1539. insert: {
  1540. style: 'primary',
  1541. text: editing ? l10n.updateGallery : l10n.insertGallery,
  1542. priority: 80,
  1543. requires: { library: true },
  1544. /**
  1545. * @fires wp.media.controller.State#update
  1546. */
  1547. click: function() {
  1548. var controller = this.controller,
  1549. state = controller.state();
  1550. controller.close();
  1551. state.trigger( 'update', state.get('library') );
  1552. // Restore and reset the default state.
  1553. controller.setState( controller.options.state );
  1554. controller.reset();
  1555. }
  1556. }
  1557. }
  1558. }) );
  1559. },
  1560. galleryAddToolbar: function() {
  1561. this.toolbar.set( new wp.media.view.Toolbar({
  1562. controller: this,
  1563. items: {
  1564. insert: {
  1565. style: 'primary',
  1566. text: l10n.addToGallery,
  1567. priority: 80,
  1568. requires: { selection: true },
  1569. /**
  1570. * @fires wp.media.controller.State#reset
  1571. */
  1572. click: function() {
  1573. var controller = this.controller,
  1574. state = controller.state(),
  1575. edit = controller.state('gallery-edit');
  1576. edit.get('library').add( state.get('selection').models );
  1577. state.trigger('reset');
  1578. controller.setState('gallery-edit');
  1579. // Move focus to the modal when jumping back from Add to Gallery to Edit Gallery view.
  1580. this.controller.modal.focusManager.focus();
  1581. }
  1582. }
  1583. }
  1584. }) );
  1585. },
  1586. playlistEditToolbar: function() {
  1587. var editing = this.state().get('editing');
  1588. this.toolbar.set( new wp.media.view.Toolbar({
  1589. controller: this,
  1590. items: {
  1591. insert: {
  1592. style: 'primary',
  1593. text: editing ? l10n.updatePlaylist : l10n.insertPlaylist,
  1594. priority: 80,
  1595. requires: { library: true },
  1596. /**
  1597. * @fires wp.media.controller.State#update
  1598. */
  1599. click: function() {
  1600. var controller = this.controller,
  1601. state = controller.state();
  1602. controller.close();
  1603. state.trigger( 'update', state.get('library') );
  1604. // Restore and reset the default state.
  1605. controller.setState( controller.options.state );
  1606. controller.reset();
  1607. }
  1608. }
  1609. }
  1610. }) );
  1611. },
  1612. playlistAddToolbar: function() {
  1613. this.toolbar.set( new wp.media.view.Toolbar({
  1614. controller: this,
  1615. items: {
  1616. insert: {
  1617. style: 'primary',
  1618. text: l10n.addToPlaylist,
  1619. priority: 80,
  1620. requires: { selection: true },
  1621. /**
  1622. * @fires wp.media.controller.State#reset
  1623. */
  1624. click: function() {
  1625. var controller = this.controller,
  1626. state = controller.state(),
  1627. edit = controller.state('playlist-edit');
  1628. edit.get('library').add( state.get('selection').models );
  1629. state.trigger('reset');
  1630. controller.setState('playlist-edit');
  1631. // Move focus to the modal when jumping back from Add to Audio Playlist to Edit Audio Playlist view.
  1632. this.controller.modal.focusManager.focus();
  1633. }
  1634. }
  1635. }
  1636. }) );
  1637. },
  1638. videoPlaylistEditToolbar: function() {
  1639. var editing = this.state().get('editing');
  1640. this.toolbar.set( new wp.media.view.Toolbar({
  1641. controller: this,
  1642. items: {
  1643. insert: {
  1644. style: 'primary',
  1645. text: editing ? l10n.updateVideoPlaylist : l10n.insertVideoPlaylist,
  1646. priority: 140,
  1647. requires: { library: true },
  1648. click: function() {
  1649. var controller = this.controller,
  1650. state = controller.state(),
  1651. library = state.get('library');
  1652. library.type = 'video';
  1653. controller.close();
  1654. state.trigger( 'update', library );
  1655. // Restore and reset the default state.
  1656. controller.setState( controller.options.state );
  1657. controller.reset();
  1658. }
  1659. }
  1660. }
  1661. }) );
  1662. },
  1663. videoPlaylistAddToolbar: function() {
  1664. this.toolbar.set( new wp.media.view.Toolbar({
  1665. controller: this,
  1666. items: {
  1667. insert: {
  1668. style: 'primary',
  1669. text: l10n.addToVideoPlaylist,
  1670. priority: 140,
  1671. requires: { selection: true },
  1672. click: function() {
  1673. var controller = this.controller,
  1674. state = controller.state(),
  1675. edit = controller.state('video-playlist-edit');
  1676. edit.get('library').add( state.get('selection').models );
  1677. state.trigger('reset');
  1678. controller.setState('video-playlist-edit');
  1679. // Move focus to the modal when jumping back from Add to Video Playlist to Edit Video Playlist view.
  1680. this.controller.modal.focusManager.focus();
  1681. }
  1682. }
  1683. }
  1684. }) );
  1685. }
  1686. });
  1687. module.exports = Post;
  1688. /***/ }),
  1689. /***/ "72mI":
  1690. /***/ (function(module, exports) {
  1691. var View = wp.media.View,
  1692. mediaTrash = wp.media.view.settings.mediaTrash,
  1693. l10n = wp.media.view.l10n,
  1694. $ = jQuery,
  1695. AttachmentsBrowser,
  1696. infiniteScrolling = wp.media.view.settings.infiniteScrolling,
  1697. __ = wp.i18n.__,
  1698. sprintf = wp.i18n.sprintf;
  1699. /**
  1700. * wp.media.view.AttachmentsBrowser
  1701. *
  1702. * @memberOf wp.media.view
  1703. *
  1704. * @class
  1705. * @augments wp.media.View
  1706. * @augments wp.Backbone.View
  1707. * @augments Backbone.View
  1708. *
  1709. * @param {object} [options] The options hash passed to the view.
  1710. * @param {boolean|string} [options.filters=false] Which filters to show in the browser's toolbar.
  1711. * Accepts 'uploaded' and 'all'.
  1712. * @param {boolean} [options.search=true] Whether to show the search interface in the
  1713. * browser's toolbar.
  1714. * @param {boolean} [options.date=true] Whether to show the date filter in the
  1715. * browser's toolbar.
  1716. * @param {boolean} [options.display=false] Whether to show the attachments display settings
  1717. * view in the sidebar.
  1718. * @param {boolean|string} [options.sidebar=true] Whether to create a sidebar for the browser.
  1719. * Accepts true, false, and 'errors'.
  1720. */
  1721. AttachmentsBrowser = View.extend(/** @lends wp.media.view.AttachmentsBrowser.prototype */{
  1722. tagName: 'div',
  1723. className: 'attachments-browser',
  1724. initialize: function() {
  1725. _.defaults( this.options, {
  1726. filters: false,
  1727. search: true,
  1728. date: true,
  1729. display: false,
  1730. sidebar: true,
  1731. AttachmentView: wp.media.view.Attachment.Library
  1732. });
  1733. this.controller.on( 'toggle:upload:attachment', this.toggleUploader, this );
  1734. this.controller.on( 'edit:selection', this.editSelection );
  1735. // In the Media Library, the sidebar is used to display errors before the attachments grid.
  1736. if ( this.options.sidebar && 'errors' === this.options.sidebar ) {
  1737. this.createSidebar();
  1738. }
  1739. /*
  1740. * In the grid mode (the Media Library), place the Inline Uploader before
  1741. * other sections so that the visual order and the DOM order match. This way,
  1742. * the Inline Uploader in the Media Library is right after the "Add New"
  1743. * button, see ticket #37188.
  1744. */
  1745. if ( this.controller.isModeActive( 'grid' ) ) {
  1746. this.createUploader();
  1747. /*
  1748. * Create a multi-purpose toolbar. Used as main toolbar in the Media Library
  1749. * and also for other things, for example the "Drag and drop to reorder" and
  1750. * "Suggested dimensions" info in the media modal.
  1751. */
  1752. this.createToolbar();
  1753. } else {
  1754. this.createToolbar();
  1755. this.createUploader();
  1756. }
  1757. // Add a heading before the attachments list.
  1758. this.createAttachmentsHeading();
  1759. // Create the attachments wrapper view.
  1760. this.createAttachmentsWrapperView();
  1761. if ( ! infiniteScrolling ) {
  1762. this.$el.addClass( 'has-load-more' );
  1763. this.createLoadMoreView();
  1764. }
  1765. // For accessibility reasons, place the normal sidebar after the attachments, see ticket #36909.
  1766. if ( this.options.sidebar && 'errors' !== this.options.sidebar ) {
  1767. this.createSidebar();
  1768. }
  1769. this.updateContent();
  1770. if ( ! infiniteScrolling ) {
  1771. this.updateLoadMoreView();
  1772. }
  1773. if ( ! this.options.sidebar || 'errors' === this.options.sidebar ) {
  1774. this.$el.addClass( 'hide-sidebar' );
  1775. if ( 'errors' === this.options.sidebar ) {
  1776. this.$el.addClass( 'sidebar-for-errors' );
  1777. }
  1778. }
  1779. this.collection.on( 'add remove reset', this.updateContent, this );
  1780. if ( ! infiniteScrolling ) {
  1781. this.collection.on( 'add remove reset', this.updateLoadMoreView, this );
  1782. }
  1783. // The non-cached or cached attachments query has completed.
  1784. this.collection.on( 'attachments:received', this.announceSearchResults, this );
  1785. },
  1786. /**
  1787. * Updates the `wp.a11y.speak()` ARIA live region with a message to communicate
  1788. * the number of search results to screen reader users. This function is
  1789. * debounced because the collection updates multiple times.
  1790. *
  1791. * @since 5.3.0
  1792. *
  1793. * @return {void}
  1794. */
  1795. announceSearchResults: _.debounce( function() {
  1796. var count,
  1797. /* translators: Accessibility text. %d: Number of attachments found in a search. */
  1798. mediaFoundHasMoreResultsMessage = __( 'Number of media items displayed: %d. Click load more for more results.' );
  1799. if ( infiniteScrolling ) {
  1800. /* translators: Accessibility text. %d: Number of attachments found in a search. */
  1801. mediaFoundHasMoreResultsMessage = __( 'Number of media items displayed: %d. Scroll the page for more results.' );
  1802. }
  1803. if ( this.collection.mirroring.args.s ) {
  1804. count = this.collection.length;
  1805. if ( 0 === count ) {
  1806. wp.a11y.speak( l10n.noMediaTryNewSearch );
  1807. return;
  1808. }
  1809. if ( this.collection.hasMore() ) {
  1810. wp.a11y.speak( mediaFoundHasMoreResultsMessage.replace( '%d', count ) );
  1811. return;
  1812. }
  1813. wp.a11y.speak( l10n.mediaFound.replace( '%d', count ) );
  1814. }
  1815. }, 200 ),
  1816. editSelection: function( modal ) {
  1817. // When editing a selection, move focus to the "Go to library" button.
  1818. modal.$( '.media-button-backToLibrary' ).focus();
  1819. },
  1820. /**
  1821. * @return {wp.media.view.AttachmentsBrowser} Returns itself to allow chaining.
  1822. */
  1823. dispose: function() {
  1824. this.options.selection.off( null, null, this );
  1825. View.prototype.dispose.apply( this, arguments );
  1826. return this;
  1827. },
  1828. createToolbar: function() {
  1829. var LibraryViewSwitcher, Filters, toolbarOptions,
  1830. showFilterByType = -1 !== $.inArray( this.options.filters, [ 'uploaded', 'all' ] );
  1831. toolbarOptions = {
  1832. controller: this.controller
  1833. };
  1834. if ( this.controller.isModeActive( 'grid' ) ) {
  1835. toolbarOptions.className = 'media-toolbar wp-filter';
  1836. }
  1837. /**
  1838. * @member {wp.media.view.Toolbar}
  1839. */
  1840. this.toolbar = new wp.media.view.Toolbar( toolbarOptions );
  1841. this.views.add( this.toolbar );
  1842. this.toolbar.set( 'spinner', new wp.media.view.Spinner({
  1843. priority: -20
  1844. }) );
  1845. if ( showFilterByType || this.options.date ) {
  1846. /*
  1847. * Create a h2 heading before the select elements that filter attachments.
  1848. * This heading is visible in the modal and visually hidden in the grid.
  1849. */
  1850. this.toolbar.set( 'filters-heading', new wp.media.view.Heading( {
  1851. priority: -100,
  1852. text: l10n.filterAttachments,
  1853. level: 'h2',
  1854. className: 'media-attachments-filter-heading'
  1855. }).render() );
  1856. }
  1857. if ( showFilterByType ) {
  1858. // "Filters" is a <select>, a visually hidden label element needs to be rendered before.
  1859. this.toolbar.set( 'filtersLabel', new wp.media.view.Label({
  1860. value: l10n.filterByType,
  1861. attributes: {
  1862. 'for': 'media-attachment-filters'
  1863. },
  1864. priority: -80
  1865. }).render() );
  1866. if ( 'uploaded' === this.options.filters ) {
  1867. this.toolbar.set( 'filters', new wp.media.view.AttachmentFilters.Uploaded({
  1868. controller: this.controller,
  1869. model: this.collection.props,
  1870. priority: -80
  1871. }).render() );
  1872. } else {
  1873. Filters = new wp.media.view.AttachmentFilters.All({
  1874. controller: this.controller,
  1875. model: this.collection.props,
  1876. priority: -80
  1877. });
  1878. this.toolbar.set( 'filters', Filters.render() );
  1879. }
  1880. }
  1881. /*
  1882. * Feels odd to bring the global media library switcher into the Attachment browser view.
  1883. * Is this a use case for doAction( 'add:toolbar-items:attachments-browser', this.toolbar );
  1884. * which the controller can tap into and add this view?
  1885. */
  1886. if ( this.controller.isModeActive( 'grid' ) ) {
  1887. LibraryViewSwitcher = View.extend({
  1888. className: 'view-switch media-grid-view-switch',
  1889. template: wp.template( 'media-library-view-switcher')
  1890. });
  1891. this.toolbar.set( 'libraryViewSwitcher', new LibraryViewSwitcher({
  1892. controller: this.controller,
  1893. priority: -90
  1894. }).render() );
  1895. // DateFilter is a <select>, a visually hidden label element needs to be rendered before.
  1896. this.toolbar.set( 'dateFilterLabel', new wp.media.view.Label({
  1897. value: l10n.filterByDate,
  1898. attributes: {
  1899. 'for': 'media-attachment-date-filters'
  1900. },
  1901. priority: -75
  1902. }).render() );
  1903. this.toolbar.set( 'dateFilter', new wp.media.view.DateFilter({
  1904. controller: this.controller,
  1905. model: this.collection.props,
  1906. priority: -75
  1907. }).render() );
  1908. // BulkSelection is a <div> with subviews, including screen reader text.
  1909. this.toolbar.set( 'selectModeToggleButton', new wp.media.view.SelectModeToggleButton({
  1910. text: l10n.bulkSelect,
  1911. controller: this.controller,
  1912. priority: -70
  1913. }).render() );
  1914. this.toolbar.set( 'deleteSelectedButton', new wp.media.view.DeleteSelectedButton({
  1915. filters: Filters,
  1916. style: 'primary',
  1917. disabled: true,
  1918. text: mediaTrash ? l10n.trashSelected : l10n.deletePermanently,
  1919. controller: this.controller,
  1920. priority: -80,
  1921. click: function() {
  1922. var changed = [], removed = [],
  1923. selection = this.controller.state().get( 'selection' ),
  1924. library = this.controller.state().get( 'library' );
  1925. if ( ! selection.length ) {
  1926. return;
  1927. }
  1928. if ( ! mediaTrash && ! window.confirm( l10n.warnBulkDelete ) ) {
  1929. return;
  1930. }
  1931. if ( mediaTrash &&
  1932. 'trash' !== selection.at( 0 ).get( 'status' ) &&
  1933. ! window.confirm( l10n.warnBulkTrash ) ) {
  1934. return;
  1935. }
  1936. selection.each( function( model ) {
  1937. if ( ! model.get( 'nonces' )['delete'] ) {
  1938. removed.push( model );
  1939. return;
  1940. }
  1941. if ( mediaTrash && 'trash' === model.get( 'status' ) ) {
  1942. model.set( 'status', 'inherit' );
  1943. changed.push( model.save() );
  1944. removed.push( model );
  1945. } else if ( mediaTrash ) {
  1946. model.set( 'status', 'trash' );
  1947. changed.push( model.save() );
  1948. removed.push( model );
  1949. } else {
  1950. model.destroy({wait: true});
  1951. }
  1952. } );
  1953. if ( changed.length ) {
  1954. selection.remove( removed );
  1955. $.when.apply( null, changed ).then( _.bind( function() {
  1956. library._requery( true );
  1957. this.controller.trigger( 'selection:action:done' );
  1958. }, this ) );
  1959. } else {
  1960. this.controller.trigger( 'selection:action:done' );
  1961. }
  1962. }
  1963. }).render() );
  1964. if ( mediaTrash ) {
  1965. this.toolbar.set( 'deleteSelectedPermanentlyButton', new wp.media.view.DeleteSelectedPermanentlyButton({
  1966. filters: Filters,
  1967. style: 'link button-link-delete',
  1968. disabled: true,
  1969. text: l10n.deletePermanently,
  1970. controller: this.controller,
  1971. priority: -55,
  1972. click: function() {
  1973. var removed = [],
  1974. destroy = [],
  1975. selection = this.controller.state().get( 'selection' );
  1976. if ( ! selection.length || ! window.confirm( l10n.warnBulkDelete ) ) {
  1977. return;
  1978. }
  1979. selection.each( function( model ) {
  1980. if ( ! model.get( 'nonces' )['delete'] ) {
  1981. removed.push( model );
  1982. return;
  1983. }
  1984. destroy.push( model );
  1985. } );
  1986. if ( removed.length ) {
  1987. selection.remove( removed );
  1988. }
  1989. if ( destroy.length ) {
  1990. $.when.apply( null, destroy.map( function (item) {
  1991. return item.destroy();
  1992. } ) ).then( _.bind( function() {
  1993. this.controller.trigger( 'selection:action:done' );
  1994. }, this ) );
  1995. }
  1996. }
  1997. }).render() );
  1998. }
  1999. } else if ( this.options.date ) {
  2000. // DateFilter is a <select>, a visually hidden label element needs to be rendered before.
  2001. this.toolbar.set( 'dateFilterLabel', new wp.media.view.Label({
  2002. value: l10n.filterByDate,
  2003. attributes: {
  2004. 'for': 'media-attachment-date-filters'
  2005. },
  2006. priority: -75
  2007. }).render() );
  2008. this.toolbar.set( 'dateFilter', new wp.media.view.DateFilter({
  2009. controller: this.controller,
  2010. model: this.collection.props,
  2011. priority: -75
  2012. }).render() );
  2013. }
  2014. if ( this.options.search ) {
  2015. // Search is an input, a visually hidden label element needs to be rendered before.
  2016. this.toolbar.set( 'searchLabel', new wp.media.view.Label({
  2017. value: l10n.searchLabel,
  2018. className: 'media-search-input-label',
  2019. attributes: {
  2020. 'for': 'media-search-input'
  2021. },
  2022. priority: 60
  2023. }).render() );
  2024. this.toolbar.set( 'search', new wp.media.view.Search({
  2025. controller: this.controller,
  2026. model: this.collection.props,
  2027. priority: 60
  2028. }).render() );
  2029. }
  2030. if ( this.options.dragInfo ) {
  2031. this.toolbar.set( 'dragInfo', new View({
  2032. el: $( '<div class="instructions">' + l10n.dragInfo + '</div>' )[0],
  2033. priority: -40
  2034. }) );
  2035. }
  2036. if ( this.options.suggestedWidth && this.options.suggestedHeight ) {
  2037. this.toolbar.set( 'suggestedDimensions', new View({
  2038. el: $( '<div class="instructions">' + l10n.suggestedDimensions.replace( '%1$s', this.options.suggestedWidth ).replace( '%2$s', this.options.suggestedHeight ) + '</div>' )[0],
  2039. priority: -40
  2040. }) );
  2041. }
  2042. },
  2043. updateContent: function() {
  2044. var view = this,
  2045. noItemsView;
  2046. if ( this.controller.isModeActive( 'grid' ) ) {
  2047. // Usually the media library.
  2048. noItemsView = view.attachmentsNoResults;
  2049. } else {
  2050. // Usually the media modal.
  2051. noItemsView = view.uploader;
  2052. }
  2053. if ( ! this.collection.length ) {
  2054. this.toolbar.get( 'spinner' ).show();
  2055. this.dfd = this.collection.more().done( function() {
  2056. if ( ! view.collection.length ) {
  2057. noItemsView.$el.removeClass( 'hidden' );
  2058. } else {
  2059. noItemsView.$el.addClass( 'hidden' );
  2060. }
  2061. view.toolbar.get( 'spinner' ).hide();
  2062. } );
  2063. } else {
  2064. noItemsView.$el.addClass( 'hidden' );
  2065. view.toolbar.get( 'spinner' ).hide();
  2066. }
  2067. },
  2068. createUploader: function() {
  2069. this.uploader = new wp.media.view.UploaderInline({
  2070. controller: this.controller,
  2071. status: false,
  2072. message: this.controller.isModeActive( 'grid' ) ? '' : l10n.noItemsFound,
  2073. canClose: this.controller.isModeActive( 'grid' )
  2074. });
  2075. this.uploader.$el.addClass( 'hidden' );
  2076. this.views.add( this.uploader );
  2077. },
  2078. toggleUploader: function() {
  2079. if ( this.uploader.$el.hasClass( 'hidden' ) ) {
  2080. this.uploader.show();
  2081. } else {
  2082. this.uploader.hide();
  2083. }
  2084. },
  2085. /**
  2086. * Creates the Attachments wrapper view.
  2087. *
  2088. * @since 5.8.0
  2089. *
  2090. * @return {void}
  2091. */
  2092. createAttachmentsWrapperView: function() {
  2093. this.attachmentsWrapper = new wp.media.View( {
  2094. className: 'attachments-wrapper'
  2095. } );
  2096. // Create the list of attachments.
  2097. this.views.add( this.attachmentsWrapper );
  2098. this.createAttachments();
  2099. },
  2100. createAttachments: function() {
  2101. this.attachments = new wp.media.view.Attachments({
  2102. controller: this.controller,
  2103. collection: this.collection,
  2104. selection: this.options.selection,
  2105. model: this.model,
  2106. sortable: this.options.sortable,
  2107. scrollElement: this.options.scrollElement,
  2108. idealColumnWidth: this.options.idealColumnWidth,
  2109. // The single `Attachment` view to be used in the `Attachments` view.
  2110. AttachmentView: this.options.AttachmentView
  2111. });
  2112. // Add keydown listener to the instance of the Attachments view.
  2113. this.controller.on( 'attachment:keydown:arrow', _.bind( this.attachments.arrowEvent, this.attachments ) );
  2114. this.controller.on( 'attachment:details:shift-tab', _.bind( this.attachments.restoreFocus, this.attachments ) );
  2115. this.views.add( '.attachments-wrapper', this.attachments );
  2116. if ( this.controller.isModeActive( 'grid' ) ) {
  2117. this.attachmentsNoResults = new View({
  2118. controller: this.controller,
  2119. tagName: 'p'
  2120. });
  2121. this.attachmentsNoResults.$el.addClass( 'hidden no-media' );
  2122. this.attachmentsNoResults.$el.html( l10n.noMedia );
  2123. this.views.add( this.attachmentsNoResults );
  2124. }
  2125. },
  2126. /**
  2127. * Creates the load more button and attachments counter view.
  2128. *
  2129. * @since 5.8.0
  2130. *
  2131. * @return {void}
  2132. */
  2133. createLoadMoreView: function() {
  2134. var view = this;
  2135. this.loadMoreWrapper = new View( {
  2136. controller: this.controller,
  2137. className: 'load-more-wrapper'
  2138. } );
  2139. this.loadMoreCount = new View( {
  2140. controller: this.controller,
  2141. tagName: 'p',
  2142. className: 'load-more-count hidden'
  2143. } );
  2144. this.loadMoreButton = new wp.media.view.Button( {
  2145. text: __( 'Load more' ),
  2146. className: 'load-more hidden',
  2147. style: 'primary',
  2148. size: '',
  2149. click: function() {
  2150. view.loadMoreAttachments();
  2151. }
  2152. } );
  2153. this.loadMoreSpinner = new wp.media.view.Spinner();
  2154. this.loadMoreJumpToFirst = new wp.media.view.Button( {
  2155. text: __( 'Jump to first loaded item' ),
  2156. className: 'load-more-jump hidden',
  2157. size: '',
  2158. click: function() {
  2159. view.jumpToFirstAddedItem();
  2160. }
  2161. } );
  2162. this.views.add( '.attachments-wrapper', this.loadMoreWrapper );
  2163. this.views.add( '.load-more-wrapper', this.loadMoreSpinner );
  2164. this.views.add( '.load-more-wrapper', this.loadMoreCount );
  2165. this.views.add( '.load-more-wrapper', this.loadMoreButton );
  2166. this.views.add( '.load-more-wrapper', this.loadMoreJumpToFirst );
  2167. },
  2168. /**
  2169. * Updates the Load More view. This function is debounced because the
  2170. * collection updates multiple times at the add, remove, and reset events.
  2171. * We need it to run only once, after all attachments are added or removed.
  2172. *
  2173. * @since 5.8.0
  2174. *
  2175. * @return {void}
  2176. */
  2177. updateLoadMoreView: _.debounce( function() {
  2178. // Ensure the load more view elements are initially hidden at each update.
  2179. this.loadMoreButton.$el.addClass( 'hidden' );
  2180. this.loadMoreCount.$el.addClass( 'hidden' );
  2181. this.loadMoreJumpToFirst.$el.addClass( 'hidden' ).prop( 'disabled', true );
  2182. if ( ! this.collection.getTotalAttachments() ) {
  2183. return;
  2184. }
  2185. if ( this.collection.length ) {
  2186. this.loadMoreCount.$el.text(
  2187. /* translators: 1: Number of displayed attachments, 2: Number of total attachments. */
  2188. sprintf(
  2189. __( 'Showing %1$s of %2$s media items' ),
  2190. this.collection.length,
  2191. this.collection.getTotalAttachments()
  2192. )
  2193. );
  2194. this.loadMoreCount.$el.removeClass( 'hidden' );
  2195. }
  2196. /*
  2197. * Notice that while the collection updates multiple times hasMore() may
  2198. * return true when it's actually not true.
  2199. */
  2200. if ( this.collection.hasMore() ) {
  2201. this.loadMoreButton.$el.removeClass( 'hidden' );
  2202. }
  2203. // Find the media item to move focus to. The jQuery `eq()` index is zero-based.
  2204. this.firstAddedMediaItem = this.$el.find( '.attachment' ).eq( this.firstAddedMediaItemIndex );
  2205. // If there's a media item to move focus to, make the "Jump to" button available.
  2206. if ( this.firstAddedMediaItem.length ) {
  2207. this.firstAddedMediaItem.addClass( 'new-media' );
  2208. this.loadMoreJumpToFirst.$el.removeClass( 'hidden' ).prop( 'disabled', false );
  2209. }
  2210. // If there are new items added, but no more to be added, move focus to Jump button.
  2211. if ( this.firstAddedMediaItem.length && ! this.collection.hasMore() ) {
  2212. this.loadMoreJumpToFirst.$el.trigger( 'focus' );
  2213. }
  2214. }, 10 ),
  2215. /**
  2216. * Loads more attachments.
  2217. *
  2218. * @since 5.8.0
  2219. *
  2220. * @return {void}
  2221. */
  2222. loadMoreAttachments: function() {
  2223. var view = this;
  2224. if ( ! this.collection.hasMore() ) {
  2225. return;
  2226. }
  2227. /*
  2228. * The collection index is zero-based while the length counts the actual
  2229. * amount of items. Thus the length is equivalent to the position of the
  2230. * first added item.
  2231. */
  2232. this.firstAddedMediaItemIndex = this.collection.length;
  2233. this.$el.addClass( 'more-loaded' );
  2234. this.collection.each( function( attachment ) {
  2235. var attach_id = attachment.attributes.id;
  2236. $( '[data-id="' + attach_id + '"]' ).addClass( 'found-media' );
  2237. });
  2238. view.loadMoreSpinner.show();
  2239. this.collection.once( 'attachments:received', function() {
  2240. view.loadMoreSpinner.hide();
  2241. } );
  2242. this.collection.more();
  2243. },
  2244. /**
  2245. * Moves focus to the first new added item. .
  2246. *
  2247. * @since 5.8.0
  2248. *
  2249. * @return {void}
  2250. */
  2251. jumpToFirstAddedItem: function() {
  2252. // Set focus on first added item.
  2253. this.firstAddedMediaItem.focus();
  2254. },
  2255. createAttachmentsHeading: function() {
  2256. this.attachmentsHeading = new wp.media.view.Heading( {
  2257. text: l10n.attachmentsList,
  2258. level: 'h2',
  2259. className: 'media-views-heading screen-reader-text'
  2260. } );
  2261. this.views.add( this.attachmentsHeading );
  2262. },
  2263. createSidebar: function() {
  2264. var options = this.options,
  2265. selection = options.selection,
  2266. sidebar = this.sidebar = new wp.media.view.Sidebar({
  2267. controller: this.controller
  2268. });
  2269. this.views.add( sidebar );
  2270. if ( this.controller.uploader ) {
  2271. sidebar.set( 'uploads', new wp.media.view.UploaderStatus({
  2272. controller: this.controller,
  2273. priority: 40
  2274. }) );
  2275. }
  2276. selection.on( 'selection:single', this.createSingle, this );
  2277. selection.on( 'selection:unsingle', this.disposeSingle, this );
  2278. if ( selection.single() ) {
  2279. this.createSingle();
  2280. }
  2281. },
  2282. createSingle: function() {
  2283. var sidebar = this.sidebar,
  2284. single = this.options.selection.single();
  2285. sidebar.set( 'details', new wp.media.view.Attachment.Details({
  2286. controller: this.controller,
  2287. model: single,
  2288. priority: 80
  2289. }) );
  2290. sidebar.set( 'compat', new wp.media.view.AttachmentCompat({
  2291. controller: this.controller,
  2292. model: single,
  2293. priority: 120
  2294. }) );
  2295. if ( this.options.display ) {
  2296. sidebar.set( 'display', new wp.media.view.Settings.AttachmentDisplay({
  2297. controller: this.controller,
  2298. model: this.model.display( single ),
  2299. attachment: single,
  2300. priority: 160,
  2301. userSettings: this.model.get('displayUserSettings')
  2302. }) );
  2303. }
  2304. // Show the sidebar on mobile.
  2305. if ( this.model.id === 'insert' ) {
  2306. sidebar.$el.addClass( 'visible' );
  2307. }
  2308. },
  2309. disposeSingle: function() {
  2310. var sidebar = this.sidebar;
  2311. sidebar.unset('details');
  2312. sidebar.unset('compat');
  2313. sidebar.unset('display');
  2314. // Hide the sidebar on mobile.
  2315. sidebar.$el.removeClass( 'visible' );
  2316. }
  2317. });
  2318. module.exports = AttachmentsBrowser;
  2319. /***/ }),
  2320. /***/ "76BF":
  2321. /***/ (function(module, exports) {
  2322. /**
  2323. * wp.media.view.Settings.Playlist
  2324. *
  2325. * @memberOf wp.media.view.Settings
  2326. *
  2327. * @class
  2328. * @augments wp.media.view.Settings
  2329. * @augments wp.media.View
  2330. * @augments wp.Backbone.View
  2331. * @augments Backbone.View
  2332. */
  2333. var Playlist = wp.media.view.Settings.extend(/** @lends wp.media.view.Settings.Playlist.prototype */{
  2334. className: 'collection-settings playlist-settings',
  2335. template: wp.template('playlist-settings')
  2336. });
  2337. module.exports = Playlist;
  2338. /***/ }),
  2339. /***/ "7Bpz":
  2340. /***/ (function(module, exports) {
  2341. var View = wp.media.View,
  2342. UploaderInline;
  2343. /**
  2344. * wp.media.view.UploaderInline
  2345. *
  2346. * The inline uploader that shows up in the 'Upload Files' tab.
  2347. *
  2348. * @memberOf wp.media.view
  2349. *
  2350. * @class
  2351. * @augments wp.media.View
  2352. * @augments wp.Backbone.View
  2353. * @augments Backbone.View
  2354. */
  2355. UploaderInline = View.extend(/** @lends wp.media.view.UploaderInline.prototype */{
  2356. tagName: 'div',
  2357. className: 'uploader-inline',
  2358. template: wp.template('uploader-inline'),
  2359. events: {
  2360. 'click .close': 'hide'
  2361. },
  2362. initialize: function() {
  2363. _.defaults( this.options, {
  2364. message: '',
  2365. status: true,
  2366. canClose: false
  2367. });
  2368. if ( ! this.options.$browser && this.controller.uploader ) {
  2369. this.options.$browser = this.controller.uploader.$browser;
  2370. }
  2371. if ( _.isUndefined( this.options.postId ) ) {
  2372. this.options.postId = wp.media.view.settings.post.id;
  2373. }
  2374. if ( this.options.status ) {
  2375. this.views.set( '.upload-inline-status', new wp.media.view.UploaderStatus({
  2376. controller: this.controller
  2377. }) );
  2378. }
  2379. },
  2380. prepare: function() {
  2381. var suggestedWidth = this.controller.state().get('suggestedWidth'),
  2382. suggestedHeight = this.controller.state().get('suggestedHeight'),
  2383. data = {};
  2384. data.message = this.options.message;
  2385. data.canClose = this.options.canClose;
  2386. if ( suggestedWidth && suggestedHeight ) {
  2387. data.suggestedWidth = suggestedWidth;
  2388. data.suggestedHeight = suggestedHeight;
  2389. }
  2390. return data;
  2391. },
  2392. /**
  2393. * @return {wp.media.view.UploaderInline} Returns itself to allow chaining.
  2394. */
  2395. dispose: function() {
  2396. if ( this.disposing ) {
  2397. /**
  2398. * call 'dispose' directly on the parent class
  2399. */
  2400. return View.prototype.dispose.apply( this, arguments );
  2401. }
  2402. /*
  2403. * Run remove on `dispose`, so we can be sure to refresh the
  2404. * uploader with a view-less DOM. Track whether we're disposing
  2405. * so we don't trigger an infinite loop.
  2406. */
  2407. this.disposing = true;
  2408. return this.remove();
  2409. },
  2410. /**
  2411. * @return {wp.media.view.UploaderInline} Returns itself to allow chaining.
  2412. */
  2413. remove: function() {
  2414. /**
  2415. * call 'remove' directly on the parent class
  2416. */
  2417. var result = View.prototype.remove.apply( this, arguments );
  2418. _.defer( _.bind( this.refresh, this ) );
  2419. return result;
  2420. },
  2421. refresh: function() {
  2422. var uploader = this.controller.uploader;
  2423. if ( uploader ) {
  2424. uploader.refresh();
  2425. }
  2426. },
  2427. /**
  2428. * @return {wp.media.view.UploaderInline}
  2429. */
  2430. ready: function() {
  2431. var $browser = this.options.$browser,
  2432. $placeholder;
  2433. if ( this.controller.uploader ) {
  2434. $placeholder = this.$('.browser');
  2435. // Check if we've already replaced the placeholder.
  2436. if ( $placeholder[0] === $browser[0] ) {
  2437. return;
  2438. }
  2439. $browser.detach().text( $placeholder.text() );
  2440. $browser[0].className = $placeholder[0].className;
  2441. $browser[0].setAttribute( 'aria-labelledby', $browser[0].id + ' ' + $placeholder[0].getAttribute('aria-labelledby') );
  2442. $placeholder.replaceWith( $browser.show() );
  2443. }
  2444. this.refresh();
  2445. return this;
  2446. },
  2447. show: function() {
  2448. this.$el.removeClass( 'hidden' );
  2449. if ( this.controller.$uploaderToggler && this.controller.$uploaderToggler.length ) {
  2450. this.controller.$uploaderToggler.attr( 'aria-expanded', 'true' );
  2451. }
  2452. },
  2453. hide: function() {
  2454. this.$el.addClass( 'hidden' );
  2455. if ( this.controller.$uploaderToggler && this.controller.$uploaderToggler.length ) {
  2456. this.controller.$uploaderToggler
  2457. .attr( 'aria-expanded', 'false' )
  2458. // Move focus back to the toggle button when closing the uploader.
  2459. .trigger( 'focus' );
  2460. }
  2461. }
  2462. });
  2463. module.exports = UploaderInline;
  2464. /***/ }),
  2465. /***/ "99yY":
  2466. /***/ (function(module, exports) {
  2467. var Library = wp.media.controller.Library,
  2468. l10n = wp.media.view.l10n,
  2469. GalleryEdit;
  2470. /**
  2471. * wp.media.controller.GalleryEdit
  2472. *
  2473. * A state for editing a gallery's images and settings.
  2474. *
  2475. * @since 3.5.0
  2476. *
  2477. * @class
  2478. * @augments wp.media.controller.Library
  2479. * @augments wp.media.controller.State
  2480. * @augments Backbone.Model
  2481. *
  2482. * @memberOf wp.media.controller
  2483. *
  2484. * @param {Object} [attributes] The attributes hash passed to the state.
  2485. * @param {string} [attributes.id=gallery-edit] Unique identifier.
  2486. * @param {string} [attributes.title=Edit Gallery] Title for the state. Displays in the frame's title region.
  2487. * @param {wp.media.model.Attachments} [attributes.library] The collection of attachments in the gallery.
  2488. * If one is not supplied, an empty media.model.Selection collection is created.
  2489. * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled.
  2490. * @param {boolean} [attributes.searchable=false] Whether the library is searchable.
  2491. * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
  2492. * @param {boolean} [attributes.date=true] Whether to show the date filter in the browser's toolbar.
  2493. * @param {string|false} [attributes.content=browse] Initial mode for the content region.
  2494. * @param {string|false} [attributes.toolbar=image-details] Initial mode for the toolbar region.
  2495. * @param {boolean} [attributes.describe=true] Whether to offer UI to describe attachments - e.g. captioning images in a gallery.
  2496. * @param {boolean} [attributes.displaySettings=true] Whether to show the attachment display settings interface.
  2497. * @param {boolean} [attributes.dragInfo=true] Whether to show instructional text about the attachments being sortable.
  2498. * @param {number} [attributes.idealColumnWidth=170] The ideal column width in pixels for attachments.
  2499. * @param {boolean} [attributes.editing=false] Whether the gallery is being created, or editing an existing instance.
  2500. * @param {number} [attributes.priority=60] The priority for the state link in the media menu.
  2501. * @param {boolean} [attributes.syncSelection=false] Whether the Attachments selection should be persisted from the last state.
  2502. * Defaults to false for this state, because the library passed in *is* the selection.
  2503. * @param {view} [attributes.AttachmentView] The single `Attachment` view to be used in the `Attachments`.
  2504. * If none supplied, defaults to wp.media.view.Attachment.EditLibrary.
  2505. */
  2506. GalleryEdit = Library.extend(/** @lends wp.media.controller.GalleryEdit.prototype */{
  2507. defaults: {
  2508. id: 'gallery-edit',
  2509. title: l10n.editGalleryTitle,
  2510. multiple: false,
  2511. searchable: false,
  2512. sortable: true,
  2513. date: false,
  2514. display: false,
  2515. content: 'browse',
  2516. toolbar: 'gallery-edit',
  2517. describe: true,
  2518. displaySettings: true,
  2519. dragInfo: true,
  2520. idealColumnWidth: 170,
  2521. editing: false,
  2522. priority: 60,
  2523. syncSelection: false
  2524. },
  2525. /**
  2526. * Initializes the library.
  2527. *
  2528. * Creates a selection if a library isn't supplied and creates an attachment
  2529. * view if no attachment view is supplied.
  2530. *
  2531. * @since 3.5.0
  2532. *
  2533. * @return {void}
  2534. */
  2535. initialize: function() {
  2536. // If we haven't been provided a `library`, create a `Selection`.
  2537. if ( ! this.get('library') ) {
  2538. this.set( 'library', new wp.media.model.Selection() );
  2539. }
  2540. // The single `Attachment` view to be used in the `Attachments` view.
  2541. if ( ! this.get('AttachmentView') ) {
  2542. this.set( 'AttachmentView', wp.media.view.Attachment.EditLibrary );
  2543. }
  2544. Library.prototype.initialize.apply( this, arguments );
  2545. },
  2546. /**
  2547. * Activates the library.
  2548. *
  2549. * Limits the library to images, watches for uploaded attachments. Watches for
  2550. * the browse event on the frame and binds it to gallerySettings.
  2551. *
  2552. * @since 3.5.0
  2553. *
  2554. * @return {void}
  2555. */
  2556. activate: function() {
  2557. var library = this.get('library');
  2558. // Limit the library to images only.
  2559. library.props.set( 'type', 'image' );
  2560. // Watch for uploaded attachments.
  2561. this.get('library').observe( wp.Uploader.queue );
  2562. this.frame.on( 'content:render:browse', this.gallerySettings, this );
  2563. Library.prototype.activate.apply( this, arguments );
  2564. },
  2565. /**
  2566. * Deactivates the library.
  2567. *
  2568. * Stops watching for uploaded attachments and browse events.
  2569. *
  2570. * @since 3.5.0
  2571. *
  2572. * @return {void}
  2573. */
  2574. deactivate: function() {
  2575. // Stop watching for uploaded attachments.
  2576. this.get('library').unobserve( wp.Uploader.queue );
  2577. this.frame.off( 'content:render:browse', this.gallerySettings, this );
  2578. Library.prototype.deactivate.apply( this, arguments );
  2579. },
  2580. /**
  2581. * Adds the gallery settings to the sidebar and adds a reverse button to the
  2582. * toolbar.
  2583. *
  2584. * @since 3.5.0
  2585. *
  2586. * @param {wp.media.view.Frame} browser The file browser.
  2587. *
  2588. * @return {void}
  2589. */
  2590. gallerySettings: function( browser ) {
  2591. if ( ! this.get('displaySettings') ) {
  2592. return;
  2593. }
  2594. var library = this.get('library');
  2595. if ( ! library || ! browser ) {
  2596. return;
  2597. }
  2598. library.gallery = library.gallery || new Backbone.Model();
  2599. browser.sidebar.set({
  2600. gallery: new wp.media.view.Settings.Gallery({
  2601. controller: this,
  2602. model: library.gallery,
  2603. priority: 40
  2604. })
  2605. });
  2606. browser.toolbar.set( 'reverse', {
  2607. text: l10n.reverseOrder,
  2608. priority: 80,
  2609. click: function() {
  2610. library.reset( library.toArray().reverse() );
  2611. }
  2612. });
  2613. }
  2614. });
  2615. module.exports = GalleryEdit;
  2616. /***/ }),
  2617. /***/ "9ARG":
  2618. /***/ (function(module, exports) {
  2619. /**
  2620. * wp.media.view.Sidebar
  2621. *
  2622. * @memberOf wp.media.view
  2623. *
  2624. * @class
  2625. * @augments wp.media.view.PriorityList
  2626. * @augments wp.media.View
  2627. * @augments wp.Backbone.View
  2628. * @augments Backbone.View
  2629. */
  2630. var Sidebar = wp.media.view.PriorityList.extend(/** @lends wp.media.view.Sidebar.prototype */{
  2631. className: 'media-sidebar'
  2632. });
  2633. module.exports = Sidebar;
  2634. /***/ }),
  2635. /***/ "Bbnu":
  2636. /***/ (function(module, exports) {
  2637. /**
  2638. * wp.media.View
  2639. *
  2640. * The base view class for media.
  2641. *
  2642. * Undelegating events, removing events from the model, and
  2643. * removing events from the controller mirror the code for
  2644. * `Backbone.View.dispose` in Backbone 0.9.8 development.
  2645. *
  2646. * This behavior has since been removed, and should not be used
  2647. * outside of the media manager.
  2648. *
  2649. * @memberOf wp.media
  2650. *
  2651. * @class
  2652. * @augments wp.Backbone.View
  2653. * @augments Backbone.View
  2654. */
  2655. var View = wp.Backbone.View.extend(/** @lends wp.media.View.prototype */{
  2656. constructor: function( options ) {
  2657. if ( options && options.controller ) {
  2658. this.controller = options.controller;
  2659. }
  2660. wp.Backbone.View.apply( this, arguments );
  2661. },
  2662. /**
  2663. * @todo The internal comment mentions this might have been a stop-gap
  2664. * before Backbone 0.9.8 came out. Figure out if Backbone core takes
  2665. * care of this in Backbone.View now.
  2666. *
  2667. * @return {wp.media.View} Returns itself to allow chaining.
  2668. */
  2669. dispose: function() {
  2670. /*
  2671. * Undelegating events, removing events from the model, and
  2672. * removing events from the controller mirror the code for
  2673. * `Backbone.View.dispose` in Backbone 0.9.8 development.
  2674. */
  2675. this.undelegateEvents();
  2676. if ( this.model && this.model.off ) {
  2677. this.model.off( null, null, this );
  2678. }
  2679. if ( this.collection && this.collection.off ) {
  2680. this.collection.off( null, null, this );
  2681. }
  2682. // Unbind controller events.
  2683. if ( this.controller && this.controller.off ) {
  2684. this.controller.off( null, null, this );
  2685. }
  2686. return this;
  2687. },
  2688. /**
  2689. * @return {wp.media.View} Returns itself to allow chaining.
  2690. */
  2691. remove: function() {
  2692. this.dispose();
  2693. /**
  2694. * call 'remove' directly on the parent class
  2695. */
  2696. return wp.Backbone.View.prototype.remove.apply( this, arguments );
  2697. }
  2698. });
  2699. module.exports = View;
  2700. /***/ }),
  2701. /***/ "EVvK":
  2702. /***/ (function(module, exports) {
  2703. var Menu = wp.media.view.Menu,
  2704. Router;
  2705. /**
  2706. * wp.media.view.Router
  2707. *
  2708. * @memberOf wp.media.view
  2709. *
  2710. * @class
  2711. * @augments wp.media.view.Menu
  2712. * @augments wp.media.view.PriorityList
  2713. * @augments wp.media.View
  2714. * @augments wp.Backbone.View
  2715. * @augments Backbone.View
  2716. */
  2717. Router = Menu.extend(/** @lends wp.media.view.Router.prototype */{
  2718. tagName: 'div',
  2719. className: 'media-router',
  2720. property: 'contentMode',
  2721. ItemView: wp.media.view.RouterItem,
  2722. region: 'router',
  2723. attributes: {
  2724. role: 'tablist',
  2725. 'aria-orientation': 'horizontal'
  2726. },
  2727. initialize: function() {
  2728. this.controller.on( 'content:render', this.update, this );
  2729. // Call 'initialize' directly on the parent class.
  2730. Menu.prototype.initialize.apply( this, arguments );
  2731. },
  2732. update: function() {
  2733. var mode = this.controller.content.mode();
  2734. if ( mode ) {
  2735. this.select( mode );
  2736. }
  2737. }
  2738. });
  2739. module.exports = Router;
  2740. /***/ }),
  2741. /***/ "EvXF":
  2742. /***/ (function(module, exports) {
  2743. /**
  2744. * wp.media.view.Attachment.EditLibrary
  2745. *
  2746. * @memberOf wp.media.view.Attachment
  2747. *
  2748. * @class
  2749. * @augments wp.media.view.Attachment
  2750. * @augments wp.media.View
  2751. * @augments wp.Backbone.View
  2752. * @augments Backbone.View
  2753. */
  2754. var EditLibrary = wp.media.view.Attachment.extend(/** @lends wp.media.view.Attachment.EditLibrary.prototype */{
  2755. buttons: {
  2756. close: true
  2757. }
  2758. });
  2759. module.exports = EditLibrary;
  2760. /***/ }),
  2761. /***/ "F/kE":
  2762. /***/ (function(module, exports) {
  2763. var l10n = wp.media.view.l10n,
  2764. getUserSetting = window.getUserSetting,
  2765. setUserSetting = window.setUserSetting,
  2766. Library;
  2767. /**
  2768. * wp.media.controller.Library
  2769. *
  2770. * A state for choosing an attachment or group of attachments from the media library.
  2771. *
  2772. * @memberOf wp.media.controller
  2773. *
  2774. * @class
  2775. * @augments wp.media.controller.State
  2776. * @augments Backbone.Model
  2777. * @mixes media.selectionSync
  2778. *
  2779. * @param {object} [attributes] The attributes hash passed to the state.
  2780. * @param {string} [attributes.id=library] Unique identifier.
  2781. * @param {string} [attributes.title=Media library] Title for the state. Displays in the media menu and the frame's title region.
  2782. * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse.
  2783. * If one is not supplied, a collection of all attachments will be created.
  2784. * @param {wp.media.model.Selection|object} [attributes.selection] A collection to contain attachment selections within the state.
  2785. * If the 'selection' attribute is a plain JS object,
  2786. * a Selection will be created using its values as the selection instance's `props` model.
  2787. * Otherwise, it will copy the library's `props` model.
  2788. * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled.
  2789. * @param {string} [attributes.content=upload] Initial mode for the content region.
  2790. * Overridden by persistent user setting if 'contentUserSetting' is true.
  2791. * @param {string} [attributes.menu=default] Initial mode for the menu region.
  2792. * @param {string} [attributes.router=browse] Initial mode for the router region.
  2793. * @param {string} [attributes.toolbar=select] Initial mode for the toolbar region.
  2794. * @param {boolean} [attributes.searchable=true] Whether the library is searchable.
  2795. * @param {boolean|string} [attributes.filterable=false] Whether the library is filterable, and if so what filters should be shown.
  2796. * Accepts 'all', 'uploaded', or 'unattached'.
  2797. * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
  2798. * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection.
  2799. * @param {boolean} [attributes.describe=false] Whether to offer UI to describe attachments - e.g. captioning images in a gallery.
  2800. * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user.
  2801. * @param {boolean} [attributes.syncSelection=true] Whether the Attachments selection should be persisted from the last state.
  2802. */
  2803. Library = wp.media.controller.State.extend(/** @lends wp.media.controller.Library.prototype */{
  2804. defaults: {
  2805. id: 'library',
  2806. title: l10n.mediaLibraryTitle,
  2807. multiple: false,
  2808. content: 'upload',
  2809. menu: 'default',
  2810. router: 'browse',
  2811. toolbar: 'select',
  2812. searchable: true,
  2813. filterable: false,
  2814. sortable: true,
  2815. autoSelect: true,
  2816. describe: false,
  2817. contentUserSetting: true,
  2818. syncSelection: true
  2819. },
  2820. /**
  2821. * If a library isn't provided, query all media items.
  2822. * If a selection instance isn't provided, create one.
  2823. *
  2824. * @since 3.5.0
  2825. */
  2826. initialize: function() {
  2827. var selection = this.get('selection'),
  2828. props;
  2829. if ( ! this.get('library') ) {
  2830. this.set( 'library', wp.media.query() );
  2831. }
  2832. if ( ! ( selection instanceof wp.media.model.Selection ) ) {
  2833. props = selection;
  2834. if ( ! props ) {
  2835. props = this.get('library').props.toJSON();
  2836. props = _.omit( props, 'orderby', 'query' );
  2837. }
  2838. this.set( 'selection', new wp.media.model.Selection( null, {
  2839. multiple: this.get('multiple'),
  2840. props: props
  2841. }) );
  2842. }
  2843. this.resetDisplays();
  2844. },
  2845. /**
  2846. * @since 3.5.0
  2847. */
  2848. activate: function() {
  2849. this.syncSelection();
  2850. wp.Uploader.queue.on( 'add', this.uploading, this );
  2851. this.get('selection').on( 'add remove reset', this.refreshContent, this );
  2852. if ( this.get( 'router' ) && this.get('contentUserSetting') ) {
  2853. this.frame.on( 'content:activate', this.saveContentMode, this );
  2854. this.set( 'content', getUserSetting( 'libraryContent', this.get('content') ) );
  2855. }
  2856. },
  2857. /**
  2858. * @since 3.5.0
  2859. */
  2860. deactivate: function() {
  2861. this.recordSelection();
  2862. this.frame.off( 'content:activate', this.saveContentMode, this );
  2863. // Unbind all event handlers that use this state as the context
  2864. // from the selection.
  2865. this.get('selection').off( null, null, this );
  2866. wp.Uploader.queue.off( null, null, this );
  2867. },
  2868. /**
  2869. * Reset the library to its initial state.
  2870. *
  2871. * @since 3.5.0
  2872. */
  2873. reset: function() {
  2874. this.get('selection').reset();
  2875. this.resetDisplays();
  2876. this.refreshContent();
  2877. },
  2878. /**
  2879. * Reset the attachment display settings defaults to the site options.
  2880. *
  2881. * If site options don't define them, fall back to a persistent user setting.
  2882. *
  2883. * @since 3.5.0
  2884. */
  2885. resetDisplays: function() {
  2886. var defaultProps = wp.media.view.settings.defaultProps;
  2887. this._displays = [];
  2888. this._defaultDisplaySettings = {
  2889. align: getUserSetting( 'align', defaultProps.align ) || 'none',
  2890. size: getUserSetting( 'imgsize', defaultProps.size ) || 'medium',
  2891. link: getUserSetting( 'urlbutton', defaultProps.link ) || 'none'
  2892. };
  2893. },
  2894. /**
  2895. * Create a model to represent display settings (alignment, etc.) for an attachment.
  2896. *
  2897. * @since 3.5.0
  2898. *
  2899. * @param {wp.media.model.Attachment} attachment
  2900. * @return {Backbone.Model}
  2901. */
  2902. display: function( attachment ) {
  2903. var displays = this._displays;
  2904. if ( ! displays[ attachment.cid ] ) {
  2905. displays[ attachment.cid ] = new Backbone.Model( this.defaultDisplaySettings( attachment ) );
  2906. }
  2907. return displays[ attachment.cid ];
  2908. },
  2909. /**
  2910. * Given an attachment, create attachment display settings properties.
  2911. *
  2912. * @since 3.6.0
  2913. *
  2914. * @param {wp.media.model.Attachment} attachment
  2915. * @return {Object}
  2916. */
  2917. defaultDisplaySettings: function( attachment ) {
  2918. var settings = _.clone( this._defaultDisplaySettings );
  2919. settings.canEmbed = this.canEmbed( attachment );
  2920. if ( settings.canEmbed ) {
  2921. settings.link = 'embed';
  2922. } else if ( ! this.isImageAttachment( attachment ) && settings.link === 'none' ) {
  2923. settings.link = 'file';
  2924. }
  2925. return settings;
  2926. },
  2927. /**
  2928. * Whether an attachment is image.
  2929. *
  2930. * @since 4.4.1
  2931. *
  2932. * @param {wp.media.model.Attachment} attachment
  2933. * @return {boolean}
  2934. */
  2935. isImageAttachment: function( attachment ) {
  2936. // If uploading, we know the filename but not the mime type.
  2937. if ( attachment.get('uploading') ) {
  2938. return /\.(jpe?g|png|gif)$/i.test( attachment.get('filename') );
  2939. }
  2940. return attachment.get('type') === 'image';
  2941. },
  2942. /**
  2943. * Whether an attachment can be embedded (audio or video).
  2944. *
  2945. * @since 3.6.0
  2946. *
  2947. * @param {wp.media.model.Attachment} attachment
  2948. * @return {boolean}
  2949. */
  2950. canEmbed: function( attachment ) {
  2951. // If uploading, we know the filename but not the mime type.
  2952. if ( ! attachment.get('uploading') ) {
  2953. var type = attachment.get('type');
  2954. if ( type !== 'audio' && type !== 'video' ) {
  2955. return false;
  2956. }
  2957. }
  2958. return _.contains( wp.media.view.settings.embedExts, attachment.get('filename').split('.').pop() );
  2959. },
  2960. /**
  2961. * If the state is active, no items are selected, and the current
  2962. * content mode is not an option in the state's router (provided
  2963. * the state has a router), reset the content mode to the default.
  2964. *
  2965. * @since 3.5.0
  2966. */
  2967. refreshContent: function() {
  2968. var selection = this.get('selection'),
  2969. frame = this.frame,
  2970. router = frame.router.get(),
  2971. mode = frame.content.mode();
  2972. if ( this.active && ! selection.length && router && ! router.get( mode ) ) {
  2973. this.frame.content.render( this.get('content') );
  2974. }
  2975. },
  2976. /**
  2977. * Callback handler when an attachment is uploaded.
  2978. *
  2979. * Switch to the Media Library if uploaded from the 'Upload Files' tab.
  2980. *
  2981. * Adds any uploading attachments to the selection.
  2982. *
  2983. * If the state only supports one attachment to be selected and multiple
  2984. * attachments are uploaded, the last attachment in the upload queue will
  2985. * be selected.
  2986. *
  2987. * @since 3.5.0
  2988. *
  2989. * @param {wp.media.model.Attachment} attachment
  2990. */
  2991. uploading: function( attachment ) {
  2992. var content = this.frame.content;
  2993. if ( 'upload' === content.mode() ) {
  2994. this.frame.content.mode('browse');
  2995. }
  2996. if ( this.get( 'autoSelect' ) ) {
  2997. this.get('selection').add( attachment );
  2998. this.frame.trigger( 'library:selection:add' );
  2999. }
  3000. },
  3001. /**
  3002. * Persist the mode of the content region as a user setting.
  3003. *
  3004. * @since 3.5.0
  3005. */
  3006. saveContentMode: function() {
  3007. if ( 'browse' !== this.get('router') ) {
  3008. return;
  3009. }
  3010. var mode = this.frame.content.mode(),
  3011. view = this.frame.router.get();
  3012. if ( view && view.get( mode ) ) {
  3013. setUserSetting( 'libraryContent', mode );
  3014. }
  3015. }
  3016. });
  3017. // Make selectionSync available on any Media Library state.
  3018. _.extend( Library.prototype, wp.media.selectionSync );
  3019. module.exports = Library;
  3020. /***/ }),
  3021. /***/ "GXJ6":
  3022. /***/ (function(module, exports) {
  3023. var AttachmentDisplay = wp.media.view.Settings.AttachmentDisplay,
  3024. $ = jQuery,
  3025. ImageDetails;
  3026. /**
  3027. * wp.media.view.ImageDetails
  3028. *
  3029. * @memberOf wp.media.view
  3030. *
  3031. * @class
  3032. * @augments wp.media.view.Settings.AttachmentDisplay
  3033. * @augments wp.media.view.Settings
  3034. * @augments wp.media.View
  3035. * @augments wp.Backbone.View
  3036. * @augments Backbone.View
  3037. */
  3038. ImageDetails = AttachmentDisplay.extend(/** @lends wp.media.view.ImageDetails.prototype */{
  3039. className: 'image-details',
  3040. template: wp.template('image-details'),
  3041. events: _.defaults( AttachmentDisplay.prototype.events, {
  3042. 'click .edit-attachment': 'editAttachment',
  3043. 'click .replace-attachment': 'replaceAttachment',
  3044. 'click .advanced-toggle': 'onToggleAdvanced',
  3045. 'change [data-setting="customWidth"]': 'onCustomSize',
  3046. 'change [data-setting="customHeight"]': 'onCustomSize',
  3047. 'keyup [data-setting="customWidth"]': 'onCustomSize',
  3048. 'keyup [data-setting="customHeight"]': 'onCustomSize'
  3049. } ),
  3050. initialize: function() {
  3051. // Used in AttachmentDisplay.prototype.updateLinkTo.
  3052. this.options.attachment = this.model.attachment;
  3053. this.listenTo( this.model, 'change:url', this.updateUrl );
  3054. this.listenTo( this.model, 'change:link', this.toggleLinkSettings );
  3055. this.listenTo( this.model, 'change:size', this.toggleCustomSize );
  3056. AttachmentDisplay.prototype.initialize.apply( this, arguments );
  3057. },
  3058. prepare: function() {
  3059. var attachment = false;
  3060. if ( this.model.attachment ) {
  3061. attachment = this.model.attachment.toJSON();
  3062. }
  3063. return _.defaults({
  3064. model: this.model.toJSON(),
  3065. attachment: attachment
  3066. }, this.options );
  3067. },
  3068. render: function() {
  3069. var args = arguments;
  3070. if ( this.model.attachment && 'pending' === this.model.dfd.state() ) {
  3071. this.model.dfd
  3072. .done( _.bind( function() {
  3073. AttachmentDisplay.prototype.render.apply( this, args );
  3074. this.postRender();
  3075. }, this ) )
  3076. .fail( _.bind( function() {
  3077. this.model.attachment = false;
  3078. AttachmentDisplay.prototype.render.apply( this, args );
  3079. this.postRender();
  3080. }, this ) );
  3081. } else {
  3082. AttachmentDisplay.prototype.render.apply( this, arguments );
  3083. this.postRender();
  3084. }
  3085. return this;
  3086. },
  3087. postRender: function() {
  3088. setTimeout( _.bind( this.scrollToTop, this ), 10 );
  3089. this.toggleLinkSettings();
  3090. if ( window.getUserSetting( 'advImgDetails' ) === 'show' ) {
  3091. this.toggleAdvanced( true );
  3092. }
  3093. this.trigger( 'post-render' );
  3094. },
  3095. scrollToTop: function() {
  3096. this.$( '.embed-media-settings' ).scrollTop( 0 );
  3097. },
  3098. updateUrl: function() {
  3099. this.$( '.image img' ).attr( 'src', this.model.get( 'url' ) );
  3100. this.$( '.url' ).val( this.model.get( 'url' ) );
  3101. },
  3102. toggleLinkSettings: function() {
  3103. if ( this.model.get( 'link' ) === 'none' ) {
  3104. this.$( '.link-settings' ).addClass('hidden');
  3105. } else {
  3106. this.$( '.link-settings' ).removeClass('hidden');
  3107. }
  3108. },
  3109. toggleCustomSize: function() {
  3110. if ( this.model.get( 'size' ) !== 'custom' ) {
  3111. this.$( '.custom-size' ).addClass('hidden');
  3112. } else {
  3113. this.$( '.custom-size' ).removeClass('hidden');
  3114. }
  3115. },
  3116. onCustomSize: function( event ) {
  3117. var dimension = $( event.target ).data('setting'),
  3118. num = $( event.target ).val(),
  3119. value;
  3120. // Ignore bogus input.
  3121. if ( ! /^\d+/.test( num ) || parseInt( num, 10 ) < 1 ) {
  3122. event.preventDefault();
  3123. return;
  3124. }
  3125. if ( dimension === 'customWidth' ) {
  3126. value = Math.round( 1 / this.model.get( 'aspectRatio' ) * num );
  3127. this.model.set( 'customHeight', value, { silent: true } );
  3128. this.$( '[data-setting="customHeight"]' ).val( value );
  3129. } else {
  3130. value = Math.round( this.model.get( 'aspectRatio' ) * num );
  3131. this.model.set( 'customWidth', value, { silent: true } );
  3132. this.$( '[data-setting="customWidth"]' ).val( value );
  3133. }
  3134. },
  3135. onToggleAdvanced: function( event ) {
  3136. event.preventDefault();
  3137. this.toggleAdvanced();
  3138. },
  3139. toggleAdvanced: function( show ) {
  3140. var $advanced = this.$el.find( '.advanced-section' ),
  3141. mode;
  3142. if ( $advanced.hasClass('advanced-visible') || show === false ) {
  3143. $advanced.removeClass('advanced-visible');
  3144. $advanced.find('.advanced-settings').addClass('hidden');
  3145. mode = 'hide';
  3146. } else {
  3147. $advanced.addClass('advanced-visible');
  3148. $advanced.find('.advanced-settings').removeClass('hidden');
  3149. mode = 'show';
  3150. }
  3151. window.setUserSetting( 'advImgDetails', mode );
  3152. },
  3153. editAttachment: function( event ) {
  3154. var editState = this.controller.states.get( 'edit-image' );
  3155. if ( window.imageEdit && editState ) {
  3156. event.preventDefault();
  3157. editState.set( 'image', this.model.attachment );
  3158. this.controller.setState( 'edit-image' );
  3159. }
  3160. },
  3161. replaceAttachment: function( event ) {
  3162. event.preventDefault();
  3163. this.controller.setState( 'replace-image' );
  3164. }
  3165. });
  3166. module.exports = ImageDetails;
  3167. /***/ }),
  3168. /***/ "GXkx":
  3169. /***/ (function(module, exports) {
  3170. var View = wp.media.View,
  3171. l10n = wp.media.view.l10n,
  3172. $ = jQuery,
  3173. EditorUploader;
  3174. /**
  3175. * Creates a dropzone on WP editor instances (elements with .wp-editor-wrap)
  3176. * and relays drag'n'dropped files to a media workflow.
  3177. *
  3178. * wp.media.view.EditorUploader
  3179. *
  3180. * @memberOf wp.media.view
  3181. *
  3182. * @class
  3183. * @augments wp.media.View
  3184. * @augments wp.Backbone.View
  3185. * @augments Backbone.View
  3186. */
  3187. EditorUploader = View.extend(/** @lends wp.media.view.EditorUploader.prototype */{
  3188. tagName: 'div',
  3189. className: 'uploader-editor',
  3190. template: wp.template( 'uploader-editor' ),
  3191. localDrag: false,
  3192. overContainer: false,
  3193. overDropzone: false,
  3194. draggingFile: null,
  3195. /**
  3196. * Bind drag'n'drop events to callbacks.
  3197. */
  3198. initialize: function() {
  3199. this.initialized = false;
  3200. // Bail if not enabled or UA does not support drag'n'drop or File API.
  3201. if ( ! window.tinyMCEPreInit || ! window.tinyMCEPreInit.dragDropUpload || ! this.browserSupport() ) {
  3202. return this;
  3203. }
  3204. this.$document = $(document);
  3205. this.dropzones = [];
  3206. this.files = [];
  3207. this.$document.on( 'drop', '.uploader-editor', _.bind( this.drop, this ) );
  3208. this.$document.on( 'dragover', '.uploader-editor', _.bind( this.dropzoneDragover, this ) );
  3209. this.$document.on( 'dragleave', '.uploader-editor', _.bind( this.dropzoneDragleave, this ) );
  3210. this.$document.on( 'click', '.uploader-editor', _.bind( this.click, this ) );
  3211. this.$document.on( 'dragover', _.bind( this.containerDragover, this ) );
  3212. this.$document.on( 'dragleave', _.bind( this.containerDragleave, this ) );
  3213. this.$document.on( 'dragstart dragend drop', _.bind( function( event ) {
  3214. this.localDrag = event.type === 'dragstart';
  3215. if ( event.type === 'drop' ) {
  3216. this.containerDragleave();
  3217. }
  3218. }, this ) );
  3219. this.initialized = true;
  3220. return this;
  3221. },
  3222. /**
  3223. * Check browser support for drag'n'drop.
  3224. *
  3225. * @return {boolean}
  3226. */
  3227. browserSupport: function() {
  3228. var supports = false, div = document.createElement('div');
  3229. supports = ( 'draggable' in div ) || ( 'ondragstart' in div && 'ondrop' in div );
  3230. supports = supports && !! ( window.File && window.FileList && window.FileReader );
  3231. return supports;
  3232. },
  3233. isDraggingFile: function( event ) {
  3234. if ( this.draggingFile !== null ) {
  3235. return this.draggingFile;
  3236. }
  3237. if ( _.isUndefined( event.originalEvent ) || _.isUndefined( event.originalEvent.dataTransfer ) ) {
  3238. return false;
  3239. }
  3240. this.draggingFile = _.indexOf( event.originalEvent.dataTransfer.types, 'Files' ) > -1 &&
  3241. _.indexOf( event.originalEvent.dataTransfer.types, 'text/plain' ) === -1;
  3242. return this.draggingFile;
  3243. },
  3244. refresh: function( e ) {
  3245. var dropzone_id;
  3246. for ( dropzone_id in this.dropzones ) {
  3247. // Hide the dropzones only if dragging has left the screen.
  3248. this.dropzones[ dropzone_id ].toggle( this.overContainer || this.overDropzone );
  3249. }
  3250. if ( ! _.isUndefined( e ) ) {
  3251. $( e.target ).closest( '.uploader-editor' ).toggleClass( 'droppable', this.overDropzone );
  3252. }
  3253. if ( ! this.overContainer && ! this.overDropzone ) {
  3254. this.draggingFile = null;
  3255. }
  3256. return this;
  3257. },
  3258. render: function() {
  3259. if ( ! this.initialized ) {
  3260. return this;
  3261. }
  3262. View.prototype.render.apply( this, arguments );
  3263. $( '.wp-editor-wrap' ).each( _.bind( this.attach, this ) );
  3264. return this;
  3265. },
  3266. attach: function( index, editor ) {
  3267. // Attach a dropzone to an editor.
  3268. var dropzone = this.$el.clone();
  3269. this.dropzones.push( dropzone );
  3270. $( editor ).append( dropzone );
  3271. return this;
  3272. },
  3273. /**
  3274. * When a file is dropped on the editor uploader, open up an editor media workflow
  3275. * and upload the file immediately.
  3276. *
  3277. * @param {jQuery.Event} event The 'drop' event.
  3278. */
  3279. drop: function( event ) {
  3280. var $wrap, uploadView;
  3281. this.containerDragleave( event );
  3282. this.dropzoneDragleave( event );
  3283. this.files = event.originalEvent.dataTransfer.files;
  3284. if ( this.files.length < 1 ) {
  3285. return;
  3286. }
  3287. // Set the active editor to the drop target.
  3288. $wrap = $( event.target ).parents( '.wp-editor-wrap' );
  3289. if ( $wrap.length > 0 && $wrap[0].id ) {
  3290. window.wpActiveEditor = $wrap[0].id.slice( 3, -5 );
  3291. }
  3292. if ( ! this.workflow ) {
  3293. this.workflow = wp.media.editor.open( window.wpActiveEditor, {
  3294. frame: 'post',
  3295. state: 'insert',
  3296. title: l10n.addMedia,
  3297. multiple: true
  3298. });
  3299. uploadView = this.workflow.uploader;
  3300. if ( uploadView.uploader && uploadView.uploader.ready ) {
  3301. this.addFiles.apply( this );
  3302. } else {
  3303. this.workflow.on( 'uploader:ready', this.addFiles, this );
  3304. }
  3305. } else {
  3306. this.workflow.state().reset();
  3307. this.addFiles.apply( this );
  3308. this.workflow.open();
  3309. }
  3310. return false;
  3311. },
  3312. /**
  3313. * Add the files to the uploader.
  3314. */
  3315. addFiles: function() {
  3316. if ( this.files.length ) {
  3317. this.workflow.uploader.uploader.uploader.addFile( _.toArray( this.files ) );
  3318. this.files = [];
  3319. }
  3320. return this;
  3321. },
  3322. containerDragover: function( event ) {
  3323. if ( this.localDrag || ! this.isDraggingFile( event ) ) {
  3324. return;
  3325. }
  3326. this.overContainer = true;
  3327. this.refresh();
  3328. },
  3329. containerDragleave: function() {
  3330. this.overContainer = false;
  3331. // Throttle dragleave because it's called when bouncing from some elements to others.
  3332. _.delay( _.bind( this.refresh, this ), 50 );
  3333. },
  3334. dropzoneDragover: function( event ) {
  3335. if ( this.localDrag || ! this.isDraggingFile( event ) ) {
  3336. return;
  3337. }
  3338. this.overDropzone = true;
  3339. this.refresh( event );
  3340. return false;
  3341. },
  3342. dropzoneDragleave: function( e ) {
  3343. this.overDropzone = false;
  3344. _.delay( _.bind( this.refresh, this, e ), 50 );
  3345. },
  3346. click: function( e ) {
  3347. // In the rare case where the dropzone gets stuck, hide it on click.
  3348. this.containerDragleave( e );
  3349. this.dropzoneDragleave( e );
  3350. this.localDrag = false;
  3351. }
  3352. });
  3353. module.exports = EditorUploader;
  3354. /***/ }),
  3355. /***/ "I7TD":
  3356. /***/ (function(module, exports) {
  3357. var Attachment = wp.media.model.Attachment,
  3358. Library = wp.media.controller.Library,
  3359. l10n = wp.media.view.l10n,
  3360. FeaturedImage;
  3361. /**
  3362. * wp.media.controller.FeaturedImage
  3363. *
  3364. * A state for selecting a featured image for a post.
  3365. *
  3366. * @memberOf wp.media.controller
  3367. *
  3368. * @class
  3369. * @augments wp.media.controller.Library
  3370. * @augments wp.media.controller.State
  3371. * @augments Backbone.Model
  3372. *
  3373. * @param {object} [attributes] The attributes hash passed to the state.
  3374. * @param {string} [attributes.id=featured-image] Unique identifier.
  3375. * @param {string} [attributes.title=Set Featured Image] Title for the state. Displays in the media menu and the frame's title region.
  3376. * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse.
  3377. * If one is not supplied, a collection of all images will be created.
  3378. * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled.
  3379. * @param {string} [attributes.content=upload] Initial mode for the content region.
  3380. * Overridden by persistent user setting if 'contentUserSetting' is true.
  3381. * @param {string} [attributes.menu=default] Initial mode for the menu region.
  3382. * @param {string} [attributes.router=browse] Initial mode for the router region.
  3383. * @param {string} [attributes.toolbar=featured-image] Initial mode for the toolbar region.
  3384. * @param {int} [attributes.priority=60] The priority for the state link in the media menu.
  3385. * @param {boolean} [attributes.searchable=true] Whether the library is searchable.
  3386. * @param {boolean|string} [attributes.filterable=false] Whether the library is filterable, and if so what filters should be shown.
  3387. * Accepts 'all', 'uploaded', or 'unattached'.
  3388. * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
  3389. * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection.
  3390. * @param {boolean} [attributes.describe=false] Whether to offer UI to describe attachments - e.g. captioning images in a gallery.
  3391. * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user.
  3392. * @param {boolean} [attributes.syncSelection=true] Whether the Attachments selection should be persisted from the last state.
  3393. */
  3394. FeaturedImage = Library.extend(/** @lends wp.media.controller.FeaturedImage.prototype */{
  3395. defaults: _.defaults({
  3396. id: 'featured-image',
  3397. title: l10n.setFeaturedImageTitle,
  3398. multiple: false,
  3399. filterable: 'uploaded',
  3400. toolbar: 'featured-image',
  3401. priority: 60,
  3402. syncSelection: true
  3403. }, Library.prototype.defaults ),
  3404. /**
  3405. * @since 3.5.0
  3406. */
  3407. initialize: function() {
  3408. var library, comparator;
  3409. // If we haven't been provided a `library`, create a `Selection`.
  3410. if ( ! this.get('library') ) {
  3411. this.set( 'library', wp.media.query({ type: 'image' }) );
  3412. }
  3413. Library.prototype.initialize.apply( this, arguments );
  3414. library = this.get('library');
  3415. comparator = library.comparator;
  3416. // Overload the library's comparator to push items that are not in
  3417. // the mirrored query to the front of the aggregate collection.
  3418. library.comparator = function( a, b ) {
  3419. var aInQuery = !! this.mirroring.get( a.cid ),
  3420. bInQuery = !! this.mirroring.get( b.cid );
  3421. if ( ! aInQuery && bInQuery ) {
  3422. return -1;
  3423. } else if ( aInQuery && ! bInQuery ) {
  3424. return 1;
  3425. } else {
  3426. return comparator.apply( this, arguments );
  3427. }
  3428. };
  3429. // Add all items in the selection to the library, so any featured
  3430. // images that are not initially loaded still appear.
  3431. library.observe( this.get('selection') );
  3432. },
  3433. /**
  3434. * @since 3.5.0
  3435. */
  3436. activate: function() {
  3437. this.updateSelection();
  3438. this.frame.on( 'open', this.updateSelection, this );
  3439. Library.prototype.activate.apply( this, arguments );
  3440. },
  3441. /**
  3442. * @since 3.5.0
  3443. */
  3444. deactivate: function() {
  3445. this.frame.off( 'open', this.updateSelection, this );
  3446. Library.prototype.deactivate.apply( this, arguments );
  3447. },
  3448. /**
  3449. * @since 3.5.0
  3450. */
  3451. updateSelection: function() {
  3452. var selection = this.get('selection'),
  3453. id = wp.media.view.settings.post.featuredImageId,
  3454. attachment;
  3455. if ( '' !== id && -1 !== id ) {
  3456. attachment = Attachment.get( id );
  3457. attachment.fetch();
  3458. }
  3459. selection.reset( attachment ? [ attachment ] : [] );
  3460. }
  3461. });
  3462. module.exports = FeaturedImage;
  3463. /***/ }),
  3464. /***/ "IgEq":
  3465. /***/ (function(module, exports) {
  3466. var Toolbar = wp.media.view.Toolbar,
  3467. l10n = wp.media.view.l10n,
  3468. Select;
  3469. /**
  3470. * wp.media.view.Toolbar.Select
  3471. *
  3472. * @memberOf wp.media.view.Toolbar
  3473. *
  3474. * @class
  3475. * @augments wp.media.view.Toolbar
  3476. * @augments wp.media.View
  3477. * @augments wp.Backbone.View
  3478. * @augments Backbone.View
  3479. */
  3480. Select = Toolbar.extend(/** @lends wp.media.view.Toolbar.Select.prototype */{
  3481. initialize: function() {
  3482. var options = this.options;
  3483. _.bindAll( this, 'clickSelect' );
  3484. _.defaults( options, {
  3485. event: 'select',
  3486. state: false,
  3487. reset: true,
  3488. close: true,
  3489. text: l10n.select,
  3490. // Does the button rely on the selection?
  3491. requires: {
  3492. selection: true
  3493. }
  3494. });
  3495. options.items = _.defaults( options.items || {}, {
  3496. select: {
  3497. style: 'primary',
  3498. text: options.text,
  3499. priority: 80,
  3500. click: this.clickSelect,
  3501. requires: options.requires
  3502. }
  3503. });
  3504. // Call 'initialize' directly on the parent class.
  3505. Toolbar.prototype.initialize.apply( this, arguments );
  3506. },
  3507. clickSelect: function() {
  3508. var options = this.options,
  3509. controller = this.controller;
  3510. if ( options.close ) {
  3511. controller.close();
  3512. }
  3513. if ( options.event ) {
  3514. controller.state().trigger( options.event );
  3515. }
  3516. if ( options.state ) {
  3517. controller.setState( options.state );
  3518. }
  3519. if ( options.reset ) {
  3520. controller.reset();
  3521. }
  3522. }
  3523. });
  3524. module.exports = Select;
  3525. /***/ }),
  3526. /***/ "IkWq":
  3527. /***/ (function(module, exports) {
  3528. var State = wp.media.controller.State,
  3529. Library = wp.media.controller.Library,
  3530. l10n = wp.media.view.l10n,
  3531. ImageDetails;
  3532. /**
  3533. * wp.media.controller.ImageDetails
  3534. *
  3535. * A state for editing the attachment display settings of an image that's been
  3536. * inserted into the editor.
  3537. *
  3538. * @memberOf wp.media.controller
  3539. *
  3540. * @class
  3541. * @augments wp.media.controller.State
  3542. * @augments Backbone.Model
  3543. *
  3544. * @param {object} [attributes] The attributes hash passed to the state.
  3545. * @param {string} [attributes.id=image-details] Unique identifier.
  3546. * @param {string} [attributes.title=Image Details] Title for the state. Displays in the frame's title region.
  3547. * @param {wp.media.model.Attachment} attributes.image The image's model.
  3548. * @param {string|false} [attributes.content=image-details] Initial mode for the content region.
  3549. * @param {string|false} [attributes.menu=false] Initial mode for the menu region.
  3550. * @param {string|false} [attributes.router=false] Initial mode for the router region.
  3551. * @param {string|false} [attributes.toolbar=image-details] Initial mode for the toolbar region.
  3552. * @param {boolean} [attributes.editing=false] Unused.
  3553. * @param {int} [attributes.priority=60] Unused.
  3554. *
  3555. * @todo This state inherits some defaults from media.controller.Library.prototype.defaults,
  3556. * however this may not do anything.
  3557. */
  3558. ImageDetails = State.extend(/** @lends wp.media.controller.ImageDetails.prototype */{
  3559. defaults: _.defaults({
  3560. id: 'image-details',
  3561. title: l10n.imageDetailsTitle,
  3562. content: 'image-details',
  3563. menu: false,
  3564. router: false,
  3565. toolbar: 'image-details',
  3566. editing: false,
  3567. priority: 60
  3568. }, Library.prototype.defaults ),
  3569. /**
  3570. * @since 3.9.0
  3571. *
  3572. * @param options Attributes
  3573. */
  3574. initialize: function( options ) {
  3575. this.image = options.image;
  3576. State.prototype.initialize.apply( this, arguments );
  3577. },
  3578. /**
  3579. * @since 3.9.0
  3580. */
  3581. activate: function() {
  3582. this.frame.modal.$el.addClass('image-details');
  3583. }
  3584. });
  3585. module.exports = ImageDetails;
  3586. /***/ }),
  3587. /***/ "JecU":
  3588. /***/ (function(module, exports) {
  3589. var $ = jQuery,
  3590. EmbedLink;
  3591. /**
  3592. * wp.media.view.EmbedLink
  3593. *
  3594. * @memberOf wp.media.view
  3595. *
  3596. * @class
  3597. * @augments wp.media.view.Settings
  3598. * @augments wp.media.View
  3599. * @augments wp.Backbone.View
  3600. * @augments Backbone.View
  3601. */
  3602. EmbedLink = wp.media.view.Settings.extend(/** @lends wp.media.view.EmbedLink.prototype */{
  3603. className: 'embed-link-settings',
  3604. template: wp.template('embed-link-settings'),
  3605. initialize: function() {
  3606. this.listenTo( this.model, 'change:url', this.updateoEmbed );
  3607. },
  3608. updateoEmbed: _.debounce( function() {
  3609. var url = this.model.get( 'url' );
  3610. // Clear out previous results.
  3611. this.$('.embed-container').hide().find('.embed-preview').empty();
  3612. this.$( '.setting' ).hide();
  3613. // Only proceed with embed if the field contains more than 11 characters.
  3614. // Example: http://a.io is 11 chars
  3615. if ( url && ( url.length < 11 || ! url.match(/^http(s)?:\/\//) ) ) {
  3616. return;
  3617. }
  3618. this.fetch();
  3619. }, wp.media.controller.Embed.sensitivity ),
  3620. fetch: function() {
  3621. var url = this.model.get( 'url' ), re, youTubeEmbedMatch;
  3622. // Check if they haven't typed in 500 ms.
  3623. if ( $('#embed-url-field').val() !== url ) {
  3624. return;
  3625. }
  3626. if ( this.dfd && 'pending' === this.dfd.state() ) {
  3627. this.dfd.abort();
  3628. }
  3629. // Support YouTube embed urls, since they work once in the editor.
  3630. re = /https?:\/\/www\.youtube\.com\/embed\/([^/]+)/;
  3631. youTubeEmbedMatch = re.exec( url );
  3632. if ( youTubeEmbedMatch ) {
  3633. url = 'https://www.youtube.com/watch?v=' + youTubeEmbedMatch[ 1 ];
  3634. }
  3635. this.dfd = wp.apiRequest({
  3636. url: wp.media.view.settings.oEmbedProxyUrl,
  3637. data: {
  3638. url: url,
  3639. maxwidth: this.model.get( 'width' ),
  3640. maxheight: this.model.get( 'height' )
  3641. },
  3642. type: 'GET',
  3643. dataType: 'json',
  3644. context: this
  3645. })
  3646. .done( function( response ) {
  3647. this.renderoEmbed( {
  3648. data: {
  3649. body: response.html || ''
  3650. }
  3651. } );
  3652. } )
  3653. .fail( this.renderFail );
  3654. },
  3655. renderFail: function ( response, status ) {
  3656. if ( 'abort' === status ) {
  3657. return;
  3658. }
  3659. this.$( '.link-text' ).show();
  3660. },
  3661. renderoEmbed: function( response ) {
  3662. var html = ( response && response.data && response.data.body ) || '';
  3663. if ( html ) {
  3664. this.$('.embed-container').show().find('.embed-preview').html( html );
  3665. } else {
  3666. this.renderFail();
  3667. }
  3668. }
  3669. });
  3670. module.exports = EmbedLink;
  3671. /***/ }),
  3672. /***/ "Ju2C":
  3673. /***/ (function(module, exports) {
  3674. var MenuItem = wp.media.view.MenuItem,
  3675. PriorityList = wp.media.view.PriorityList,
  3676. Menu;
  3677. /**
  3678. * wp.media.view.Menu
  3679. *
  3680. * @memberOf wp.media.view
  3681. *
  3682. * @class
  3683. * @augments wp.media.view.PriorityList
  3684. * @augments wp.media.View
  3685. * @augments wp.Backbone.View
  3686. * @augments Backbone.View
  3687. */
  3688. Menu = PriorityList.extend(/** @lends wp.media.view.Menu.prototype */{
  3689. tagName: 'div',
  3690. className: 'media-menu',
  3691. property: 'state',
  3692. ItemView: MenuItem,
  3693. region: 'menu',
  3694. attributes: {
  3695. role: 'tablist',
  3696. 'aria-orientation': 'horizontal'
  3697. },
  3698. initialize: function() {
  3699. this._views = {};
  3700. this.set( _.extend( {}, this._views, this.options.views ), { silent: true });
  3701. delete this.options.views;
  3702. if ( ! this.options.silent ) {
  3703. this.render();
  3704. }
  3705. // Initialize the Focus Manager.
  3706. this.focusManager = new wp.media.view.FocusManager( {
  3707. el: this.el,
  3708. mode: 'tabsNavigation'
  3709. } );
  3710. // The menu is always rendered and can be visible or hidden on some frames.
  3711. this.isVisible = true;
  3712. },
  3713. /**
  3714. * @param {Object} options
  3715. * @param {string} id
  3716. * @return {wp.media.View}
  3717. */
  3718. toView: function( options, id ) {
  3719. options = options || {};
  3720. options[ this.property ] = options[ this.property ] || id;
  3721. return new this.ItemView( options ).render();
  3722. },
  3723. ready: function() {
  3724. /**
  3725. * call 'ready' directly on the parent class
  3726. */
  3727. PriorityList.prototype.ready.apply( this, arguments );
  3728. this.visibility();
  3729. // Set up aria tabs initial attributes.
  3730. this.focusManager.setupAriaTabs();
  3731. },
  3732. set: function() {
  3733. /**
  3734. * call 'set' directly on the parent class
  3735. */
  3736. PriorityList.prototype.set.apply( this, arguments );
  3737. this.visibility();
  3738. },
  3739. unset: function() {
  3740. /**
  3741. * call 'unset' directly on the parent class
  3742. */
  3743. PriorityList.prototype.unset.apply( this, arguments );
  3744. this.visibility();
  3745. },
  3746. visibility: function() {
  3747. var region = this.region,
  3748. view = this.controller[ region ].get(),
  3749. views = this.views.get(),
  3750. hide = ! views || views.length < 2;
  3751. if ( this === view ) {
  3752. // Flag this menu as hidden or visible.
  3753. this.isVisible = ! hide;
  3754. // Set or remove a CSS class to hide the menu.
  3755. this.controller.$el.toggleClass( 'hide-' + region, hide );
  3756. }
  3757. },
  3758. /**
  3759. * @param {string} id
  3760. */
  3761. select: function( id ) {
  3762. var view = this.get( id );
  3763. if ( ! view ) {
  3764. return;
  3765. }
  3766. this.deselect();
  3767. view.$el.addClass('active');
  3768. // Set up again the aria tabs initial attributes after the menu updates.
  3769. this.focusManager.setupAriaTabs();
  3770. },
  3771. deselect: function() {
  3772. this.$el.children().removeClass('active');
  3773. },
  3774. hide: function( id ) {
  3775. var view = this.get( id );
  3776. if ( ! view ) {
  3777. return;
  3778. }
  3779. view.$el.addClass('hidden');
  3780. },
  3781. show: function( id ) {
  3782. var view = this.get( id );
  3783. if ( ! view ) {
  3784. return;
  3785. }
  3786. view.$el.removeClass('hidden');
  3787. }
  3788. });
  3789. module.exports = Menu;
  3790. /***/ }),
  3791. /***/ "KerO":
  3792. /***/ (function(module, exports) {
  3793. var l10n = wp.media.view.l10n,
  3794. All;
  3795. /**
  3796. * wp.media.view.AttachmentFilters.All
  3797. *
  3798. * @memberOf wp.media.view.AttachmentFilters
  3799. *
  3800. * @class
  3801. * @augments wp.media.view.AttachmentFilters
  3802. * @augments wp.media.View
  3803. * @augments wp.Backbone.View
  3804. * @augments Backbone.View
  3805. */
  3806. All = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.AttachmentFilters.All.prototype */{
  3807. createFilters: function() {
  3808. var filters = {},
  3809. uid = window.userSettings ? parseInt( window.userSettings.uid, 10 ) : 0;
  3810. _.each( wp.media.view.settings.mimeTypes || {}, function( text, key ) {
  3811. filters[ key ] = {
  3812. text: text,
  3813. props: {
  3814. status: null,
  3815. type: key,
  3816. uploadedTo: null,
  3817. orderby: 'date',
  3818. order: 'DESC',
  3819. author: null
  3820. }
  3821. };
  3822. });
  3823. filters.all = {
  3824. text: l10n.allMediaItems,
  3825. props: {
  3826. status: null,
  3827. type: null,
  3828. uploadedTo: null,
  3829. orderby: 'date',
  3830. order: 'DESC',
  3831. author: null
  3832. },
  3833. priority: 10
  3834. };
  3835. if ( wp.media.view.settings.post.id ) {
  3836. filters.uploaded = {
  3837. text: l10n.uploadedToThisPost,
  3838. props: {
  3839. status: null,
  3840. type: null,
  3841. uploadedTo: wp.media.view.settings.post.id,
  3842. orderby: 'menuOrder',
  3843. order: 'ASC',
  3844. author: null
  3845. },
  3846. priority: 20
  3847. };
  3848. }
  3849. filters.unattached = {
  3850. text: l10n.unattached,
  3851. props: {
  3852. status: null,
  3853. uploadedTo: 0,
  3854. type: null,
  3855. orderby: 'menuOrder',
  3856. order: 'ASC',
  3857. author: null
  3858. },
  3859. priority: 50
  3860. };
  3861. if ( uid ) {
  3862. filters.mine = {
  3863. text: l10n.mine,
  3864. props: {
  3865. status: null,
  3866. type: null,
  3867. uploadedTo: null,
  3868. orderby: 'date',
  3869. order: 'DESC',
  3870. author: uid
  3871. },
  3872. priority: 50
  3873. };
  3874. }
  3875. if ( wp.media.view.settings.mediaTrash &&
  3876. this.controller.isModeActive( 'grid' ) ) {
  3877. filters.trash = {
  3878. text: l10n.trash,
  3879. props: {
  3880. uploadedTo: null,
  3881. status: 'trash',
  3882. type: null,
  3883. orderby: 'date',
  3884. order: 'DESC',
  3885. author: null
  3886. },
  3887. priority: 50
  3888. };
  3889. }
  3890. this.filters = filters;
  3891. }
  3892. });
  3893. module.exports = All;
  3894. /***/ }),
  3895. /***/ "LGdN":
  3896. /***/ (function(module, exports) {
  3897. /**
  3898. * wp.media.view.Frame
  3899. *
  3900. * A frame is a composite view consisting of one or more regions and one or more
  3901. * states.
  3902. *
  3903. * @memberOf wp.media.view
  3904. *
  3905. * @see wp.media.controller.State
  3906. * @see wp.media.controller.Region
  3907. *
  3908. * @class
  3909. * @augments wp.media.View
  3910. * @augments wp.Backbone.View
  3911. * @augments Backbone.View
  3912. * @mixes wp.media.controller.StateMachine
  3913. */
  3914. var Frame = wp.media.View.extend(/** @lends wp.media.view.Frame.prototype */{
  3915. initialize: function() {
  3916. _.defaults( this.options, {
  3917. mode: [ 'select' ]
  3918. });
  3919. this._createRegions();
  3920. this._createStates();
  3921. this._createModes();
  3922. },
  3923. _createRegions: function() {
  3924. // Clone the regions array.
  3925. this.regions = this.regions ? this.regions.slice() : [];
  3926. // Initialize regions.
  3927. _.each( this.regions, function( region ) {
  3928. this[ region ] = new wp.media.controller.Region({
  3929. view: this,
  3930. id: region,
  3931. selector: '.media-frame-' + region
  3932. });
  3933. }, this );
  3934. },
  3935. /**
  3936. * Create the frame's states.
  3937. *
  3938. * @see wp.media.controller.State
  3939. * @see wp.media.controller.StateMachine
  3940. *
  3941. * @fires wp.media.controller.State#ready
  3942. */
  3943. _createStates: function() {
  3944. // Create the default `states` collection.
  3945. this.states = new Backbone.Collection( null, {
  3946. model: wp.media.controller.State
  3947. });
  3948. // Ensure states have a reference to the frame.
  3949. this.states.on( 'add', function( model ) {
  3950. model.frame = this;
  3951. model.trigger('ready');
  3952. }, this );
  3953. if ( this.options.states ) {
  3954. this.states.add( this.options.states );
  3955. }
  3956. },
  3957. /**
  3958. * A frame can be in a mode or multiple modes at one time.
  3959. *
  3960. * For example, the manage media frame can be in the `Bulk Select` or `Edit` mode.
  3961. */
  3962. _createModes: function() {
  3963. // Store active "modes" that the frame is in. Unrelated to region modes.
  3964. this.activeModes = new Backbone.Collection();
  3965. this.activeModes.on( 'add remove reset', _.bind( this.triggerModeEvents, this ) );
  3966. _.each( this.options.mode, function( mode ) {
  3967. this.activateMode( mode );
  3968. }, this );
  3969. },
  3970. /**
  3971. * Reset all states on the frame to their defaults.
  3972. *
  3973. * @return {wp.media.view.Frame} Returns itself to allow chaining.
  3974. */
  3975. reset: function() {
  3976. this.states.invoke( 'trigger', 'reset' );
  3977. return this;
  3978. },
  3979. /**
  3980. * Map activeMode collection events to the frame.
  3981. */
  3982. triggerModeEvents: function( model, collection, options ) {
  3983. var collectionEvent,
  3984. modeEventMap = {
  3985. add: 'activate',
  3986. remove: 'deactivate'
  3987. },
  3988. eventToTrigger;
  3989. // Probably a better way to do this.
  3990. _.each( options, function( value, key ) {
  3991. if ( value ) {
  3992. collectionEvent = key;
  3993. }
  3994. } );
  3995. if ( ! _.has( modeEventMap, collectionEvent ) ) {
  3996. return;
  3997. }
  3998. eventToTrigger = model.get('id') + ':' + modeEventMap[collectionEvent];
  3999. this.trigger( eventToTrigger );
  4000. },
  4001. /**
  4002. * Activate a mode on the frame.
  4003. *
  4004. * @param string mode Mode ID.
  4005. * @return {this} Returns itself to allow chaining.
  4006. */
  4007. activateMode: function( mode ) {
  4008. // Bail if the mode is already active.
  4009. if ( this.isModeActive( mode ) ) {
  4010. return;
  4011. }
  4012. this.activeModes.add( [ { id: mode } ] );
  4013. // Add a CSS class to the frame so elements can be styled for the mode.
  4014. this.$el.addClass( 'mode-' + mode );
  4015. return this;
  4016. },
  4017. /**
  4018. * Deactivate a mode on the frame.
  4019. *
  4020. * @param string mode Mode ID.
  4021. * @return {this} Returns itself to allow chaining.
  4022. */
  4023. deactivateMode: function( mode ) {
  4024. // Bail if the mode isn't active.
  4025. if ( ! this.isModeActive( mode ) ) {
  4026. return this;
  4027. }
  4028. this.activeModes.remove( this.activeModes.where( { id: mode } ) );
  4029. this.$el.removeClass( 'mode-' + mode );
  4030. /**
  4031. * Frame mode deactivation event.
  4032. *
  4033. * @event wp.media.view.Frame#{mode}:deactivate
  4034. */
  4035. this.trigger( mode + ':deactivate' );
  4036. return this;
  4037. },
  4038. /**
  4039. * Check if a mode is enabled on the frame.
  4040. *
  4041. * @param string mode Mode ID.
  4042. * @return bool
  4043. */
  4044. isModeActive: function( mode ) {
  4045. return Boolean( this.activeModes.where( { id: mode } ).length );
  4046. }
  4047. });
  4048. // Make the `Frame` a `StateMachine`.
  4049. _.extend( Frame.prototype, wp.media.controller.StateMachine.prototype );
  4050. module.exports = Frame;
  4051. /***/ }),
  4052. /***/ "LND6":
  4053. /***/ (function(module, exports) {
  4054. var View = wp.media.View,
  4055. AttachmentCompat;
  4056. /**
  4057. * wp.media.view.AttachmentCompat
  4058. *
  4059. * A view to display fields added via the `attachment_fields_to_edit` filter.
  4060. *
  4061. * @memberOf wp.media.view
  4062. *
  4063. * @class
  4064. * @augments wp.media.View
  4065. * @augments wp.Backbone.View
  4066. * @augments Backbone.View
  4067. */
  4068. AttachmentCompat = View.extend(/** @lends wp.media.view.AttachmentCompat.prototype */{
  4069. tagName: 'form',
  4070. className: 'compat-item',
  4071. events: {
  4072. 'submit': 'preventDefault',
  4073. 'change input': 'save',
  4074. 'change select': 'save',
  4075. 'change textarea': 'save'
  4076. },
  4077. initialize: function() {
  4078. this.listenTo( this.model, 'change:compat', this.render );
  4079. },
  4080. /**
  4081. * @return {wp.media.view.AttachmentCompat} Returns itself to allow chaining.
  4082. */
  4083. dispose: function() {
  4084. if ( this.$(':focus').length ) {
  4085. this.save();
  4086. }
  4087. /**
  4088. * call 'dispose' directly on the parent class
  4089. */
  4090. return View.prototype.dispose.apply( this, arguments );
  4091. },
  4092. /**
  4093. * @return {wp.media.view.AttachmentCompat} Returns itself to allow chaining.
  4094. */
  4095. render: function() {
  4096. var compat = this.model.get('compat');
  4097. if ( ! compat || ! compat.item ) {
  4098. return;
  4099. }
  4100. this.views.detach();
  4101. this.$el.html( compat.item );
  4102. this.views.render();
  4103. return this;
  4104. },
  4105. /**
  4106. * @param {Object} event
  4107. */
  4108. preventDefault: function( event ) {
  4109. event.preventDefault();
  4110. },
  4111. /**
  4112. * @param {Object} event
  4113. */
  4114. save: function( event ) {
  4115. var data = {};
  4116. if ( event ) {
  4117. event.preventDefault();
  4118. }
  4119. _.each( this.$el.serializeArray(), function( pair ) {
  4120. data[ pair.name ] = pair.value;
  4121. });
  4122. this.controller.trigger( 'attachment:compat:waiting', ['waiting'] );
  4123. this.model.saveCompat( data ).always( _.bind( this.postSave, this ) );
  4124. },
  4125. postSave: function() {
  4126. this.controller.trigger( 'attachment:compat:ready', ['ready'] );
  4127. }
  4128. });
  4129. module.exports = AttachmentCompat;
  4130. /***/ }),
  4131. /***/ "LZpE":
  4132. /***/ (function(module, exports) {
  4133. /**
  4134. * wp.media.view.Button
  4135. *
  4136. * @memberOf wp.media.view
  4137. *
  4138. * @class
  4139. * @augments wp.media.View
  4140. * @augments wp.Backbone.View
  4141. * @augments Backbone.View
  4142. */
  4143. var Button = wp.media.View.extend(/** @lends wp.media.view.Button.prototype */{
  4144. tagName: 'button',
  4145. className: 'media-button',
  4146. attributes: { type: 'button' },
  4147. events: {
  4148. 'click': 'click'
  4149. },
  4150. defaults: {
  4151. text: '',
  4152. style: '',
  4153. size: 'large',
  4154. disabled: false
  4155. },
  4156. initialize: function() {
  4157. /**
  4158. * Create a model with the provided `defaults`.
  4159. *
  4160. * @member {Backbone.Model}
  4161. */
  4162. this.model = new Backbone.Model( this.defaults );
  4163. // If any of the `options` have a key from `defaults`, apply its
  4164. // value to the `model` and remove it from the `options object.
  4165. _.each( this.defaults, function( def, key ) {
  4166. var value = this.options[ key ];
  4167. if ( _.isUndefined( value ) ) {
  4168. return;
  4169. }
  4170. this.model.set( key, value );
  4171. delete this.options[ key ];
  4172. }, this );
  4173. this.listenTo( this.model, 'change', this.render );
  4174. },
  4175. /**
  4176. * @return {wp.media.view.Button} Returns itself to allow chaining.
  4177. */
  4178. render: function() {
  4179. var classes = [ 'button', this.className ],
  4180. model = this.model.toJSON();
  4181. if ( model.style ) {
  4182. classes.push( 'button-' + model.style );
  4183. }
  4184. if ( model.size ) {
  4185. classes.push( 'button-' + model.size );
  4186. }
  4187. classes = _.uniq( classes.concat( this.options.classes ) );
  4188. this.el.className = classes.join(' ');
  4189. this.$el.attr( 'disabled', model.disabled );
  4190. this.$el.text( this.model.get('text') );
  4191. return this;
  4192. },
  4193. /**
  4194. * @param {Object} event
  4195. */
  4196. click: function( event ) {
  4197. if ( '#' === this.attributes.href ) {
  4198. event.preventDefault();
  4199. }
  4200. if ( this.options.click && ! this.model.get('disabled') ) {
  4201. this.options.click.apply( this, arguments );
  4202. }
  4203. }
  4204. });
  4205. module.exports = Button;
  4206. /***/ }),
  4207. /***/ "M+xU":
  4208. /***/ (function(module, exports) {
  4209. var l10n = wp.media.view.l10n,
  4210. Cropper;
  4211. /**
  4212. * wp.media.controller.Cropper
  4213. *
  4214. * A class for cropping an image when called from the header media customization panel.
  4215. *
  4216. * @memberOf wp.media.controller
  4217. *
  4218. * @class
  4219. * @augments wp.media.controller.State
  4220. * @augments Backbone.Model
  4221. */
  4222. Cropper = wp.media.controller.State.extend(/** @lends wp.media.controller.Cropper.prototype */{
  4223. defaults: {
  4224. id: 'cropper',
  4225. title: l10n.cropImage,
  4226. // Region mode defaults.
  4227. toolbar: 'crop',
  4228. content: 'crop',
  4229. router: false,
  4230. canSkipCrop: false,
  4231. // Default doCrop Ajax arguments to allow the Customizer (for example) to inject state.
  4232. doCropArgs: {}
  4233. },
  4234. /**
  4235. * Shows the crop image window when called from the Add new image button.
  4236. *
  4237. * @since 4.2.0
  4238. *
  4239. * @return {void}
  4240. */
  4241. activate: function() {
  4242. this.frame.on( 'content:create:crop', this.createCropContent, this );
  4243. this.frame.on( 'close', this.removeCropper, this );
  4244. this.set('selection', new Backbone.Collection(this.frame._selection.single));
  4245. },
  4246. /**
  4247. * Changes the state of the toolbar window to browse mode.
  4248. *
  4249. * @since 4.2.0
  4250. *
  4251. * @return {void}
  4252. */
  4253. deactivate: function() {
  4254. this.frame.toolbar.mode('browse');
  4255. },
  4256. /**
  4257. * Creates the crop image window.
  4258. *
  4259. * Initialized when clicking on the Select and Crop button.
  4260. *
  4261. * @since 4.2.0
  4262. *
  4263. * @fires crop window
  4264. *
  4265. * @return {void}
  4266. */
  4267. createCropContent: function() {
  4268. this.cropperView = new wp.media.view.Cropper({
  4269. controller: this,
  4270. attachment: this.get('selection').first()
  4271. });
  4272. this.cropperView.on('image-loaded', this.createCropToolbar, this);
  4273. this.frame.content.set(this.cropperView);
  4274. },
  4275. /**
  4276. * Removes the image selection and closes the cropping window.
  4277. *
  4278. * @since 4.2.0
  4279. *
  4280. * @return {void}
  4281. */
  4282. removeCropper: function() {
  4283. this.imgSelect.cancelSelection();
  4284. this.imgSelect.setOptions({remove: true});
  4285. this.imgSelect.update();
  4286. this.cropperView.remove();
  4287. },
  4288. /**
  4289. * Checks if cropping can be skipped and creates crop toolbar accordingly.
  4290. *
  4291. * @since 4.2.0
  4292. *
  4293. * @return {void}
  4294. */
  4295. createCropToolbar: function() {
  4296. var canSkipCrop, toolbarOptions;
  4297. canSkipCrop = this.get('canSkipCrop') || false;
  4298. toolbarOptions = {
  4299. controller: this.frame,
  4300. items: {
  4301. insert: {
  4302. style: 'primary',
  4303. text: l10n.cropImage,
  4304. priority: 80,
  4305. requires: { library: false, selection: false },
  4306. click: function() {
  4307. var controller = this.controller,
  4308. selection;
  4309. selection = controller.state().get('selection').first();
  4310. selection.set({cropDetails: controller.state().imgSelect.getSelection()});
  4311. this.$el.text(l10n.cropping);
  4312. this.$el.attr('disabled', true);
  4313. controller.state().doCrop( selection ).done( function( croppedImage ) {
  4314. controller.trigger('cropped', croppedImage );
  4315. controller.close();
  4316. }).fail( function() {
  4317. controller.trigger('content:error:crop');
  4318. });
  4319. }
  4320. }
  4321. }
  4322. };
  4323. if ( canSkipCrop ) {
  4324. _.extend( toolbarOptions.items, {
  4325. skip: {
  4326. style: 'secondary',
  4327. text: l10n.skipCropping,
  4328. priority: 70,
  4329. requires: { library: false, selection: false },
  4330. click: function() {
  4331. var selection = this.controller.state().get('selection').first();
  4332. this.controller.state().cropperView.remove();
  4333. this.controller.trigger('skippedcrop', selection);
  4334. this.controller.close();
  4335. }
  4336. }
  4337. });
  4338. }
  4339. this.frame.toolbar.set( new wp.media.view.Toolbar(toolbarOptions) );
  4340. },
  4341. /**
  4342. * Creates an object with the image attachment and crop properties.
  4343. *
  4344. * @since 4.2.0
  4345. *
  4346. * @return {$.promise} A jQuery promise with the custom header crop details.
  4347. */
  4348. doCrop: function( attachment ) {
  4349. return wp.ajax.post( 'custom-header-crop', _.extend(
  4350. {},
  4351. this.defaults.doCropArgs,
  4352. {
  4353. nonce: attachment.get( 'nonces' ).edit,
  4354. id: attachment.get( 'id' ),
  4355. cropDetails: attachment.get( 'cropDetails' )
  4356. }
  4357. ) );
  4358. }
  4359. });
  4360. module.exports = Cropper;
  4361. /***/ }),
  4362. /***/ "M5ZC":
  4363. /***/ (function(module, exports) {
  4364. /**
  4365. * wp.media.controller.State
  4366. *
  4367. * A state is a step in a workflow that when set will trigger the controllers
  4368. * for the regions to be updated as specified in the frame.
  4369. *
  4370. * A state has an event-driven lifecycle:
  4371. *
  4372. * 'ready' triggers when a state is added to a state machine's collection.
  4373. * 'activate' triggers when a state is activated by a state machine.
  4374. * 'deactivate' triggers when a state is deactivated by a state machine.
  4375. * 'reset' is not triggered automatically. It should be invoked by the
  4376. * proper controller to reset the state to its default.
  4377. *
  4378. * @memberOf wp.media.controller
  4379. *
  4380. * @class
  4381. * @augments Backbone.Model
  4382. */
  4383. var State = Backbone.Model.extend(/** @lends wp.media.controller.State.prototype */{
  4384. /**
  4385. * Constructor.
  4386. *
  4387. * @since 3.5.0
  4388. */
  4389. constructor: function() {
  4390. this.on( 'activate', this._preActivate, this );
  4391. this.on( 'activate', this.activate, this );
  4392. this.on( 'activate', this._postActivate, this );
  4393. this.on( 'deactivate', this._deactivate, this );
  4394. this.on( 'deactivate', this.deactivate, this );
  4395. this.on( 'reset', this.reset, this );
  4396. this.on( 'ready', this._ready, this );
  4397. this.on( 'ready', this.ready, this );
  4398. /**
  4399. * Call parent constructor with passed arguments
  4400. */
  4401. Backbone.Model.apply( this, arguments );
  4402. this.on( 'change:menu', this._updateMenu, this );
  4403. },
  4404. /**
  4405. * Ready event callback.
  4406. *
  4407. * @abstract
  4408. * @since 3.5.0
  4409. */
  4410. ready: function() {},
  4411. /**
  4412. * Activate event callback.
  4413. *
  4414. * @abstract
  4415. * @since 3.5.0
  4416. */
  4417. activate: function() {},
  4418. /**
  4419. * Deactivate event callback.
  4420. *
  4421. * @abstract
  4422. * @since 3.5.0
  4423. */
  4424. deactivate: function() {},
  4425. /**
  4426. * Reset event callback.
  4427. *
  4428. * @abstract
  4429. * @since 3.5.0
  4430. */
  4431. reset: function() {},
  4432. /**
  4433. * @since 3.5.0
  4434. * @access private
  4435. */
  4436. _ready: function() {
  4437. this._updateMenu();
  4438. },
  4439. /**
  4440. * @since 3.5.0
  4441. * @access private
  4442. */
  4443. _preActivate: function() {
  4444. this.active = true;
  4445. },
  4446. /**
  4447. * @since 3.5.0
  4448. * @access private
  4449. */
  4450. _postActivate: function() {
  4451. this.on( 'change:menu', this._menu, this );
  4452. this.on( 'change:titleMode', this._title, this );
  4453. this.on( 'change:content', this._content, this );
  4454. this.on( 'change:toolbar', this._toolbar, this );
  4455. this.frame.on( 'title:render:default', this._renderTitle, this );
  4456. this._title();
  4457. this._menu();
  4458. this._toolbar();
  4459. this._content();
  4460. this._router();
  4461. },
  4462. /**
  4463. * @since 3.5.0
  4464. * @access private
  4465. */
  4466. _deactivate: function() {
  4467. this.active = false;
  4468. this.frame.off( 'title:render:default', this._renderTitle, this );
  4469. this.off( 'change:menu', this._menu, this );
  4470. this.off( 'change:titleMode', this._title, this );
  4471. this.off( 'change:content', this._content, this );
  4472. this.off( 'change:toolbar', this._toolbar, this );
  4473. },
  4474. /**
  4475. * @since 3.5.0
  4476. * @access private
  4477. */
  4478. _title: function() {
  4479. this.frame.title.render( this.get('titleMode') || 'default' );
  4480. },
  4481. /**
  4482. * @since 3.5.0
  4483. * @access private
  4484. */
  4485. _renderTitle: function( view ) {
  4486. view.$el.text( this.get('title') || '' );
  4487. },
  4488. /**
  4489. * @since 3.5.0
  4490. * @access private
  4491. */
  4492. _router: function() {
  4493. var router = this.frame.router,
  4494. mode = this.get('router'),
  4495. view;
  4496. this.frame.$el.toggleClass( 'hide-router', ! mode );
  4497. if ( ! mode ) {
  4498. return;
  4499. }
  4500. this.frame.router.render( mode );
  4501. view = router.get();
  4502. if ( view && view.select ) {
  4503. view.select( this.frame.content.mode() );
  4504. }
  4505. },
  4506. /**
  4507. * @since 3.5.0
  4508. * @access private
  4509. */
  4510. _menu: function() {
  4511. var menu = this.frame.menu,
  4512. mode = this.get('menu'),
  4513. view;
  4514. this.frame.$el.toggleClass( 'hide-menu', ! mode );
  4515. if ( ! mode ) {
  4516. return;
  4517. }
  4518. menu.mode( mode );
  4519. view = menu.get();
  4520. if ( view && view.select ) {
  4521. view.select( this.id );
  4522. }
  4523. },
  4524. /**
  4525. * @since 3.5.0
  4526. * @access private
  4527. */
  4528. _updateMenu: function() {
  4529. var previous = this.previous('menu'),
  4530. menu = this.get('menu');
  4531. if ( previous ) {
  4532. this.frame.off( 'menu:render:' + previous, this._renderMenu, this );
  4533. }
  4534. if ( menu ) {
  4535. this.frame.on( 'menu:render:' + menu, this._renderMenu, this );
  4536. }
  4537. },
  4538. /**
  4539. * Create a view in the media menu for the state.
  4540. *
  4541. * @since 3.5.0
  4542. * @access private
  4543. *
  4544. * @param {media.view.Menu} view The menu view.
  4545. */
  4546. _renderMenu: function( view ) {
  4547. var menuItem = this.get('menuItem'),
  4548. title = this.get('title'),
  4549. priority = this.get('priority');
  4550. if ( ! menuItem && title ) {
  4551. menuItem = { text: title };
  4552. if ( priority ) {
  4553. menuItem.priority = priority;
  4554. }
  4555. }
  4556. if ( ! menuItem ) {
  4557. return;
  4558. }
  4559. view.set( this.id, menuItem );
  4560. }
  4561. });
  4562. _.each(['toolbar','content'], function( region ) {
  4563. /**
  4564. * @access private
  4565. */
  4566. State.prototype[ '_' + region ] = function() {
  4567. var mode = this.get( region );
  4568. if ( mode ) {
  4569. this.frame[ region ].render( mode );
  4570. }
  4571. };
  4572. });
  4573. module.exports = State;
  4574. /***/ }),
  4575. /***/ "Mt+m":
  4576. /***/ (function(module, exports) {
  4577. var Library = wp.media.controller.Library,
  4578. l10n = wp.media.view.l10n,
  4579. $ = jQuery,
  4580. CollectionEdit;
  4581. /**
  4582. * wp.media.controller.CollectionEdit
  4583. *
  4584. * A state for editing a collection, which is used by audio and video playlists,
  4585. * and can be used for other collections.
  4586. *
  4587. * @memberOf wp.media.controller
  4588. *
  4589. * @class
  4590. * @augments wp.media.controller.Library
  4591. * @augments wp.media.controller.State
  4592. * @augments Backbone.Model
  4593. *
  4594. * @param {object} [attributes] The attributes hash passed to the state.
  4595. * @param {string} attributes.title Title for the state. Displays in the media menu and the frame's title region.
  4596. * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to edit.
  4597. * If one is not supplied, an empty media.model.Selection collection is created.
  4598. * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled.
  4599. * @param {string} [attributes.content=browse] Initial mode for the content region.
  4600. * @param {string} attributes.menu Initial mode for the menu region. @todo this needs a better explanation.
  4601. * @param {boolean} [attributes.searchable=false] Whether the library is searchable.
  4602. * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
  4603. * @param {boolean} [attributes.date=true] Whether to show the date filter in the browser's toolbar.
  4604. * @param {boolean} [attributes.describe=true] Whether to offer UI to describe the attachments - e.g. captioning images in a gallery.
  4605. * @param {boolean} [attributes.dragInfo=true] Whether to show instructional text about the attachments being sortable.
  4606. * @param {boolean} [attributes.dragInfoText] Instructional text about the attachments being sortable.
  4607. * @param {int} [attributes.idealColumnWidth=170] The ideal column width in pixels for attachments.
  4608. * @param {boolean} [attributes.editing=false] Whether the gallery is being created, or editing an existing instance.
  4609. * @param {int} [attributes.priority=60] The priority for the state link in the media menu.
  4610. * @param {boolean} [attributes.syncSelection=false] Whether the Attachments selection should be persisted from the last state.
  4611. * Defaults to false for this state, because the library passed in *is* the selection.
  4612. * @param {view} [attributes.SettingsView] The view to edit the collection instance settings (e.g. Playlist settings with "Show tracklist" checkbox).
  4613. * @param {view} [attributes.AttachmentView] The single `Attachment` view to be used in the `Attachments`.
  4614. * If none supplied, defaults to wp.media.view.Attachment.EditLibrary.
  4615. * @param {string} attributes.type The collection's media type. (e.g. 'video').
  4616. * @param {string} attributes.collectionType The collection type. (e.g. 'playlist').
  4617. */
  4618. CollectionEdit = Library.extend(/** @lends wp.media.controller.CollectionEdit.prototype */{
  4619. defaults: {
  4620. multiple: false,
  4621. sortable: true,
  4622. date: false,
  4623. searchable: false,
  4624. content: 'browse',
  4625. describe: true,
  4626. dragInfo: true,
  4627. idealColumnWidth: 170,
  4628. editing: false,
  4629. priority: 60,
  4630. SettingsView: false,
  4631. syncSelection: false
  4632. },
  4633. /**
  4634. * @since 3.9.0
  4635. */
  4636. initialize: function() {
  4637. var collectionType = this.get('collectionType');
  4638. if ( 'video' === this.get( 'type' ) ) {
  4639. collectionType = 'video-' + collectionType;
  4640. }
  4641. this.set( 'id', collectionType + '-edit' );
  4642. this.set( 'toolbar', collectionType + '-edit' );
  4643. // If we haven't been provided a `library`, create a `Selection`.
  4644. if ( ! this.get('library') ) {
  4645. this.set( 'library', new wp.media.model.Selection() );
  4646. }
  4647. // The single `Attachment` view to be used in the `Attachments` view.
  4648. if ( ! this.get('AttachmentView') ) {
  4649. this.set( 'AttachmentView', wp.media.view.Attachment.EditLibrary );
  4650. }
  4651. Library.prototype.initialize.apply( this, arguments );
  4652. },
  4653. /**
  4654. * @since 3.9.0
  4655. */
  4656. activate: function() {
  4657. var library = this.get('library');
  4658. // Limit the library to images only.
  4659. library.props.set( 'type', this.get( 'type' ) );
  4660. // Watch for uploaded attachments.
  4661. this.get('library').observe( wp.Uploader.queue );
  4662. this.frame.on( 'content:render:browse', this.renderSettings, this );
  4663. Library.prototype.activate.apply( this, arguments );
  4664. },
  4665. /**
  4666. * @since 3.9.0
  4667. */
  4668. deactivate: function() {
  4669. // Stop watching for uploaded attachments.
  4670. this.get('library').unobserve( wp.Uploader.queue );
  4671. this.frame.off( 'content:render:browse', this.renderSettings, this );
  4672. Library.prototype.deactivate.apply( this, arguments );
  4673. },
  4674. /**
  4675. * Render the collection embed settings view in the browser sidebar.
  4676. *
  4677. * @todo This is against the pattern elsewhere in media. Typically the frame
  4678. * is responsible for adding region mode callbacks. Explain.
  4679. *
  4680. * @since 3.9.0
  4681. *
  4682. * @param {wp.media.view.attachmentsBrowser} The attachments browser view.
  4683. */
  4684. renderSettings: function( attachmentsBrowserView ) {
  4685. var library = this.get('library'),
  4686. collectionType = this.get('collectionType'),
  4687. dragInfoText = this.get('dragInfoText'),
  4688. SettingsView = this.get('SettingsView'),
  4689. obj = {};
  4690. if ( ! library || ! attachmentsBrowserView ) {
  4691. return;
  4692. }
  4693. library[ collectionType ] = library[ collectionType ] || new Backbone.Model();
  4694. obj[ collectionType ] = new SettingsView({
  4695. controller: this,
  4696. model: library[ collectionType ],
  4697. priority: 40
  4698. });
  4699. attachmentsBrowserView.sidebar.set( obj );
  4700. if ( dragInfoText ) {
  4701. attachmentsBrowserView.toolbar.set( 'dragInfo', new wp.media.View({
  4702. el: $( '<div class="instructions">' + dragInfoText + '</div>' )[0],
  4703. priority: -40
  4704. }) );
  4705. }
  4706. // Add the 'Reverse order' button to the toolbar.
  4707. attachmentsBrowserView.toolbar.set( 'reverse', {
  4708. text: l10n.reverseOrder,
  4709. priority: 80,
  4710. click: function() {
  4711. library.reset( library.toArray().reverse() );
  4712. }
  4713. });
  4714. }
  4715. });
  4716. module.exports = CollectionEdit;
  4717. /***/ }),
  4718. /***/ "NguE":
  4719. /***/ (function(module, exports) {
  4720. var View = wp.media.View,
  4721. UploaderStatus;
  4722. /**
  4723. * wp.media.view.UploaderStatus
  4724. *
  4725. * An uploader status for on-going uploads.
  4726. *
  4727. * @memberOf wp.media.view
  4728. *
  4729. * @class
  4730. * @augments wp.media.View
  4731. * @augments wp.Backbone.View
  4732. * @augments Backbone.View
  4733. */
  4734. UploaderStatus = View.extend(/** @lends wp.media.view.UploaderStatus.prototype */{
  4735. className: 'media-uploader-status',
  4736. template: wp.template('uploader-status'),
  4737. events: {
  4738. 'click .upload-dismiss-errors': 'dismiss'
  4739. },
  4740. initialize: function() {
  4741. this.queue = wp.Uploader.queue;
  4742. this.queue.on( 'add remove reset', this.visibility, this );
  4743. this.queue.on( 'add remove reset change:percent', this.progress, this );
  4744. this.queue.on( 'add remove reset change:uploading', this.info, this );
  4745. this.errors = wp.Uploader.errors;
  4746. this.errors.reset();
  4747. this.errors.on( 'add remove reset', this.visibility, this );
  4748. this.errors.on( 'add', this.error, this );
  4749. },
  4750. /**
  4751. * @return {wp.media.view.UploaderStatus}
  4752. */
  4753. dispose: function() {
  4754. wp.Uploader.queue.off( null, null, this );
  4755. /**
  4756. * call 'dispose' directly on the parent class
  4757. */
  4758. View.prototype.dispose.apply( this, arguments );
  4759. return this;
  4760. },
  4761. visibility: function() {
  4762. this.$el.toggleClass( 'uploading', !! this.queue.length );
  4763. this.$el.toggleClass( 'errors', !! this.errors.length );
  4764. this.$el.toggle( !! this.queue.length || !! this.errors.length );
  4765. },
  4766. ready: function() {
  4767. _.each({
  4768. '$bar': '.media-progress-bar div',
  4769. '$index': '.upload-index',
  4770. '$total': '.upload-total',
  4771. '$filename': '.upload-filename'
  4772. }, function( selector, key ) {
  4773. this[ key ] = this.$( selector );
  4774. }, this );
  4775. this.visibility();
  4776. this.progress();
  4777. this.info();
  4778. },
  4779. progress: function() {
  4780. var queue = this.queue,
  4781. $bar = this.$bar;
  4782. if ( ! $bar || ! queue.length ) {
  4783. return;
  4784. }
  4785. $bar.width( ( queue.reduce( function( memo, attachment ) {
  4786. if ( ! attachment.get('uploading') ) {
  4787. return memo + 100;
  4788. }
  4789. var percent = attachment.get('percent');
  4790. return memo + ( _.isNumber( percent ) ? percent : 100 );
  4791. }, 0 ) / queue.length ) + '%' );
  4792. },
  4793. info: function() {
  4794. var queue = this.queue,
  4795. index = 0, active;
  4796. if ( ! queue.length ) {
  4797. return;
  4798. }
  4799. active = this.queue.find( function( attachment, i ) {
  4800. index = i;
  4801. return attachment.get('uploading');
  4802. });
  4803. if ( this.$index && this.$total && this.$filename ) {
  4804. this.$index.text( index + 1 );
  4805. this.$total.text( queue.length );
  4806. this.$filename.html( active ? this.filename( active.get('filename') ) : '' );
  4807. }
  4808. },
  4809. /**
  4810. * @param {string} filename
  4811. * @return {string}
  4812. */
  4813. filename: function( filename ) {
  4814. return _.escape( filename );
  4815. },
  4816. /**
  4817. * @param {Backbone.Model} error
  4818. */
  4819. error: function( error ) {
  4820. var statusError = new wp.media.view.UploaderStatusError( {
  4821. filename: this.filename( error.get( 'file' ).name ),
  4822. message: error.get( 'message' )
  4823. } );
  4824. var buttonClose = this.$el.find( 'button' );
  4825. // Can show additional info here while retrying to create image sub-sizes.
  4826. this.views.add( '.upload-errors', statusError, { at: 0 } );
  4827. _.delay( function() {
  4828. buttonClose.trigger( 'focus' );
  4829. wp.a11y.speak( error.get( 'message' ), 'assertive' );
  4830. }, 1000 );
  4831. },
  4832. dismiss: function() {
  4833. var errors = this.views.get('.upload-errors');
  4834. if ( errors ) {
  4835. _.invoke( errors, 'remove' );
  4836. }
  4837. wp.Uploader.errors.reset();
  4838. // Move focus to the modal after the dismiss button gets removed from the DOM.
  4839. if ( this.controller.modal ) {
  4840. this.controller.modal.focusManager.focus();
  4841. }
  4842. }
  4843. });
  4844. module.exports = UploaderStatus;
  4845. /***/ }),
  4846. /***/ "NjyZ":
  4847. /***/ (function(module, exports) {
  4848. /**
  4849. * wp.media.view.PriorityList
  4850. *
  4851. * @memberOf wp.media.view
  4852. *
  4853. * @class
  4854. * @augments wp.media.View
  4855. * @augments wp.Backbone.View
  4856. * @augments Backbone.View
  4857. */
  4858. var PriorityList = wp.media.View.extend(/** @lends wp.media.view.PriorityList.prototype */{
  4859. tagName: 'div',
  4860. initialize: function() {
  4861. this._views = {};
  4862. this.set( _.extend( {}, this._views, this.options.views ), { silent: true });
  4863. delete this.options.views;
  4864. if ( ! this.options.silent ) {
  4865. this.render();
  4866. }
  4867. },
  4868. /**
  4869. * @param {string} id
  4870. * @param {wp.media.View|Object} view
  4871. * @param {Object} options
  4872. * @return {wp.media.view.PriorityList} Returns itself to allow chaining.
  4873. */
  4874. set: function( id, view, options ) {
  4875. var priority, views, index;
  4876. options = options || {};
  4877. // Accept an object with an `id` : `view` mapping.
  4878. if ( _.isObject( id ) ) {
  4879. _.each( id, function( view, id ) {
  4880. this.set( id, view );
  4881. }, this );
  4882. return this;
  4883. }
  4884. if ( ! (view instanceof Backbone.View) ) {
  4885. view = this.toView( view, id, options );
  4886. }
  4887. view.controller = view.controller || this.controller;
  4888. this.unset( id );
  4889. priority = view.options.priority || 10;
  4890. views = this.views.get() || [];
  4891. _.find( views, function( existing, i ) {
  4892. if ( existing.options.priority > priority ) {
  4893. index = i;
  4894. return true;
  4895. }
  4896. });
  4897. this._views[ id ] = view;
  4898. this.views.add( view, {
  4899. at: _.isNumber( index ) ? index : views.length || 0
  4900. });
  4901. return this;
  4902. },
  4903. /**
  4904. * @param {string} id
  4905. * @return {wp.media.View}
  4906. */
  4907. get: function( id ) {
  4908. return this._views[ id ];
  4909. },
  4910. /**
  4911. * @param {string} id
  4912. * @return {wp.media.view.PriorityList}
  4913. */
  4914. unset: function( id ) {
  4915. var view = this.get( id );
  4916. if ( view ) {
  4917. view.remove();
  4918. }
  4919. delete this._views[ id ];
  4920. return this;
  4921. },
  4922. /**
  4923. * @param {Object} options
  4924. * @return {wp.media.View}
  4925. */
  4926. toView: function( options ) {
  4927. return new wp.media.View( options );
  4928. }
  4929. });
  4930. module.exports = PriorityList;
  4931. /***/ }),
  4932. /***/ "P6DV":
  4933. /***/ (function(module, exports) {
  4934. /**
  4935. * wp.media.view.Attachment.EditSelection
  4936. *
  4937. * @memberOf wp.media.view.Attachment
  4938. *
  4939. * @class
  4940. * @augments wp.media.view.Attachment.Selection
  4941. * @augments wp.media.view.Attachment
  4942. * @augments wp.media.View
  4943. * @augments wp.Backbone.View
  4944. * @augments Backbone.View
  4945. */
  4946. var EditSelection = wp.media.view.Attachment.Selection.extend(/** @lends wp.media.view.Attachment.EditSelection.prototype */{
  4947. buttons: {
  4948. close: true
  4949. }
  4950. });
  4951. module.exports = EditSelection;
  4952. /***/ }),
  4953. /***/ "PgTd":
  4954. /***/ (function(module, exports) {
  4955. /**
  4956. * wp.media.selectionSync
  4957. *
  4958. * Sync an attachments selection in a state with another state.
  4959. *
  4960. * Allows for selecting multiple images in the Add Media workflow, and then
  4961. * switching to the Insert Gallery workflow while preserving the attachments selection.
  4962. *
  4963. * @memberOf wp.media
  4964. *
  4965. * @mixin
  4966. */
  4967. var selectionSync = {
  4968. /**
  4969. * @since 3.5.0
  4970. */
  4971. syncSelection: function() {
  4972. var selection = this.get('selection'),
  4973. manager = this.frame._selection;
  4974. if ( ! this.get('syncSelection') || ! manager || ! selection ) {
  4975. return;
  4976. }
  4977. /*
  4978. * If the selection supports multiple items, validate the stored
  4979. * attachments based on the new selection's conditions. Record
  4980. * the attachments that are not included; we'll maintain a
  4981. * reference to those. Other attachments are considered in flux.
  4982. */
  4983. if ( selection.multiple ) {
  4984. selection.reset( [], { silent: true });
  4985. selection.validateAll( manager.attachments );
  4986. manager.difference = _.difference( manager.attachments.models, selection.models );
  4987. }
  4988. // Sync the selection's single item with the master.
  4989. selection.single( manager.single );
  4990. },
  4991. /**
  4992. * Record the currently active attachments, which is a combination
  4993. * of the selection's attachments and the set of selected
  4994. * attachments that this specific selection considered invalid.
  4995. * Reset the difference and record the single attachment.
  4996. *
  4997. * @since 3.5.0
  4998. */
  4999. recordSelection: function() {
  5000. var selection = this.get('selection'),
  5001. manager = this.frame._selection;
  5002. if ( ! this.get('syncSelection') || ! manager || ! selection ) {
  5003. return;
  5004. }
  5005. if ( selection.multiple ) {
  5006. manager.attachments.reset( selection.toArray().concat( manager.difference ) );
  5007. manager.difference = [];
  5008. } else {
  5009. manager.attachments.add( selection.toArray() );
  5010. }
  5011. manager.single = selection._single;
  5012. }
  5013. };
  5014. module.exports = selectionSync;
  5015. /***/ }),
  5016. /***/ "Pt9x":
  5017. /***/ (function(module, exports) {
  5018. var Frame = wp.media.view.Frame,
  5019. l10n = wp.media.view.l10n,
  5020. $ = jQuery,
  5021. MediaFrame;
  5022. /**
  5023. * wp.media.view.MediaFrame
  5024. *
  5025. * The frame used to create the media modal.
  5026. *
  5027. * @memberOf wp.media.view
  5028. *
  5029. * @class
  5030. * @augments wp.media.view.Frame
  5031. * @augments wp.media.View
  5032. * @augments wp.Backbone.View
  5033. * @augments Backbone.View
  5034. * @mixes wp.media.controller.StateMachine
  5035. */
  5036. MediaFrame = Frame.extend(/** @lends wp.media.view.MediaFrame.prototype */{
  5037. className: 'media-frame',
  5038. template: wp.template('media-frame'),
  5039. regions: ['menu','title','content','toolbar','router'],
  5040. events: {
  5041. 'click .media-frame-menu-toggle': 'toggleMenu'
  5042. },
  5043. /**
  5044. * @constructs
  5045. */
  5046. initialize: function() {
  5047. Frame.prototype.initialize.apply( this, arguments );
  5048. _.defaults( this.options, {
  5049. title: l10n.mediaFrameDefaultTitle,
  5050. modal: true,
  5051. uploader: true
  5052. });
  5053. // Ensure core UI is enabled.
  5054. this.$el.addClass('wp-core-ui');
  5055. // Initialize modal container view.
  5056. if ( this.options.modal ) {
  5057. this.modal = new wp.media.view.Modal({
  5058. controller: this,
  5059. title: this.options.title
  5060. });
  5061. this.modal.content( this );
  5062. }
  5063. // Force the uploader off if the upload limit has been exceeded or
  5064. // if the browser isn't supported.
  5065. if ( wp.Uploader.limitExceeded || ! wp.Uploader.browser.supported ) {
  5066. this.options.uploader = false;
  5067. }
  5068. // Initialize window-wide uploader.
  5069. if ( this.options.uploader ) {
  5070. this.uploader = new wp.media.view.UploaderWindow({
  5071. controller: this,
  5072. uploader: {
  5073. dropzone: this.modal ? this.modal.$el : this.$el,
  5074. container: this.$el
  5075. }
  5076. });
  5077. this.views.set( '.media-frame-uploader', this.uploader );
  5078. }
  5079. this.on( 'attach', _.bind( this.views.ready, this.views ), this );
  5080. // Bind default title creation.
  5081. this.on( 'title:create:default', this.createTitle, this );
  5082. this.title.mode('default');
  5083. // Bind default menu.
  5084. this.on( 'menu:create:default', this.createMenu, this );
  5085. // Set the menu ARIA tab panel attributes when the modal opens.
  5086. this.on( 'open', this.setMenuTabPanelAriaAttributes, this );
  5087. // Set the router ARIA tab panel attributes when the modal opens.
  5088. this.on( 'open', this.setRouterTabPanelAriaAttributes, this );
  5089. // Update the menu ARIA tab panel attributes when the content updates.
  5090. this.on( 'content:render', this.setMenuTabPanelAriaAttributes, this );
  5091. // Update the router ARIA tab panel attributes when the content updates.
  5092. this.on( 'content:render', this.setRouterTabPanelAriaAttributes, this );
  5093. },
  5094. /**
  5095. * Sets the attributes to be used on the menu ARIA tab panel.
  5096. *
  5097. * @since 5.3.0
  5098. *
  5099. * @return {void}
  5100. */
  5101. setMenuTabPanelAriaAttributes: function() {
  5102. var stateId = this.state().get( 'id' ),
  5103. tabPanelEl = this.$el.find( '.media-frame-tab-panel' ),
  5104. ariaLabelledby;
  5105. tabPanelEl.removeAttr( 'role aria-labelledby tabindex' );
  5106. if ( this.state().get( 'menu' ) && this.menuView && this.menuView.isVisible ) {
  5107. ariaLabelledby = 'menu-item-' + stateId;
  5108. // Set the tab panel attributes only if the tabs are visible.
  5109. tabPanelEl
  5110. .attr( {
  5111. role: 'tabpanel',
  5112. 'aria-labelledby': ariaLabelledby,
  5113. tabIndex: '0'
  5114. } );
  5115. }
  5116. },
  5117. /**
  5118. * Sets the attributes to be used on the router ARIA tab panel.
  5119. *
  5120. * @since 5.3.0
  5121. *
  5122. * @return {void}
  5123. */
  5124. setRouterTabPanelAriaAttributes: function() {
  5125. var tabPanelEl = this.$el.find( '.media-frame-content' ),
  5126. ariaLabelledby;
  5127. tabPanelEl.removeAttr( 'role aria-labelledby tabindex' );
  5128. // Set the tab panel attributes only if the tabs are visible.
  5129. if ( this.state().get( 'router' ) && this.routerView && this.routerView.isVisible && this.content._mode ) {
  5130. ariaLabelledby = 'menu-item-' + this.content._mode;
  5131. tabPanelEl
  5132. .attr( {
  5133. role: 'tabpanel',
  5134. 'aria-labelledby': ariaLabelledby,
  5135. tabIndex: '0'
  5136. } );
  5137. }
  5138. },
  5139. /**
  5140. * @return {wp.media.view.MediaFrame} Returns itself to allow chaining.
  5141. */
  5142. render: function() {
  5143. // Activate the default state if no active state exists.
  5144. if ( ! this.state() && this.options.state ) {
  5145. this.setState( this.options.state );
  5146. }
  5147. /**
  5148. * call 'render' directly on the parent class
  5149. */
  5150. return Frame.prototype.render.apply( this, arguments );
  5151. },
  5152. /**
  5153. * @param {Object} title
  5154. * @this wp.media.controller.Region
  5155. */
  5156. createTitle: function( title ) {
  5157. title.view = new wp.media.View({
  5158. controller: this,
  5159. tagName: 'h1'
  5160. });
  5161. },
  5162. /**
  5163. * @param {Object} menu
  5164. * @this wp.media.controller.Region
  5165. */
  5166. createMenu: function( menu ) {
  5167. menu.view = new wp.media.view.Menu({
  5168. controller: this,
  5169. attributes: {
  5170. role: 'tablist',
  5171. 'aria-orientation': 'vertical'
  5172. }
  5173. });
  5174. this.menuView = menu.view;
  5175. },
  5176. toggleMenu: function( event ) {
  5177. var menu = this.$el.find( '.media-menu' );
  5178. menu.toggleClass( 'visible' );
  5179. $( event.target ).attr( 'aria-expanded', menu.hasClass( 'visible' ) );
  5180. },
  5181. /**
  5182. * @param {Object} toolbar
  5183. * @this wp.media.controller.Region
  5184. */
  5185. createToolbar: function( toolbar ) {
  5186. toolbar.view = new wp.media.view.Toolbar({
  5187. controller: this
  5188. });
  5189. },
  5190. /**
  5191. * @param {Object} router
  5192. * @this wp.media.controller.Region
  5193. */
  5194. createRouter: function( router ) {
  5195. router.view = new wp.media.view.Router({
  5196. controller: this,
  5197. attributes: {
  5198. role: 'tablist',
  5199. 'aria-orientation': 'horizontal'
  5200. }
  5201. });
  5202. this.routerView = router.view;
  5203. },
  5204. /**
  5205. * @param {Object} options
  5206. */
  5207. createIframeStates: function( options ) {
  5208. var settings = wp.media.view.settings,
  5209. tabs = settings.tabs,
  5210. tabUrl = settings.tabUrl,
  5211. $postId;
  5212. if ( ! tabs || ! tabUrl ) {
  5213. return;
  5214. }
  5215. // Add the post ID to the tab URL if it exists.
  5216. $postId = $('#post_ID');
  5217. if ( $postId.length ) {
  5218. tabUrl += '&post_id=' + $postId.val();
  5219. }
  5220. // Generate the tab states.
  5221. _.each( tabs, function( title, id ) {
  5222. this.state( 'iframe:' + id ).set( _.defaults({
  5223. tab: id,
  5224. src: tabUrl + '&tab=' + id,
  5225. title: title,
  5226. content: 'iframe',
  5227. menu: 'default'
  5228. }, options ) );
  5229. }, this );
  5230. this.on( 'content:create:iframe', this.iframeContent, this );
  5231. this.on( 'content:deactivate:iframe', this.iframeContentCleanup, this );
  5232. this.on( 'menu:render:default', this.iframeMenu, this );
  5233. this.on( 'open', this.hijackThickbox, this );
  5234. this.on( 'close', this.restoreThickbox, this );
  5235. },
  5236. /**
  5237. * @param {Object} content
  5238. * @this wp.media.controller.Region
  5239. */
  5240. iframeContent: function( content ) {
  5241. this.$el.addClass('hide-toolbar');
  5242. content.view = new wp.media.view.Iframe({
  5243. controller: this
  5244. });
  5245. },
  5246. iframeContentCleanup: function() {
  5247. this.$el.removeClass('hide-toolbar');
  5248. },
  5249. iframeMenu: function( view ) {
  5250. var views = {};
  5251. if ( ! view ) {
  5252. return;
  5253. }
  5254. _.each( wp.media.view.settings.tabs, function( title, id ) {
  5255. views[ 'iframe:' + id ] = {
  5256. text: this.state( 'iframe:' + id ).get('title'),
  5257. priority: 200
  5258. };
  5259. }, this );
  5260. view.set( views );
  5261. },
  5262. hijackThickbox: function() {
  5263. var frame = this;
  5264. if ( ! window.tb_remove || this._tb_remove ) {
  5265. return;
  5266. }
  5267. this._tb_remove = window.tb_remove;
  5268. window.tb_remove = function() {
  5269. frame.close();
  5270. frame.reset();
  5271. frame.setState( frame.options.state );
  5272. frame._tb_remove.call( window );
  5273. };
  5274. },
  5275. restoreThickbox: function() {
  5276. if ( ! this._tb_remove ) {
  5277. return;
  5278. }
  5279. window.tb_remove = this._tb_remove;
  5280. delete this._tb_remove;
  5281. }
  5282. });
  5283. // Map some of the modal's methods to the frame.
  5284. _.each(['open','close','attach','detach','escape'], function( method ) {
  5285. /**
  5286. * @function open
  5287. * @memberOf wp.media.view.MediaFrame
  5288. * @instance
  5289. *
  5290. * @return {wp.media.view.MediaFrame} Returns itself to allow chaining.
  5291. */
  5292. /**
  5293. * @function close
  5294. * @memberOf wp.media.view.MediaFrame
  5295. * @instance
  5296. *
  5297. * @return {wp.media.view.MediaFrame} Returns itself to allow chaining.
  5298. */
  5299. /**
  5300. * @function attach
  5301. * @memberOf wp.media.view.MediaFrame
  5302. * @instance
  5303. *
  5304. * @return {wp.media.view.MediaFrame} Returns itself to allow chaining.
  5305. */
  5306. /**
  5307. * @function detach
  5308. * @memberOf wp.media.view.MediaFrame
  5309. * @instance
  5310. *
  5311. * @return {wp.media.view.MediaFrame} Returns itself to allow chaining.
  5312. */
  5313. /**
  5314. * @function escape
  5315. * @memberOf wp.media.view.MediaFrame
  5316. * @instance
  5317. *
  5318. * @return {wp.media.view.MediaFrame} Returns itself to allow chaining.
  5319. */
  5320. MediaFrame.prototype[ method ] = function() {
  5321. if ( this.modal ) {
  5322. this.modal[ method ].apply( this.modal, arguments );
  5323. }
  5324. return this;
  5325. };
  5326. });
  5327. module.exports = MediaFrame;
  5328. /***/ }),
  5329. /***/ "Q9T/":
  5330. /***/ (function(module, exports) {
  5331. /**
  5332. * wp.media.view.RouterItem
  5333. *
  5334. * @memberOf wp.media.view
  5335. *
  5336. * @class
  5337. * @augments wp.media.view.MenuItem
  5338. * @augments wp.media.View
  5339. * @augments wp.Backbone.View
  5340. * @augments Backbone.View
  5341. */
  5342. var RouterItem = wp.media.view.MenuItem.extend(/** @lends wp.media.view.RouterItem.prototype */{
  5343. /**
  5344. * On click handler to activate the content region's corresponding mode.
  5345. */
  5346. click: function() {
  5347. var contentMode = this.options.contentMode;
  5348. if ( contentMode ) {
  5349. this.controller.content.mode( contentMode );
  5350. }
  5351. }
  5352. });
  5353. module.exports = RouterItem;
  5354. /***/ }),
  5355. /***/ "S4jH":
  5356. /***/ (function(module, exports) {
  5357. var $ = jQuery,
  5358. UploaderWindow;
  5359. /**
  5360. * wp.media.view.UploaderWindow
  5361. *
  5362. * An uploader window that allows for dragging and dropping media.
  5363. *
  5364. * @memberOf wp.media.view
  5365. *
  5366. * @class
  5367. * @augments wp.media.View
  5368. * @augments wp.Backbone.View
  5369. * @augments Backbone.View
  5370. *
  5371. * @param {object} [options] Options hash passed to the view.
  5372. * @param {object} [options.uploader] Uploader properties.
  5373. * @param {jQuery} [options.uploader.browser]
  5374. * @param {jQuery} [options.uploader.dropzone] jQuery collection of the dropzone.
  5375. * @param {object} [options.uploader.params]
  5376. */
  5377. UploaderWindow = wp.media.View.extend(/** @lends wp.media.view.UploaderWindow.prototype */{
  5378. tagName: 'div',
  5379. className: 'uploader-window',
  5380. template: wp.template('uploader-window'),
  5381. initialize: function() {
  5382. var uploader;
  5383. this.$browser = $( '<button type="button" class="browser" />' ).hide().appendTo( 'body' );
  5384. uploader = this.options.uploader = _.defaults( this.options.uploader || {}, {
  5385. dropzone: this.$el,
  5386. browser: this.$browser,
  5387. params: {}
  5388. });
  5389. // Ensure the dropzone is a jQuery collection.
  5390. if ( uploader.dropzone && ! (uploader.dropzone instanceof $) ) {
  5391. uploader.dropzone = $( uploader.dropzone );
  5392. }
  5393. this.controller.on( 'activate', this.refresh, this );
  5394. this.controller.on( 'detach', function() {
  5395. this.$browser.remove();
  5396. }, this );
  5397. },
  5398. refresh: function() {
  5399. if ( this.uploader ) {
  5400. this.uploader.refresh();
  5401. }
  5402. },
  5403. ready: function() {
  5404. var postId = wp.media.view.settings.post.id,
  5405. dropzone;
  5406. // If the uploader already exists, bail.
  5407. if ( this.uploader ) {
  5408. return;
  5409. }
  5410. if ( postId ) {
  5411. this.options.uploader.params.post_id = postId;
  5412. }
  5413. this.uploader = new wp.Uploader( this.options.uploader );
  5414. dropzone = this.uploader.dropzone;
  5415. dropzone.on( 'dropzone:enter', _.bind( this.show, this ) );
  5416. dropzone.on( 'dropzone:leave', _.bind( this.hide, this ) );
  5417. $( this.uploader ).on( 'uploader:ready', _.bind( this._ready, this ) );
  5418. },
  5419. _ready: function() {
  5420. this.controller.trigger( 'uploader:ready' );
  5421. },
  5422. show: function() {
  5423. var $el = this.$el.show();
  5424. // Ensure that the animation is triggered by waiting until
  5425. // the transparent element is painted into the DOM.
  5426. _.defer( function() {
  5427. $el.css({ opacity: 1 });
  5428. });
  5429. },
  5430. hide: function() {
  5431. var $el = this.$el.css({ opacity: 0 });
  5432. wp.media.transition( $el ).done( function() {
  5433. // Transition end events are subject to race conditions.
  5434. // Make sure that the value is set as intended.
  5435. if ( '0' === $el.css('opacity') ) {
  5436. $el.hide();
  5437. }
  5438. });
  5439. // https://core.trac.wordpress.org/ticket/27341
  5440. _.delay( function() {
  5441. if ( '0' === $el.css('opacity') && $el.is(':visible') ) {
  5442. $el.hide();
  5443. }
  5444. }, 500 );
  5445. }
  5446. });
  5447. module.exports = UploaderWindow;
  5448. /***/ }),
  5449. /***/ "U3Se":
  5450. /***/ (function(module, exports) {
  5451. /**
  5452. * wp.media.controller.StateMachine
  5453. *
  5454. * A state machine keeps track of state. It is in one state at a time,
  5455. * and can change from one state to another.
  5456. *
  5457. * States are stored as models in a Backbone collection.
  5458. *
  5459. * @memberOf wp.media.controller
  5460. *
  5461. * @since 3.5.0
  5462. *
  5463. * @class
  5464. * @augments Backbone.Model
  5465. * @mixin
  5466. * @mixes Backbone.Events
  5467. */
  5468. var StateMachine = function() {
  5469. return {
  5470. // Use Backbone's self-propagating `extend` inheritance method.
  5471. extend: Backbone.Model.extend
  5472. };
  5473. };
  5474. _.extend( StateMachine.prototype, Backbone.Events,/** @lends wp.media.controller.StateMachine.prototype */{
  5475. /**
  5476. * Fetch a state.
  5477. *
  5478. * If no `id` is provided, returns the active state.
  5479. *
  5480. * Implicitly creates states.
  5481. *
  5482. * Ensure that the `states` collection exists so the `StateMachine`
  5483. * can be used as a mixin.
  5484. *
  5485. * @since 3.5.0
  5486. *
  5487. * @param {string} id
  5488. * @return {wp.media.controller.State} Returns a State model from
  5489. * the StateMachine collection.
  5490. */
  5491. state: function( id ) {
  5492. this.states = this.states || new Backbone.Collection();
  5493. // Default to the active state.
  5494. id = id || this._state;
  5495. if ( id && ! this.states.get( id ) ) {
  5496. this.states.add({ id: id });
  5497. }
  5498. return this.states.get( id );
  5499. },
  5500. /**
  5501. * Sets the active state.
  5502. *
  5503. * Bail if we're trying to select the current state, if we haven't
  5504. * created the `states` collection, or are trying to select a state
  5505. * that does not exist.
  5506. *
  5507. * @since 3.5.0
  5508. *
  5509. * @param {string} id
  5510. *
  5511. * @fires wp.media.controller.State#deactivate
  5512. * @fires wp.media.controller.State#activate
  5513. *
  5514. * @return {wp.media.controller.StateMachine} Returns itself to allow chaining.
  5515. */
  5516. setState: function( id ) {
  5517. var previous = this.state();
  5518. if ( ( previous && id === previous.id ) || ! this.states || ! this.states.get( id ) ) {
  5519. return this;
  5520. }
  5521. if ( previous ) {
  5522. previous.trigger('deactivate');
  5523. this._lastState = previous.id;
  5524. }
  5525. this._state = id;
  5526. this.state().trigger('activate');
  5527. return this;
  5528. },
  5529. /**
  5530. * Returns the previous active state.
  5531. *
  5532. * Call the `state()` method with no parameters to retrieve the current
  5533. * active state.
  5534. *
  5535. * @since 3.5.0
  5536. *
  5537. * @return {wp.media.controller.State} Returns a State model from
  5538. * the StateMachine collection.
  5539. */
  5540. lastState: function() {
  5541. if ( this._lastState ) {
  5542. return this.state( this._lastState );
  5543. }
  5544. }
  5545. });
  5546. // Map all event binding and triggering on a StateMachine to its `states` collection.
  5547. _.each([ 'on', 'off', 'trigger' ], function( method ) {
  5548. /**
  5549. * @function on
  5550. * @memberOf wp.media.controller.StateMachine
  5551. * @instance
  5552. * @return {wp.media.controller.StateMachine} Returns itself to allow chaining.
  5553. */
  5554. /**
  5555. * @function off
  5556. * @memberOf wp.media.controller.StateMachine
  5557. * @instance
  5558. * @return {wp.media.controller.StateMachine} Returns itself to allow chaining.
  5559. */
  5560. /**
  5561. * @function trigger
  5562. * @memberOf wp.media.controller.StateMachine
  5563. * @instance
  5564. * @return {wp.media.controller.StateMachine} Returns itself to allow chaining.
  5565. */
  5566. StateMachine.prototype[ method ] = function() {
  5567. // Ensure that the `states` collection exists so the `StateMachine`
  5568. // can be used as a mixin.
  5569. this.states = this.states || new Backbone.Collection();
  5570. // Forward the method to the `states` collection.
  5571. this.states[ method ].apply( this.states, arguments );
  5572. return this;
  5573. };
  5574. });
  5575. module.exports = StateMachine;
  5576. /***/ }),
  5577. /***/ "UmHM":
  5578. /***/ (function(module, exports) {
  5579. var View = wp.media.view,
  5580. SiteIconCropper;
  5581. /**
  5582. * wp.media.view.SiteIconCropper
  5583. *
  5584. * Uses the imgAreaSelect plugin to allow a user to crop a Site Icon.
  5585. *
  5586. * Takes imgAreaSelect options from
  5587. * wp.customize.SiteIconControl.calculateImageSelectOptions.
  5588. *
  5589. * @memberOf wp.media.view
  5590. *
  5591. * @class
  5592. * @augments wp.media.view.Cropper
  5593. * @augments wp.media.View
  5594. * @augments wp.Backbone.View
  5595. * @augments Backbone.View
  5596. */
  5597. SiteIconCropper = View.Cropper.extend(/** @lends wp.media.view.SiteIconCropper.prototype */{
  5598. className: 'crop-content site-icon',
  5599. ready: function () {
  5600. View.Cropper.prototype.ready.apply( this, arguments );
  5601. this.$( '.crop-image' ).on( 'load', _.bind( this.addSidebar, this ) );
  5602. },
  5603. addSidebar: function() {
  5604. this.sidebar = new wp.media.view.Sidebar({
  5605. controller: this.controller
  5606. });
  5607. this.sidebar.set( 'preview', new wp.media.view.SiteIconPreview({
  5608. controller: this.controller,
  5609. attachment: this.options.attachment
  5610. }) );
  5611. this.controller.cropperView.views.add( this.sidebar );
  5612. }
  5613. });
  5614. module.exports = SiteIconCropper;
  5615. /***/ }),
  5616. /***/ "V6sy":
  5617. /***/ (function(module, exports) {
  5618. /**
  5619. * wp.media.view.Label
  5620. *
  5621. * @memberOf wp.media.view
  5622. *
  5623. * @class
  5624. * @augments wp.media.View
  5625. * @augments wp.Backbone.View
  5626. * @augments Backbone.View
  5627. */
  5628. var Label = wp.media.View.extend(/** @lends wp.media.view.Label.prototype */{
  5629. tagName: 'label',
  5630. className: 'screen-reader-text',
  5631. initialize: function() {
  5632. this.value = this.options.value;
  5633. },
  5634. render: function() {
  5635. this.$el.html( this.value );
  5636. return this;
  5637. }
  5638. });
  5639. module.exports = Label;
  5640. /***/ }),
  5641. /***/ "VIJ9":
  5642. /***/ (function(module, exports) {
  5643. var Select = wp.media.view.MediaFrame.Select,
  5644. l10n = wp.media.view.l10n,
  5645. ImageDetails;
  5646. /**
  5647. * wp.media.view.MediaFrame.ImageDetails
  5648. *
  5649. * A media frame for manipulating an image that's already been inserted
  5650. * into a post.
  5651. *
  5652. * @memberOf wp.media.view.MediaFrame
  5653. *
  5654. * @class
  5655. * @augments wp.media.view.MediaFrame.Select
  5656. * @augments wp.media.view.MediaFrame
  5657. * @augments wp.media.view.Frame
  5658. * @augments wp.media.View
  5659. * @augments wp.Backbone.View
  5660. * @augments Backbone.View
  5661. * @mixes wp.media.controller.StateMachine
  5662. */
  5663. ImageDetails = Select.extend(/** @lends wp.media.view.MediaFrame.ImageDetails.prototype */{
  5664. defaults: {
  5665. id: 'image',
  5666. url: '',
  5667. menu: 'image-details',
  5668. content: 'image-details',
  5669. toolbar: 'image-details',
  5670. type: 'link',
  5671. title: l10n.imageDetailsTitle,
  5672. priority: 120
  5673. },
  5674. initialize: function( options ) {
  5675. this.image = new wp.media.model.PostImage( options.metadata );
  5676. this.options.selection = new wp.media.model.Selection( this.image.attachment, { multiple: false } );
  5677. Select.prototype.initialize.apply( this, arguments );
  5678. },
  5679. bindHandlers: function() {
  5680. Select.prototype.bindHandlers.apply( this, arguments );
  5681. this.on( 'menu:create:image-details', this.createMenu, this );
  5682. this.on( 'content:create:image-details', this.imageDetailsContent, this );
  5683. this.on( 'content:render:edit-image', this.editImageContent, this );
  5684. this.on( 'toolbar:render:image-details', this.renderImageDetailsToolbar, this );
  5685. // Override the select toolbar.
  5686. this.on( 'toolbar:render:replace', this.renderReplaceImageToolbar, this );
  5687. },
  5688. createStates: function() {
  5689. this.states.add([
  5690. new wp.media.controller.ImageDetails({
  5691. image: this.image,
  5692. editable: false
  5693. }),
  5694. new wp.media.controller.ReplaceImage({
  5695. id: 'replace-image',
  5696. library: wp.media.query( { type: 'image' } ),
  5697. image: this.image,
  5698. multiple: false,
  5699. title: l10n.imageReplaceTitle,
  5700. toolbar: 'replace',
  5701. priority: 80,
  5702. displaySettings: true
  5703. }),
  5704. new wp.media.controller.EditImage( {
  5705. image: this.image,
  5706. selection: this.options.selection
  5707. } )
  5708. ]);
  5709. },
  5710. imageDetailsContent: function( options ) {
  5711. options.view = new wp.media.view.ImageDetails({
  5712. controller: this,
  5713. model: this.state().image,
  5714. attachment: this.state().image.attachment
  5715. });
  5716. },
  5717. editImageContent: function() {
  5718. var state = this.state(),
  5719. model = state.get('image'),
  5720. view;
  5721. if ( ! model ) {
  5722. return;
  5723. }
  5724. view = new wp.media.view.EditImage( { model: model, controller: this } ).render();
  5725. this.content.set( view );
  5726. // After bringing in the frame, load the actual editor via an Ajax call.
  5727. view.loadEditor();
  5728. },
  5729. renderImageDetailsToolbar: function() {
  5730. this.toolbar.set( new wp.media.view.Toolbar({
  5731. controller: this,
  5732. items: {
  5733. select: {
  5734. style: 'primary',
  5735. text: l10n.update,
  5736. priority: 80,
  5737. click: function() {
  5738. var controller = this.controller,
  5739. state = controller.state();
  5740. controller.close();
  5741. // Not sure if we want to use wp.media.string.image which will create a shortcode or
  5742. // perhaps wp.html.string to at least to build the <img />.
  5743. state.trigger( 'update', controller.image.toJSON() );
  5744. // Restore and reset the default state.
  5745. controller.setState( controller.options.state );
  5746. controller.reset();
  5747. }
  5748. }
  5749. }
  5750. }) );
  5751. },
  5752. renderReplaceImageToolbar: function() {
  5753. var frame = this,
  5754. lastState = frame.lastState(),
  5755. previous = lastState && lastState.id;
  5756. this.toolbar.set( new wp.media.view.Toolbar({
  5757. controller: this,
  5758. items: {
  5759. back: {
  5760. text: l10n.back,
  5761. priority: 80,
  5762. click: function() {
  5763. if ( previous ) {
  5764. frame.setState( previous );
  5765. } else {
  5766. frame.close();
  5767. }
  5768. }
  5769. },
  5770. replace: {
  5771. style: 'primary',
  5772. text: l10n.replace,
  5773. priority: 20,
  5774. requires: { selection: true },
  5775. click: function() {
  5776. var controller = this.controller,
  5777. state = controller.state(),
  5778. selection = state.get( 'selection' ),
  5779. attachment = selection.single();
  5780. controller.close();
  5781. controller.image.changeAttachment( attachment, state.display( attachment ) );
  5782. // Not sure if we want to use wp.media.string.image which will create a shortcode or
  5783. // perhaps wp.html.string to at least to build the <img />.
  5784. state.trigger( 'replace', controller.image.toJSON() );
  5785. // Restore and reset the default state.
  5786. controller.setState( controller.options.state );
  5787. controller.reset();
  5788. }
  5789. }
  5790. }
  5791. }) );
  5792. }
  5793. });
  5794. module.exports = ImageDetails;
  5795. /***/ }),
  5796. /***/ "VMHs":
  5797. /***/ (function(module, exports) {
  5798. /**
  5799. * wp.media.view.Embed
  5800. *
  5801. * @memberOf wp.media.view
  5802. *
  5803. * @class
  5804. * @augments wp.media.View
  5805. * @augments wp.Backbone.View
  5806. * @augments Backbone.View
  5807. */
  5808. var Embed = wp.media.View.extend(/** @lends wp.media.view.Ember.prototype */{
  5809. className: 'media-embed',
  5810. initialize: function() {
  5811. /**
  5812. * @member {wp.media.view.EmbedUrl}
  5813. */
  5814. this.url = new wp.media.view.EmbedUrl({
  5815. controller: this.controller,
  5816. model: this.model.props
  5817. }).render();
  5818. this.views.set([ this.url ]);
  5819. this.refresh();
  5820. this.listenTo( this.model, 'change:type', this.refresh );
  5821. this.listenTo( this.model, 'change:loading', this.loading );
  5822. },
  5823. /**
  5824. * @param {Object} view
  5825. */
  5826. settings: function( view ) {
  5827. if ( this._settings ) {
  5828. this._settings.remove();
  5829. }
  5830. this._settings = view;
  5831. this.views.add( view );
  5832. },
  5833. refresh: function() {
  5834. var type = this.model.get('type'),
  5835. constructor;
  5836. if ( 'image' === type ) {
  5837. constructor = wp.media.view.EmbedImage;
  5838. } else if ( 'link' === type ) {
  5839. constructor = wp.media.view.EmbedLink;
  5840. } else {
  5841. return;
  5842. }
  5843. this.settings( new constructor({
  5844. controller: this.controller,
  5845. model: this.model.props,
  5846. priority: 40
  5847. }) );
  5848. },
  5849. loading: function() {
  5850. this.$el.toggleClass( 'embed-loading', this.model.get('loading') );
  5851. }
  5852. });
  5853. module.exports = Embed;
  5854. /***/ }),
  5855. /***/ "Vh02":
  5856. /***/ (function(module, exports) {
  5857. var View = wp.media.View,
  5858. UploaderStatus = wp.media.view.UploaderStatus,
  5859. l10n = wp.media.view.l10n,
  5860. $ = jQuery,
  5861. Cropper;
  5862. /**
  5863. * wp.media.view.Cropper
  5864. *
  5865. * Uses the imgAreaSelect plugin to allow a user to crop an image.
  5866. *
  5867. * Takes imgAreaSelect options from
  5868. * wp.customize.HeaderControl.calculateImageSelectOptions via
  5869. * wp.customize.HeaderControl.openMM.
  5870. *
  5871. * @memberOf wp.media.view
  5872. *
  5873. * @class
  5874. * @augments wp.media.View
  5875. * @augments wp.Backbone.View
  5876. * @augments Backbone.View
  5877. */
  5878. Cropper = View.extend(/** @lends wp.media.view.Cropper.prototype */{
  5879. className: 'crop-content',
  5880. template: wp.template('crop-content'),
  5881. initialize: function() {
  5882. _.bindAll(this, 'onImageLoad');
  5883. },
  5884. ready: function() {
  5885. this.controller.frame.on('content:error:crop', this.onError, this);
  5886. this.$image = this.$el.find('.crop-image');
  5887. this.$image.on('load', this.onImageLoad);
  5888. $(window).on('resize.cropper', _.debounce(this.onImageLoad, 250));
  5889. },
  5890. remove: function() {
  5891. $(window).off('resize.cropper');
  5892. this.$el.remove();
  5893. this.$el.off();
  5894. View.prototype.remove.apply(this, arguments);
  5895. },
  5896. prepare: function() {
  5897. return {
  5898. title: l10n.cropYourImage,
  5899. url: this.options.attachment.get('url')
  5900. };
  5901. },
  5902. onImageLoad: function() {
  5903. var imgOptions = this.controller.get('imgSelectOptions'),
  5904. imgSelect;
  5905. if (typeof imgOptions === 'function') {
  5906. imgOptions = imgOptions(this.options.attachment, this.controller);
  5907. }
  5908. imgOptions = _.extend(imgOptions, {
  5909. parent: this.$el,
  5910. onInit: function() {
  5911. // Store the set ratio.
  5912. var setRatio = imgSelect.getOptions().aspectRatio;
  5913. // On mousedown, if no ratio is set and the Shift key is down, use a 1:1 ratio.
  5914. this.parent.children().on( 'mousedown touchstart', function( e ) {
  5915. // If no ratio is set and the shift key is down, use a 1:1 ratio.
  5916. if ( ! setRatio && e.shiftKey ) {
  5917. imgSelect.setOptions( {
  5918. aspectRatio: '1:1'
  5919. } );
  5920. }
  5921. } );
  5922. this.parent.children().on( 'mouseup touchend', function() {
  5923. // Restore the set ratio.
  5924. imgSelect.setOptions( {
  5925. aspectRatio: setRatio ? setRatio : false
  5926. } );
  5927. } );
  5928. }
  5929. } );
  5930. this.trigger('image-loaded');
  5931. imgSelect = this.controller.imgSelect = this.$image.imgAreaSelect(imgOptions);
  5932. },
  5933. onError: function() {
  5934. var filename = this.options.attachment.get('filename');
  5935. this.views.add( '.upload-errors', new wp.media.view.UploaderStatusError({
  5936. filename: UploaderStatus.prototype.filename(filename),
  5937. message: window._wpMediaViewsL10n.cropError
  5938. }), { at: 0 });
  5939. }
  5940. });
  5941. module.exports = Cropper;
  5942. /***/ }),
  5943. /***/ "VkcK":
  5944. /***/ (function(module, exports) {
  5945. var l10n = wp.media.view.l10n,
  5946. DateFilter;
  5947. /**
  5948. * A filter dropdown for month/dates.
  5949. *
  5950. * @memberOf wp.media.view.AttachmentFilters
  5951. *
  5952. * @class
  5953. * @augments wp.media.view.AttachmentFilters
  5954. * @augments wp.media.View
  5955. * @augments wp.Backbone.View
  5956. * @augments Backbone.View
  5957. */
  5958. DateFilter = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.AttachmentFilters.Date.prototype */{
  5959. id: 'media-attachment-date-filters',
  5960. createFilters: function() {
  5961. var filters = {};
  5962. _.each( wp.media.view.settings.months || {}, function( value, index ) {
  5963. filters[ index ] = {
  5964. text: value.text,
  5965. props: {
  5966. year: value.year,
  5967. monthnum: value.month
  5968. }
  5969. };
  5970. });
  5971. filters.all = {
  5972. text: l10n.allDates,
  5973. props: {
  5974. monthnum: false,
  5975. year: false
  5976. },
  5977. priority: 10
  5978. };
  5979. this.filters = filters;
  5980. }
  5981. });
  5982. module.exports = DateFilter;
  5983. /***/ }),
  5984. /***/ "W+32":
  5985. /***/ (function(module, exports) {
  5986. var Controller = wp.media.controller,
  5987. SiteIconCropper;
  5988. /**
  5989. * wp.media.controller.SiteIconCropper
  5990. *
  5991. * A state for cropping a Site Icon.
  5992. *
  5993. * @memberOf wp.media.controller
  5994. *
  5995. * @class
  5996. * @augments wp.media.controller.Cropper
  5997. * @augments wp.media.controller.State
  5998. * @augments Backbone.Model
  5999. */
  6000. SiteIconCropper = Controller.Cropper.extend(/** @lends wp.media.controller.SiteIconCropper.prototype */{
  6001. activate: function() {
  6002. this.frame.on( 'content:create:crop', this.createCropContent, this );
  6003. this.frame.on( 'close', this.removeCropper, this );
  6004. this.set('selection', new Backbone.Collection(this.frame._selection.single));
  6005. },
  6006. createCropContent: function() {
  6007. this.cropperView = new wp.media.view.SiteIconCropper({
  6008. controller: this,
  6009. attachment: this.get('selection').first()
  6010. });
  6011. this.cropperView.on('image-loaded', this.createCropToolbar, this);
  6012. this.frame.content.set(this.cropperView);
  6013. },
  6014. doCrop: function( attachment ) {
  6015. var cropDetails = attachment.get( 'cropDetails' ),
  6016. control = this.get( 'control' );
  6017. cropDetails.dst_width = control.params.width;
  6018. cropDetails.dst_height = control.params.height;
  6019. return wp.ajax.post( 'crop-image', {
  6020. nonce: attachment.get( 'nonces' ).edit,
  6021. id: attachment.get( 'id' ),
  6022. context: 'site-icon',
  6023. cropDetails: cropDetails
  6024. } );
  6025. }
  6026. });
  6027. module.exports = SiteIconCropper;
  6028. /***/ }),
  6029. /***/ "WiNq":
  6030. /***/ (function(module, exports) {
  6031. /**
  6032. * wp.media.controller.Region
  6033. *
  6034. * A region is a persistent application layout area.
  6035. *
  6036. * A region assumes one mode at any time, and can be switched to another.
  6037. *
  6038. * When mode changes, events are triggered on the region's parent view.
  6039. * The parent view will listen to specific events and fill the region with an
  6040. * appropriate view depending on mode. For example, a frame listens for the
  6041. * 'browse' mode t be activated on the 'content' view and then fills the region
  6042. * with an AttachmentsBrowser view.
  6043. *
  6044. * @memberOf wp.media.controller
  6045. *
  6046. * @class
  6047. *
  6048. * @param {Object} options Options hash for the region.
  6049. * @param {string} options.id Unique identifier for the region.
  6050. * @param {Backbone.View} options.view A parent view the region exists within.
  6051. * @param {string} options.selector jQuery selector for the region within the parent view.
  6052. */
  6053. var Region = function( options ) {
  6054. _.extend( this, _.pick( options || {}, 'id', 'view', 'selector' ) );
  6055. };
  6056. // Use Backbone's self-propagating `extend` inheritance method.
  6057. Region.extend = Backbone.Model.extend;
  6058. _.extend( Region.prototype,/** @lends wp.media.controller.Region.prototype */{
  6059. /**
  6060. * Activate a mode.
  6061. *
  6062. * @since 3.5.0
  6063. *
  6064. * @param {string} mode
  6065. *
  6066. * @fires Region#activate
  6067. * @fires Region#deactivate
  6068. *
  6069. * @return {wp.media.controller.Region} Returns itself to allow chaining.
  6070. */
  6071. mode: function( mode ) {
  6072. if ( ! mode ) {
  6073. return this._mode;
  6074. }
  6075. // Bail if we're trying to change to the current mode.
  6076. if ( mode === this._mode ) {
  6077. return this;
  6078. }
  6079. /**
  6080. * Region mode deactivation event.
  6081. *
  6082. * @event wp.media.controller.Region#deactivate
  6083. */
  6084. this.trigger('deactivate');
  6085. this._mode = mode;
  6086. this.render( mode );
  6087. /**
  6088. * Region mode activation event.
  6089. *
  6090. * @event wp.media.controller.Region#activate
  6091. */
  6092. this.trigger('activate');
  6093. return this;
  6094. },
  6095. /**
  6096. * Render a mode.
  6097. *
  6098. * @since 3.5.0
  6099. *
  6100. * @param {string} mode
  6101. *
  6102. * @fires Region#create
  6103. * @fires Region#render
  6104. *
  6105. * @return {wp.media.controller.Region} Returns itself to allow chaining.
  6106. */
  6107. render: function( mode ) {
  6108. // If the mode isn't active, activate it.
  6109. if ( mode && mode !== this._mode ) {
  6110. return this.mode( mode );
  6111. }
  6112. var set = { view: null },
  6113. view;
  6114. /**
  6115. * Create region view event.
  6116. *
  6117. * Region view creation takes place in an event callback on the frame.
  6118. *
  6119. * @event wp.media.controller.Region#create
  6120. * @type {object}
  6121. * @property {object} view
  6122. */
  6123. this.trigger( 'create', set );
  6124. view = set.view;
  6125. /**
  6126. * Render region view event.
  6127. *
  6128. * Region view creation takes place in an event callback on the frame.
  6129. *
  6130. * @event wp.media.controller.Region#render
  6131. * @type {object}
  6132. */
  6133. this.trigger( 'render', view );
  6134. if ( view ) {
  6135. this.set( view );
  6136. }
  6137. return this;
  6138. },
  6139. /**
  6140. * Get the region's view.
  6141. *
  6142. * @since 3.5.0
  6143. *
  6144. * @return {wp.media.View}
  6145. */
  6146. get: function() {
  6147. return this.view.views.first( this.selector );
  6148. },
  6149. /**
  6150. * Set the region's view as a subview of the frame.
  6151. *
  6152. * @since 3.5.0
  6153. *
  6154. * @param {Array|Object} views
  6155. * @param {Object} [options={}]
  6156. * @return {wp.Backbone.Subviews} Subviews is returned to allow chaining.
  6157. */
  6158. set: function( views, options ) {
  6159. if ( options ) {
  6160. options.add = false;
  6161. }
  6162. return this.view.views.set( this.selector, views, options );
  6163. },
  6164. /**
  6165. * Trigger regional view events on the frame.
  6166. *
  6167. * @since 3.5.0
  6168. *
  6169. * @param {string} event
  6170. * @return {undefined|wp.media.controller.Region} Returns itself to allow chaining.
  6171. */
  6172. trigger: function( event ) {
  6173. var base, args;
  6174. if ( ! this._mode ) {
  6175. return;
  6176. }
  6177. args = _.toArray( arguments );
  6178. base = this.id + ':' + event;
  6179. // Trigger `{this.id}:{event}:{this._mode}` event on the frame.
  6180. args[0] = base + ':' + this._mode;
  6181. this.view.trigger.apply( this.view, args );
  6182. // Trigger `{this.id}:{event}` event on the frame.
  6183. args[0] = base;
  6184. this.view.trigger.apply( this.view, args );
  6185. return this;
  6186. }
  6187. });
  6188. module.exports = Region;
  6189. /***/ }),
  6190. /***/ "ZeG4":
  6191. /***/ (function(module, exports) {
  6192. /**
  6193. * wp.media.view.UploaderStatusError
  6194. *
  6195. * @memberOf wp.media.view
  6196. *
  6197. * @class
  6198. * @augments wp.media.View
  6199. * @augments wp.Backbone.View
  6200. * @augments Backbone.View
  6201. */
  6202. var UploaderStatusError = wp.media.View.extend(/** @lends wp.media.view.UploaderStatusError.prototype */{
  6203. className: 'upload-error',
  6204. template: wp.template('uploader-status-error')
  6205. });
  6206. module.exports = UploaderStatusError;
  6207. /***/ }),
  6208. /***/ "ZgZ7":
  6209. /***/ (function(module, exports) {
  6210. var Search;
  6211. /**
  6212. * wp.media.view.Search
  6213. *
  6214. * @memberOf wp.media.view
  6215. *
  6216. * @class
  6217. * @augments wp.media.View
  6218. * @augments wp.Backbone.View
  6219. * @augments Backbone.View
  6220. */
  6221. Search = wp.media.View.extend(/** @lends wp.media.view.Search.prototype */{
  6222. tagName: 'input',
  6223. className: 'search',
  6224. id: 'media-search-input',
  6225. attributes: {
  6226. type: 'search'
  6227. },
  6228. events: {
  6229. 'input': 'search'
  6230. },
  6231. /**
  6232. * @return {wp.media.view.Search} Returns itself to allow chaining.
  6233. */
  6234. render: function() {
  6235. this.el.value = this.model.escape('search');
  6236. return this;
  6237. },
  6238. search: _.debounce( function( event ) {
  6239. var searchTerm = event.target.value.trim();
  6240. // Trigger the search only after 2 ASCII characters.
  6241. if ( searchTerm && searchTerm.length > 1 ) {
  6242. this.model.set( 'search', searchTerm );
  6243. } else {
  6244. this.model.unset( 'search' );
  6245. }
  6246. }, 500 )
  6247. });
  6248. module.exports = Search;
  6249. /***/ }),
  6250. /***/ "aBqq":
  6251. /***/ (function(module, exports) {
  6252. var Library = wp.media.controller.Library,
  6253. l10n = wp.media.view.l10n,
  6254. ReplaceImage;
  6255. /**
  6256. * wp.media.controller.ReplaceImage
  6257. *
  6258. * A state for replacing an image.
  6259. *
  6260. * @memberOf wp.media.controller
  6261. *
  6262. * @class
  6263. * @augments wp.media.controller.Library
  6264. * @augments wp.media.controller.State
  6265. * @augments Backbone.Model
  6266. *
  6267. * @param {object} [attributes] The attributes hash passed to the state.
  6268. * @param {string} [attributes.id=replace-image] Unique identifier.
  6269. * @param {string} [attributes.title=Replace Image] Title for the state. Displays in the media menu and the frame's title region.
  6270. * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse.
  6271. * If one is not supplied, a collection of all images will be created.
  6272. * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled.
  6273. * @param {string} [attributes.content=upload] Initial mode for the content region.
  6274. * Overridden by persistent user setting if 'contentUserSetting' is true.
  6275. * @param {string} [attributes.menu=default] Initial mode for the menu region.
  6276. * @param {string} [attributes.router=browse] Initial mode for the router region.
  6277. * @param {string} [attributes.toolbar=replace] Initial mode for the toolbar region.
  6278. * @param {int} [attributes.priority=60] The priority for the state link in the media menu.
  6279. * @param {boolean} [attributes.searchable=true] Whether the library is searchable.
  6280. * @param {boolean|string} [attributes.filterable=uploaded] Whether the library is filterable, and if so what filters should be shown.
  6281. * Accepts 'all', 'uploaded', or 'unattached'.
  6282. * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
  6283. * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection.
  6284. * @param {boolean} [attributes.describe=false] Whether to offer UI to describe attachments - e.g. captioning images in a gallery.
  6285. * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user.
  6286. * @param {boolean} [attributes.syncSelection=true] Whether the Attachments selection should be persisted from the last state.
  6287. */
  6288. ReplaceImage = Library.extend(/** @lends wp.media.controller.ReplaceImage.prototype */{
  6289. defaults: _.defaults({
  6290. id: 'replace-image',
  6291. title: l10n.replaceImageTitle,
  6292. multiple: false,
  6293. filterable: 'uploaded',
  6294. toolbar: 'replace',
  6295. menu: false,
  6296. priority: 60,
  6297. syncSelection: true
  6298. }, Library.prototype.defaults ),
  6299. /**
  6300. * @since 3.9.0
  6301. *
  6302. * @param options
  6303. */
  6304. initialize: function( options ) {
  6305. var library, comparator;
  6306. this.image = options.image;
  6307. // If we haven't been provided a `library`, create a `Selection`.
  6308. if ( ! this.get('library') ) {
  6309. this.set( 'library', wp.media.query({ type: 'image' }) );
  6310. }
  6311. Library.prototype.initialize.apply( this, arguments );
  6312. library = this.get('library');
  6313. comparator = library.comparator;
  6314. // Overload the library's comparator to push items that are not in
  6315. // the mirrored query to the front of the aggregate collection.
  6316. library.comparator = function( a, b ) {
  6317. var aInQuery = !! this.mirroring.get( a.cid ),
  6318. bInQuery = !! this.mirroring.get( b.cid );
  6319. if ( ! aInQuery && bInQuery ) {
  6320. return -1;
  6321. } else if ( aInQuery && ! bInQuery ) {
  6322. return 1;
  6323. } else {
  6324. return comparator.apply( this, arguments );
  6325. }
  6326. };
  6327. // Add all items in the selection to the library, so any featured
  6328. // images that are not initially loaded still appear.
  6329. library.observe( this.get('selection') );
  6330. },
  6331. /**
  6332. * @since 3.9.0
  6333. */
  6334. activate: function() {
  6335. this.updateSelection();
  6336. Library.prototype.activate.apply( this, arguments );
  6337. },
  6338. /**
  6339. * @since 3.9.0
  6340. */
  6341. updateSelection: function() {
  6342. var selection = this.get('selection'),
  6343. attachment = this.image.attachment;
  6344. selection.reset( attachment ? [ attachment ] : [] );
  6345. }
  6346. });
  6347. module.exports = ReplaceImage;
  6348. /***/ }),
  6349. /***/ "cH3P":
  6350. /***/ (function(module, exports) {
  6351. /**
  6352. * wp.media.view.Spinner
  6353. *
  6354. * Represents a spinner in the Media Library.
  6355. *
  6356. * @since 3.9.0
  6357. *
  6358. * @memberOf wp.media.view
  6359. *
  6360. * @class
  6361. * @augments wp.media.View
  6362. * @augments wp.Backbone.View
  6363. * @augments Backbone.View
  6364. */
  6365. var Spinner = wp.media.View.extend(/** @lends wp.media.view.Spinner.prototype */{
  6366. tagName: 'span',
  6367. className: 'spinner',
  6368. spinnerTimeout: false,
  6369. delay: 400,
  6370. /**
  6371. * Shows the spinner. Delays the visibility by the configured amount.
  6372. *
  6373. * @since 3.9.0
  6374. *
  6375. * @return {wp.media.view.Spinner} The spinner.
  6376. */
  6377. show: function() {
  6378. if ( ! this.spinnerTimeout ) {
  6379. this.spinnerTimeout = _.delay(function( $el ) {
  6380. $el.addClass( 'is-active' );
  6381. }, this.delay, this.$el );
  6382. }
  6383. return this;
  6384. },
  6385. /**
  6386. * Hides the spinner.
  6387. *
  6388. * @since 3.9.0
  6389. *
  6390. * @return {wp.media.view.Spinner} The spinner.
  6391. */
  6392. hide: function() {
  6393. this.$el.removeClass( 'is-active' );
  6394. this.spinnerTimeout = clearTimeout( this.spinnerTimeout );
  6395. return this;
  6396. }
  6397. });
  6398. module.exports = Spinner;
  6399. /***/ }),
  6400. /***/ "d3xu":
  6401. /***/ (function(module, exports) {
  6402. var View = wp.media.View,
  6403. $ = jQuery,
  6404. SiteIconPreview;
  6405. /**
  6406. * wp.media.view.SiteIconPreview
  6407. *
  6408. * Shows a preview of the Site Icon as a favicon and app icon while cropping.
  6409. *
  6410. * @memberOf wp.media.view
  6411. *
  6412. * @class
  6413. * @augments wp.media.View
  6414. * @augments wp.Backbone.View
  6415. * @augments Backbone.View
  6416. */
  6417. SiteIconPreview = View.extend(/** @lends wp.media.view.SiteIconPreview.prototype */{
  6418. className: 'site-icon-preview',
  6419. template: wp.template( 'site-icon-preview' ),
  6420. ready: function() {
  6421. this.controller.imgSelect.setOptions({
  6422. onInit: this.updatePreview,
  6423. onSelectChange: this.updatePreview
  6424. });
  6425. },
  6426. prepare: function() {
  6427. return {
  6428. url: this.options.attachment.get( 'url' )
  6429. };
  6430. },
  6431. updatePreview: function( img, coords ) {
  6432. var rx = 64 / coords.width,
  6433. ry = 64 / coords.height,
  6434. preview_rx = 16 / coords.width,
  6435. preview_ry = 16 / coords.height;
  6436. $( '#preview-app-icon' ).css({
  6437. width: Math.round(rx * this.imageWidth ) + 'px',
  6438. height: Math.round(ry * this.imageHeight ) + 'px',
  6439. marginLeft: '-' + Math.round(rx * coords.x1) + 'px',
  6440. marginTop: '-' + Math.round(ry * coords.y1) + 'px'
  6441. });
  6442. $( '#preview-favicon' ).css({
  6443. width: Math.round( preview_rx * this.imageWidth ) + 'px',
  6444. height: Math.round( preview_ry * this.imageHeight ) + 'px',
  6445. marginLeft: '-' + Math.round( preview_rx * coords.x1 ) + 'px',
  6446. marginTop: '-' + Math.floor( preview_ry* coords.y1 ) + 'px'
  6447. });
  6448. }
  6449. });
  6450. module.exports = SiteIconPreview;
  6451. /***/ }),
  6452. /***/ "dpRc":
  6453. /***/ (function(module, exports) {
  6454. var MenuItem;
  6455. /**
  6456. * wp.media.view.MenuItem
  6457. *
  6458. * @memberOf wp.media.view
  6459. *
  6460. * @class
  6461. * @augments wp.media.View
  6462. * @augments wp.Backbone.View
  6463. * @augments Backbone.View
  6464. */
  6465. MenuItem = wp.media.View.extend(/** @lends wp.media.view.MenuItem.prototype */{
  6466. tagName: 'button',
  6467. className: 'media-menu-item',
  6468. attributes: {
  6469. type: 'button',
  6470. role: 'tab'
  6471. },
  6472. events: {
  6473. 'click': '_click'
  6474. },
  6475. /**
  6476. * Allows to override the click event.
  6477. */
  6478. _click: function() {
  6479. var clickOverride = this.options.click;
  6480. if ( clickOverride ) {
  6481. clickOverride.call( this );
  6482. } else {
  6483. this.click();
  6484. }
  6485. },
  6486. click: function() {
  6487. var state = this.options.state;
  6488. if ( state ) {
  6489. this.controller.setState( state );
  6490. // Toggle the menu visibility in the responsive view.
  6491. this.views.parent.$el.removeClass( 'visible' ); // @todo Or hide on any click, see below.
  6492. }
  6493. },
  6494. /**
  6495. * @return {wp.media.view.MenuItem} returns itself to allow chaining.
  6496. */
  6497. render: function() {
  6498. var options = this.options,
  6499. menuProperty = options.state || options.contentMode;
  6500. if ( options.text ) {
  6501. this.$el.text( options.text );
  6502. } else if ( options.html ) {
  6503. this.$el.html( options.html );
  6504. }
  6505. // Set the menu item ID based on the frame state associated to the menu item.
  6506. this.$el.attr( 'id', 'menu-item-' + menuProperty );
  6507. return this;
  6508. }
  6509. });
  6510. module.exports = MenuItem;
  6511. /***/ }),
  6512. /***/ "eqTc":
  6513. /***/ (function(module, exports) {
  6514. var Controller = wp.media.controller,
  6515. CustomizeImageCropper;
  6516. /**
  6517. * A state for cropping an image in the customizer.
  6518. *
  6519. * @since 4.3.0
  6520. *
  6521. * @constructs wp.media.controller.CustomizeImageCropper
  6522. * @memberOf wp.media.controller
  6523. * @augments wp.media.controller.CustomizeImageCropper.Cropper
  6524. * @inheritDoc
  6525. */
  6526. CustomizeImageCropper = Controller.Cropper.extend(/** @lends wp.media.controller.CustomizeImageCropper.prototype */{
  6527. /**
  6528. * Posts the crop details to the admin.
  6529. *
  6530. * Uses crop measurements when flexible in both directions.
  6531. * Constrains flexible side based on image ratio and size of the fixed side.
  6532. *
  6533. * @since 4.3.0
  6534. *
  6535. * @param {Object} attachment The attachment to crop.
  6536. *
  6537. * @return {$.promise} A jQuery promise that represents the crop image request.
  6538. */
  6539. doCrop: function( attachment ) {
  6540. var cropDetails = attachment.get( 'cropDetails' ),
  6541. control = this.get( 'control' ),
  6542. ratio = cropDetails.width / cropDetails.height;
  6543. // Use crop measurements when flexible in both directions.
  6544. if ( control.params.flex_width && control.params.flex_height ) {
  6545. cropDetails.dst_width = cropDetails.width;
  6546. cropDetails.dst_height = cropDetails.height;
  6547. // Constrain flexible side based on image ratio and size of the fixed side.
  6548. } else {
  6549. cropDetails.dst_width = control.params.flex_width ? control.params.height * ratio : control.params.width;
  6550. cropDetails.dst_height = control.params.flex_height ? control.params.width / ratio : control.params.height;
  6551. }
  6552. return wp.ajax.post( 'crop-image', {
  6553. wp_customize: 'on',
  6554. nonce: attachment.get( 'nonces' ).edit,
  6555. id: attachment.get( 'id' ),
  6556. context: control.id,
  6557. cropDetails: cropDetails
  6558. } );
  6559. }
  6560. });
  6561. module.exports = CustomizeImageCropper;
  6562. /***/ }),
  6563. /***/ "fYN4":
  6564. /***/ (function(module, exports) {
  6565. var MediaFrame = wp.media.view.MediaFrame,
  6566. l10n = wp.media.view.l10n,
  6567. Select;
  6568. /**
  6569. * wp.media.view.MediaFrame.Select
  6570. *
  6571. * A frame for selecting an item or items from the media library.
  6572. *
  6573. * @memberOf wp.media.view.MediaFrame
  6574. *
  6575. * @class
  6576. * @augments wp.media.view.MediaFrame
  6577. * @augments wp.media.view.Frame
  6578. * @augments wp.media.View
  6579. * @augments wp.Backbone.View
  6580. * @augments Backbone.View
  6581. * @mixes wp.media.controller.StateMachine
  6582. */
  6583. Select = MediaFrame.extend(/** @lends wp.media.view.MediaFrame.Select.prototype */{
  6584. initialize: function() {
  6585. // Call 'initialize' directly on the parent class.
  6586. MediaFrame.prototype.initialize.apply( this, arguments );
  6587. _.defaults( this.options, {
  6588. selection: [],
  6589. library: {},
  6590. multiple: false,
  6591. state: 'library'
  6592. });
  6593. this.createSelection();
  6594. this.createStates();
  6595. this.bindHandlers();
  6596. },
  6597. /**
  6598. * Attach a selection collection to the frame.
  6599. *
  6600. * A selection is a collection of attachments used for a specific purpose
  6601. * by a media frame. e.g. Selecting an attachment (or many) to insert into
  6602. * post content.
  6603. *
  6604. * @see media.model.Selection
  6605. */
  6606. createSelection: function() {
  6607. var selection = this.options.selection;
  6608. if ( ! (selection instanceof wp.media.model.Selection) ) {
  6609. this.options.selection = new wp.media.model.Selection( selection, {
  6610. multiple: this.options.multiple
  6611. });
  6612. }
  6613. this._selection = {
  6614. attachments: new wp.media.model.Attachments(),
  6615. difference: []
  6616. };
  6617. },
  6618. editImageContent: function() {
  6619. var image = this.state().get('image'),
  6620. view = new wp.media.view.EditImage( { model: image, controller: this } ).render();
  6621. this.content.set( view );
  6622. // After creating the wrapper view, load the actual editor via an Ajax call.
  6623. view.loadEditor();
  6624. },
  6625. /**
  6626. * Create the default states on the frame.
  6627. */
  6628. createStates: function() {
  6629. var options = this.options;
  6630. if ( this.options.states ) {
  6631. return;
  6632. }
  6633. // Add the default states.
  6634. this.states.add([
  6635. // Main states.
  6636. new wp.media.controller.Library({
  6637. library: wp.media.query( options.library ),
  6638. multiple: options.multiple,
  6639. title: options.title,
  6640. priority: 20
  6641. }),
  6642. new wp.media.controller.EditImage( { model: options.editImage } )
  6643. ]);
  6644. },
  6645. /**
  6646. * Bind region mode event callbacks.
  6647. *
  6648. * @see media.controller.Region.render
  6649. */
  6650. bindHandlers: function() {
  6651. this.on( 'router:create:browse', this.createRouter, this );
  6652. this.on( 'router:render:browse', this.browseRouter, this );
  6653. this.on( 'content:create:browse', this.browseContent, this );
  6654. this.on( 'content:render:upload', this.uploadContent, this );
  6655. this.on( 'toolbar:create:select', this.createSelectToolbar, this );
  6656. this.on( 'content:render:edit-image', this.editImageContent, this );
  6657. },
  6658. /**
  6659. * Render callback for the router region in the `browse` mode.
  6660. *
  6661. * @param {wp.media.view.Router} routerView
  6662. */
  6663. browseRouter: function( routerView ) {
  6664. routerView.set({
  6665. upload: {
  6666. text: l10n.uploadFilesTitle,
  6667. priority: 20
  6668. },
  6669. browse: {
  6670. text: l10n.mediaLibraryTitle,
  6671. priority: 40
  6672. }
  6673. });
  6674. },
  6675. /**
  6676. * Render callback for the content region in the `browse` mode.
  6677. *
  6678. * @param {wp.media.controller.Region} contentRegion
  6679. */
  6680. browseContent: function( contentRegion ) {
  6681. var state = this.state();
  6682. this.$el.removeClass('hide-toolbar');
  6683. // Browse our library of attachments.
  6684. contentRegion.view = new wp.media.view.AttachmentsBrowser({
  6685. controller: this,
  6686. collection: state.get('library'),
  6687. selection: state.get('selection'),
  6688. model: state,
  6689. sortable: state.get('sortable'),
  6690. search: state.get('searchable'),
  6691. filters: state.get('filterable'),
  6692. date: state.get('date'),
  6693. display: state.has('display') ? state.get('display') : state.get('displaySettings'),
  6694. dragInfo: state.get('dragInfo'),
  6695. idealColumnWidth: state.get('idealColumnWidth'),
  6696. suggestedWidth: state.get('suggestedWidth'),
  6697. suggestedHeight: state.get('suggestedHeight'),
  6698. AttachmentView: state.get('AttachmentView')
  6699. });
  6700. },
  6701. /**
  6702. * Render callback for the content region in the `upload` mode.
  6703. */
  6704. uploadContent: function() {
  6705. this.$el.removeClass( 'hide-toolbar' );
  6706. this.content.set( new wp.media.view.UploaderInline({
  6707. controller: this
  6708. }) );
  6709. },
  6710. /**
  6711. * Toolbars
  6712. *
  6713. * @param {Object} toolbar
  6714. * @param {Object} [options={}]
  6715. * @this wp.media.controller.Region
  6716. */
  6717. createSelectToolbar: function( toolbar, options ) {
  6718. options = options || this.options.button || {};
  6719. options.controller = this;
  6720. toolbar.view = new wp.media.view.Toolbar.Select( options );
  6721. }
  6722. });
  6723. module.exports = Select;
  6724. /***/ }),
  6725. /***/ "gOpb":
  6726. /***/ (function(module, exports) {
  6727. var $ = jQuery,
  6728. Modal;
  6729. /**
  6730. * wp.media.view.Modal
  6731. *
  6732. * A modal view, which the media modal uses as its default container.
  6733. *
  6734. * @memberOf wp.media.view
  6735. *
  6736. * @class
  6737. * @augments wp.media.View
  6738. * @augments wp.Backbone.View
  6739. * @augments Backbone.View
  6740. */
  6741. Modal = wp.media.View.extend(/** @lends wp.media.view.Modal.prototype */{
  6742. tagName: 'div',
  6743. template: wp.template('media-modal'),
  6744. events: {
  6745. 'click .media-modal-backdrop, .media-modal-close': 'escapeHandler',
  6746. 'keydown': 'keydown'
  6747. },
  6748. clickedOpenerEl: null,
  6749. initialize: function() {
  6750. _.defaults( this.options, {
  6751. container: document.body,
  6752. title: '',
  6753. propagate: true,
  6754. hasCloseButton: true
  6755. });
  6756. this.focusManager = new wp.media.view.FocusManager({
  6757. el: this.el
  6758. });
  6759. },
  6760. /**
  6761. * @return {Object}
  6762. */
  6763. prepare: function() {
  6764. return {
  6765. title: this.options.title,
  6766. hasCloseButton: this.options.hasCloseButton
  6767. };
  6768. },
  6769. /**
  6770. * @return {wp.media.view.Modal} Returns itself to allow chaining.
  6771. */
  6772. attach: function() {
  6773. if ( this.views.attached ) {
  6774. return this;
  6775. }
  6776. if ( ! this.views.rendered ) {
  6777. this.render();
  6778. }
  6779. this.$el.appendTo( this.options.container );
  6780. // Manually mark the view as attached and trigger ready.
  6781. this.views.attached = true;
  6782. this.views.ready();
  6783. return this.propagate('attach');
  6784. },
  6785. /**
  6786. * @return {wp.media.view.Modal} Returns itself to allow chaining.
  6787. */
  6788. detach: function() {
  6789. if ( this.$el.is(':visible') ) {
  6790. this.close();
  6791. }
  6792. this.$el.detach();
  6793. this.views.attached = false;
  6794. return this.propagate('detach');
  6795. },
  6796. /**
  6797. * @return {wp.media.view.Modal} Returns itself to allow chaining.
  6798. */
  6799. open: function() {
  6800. var $el = this.$el,
  6801. mceEditor;
  6802. if ( $el.is(':visible') ) {
  6803. return this;
  6804. }
  6805. this.clickedOpenerEl = document.activeElement;
  6806. if ( ! this.views.attached ) {
  6807. this.attach();
  6808. }
  6809. // Disable page scrolling.
  6810. $( 'body' ).addClass( 'modal-open' );
  6811. $el.show();
  6812. // Try to close the onscreen keyboard.
  6813. if ( 'ontouchend' in document ) {
  6814. if ( ( mceEditor = window.tinymce && window.tinymce.activeEditor ) && ! mceEditor.isHidden() && mceEditor.iframeElement ) {
  6815. mceEditor.iframeElement.focus();
  6816. mceEditor.iframeElement.blur();
  6817. setTimeout( function() {
  6818. mceEditor.iframeElement.blur();
  6819. }, 100 );
  6820. }
  6821. }
  6822. // Set initial focus on the content instead of this view element, to avoid page scrolling.
  6823. this.$( '.media-modal' ).trigger( 'focus' );
  6824. // Hide the page content from assistive technologies.
  6825. this.focusManager.setAriaHiddenOnBodyChildren( $el );
  6826. return this.propagate('open');
  6827. },
  6828. /**
  6829. * @param {Object} options
  6830. * @return {wp.media.view.Modal} Returns itself to allow chaining.
  6831. */
  6832. close: function( options ) {
  6833. if ( ! this.views.attached || ! this.$el.is(':visible') ) {
  6834. return this;
  6835. }
  6836. // Pause current audio/video even after closing the modal.
  6837. $( '.mejs-pause button' ).trigger( 'click' );
  6838. // Enable page scrolling.
  6839. $( 'body' ).removeClass( 'modal-open' );
  6840. // Hide modal and remove restricted media modal tab focus once it's closed.
  6841. this.$el.hide().off( 'keydown' );
  6842. /*
  6843. * Make visible again to assistive technologies all body children that
  6844. * have been made hidden when the modal opened.
  6845. */
  6846. this.focusManager.removeAriaHiddenFromBodyChildren();
  6847. // Move focus back in useful location once modal is closed.
  6848. if ( null !== this.clickedOpenerEl ) {
  6849. // Move focus back to the element that opened the modal.
  6850. this.clickedOpenerEl.focus();
  6851. } else {
  6852. // Fallback to the admin page main element.
  6853. $( '#wpbody-content' )
  6854. .attr( 'tabindex', '-1' )
  6855. .trigger( 'focus' );
  6856. }
  6857. this.propagate('close');
  6858. if ( options && options.escape ) {
  6859. this.propagate('escape');
  6860. }
  6861. return this;
  6862. },
  6863. /**
  6864. * @return {wp.media.view.Modal} Returns itself to allow chaining.
  6865. */
  6866. escape: function() {
  6867. return this.close({ escape: true });
  6868. },
  6869. /**
  6870. * @param {Object} event
  6871. */
  6872. escapeHandler: function( event ) {
  6873. event.preventDefault();
  6874. this.escape();
  6875. },
  6876. /**
  6877. * @param {Array|Object} content Views to register to '.media-modal-content'
  6878. * @return {wp.media.view.Modal} Returns itself to allow chaining.
  6879. */
  6880. content: function( content ) {
  6881. this.views.set( '.media-modal-content', content );
  6882. return this;
  6883. },
  6884. /**
  6885. * Triggers a modal event and if the `propagate` option is set,
  6886. * forwards events to the modal's controller.
  6887. *
  6888. * @param {string} id
  6889. * @return {wp.media.view.Modal} Returns itself to allow chaining.
  6890. */
  6891. propagate: function( id ) {
  6892. this.trigger( id );
  6893. if ( this.options.propagate ) {
  6894. this.controller.trigger( id );
  6895. }
  6896. return this;
  6897. },
  6898. /**
  6899. * @param {Object} event
  6900. */
  6901. keydown: function( event ) {
  6902. // Close the modal when escape is pressed.
  6903. if ( 27 === event.which && this.$el.is(':visible') ) {
  6904. this.escape();
  6905. event.stopImmediatePropagation();
  6906. }
  6907. }
  6908. });
  6909. module.exports = Modal;
  6910. /***/ }),
  6911. /***/ "ibOK":
  6912. /***/ (function(module, exports) {
  6913. var View = wp.media.View,
  6914. EditImage;
  6915. /**
  6916. * wp.media.view.EditImage
  6917. *
  6918. * @memberOf wp.media.view
  6919. *
  6920. * @class
  6921. * @augments wp.media.View
  6922. * @augments wp.Backbone.View
  6923. * @augments Backbone.View
  6924. */
  6925. EditImage = View.extend(/** @lends wp.media.view.EditImage.prototype */{
  6926. className: 'image-editor',
  6927. template: wp.template('image-editor'),
  6928. initialize: function( options ) {
  6929. this.editor = window.imageEdit;
  6930. this.controller = options.controller;
  6931. View.prototype.initialize.apply( this, arguments );
  6932. },
  6933. prepare: function() {
  6934. return this.model.toJSON();
  6935. },
  6936. loadEditor: function() {
  6937. this.editor.open( this.model.get( 'id' ), this.model.get( 'nonces' ).edit, this );
  6938. },
  6939. back: function() {
  6940. var lastState = this.controller.lastState();
  6941. this.controller.setState( lastState );
  6942. },
  6943. refresh: function() {
  6944. this.model.fetch();
  6945. },
  6946. save: function() {
  6947. var lastState = this.controller.lastState();
  6948. this.model.fetch().done( _.bind( function() {
  6949. this.controller.setState( lastState );
  6950. }, this ) );
  6951. }
  6952. });
  6953. module.exports = EditImage;
  6954. /***/ }),
  6955. /***/ "iipZ":
  6956. /***/ (function(module, exports) {
  6957. var Selection = wp.media.model.Selection,
  6958. Library = wp.media.controller.Library,
  6959. CollectionAdd;
  6960. /**
  6961. * wp.media.controller.CollectionAdd
  6962. *
  6963. * A state for adding attachments to a collection (e.g. video playlist).
  6964. *
  6965. * @memberOf wp.media.controller
  6966. *
  6967. * @class
  6968. * @augments wp.media.controller.Library
  6969. * @augments wp.media.controller.State
  6970. * @augments Backbone.Model
  6971. *
  6972. * @param {object} [attributes] The attributes hash passed to the state.
  6973. * @param {string} [attributes.id=library] Unique identifier.
  6974. * @param {string} attributes.title Title for the state. Displays in the frame's title region.
  6975. * @param {boolean} [attributes.multiple=add] Whether multi-select is enabled. @todo 'add' doesn't seem do anything special, and gets used as a boolean.
  6976. * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse.
  6977. * If one is not supplied, a collection of attachments of the specified type will be created.
  6978. * @param {boolean|string} [attributes.filterable=uploaded] Whether the library is filterable, and if so what filters should be shown.
  6979. * Accepts 'all', 'uploaded', or 'unattached'.
  6980. * @param {string} [attributes.menu=gallery] Initial mode for the menu region.
  6981. * @param {string} [attributes.content=upload] Initial mode for the content region.
  6982. * Overridden by persistent user setting if 'contentUserSetting' is true.
  6983. * @param {string} [attributes.router=browse] Initial mode for the router region.
  6984. * @param {string} [attributes.toolbar=gallery-add] Initial mode for the toolbar region.
  6985. * @param {boolean} [attributes.searchable=true] Whether the library is searchable.
  6986. * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
  6987. * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection.
  6988. * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user.
  6989. * @param {int} [attributes.priority=100] The priority for the state link in the media menu.
  6990. * @param {boolean} [attributes.syncSelection=false] Whether the Attachments selection should be persisted from the last state.
  6991. * Defaults to false because for this state, because the library of the Edit Gallery state is the selection.
  6992. * @param {string} attributes.type The collection's media type. (e.g. 'video').
  6993. * @param {string} attributes.collectionType The collection type. (e.g. 'playlist').
  6994. */
  6995. CollectionAdd = Library.extend(/** @lends wp.media.controller.CollectionAdd.prototype */{
  6996. defaults: _.defaults( {
  6997. // Selection defaults. @see media.model.Selection
  6998. multiple: 'add',
  6999. // Attachments browser defaults. @see media.view.AttachmentsBrowser
  7000. filterable: 'uploaded',
  7001. priority: 100,
  7002. syncSelection: false
  7003. }, Library.prototype.defaults ),
  7004. /**
  7005. * @since 3.9.0
  7006. */
  7007. initialize: function() {
  7008. var collectionType = this.get('collectionType');
  7009. if ( 'video' === this.get( 'type' ) ) {
  7010. collectionType = 'video-' + collectionType;
  7011. }
  7012. this.set( 'id', collectionType + '-library' );
  7013. this.set( 'toolbar', collectionType + '-add' );
  7014. this.set( 'menu', collectionType );
  7015. // If we haven't been provided a `library`, create a `Selection`.
  7016. if ( ! this.get('library') ) {
  7017. this.set( 'library', wp.media.query({ type: this.get('type') }) );
  7018. }
  7019. Library.prototype.initialize.apply( this, arguments );
  7020. },
  7021. /**
  7022. * @since 3.9.0
  7023. */
  7024. activate: function() {
  7025. var library = this.get('library'),
  7026. editLibrary = this.get('editLibrary'),
  7027. edit = this.frame.state( this.get('collectionType') + '-edit' ).get('library');
  7028. if ( editLibrary && editLibrary !== edit ) {
  7029. library.unobserve( editLibrary );
  7030. }
  7031. // Accepts attachments that exist in the original library and
  7032. // that do not exist in gallery's library.
  7033. library.validator = function( attachment ) {
  7034. return !! this.mirroring.get( attachment.cid ) && ! edit.get( attachment.cid ) && Selection.prototype.validator.apply( this, arguments );
  7035. };
  7036. /*
  7037. * Reset the library to ensure that all attachments are re-added
  7038. * to the collection. Do so silently, as calling `observe` will
  7039. * trigger the `reset` event.
  7040. */
  7041. library.reset( library.mirroring.models, { silent: true });
  7042. library.observe( edit );
  7043. this.set('editLibrary', edit);
  7044. Library.prototype.activate.apply( this, arguments );
  7045. }
  7046. });
  7047. module.exports = CollectionAdd;
  7048. /***/ }),
  7049. /***/ "iupV":
  7050. /***/ (function(module, exports) {
  7051. /* global ClipboardJS */
  7052. var Attachment = wp.media.view.Attachment,
  7053. l10n = wp.media.view.l10n,
  7054. $ = jQuery,
  7055. Details,
  7056. __ = wp.i18n.__;
  7057. Details = Attachment.extend(/** @lends wp.media.view.Attachment.Details.prototype */{
  7058. tagName: 'div',
  7059. className: 'attachment-details',
  7060. template: wp.template('attachment-details'),
  7061. /*
  7062. * Reset all the attributes inherited from Attachment including role=checkbox,
  7063. * tabindex, etc., as they are inappropriate for this view. See #47458 and [30483] / #30390.
  7064. */
  7065. attributes: {},
  7066. events: {
  7067. 'change [data-setting]': 'updateSetting',
  7068. 'change [data-setting] input': 'updateSetting',
  7069. 'change [data-setting] select': 'updateSetting',
  7070. 'change [data-setting] textarea': 'updateSetting',
  7071. 'click .delete-attachment': 'deleteAttachment',
  7072. 'click .trash-attachment': 'trashAttachment',
  7073. 'click .untrash-attachment': 'untrashAttachment',
  7074. 'click .edit-attachment': 'editAttachment',
  7075. 'keydown': 'toggleSelectionHandler'
  7076. },
  7077. /**
  7078. * Copies the attachment URL to the clipboard.
  7079. *
  7080. * @since 5.5.0
  7081. *
  7082. * @param {MouseEvent} event A click event.
  7083. *
  7084. * @return {void}
  7085. */
  7086. copyAttachmentDetailsURLClipboard: function() {
  7087. var clipboard = new ClipboardJS( '.copy-attachment-url' ),
  7088. successTimeout;
  7089. clipboard.on( 'success', function( event ) {
  7090. var triggerElement = $( event.trigger ),
  7091. successElement = $( '.success', triggerElement.closest( '.copy-to-clipboard-container' ) );
  7092. // Clear the selection and move focus back to the trigger.
  7093. event.clearSelection();
  7094. // Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680
  7095. triggerElement.trigger( 'focus' );
  7096. // Show success visual feedback.
  7097. clearTimeout( successTimeout );
  7098. successElement.removeClass( 'hidden' );
  7099. // Hide success visual feedback after 3 seconds since last success.
  7100. successTimeout = setTimeout( function() {
  7101. successElement.addClass( 'hidden' );
  7102. }, 3000 );
  7103. // Handle success audible feedback.
  7104. wp.a11y.speak( __( 'The file URL has been copied to your clipboard' ) );
  7105. } );
  7106. },
  7107. /**
  7108. * Shows the details of an attachment.
  7109. *
  7110. * @since 3.5.0
  7111. *
  7112. * @constructs wp.media.view.Attachment.Details
  7113. * @augments wp.media.view.Attachment
  7114. *
  7115. * @return {void}
  7116. */
  7117. initialize: function() {
  7118. this.options = _.defaults( this.options, {
  7119. rerenderOnModelChange: false
  7120. });
  7121. // Call 'initialize' directly on the parent class.
  7122. Attachment.prototype.initialize.apply( this, arguments );
  7123. this.copyAttachmentDetailsURLClipboard();
  7124. },
  7125. /**
  7126. * Gets the focusable elements to move focus to.
  7127. *
  7128. * @since 5.3.0
  7129. */
  7130. getFocusableElements: function() {
  7131. var editedAttachment = $( 'li[data-id="' + this.model.id + '"]' );
  7132. this.previousAttachment = editedAttachment.prev();
  7133. this.nextAttachment = editedAttachment.next();
  7134. },
  7135. /**
  7136. * Moves focus to the previous or next attachment in the grid.
  7137. * Fallbacks to the upload button or media frame when there are no attachments.
  7138. *
  7139. * @since 5.3.0
  7140. */
  7141. moveFocus: function() {
  7142. if ( this.previousAttachment.length ) {
  7143. this.previousAttachment.trigger( 'focus' );
  7144. return;
  7145. }
  7146. if ( this.nextAttachment.length ) {
  7147. this.nextAttachment.trigger( 'focus' );
  7148. return;
  7149. }
  7150. // Fallback: move focus to the "Select Files" button in the media modal.
  7151. if ( this.controller.uploader && this.controller.uploader.$browser ) {
  7152. this.controller.uploader.$browser.trigger( 'focus' );
  7153. return;
  7154. }
  7155. // Last fallback.
  7156. this.moveFocusToLastFallback();
  7157. },
  7158. /**
  7159. * Moves focus to the media frame as last fallback.
  7160. *
  7161. * @since 5.3.0
  7162. */
  7163. moveFocusToLastFallback: function() {
  7164. // Last fallback: make the frame focusable and move focus to it.
  7165. $( '.media-frame' )
  7166. .attr( 'tabindex', '-1' )
  7167. .trigger( 'focus' );
  7168. },
  7169. /**
  7170. * Deletes an attachment.
  7171. *
  7172. * Deletes an attachment after asking for confirmation. After deletion,
  7173. * keeps focus in the modal.
  7174. *
  7175. * @since 3.5.0
  7176. *
  7177. * @param {MouseEvent} event A click event.
  7178. *
  7179. * @return {void}
  7180. */
  7181. deleteAttachment: function( event ) {
  7182. event.preventDefault();
  7183. this.getFocusableElements();
  7184. if ( window.confirm( l10n.warnDelete ) ) {
  7185. this.model.destroy();
  7186. this.moveFocus();
  7187. }
  7188. },
  7189. /**
  7190. * Sets the Trash state on an attachment, or destroys the model itself.
  7191. *
  7192. * If the mediaTrash setting is set to true, trashes the attachment.
  7193. * Otherwise, the model itself is destroyed.
  7194. *
  7195. * @since 3.9.0
  7196. *
  7197. * @param {MouseEvent} event A click event.
  7198. *
  7199. * @return {void}
  7200. */
  7201. trashAttachment: function( event ) {
  7202. var library = this.controller.library,
  7203. self = this;
  7204. event.preventDefault();
  7205. this.getFocusableElements();
  7206. // When in the Media Library and the Media Trash is enabled.
  7207. if ( wp.media.view.settings.mediaTrash &&
  7208. 'edit-metadata' === this.controller.content.mode() ) {
  7209. this.model.set( 'status', 'trash' );
  7210. this.model.save().done( function() {
  7211. library._requery( true );
  7212. /*
  7213. * @todo We need to move focus back to the previous, next, or first
  7214. * attachment but the library gets re-queried and refreshed.
  7215. * Thus, the references to the previous attachments are lost.
  7216. * We need an alternate method.
  7217. */
  7218. self.moveFocusToLastFallback();
  7219. } );
  7220. } else {
  7221. this.model.destroy();
  7222. this.moveFocus();
  7223. }
  7224. },
  7225. /**
  7226. * Untrashes an attachment.
  7227. *
  7228. * @since 4.0.0
  7229. *
  7230. * @param {MouseEvent} event A click event.
  7231. *
  7232. * @return {void}
  7233. */
  7234. untrashAttachment: function( event ) {
  7235. var library = this.controller.library;
  7236. event.preventDefault();
  7237. this.model.set( 'status', 'inherit' );
  7238. this.model.save().done( function() {
  7239. library._requery( true );
  7240. } );
  7241. },
  7242. /**
  7243. * Opens the edit page for a specific attachment.
  7244. *
  7245. * @since 3.5.0
  7246. *
  7247. * @param {MouseEvent} event A click event.
  7248. *
  7249. * @return {void}
  7250. */
  7251. editAttachment: function( event ) {
  7252. var editState = this.controller.states.get( 'edit-image' );
  7253. if ( window.imageEdit && editState ) {
  7254. event.preventDefault();
  7255. editState.set( 'image', this.model );
  7256. this.controller.setState( 'edit-image' );
  7257. } else {
  7258. this.$el.addClass('needs-refresh');
  7259. }
  7260. },
  7261. /**
  7262. * Triggers an event on the controller when reverse tabbing (shift+tab).
  7263. *
  7264. * This event can be used to make sure to move the focus correctly.
  7265. *
  7266. * @since 4.0.0
  7267. *
  7268. * @fires wp.media.controller.MediaLibrary#attachment:details:shift-tab
  7269. * @fires wp.media.controller.MediaLibrary#attachment:keydown:arrow
  7270. *
  7271. * @param {KeyboardEvent} event A keyboard event.
  7272. *
  7273. * @return {boolean|void} Returns false or undefined.
  7274. */
  7275. toggleSelectionHandler: function( event ) {
  7276. if ( 'keydown' === event.type && 9 === event.keyCode && event.shiftKey && event.target === this.$( ':tabbable' ).get( 0 ) ) {
  7277. this.controller.trigger( 'attachment:details:shift-tab', event );
  7278. return false;
  7279. }
  7280. },
  7281. render: function() {
  7282. Attachment.prototype.render.apply( this, arguments );
  7283. wp.media.mixin.removeAllPlayers();
  7284. this.$( 'audio, video' ).each( function (i, elem) {
  7285. var el = wp.media.view.MediaDetails.prepareSrc( elem );
  7286. new window.MediaElementPlayer( el, wp.media.mixin.mejsSettings );
  7287. } );
  7288. }
  7289. });
  7290. module.exports = Details;
  7291. /***/ }),
  7292. /***/ "l2j4":
  7293. /***/ (function(module, exports) {
  7294. /**
  7295. * wp.media.view.Heading
  7296. *
  7297. * A reusable heading component for the media library
  7298. *
  7299. * Used to add accessibility friendly headers in the media library/modal.
  7300. *
  7301. * @class
  7302. * @augments wp.media.View
  7303. * @augments wp.Backbone.View
  7304. * @augments Backbone.View
  7305. */
  7306. var Heading = wp.media.View.extend( {
  7307. tagName: function() {
  7308. return this.options.level || 'h1';
  7309. },
  7310. className: 'media-views-heading',
  7311. initialize: function() {
  7312. if ( this.options.className ) {
  7313. this.$el.addClass( this.options.className );
  7314. }
  7315. this.text = this.options.text;
  7316. },
  7317. render: function() {
  7318. this.$el.html( this.text );
  7319. return this;
  7320. }
  7321. } );
  7322. module.exports = Heading;
  7323. /***/ }),
  7324. /***/ "mVaH":
  7325. /***/ (function(module, exports) {
  7326. /**
  7327. * wp.media.controller.MediaLibrary
  7328. *
  7329. * @memberOf wp.media.controller
  7330. *
  7331. * @class
  7332. * @augments wp.media.controller.Library
  7333. * @augments wp.media.controller.State
  7334. * @augments Backbone.Model
  7335. */
  7336. var Library = wp.media.controller.Library,
  7337. MediaLibrary;
  7338. MediaLibrary = Library.extend(/** @lends wp.media.controller.MediaLibrary.prototype */{
  7339. defaults: _.defaults({
  7340. // Attachments browser defaults. @see media.view.AttachmentsBrowser
  7341. filterable: 'uploaded',
  7342. displaySettings: false,
  7343. priority: 80,
  7344. syncSelection: false
  7345. }, Library.prototype.defaults ),
  7346. /**
  7347. * @since 3.9.0
  7348. *
  7349. * @param options
  7350. */
  7351. initialize: function( options ) {
  7352. this.media = options.media;
  7353. this.type = options.type;
  7354. this.set( 'library', wp.media.query({ type: this.type }) );
  7355. Library.prototype.initialize.apply( this, arguments );
  7356. },
  7357. /**
  7358. * @since 3.9.0
  7359. */
  7360. activate: function() {
  7361. // @todo this should use this.frame.
  7362. if ( wp.media.frame.lastMime ) {
  7363. this.set( 'library', wp.media.query({ type: wp.media.frame.lastMime }) );
  7364. delete wp.media.frame.lastMime;
  7365. }
  7366. Library.prototype.activate.apply( this, arguments );
  7367. }
  7368. });
  7369. module.exports = MediaLibrary;
  7370. /***/ }),
  7371. /***/ "ng6N":
  7372. /***/ (function(module, exports) {
  7373. var Selection = wp.media.model.Selection,
  7374. Library = wp.media.controller.Library,
  7375. l10n = wp.media.view.l10n,
  7376. GalleryAdd;
  7377. /**
  7378. * wp.media.controller.GalleryAdd
  7379. *
  7380. * A state for selecting more images to add to a gallery.
  7381. *
  7382. * @since 3.5.0
  7383. *
  7384. * @class
  7385. * @augments wp.media.controller.Library
  7386. * @augments wp.media.controller.State
  7387. * @augments Backbone.Model
  7388. *
  7389. * @memberof wp.media.controller
  7390. *
  7391. * @param {Object} [attributes] The attributes hash passed to the state.
  7392. * @param {string} [attributes.id=gallery-library] Unique identifier.
  7393. * @param {string} [attributes.title=Add to Gallery] Title for the state. Displays in the frame's title region.
  7394. * @param {boolean} [attributes.multiple=add] Whether multi-select is enabled. @todo 'add' doesn't seem do anything special, and gets used as a boolean.
  7395. * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse.
  7396. * If one is not supplied, a collection of all images will be created.
  7397. * @param {boolean|string} [attributes.filterable=uploaded] Whether the library is filterable, and if so what filters should be shown.
  7398. * Accepts 'all', 'uploaded', or 'unattached'.
  7399. * @param {string} [attributes.menu=gallery] Initial mode for the menu region.
  7400. * @param {string} [attributes.content=upload] Initial mode for the content region.
  7401. * Overridden by persistent user setting if 'contentUserSetting' is true.
  7402. * @param {string} [attributes.router=browse] Initial mode for the router region.
  7403. * @param {string} [attributes.toolbar=gallery-add] Initial mode for the toolbar region.
  7404. * @param {boolean} [attributes.searchable=true] Whether the library is searchable.
  7405. * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
  7406. * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection.
  7407. * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user.
  7408. * @param {number} [attributes.priority=100] The priority for the state link in the media menu.
  7409. * @param {boolean} [attributes.syncSelection=false] Whether the Attachments selection should be persisted from the last state.
  7410. * Defaults to false because for this state, because the library of the Edit Gallery state is the selection.
  7411. */
  7412. GalleryAdd = Library.extend(/** @lends wp.media.controller.GalleryAdd.prototype */{
  7413. defaults: _.defaults({
  7414. id: 'gallery-library',
  7415. title: l10n.addToGalleryTitle,
  7416. multiple: 'add',
  7417. filterable: 'uploaded',
  7418. menu: 'gallery',
  7419. toolbar: 'gallery-add',
  7420. priority: 100,
  7421. syncSelection: false
  7422. }, Library.prototype.defaults ),
  7423. /**
  7424. * Initializes the library. Creates a library of images if a library isn't supplied.
  7425. *
  7426. * @since 3.5.0
  7427. *
  7428. * @return {void}
  7429. */
  7430. initialize: function() {
  7431. if ( ! this.get('library') ) {
  7432. this.set( 'library', wp.media.query({ type: 'image' }) );
  7433. }
  7434. Library.prototype.initialize.apply( this, arguments );
  7435. },
  7436. /**
  7437. * Activates the library.
  7438. *
  7439. * Removes all event listeners if in edit mode. Creates a validator to check an attachment.
  7440. * Resets library and re-enables event listeners. Activates edit mode. Calls the parent's activate method.
  7441. *
  7442. * @since 3.5.0
  7443. *
  7444. * @return {void}
  7445. */
  7446. activate: function() {
  7447. var library = this.get('library'),
  7448. edit = this.frame.state('gallery-edit').get('library');
  7449. if ( this.editLibrary && this.editLibrary !== edit ) {
  7450. library.unobserve( this.editLibrary );
  7451. }
  7452. /*
  7453. * Accept attachments that exist in the original library but
  7454. * that do not exist in gallery's library yet.
  7455. */
  7456. library.validator = function( attachment ) {
  7457. return !! this.mirroring.get( attachment.cid ) && ! edit.get( attachment.cid ) && Selection.prototype.validator.apply( this, arguments );
  7458. };
  7459. /*
  7460. * Reset the library to ensure that all attachments are re-added
  7461. * to the collection. Do so silently, as calling `observe` will
  7462. * trigger the `reset` event.
  7463. */
  7464. library.reset( library.mirroring.models, { silent: true });
  7465. library.observe( edit );
  7466. this.editLibrary = edit;
  7467. Library.prototype.activate.apply( this, arguments );
  7468. }
  7469. });
  7470. module.exports = GalleryAdd;
  7471. /***/ }),
  7472. /***/ "nwwF":
  7473. /***/ (function(module, exports) {
  7474. var View = wp.media.View,
  7475. $ = Backbone.$,
  7476. Settings;
  7477. /**
  7478. * wp.media.view.Settings
  7479. *
  7480. * @memberOf wp.media.view
  7481. *
  7482. * @class
  7483. * @augments wp.media.View
  7484. * @augments wp.Backbone.View
  7485. * @augments Backbone.View
  7486. */
  7487. Settings = View.extend(/** @lends wp.media.view.Settings.prototype */{
  7488. events: {
  7489. 'click button': 'updateHandler',
  7490. 'change input': 'updateHandler',
  7491. 'change select': 'updateHandler',
  7492. 'change textarea': 'updateHandler'
  7493. },
  7494. initialize: function() {
  7495. this.model = this.model || new Backbone.Model();
  7496. this.listenTo( this.model, 'change', this.updateChanges );
  7497. },
  7498. prepare: function() {
  7499. return _.defaults({
  7500. model: this.model.toJSON()
  7501. }, this.options );
  7502. },
  7503. /**
  7504. * @return {wp.media.view.Settings} Returns itself to allow chaining.
  7505. */
  7506. render: function() {
  7507. View.prototype.render.apply( this, arguments );
  7508. // Select the correct values.
  7509. _( this.model.attributes ).chain().keys().each( this.update, this );
  7510. return this;
  7511. },
  7512. /**
  7513. * @param {string} key
  7514. */
  7515. update: function( key ) {
  7516. var value = this.model.get( key ),
  7517. $setting = this.$('[data-setting="' + key + '"]'),
  7518. $buttons, $value;
  7519. // Bail if we didn't find a matching setting.
  7520. if ( ! $setting.length ) {
  7521. return;
  7522. }
  7523. // Attempt to determine how the setting is rendered and update
  7524. // the selected value.
  7525. // Handle dropdowns.
  7526. if ( $setting.is('select') ) {
  7527. $value = $setting.find('[value="' + value + '"]');
  7528. if ( $value.length ) {
  7529. $setting.find('option').prop( 'selected', false );
  7530. $value.prop( 'selected', true );
  7531. } else {
  7532. // If we can't find the desired value, record what *is* selected.
  7533. this.model.set( key, $setting.find(':selected').val() );
  7534. }
  7535. // Handle button groups.
  7536. } else if ( $setting.hasClass('button-group') ) {
  7537. $buttons = $setting.find( 'button' )
  7538. .removeClass( 'active' )
  7539. .attr( 'aria-pressed', 'false' );
  7540. $buttons.filter( '[value="' + value + '"]' )
  7541. .addClass( 'active' )
  7542. .attr( 'aria-pressed', 'true' );
  7543. // Handle text inputs and textareas.
  7544. } else if ( $setting.is('input[type="text"], textarea') ) {
  7545. if ( ! $setting.is(':focus') ) {
  7546. $setting.val( value );
  7547. }
  7548. // Handle checkboxes.
  7549. } else if ( $setting.is('input[type="checkbox"]') ) {
  7550. $setting.prop( 'checked', !! value && 'false' !== value );
  7551. }
  7552. },
  7553. /**
  7554. * @param {Object} event
  7555. */
  7556. updateHandler: function( event ) {
  7557. var $setting = $( event.target ).closest('[data-setting]'),
  7558. value = event.target.value,
  7559. userSetting;
  7560. event.preventDefault();
  7561. if ( ! $setting.length ) {
  7562. return;
  7563. }
  7564. // Use the correct value for checkboxes.
  7565. if ( $setting.is('input[type="checkbox"]') ) {
  7566. value = $setting[0].checked;
  7567. }
  7568. // Update the corresponding setting.
  7569. this.model.set( $setting.data('setting'), value );
  7570. // If the setting has a corresponding user setting,
  7571. // update that as well.
  7572. userSetting = $setting.data('userSetting');
  7573. if ( userSetting ) {
  7574. window.setUserSetting( userSetting, value );
  7575. }
  7576. },
  7577. updateChanges: function( model ) {
  7578. if ( model.hasChanged() ) {
  7579. _( model.changed ).chain().keys().each( this.update, this );
  7580. }
  7581. }
  7582. });
  7583. module.exports = Settings;
  7584. /***/ }),
  7585. /***/ "ojD6":
  7586. /***/ (function(module, exports) {
  7587. var View = wp.media.View,
  7588. $ = jQuery,
  7589. Attachments,
  7590. infiniteScrolling = wp.media.view.settings.infiniteScrolling;
  7591. Attachments = View.extend(/** @lends wp.media.view.Attachments.prototype */{
  7592. tagName: 'ul',
  7593. className: 'attachments',
  7594. attributes: {
  7595. tabIndex: -1
  7596. },
  7597. /**
  7598. * Represents the overview of attachments in the Media Library.
  7599. *
  7600. * The constructor binds events to the collection this view represents when
  7601. * adding or removing attachments or resetting the entire collection.
  7602. *
  7603. * @since 3.5.0
  7604. *
  7605. * @constructs
  7606. * @memberof wp.media.view
  7607. *
  7608. * @augments wp.media.View
  7609. *
  7610. * @listens collection:add
  7611. * @listens collection:remove
  7612. * @listens collection:reset
  7613. * @listens controller:library:selection:add
  7614. * @listens scrollElement:scroll
  7615. * @listens this:ready
  7616. * @listens controller:open
  7617. */
  7618. initialize: function() {
  7619. this.el.id = _.uniqueId('__attachments-view-');
  7620. /**
  7621. * @since 5.8.0 Added the `infiniteScrolling` parameter.
  7622. *
  7623. * @param infiniteScrolling Whether to enable infinite scrolling or use
  7624. * the default "load more" button.
  7625. * @param refreshSensitivity The time in milliseconds to throttle the scroll
  7626. * handler.
  7627. * @param refreshThreshold The amount of pixels that should be scrolled before
  7628. * loading more attachments from the server.
  7629. * @param AttachmentView The view class to be used for models in the
  7630. * collection.
  7631. * @param sortable A jQuery sortable options object
  7632. * ( http://api.jqueryui.com/sortable/ ).
  7633. * @param resize A boolean indicating whether or not to listen to
  7634. * resize events.
  7635. * @param idealColumnWidth The width in pixels which a column should have when
  7636. * calculating the total number of columns.
  7637. */
  7638. _.defaults( this.options, {
  7639. infiniteScrolling: infiniteScrolling || false,
  7640. refreshSensitivity: wp.media.isTouchDevice ? 300 : 200,
  7641. refreshThreshold: 3,
  7642. AttachmentView: wp.media.view.Attachment,
  7643. sortable: false,
  7644. resize: true,
  7645. idealColumnWidth: $( window ).width() < 640 ? 135 : 150
  7646. });
  7647. this._viewsByCid = {};
  7648. this.$window = $( window );
  7649. this.resizeEvent = 'resize.media-modal-columns';
  7650. this.collection.on( 'add', function( attachment ) {
  7651. this.views.add( this.createAttachmentView( attachment ), {
  7652. at: this.collection.indexOf( attachment )
  7653. });
  7654. }, this );
  7655. /*
  7656. * Find the view to be removed, delete it and call the remove function to clear
  7657. * any set event handlers.
  7658. */
  7659. this.collection.on( 'remove', function( attachment ) {
  7660. var view = this._viewsByCid[ attachment.cid ];
  7661. delete this._viewsByCid[ attachment.cid ];
  7662. if ( view ) {
  7663. view.remove();
  7664. }
  7665. }, this );
  7666. this.collection.on( 'reset', this.render, this );
  7667. this.controller.on( 'library:selection:add', this.attachmentFocus, this );
  7668. if ( this.options.infiniteScrolling ) {
  7669. // Throttle the scroll handler and bind this.
  7670. this.scroll = _.chain( this.scroll ).bind( this ).throttle( this.options.refreshSensitivity ).value();
  7671. this.options.scrollElement = this.options.scrollElement || this.el;
  7672. $( this.options.scrollElement ).on( 'scroll', this.scroll );
  7673. }
  7674. this.initSortable();
  7675. _.bindAll( this, 'setColumns' );
  7676. if ( this.options.resize ) {
  7677. this.on( 'ready', this.bindEvents );
  7678. this.controller.on( 'open', this.setColumns );
  7679. /*
  7680. * Call this.setColumns() after this view has been rendered in the
  7681. * DOM so attachments get proper width applied.
  7682. */
  7683. _.defer( this.setColumns, this );
  7684. }
  7685. },
  7686. /**
  7687. * Listens to the resizeEvent on the window.
  7688. *
  7689. * Adjusts the amount of columns accordingly. First removes any existing event
  7690. * handlers to prevent duplicate listeners.
  7691. *
  7692. * @since 4.0.0
  7693. *
  7694. * @listens window:resize
  7695. *
  7696. * @return {void}
  7697. */
  7698. bindEvents: function() {
  7699. this.$window.off( this.resizeEvent ).on( this.resizeEvent, _.debounce( this.setColumns, 50 ) );
  7700. },
  7701. /**
  7702. * Focuses the first item in the collection.
  7703. *
  7704. * @since 4.0.0
  7705. *
  7706. * @return {void}
  7707. */
  7708. attachmentFocus: function() {
  7709. /*
  7710. * @todo When uploading new attachments, this tries to move focus to
  7711. * the attachments grid. Actually, a progress bar gets initially displayed
  7712. * and then updated when uploading completes, so focus is lost.
  7713. * Additionally: this view is used for both the attachments list and
  7714. * the list of selected attachments in the bottom media toolbar. Thus, when
  7715. * uploading attachments, it is called twice and returns two different `this`.
  7716. * `this.columns` is truthy within the modal.
  7717. */
  7718. if ( this.columns ) {
  7719. // Move focus to the grid list within the modal.
  7720. this.$el.focus();
  7721. }
  7722. },
  7723. /**
  7724. * Restores focus to the selected item in the collection.
  7725. *
  7726. * Moves focus back to the first selected attachment in the grid. Used when
  7727. * tabbing backwards from the attachment details sidebar.
  7728. * See media.view.AttachmentsBrowser.
  7729. *
  7730. * @since 4.0.0
  7731. *
  7732. * @return {void}
  7733. */
  7734. restoreFocus: function() {
  7735. this.$( 'li.selected:first' ).focus();
  7736. },
  7737. /**
  7738. * Handles events for arrow key presses.
  7739. *
  7740. * Focuses the attachment in the direction of the used arrow key if it exists.
  7741. *
  7742. * @since 4.0.0
  7743. *
  7744. * @param {KeyboardEvent} event The keyboard event that triggered this function.
  7745. *
  7746. * @return {void}
  7747. */
  7748. arrowEvent: function( event ) {
  7749. var attachments = this.$el.children( 'li' ),
  7750. perRow = this.columns,
  7751. index = attachments.filter( ':focus' ).index(),
  7752. row = ( index + 1 ) <= perRow ? 1 : Math.ceil( ( index + 1 ) / perRow );
  7753. if ( index === -1 ) {
  7754. return;
  7755. }
  7756. // Left arrow = 37.
  7757. if ( 37 === event.keyCode ) {
  7758. if ( 0 === index ) {
  7759. return;
  7760. }
  7761. attachments.eq( index - 1 ).focus();
  7762. }
  7763. // Up arrow = 38.
  7764. if ( 38 === event.keyCode ) {
  7765. if ( 1 === row ) {
  7766. return;
  7767. }
  7768. attachments.eq( index - perRow ).focus();
  7769. }
  7770. // Right arrow = 39.
  7771. if ( 39 === event.keyCode ) {
  7772. if ( attachments.length === index ) {
  7773. return;
  7774. }
  7775. attachments.eq( index + 1 ).focus();
  7776. }
  7777. // Down arrow = 40.
  7778. if ( 40 === event.keyCode ) {
  7779. if ( Math.ceil( attachments.length / perRow ) === row ) {
  7780. return;
  7781. }
  7782. attachments.eq( index + perRow ).focus();
  7783. }
  7784. },
  7785. /**
  7786. * Clears any set event handlers.
  7787. *
  7788. * @since 3.5.0
  7789. *
  7790. * @return {void}
  7791. */
  7792. dispose: function() {
  7793. this.collection.props.off( null, null, this );
  7794. if ( this.options.resize ) {
  7795. this.$window.off( this.resizeEvent );
  7796. }
  7797. // Call 'dispose' directly on the parent class.
  7798. View.prototype.dispose.apply( this, arguments );
  7799. },
  7800. /**
  7801. * Calculates the amount of columns.
  7802. *
  7803. * Calculates the amount of columns and sets it on the data-columns attribute
  7804. * of .media-frame-content.
  7805. *
  7806. * @since 4.0.0
  7807. *
  7808. * @return {void}
  7809. */
  7810. setColumns: function() {
  7811. var prev = this.columns,
  7812. width = this.$el.width();
  7813. if ( width ) {
  7814. this.columns = Math.min( Math.round( width / this.options.idealColumnWidth ), 12 ) || 1;
  7815. if ( ! prev || prev !== this.columns ) {
  7816. this.$el.closest( '.media-frame-content' ).attr( 'data-columns', this.columns );
  7817. }
  7818. }
  7819. },
  7820. /**
  7821. * Initializes jQuery sortable on the attachment list.
  7822. *
  7823. * Fails gracefully if jQuery sortable doesn't exist or isn't passed
  7824. * in the options.
  7825. *
  7826. * @since 3.5.0
  7827. *
  7828. * @fires collection:reset
  7829. *
  7830. * @return {void}
  7831. */
  7832. initSortable: function() {
  7833. var collection = this.collection;
  7834. if ( ! this.options.sortable || ! $.fn.sortable ) {
  7835. return;
  7836. }
  7837. this.$el.sortable( _.extend({
  7838. // If the `collection` has a `comparator`, disable sorting.
  7839. disabled: !! collection.comparator,
  7840. /*
  7841. * Change the position of the attachment as soon as the mouse pointer
  7842. * overlaps a thumbnail.
  7843. */
  7844. tolerance: 'pointer',
  7845. // Record the initial `index` of the dragged model.
  7846. start: function( event, ui ) {
  7847. ui.item.data('sortableIndexStart', ui.item.index());
  7848. },
  7849. /*
  7850. * Update the model's index in the collection. Do so silently, as the view
  7851. * is already accurate.
  7852. */
  7853. update: function( event, ui ) {
  7854. var model = collection.at( ui.item.data('sortableIndexStart') ),
  7855. comparator = collection.comparator;
  7856. // Temporarily disable the comparator to prevent `add`
  7857. // from re-sorting.
  7858. delete collection.comparator;
  7859. // Silently shift the model to its new index.
  7860. collection.remove( model, {
  7861. silent: true
  7862. });
  7863. collection.add( model, {
  7864. silent: true,
  7865. at: ui.item.index()
  7866. });
  7867. // Restore the comparator.
  7868. collection.comparator = comparator;
  7869. // Fire the `reset` event to ensure other collections sync.
  7870. collection.trigger( 'reset', collection );
  7871. // If the collection is sorted by menu order, update the menu order.
  7872. collection.saveMenuOrder();
  7873. }
  7874. }, this.options.sortable ) );
  7875. /*
  7876. * If the `orderby` property is changed on the `collection`,
  7877. * check to see if we have a `comparator`. If so, disable sorting.
  7878. */
  7879. collection.props.on( 'change:orderby', function() {
  7880. this.$el.sortable( 'option', 'disabled', !! collection.comparator );
  7881. }, this );
  7882. this.collection.props.on( 'change:orderby', this.refreshSortable, this );
  7883. this.refreshSortable();
  7884. },
  7885. /**
  7886. * Disables jQuery sortable if collection has a comparator or collection.orderby
  7887. * equals menuOrder.
  7888. *
  7889. * @since 3.5.0
  7890. *
  7891. * @return {void}
  7892. */
  7893. refreshSortable: function() {
  7894. if ( ! this.options.sortable || ! $.fn.sortable ) {
  7895. return;
  7896. }
  7897. var collection = this.collection,
  7898. orderby = collection.props.get('orderby'),
  7899. enabled = 'menuOrder' === orderby || ! collection.comparator;
  7900. this.$el.sortable( 'option', 'disabled', ! enabled );
  7901. },
  7902. /**
  7903. * Creates a new view for an attachment and adds it to _viewsByCid.
  7904. *
  7905. * @since 3.5.0
  7906. *
  7907. * @param {wp.media.model.Attachment} attachment
  7908. *
  7909. * @return {wp.media.View} The created view.
  7910. */
  7911. createAttachmentView: function( attachment ) {
  7912. var view = new this.options.AttachmentView({
  7913. controller: this.controller,
  7914. model: attachment,
  7915. collection: this.collection,
  7916. selection: this.options.selection
  7917. });
  7918. return this._viewsByCid[ attachment.cid ] = view;
  7919. },
  7920. /**
  7921. * Prepares view for display.
  7922. *
  7923. * Creates views for every attachment in collection if the collection is not
  7924. * empty, otherwise clears all views and loads more attachments.
  7925. *
  7926. * @since 3.5.0
  7927. *
  7928. * @return {void}
  7929. */
  7930. prepare: function() {
  7931. if ( this.collection.length ) {
  7932. this.views.set( this.collection.map( this.createAttachmentView, this ) );
  7933. } else {
  7934. this.views.unset();
  7935. if ( this.options.infiniteScrolling ) {
  7936. this.collection.more().done( this.scroll );
  7937. }
  7938. }
  7939. },
  7940. /**
  7941. * Triggers the scroll function to check if we should query for additional
  7942. * attachments right away.
  7943. *
  7944. * @since 3.5.0
  7945. *
  7946. * @return {void}
  7947. */
  7948. ready: function() {
  7949. if ( this.options.infiniteScrolling ) {
  7950. this.scroll();
  7951. }
  7952. },
  7953. /**
  7954. * Handles scroll events.
  7955. *
  7956. * Shows the spinner if we're close to the bottom. Loads more attachments from
  7957. * server if we're {refreshThreshold} times away from the bottom.
  7958. *
  7959. * @since 3.5.0
  7960. *
  7961. * @return {void}
  7962. */
  7963. scroll: function() {
  7964. var view = this,
  7965. el = this.options.scrollElement,
  7966. scrollTop = el.scrollTop,
  7967. toolbar;
  7968. /*
  7969. * The scroll event occurs on the document, but the element that should be
  7970. * checked is the document body.
  7971. */
  7972. if ( el === document ) {
  7973. el = document.body;
  7974. scrollTop = $(document).scrollTop();
  7975. }
  7976. if ( ! $(el).is(':visible') || ! this.collection.hasMore() ) {
  7977. return;
  7978. }
  7979. toolbar = this.views.parent.toolbar;
  7980. // Show the spinner only if we are close to the bottom.
  7981. if ( el.scrollHeight - ( scrollTop + el.clientHeight ) < el.clientHeight / 3 ) {
  7982. toolbar.get('spinner').show();
  7983. }
  7984. if ( el.scrollHeight < scrollTop + ( el.clientHeight * this.options.refreshThreshold ) ) {
  7985. this.collection.more().done(function() {
  7986. view.scroll();
  7987. toolbar.get('spinner').hide();
  7988. });
  7989. }
  7990. }
  7991. });
  7992. module.exports = Attachments;
  7993. /***/ }),
  7994. /***/ "qe5n":
  7995. /***/ (function(module, exports) {
  7996. var l10n = wp.media.view.l10n,
  7997. $ = Backbone.$,
  7998. Embed;
  7999. /**
  8000. * wp.media.controller.Embed
  8001. *
  8002. * A state for embedding media from a URL.
  8003. *
  8004. * @memberOf wp.media.controller
  8005. *
  8006. * @class
  8007. * @augments wp.media.controller.State
  8008. * @augments Backbone.Model
  8009. *
  8010. * @param {object} attributes The attributes hash passed to the state.
  8011. * @param {string} [attributes.id=embed] Unique identifier.
  8012. * @param {string} [attributes.title=Insert From URL] Title for the state. Displays in the media menu and the frame's title region.
  8013. * @param {string} [attributes.content=embed] Initial mode for the content region.
  8014. * @param {string} [attributes.menu=default] Initial mode for the menu region.
  8015. * @param {string} [attributes.toolbar=main-embed] Initial mode for the toolbar region.
  8016. * @param {string} [attributes.menu=false] Initial mode for the menu region.
  8017. * @param {int} [attributes.priority=120] The priority for the state link in the media menu.
  8018. * @param {string} [attributes.type=link] The type of embed. Currently only link is supported.
  8019. * @param {string} [attributes.url] The embed URL.
  8020. * @param {object} [attributes.metadata={}] Properties of the embed, which will override attributes.url if set.
  8021. */
  8022. Embed = wp.media.controller.State.extend(/** @lends wp.media.controller.Embed.prototype */{
  8023. defaults: {
  8024. id: 'embed',
  8025. title: l10n.insertFromUrlTitle,
  8026. content: 'embed',
  8027. menu: 'default',
  8028. toolbar: 'main-embed',
  8029. priority: 120,
  8030. type: 'link',
  8031. url: '',
  8032. metadata: {}
  8033. },
  8034. // The amount of time used when debouncing the scan.
  8035. sensitivity: 400,
  8036. initialize: function(options) {
  8037. this.metadata = options.metadata;
  8038. this.debouncedScan = _.debounce( _.bind( this.scan, this ), this.sensitivity );
  8039. this.props = new Backbone.Model( this.metadata || { url: '' });
  8040. this.props.on( 'change:url', this.debouncedScan, this );
  8041. this.props.on( 'change:url', this.refresh, this );
  8042. this.on( 'scan', this.scanImage, this );
  8043. },
  8044. /**
  8045. * Trigger a scan of the embedded URL's content for metadata required to embed.
  8046. *
  8047. * @fires wp.media.controller.Embed#scan
  8048. */
  8049. scan: function() {
  8050. var scanners,
  8051. embed = this,
  8052. attributes = {
  8053. type: 'link',
  8054. scanners: []
  8055. };
  8056. /*
  8057. * Scan is triggered with the list of `attributes` to set on the
  8058. * state, useful for the 'type' attribute and 'scanners' attribute,
  8059. * an array of promise objects for asynchronous scan operations.
  8060. */
  8061. if ( this.props.get('url') ) {
  8062. this.trigger( 'scan', attributes );
  8063. }
  8064. if ( attributes.scanners.length ) {
  8065. scanners = attributes.scanners = $.when.apply( $, attributes.scanners );
  8066. scanners.always( function() {
  8067. if ( embed.get('scanners') === scanners ) {
  8068. embed.set( 'loading', false );
  8069. }
  8070. });
  8071. } else {
  8072. attributes.scanners = null;
  8073. }
  8074. attributes.loading = !! attributes.scanners;
  8075. this.set( attributes );
  8076. },
  8077. /**
  8078. * Try scanning the embed as an image to discover its dimensions.
  8079. *
  8080. * @param {Object} attributes
  8081. */
  8082. scanImage: function( attributes ) {
  8083. var frame = this.frame,
  8084. state = this,
  8085. url = this.props.get('url'),
  8086. image = new Image(),
  8087. deferred = $.Deferred();
  8088. attributes.scanners.push( deferred.promise() );
  8089. // Try to load the image and find its width/height.
  8090. image.onload = function() {
  8091. deferred.resolve();
  8092. if ( state !== frame.state() || url !== state.props.get('url') ) {
  8093. return;
  8094. }
  8095. state.set({
  8096. type: 'image'
  8097. });
  8098. state.props.set({
  8099. width: image.width,
  8100. height: image.height
  8101. });
  8102. };
  8103. image.onerror = deferred.reject;
  8104. image.src = url;
  8105. },
  8106. refresh: function() {
  8107. this.frame.toolbar.get().refresh();
  8108. },
  8109. reset: function() {
  8110. this.props.clear().set({ url: '' });
  8111. if ( this.active ) {
  8112. this.refresh();
  8113. }
  8114. }
  8115. });
  8116. module.exports = Embed;
  8117. /***/ }),
  8118. /***/ "sULL":
  8119. /***/ (function(module, exports) {
  8120. var View = wp.media.View,
  8121. $ = jQuery,
  8122. Attachment;
  8123. /**
  8124. * wp.media.view.Attachment
  8125. *
  8126. * @memberOf wp.media.view
  8127. *
  8128. * @class
  8129. * @augments wp.media.View
  8130. * @augments wp.Backbone.View
  8131. * @augments Backbone.View
  8132. */
  8133. Attachment = View.extend(/** @lends wp.media.view.Attachment.prototype */{
  8134. tagName: 'li',
  8135. className: 'attachment',
  8136. template: wp.template('attachment'),
  8137. attributes: function() {
  8138. return {
  8139. 'tabIndex': 0,
  8140. 'role': 'checkbox',
  8141. 'aria-label': this.model.get( 'title' ),
  8142. 'aria-checked': false,
  8143. 'data-id': this.model.get( 'id' )
  8144. };
  8145. },
  8146. events: {
  8147. 'click': 'toggleSelectionHandler',
  8148. 'change [data-setting]': 'updateSetting',
  8149. 'change [data-setting] input': 'updateSetting',
  8150. 'change [data-setting] select': 'updateSetting',
  8151. 'change [data-setting] textarea': 'updateSetting',
  8152. 'click .attachment-close': 'removeFromLibrary',
  8153. 'click .check': 'checkClickHandler',
  8154. 'keydown': 'toggleSelectionHandler'
  8155. },
  8156. buttons: {},
  8157. initialize: function() {
  8158. var selection = this.options.selection,
  8159. options = _.defaults( this.options, {
  8160. rerenderOnModelChange: true
  8161. } );
  8162. if ( options.rerenderOnModelChange ) {
  8163. this.listenTo( this.model, 'change', this.render );
  8164. } else {
  8165. this.listenTo( this.model, 'change:percent', this.progress );
  8166. }
  8167. this.listenTo( this.model, 'change:title', this._syncTitle );
  8168. this.listenTo( this.model, 'change:caption', this._syncCaption );
  8169. this.listenTo( this.model, 'change:artist', this._syncArtist );
  8170. this.listenTo( this.model, 'change:album', this._syncAlbum );
  8171. // Update the selection.
  8172. this.listenTo( this.model, 'add', this.select );
  8173. this.listenTo( this.model, 'remove', this.deselect );
  8174. if ( selection ) {
  8175. selection.on( 'reset', this.updateSelect, this );
  8176. // Update the model's details view.
  8177. this.listenTo( this.model, 'selection:single selection:unsingle', this.details );
  8178. this.details( this.model, this.controller.state().get('selection') );
  8179. }
  8180. this.listenTo( this.controller.states, 'attachment:compat:waiting attachment:compat:ready', this.updateSave );
  8181. },
  8182. /**
  8183. * @return {wp.media.view.Attachment} Returns itself to allow chaining.
  8184. */
  8185. dispose: function() {
  8186. var selection = this.options.selection;
  8187. // Make sure all settings are saved before removing the view.
  8188. this.updateAll();
  8189. if ( selection ) {
  8190. selection.off( null, null, this );
  8191. }
  8192. /**
  8193. * call 'dispose' directly on the parent class
  8194. */
  8195. View.prototype.dispose.apply( this, arguments );
  8196. return this;
  8197. },
  8198. /**
  8199. * @return {wp.media.view.Attachment} Returns itself to allow chaining.
  8200. */
  8201. render: function() {
  8202. var options = _.defaults( this.model.toJSON(), {
  8203. orientation: 'landscape',
  8204. uploading: false,
  8205. type: '',
  8206. subtype: '',
  8207. icon: '',
  8208. filename: '',
  8209. caption: '',
  8210. title: '',
  8211. dateFormatted: '',
  8212. width: '',
  8213. height: '',
  8214. compat: false,
  8215. alt: '',
  8216. description: ''
  8217. }, this.options );
  8218. options.buttons = this.buttons;
  8219. options.describe = this.controller.state().get('describe');
  8220. if ( 'image' === options.type ) {
  8221. options.size = this.imageSize();
  8222. }
  8223. options.can = {};
  8224. if ( options.nonces ) {
  8225. options.can.remove = !! options.nonces['delete'];
  8226. options.can.save = !! options.nonces.update;
  8227. }
  8228. if ( this.controller.state().get('allowLocalEdits') ) {
  8229. options.allowLocalEdits = true;
  8230. }
  8231. if ( options.uploading && ! options.percent ) {
  8232. options.percent = 0;
  8233. }
  8234. this.views.detach();
  8235. this.$el.html( this.template( options ) );
  8236. this.$el.toggleClass( 'uploading', options.uploading );
  8237. if ( options.uploading ) {
  8238. this.$bar = this.$('.media-progress-bar div');
  8239. } else {
  8240. delete this.$bar;
  8241. }
  8242. // Check if the model is selected.
  8243. this.updateSelect();
  8244. // Update the save status.
  8245. this.updateSave();
  8246. this.views.render();
  8247. return this;
  8248. },
  8249. progress: function() {
  8250. if ( this.$bar && this.$bar.length ) {
  8251. this.$bar.width( this.model.get('percent') + '%' );
  8252. }
  8253. },
  8254. /**
  8255. * @param {Object} event
  8256. */
  8257. toggleSelectionHandler: function( event ) {
  8258. var method;
  8259. // Don't do anything inside inputs and on the attachment check and remove buttons.
  8260. if ( 'INPUT' === event.target.nodeName || 'BUTTON' === event.target.nodeName ) {
  8261. return;
  8262. }
  8263. // Catch arrow events.
  8264. if ( 37 === event.keyCode || 38 === event.keyCode || 39 === event.keyCode || 40 === event.keyCode ) {
  8265. this.controller.trigger( 'attachment:keydown:arrow', event );
  8266. return;
  8267. }
  8268. // Catch enter and space events.
  8269. if ( 'keydown' === event.type && 13 !== event.keyCode && 32 !== event.keyCode ) {
  8270. return;
  8271. }
  8272. event.preventDefault();
  8273. // In the grid view, bubble up an edit:attachment event to the controller.
  8274. if ( this.controller.isModeActive( 'grid' ) ) {
  8275. if ( this.controller.isModeActive( 'edit' ) ) {
  8276. // Pass the current target to restore focus when closing.
  8277. this.controller.trigger( 'edit:attachment', this.model, event.currentTarget );
  8278. return;
  8279. }
  8280. if ( this.controller.isModeActive( 'select' ) ) {
  8281. method = 'toggle';
  8282. }
  8283. }
  8284. if ( event.shiftKey ) {
  8285. method = 'between';
  8286. } else if ( event.ctrlKey || event.metaKey ) {
  8287. method = 'toggle';
  8288. }
  8289. this.toggleSelection({
  8290. method: method
  8291. });
  8292. this.controller.trigger( 'selection:toggle' );
  8293. },
  8294. /**
  8295. * @param {Object} options
  8296. */
  8297. toggleSelection: function( options ) {
  8298. var collection = this.collection,
  8299. selection = this.options.selection,
  8300. model = this.model,
  8301. method = options && options.method,
  8302. single, models, singleIndex, modelIndex;
  8303. if ( ! selection ) {
  8304. return;
  8305. }
  8306. single = selection.single();
  8307. method = _.isUndefined( method ) ? selection.multiple : method;
  8308. // If the `method` is set to `between`, select all models that
  8309. // exist between the current and the selected model.
  8310. if ( 'between' === method && single && selection.multiple ) {
  8311. // If the models are the same, short-circuit.
  8312. if ( single === model ) {
  8313. return;
  8314. }
  8315. singleIndex = collection.indexOf( single );
  8316. modelIndex = collection.indexOf( this.model );
  8317. if ( singleIndex < modelIndex ) {
  8318. models = collection.models.slice( singleIndex, modelIndex + 1 );
  8319. } else {
  8320. models = collection.models.slice( modelIndex, singleIndex + 1 );
  8321. }
  8322. selection.add( models );
  8323. selection.single( model );
  8324. return;
  8325. // If the `method` is set to `toggle`, just flip the selection
  8326. // status, regardless of whether the model is the single model.
  8327. } else if ( 'toggle' === method ) {
  8328. selection[ this.selected() ? 'remove' : 'add' ]( model );
  8329. selection.single( model );
  8330. return;
  8331. } else if ( 'add' === method ) {
  8332. selection.add( model );
  8333. selection.single( model );
  8334. return;
  8335. }
  8336. // Fixes bug that loses focus when selecting a featured image.
  8337. if ( ! method ) {
  8338. method = 'add';
  8339. }
  8340. if ( method !== 'add' ) {
  8341. method = 'reset';
  8342. }
  8343. if ( this.selected() ) {
  8344. /*
  8345. * If the model is the single model, remove it.
  8346. * If it is not the same as the single model,
  8347. * it now becomes the single model.
  8348. */
  8349. selection[ single === model ? 'remove' : 'single' ]( model );
  8350. } else {
  8351. /*
  8352. * If the model is not selected, run the `method` on the
  8353. * selection. By default, we `reset` the selection, but the
  8354. * `method` can be set to `add` the model to the selection.
  8355. */
  8356. selection[ method ]( model );
  8357. selection.single( model );
  8358. }
  8359. },
  8360. updateSelect: function() {
  8361. this[ this.selected() ? 'select' : 'deselect' ]();
  8362. },
  8363. /**
  8364. * @return {unresolved|boolean}
  8365. */
  8366. selected: function() {
  8367. var selection = this.options.selection;
  8368. if ( selection ) {
  8369. return !! selection.get( this.model.cid );
  8370. }
  8371. },
  8372. /**
  8373. * @param {Backbone.Model} model
  8374. * @param {Backbone.Collection} collection
  8375. */
  8376. select: function( model, collection ) {
  8377. var selection = this.options.selection,
  8378. controller = this.controller;
  8379. /*
  8380. * Check if a selection exists and if it's the collection provided.
  8381. * If they're not the same collection, bail; we're in another
  8382. * selection's event loop.
  8383. */
  8384. if ( ! selection || ( collection && collection !== selection ) ) {
  8385. return;
  8386. }
  8387. // Bail if the model is already selected.
  8388. if ( this.$el.hasClass( 'selected' ) ) {
  8389. return;
  8390. }
  8391. // Add 'selected' class to model, set aria-checked to true.
  8392. this.$el.addClass( 'selected' ).attr( 'aria-checked', true );
  8393. // Make the checkbox tabable, except in media grid (bulk select mode).
  8394. if ( ! ( controller.isModeActive( 'grid' ) && controller.isModeActive( 'select' ) ) ) {
  8395. this.$( '.check' ).attr( 'tabindex', '0' );
  8396. }
  8397. },
  8398. /**
  8399. * @param {Backbone.Model} model
  8400. * @param {Backbone.Collection} collection
  8401. */
  8402. deselect: function( model, collection ) {
  8403. var selection = this.options.selection;
  8404. /*
  8405. * Check if a selection exists and if it's the collection provided.
  8406. * If they're not the same collection, bail; we're in another
  8407. * selection's event loop.
  8408. */
  8409. if ( ! selection || ( collection && collection !== selection ) ) {
  8410. return;
  8411. }
  8412. this.$el.removeClass( 'selected' ).attr( 'aria-checked', false )
  8413. .find( '.check' ).attr( 'tabindex', '-1' );
  8414. },
  8415. /**
  8416. * @param {Backbone.Model} model
  8417. * @param {Backbone.Collection} collection
  8418. */
  8419. details: function( model, collection ) {
  8420. var selection = this.options.selection,
  8421. details;
  8422. if ( selection !== collection ) {
  8423. return;
  8424. }
  8425. details = selection.single();
  8426. this.$el.toggleClass( 'details', details === this.model );
  8427. },
  8428. /**
  8429. * @param {string} size
  8430. * @return {Object}
  8431. */
  8432. imageSize: function( size ) {
  8433. var sizes = this.model.get('sizes'), matched = false;
  8434. size = size || 'medium';
  8435. // Use the provided image size if possible.
  8436. if ( sizes ) {
  8437. if ( sizes[ size ] ) {
  8438. matched = sizes[ size ];
  8439. } else if ( sizes.large ) {
  8440. matched = sizes.large;
  8441. } else if ( sizes.thumbnail ) {
  8442. matched = sizes.thumbnail;
  8443. } else if ( sizes.full ) {
  8444. matched = sizes.full;
  8445. }
  8446. if ( matched ) {
  8447. return _.clone( matched );
  8448. }
  8449. }
  8450. return {
  8451. url: this.model.get('url'),
  8452. width: this.model.get('width'),
  8453. height: this.model.get('height'),
  8454. orientation: this.model.get('orientation')
  8455. };
  8456. },
  8457. /**
  8458. * @param {Object} event
  8459. */
  8460. updateSetting: function( event ) {
  8461. var $setting = $( event.target ).closest('[data-setting]'),
  8462. setting, value;
  8463. if ( ! $setting.length ) {
  8464. return;
  8465. }
  8466. setting = $setting.data('setting');
  8467. value = event.target.value;
  8468. if ( this.model.get( setting ) !== value ) {
  8469. this.save( setting, value );
  8470. }
  8471. },
  8472. /**
  8473. * Pass all the arguments to the model's save method.
  8474. *
  8475. * Records the aggregate status of all save requests and updates the
  8476. * view's classes accordingly.
  8477. */
  8478. save: function() {
  8479. var view = this,
  8480. save = this._save = this._save || { status: 'ready' },
  8481. request = this.model.save.apply( this.model, arguments ),
  8482. requests = save.requests ? $.when( request, save.requests ) : request;
  8483. // If we're waiting to remove 'Saved.', stop.
  8484. if ( save.savedTimer ) {
  8485. clearTimeout( save.savedTimer );
  8486. }
  8487. this.updateSave('waiting');
  8488. save.requests = requests;
  8489. requests.always( function() {
  8490. // If we've performed another request since this one, bail.
  8491. if ( save.requests !== requests ) {
  8492. return;
  8493. }
  8494. view.updateSave( requests.state() === 'resolved' ? 'complete' : 'error' );
  8495. save.savedTimer = setTimeout( function() {
  8496. view.updateSave('ready');
  8497. delete save.savedTimer;
  8498. }, 2000 );
  8499. });
  8500. },
  8501. /**
  8502. * @param {string} status
  8503. * @return {wp.media.view.Attachment} Returns itself to allow chaining.
  8504. */
  8505. updateSave: function( status ) {
  8506. var save = this._save = this._save || { status: 'ready' };
  8507. if ( status && status !== save.status ) {
  8508. this.$el.removeClass( 'save-' + save.status );
  8509. save.status = status;
  8510. }
  8511. this.$el.addClass( 'save-' + save.status );
  8512. return this;
  8513. },
  8514. updateAll: function() {
  8515. var $settings = this.$('[data-setting]'),
  8516. model = this.model,
  8517. changed;
  8518. changed = _.chain( $settings ).map( function( el ) {
  8519. var $input = $('input, textarea, select, [value]', el ),
  8520. setting, value;
  8521. if ( ! $input.length ) {
  8522. return;
  8523. }
  8524. setting = $(el).data('setting');
  8525. value = $input.val();
  8526. // Record the value if it changed.
  8527. if ( model.get( setting ) !== value ) {
  8528. return [ setting, value ];
  8529. }
  8530. }).compact().object().value();
  8531. if ( ! _.isEmpty( changed ) ) {
  8532. model.save( changed );
  8533. }
  8534. },
  8535. /**
  8536. * @param {Object} event
  8537. */
  8538. removeFromLibrary: function( event ) {
  8539. // Catch enter and space events.
  8540. if ( 'keydown' === event.type && 13 !== event.keyCode && 32 !== event.keyCode ) {
  8541. return;
  8542. }
  8543. // Stop propagation so the model isn't selected.
  8544. event.stopPropagation();
  8545. this.collection.remove( this.model );
  8546. },
  8547. /**
  8548. * Add the model if it isn't in the selection, if it is in the selection,
  8549. * remove it.
  8550. *
  8551. * @param {[type]} event [description]
  8552. * @return {[type]} [description]
  8553. */
  8554. checkClickHandler: function ( event ) {
  8555. var selection = this.options.selection;
  8556. if ( ! selection ) {
  8557. return;
  8558. }
  8559. event.stopPropagation();
  8560. if ( selection.where( { id: this.model.get( 'id' ) } ).length ) {
  8561. selection.remove( this.model );
  8562. // Move focus back to the attachment tile (from the check).
  8563. this.$el.focus();
  8564. } else {
  8565. selection.add( this.model );
  8566. }
  8567. // Trigger an action button update.
  8568. this.controller.trigger( 'selection:toggle' );
  8569. }
  8570. });
  8571. // Ensure settings remain in sync between attachment views.
  8572. _.each({
  8573. caption: '_syncCaption',
  8574. title: '_syncTitle',
  8575. artist: '_syncArtist',
  8576. album: '_syncAlbum'
  8577. }, function( method, setting ) {
  8578. /**
  8579. * @function _syncCaption
  8580. * @memberOf wp.media.view.Attachment
  8581. * @instance
  8582. *
  8583. * @param {Backbone.Model} model
  8584. * @param {string} value
  8585. * @return {wp.media.view.Attachment} Returns itself to allow chaining.
  8586. */
  8587. /**
  8588. * @function _syncTitle
  8589. * @memberOf wp.media.view.Attachment
  8590. * @instance
  8591. *
  8592. * @param {Backbone.Model} model
  8593. * @param {string} value
  8594. * @return {wp.media.view.Attachment} Returns itself to allow chaining.
  8595. */
  8596. /**
  8597. * @function _syncArtist
  8598. * @memberOf wp.media.view.Attachment
  8599. * @instance
  8600. *
  8601. * @param {Backbone.Model} model
  8602. * @param {string} value
  8603. * @return {wp.media.view.Attachment} Returns itself to allow chaining.
  8604. */
  8605. /**
  8606. * @function _syncAlbum
  8607. * @memberOf wp.media.view.Attachment
  8608. * @instance
  8609. *
  8610. * @param {Backbone.Model} model
  8611. * @param {string} value
  8612. * @return {wp.media.view.Attachment} Returns itself to allow chaining.
  8613. */
  8614. Attachment.prototype[ method ] = function( model, value ) {
  8615. var $setting = this.$('[data-setting="' + setting + '"]');
  8616. if ( ! $setting.length ) {
  8617. return this;
  8618. }
  8619. /*
  8620. * If the updated value is in sync with the value in the DOM, there
  8621. * is no need to re-render. If we're currently editing the value,
  8622. * it will automatically be in sync, suppressing the re-render for
  8623. * the view we're editing, while updating any others.
  8624. */
  8625. if ( value === $setting.find('input, textarea, select, [value]').val() ) {
  8626. return this;
  8627. }
  8628. return this.render();
  8629. };
  8630. });
  8631. module.exports = Attachment;
  8632. /***/ }),
  8633. /***/ "t3nl":
  8634. /***/ (function(module, exports) {
  8635. /**
  8636. * wp.media.view.Iframe
  8637. *
  8638. * @memberOf wp.media.view
  8639. *
  8640. * @class
  8641. * @augments wp.media.View
  8642. * @augments wp.Backbone.View
  8643. * @augments Backbone.View
  8644. */
  8645. var Iframe = wp.media.View.extend(/** @lends wp.media.view.Iframe.prototype */{
  8646. className: 'media-iframe',
  8647. /**
  8648. * @return {wp.media.view.Iframe} Returns itself to allow chaining.
  8649. */
  8650. render: function() {
  8651. this.views.detach();
  8652. this.$el.html( '<iframe src="' + this.controller.state().get('src') + '" />' );
  8653. this.views.render();
  8654. return this;
  8655. }
  8656. });
  8657. module.exports = Iframe;
  8658. /***/ }),
  8659. /***/ "tg/Y":
  8660. /***/ (function(module, exports, __webpack_require__) {
  8661. /**
  8662. * @output wp-includes/js/media-views.js
  8663. */
  8664. var media = wp.media,
  8665. $ = jQuery,
  8666. l10n;
  8667. media.isTouchDevice = ( 'ontouchend' in document );
  8668. // Link any localized strings.
  8669. l10n = media.view.l10n = window._wpMediaViewsL10n || {};
  8670. // Link any settings.
  8671. media.view.settings = l10n.settings || {};
  8672. delete l10n.settings;
  8673. // Copy the `post` setting over to the model settings.
  8674. media.model.settings.post = media.view.settings.post;
  8675. // Check if the browser supports CSS 3.0 transitions.
  8676. $.support.transition = (function(){
  8677. var style = document.documentElement.style,
  8678. transitions = {
  8679. WebkitTransition: 'webkitTransitionEnd',
  8680. MozTransition: 'transitionend',
  8681. OTransition: 'oTransitionEnd otransitionend',
  8682. transition: 'transitionend'
  8683. }, transition;
  8684. transition = _.find( _.keys( transitions ), function( transition ) {
  8685. return ! _.isUndefined( style[ transition ] );
  8686. });
  8687. return transition && {
  8688. end: transitions[ transition ]
  8689. };
  8690. }());
  8691. /**
  8692. * A shared event bus used to provide events into
  8693. * the media workflows that 3rd-party devs can use to hook
  8694. * in.
  8695. */
  8696. media.events = _.extend( {}, Backbone.Events );
  8697. /**
  8698. * Makes it easier to bind events using transitions.
  8699. *
  8700. * @param {string} selector
  8701. * @param {number} sensitivity
  8702. * @return {Promise}
  8703. */
  8704. media.transition = function( selector, sensitivity ) {
  8705. var deferred = $.Deferred();
  8706. sensitivity = sensitivity || 2000;
  8707. if ( $.support.transition ) {
  8708. if ( ! (selector instanceof $) ) {
  8709. selector = $( selector );
  8710. }
  8711. // Resolve the deferred when the first element finishes animating.
  8712. selector.first().one( $.support.transition.end, deferred.resolve );
  8713. // Just in case the event doesn't trigger, fire a callback.
  8714. _.delay( deferred.resolve, sensitivity );
  8715. // Otherwise, execute on the spot.
  8716. } else {
  8717. deferred.resolve();
  8718. }
  8719. return deferred.promise();
  8720. };
  8721. media.controller.Region = __webpack_require__( "WiNq" );
  8722. media.controller.StateMachine = __webpack_require__( "U3Se" );
  8723. media.controller.State = __webpack_require__( "M5ZC" );
  8724. media.selectionSync = __webpack_require__( "PgTd" );
  8725. media.controller.Library = __webpack_require__( "F/kE" );
  8726. media.controller.ImageDetails = __webpack_require__( "IkWq" );
  8727. media.controller.GalleryEdit = __webpack_require__( "99yY" );
  8728. media.controller.GalleryAdd = __webpack_require__( "ng6N" );
  8729. media.controller.CollectionEdit = __webpack_require__( "Mt+m" );
  8730. media.controller.CollectionAdd = __webpack_require__( "iipZ" );
  8731. media.controller.FeaturedImage = __webpack_require__( "I7TD" );
  8732. media.controller.ReplaceImage = __webpack_require__( "aBqq" );
  8733. media.controller.EditImage = __webpack_require__( "4tHu" );
  8734. media.controller.MediaLibrary = __webpack_require__( "mVaH" );
  8735. media.controller.Embed = __webpack_require__( "qe5n" );
  8736. media.controller.Cropper = __webpack_require__( "M+xU" );
  8737. media.controller.CustomizeImageCropper = __webpack_require__( "eqTc" );
  8738. media.controller.SiteIconCropper = __webpack_require__( "W+32" );
  8739. media.View = __webpack_require__( "Bbnu" );
  8740. media.view.Frame = __webpack_require__( "LGdN" );
  8741. media.view.MediaFrame = __webpack_require__( "Pt9x" );
  8742. media.view.MediaFrame.Select = __webpack_require__( "fYN4" );
  8743. media.view.MediaFrame.Post = __webpack_require__( "6B7g" );
  8744. media.view.MediaFrame.ImageDetails = __webpack_require__( "VIJ9" );
  8745. media.view.Modal = __webpack_require__( "gOpb" );
  8746. media.view.FocusManager = __webpack_require__( "3nJM" );
  8747. media.view.UploaderWindow = __webpack_require__( "S4jH" );
  8748. media.view.EditorUploader = __webpack_require__( "GXkx" );
  8749. media.view.UploaderInline = __webpack_require__( "7Bpz" );
  8750. media.view.UploaderStatus = __webpack_require__( "NguE" );
  8751. media.view.UploaderStatusError = __webpack_require__( "ZeG4" );
  8752. media.view.Toolbar = __webpack_require__( "2NU8" );
  8753. media.view.Toolbar.Select = __webpack_require__( "IgEq" );
  8754. media.view.Toolbar.Embed = __webpack_require__( "xQvM" );
  8755. media.view.Button = __webpack_require__( "LZpE" );
  8756. media.view.ButtonGroup = __webpack_require__( "z/+l" );
  8757. media.view.PriorityList = __webpack_require__( "NjyZ" );
  8758. media.view.MenuItem = __webpack_require__( "dpRc" );
  8759. media.view.Menu = __webpack_require__( "Ju2C" );
  8760. media.view.RouterItem = __webpack_require__( "Q9T/" );
  8761. media.view.Router = __webpack_require__( "EVvK" );
  8762. media.view.Sidebar = __webpack_require__( "9ARG" );
  8763. media.view.Attachment = __webpack_require__( "sULL" );
  8764. media.view.Attachment.Library = __webpack_require__( "2jku" );
  8765. media.view.Attachment.EditLibrary = __webpack_require__( "EvXF" );
  8766. media.view.Attachments = __webpack_require__( "ojD6" );
  8767. media.view.Search = __webpack_require__( "ZgZ7" );
  8768. media.view.AttachmentFilters = __webpack_require__( "1S4+" );
  8769. media.view.DateFilter = __webpack_require__( "VkcK" );
  8770. media.view.AttachmentFilters.Uploaded = __webpack_require__( "4jjk" );
  8771. media.view.AttachmentFilters.All = __webpack_require__( "KerO" );
  8772. media.view.AttachmentsBrowser = __webpack_require__( "72mI" );
  8773. media.view.Selection = __webpack_require__( "04Ix" );
  8774. media.view.Attachment.Selection = __webpack_require__( "yGM1" );
  8775. media.view.Attachments.Selection = __webpack_require__( "wfCN" );
  8776. media.view.Attachment.EditSelection = __webpack_require__( "P6DV" );
  8777. media.view.Settings = __webpack_require__( "nwwF" );
  8778. media.view.Settings.AttachmentDisplay = __webpack_require__( "2AvB" );
  8779. media.view.Settings.Gallery = __webpack_require__( "umxe" );
  8780. media.view.Settings.Playlist = __webpack_require__( "76BF" );
  8781. media.view.Attachment.Details = __webpack_require__( "iupV" );
  8782. media.view.AttachmentCompat = __webpack_require__( "LND6" );
  8783. media.view.Iframe = __webpack_require__( "t3nl" );
  8784. media.view.Embed = __webpack_require__( "VMHs" );
  8785. media.view.Label = __webpack_require__( "V6sy" );
  8786. media.view.EmbedUrl = __webpack_require__( "+mQJ" );
  8787. media.view.EmbedLink = __webpack_require__( "JecU" );
  8788. media.view.EmbedImage = __webpack_require__( "+B8m" );
  8789. media.view.ImageDetails = __webpack_require__( "GXJ6" );
  8790. media.view.Cropper = __webpack_require__( "Vh02" );
  8791. media.view.SiteIconCropper = __webpack_require__( "UmHM" );
  8792. media.view.SiteIconPreview = __webpack_require__( "d3xu" );
  8793. media.view.EditImage = __webpack_require__( "ibOK" );
  8794. media.view.Spinner = __webpack_require__( "cH3P" );
  8795. media.view.Heading = __webpack_require__( "l2j4" );
  8796. /***/ }),
  8797. /***/ "umxe":
  8798. /***/ (function(module, exports) {
  8799. /**
  8800. * wp.media.view.Settings.Gallery
  8801. *
  8802. * @memberOf wp.media.view.Settings
  8803. *
  8804. * @class
  8805. * @augments wp.media.view.Settings
  8806. * @augments wp.media.View
  8807. * @augments wp.Backbone.View
  8808. * @augments Backbone.View
  8809. */
  8810. var Gallery = wp.media.view.Settings.extend(/** @lends wp.media.view.Settings.Gallery.prototype */{
  8811. className: 'collection-settings gallery-settings',
  8812. template: wp.template('gallery-settings')
  8813. });
  8814. module.exports = Gallery;
  8815. /***/ }),
  8816. /***/ "wfCN":
  8817. /***/ (function(module, exports) {
  8818. var Attachments = wp.media.view.Attachments,
  8819. Selection;
  8820. /**
  8821. * wp.media.view.Attachments.Selection
  8822. *
  8823. * @memberOf wp.media.view.Attachments
  8824. *
  8825. * @class
  8826. * @augments wp.media.view.Attachments
  8827. * @augments wp.media.View
  8828. * @augments wp.Backbone.View
  8829. * @augments Backbone.View
  8830. */
  8831. Selection = Attachments.extend(/** @lends wp.media.view.Attachments.Selection.prototype */{
  8832. events: {},
  8833. initialize: function() {
  8834. _.defaults( this.options, {
  8835. sortable: false,
  8836. resize: false,
  8837. // The single `Attachment` view to be used in the `Attachments` view.
  8838. AttachmentView: wp.media.view.Attachment.Selection
  8839. });
  8840. // Call 'initialize' directly on the parent class.
  8841. return Attachments.prototype.initialize.apply( this, arguments );
  8842. }
  8843. });
  8844. module.exports = Selection;
  8845. /***/ }),
  8846. /***/ "xQvM":
  8847. /***/ (function(module, exports) {
  8848. var Select = wp.media.view.Toolbar.Select,
  8849. l10n = wp.media.view.l10n,
  8850. Embed;
  8851. /**
  8852. * wp.media.view.Toolbar.Embed
  8853. *
  8854. * @memberOf wp.media.view.Toolbar
  8855. *
  8856. * @class
  8857. * @augments wp.media.view.Toolbar.Select
  8858. * @augments wp.media.view.Toolbar
  8859. * @augments wp.media.View
  8860. * @augments wp.Backbone.View
  8861. * @augments Backbone.View
  8862. */
  8863. Embed = Select.extend(/** @lends wp.media.view.Toolbar.Embed.prototype */{
  8864. initialize: function() {
  8865. _.defaults( this.options, {
  8866. text: l10n.insertIntoPost,
  8867. requires: false
  8868. });
  8869. // Call 'initialize' directly on the parent class.
  8870. Select.prototype.initialize.apply( this, arguments );
  8871. },
  8872. refresh: function() {
  8873. var url = this.controller.state().props.get('url');
  8874. this.get('select').model.set( 'disabled', ! url || url === 'http://' );
  8875. /**
  8876. * call 'refresh' directly on the parent class
  8877. */
  8878. Select.prototype.refresh.apply( this, arguments );
  8879. }
  8880. });
  8881. module.exports = Embed;
  8882. /***/ }),
  8883. /***/ "yGM1":
  8884. /***/ (function(module, exports) {
  8885. /**
  8886. * wp.media.view.Attachment.Selection
  8887. *
  8888. * @memberOf wp.media.view.Attachment
  8889. *
  8890. * @class
  8891. * @augments wp.media.view.Attachment
  8892. * @augments wp.media.View
  8893. * @augments wp.Backbone.View
  8894. * @augments Backbone.View
  8895. */
  8896. var Selection = wp.media.view.Attachment.extend(/** @lends wp.media.view.Attachment.Selection.prototype */{
  8897. className: 'attachment selection',
  8898. // On click, just select the model, instead of removing the model from
  8899. // the selection.
  8900. toggleSelection: function() {
  8901. this.options.selection.single( this.model );
  8902. }
  8903. });
  8904. module.exports = Selection;
  8905. /***/ }),
  8906. /***/ "z/+l":
  8907. /***/ (function(module, exports) {
  8908. var $ = Backbone.$,
  8909. ButtonGroup;
  8910. /**
  8911. * wp.media.view.ButtonGroup
  8912. *
  8913. * @memberOf wp.media.view
  8914. *
  8915. * @class
  8916. * @augments wp.media.View
  8917. * @augments wp.Backbone.View
  8918. * @augments Backbone.View
  8919. */
  8920. ButtonGroup = wp.media.View.extend(/** @lends wp.media.view.ButtonGroup.prototype */{
  8921. tagName: 'div',
  8922. className: 'button-group button-large media-button-group',
  8923. initialize: function() {
  8924. /**
  8925. * @member {wp.media.view.Button[]}
  8926. */
  8927. this.buttons = _.map( this.options.buttons || [], function( button ) {
  8928. if ( button instanceof Backbone.View ) {
  8929. return button;
  8930. } else {
  8931. return new wp.media.view.Button( button ).render();
  8932. }
  8933. });
  8934. delete this.options.buttons;
  8935. if ( this.options.classes ) {
  8936. this.$el.addClass( this.options.classes );
  8937. }
  8938. },
  8939. /**
  8940. * @return {wp.media.view.ButtonGroup}
  8941. */
  8942. render: function() {
  8943. this.$el.html( $( _.pluck( this.buttons, 'el' ) ).detach() );
  8944. return this;
  8945. }
  8946. });
  8947. module.exports = ButtonGroup;
  8948. /***/ })
  8949. /******/ });