media-views.js 235 KB

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