video.cjs.js 683 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336
  1. /**
  2. * @license
  3. * Video.js 6.13.0 <http://videojs.com/>
  4. * Copyright Brightcove, Inc. <https://www.brightcove.com/>
  5. * Available under Apache License Version 2.0
  6. * <https://github.com/videojs/video.js/blob/master/LICENSE>
  7. *
  8. * Includes vtt.js <https://github.com/mozilla/vtt.js>
  9. * Available under Apache License Version 2.0
  10. * <https://github.com/mozilla/vtt.js/blob/master/LICENSE>
  11. */
  12. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  13. var window = _interopDefault(require('global/window'));
  14. var document = _interopDefault(require('global/document'));
  15. var tsml = _interopDefault(require('tsml'));
  16. var safeParseTuple = _interopDefault(require('safe-json-parse/tuple'));
  17. var xhr = _interopDefault(require('xhr'));
  18. var vtt = _interopDefault(require('videojs-vtt.js'));
  19. var version = "6.13.0";
  20. /**
  21. * @file browser.js
  22. * @module browser
  23. */
  24. var USER_AGENT = window.navigator && window.navigator.userAgent || '';
  25. var webkitVersionMap = /AppleWebKit\/([\d.]+)/i.exec(USER_AGENT);
  26. var appleWebkitVersion = webkitVersionMap ? parseFloat(webkitVersionMap.pop()) : null;
  27. /*
  28. * Device is an iPhone
  29. *
  30. * @type {Boolean}
  31. * @constant
  32. * @private
  33. */
  34. var IS_IPAD = /iPad/i.test(USER_AGENT);
  35. // The Facebook app's UIWebView identifies as both an iPhone and iPad, so
  36. // to identify iPhones, we need to exclude iPads.
  37. // http://artsy.github.io/blog/2012/10/18/the-perils-of-ios-user-agent-sniffing/
  38. var IS_IPHONE = /iPhone/i.test(USER_AGENT) && !IS_IPAD;
  39. var IS_IPOD = /iPod/i.test(USER_AGENT);
  40. var IS_IOS = IS_IPHONE || IS_IPAD || IS_IPOD;
  41. var IOS_VERSION = function () {
  42. var match = USER_AGENT.match(/OS (\d+)_/i);
  43. if (match && match[1]) {
  44. return match[1];
  45. }
  46. return null;
  47. }();
  48. var IS_ANDROID = /Android/i.test(USER_AGENT);
  49. var ANDROID_VERSION = function () {
  50. // This matches Android Major.Minor.Patch versions
  51. // ANDROID_VERSION is Major.Minor as a Number, if Minor isn't available, then only Major is returned
  52. var match = USER_AGENT.match(/Android (\d+)(?:\.(\d+))?(?:\.(\d+))*/i);
  53. if (!match) {
  54. return null;
  55. }
  56. var major = match[1] && parseFloat(match[1]);
  57. var minor = match[2] && parseFloat(match[2]);
  58. if (major && minor) {
  59. return parseFloat(match[1] + '.' + match[2]);
  60. } else if (major) {
  61. return major;
  62. }
  63. return null;
  64. }();
  65. // Old Android is defined as Version older than 2.3, and requiring a webkit version of the android browser
  66. var IS_OLD_ANDROID = IS_ANDROID && /webkit/i.test(USER_AGENT) && ANDROID_VERSION < 2.3;
  67. var IS_NATIVE_ANDROID = IS_ANDROID && ANDROID_VERSION < 5 && appleWebkitVersion < 537;
  68. var IS_FIREFOX = /Firefox/i.test(USER_AGENT);
  69. var IS_EDGE = /Edge/i.test(USER_AGENT);
  70. var IS_CHROME = !IS_EDGE && (/Chrome/i.test(USER_AGENT) || /CriOS/i.test(USER_AGENT));
  71. var CHROME_VERSION = function () {
  72. var match = USER_AGENT.match(/(Chrome|CriOS)\/(\d+)/);
  73. if (match && match[2]) {
  74. return parseFloat(match[2]);
  75. }
  76. return null;
  77. }();
  78. var IS_IE8 = /MSIE\s8\.0/.test(USER_AGENT);
  79. var IE_VERSION = function () {
  80. var result = /MSIE\s(\d+)\.\d/.exec(USER_AGENT);
  81. var version = result && parseFloat(result[1]);
  82. if (!version && /Trident\/7.0/i.test(USER_AGENT) && /rv:11.0/.test(USER_AGENT)) {
  83. // IE 11 has a different user agent string than other IE versions
  84. version = 11.0;
  85. }
  86. return version;
  87. }();
  88. var IS_SAFARI = /Safari/i.test(USER_AGENT) && !IS_CHROME && !IS_ANDROID && !IS_EDGE;
  89. var IS_ANY_SAFARI = (IS_SAFARI || IS_IOS) && !IS_CHROME;
  90. var TOUCH_ENABLED = isReal() && ('ontouchstart' in window || window.navigator.maxTouchPoints || window.DocumentTouch && window.document instanceof window.DocumentTouch);
  91. var BACKGROUND_SIZE_SUPPORTED = isReal() && 'backgroundSize' in window.document.createElement('video').style;
  92. var browser = (Object.freeze || Object)({
  93. IS_IPAD: IS_IPAD,
  94. IS_IPHONE: IS_IPHONE,
  95. IS_IPOD: IS_IPOD,
  96. IS_IOS: IS_IOS,
  97. IOS_VERSION: IOS_VERSION,
  98. IS_ANDROID: IS_ANDROID,
  99. ANDROID_VERSION: ANDROID_VERSION,
  100. IS_OLD_ANDROID: IS_OLD_ANDROID,
  101. IS_NATIVE_ANDROID: IS_NATIVE_ANDROID,
  102. IS_FIREFOX: IS_FIREFOX,
  103. IS_EDGE: IS_EDGE,
  104. IS_CHROME: IS_CHROME,
  105. CHROME_VERSION: CHROME_VERSION,
  106. IS_IE8: IS_IE8,
  107. IE_VERSION: IE_VERSION,
  108. IS_SAFARI: IS_SAFARI,
  109. IS_ANY_SAFARI: IS_ANY_SAFARI,
  110. TOUCH_ENABLED: TOUCH_ENABLED,
  111. BACKGROUND_SIZE_SUPPORTED: BACKGROUND_SIZE_SUPPORTED
  112. });
  113. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  114. return typeof obj;
  115. } : function (obj) {
  116. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  117. };
  118. var classCallCheck = function (instance, Constructor) {
  119. if (!(instance instanceof Constructor)) {
  120. throw new TypeError("Cannot call a class as a function");
  121. }
  122. };
  123. var inherits = function (subClass, superClass) {
  124. if (typeof superClass !== "function" && superClass !== null) {
  125. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  126. }
  127. subClass.prototype = Object.create(superClass && superClass.prototype, {
  128. constructor: {
  129. value: subClass,
  130. enumerable: false,
  131. writable: true,
  132. configurable: true
  133. }
  134. });
  135. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  136. };
  137. var possibleConstructorReturn = function (self, call) {
  138. if (!self) {
  139. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  140. }
  141. return call && (typeof call === "object" || typeof call === "function") ? call : self;
  142. };
  143. var taggedTemplateLiteralLoose = function (strings, raw) {
  144. strings.raw = raw;
  145. return strings;
  146. };
  147. /**
  148. * @file obj.js
  149. * @module obj
  150. */
  151. /**
  152. * @callback obj:EachCallback
  153. *
  154. * @param {Mixed} value
  155. * The current key for the object that is being iterated over.
  156. *
  157. * @param {string} key
  158. * The current key-value for object that is being iterated over
  159. */
  160. /**
  161. * @callback obj:ReduceCallback
  162. *
  163. * @param {Mixed} accum
  164. * The value that is accumulating over the reduce loop.
  165. *
  166. * @param {Mixed} value
  167. * The current key for the object that is being iterated over.
  168. *
  169. * @param {string} key
  170. * The current key-value for object that is being iterated over
  171. *
  172. * @return {Mixed}
  173. * The new accumulated value.
  174. */
  175. var toString = Object.prototype.toString;
  176. /**
  177. * Get the keys of an Object
  178. *
  179. * @param {Object}
  180. * The Object to get the keys from
  181. *
  182. * @return {string[]}
  183. * An array of the keys from the object. Returns an empty array if the
  184. * object passed in was invalid or had no keys.
  185. *
  186. * @private
  187. */
  188. var keys = function keys(object) {
  189. return isObject(object) ? Object.keys(object) : [];
  190. };
  191. /**
  192. * Array-like iteration for objects.
  193. *
  194. * @param {Object} object
  195. * The object to iterate over
  196. *
  197. * @param {obj:EachCallback} fn
  198. * The callback function which is called for each key in the object.
  199. */
  200. function each(object, fn) {
  201. keys(object).forEach(function (key) {
  202. return fn(object[key], key);
  203. });
  204. }
  205. /**
  206. * Array-like reduce for objects.
  207. *
  208. * @param {Object} object
  209. * The Object that you want to reduce.
  210. *
  211. * @param {Function} fn
  212. * A callback function which is called for each key in the object. It
  213. * receives the accumulated value and the per-iteration value and key
  214. * as arguments.
  215. *
  216. * @param {Mixed} [initial = 0]
  217. * Starting value
  218. *
  219. * @return {Mixed}
  220. * The final accumulated value.
  221. */
  222. function reduce(object, fn) {
  223. var initial = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  224. return keys(object).reduce(function (accum, key) {
  225. return fn(accum, object[key], key);
  226. }, initial);
  227. }
  228. /**
  229. * Object.assign-style object shallow merge/extend.
  230. *
  231. * @param {Object} target
  232. * @param {Object} ...sources
  233. * @return {Object}
  234. */
  235. function assign(target) {
  236. for (var _len = arguments.length, sources = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  237. sources[_key - 1] = arguments[_key];
  238. }
  239. if (Object.assign) {
  240. return Object.assign.apply(Object, [target].concat(sources));
  241. }
  242. sources.forEach(function (source) {
  243. if (!source) {
  244. return;
  245. }
  246. each(source, function (value, key) {
  247. target[key] = value;
  248. });
  249. });
  250. return target;
  251. }
  252. /**
  253. * Returns whether a value is an object of any kind - including DOM nodes,
  254. * arrays, regular expressions, etc. Not functions, though.
  255. *
  256. * This avoids the gotcha where using `typeof` on a `null` value
  257. * results in `'object'`.
  258. *
  259. * @param {Object} value
  260. * @return {Boolean}
  261. */
  262. function isObject(value) {
  263. return !!value && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object';
  264. }
  265. /**
  266. * Returns whether an object appears to be a "plain" object - that is, a
  267. * direct instance of `Object`.
  268. *
  269. * @param {Object} value
  270. * @return {Boolean}
  271. */
  272. function isPlain(value) {
  273. return isObject(value) && toString.call(value) === '[object Object]' && value.constructor === Object;
  274. }
  275. /**
  276. * @file create-logger.js
  277. * @module create-logger
  278. */
  279. // This is the private tracking variable for the logging history.
  280. var history = [];
  281. /**
  282. * Log messages to the console and history based on the type of message
  283. *
  284. * @private
  285. * @param {string} type
  286. * The name of the console method to use.
  287. *
  288. * @param {Array} args
  289. * The arguments to be passed to the matching console method.
  290. */
  291. var LogByTypeFactory = function LogByTypeFactory(name, log) {
  292. return function (type, level, args, stringify) {
  293. var lvl = log.levels[level];
  294. var lvlRegExp = new RegExp('^(' + lvl + ')$');
  295. if (type !== 'log') {
  296. // Add the type to the front of the message when it's not "log".
  297. args.unshift(type.toUpperCase() + ':');
  298. }
  299. // Add console prefix after adding to history.
  300. args.unshift(name + ':');
  301. // Add a clone of the args at this point to history.
  302. if (history) {
  303. history.push([].concat(args));
  304. }
  305. // If there's no console then don't try to output messages, but they will
  306. // still be stored in history.
  307. if (!window.console) {
  308. return;
  309. }
  310. // Was setting these once outside of this function, but containing them
  311. // in the function makes it easier to test cases where console doesn't exist
  312. // when the module is executed.
  313. var fn = window.console[type];
  314. if (!fn && type === 'debug') {
  315. // Certain browsers don't have support for console.debug. For those, we
  316. // should default to the closest comparable log.
  317. fn = window.console.info || window.console.log;
  318. }
  319. // Bail out if there's no console or if this type is not allowed by the
  320. // current logging level.
  321. if (!fn || !lvl || !lvlRegExp.test(type)) {
  322. return;
  323. }
  324. // IEs previous to 11 log objects uselessly as "[object Object]"; so, JSONify
  325. // objects and arrays for those less-capable browsers.
  326. if (stringify) {
  327. args = args.map(function (a) {
  328. if (isObject(a) || Array.isArray(a)) {
  329. try {
  330. return JSON.stringify(a);
  331. } catch (x) {
  332. return String(a);
  333. }
  334. }
  335. // Cast to string before joining, so we get null and undefined explicitly
  336. // included in output (as we would in a modern console).
  337. return String(a);
  338. }).join(' ');
  339. }
  340. // Old IE versions do not allow .apply() for console methods (they are
  341. // reported as objects rather than functions).
  342. if (!fn.apply) {
  343. fn(args);
  344. } else {
  345. fn[Array.isArray(args) ? 'apply' : 'call'](window.console, args);
  346. }
  347. };
  348. };
  349. function createLogger$1(name) {
  350. // This is the private tracking variable for logging level.
  351. var level = 'info';
  352. // the curried logByType bound to the specific log and history
  353. var logByType = void 0;
  354. /**
  355. * Logs plain debug messages. Similar to `console.log`.
  356. *
  357. * Due to [limitations](https://github.com/jsdoc3/jsdoc/issues/955#issuecomment-313829149)
  358. * of our JSDoc template, we cannot properly document this as both a function
  359. * and a namespace, so its function signature is documented here.
  360. *
  361. * #### Arguments
  362. * ##### *args
  363. * Mixed[]
  364. *
  365. * Any combination of values that could be passed to `console.log()`.
  366. *
  367. * #### Return Value
  368. *
  369. * `undefined`
  370. *
  371. * @namespace
  372. * @param {Mixed[]} args
  373. * One or more messages or objects that should be logged.
  374. */
  375. var log = function log() {
  376. var stringify = log.stringify || IE_VERSION && IE_VERSION < 11;
  377. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  378. args[_key] = arguments[_key];
  379. }
  380. logByType('log', level, args, stringify);
  381. };
  382. // This is the logByType helper that the logging methods below use
  383. logByType = LogByTypeFactory(name, log);
  384. /**
  385. * Create a new sublogger which chains the old name to the new name.
  386. *
  387. * For example, doing `videojs.log.createLogger('player')` and then using that logger will log the following:
  388. * ```js
  389. * mylogger('foo');
  390. * // > VIDEOJS: player: foo
  391. * ```
  392. *
  393. * @param {string} name
  394. * The name to add call the new logger
  395. * @return {Object}
  396. */
  397. log.createLogger = function (subname) {
  398. return createLogger$1(name + ': ' + subname);
  399. };
  400. /**
  401. * Enumeration of available logging levels, where the keys are the level names
  402. * and the values are `|`-separated strings containing logging methods allowed
  403. * in that logging level. These strings are used to create a regular expression
  404. * matching the function name being called.
  405. *
  406. * Levels provided by Video.js are:
  407. *
  408. * - `off`: Matches no calls. Any value that can be cast to `false` will have
  409. * this effect. The most restrictive.
  410. * - `all`: Matches only Video.js-provided functions (`debug`, `log`,
  411. * `log.warn`, and `log.error`).
  412. * - `debug`: Matches `log.debug`, `log`, `log.warn`, and `log.error` calls.
  413. * - `info` (default): Matches `log`, `log.warn`, and `log.error` calls.
  414. * - `warn`: Matches `log.warn` and `log.error` calls.
  415. * - `error`: Matches only `log.error` calls.
  416. *
  417. * @type {Object}
  418. */
  419. log.levels = {
  420. all: 'debug|log|warn|error',
  421. off: '',
  422. debug: 'debug|log|warn|error',
  423. info: 'log|warn|error',
  424. warn: 'warn|error',
  425. error: 'error',
  426. DEFAULT: level
  427. };
  428. /**
  429. * Get or set the current logging level.
  430. *
  431. * If a string matching a key from {@link module:log.levels} is provided, acts
  432. * as a setter.
  433. *
  434. * @param {string} [lvl]
  435. * Pass a valid level to set a new logging level.
  436. *
  437. * @return {string}
  438. * The current logging level.
  439. */
  440. log.level = function (lvl) {
  441. if (typeof lvl === 'string') {
  442. if (!log.levels.hasOwnProperty(lvl)) {
  443. throw new Error('"' + lvl + '" in not a valid log level');
  444. }
  445. level = lvl;
  446. }
  447. return level;
  448. };
  449. /**
  450. * Returns an array containing everything that has been logged to the history.
  451. *
  452. * This array is a shallow clone of the internal history record. However, its
  453. * contents are _not_ cloned; so, mutating objects inside this array will
  454. * mutate them in history.
  455. *
  456. * @return {Array}
  457. */
  458. log.history = function () {
  459. return history ? [].concat(history) : [];
  460. };
  461. /**
  462. * Allows you to filter the history by the given logger name
  463. *
  464. * @param {string} fname
  465. * The name to filter by
  466. *
  467. * @return {Array}
  468. * The filtered list to return
  469. */
  470. log.history.filter = function (fname) {
  471. return (history || []).filter(function (historyItem) {
  472. // if the first item in each historyItem includes `fname`, then it's a match
  473. return new RegExp('.*' + fname + '.*').test(historyItem[0]);
  474. });
  475. };
  476. /**
  477. * Clears the internal history tracking, but does not prevent further history
  478. * tracking.
  479. */
  480. log.history.clear = function () {
  481. if (history) {
  482. history.length = 0;
  483. }
  484. };
  485. /**
  486. * Disable history tracking if it is currently enabled.
  487. */
  488. log.history.disable = function () {
  489. if (history !== null) {
  490. history.length = 0;
  491. history = null;
  492. }
  493. };
  494. /**
  495. * Enable history tracking if it is currently disabled.
  496. */
  497. log.history.enable = function () {
  498. if (history === null) {
  499. history = [];
  500. }
  501. };
  502. /**
  503. * Logs error messages. Similar to `console.error`.
  504. *
  505. * @param {Mixed[]} args
  506. * One or more messages or objects that should be logged as an error
  507. */
  508. log.error = function () {
  509. for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  510. args[_key2] = arguments[_key2];
  511. }
  512. return logByType('error', level, args);
  513. };
  514. /**
  515. * Logs warning messages. Similar to `console.warn`.
  516. *
  517. * @param {Mixed[]} args
  518. * One or more messages or objects that should be logged as a warning.
  519. */
  520. log.warn = function () {
  521. for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  522. args[_key3] = arguments[_key3];
  523. }
  524. return logByType('warn', level, args);
  525. };
  526. /**
  527. * Logs debug messages. Similar to `console.debug`, but may also act as a comparable
  528. * log if `console.debug` is not available
  529. *
  530. * @param {Mixed[]} args
  531. * One or more messages or objects that should be logged as debug.
  532. */
  533. log.debug = function () {
  534. for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
  535. args[_key4] = arguments[_key4];
  536. }
  537. return logByType('debug', level, args);
  538. };
  539. return log;
  540. }
  541. /**
  542. * @file log.js
  543. * @module log
  544. */
  545. var log = createLogger$1('VIDEOJS');
  546. var createLogger = log.createLogger;
  547. /**
  548. * @file computed-style.js
  549. * @module computed-style
  550. */
  551. /**
  552. * A safe getComputedStyle with an IE8 fallback.
  553. *
  554. * This is needed because in Firefox, if the player is loaded in an iframe with
  555. * `display:none`, then `getComputedStyle` returns `null`, so, we do a null-check to
  556. * make sure that the player doesn't break in these cases.
  557. *
  558. * @param {Element} el
  559. * The element you want the computed style of
  560. *
  561. * @param {string} prop
  562. * The property name you want
  563. *
  564. * @see https://bugzilla.mozilla.org/show_bug.cgi?id=548397
  565. *
  566. * @static
  567. * @const
  568. */
  569. function computedStyle(el, prop) {
  570. if (!el || !prop) {
  571. return '';
  572. }
  573. if (typeof window.getComputedStyle === 'function') {
  574. var cs = window.getComputedStyle(el);
  575. return cs ? cs[prop] : '';
  576. }
  577. return el.currentStyle[prop] || '';
  578. }
  579. var _templateObject = taggedTemplateLiteralLoose(['Setting attributes in the second argument of createEl()\n has been deprecated. Use the third argument instead.\n createEl(type, properties, attributes). Attempting to set ', ' to ', '.'], ['Setting attributes in the second argument of createEl()\n has been deprecated. Use the third argument instead.\n createEl(type, properties, attributes). Attempting to set ', ' to ', '.']);
  580. /**
  581. * @file dom.js
  582. * @module dom
  583. */
  584. /**
  585. * Detect if a value is a string with any non-whitespace characters.
  586. *
  587. * @param {string} str
  588. * The string to check
  589. *
  590. * @return {boolean}
  591. * - True if the string is non-blank
  592. * - False otherwise
  593. *
  594. */
  595. function isNonBlankString(str) {
  596. return typeof str === 'string' && /\S/.test(str);
  597. }
  598. /**
  599. * Throws an error if the passed string has whitespace. This is used by
  600. * class methods to be relatively consistent with the classList API.
  601. *
  602. * @param {string} str
  603. * The string to check for whitespace.
  604. *
  605. * @throws {Error}
  606. * Throws an error if there is whitespace in the string.
  607. *
  608. */
  609. function throwIfWhitespace(str) {
  610. if (/\s/.test(str)) {
  611. throw new Error('class has illegal whitespace characters');
  612. }
  613. }
  614. /**
  615. * Produce a regular expression for matching a className within an elements className.
  616. *
  617. * @param {string} className
  618. * The className to generate the RegExp for.
  619. *
  620. * @return {RegExp}
  621. * The RegExp that will check for a specific `className` in an elements
  622. * className.
  623. */
  624. function classRegExp(className) {
  625. return new RegExp('(^|\\s)' + className + '($|\\s)');
  626. }
  627. /**
  628. * Whether the current DOM interface appears to be real.
  629. *
  630. * @return {Boolean}
  631. */
  632. function isReal() {
  633. return (
  634. // Both document and window will never be undefined thanks to `global`.
  635. document === window.document &&
  636. // In IE < 9, DOM methods return "object" as their type, so all we can
  637. // confidently check is that it exists.
  638. typeof document.createElement !== 'undefined'
  639. );
  640. }
  641. /**
  642. * Determines, via duck typing, whether or not a value is a DOM element.
  643. *
  644. * @param {Mixed} value
  645. * The thing to check
  646. *
  647. * @return {boolean}
  648. * - True if it is a DOM element
  649. * - False otherwise
  650. */
  651. function isEl(value) {
  652. return isObject(value) && value.nodeType === 1;
  653. }
  654. /**
  655. * Determines if the current DOM is embedded in an iframe.
  656. *
  657. * @return {boolean}
  658. *
  659. */
  660. function isInFrame() {
  661. // We need a try/catch here because Safari will throw errors when attempting
  662. // to get either `parent` or `self`
  663. try {
  664. return window.parent !== window.self;
  665. } catch (x) {
  666. return true;
  667. }
  668. }
  669. /**
  670. * Creates functions to query the DOM using a given method.
  671. *
  672. * @param {string} method
  673. * The method to create the query with.
  674. *
  675. * @return {Function}
  676. * The query method
  677. */
  678. function createQuerier(method) {
  679. return function (selector, context) {
  680. if (!isNonBlankString(selector)) {
  681. return document[method](null);
  682. }
  683. if (isNonBlankString(context)) {
  684. context = document.querySelector(context);
  685. }
  686. var ctx = isEl(context) ? context : document;
  687. return ctx[method] && ctx[method](selector);
  688. };
  689. }
  690. /**
  691. * Creates an element and applies properties.
  692. *
  693. * @param {string} [tagName='div']
  694. * Name of tag to be created.
  695. *
  696. * @param {Object} [properties={}]
  697. * Element properties to be applied.
  698. *
  699. * @param {Object} [attributes={}]
  700. * Element attributes to be applied.
  701. *
  702. * @param {String|Element|TextNode|Array|Function} [content]
  703. * Contents for the element (see: {@link dom:normalizeContent})
  704. *
  705. * @return {Element}
  706. * The element that was created.
  707. */
  708. function createEl() {
  709. var tagName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'div';
  710. var properties = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  711. var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  712. var content = arguments[3];
  713. var el = document.createElement(tagName);
  714. Object.getOwnPropertyNames(properties).forEach(function (propName) {
  715. var val = properties[propName];
  716. // See #2176
  717. // We originally were accepting both properties and attributes in the
  718. // same object, but that doesn't work so well.
  719. if (propName.indexOf('aria-') !== -1 || propName === 'role' || propName === 'type') {
  720. log.warn(tsml(_templateObject, propName, val));
  721. el.setAttribute(propName, val);
  722. // Handle textContent since it's not supported everywhere and we have a
  723. // method for it.
  724. } else if (propName === 'textContent') {
  725. textContent(el, val);
  726. } else {
  727. el[propName] = val;
  728. }
  729. });
  730. Object.getOwnPropertyNames(attributes).forEach(function (attrName) {
  731. el.setAttribute(attrName, attributes[attrName]);
  732. });
  733. if (content) {
  734. appendContent(el, content);
  735. }
  736. return el;
  737. }
  738. /**
  739. * Injects text into an element, replacing any existing contents entirely.
  740. *
  741. * @param {Element} el
  742. * The element to add text content into
  743. *
  744. * @param {string} text
  745. * The text content to add.
  746. *
  747. * @return {Element}
  748. * The element with added text content.
  749. */
  750. function textContent(el, text) {
  751. if (typeof el.textContent === 'undefined') {
  752. el.innerText = text;
  753. } else {
  754. el.textContent = text;
  755. }
  756. return el;
  757. }
  758. /**
  759. * Insert an element as the first child node of another
  760. *
  761. * @param {Element} child
  762. * Element to insert
  763. *
  764. * @param {Element} parent
  765. * Element to insert child into
  766. */
  767. function prependTo(child, parent) {
  768. if (parent.firstChild) {
  769. parent.insertBefore(child, parent.firstChild);
  770. } else {
  771. parent.appendChild(child);
  772. }
  773. }
  774. /**
  775. * Check if an element has a CSS class
  776. *
  777. * @param {Element} element
  778. * Element to check
  779. *
  780. * @param {string} classToCheck
  781. * Class name to check for
  782. *
  783. * @return {boolean}
  784. * - True if the element had the class
  785. * - False otherwise.
  786. *
  787. * @throws {Error}
  788. * Throws an error if `classToCheck` has white space.
  789. */
  790. function hasClass(element, classToCheck) {
  791. throwIfWhitespace(classToCheck);
  792. if (element.classList) {
  793. return element.classList.contains(classToCheck);
  794. }
  795. return classRegExp(classToCheck).test(element.className);
  796. }
  797. /**
  798. * Add a CSS class name to an element
  799. *
  800. * @param {Element} element
  801. * Element to add class name to.
  802. *
  803. * @param {string} classToAdd
  804. * Class name to add.
  805. *
  806. * @return {Element}
  807. * The dom element with the added class name.
  808. */
  809. function addClass(element, classToAdd) {
  810. if (element.classList) {
  811. element.classList.add(classToAdd);
  812. // Don't need to `throwIfWhitespace` here because `hasElClass` will do it
  813. // in the case of classList not being supported.
  814. } else if (!hasClass(element, classToAdd)) {
  815. element.className = (element.className + ' ' + classToAdd).trim();
  816. }
  817. return element;
  818. }
  819. /**
  820. * Remove a CSS class name from an element
  821. *
  822. * @param {Element} element
  823. * Element to remove a class name from.
  824. *
  825. * @param {string} classToRemove
  826. * Class name to remove
  827. *
  828. * @return {Element}
  829. * The dom element with class name removed.
  830. */
  831. function removeClass(element, classToRemove) {
  832. if (element.classList) {
  833. element.classList.remove(classToRemove);
  834. } else {
  835. throwIfWhitespace(classToRemove);
  836. element.className = element.className.split(/\s+/).filter(function (c) {
  837. return c !== classToRemove;
  838. }).join(' ');
  839. }
  840. return element;
  841. }
  842. /**
  843. * The callback definition for toggleElClass.
  844. *
  845. * @callback Dom~PredicateCallback
  846. * @param {Element} element
  847. * The DOM element of the Component.
  848. *
  849. * @param {string} classToToggle
  850. * The `className` that wants to be toggled
  851. *
  852. * @return {boolean|undefined}
  853. * - If true the `classToToggle` will get added to `element`.
  854. * - If false the `classToToggle` will get removed from `element`.
  855. * - If undefined this callback will be ignored
  856. */
  857. /**
  858. * Adds or removes a CSS class name on an element depending on an optional
  859. * condition or the presence/absence of the class name.
  860. *
  861. * @param {Element} element
  862. * The element to toggle a class name on.
  863. *
  864. * @param {string} classToToggle
  865. * The class that should be toggled
  866. *
  867. * @param {boolean|PredicateCallback} [predicate]
  868. * See the return value for {@link Dom~PredicateCallback}
  869. *
  870. * @return {Element}
  871. * The element with a class that has been toggled.
  872. */
  873. function toggleClass(element, classToToggle, predicate) {
  874. // This CANNOT use `classList` internally because IE does not support the
  875. // second parameter to the `classList.toggle()` method! Which is fine because
  876. // `classList` will be used by the add/remove functions.
  877. var has = hasClass(element, classToToggle);
  878. if (typeof predicate === 'function') {
  879. predicate = predicate(element, classToToggle);
  880. }
  881. if (typeof predicate !== 'boolean') {
  882. predicate = !has;
  883. }
  884. // If the necessary class operation matches the current state of the
  885. // element, no action is required.
  886. if (predicate === has) {
  887. return;
  888. }
  889. if (predicate) {
  890. addClass(element, classToToggle);
  891. } else {
  892. removeClass(element, classToToggle);
  893. }
  894. return element;
  895. }
  896. /**
  897. * Apply attributes to an HTML element.
  898. *
  899. * @param {Element} el
  900. * Element to add attributes to.
  901. *
  902. * @param {Object} [attributes]
  903. * Attributes to be applied.
  904. */
  905. function setAttributes(el, attributes) {
  906. Object.getOwnPropertyNames(attributes).forEach(function (attrName) {
  907. var attrValue = attributes[attrName];
  908. if (attrValue === null || typeof attrValue === 'undefined' || attrValue === false) {
  909. el.removeAttribute(attrName);
  910. } else {
  911. el.setAttribute(attrName, attrValue === true ? '' : attrValue);
  912. }
  913. });
  914. }
  915. /**
  916. * Get an element's attribute values, as defined on the HTML tag
  917. * Attributes are not the same as properties. They're defined on the tag
  918. * or with setAttribute (which shouldn't be used with HTML)
  919. * This will return true or false for boolean attributes.
  920. *
  921. * @param {Element} tag
  922. * Element from which to get tag attributes.
  923. *
  924. * @return {Object}
  925. * All attributes of the element.
  926. */
  927. function getAttributes(tag) {
  928. var obj = {};
  929. // known boolean attributes
  930. // we can check for matching boolean properties, but older browsers
  931. // won't know about HTML5 boolean attributes that we still read from
  932. var knownBooleans = ',' + 'autoplay,controls,playsinline,loop,muted,default,defaultMuted' + ',';
  933. if (tag && tag.attributes && tag.attributes.length > 0) {
  934. var attrs = tag.attributes;
  935. for (var i = attrs.length - 1; i >= 0; i--) {
  936. var attrName = attrs[i].name;
  937. var attrVal = attrs[i].value;
  938. // check for known booleans
  939. // the matching element property will return a value for typeof
  940. if (typeof tag[attrName] === 'boolean' || knownBooleans.indexOf(',' + attrName + ',') !== -1) {
  941. // the value of an included boolean attribute is typically an empty
  942. // string ('') which would equal false if we just check for a false value.
  943. // we also don't want support bad code like autoplay='false'
  944. attrVal = attrVal !== null ? true : false;
  945. }
  946. obj[attrName] = attrVal;
  947. }
  948. }
  949. return obj;
  950. }
  951. /**
  952. * Get the value of an element's attribute
  953. *
  954. * @param {Element} el
  955. * A DOM element
  956. *
  957. * @param {string} attribute
  958. * Attribute to get the value of
  959. *
  960. * @return {string}
  961. * value of the attribute
  962. */
  963. function getAttribute(el, attribute) {
  964. return el.getAttribute(attribute);
  965. }
  966. /**
  967. * Set the value of an element's attribute
  968. *
  969. * @param {Element} el
  970. * A DOM element
  971. *
  972. * @param {string} attribute
  973. * Attribute to set
  974. *
  975. * @param {string} value
  976. * Value to set the attribute to
  977. */
  978. function setAttribute(el, attribute, value) {
  979. el.setAttribute(attribute, value);
  980. }
  981. /**
  982. * Remove an element's attribute
  983. *
  984. * @param {Element} el
  985. * A DOM element
  986. *
  987. * @param {string} attribute
  988. * Attribute to remove
  989. */
  990. function removeAttribute(el, attribute) {
  991. el.removeAttribute(attribute);
  992. }
  993. /**
  994. * Attempt to block the ability to select text while dragging controls
  995. */
  996. function blockTextSelection() {
  997. document.body.focus();
  998. document.onselectstart = function () {
  999. return false;
  1000. };
  1001. }
  1002. /**
  1003. * Turn off text selection blocking
  1004. */
  1005. function unblockTextSelection() {
  1006. document.onselectstart = function () {
  1007. return true;
  1008. };
  1009. }
  1010. /**
  1011. * Identical to the native `getBoundingClientRect` function, but ensures that
  1012. * the method is supported at all (it is in all browsers we claim to support)
  1013. * and that the element is in the DOM before continuing.
  1014. *
  1015. * This wrapper function also shims properties which are not provided by some
  1016. * older browsers (namely, IE8).
  1017. *
  1018. * Additionally, some browsers do not support adding properties to a
  1019. * `ClientRect`/`DOMRect` object; so, we shallow-copy it with the standard
  1020. * properties (except `x` and `y` which are not widely supported). This helps
  1021. * avoid implementations where keys are non-enumerable.
  1022. *
  1023. * @param {Element} el
  1024. * Element whose `ClientRect` we want to calculate.
  1025. *
  1026. * @return {Object|undefined}
  1027. * Always returns a plain
  1028. */
  1029. function getBoundingClientRect(el) {
  1030. if (el && el.getBoundingClientRect && el.parentNode) {
  1031. var rect = el.getBoundingClientRect();
  1032. var result = {};
  1033. ['bottom', 'height', 'left', 'right', 'top', 'width'].forEach(function (k) {
  1034. if (rect[k] !== undefined) {
  1035. result[k] = rect[k];
  1036. }
  1037. });
  1038. if (!result.height) {
  1039. result.height = parseFloat(computedStyle(el, 'height'));
  1040. }
  1041. if (!result.width) {
  1042. result.width = parseFloat(computedStyle(el, 'width'));
  1043. }
  1044. return result;
  1045. }
  1046. }
  1047. /**
  1048. * The postion of a DOM element on the page.
  1049. *
  1050. * @typedef {Object} module:dom~Position
  1051. *
  1052. * @property {number} left
  1053. * Pixels to the left
  1054. *
  1055. * @property {number} top
  1056. * Pixels on top
  1057. */
  1058. /**
  1059. * Offset Left.
  1060. * getBoundingClientRect technique from
  1061. * John Resig
  1062. *
  1063. * @see http://ejohn.org/blog/getboundingclientrect-is-awesome/
  1064. *
  1065. * @param {Element} el
  1066. * Element from which to get offset
  1067. *
  1068. * @return {module:dom~Position}
  1069. * The position of the element that was passed in.
  1070. */
  1071. function findPosition(el) {
  1072. var box = void 0;
  1073. if (el.getBoundingClientRect && el.parentNode) {
  1074. box = el.getBoundingClientRect();
  1075. }
  1076. if (!box) {
  1077. return {
  1078. left: 0,
  1079. top: 0
  1080. };
  1081. }
  1082. var docEl = document.documentElement;
  1083. var body = document.body;
  1084. var clientLeft = docEl.clientLeft || body.clientLeft || 0;
  1085. var scrollLeft = window.pageXOffset || body.scrollLeft;
  1086. var left = box.left + scrollLeft - clientLeft;
  1087. var clientTop = docEl.clientTop || body.clientTop || 0;
  1088. var scrollTop = window.pageYOffset || body.scrollTop;
  1089. var top = box.top + scrollTop - clientTop;
  1090. // Android sometimes returns slightly off decimal values, so need to round
  1091. return {
  1092. left: Math.round(left),
  1093. top: Math.round(top)
  1094. };
  1095. }
  1096. /**
  1097. * x and y coordinates for a dom element or mouse pointer
  1098. *
  1099. * @typedef {Object} Dom~Coordinates
  1100. *
  1101. * @property {number} x
  1102. * x coordinate in pixels
  1103. *
  1104. * @property {number} y
  1105. * y coordinate in pixels
  1106. */
  1107. /**
  1108. * Get pointer position in element
  1109. * Returns an object with x and y coordinates.
  1110. * The base on the coordinates are the bottom left of the element.
  1111. *
  1112. * @param {Element} el
  1113. * Element on which to get the pointer position on
  1114. *
  1115. * @param {EventTarget~Event} event
  1116. * Event object
  1117. *
  1118. * @return {Dom~Coordinates}
  1119. * A Coordinates object corresponding to the mouse position.
  1120. *
  1121. */
  1122. function getPointerPosition(el, event) {
  1123. var position = {};
  1124. var box = findPosition(el);
  1125. var boxW = el.offsetWidth;
  1126. var boxH = el.offsetHeight;
  1127. var boxY = box.top;
  1128. var boxX = box.left;
  1129. var pageY = event.pageY;
  1130. var pageX = event.pageX;
  1131. if (event.changedTouches) {
  1132. pageX = event.changedTouches[0].pageX;
  1133. pageY = event.changedTouches[0].pageY;
  1134. }
  1135. position.y = Math.max(0, Math.min(1, (boxY - pageY + boxH) / boxH));
  1136. position.x = Math.max(0, Math.min(1, (pageX - boxX) / boxW));
  1137. return position;
  1138. }
  1139. /**
  1140. * Determines, via duck typing, whether or not a value is a text node.
  1141. *
  1142. * @param {Mixed} value
  1143. * Check if this value is a text node.
  1144. *
  1145. * @return {boolean}
  1146. * - True if it is a text node
  1147. * - False otherwise
  1148. */
  1149. function isTextNode(value) {
  1150. return isObject(value) && value.nodeType === 3;
  1151. }
  1152. /**
  1153. * Empties the contents of an element.
  1154. *
  1155. * @param {Element} el
  1156. * The element to empty children from
  1157. *
  1158. * @return {Element}
  1159. * The element with no children
  1160. */
  1161. function emptyEl(el) {
  1162. while (el.firstChild) {
  1163. el.removeChild(el.firstChild);
  1164. }
  1165. return el;
  1166. }
  1167. /**
  1168. * Normalizes content for eventual insertion into the DOM.
  1169. *
  1170. * This allows a wide range of content definition methods, but protects
  1171. * from falling into the trap of simply writing to `innerHTML`, which is
  1172. * an XSS concern.
  1173. *
  1174. * The content for an element can be passed in multiple types and
  1175. * combinations, whose behavior is as follows:
  1176. *
  1177. * @param {String|Element|TextNode|Array|Function} content
  1178. * - String: Normalized into a text node.
  1179. * - Element/TextNode: Passed through.
  1180. * - Array: A one-dimensional array of strings, elements, nodes, or functions
  1181. * (which return single strings, elements, or nodes).
  1182. * - Function: If the sole argument, is expected to produce a string, element,
  1183. * node, or array as defined above.
  1184. *
  1185. * @return {Array}
  1186. * All of the content that was passed in normalized.
  1187. */
  1188. function normalizeContent(content) {
  1189. // First, invoke content if it is a function. If it produces an array,
  1190. // that needs to happen before normalization.
  1191. if (typeof content === 'function') {
  1192. content = content();
  1193. }
  1194. // Next up, normalize to an array, so one or many items can be normalized,
  1195. // filtered, and returned.
  1196. return (Array.isArray(content) ? content : [content]).map(function (value) {
  1197. // First, invoke value if it is a function to produce a new value,
  1198. // which will be subsequently normalized to a Node of some kind.
  1199. if (typeof value === 'function') {
  1200. value = value();
  1201. }
  1202. if (isEl(value) || isTextNode(value)) {
  1203. return value;
  1204. }
  1205. if (typeof value === 'string' && /\S/.test(value)) {
  1206. return document.createTextNode(value);
  1207. }
  1208. }).filter(function (value) {
  1209. return value;
  1210. });
  1211. }
  1212. /**
  1213. * Normalizes and appends content to an element.
  1214. *
  1215. * @param {Element} el
  1216. * Element to append normalized content to.
  1217. *
  1218. *
  1219. * @param {String|Element|TextNode|Array|Function} content
  1220. * See the `content` argument of {@link dom:normalizeContent}
  1221. *
  1222. * @return {Element}
  1223. * The element with appended normalized content.
  1224. */
  1225. function appendContent(el, content) {
  1226. normalizeContent(content).forEach(function (node) {
  1227. return el.appendChild(node);
  1228. });
  1229. return el;
  1230. }
  1231. /**
  1232. * Normalizes and inserts content into an element; this is identical to
  1233. * `appendContent()`, except it empties the element first.
  1234. *
  1235. * @param {Element} el
  1236. * Element to insert normalized content into.
  1237. *
  1238. * @param {String|Element|TextNode|Array|Function} content
  1239. * See the `content` argument of {@link dom:normalizeContent}
  1240. *
  1241. * @return {Element}
  1242. * The element with inserted normalized content.
  1243. *
  1244. */
  1245. function insertContent(el, content) {
  1246. return appendContent(emptyEl(el), content);
  1247. }
  1248. /**
  1249. * Check if event was a single left click
  1250. *
  1251. * @param {EventTarget~Event} event
  1252. * Event object
  1253. *
  1254. * @return {boolean}
  1255. * - True if a left click
  1256. * - False if not a left click
  1257. */
  1258. function isSingleLeftClick(event) {
  1259. // Note: if you create something draggable, be sure to
  1260. // call it on both `mousedown` and `mousemove` event,
  1261. // otherwise `mousedown` should be enough for a button
  1262. if (event.button === undefined && event.buttons === undefined) {
  1263. // Why do we need `buttons` ?
  1264. // Because, middle mouse sometimes have this:
  1265. // e.button === 0 and e.buttons === 4
  1266. // Furthermore, we want to prevent combination click, something like
  1267. // HOLD middlemouse then left click, that would be
  1268. // e.button === 0, e.buttons === 5
  1269. // just `button` is not gonna work
  1270. // Alright, then what this block does ?
  1271. // this is for chrome `simulate mobile devices`
  1272. // I want to support this as well
  1273. return true;
  1274. }
  1275. if (event.button === 0 && event.buttons === undefined) {
  1276. // Touch screen, sometimes on some specific device, `buttons`
  1277. // doesn't have anything (safari on ios, blackberry...)
  1278. return true;
  1279. }
  1280. if (IE_VERSION === 9) {
  1281. // Ignore IE9
  1282. return true;
  1283. }
  1284. if (event.button !== 0 || event.buttons !== 1) {
  1285. // This is the reason we have those if else block above
  1286. // if any special case we can catch and let it slide
  1287. // we do it above, when get to here, this definitely
  1288. // is-not-left-click
  1289. return false;
  1290. }
  1291. return true;
  1292. }
  1293. /**
  1294. * Finds a single DOM element matching `selector` within the optional
  1295. * `context` of another DOM element (defaulting to `document`).
  1296. *
  1297. * @param {string} selector
  1298. * A valid CSS selector, which will be passed to `querySelector`.
  1299. *
  1300. * @param {Element|String} [context=document]
  1301. * A DOM element within which to query. Can also be a selector
  1302. * string in which case the first matching element will be used
  1303. * as context. If missing (or no element matches selector), falls
  1304. * back to `document`.
  1305. *
  1306. * @return {Element|null}
  1307. * The element that was found or null.
  1308. */
  1309. var $ = createQuerier('querySelector');
  1310. /**
  1311. * Finds a all DOM elements matching `selector` within the optional
  1312. * `context` of another DOM element (defaulting to `document`).
  1313. *
  1314. * @param {string} selector
  1315. * A valid CSS selector, which will be passed to `querySelectorAll`.
  1316. *
  1317. * @param {Element|String} [context=document]
  1318. * A DOM element within which to query. Can also be a selector
  1319. * string in which case the first matching element will be used
  1320. * as context. If missing (or no element matches selector), falls
  1321. * back to `document`.
  1322. *
  1323. * @return {NodeList}
  1324. * A element list of elements that were found. Will be empty if none were found.
  1325. *
  1326. */
  1327. var $$ = createQuerier('querySelectorAll');
  1328. var Dom = (Object.freeze || Object)({
  1329. isReal: isReal,
  1330. isEl: isEl,
  1331. isInFrame: isInFrame,
  1332. createEl: createEl,
  1333. textContent: textContent,
  1334. prependTo: prependTo,
  1335. hasClass: hasClass,
  1336. addClass: addClass,
  1337. removeClass: removeClass,
  1338. toggleClass: toggleClass,
  1339. setAttributes: setAttributes,
  1340. getAttributes: getAttributes,
  1341. getAttribute: getAttribute,
  1342. setAttribute: setAttribute,
  1343. removeAttribute: removeAttribute,
  1344. blockTextSelection: blockTextSelection,
  1345. unblockTextSelection: unblockTextSelection,
  1346. getBoundingClientRect: getBoundingClientRect,
  1347. findPosition: findPosition,
  1348. getPointerPosition: getPointerPosition,
  1349. isTextNode: isTextNode,
  1350. emptyEl: emptyEl,
  1351. normalizeContent: normalizeContent,
  1352. appendContent: appendContent,
  1353. insertContent: insertContent,
  1354. isSingleLeftClick: isSingleLeftClick,
  1355. $: $,
  1356. $$: $$
  1357. });
  1358. /**
  1359. * @file guid.js
  1360. * @module guid
  1361. */
  1362. /**
  1363. * Unique ID for an element or function
  1364. * @type {Number}
  1365. */
  1366. var _guid = 1;
  1367. /**
  1368. * Get a unique auto-incrementing ID by number that has not been returned before.
  1369. *
  1370. * @return {number}
  1371. * A new unique ID.
  1372. */
  1373. function newGUID() {
  1374. return _guid++;
  1375. }
  1376. /**
  1377. * @file dom-data.js
  1378. * @module dom-data
  1379. */
  1380. /**
  1381. * Element Data Store.
  1382. *
  1383. * Allows for binding data to an element without putting it directly on the
  1384. * element. Ex. Event listeners are stored here.
  1385. * (also from jsninja.com, slightly modified and updated for closure compiler)
  1386. *
  1387. * @type {Object}
  1388. * @private
  1389. */
  1390. var elData = {};
  1391. /*
  1392. * Unique attribute name to store an element's guid in
  1393. *
  1394. * @type {String}
  1395. * @constant
  1396. * @private
  1397. */
  1398. var elIdAttr = 'vdata' + new Date().getTime();
  1399. /**
  1400. * Returns the cache object where data for an element is stored
  1401. *
  1402. * @param {Element} el
  1403. * Element to store data for.
  1404. *
  1405. * @return {Object}
  1406. * The cache object for that el that was passed in.
  1407. */
  1408. function getData(el) {
  1409. var id = el[elIdAttr];
  1410. if (!id) {
  1411. id = el[elIdAttr] = newGUID();
  1412. }
  1413. if (!elData[id]) {
  1414. elData[id] = {};
  1415. }
  1416. return elData[id];
  1417. }
  1418. /**
  1419. * Returns whether or not an element has cached data
  1420. *
  1421. * @param {Element} el
  1422. * Check if this element has cached data.
  1423. *
  1424. * @return {boolean}
  1425. * - True if the DOM element has cached data.
  1426. * - False otherwise.
  1427. */
  1428. function hasData(el) {
  1429. var id = el[elIdAttr];
  1430. if (!id) {
  1431. return false;
  1432. }
  1433. return !!Object.getOwnPropertyNames(elData[id]).length;
  1434. }
  1435. /**
  1436. * Delete data for the element from the cache and the guid attr from getElementById
  1437. *
  1438. * @param {Element} el
  1439. * Remove cached data for this element.
  1440. */
  1441. function removeData(el) {
  1442. var id = el[elIdAttr];
  1443. if (!id) {
  1444. return;
  1445. }
  1446. // Remove all stored data
  1447. delete elData[id];
  1448. // Remove the elIdAttr property from the DOM node
  1449. try {
  1450. delete el[elIdAttr];
  1451. } catch (e) {
  1452. if (el.removeAttribute) {
  1453. el.removeAttribute(elIdAttr);
  1454. } else {
  1455. // IE doesn't appear to support removeAttribute on the document element
  1456. el[elIdAttr] = null;
  1457. }
  1458. }
  1459. }
  1460. /**
  1461. * @file events.js. An Event System (John Resig - Secrets of a JS Ninja http://jsninja.com/)
  1462. * (Original book version wasn't completely usable, so fixed some things and made Closure Compiler compatible)
  1463. * This should work very similarly to jQuery's events, however it's based off the book version which isn't as
  1464. * robust as jquery's, so there's probably some differences.
  1465. *
  1466. * @module events
  1467. */
  1468. /**
  1469. * Clean up the listener cache and dispatchers
  1470. *
  1471. * @param {Element|Object} elem
  1472. * Element to clean up
  1473. *
  1474. * @param {string} type
  1475. * Type of event to clean up
  1476. */
  1477. function _cleanUpEvents(elem, type) {
  1478. var data = getData(elem);
  1479. // Remove the events of a particular type if there are none left
  1480. if (data.handlers[type].length === 0) {
  1481. delete data.handlers[type];
  1482. // data.handlers[type] = null;
  1483. // Setting to null was causing an error with data.handlers
  1484. // Remove the meta-handler from the element
  1485. if (elem.removeEventListener) {
  1486. elem.removeEventListener(type, data.dispatcher, false);
  1487. } else if (elem.detachEvent) {
  1488. elem.detachEvent('on' + type, data.dispatcher);
  1489. }
  1490. }
  1491. // Remove the events object if there are no types left
  1492. if (Object.getOwnPropertyNames(data.handlers).length <= 0) {
  1493. delete data.handlers;
  1494. delete data.dispatcher;
  1495. delete data.disabled;
  1496. }
  1497. // Finally remove the element data if there is no data left
  1498. if (Object.getOwnPropertyNames(data).length === 0) {
  1499. removeData(elem);
  1500. }
  1501. }
  1502. /**
  1503. * Loops through an array of event types and calls the requested method for each type.
  1504. *
  1505. * @param {Function} fn
  1506. * The event method we want to use.
  1507. *
  1508. * @param {Element|Object} elem
  1509. * Element or object to bind listeners to
  1510. *
  1511. * @param {string} type
  1512. * Type of event to bind to.
  1513. *
  1514. * @param {EventTarget~EventListener} callback
  1515. * Event listener.
  1516. */
  1517. function _handleMultipleEvents(fn, elem, types, callback) {
  1518. types.forEach(function (type) {
  1519. // Call the event method for each one of the types
  1520. fn(elem, type, callback);
  1521. });
  1522. }
  1523. /**
  1524. * Fix a native event to have standard property values
  1525. *
  1526. * @param {Object} event
  1527. * Event object to fix.
  1528. *
  1529. * @return {Object}
  1530. * Fixed event object.
  1531. */
  1532. function fixEvent(event) {
  1533. function returnTrue() {
  1534. return true;
  1535. }
  1536. function returnFalse() {
  1537. return false;
  1538. }
  1539. // Test if fixing up is needed
  1540. // Used to check if !event.stopPropagation instead of isPropagationStopped
  1541. // But native events return true for stopPropagation, but don't have
  1542. // other expected methods like isPropagationStopped. Seems to be a problem
  1543. // with the Javascript Ninja code. So we're just overriding all events now.
  1544. if (!event || !event.isPropagationStopped) {
  1545. var old = event || window.event;
  1546. event = {};
  1547. // Clone the old object so that we can modify the values event = {};
  1548. // IE8 Doesn't like when you mess with native event properties
  1549. // Firefox returns false for event.hasOwnProperty('type') and other props
  1550. // which makes copying more difficult.
  1551. // TODO: Probably best to create a whitelist of event props
  1552. for (var key in old) {
  1553. // Safari 6.0.3 warns you if you try to copy deprecated layerX/Y
  1554. // Chrome warns you if you try to copy deprecated keyboardEvent.keyLocation
  1555. // and webkitMovementX/Y
  1556. if (key !== 'layerX' && key !== 'layerY' && key !== 'keyLocation' && key !== 'webkitMovementX' && key !== 'webkitMovementY') {
  1557. // Chrome 32+ warns if you try to copy deprecated returnValue, but
  1558. // we still want to if preventDefault isn't supported (IE8).
  1559. if (!(key === 'returnValue' && old.preventDefault)) {
  1560. event[key] = old[key];
  1561. }
  1562. }
  1563. }
  1564. // The event occurred on this element
  1565. if (!event.target) {
  1566. event.target = event.srcElement || document;
  1567. }
  1568. // Handle which other element the event is related to
  1569. if (!event.relatedTarget) {
  1570. event.relatedTarget = event.fromElement === event.target ? event.toElement : event.fromElement;
  1571. }
  1572. // Stop the default browser action
  1573. event.preventDefault = function () {
  1574. if (old.preventDefault) {
  1575. old.preventDefault();
  1576. }
  1577. event.returnValue = false;
  1578. old.returnValue = false;
  1579. event.defaultPrevented = true;
  1580. };
  1581. event.defaultPrevented = false;
  1582. // Stop the event from bubbling
  1583. event.stopPropagation = function () {
  1584. if (old.stopPropagation) {
  1585. old.stopPropagation();
  1586. }
  1587. event.cancelBubble = true;
  1588. old.cancelBubble = true;
  1589. event.isPropagationStopped = returnTrue;
  1590. };
  1591. event.isPropagationStopped = returnFalse;
  1592. // Stop the event from bubbling and executing other handlers
  1593. event.stopImmediatePropagation = function () {
  1594. if (old.stopImmediatePropagation) {
  1595. old.stopImmediatePropagation();
  1596. }
  1597. event.isImmediatePropagationStopped = returnTrue;
  1598. event.stopPropagation();
  1599. };
  1600. event.isImmediatePropagationStopped = returnFalse;
  1601. // Handle mouse position
  1602. if (event.clientX !== null && event.clientX !== undefined) {
  1603. var doc = document.documentElement;
  1604. var body = document.body;
  1605. event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0);
  1606. event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0);
  1607. }
  1608. // Handle key presses
  1609. event.which = event.charCode || event.keyCode;
  1610. // Fix button for mouse clicks:
  1611. // 0 == left; 1 == middle; 2 == right
  1612. if (event.button !== null && event.button !== undefined) {
  1613. // The following is disabled because it does not pass videojs-standard
  1614. // and... yikes.
  1615. /* eslint-disable */
  1616. event.button = event.button & 1 ? 0 : event.button & 4 ? 1 : event.button & 2 ? 2 : 0;
  1617. /* eslint-enable */
  1618. }
  1619. }
  1620. // Returns fixed-up instance
  1621. return event;
  1622. }
  1623. /**
  1624. * Whether passive event listeners are supported
  1625. */
  1626. var _supportsPassive = false;
  1627. (function () {
  1628. try {
  1629. var opts = Object.defineProperty({}, 'passive', {
  1630. get: function get() {
  1631. _supportsPassive = true;
  1632. }
  1633. });
  1634. window.addEventListener('test', null, opts);
  1635. window.removeEventListener('test', null, opts);
  1636. } catch (e) {
  1637. // disregard
  1638. }
  1639. })();
  1640. /**
  1641. * Touch events Chrome expects to be passive
  1642. */
  1643. var passiveEvents = ['touchstart', 'touchmove'];
  1644. /**
  1645. * Add an event listener to element
  1646. * It stores the handler function in a separate cache object
  1647. * and adds a generic handler to the element's event,
  1648. * along with a unique id (guid) to the element.
  1649. *
  1650. * @param {Element|Object} elem
  1651. * Element or object to bind listeners to
  1652. *
  1653. * @param {string|string[]} type
  1654. * Type of event to bind to.
  1655. *
  1656. * @param {EventTarget~EventListener} fn
  1657. * Event listener.
  1658. */
  1659. function on(elem, type, fn) {
  1660. if (Array.isArray(type)) {
  1661. return _handleMultipleEvents(on, elem, type, fn);
  1662. }
  1663. var data = getData(elem);
  1664. // We need a place to store all our handler data
  1665. if (!data.handlers) {
  1666. data.handlers = {};
  1667. }
  1668. if (!data.handlers[type]) {
  1669. data.handlers[type] = [];
  1670. }
  1671. if (!fn.guid) {
  1672. fn.guid = newGUID();
  1673. }
  1674. data.handlers[type].push(fn);
  1675. if (!data.dispatcher) {
  1676. data.disabled = false;
  1677. data.dispatcher = function (event, hash) {
  1678. if (data.disabled) {
  1679. return;
  1680. }
  1681. event = fixEvent(event);
  1682. var handlers = data.handlers[event.type];
  1683. if (handlers) {
  1684. // Copy handlers so if handlers are added/removed during the process it doesn't throw everything off.
  1685. var handlersCopy = handlers.slice(0);
  1686. for (var m = 0, n = handlersCopy.length; m < n; m++) {
  1687. if (event.isImmediatePropagationStopped()) {
  1688. break;
  1689. } else {
  1690. try {
  1691. handlersCopy[m].call(elem, event, hash);
  1692. } catch (e) {
  1693. log.error(e);
  1694. }
  1695. }
  1696. }
  1697. }
  1698. };
  1699. }
  1700. if (data.handlers[type].length === 1) {
  1701. if (elem.addEventListener) {
  1702. var options = false;
  1703. if (_supportsPassive && passiveEvents.indexOf(type) > -1) {
  1704. options = { passive: true };
  1705. }
  1706. elem.addEventListener(type, data.dispatcher, options);
  1707. } else if (elem.attachEvent) {
  1708. elem.attachEvent('on' + type, data.dispatcher);
  1709. }
  1710. }
  1711. }
  1712. /**
  1713. * Removes event listeners from an element
  1714. *
  1715. * @param {Element|Object} elem
  1716. * Object to remove listeners from.
  1717. *
  1718. * @param {string|string[]} [type]
  1719. * Type of listener to remove. Don't include to remove all events from element.
  1720. *
  1721. * @param {EventTarget~EventListener} [fn]
  1722. * Specific listener to remove. Don't include to remove listeners for an event
  1723. * type.
  1724. */
  1725. function off(elem, type, fn) {
  1726. // Don't want to add a cache object through getElData if not needed
  1727. if (!hasData(elem)) {
  1728. return;
  1729. }
  1730. var data = getData(elem);
  1731. // If no events exist, nothing to unbind
  1732. if (!data.handlers) {
  1733. return;
  1734. }
  1735. if (Array.isArray(type)) {
  1736. return _handleMultipleEvents(off, elem, type, fn);
  1737. }
  1738. // Utility function
  1739. var removeType = function removeType(el, t) {
  1740. data.handlers[t] = [];
  1741. _cleanUpEvents(el, t);
  1742. };
  1743. // Are we removing all bound events?
  1744. if (type === undefined) {
  1745. for (var t in data.handlers) {
  1746. if (Object.prototype.hasOwnProperty.call(data.handlers || {}, t)) {
  1747. removeType(elem, t);
  1748. }
  1749. }
  1750. return;
  1751. }
  1752. var handlers = data.handlers[type];
  1753. // If no handlers exist, nothing to unbind
  1754. if (!handlers) {
  1755. return;
  1756. }
  1757. // If no listener was provided, remove all listeners for type
  1758. if (!fn) {
  1759. removeType(elem, type);
  1760. return;
  1761. }
  1762. // We're only removing a single handler
  1763. if (fn.guid) {
  1764. for (var n = 0; n < handlers.length; n++) {
  1765. if (handlers[n].guid === fn.guid) {
  1766. handlers.splice(n--, 1);
  1767. }
  1768. }
  1769. }
  1770. _cleanUpEvents(elem, type);
  1771. }
  1772. /**
  1773. * Trigger an event for an element
  1774. *
  1775. * @param {Element|Object} elem
  1776. * Element to trigger an event on
  1777. *
  1778. * @param {EventTarget~Event|string} event
  1779. * A string (the type) or an event object with a type attribute
  1780. *
  1781. * @param {Object} [hash]
  1782. * data hash to pass along with the event
  1783. *
  1784. * @return {boolean|undefined}
  1785. * - Returns the opposite of `defaultPrevented` if default was prevented
  1786. * - Otherwise returns undefined
  1787. */
  1788. function trigger(elem, event, hash) {
  1789. // Fetches element data and a reference to the parent (for bubbling).
  1790. // Don't want to add a data object to cache for every parent,
  1791. // so checking hasElData first.
  1792. var elemData = hasData(elem) ? getData(elem) : {};
  1793. var parent = elem.parentNode || elem.ownerDocument;
  1794. // type = event.type || event,
  1795. // handler;
  1796. // If an event name was passed as a string, creates an event out of it
  1797. if (typeof event === 'string') {
  1798. event = { type: event, target: elem };
  1799. } else if (!event.target) {
  1800. event.target = elem;
  1801. }
  1802. // Normalizes the event properties.
  1803. event = fixEvent(event);
  1804. // If the passed element has a dispatcher, executes the established handlers.
  1805. if (elemData.dispatcher) {
  1806. elemData.dispatcher.call(elem, event, hash);
  1807. }
  1808. // Unless explicitly stopped or the event does not bubble (e.g. media events)
  1809. // recursively calls this function to bubble the event up the DOM.
  1810. if (parent && !event.isPropagationStopped() && event.bubbles === true) {
  1811. trigger.call(null, parent, event, hash);
  1812. // If at the top of the DOM, triggers the default action unless disabled.
  1813. } else if (!parent && !event.defaultPrevented) {
  1814. var targetData = getData(event.target);
  1815. // Checks if the target has a default action for this event.
  1816. if (event.target[event.type]) {
  1817. // Temporarily disables event dispatching on the target as we have already executed the handler.
  1818. targetData.disabled = true;
  1819. // Executes the default action.
  1820. if (typeof event.target[event.type] === 'function') {
  1821. event.target[event.type]();
  1822. }
  1823. // Re-enables event dispatching.
  1824. targetData.disabled = false;
  1825. }
  1826. }
  1827. // Inform the triggerer if the default was prevented by returning false
  1828. return !event.defaultPrevented;
  1829. }
  1830. /**
  1831. * Trigger a listener only once for an event
  1832. *
  1833. * @param {Element|Object} elem
  1834. * Element or object to bind to.
  1835. *
  1836. * @param {string|string[]} type
  1837. * Name/type of event
  1838. *
  1839. * @param {Event~EventListener} fn
  1840. * Event Listener function
  1841. */
  1842. function one(elem, type, fn) {
  1843. if (Array.isArray(type)) {
  1844. return _handleMultipleEvents(one, elem, type, fn);
  1845. }
  1846. var func = function func() {
  1847. off(elem, type, func);
  1848. fn.apply(this, arguments);
  1849. };
  1850. // copy the guid to the new function so it can removed using the original function's ID
  1851. func.guid = fn.guid = fn.guid || newGUID();
  1852. on(elem, type, func);
  1853. }
  1854. var Events = (Object.freeze || Object)({
  1855. fixEvent: fixEvent,
  1856. on: on,
  1857. off: off,
  1858. trigger: trigger,
  1859. one: one
  1860. });
  1861. /**
  1862. * @file setup.js - Functions for setting up a player without
  1863. * user interaction based on the data-setup `attribute` of the video tag.
  1864. *
  1865. * @module setup
  1866. */
  1867. var _windowLoaded = false;
  1868. var videojs$2 = void 0;
  1869. /**
  1870. * Set up any tags that have a data-setup `attribute` when the player is started.
  1871. */
  1872. var autoSetup = function autoSetup() {
  1873. // Protect against breakage in non-browser environments and check global autoSetup option.
  1874. if (!isReal() || videojs$2.options.autoSetup === false) {
  1875. return;
  1876. }
  1877. // One day, when we stop supporting IE8, go back to this, but in the meantime...*hack hack hack*
  1878. // var vids = Array.prototype.slice.call(document.getElementsByTagName('video'));
  1879. // var audios = Array.prototype.slice.call(document.getElementsByTagName('audio'));
  1880. // var mediaEls = vids.concat(audios);
  1881. // Because IE8 doesn't support calling slice on a node list, we need to loop
  1882. // through each list of elements to build up a new, combined list of elements.
  1883. var vids = document.getElementsByTagName('video');
  1884. var audios = document.getElementsByTagName('audio');
  1885. var divs = document.getElementsByTagName('video-js');
  1886. var mediaEls = [];
  1887. if (vids && vids.length > 0) {
  1888. for (var i = 0, e = vids.length; i < e; i++) {
  1889. mediaEls.push(vids[i]);
  1890. }
  1891. }
  1892. if (audios && audios.length > 0) {
  1893. for (var _i = 0, _e = audios.length; _i < _e; _i++) {
  1894. mediaEls.push(audios[_i]);
  1895. }
  1896. }
  1897. if (divs && divs.length > 0) {
  1898. for (var _i2 = 0, _e2 = divs.length; _i2 < _e2; _i2++) {
  1899. mediaEls.push(divs[_i2]);
  1900. }
  1901. }
  1902. // Check if any media elements exist
  1903. if (mediaEls && mediaEls.length > 0) {
  1904. for (var _i3 = 0, _e3 = mediaEls.length; _i3 < _e3; _i3++) {
  1905. var mediaEl = mediaEls[_i3];
  1906. // Check if element exists, has getAttribute func.
  1907. // IE seems to consider typeof el.getAttribute == 'object' instead of
  1908. // 'function' like expected, at least when loading the player immediately.
  1909. if (mediaEl && mediaEl.getAttribute) {
  1910. // Make sure this player hasn't already been set up.
  1911. if (mediaEl.player === undefined) {
  1912. var options = mediaEl.getAttribute('data-setup');
  1913. // Check if data-setup attr exists.
  1914. // We only auto-setup if they've added the data-setup attr.
  1915. if (options !== null) {
  1916. // Create new video.js instance.
  1917. videojs$2(mediaEl);
  1918. }
  1919. }
  1920. // If getAttribute isn't defined, we need to wait for the DOM.
  1921. } else {
  1922. autoSetupTimeout(1);
  1923. break;
  1924. }
  1925. }
  1926. // No videos were found, so keep looping unless page is finished loading.
  1927. } else if (!_windowLoaded) {
  1928. autoSetupTimeout(1);
  1929. }
  1930. };
  1931. /**
  1932. * Wait until the page is loaded before running autoSetup. This will be called in
  1933. * autoSetup if `hasLoaded` returns false.
  1934. *
  1935. * @param {number} wait
  1936. * How long to wait in ms
  1937. *
  1938. * @param {module:videojs} [vjs]
  1939. * The videojs library function
  1940. */
  1941. function autoSetupTimeout(wait, vjs) {
  1942. if (vjs) {
  1943. videojs$2 = vjs;
  1944. }
  1945. window.setTimeout(autoSetup, wait);
  1946. }
  1947. if (isReal() && document.readyState === 'complete') {
  1948. _windowLoaded = true;
  1949. } else {
  1950. /**
  1951. * Listen for the load event on window, and set _windowLoaded to true.
  1952. *
  1953. * @listens load
  1954. */
  1955. one(window, 'load', function () {
  1956. _windowLoaded = true;
  1957. });
  1958. }
  1959. /**
  1960. * @file stylesheet.js
  1961. * @module stylesheet
  1962. */
  1963. /**
  1964. * Create a DOM syle element given a className for it.
  1965. *
  1966. * @param {string} className
  1967. * The className to add to the created style element.
  1968. *
  1969. * @return {Element}
  1970. * The element that was created.
  1971. */
  1972. var createStyleElement = function createStyleElement(className) {
  1973. var style = document.createElement('style');
  1974. style.className = className;
  1975. return style;
  1976. };
  1977. /**
  1978. * Add text to a DOM element.
  1979. *
  1980. * @param {Element} el
  1981. * The Element to add text content to.
  1982. *
  1983. * @param {string} content
  1984. * The text to add to the element.
  1985. */
  1986. var setTextContent = function setTextContent(el, content) {
  1987. if (el.styleSheet) {
  1988. el.styleSheet.cssText = content;
  1989. } else {
  1990. el.textContent = content;
  1991. }
  1992. };
  1993. /**
  1994. * @file fn.js
  1995. * @module fn
  1996. */
  1997. /**
  1998. * Bind (a.k.a proxy or Context). A simple method for changing the context of a function
  1999. * It also stores a unique id on the function so it can be easily removed from events.
  2000. *
  2001. * @param {Mixed} context
  2002. * The object to bind as scope.
  2003. *
  2004. * @param {Function} fn
  2005. * The function to be bound to a scope.
  2006. *
  2007. * @param {number} [uid]
  2008. * An optional unique ID for the function to be set
  2009. *
  2010. * @return {Function}
  2011. * The new function that will be bound into the context given
  2012. */
  2013. var bind = function bind(context, fn, uid) {
  2014. // Make sure the function has a unique ID
  2015. if (!fn.guid) {
  2016. fn.guid = newGUID();
  2017. }
  2018. // Create the new function that changes the context
  2019. var bound = function bound() {
  2020. return fn.apply(context, arguments);
  2021. };
  2022. // Allow for the ability to individualize this function
  2023. // Needed in the case where multiple objects might share the same prototype
  2024. // IF both items add an event listener with the same function, then you try to remove just one
  2025. // it will remove both because they both have the same guid.
  2026. // when using this, you need to use the bind method when you remove the listener as well.
  2027. // currently used in text tracks
  2028. bound.guid = uid ? uid + '_' + fn.guid : fn.guid;
  2029. return bound;
  2030. };
  2031. /**
  2032. * Wraps the given function, `fn`, with a new function that only invokes `fn`
  2033. * at most once per every `wait` milliseconds.
  2034. *
  2035. * @param {Function} fn
  2036. * The function to be throttled.
  2037. *
  2038. * @param {Number} wait
  2039. * The number of milliseconds by which to throttle.
  2040. *
  2041. * @return {Function}
  2042. */
  2043. var throttle = function throttle(fn, wait) {
  2044. var last = Date.now();
  2045. var throttled = function throttled() {
  2046. var now = Date.now();
  2047. if (now - last >= wait) {
  2048. fn.apply(undefined, arguments);
  2049. last = now;
  2050. }
  2051. };
  2052. return throttled;
  2053. };
  2054. /**
  2055. * Creates a debounced function that delays invoking `func` until after `wait`
  2056. * milliseconds have elapsed since the last time the debounced function was
  2057. * invoked.
  2058. *
  2059. * Inspired by lodash and underscore implementations.
  2060. *
  2061. * @param {Function} func
  2062. * The function to wrap with debounce behavior.
  2063. *
  2064. * @param {number} wait
  2065. * The number of milliseconds to wait after the last invocation.
  2066. *
  2067. * @param {boolean} [immediate]
  2068. * Whether or not to invoke the function immediately upon creation.
  2069. *
  2070. * @param {Object} [context=window]
  2071. * The "context" in which the debounced function should debounce. For
  2072. * example, if this function should be tied to a Video.js player,
  2073. * the player can be passed here. Alternatively, defaults to the
  2074. * global `window` object.
  2075. *
  2076. * @return {Function}
  2077. * A debounced function.
  2078. */
  2079. var debounce = function debounce(func, wait, immediate) {
  2080. var context = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : window;
  2081. var timeout = void 0;
  2082. var cancel = function cancel() {
  2083. context.clearTimeout(timeout);
  2084. timeout = null;
  2085. };
  2086. /* eslint-disable consistent-this */
  2087. var debounced = function debounced() {
  2088. var self = this;
  2089. var args = arguments;
  2090. var _later = function later() {
  2091. timeout = null;
  2092. _later = null;
  2093. if (!immediate) {
  2094. func.apply(self, args);
  2095. }
  2096. };
  2097. if (!timeout && immediate) {
  2098. func.apply(self, args);
  2099. }
  2100. context.clearTimeout(timeout);
  2101. timeout = context.setTimeout(_later, wait);
  2102. };
  2103. /* eslint-enable consistent-this */
  2104. debounced.cancel = cancel;
  2105. return debounced;
  2106. };
  2107. /**
  2108. * @file src/js/event-target.js
  2109. */
  2110. /**
  2111. * `EventTarget` is a class that can have the same API as the DOM `EventTarget`. It
  2112. * adds shorthand functions that wrap around lengthy functions. For example:
  2113. * the `on` function is a wrapper around `addEventListener`.
  2114. *
  2115. * @see [EventTarget Spec]{@link https://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget}
  2116. * @class EventTarget
  2117. */
  2118. var EventTarget = function EventTarget() {};
  2119. /**
  2120. * A Custom DOM event.
  2121. *
  2122. * @typedef {Object} EventTarget~Event
  2123. * @see [Properties]{@link https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent}
  2124. */
  2125. /**
  2126. * All event listeners should follow the following format.
  2127. *
  2128. * @callback EventTarget~EventListener
  2129. * @this {EventTarget}
  2130. *
  2131. * @param {EventTarget~Event} event
  2132. * the event that triggered this function
  2133. *
  2134. * @param {Object} [hash]
  2135. * hash of data sent during the event
  2136. */
  2137. /**
  2138. * An object containing event names as keys and booleans as values.
  2139. *
  2140. * > NOTE: If an event name is set to a true value here {@link EventTarget#trigger}
  2141. * will have extra functionality. See that function for more information.
  2142. *
  2143. * @property EventTarget.prototype.allowedEvents_
  2144. * @private
  2145. */
  2146. EventTarget.prototype.allowedEvents_ = {};
  2147. /**
  2148. * Adds an `event listener` to an instance of an `EventTarget`. An `event listener` is a
  2149. * function that will get called when an event with a certain name gets triggered.
  2150. *
  2151. * @param {string|string[]} type
  2152. * An event name or an array of event names.
  2153. *
  2154. * @param {EventTarget~EventListener} fn
  2155. * The function to call with `EventTarget`s
  2156. */
  2157. EventTarget.prototype.on = function (type, fn) {
  2158. // Remove the addEventListener alias before calling Events.on
  2159. // so we don't get into an infinite type loop
  2160. var ael = this.addEventListener;
  2161. this.addEventListener = function () {};
  2162. on(this, type, fn);
  2163. this.addEventListener = ael;
  2164. };
  2165. /**
  2166. * An alias of {@link EventTarget#on}. Allows `EventTarget` to mimic
  2167. * the standard DOM API.
  2168. *
  2169. * @function
  2170. * @see {@link EventTarget#on}
  2171. */
  2172. EventTarget.prototype.addEventListener = EventTarget.prototype.on;
  2173. /**
  2174. * Removes an `event listener` for a specific event from an instance of `EventTarget`.
  2175. * This makes it so that the `event listener` will no longer get called when the
  2176. * named event happens.
  2177. *
  2178. * @param {string|string[]} type
  2179. * An event name or an array of event names.
  2180. *
  2181. * @param {EventTarget~EventListener} fn
  2182. * The function to remove.
  2183. */
  2184. EventTarget.prototype.off = function (type, fn) {
  2185. off(this, type, fn);
  2186. };
  2187. /**
  2188. * An alias of {@link EventTarget#off}. Allows `EventTarget` to mimic
  2189. * the standard DOM API.
  2190. *
  2191. * @function
  2192. * @see {@link EventTarget#off}
  2193. */
  2194. EventTarget.prototype.removeEventListener = EventTarget.prototype.off;
  2195. /**
  2196. * This function will add an `event listener` that gets triggered only once. After the
  2197. * first trigger it will get removed. This is like adding an `event listener`
  2198. * with {@link EventTarget#on} that calls {@link EventTarget#off} on itself.
  2199. *
  2200. * @param {string|string[]} type
  2201. * An event name or an array of event names.
  2202. *
  2203. * @param {EventTarget~EventListener} fn
  2204. * The function to be called once for each event name.
  2205. */
  2206. EventTarget.prototype.one = function (type, fn) {
  2207. // Remove the addEventListener alialing Events.on
  2208. // so we don't get into an infinite type loop
  2209. var ael = this.addEventListener;
  2210. this.addEventListener = function () {};
  2211. one(this, type, fn);
  2212. this.addEventListener = ael;
  2213. };
  2214. /**
  2215. * This function causes an event to happen. This will then cause any `event listeners`
  2216. * that are waiting for that event, to get called. If there are no `event listeners`
  2217. * for an event then nothing will happen.
  2218. *
  2219. * If the name of the `Event` that is being triggered is in `EventTarget.allowedEvents_`.
  2220. * Trigger will also call the `on` + `uppercaseEventName` function.
  2221. *
  2222. * Example:
  2223. * 'click' is in `EventTarget.allowedEvents_`, so, trigger will attempt to call
  2224. * `onClick` if it exists.
  2225. *
  2226. * @param {string|EventTarget~Event|Object} event
  2227. * The name of the event, an `Event`, or an object with a key of type set to
  2228. * an event name.
  2229. */
  2230. EventTarget.prototype.trigger = function (event) {
  2231. var type = event.type || event;
  2232. if (typeof event === 'string') {
  2233. event = { type: type };
  2234. }
  2235. event = fixEvent(event);
  2236. if (this.allowedEvents_[type] && this['on' + type]) {
  2237. this['on' + type](event);
  2238. }
  2239. trigger(this, event);
  2240. };
  2241. /**
  2242. * An alias of {@link EventTarget#trigger}. Allows `EventTarget` to mimic
  2243. * the standard DOM API.
  2244. *
  2245. * @function
  2246. * @see {@link EventTarget#trigger}
  2247. */
  2248. EventTarget.prototype.dispatchEvent = EventTarget.prototype.trigger;
  2249. /**
  2250. * @file mixins/evented.js
  2251. * @module evented
  2252. */
  2253. /**
  2254. * Returns whether or not an object has had the evented mixin applied.
  2255. *
  2256. * @param {Object} object
  2257. * An object to test.
  2258. *
  2259. * @return {boolean}
  2260. * Whether or not the object appears to be evented.
  2261. */
  2262. var isEvented = function isEvented(object) {
  2263. return object instanceof EventTarget || !!object.eventBusEl_ && ['on', 'one', 'off', 'trigger'].every(function (k) {
  2264. return typeof object[k] === 'function';
  2265. });
  2266. };
  2267. /**
  2268. * Whether a value is a valid event type - non-empty string or array.
  2269. *
  2270. * @private
  2271. * @param {string|Array} type
  2272. * The type value to test.
  2273. *
  2274. * @return {boolean}
  2275. * Whether or not the type is a valid event type.
  2276. */
  2277. var isValidEventType = function isValidEventType(type) {
  2278. return (
  2279. // The regex here verifies that the `type` contains at least one non-
  2280. // whitespace character.
  2281. typeof type === 'string' && /\S/.test(type) || Array.isArray(type) && !!type.length
  2282. );
  2283. };
  2284. /**
  2285. * Validates a value to determine if it is a valid event target. Throws if not.
  2286. *
  2287. * @private
  2288. * @throws {Error}
  2289. * If the target does not appear to be a valid event target.
  2290. *
  2291. * @param {Object} target
  2292. * The object to test.
  2293. */
  2294. var validateTarget = function validateTarget(target) {
  2295. if (!target.nodeName && !isEvented(target)) {
  2296. throw new Error('Invalid target; must be a DOM node or evented object.');
  2297. }
  2298. };
  2299. /**
  2300. * Validates a value to determine if it is a valid event target. Throws if not.
  2301. *
  2302. * @private
  2303. * @throws {Error}
  2304. * If the type does not appear to be a valid event type.
  2305. *
  2306. * @param {string|Array} type
  2307. * The type to test.
  2308. */
  2309. var validateEventType = function validateEventType(type) {
  2310. if (!isValidEventType(type)) {
  2311. throw new Error('Invalid event type; must be a non-empty string or array.');
  2312. }
  2313. };
  2314. /**
  2315. * Validates a value to determine if it is a valid listener. Throws if not.
  2316. *
  2317. * @private
  2318. * @throws {Error}
  2319. * If the listener is not a function.
  2320. *
  2321. * @param {Function} listener
  2322. * The listener to test.
  2323. */
  2324. var validateListener = function validateListener(listener) {
  2325. if (typeof listener !== 'function') {
  2326. throw new Error('Invalid listener; must be a function.');
  2327. }
  2328. };
  2329. /**
  2330. * Takes an array of arguments given to `on()` or `one()`, validates them, and
  2331. * normalizes them into an object.
  2332. *
  2333. * @private
  2334. * @param {Object} self
  2335. * The evented object on which `on()` or `one()` was called. This
  2336. * object will be bound as the `this` value for the listener.
  2337. *
  2338. * @param {Array} args
  2339. * An array of arguments passed to `on()` or `one()`.
  2340. *
  2341. * @return {Object}
  2342. * An object containing useful values for `on()` or `one()` calls.
  2343. */
  2344. var normalizeListenArgs = function normalizeListenArgs(self, args) {
  2345. // If the number of arguments is less than 3, the target is always the
  2346. // evented object itself.
  2347. var isTargetingSelf = args.length < 3 || args[0] === self || args[0] === self.eventBusEl_;
  2348. var target = void 0;
  2349. var type = void 0;
  2350. var listener = void 0;
  2351. if (isTargetingSelf) {
  2352. target = self.eventBusEl_;
  2353. // Deal with cases where we got 3 arguments, but we are still listening to
  2354. // the evented object itself.
  2355. if (args.length >= 3) {
  2356. args.shift();
  2357. }
  2358. type = args[0];
  2359. listener = args[1];
  2360. } else {
  2361. target = args[0];
  2362. type = args[1];
  2363. listener = args[2];
  2364. }
  2365. validateTarget(target);
  2366. validateEventType(type);
  2367. validateListener(listener);
  2368. listener = bind(self, listener);
  2369. return { isTargetingSelf: isTargetingSelf, target: target, type: type, listener: listener };
  2370. };
  2371. /**
  2372. * Adds the listener to the event type(s) on the target, normalizing for
  2373. * the type of target.
  2374. *
  2375. * @private
  2376. * @param {Element|Object} target
  2377. * A DOM node or evented object.
  2378. *
  2379. * @param {string} method
  2380. * The event binding method to use ("on" or "one").
  2381. *
  2382. * @param {string|Array} type
  2383. * One or more event type(s).
  2384. *
  2385. * @param {Function} listener
  2386. * A listener function.
  2387. */
  2388. var listen = function listen(target, method, type, listener) {
  2389. validateTarget(target);
  2390. if (target.nodeName) {
  2391. Events[method](target, type, listener);
  2392. } else {
  2393. target[method](type, listener);
  2394. }
  2395. };
  2396. /**
  2397. * Contains methods that provide event capabilites to an object which is passed
  2398. * to {@link module:evented|evented}.
  2399. *
  2400. * @mixin EventedMixin
  2401. */
  2402. var EventedMixin = {
  2403. /**
  2404. * Add a listener to an event (or events) on this object or another evented
  2405. * object.
  2406. *
  2407. * @param {string|Array|Element|Object} targetOrType
  2408. * If this is a string or array, it represents the event type(s)
  2409. * that will trigger the listener.
  2410. *
  2411. * Another evented object can be passed here instead, which will
  2412. * cause the listener to listen for events on _that_ object.
  2413. *
  2414. * In either case, the listener's `this` value will be bound to
  2415. * this object.
  2416. *
  2417. * @param {string|Array|Function} typeOrListener
  2418. * If the first argument was a string or array, this should be the
  2419. * listener function. Otherwise, this is a string or array of event
  2420. * type(s).
  2421. *
  2422. * @param {Function} [listener]
  2423. * If the first argument was another evented object, this will be
  2424. * the listener function.
  2425. */
  2426. on: function on$$1() {
  2427. var _this = this;
  2428. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  2429. args[_key] = arguments[_key];
  2430. }
  2431. var _normalizeListenArgs = normalizeListenArgs(this, args),
  2432. isTargetingSelf = _normalizeListenArgs.isTargetingSelf,
  2433. target = _normalizeListenArgs.target,
  2434. type = _normalizeListenArgs.type,
  2435. listener = _normalizeListenArgs.listener;
  2436. listen(target, 'on', type, listener);
  2437. // If this object is listening to another evented object.
  2438. if (!isTargetingSelf) {
  2439. // If this object is disposed, remove the listener.
  2440. var removeListenerOnDispose = function removeListenerOnDispose() {
  2441. return _this.off(target, type, listener);
  2442. };
  2443. // Use the same function ID as the listener so we can remove it later it
  2444. // using the ID of the original listener.
  2445. removeListenerOnDispose.guid = listener.guid;
  2446. // Add a listener to the target's dispose event as well. This ensures
  2447. // that if the target is disposed BEFORE this object, we remove the
  2448. // removal listener that was just added. Otherwise, we create a memory leak.
  2449. var removeRemoverOnTargetDispose = function removeRemoverOnTargetDispose() {
  2450. return _this.off('dispose', removeListenerOnDispose);
  2451. };
  2452. // Use the same function ID as the listener so we can remove it later
  2453. // it using the ID of the original listener.
  2454. removeRemoverOnTargetDispose.guid = listener.guid;
  2455. listen(this, 'on', 'dispose', removeListenerOnDispose);
  2456. listen(target, 'on', 'dispose', removeRemoverOnTargetDispose);
  2457. }
  2458. },
  2459. /**
  2460. * Add a listener to an event (or events) on this object or another evented
  2461. * object. The listener will only be called once and then removed.
  2462. *
  2463. * @param {string|Array|Element|Object} targetOrType
  2464. * If this is a string or array, it represents the event type(s)
  2465. * that will trigger the listener.
  2466. *
  2467. * Another evented object can be passed here instead, which will
  2468. * cause the listener to listen for events on _that_ object.
  2469. *
  2470. * In either case, the listener's `this` value will be bound to
  2471. * this object.
  2472. *
  2473. * @param {string|Array|Function} typeOrListener
  2474. * If the first argument was a string or array, this should be the
  2475. * listener function. Otherwise, this is a string or array of event
  2476. * type(s).
  2477. *
  2478. * @param {Function} [listener]
  2479. * If the first argument was another evented object, this will be
  2480. * the listener function.
  2481. */
  2482. one: function one$$1() {
  2483. var _this2 = this;
  2484. for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  2485. args[_key2] = arguments[_key2];
  2486. }
  2487. var _normalizeListenArgs2 = normalizeListenArgs(this, args),
  2488. isTargetingSelf = _normalizeListenArgs2.isTargetingSelf,
  2489. target = _normalizeListenArgs2.target,
  2490. type = _normalizeListenArgs2.type,
  2491. listener = _normalizeListenArgs2.listener;
  2492. // Targeting this evented object.
  2493. if (isTargetingSelf) {
  2494. listen(target, 'one', type, listener);
  2495. // Targeting another evented object.
  2496. } else {
  2497. var wrapper = function wrapper() {
  2498. for (var _len3 = arguments.length, largs = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  2499. largs[_key3] = arguments[_key3];
  2500. }
  2501. _this2.off(target, type, wrapper);
  2502. listener.apply(null, largs);
  2503. };
  2504. // Use the same function ID as the listener so we can remove it later
  2505. // it using the ID of the original listener.
  2506. wrapper.guid = listener.guid;
  2507. listen(target, 'one', type, wrapper);
  2508. }
  2509. },
  2510. /**
  2511. * Removes listener(s) from event(s) on an evented object.
  2512. *
  2513. * @param {string|Array|Element|Object} [targetOrType]
  2514. * If this is a string or array, it represents the event type(s).
  2515. *
  2516. * Another evented object can be passed here instead, in which case
  2517. * ALL 3 arguments are _required_.
  2518. *
  2519. * @param {string|Array|Function} [typeOrListener]
  2520. * If the first argument was a string or array, this may be the
  2521. * listener function. Otherwise, this is a string or array of event
  2522. * type(s).
  2523. *
  2524. * @param {Function} [listener]
  2525. * If the first argument was another evented object, this will be
  2526. * the listener function; otherwise, _all_ listeners bound to the
  2527. * event type(s) will be removed.
  2528. */
  2529. off: function off$$1(targetOrType, typeOrListener, listener) {
  2530. // Targeting this evented object.
  2531. if (!targetOrType || isValidEventType(targetOrType)) {
  2532. off(this.eventBusEl_, targetOrType, typeOrListener);
  2533. // Targeting another evented object.
  2534. } else {
  2535. var target = targetOrType;
  2536. var type = typeOrListener;
  2537. // Fail fast and in a meaningful way!
  2538. validateTarget(target);
  2539. validateEventType(type);
  2540. validateListener(listener);
  2541. // Ensure there's at least a guid, even if the function hasn't been used
  2542. listener = bind(this, listener);
  2543. // Remove the dispose listener on this evented object, which was given
  2544. // the same guid as the event listener in on().
  2545. this.off('dispose', listener);
  2546. if (target.nodeName) {
  2547. off(target, type, listener);
  2548. off(target, 'dispose', listener);
  2549. } else if (isEvented(target)) {
  2550. target.off(type, listener);
  2551. target.off('dispose', listener);
  2552. }
  2553. }
  2554. },
  2555. /**
  2556. * Fire an event on this evented object, causing its listeners to be called.
  2557. *
  2558. * @param {string|Object} event
  2559. * An event type or an object with a type property.
  2560. *
  2561. * @param {Object} [hash]
  2562. * An additional object to pass along to listeners.
  2563. *
  2564. * @returns {boolean}
  2565. * Whether or not the default behavior was prevented.
  2566. */
  2567. trigger: function trigger$$1(event, hash) {
  2568. return trigger(this.eventBusEl_, event, hash);
  2569. }
  2570. };
  2571. /**
  2572. * Applies {@link module:evented~EventedMixin|EventedMixin} to a target object.
  2573. *
  2574. * @param {Object} target
  2575. * The object to which to add event methods.
  2576. *
  2577. * @param {Object} [options={}]
  2578. * Options for customizing the mixin behavior.
  2579. *
  2580. * @param {String} [options.eventBusKey]
  2581. * By default, adds a `eventBusEl_` DOM element to the target object,
  2582. * which is used as an event bus. If the target object already has a
  2583. * DOM element that should be used, pass its key here.
  2584. *
  2585. * @return {Object}
  2586. * The target object.
  2587. */
  2588. function evented(target) {
  2589. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  2590. var eventBusKey = options.eventBusKey;
  2591. // Set or create the eventBusEl_.
  2592. if (eventBusKey) {
  2593. if (!target[eventBusKey].nodeName) {
  2594. throw new Error('The eventBusKey "' + eventBusKey + '" does not refer to an element.');
  2595. }
  2596. target.eventBusEl_ = target[eventBusKey];
  2597. } else {
  2598. target.eventBusEl_ = createEl('span', { className: 'vjs-event-bus' });
  2599. }
  2600. assign(target, EventedMixin);
  2601. // When any evented object is disposed, it removes all its listeners.
  2602. target.on('dispose', function () {
  2603. target.off();
  2604. window.setTimeout(function () {
  2605. target.eventBusEl_ = null;
  2606. }, 0);
  2607. });
  2608. return target;
  2609. }
  2610. /**
  2611. * @file mixins/stateful.js
  2612. * @module stateful
  2613. */
  2614. /**
  2615. * Contains methods that provide statefulness to an object which is passed
  2616. * to {@link module:stateful}.
  2617. *
  2618. * @mixin StatefulMixin
  2619. */
  2620. var StatefulMixin = {
  2621. /**
  2622. * A hash containing arbitrary keys and values representing the state of
  2623. * the object.
  2624. *
  2625. * @type {Object}
  2626. */
  2627. state: {},
  2628. /**
  2629. * Set the state of an object by mutating its
  2630. * {@link module:stateful~StatefulMixin.state|state} object in place.
  2631. *
  2632. * @fires module:stateful~StatefulMixin#statechanged
  2633. * @param {Object|Function} stateUpdates
  2634. * A new set of properties to shallow-merge into the plugin state.
  2635. * Can be a plain object or a function returning a plain object.
  2636. *
  2637. * @returns {Object|undefined}
  2638. * An object containing changes that occurred. If no changes
  2639. * occurred, returns `undefined`.
  2640. */
  2641. setState: function setState(stateUpdates) {
  2642. var _this = this;
  2643. // Support providing the `stateUpdates` state as a function.
  2644. if (typeof stateUpdates === 'function') {
  2645. stateUpdates = stateUpdates();
  2646. }
  2647. var changes = void 0;
  2648. each(stateUpdates, function (value, key) {
  2649. // Record the change if the value is different from what's in the
  2650. // current state.
  2651. if (_this.state[key] !== value) {
  2652. changes = changes || {};
  2653. changes[key] = {
  2654. from: _this.state[key],
  2655. to: value
  2656. };
  2657. }
  2658. _this.state[key] = value;
  2659. });
  2660. // Only trigger "statechange" if there were changes AND we have a trigger
  2661. // function. This allows us to not require that the target object be an
  2662. // evented object.
  2663. if (changes && isEvented(this)) {
  2664. /**
  2665. * An event triggered on an object that is both
  2666. * {@link module:stateful|stateful} and {@link module:evented|evented}
  2667. * indicating that its state has changed.
  2668. *
  2669. * @event module:stateful~StatefulMixin#statechanged
  2670. * @type {Object}
  2671. * @property {Object} changes
  2672. * A hash containing the properties that were changed and
  2673. * the values they were changed `from` and `to`.
  2674. */
  2675. this.trigger({
  2676. changes: changes,
  2677. type: 'statechanged'
  2678. });
  2679. }
  2680. return changes;
  2681. }
  2682. };
  2683. /**
  2684. * Applies {@link module:stateful~StatefulMixin|StatefulMixin} to a target
  2685. * object.
  2686. *
  2687. * If the target object is {@link module:evented|evented} and has a
  2688. * `handleStateChanged` method, that method will be automatically bound to the
  2689. * `statechanged` event on itself.
  2690. *
  2691. * @param {Object} target
  2692. * The object to be made stateful.
  2693. *
  2694. * @param {Object} [defaultState]
  2695. * A default set of properties to populate the newly-stateful object's
  2696. * `state` property.
  2697. *
  2698. * @returns {Object}
  2699. * Returns the `target`.
  2700. */
  2701. function stateful(target, defaultState) {
  2702. assign(target, StatefulMixin);
  2703. // This happens after the mixing-in because we need to replace the `state`
  2704. // added in that step.
  2705. target.state = assign({}, target.state, defaultState);
  2706. // Auto-bind the `handleStateChanged` method of the target object if it exists.
  2707. if (typeof target.handleStateChanged === 'function' && isEvented(target)) {
  2708. target.on('statechanged', target.handleStateChanged);
  2709. }
  2710. return target;
  2711. }
  2712. /**
  2713. * @file to-title-case.js
  2714. * @module to-title-case
  2715. */
  2716. /**
  2717. * Uppercase the first letter of a string.
  2718. *
  2719. * @param {string} string
  2720. * String to be uppercased
  2721. *
  2722. * @return {string}
  2723. * The string with an uppercased first letter
  2724. */
  2725. function toTitleCase(string) {
  2726. if (typeof string !== 'string') {
  2727. return string;
  2728. }
  2729. return string.charAt(0).toUpperCase() + string.slice(1);
  2730. }
  2731. /**
  2732. * Compares the TitleCase versions of the two strings for equality.
  2733. *
  2734. * @param {string} str1
  2735. * The first string to compare
  2736. *
  2737. * @param {string} str2
  2738. * The second string to compare
  2739. *
  2740. * @return {boolean}
  2741. * Whether the TitleCase versions of the strings are equal
  2742. */
  2743. function titleCaseEquals(str1, str2) {
  2744. return toTitleCase(str1) === toTitleCase(str2);
  2745. }
  2746. /**
  2747. * @file merge-options.js
  2748. * @module merge-options
  2749. */
  2750. /**
  2751. * Deep-merge one or more options objects, recursively merging **only** plain
  2752. * object properties.
  2753. *
  2754. * @param {Object[]} sources
  2755. * One or more objects to merge into a new object.
  2756. *
  2757. * @returns {Object}
  2758. * A new object that is the merged result of all sources.
  2759. */
  2760. function mergeOptions() {
  2761. var result = {};
  2762. for (var _len = arguments.length, sources = Array(_len), _key = 0; _key < _len; _key++) {
  2763. sources[_key] = arguments[_key];
  2764. }
  2765. sources.forEach(function (source) {
  2766. if (!source) {
  2767. return;
  2768. }
  2769. each(source, function (value, key) {
  2770. if (!isPlain(value)) {
  2771. result[key] = value;
  2772. return;
  2773. }
  2774. if (!isPlain(result[key])) {
  2775. result[key] = {};
  2776. }
  2777. result[key] = mergeOptions(result[key], value);
  2778. });
  2779. });
  2780. return result;
  2781. }
  2782. /**
  2783. * Player Component - Base class for all UI objects
  2784. *
  2785. * @file component.js
  2786. */
  2787. /**
  2788. * Base class for all UI Components.
  2789. * Components are UI objects which represent both a javascript object and an element
  2790. * in the DOM. They can be children of other components, and can have
  2791. * children themselves.
  2792. *
  2793. * Components can also use methods from {@link EventTarget}
  2794. */
  2795. var Component = function () {
  2796. /**
  2797. * A callback that is called when a component is ready. Does not have any
  2798. * paramters and any callback value will be ignored.
  2799. *
  2800. * @callback Component~ReadyCallback
  2801. * @this Component
  2802. */
  2803. /**
  2804. * Creates an instance of this class.
  2805. *
  2806. * @param {Player} player
  2807. * The `Player` that this class should be attached to.
  2808. *
  2809. * @param {Object} [options]
  2810. * The key/value store of player options.
  2811. *
  2812. * @param {Object[]} [options.children]
  2813. * An array of children objects to intialize this component with. Children objects have
  2814. * a name property that will be used if more than one component of the same type needs to be
  2815. * added.
  2816. *
  2817. * @param {Component~ReadyCallback} [ready]
  2818. * Function that gets called when the `Component` is ready.
  2819. */
  2820. function Component(player, options, ready) {
  2821. classCallCheck(this, Component);
  2822. // The component might be the player itself and we can't pass `this` to super
  2823. if (!player && this.play) {
  2824. this.player_ = player = this; // eslint-disable-line
  2825. } else {
  2826. this.player_ = player;
  2827. }
  2828. // Make a copy of prototype.options_ to protect against overriding defaults
  2829. this.options_ = mergeOptions({}, this.options_);
  2830. // Updated options with supplied options
  2831. options = this.options_ = mergeOptions(this.options_, options);
  2832. // Get ID from options or options element if one is supplied
  2833. this.id_ = options.id || options.el && options.el.id;
  2834. // If there was no ID from the options, generate one
  2835. if (!this.id_) {
  2836. // Don't require the player ID function in the case of mock players
  2837. var id = player && player.id && player.id() || 'no_player';
  2838. this.id_ = id + '_component_' + newGUID();
  2839. }
  2840. this.name_ = options.name || null;
  2841. // Create element if one wasn't provided in options
  2842. if (options.el) {
  2843. this.el_ = options.el;
  2844. } else if (options.createEl !== false) {
  2845. this.el_ = this.createEl();
  2846. }
  2847. // if evented is anything except false, we want to mixin in evented
  2848. if (options.evented !== false) {
  2849. // Make this an evented object and use `el_`, if available, as its event bus
  2850. evented(this, { eventBusKey: this.el_ ? 'el_' : null });
  2851. }
  2852. stateful(this, this.constructor.defaultState);
  2853. this.children_ = [];
  2854. this.childIndex_ = {};
  2855. this.childNameIndex_ = {};
  2856. // Add any child components in options
  2857. if (options.initChildren !== false) {
  2858. this.initChildren();
  2859. }
  2860. this.ready(ready);
  2861. // Don't want to trigger ready here or it will before init is actually
  2862. // finished for all children that run this constructor
  2863. if (options.reportTouchActivity !== false) {
  2864. this.enableTouchActivity();
  2865. }
  2866. }
  2867. /**
  2868. * Dispose of the `Component` and all child components.
  2869. *
  2870. * @fires Component#dispose
  2871. */
  2872. Component.prototype.dispose = function dispose() {
  2873. /**
  2874. * Triggered when a `Component` is disposed.
  2875. *
  2876. * @event Component#dispose
  2877. * @type {EventTarget~Event}
  2878. *
  2879. * @property {boolean} [bubbles=false]
  2880. * set to false so that the close event does not
  2881. * bubble up
  2882. */
  2883. this.trigger({ type: 'dispose', bubbles: false });
  2884. // Dispose all children.
  2885. if (this.children_) {
  2886. for (var i = this.children_.length - 1; i >= 0; i--) {
  2887. if (this.children_[i].dispose) {
  2888. this.children_[i].dispose();
  2889. }
  2890. }
  2891. }
  2892. // Delete child references
  2893. this.children_ = null;
  2894. this.childIndex_ = null;
  2895. this.childNameIndex_ = null;
  2896. if (this.el_) {
  2897. // Remove element from DOM
  2898. if (this.el_.parentNode) {
  2899. this.el_.parentNode.removeChild(this.el_);
  2900. }
  2901. removeData(this.el_);
  2902. this.el_ = null;
  2903. }
  2904. // remove reference to the player after disposing of the element
  2905. this.player_ = null;
  2906. };
  2907. /**
  2908. * Return the {@link Player} that the `Component` has attached to.
  2909. *
  2910. * @return {Player}
  2911. * The player that this `Component` has attached to.
  2912. */
  2913. Component.prototype.player = function player() {
  2914. return this.player_;
  2915. };
  2916. /**
  2917. * Deep merge of options objects with new options.
  2918. * > Note: When both `obj` and `options` contain properties whose values are objects.
  2919. * The two properties get merged using {@link module:mergeOptions}
  2920. *
  2921. * @param {Object} obj
  2922. * The object that contains new options.
  2923. *
  2924. * @return {Object}
  2925. * A new object of `this.options_` and `obj` merged together.
  2926. *
  2927. * @deprecated since version 5
  2928. */
  2929. Component.prototype.options = function options(obj) {
  2930. log.warn('this.options() has been deprecated and will be moved to the constructor in 6.0');
  2931. if (!obj) {
  2932. return this.options_;
  2933. }
  2934. this.options_ = mergeOptions(this.options_, obj);
  2935. return this.options_;
  2936. };
  2937. /**
  2938. * Get the `Component`s DOM element
  2939. *
  2940. * @return {Element}
  2941. * The DOM element for this `Component`.
  2942. */
  2943. Component.prototype.el = function el() {
  2944. return this.el_;
  2945. };
  2946. /**
  2947. * Create the `Component`s DOM element.
  2948. *
  2949. * @param {string} [tagName]
  2950. * Element's DOM node type. e.g. 'div'
  2951. *
  2952. * @param {Object} [properties]
  2953. * An object of properties that should be set.
  2954. *
  2955. * @param {Object} [attributes]
  2956. * An object of attributes that should be set.
  2957. *
  2958. * @return {Element}
  2959. * The element that gets created.
  2960. */
  2961. Component.prototype.createEl = function createEl$$1(tagName, properties, attributes) {
  2962. return createEl(tagName, properties, attributes);
  2963. };
  2964. /**
  2965. * Localize a string given the string in english.
  2966. *
  2967. * If tokens are provided, it'll try and run a simple token replacement on the provided string.
  2968. * The tokens it looks for look like `{1}` with the index being 1-indexed into the tokens array.
  2969. *
  2970. * If a `defaultValue` is provided, it'll use that over `string`,
  2971. * if a value isn't found in provided language files.
  2972. * This is useful if you want to have a descriptive key for token replacement
  2973. * but have a succinct localized string and not require `en.json` to be included.
  2974. *
  2975. * Currently, it is used for the progress bar timing.
  2976. * ```js
  2977. * {
  2978. * "progress bar timing: currentTime={1} duration={2}": "{1} of {2}"
  2979. * }
  2980. * ```
  2981. * It is then used like so:
  2982. * ```js
  2983. * this.localize('progress bar timing: currentTime={1} duration{2}',
  2984. * [this.player_.currentTime(), this.player_.duration()],
  2985. * '{1} of {2}');
  2986. * ```
  2987. *
  2988. * Which outputs something like: `01:23 of 24:56`.
  2989. *
  2990. *
  2991. * @param {string} string
  2992. * The string to localize and the key to lookup in the language files.
  2993. * @param {string[]} [tokens]
  2994. * If the current item has token replacements, provide the tokens here.
  2995. * @param {string} [defaultValue]
  2996. * Defaults to `string`. Can be a default value to use for token replacement
  2997. * if the lookup key is needed to be separate.
  2998. *
  2999. * @return {string}
  3000. * The localized string or if no localization exists the english string.
  3001. */
  3002. Component.prototype.localize = function localize(string, tokens) {
  3003. var defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : string;
  3004. var code = this.player_.language && this.player_.language();
  3005. var languages = this.player_.languages && this.player_.languages();
  3006. var language = languages && languages[code];
  3007. var primaryCode = code && code.split('-')[0];
  3008. var primaryLang = languages && languages[primaryCode];
  3009. var localizedString = defaultValue;
  3010. if (language && language[string]) {
  3011. localizedString = language[string];
  3012. } else if (primaryLang && primaryLang[string]) {
  3013. localizedString = primaryLang[string];
  3014. }
  3015. if (tokens) {
  3016. localizedString = localizedString.replace(/\{(\d+)\}/g, function (match, index) {
  3017. var value = tokens[index - 1];
  3018. var ret = value;
  3019. if (typeof value === 'undefined') {
  3020. ret = match;
  3021. }
  3022. return ret;
  3023. });
  3024. }
  3025. return localizedString;
  3026. };
  3027. /**
  3028. * Return the `Component`s DOM element. This is where children get inserted.
  3029. * This will usually be the the same as the element returned in {@link Component#el}.
  3030. *
  3031. * @return {Element}
  3032. * The content element for this `Component`.
  3033. */
  3034. Component.prototype.contentEl = function contentEl() {
  3035. return this.contentEl_ || this.el_;
  3036. };
  3037. /**
  3038. * Get this `Component`s ID
  3039. *
  3040. * @return {string}
  3041. * The id of this `Component`
  3042. */
  3043. Component.prototype.id = function id() {
  3044. return this.id_;
  3045. };
  3046. /**
  3047. * Get the `Component`s name. The name gets used to reference the `Component`
  3048. * and is set during registration.
  3049. *
  3050. * @return {string}
  3051. * The name of this `Component`.
  3052. */
  3053. Component.prototype.name = function name() {
  3054. return this.name_;
  3055. };
  3056. /**
  3057. * Get an array of all child components
  3058. *
  3059. * @return {Array}
  3060. * The children
  3061. */
  3062. Component.prototype.children = function children() {
  3063. return this.children_;
  3064. };
  3065. /**
  3066. * Returns the child `Component` with the given `id`.
  3067. *
  3068. * @param {string} id
  3069. * The id of the child `Component` to get.
  3070. *
  3071. * @return {Component|undefined}
  3072. * The child `Component` with the given `id` or undefined.
  3073. */
  3074. Component.prototype.getChildById = function getChildById(id) {
  3075. return this.childIndex_[id];
  3076. };
  3077. /**
  3078. * Returns the child `Component` with the given `name`.
  3079. *
  3080. * @param {string} name
  3081. * The name of the child `Component` to get.
  3082. *
  3083. * @return {Component|undefined}
  3084. * The child `Component` with the given `name` or undefined.
  3085. */
  3086. Component.prototype.getChild = function getChild(name) {
  3087. if (!name) {
  3088. return;
  3089. }
  3090. name = toTitleCase(name);
  3091. return this.childNameIndex_[name];
  3092. };
  3093. /**
  3094. * Add a child `Component` inside the current `Component`.
  3095. *
  3096. *
  3097. * @param {string|Component} child
  3098. * The name or instance of a child to add.
  3099. *
  3100. * @param {Object} [options={}]
  3101. * The key/value store of options that will get passed to children of
  3102. * the child.
  3103. *
  3104. * @param {number} [index=this.children_.length]
  3105. * The index to attempt to add a child into.
  3106. *
  3107. * @return {Component}
  3108. * The `Component` that gets added as a child. When using a string the
  3109. * `Component` will get created by this process.
  3110. */
  3111. Component.prototype.addChild = function addChild(child) {
  3112. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  3113. var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.children_.length;
  3114. var component = void 0;
  3115. var componentName = void 0;
  3116. // If child is a string, create component with options
  3117. if (typeof child === 'string') {
  3118. componentName = toTitleCase(child);
  3119. var componentClassName = options.componentClass || componentName;
  3120. // Set name through options
  3121. options.name = componentName;
  3122. // Create a new object & element for this controls set
  3123. // If there's no .player_, this is a player
  3124. var ComponentClass = Component.getComponent(componentClassName);
  3125. if (!ComponentClass) {
  3126. throw new Error('Component ' + componentClassName + ' does not exist');
  3127. }
  3128. // data stored directly on the videojs object may be
  3129. // misidentified as a component to retain
  3130. // backwards-compatibility with 4.x. check to make sure the
  3131. // component class can be instantiated.
  3132. if (typeof ComponentClass !== 'function') {
  3133. return null;
  3134. }
  3135. component = new ComponentClass(this.player_ || this, options);
  3136. // child is a component instance
  3137. } else {
  3138. component = child;
  3139. }
  3140. this.children_.splice(index, 0, component);
  3141. if (typeof component.id === 'function') {
  3142. this.childIndex_[component.id()] = component;
  3143. }
  3144. // If a name wasn't used to create the component, check if we can use the
  3145. // name function of the component
  3146. componentName = componentName || component.name && toTitleCase(component.name());
  3147. if (componentName) {
  3148. this.childNameIndex_[componentName] = component;
  3149. }
  3150. // Add the UI object's element to the container div (box)
  3151. // Having an element is not required
  3152. if (typeof component.el === 'function' && component.el()) {
  3153. var childNodes = this.contentEl().children;
  3154. var refNode = childNodes[index] || null;
  3155. this.contentEl().insertBefore(component.el(), refNode);
  3156. }
  3157. // Return so it can stored on parent object if desired.
  3158. return component;
  3159. };
  3160. /**
  3161. * Remove a child `Component` from this `Component`s list of children. Also removes
  3162. * the child `Component`s element from this `Component`s element.
  3163. *
  3164. * @param {Component} component
  3165. * The child `Component` to remove.
  3166. */
  3167. Component.prototype.removeChild = function removeChild(component) {
  3168. if (typeof component === 'string') {
  3169. component = this.getChild(component);
  3170. }
  3171. if (!component || !this.children_) {
  3172. return;
  3173. }
  3174. var childFound = false;
  3175. for (var i = this.children_.length - 1; i >= 0; i--) {
  3176. if (this.children_[i] === component) {
  3177. childFound = true;
  3178. this.children_.splice(i, 1);
  3179. break;
  3180. }
  3181. }
  3182. if (!childFound) {
  3183. return;
  3184. }
  3185. this.childIndex_[component.id()] = null;
  3186. this.childNameIndex_[component.name()] = null;
  3187. var compEl = component.el();
  3188. if (compEl && compEl.parentNode === this.contentEl()) {
  3189. this.contentEl().removeChild(component.el());
  3190. }
  3191. };
  3192. /**
  3193. * Add and initialize default child `Component`s based upon options.
  3194. */
  3195. Component.prototype.initChildren = function initChildren() {
  3196. var _this = this;
  3197. var children = this.options_.children;
  3198. if (children) {
  3199. // `this` is `parent`
  3200. var parentOptions = this.options_;
  3201. var handleAdd = function handleAdd(child) {
  3202. var name = child.name;
  3203. var opts = child.opts;
  3204. // Allow options for children to be set at the parent options
  3205. // e.g. videojs(id, { controlBar: false });
  3206. // instead of videojs(id, { children: { controlBar: false });
  3207. if (parentOptions[name] !== undefined) {
  3208. opts = parentOptions[name];
  3209. }
  3210. // Allow for disabling default components
  3211. // e.g. options['children']['posterImage'] = false
  3212. if (opts === false) {
  3213. return;
  3214. }
  3215. // Allow options to be passed as a simple boolean if no configuration
  3216. // is necessary.
  3217. if (opts === true) {
  3218. opts = {};
  3219. }
  3220. // We also want to pass the original player options
  3221. // to each component as well so they don't need to
  3222. // reach back into the player for options later.
  3223. opts.playerOptions = _this.options_.playerOptions;
  3224. // Create and add the child component.
  3225. // Add a direct reference to the child by name on the parent instance.
  3226. // If two of the same component are used, different names should be supplied
  3227. // for each
  3228. var newChild = _this.addChild(name, opts);
  3229. if (newChild) {
  3230. _this[name] = newChild;
  3231. }
  3232. };
  3233. // Allow for an array of children details to passed in the options
  3234. var workingChildren = void 0;
  3235. var Tech = Component.getComponent('Tech');
  3236. if (Array.isArray(children)) {
  3237. workingChildren = children;
  3238. } else {
  3239. workingChildren = Object.keys(children);
  3240. }
  3241. workingChildren
  3242. // children that are in this.options_ but also in workingChildren would
  3243. // give us extra children we do not want. So, we want to filter them out.
  3244. .concat(Object.keys(this.options_).filter(function (child) {
  3245. return !workingChildren.some(function (wchild) {
  3246. if (typeof wchild === 'string') {
  3247. return child === wchild;
  3248. }
  3249. return child === wchild.name;
  3250. });
  3251. })).map(function (child) {
  3252. var name = void 0;
  3253. var opts = void 0;
  3254. if (typeof child === 'string') {
  3255. name = child;
  3256. opts = children[name] || _this.options_[name] || {};
  3257. } else {
  3258. name = child.name;
  3259. opts = child;
  3260. }
  3261. return { name: name, opts: opts };
  3262. }).filter(function (child) {
  3263. // we have to make sure that child.name isn't in the techOrder since
  3264. // techs are registerd as Components but can't aren't compatible
  3265. // See https://github.com/videojs/video.js/issues/2772
  3266. var c = Component.getComponent(child.opts.componentClass || toTitleCase(child.name));
  3267. return c && !Tech.isTech(c);
  3268. }).forEach(handleAdd);
  3269. }
  3270. };
  3271. /**
  3272. * Builds the default DOM class name. Should be overriden by sub-components.
  3273. *
  3274. * @return {string}
  3275. * The DOM class name for this object.
  3276. *
  3277. * @abstract
  3278. */
  3279. Component.prototype.buildCSSClass = function buildCSSClass() {
  3280. // Child classes can include a function that does:
  3281. // return 'CLASS NAME' + this._super();
  3282. return '';
  3283. };
  3284. /**
  3285. * Bind a listener to the component's ready state.
  3286. * Different from event listeners in that if the ready event has already happened
  3287. * it will trigger the function immediately.
  3288. *
  3289. * @return {Component}
  3290. * Returns itself; method can be chained.
  3291. */
  3292. Component.prototype.ready = function ready(fn) {
  3293. var sync = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  3294. if (!fn) {
  3295. return;
  3296. }
  3297. if (!this.isReady_) {
  3298. this.readyQueue_ = this.readyQueue_ || [];
  3299. this.readyQueue_.push(fn);
  3300. return;
  3301. }
  3302. if (sync) {
  3303. fn.call(this);
  3304. } else {
  3305. // Call the function asynchronously by default for consistency
  3306. this.setTimeout(fn, 1);
  3307. }
  3308. };
  3309. /**
  3310. * Trigger all the ready listeners for this `Component`.
  3311. *
  3312. * @fires Component#ready
  3313. */
  3314. Component.prototype.triggerReady = function triggerReady() {
  3315. this.isReady_ = true;
  3316. // Ensure ready is triggered asynchronously
  3317. this.setTimeout(function () {
  3318. var readyQueue = this.readyQueue_;
  3319. // Reset Ready Queue
  3320. this.readyQueue_ = [];
  3321. if (readyQueue && readyQueue.length > 0) {
  3322. readyQueue.forEach(function (fn) {
  3323. fn.call(this);
  3324. }, this);
  3325. }
  3326. // Allow for using event listeners also
  3327. /**
  3328. * Triggered when a `Component` is ready.
  3329. *
  3330. * @event Component#ready
  3331. * @type {EventTarget~Event}
  3332. */
  3333. this.trigger('ready');
  3334. }, 1);
  3335. };
  3336. /**
  3337. * Find a single DOM element matching a `selector`. This can be within the `Component`s
  3338. * `contentEl()` or another custom context.
  3339. *
  3340. * @param {string} selector
  3341. * A valid CSS selector, which will be passed to `querySelector`.
  3342. *
  3343. * @param {Element|string} [context=this.contentEl()]
  3344. * A DOM element within which to query. Can also be a selector string in
  3345. * which case the first matching element will get used as context. If
  3346. * missing `this.contentEl()` gets used. If `this.contentEl()` returns
  3347. * nothing it falls back to `document`.
  3348. *
  3349. * @return {Element|null}
  3350. * the dom element that was found, or null
  3351. *
  3352. * @see [Information on CSS Selectors](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_Started/Selectors)
  3353. */
  3354. Component.prototype.$ = function $$$1(selector, context) {
  3355. return $(selector, context || this.contentEl());
  3356. };
  3357. /**
  3358. * Finds all DOM element matching a `selector`. This can be within the `Component`s
  3359. * `contentEl()` or another custom context.
  3360. *
  3361. * @param {string} selector
  3362. * A valid CSS selector, which will be passed to `querySelectorAll`.
  3363. *
  3364. * @param {Element|string} [context=this.contentEl()]
  3365. * A DOM element within which to query. Can also be a selector string in
  3366. * which case the first matching element will get used as context. If
  3367. * missing `this.contentEl()` gets used. If `this.contentEl()` returns
  3368. * nothing it falls back to `document`.
  3369. *
  3370. * @return {NodeList}
  3371. * a list of dom elements that were found
  3372. *
  3373. * @see [Information on CSS Selectors](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_Started/Selectors)
  3374. */
  3375. Component.prototype.$$ = function $$$$1(selector, context) {
  3376. return $$(selector, context || this.contentEl());
  3377. };
  3378. /**
  3379. * Check if a component's element has a CSS class name.
  3380. *
  3381. * @param {string} classToCheck
  3382. * CSS class name to check.
  3383. *
  3384. * @return {boolean}
  3385. * - True if the `Component` has the class.
  3386. * - False if the `Component` does not have the class`
  3387. */
  3388. Component.prototype.hasClass = function hasClass$$1(classToCheck) {
  3389. return hasClass(this.el_, classToCheck);
  3390. };
  3391. /**
  3392. * Add a CSS class name to the `Component`s element.
  3393. *
  3394. * @param {string} classToAdd
  3395. * CSS class name to add
  3396. */
  3397. Component.prototype.addClass = function addClass$$1(classToAdd) {
  3398. addClass(this.el_, classToAdd);
  3399. };
  3400. /**
  3401. * Remove a CSS class name from the `Component`s element.
  3402. *
  3403. * @param {string} classToRemove
  3404. * CSS class name to remove
  3405. */
  3406. Component.prototype.removeClass = function removeClass$$1(classToRemove) {
  3407. removeClass(this.el_, classToRemove);
  3408. };
  3409. /**
  3410. * Add or remove a CSS class name from the component's element.
  3411. * - `classToToggle` gets added when {@link Component#hasClass} would return false.
  3412. * - `classToToggle` gets removed when {@link Component#hasClass} would return true.
  3413. *
  3414. * @param {string} classToToggle
  3415. * The class to add or remove based on (@link Component#hasClass}
  3416. *
  3417. * @param {boolean|Dom~predicate} [predicate]
  3418. * An {@link Dom~predicate} function or a boolean
  3419. */
  3420. Component.prototype.toggleClass = function toggleClass$$1(classToToggle, predicate) {
  3421. toggleClass(this.el_, classToToggle, predicate);
  3422. };
  3423. /**
  3424. * Show the `Component`s element if it is hidden by removing the
  3425. * 'vjs-hidden' class name from it.
  3426. */
  3427. Component.prototype.show = function show() {
  3428. this.removeClass('vjs-hidden');
  3429. };
  3430. /**
  3431. * Hide the `Component`s element if it is currently showing by adding the
  3432. * 'vjs-hidden` class name to it.
  3433. */
  3434. Component.prototype.hide = function hide() {
  3435. this.addClass('vjs-hidden');
  3436. };
  3437. /**
  3438. * Lock a `Component`s element in its visible state by adding the 'vjs-lock-showing'
  3439. * class name to it. Used during fadeIn/fadeOut.
  3440. *
  3441. * @private
  3442. */
  3443. Component.prototype.lockShowing = function lockShowing() {
  3444. this.addClass('vjs-lock-showing');
  3445. };
  3446. /**
  3447. * Unlock a `Component`s element from its visible state by removing the 'vjs-lock-showing'
  3448. * class name from it. Used during fadeIn/fadeOut.
  3449. *
  3450. * @private
  3451. */
  3452. Component.prototype.unlockShowing = function unlockShowing() {
  3453. this.removeClass('vjs-lock-showing');
  3454. };
  3455. /**
  3456. * Get the value of an attribute on the `Component`s element.
  3457. *
  3458. * @param {string} attribute
  3459. * Name of the attribute to get the value from.
  3460. *
  3461. * @return {string|null}
  3462. * - The value of the attribute that was asked for.
  3463. * - Can be an empty string on some browsers if the attribute does not exist
  3464. * or has no value
  3465. * - Most browsers will return null if the attibute does not exist or has
  3466. * no value.
  3467. *
  3468. * @see [DOM API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute}
  3469. */
  3470. Component.prototype.getAttribute = function getAttribute$$1(attribute) {
  3471. return getAttribute(this.el_, attribute);
  3472. };
  3473. /**
  3474. * Set the value of an attribute on the `Component`'s element
  3475. *
  3476. * @param {string} attribute
  3477. * Name of the attribute to set.
  3478. *
  3479. * @param {string} value
  3480. * Value to set the attribute to.
  3481. *
  3482. * @see [DOM API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute}
  3483. */
  3484. Component.prototype.setAttribute = function setAttribute$$1(attribute, value) {
  3485. setAttribute(this.el_, attribute, value);
  3486. };
  3487. /**
  3488. * Remove an attribute from the `Component`s element.
  3489. *
  3490. * @param {string} attribute
  3491. * Name of the attribute to remove.
  3492. *
  3493. * @see [DOM API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute}
  3494. */
  3495. Component.prototype.removeAttribute = function removeAttribute$$1(attribute) {
  3496. removeAttribute(this.el_, attribute);
  3497. };
  3498. /**
  3499. * Get or set the width of the component based upon the CSS styles.
  3500. * See {@link Component#dimension} for more detailed information.
  3501. *
  3502. * @param {number|string} [num]
  3503. * The width that you want to set postfixed with '%', 'px' or nothing.
  3504. *
  3505. * @param {boolean} [skipListeners]
  3506. * Skip the componentresize event trigger
  3507. *
  3508. * @return {number|string}
  3509. * The width when getting, zero if there is no width. Can be a string
  3510. * postpixed with '%' or 'px'.
  3511. */
  3512. Component.prototype.width = function width(num, skipListeners) {
  3513. return this.dimension('width', num, skipListeners);
  3514. };
  3515. /**
  3516. * Get or set the height of the component based upon the CSS styles.
  3517. * See {@link Component#dimension} for more detailed information.
  3518. *
  3519. * @param {number|string} [num]
  3520. * The height that you want to set postfixed with '%', 'px' or nothing.
  3521. *
  3522. * @param {boolean} [skipListeners]
  3523. * Skip the componentresize event trigger
  3524. *
  3525. * @return {number|string}
  3526. * The width when getting, zero if there is no width. Can be a string
  3527. * postpixed with '%' or 'px'.
  3528. */
  3529. Component.prototype.height = function height(num, skipListeners) {
  3530. return this.dimension('height', num, skipListeners);
  3531. };
  3532. /**
  3533. * Set both the width and height of the `Component` element at the same time.
  3534. *
  3535. * @param {number|string} width
  3536. * Width to set the `Component`s element to.
  3537. *
  3538. * @param {number|string} height
  3539. * Height to set the `Component`s element to.
  3540. */
  3541. Component.prototype.dimensions = function dimensions(width, height) {
  3542. // Skip componentresize listeners on width for optimization
  3543. this.width(width, true);
  3544. this.height(height);
  3545. };
  3546. /**
  3547. * Get or set width or height of the `Component` element. This is the shared code
  3548. * for the {@link Component#width} and {@link Component#height}.
  3549. *
  3550. * Things to know:
  3551. * - If the width or height in an number this will return the number postfixed with 'px'.
  3552. * - If the width/height is a percent this will return the percent postfixed with '%'
  3553. * - Hidden elements have a width of 0 with `window.getComputedStyle`. This function
  3554. * defaults to the `Component`s `style.width` and falls back to `window.getComputedStyle`.
  3555. * See [this]{@link http://www.foliotek.com/devblog/getting-the-width-of-a-hidden-element-with-jquery-using-width/}
  3556. * for more information
  3557. * - If you want the computed style of the component, use {@link Component#currentWidth}
  3558. * and {@link {Component#currentHeight}
  3559. *
  3560. * @fires Component#componentresize
  3561. *
  3562. * @param {string} widthOrHeight
  3563. 8 'width' or 'height'
  3564. *
  3565. * @param {number|string} [num]
  3566. 8 New dimension
  3567. *
  3568. * @param {boolean} [skipListeners]
  3569. * Skip componentresize event trigger
  3570. *
  3571. * @return {number}
  3572. * The dimension when getting or 0 if unset
  3573. */
  3574. Component.prototype.dimension = function dimension(widthOrHeight, num, skipListeners) {
  3575. if (num !== undefined) {
  3576. // Set to zero if null or literally NaN (NaN !== NaN)
  3577. if (num === null || num !== num) {
  3578. num = 0;
  3579. }
  3580. // Check if using css width/height (% or px) and adjust
  3581. if (('' + num).indexOf('%') !== -1 || ('' + num).indexOf('px') !== -1) {
  3582. this.el_.style[widthOrHeight] = num;
  3583. } else if (num === 'auto') {
  3584. this.el_.style[widthOrHeight] = '';
  3585. } else {
  3586. this.el_.style[widthOrHeight] = num + 'px';
  3587. }
  3588. // skipListeners allows us to avoid triggering the resize event when setting both width and height
  3589. if (!skipListeners) {
  3590. /**
  3591. * Triggered when a component is resized.
  3592. *
  3593. * @event Component#componentresize
  3594. * @type {EventTarget~Event}
  3595. */
  3596. this.trigger('componentresize');
  3597. }
  3598. return;
  3599. }
  3600. // Not setting a value, so getting it
  3601. // Make sure element exists
  3602. if (!this.el_) {
  3603. return 0;
  3604. }
  3605. // Get dimension value from style
  3606. var val = this.el_.style[widthOrHeight];
  3607. var pxIndex = val.indexOf('px');
  3608. if (pxIndex !== -1) {
  3609. // Return the pixel value with no 'px'
  3610. return parseInt(val.slice(0, pxIndex), 10);
  3611. }
  3612. // No px so using % or no style was set, so falling back to offsetWidth/height
  3613. // If component has display:none, offset will return 0
  3614. // TODO: handle display:none and no dimension style using px
  3615. return parseInt(this.el_['offset' + toTitleCase(widthOrHeight)], 10);
  3616. };
  3617. /**
  3618. * Get the computed width or the height of the component's element.
  3619. *
  3620. * Uses `window.getComputedStyle`.
  3621. *
  3622. * @param {string} widthOrHeight
  3623. * A string containing 'width' or 'height'. Whichever one you want to get.
  3624. *
  3625. * @return {number}
  3626. * The dimension that gets asked for or 0 if nothing was set
  3627. * for that dimension.
  3628. */
  3629. Component.prototype.currentDimension = function currentDimension(widthOrHeight) {
  3630. var computedWidthOrHeight = 0;
  3631. if (widthOrHeight !== 'width' && widthOrHeight !== 'height') {
  3632. throw new Error('currentDimension only accepts width or height value');
  3633. }
  3634. if (typeof window.getComputedStyle === 'function') {
  3635. var computedStyle = window.getComputedStyle(this.el_);
  3636. computedWidthOrHeight = computedStyle.getPropertyValue(widthOrHeight) || computedStyle[widthOrHeight];
  3637. }
  3638. // remove 'px' from variable and parse as integer
  3639. computedWidthOrHeight = parseFloat(computedWidthOrHeight);
  3640. // if the computed value is still 0, it's possible that the browser is lying
  3641. // and we want to check the offset values.
  3642. // This code also runs on IE8 and wherever getComputedStyle doesn't exist.
  3643. if (computedWidthOrHeight === 0) {
  3644. var rule = 'offset' + toTitleCase(widthOrHeight);
  3645. computedWidthOrHeight = this.el_[rule];
  3646. }
  3647. return computedWidthOrHeight;
  3648. };
  3649. /**
  3650. * An object that contains width and height values of the `Component`s
  3651. * computed style. Uses `window.getComputedStyle`.
  3652. *
  3653. * @typedef {Object} Component~DimensionObject
  3654. *
  3655. * @property {number} width
  3656. * The width of the `Component`s computed style.
  3657. *
  3658. * @property {number} height
  3659. * The height of the `Component`s computed style.
  3660. */
  3661. /**
  3662. * Get an object that contains computed width and height values of the
  3663. * component's element.
  3664. *
  3665. * Uses `window.getComputedStyle`.
  3666. *
  3667. * @return {Component~DimensionObject}
  3668. * The computed dimensions of the component's element.
  3669. */
  3670. Component.prototype.currentDimensions = function currentDimensions() {
  3671. return {
  3672. width: this.currentDimension('width'),
  3673. height: this.currentDimension('height')
  3674. };
  3675. };
  3676. /**
  3677. * Get the computed width of the component's element.
  3678. *
  3679. * Uses `window.getComputedStyle`.
  3680. *
  3681. * @return {number}
  3682. * The computed width of the component's element.
  3683. */
  3684. Component.prototype.currentWidth = function currentWidth() {
  3685. return this.currentDimension('width');
  3686. };
  3687. /**
  3688. * Get the computed height of the component's element.
  3689. *
  3690. * Uses `window.getComputedStyle`.
  3691. *
  3692. * @return {number}
  3693. * The computed height of the component's element.
  3694. */
  3695. Component.prototype.currentHeight = function currentHeight() {
  3696. return this.currentDimension('height');
  3697. };
  3698. /**
  3699. * Set the focus to this component
  3700. */
  3701. Component.prototype.focus = function focus() {
  3702. this.el_.focus();
  3703. };
  3704. /**
  3705. * Remove the focus from this component
  3706. */
  3707. Component.prototype.blur = function blur() {
  3708. this.el_.blur();
  3709. };
  3710. /**
  3711. * Emit a 'tap' events when touch event support gets detected. This gets used to
  3712. * support toggling the controls through a tap on the video. They get enabled
  3713. * because every sub-component would have extra overhead otherwise.
  3714. *
  3715. * @private
  3716. * @fires Component#tap
  3717. * @listens Component#touchstart
  3718. * @listens Component#touchmove
  3719. * @listens Component#touchleave
  3720. * @listens Component#touchcancel
  3721. * @listens Component#touchend
  3722. */
  3723. Component.prototype.emitTapEvents = function emitTapEvents() {
  3724. // Track the start time so we can determine how long the touch lasted
  3725. var touchStart = 0;
  3726. var firstTouch = null;
  3727. // Maximum movement allowed during a touch event to still be considered a tap
  3728. // Other popular libs use anywhere from 2 (hammer.js) to 15,
  3729. // so 10 seems like a nice, round number.
  3730. var tapMovementThreshold = 10;
  3731. // The maximum length a touch can be while still being considered a tap
  3732. var touchTimeThreshold = 200;
  3733. var couldBeTap = void 0;
  3734. this.on('touchstart', function (event) {
  3735. // If more than one finger, don't consider treating this as a click
  3736. if (event.touches.length === 1) {
  3737. // Copy pageX/pageY from the object
  3738. firstTouch = {
  3739. pageX: event.touches[0].pageX,
  3740. pageY: event.touches[0].pageY
  3741. };
  3742. // Record start time so we can detect a tap vs. "touch and hold"
  3743. touchStart = new Date().getTime();
  3744. // Reset couldBeTap tracking
  3745. couldBeTap = true;
  3746. }
  3747. });
  3748. this.on('touchmove', function (event) {
  3749. // If more than one finger, don't consider treating this as a click
  3750. if (event.touches.length > 1) {
  3751. couldBeTap = false;
  3752. } else if (firstTouch) {
  3753. // Some devices will throw touchmoves for all but the slightest of taps.
  3754. // So, if we moved only a small distance, this could still be a tap
  3755. var xdiff = event.touches[0].pageX - firstTouch.pageX;
  3756. var ydiff = event.touches[0].pageY - firstTouch.pageY;
  3757. var touchDistance = Math.sqrt(xdiff * xdiff + ydiff * ydiff);
  3758. if (touchDistance > tapMovementThreshold) {
  3759. couldBeTap = false;
  3760. }
  3761. }
  3762. });
  3763. var noTap = function noTap() {
  3764. couldBeTap = false;
  3765. };
  3766. // TODO: Listen to the original target. http://youtu.be/DujfpXOKUp8?t=13m8s
  3767. this.on('touchleave', noTap);
  3768. this.on('touchcancel', noTap);
  3769. // When the touch ends, measure how long it took and trigger the appropriate
  3770. // event
  3771. this.on('touchend', function (event) {
  3772. firstTouch = null;
  3773. // Proceed only if the touchmove/leave/cancel event didn't happen
  3774. if (couldBeTap === true) {
  3775. // Measure how long the touch lasted
  3776. var touchTime = new Date().getTime() - touchStart;
  3777. // Make sure the touch was less than the threshold to be considered a tap
  3778. if (touchTime < touchTimeThreshold) {
  3779. // Don't let browser turn this into a click
  3780. event.preventDefault();
  3781. /**
  3782. * Triggered when a `Component` is tapped.
  3783. *
  3784. * @event Component#tap
  3785. * @type {EventTarget~Event}
  3786. */
  3787. this.trigger('tap');
  3788. // It may be good to copy the touchend event object and change the
  3789. // type to tap, if the other event properties aren't exact after
  3790. // Events.fixEvent runs (e.g. event.target)
  3791. }
  3792. }
  3793. });
  3794. };
  3795. /**
  3796. * This function reports user activity whenever touch events happen. This can get
  3797. * turned off by any sub-components that wants touch events to act another way.
  3798. *
  3799. * Report user touch activity when touch events occur. User activity gets used to
  3800. * determine when controls should show/hide. It is simple when it comes to mouse
  3801. * events, because any mouse event should show the controls. So we capture mouse
  3802. * events that bubble up to the player and report activity when that happens.
  3803. * With touch events it isn't as easy as `touchstart` and `touchend` toggle player
  3804. * controls. So touch events can't help us at the player level either.
  3805. *
  3806. * User activity gets checked asynchronously. So what could happen is a tap event
  3807. * on the video turns the controls off. Then the `touchend` event bubbles up to
  3808. * the player. Which, if it reported user activity, would turn the controls right
  3809. * back on. We also don't want to completely block touch events from bubbling up.
  3810. * Furthermore a `touchmove` event and anything other than a tap, should not turn
  3811. * controls back on.
  3812. *
  3813. * @listens Component#touchstart
  3814. * @listens Component#touchmove
  3815. * @listens Component#touchend
  3816. * @listens Component#touchcancel
  3817. */
  3818. Component.prototype.enableTouchActivity = function enableTouchActivity() {
  3819. // Don't continue if the root player doesn't support reporting user activity
  3820. if (!this.player() || !this.player().reportUserActivity) {
  3821. return;
  3822. }
  3823. // listener for reporting that the user is active
  3824. var report = bind(this.player(), this.player().reportUserActivity);
  3825. var touchHolding = void 0;
  3826. this.on('touchstart', function () {
  3827. report();
  3828. // For as long as the they are touching the device or have their mouse down,
  3829. // we consider them active even if they're not moving their finger or mouse.
  3830. // So we want to continue to update that they are active
  3831. this.clearInterval(touchHolding);
  3832. // report at the same interval as activityCheck
  3833. touchHolding = this.setInterval(report, 250);
  3834. });
  3835. var touchEnd = function touchEnd(event) {
  3836. report();
  3837. // stop the interval that maintains activity if the touch is holding
  3838. this.clearInterval(touchHolding);
  3839. };
  3840. this.on('touchmove', report);
  3841. this.on('touchend', touchEnd);
  3842. this.on('touchcancel', touchEnd);
  3843. };
  3844. /**
  3845. * A callback that has no parameters and is bound into `Component`s context.
  3846. *
  3847. * @callback Component~GenericCallback
  3848. * @this Component
  3849. */
  3850. /**
  3851. * Creates a function that runs after an `x` millisecond timeout. This function is a
  3852. * wrapper around `window.setTimeout`. There are a few reasons to use this one
  3853. * instead though:
  3854. * 1. It gets cleared via {@link Component#clearTimeout} when
  3855. * {@link Component#dispose} gets called.
  3856. * 2. The function callback will gets turned into a {@link Component~GenericCallback}
  3857. *
  3858. * > Note: You can't use `window.clearTimeout` on the id returned by this function. This
  3859. * will cause its dispose listener not to get cleaned up! Please use
  3860. * {@link Component#clearTimeout} or {@link Component#dispose} instead.
  3861. *
  3862. * @param {Component~GenericCallback} fn
  3863. * The function that will be run after `timeout`.
  3864. *
  3865. * @param {number} timeout
  3866. * Timeout in milliseconds to delay before executing the specified function.
  3867. *
  3868. * @return {number}
  3869. * Returns a timeout ID that gets used to identify the timeout. It can also
  3870. * get used in {@link Component#clearTimeout} to clear the timeout that
  3871. * was set.
  3872. *
  3873. * @listens Component#dispose
  3874. * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout}
  3875. */
  3876. Component.prototype.setTimeout = function setTimeout(fn, timeout) {
  3877. var _this2 = this;
  3878. // declare as variables so they are properly available in timeout function
  3879. // eslint-disable-next-line
  3880. var timeoutId, disposeFn;
  3881. fn = bind(this, fn);
  3882. timeoutId = window.setTimeout(function () {
  3883. _this2.off('dispose', disposeFn);
  3884. fn();
  3885. }, timeout);
  3886. disposeFn = function disposeFn() {
  3887. return _this2.clearTimeout(timeoutId);
  3888. };
  3889. disposeFn.guid = 'vjs-timeout-' + timeoutId;
  3890. this.on('dispose', disposeFn);
  3891. return timeoutId;
  3892. };
  3893. /**
  3894. * Clears a timeout that gets created via `window.setTimeout` or
  3895. * {@link Component#setTimeout}. If you set a timeout via {@link Component#setTimeout}
  3896. * use this function instead of `window.clearTimout`. If you don't your dispose
  3897. * listener will not get cleaned up until {@link Component#dispose}!
  3898. *
  3899. * @param {number} timeoutId
  3900. * The id of the timeout to clear. The return value of
  3901. * {@link Component#setTimeout} or `window.setTimeout`.
  3902. *
  3903. * @return {number}
  3904. * Returns the timeout id that was cleared.
  3905. *
  3906. * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/clearTimeout}
  3907. */
  3908. Component.prototype.clearTimeout = function clearTimeout(timeoutId) {
  3909. window.clearTimeout(timeoutId);
  3910. var disposeFn = function disposeFn() {};
  3911. disposeFn.guid = 'vjs-timeout-' + timeoutId;
  3912. this.off('dispose', disposeFn);
  3913. return timeoutId;
  3914. };
  3915. /**
  3916. * Creates a function that gets run every `x` milliseconds. This function is a wrapper
  3917. * around `window.setInterval`. There are a few reasons to use this one instead though.
  3918. * 1. It gets cleared via {@link Component#clearInterval} when
  3919. * {@link Component#dispose} gets called.
  3920. * 2. The function callback will be a {@link Component~GenericCallback}
  3921. *
  3922. * @param {Component~GenericCallback} fn
  3923. * The function to run every `x` seconds.
  3924. *
  3925. * @param {number} interval
  3926. * Execute the specified function every `x` milliseconds.
  3927. *
  3928. * @return {number}
  3929. * Returns an id that can be used to identify the interval. It can also be be used in
  3930. * {@link Component#clearInterval} to clear the interval.
  3931. *
  3932. * @listens Component#dispose
  3933. * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval}
  3934. */
  3935. Component.prototype.setInterval = function setInterval(fn, interval) {
  3936. var _this3 = this;
  3937. fn = bind(this, fn);
  3938. var intervalId = window.setInterval(fn, interval);
  3939. var disposeFn = function disposeFn() {
  3940. return _this3.clearInterval(intervalId);
  3941. };
  3942. disposeFn.guid = 'vjs-interval-' + intervalId;
  3943. this.on('dispose', disposeFn);
  3944. return intervalId;
  3945. };
  3946. /**
  3947. * Clears an interval that gets created via `window.setInterval` or
  3948. * {@link Component#setInterval}. If you set an inteval via {@link Component#setInterval}
  3949. * use this function instead of `window.clearInterval`. If you don't your dispose
  3950. * listener will not get cleaned up until {@link Component#dispose}!
  3951. *
  3952. * @param {number} intervalId
  3953. * The id of the interval to clear. The return value of
  3954. * {@link Component#setInterval} or `window.setInterval`.
  3955. *
  3956. * @return {number}
  3957. * Returns the interval id that was cleared.
  3958. *
  3959. * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/clearInterval}
  3960. */
  3961. Component.prototype.clearInterval = function clearInterval(intervalId) {
  3962. window.clearInterval(intervalId);
  3963. var disposeFn = function disposeFn() {};
  3964. disposeFn.guid = 'vjs-interval-' + intervalId;
  3965. this.off('dispose', disposeFn);
  3966. return intervalId;
  3967. };
  3968. /**
  3969. * Queues up a callback to be passed to requestAnimationFrame (rAF), but
  3970. * with a few extra bonuses:
  3971. *
  3972. * - Supports browsers that do not support rAF by falling back to
  3973. * {@link Component#setTimeout}.
  3974. *
  3975. * - The callback is turned into a {@link Component~GenericCallback} (i.e.
  3976. * bound to the component).
  3977. *
  3978. * - Automatic cancellation of the rAF callback is handled if the component
  3979. * is disposed before it is called.
  3980. *
  3981. * @param {Component~GenericCallback} fn
  3982. * A function that will be bound to this component and executed just
  3983. * before the browser's next repaint.
  3984. *
  3985. * @return {number}
  3986. * Returns an rAF ID that gets used to identify the timeout. It can
  3987. * also be used in {@link Component#cancelAnimationFrame} to cancel
  3988. * the animation frame callback.
  3989. *
  3990. * @listens Component#dispose
  3991. * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame}
  3992. */
  3993. Component.prototype.requestAnimationFrame = function requestAnimationFrame(fn) {
  3994. var _this4 = this;
  3995. // declare as variables so they are properly available in rAF function
  3996. // eslint-disable-next-line
  3997. var id, disposeFn;
  3998. if (this.supportsRaf_) {
  3999. fn = bind(this, fn);
  4000. id = window.requestAnimationFrame(function () {
  4001. _this4.off('dispose', disposeFn);
  4002. fn();
  4003. });
  4004. disposeFn = function disposeFn() {
  4005. return _this4.cancelAnimationFrame(id);
  4006. };
  4007. disposeFn.guid = 'vjs-raf-' + id;
  4008. this.on('dispose', disposeFn);
  4009. return id;
  4010. }
  4011. // Fall back to using a timer.
  4012. return this.setTimeout(fn, 1000 / 60);
  4013. };
  4014. /**
  4015. * Cancels a queued callback passed to {@link Component#requestAnimationFrame}
  4016. * (rAF).
  4017. *
  4018. * If you queue an rAF callback via {@link Component#requestAnimationFrame},
  4019. * use this function instead of `window.cancelAnimationFrame`. If you don't,
  4020. * your dispose listener will not get cleaned up until {@link Component#dispose}!
  4021. *
  4022. * @param {number} id
  4023. * The rAF ID to clear. The return value of {@link Component#requestAnimationFrame}.
  4024. *
  4025. * @return {number}
  4026. * Returns the rAF ID that was cleared.
  4027. *
  4028. * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/window/cancelAnimationFrame}
  4029. */
  4030. Component.prototype.cancelAnimationFrame = function cancelAnimationFrame(id) {
  4031. if (this.supportsRaf_) {
  4032. window.cancelAnimationFrame(id);
  4033. var disposeFn = function disposeFn() {};
  4034. disposeFn.guid = 'vjs-raf-' + id;
  4035. this.off('dispose', disposeFn);
  4036. return id;
  4037. }
  4038. // Fall back to using a timer.
  4039. return this.clearTimeout(id);
  4040. };
  4041. /**
  4042. * Register a `Component` with `videojs` given the name and the component.
  4043. *
  4044. * > NOTE: {@link Tech}s should not be registered as a `Component`. {@link Tech}s
  4045. * should be registered using {@link Tech.registerTech} or
  4046. * {@link videojs:videojs.registerTech}.
  4047. *
  4048. * > NOTE: This function can also be seen on videojs as
  4049. * {@link videojs:videojs.registerComponent}.
  4050. *
  4051. * @param {string} name
  4052. * The name of the `Component` to register.
  4053. *
  4054. * @param {Component} ComponentToRegister
  4055. * The `Component` class to register.
  4056. *
  4057. * @return {Component}
  4058. * The `Component` that was registered.
  4059. */
  4060. Component.registerComponent = function registerComponent(name, ComponentToRegister) {
  4061. if (typeof name !== 'string' || !name) {
  4062. throw new Error('Illegal component name, "' + name + '"; must be a non-empty string.');
  4063. }
  4064. var Tech = Component.getComponent('Tech');
  4065. // We need to make sure this check is only done if Tech has been registered.
  4066. var isTech = Tech && Tech.isTech(ComponentToRegister);
  4067. var isComp = Component === ComponentToRegister || Component.prototype.isPrototypeOf(ComponentToRegister.prototype);
  4068. if (isTech || !isComp) {
  4069. var reason = void 0;
  4070. if (isTech) {
  4071. reason = 'techs must be registered using Tech.registerTech()';
  4072. } else {
  4073. reason = 'must be a Component subclass';
  4074. }
  4075. throw new Error('Illegal component, "' + name + '"; ' + reason + '.');
  4076. }
  4077. name = toTitleCase(name);
  4078. if (!Component.components_) {
  4079. Component.components_ = {};
  4080. }
  4081. var Player = Component.getComponent('Player');
  4082. if (name === 'Player' && Player && Player.players) {
  4083. var players = Player.players;
  4084. var playerNames = Object.keys(players);
  4085. // If we have players that were disposed, then their name will still be
  4086. // in Players.players. So, we must loop through and verify that the value
  4087. // for each item is not null. This allows registration of the Player component
  4088. // after all players have been disposed or before any were created.
  4089. if (players && playerNames.length > 0 && playerNames.map(function (pname) {
  4090. return players[pname];
  4091. }).every(Boolean)) {
  4092. throw new Error('Can not register Player component after player has been created.');
  4093. }
  4094. }
  4095. Component.components_[name] = ComponentToRegister;
  4096. return ComponentToRegister;
  4097. };
  4098. /**
  4099. * Get a `Component` based on the name it was registered with.
  4100. *
  4101. * @param {string} name
  4102. * The Name of the component to get.
  4103. *
  4104. * @return {Component}
  4105. * The `Component` that got registered under the given name.
  4106. *
  4107. * @deprecated In `videojs` 6 this will not return `Component`s that were not
  4108. * registered using {@link Component.registerComponent}. Currently we
  4109. * check the global `videojs` object for a `Component` name and
  4110. * return that if it exists.
  4111. */
  4112. Component.getComponent = function getComponent(name) {
  4113. if (!name) {
  4114. return;
  4115. }
  4116. name = toTitleCase(name);
  4117. if (Component.components_ && Component.components_[name]) {
  4118. return Component.components_[name];
  4119. }
  4120. };
  4121. return Component;
  4122. }();
  4123. /**
  4124. * Whether or not this component supports `requestAnimationFrame`.
  4125. *
  4126. * This is exposed primarily for testing purposes.
  4127. *
  4128. * @private
  4129. * @type {Boolean}
  4130. */
  4131. Component.prototype.supportsRaf_ = typeof window.requestAnimationFrame === 'function' && typeof window.cancelAnimationFrame === 'function';
  4132. Component.registerComponent('Component', Component);
  4133. /**
  4134. * @file time-ranges.js
  4135. * @module time-ranges
  4136. */
  4137. /**
  4138. * Returns the time for the specified index at the start or end
  4139. * of a TimeRange object.
  4140. *
  4141. * @function time-ranges:indexFunction
  4142. *
  4143. * @param {number} [index=0]
  4144. * The range number to return the time for.
  4145. *
  4146. * @return {number}
  4147. * The time that offset at the specified index.
  4148. *
  4149. * @depricated index must be set to a value, in the future this will throw an error.
  4150. */
  4151. /**
  4152. * An object that contains ranges of time for various reasons.
  4153. *
  4154. * @typedef {Object} TimeRange
  4155. *
  4156. * @property {number} length
  4157. * The number of time ranges represented by this Object
  4158. *
  4159. * @property {time-ranges:indexFunction} start
  4160. * Returns the time offset at which a specified time range begins.
  4161. *
  4162. * @property {time-ranges:indexFunction} end
  4163. * Returns the time offset at which a specified time range ends.
  4164. *
  4165. * @see https://developer.mozilla.org/en-US/docs/Web/API/TimeRanges
  4166. */
  4167. /**
  4168. * Check if any of the time ranges are over the maximum index.
  4169. *
  4170. * @param {string} fnName
  4171. * The function name to use for logging
  4172. *
  4173. * @param {number} index
  4174. * The index to check
  4175. *
  4176. * @param {number} maxIndex
  4177. * The maximum possible index
  4178. *
  4179. * @throws {Error} if the timeRanges provided are over the maxIndex
  4180. */
  4181. function rangeCheck(fnName, index, maxIndex) {
  4182. if (typeof index !== 'number' || index < 0 || index > maxIndex) {
  4183. throw new Error('Failed to execute \'' + fnName + '\' on \'TimeRanges\': The index provided (' + index + ') is non-numeric or out of bounds (0-' + maxIndex + ').');
  4184. }
  4185. }
  4186. /**
  4187. * Get the time for the specified index at the start or end
  4188. * of a TimeRange object.
  4189. *
  4190. * @param {string} fnName
  4191. * The function name to use for logging
  4192. *
  4193. * @param {string} valueIndex
  4194. * The proprety that should be used to get the time. should be 'start' or 'end'
  4195. *
  4196. * @param {Array} ranges
  4197. * An array of time ranges
  4198. *
  4199. * @param {Array} [rangeIndex=0]
  4200. * The index to start the search at
  4201. *
  4202. * @return {number}
  4203. * The time that offset at the specified index.
  4204. *
  4205. *
  4206. * @depricated rangeIndex must be set to a value, in the future this will throw an error.
  4207. * @throws {Error} if rangeIndex is more than the length of ranges
  4208. */
  4209. function getRange(fnName, valueIndex, ranges, rangeIndex) {
  4210. rangeCheck(fnName, rangeIndex, ranges.length - 1);
  4211. return ranges[rangeIndex][valueIndex];
  4212. }
  4213. /**
  4214. * Create a time range object given ranges of time.
  4215. *
  4216. * @param {Array} [ranges]
  4217. * An array of time ranges.
  4218. */
  4219. function createTimeRangesObj(ranges) {
  4220. if (ranges === undefined || ranges.length === 0) {
  4221. return {
  4222. length: 0,
  4223. start: function start() {
  4224. throw new Error('This TimeRanges object is empty');
  4225. },
  4226. end: function end() {
  4227. throw new Error('This TimeRanges object is empty');
  4228. }
  4229. };
  4230. }
  4231. return {
  4232. length: ranges.length,
  4233. start: getRange.bind(null, 'start', 0, ranges),
  4234. end: getRange.bind(null, 'end', 1, ranges)
  4235. };
  4236. }
  4237. /**
  4238. * Should create a fake `TimeRange` object which mimics an HTML5 time range instance.
  4239. *
  4240. * @param {number|Array} start
  4241. * The start of a single range or an array of ranges
  4242. *
  4243. * @param {number} end
  4244. * The end of a single range.
  4245. *
  4246. * @private
  4247. */
  4248. function createTimeRanges(start, end) {
  4249. if (Array.isArray(start)) {
  4250. return createTimeRangesObj(start);
  4251. } else if (start === undefined || end === undefined) {
  4252. return createTimeRangesObj();
  4253. }
  4254. return createTimeRangesObj([[start, end]]);
  4255. }
  4256. /**
  4257. * @file buffer.js
  4258. * @module buffer
  4259. */
  4260. /**
  4261. * Compute the percentage of the media that has been buffered.
  4262. *
  4263. * @param {TimeRange} buffered
  4264. * The current `TimeRange` object representing buffered time ranges
  4265. *
  4266. * @param {number} duration
  4267. * Total duration of the media
  4268. *
  4269. * @return {number}
  4270. * Percent buffered of the total duration in decimal form.
  4271. */
  4272. function bufferedPercent(buffered, duration) {
  4273. var bufferedDuration = 0;
  4274. var start = void 0;
  4275. var end = void 0;
  4276. if (!duration) {
  4277. return 0;
  4278. }
  4279. if (!buffered || !buffered.length) {
  4280. buffered = createTimeRanges(0, 0);
  4281. }
  4282. for (var i = 0; i < buffered.length; i++) {
  4283. start = buffered.start(i);
  4284. end = buffered.end(i);
  4285. // buffered end can be bigger than duration by a very small fraction
  4286. if (end > duration) {
  4287. end = duration;
  4288. }
  4289. bufferedDuration += end - start;
  4290. }
  4291. return bufferedDuration / duration;
  4292. }
  4293. /**
  4294. * @file fullscreen-api.js
  4295. * @module fullscreen-api
  4296. * @private
  4297. */
  4298. /**
  4299. * Store the browser-specific methods for the fullscreen API.
  4300. *
  4301. * @type {Object}
  4302. * @see [Specification]{@link https://fullscreen.spec.whatwg.org}
  4303. * @see [Map Approach From Screenfull.js]{@link https://github.com/sindresorhus/screenfull.js}
  4304. */
  4305. var FullscreenApi = {};
  4306. // browser API methods
  4307. var apiMap = [['requestFullscreen', 'exitFullscreen', 'fullscreenElement', 'fullscreenEnabled', 'fullscreenchange', 'fullscreenerror'],
  4308. // WebKit
  4309. ['webkitRequestFullscreen', 'webkitExitFullscreen', 'webkitFullscreenElement', 'webkitFullscreenEnabled', 'webkitfullscreenchange', 'webkitfullscreenerror'],
  4310. // Old WebKit (Safari 5.1)
  4311. ['webkitRequestFullScreen', 'webkitCancelFullScreen', 'webkitCurrentFullScreenElement', 'webkitCancelFullScreen', 'webkitfullscreenchange', 'webkitfullscreenerror'],
  4312. // Mozilla
  4313. ['mozRequestFullScreen', 'mozCancelFullScreen', 'mozFullScreenElement', 'mozFullScreenEnabled', 'mozfullscreenchange', 'mozfullscreenerror'],
  4314. // Microsoft
  4315. ['msRequestFullscreen', 'msExitFullscreen', 'msFullscreenElement', 'msFullscreenEnabled', 'MSFullscreenChange', 'MSFullscreenError']];
  4316. var specApi = apiMap[0];
  4317. var browserApi = void 0;
  4318. // determine the supported set of functions
  4319. for (var i = 0; i < apiMap.length; i++) {
  4320. // check for exitFullscreen function
  4321. if (apiMap[i][1] in document) {
  4322. browserApi = apiMap[i];
  4323. break;
  4324. }
  4325. }
  4326. // map the browser API names to the spec API names
  4327. if (browserApi) {
  4328. for (var _i = 0; _i < browserApi.length; _i++) {
  4329. FullscreenApi[specApi[_i]] = browserApi[_i];
  4330. }
  4331. }
  4332. /**
  4333. * @file media-error.js
  4334. */
  4335. /**
  4336. * A Custom `MediaError` class which mimics the standard HTML5 `MediaError` class.
  4337. *
  4338. * @param {number|string|Object|MediaError} value
  4339. * This can be of multiple types:
  4340. * - number: should be a standard error code
  4341. * - string: an error message (the code will be 0)
  4342. * - Object: arbitrary properties
  4343. * - `MediaError` (native): used to populate a video.js `MediaError` object
  4344. * - `MediaError` (video.js): will return itself if it's already a
  4345. * video.js `MediaError` object.
  4346. *
  4347. * @see [MediaError Spec]{@link https://dev.w3.org/html5/spec-author-view/video.html#mediaerror}
  4348. * @see [Encrypted MediaError Spec]{@link https://www.w3.org/TR/2013/WD-encrypted-media-20130510/#error-codes}
  4349. *
  4350. * @class MediaError
  4351. */
  4352. function MediaError(value) {
  4353. // Allow redundant calls to this constructor to avoid having `instanceof`
  4354. // checks peppered around the code.
  4355. if (value instanceof MediaError) {
  4356. return value;
  4357. }
  4358. if (typeof value === 'number') {
  4359. this.code = value;
  4360. } else if (typeof value === 'string') {
  4361. // default code is zero, so this is a custom error
  4362. this.message = value;
  4363. } else if (isObject(value)) {
  4364. // We assign the `code` property manually because native `MediaError` objects
  4365. // do not expose it as an own/enumerable property of the object.
  4366. if (typeof value.code === 'number') {
  4367. this.code = value.code;
  4368. }
  4369. assign(this, value);
  4370. }
  4371. if (!this.message) {
  4372. this.message = MediaError.defaultMessages[this.code] || '';
  4373. }
  4374. }
  4375. /**
  4376. * The error code that refers two one of the defined `MediaError` types
  4377. *
  4378. * @type {Number}
  4379. */
  4380. MediaError.prototype.code = 0;
  4381. /**
  4382. * An optional message that to show with the error. Message is not part of the HTML5
  4383. * video spec but allows for more informative custom errors.
  4384. *
  4385. * @type {String}
  4386. */
  4387. MediaError.prototype.message = '';
  4388. /**
  4389. * An optional status code that can be set by plugins to allow even more detail about
  4390. * the error. For example a plugin might provide a specific HTTP status code and an
  4391. * error message for that code. Then when the plugin gets that error this class will
  4392. * know how to display an error message for it. This allows a custom message to show
  4393. * up on the `Player` error overlay.
  4394. *
  4395. * @type {Array}
  4396. */
  4397. MediaError.prototype.status = null;
  4398. /**
  4399. * Errors indexed by the W3C standard. The order **CANNOT CHANGE**! See the
  4400. * specification listed under {@link MediaError} for more information.
  4401. *
  4402. * @enum {array}
  4403. * @readonly
  4404. * @property {string} 0 - MEDIA_ERR_CUSTOM
  4405. * @property {string} 1 - MEDIA_ERR_CUSTOM
  4406. * @property {string} 2 - MEDIA_ERR_ABORTED
  4407. * @property {string} 3 - MEDIA_ERR_NETWORK
  4408. * @property {string} 4 - MEDIA_ERR_SRC_NOT_SUPPORTED
  4409. * @property {string} 5 - MEDIA_ERR_ENCRYPTED
  4410. */
  4411. MediaError.errorTypes = ['MEDIA_ERR_CUSTOM', 'MEDIA_ERR_ABORTED', 'MEDIA_ERR_NETWORK', 'MEDIA_ERR_DECODE', 'MEDIA_ERR_SRC_NOT_SUPPORTED', 'MEDIA_ERR_ENCRYPTED'];
  4412. /**
  4413. * The default `MediaError` messages based on the {@link MediaError.errorTypes}.
  4414. *
  4415. * @type {Array}
  4416. * @constant
  4417. */
  4418. MediaError.defaultMessages = {
  4419. 1: 'You aborted the media playback',
  4420. 2: 'A network error caused the media download to fail part-way.',
  4421. 3: 'The media playback was aborted due to a corruption problem or because the media used features your browser did not support.',
  4422. 4: 'The media could not be loaded, either because the server or network failed or because the format is not supported.',
  4423. 5: 'The media is encrypted and we do not have the keys to decrypt it.'
  4424. };
  4425. // Add types as properties on MediaError
  4426. // e.g. MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
  4427. for (var errNum = 0; errNum < MediaError.errorTypes.length; errNum++) {
  4428. MediaError[MediaError.errorTypes[errNum]] = errNum;
  4429. // values should be accessible on both the class and instance
  4430. MediaError.prototype[MediaError.errorTypes[errNum]] = errNum;
  4431. }
  4432. /**
  4433. * Returns whether an object is `Promise`-like (i.e. has a `then` method).
  4434. *
  4435. * @param {Object} value
  4436. * An object that may or may not be `Promise`-like.
  4437. *
  4438. * @return {Boolean}
  4439. * Whether or not the object is `Promise`-like.
  4440. */
  4441. function isPromise(value) {
  4442. return value !== undefined && value !== null && typeof value.then === 'function';
  4443. }
  4444. /**
  4445. * Silence a Promise-like object.
  4446. *
  4447. * This is useful for avoiding non-harmful, but potentially confusing "uncaught
  4448. * play promise" rejection error messages.
  4449. *
  4450. * @param {Object} value
  4451. * An object that may or may not be `Promise`-like.
  4452. */
  4453. function silencePromise(value) {
  4454. if (isPromise(value)) {
  4455. value.then(null, function (e) {});
  4456. }
  4457. }
  4458. /**
  4459. * @file text-track-list-converter.js Utilities for capturing text track state and
  4460. * re-creating tracks based on a capture.
  4461. *
  4462. * @module text-track-list-converter
  4463. */
  4464. /**
  4465. * Examine a single {@link TextTrack} and return a JSON-compatible javascript object that
  4466. * represents the {@link TextTrack}'s state.
  4467. *
  4468. * @param {TextTrack} track
  4469. * The text track to query.
  4470. *
  4471. * @return {Object}
  4472. * A serializable javascript representation of the TextTrack.
  4473. * @private
  4474. */
  4475. var trackToJson_ = function trackToJson_(track) {
  4476. var ret = ['kind', 'label', 'language', 'id', 'inBandMetadataTrackDispatchType', 'mode', 'src'].reduce(function (acc, prop, i) {
  4477. if (track[prop]) {
  4478. acc[prop] = track[prop];
  4479. }
  4480. return acc;
  4481. }, {
  4482. cues: track.cues && Array.prototype.map.call(track.cues, function (cue) {
  4483. return {
  4484. startTime: cue.startTime,
  4485. endTime: cue.endTime,
  4486. text: cue.text,
  4487. id: cue.id
  4488. };
  4489. })
  4490. });
  4491. return ret;
  4492. };
  4493. /**
  4494. * Examine a {@link Tech} and return a JSON-compatible javascript array that represents the
  4495. * state of all {@link TextTrack}s currently configured. The return array is compatible with
  4496. * {@link text-track-list-converter:jsonToTextTracks}.
  4497. *
  4498. * @param {Tech} tech
  4499. * The tech object to query
  4500. *
  4501. * @return {Array}
  4502. * A serializable javascript representation of the {@link Tech}s
  4503. * {@link TextTrackList}.
  4504. */
  4505. var textTracksToJson = function textTracksToJson(tech) {
  4506. var trackEls = tech.$$('track');
  4507. var trackObjs = Array.prototype.map.call(trackEls, function (t) {
  4508. return t.track;
  4509. });
  4510. var tracks = Array.prototype.map.call(trackEls, function (trackEl) {
  4511. var json = trackToJson_(trackEl.track);
  4512. if (trackEl.src) {
  4513. json.src = trackEl.src;
  4514. }
  4515. return json;
  4516. });
  4517. return tracks.concat(Array.prototype.filter.call(tech.textTracks(), function (track) {
  4518. return trackObjs.indexOf(track) === -1;
  4519. }).map(trackToJson_));
  4520. };
  4521. /**
  4522. * Create a set of remote {@link TextTrack}s on a {@link Tech} based on an array of javascript
  4523. * object {@link TextTrack} representations.
  4524. *
  4525. * @param {Array} json
  4526. * An array of `TextTrack` representation objects, like those that would be
  4527. * produced by `textTracksToJson`.
  4528. *
  4529. * @param {Tech} tech
  4530. * The `Tech` to create the `TextTrack`s on.
  4531. */
  4532. var jsonToTextTracks = function jsonToTextTracks(json, tech) {
  4533. json.forEach(function (track) {
  4534. var addedTrack = tech.addRemoteTextTrack(track).track;
  4535. if (!track.src && track.cues) {
  4536. track.cues.forEach(function (cue) {
  4537. return addedTrack.addCue(cue);
  4538. });
  4539. }
  4540. });
  4541. return tech.textTracks();
  4542. };
  4543. var textTrackConverter = { textTracksToJson: textTracksToJson, jsonToTextTracks: jsonToTextTracks, trackToJson_: trackToJson_ };
  4544. /**
  4545. * @file modal-dialog.js
  4546. */
  4547. var MODAL_CLASS_NAME = 'vjs-modal-dialog';
  4548. var ESC = 27;
  4549. /**
  4550. * The `ModalDialog` displays over the video and its controls, which blocks
  4551. * interaction with the player until it is closed.
  4552. *
  4553. * Modal dialogs include a "Close" button and will close when that button
  4554. * is activated - or when ESC is pressed anywhere.
  4555. *
  4556. * @extends Component
  4557. */
  4558. var ModalDialog = function (_Component) {
  4559. inherits(ModalDialog, _Component);
  4560. /**
  4561. * Create an instance of this class.
  4562. *
  4563. * @param {Player} player
  4564. * The `Player` that this class should be attached to.
  4565. *
  4566. * @param {Object} [options]
  4567. * The key/value store of player options.
  4568. *
  4569. * @param {Mixed} [options.content=undefined]
  4570. * Provide customized content for this modal.
  4571. *
  4572. * @param {string} [options.description]
  4573. * A text description for the modal, primarily for accessibility.
  4574. *
  4575. * @param {boolean} [options.fillAlways=false]
  4576. * Normally, modals are automatically filled only the first time
  4577. * they open. This tells the modal to refresh its content
  4578. * every time it opens.
  4579. *
  4580. * @param {string} [options.label]
  4581. * A text label for the modal, primarily for accessibility.
  4582. *
  4583. * @param {boolean} [options.temporary=true]
  4584. * If `true`, the modal can only be opened once; it will be
  4585. * disposed as soon as it's closed.
  4586. *
  4587. * @param {boolean} [options.uncloseable=false]
  4588. * If `true`, the user will not be able to close the modal
  4589. * through the UI in the normal ways. Programmatic closing is
  4590. * still possible.
  4591. */
  4592. function ModalDialog(player, options) {
  4593. classCallCheck(this, ModalDialog);
  4594. var _this = possibleConstructorReturn(this, _Component.call(this, player, options));
  4595. _this.opened_ = _this.hasBeenOpened_ = _this.hasBeenFilled_ = false;
  4596. _this.closeable(!_this.options_.uncloseable);
  4597. _this.content(_this.options_.content);
  4598. // Make sure the contentEl is defined AFTER any children are initialized
  4599. // because we only want the contents of the modal in the contentEl
  4600. // (not the UI elements like the close button).
  4601. _this.contentEl_ = createEl('div', {
  4602. className: MODAL_CLASS_NAME + '-content'
  4603. }, {
  4604. role: 'document'
  4605. });
  4606. _this.descEl_ = createEl('p', {
  4607. className: MODAL_CLASS_NAME + '-description vjs-control-text',
  4608. id: _this.el().getAttribute('aria-describedby')
  4609. });
  4610. textContent(_this.descEl_, _this.description());
  4611. _this.el_.appendChild(_this.descEl_);
  4612. _this.el_.appendChild(_this.contentEl_);
  4613. return _this;
  4614. }
  4615. /**
  4616. * Create the `ModalDialog`'s DOM element
  4617. *
  4618. * @return {Element}
  4619. * The DOM element that gets created.
  4620. */
  4621. ModalDialog.prototype.createEl = function createEl$$1() {
  4622. return _Component.prototype.createEl.call(this, 'div', {
  4623. className: this.buildCSSClass(),
  4624. tabIndex: -1
  4625. }, {
  4626. 'aria-describedby': this.id() + '_description',
  4627. 'aria-hidden': 'true',
  4628. 'aria-label': this.label(),
  4629. 'role': 'dialog'
  4630. });
  4631. };
  4632. ModalDialog.prototype.dispose = function dispose() {
  4633. this.contentEl_ = null;
  4634. this.descEl_ = null;
  4635. this.previouslyActiveEl_ = null;
  4636. _Component.prototype.dispose.call(this);
  4637. };
  4638. /**
  4639. * Builds the default DOM `className`.
  4640. *
  4641. * @return {string}
  4642. * The DOM `className` for this object.
  4643. */
  4644. ModalDialog.prototype.buildCSSClass = function buildCSSClass() {
  4645. return MODAL_CLASS_NAME + ' vjs-hidden ' + _Component.prototype.buildCSSClass.call(this);
  4646. };
  4647. /**
  4648. * Handles `keydown` events on the document, looking for ESC, which closes
  4649. * the modal.
  4650. *
  4651. * @param {EventTarget~Event} e
  4652. * The keypress that triggered this event.
  4653. *
  4654. * @listens keydown
  4655. */
  4656. ModalDialog.prototype.handleKeyPress = function handleKeyPress(e) {
  4657. if (e.which === ESC && this.closeable()) {
  4658. this.close();
  4659. }
  4660. };
  4661. /**
  4662. * Returns the label string for this modal. Primarily used for accessibility.
  4663. *
  4664. * @return {string}
  4665. * the localized or raw label of this modal.
  4666. */
  4667. ModalDialog.prototype.label = function label() {
  4668. return this.localize(this.options_.label || 'Modal Window');
  4669. };
  4670. /**
  4671. * Returns the description string for this modal. Primarily used for
  4672. * accessibility.
  4673. *
  4674. * @return {string}
  4675. * The localized or raw description of this modal.
  4676. */
  4677. ModalDialog.prototype.description = function description() {
  4678. var desc = this.options_.description || this.localize('This is a modal window.');
  4679. // Append a universal closeability message if the modal is closeable.
  4680. if (this.closeable()) {
  4681. desc += ' ' + this.localize('This modal can be closed by pressing the Escape key or activating the close button.');
  4682. }
  4683. return desc;
  4684. };
  4685. /**
  4686. * Opens the modal.
  4687. *
  4688. * @fires ModalDialog#beforemodalopen
  4689. * @fires ModalDialog#modalopen
  4690. */
  4691. ModalDialog.prototype.open = function open() {
  4692. if (!this.opened_) {
  4693. var player = this.player();
  4694. /**
  4695. * Fired just before a `ModalDialog` is opened.
  4696. *
  4697. * @event ModalDialog#beforemodalopen
  4698. * @type {EventTarget~Event}
  4699. */
  4700. this.trigger('beforemodalopen');
  4701. this.opened_ = true;
  4702. // Fill content if the modal has never opened before and
  4703. // never been filled.
  4704. if (this.options_.fillAlways || !this.hasBeenOpened_ && !this.hasBeenFilled_) {
  4705. this.fill();
  4706. }
  4707. // If the player was playing, pause it and take note of its previously
  4708. // playing state.
  4709. this.wasPlaying_ = !player.paused();
  4710. if (this.options_.pauseOnOpen && this.wasPlaying_) {
  4711. player.pause();
  4712. }
  4713. if (this.closeable()) {
  4714. this.on(this.el_.ownerDocument, 'keydown', bind(this, this.handleKeyPress));
  4715. }
  4716. // Hide controls and note if they were enabled.
  4717. this.hadControls_ = player.controls();
  4718. player.controls(false);
  4719. this.show();
  4720. this.conditionalFocus_();
  4721. this.el().setAttribute('aria-hidden', 'false');
  4722. /**
  4723. * Fired just after a `ModalDialog` is opened.
  4724. *
  4725. * @event ModalDialog#modalopen
  4726. * @type {EventTarget~Event}
  4727. */
  4728. this.trigger('modalopen');
  4729. this.hasBeenOpened_ = true;
  4730. }
  4731. };
  4732. /**
  4733. * If the `ModalDialog` is currently open or closed.
  4734. *
  4735. * @param {boolean} [value]
  4736. * If given, it will open (`true`) or close (`false`) the modal.
  4737. *
  4738. * @return {boolean}
  4739. * the current open state of the modaldialog
  4740. */
  4741. ModalDialog.prototype.opened = function opened(value) {
  4742. if (typeof value === 'boolean') {
  4743. this[value ? 'open' : 'close']();
  4744. }
  4745. return this.opened_;
  4746. };
  4747. /**
  4748. * Closes the modal, does nothing if the `ModalDialog` is
  4749. * not open.
  4750. *
  4751. * @fires ModalDialog#beforemodalclose
  4752. * @fires ModalDialog#modalclose
  4753. */
  4754. ModalDialog.prototype.close = function close() {
  4755. if (!this.opened_) {
  4756. return;
  4757. }
  4758. var player = this.player();
  4759. /**
  4760. * Fired just before a `ModalDialog` is closed.
  4761. *
  4762. * @event ModalDialog#beforemodalclose
  4763. * @type {EventTarget~Event}
  4764. */
  4765. this.trigger('beforemodalclose');
  4766. this.opened_ = false;
  4767. if (this.wasPlaying_ && this.options_.pauseOnOpen) {
  4768. player.play();
  4769. }
  4770. if (this.closeable()) {
  4771. this.off(this.el_.ownerDocument, 'keydown', bind(this, this.handleKeyPress));
  4772. }
  4773. if (this.hadControls_) {
  4774. player.controls(true);
  4775. }
  4776. this.hide();
  4777. this.el().setAttribute('aria-hidden', 'true');
  4778. /**
  4779. * Fired just after a `ModalDialog` is closed.
  4780. *
  4781. * @event ModalDialog#modalclose
  4782. * @type {EventTarget~Event}
  4783. */
  4784. this.trigger('modalclose');
  4785. this.conditionalBlur_();
  4786. if (this.options_.temporary) {
  4787. this.dispose();
  4788. }
  4789. };
  4790. /**
  4791. * Check to see if the `ModalDialog` is closeable via the UI.
  4792. *
  4793. * @param {boolean} [value]
  4794. * If given as a boolean, it will set the `closeable` option.
  4795. *
  4796. * @return {boolean}
  4797. * Returns the final value of the closable option.
  4798. */
  4799. ModalDialog.prototype.closeable = function closeable(value) {
  4800. if (typeof value === 'boolean') {
  4801. var closeable = this.closeable_ = !!value;
  4802. var close = this.getChild('closeButton');
  4803. // If this is being made closeable and has no close button, add one.
  4804. if (closeable && !close) {
  4805. // The close button should be a child of the modal - not its
  4806. // content element, so temporarily change the content element.
  4807. var temp = this.contentEl_;
  4808. this.contentEl_ = this.el_;
  4809. close = this.addChild('closeButton', { controlText: 'Close Modal Dialog' });
  4810. this.contentEl_ = temp;
  4811. this.on(close, 'close', this.close);
  4812. }
  4813. // If this is being made uncloseable and has a close button, remove it.
  4814. if (!closeable && close) {
  4815. this.off(close, 'close', this.close);
  4816. this.removeChild(close);
  4817. close.dispose();
  4818. }
  4819. }
  4820. return this.closeable_;
  4821. };
  4822. /**
  4823. * Fill the modal's content element with the modal's "content" option.
  4824. * The content element will be emptied before this change takes place.
  4825. */
  4826. ModalDialog.prototype.fill = function fill() {
  4827. this.fillWith(this.content());
  4828. };
  4829. /**
  4830. * Fill the modal's content element with arbitrary content.
  4831. * The content element will be emptied before this change takes place.
  4832. *
  4833. * @fires ModalDialog#beforemodalfill
  4834. * @fires ModalDialog#modalfill
  4835. *
  4836. * @param {Mixed} [content]
  4837. * The same rules apply to this as apply to the `content` option.
  4838. */
  4839. ModalDialog.prototype.fillWith = function fillWith(content) {
  4840. var contentEl = this.contentEl();
  4841. var parentEl = contentEl.parentNode;
  4842. var nextSiblingEl = contentEl.nextSibling;
  4843. /**
  4844. * Fired just before a `ModalDialog` is filled with content.
  4845. *
  4846. * @event ModalDialog#beforemodalfill
  4847. * @type {EventTarget~Event}
  4848. */
  4849. this.trigger('beforemodalfill');
  4850. this.hasBeenFilled_ = true;
  4851. // Detach the content element from the DOM before performing
  4852. // manipulation to avoid modifying the live DOM multiple times.
  4853. parentEl.removeChild(contentEl);
  4854. this.empty();
  4855. insertContent(contentEl, content);
  4856. /**
  4857. * Fired just after a `ModalDialog` is filled with content.
  4858. *
  4859. * @event ModalDialog#modalfill
  4860. * @type {EventTarget~Event}
  4861. */
  4862. this.trigger('modalfill');
  4863. // Re-inject the re-filled content element.
  4864. if (nextSiblingEl) {
  4865. parentEl.insertBefore(contentEl, nextSiblingEl);
  4866. } else {
  4867. parentEl.appendChild(contentEl);
  4868. }
  4869. // make sure that the close button is last in the dialog DOM
  4870. var closeButton = this.getChild('closeButton');
  4871. if (closeButton) {
  4872. parentEl.appendChild(closeButton.el_);
  4873. }
  4874. };
  4875. /**
  4876. * Empties the content element. This happens anytime the modal is filled.
  4877. *
  4878. * @fires ModalDialog#beforemodalempty
  4879. * @fires ModalDialog#modalempty
  4880. */
  4881. ModalDialog.prototype.empty = function empty() {
  4882. /**
  4883. * Fired just before a `ModalDialog` is emptied.
  4884. *
  4885. * @event ModalDialog#beforemodalempty
  4886. * @type {EventTarget~Event}
  4887. */
  4888. this.trigger('beforemodalempty');
  4889. emptyEl(this.contentEl());
  4890. /**
  4891. * Fired just after a `ModalDialog` is emptied.
  4892. *
  4893. * @event ModalDialog#modalempty
  4894. * @type {EventTarget~Event}
  4895. */
  4896. this.trigger('modalempty');
  4897. };
  4898. /**
  4899. * Gets or sets the modal content, which gets normalized before being
  4900. * rendered into the DOM.
  4901. *
  4902. * This does not update the DOM or fill the modal, but it is called during
  4903. * that process.
  4904. *
  4905. * @param {Mixed} [value]
  4906. * If defined, sets the internal content value to be used on the
  4907. * next call(s) to `fill`. This value is normalized before being
  4908. * inserted. To "clear" the internal content value, pass `null`.
  4909. *
  4910. * @return {Mixed}
  4911. * The current content of the modal dialog
  4912. */
  4913. ModalDialog.prototype.content = function content(value) {
  4914. if (typeof value !== 'undefined') {
  4915. this.content_ = value;
  4916. }
  4917. return this.content_;
  4918. };
  4919. /**
  4920. * conditionally focus the modal dialog if focus was previously on the player.
  4921. *
  4922. * @private
  4923. */
  4924. ModalDialog.prototype.conditionalFocus_ = function conditionalFocus_() {
  4925. var activeEl = document.activeElement;
  4926. var playerEl = this.player_.el_;
  4927. this.previouslyActiveEl_ = null;
  4928. if (playerEl.contains(activeEl) || playerEl === activeEl) {
  4929. this.previouslyActiveEl_ = activeEl;
  4930. this.focus();
  4931. this.on(document, 'keydown', this.handleKeyDown);
  4932. }
  4933. };
  4934. /**
  4935. * conditionally blur the element and refocus the last focused element
  4936. *
  4937. * @private
  4938. */
  4939. ModalDialog.prototype.conditionalBlur_ = function conditionalBlur_() {
  4940. if (this.previouslyActiveEl_) {
  4941. this.previouslyActiveEl_.focus();
  4942. this.previouslyActiveEl_ = null;
  4943. }
  4944. this.off(document, 'keydown', this.handleKeyDown);
  4945. };
  4946. /**
  4947. * Keydown handler. Attached when modal is focused.
  4948. *
  4949. * @listens keydown
  4950. */
  4951. ModalDialog.prototype.handleKeyDown = function handleKeyDown(event) {
  4952. // exit early if it isn't a tab key
  4953. if (event.which !== 9) {
  4954. return;
  4955. }
  4956. var focusableEls = this.focusableEls_();
  4957. var activeEl = this.el_.querySelector(':focus');
  4958. var focusIndex = void 0;
  4959. for (var i = 0; i < focusableEls.length; i++) {
  4960. if (activeEl === focusableEls[i]) {
  4961. focusIndex = i;
  4962. break;
  4963. }
  4964. }
  4965. if (document.activeElement === this.el_) {
  4966. focusIndex = 0;
  4967. }
  4968. if (event.shiftKey && focusIndex === 0) {
  4969. focusableEls[focusableEls.length - 1].focus();
  4970. event.preventDefault();
  4971. } else if (!event.shiftKey && focusIndex === focusableEls.length - 1) {
  4972. focusableEls[0].focus();
  4973. event.preventDefault();
  4974. }
  4975. };
  4976. /**
  4977. * get all focusable elements
  4978. *
  4979. * @private
  4980. */
  4981. ModalDialog.prototype.focusableEls_ = function focusableEls_() {
  4982. var allChildren = this.el_.querySelectorAll('*');
  4983. return Array.prototype.filter.call(allChildren, function (child) {
  4984. return (child instanceof window.HTMLAnchorElement || child instanceof window.HTMLAreaElement) && child.hasAttribute('href') || (child instanceof window.HTMLInputElement || child instanceof window.HTMLSelectElement || child instanceof window.HTMLTextAreaElement || child instanceof window.HTMLButtonElement) && !child.hasAttribute('disabled') || child instanceof window.HTMLIFrameElement || child instanceof window.HTMLObjectElement || child instanceof window.HTMLEmbedElement || child.hasAttribute('tabindex') && child.getAttribute('tabindex') !== -1 || child.hasAttribute('contenteditable');
  4985. });
  4986. };
  4987. return ModalDialog;
  4988. }(Component);
  4989. /**
  4990. * Default options for `ModalDialog` default options.
  4991. *
  4992. * @type {Object}
  4993. * @private
  4994. */
  4995. ModalDialog.prototype.options_ = {
  4996. pauseOnOpen: true,
  4997. temporary: true
  4998. };
  4999. Component.registerComponent('ModalDialog', ModalDialog);
  5000. /**
  5001. * @file track-list.js
  5002. */
  5003. /**
  5004. * Common functionaliy between {@link TextTrackList}, {@link AudioTrackList}, and
  5005. * {@link VideoTrackList}
  5006. *
  5007. * @extends EventTarget
  5008. */
  5009. var TrackList = function (_EventTarget) {
  5010. inherits(TrackList, _EventTarget);
  5011. /**
  5012. * Create an instance of this class
  5013. *
  5014. * @param {Track[]} tracks
  5015. * A list of tracks to initialize the list with.
  5016. *
  5017. * @param {Object} [list]
  5018. * The child object with inheritance done manually for ie8.
  5019. *
  5020. * @abstract
  5021. */
  5022. function TrackList() {
  5023. var tracks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  5024. var _ret;
  5025. var list = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  5026. classCallCheck(this, TrackList);
  5027. var _this = possibleConstructorReturn(this, _EventTarget.call(this));
  5028. if (!list) {
  5029. list = _this; // eslint-disable-line
  5030. if (IS_IE8) {
  5031. list = document.createElement('custom');
  5032. for (var prop in TrackList.prototype) {
  5033. if (prop !== 'constructor') {
  5034. list[prop] = TrackList.prototype[prop];
  5035. }
  5036. }
  5037. }
  5038. }
  5039. list.tracks_ = [];
  5040. /**
  5041. * @memberof TrackList
  5042. * @member {number} length
  5043. * The current number of `Track`s in the this Trackist.
  5044. * @instance
  5045. */
  5046. Object.defineProperty(list, 'length', {
  5047. get: function get$$1() {
  5048. return this.tracks_.length;
  5049. }
  5050. });
  5051. for (var i = 0; i < tracks.length; i++) {
  5052. list.addTrack(tracks[i]);
  5053. }
  5054. // must return the object, as for ie8 it will not be this
  5055. // but a reference to a document object
  5056. return _ret = list, possibleConstructorReturn(_this, _ret);
  5057. }
  5058. /**
  5059. * Add a {@link Track} to the `TrackList`
  5060. *
  5061. * @param {Track} track
  5062. * The audio, video, or text track to add to the list.
  5063. *
  5064. * @fires TrackList#addtrack
  5065. */
  5066. TrackList.prototype.addTrack = function addTrack(track) {
  5067. var index = this.tracks_.length;
  5068. if (!('' + index in this)) {
  5069. Object.defineProperty(this, index, {
  5070. get: function get$$1() {
  5071. return this.tracks_[index];
  5072. }
  5073. });
  5074. }
  5075. // Do not add duplicate tracks
  5076. if (this.tracks_.indexOf(track) === -1) {
  5077. this.tracks_.push(track);
  5078. /**
  5079. * Triggered when a track is added to a track list.
  5080. *
  5081. * @event TrackList#addtrack
  5082. * @type {EventTarget~Event}
  5083. * @property {Track} track
  5084. * A reference to track that was added.
  5085. */
  5086. this.trigger({
  5087. track: track,
  5088. type: 'addtrack'
  5089. });
  5090. }
  5091. };
  5092. /**
  5093. * Remove a {@link Track} from the `TrackList`
  5094. *
  5095. * @param {Track} rtrack
  5096. * The audio, video, or text track to remove from the list.
  5097. *
  5098. * @fires TrackList#removetrack
  5099. */
  5100. TrackList.prototype.removeTrack = function removeTrack(rtrack) {
  5101. var track = void 0;
  5102. for (var i = 0, l = this.length; i < l; i++) {
  5103. if (this[i] === rtrack) {
  5104. track = this[i];
  5105. if (track.off) {
  5106. track.off();
  5107. }
  5108. this.tracks_.splice(i, 1);
  5109. break;
  5110. }
  5111. }
  5112. if (!track) {
  5113. return;
  5114. }
  5115. /**
  5116. * Triggered when a track is removed from track list.
  5117. *
  5118. * @event TrackList#removetrack
  5119. * @type {EventTarget~Event}
  5120. * @property {Track} track
  5121. * A reference to track that was removed.
  5122. */
  5123. this.trigger({
  5124. track: track,
  5125. type: 'removetrack'
  5126. });
  5127. };
  5128. /**
  5129. * Get a Track from the TrackList by a tracks id
  5130. *
  5131. * @param {String} id - the id of the track to get
  5132. * @method getTrackById
  5133. * @return {Track}
  5134. * @private
  5135. */
  5136. TrackList.prototype.getTrackById = function getTrackById(id) {
  5137. var result = null;
  5138. for (var i = 0, l = this.length; i < l; i++) {
  5139. var track = this[i];
  5140. if (track.id === id) {
  5141. result = track;
  5142. break;
  5143. }
  5144. }
  5145. return result;
  5146. };
  5147. return TrackList;
  5148. }(EventTarget);
  5149. /**
  5150. * Triggered when a different track is selected/enabled.
  5151. *
  5152. * @event TrackList#change
  5153. * @type {EventTarget~Event}
  5154. */
  5155. /**
  5156. * Events that can be called with on + eventName. See {@link EventHandler}.
  5157. *
  5158. * @property {Object} TrackList#allowedEvents_
  5159. * @private
  5160. */
  5161. TrackList.prototype.allowedEvents_ = {
  5162. change: 'change',
  5163. addtrack: 'addtrack',
  5164. removetrack: 'removetrack'
  5165. };
  5166. // emulate attribute EventHandler support to allow for feature detection
  5167. for (var event in TrackList.prototype.allowedEvents_) {
  5168. TrackList.prototype['on' + event] = null;
  5169. }
  5170. /**
  5171. * @file audio-track-list.js
  5172. */
  5173. /**
  5174. * Anywhere we call this function we diverge from the spec
  5175. * as we only support one enabled audiotrack at a time
  5176. *
  5177. * @param {AudioTrackList} list
  5178. * list to work on
  5179. *
  5180. * @param {AudioTrack} track
  5181. * The track to skip
  5182. *
  5183. * @private
  5184. */
  5185. var disableOthers = function disableOthers(list, track) {
  5186. for (var i = 0; i < list.length; i++) {
  5187. if (!Object.keys(list[i]).length || track.id === list[i].id) {
  5188. continue;
  5189. }
  5190. // another audio track is enabled, disable it
  5191. list[i].enabled = false;
  5192. }
  5193. };
  5194. /**
  5195. * The current list of {@link AudioTrack} for a media file.
  5196. *
  5197. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#audiotracklist}
  5198. * @extends TrackList
  5199. */
  5200. var AudioTrackList = function (_TrackList) {
  5201. inherits(AudioTrackList, _TrackList);
  5202. /**
  5203. * Create an instance of this class.
  5204. *
  5205. * @param {AudioTrack[]} [tracks=[]]
  5206. * A list of `AudioTrack` to instantiate the list with.
  5207. */
  5208. function AudioTrackList() {
  5209. var _this, _ret;
  5210. var tracks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  5211. classCallCheck(this, AudioTrackList);
  5212. var list = void 0;
  5213. // make sure only 1 track is enabled
  5214. // sorted from last index to first index
  5215. for (var i = tracks.length - 1; i >= 0; i--) {
  5216. if (tracks[i].enabled) {
  5217. disableOthers(tracks, tracks[i]);
  5218. break;
  5219. }
  5220. }
  5221. // IE8 forces us to implement inheritance ourselves
  5222. // as it does not support Object.defineProperty properly
  5223. if (IS_IE8) {
  5224. list = document.createElement('custom');
  5225. for (var prop in TrackList.prototype) {
  5226. if (prop !== 'constructor') {
  5227. list[prop] = TrackList.prototype[prop];
  5228. }
  5229. }
  5230. for (var _prop in AudioTrackList.prototype) {
  5231. if (_prop !== 'constructor') {
  5232. list[_prop] = AudioTrackList.prototype[_prop];
  5233. }
  5234. }
  5235. }
  5236. list = (_this = possibleConstructorReturn(this, _TrackList.call(this, tracks, list)), _this);
  5237. list.changing_ = false;
  5238. return _ret = list, possibleConstructorReturn(_this, _ret);
  5239. }
  5240. /**
  5241. * Add an {@link AudioTrack} to the `AudioTrackList`.
  5242. *
  5243. * @param {AudioTrack} track
  5244. * The AudioTrack to add to the list
  5245. *
  5246. * @fires TrackList#addtrack
  5247. */
  5248. AudioTrackList.prototype.addTrack = function addTrack(track) {
  5249. var _this2 = this;
  5250. if (track.enabled) {
  5251. disableOthers(this, track);
  5252. }
  5253. _TrackList.prototype.addTrack.call(this, track);
  5254. // native tracks don't have this
  5255. if (!track.addEventListener) {
  5256. return;
  5257. }
  5258. /**
  5259. * @listens AudioTrack#enabledchange
  5260. * @fires TrackList#change
  5261. */
  5262. track.addEventListener('enabledchange', function () {
  5263. // when we are disabling other tracks (since we don't support
  5264. // more than one track at a time) we will set changing_
  5265. // to true so that we don't trigger additional change events
  5266. if (_this2.changing_) {
  5267. return;
  5268. }
  5269. _this2.changing_ = true;
  5270. disableOthers(_this2, track);
  5271. _this2.changing_ = false;
  5272. _this2.trigger('change');
  5273. });
  5274. };
  5275. return AudioTrackList;
  5276. }(TrackList);
  5277. /**
  5278. * @file video-track-list.js
  5279. */
  5280. /**
  5281. * Un-select all other {@link VideoTrack}s that are selected.
  5282. *
  5283. * @param {VideoTrackList} list
  5284. * list to work on
  5285. *
  5286. * @param {VideoTrack} track
  5287. * The track to skip
  5288. *
  5289. * @private
  5290. */
  5291. var disableOthers$1 = function disableOthers(list, track) {
  5292. for (var i = 0; i < list.length; i++) {
  5293. if (!Object.keys(list[i]).length || track.id === list[i].id) {
  5294. continue;
  5295. }
  5296. // another video track is enabled, disable it
  5297. list[i].selected = false;
  5298. }
  5299. };
  5300. /**
  5301. * The current list of {@link VideoTrack} for a video.
  5302. *
  5303. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#videotracklist}
  5304. * @extends TrackList
  5305. */
  5306. var VideoTrackList = function (_TrackList) {
  5307. inherits(VideoTrackList, _TrackList);
  5308. /**
  5309. * Create an instance of this class.
  5310. *
  5311. * @param {VideoTrack[]} [tracks=[]]
  5312. * A list of `VideoTrack` to instantiate the list with.
  5313. */
  5314. function VideoTrackList() {
  5315. var _this, _ret;
  5316. var tracks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  5317. classCallCheck(this, VideoTrackList);
  5318. var list = void 0;
  5319. // make sure only 1 track is enabled
  5320. // sorted from last index to first index
  5321. for (var i = tracks.length - 1; i >= 0; i--) {
  5322. if (tracks[i].selected) {
  5323. disableOthers$1(tracks, tracks[i]);
  5324. break;
  5325. }
  5326. }
  5327. // IE8 forces us to implement inheritance ourselves
  5328. // as it does not support Object.defineProperty properly
  5329. if (IS_IE8) {
  5330. list = document.createElement('custom');
  5331. for (var prop in TrackList.prototype) {
  5332. if (prop !== 'constructor') {
  5333. list[prop] = TrackList.prototype[prop];
  5334. }
  5335. }
  5336. for (var _prop in VideoTrackList.prototype) {
  5337. if (_prop !== 'constructor') {
  5338. list[_prop] = VideoTrackList.prototype[_prop];
  5339. }
  5340. }
  5341. }
  5342. list = (_this = possibleConstructorReturn(this, _TrackList.call(this, tracks, list)), _this);
  5343. list.changing_ = false;
  5344. /**
  5345. * @member {number} VideoTrackList#selectedIndex
  5346. * The current index of the selected {@link VideoTrack`}.
  5347. */
  5348. Object.defineProperty(list, 'selectedIndex', {
  5349. get: function get$$1() {
  5350. for (var _i = 0; _i < this.length; _i++) {
  5351. if (this[_i].selected) {
  5352. return _i;
  5353. }
  5354. }
  5355. return -1;
  5356. },
  5357. set: function set$$1() {}
  5358. });
  5359. return _ret = list, possibleConstructorReturn(_this, _ret);
  5360. }
  5361. /**
  5362. * Add a {@link VideoTrack} to the `VideoTrackList`.
  5363. *
  5364. * @param {VideoTrack} track
  5365. * The VideoTrack to add to the list
  5366. *
  5367. * @fires TrackList#addtrack
  5368. */
  5369. VideoTrackList.prototype.addTrack = function addTrack(track) {
  5370. var _this2 = this;
  5371. if (track.selected) {
  5372. disableOthers$1(this, track);
  5373. }
  5374. _TrackList.prototype.addTrack.call(this, track);
  5375. // native tracks don't have this
  5376. if (!track.addEventListener) {
  5377. return;
  5378. }
  5379. /**
  5380. * @listens VideoTrack#selectedchange
  5381. * @fires TrackList#change
  5382. */
  5383. track.addEventListener('selectedchange', function () {
  5384. if (_this2.changing_) {
  5385. return;
  5386. }
  5387. _this2.changing_ = true;
  5388. disableOthers$1(_this2, track);
  5389. _this2.changing_ = false;
  5390. _this2.trigger('change');
  5391. });
  5392. };
  5393. return VideoTrackList;
  5394. }(TrackList);
  5395. /**
  5396. * @file text-track-list.js
  5397. */
  5398. /**
  5399. * The current list of {@link TextTrack} for a media file.
  5400. *
  5401. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#texttracklist}
  5402. * @extends TrackList
  5403. */
  5404. var TextTrackList = function (_TrackList) {
  5405. inherits(TextTrackList, _TrackList);
  5406. /**
  5407. * Create an instance of this class.
  5408. *
  5409. * @param {TextTrack[]} [tracks=[]]
  5410. * A list of `TextTrack` to instantiate the list with.
  5411. */
  5412. function TextTrackList() {
  5413. var _this, _ret;
  5414. var tracks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  5415. classCallCheck(this, TextTrackList);
  5416. var list = void 0;
  5417. // IE8 forces us to implement inheritance ourselves
  5418. // as it does not support Object.defineProperty properly
  5419. if (IS_IE8) {
  5420. list = document.createElement('custom');
  5421. for (var prop in TrackList.prototype) {
  5422. if (prop !== 'constructor') {
  5423. list[prop] = TrackList.prototype[prop];
  5424. }
  5425. }
  5426. for (var _prop in TextTrackList.prototype) {
  5427. if (_prop !== 'constructor') {
  5428. list[_prop] = TextTrackList.prototype[_prop];
  5429. }
  5430. }
  5431. }
  5432. list = (_this = possibleConstructorReturn(this, _TrackList.call(this, tracks, list)), _this);
  5433. return _ret = list, possibleConstructorReturn(_this, _ret);
  5434. }
  5435. /**
  5436. * Add a {@link TextTrack} to the `TextTrackList`
  5437. *
  5438. * @param {TextTrack} track
  5439. * The text track to add to the list.
  5440. *
  5441. * @fires TrackList#addtrack
  5442. */
  5443. TextTrackList.prototype.addTrack = function addTrack(track) {
  5444. _TrackList.prototype.addTrack.call(this, track);
  5445. /**
  5446. * @listens TextTrack#modechange
  5447. * @fires TrackList#change
  5448. */
  5449. track.addEventListener('modechange', bind(this, function () {
  5450. this.trigger('change');
  5451. }));
  5452. var nonLanguageTextTrackKind = ['metadata', 'chapters'];
  5453. if (nonLanguageTextTrackKind.indexOf(track.kind) === -1) {
  5454. track.addEventListener('modechange', bind(this, function () {
  5455. this.trigger('selectedlanguagechange');
  5456. }));
  5457. }
  5458. };
  5459. return TextTrackList;
  5460. }(TrackList);
  5461. /**
  5462. * @file html-track-element-list.js
  5463. */
  5464. /**
  5465. * The current list of {@link HtmlTrackElement}s.
  5466. */
  5467. var HtmlTrackElementList = function () {
  5468. /**
  5469. * Create an instance of this class.
  5470. *
  5471. * @param {HtmlTrackElement[]} [tracks=[]]
  5472. * A list of `HtmlTrackElement` to instantiate the list with.
  5473. */
  5474. function HtmlTrackElementList() {
  5475. var trackElements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  5476. classCallCheck(this, HtmlTrackElementList);
  5477. var list = this; // eslint-disable-line
  5478. if (IS_IE8) {
  5479. list = document.createElement('custom');
  5480. for (var prop in HtmlTrackElementList.prototype) {
  5481. if (prop !== 'constructor') {
  5482. list[prop] = HtmlTrackElementList.prototype[prop];
  5483. }
  5484. }
  5485. }
  5486. list.trackElements_ = [];
  5487. /**
  5488. * @memberof HtmlTrackElementList
  5489. * @member {number} length
  5490. * The current number of `Track`s in the this Trackist.
  5491. * @instance
  5492. */
  5493. Object.defineProperty(list, 'length', {
  5494. get: function get$$1() {
  5495. return this.trackElements_.length;
  5496. }
  5497. });
  5498. for (var i = 0, length = trackElements.length; i < length; i++) {
  5499. list.addTrackElement_(trackElements[i]);
  5500. }
  5501. if (IS_IE8) {
  5502. return list;
  5503. }
  5504. }
  5505. /**
  5506. * Add an {@link HtmlTrackElement} to the `HtmlTrackElementList`
  5507. *
  5508. * @param {HtmlTrackElement} trackElement
  5509. * The track element to add to the list.
  5510. *
  5511. * @private
  5512. */
  5513. HtmlTrackElementList.prototype.addTrackElement_ = function addTrackElement_(trackElement) {
  5514. var index = this.trackElements_.length;
  5515. if (!('' + index in this)) {
  5516. Object.defineProperty(this, index, {
  5517. get: function get$$1() {
  5518. return this.trackElements_[index];
  5519. }
  5520. });
  5521. }
  5522. // Do not add duplicate elements
  5523. if (this.trackElements_.indexOf(trackElement) === -1) {
  5524. this.trackElements_.push(trackElement);
  5525. }
  5526. };
  5527. /**
  5528. * Get an {@link HtmlTrackElement} from the `HtmlTrackElementList` given an
  5529. * {@link TextTrack}.
  5530. *
  5531. * @param {TextTrack} track
  5532. * The track associated with a track element.
  5533. *
  5534. * @return {HtmlTrackElement|undefined}
  5535. * The track element that was found or undefined.
  5536. *
  5537. * @private
  5538. */
  5539. HtmlTrackElementList.prototype.getTrackElementByTrack_ = function getTrackElementByTrack_(track) {
  5540. var trackElement_ = void 0;
  5541. for (var i = 0, length = this.trackElements_.length; i < length; i++) {
  5542. if (track === this.trackElements_[i].track) {
  5543. trackElement_ = this.trackElements_[i];
  5544. break;
  5545. }
  5546. }
  5547. return trackElement_;
  5548. };
  5549. /**
  5550. * Remove a {@link HtmlTrackElement} from the `HtmlTrackElementList`
  5551. *
  5552. * @param {HtmlTrackElement} trackElement
  5553. * The track element to remove from the list.
  5554. *
  5555. * @private
  5556. */
  5557. HtmlTrackElementList.prototype.removeTrackElement_ = function removeTrackElement_(trackElement) {
  5558. for (var i = 0, length = this.trackElements_.length; i < length; i++) {
  5559. if (trackElement === this.trackElements_[i]) {
  5560. this.trackElements_.splice(i, 1);
  5561. break;
  5562. }
  5563. }
  5564. };
  5565. return HtmlTrackElementList;
  5566. }();
  5567. /**
  5568. * @file text-track-cue-list.js
  5569. */
  5570. /**
  5571. * @typedef {Object} TextTrackCueList~TextTrackCue
  5572. *
  5573. * @property {string} id
  5574. * The unique id for this text track cue
  5575. *
  5576. * @property {number} startTime
  5577. * The start time for this text track cue
  5578. *
  5579. * @property {number} endTime
  5580. * The end time for this text track cue
  5581. *
  5582. * @property {boolean} pauseOnExit
  5583. * Pause when the end time is reached if true.
  5584. *
  5585. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#texttrackcue}
  5586. */
  5587. /**
  5588. * A List of TextTrackCues.
  5589. *
  5590. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#texttrackcuelist}
  5591. */
  5592. var TextTrackCueList = function () {
  5593. /**
  5594. * Create an instance of this class..
  5595. *
  5596. * @param {Array} cues
  5597. * A list of cues to be initialized with
  5598. */
  5599. function TextTrackCueList(cues) {
  5600. classCallCheck(this, TextTrackCueList);
  5601. var list = this; // eslint-disable-line
  5602. if (IS_IE8) {
  5603. list = document.createElement('custom');
  5604. for (var prop in TextTrackCueList.prototype) {
  5605. if (prop !== 'constructor') {
  5606. list[prop] = TextTrackCueList.prototype[prop];
  5607. }
  5608. }
  5609. }
  5610. TextTrackCueList.prototype.setCues_.call(list, cues);
  5611. /**
  5612. * @memberof TextTrackCueList
  5613. * @member {number} length
  5614. * The current number of `TextTrackCue`s in the TextTrackCueList.
  5615. * @instance
  5616. */
  5617. Object.defineProperty(list, 'length', {
  5618. get: function get$$1() {
  5619. return this.length_;
  5620. }
  5621. });
  5622. if (IS_IE8) {
  5623. return list;
  5624. }
  5625. }
  5626. /**
  5627. * A setter for cues in this list. Creates getters
  5628. * an an index for the cues.
  5629. *
  5630. * @param {Array} cues
  5631. * An array of cues to set
  5632. *
  5633. * @private
  5634. */
  5635. TextTrackCueList.prototype.setCues_ = function setCues_(cues) {
  5636. var oldLength = this.length || 0;
  5637. var i = 0;
  5638. var l = cues.length;
  5639. this.cues_ = cues;
  5640. this.length_ = cues.length;
  5641. var defineProp = function defineProp(index) {
  5642. if (!('' + index in this)) {
  5643. Object.defineProperty(this, '' + index, {
  5644. get: function get$$1() {
  5645. return this.cues_[index];
  5646. }
  5647. });
  5648. }
  5649. };
  5650. if (oldLength < l) {
  5651. i = oldLength;
  5652. for (; i < l; i++) {
  5653. defineProp.call(this, i);
  5654. }
  5655. }
  5656. };
  5657. /**
  5658. * Get a `TextTrackCue` that is currently in the `TextTrackCueList` by id.
  5659. *
  5660. * @param {string} id
  5661. * The id of the cue that should be searched for.
  5662. *
  5663. * @return {TextTrackCueList~TextTrackCue|null}
  5664. * A single cue or null if none was found.
  5665. */
  5666. TextTrackCueList.prototype.getCueById = function getCueById(id) {
  5667. var result = null;
  5668. for (var i = 0, l = this.length; i < l; i++) {
  5669. var cue = this[i];
  5670. if (cue.id === id) {
  5671. result = cue;
  5672. break;
  5673. }
  5674. }
  5675. return result;
  5676. };
  5677. return TextTrackCueList;
  5678. }();
  5679. /**
  5680. * @file track-kinds.js
  5681. */
  5682. /**
  5683. * All possible `VideoTrackKind`s
  5684. *
  5685. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-videotrack-kind
  5686. * @typedef VideoTrack~Kind
  5687. * @enum
  5688. */
  5689. var VideoTrackKind = {
  5690. alternative: 'alternative',
  5691. captions: 'captions',
  5692. main: 'main',
  5693. sign: 'sign',
  5694. subtitles: 'subtitles',
  5695. commentary: 'commentary'
  5696. };
  5697. /**
  5698. * All possible `AudioTrackKind`s
  5699. *
  5700. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-audiotrack-kind
  5701. * @typedef AudioTrack~Kind
  5702. * @enum
  5703. */
  5704. var AudioTrackKind = {
  5705. 'alternative': 'alternative',
  5706. 'descriptions': 'descriptions',
  5707. 'main': 'main',
  5708. 'main-desc': 'main-desc',
  5709. 'translation': 'translation',
  5710. 'commentary': 'commentary'
  5711. };
  5712. /**
  5713. * All possible `TextTrackKind`s
  5714. *
  5715. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-texttrack-kind
  5716. * @typedef TextTrack~Kind
  5717. * @enum
  5718. */
  5719. var TextTrackKind = {
  5720. subtitles: 'subtitles',
  5721. captions: 'captions',
  5722. descriptions: 'descriptions',
  5723. chapters: 'chapters',
  5724. metadata: 'metadata'
  5725. };
  5726. /**
  5727. * All possible `TextTrackMode`s
  5728. *
  5729. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#texttrackmode
  5730. * @typedef TextTrack~Mode
  5731. * @enum
  5732. */
  5733. var TextTrackMode = {
  5734. disabled: 'disabled',
  5735. hidden: 'hidden',
  5736. showing: 'showing'
  5737. };
  5738. /**
  5739. * @file track.js
  5740. */
  5741. /**
  5742. * A Track class that contains all of the common functionality for {@link AudioTrack},
  5743. * {@link VideoTrack}, and {@link TextTrack}.
  5744. *
  5745. * > Note: This class should not be used directly
  5746. *
  5747. * @see {@link https://html.spec.whatwg.org/multipage/embedded-content.html}
  5748. * @extends EventTarget
  5749. * @abstract
  5750. */
  5751. var Track = function (_EventTarget) {
  5752. inherits(Track, _EventTarget);
  5753. /**
  5754. * Create an instance of this class.
  5755. *
  5756. * @param {Object} [options={}]
  5757. * Object of option names and values
  5758. *
  5759. * @param {string} [options.kind='']
  5760. * A valid kind for the track type you are creating.
  5761. *
  5762. * @param {string} [options.id='vjs_track_' + Guid.newGUID()]
  5763. * A unique id for this AudioTrack.
  5764. *
  5765. * @param {string} [options.label='']
  5766. * The menu label for this track.
  5767. *
  5768. * @param {string} [options.language='']
  5769. * A valid two character language code.
  5770. *
  5771. * @abstract
  5772. */
  5773. function Track() {
  5774. var _ret;
  5775. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  5776. classCallCheck(this, Track);
  5777. var _this = possibleConstructorReturn(this, _EventTarget.call(this));
  5778. var track = _this; // eslint-disable-line
  5779. if (IS_IE8) {
  5780. track = document.createElement('custom');
  5781. for (var prop in Track.prototype) {
  5782. if (prop !== 'constructor') {
  5783. track[prop] = Track.prototype[prop];
  5784. }
  5785. }
  5786. }
  5787. var trackProps = {
  5788. id: options.id || 'vjs_track_' + newGUID(),
  5789. kind: options.kind || '',
  5790. label: options.label || '',
  5791. language: options.language || ''
  5792. };
  5793. /**
  5794. * @memberof Track
  5795. * @member {string} id
  5796. * The id of this track. Cannot be changed after creation.
  5797. * @instance
  5798. *
  5799. * @readonly
  5800. */
  5801. /**
  5802. * @memberof Track
  5803. * @member {string} kind
  5804. * The kind of track that this is. Cannot be changed after creation.
  5805. * @instance
  5806. *
  5807. * @readonly
  5808. */
  5809. /**
  5810. * @memberof Track
  5811. * @member {string} label
  5812. * The label of this track. Cannot be changed after creation.
  5813. * @instance
  5814. *
  5815. * @readonly
  5816. */
  5817. /**
  5818. * @memberof Track
  5819. * @member {string} language
  5820. * The two letter language code for this track. Cannot be changed after
  5821. * creation.
  5822. * @instance
  5823. *
  5824. * @readonly
  5825. */
  5826. var _loop = function _loop(key) {
  5827. Object.defineProperty(track, key, {
  5828. get: function get$$1() {
  5829. return trackProps[key];
  5830. },
  5831. set: function set$$1() {}
  5832. });
  5833. };
  5834. for (var key in trackProps) {
  5835. _loop(key);
  5836. }
  5837. return _ret = track, possibleConstructorReturn(_this, _ret);
  5838. }
  5839. return Track;
  5840. }(EventTarget);
  5841. /**
  5842. * @file url.js
  5843. * @module url
  5844. */
  5845. /**
  5846. * @typedef {Object} url:URLObject
  5847. *
  5848. * @property {string} protocol
  5849. * The protocol of the url that was parsed.
  5850. *
  5851. * @property {string} hostname
  5852. * The hostname of the url that was parsed.
  5853. *
  5854. * @property {string} port
  5855. * The port of the url that was parsed.
  5856. *
  5857. * @property {string} pathname
  5858. * The pathname of the url that was parsed.
  5859. *
  5860. * @property {string} search
  5861. * The search query of the url that was parsed.
  5862. *
  5863. * @property {string} hash
  5864. * The hash of the url that was parsed.
  5865. *
  5866. * @property {string} host
  5867. * The host of the url that was parsed.
  5868. */
  5869. /**
  5870. * Resolve and parse the elements of a URL.
  5871. *
  5872. * @param {String} url
  5873. * The url to parse
  5874. *
  5875. * @return {url:URLObject}
  5876. * An object of url details
  5877. */
  5878. var parseUrl = function parseUrl(url) {
  5879. var props = ['protocol', 'hostname', 'port', 'pathname', 'search', 'hash', 'host'];
  5880. // add the url to an anchor and let the browser parse the URL
  5881. var a = document.createElement('a');
  5882. a.href = url;
  5883. // IE8 (and 9?) Fix
  5884. // ie8 doesn't parse the URL correctly until the anchor is actually
  5885. // added to the body, and an innerHTML is needed to trigger the parsing
  5886. var addToBody = a.host === '' && a.protocol !== 'file:';
  5887. var div = void 0;
  5888. if (addToBody) {
  5889. div = document.createElement('div');
  5890. div.innerHTML = '<a href="' + url + '"></a>';
  5891. a = div.firstChild;
  5892. // prevent the div from affecting layout
  5893. div.setAttribute('style', 'display:none; position:absolute;');
  5894. document.body.appendChild(div);
  5895. }
  5896. // Copy the specific URL properties to a new object
  5897. // This is also needed for IE8 because the anchor loses its
  5898. // properties when it's removed from the dom
  5899. var details = {};
  5900. for (var i = 0; i < props.length; i++) {
  5901. details[props[i]] = a[props[i]];
  5902. }
  5903. // IE9 adds the port to the host property unlike everyone else. If
  5904. // a port identifier is added for standard ports, strip it.
  5905. if (details.protocol === 'http:') {
  5906. details.host = details.host.replace(/:80$/, '');
  5907. }
  5908. if (details.protocol === 'https:') {
  5909. details.host = details.host.replace(/:443$/, '');
  5910. }
  5911. if (!details.protocol) {
  5912. details.protocol = window.location.protocol;
  5913. }
  5914. if (addToBody) {
  5915. document.body.removeChild(div);
  5916. }
  5917. return details;
  5918. };
  5919. /**
  5920. * Get absolute version of relative URL. Used to tell flash correct URL.
  5921. *
  5922. *
  5923. * @param {string} url
  5924. * URL to make absolute
  5925. *
  5926. * @return {string}
  5927. * Absolute URL
  5928. *
  5929. * @see http://stackoverflow.com/questions/470832/getting-an-absolute-url-from-a-relative-one-ie6-issue
  5930. */
  5931. var getAbsoluteURL = function getAbsoluteURL(url) {
  5932. // Check if absolute URL
  5933. if (!url.match(/^https?:\/\//)) {
  5934. // Convert to absolute URL. Flash hosted off-site needs an absolute URL.
  5935. var div = document.createElement('div');
  5936. div.innerHTML = '<a href="' + url + '">x</a>';
  5937. url = div.firstChild.href;
  5938. }
  5939. return url;
  5940. };
  5941. /**
  5942. * Returns the extension of the passed file name. It will return an empty string
  5943. * if passed an invalid path.
  5944. *
  5945. * @param {string} path
  5946. * The fileName path like '/path/to/file.mp4'
  5947. *
  5948. * @returns {string}
  5949. * The extension in lower case or an empty string if no
  5950. * extension could be found.
  5951. */
  5952. var getFileExtension = function getFileExtension(path) {
  5953. if (typeof path === 'string') {
  5954. var splitPathRe = /^(\/?)([\s\S]*?)((?:\.{1,2}|[^\/]+?)(\.([^\.\/\?]+)))(?:[\/]*|[\?].*)$/i;
  5955. var pathParts = splitPathRe.exec(path);
  5956. if (pathParts) {
  5957. return pathParts.pop().toLowerCase();
  5958. }
  5959. }
  5960. return '';
  5961. };
  5962. /**
  5963. * Returns whether the url passed is a cross domain request or not.
  5964. *
  5965. * @param {string} url
  5966. * The url to check.
  5967. *
  5968. * @return {boolean}
  5969. * Whether it is a cross domain request or not.
  5970. */
  5971. var isCrossOrigin = function isCrossOrigin(url) {
  5972. var winLoc = window.location;
  5973. var urlInfo = parseUrl(url);
  5974. // IE8 protocol relative urls will return ':' for protocol
  5975. var srcProtocol = urlInfo.protocol === ':' ? winLoc.protocol : urlInfo.protocol;
  5976. // Check if url is for another domain/origin
  5977. // IE8 doesn't know location.origin, so we won't rely on it here
  5978. var crossOrigin = srcProtocol + urlInfo.host !== winLoc.protocol + winLoc.host;
  5979. return crossOrigin;
  5980. };
  5981. var Url = (Object.freeze || Object)({
  5982. parseUrl: parseUrl,
  5983. getAbsoluteURL: getAbsoluteURL,
  5984. getFileExtension: getFileExtension,
  5985. isCrossOrigin: isCrossOrigin
  5986. });
  5987. /**
  5988. * @file text-track.js
  5989. */
  5990. /**
  5991. * Takes a webvtt file contents and parses it into cues
  5992. *
  5993. * @param {string} srcContent
  5994. * webVTT file contents
  5995. *
  5996. * @param {TextTrack} track
  5997. * TextTrack to add cues to. Cues come from the srcContent.
  5998. *
  5999. * @private
  6000. */
  6001. var parseCues = function parseCues(srcContent, track) {
  6002. var parser = new window.WebVTT.Parser(window, window.vttjs, window.WebVTT.StringDecoder());
  6003. var errors = [];
  6004. parser.oncue = function (cue) {
  6005. track.addCue(cue);
  6006. };
  6007. parser.onparsingerror = function (error) {
  6008. errors.push(error);
  6009. };
  6010. parser.onflush = function () {
  6011. track.trigger({
  6012. type: 'loadeddata',
  6013. target: track
  6014. });
  6015. };
  6016. parser.parse(srcContent);
  6017. if (errors.length > 0) {
  6018. if (window.console && window.console.groupCollapsed) {
  6019. window.console.groupCollapsed('Text Track parsing errors for ' + track.src);
  6020. }
  6021. errors.forEach(function (error) {
  6022. return log.error(error);
  6023. });
  6024. if (window.console && window.console.groupEnd) {
  6025. window.console.groupEnd();
  6026. }
  6027. }
  6028. parser.flush();
  6029. };
  6030. /**
  6031. * Load a `TextTrack` from a specifed url.
  6032. *
  6033. * @param {string} src
  6034. * Url to load track from.
  6035. *
  6036. * @param {TextTrack} track
  6037. * Track to add cues to. Comes from the content at the end of `url`.
  6038. *
  6039. * @private
  6040. */
  6041. var loadTrack = function loadTrack(src, track) {
  6042. var opts = {
  6043. uri: src
  6044. };
  6045. var crossOrigin = isCrossOrigin(src);
  6046. if (crossOrigin) {
  6047. opts.cors = crossOrigin;
  6048. }
  6049. xhr(opts, bind(this, function (err, response, responseBody) {
  6050. if (err) {
  6051. return log.error(err, response);
  6052. }
  6053. track.loaded_ = true;
  6054. // Make sure that vttjs has loaded, otherwise, wait till it finished loading
  6055. // NOTE: this is only used for the alt/video.novtt.js build
  6056. if (typeof window.WebVTT !== 'function') {
  6057. if (track.tech_) {
  6058. var loadHandler = function loadHandler() {
  6059. return parseCues(responseBody, track);
  6060. };
  6061. track.tech_.on('vttjsloaded', loadHandler);
  6062. track.tech_.on('vttjserror', function () {
  6063. log.error('vttjs failed to load, stopping trying to process ' + track.src);
  6064. track.tech_.off('vttjsloaded', loadHandler);
  6065. });
  6066. }
  6067. } else {
  6068. parseCues(responseBody, track);
  6069. }
  6070. }));
  6071. };
  6072. /**
  6073. * A representation of a single `TextTrack`.
  6074. *
  6075. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#texttrack}
  6076. * @extends Track
  6077. */
  6078. var TextTrack = function (_Track) {
  6079. inherits(TextTrack, _Track);
  6080. /**
  6081. * Create an instance of this class.
  6082. *
  6083. * @param {Object} options={}
  6084. * Object of option names and values
  6085. *
  6086. * @param {Tech} options.tech
  6087. * A reference to the tech that owns this TextTrack.
  6088. *
  6089. * @param {TextTrack~Kind} [options.kind='subtitles']
  6090. * A valid text track kind.
  6091. *
  6092. * @param {TextTrack~Mode} [options.mode='disabled']
  6093. * A valid text track mode.
  6094. *
  6095. * @param {string} [options.id='vjs_track_' + Guid.newGUID()]
  6096. * A unique id for this TextTrack.
  6097. *
  6098. * @param {string} [options.label='']
  6099. * The menu label for this track.
  6100. *
  6101. * @param {string} [options.language='']
  6102. * A valid two character language code.
  6103. *
  6104. * @param {string} [options.srclang='']
  6105. * A valid two character language code. An alternative, but deprioritized
  6106. * vesion of `options.language`
  6107. *
  6108. * @param {string} [options.src]
  6109. * A url to TextTrack cues.
  6110. *
  6111. * @param {boolean} [options.default]
  6112. * If this track should default to on or off.
  6113. */
  6114. function TextTrack() {
  6115. var _this, _ret;
  6116. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  6117. classCallCheck(this, TextTrack);
  6118. if (!options.tech) {
  6119. throw new Error('A tech was not provided.');
  6120. }
  6121. var settings = mergeOptions(options, {
  6122. kind: TextTrackKind[options.kind] || 'subtitles',
  6123. language: options.language || options.srclang || ''
  6124. });
  6125. var mode = TextTrackMode[settings.mode] || 'disabled';
  6126. var default_ = settings['default'];
  6127. if (settings.kind === 'metadata' || settings.kind === 'chapters') {
  6128. mode = 'hidden';
  6129. }
  6130. // on IE8 this will be a document element
  6131. // for every other browser this will be a normal object
  6132. var tt = (_this = possibleConstructorReturn(this, _Track.call(this, settings)), _this);
  6133. tt.tech_ = settings.tech;
  6134. if (IS_IE8) {
  6135. for (var prop in TextTrack.prototype) {
  6136. if (prop !== 'constructor') {
  6137. tt[prop] = TextTrack.prototype[prop];
  6138. }
  6139. }
  6140. }
  6141. tt.cues_ = [];
  6142. tt.activeCues_ = [];
  6143. var cues = new TextTrackCueList(tt.cues_);
  6144. var activeCues = new TextTrackCueList(tt.activeCues_);
  6145. var changed = false;
  6146. var timeupdateHandler = bind(tt, function () {
  6147. // Accessing this.activeCues for the side-effects of updating itself
  6148. // due to it's nature as a getter function. Do not remove or cues will
  6149. // stop updating!
  6150. // Use the setter to prevent deletion from uglify (pure_getters rule)
  6151. this.activeCues = this.activeCues;
  6152. if (changed) {
  6153. this.trigger('cuechange');
  6154. changed = false;
  6155. }
  6156. });
  6157. if (mode !== 'disabled') {
  6158. tt.tech_.ready(function () {
  6159. tt.tech_.on('timeupdate', timeupdateHandler);
  6160. }, true);
  6161. }
  6162. /**
  6163. * @memberof TextTrack
  6164. * @member {boolean} default
  6165. * If this track was set to be on or off by default. Cannot be changed after
  6166. * creation.
  6167. * @instance
  6168. *
  6169. * @readonly
  6170. */
  6171. Object.defineProperty(tt, 'default', {
  6172. get: function get$$1() {
  6173. return default_;
  6174. },
  6175. set: function set$$1() {}
  6176. });
  6177. /**
  6178. * @memberof TextTrack
  6179. * @member {string} mode
  6180. * Set the mode of this TextTrack to a valid {@link TextTrack~Mode}. Will
  6181. * not be set if setting to an invalid mode.
  6182. * @instance
  6183. *
  6184. * @fires TextTrack#modechange
  6185. */
  6186. Object.defineProperty(tt, 'mode', {
  6187. get: function get$$1() {
  6188. return mode;
  6189. },
  6190. set: function set$$1(newMode) {
  6191. var _this2 = this;
  6192. if (!TextTrackMode[newMode]) {
  6193. return;
  6194. }
  6195. mode = newMode;
  6196. if (mode !== 'disabled') {
  6197. this.tech_.ready(function () {
  6198. _this2.tech_.on('timeupdate', timeupdateHandler);
  6199. }, true);
  6200. } else {
  6201. this.tech_.off('timeupdate', timeupdateHandler);
  6202. }
  6203. /**
  6204. * An event that fires when mode changes on this track. This allows
  6205. * the TextTrackList that holds this track to act accordingly.
  6206. *
  6207. * > Note: This is not part of the spec!
  6208. *
  6209. * @event TextTrack#modechange
  6210. * @type {EventTarget~Event}
  6211. */
  6212. this.trigger('modechange');
  6213. }
  6214. });
  6215. /**
  6216. * @memberof TextTrack
  6217. * @member {TextTrackCueList} cues
  6218. * The text track cue list for this TextTrack.
  6219. * @instance
  6220. */
  6221. Object.defineProperty(tt, 'cues', {
  6222. get: function get$$1() {
  6223. if (!this.loaded_) {
  6224. return null;
  6225. }
  6226. return cues;
  6227. },
  6228. set: function set$$1() {}
  6229. });
  6230. /**
  6231. * @memberof TextTrack
  6232. * @member {TextTrackCueList} activeCues
  6233. * The list text track cues that are currently active for this TextTrack.
  6234. * @instance
  6235. */
  6236. Object.defineProperty(tt, 'activeCues', {
  6237. get: function get$$1() {
  6238. if (!this.loaded_) {
  6239. return null;
  6240. }
  6241. // nothing to do
  6242. if (this.cues.length === 0) {
  6243. return activeCues;
  6244. }
  6245. var ct = this.tech_.currentTime();
  6246. var active = [];
  6247. for (var i = 0, l = this.cues.length; i < l; i++) {
  6248. var cue = this.cues[i];
  6249. if (cue.startTime <= ct && cue.endTime >= ct) {
  6250. active.push(cue);
  6251. } else if (cue.startTime === cue.endTime && cue.startTime <= ct && cue.startTime + 0.5 >= ct) {
  6252. active.push(cue);
  6253. }
  6254. }
  6255. changed = false;
  6256. if (active.length !== this.activeCues_.length) {
  6257. changed = true;
  6258. } else {
  6259. for (var _i = 0; _i < active.length; _i++) {
  6260. if (this.activeCues_.indexOf(active[_i]) === -1) {
  6261. changed = true;
  6262. }
  6263. }
  6264. }
  6265. this.activeCues_ = active;
  6266. activeCues.setCues_(this.activeCues_);
  6267. return activeCues;
  6268. },
  6269. // /!\ Keep this setter empty (see the timeupdate handler above)
  6270. set: function set$$1() {}
  6271. });
  6272. if (settings.src) {
  6273. tt.src = settings.src;
  6274. loadTrack(settings.src, tt);
  6275. } else {
  6276. tt.loaded_ = true;
  6277. }
  6278. return _ret = tt, possibleConstructorReturn(_this, _ret);
  6279. }
  6280. /**
  6281. * Add a cue to the internal list of cues.
  6282. *
  6283. * @param {TextTrack~Cue} cue
  6284. * The cue to add to our internal list
  6285. */
  6286. TextTrack.prototype.addCue = function addCue(originalCue) {
  6287. var cue = originalCue;
  6288. if (window.vttjs && !(originalCue instanceof window.vttjs.VTTCue)) {
  6289. cue = new window.vttjs.VTTCue(originalCue.startTime, originalCue.endTime, originalCue.text);
  6290. for (var prop in originalCue) {
  6291. if (!(prop in cue)) {
  6292. cue[prop] = originalCue[prop];
  6293. }
  6294. }
  6295. // make sure that `id` is copied over
  6296. cue.id = originalCue.id;
  6297. cue.originalCue_ = originalCue;
  6298. }
  6299. var tracks = this.tech_.textTracks();
  6300. for (var i = 0; i < tracks.length; i++) {
  6301. if (tracks[i] !== this) {
  6302. tracks[i].removeCue(cue);
  6303. }
  6304. }
  6305. this.cues_.push(cue);
  6306. this.cues.setCues_(this.cues_);
  6307. };
  6308. /**
  6309. * Remove a cue from our internal list
  6310. *
  6311. * @param {TextTrack~Cue} removeCue
  6312. * The cue to remove from our internal list
  6313. */
  6314. TextTrack.prototype.removeCue = function removeCue(_removeCue) {
  6315. var i = this.cues_.length;
  6316. while (i--) {
  6317. var cue = this.cues_[i];
  6318. if (cue === _removeCue || cue.originalCue_ && cue.originalCue_ === _removeCue) {
  6319. this.cues_.splice(i, 1);
  6320. this.cues.setCues_(this.cues_);
  6321. break;
  6322. }
  6323. }
  6324. };
  6325. return TextTrack;
  6326. }(Track);
  6327. /**
  6328. * cuechange - One or more cues in the track have become active or stopped being active.
  6329. */
  6330. TextTrack.prototype.allowedEvents_ = {
  6331. cuechange: 'cuechange'
  6332. };
  6333. /**
  6334. * A representation of a single `AudioTrack`. If it is part of an {@link AudioTrackList}
  6335. * only one `AudioTrack` in the list will be enabled at a time.
  6336. *
  6337. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#audiotrack}
  6338. * @extends Track
  6339. */
  6340. var AudioTrack = function (_Track) {
  6341. inherits(AudioTrack, _Track);
  6342. /**
  6343. * Create an instance of this class.
  6344. *
  6345. * @param {Object} [options={}]
  6346. * Object of option names and values
  6347. *
  6348. * @param {AudioTrack~Kind} [options.kind='']
  6349. * A valid audio track kind
  6350. *
  6351. * @param {string} [options.id='vjs_track_' + Guid.newGUID()]
  6352. * A unique id for this AudioTrack.
  6353. *
  6354. * @param {string} [options.label='']
  6355. * The menu label for this track.
  6356. *
  6357. * @param {string} [options.language='']
  6358. * A valid two character language code.
  6359. *
  6360. * @param {boolean} [options.enabled]
  6361. * If this track is the one that is currently playing. If this track is part of
  6362. * an {@link AudioTrackList}, only one {@link AudioTrack} will be enabled.
  6363. */
  6364. function AudioTrack() {
  6365. var _this, _ret;
  6366. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  6367. classCallCheck(this, AudioTrack);
  6368. var settings = mergeOptions(options, {
  6369. kind: AudioTrackKind[options.kind] || ''
  6370. });
  6371. // on IE8 this will be a document element
  6372. // for every other browser this will be a normal object
  6373. var track = (_this = possibleConstructorReturn(this, _Track.call(this, settings)), _this);
  6374. var enabled = false;
  6375. if (IS_IE8) {
  6376. for (var prop in AudioTrack.prototype) {
  6377. if (prop !== 'constructor') {
  6378. track[prop] = AudioTrack.prototype[prop];
  6379. }
  6380. }
  6381. }
  6382. /**
  6383. * @memberof AudioTrack
  6384. * @member {boolean} enabled
  6385. * If this `AudioTrack` is enabled or not. When setting this will
  6386. * fire {@link AudioTrack#enabledchange} if the state of enabled is changed.
  6387. * @instance
  6388. *
  6389. * @fires VideoTrack#selectedchange
  6390. */
  6391. Object.defineProperty(track, 'enabled', {
  6392. get: function get$$1() {
  6393. return enabled;
  6394. },
  6395. set: function set$$1(newEnabled) {
  6396. // an invalid or unchanged value
  6397. if (typeof newEnabled !== 'boolean' || newEnabled === enabled) {
  6398. return;
  6399. }
  6400. enabled = newEnabled;
  6401. /**
  6402. * An event that fires when enabled changes on this track. This allows
  6403. * the AudioTrackList that holds this track to act accordingly.
  6404. *
  6405. * > Note: This is not part of the spec! Native tracks will do
  6406. * this internally without an event.
  6407. *
  6408. * @event AudioTrack#enabledchange
  6409. * @type {EventTarget~Event}
  6410. */
  6411. this.trigger('enabledchange');
  6412. }
  6413. });
  6414. // if the user sets this track to selected then
  6415. // set selected to that true value otherwise
  6416. // we keep it false
  6417. if (settings.enabled) {
  6418. track.enabled = settings.enabled;
  6419. }
  6420. track.loaded_ = true;
  6421. return _ret = track, possibleConstructorReturn(_this, _ret);
  6422. }
  6423. return AudioTrack;
  6424. }(Track);
  6425. /**
  6426. * A representation of a single `VideoTrack`.
  6427. *
  6428. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#videotrack}
  6429. * @extends Track
  6430. */
  6431. var VideoTrack = function (_Track) {
  6432. inherits(VideoTrack, _Track);
  6433. /**
  6434. * Create an instance of this class.
  6435. *
  6436. * @param {Object} [options={}]
  6437. * Object of option names and values
  6438. *
  6439. * @param {string} [options.kind='']
  6440. * A valid {@link VideoTrack~Kind}
  6441. *
  6442. * @param {string} [options.id='vjs_track_' + Guid.newGUID()]
  6443. * A unique id for this AudioTrack.
  6444. *
  6445. * @param {string} [options.label='']
  6446. * The menu label for this track.
  6447. *
  6448. * @param {string} [options.language='']
  6449. * A valid two character language code.
  6450. *
  6451. * @param {boolean} [options.selected]
  6452. * If this track is the one that is currently playing.
  6453. */
  6454. function VideoTrack() {
  6455. var _this, _ret;
  6456. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  6457. classCallCheck(this, VideoTrack);
  6458. var settings = mergeOptions(options, {
  6459. kind: VideoTrackKind[options.kind] || ''
  6460. });
  6461. // on IE8 this will be a document element
  6462. // for every other browser this will be a normal object
  6463. var track = (_this = possibleConstructorReturn(this, _Track.call(this, settings)), _this);
  6464. var selected = false;
  6465. if (IS_IE8) {
  6466. for (var prop in VideoTrack.prototype) {
  6467. if (prop !== 'constructor') {
  6468. track[prop] = VideoTrack.prototype[prop];
  6469. }
  6470. }
  6471. }
  6472. /**
  6473. * @memberof VideoTrack
  6474. * @member {boolean} selected
  6475. * If this `VideoTrack` is selected or not. When setting this will
  6476. * fire {@link VideoTrack#selectedchange} if the state of selected changed.
  6477. * @instance
  6478. *
  6479. * @fires VideoTrack#selectedchange
  6480. */
  6481. Object.defineProperty(track, 'selected', {
  6482. get: function get$$1() {
  6483. return selected;
  6484. },
  6485. set: function set$$1(newSelected) {
  6486. // an invalid or unchanged value
  6487. if (typeof newSelected !== 'boolean' || newSelected === selected) {
  6488. return;
  6489. }
  6490. selected = newSelected;
  6491. /**
  6492. * An event that fires when selected changes on this track. This allows
  6493. * the VideoTrackList that holds this track to act accordingly.
  6494. *
  6495. * > Note: This is not part of the spec! Native tracks will do
  6496. * this internally without an event.
  6497. *
  6498. * @event VideoTrack#selectedchange
  6499. * @type {EventTarget~Event}
  6500. */
  6501. this.trigger('selectedchange');
  6502. }
  6503. });
  6504. // if the user sets this track to selected then
  6505. // set selected to that true value otherwise
  6506. // we keep it false
  6507. if (settings.selected) {
  6508. track.selected = settings.selected;
  6509. }
  6510. return _ret = track, possibleConstructorReturn(_this, _ret);
  6511. }
  6512. return VideoTrack;
  6513. }(Track);
  6514. /**
  6515. * @file html-track-element.js
  6516. */
  6517. /**
  6518. * @memberof HTMLTrackElement
  6519. * @typedef {HTMLTrackElement~ReadyState}
  6520. * @enum {number}
  6521. */
  6522. var NONE = 0;
  6523. var LOADING = 1;
  6524. var LOADED = 2;
  6525. var ERROR = 3;
  6526. /**
  6527. * A single track represented in the DOM.
  6528. *
  6529. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#htmltrackelement}
  6530. * @extends EventTarget
  6531. */
  6532. var HTMLTrackElement = function (_EventTarget) {
  6533. inherits(HTMLTrackElement, _EventTarget);
  6534. /**
  6535. * Create an instance of this class.
  6536. *
  6537. * @param {Object} options={}
  6538. * Object of option names and values
  6539. *
  6540. * @param {Tech} options.tech
  6541. * A reference to the tech that owns this HTMLTrackElement.
  6542. *
  6543. * @param {TextTrack~Kind} [options.kind='subtitles']
  6544. * A valid text track kind.
  6545. *
  6546. * @param {TextTrack~Mode} [options.mode='disabled']
  6547. * A valid text track mode.
  6548. *
  6549. * @param {string} [options.id='vjs_track_' + Guid.newGUID()]
  6550. * A unique id for this TextTrack.
  6551. *
  6552. * @param {string} [options.label='']
  6553. * The menu label for this track.
  6554. *
  6555. * @param {string} [options.language='']
  6556. * A valid two character language code.
  6557. *
  6558. * @param {string} [options.srclang='']
  6559. * A valid two character language code. An alternative, but deprioritized
  6560. * vesion of `options.language`
  6561. *
  6562. * @param {string} [options.src]
  6563. * A url to TextTrack cues.
  6564. *
  6565. * @param {boolean} [options.default]
  6566. * If this track should default to on or off.
  6567. */
  6568. function HTMLTrackElement() {
  6569. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  6570. classCallCheck(this, HTMLTrackElement);
  6571. var _this = possibleConstructorReturn(this, _EventTarget.call(this));
  6572. var readyState = void 0;
  6573. var trackElement = _this; // eslint-disable-line
  6574. if (IS_IE8) {
  6575. trackElement = document.createElement('custom');
  6576. for (var prop in HTMLTrackElement.prototype) {
  6577. if (prop !== 'constructor') {
  6578. trackElement[prop] = HTMLTrackElement.prototype[prop];
  6579. }
  6580. }
  6581. }
  6582. var track = new TextTrack(options);
  6583. trackElement.kind = track.kind;
  6584. trackElement.src = track.src;
  6585. trackElement.srclang = track.language;
  6586. trackElement.label = track.label;
  6587. trackElement['default'] = track['default'];
  6588. /**
  6589. * @memberof HTMLTrackElement
  6590. * @member {HTMLTrackElement~ReadyState} readyState
  6591. * The current ready state of the track element.
  6592. * @instance
  6593. */
  6594. Object.defineProperty(trackElement, 'readyState', {
  6595. get: function get$$1() {
  6596. return readyState;
  6597. }
  6598. });
  6599. /**
  6600. * @memberof HTMLTrackElement
  6601. * @member {TextTrack} track
  6602. * The underlying TextTrack object.
  6603. * @instance
  6604. *
  6605. */
  6606. Object.defineProperty(trackElement, 'track', {
  6607. get: function get$$1() {
  6608. return track;
  6609. }
  6610. });
  6611. readyState = NONE;
  6612. /**
  6613. * @listens TextTrack#loadeddata
  6614. * @fires HTMLTrackElement#load
  6615. */
  6616. track.addEventListener('loadeddata', function () {
  6617. readyState = LOADED;
  6618. trackElement.trigger({
  6619. type: 'load',
  6620. target: trackElement
  6621. });
  6622. });
  6623. if (IS_IE8) {
  6624. var _ret;
  6625. return _ret = trackElement, possibleConstructorReturn(_this, _ret);
  6626. }
  6627. return _this;
  6628. }
  6629. return HTMLTrackElement;
  6630. }(EventTarget);
  6631. HTMLTrackElement.prototype.allowedEvents_ = {
  6632. load: 'load'
  6633. };
  6634. HTMLTrackElement.NONE = NONE;
  6635. HTMLTrackElement.LOADING = LOADING;
  6636. HTMLTrackElement.LOADED = LOADED;
  6637. HTMLTrackElement.ERROR = ERROR;
  6638. /*
  6639. * This file contains all track properties that are used in
  6640. * player.js, tech.js, html5.js and possibly other techs in the future.
  6641. */
  6642. var NORMAL = {
  6643. audio: {
  6644. ListClass: AudioTrackList,
  6645. TrackClass: AudioTrack,
  6646. capitalName: 'Audio'
  6647. },
  6648. video: {
  6649. ListClass: VideoTrackList,
  6650. TrackClass: VideoTrack,
  6651. capitalName: 'Video'
  6652. },
  6653. text: {
  6654. ListClass: TextTrackList,
  6655. TrackClass: TextTrack,
  6656. capitalName: 'Text'
  6657. }
  6658. };
  6659. Object.keys(NORMAL).forEach(function (type) {
  6660. NORMAL[type].getterName = type + 'Tracks';
  6661. NORMAL[type].privateName = type + 'Tracks_';
  6662. });
  6663. var REMOTE = {
  6664. remoteText: {
  6665. ListClass: TextTrackList,
  6666. TrackClass: TextTrack,
  6667. capitalName: 'RemoteText',
  6668. getterName: 'remoteTextTracks',
  6669. privateName: 'remoteTextTracks_'
  6670. },
  6671. remoteTextEl: {
  6672. ListClass: HtmlTrackElementList,
  6673. TrackClass: HTMLTrackElement,
  6674. capitalName: 'RemoteTextTrackEls',
  6675. getterName: 'remoteTextTrackEls',
  6676. privateName: 'remoteTextTrackEls_'
  6677. }
  6678. };
  6679. var ALL = mergeOptions(NORMAL, REMOTE);
  6680. REMOTE.names = Object.keys(REMOTE);
  6681. NORMAL.names = Object.keys(NORMAL);
  6682. ALL.names = [].concat(REMOTE.names).concat(NORMAL.names);
  6683. /**
  6684. * @file tech.js
  6685. */
  6686. /**
  6687. * An Object containing a structure like: `{src: 'url', type: 'mimetype'}` or string
  6688. * that just contains the src url alone.
  6689. * * `var SourceObject = {src: 'http://ex.com/video.mp4', type: 'video/mp4'};`
  6690. * `var SourceString = 'http://example.com/some-video.mp4';`
  6691. *
  6692. * @typedef {Object|string} Tech~SourceObject
  6693. *
  6694. * @property {string} src
  6695. * The url to the source
  6696. *
  6697. * @property {string} type
  6698. * The mime type of the source
  6699. */
  6700. /**
  6701. * A function used by {@link Tech} to create a new {@link TextTrack}.
  6702. *
  6703. * @private
  6704. *
  6705. * @param {Tech} self
  6706. * An instance of the Tech class.
  6707. *
  6708. * @param {string} kind
  6709. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata)
  6710. *
  6711. * @param {string} [label]
  6712. * Label to identify the text track
  6713. *
  6714. * @param {string} [language]
  6715. * Two letter language abbreviation
  6716. *
  6717. * @param {Object} [options={}]
  6718. * An object with additional text track options
  6719. *
  6720. * @return {TextTrack}
  6721. * The text track that was created.
  6722. */
  6723. function createTrackHelper(self, kind, label, language) {
  6724. var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
  6725. var tracks = self.textTracks();
  6726. options.kind = kind;
  6727. if (label) {
  6728. options.label = label;
  6729. }
  6730. if (language) {
  6731. options.language = language;
  6732. }
  6733. options.tech = self;
  6734. var track = new ALL.text.TrackClass(options);
  6735. tracks.addTrack(track);
  6736. return track;
  6737. }
  6738. /**
  6739. * This is the base class for media playback technology controllers, such as
  6740. * {@link Flash} and {@link HTML5}
  6741. *
  6742. * @extends Component
  6743. */
  6744. var Tech = function (_Component) {
  6745. inherits(Tech, _Component);
  6746. /**
  6747. * Create an instance of this Tech.
  6748. *
  6749. * @param {Object} [options]
  6750. * The key/value store of player options.
  6751. *
  6752. * @param {Component~ReadyCallback} ready
  6753. * Callback function to call when the `HTML5` Tech is ready.
  6754. */
  6755. function Tech() {
  6756. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  6757. var ready = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};
  6758. classCallCheck(this, Tech);
  6759. // we don't want the tech to report user activity automatically.
  6760. // This is done manually in addControlsListeners
  6761. options.reportTouchActivity = false;
  6762. // keep track of whether the current source has played at all to
  6763. // implement a very limited played()
  6764. var _this = possibleConstructorReturn(this, _Component.call(this, null, options, ready));
  6765. _this.hasStarted_ = false;
  6766. _this.on('playing', function () {
  6767. this.hasStarted_ = true;
  6768. });
  6769. _this.on('loadstart', function () {
  6770. this.hasStarted_ = false;
  6771. });
  6772. ALL.names.forEach(function (name) {
  6773. var props = ALL[name];
  6774. if (options && options[props.getterName]) {
  6775. _this[props.privateName] = options[props.getterName];
  6776. }
  6777. });
  6778. // Manually track progress in cases where the browser/flash player doesn't report it.
  6779. if (!_this.featuresProgressEvents) {
  6780. _this.manualProgressOn();
  6781. }
  6782. // Manually track timeupdates in cases where the browser/flash player doesn't report it.
  6783. if (!_this.featuresTimeupdateEvents) {
  6784. _this.manualTimeUpdatesOn();
  6785. }
  6786. ['Text', 'Audio', 'Video'].forEach(function (track) {
  6787. if (options['native' + track + 'Tracks'] === false) {
  6788. _this['featuresNative' + track + 'Tracks'] = false;
  6789. }
  6790. });
  6791. if (options.nativeCaptions === false || options.nativeTextTracks === false) {
  6792. _this.featuresNativeTextTracks = false;
  6793. } else if (options.nativeCaptions === true || options.nativeTextTracks === true) {
  6794. _this.featuresNativeTextTracks = true;
  6795. }
  6796. if (!_this.featuresNativeTextTracks) {
  6797. _this.emulateTextTracks();
  6798. }
  6799. _this.autoRemoteTextTracks_ = new ALL.text.ListClass();
  6800. _this.initTrackListeners();
  6801. // Turn on component tap events only if not using native controls
  6802. if (!options.nativeControlsForTouch) {
  6803. _this.emitTapEvents();
  6804. }
  6805. if (_this.constructor) {
  6806. _this.name_ = _this.constructor.name || 'Unknown Tech';
  6807. }
  6808. return _this;
  6809. }
  6810. /**
  6811. * A special function to trigger source set in a way that will allow player
  6812. * to re-trigger if the player or tech are not ready yet.
  6813. *
  6814. * @fires Tech#sourceset
  6815. * @param {string} src The source string at the time of the source changing.
  6816. */
  6817. Tech.prototype.triggerSourceset = function triggerSourceset(src) {
  6818. var _this2 = this;
  6819. if (!this.isReady_) {
  6820. // on initial ready we have to trigger source set
  6821. // 1ms after ready so that player can watch for it.
  6822. this.one('ready', function () {
  6823. return _this2.setTimeout(function () {
  6824. return _this2.triggerSourceset(src);
  6825. }, 1);
  6826. });
  6827. }
  6828. /**
  6829. * Fired when the source is set on the tech causing the media element
  6830. * to reload.
  6831. *
  6832. * @see {@link Player#event:sourceset}
  6833. * @event Tech#sourceset
  6834. * @type {EventTarget~Event}
  6835. */
  6836. this.trigger({
  6837. src: src,
  6838. type: 'sourceset'
  6839. });
  6840. };
  6841. /* Fallbacks for unsupported event types
  6842. ================================================================================ */
  6843. /**
  6844. * Polyfill the `progress` event for browsers that don't support it natively.
  6845. *
  6846. * @see {@link Tech#trackProgress}
  6847. */
  6848. Tech.prototype.manualProgressOn = function manualProgressOn() {
  6849. this.on('durationchange', this.onDurationChange);
  6850. this.manualProgress = true;
  6851. // Trigger progress watching when a source begins loading
  6852. this.one('ready', this.trackProgress);
  6853. };
  6854. /**
  6855. * Turn off the polyfill for `progress` events that was created in
  6856. * {@link Tech#manualProgressOn}
  6857. */
  6858. Tech.prototype.manualProgressOff = function manualProgressOff() {
  6859. this.manualProgress = false;
  6860. this.stopTrackingProgress();
  6861. this.off('durationchange', this.onDurationChange);
  6862. };
  6863. /**
  6864. * This is used to trigger a `progress` event when the buffered percent changes. It
  6865. * sets an interval function that will be called every 500 milliseconds to check if the
  6866. * buffer end percent has changed.
  6867. *
  6868. * > This function is called by {@link Tech#manualProgressOn}
  6869. *
  6870. * @param {EventTarget~Event} event
  6871. * The `ready` event that caused this to run.
  6872. *
  6873. * @listens Tech#ready
  6874. * @fires Tech#progress
  6875. */
  6876. Tech.prototype.trackProgress = function trackProgress(event) {
  6877. this.stopTrackingProgress();
  6878. this.progressInterval = this.setInterval(bind(this, function () {
  6879. // Don't trigger unless buffered amount is greater than last time
  6880. var numBufferedPercent = this.bufferedPercent();
  6881. if (this.bufferedPercent_ !== numBufferedPercent) {
  6882. /**
  6883. * See {@link Player#progress}
  6884. *
  6885. * @event Tech#progress
  6886. * @type {EventTarget~Event}
  6887. */
  6888. this.trigger('progress');
  6889. }
  6890. this.bufferedPercent_ = numBufferedPercent;
  6891. if (numBufferedPercent === 1) {
  6892. this.stopTrackingProgress();
  6893. }
  6894. }), 500);
  6895. };
  6896. /**
  6897. * Update our internal duration on a `durationchange` event by calling
  6898. * {@link Tech#duration}.
  6899. *
  6900. * @param {EventTarget~Event} event
  6901. * The `durationchange` event that caused this to run.
  6902. *
  6903. * @listens Tech#durationchange
  6904. */
  6905. Tech.prototype.onDurationChange = function onDurationChange(event) {
  6906. this.duration_ = this.duration();
  6907. };
  6908. /**
  6909. * Get and create a `TimeRange` object for buffering.
  6910. *
  6911. * @return {TimeRange}
  6912. * The time range object that was created.
  6913. */
  6914. Tech.prototype.buffered = function buffered() {
  6915. return createTimeRanges(0, 0);
  6916. };
  6917. /**
  6918. * Get the percentage of the current video that is currently buffered.
  6919. *
  6920. * @return {number}
  6921. * A number from 0 to 1 that represents the decimal percentage of the
  6922. * video that is buffered.
  6923. *
  6924. */
  6925. Tech.prototype.bufferedPercent = function bufferedPercent$$1() {
  6926. return bufferedPercent(this.buffered(), this.duration_);
  6927. };
  6928. /**
  6929. * Turn off the polyfill for `progress` events that was created in
  6930. * {@link Tech#manualProgressOn}
  6931. * Stop manually tracking progress events by clearing the interval that was set in
  6932. * {@link Tech#trackProgress}.
  6933. */
  6934. Tech.prototype.stopTrackingProgress = function stopTrackingProgress() {
  6935. this.clearInterval(this.progressInterval);
  6936. };
  6937. /**
  6938. * Polyfill the `timeupdate` event for browsers that don't support it.
  6939. *
  6940. * @see {@link Tech#trackCurrentTime}
  6941. */
  6942. Tech.prototype.manualTimeUpdatesOn = function manualTimeUpdatesOn() {
  6943. this.manualTimeUpdates = true;
  6944. this.on('play', this.trackCurrentTime);
  6945. this.on('pause', this.stopTrackingCurrentTime);
  6946. };
  6947. /**
  6948. * Turn off the polyfill for `timeupdate` events that was created in
  6949. * {@link Tech#manualTimeUpdatesOn}
  6950. */
  6951. Tech.prototype.manualTimeUpdatesOff = function manualTimeUpdatesOff() {
  6952. this.manualTimeUpdates = false;
  6953. this.stopTrackingCurrentTime();
  6954. this.off('play', this.trackCurrentTime);
  6955. this.off('pause', this.stopTrackingCurrentTime);
  6956. };
  6957. /**
  6958. * Sets up an interval function to track current time and trigger `timeupdate` every
  6959. * 250 milliseconds.
  6960. *
  6961. * @listens Tech#play
  6962. * @triggers Tech#timeupdate
  6963. */
  6964. Tech.prototype.trackCurrentTime = function trackCurrentTime() {
  6965. if (this.currentTimeInterval) {
  6966. this.stopTrackingCurrentTime();
  6967. }
  6968. this.currentTimeInterval = this.setInterval(function () {
  6969. /**
  6970. * Triggered at an interval of 250ms to indicated that time is passing in the video.
  6971. *
  6972. * @event Tech#timeupdate
  6973. * @type {EventTarget~Event}
  6974. */
  6975. this.trigger({ type: 'timeupdate', target: this, manuallyTriggered: true });
  6976. // 42 = 24 fps // 250 is what Webkit uses // FF uses 15
  6977. }, 250);
  6978. };
  6979. /**
  6980. * Stop the interval function created in {@link Tech#trackCurrentTime} so that the
  6981. * `timeupdate` event is no longer triggered.
  6982. *
  6983. * @listens {Tech#pause}
  6984. */
  6985. Tech.prototype.stopTrackingCurrentTime = function stopTrackingCurrentTime() {
  6986. this.clearInterval(this.currentTimeInterval);
  6987. // #1002 - if the video ends right before the next timeupdate would happen,
  6988. // the progress bar won't make it all the way to the end
  6989. this.trigger({ type: 'timeupdate', target: this, manuallyTriggered: true });
  6990. };
  6991. /**
  6992. * Turn off all event polyfills, clear the `Tech`s {@link AudioTrackList},
  6993. * {@link VideoTrackList}, and {@link TextTrackList}, and dispose of this Tech.
  6994. *
  6995. * @fires Component#dispose
  6996. */
  6997. Tech.prototype.dispose = function dispose() {
  6998. // clear out all tracks because we can't reuse them between techs
  6999. this.clearTracks(NORMAL.names);
  7000. // Turn off any manual progress or timeupdate tracking
  7001. if (this.manualProgress) {
  7002. this.manualProgressOff();
  7003. }
  7004. if (this.manualTimeUpdates) {
  7005. this.manualTimeUpdatesOff();
  7006. }
  7007. _Component.prototype.dispose.call(this);
  7008. };
  7009. /**
  7010. * Clear out a single `TrackList` or an array of `TrackLists` given their names.
  7011. *
  7012. * > Note: Techs without source handlers should call this between sources for `video`
  7013. * & `audio` tracks. You don't want to use them between tracks!
  7014. *
  7015. * @param {string[]|string} types
  7016. * TrackList names to clear, valid names are `video`, `audio`, and
  7017. * `text`.
  7018. */
  7019. Tech.prototype.clearTracks = function clearTracks(types) {
  7020. var _this3 = this;
  7021. types = [].concat(types);
  7022. // clear out all tracks because we can't reuse them between techs
  7023. types.forEach(function (type) {
  7024. var list = _this3[type + 'Tracks']() || [];
  7025. var i = list.length;
  7026. while (i--) {
  7027. var track = list[i];
  7028. if (type === 'text') {
  7029. _this3.removeRemoteTextTrack(track);
  7030. }
  7031. list.removeTrack(track);
  7032. }
  7033. });
  7034. };
  7035. /**
  7036. * Remove any TextTracks added via addRemoteTextTrack that are
  7037. * flagged for automatic garbage collection
  7038. */
  7039. Tech.prototype.cleanupAutoTextTracks = function cleanupAutoTextTracks() {
  7040. var list = this.autoRemoteTextTracks_ || [];
  7041. var i = list.length;
  7042. while (i--) {
  7043. var track = list[i];
  7044. this.removeRemoteTextTrack(track);
  7045. }
  7046. };
  7047. /**
  7048. * Reset the tech, which will removes all sources and reset the internal readyState.
  7049. *
  7050. * @abstract
  7051. */
  7052. Tech.prototype.reset = function reset() {};
  7053. /**
  7054. * Get or set an error on the Tech.
  7055. *
  7056. * @param {MediaError} [err]
  7057. * Error to set on the Tech
  7058. *
  7059. * @return {MediaError|null}
  7060. * The current error object on the tech, or null if there isn't one.
  7061. */
  7062. Tech.prototype.error = function error(err) {
  7063. if (err !== undefined) {
  7064. this.error_ = new MediaError(err);
  7065. this.trigger('error');
  7066. }
  7067. return this.error_;
  7068. };
  7069. /**
  7070. * Returns the `TimeRange`s that have been played through for the current source.
  7071. *
  7072. * > NOTE: This implementation is incomplete. It does not track the played `TimeRange`.
  7073. * It only checks wether the source has played at all or not.
  7074. *
  7075. * @return {TimeRange}
  7076. * - A single time range if this video has played
  7077. * - An empty set of ranges if not.
  7078. */
  7079. Tech.prototype.played = function played() {
  7080. if (this.hasStarted_) {
  7081. return createTimeRanges(0, 0);
  7082. }
  7083. return createTimeRanges();
  7084. };
  7085. /**
  7086. * Causes a manual time update to occur if {@link Tech#manualTimeUpdatesOn} was
  7087. * previously called.
  7088. *
  7089. * @fires Tech#timeupdate
  7090. */
  7091. Tech.prototype.setCurrentTime = function setCurrentTime() {
  7092. // improve the accuracy of manual timeupdates
  7093. if (this.manualTimeUpdates) {
  7094. /**
  7095. * A manual `timeupdate` event.
  7096. *
  7097. * @event Tech#timeupdate
  7098. * @type {EventTarget~Event}
  7099. */
  7100. this.trigger({ type: 'timeupdate', target: this, manuallyTriggered: true });
  7101. }
  7102. };
  7103. /**
  7104. * Turn on listeners for {@link VideoTrackList}, {@link {AudioTrackList}, and
  7105. * {@link TextTrackList} events.
  7106. *
  7107. * This adds {@link EventTarget~EventListeners} for `addtrack`, and `removetrack`.
  7108. *
  7109. * @fires Tech#audiotrackchange
  7110. * @fires Tech#videotrackchange
  7111. * @fires Tech#texttrackchange
  7112. */
  7113. Tech.prototype.initTrackListeners = function initTrackListeners() {
  7114. var _this4 = this;
  7115. /**
  7116. * Triggered when tracks are added or removed on the Tech {@link AudioTrackList}
  7117. *
  7118. * @event Tech#audiotrackchange
  7119. * @type {EventTarget~Event}
  7120. */
  7121. /**
  7122. * Triggered when tracks are added or removed on the Tech {@link VideoTrackList}
  7123. *
  7124. * @event Tech#videotrackchange
  7125. * @type {EventTarget~Event}
  7126. */
  7127. /**
  7128. * Triggered when tracks are added or removed on the Tech {@link TextTrackList}
  7129. *
  7130. * @event Tech#texttrackchange
  7131. * @type {EventTarget~Event}
  7132. */
  7133. NORMAL.names.forEach(function (name) {
  7134. var props = NORMAL[name];
  7135. var trackListChanges = function trackListChanges() {
  7136. _this4.trigger(name + 'trackchange');
  7137. };
  7138. var tracks = _this4[props.getterName]();
  7139. tracks.addEventListener('removetrack', trackListChanges);
  7140. tracks.addEventListener('addtrack', trackListChanges);
  7141. _this4.on('dispose', function () {
  7142. tracks.removeEventListener('removetrack', trackListChanges);
  7143. tracks.removeEventListener('addtrack', trackListChanges);
  7144. });
  7145. });
  7146. };
  7147. /**
  7148. * Emulate TextTracks using vtt.js if necessary
  7149. *
  7150. * @fires Tech#vttjsloaded
  7151. * @fires Tech#vttjserror
  7152. */
  7153. Tech.prototype.addWebVttScript_ = function addWebVttScript_() {
  7154. var _this5 = this;
  7155. if (window.WebVTT) {
  7156. return;
  7157. }
  7158. // Initially, Tech.el_ is a child of a dummy-div wait until the Component system
  7159. // signals that the Tech is ready at which point Tech.el_ is part of the DOM
  7160. // before inserting the WebVTT script
  7161. if (document.body.contains(this.el())) {
  7162. // load via require if available and vtt.js script location was not passed in
  7163. // as an option. novtt builds will turn the above require call into an empty object
  7164. // which will cause this if check to always fail.
  7165. if (!this.options_['vtt.js'] && isPlain(vtt) && Object.keys(vtt).length > 0) {
  7166. this.trigger('vttjsloaded');
  7167. return;
  7168. }
  7169. // load vtt.js via the script location option or the cdn of no location was
  7170. // passed in
  7171. var script = document.createElement('script');
  7172. script.src = this.options_['vtt.js'] || 'https://vjs.zencdn.net/vttjs/0.12.4/vtt.min.js';
  7173. script.onload = function () {
  7174. /**
  7175. * Fired when vtt.js is loaded.
  7176. *
  7177. * @event Tech#vttjsloaded
  7178. * @type {EventTarget~Event}
  7179. */
  7180. _this5.trigger('vttjsloaded');
  7181. };
  7182. script.onerror = function () {
  7183. /**
  7184. * Fired when vtt.js was not loaded due to an error
  7185. *
  7186. * @event Tech#vttjsloaded
  7187. * @type {EventTarget~Event}
  7188. */
  7189. _this5.trigger('vttjserror');
  7190. };
  7191. this.on('dispose', function () {
  7192. script.onload = null;
  7193. script.onerror = null;
  7194. });
  7195. // but have not loaded yet and we set it to true before the inject so that
  7196. // we don't overwrite the injected window.WebVTT if it loads right away
  7197. window.WebVTT = true;
  7198. this.el().parentNode.appendChild(script);
  7199. } else {
  7200. this.ready(this.addWebVttScript_);
  7201. }
  7202. };
  7203. /**
  7204. * Emulate texttracks
  7205. *
  7206. */
  7207. Tech.prototype.emulateTextTracks = function emulateTextTracks() {
  7208. var _this6 = this;
  7209. var tracks = this.textTracks();
  7210. var remoteTracks = this.remoteTextTracks();
  7211. var handleAddTrack = function handleAddTrack(e) {
  7212. return tracks.addTrack(e.track);
  7213. };
  7214. var handleRemoveTrack = function handleRemoveTrack(e) {
  7215. return tracks.removeTrack(e.track);
  7216. };
  7217. remoteTracks.on('addtrack', handleAddTrack);
  7218. remoteTracks.on('removetrack', handleRemoveTrack);
  7219. this.addWebVttScript_();
  7220. var updateDisplay = function updateDisplay() {
  7221. return _this6.trigger('texttrackchange');
  7222. };
  7223. var textTracksChanges = function textTracksChanges() {
  7224. updateDisplay();
  7225. for (var i = 0; i < tracks.length; i++) {
  7226. var track = tracks[i];
  7227. track.removeEventListener('cuechange', updateDisplay);
  7228. if (track.mode === 'showing') {
  7229. track.addEventListener('cuechange', updateDisplay);
  7230. }
  7231. }
  7232. };
  7233. textTracksChanges();
  7234. tracks.addEventListener('change', textTracksChanges);
  7235. tracks.addEventListener('addtrack', textTracksChanges);
  7236. tracks.addEventListener('removetrack', textTracksChanges);
  7237. this.on('dispose', function () {
  7238. remoteTracks.off('addtrack', handleAddTrack);
  7239. remoteTracks.off('removetrack', handleRemoveTrack);
  7240. tracks.removeEventListener('change', textTracksChanges);
  7241. tracks.removeEventListener('addtrack', textTracksChanges);
  7242. tracks.removeEventListener('removetrack', textTracksChanges);
  7243. for (var i = 0; i < tracks.length; i++) {
  7244. var track = tracks[i];
  7245. track.removeEventListener('cuechange', updateDisplay);
  7246. }
  7247. });
  7248. };
  7249. /**
  7250. * Create and returns a remote {@link TextTrack} object.
  7251. *
  7252. * @param {string} kind
  7253. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata)
  7254. *
  7255. * @param {string} [label]
  7256. * Label to identify the text track
  7257. *
  7258. * @param {string} [language]
  7259. * Two letter language abbreviation
  7260. *
  7261. * @return {TextTrack}
  7262. * The TextTrack that gets created.
  7263. */
  7264. Tech.prototype.addTextTrack = function addTextTrack(kind, label, language) {
  7265. if (!kind) {
  7266. throw new Error('TextTrack kind is required but was not provided');
  7267. }
  7268. return createTrackHelper(this, kind, label, language);
  7269. };
  7270. /**
  7271. * Create an emulated TextTrack for use by addRemoteTextTrack
  7272. *
  7273. * This is intended to be overridden by classes that inherit from
  7274. * Tech in order to create native or custom TextTracks.
  7275. *
  7276. * @param {Object} options
  7277. * The object should contain the options to initialize the TextTrack with.
  7278. *
  7279. * @param {string} [options.kind]
  7280. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata).
  7281. *
  7282. * @param {string} [options.label].
  7283. * Label to identify the text track
  7284. *
  7285. * @param {string} [options.language]
  7286. * Two letter language abbreviation.
  7287. *
  7288. * @return {HTMLTrackElement}
  7289. * The track element that gets created.
  7290. */
  7291. Tech.prototype.createRemoteTextTrack = function createRemoteTextTrack(options) {
  7292. var track = mergeOptions(options, {
  7293. tech: this
  7294. });
  7295. return new REMOTE.remoteTextEl.TrackClass(track);
  7296. };
  7297. /**
  7298. * Creates a remote text track object and returns an html track element.
  7299. *
  7300. * > Note: This can be an emulated {@link HTMLTrackElement} or a native one.
  7301. *
  7302. * @param {Object} options
  7303. * See {@link Tech#createRemoteTextTrack} for more detailed properties.
  7304. *
  7305. * @param {boolean} [manualCleanup=true]
  7306. * - When false: the TextTrack will be automatically removed from the video
  7307. * element whenever the source changes
  7308. * - When True: The TextTrack will have to be cleaned up manually
  7309. *
  7310. * @return {HTMLTrackElement}
  7311. * An Html Track Element.
  7312. *
  7313. * @deprecated The default functionality for this function will be equivalent
  7314. * to "manualCleanup=false" in the future. The manualCleanup parameter will
  7315. * also be removed.
  7316. */
  7317. Tech.prototype.addRemoteTextTrack = function addRemoteTextTrack() {
  7318. var _this7 = this;
  7319. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  7320. var manualCleanup = arguments[1];
  7321. var htmlTrackElement = this.createRemoteTextTrack(options);
  7322. if (manualCleanup !== true && manualCleanup !== false) {
  7323. // deprecation warning
  7324. log.warn('Calling addRemoteTextTrack without explicitly setting the "manualCleanup" parameter to `true` is deprecated and default to `false` in future version of video.js');
  7325. manualCleanup = true;
  7326. }
  7327. // store HTMLTrackElement and TextTrack to remote list
  7328. this.remoteTextTrackEls().addTrackElement_(htmlTrackElement);
  7329. this.remoteTextTracks().addTrack(htmlTrackElement.track);
  7330. if (manualCleanup !== true) {
  7331. // create the TextTrackList if it doesn't exist
  7332. this.ready(function () {
  7333. return _this7.autoRemoteTextTracks_.addTrack(htmlTrackElement.track);
  7334. });
  7335. }
  7336. return htmlTrackElement;
  7337. };
  7338. /**
  7339. * Remove a remote text track from the remote `TextTrackList`.
  7340. *
  7341. * @param {TextTrack} track
  7342. * `TextTrack` to remove from the `TextTrackList`
  7343. */
  7344. Tech.prototype.removeRemoteTextTrack = function removeRemoteTextTrack(track) {
  7345. var trackElement = this.remoteTextTrackEls().getTrackElementByTrack_(track);
  7346. // remove HTMLTrackElement and TextTrack from remote list
  7347. this.remoteTextTrackEls().removeTrackElement_(trackElement);
  7348. this.remoteTextTracks().removeTrack(track);
  7349. this.autoRemoteTextTracks_.removeTrack(track);
  7350. };
  7351. /**
  7352. * Gets available media playback quality metrics as specified by the W3C's Media
  7353. * Playback Quality API.
  7354. *
  7355. * @see [Spec]{@link https://wicg.github.io/media-playback-quality}
  7356. *
  7357. * @return {Object}
  7358. * An object with supported media playback quality metrics
  7359. *
  7360. * @abstract
  7361. */
  7362. Tech.prototype.getVideoPlaybackQuality = function getVideoPlaybackQuality() {
  7363. return {};
  7364. };
  7365. /**
  7366. * A method to set a poster from a `Tech`.
  7367. *
  7368. * @abstract
  7369. */
  7370. Tech.prototype.setPoster = function setPoster() {};
  7371. /**
  7372. * A method to check for the presence of the 'playsinine' <video> attribute.
  7373. *
  7374. * @abstract
  7375. */
  7376. Tech.prototype.playsinline = function playsinline() {};
  7377. /**
  7378. * A method to set or unset the 'playsinine' <video> attribute.
  7379. *
  7380. * @abstract
  7381. */
  7382. Tech.prototype.setPlaysinline = function setPlaysinline() {};
  7383. /*
  7384. * Check if the tech can support the given mime-type.
  7385. *
  7386. * The base tech does not support any type, but source handlers might
  7387. * overwrite this.
  7388. *
  7389. * @param {string} type
  7390. * The mimetype to check for support
  7391. *
  7392. * @return {string}
  7393. * 'probably', 'maybe', or empty string
  7394. *
  7395. * @see [Spec]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/canPlayType}
  7396. *
  7397. * @abstract
  7398. */
  7399. Tech.prototype.canPlayType = function canPlayType() {
  7400. return '';
  7401. };
  7402. /**
  7403. * Check if the type is supported by this tech.
  7404. *
  7405. * The base tech does not support any type, but source handlers might
  7406. * overwrite this.
  7407. *
  7408. * @param {string} type
  7409. * The media type to check
  7410. * @return {string} Returns the native video element's response
  7411. */
  7412. Tech.canPlayType = function canPlayType() {
  7413. return '';
  7414. };
  7415. /**
  7416. * Check if the tech can support the given source
  7417. * @param {Object} srcObj
  7418. * The source object
  7419. * @param {Object} options
  7420. * The options passed to the tech
  7421. * @return {string} 'probably', 'maybe', or '' (empty string)
  7422. */
  7423. Tech.canPlaySource = function canPlaySource(srcObj, options) {
  7424. return Tech.canPlayType(srcObj.type);
  7425. };
  7426. /*
  7427. * Return whether the argument is a Tech or not.
  7428. * Can be passed either a Class like `Html5` or a instance like `player.tech_`
  7429. *
  7430. * @param {Object} component
  7431. * The item to check
  7432. *
  7433. * @return {boolean}
  7434. * Whether it is a tech or not
  7435. * - True if it is a tech
  7436. * - False if it is not
  7437. */
  7438. Tech.isTech = function isTech(component) {
  7439. return component.prototype instanceof Tech || component instanceof Tech || component === Tech;
  7440. };
  7441. /**
  7442. * Registers a `Tech` into a shared list for videojs.
  7443. *
  7444. * @param {string} name
  7445. * Name of the `Tech` to register.
  7446. *
  7447. * @param {Object} tech
  7448. * The `Tech` class to register.
  7449. */
  7450. Tech.registerTech = function registerTech(name, tech) {
  7451. if (!Tech.techs_) {
  7452. Tech.techs_ = {};
  7453. }
  7454. if (!Tech.isTech(tech)) {
  7455. throw new Error('Tech ' + name + ' must be a Tech');
  7456. }
  7457. if (!Tech.canPlayType) {
  7458. throw new Error('Techs must have a static canPlayType method on them');
  7459. }
  7460. if (!Tech.canPlaySource) {
  7461. throw new Error('Techs must have a static canPlaySource method on them');
  7462. }
  7463. name = toTitleCase(name);
  7464. Tech.techs_[name] = tech;
  7465. if (name !== 'Tech') {
  7466. // camel case the techName for use in techOrder
  7467. Tech.defaultTechOrder_.push(name);
  7468. }
  7469. return tech;
  7470. };
  7471. /**
  7472. * Get a `Tech` from the shared list by name.
  7473. *
  7474. * @param {string} name
  7475. * `camelCase` or `TitleCase` name of the Tech to get
  7476. *
  7477. * @return {Tech|undefined}
  7478. * The `Tech` or undefined if there was no tech with the name requsted.
  7479. */
  7480. Tech.getTech = function getTech(name) {
  7481. if (!name) {
  7482. return;
  7483. }
  7484. name = toTitleCase(name);
  7485. if (Tech.techs_ && Tech.techs_[name]) {
  7486. return Tech.techs_[name];
  7487. }
  7488. if (window && window.videojs && window.videojs[name]) {
  7489. log.warn('The ' + name + ' tech was added to the videojs object when it should be registered using videojs.registerTech(name, tech)');
  7490. return window.videojs[name];
  7491. }
  7492. };
  7493. return Tech;
  7494. }(Component);
  7495. /**
  7496. * Get the {@link VideoTrackList}
  7497. *
  7498. * @returns {VideoTrackList}
  7499. * @method Tech.prototype.videoTracks
  7500. */
  7501. /**
  7502. * Get the {@link AudioTrackList}
  7503. *
  7504. * @returns {AudioTrackList}
  7505. * @method Tech.prototype.audioTracks
  7506. */
  7507. /**
  7508. * Get the {@link TextTrackList}
  7509. *
  7510. * @returns {TextTrackList}
  7511. * @method Tech.prototype.textTracks
  7512. */
  7513. /**
  7514. * Get the remote element {@link TextTrackList}
  7515. *
  7516. * @returns {TextTrackList}
  7517. * @method Tech.prototype.remoteTextTracks
  7518. */
  7519. /**
  7520. * Get the remote element {@link HtmlTrackElementList}
  7521. *
  7522. * @returns {HtmlTrackElementList}
  7523. * @method Tech.prototype.remoteTextTrackEls
  7524. */
  7525. ALL.names.forEach(function (name) {
  7526. var props = ALL[name];
  7527. Tech.prototype[props.getterName] = function () {
  7528. this[props.privateName] = this[props.privateName] || new props.ListClass();
  7529. return this[props.privateName];
  7530. };
  7531. });
  7532. /**
  7533. * List of associated text tracks
  7534. *
  7535. * @type {TextTrackList}
  7536. * @private
  7537. * @property Tech#textTracks_
  7538. */
  7539. /**
  7540. * List of associated audio tracks.
  7541. *
  7542. * @type {AudioTrackList}
  7543. * @private
  7544. * @property Tech#audioTracks_
  7545. */
  7546. /**
  7547. * List of associated video tracks.
  7548. *
  7549. * @type {VideoTrackList}
  7550. * @private
  7551. * @property Tech#videoTracks_
  7552. */
  7553. /**
  7554. * Boolean indicating wether the `Tech` supports volume control.
  7555. *
  7556. * @type {boolean}
  7557. * @default
  7558. */
  7559. Tech.prototype.featuresVolumeControl = true;
  7560. /**
  7561. * Boolean indicating whether the `Tech` supports muting volume.
  7562. *
  7563. * @type {bolean}
  7564. * @default
  7565. */
  7566. Tech.prototype.featuresMuteControl = true;
  7567. /**
  7568. * Boolean indicating whether the `Tech` supports fullscreen resize control.
  7569. * Resizing plugins using request fullscreen reloads the plugin
  7570. *
  7571. * @type {boolean}
  7572. * @default
  7573. */
  7574. Tech.prototype.featuresFullscreenResize = false;
  7575. /**
  7576. * Boolean indicating wether the `Tech` supports changing the speed at which the video
  7577. * plays. Examples:
  7578. * - Set player to play 2x (twice) as fast
  7579. * - Set player to play 0.5x (half) as fast
  7580. *
  7581. * @type {boolean}
  7582. * @default
  7583. */
  7584. Tech.prototype.featuresPlaybackRate = false;
  7585. /**
  7586. * Boolean indicating wether the `Tech` supports the `progress` event. This is currently
  7587. * not triggered by video-js-swf. This will be used to determine if
  7588. * {@link Tech#manualProgressOn} should be called.
  7589. *
  7590. * @type {boolean}
  7591. * @default
  7592. */
  7593. Tech.prototype.featuresProgressEvents = false;
  7594. /**
  7595. * Boolean indicating wether the `Tech` supports the `sourceset` event.
  7596. *
  7597. * A tech should set this to `true` and then use {@link Tech#triggerSourceset}
  7598. * to trigger a {@link Tech#event:sourceset} at the earliest time after getting
  7599. * a new source.
  7600. *
  7601. * @type {boolean}
  7602. * @default
  7603. */
  7604. Tech.prototype.featuresSourceset = false;
  7605. /**
  7606. * Boolean indicating wether the `Tech` supports the `timeupdate` event. This is currently
  7607. * not triggered by video-js-swf. This will be used to determine if
  7608. * {@link Tech#manualTimeUpdates} should be called.
  7609. *
  7610. * @type {boolean}
  7611. * @default
  7612. */
  7613. Tech.prototype.featuresTimeupdateEvents = false;
  7614. /**
  7615. * Boolean indicating wether the `Tech` supports the native `TextTrack`s.
  7616. * This will help us integrate with native `TextTrack`s if the browser supports them.
  7617. *
  7618. * @type {boolean}
  7619. * @default
  7620. */
  7621. Tech.prototype.featuresNativeTextTracks = false;
  7622. /**
  7623. * A functional mixin for techs that want to use the Source Handler pattern.
  7624. * Source handlers are scripts for handling specific formats.
  7625. * The source handler pattern is used for adaptive formats (HLS, DASH) that
  7626. * manually load video data and feed it into a Source Buffer (Media Source Extensions)
  7627. * Example: `Tech.withSourceHandlers.call(MyTech);`
  7628. *
  7629. * @param {Tech} _Tech
  7630. * The tech to add source handler functions to.
  7631. *
  7632. * @mixes Tech~SourceHandlerAdditions
  7633. */
  7634. Tech.withSourceHandlers = function (_Tech) {
  7635. /**
  7636. * Register a source handler
  7637. *
  7638. * @param {Function} handler
  7639. * The source handler class
  7640. *
  7641. * @param {number} [index]
  7642. * Register it at the following index
  7643. */
  7644. _Tech.registerSourceHandler = function (handler, index) {
  7645. var handlers = _Tech.sourceHandlers;
  7646. if (!handlers) {
  7647. handlers = _Tech.sourceHandlers = [];
  7648. }
  7649. if (index === undefined) {
  7650. // add to the end of the list
  7651. index = handlers.length;
  7652. }
  7653. handlers.splice(index, 0, handler);
  7654. };
  7655. /**
  7656. * Check if the tech can support the given type. Also checks the
  7657. * Techs sourceHandlers.
  7658. *
  7659. * @param {string} type
  7660. * The mimetype to check.
  7661. *
  7662. * @return {string}
  7663. * 'probably', 'maybe', or '' (empty string)
  7664. */
  7665. _Tech.canPlayType = function (type) {
  7666. var handlers = _Tech.sourceHandlers || [];
  7667. var can = void 0;
  7668. for (var i = 0; i < handlers.length; i++) {
  7669. can = handlers[i].canPlayType(type);
  7670. if (can) {
  7671. return can;
  7672. }
  7673. }
  7674. return '';
  7675. };
  7676. /**
  7677. * Returns the first source handler that supports the source.
  7678. *
  7679. * TODO: Answer question: should 'probably' be prioritized over 'maybe'
  7680. *
  7681. * @param {Tech~SourceObject} source
  7682. * The source object
  7683. *
  7684. * @param {Object} options
  7685. * The options passed to the tech
  7686. *
  7687. * @return {SourceHandler|null}
  7688. * The first source handler that supports the source or null if
  7689. * no SourceHandler supports the source
  7690. */
  7691. _Tech.selectSourceHandler = function (source, options) {
  7692. var handlers = _Tech.sourceHandlers || [];
  7693. var can = void 0;
  7694. for (var i = 0; i < handlers.length; i++) {
  7695. can = handlers[i].canHandleSource(source, options);
  7696. if (can) {
  7697. return handlers[i];
  7698. }
  7699. }
  7700. return null;
  7701. };
  7702. /**
  7703. * Check if the tech can support the given source.
  7704. *
  7705. * @param {Tech~SourceObject} srcObj
  7706. * The source object
  7707. *
  7708. * @param {Object} options
  7709. * The options passed to the tech
  7710. *
  7711. * @return {string}
  7712. * 'probably', 'maybe', or '' (empty string)
  7713. */
  7714. _Tech.canPlaySource = function (srcObj, options) {
  7715. var sh = _Tech.selectSourceHandler(srcObj, options);
  7716. if (sh) {
  7717. return sh.canHandleSource(srcObj, options);
  7718. }
  7719. return '';
  7720. };
  7721. /**
  7722. * When using a source handler, prefer its implementation of
  7723. * any function normally provided by the tech.
  7724. */
  7725. var deferrable = ['seekable', 'seeking', 'duration'];
  7726. /**
  7727. * A wrapper around {@link Tech#seekable} that will call a `SourceHandler`s seekable
  7728. * function if it exists, with a fallback to the Techs seekable function.
  7729. *
  7730. * @method _Tech.seekable
  7731. */
  7732. /**
  7733. * A wrapper around {@link Tech#duration} that will call a `SourceHandler`s duration
  7734. * function if it exists, otherwise it will fallback to the techs duration function.
  7735. *
  7736. * @method _Tech.duration
  7737. */
  7738. deferrable.forEach(function (fnName) {
  7739. var originalFn = this[fnName];
  7740. if (typeof originalFn !== 'function') {
  7741. return;
  7742. }
  7743. this[fnName] = function () {
  7744. if (this.sourceHandler_ && this.sourceHandler_[fnName]) {
  7745. return this.sourceHandler_[fnName].apply(this.sourceHandler_, arguments);
  7746. }
  7747. return originalFn.apply(this, arguments);
  7748. };
  7749. }, _Tech.prototype);
  7750. /**
  7751. * Create a function for setting the source using a source object
  7752. * and source handlers.
  7753. * Should never be called unless a source handler was found.
  7754. *
  7755. * @param {Tech~SourceObject} source
  7756. * A source object with src and type keys
  7757. */
  7758. _Tech.prototype.setSource = function (source) {
  7759. var sh = _Tech.selectSourceHandler(source, this.options_);
  7760. if (!sh) {
  7761. // Fall back to a native source hander when unsupported sources are
  7762. // deliberately set
  7763. if (_Tech.nativeSourceHandler) {
  7764. sh = _Tech.nativeSourceHandler;
  7765. } else {
  7766. log.error('No source hander found for the current source.');
  7767. }
  7768. }
  7769. // Dispose any existing source handler
  7770. this.disposeSourceHandler();
  7771. this.off('dispose', this.disposeSourceHandler);
  7772. if (sh !== _Tech.nativeSourceHandler) {
  7773. this.currentSource_ = source;
  7774. }
  7775. this.sourceHandler_ = sh.handleSource(source, this, this.options_);
  7776. this.on('dispose', this.disposeSourceHandler);
  7777. };
  7778. /**
  7779. * Clean up any existing SourceHandlers and listeners when the Tech is disposed.
  7780. *
  7781. * @listens Tech#dispose
  7782. */
  7783. _Tech.prototype.disposeSourceHandler = function () {
  7784. // if we have a source and get another one
  7785. // then we are loading something new
  7786. // than clear all of our current tracks
  7787. if (this.currentSource_) {
  7788. this.clearTracks(['audio', 'video']);
  7789. this.currentSource_ = null;
  7790. }
  7791. // always clean up auto-text tracks
  7792. this.cleanupAutoTextTracks();
  7793. if (this.sourceHandler_) {
  7794. if (this.sourceHandler_.dispose) {
  7795. this.sourceHandler_.dispose();
  7796. }
  7797. this.sourceHandler_ = null;
  7798. }
  7799. };
  7800. };
  7801. // The base Tech class needs to be registered as a Component. It is the only
  7802. // Tech that can be registered as a Component.
  7803. Component.registerComponent('Tech', Tech);
  7804. Tech.registerTech('Tech', Tech);
  7805. /**
  7806. * A list of techs that should be added to techOrder on Players
  7807. *
  7808. * @private
  7809. */
  7810. Tech.defaultTechOrder_ = [];
  7811. var middlewares = {};
  7812. var middlewareInstances = {};
  7813. var TERMINATOR = {};
  7814. function use(type, middleware) {
  7815. middlewares[type] = middlewares[type] || [];
  7816. middlewares[type].push(middleware);
  7817. }
  7818. function setSource(player, src, next) {
  7819. player.setTimeout(function () {
  7820. return setSourceHelper(src, middlewares[src.type], next, player);
  7821. }, 1);
  7822. }
  7823. function setTech(middleware, tech) {
  7824. middleware.forEach(function (mw) {
  7825. return mw.setTech && mw.setTech(tech);
  7826. });
  7827. }
  7828. /**
  7829. * Calls a getter on the tech first, through each middleware
  7830. * from right to left to the player.
  7831. */
  7832. function get$1(middleware, tech, method) {
  7833. return middleware.reduceRight(middlewareIterator(method), tech[method]());
  7834. }
  7835. /**
  7836. * Takes the argument given to the player and calls the setter method on each
  7837. * middlware from left to right to the tech.
  7838. */
  7839. function set$1(middleware, tech, method, arg) {
  7840. return tech[method](middleware.reduce(middlewareIterator(method), arg));
  7841. }
  7842. /**
  7843. * Takes the argument given to the player and calls the `call` version of the method
  7844. * on each middleware from left to right.
  7845. * Then, call the passed in method on the tech and return the result unchanged
  7846. * back to the player, through middleware, this time from right to left.
  7847. */
  7848. function mediate(middleware, tech, method) {
  7849. var arg = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  7850. var callMethod = 'call' + toTitleCase(method);
  7851. var middlewareValue = middleware.reduce(middlewareIterator(callMethod), arg);
  7852. var terminated = middlewareValue === TERMINATOR;
  7853. var returnValue = terminated ? null : tech[method](middlewareValue);
  7854. executeRight(middleware, method, returnValue, terminated);
  7855. return returnValue;
  7856. }
  7857. var allowedGetters = {
  7858. buffered: 1,
  7859. currentTime: 1,
  7860. duration: 1,
  7861. seekable: 1,
  7862. played: 1,
  7863. paused: 1
  7864. };
  7865. var allowedSetters = {
  7866. setCurrentTime: 1
  7867. };
  7868. var allowedMediators = {
  7869. play: 1,
  7870. pause: 1
  7871. };
  7872. function middlewareIterator(method) {
  7873. return function (value, mw) {
  7874. // if the previous middleware terminated, pass along the termination
  7875. if (value === TERMINATOR) {
  7876. return TERMINATOR;
  7877. }
  7878. if (mw[method]) {
  7879. return mw[method](value);
  7880. }
  7881. return value;
  7882. };
  7883. }
  7884. function executeRight(mws, method, value, terminated) {
  7885. for (var i = mws.length - 1; i >= 0; i--) {
  7886. var mw = mws[i];
  7887. if (mw[method]) {
  7888. mw[method](terminated, value);
  7889. }
  7890. }
  7891. }
  7892. function clearCacheForPlayer(player) {
  7893. middlewareInstances[player.id()] = null;
  7894. }
  7895. /**
  7896. * {
  7897. * [playerId]: [[mwFactory, mwInstance], ...]
  7898. * }
  7899. */
  7900. function getOrCreateFactory(player, mwFactory) {
  7901. var mws = middlewareInstances[player.id()];
  7902. var mw = null;
  7903. if (mws === undefined || mws === null) {
  7904. mw = mwFactory(player);
  7905. middlewareInstances[player.id()] = [[mwFactory, mw]];
  7906. return mw;
  7907. }
  7908. for (var i = 0; i < mws.length; i++) {
  7909. var _mws$i = mws[i],
  7910. mwf = _mws$i[0],
  7911. mwi = _mws$i[1];
  7912. if (mwf !== mwFactory) {
  7913. continue;
  7914. }
  7915. mw = mwi;
  7916. }
  7917. if (mw === null) {
  7918. mw = mwFactory(player);
  7919. mws.push([mwFactory, mw]);
  7920. }
  7921. return mw;
  7922. }
  7923. function setSourceHelper() {
  7924. var src = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  7925. var middleware = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  7926. var next = arguments[2];
  7927. var player = arguments[3];
  7928. var acc = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
  7929. var lastRun = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
  7930. var mwFactory = middleware[0],
  7931. mwrest = middleware.slice(1);
  7932. // if mwFactory is a string, then we're at a fork in the road
  7933. if (typeof mwFactory === 'string') {
  7934. setSourceHelper(src, middlewares[mwFactory], next, player, acc, lastRun);
  7935. // if we have an mwFactory, call it with the player to get the mw,
  7936. // then call the mw's setSource method
  7937. } else if (mwFactory) {
  7938. var mw = getOrCreateFactory(player, mwFactory);
  7939. // if setSource isn't present, implicitly select this middleware
  7940. if (!mw.setSource) {
  7941. acc.push(mw);
  7942. return setSourceHelper(src, mwrest, next, player, acc, lastRun);
  7943. }
  7944. mw.setSource(assign({}, src), function (err, _src) {
  7945. // something happened, try the next middleware on the current level
  7946. // make sure to use the old src
  7947. if (err) {
  7948. return setSourceHelper(src, mwrest, next, player, acc, lastRun);
  7949. }
  7950. // we've succeeded, now we need to go deeper
  7951. acc.push(mw);
  7952. // if it's the same type, continue down the current chain
  7953. // otherwise, we want to go down the new chain
  7954. setSourceHelper(_src, src.type === _src.type ? mwrest : middlewares[_src.type], next, player, acc, lastRun);
  7955. });
  7956. } else if (mwrest.length) {
  7957. setSourceHelper(src, mwrest, next, player, acc, lastRun);
  7958. } else if (lastRun) {
  7959. next(src, acc);
  7960. } else {
  7961. setSourceHelper(src, middlewares['*'], next, player, acc, true);
  7962. }
  7963. }
  7964. /**
  7965. * Mimetypes
  7966. *
  7967. * @see http://hul.harvard.edu/ois/////systems/wax/wax-public-help/mimetypes.htm
  7968. * @typedef Mimetypes~Kind
  7969. * @enum
  7970. */
  7971. var MimetypesKind = {
  7972. opus: 'video/ogg',
  7973. ogv: 'video/ogg',
  7974. mp4: 'video/mp4',
  7975. mov: 'video/mp4',
  7976. m4v: 'video/mp4',
  7977. mkv: 'video/x-matroska',
  7978. mp3: 'audio/mpeg',
  7979. aac: 'audio/aac',
  7980. oga: 'audio/ogg',
  7981. m3u8: 'application/x-mpegURL'
  7982. };
  7983. /**
  7984. * Get the mimetype of a given src url if possible
  7985. *
  7986. * @param {string} src
  7987. * The url to the src
  7988. *
  7989. * @return {string}
  7990. * return the mimetype if it was known or empty string otherwise
  7991. */
  7992. var getMimetype = function getMimetype() {
  7993. var src = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  7994. var ext = getFileExtension(src);
  7995. var mimetype = MimetypesKind[ext.toLowerCase()];
  7996. return mimetype || '';
  7997. };
  7998. /**
  7999. * Find the mime type of a given source string if possible. Uses the player
  8000. * source cache.
  8001. *
  8002. * @param {Player} player
  8003. * The player object
  8004. *
  8005. * @param {string} src
  8006. * The source string
  8007. *
  8008. * @return {string}
  8009. * The type that was found
  8010. */
  8011. var findMimetype = function findMimetype(player, src) {
  8012. if (!src) {
  8013. return '';
  8014. }
  8015. // 1. check for the type in the `source` cache
  8016. if (player.cache_.source.src === src && player.cache_.source.type) {
  8017. return player.cache_.source.type;
  8018. }
  8019. // 2. see if we have this source in our `currentSources` cache
  8020. var matchingSources = player.cache_.sources.filter(function (s) {
  8021. return s.src === src;
  8022. });
  8023. if (matchingSources.length) {
  8024. return matchingSources[0].type;
  8025. }
  8026. // 3. look for the src url in source elements and use the type there
  8027. var sources = player.$$('source');
  8028. for (var i = 0; i < sources.length; i++) {
  8029. var s = sources[i];
  8030. if (s.type && s.src && s.src === src) {
  8031. return s.type;
  8032. }
  8033. }
  8034. // 4. finally fallback to our list of mime types based on src url extension
  8035. return getMimetype(src);
  8036. };
  8037. /**
  8038. * @module filter-source
  8039. */
  8040. /**
  8041. * Filter out single bad source objects or multiple source objects in an
  8042. * array. Also flattens nested source object arrays into a 1 dimensional
  8043. * array of source objects.
  8044. *
  8045. * @param {Tech~SourceObject|Tech~SourceObject[]} src
  8046. * The src object to filter
  8047. *
  8048. * @return {Tech~SourceObject[]}
  8049. * An array of sourceobjects containing only valid sources
  8050. *
  8051. * @private
  8052. */
  8053. var filterSource = function filterSource(src) {
  8054. // traverse array
  8055. if (Array.isArray(src)) {
  8056. var newsrc = [];
  8057. src.forEach(function (srcobj) {
  8058. srcobj = filterSource(srcobj);
  8059. if (Array.isArray(srcobj)) {
  8060. newsrc = newsrc.concat(srcobj);
  8061. } else if (isObject(srcobj)) {
  8062. newsrc.push(srcobj);
  8063. }
  8064. });
  8065. src = newsrc;
  8066. } else if (typeof src === 'string' && src.trim()) {
  8067. // convert string into object
  8068. src = [fixSource({ src: src })];
  8069. } else if (isObject(src) && typeof src.src === 'string' && src.src && src.src.trim()) {
  8070. // src is already valid
  8071. src = [fixSource(src)];
  8072. } else {
  8073. // invalid source, turn it into an empty array
  8074. src = [];
  8075. }
  8076. return src;
  8077. };
  8078. /**
  8079. * Checks src mimetype, adding it when possible
  8080. *
  8081. * @param {Tech~SourceObject} src
  8082. * The src object to check
  8083. * @return {Tech~SourceObject}
  8084. * src Object with known type
  8085. */
  8086. function fixSource(src) {
  8087. var mimetype = getMimetype(src.src);
  8088. if (!src.type && mimetype) {
  8089. src.type = mimetype;
  8090. }
  8091. return src;
  8092. }
  8093. /**
  8094. * @file loader.js
  8095. */
  8096. /**
  8097. * The `MediaLoader` is the `Component` that decides which playback technology to load
  8098. * when a player is initialized.
  8099. *
  8100. * @extends Component
  8101. */
  8102. var MediaLoader = function (_Component) {
  8103. inherits(MediaLoader, _Component);
  8104. /**
  8105. * Create an instance of this class.
  8106. *
  8107. * @param {Player} player
  8108. * The `Player` that this class should attach to.
  8109. *
  8110. * @param {Object} [options]
  8111. * The key/value stroe of player options.
  8112. *
  8113. * @param {Component~ReadyCallback} [ready]
  8114. * The function that is run when this component is ready.
  8115. */
  8116. function MediaLoader(player, options, ready) {
  8117. classCallCheck(this, MediaLoader);
  8118. // MediaLoader has no element
  8119. var options_ = mergeOptions({ createEl: false }, options);
  8120. // If there are no sources when the player is initialized,
  8121. // load the first supported playback technology.
  8122. var _this = possibleConstructorReturn(this, _Component.call(this, player, options_, ready));
  8123. if (!options.playerOptions.sources || options.playerOptions.sources.length === 0) {
  8124. for (var i = 0, j = options.playerOptions.techOrder; i < j.length; i++) {
  8125. var techName = toTitleCase(j[i]);
  8126. var tech = Tech.getTech(techName);
  8127. // Support old behavior of techs being registered as components.
  8128. // Remove once that deprecated behavior is removed.
  8129. if (!techName) {
  8130. tech = Component.getComponent(techName);
  8131. }
  8132. // Check if the browser supports this technology
  8133. if (tech && tech.isSupported()) {
  8134. player.loadTech_(techName);
  8135. break;
  8136. }
  8137. }
  8138. } else {
  8139. // Loop through playback technologies (HTML5, Flash) and check for support.
  8140. // Then load the best source.
  8141. // A few assumptions here:
  8142. // All playback technologies respect preload false.
  8143. player.src(options.playerOptions.sources);
  8144. }
  8145. return _this;
  8146. }
  8147. return MediaLoader;
  8148. }(Component);
  8149. Component.registerComponent('MediaLoader', MediaLoader);
  8150. /**
  8151. * @file button.js
  8152. */
  8153. /**
  8154. * Clickable Component which is clickable or keyboard actionable,
  8155. * but is not a native HTML button.
  8156. *
  8157. * @extends Component
  8158. */
  8159. var ClickableComponent = function (_Component) {
  8160. inherits(ClickableComponent, _Component);
  8161. /**
  8162. * Creates an instance of this class.
  8163. *
  8164. * @param {Player} player
  8165. * The `Player` that this class should be attached to.
  8166. *
  8167. * @param {Object} [options]
  8168. * The key/value store of player options.
  8169. */
  8170. function ClickableComponent(player, options) {
  8171. classCallCheck(this, ClickableComponent);
  8172. var _this = possibleConstructorReturn(this, _Component.call(this, player, options));
  8173. _this.emitTapEvents();
  8174. _this.enable();
  8175. return _this;
  8176. }
  8177. /**
  8178. * Create the `Component`s DOM element.
  8179. *
  8180. * @param {string} [tag=div]
  8181. * The element's node type.
  8182. *
  8183. * @param {Object} [props={}]
  8184. * An object of properties that should be set on the element.
  8185. *
  8186. * @param {Object} [attributes={}]
  8187. * An object of attributes that should be set on the element.
  8188. *
  8189. * @return {Element}
  8190. * The element that gets created.
  8191. */
  8192. ClickableComponent.prototype.createEl = function createEl$$1() {
  8193. var tag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'div';
  8194. var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  8195. var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  8196. props = assign({
  8197. innerHTML: '<span aria-hidden="true" class="vjs-icon-placeholder"></span>',
  8198. className: this.buildCSSClass(),
  8199. tabIndex: 0
  8200. }, props);
  8201. if (tag === 'button') {
  8202. log.error('Creating a ClickableComponent with an HTML element of ' + tag + ' is not supported; use a Button instead.');
  8203. }
  8204. // Add ARIA attributes for clickable element which is not a native HTML button
  8205. attributes = assign({
  8206. role: 'button'
  8207. }, attributes);
  8208. this.tabIndex_ = props.tabIndex;
  8209. var el = _Component.prototype.createEl.call(this, tag, props, attributes);
  8210. this.createControlTextEl(el);
  8211. return el;
  8212. };
  8213. ClickableComponent.prototype.dispose = function dispose() {
  8214. // remove controlTextEl_ on dipose
  8215. this.controlTextEl_ = null;
  8216. _Component.prototype.dispose.call(this);
  8217. };
  8218. /**
  8219. * Create a control text element on this `Component`
  8220. *
  8221. * @param {Element} [el]
  8222. * Parent element for the control text.
  8223. *
  8224. * @return {Element}
  8225. * The control text element that gets created.
  8226. */
  8227. ClickableComponent.prototype.createControlTextEl = function createControlTextEl(el) {
  8228. this.controlTextEl_ = createEl('span', {
  8229. className: 'vjs-control-text'
  8230. }, {
  8231. // let the screen reader user know that the text of the element may change
  8232. 'aria-live': 'polite'
  8233. });
  8234. if (el) {
  8235. el.appendChild(this.controlTextEl_);
  8236. }
  8237. this.controlText(this.controlText_, el);
  8238. return this.controlTextEl_;
  8239. };
  8240. /**
  8241. * Get or set the localize text to use for the controls on the `Component`.
  8242. *
  8243. * @param {string} [text]
  8244. * Control text for element.
  8245. *
  8246. * @param {Element} [el=this.el()]
  8247. * Element to set the title on.
  8248. *
  8249. * @return {string}
  8250. * - The control text when getting
  8251. */
  8252. ClickableComponent.prototype.controlText = function controlText(text) {
  8253. var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.el();
  8254. if (text === undefined) {
  8255. return this.controlText_ || 'Need Text';
  8256. }
  8257. var localizedText = this.localize(text);
  8258. this.controlText_ = text;
  8259. textContent(this.controlTextEl_, localizedText);
  8260. if (!this.nonIconControl) {
  8261. // Set title attribute if only an icon is shown
  8262. el.setAttribute('title', localizedText);
  8263. }
  8264. };
  8265. /**
  8266. * Builds the default DOM `className`.
  8267. *
  8268. * @return {string}
  8269. * The DOM `className` for this object.
  8270. */
  8271. ClickableComponent.prototype.buildCSSClass = function buildCSSClass() {
  8272. return 'vjs-control vjs-button ' + _Component.prototype.buildCSSClass.call(this);
  8273. };
  8274. /**
  8275. * Enable this `Component`s element.
  8276. */
  8277. ClickableComponent.prototype.enable = function enable() {
  8278. if (!this.enabled_) {
  8279. this.enabled_ = true;
  8280. this.removeClass('vjs-disabled');
  8281. this.el_.setAttribute('aria-disabled', 'false');
  8282. if (typeof this.tabIndex_ !== 'undefined') {
  8283. this.el_.setAttribute('tabIndex', this.tabIndex_);
  8284. }
  8285. this.on(['tap', 'click'], this.handleClick);
  8286. this.on('focus', this.handleFocus);
  8287. this.on('blur', this.handleBlur);
  8288. }
  8289. };
  8290. /**
  8291. * Disable this `Component`s element.
  8292. */
  8293. ClickableComponent.prototype.disable = function disable() {
  8294. this.enabled_ = false;
  8295. this.addClass('vjs-disabled');
  8296. this.el_.setAttribute('aria-disabled', 'true');
  8297. if (typeof this.tabIndex_ !== 'undefined') {
  8298. this.el_.removeAttribute('tabIndex');
  8299. }
  8300. this.off(['tap', 'click'], this.handleClick);
  8301. this.off('focus', this.handleFocus);
  8302. this.off('blur', this.handleBlur);
  8303. };
  8304. /**
  8305. * This gets called when a `ClickableComponent` gets:
  8306. * - Clicked (via the `click` event, listening starts in the constructor)
  8307. * - Tapped (via the `tap` event, listening starts in the constructor)
  8308. * - The following things happen in order:
  8309. * 1. {@link ClickableComponent#handleFocus} is called via a `focus` event on the
  8310. * `ClickableComponent`.
  8311. * 2. {@link ClickableComponent#handleFocus} adds a listener for `keydown` on using
  8312. * {@link ClickableComponent#handleKeyPress}.
  8313. * 3. `ClickableComponent` has not had a `blur` event (`blur` means that focus was lost). The user presses
  8314. * the space or enter key.
  8315. * 4. {@link ClickableComponent#handleKeyPress} calls this function with the `keydown`
  8316. * event as a parameter.
  8317. *
  8318. * @param {EventTarget~Event} event
  8319. * The `keydown`, `tap`, or `click` event that caused this function to be
  8320. * called.
  8321. *
  8322. * @listens tap
  8323. * @listens click
  8324. * @abstract
  8325. */
  8326. ClickableComponent.prototype.handleClick = function handleClick(event) {};
  8327. /**
  8328. * This gets called when a `ClickableComponent` gains focus via a `focus` event.
  8329. * Turns on listening for `keydown` events. When they happen it
  8330. * calls `this.handleKeyPress`.
  8331. *
  8332. * @param {EventTarget~Event} event
  8333. * The `focus` event that caused this function to be called.
  8334. *
  8335. * @listens focus
  8336. */
  8337. ClickableComponent.prototype.handleFocus = function handleFocus(event) {
  8338. on(document, 'keydown', bind(this, this.handleKeyPress));
  8339. };
  8340. /**
  8341. * Called when this ClickableComponent has focus and a key gets pressed down. By
  8342. * default it will call `this.handleClick` when the key is space or enter.
  8343. *
  8344. * @param {EventTarget~Event} event
  8345. * The `keydown` event that caused this function to be called.
  8346. *
  8347. * @listens keydown
  8348. */
  8349. ClickableComponent.prototype.handleKeyPress = function handleKeyPress(event) {
  8350. // Support Space (32) or Enter (13) key operation to fire a click event
  8351. if (event.which === 32 || event.which === 13) {
  8352. event.preventDefault();
  8353. this.trigger('click');
  8354. } else if (_Component.prototype.handleKeyPress) {
  8355. // Pass keypress handling up for unsupported keys
  8356. _Component.prototype.handleKeyPress.call(this, event);
  8357. }
  8358. };
  8359. /**
  8360. * Called when a `ClickableComponent` loses focus. Turns off the listener for
  8361. * `keydown` events. Which Stops `this.handleKeyPress` from getting called.
  8362. *
  8363. * @param {EventTarget~Event} event
  8364. * The `blur` event that caused this function to be called.
  8365. *
  8366. * @listens blur
  8367. */
  8368. ClickableComponent.prototype.handleBlur = function handleBlur(event) {
  8369. off(document, 'keydown', bind(this, this.handleKeyPress));
  8370. };
  8371. return ClickableComponent;
  8372. }(Component);
  8373. Component.registerComponent('ClickableComponent', ClickableComponent);
  8374. /**
  8375. * @file poster-image.js
  8376. */
  8377. /**
  8378. * A `ClickableComponent` that handles showing the poster image for the player.
  8379. *
  8380. * @extends ClickableComponent
  8381. */
  8382. var PosterImage = function (_ClickableComponent) {
  8383. inherits(PosterImage, _ClickableComponent);
  8384. /**
  8385. * Create an instance of this class.
  8386. *
  8387. * @param {Player} player
  8388. * The `Player` that this class should attach to.
  8389. *
  8390. * @param {Object} [options]
  8391. * The key/value store of player options.
  8392. */
  8393. function PosterImage(player, options) {
  8394. classCallCheck(this, PosterImage);
  8395. var _this = possibleConstructorReturn(this, _ClickableComponent.call(this, player, options));
  8396. _this.update();
  8397. player.on('posterchange', bind(_this, _this.update));
  8398. return _this;
  8399. }
  8400. /**
  8401. * Clean up and dispose of the `PosterImage`.
  8402. */
  8403. PosterImage.prototype.dispose = function dispose() {
  8404. this.player().off('posterchange', this.update);
  8405. _ClickableComponent.prototype.dispose.call(this);
  8406. };
  8407. /**
  8408. * Create the `PosterImage`s DOM element.
  8409. *
  8410. * @return {Element}
  8411. * The element that gets created.
  8412. */
  8413. PosterImage.prototype.createEl = function createEl$$1() {
  8414. var el = createEl('div', {
  8415. className: 'vjs-poster',
  8416. // Don't want poster to be tabbable.
  8417. tabIndex: -1
  8418. });
  8419. // To ensure the poster image resizes while maintaining its original aspect
  8420. // ratio, use a div with `background-size` when available. For browsers that
  8421. // do not support `background-size` (e.g. IE8), fall back on using a regular
  8422. // img element.
  8423. if (!BACKGROUND_SIZE_SUPPORTED) {
  8424. this.fallbackImg_ = createEl('img');
  8425. el.appendChild(this.fallbackImg_);
  8426. }
  8427. return el;
  8428. };
  8429. /**
  8430. * An {@link EventTarget~EventListener} for {@link Player#posterchange} events.
  8431. *
  8432. * @listens Player#posterchange
  8433. *
  8434. * @param {EventTarget~Event} [event]
  8435. * The `Player#posterchange` event that triggered this function.
  8436. */
  8437. PosterImage.prototype.update = function update(event) {
  8438. var url = this.player().poster();
  8439. this.setSrc(url);
  8440. // If there's no poster source we should display:none on this component
  8441. // so it's not still clickable or right-clickable
  8442. if (url) {
  8443. this.show();
  8444. } else {
  8445. this.hide();
  8446. }
  8447. };
  8448. /**
  8449. * Set the source of the `PosterImage` depending on the display method.
  8450. *
  8451. * @param {string} url
  8452. * The URL to the source for the `PosterImage`.
  8453. */
  8454. PosterImage.prototype.setSrc = function setSrc(url) {
  8455. if (this.fallbackImg_) {
  8456. this.fallbackImg_.src = url;
  8457. } else {
  8458. var backgroundImage = '';
  8459. // Any falsey values should stay as an empty string, otherwise
  8460. // this will throw an extra error
  8461. if (url) {
  8462. backgroundImage = 'url("' + url + '")';
  8463. }
  8464. this.el_.style.backgroundImage = backgroundImage;
  8465. }
  8466. };
  8467. /**
  8468. * An {@link EventTarget~EventListener} for clicks on the `PosterImage`. See
  8469. * {@link ClickableComponent#handleClick} for instances where this will be triggered.
  8470. *
  8471. * @listens tap
  8472. * @listens click
  8473. * @listens keydown
  8474. *
  8475. * @param {EventTarget~Event} event
  8476. + The `click`, `tap` or `keydown` event that caused this function to be called.
  8477. */
  8478. PosterImage.prototype.handleClick = function handleClick(event) {
  8479. // We don't want a click to trigger playback when controls are disabled
  8480. if (!this.player_.controls()) {
  8481. return;
  8482. }
  8483. if (this.player_.paused()) {
  8484. silencePromise(this.player_.play());
  8485. } else {
  8486. this.player_.pause();
  8487. }
  8488. };
  8489. return PosterImage;
  8490. }(ClickableComponent);
  8491. Component.registerComponent('PosterImage', PosterImage);
  8492. /**
  8493. * @file text-track-display.js
  8494. */
  8495. var darkGray = '#222';
  8496. var lightGray = '#ccc';
  8497. var fontMap = {
  8498. monospace: 'monospace',
  8499. sansSerif: 'sans-serif',
  8500. serif: 'serif',
  8501. monospaceSansSerif: '"Andale Mono", "Lucida Console", monospace',
  8502. monospaceSerif: '"Courier New", monospace',
  8503. proportionalSansSerif: 'sans-serif',
  8504. proportionalSerif: 'serif',
  8505. casual: '"Comic Sans MS", Impact, fantasy',
  8506. script: '"Monotype Corsiva", cursive',
  8507. smallcaps: '"Andale Mono", "Lucida Console", monospace, sans-serif'
  8508. };
  8509. /**
  8510. * Construct an rgba color from a given hex color code.
  8511. *
  8512. * @param {number} color
  8513. * Hex number for color, like #f0e or #f604e2.
  8514. *
  8515. * @param {number} opacity
  8516. * Value for opacity, 0.0 - 1.0.
  8517. *
  8518. * @return {string}
  8519. * The rgba color that was created, like 'rgba(255, 0, 0, 0.3)'.
  8520. */
  8521. function constructColor(color, opacity) {
  8522. var hex = void 0;
  8523. if (color.length === 4) {
  8524. // color looks like "#f0e"
  8525. hex = color[1] + color[1] + color[2] + color[2] + color[3] + color[3];
  8526. } else if (color.length === 7) {
  8527. // color looks like "#f604e2"
  8528. hex = color.slice(1);
  8529. } else {
  8530. throw new Error('Invalid color code provided, ' + color + '; must be formatted as e.g. #f0e or #f604e2.');
  8531. }
  8532. return 'rgba(' + parseInt(hex.slice(0, 2), 16) + ',' + parseInt(hex.slice(2, 4), 16) + ',' + parseInt(hex.slice(4, 6), 16) + ',' + opacity + ')';
  8533. }
  8534. /**
  8535. * Try to update the style of a DOM element. Some style changes will throw an error,
  8536. * particularly in IE8. Those should be noops.
  8537. *
  8538. * @param {Element} el
  8539. * The DOM element to be styled.
  8540. *
  8541. * @param {string} style
  8542. * The CSS property on the element that should be styled.
  8543. *
  8544. * @param {string} rule
  8545. * The style rule that should be applied to the property.
  8546. *
  8547. * @private
  8548. */
  8549. function tryUpdateStyle(el, style, rule) {
  8550. try {
  8551. el.style[style] = rule;
  8552. } catch (e) {
  8553. // Satisfies linter.
  8554. return;
  8555. }
  8556. }
  8557. /**
  8558. * The component for displaying text track cues.
  8559. *
  8560. * @extends Component
  8561. */
  8562. var TextTrackDisplay = function (_Component) {
  8563. inherits(TextTrackDisplay, _Component);
  8564. /**
  8565. * Creates an instance of this class.
  8566. *
  8567. * @param {Player} player
  8568. * The `Player` that this class should be attached to.
  8569. *
  8570. * @param {Object} [options]
  8571. * The key/value store of player options.
  8572. *
  8573. * @param {Component~ReadyCallback} [ready]
  8574. * The function to call when `TextTrackDisplay` is ready.
  8575. */
  8576. function TextTrackDisplay(player, options, ready) {
  8577. classCallCheck(this, TextTrackDisplay);
  8578. var _this = possibleConstructorReturn(this, _Component.call(this, player, options, ready));
  8579. var updateDisplayHandler = bind(_this, _this.updateDisplay);
  8580. player.on('loadstart', bind(_this, _this.toggleDisplay));
  8581. player.on('texttrackchange', updateDisplayHandler);
  8582. player.on('loadstart', bind(_this, _this.preselectTrack));
  8583. // This used to be called during player init, but was causing an error
  8584. // if a track should show by default and the display hadn't loaded yet.
  8585. // Should probably be moved to an external track loader when we support
  8586. // tracks that don't need a display.
  8587. player.ready(bind(_this, function () {
  8588. if (player.tech_ && player.tech_.featuresNativeTextTracks) {
  8589. this.hide();
  8590. return;
  8591. }
  8592. player.on('fullscreenchange', updateDisplayHandler);
  8593. player.on('playerresize', updateDisplayHandler);
  8594. if (window.addEventListener) {
  8595. window.addEventListener('orientationchange', updateDisplayHandler);
  8596. }
  8597. player.on('dispose', function () {
  8598. return window.removeEventListener('orientationchange', updateDisplayHandler);
  8599. });
  8600. var tracks = this.options_.playerOptions.tracks || [];
  8601. for (var i = 0; i < tracks.length; i++) {
  8602. this.player_.addRemoteTextTrack(tracks[i], true);
  8603. }
  8604. this.preselectTrack();
  8605. }));
  8606. return _this;
  8607. }
  8608. /**
  8609. * Preselect a track following this precedence:
  8610. * - matches the previously selected {@link TextTrack}'s language and kind
  8611. * - matches the previously selected {@link TextTrack}'s language only
  8612. * - is the first default captions track
  8613. * - is the first default descriptions track
  8614. *
  8615. * @listens Player#loadstart
  8616. */
  8617. TextTrackDisplay.prototype.preselectTrack = function preselectTrack() {
  8618. var modes = { captions: 1, subtitles: 1 };
  8619. var trackList = this.player_.textTracks();
  8620. var userPref = this.player_.cache_.selectedLanguage;
  8621. var firstDesc = void 0;
  8622. var firstCaptions = void 0;
  8623. var preferredTrack = void 0;
  8624. for (var i = 0; i < trackList.length; i++) {
  8625. var track = trackList[i];
  8626. if (userPref && userPref.enabled && userPref.language === track.language) {
  8627. // Always choose the track that matches both language and kind
  8628. if (track.kind === userPref.kind) {
  8629. preferredTrack = track;
  8630. // or choose the first track that matches language
  8631. } else if (!preferredTrack) {
  8632. preferredTrack = track;
  8633. }
  8634. // clear everything if offTextTrackMenuItem was clicked
  8635. } else if (userPref && !userPref.enabled) {
  8636. preferredTrack = null;
  8637. firstDesc = null;
  8638. firstCaptions = null;
  8639. } else if (track['default']) {
  8640. if (track.kind === 'descriptions' && !firstDesc) {
  8641. firstDesc = track;
  8642. } else if (track.kind in modes && !firstCaptions) {
  8643. firstCaptions = track;
  8644. }
  8645. }
  8646. }
  8647. // The preferredTrack matches the user preference and takes
  8648. // precendence over all the other tracks.
  8649. // So, display the preferredTrack before the first default track
  8650. // and the subtitles/captions track before the descriptions track
  8651. if (preferredTrack) {
  8652. preferredTrack.mode = 'showing';
  8653. } else if (firstCaptions) {
  8654. firstCaptions.mode = 'showing';
  8655. } else if (firstDesc) {
  8656. firstDesc.mode = 'showing';
  8657. }
  8658. };
  8659. /**
  8660. * Turn display of {@link TextTrack}'s from the current state into the other state.
  8661. * There are only two states:
  8662. * - 'shown'
  8663. * - 'hidden'
  8664. *
  8665. * @listens Player#loadstart
  8666. */
  8667. TextTrackDisplay.prototype.toggleDisplay = function toggleDisplay() {
  8668. if (this.player_.tech_ && this.player_.tech_.featuresNativeTextTracks) {
  8669. this.hide();
  8670. } else {
  8671. this.show();
  8672. }
  8673. };
  8674. /**
  8675. * Create the {@link Component}'s DOM element.
  8676. *
  8677. * @return {Element}
  8678. * The element that was created.
  8679. */
  8680. TextTrackDisplay.prototype.createEl = function createEl() {
  8681. return _Component.prototype.createEl.call(this, 'div', {
  8682. className: 'vjs-text-track-display'
  8683. }, {
  8684. 'aria-live': 'off',
  8685. 'aria-atomic': 'true'
  8686. });
  8687. };
  8688. /**
  8689. * Clear all displayed {@link TextTrack}s.
  8690. */
  8691. TextTrackDisplay.prototype.clearDisplay = function clearDisplay() {
  8692. if (typeof window.WebVTT === 'function') {
  8693. window.WebVTT.processCues(window, [], this.el_);
  8694. }
  8695. };
  8696. /**
  8697. * Update the displayed TextTrack when a either a {@link Player#texttrackchange} or
  8698. * a {@link Player#fullscreenchange} is fired.
  8699. *
  8700. * @listens Player#texttrackchange
  8701. * @listens Player#fullscreenchange
  8702. */
  8703. TextTrackDisplay.prototype.updateDisplay = function updateDisplay() {
  8704. var tracks = this.player_.textTracks();
  8705. this.clearDisplay();
  8706. // Track display prioritization model: if multiple tracks are 'showing',
  8707. // display the first 'subtitles' or 'captions' track which is 'showing',
  8708. // otherwise display the first 'descriptions' track which is 'showing'
  8709. var descriptionsTrack = null;
  8710. var captionsSubtitlesTrack = null;
  8711. var i = tracks.length;
  8712. while (i--) {
  8713. var track = tracks[i];
  8714. if (track.mode === 'showing') {
  8715. if (track.kind === 'descriptions') {
  8716. descriptionsTrack = track;
  8717. } else {
  8718. captionsSubtitlesTrack = track;
  8719. }
  8720. }
  8721. }
  8722. if (captionsSubtitlesTrack) {
  8723. if (this.getAttribute('aria-live') !== 'off') {
  8724. this.setAttribute('aria-live', 'off');
  8725. }
  8726. this.updateForTrack(captionsSubtitlesTrack);
  8727. } else if (descriptionsTrack) {
  8728. if (this.getAttribute('aria-live') !== 'assertive') {
  8729. this.setAttribute('aria-live', 'assertive');
  8730. }
  8731. this.updateForTrack(descriptionsTrack);
  8732. }
  8733. };
  8734. /**
  8735. * Add an {@link Texttrack} to to the {@link Tech}s {@link TextTrackList}.
  8736. *
  8737. * @param {TextTrack} track
  8738. * Text track object to be added to the list.
  8739. */
  8740. TextTrackDisplay.prototype.updateForTrack = function updateForTrack(track) {
  8741. if (typeof window.WebVTT !== 'function' || !track.activeCues) {
  8742. return;
  8743. }
  8744. var cues = [];
  8745. for (var _i = 0; _i < track.activeCues.length; _i++) {
  8746. cues.push(track.activeCues[_i]);
  8747. }
  8748. window.WebVTT.processCues(window, cues, this.el_);
  8749. if (!this.player_.textTrackSettings) {
  8750. return;
  8751. }
  8752. var overrides = this.player_.textTrackSettings.getValues();
  8753. var i = cues.length;
  8754. while (i--) {
  8755. var cue = cues[i];
  8756. if (!cue) {
  8757. continue;
  8758. }
  8759. var cueDiv = cue.displayState;
  8760. if (overrides.color) {
  8761. cueDiv.firstChild.style.color = overrides.color;
  8762. }
  8763. if (overrides.textOpacity) {
  8764. tryUpdateStyle(cueDiv.firstChild, 'color', constructColor(overrides.color || '#fff', overrides.textOpacity));
  8765. }
  8766. if (overrides.backgroundColor) {
  8767. cueDiv.firstChild.style.backgroundColor = overrides.backgroundColor;
  8768. }
  8769. if (overrides.backgroundOpacity) {
  8770. tryUpdateStyle(cueDiv.firstChild, 'backgroundColor', constructColor(overrides.backgroundColor || '#000', overrides.backgroundOpacity));
  8771. }
  8772. if (overrides.windowColor) {
  8773. if (overrides.windowOpacity) {
  8774. tryUpdateStyle(cueDiv, 'backgroundColor', constructColor(overrides.windowColor, overrides.windowOpacity));
  8775. } else {
  8776. cueDiv.style.backgroundColor = overrides.windowColor;
  8777. }
  8778. }
  8779. if (overrides.edgeStyle) {
  8780. if (overrides.edgeStyle === 'dropshadow') {
  8781. cueDiv.firstChild.style.textShadow = '2px 2px 3px ' + darkGray + ', 2px 2px 4px ' + darkGray + ', 2px 2px 5px ' + darkGray;
  8782. } else if (overrides.edgeStyle === 'raised') {
  8783. cueDiv.firstChild.style.textShadow = '1px 1px ' + darkGray + ', 2px 2px ' + darkGray + ', 3px 3px ' + darkGray;
  8784. } else if (overrides.edgeStyle === 'depressed') {
  8785. cueDiv.firstChild.style.textShadow = '1px 1px ' + lightGray + ', 0 1px ' + lightGray + ', -1px -1px ' + darkGray + ', 0 -1px ' + darkGray;
  8786. } else if (overrides.edgeStyle === 'uniform') {
  8787. cueDiv.firstChild.style.textShadow = '0 0 4px ' + darkGray + ', 0 0 4px ' + darkGray + ', 0 0 4px ' + darkGray + ', 0 0 4px ' + darkGray;
  8788. }
  8789. }
  8790. if (overrides.fontPercent && overrides.fontPercent !== 1) {
  8791. var fontSize = window.parseFloat(cueDiv.style.fontSize);
  8792. cueDiv.style.fontSize = fontSize * overrides.fontPercent + 'px';
  8793. cueDiv.style.height = 'auto';
  8794. cueDiv.style.top = 'auto';
  8795. cueDiv.style.bottom = '2px';
  8796. }
  8797. if (overrides.fontFamily && overrides.fontFamily !== 'default') {
  8798. if (overrides.fontFamily === 'small-caps') {
  8799. cueDiv.firstChild.style.fontVariant = 'small-caps';
  8800. } else {
  8801. cueDiv.firstChild.style.fontFamily = fontMap[overrides.fontFamily];
  8802. }
  8803. }
  8804. }
  8805. };
  8806. return TextTrackDisplay;
  8807. }(Component);
  8808. Component.registerComponent('TextTrackDisplay', TextTrackDisplay);
  8809. /**
  8810. * @file loading-spinner.js
  8811. */
  8812. /**
  8813. * A loading spinner for use during waiting/loading events.
  8814. *
  8815. * @extends Component
  8816. */
  8817. var LoadingSpinner = function (_Component) {
  8818. inherits(LoadingSpinner, _Component);
  8819. function LoadingSpinner() {
  8820. classCallCheck(this, LoadingSpinner);
  8821. return possibleConstructorReturn(this, _Component.apply(this, arguments));
  8822. }
  8823. /**
  8824. * Create the `LoadingSpinner`s DOM element.
  8825. *
  8826. * @return {Element}
  8827. * The dom element that gets created.
  8828. */
  8829. LoadingSpinner.prototype.createEl = function createEl$$1() {
  8830. var isAudio = this.player_.isAudio();
  8831. var playerType = this.localize(isAudio ? 'Audio Player' : 'Video Player');
  8832. var controlText = createEl('span', {
  8833. className: 'vjs-control-text',
  8834. innerHTML: this.localize('{1} is loading.', [playerType])
  8835. });
  8836. var el = _Component.prototype.createEl.call(this, 'div', {
  8837. className: 'vjs-loading-spinner',
  8838. dir: 'ltr'
  8839. });
  8840. el.appendChild(controlText);
  8841. return el;
  8842. };
  8843. return LoadingSpinner;
  8844. }(Component);
  8845. Component.registerComponent('LoadingSpinner', LoadingSpinner);
  8846. /**
  8847. * @file button.js
  8848. */
  8849. /**
  8850. * Base class for all buttons.
  8851. *
  8852. * @extends ClickableComponent
  8853. */
  8854. var Button = function (_ClickableComponent) {
  8855. inherits(Button, _ClickableComponent);
  8856. function Button() {
  8857. classCallCheck(this, Button);
  8858. return possibleConstructorReturn(this, _ClickableComponent.apply(this, arguments));
  8859. }
  8860. /**
  8861. * Create the `Button`s DOM element.
  8862. *
  8863. * @param {string} [tag="button"]
  8864. * The element's node type. This argument is IGNORED: no matter what
  8865. * is passed, it will always create a `button` element.
  8866. *
  8867. * @param {Object} [props={}]
  8868. * An object of properties that should be set on the element.
  8869. *
  8870. * @param {Object} [attributes={}]
  8871. * An object of attributes that should be set on the element.
  8872. *
  8873. * @return {Element}
  8874. * The element that gets created.
  8875. */
  8876. Button.prototype.createEl = function createEl(tag) {
  8877. var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  8878. var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  8879. tag = 'button';
  8880. props = assign({
  8881. innerHTML: '<span aria-hidden="true" class="vjs-icon-placeholder"></span>',
  8882. className: this.buildCSSClass()
  8883. }, props);
  8884. // Add attributes for button element
  8885. attributes = assign({
  8886. // Necessary since the default button type is "submit"
  8887. type: 'button'
  8888. }, attributes);
  8889. var el = Component.prototype.createEl.call(this, tag, props, attributes);
  8890. this.createControlTextEl(el);
  8891. return el;
  8892. };
  8893. /**
  8894. * Add a child `Component` inside of this `Button`.
  8895. *
  8896. * @param {string|Component} child
  8897. * The name or instance of a child to add.
  8898. *
  8899. * @param {Object} [options={}]
  8900. * The key/value store of options that will get passed to children of
  8901. * the child.
  8902. *
  8903. * @return {Component}
  8904. * The `Component` that gets added as a child. When using a string the
  8905. * `Component` will get created by this process.
  8906. *
  8907. * @deprecated since version 5
  8908. */
  8909. Button.prototype.addChild = function addChild(child) {
  8910. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  8911. var className = this.constructor.name;
  8912. log.warn('Adding an actionable (user controllable) child to a Button (' + className + ') is not supported; use a ClickableComponent instead.');
  8913. // Avoid the error message generated by ClickableComponent's addChild method
  8914. return Component.prototype.addChild.call(this, child, options);
  8915. };
  8916. /**
  8917. * Enable the `Button` element so that it can be activated or clicked. Use this with
  8918. * {@link Button#disable}.
  8919. */
  8920. Button.prototype.enable = function enable() {
  8921. _ClickableComponent.prototype.enable.call(this);
  8922. this.el_.removeAttribute('disabled');
  8923. };
  8924. /**
  8925. * Disable the `Button` element so that it cannot be activated or clicked. Use this with
  8926. * {@link Button#enable}.
  8927. */
  8928. Button.prototype.disable = function disable() {
  8929. _ClickableComponent.prototype.disable.call(this);
  8930. this.el_.setAttribute('disabled', 'disabled');
  8931. };
  8932. /**
  8933. * This gets called when a `Button` has focus and `keydown` is triggered via a key
  8934. * press.
  8935. *
  8936. * @param {EventTarget~Event} event
  8937. * The event that caused this function to get called.
  8938. *
  8939. * @listens keydown
  8940. */
  8941. Button.prototype.handleKeyPress = function handleKeyPress(event) {
  8942. // Ignore Space (32) or Enter (13) key operation, which is handled by the browser for a button.
  8943. if (event.which === 32 || event.which === 13) {
  8944. return;
  8945. }
  8946. // Pass keypress handling up for unsupported keys
  8947. _ClickableComponent.prototype.handleKeyPress.call(this, event);
  8948. };
  8949. return Button;
  8950. }(ClickableComponent);
  8951. Component.registerComponent('Button', Button);
  8952. /**
  8953. * @file big-play-button.js
  8954. */
  8955. /**
  8956. * The initial play button that shows before the video has played. The hiding of the
  8957. * `BigPlayButton` get done via CSS and `Player` states.
  8958. *
  8959. * @extends Button
  8960. */
  8961. var BigPlayButton = function (_Button) {
  8962. inherits(BigPlayButton, _Button);
  8963. function BigPlayButton(player, options) {
  8964. classCallCheck(this, BigPlayButton);
  8965. var _this = possibleConstructorReturn(this, _Button.call(this, player, options));
  8966. _this.mouseused_ = false;
  8967. _this.on('mousedown', _this.handleMouseDown);
  8968. return _this;
  8969. }
  8970. /**
  8971. * Builds the default DOM `className`.
  8972. *
  8973. * @return {string}
  8974. * The DOM `className` for this object. Always returns 'vjs-big-play-button'.
  8975. */
  8976. BigPlayButton.prototype.buildCSSClass = function buildCSSClass() {
  8977. return 'vjs-big-play-button';
  8978. };
  8979. /**
  8980. * This gets called when a `BigPlayButton` "clicked". See {@link ClickableComponent}
  8981. * for more detailed information on what a click can be.
  8982. *
  8983. * @param {EventTarget~Event} event
  8984. * The `keydown`, `tap`, or `click` event that caused this function to be
  8985. * called.
  8986. *
  8987. * @listens tap
  8988. * @listens click
  8989. */
  8990. BigPlayButton.prototype.handleClick = function handleClick(event) {
  8991. var playPromise = this.player_.play();
  8992. // exit early if clicked via the mouse
  8993. if (this.mouseused_ && event.clientX && event.clientY) {
  8994. silencePromise(playPromise);
  8995. return;
  8996. }
  8997. var cb = this.player_.getChild('controlBar');
  8998. var playToggle = cb && cb.getChild('playToggle');
  8999. if (!playToggle) {
  9000. this.player_.focus();
  9001. return;
  9002. }
  9003. var playFocus = function playFocus() {
  9004. return playToggle.focus();
  9005. };
  9006. if (isPromise(playPromise)) {
  9007. playPromise.then(playFocus, function () {});
  9008. } else {
  9009. this.setTimeout(playFocus, 1);
  9010. }
  9011. };
  9012. BigPlayButton.prototype.handleKeyPress = function handleKeyPress(event) {
  9013. this.mouseused_ = false;
  9014. _Button.prototype.handleKeyPress.call(this, event);
  9015. };
  9016. BigPlayButton.prototype.handleMouseDown = function handleMouseDown(event) {
  9017. this.mouseused_ = true;
  9018. };
  9019. return BigPlayButton;
  9020. }(Button);
  9021. /**
  9022. * The text that should display over the `BigPlayButton`s controls. Added to for localization.
  9023. *
  9024. * @type {string}
  9025. * @private
  9026. */
  9027. BigPlayButton.prototype.controlText_ = 'Play Video';
  9028. Component.registerComponent('BigPlayButton', BigPlayButton);
  9029. /**
  9030. * @file close-button.js
  9031. */
  9032. /**
  9033. * The `CloseButton` is a `{@link Button}` that fires a `close` event when
  9034. * it gets clicked.
  9035. *
  9036. * @extends Button
  9037. */
  9038. var CloseButton = function (_Button) {
  9039. inherits(CloseButton, _Button);
  9040. /**
  9041. * Creates an instance of the this class.
  9042. *
  9043. * @param {Player} player
  9044. * The `Player` that this class should be attached to.
  9045. *
  9046. * @param {Object} [options]
  9047. * The key/value store of player options.
  9048. */
  9049. function CloseButton(player, options) {
  9050. classCallCheck(this, CloseButton);
  9051. var _this = possibleConstructorReturn(this, _Button.call(this, player, options));
  9052. _this.controlText(options && options.controlText || _this.localize('Close'));
  9053. return _this;
  9054. }
  9055. /**
  9056. * Builds the default DOM `className`.
  9057. *
  9058. * @return {string}
  9059. * The DOM `className` for this object.
  9060. */
  9061. CloseButton.prototype.buildCSSClass = function buildCSSClass() {
  9062. return 'vjs-close-button ' + _Button.prototype.buildCSSClass.call(this);
  9063. };
  9064. /**
  9065. * This gets called when a `CloseButton` gets clicked. See
  9066. * {@link ClickableComponent#handleClick} for more information on when this will be
  9067. * triggered
  9068. *
  9069. * @param {EventTarget~Event} event
  9070. * The `keydown`, `tap`, or `click` event that caused this function to be
  9071. * called.
  9072. *
  9073. * @listens tap
  9074. * @listens click
  9075. * @fires CloseButton#close
  9076. */
  9077. CloseButton.prototype.handleClick = function handleClick(event) {
  9078. /**
  9079. * Triggered when the a `CloseButton` is clicked.
  9080. *
  9081. * @event CloseButton#close
  9082. * @type {EventTarget~Event}
  9083. *
  9084. * @property {boolean} [bubbles=false]
  9085. * set to false so that the close event does not
  9086. * bubble up to parents if there is no listener
  9087. */
  9088. this.trigger({ type: 'close', bubbles: false });
  9089. };
  9090. return CloseButton;
  9091. }(Button);
  9092. Component.registerComponent('CloseButton', CloseButton);
  9093. /**
  9094. * @file play-toggle.js
  9095. */
  9096. /**
  9097. * Button to toggle between play and pause.
  9098. *
  9099. * @extends Button
  9100. */
  9101. var PlayToggle = function (_Button) {
  9102. inherits(PlayToggle, _Button);
  9103. /**
  9104. * Creates an instance of this class.
  9105. *
  9106. * @param {Player} player
  9107. * The `Player` that this class should be attached to.
  9108. *
  9109. * @param {Object} [options]
  9110. * The key/value store of player options.
  9111. */
  9112. function PlayToggle(player, options) {
  9113. classCallCheck(this, PlayToggle);
  9114. var _this = possibleConstructorReturn(this, _Button.call(this, player, options));
  9115. _this.on(player, 'play', _this.handlePlay);
  9116. _this.on(player, 'pause', _this.handlePause);
  9117. _this.on(player, 'ended', _this.handleEnded);
  9118. return _this;
  9119. }
  9120. /**
  9121. * Builds the default DOM `className`.
  9122. *
  9123. * @return {string}
  9124. * The DOM `className` for this object.
  9125. */
  9126. PlayToggle.prototype.buildCSSClass = function buildCSSClass() {
  9127. return 'vjs-play-control ' + _Button.prototype.buildCSSClass.call(this);
  9128. };
  9129. /**
  9130. * This gets called when an `PlayToggle` is "clicked". See
  9131. * {@link ClickableComponent} for more detailed information on what a click can be.
  9132. *
  9133. * @param {EventTarget~Event} [event]
  9134. * The `keydown`, `tap`, or `click` event that caused this function to be
  9135. * called.
  9136. *
  9137. * @listens tap
  9138. * @listens click
  9139. */
  9140. PlayToggle.prototype.handleClick = function handleClick(event) {
  9141. if (this.player_.paused()) {
  9142. this.player_.play();
  9143. } else {
  9144. this.player_.pause();
  9145. }
  9146. };
  9147. /**
  9148. * This gets called once after the video has ended and the user seeks so that
  9149. * we can change the replay button back to a play button.
  9150. *
  9151. * @param {EventTarget~Event} [event]
  9152. * The event that caused this function to run.
  9153. *
  9154. * @listens Player#seeked
  9155. */
  9156. PlayToggle.prototype.handleSeeked = function handleSeeked(event) {
  9157. this.removeClass('vjs-ended');
  9158. if (this.player_.paused()) {
  9159. this.handlePause(event);
  9160. } else {
  9161. this.handlePlay(event);
  9162. }
  9163. };
  9164. /**
  9165. * Add the vjs-playing class to the element so it can change appearance.
  9166. *
  9167. * @param {EventTarget~Event} [event]
  9168. * The event that caused this function to run.
  9169. *
  9170. * @listens Player#play
  9171. */
  9172. PlayToggle.prototype.handlePlay = function handlePlay(event) {
  9173. this.removeClass('vjs-ended');
  9174. this.removeClass('vjs-paused');
  9175. this.addClass('vjs-playing');
  9176. // change the button text to "Pause"
  9177. this.controlText('Pause');
  9178. };
  9179. /**
  9180. * Add the vjs-paused class to the element so it can change appearance.
  9181. *
  9182. * @param {EventTarget~Event} [event]
  9183. * The event that caused this function to run.
  9184. *
  9185. * @listens Player#pause
  9186. */
  9187. PlayToggle.prototype.handlePause = function handlePause(event) {
  9188. this.removeClass('vjs-playing');
  9189. this.addClass('vjs-paused');
  9190. // change the button text to "Play"
  9191. this.controlText('Play');
  9192. };
  9193. /**
  9194. * Add the vjs-ended class to the element so it can change appearance
  9195. *
  9196. * @param {EventTarget~Event} [event]
  9197. * The event that caused this function to run.
  9198. *
  9199. * @listens Player#ended
  9200. */
  9201. PlayToggle.prototype.handleEnded = function handleEnded(event) {
  9202. this.removeClass('vjs-playing');
  9203. this.addClass('vjs-ended');
  9204. // change the button text to "Replay"
  9205. this.controlText('Replay');
  9206. // on the next seek remove the replay button
  9207. this.one(this.player_, 'seeked', this.handleSeeked);
  9208. };
  9209. return PlayToggle;
  9210. }(Button);
  9211. /**
  9212. * The text that should display over the `PlayToggle`s controls. Added for localization.
  9213. *
  9214. * @type {string}
  9215. * @private
  9216. */
  9217. PlayToggle.prototype.controlText_ = 'Play';
  9218. Component.registerComponent('PlayToggle', PlayToggle);
  9219. /**
  9220. * @file format-time.js
  9221. * @module format-time
  9222. */
  9223. /**
  9224. * Format seconds as a time string, H:MM:SS or M:SS. Supplying a guide (in seconds)
  9225. * will force a number of leading zeros to cover the length of the guide.
  9226. *
  9227. * @param {number} seconds
  9228. * Number of seconds to be turned into a string
  9229. *
  9230. * @param {number} guide
  9231. * Number (in seconds) to model the string after
  9232. *
  9233. * @return {string}
  9234. * Time formatted as H:MM:SS or M:SS
  9235. */
  9236. var defaultImplementation = function defaultImplementation(seconds, guide) {
  9237. seconds = seconds < 0 ? 0 : seconds;
  9238. var s = Math.floor(seconds % 60);
  9239. var m = Math.floor(seconds / 60 % 60);
  9240. var h = Math.floor(seconds / 3600);
  9241. var gm = Math.floor(guide / 60 % 60);
  9242. var gh = Math.floor(guide / 3600);
  9243. // handle invalid times
  9244. if (isNaN(seconds) || seconds === Infinity) {
  9245. // '-' is false for all relational operators (e.g. <, >=) so this setting
  9246. // will add the minimum number of fields specified by the guide
  9247. h = m = s = '-';
  9248. }
  9249. // Check if we need to show hours
  9250. h = h > 0 || gh > 0 ? h + ':' : '';
  9251. // If hours are showing, we may need to add a leading zero.
  9252. // Always show at least one digit of minutes.
  9253. m = ((h || gm >= 10) && m < 10 ? '0' + m : m) + ':';
  9254. // Check if leading zero is need for seconds
  9255. s = s < 10 ? '0' + s : s;
  9256. return h + m + s;
  9257. };
  9258. var implementation = defaultImplementation;
  9259. /**
  9260. * Replaces the default formatTime implementation with a custom implementation.
  9261. *
  9262. * @param {Function} customImplementation
  9263. * A function which will be used in place of the default formatTime implementation.
  9264. * Will receive the current time in seconds and the guide (in seconds) as arguments.
  9265. */
  9266. function setFormatTime(customImplementation) {
  9267. implementation = customImplementation;
  9268. }
  9269. /**
  9270. * Resets formatTime to the default implementation.
  9271. */
  9272. function resetFormatTime() {
  9273. implementation = defaultImplementation;
  9274. }
  9275. var formatTime = function (seconds) {
  9276. var guide = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : seconds;
  9277. return implementation(seconds, guide);
  9278. };
  9279. /**
  9280. * @file time-display.js
  9281. */
  9282. /**
  9283. * Displays the time left in the video
  9284. *
  9285. * @extends Component
  9286. */
  9287. var TimeDisplay = function (_Component) {
  9288. inherits(TimeDisplay, _Component);
  9289. /**
  9290. * Creates an instance of this class.
  9291. *
  9292. * @param {Player} player
  9293. * The `Player` that this class should be attached to.
  9294. *
  9295. * @param {Object} [options]
  9296. * The key/value store of player options.
  9297. */
  9298. function TimeDisplay(player, options) {
  9299. classCallCheck(this, TimeDisplay);
  9300. var _this = possibleConstructorReturn(this, _Component.call(this, player, options));
  9301. _this.throttledUpdateContent = throttle(bind(_this, _this.updateContent), 25);
  9302. _this.on(player, 'timeupdate', _this.throttledUpdateContent);
  9303. return _this;
  9304. }
  9305. /**
  9306. * Create the `Component`'s DOM element
  9307. *
  9308. * @return {Element}
  9309. * The element that was created.
  9310. */
  9311. TimeDisplay.prototype.createEl = function createEl$$1(plainName) {
  9312. var className = this.buildCSSClass();
  9313. var el = _Component.prototype.createEl.call(this, 'div', {
  9314. className: className + ' vjs-time-control vjs-control',
  9315. innerHTML: '<span class="vjs-control-text">' + this.localize(this.labelText_) + '\xA0</span>'
  9316. });
  9317. this.contentEl_ = createEl('span', {
  9318. className: className + '-display'
  9319. }, {
  9320. // tell screen readers not to automatically read the time as it changes
  9321. 'aria-live': 'off'
  9322. });
  9323. this.updateTextNode_();
  9324. el.appendChild(this.contentEl_);
  9325. return el;
  9326. };
  9327. TimeDisplay.prototype.dispose = function dispose() {
  9328. this.contentEl_ = null;
  9329. this.textNode_ = null;
  9330. _Component.prototype.dispose.call(this);
  9331. };
  9332. /**
  9333. * Updates the "remaining time" text node with new content using the
  9334. * contents of the `formattedTime_` property.
  9335. *
  9336. * @private
  9337. */
  9338. TimeDisplay.prototype.updateTextNode_ = function updateTextNode_() {
  9339. if (!this.contentEl_) {
  9340. return;
  9341. }
  9342. while (this.contentEl_.firstChild) {
  9343. this.contentEl_.removeChild(this.contentEl_.firstChild);
  9344. }
  9345. this.textNode_ = document.createTextNode(this.formattedTime_ || this.formatTime_(0));
  9346. this.contentEl_.appendChild(this.textNode_);
  9347. };
  9348. /**
  9349. * Generates a formatted time for this component to use in display.
  9350. *
  9351. * @param {number} time
  9352. * A numeric time, in seconds.
  9353. *
  9354. * @return {string}
  9355. * A formatted time
  9356. *
  9357. * @private
  9358. */
  9359. TimeDisplay.prototype.formatTime_ = function formatTime_(time) {
  9360. return formatTime(time);
  9361. };
  9362. /**
  9363. * Updates the time display text node if it has what was passed in changed
  9364. * the formatted time.
  9365. *
  9366. * @param {number} time
  9367. * The time to update to
  9368. *
  9369. * @private
  9370. */
  9371. TimeDisplay.prototype.updateFormattedTime_ = function updateFormattedTime_(time) {
  9372. var formattedTime = this.formatTime_(time);
  9373. if (formattedTime === this.formattedTime_) {
  9374. return;
  9375. }
  9376. this.formattedTime_ = formattedTime;
  9377. this.requestAnimationFrame(this.updateTextNode_);
  9378. };
  9379. /**
  9380. * To be filled out in the child class, should update the displayed time
  9381. * in accordance with the fact that the current time has changed.
  9382. *
  9383. * @param {EventTarget~Event} [event]
  9384. * The `timeupdate` event that caused this to run.
  9385. *
  9386. * @listens Player#timeupdate
  9387. */
  9388. TimeDisplay.prototype.updateContent = function updateContent(event) {};
  9389. return TimeDisplay;
  9390. }(Component);
  9391. /**
  9392. * The text that is added to the `TimeDisplay` for screen reader users.
  9393. *
  9394. * @type {string}
  9395. * @private
  9396. */
  9397. TimeDisplay.prototype.labelText_ = 'Time';
  9398. /**
  9399. * The text that should display over the `TimeDisplay`s controls. Added to for localization.
  9400. *
  9401. * @type {string}
  9402. * @private
  9403. *
  9404. * @deprecated in v7; controlText_ is not used in non-active display Components
  9405. */
  9406. TimeDisplay.prototype.controlText_ = 'Time';
  9407. Component.registerComponent('TimeDisplay', TimeDisplay);
  9408. /**
  9409. * @file current-time-display.js
  9410. */
  9411. /**
  9412. * Displays the current time
  9413. *
  9414. * @extends Component
  9415. */
  9416. var CurrentTimeDisplay = function (_TimeDisplay) {
  9417. inherits(CurrentTimeDisplay, _TimeDisplay);
  9418. /**
  9419. * Creates an instance of this class.
  9420. *
  9421. * @param {Player} player
  9422. * The `Player` that this class should be attached to.
  9423. *
  9424. * @param {Object} [options]
  9425. * The key/value store of player options.
  9426. */
  9427. function CurrentTimeDisplay(player, options) {
  9428. classCallCheck(this, CurrentTimeDisplay);
  9429. var _this = possibleConstructorReturn(this, _TimeDisplay.call(this, player, options));
  9430. _this.on(player, 'ended', _this.handleEnded);
  9431. return _this;
  9432. }
  9433. /**
  9434. * Builds the default DOM `className`.
  9435. *
  9436. * @return {string}
  9437. * The DOM `className` for this object.
  9438. */
  9439. CurrentTimeDisplay.prototype.buildCSSClass = function buildCSSClass() {
  9440. return 'vjs-current-time';
  9441. };
  9442. /**
  9443. * Update current time display
  9444. *
  9445. * @param {EventTarget~Event} [event]
  9446. * The `timeupdate` event that caused this function to run.
  9447. *
  9448. * @listens Player#timeupdate
  9449. */
  9450. CurrentTimeDisplay.prototype.updateContent = function updateContent(event) {
  9451. // Allows for smooth scrubbing, when player can't keep up.
  9452. var time = this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
  9453. this.updateFormattedTime_(time);
  9454. };
  9455. /**
  9456. * When the player fires ended there should be no time left. Sadly
  9457. * this is not always the case, lets make it seem like that is the case
  9458. * for users.
  9459. *
  9460. * @param {EventTarget~Event} [event]
  9461. * The `ended` event that caused this to run.
  9462. *
  9463. * @listens Player#ended
  9464. */
  9465. CurrentTimeDisplay.prototype.handleEnded = function handleEnded(event) {
  9466. if (!this.player_.duration()) {
  9467. return;
  9468. }
  9469. this.updateFormattedTime_(this.player_.duration());
  9470. };
  9471. return CurrentTimeDisplay;
  9472. }(TimeDisplay);
  9473. /**
  9474. * The text that is added to the `CurrentTimeDisplay` for screen reader users.
  9475. *
  9476. * @type {string}
  9477. * @private
  9478. */
  9479. CurrentTimeDisplay.prototype.labelText_ = 'Current Time';
  9480. /**
  9481. * The text that should display over the `CurrentTimeDisplay`s controls. Added to for localization.
  9482. *
  9483. * @type {string}
  9484. * @private
  9485. *
  9486. * @deprecated in v7; controlText_ is not used in non-active display Components
  9487. */
  9488. CurrentTimeDisplay.prototype.controlText_ = 'Current Time';
  9489. Component.registerComponent('CurrentTimeDisplay', CurrentTimeDisplay);
  9490. /**
  9491. * @file duration-display.js
  9492. */
  9493. /**
  9494. * Displays the duration
  9495. *
  9496. * @extends Component
  9497. */
  9498. var DurationDisplay = function (_TimeDisplay) {
  9499. inherits(DurationDisplay, _TimeDisplay);
  9500. /**
  9501. * Creates an instance of this class.
  9502. *
  9503. * @param {Player} player
  9504. * The `Player` that this class should be attached to.
  9505. *
  9506. * @param {Object} [options]
  9507. * The key/value store of player options.
  9508. */
  9509. function DurationDisplay(player, options) {
  9510. classCallCheck(this, DurationDisplay);
  9511. // we do not want to/need to throttle duration changes,
  9512. // as they should always display the changed duration as
  9513. // it has changed
  9514. var _this = possibleConstructorReturn(this, _TimeDisplay.call(this, player, options));
  9515. _this.on(player, 'durationchange', _this.updateContent);
  9516. // Also listen for timeupdate (in the parent) and loadedmetadata because removing those
  9517. // listeners could have broken dependent applications/libraries. These
  9518. // can likely be removed for 7.0.
  9519. _this.on(player, 'loadedmetadata', _this.throttledUpdateContent);
  9520. return _this;
  9521. }
  9522. /**
  9523. * Builds the default DOM `className`.
  9524. *
  9525. * @return {string}
  9526. * The DOM `className` for this object.
  9527. */
  9528. DurationDisplay.prototype.buildCSSClass = function buildCSSClass() {
  9529. return 'vjs-duration';
  9530. };
  9531. /**
  9532. * Update duration time display.
  9533. *
  9534. * @param {EventTarget~Event} [event]
  9535. * The `durationchange`, `timeupdate`, or `loadedmetadata` event that caused
  9536. * this function to be called.
  9537. *
  9538. * @listens Player#durationchange
  9539. * @listens Player#timeupdate
  9540. * @listens Player#loadedmetadata
  9541. */
  9542. DurationDisplay.prototype.updateContent = function updateContent(event) {
  9543. var duration = this.player_.duration();
  9544. if (duration && this.duration_ !== duration) {
  9545. this.duration_ = duration;
  9546. this.updateFormattedTime_(duration);
  9547. }
  9548. };
  9549. return DurationDisplay;
  9550. }(TimeDisplay);
  9551. /**
  9552. * The text that is added to the `DurationDisplay` for screen reader users.
  9553. *
  9554. * @type {string}
  9555. * @private
  9556. */
  9557. DurationDisplay.prototype.labelText_ = 'Duration';
  9558. /**
  9559. * The text that should display over the `DurationDisplay`s controls. Added to for localization.
  9560. *
  9561. * @type {string}
  9562. * @private
  9563. *
  9564. * @deprecated in v7; controlText_ is not used in non-active display Components
  9565. */
  9566. DurationDisplay.prototype.controlText_ = 'Duration';
  9567. Component.registerComponent('DurationDisplay', DurationDisplay);
  9568. /**
  9569. * @file time-divider.js
  9570. */
  9571. /**
  9572. * The separator between the current time and duration.
  9573. * Can be hidden if it's not needed in the design.
  9574. *
  9575. * @extends Component
  9576. */
  9577. var TimeDivider = function (_Component) {
  9578. inherits(TimeDivider, _Component);
  9579. function TimeDivider() {
  9580. classCallCheck(this, TimeDivider);
  9581. return possibleConstructorReturn(this, _Component.apply(this, arguments));
  9582. }
  9583. /**
  9584. * Create the component's DOM element
  9585. *
  9586. * @return {Element}
  9587. * The element that was created.
  9588. */
  9589. TimeDivider.prototype.createEl = function createEl() {
  9590. return _Component.prototype.createEl.call(this, 'div', {
  9591. className: 'vjs-time-control vjs-time-divider',
  9592. innerHTML: '<div><span>/</span></div>'
  9593. });
  9594. };
  9595. return TimeDivider;
  9596. }(Component);
  9597. Component.registerComponent('TimeDivider', TimeDivider);
  9598. /**
  9599. * @file remaining-time-display.js
  9600. */
  9601. /**
  9602. * Displays the time left in the video
  9603. *
  9604. * @extends Component
  9605. */
  9606. var RemainingTimeDisplay = function (_TimeDisplay) {
  9607. inherits(RemainingTimeDisplay, _TimeDisplay);
  9608. /**
  9609. * Creates an instance of this class.
  9610. *
  9611. * @param {Player} player
  9612. * The `Player` that this class should be attached to.
  9613. *
  9614. * @param {Object} [options]
  9615. * The key/value store of player options.
  9616. */
  9617. function RemainingTimeDisplay(player, options) {
  9618. classCallCheck(this, RemainingTimeDisplay);
  9619. var _this = possibleConstructorReturn(this, _TimeDisplay.call(this, player, options));
  9620. _this.on(player, 'durationchange', _this.throttledUpdateContent);
  9621. _this.on(player, 'ended', _this.handleEnded);
  9622. return _this;
  9623. }
  9624. /**
  9625. * Builds the default DOM `className`.
  9626. *
  9627. * @return {string}
  9628. * The DOM `className` for this object.
  9629. */
  9630. RemainingTimeDisplay.prototype.buildCSSClass = function buildCSSClass() {
  9631. return 'vjs-remaining-time';
  9632. };
  9633. /**
  9634. * The remaining time display prefixes numbers with a "minus" character.
  9635. *
  9636. * @param {number} time
  9637. * A numeric time, in seconds.
  9638. *
  9639. * @return {string}
  9640. * A formatted time
  9641. *
  9642. * @private
  9643. */
  9644. RemainingTimeDisplay.prototype.formatTime_ = function formatTime_(time) {
  9645. // TODO: The "-" should be decorative, and not announced by a screen reader
  9646. return '-' + _TimeDisplay.prototype.formatTime_.call(this, time);
  9647. };
  9648. /**
  9649. * Update remaining time display.
  9650. *
  9651. * @param {EventTarget~Event} [event]
  9652. * The `timeupdate` or `durationchange` event that caused this to run.
  9653. *
  9654. * @listens Player#timeupdate
  9655. * @listens Player#durationchange
  9656. */
  9657. RemainingTimeDisplay.prototype.updateContent = function updateContent(event) {
  9658. if (!this.player_.duration()) {
  9659. return;
  9660. }
  9661. // @deprecated We should only use remainingTimeDisplay
  9662. // as of video.js 7
  9663. if (this.player_.remainingTimeDisplay) {
  9664. this.updateFormattedTime_(this.player_.remainingTimeDisplay());
  9665. } else {
  9666. this.updateFormattedTime_(this.player_.remainingTime());
  9667. }
  9668. };
  9669. /**
  9670. * When the player fires ended there should be no time left. Sadly
  9671. * this is not always the case, lets make it seem like that is the case
  9672. * for users.
  9673. *
  9674. * @param {EventTarget~Event} [event]
  9675. * The `ended` event that caused this to run.
  9676. *
  9677. * @listens Player#ended
  9678. */
  9679. RemainingTimeDisplay.prototype.handleEnded = function handleEnded(event) {
  9680. if (!this.player_.duration()) {
  9681. return;
  9682. }
  9683. this.updateFormattedTime_(0);
  9684. };
  9685. return RemainingTimeDisplay;
  9686. }(TimeDisplay);
  9687. /**
  9688. * The text that is added to the `RemainingTimeDisplay` for screen reader users.
  9689. *
  9690. * @type {string}
  9691. * @private
  9692. */
  9693. RemainingTimeDisplay.prototype.labelText_ = 'Remaining Time';
  9694. /**
  9695. * The text that should display over the `RemainingTimeDisplay`s controls. Added to for localization.
  9696. *
  9697. * @type {string}
  9698. * @private
  9699. *
  9700. * @deprecated in v7; controlText_ is not used in non-active display Components
  9701. */
  9702. RemainingTimeDisplay.prototype.controlText_ = 'Remaining Time';
  9703. Component.registerComponent('RemainingTimeDisplay', RemainingTimeDisplay);
  9704. /**
  9705. * @file live-display.js
  9706. */
  9707. // TODO - Future make it click to snap to live
  9708. /**
  9709. * Displays the live indicator when duration is Infinity.
  9710. *
  9711. * @extends Component
  9712. */
  9713. var LiveDisplay = function (_Component) {
  9714. inherits(LiveDisplay, _Component);
  9715. /**
  9716. * Creates an instance of this class.
  9717. *
  9718. * @param {Player} player
  9719. * The `Player` that this class should be attached to.
  9720. *
  9721. * @param {Object} [options]
  9722. * The key/value store of player options.
  9723. */
  9724. function LiveDisplay(player, options) {
  9725. classCallCheck(this, LiveDisplay);
  9726. var _this = possibleConstructorReturn(this, _Component.call(this, player, options));
  9727. _this.updateShowing();
  9728. _this.on(_this.player(), 'durationchange', _this.updateShowing);
  9729. return _this;
  9730. }
  9731. /**
  9732. * Create the `Component`'s DOM element
  9733. *
  9734. * @return {Element}
  9735. * The element that was created.
  9736. */
  9737. LiveDisplay.prototype.createEl = function createEl$$1() {
  9738. var el = _Component.prototype.createEl.call(this, 'div', {
  9739. className: 'vjs-live-control vjs-control'
  9740. });
  9741. this.contentEl_ = createEl('div', {
  9742. className: 'vjs-live-display',
  9743. innerHTML: '<span class="vjs-control-text">' + this.localize('Stream Type') + '\xA0</span>' + this.localize('LIVE')
  9744. }, {
  9745. 'aria-live': 'off'
  9746. });
  9747. el.appendChild(this.contentEl_);
  9748. return el;
  9749. };
  9750. LiveDisplay.prototype.dispose = function dispose() {
  9751. this.contentEl_ = null;
  9752. _Component.prototype.dispose.call(this);
  9753. };
  9754. /**
  9755. * Check the duration to see if the LiveDisplay should be showing or not. Then show/hide
  9756. * it accordingly
  9757. *
  9758. * @param {EventTarget~Event} [event]
  9759. * The {@link Player#durationchange} event that caused this function to run.
  9760. *
  9761. * @listens Player#durationchange
  9762. */
  9763. LiveDisplay.prototype.updateShowing = function updateShowing(event) {
  9764. if (this.player().duration() === Infinity) {
  9765. this.show();
  9766. } else {
  9767. this.hide();
  9768. }
  9769. };
  9770. return LiveDisplay;
  9771. }(Component);
  9772. Component.registerComponent('LiveDisplay', LiveDisplay);
  9773. /**
  9774. * @file slider.js
  9775. */
  9776. /**
  9777. * The base functionality for a slider. Can be vertical or horizontal.
  9778. * For instance the volume bar or the seek bar on a video is a slider.
  9779. *
  9780. * @extends Component
  9781. */
  9782. var Slider = function (_Component) {
  9783. inherits(Slider, _Component);
  9784. /**
  9785. * Create an instance of this class
  9786. *
  9787. * @param {Player} player
  9788. * The `Player` that this class should be attached to.
  9789. *
  9790. * @param {Object} [options]
  9791. * The key/value store of player options.
  9792. */
  9793. function Slider(player, options) {
  9794. classCallCheck(this, Slider);
  9795. // Set property names to bar to match with the child Slider class is looking for
  9796. var _this = possibleConstructorReturn(this, _Component.call(this, player, options));
  9797. _this.bar = _this.getChild(_this.options_.barName);
  9798. // Set a horizontal or vertical class on the slider depending on the slider type
  9799. _this.vertical(!!_this.options_.vertical);
  9800. _this.enable();
  9801. return _this;
  9802. }
  9803. /**
  9804. * Are controls are currently enabled for this slider or not.
  9805. *
  9806. * @return {boolean}
  9807. * true if controls are enabled, false otherwise
  9808. */
  9809. Slider.prototype.enabled = function enabled() {
  9810. return this.enabled_;
  9811. };
  9812. /**
  9813. * Enable controls for this slider if they are disabled
  9814. */
  9815. Slider.prototype.enable = function enable() {
  9816. if (this.enabled()) {
  9817. return;
  9818. }
  9819. this.on('mousedown', this.handleMouseDown);
  9820. this.on('touchstart', this.handleMouseDown);
  9821. this.on('focus', this.handleFocus);
  9822. this.on('blur', this.handleBlur);
  9823. this.on('click', this.handleClick);
  9824. this.on(this.player_, 'controlsvisible', this.update);
  9825. if (this.playerEvent) {
  9826. this.on(this.player_, this.playerEvent, this.update);
  9827. }
  9828. this.removeClass('disabled');
  9829. this.setAttribute('tabindex', 0);
  9830. this.enabled_ = true;
  9831. };
  9832. /**
  9833. * Disable controls for this slider if they are enabled
  9834. */
  9835. Slider.prototype.disable = function disable() {
  9836. if (!this.enabled()) {
  9837. return;
  9838. }
  9839. var doc = this.bar.el_.ownerDocument;
  9840. this.off('mousedown', this.handleMouseDown);
  9841. this.off('touchstart', this.handleMouseDown);
  9842. this.off('focus', this.handleFocus);
  9843. this.off('blur', this.handleBlur);
  9844. this.off('click', this.handleClick);
  9845. this.off(this.player_, 'controlsvisible', this.update);
  9846. this.off(doc, 'mousemove', this.handleMouseMove);
  9847. this.off(doc, 'mouseup', this.handleMouseUp);
  9848. this.off(doc, 'touchmove', this.handleMouseMove);
  9849. this.off(doc, 'touchend', this.handleMouseUp);
  9850. this.removeAttribute('tabindex');
  9851. this.addClass('disabled');
  9852. if (this.playerEvent) {
  9853. this.off(this.player_, this.playerEvent, this.update);
  9854. }
  9855. this.enabled_ = false;
  9856. };
  9857. /**
  9858. * Create the `Button`s DOM element.
  9859. *
  9860. * @param {string} type
  9861. * Type of element to create.
  9862. *
  9863. * @param {Object} [props={}]
  9864. * List of properties in Object form.
  9865. *
  9866. * @param {Object} [attributes={}]
  9867. * list of attributes in Object form.
  9868. *
  9869. * @return {Element}
  9870. * The element that gets created.
  9871. */
  9872. Slider.prototype.createEl = function createEl$$1(type) {
  9873. var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  9874. var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  9875. // Add the slider element class to all sub classes
  9876. props.className = props.className + ' vjs-slider';
  9877. props = assign({
  9878. tabIndex: 0
  9879. }, props);
  9880. attributes = assign({
  9881. 'role': 'slider',
  9882. 'aria-valuenow': 0,
  9883. 'aria-valuemin': 0,
  9884. 'aria-valuemax': 100,
  9885. 'tabIndex': 0
  9886. }, attributes);
  9887. return _Component.prototype.createEl.call(this, type, props, attributes);
  9888. };
  9889. /**
  9890. * Handle `mousedown` or `touchstart` events on the `Slider`.
  9891. *
  9892. * @param {EventTarget~Event} event
  9893. * `mousedown` or `touchstart` event that triggered this function
  9894. *
  9895. * @listens mousedown
  9896. * @listens touchstart
  9897. * @fires Slider#slideractive
  9898. */
  9899. Slider.prototype.handleMouseDown = function handleMouseDown(event) {
  9900. var doc = this.bar.el_.ownerDocument;
  9901. if (event.type === 'mousedown') {
  9902. event.preventDefault();
  9903. }
  9904. // Do not call preventDefault() on touchstart in Chrome
  9905. // to avoid console warnings. Use a 'touch-action: none' style
  9906. // instead to prevent unintented scrolling.
  9907. // https://developers.google.com/web/updates/2017/01/scrolling-intervention
  9908. if (event.type === 'touchstart' && !IS_CHROME) {
  9909. event.preventDefault();
  9910. }
  9911. blockTextSelection();
  9912. this.addClass('vjs-sliding');
  9913. /**
  9914. * Triggered when the slider is in an active state
  9915. *
  9916. * @event Slider#slideractive
  9917. * @type {EventTarget~Event}
  9918. */
  9919. this.trigger('slideractive');
  9920. this.on(doc, 'mousemove', this.handleMouseMove);
  9921. this.on(doc, 'mouseup', this.handleMouseUp);
  9922. this.on(doc, 'touchmove', this.handleMouseMove);
  9923. this.on(doc, 'touchend', this.handleMouseUp);
  9924. this.handleMouseMove(event);
  9925. };
  9926. /**
  9927. * Handle the `mousemove`, `touchmove`, and `mousedown` events on this `Slider`.
  9928. * The `mousemove` and `touchmove` events will only only trigger this function during
  9929. * `mousedown` and `touchstart`. This is due to {@link Slider#handleMouseDown} and
  9930. * {@link Slider#handleMouseUp}.
  9931. *
  9932. * @param {EventTarget~Event} event
  9933. * `mousedown`, `mousemove`, `touchstart`, or `touchmove` event that triggered
  9934. * this function
  9935. *
  9936. * @listens mousemove
  9937. * @listens touchmove
  9938. */
  9939. Slider.prototype.handleMouseMove = function handleMouseMove(event) {};
  9940. /**
  9941. * Handle `mouseup` or `touchend` events on the `Slider`.
  9942. *
  9943. * @param {EventTarget~Event} event
  9944. * `mouseup` or `touchend` event that triggered this function.
  9945. *
  9946. * @listens touchend
  9947. * @listens mouseup
  9948. * @fires Slider#sliderinactive
  9949. */
  9950. Slider.prototype.handleMouseUp = function handleMouseUp() {
  9951. var doc = this.bar.el_.ownerDocument;
  9952. unblockTextSelection();
  9953. this.removeClass('vjs-sliding');
  9954. /**
  9955. * Triggered when the slider is no longer in an active state.
  9956. *
  9957. * @event Slider#sliderinactive
  9958. * @type {EventTarget~Event}
  9959. */
  9960. this.trigger('sliderinactive');
  9961. this.off(doc, 'mousemove', this.handleMouseMove);
  9962. this.off(doc, 'mouseup', this.handleMouseUp);
  9963. this.off(doc, 'touchmove', this.handleMouseMove);
  9964. this.off(doc, 'touchend', this.handleMouseUp);
  9965. this.update();
  9966. };
  9967. /**
  9968. * Update the progress bar of the `Slider`.
  9969. *
  9970. * @returns {number}
  9971. * The percentage of progress the progress bar represents as a
  9972. * number from 0 to 1.
  9973. */
  9974. Slider.prototype.update = function update() {
  9975. // In VolumeBar init we have a setTimeout for update that pops and update
  9976. // to the end of the execution stack. The player is destroyed before then
  9977. // update will cause an error
  9978. if (!this.el_) {
  9979. return;
  9980. }
  9981. // If scrubbing, we could use a cached value to make the handle keep up
  9982. // with the user's mouse. On HTML5 browsers scrubbing is really smooth, but
  9983. // some flash players are slow, so we might want to utilize this later.
  9984. // var progress = (this.player_.scrubbing()) ? this.player_.getCache().currentTime / this.player_.duration() : this.player_.currentTime() / this.player_.duration();
  9985. var progress = this.getPercent();
  9986. var bar = this.bar;
  9987. // If there's no bar...
  9988. if (!bar) {
  9989. return;
  9990. }
  9991. // Protect against no duration and other division issues
  9992. if (typeof progress !== 'number' || progress !== progress || progress < 0 || progress === Infinity) {
  9993. progress = 0;
  9994. }
  9995. // Convert to a percentage for setting
  9996. var percentage = (progress * 100).toFixed(2) + '%';
  9997. var style = bar.el().style;
  9998. // Set the new bar width or height
  9999. if (this.vertical()) {
  10000. style.height = percentage;
  10001. } else {
  10002. style.width = percentage;
  10003. }
  10004. return progress;
  10005. };
  10006. /**
  10007. * Calculate distance for slider
  10008. *
  10009. * @param {EventTarget~Event} event
  10010. * The event that caused this function to run.
  10011. *
  10012. * @return {number}
  10013. * The current position of the Slider.
  10014. * - postition.x for vertical `Slider`s
  10015. * - postition.y for horizontal `Slider`s
  10016. */
  10017. Slider.prototype.calculateDistance = function calculateDistance(event) {
  10018. var position = getPointerPosition(this.el_, event);
  10019. if (this.vertical()) {
  10020. return position.y;
  10021. }
  10022. return position.x;
  10023. };
  10024. /**
  10025. * Handle a `focus` event on this `Slider`.
  10026. *
  10027. * @param {EventTarget~Event} event
  10028. * The `focus` event that caused this function to run.
  10029. *
  10030. * @listens focus
  10031. */
  10032. Slider.prototype.handleFocus = function handleFocus() {
  10033. this.on(this.bar.el_.ownerDocument, 'keydown', this.handleKeyPress);
  10034. };
  10035. /**
  10036. * Handle a `keydown` event on the `Slider`. Watches for left, rigth, up, and down
  10037. * arrow keys. This function will only be called when the slider has focus. See
  10038. * {@link Slider#handleFocus} and {@link Slider#handleBlur}.
  10039. *
  10040. * @param {EventTarget~Event} event
  10041. * the `keydown` event that caused this function to run.
  10042. *
  10043. * @listens keydown
  10044. */
  10045. Slider.prototype.handleKeyPress = function handleKeyPress(event) {
  10046. // Left and Down Arrows
  10047. if (event.which === 37 || event.which === 40) {
  10048. event.preventDefault();
  10049. this.stepBack();
  10050. // Up and Right Arrows
  10051. } else if (event.which === 38 || event.which === 39) {
  10052. event.preventDefault();
  10053. this.stepForward();
  10054. }
  10055. };
  10056. /**
  10057. * Handle a `blur` event on this `Slider`.
  10058. *
  10059. * @param {EventTarget~Event} event
  10060. * The `blur` event that caused this function to run.
  10061. *
  10062. * @listens blur
  10063. */
  10064. Slider.prototype.handleBlur = function handleBlur() {
  10065. this.off(this.bar.el_.ownerDocument, 'keydown', this.handleKeyPress);
  10066. };
  10067. /**
  10068. * Listener for click events on slider, used to prevent clicks
  10069. * from bubbling up to parent elements like button menus.
  10070. *
  10071. * @param {Object} event
  10072. * Event that caused this object to run
  10073. */
  10074. Slider.prototype.handleClick = function handleClick(event) {
  10075. event.stopImmediatePropagation();
  10076. event.preventDefault();
  10077. };
  10078. /**
  10079. * Get/set if slider is horizontal for vertical
  10080. *
  10081. * @param {boolean} [bool]
  10082. * - true if slider is vertical,
  10083. * - false is horizontal
  10084. *
  10085. * @return {boolean}
  10086. * - true if slider is vertical, and getting
  10087. * - false if the slider is horizontal, and getting
  10088. */
  10089. Slider.prototype.vertical = function vertical(bool) {
  10090. if (bool === undefined) {
  10091. return this.vertical_ || false;
  10092. }
  10093. this.vertical_ = !!bool;
  10094. if (this.vertical_) {
  10095. this.addClass('vjs-slider-vertical');
  10096. } else {
  10097. this.addClass('vjs-slider-horizontal');
  10098. }
  10099. };
  10100. return Slider;
  10101. }(Component);
  10102. Component.registerComponent('Slider', Slider);
  10103. /**
  10104. * @file load-progress-bar.js
  10105. */
  10106. /**
  10107. * Shows loading progress
  10108. *
  10109. * @extends Component
  10110. */
  10111. var LoadProgressBar = function (_Component) {
  10112. inherits(LoadProgressBar, _Component);
  10113. /**
  10114. * Creates an instance of this class.
  10115. *
  10116. * @param {Player} player
  10117. * The `Player` that this class should be attached to.
  10118. *
  10119. * @param {Object} [options]
  10120. * The key/value store of player options.
  10121. */
  10122. function LoadProgressBar(player, options) {
  10123. classCallCheck(this, LoadProgressBar);
  10124. var _this = possibleConstructorReturn(this, _Component.call(this, player, options));
  10125. _this.partEls_ = [];
  10126. _this.on(player, 'progress', _this.update);
  10127. return _this;
  10128. }
  10129. /**
  10130. * Create the `Component`'s DOM element
  10131. *
  10132. * @return {Element}
  10133. * The element that was created.
  10134. */
  10135. LoadProgressBar.prototype.createEl = function createEl$$1() {
  10136. return _Component.prototype.createEl.call(this, 'div', {
  10137. className: 'vjs-load-progress',
  10138. innerHTML: '<span class="vjs-control-text"><span>' + this.localize('Loaded') + '</span>: 0%</span>'
  10139. });
  10140. };
  10141. LoadProgressBar.prototype.dispose = function dispose() {
  10142. this.partEls_ = null;
  10143. _Component.prototype.dispose.call(this);
  10144. };
  10145. /**
  10146. * Update progress bar
  10147. *
  10148. * @param {EventTarget~Event} [event]
  10149. * The `progress` event that caused this function to run.
  10150. *
  10151. * @listens Player#progress
  10152. */
  10153. LoadProgressBar.prototype.update = function update(event) {
  10154. var buffered = this.player_.buffered();
  10155. var duration = this.player_.duration();
  10156. var bufferedEnd = this.player_.bufferedEnd();
  10157. var children = this.partEls_;
  10158. // get the percent width of a time compared to the total end
  10159. var percentify = function percentify(time, end) {
  10160. // no NaN
  10161. var percent = time / end || 0;
  10162. return (percent >= 1 ? 1 : percent) * 100 + '%';
  10163. };
  10164. // update the width of the progress bar
  10165. this.el_.style.width = percentify(bufferedEnd, duration);
  10166. // add child elements to represent the individual buffered time ranges
  10167. for (var i = 0; i < buffered.length; i++) {
  10168. var start = buffered.start(i);
  10169. var end = buffered.end(i);
  10170. var part = children[i];
  10171. if (!part) {
  10172. part = this.el_.appendChild(createEl());
  10173. children[i] = part;
  10174. }
  10175. // set the percent based on the width of the progress bar (bufferedEnd)
  10176. part.style.left = percentify(start, bufferedEnd);
  10177. part.style.width = percentify(end - start, bufferedEnd);
  10178. }
  10179. // remove unused buffered range elements
  10180. for (var _i = children.length; _i > buffered.length; _i--) {
  10181. this.el_.removeChild(children[_i - 1]);
  10182. }
  10183. children.length = buffered.length;
  10184. };
  10185. return LoadProgressBar;
  10186. }(Component);
  10187. Component.registerComponent('LoadProgressBar', LoadProgressBar);
  10188. /**
  10189. * @file time-tooltip.js
  10190. */
  10191. /**
  10192. * Time tooltips display a time above the progress bar.
  10193. *
  10194. * @extends Component
  10195. */
  10196. var TimeTooltip = function (_Component) {
  10197. inherits(TimeTooltip, _Component);
  10198. function TimeTooltip() {
  10199. classCallCheck(this, TimeTooltip);
  10200. return possibleConstructorReturn(this, _Component.apply(this, arguments));
  10201. }
  10202. /**
  10203. * Create the time tooltip DOM element
  10204. *
  10205. * @return {Element}
  10206. * The element that was created.
  10207. */
  10208. TimeTooltip.prototype.createEl = function createEl$$1() {
  10209. return _Component.prototype.createEl.call(this, 'div', {
  10210. className: 'vjs-time-tooltip'
  10211. });
  10212. };
  10213. /**
  10214. * Updates the position of the time tooltip relative to the `SeekBar`.
  10215. *
  10216. * @param {Object} seekBarRect
  10217. * The `ClientRect` for the {@link SeekBar} element.
  10218. *
  10219. * @param {number} seekBarPoint
  10220. * A number from 0 to 1, representing a horizontal reference point
  10221. * from the left edge of the {@link SeekBar}
  10222. */
  10223. TimeTooltip.prototype.update = function update(seekBarRect, seekBarPoint, content) {
  10224. var tooltipRect = getBoundingClientRect(this.el_);
  10225. var playerRect = getBoundingClientRect(this.player_.el());
  10226. var seekBarPointPx = seekBarRect.width * seekBarPoint;
  10227. // do nothing if either rect isn't available
  10228. // for example, if the player isn't in the DOM for testing
  10229. if (!playerRect || !tooltipRect) {
  10230. return;
  10231. }
  10232. // This is the space left of the `seekBarPoint` available within the bounds
  10233. // of the player. We calculate any gap between the left edge of the player
  10234. // and the left edge of the `SeekBar` and add the number of pixels in the
  10235. // `SeekBar` before hitting the `seekBarPoint`
  10236. var spaceLeftOfPoint = seekBarRect.left - playerRect.left + seekBarPointPx;
  10237. // This is the space right of the `seekBarPoint` available within the bounds
  10238. // of the player. We calculate the number of pixels from the `seekBarPoint`
  10239. // to the right edge of the `SeekBar` and add to that any gap between the
  10240. // right edge of the `SeekBar` and the player.
  10241. var spaceRightOfPoint = seekBarRect.width - seekBarPointPx + (playerRect.right - seekBarRect.right);
  10242. // This is the number of pixels by which the tooltip will need to be pulled
  10243. // further to the right to center it over the `seekBarPoint`.
  10244. var pullTooltipBy = tooltipRect.width / 2;
  10245. // Adjust the `pullTooltipBy` distance to the left or right depending on
  10246. // the results of the space calculations above.
  10247. if (spaceLeftOfPoint < pullTooltipBy) {
  10248. pullTooltipBy += pullTooltipBy - spaceLeftOfPoint;
  10249. } else if (spaceRightOfPoint < pullTooltipBy) {
  10250. pullTooltipBy = spaceRightOfPoint;
  10251. }
  10252. // Due to the imprecision of decimal/ratio based calculations and varying
  10253. // rounding behaviors, there are cases where the spacing adjustment is off
  10254. // by a pixel or two. This adds insurance to these calculations.
  10255. if (pullTooltipBy < 0) {
  10256. pullTooltipBy = 0;
  10257. } else if (pullTooltipBy > tooltipRect.width) {
  10258. pullTooltipBy = tooltipRect.width;
  10259. }
  10260. this.el_.style.right = '-' + pullTooltipBy + 'px';
  10261. textContent(this.el_, content);
  10262. };
  10263. return TimeTooltip;
  10264. }(Component);
  10265. Component.registerComponent('TimeTooltip', TimeTooltip);
  10266. /**
  10267. * @file play-progress-bar.js
  10268. */
  10269. /**
  10270. * Used by {@link SeekBar} to display media playback progress as part of the
  10271. * {@link ProgressControl}.
  10272. *
  10273. * @extends Component
  10274. */
  10275. var PlayProgressBar = function (_Component) {
  10276. inherits(PlayProgressBar, _Component);
  10277. function PlayProgressBar() {
  10278. classCallCheck(this, PlayProgressBar);
  10279. return possibleConstructorReturn(this, _Component.apply(this, arguments));
  10280. }
  10281. /**
  10282. * Create the the DOM element for this class.
  10283. *
  10284. * @return {Element}
  10285. * The element that was created.
  10286. */
  10287. PlayProgressBar.prototype.createEl = function createEl() {
  10288. return _Component.prototype.createEl.call(this, 'div', {
  10289. className: 'vjs-play-progress vjs-slider-bar',
  10290. innerHTML: '<span class="vjs-control-text"><span>' + this.localize('Progress') + '</span>: 0%</span>'
  10291. });
  10292. };
  10293. /**
  10294. * Enqueues updates to its own DOM as well as the DOM of its
  10295. * {@link TimeTooltip} child.
  10296. *
  10297. * @param {Object} seekBarRect
  10298. * The `ClientRect` for the {@link SeekBar} element.
  10299. *
  10300. * @param {number} seekBarPoint
  10301. * A number from 0 to 1, representing a horizontal reference point
  10302. * from the left edge of the {@link SeekBar}
  10303. */
  10304. PlayProgressBar.prototype.update = function update(seekBarRect, seekBarPoint) {
  10305. var _this2 = this;
  10306. // If there is an existing rAF ID, cancel it so we don't over-queue.
  10307. if (this.rafId_) {
  10308. this.cancelAnimationFrame(this.rafId_);
  10309. }
  10310. this.rafId_ = this.requestAnimationFrame(function () {
  10311. var time = _this2.player_.scrubbing() ? _this2.player_.getCache().currentTime : _this2.player_.currentTime();
  10312. var content = formatTime(time, _this2.player_.duration());
  10313. var timeTooltip = _this2.getChild('timeTooltip');
  10314. if (timeTooltip) {
  10315. timeTooltip.update(seekBarRect, seekBarPoint, content);
  10316. }
  10317. });
  10318. };
  10319. return PlayProgressBar;
  10320. }(Component);
  10321. /**
  10322. * Default options for {@link PlayProgressBar}.
  10323. *
  10324. * @type {Object}
  10325. * @private
  10326. */
  10327. PlayProgressBar.prototype.options_ = {
  10328. children: []
  10329. };
  10330. // Time tooltips should not be added to a player on mobile devices or IE8
  10331. if ((!IE_VERSION || IE_VERSION > 8) && !IS_IOS && !IS_ANDROID) {
  10332. PlayProgressBar.prototype.options_.children.push('timeTooltip');
  10333. }
  10334. Component.registerComponent('PlayProgressBar', PlayProgressBar);
  10335. /**
  10336. * @file mouse-time-display.js
  10337. */
  10338. /**
  10339. * The {@link MouseTimeDisplay} component tracks mouse movement over the
  10340. * {@link ProgressControl}. It displays an indicator and a {@link TimeTooltip}
  10341. * indicating the time which is represented by a given point in the
  10342. * {@link ProgressControl}.
  10343. *
  10344. * @extends Component
  10345. */
  10346. var MouseTimeDisplay = function (_Component) {
  10347. inherits(MouseTimeDisplay, _Component);
  10348. /**
  10349. * Creates an instance of this class.
  10350. *
  10351. * @param {Player} player
  10352. * The {@link Player} that this class should be attached to.
  10353. *
  10354. * @param {Object} [options]
  10355. * The key/value store of player options.
  10356. */
  10357. function MouseTimeDisplay(player, options) {
  10358. classCallCheck(this, MouseTimeDisplay);
  10359. var _this = possibleConstructorReturn(this, _Component.call(this, player, options));
  10360. _this.update = throttle(bind(_this, _this.update), 25);
  10361. return _this;
  10362. }
  10363. /**
  10364. * Create the DOM element for this class.
  10365. *
  10366. * @return {Element}
  10367. * The element that was created.
  10368. */
  10369. MouseTimeDisplay.prototype.createEl = function createEl() {
  10370. return _Component.prototype.createEl.call(this, 'div', {
  10371. className: 'vjs-mouse-display'
  10372. });
  10373. };
  10374. /**
  10375. * Enqueues updates to its own DOM as well as the DOM of its
  10376. * {@link TimeTooltip} child.
  10377. *
  10378. * @param {Object} seekBarRect
  10379. * The `ClientRect` for the {@link SeekBar} element.
  10380. *
  10381. * @param {number} seekBarPoint
  10382. * A number from 0 to 1, representing a horizontal reference point
  10383. * from the left edge of the {@link SeekBar}
  10384. */
  10385. MouseTimeDisplay.prototype.update = function update(seekBarRect, seekBarPoint) {
  10386. var _this2 = this;
  10387. // If there is an existing rAF ID, cancel it so we don't over-queue.
  10388. if (this.rafId_) {
  10389. this.cancelAnimationFrame(this.rafId_);
  10390. }
  10391. this.rafId_ = this.requestAnimationFrame(function () {
  10392. var duration = _this2.player_.duration();
  10393. var content = formatTime(seekBarPoint * duration, duration);
  10394. _this2.el_.style.left = seekBarRect.width * seekBarPoint + 'px';
  10395. _this2.getChild('timeTooltip').update(seekBarRect, seekBarPoint, content);
  10396. });
  10397. };
  10398. return MouseTimeDisplay;
  10399. }(Component);
  10400. /**
  10401. * Default options for `MouseTimeDisplay`
  10402. *
  10403. * @type {Object}
  10404. * @private
  10405. */
  10406. MouseTimeDisplay.prototype.options_ = {
  10407. children: ['timeTooltip']
  10408. };
  10409. Component.registerComponent('MouseTimeDisplay', MouseTimeDisplay);
  10410. /**
  10411. * @file seek-bar.js
  10412. */
  10413. // The number of seconds the `step*` functions move the timeline.
  10414. var STEP_SECONDS = 5;
  10415. // The interval at which the bar should update as it progresses.
  10416. var UPDATE_REFRESH_INTERVAL = 30;
  10417. /**
  10418. * Seek bar and container for the progress bars. Uses {@link PlayProgressBar}
  10419. * as its `bar`.
  10420. *
  10421. * @extends Slider
  10422. */
  10423. var SeekBar = function (_Slider) {
  10424. inherits(SeekBar, _Slider);
  10425. /**
  10426. * Creates an instance of this class.
  10427. *
  10428. * @param {Player} player
  10429. * The `Player` that this class should be attached to.
  10430. *
  10431. * @param {Object} [options]
  10432. * The key/value store of player options.
  10433. */
  10434. function SeekBar(player, options) {
  10435. classCallCheck(this, SeekBar);
  10436. var _this = possibleConstructorReturn(this, _Slider.call(this, player, options));
  10437. _this.setEventHandlers_();
  10438. return _this;
  10439. }
  10440. /**
  10441. * Sets the event handlers
  10442. *
  10443. * @private
  10444. */
  10445. SeekBar.prototype.setEventHandlers_ = function setEventHandlers_() {
  10446. var _this2 = this;
  10447. this.update = throttle(bind(this, this.update), UPDATE_REFRESH_INTERVAL);
  10448. this.on(this.player_, 'timeupdate', this.update);
  10449. this.on(this.player_, 'ended', this.handleEnded);
  10450. // when playing, let's ensure we smoothly update the play progress bar
  10451. // via an interval
  10452. this.updateInterval = null;
  10453. this.on(this.player_, ['playing'], function () {
  10454. _this2.clearInterval(_this2.updateInterval);
  10455. _this2.updateInterval = _this2.setInterval(function () {
  10456. _this2.requestAnimationFrame(function () {
  10457. _this2.update();
  10458. });
  10459. }, UPDATE_REFRESH_INTERVAL);
  10460. });
  10461. this.on(this.player_, ['ended', 'pause', 'waiting'], function () {
  10462. _this2.clearInterval(_this2.updateInterval);
  10463. });
  10464. this.on(this.player_, ['timeupdate', 'ended'], this.update);
  10465. };
  10466. /**
  10467. * Create the `Component`'s DOM element
  10468. *
  10469. * @return {Element}
  10470. * The element that was created.
  10471. */
  10472. SeekBar.prototype.createEl = function createEl$$1() {
  10473. return _Slider.prototype.createEl.call(this, 'div', {
  10474. className: 'vjs-progress-holder'
  10475. }, {
  10476. 'aria-label': this.localize('Progress Bar')
  10477. });
  10478. };
  10479. /**
  10480. * This function updates the play progress bar and accessiblity
  10481. * attributes to whatever is passed in.
  10482. *
  10483. * @param {number} currentTime
  10484. * The currentTime value that should be used for accessiblity
  10485. *
  10486. * @param {number} percent
  10487. * The percentage as a decimal that the bar should be filled from 0-1.
  10488. *
  10489. * @private
  10490. */
  10491. SeekBar.prototype.update_ = function update_(currentTime, percent) {
  10492. var duration = this.player_.duration();
  10493. // machine readable value of progress bar (percentage complete)
  10494. this.el_.setAttribute('aria-valuenow', (percent * 100).toFixed(2));
  10495. // human readable value of progress bar (time complete)
  10496. this.el_.setAttribute('aria-valuetext', this.localize('progress bar timing: currentTime={1} duration={2}', [formatTime(currentTime, duration), formatTime(duration, duration)], '{1} of {2}'));
  10497. // Update the `PlayProgressBar`.
  10498. this.bar.update(getBoundingClientRect(this.el_), percent);
  10499. };
  10500. /**
  10501. * Update the seek bar's UI.
  10502. *
  10503. * @param {EventTarget~Event} [event]
  10504. * The `timeupdate` or `ended` event that caused this to run.
  10505. *
  10506. * @listens Player#timeupdate
  10507. *
  10508. * @returns {number}
  10509. * The current percent at a number from 0-1
  10510. */
  10511. SeekBar.prototype.update = function update(event) {
  10512. var percent = _Slider.prototype.update.call(this);
  10513. this.update_(this.getCurrentTime_(), percent);
  10514. return percent;
  10515. };
  10516. /**
  10517. * Get the value of current time but allows for smooth scrubbing,
  10518. * when player can't keep up.
  10519. *
  10520. * @return {number}
  10521. * The current time value to display
  10522. *
  10523. * @private
  10524. */
  10525. SeekBar.prototype.getCurrentTime_ = function getCurrentTime_() {
  10526. return this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
  10527. };
  10528. /**
  10529. * We want the seek bar to be full on ended
  10530. * no matter what the actual internal values are. so we force it.
  10531. *
  10532. * @param {EventTarget~Event} [event]
  10533. * The `timeupdate` or `ended` event that caused this to run.
  10534. *
  10535. * @listens Player#ended
  10536. */
  10537. SeekBar.prototype.handleEnded = function handleEnded(event) {
  10538. this.update_(this.player_.duration(), 1);
  10539. };
  10540. /**
  10541. * Get the percentage of media played so far.
  10542. *
  10543. * @return {number}
  10544. * The percentage of media played so far (0 to 1).
  10545. */
  10546. SeekBar.prototype.getPercent = function getPercent() {
  10547. var percent = this.getCurrentTime_() / this.player_.duration();
  10548. return percent >= 1 ? 1 : percent;
  10549. };
  10550. /**
  10551. * Handle mouse down on seek bar
  10552. *
  10553. * @param {EventTarget~Event} event
  10554. * The `mousedown` event that caused this to run.
  10555. *
  10556. * @listens mousedown
  10557. */
  10558. SeekBar.prototype.handleMouseDown = function handleMouseDown(event) {
  10559. if (!isSingleLeftClick(event)) {
  10560. return;
  10561. }
  10562. // Stop event propagation to prevent double fire in progress-control.js
  10563. event.stopPropagation();
  10564. this.player_.scrubbing(true);
  10565. this.videoWasPlaying = !this.player_.paused();
  10566. this.player_.pause();
  10567. _Slider.prototype.handleMouseDown.call(this, event);
  10568. };
  10569. /**
  10570. * Handle mouse move on seek bar
  10571. *
  10572. * @param {EventTarget~Event} event
  10573. * The `mousemove` event that caused this to run.
  10574. *
  10575. * @listens mousemove
  10576. */
  10577. SeekBar.prototype.handleMouseMove = function handleMouseMove(event) {
  10578. if (!isSingleLeftClick(event)) {
  10579. return;
  10580. }
  10581. var newTime = this.calculateDistance(event) * this.player_.duration();
  10582. // Don't let video end while scrubbing.
  10583. if (newTime === this.player_.duration()) {
  10584. newTime = newTime - 0.1;
  10585. }
  10586. // Set new time (tell player to seek to new time)
  10587. this.player_.currentTime(newTime);
  10588. };
  10589. SeekBar.prototype.enable = function enable() {
  10590. _Slider.prototype.enable.call(this);
  10591. var mouseTimeDisplay = this.getChild('mouseTimeDisplay');
  10592. if (!mouseTimeDisplay) {
  10593. return;
  10594. }
  10595. mouseTimeDisplay.show();
  10596. };
  10597. SeekBar.prototype.disable = function disable() {
  10598. _Slider.prototype.disable.call(this);
  10599. var mouseTimeDisplay = this.getChild('mouseTimeDisplay');
  10600. if (!mouseTimeDisplay) {
  10601. return;
  10602. }
  10603. mouseTimeDisplay.hide();
  10604. };
  10605. /**
  10606. * Handle mouse up on seek bar
  10607. *
  10608. * @param {EventTarget~Event} event
  10609. * The `mouseup` event that caused this to run.
  10610. *
  10611. * @listens mouseup
  10612. */
  10613. SeekBar.prototype.handleMouseUp = function handleMouseUp(event) {
  10614. _Slider.prototype.handleMouseUp.call(this, event);
  10615. // Stop event propagation to prevent double fire in progress-control.js
  10616. if (event) {
  10617. event.stopPropagation();
  10618. }
  10619. this.player_.scrubbing(false);
  10620. /**
  10621. * Trigger timeupdate because we're done seeking and the time has changed.
  10622. * This is particularly useful for if the player is paused to time the time displays.
  10623. *
  10624. * @event Tech#timeupdate
  10625. * @type {EventTarget~Event}
  10626. */
  10627. this.player_.trigger({ type: 'timeupdate', target: this, manuallyTriggered: true });
  10628. if (this.videoWasPlaying) {
  10629. silencePromise(this.player_.play());
  10630. }
  10631. };
  10632. /**
  10633. * Move more quickly fast forward for keyboard-only users
  10634. */
  10635. SeekBar.prototype.stepForward = function stepForward() {
  10636. this.player_.currentTime(this.player_.currentTime() + STEP_SECONDS);
  10637. };
  10638. /**
  10639. * Move more quickly rewind for keyboard-only users
  10640. */
  10641. SeekBar.prototype.stepBack = function stepBack() {
  10642. this.player_.currentTime(this.player_.currentTime() - STEP_SECONDS);
  10643. };
  10644. /**
  10645. * Toggles the playback state of the player
  10646. * This gets called when enter or space is used on the seekbar
  10647. *
  10648. * @param {EventTarget~Event} event
  10649. * The `keydown` event that caused this function to be called
  10650. *
  10651. */
  10652. SeekBar.prototype.handleAction = function handleAction(event) {
  10653. if (this.player_.paused()) {
  10654. this.player_.play();
  10655. } else {
  10656. this.player_.pause();
  10657. }
  10658. };
  10659. /**
  10660. * Called when this SeekBar has focus and a key gets pressed down. By
  10661. * default it will call `this.handleAction` when the key is space or enter.
  10662. *
  10663. * @param {EventTarget~Event} event
  10664. * The `keydown` event that caused this function to be called.
  10665. *
  10666. * @listens keydown
  10667. */
  10668. SeekBar.prototype.handleKeyPress = function handleKeyPress(event) {
  10669. // Support Space (32) or Enter (13) key operation to fire a click event
  10670. if (event.which === 32 || event.which === 13) {
  10671. event.preventDefault();
  10672. this.handleAction(event);
  10673. } else if (_Slider.prototype.handleKeyPress) {
  10674. // Pass keypress handling up for unsupported keys
  10675. _Slider.prototype.handleKeyPress.call(this, event);
  10676. }
  10677. };
  10678. return SeekBar;
  10679. }(Slider);
  10680. /**
  10681. * Default options for the `SeekBar`
  10682. *
  10683. * @type {Object}
  10684. * @private
  10685. */
  10686. SeekBar.prototype.options_ = {
  10687. children: ['loadProgressBar', 'playProgressBar'],
  10688. barName: 'playProgressBar'
  10689. };
  10690. // MouseTimeDisplay tooltips should not be added to a player on mobile devices or IE8
  10691. if ((!IE_VERSION || IE_VERSION > 8) && !IS_IOS && !IS_ANDROID) {
  10692. SeekBar.prototype.options_.children.splice(1, 0, 'mouseTimeDisplay');
  10693. }
  10694. /**
  10695. * Call the update event for this Slider when this event happens on the player.
  10696. *
  10697. * @type {string}
  10698. */
  10699. SeekBar.prototype.playerEvent = 'timeupdate';
  10700. Component.registerComponent('SeekBar', SeekBar);
  10701. /**
  10702. * @file progress-control.js
  10703. */
  10704. /**
  10705. * The Progress Control component contains the seek bar, load progress,
  10706. * and play progress.
  10707. *
  10708. * @extends Component
  10709. */
  10710. var ProgressControl = function (_Component) {
  10711. inherits(ProgressControl, _Component);
  10712. /**
  10713. * Creates an instance of this class.
  10714. *
  10715. * @param {Player} player
  10716. * The `Player` that this class should be attached to.
  10717. *
  10718. * @param {Object} [options]
  10719. * The key/value store of player options.
  10720. */
  10721. function ProgressControl(player, options) {
  10722. classCallCheck(this, ProgressControl);
  10723. var _this = possibleConstructorReturn(this, _Component.call(this, player, options));
  10724. _this.handleMouseMove = throttle(bind(_this, _this.handleMouseMove), 25);
  10725. _this.throttledHandleMouseSeek = throttle(bind(_this, _this.handleMouseSeek), 25);
  10726. _this.enable();
  10727. return _this;
  10728. }
  10729. /**
  10730. * Create the `Component`'s DOM element
  10731. *
  10732. * @return {Element}
  10733. * The element that was created.
  10734. */
  10735. ProgressControl.prototype.createEl = function createEl$$1() {
  10736. return _Component.prototype.createEl.call(this, 'div', {
  10737. className: 'vjs-progress-control vjs-control'
  10738. });
  10739. };
  10740. /**
  10741. * When the mouse moves over the `ProgressControl`, the pointer position
  10742. * gets passed down to the `MouseTimeDisplay` component.
  10743. *
  10744. * @param {EventTarget~Event} event
  10745. * The `mousemove` event that caused this function to run.
  10746. *
  10747. * @listen mousemove
  10748. */
  10749. ProgressControl.prototype.handleMouseMove = function handleMouseMove(event) {
  10750. var seekBar = this.getChild('seekBar');
  10751. if (seekBar) {
  10752. var mouseTimeDisplay = seekBar.getChild('mouseTimeDisplay');
  10753. var seekBarEl = seekBar.el();
  10754. var seekBarRect = getBoundingClientRect(seekBarEl);
  10755. var seekBarPoint = getPointerPosition(seekBarEl, event).x;
  10756. // The default skin has a gap on either side of the `SeekBar`. This means
  10757. // that it's possible to trigger this behavior outside the boundaries of
  10758. // the `SeekBar`. This ensures we stay within it at all times.
  10759. if (seekBarPoint > 1) {
  10760. seekBarPoint = 1;
  10761. } else if (seekBarPoint < 0) {
  10762. seekBarPoint = 0;
  10763. }
  10764. if (mouseTimeDisplay) {
  10765. mouseTimeDisplay.update(seekBarRect, seekBarPoint);
  10766. }
  10767. }
  10768. };
  10769. /**
  10770. * A throttled version of the {@link ProgressControl#handleMouseSeek} listener.
  10771. *
  10772. * @method ProgressControl#throttledHandleMouseSeek
  10773. * @param {EventTarget~Event} event
  10774. * The `mousemove` event that caused this function to run.
  10775. *
  10776. * @listen mousemove
  10777. * @listen touchmove
  10778. */
  10779. /**
  10780. * Handle `mousemove` or `touchmove` events on the `ProgressControl`.
  10781. *
  10782. * @param {EventTarget~Event} event
  10783. * `mousedown` or `touchstart` event that triggered this function
  10784. *
  10785. * @listens mousemove
  10786. * @listens touchmove
  10787. */
  10788. ProgressControl.prototype.handleMouseSeek = function handleMouseSeek(event) {
  10789. var seekBar = this.getChild('seekBar');
  10790. if (seekBar) {
  10791. seekBar.handleMouseMove(event);
  10792. }
  10793. };
  10794. /**
  10795. * Are controls are currently enabled for this progress control.
  10796. *
  10797. * @return {boolean}
  10798. * true if controls are enabled, false otherwise
  10799. */
  10800. ProgressControl.prototype.enabled = function enabled() {
  10801. return this.enabled_;
  10802. };
  10803. /**
  10804. * Disable all controls on the progress control and its children
  10805. */
  10806. ProgressControl.prototype.disable = function disable() {
  10807. this.children().forEach(function (child) {
  10808. return child.disable && child.disable();
  10809. });
  10810. if (!this.enabled()) {
  10811. return;
  10812. }
  10813. this.off(['mousedown', 'touchstart'], this.handleMouseDown);
  10814. this.off(this.el_, 'mousemove', this.handleMouseMove);
  10815. this.handleMouseUp();
  10816. this.addClass('disabled');
  10817. this.enabled_ = false;
  10818. };
  10819. /**
  10820. * Enable all controls on the progress control and its children
  10821. */
  10822. ProgressControl.prototype.enable = function enable() {
  10823. this.children().forEach(function (child) {
  10824. return child.enable && child.enable();
  10825. });
  10826. if (this.enabled()) {
  10827. return;
  10828. }
  10829. this.on(['mousedown', 'touchstart'], this.handleMouseDown);
  10830. this.on(this.el_, 'mousemove', this.handleMouseMove);
  10831. this.removeClass('disabled');
  10832. this.enabled_ = true;
  10833. };
  10834. /**
  10835. * Handle `mousedown` or `touchstart` events on the `ProgressControl`.
  10836. *
  10837. * @param {EventTarget~Event} event
  10838. * `mousedown` or `touchstart` event that triggered this function
  10839. *
  10840. * @listens mousedown
  10841. * @listens touchstart
  10842. */
  10843. ProgressControl.prototype.handleMouseDown = function handleMouseDown(event) {
  10844. var doc = this.el_.ownerDocument;
  10845. var seekBar = this.getChild('seekBar');
  10846. if (seekBar) {
  10847. seekBar.handleMouseDown(event);
  10848. }
  10849. this.on(doc, 'mousemove', this.throttledHandleMouseSeek);
  10850. this.on(doc, 'touchmove', this.throttledHandleMouseSeek);
  10851. this.on(doc, 'mouseup', this.handleMouseUp);
  10852. this.on(doc, 'touchend', this.handleMouseUp);
  10853. };
  10854. /**
  10855. * Handle `mouseup` or `touchend` events on the `ProgressControl`.
  10856. *
  10857. * @param {EventTarget~Event} event
  10858. * `mouseup` or `touchend` event that triggered this function.
  10859. *
  10860. * @listens touchend
  10861. * @listens mouseup
  10862. */
  10863. ProgressControl.prototype.handleMouseUp = function handleMouseUp(event) {
  10864. var doc = this.el_.ownerDocument;
  10865. var seekBar = this.getChild('seekBar');
  10866. if (seekBar) {
  10867. seekBar.handleMouseUp(event);
  10868. }
  10869. this.off(doc, 'mousemove', this.throttledHandleMouseSeek);
  10870. this.off(doc, 'touchmove', this.throttledHandleMouseSeek);
  10871. this.off(doc, 'mouseup', this.handleMouseUp);
  10872. this.off(doc, 'touchend', this.handleMouseUp);
  10873. };
  10874. return ProgressControl;
  10875. }(Component);
  10876. /**
  10877. * Default options for `ProgressControl`
  10878. *
  10879. * @type {Object}
  10880. * @private
  10881. */
  10882. ProgressControl.prototype.options_ = {
  10883. children: ['seekBar']
  10884. };
  10885. Component.registerComponent('ProgressControl', ProgressControl);
  10886. /**
  10887. * @file fullscreen-toggle.js
  10888. */
  10889. /**
  10890. * Toggle fullscreen video
  10891. *
  10892. * @extends Button
  10893. */
  10894. var FullscreenToggle = function (_Button) {
  10895. inherits(FullscreenToggle, _Button);
  10896. /**
  10897. * Creates an instance of this class.
  10898. *
  10899. * @param {Player} player
  10900. * The `Player` that this class should be attached to.
  10901. *
  10902. * @param {Object} [options]
  10903. * The key/value store of player options.
  10904. */
  10905. function FullscreenToggle(player, options) {
  10906. classCallCheck(this, FullscreenToggle);
  10907. var _this = possibleConstructorReturn(this, _Button.call(this, player, options));
  10908. _this.on(player, 'fullscreenchange', _this.handleFullscreenChange);
  10909. if (document[FullscreenApi.fullscreenEnabled] === false) {
  10910. _this.disable();
  10911. }
  10912. return _this;
  10913. }
  10914. /**
  10915. * Builds the default DOM `className`.
  10916. *
  10917. * @return {string}
  10918. * The DOM `className` for this object.
  10919. */
  10920. FullscreenToggle.prototype.buildCSSClass = function buildCSSClass() {
  10921. return 'vjs-fullscreen-control ' + _Button.prototype.buildCSSClass.call(this);
  10922. };
  10923. /**
  10924. * Handles fullscreenchange on the player and change control text accordingly.
  10925. *
  10926. * @param {EventTarget~Event} [event]
  10927. * The {@link Player#fullscreenchange} event that caused this function to be
  10928. * called.
  10929. *
  10930. * @listens Player#fullscreenchange
  10931. */
  10932. FullscreenToggle.prototype.handleFullscreenChange = function handleFullscreenChange(event) {
  10933. if (this.player_.isFullscreen()) {
  10934. this.controlText('Non-Fullscreen');
  10935. } else {
  10936. this.controlText('Fullscreen');
  10937. }
  10938. };
  10939. /**
  10940. * This gets called when an `FullscreenToggle` is "clicked". See
  10941. * {@link ClickableComponent} for more detailed information on what a click can be.
  10942. *
  10943. * @param {EventTarget~Event} [event]
  10944. * The `keydown`, `tap`, or `click` event that caused this function to be
  10945. * called.
  10946. *
  10947. * @listens tap
  10948. * @listens click
  10949. */
  10950. FullscreenToggle.prototype.handleClick = function handleClick(event) {
  10951. if (!this.player_.isFullscreen()) {
  10952. this.player_.requestFullscreen();
  10953. } else {
  10954. this.player_.exitFullscreen();
  10955. }
  10956. };
  10957. return FullscreenToggle;
  10958. }(Button);
  10959. /**
  10960. * The text that should display over the `FullscreenToggle`s controls. Added for localization.
  10961. *
  10962. * @type {string}
  10963. * @private
  10964. */
  10965. FullscreenToggle.prototype.controlText_ = 'Fullscreen';
  10966. Component.registerComponent('FullscreenToggle', FullscreenToggle);
  10967. /**
  10968. * Check if volume control is supported and if it isn't hide the
  10969. * `Component` that was passed using the `vjs-hidden` class.
  10970. *
  10971. * @param {Component} self
  10972. * The component that should be hidden if volume is unsupported
  10973. *
  10974. * @param {Player} player
  10975. * A reference to the player
  10976. *
  10977. * @private
  10978. */
  10979. var checkVolumeSupport = function checkVolumeSupport(self, player) {
  10980. // hide volume controls when they're not supported by the current tech
  10981. if (player.tech_ && !player.tech_.featuresVolumeControl) {
  10982. self.addClass('vjs-hidden');
  10983. }
  10984. self.on(player, 'loadstart', function () {
  10985. if (!player.tech_.featuresVolumeControl) {
  10986. self.addClass('vjs-hidden');
  10987. } else {
  10988. self.removeClass('vjs-hidden');
  10989. }
  10990. });
  10991. };
  10992. /**
  10993. * @file volume-level.js
  10994. */
  10995. /**
  10996. * Shows volume level
  10997. *
  10998. * @extends Component
  10999. */
  11000. var VolumeLevel = function (_Component) {
  11001. inherits(VolumeLevel, _Component);
  11002. function VolumeLevel() {
  11003. classCallCheck(this, VolumeLevel);
  11004. return possibleConstructorReturn(this, _Component.apply(this, arguments));
  11005. }
  11006. /**
  11007. * Create the `Component`'s DOM element
  11008. *
  11009. * @return {Element}
  11010. * The element that was created.
  11011. */
  11012. VolumeLevel.prototype.createEl = function createEl() {
  11013. return _Component.prototype.createEl.call(this, 'div', {
  11014. className: 'vjs-volume-level',
  11015. innerHTML: '<span class="vjs-control-text"></span>'
  11016. });
  11017. };
  11018. return VolumeLevel;
  11019. }(Component);
  11020. Component.registerComponent('VolumeLevel', VolumeLevel);
  11021. /**
  11022. * @file volume-bar.js
  11023. */
  11024. // Required children
  11025. /**
  11026. * The bar that contains the volume level and can be clicked on to adjust the level
  11027. *
  11028. * @extends Slider
  11029. */
  11030. var VolumeBar = function (_Slider) {
  11031. inherits(VolumeBar, _Slider);
  11032. /**
  11033. * Creates an instance of this class.
  11034. *
  11035. * @param {Player} player
  11036. * The `Player` that this class should be attached to.
  11037. *
  11038. * @param {Object} [options]
  11039. * The key/value store of player options.
  11040. */
  11041. function VolumeBar(player, options) {
  11042. classCallCheck(this, VolumeBar);
  11043. var _this = possibleConstructorReturn(this, _Slider.call(this, player, options));
  11044. _this.on('slideractive', _this.updateLastVolume_);
  11045. _this.on(player, 'volumechange', _this.updateARIAAttributes);
  11046. player.ready(function () {
  11047. return _this.updateARIAAttributes();
  11048. });
  11049. return _this;
  11050. }
  11051. /**
  11052. * Create the `Component`'s DOM element
  11053. *
  11054. * @return {Element}
  11055. * The element that was created.
  11056. */
  11057. VolumeBar.prototype.createEl = function createEl$$1() {
  11058. return _Slider.prototype.createEl.call(this, 'div', {
  11059. className: 'vjs-volume-bar vjs-slider-bar'
  11060. }, {
  11061. 'aria-label': this.localize('Volume Level'),
  11062. 'aria-live': 'polite'
  11063. });
  11064. };
  11065. /**
  11066. * Handle mouse down on volume bar
  11067. *
  11068. * @param {EventTarget~Event} event
  11069. * The `mousedown` event that caused this to run.
  11070. *
  11071. * @listens mousedown
  11072. */
  11073. VolumeBar.prototype.handleMouseDown = function handleMouseDown(event) {
  11074. if (!isSingleLeftClick(event)) {
  11075. return;
  11076. }
  11077. _Slider.prototype.handleMouseDown.call(this, event);
  11078. };
  11079. /**
  11080. * Handle movement events on the {@link VolumeMenuButton}.
  11081. *
  11082. * @param {EventTarget~Event} event
  11083. * The event that caused this function to run.
  11084. *
  11085. * @listens mousemove
  11086. */
  11087. VolumeBar.prototype.handleMouseMove = function handleMouseMove(event) {
  11088. if (!isSingleLeftClick(event)) {
  11089. return;
  11090. }
  11091. this.checkMuted();
  11092. this.player_.volume(this.calculateDistance(event));
  11093. };
  11094. /**
  11095. * If the player is muted unmute it.
  11096. */
  11097. VolumeBar.prototype.checkMuted = function checkMuted() {
  11098. if (this.player_.muted()) {
  11099. this.player_.muted(false);
  11100. }
  11101. };
  11102. /**
  11103. * Get percent of volume level
  11104. *
  11105. * @return {number}
  11106. * Volume level percent as a decimal number.
  11107. */
  11108. VolumeBar.prototype.getPercent = function getPercent() {
  11109. if (this.player_.muted()) {
  11110. return 0;
  11111. }
  11112. return this.player_.volume();
  11113. };
  11114. /**
  11115. * Increase volume level for keyboard users
  11116. */
  11117. VolumeBar.prototype.stepForward = function stepForward() {
  11118. this.checkMuted();
  11119. this.player_.volume(this.player_.volume() + 0.1);
  11120. };
  11121. /**
  11122. * Decrease volume level for keyboard users
  11123. */
  11124. VolumeBar.prototype.stepBack = function stepBack() {
  11125. this.checkMuted();
  11126. this.player_.volume(this.player_.volume() - 0.1);
  11127. };
  11128. /**
  11129. * Update ARIA accessibility attributes
  11130. *
  11131. * @param {EventTarget~Event} [event]
  11132. * The `volumechange` event that caused this function to run.
  11133. *
  11134. * @listens Player#volumechange
  11135. */
  11136. VolumeBar.prototype.updateARIAAttributes = function updateARIAAttributes(event) {
  11137. var ariaValue = this.player_.muted() ? 0 : this.volumeAsPercentage_();
  11138. this.el_.setAttribute('aria-valuenow', ariaValue);
  11139. this.el_.setAttribute('aria-valuetext', ariaValue + '%');
  11140. };
  11141. /**
  11142. * Returns the current value of the player volume as a percentage
  11143. *
  11144. * @private
  11145. */
  11146. VolumeBar.prototype.volumeAsPercentage_ = function volumeAsPercentage_() {
  11147. return Math.round(this.player_.volume() * 100);
  11148. };
  11149. /**
  11150. * When user starts dragging the VolumeBar, store the volume and listen for
  11151. * the end of the drag. When the drag ends, if the volume was set to zero,
  11152. * set lastVolume to the stored volume.
  11153. *
  11154. * @listens slideractive
  11155. * @private
  11156. */
  11157. VolumeBar.prototype.updateLastVolume_ = function updateLastVolume_() {
  11158. var _this2 = this;
  11159. var volumeBeforeDrag = this.player_.volume();
  11160. this.one('sliderinactive', function () {
  11161. if (_this2.player_.volume() === 0) {
  11162. _this2.player_.lastVolume_(volumeBeforeDrag);
  11163. }
  11164. });
  11165. };
  11166. return VolumeBar;
  11167. }(Slider);
  11168. /**
  11169. * Default options for the `VolumeBar`
  11170. *
  11171. * @type {Object}
  11172. * @private
  11173. */
  11174. VolumeBar.prototype.options_ = {
  11175. children: ['volumeLevel'],
  11176. barName: 'volumeLevel'
  11177. };
  11178. /**
  11179. * Call the update event for this Slider when this event happens on the player.
  11180. *
  11181. * @type {string}
  11182. */
  11183. VolumeBar.prototype.playerEvent = 'volumechange';
  11184. Component.registerComponent('VolumeBar', VolumeBar);
  11185. /**
  11186. * @file volume-control.js
  11187. */
  11188. // Required children
  11189. /**
  11190. * The component for controlling the volume level
  11191. *
  11192. * @extends Component
  11193. */
  11194. var VolumeControl = function (_Component) {
  11195. inherits(VolumeControl, _Component);
  11196. /**
  11197. * Creates an instance of this class.
  11198. *
  11199. * @param {Player} player
  11200. * The `Player` that this class should be attached to.
  11201. *
  11202. * @param {Object} [options={}]
  11203. * The key/value store of player options.
  11204. */
  11205. function VolumeControl(player) {
  11206. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  11207. classCallCheck(this, VolumeControl);
  11208. options.vertical = options.vertical || false;
  11209. // Pass the vertical option down to the VolumeBar if
  11210. // the VolumeBar is turned on.
  11211. if (typeof options.volumeBar === 'undefined' || isPlain(options.volumeBar)) {
  11212. options.volumeBar = options.volumeBar || {};
  11213. options.volumeBar.vertical = options.vertical;
  11214. }
  11215. // hide this control if volume support is missing
  11216. var _this = possibleConstructorReturn(this, _Component.call(this, player, options));
  11217. checkVolumeSupport(_this, player);
  11218. _this.throttledHandleMouseMove = throttle(bind(_this, _this.handleMouseMove), 25);
  11219. _this.on('mousedown', _this.handleMouseDown);
  11220. _this.on('touchstart', _this.handleMouseDown);
  11221. // while the slider is active (the mouse has been pressed down and
  11222. // is dragging) or in focus we do not want to hide the VolumeBar
  11223. _this.on(_this.volumeBar, ['focus', 'slideractive'], function () {
  11224. _this.volumeBar.addClass('vjs-slider-active');
  11225. _this.addClass('vjs-slider-active');
  11226. _this.trigger('slideractive');
  11227. });
  11228. _this.on(_this.volumeBar, ['blur', 'sliderinactive'], function () {
  11229. _this.volumeBar.removeClass('vjs-slider-active');
  11230. _this.removeClass('vjs-slider-active');
  11231. _this.trigger('sliderinactive');
  11232. });
  11233. return _this;
  11234. }
  11235. /**
  11236. * Create the `Component`'s DOM element
  11237. *
  11238. * @return {Element}
  11239. * The element that was created.
  11240. */
  11241. VolumeControl.prototype.createEl = function createEl() {
  11242. var orientationClass = 'vjs-volume-horizontal';
  11243. if (this.options_.vertical) {
  11244. orientationClass = 'vjs-volume-vertical';
  11245. }
  11246. return _Component.prototype.createEl.call(this, 'div', {
  11247. className: 'vjs-volume-control vjs-control ' + orientationClass
  11248. });
  11249. };
  11250. /**
  11251. * Handle `mousedown` or `touchstart` events on the `VolumeControl`.
  11252. *
  11253. * @param {EventTarget~Event} event
  11254. * `mousedown` or `touchstart` event that triggered this function
  11255. *
  11256. * @listens mousedown
  11257. * @listens touchstart
  11258. */
  11259. VolumeControl.prototype.handleMouseDown = function handleMouseDown(event) {
  11260. var doc = this.el_.ownerDocument;
  11261. this.on(doc, 'mousemove', this.throttledHandleMouseMove);
  11262. this.on(doc, 'touchmove', this.throttledHandleMouseMove);
  11263. this.on(doc, 'mouseup', this.handleMouseUp);
  11264. this.on(doc, 'touchend', this.handleMouseUp);
  11265. };
  11266. /**
  11267. * Handle `mouseup` or `touchend` events on the `VolumeControl`.
  11268. *
  11269. * @param {EventTarget~Event} event
  11270. * `mouseup` or `touchend` event that triggered this function.
  11271. *
  11272. * @listens touchend
  11273. * @listens mouseup
  11274. */
  11275. VolumeControl.prototype.handleMouseUp = function handleMouseUp(event) {
  11276. var doc = this.el_.ownerDocument;
  11277. this.off(doc, 'mousemove', this.throttledHandleMouseMove);
  11278. this.off(doc, 'touchmove', this.throttledHandleMouseMove);
  11279. this.off(doc, 'mouseup', this.handleMouseUp);
  11280. this.off(doc, 'touchend', this.handleMouseUp);
  11281. };
  11282. /**
  11283. * Handle `mousedown` or `touchstart` events on the `VolumeControl`.
  11284. *
  11285. * @param {EventTarget~Event} event
  11286. * `mousedown` or `touchstart` event that triggered this function
  11287. *
  11288. * @listens mousedown
  11289. * @listens touchstart
  11290. */
  11291. VolumeControl.prototype.handleMouseMove = function handleMouseMove(event) {
  11292. this.volumeBar.handleMouseMove(event);
  11293. };
  11294. return VolumeControl;
  11295. }(Component);
  11296. /**
  11297. * Default options for the `VolumeControl`
  11298. *
  11299. * @type {Object}
  11300. * @private
  11301. */
  11302. VolumeControl.prototype.options_ = {
  11303. children: ['volumeBar']
  11304. };
  11305. Component.registerComponent('VolumeControl', VolumeControl);
  11306. /**
  11307. * Check if muting volume is supported and if it isn't hide the mute toggle
  11308. * button.
  11309. *
  11310. * @param {Component} self
  11311. * A reference to the mute toggle button
  11312. *
  11313. * @param {Player} player
  11314. * A reference to the player
  11315. *
  11316. * @private
  11317. */
  11318. var checkMuteSupport = function checkMuteSupport(self, player) {
  11319. // hide mute toggle button if it's not supported by the current tech
  11320. if (player.tech_ && !player.tech_.featuresMuteControl) {
  11321. self.addClass('vjs-hidden');
  11322. }
  11323. self.on(player, 'loadstart', function () {
  11324. if (!player.tech_.featuresMuteControl) {
  11325. self.addClass('vjs-hidden');
  11326. } else {
  11327. self.removeClass('vjs-hidden');
  11328. }
  11329. });
  11330. };
  11331. /**
  11332. * @file mute-toggle.js
  11333. */
  11334. /**
  11335. * A button component for muting the audio.
  11336. *
  11337. * @extends Button
  11338. */
  11339. var MuteToggle = function (_Button) {
  11340. inherits(MuteToggle, _Button);
  11341. /**
  11342. * Creates an instance of this class.
  11343. *
  11344. * @param {Player} player
  11345. * The `Player` that this class should be attached to.
  11346. *
  11347. * @param {Object} [options]
  11348. * The key/value store of player options.
  11349. */
  11350. function MuteToggle(player, options) {
  11351. classCallCheck(this, MuteToggle);
  11352. // hide this control if volume support is missing
  11353. var _this = possibleConstructorReturn(this, _Button.call(this, player, options));
  11354. checkMuteSupport(_this, player);
  11355. _this.on(player, ['loadstart', 'volumechange'], _this.update);
  11356. return _this;
  11357. }
  11358. /**
  11359. * Builds the default DOM `className`.
  11360. *
  11361. * @return {string}
  11362. * The DOM `className` for this object.
  11363. */
  11364. MuteToggle.prototype.buildCSSClass = function buildCSSClass() {
  11365. return 'vjs-mute-control ' + _Button.prototype.buildCSSClass.call(this);
  11366. };
  11367. /**
  11368. * This gets called when an `MuteToggle` is "clicked". See
  11369. * {@link ClickableComponent} for more detailed information on what a click can be.
  11370. *
  11371. * @param {EventTarget~Event} [event]
  11372. * The `keydown`, `tap`, or `click` event that caused this function to be
  11373. * called.
  11374. *
  11375. * @listens tap
  11376. * @listens click
  11377. */
  11378. MuteToggle.prototype.handleClick = function handleClick(event) {
  11379. var vol = this.player_.volume();
  11380. var lastVolume = this.player_.lastVolume_();
  11381. if (vol === 0) {
  11382. var volumeToSet = lastVolume < 0.1 ? 0.1 : lastVolume;
  11383. this.player_.volume(volumeToSet);
  11384. this.player_.muted(false);
  11385. } else {
  11386. this.player_.muted(this.player_.muted() ? false : true);
  11387. }
  11388. };
  11389. /**
  11390. * Update the `MuteToggle` button based on the state of `volume` and `muted`
  11391. * on the player.
  11392. *
  11393. * @param {EventTarget~Event} [event]
  11394. * The {@link Player#loadstart} event if this function was called
  11395. * through an event.
  11396. *
  11397. * @listens Player#loadstart
  11398. * @listens Player#volumechange
  11399. */
  11400. MuteToggle.prototype.update = function update(event) {
  11401. this.updateIcon_();
  11402. this.updateControlText_();
  11403. };
  11404. /**
  11405. * Update the appearance of the `MuteToggle` icon.
  11406. *
  11407. * Possible states (given `level` variable below):
  11408. * - 0: crossed out
  11409. * - 1: zero bars of volume
  11410. * - 2: one bar of volume
  11411. * - 3: two bars of volume
  11412. *
  11413. * @private
  11414. */
  11415. MuteToggle.prototype.updateIcon_ = function updateIcon_() {
  11416. var vol = this.player_.volume();
  11417. var level = 3;
  11418. // in iOS when a player is loaded with muted attribute
  11419. // and volume is changed with a native mute button
  11420. // we want to make sure muted state is updated
  11421. if (IS_IOS) {
  11422. this.player_.muted(this.player_.tech_.el_.muted);
  11423. }
  11424. if (vol === 0 || this.player_.muted()) {
  11425. level = 0;
  11426. } else if (vol < 0.33) {
  11427. level = 1;
  11428. } else if (vol < 0.67) {
  11429. level = 2;
  11430. }
  11431. // TODO improve muted icon classes
  11432. for (var i = 0; i < 4; i++) {
  11433. removeClass(this.el_, 'vjs-vol-' + i);
  11434. }
  11435. addClass(this.el_, 'vjs-vol-' + level);
  11436. };
  11437. /**
  11438. * If `muted` has changed on the player, update the control text
  11439. * (`title` attribute on `vjs-mute-control` element and content of
  11440. * `vjs-control-text` element).
  11441. *
  11442. * @private
  11443. */
  11444. MuteToggle.prototype.updateControlText_ = function updateControlText_() {
  11445. var soundOff = this.player_.muted() || this.player_.volume() === 0;
  11446. var text = soundOff ? 'Unmute' : 'Mute';
  11447. if (this.controlText() !== text) {
  11448. this.controlText(text);
  11449. }
  11450. };
  11451. return MuteToggle;
  11452. }(Button);
  11453. /**
  11454. * The text that should display over the `MuteToggle`s controls. Added for localization.
  11455. *
  11456. * @type {string}
  11457. * @private
  11458. */
  11459. MuteToggle.prototype.controlText_ = 'Mute';
  11460. Component.registerComponent('MuteToggle', MuteToggle);
  11461. /**
  11462. * @file volume-control.js
  11463. */
  11464. // Required children
  11465. /**
  11466. * A Component to contain the MuteToggle and VolumeControl so that
  11467. * they can work together.
  11468. *
  11469. * @extends Component
  11470. */
  11471. var VolumePanel = function (_Component) {
  11472. inherits(VolumePanel, _Component);
  11473. /**
  11474. * Creates an instance of this class.
  11475. *
  11476. * @param {Player} player
  11477. * The `Player` that this class should be attached to.
  11478. *
  11479. * @param {Object} [options={}]
  11480. * The key/value store of player options.
  11481. */
  11482. function VolumePanel(player) {
  11483. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  11484. classCallCheck(this, VolumePanel);
  11485. if (typeof options.inline !== 'undefined') {
  11486. options.inline = options.inline;
  11487. } else {
  11488. options.inline = true;
  11489. }
  11490. // pass the inline option down to the VolumeControl as vertical if
  11491. // the VolumeControl is on.
  11492. if (typeof options.volumeControl === 'undefined' || isPlain(options.volumeControl)) {
  11493. options.volumeControl = options.volumeControl || {};
  11494. options.volumeControl.vertical = !options.inline;
  11495. }
  11496. var _this = possibleConstructorReturn(this, _Component.call(this, player, options));
  11497. _this.on(player, ['loadstart'], _this.volumePanelState_);
  11498. // while the slider is active (the mouse has been pressed down and
  11499. // is dragging) we do not want to hide the VolumeBar
  11500. _this.on(_this.volumeControl, ['slideractive'], _this.sliderActive_);
  11501. _this.on(_this.volumeControl, ['sliderinactive'], _this.sliderInactive_);
  11502. return _this;
  11503. }
  11504. /**
  11505. * Add vjs-slider-active class to the VolumePanel
  11506. *
  11507. * @listens VolumeControl#slideractive
  11508. * @private
  11509. */
  11510. VolumePanel.prototype.sliderActive_ = function sliderActive_() {
  11511. this.addClass('vjs-slider-active');
  11512. };
  11513. /**
  11514. * Removes vjs-slider-active class to the VolumePanel
  11515. *
  11516. * @listens VolumeControl#sliderinactive
  11517. * @private
  11518. */
  11519. VolumePanel.prototype.sliderInactive_ = function sliderInactive_() {
  11520. this.removeClass('vjs-slider-active');
  11521. };
  11522. /**
  11523. * Adds vjs-hidden or vjs-mute-toggle-only to the VolumePanel
  11524. * depending on MuteToggle and VolumeControl state
  11525. *
  11526. * @listens Player#loadstart
  11527. * @private
  11528. */
  11529. VolumePanel.prototype.volumePanelState_ = function volumePanelState_() {
  11530. // hide volume panel if neither volume control or mute toggle
  11531. // are displayed
  11532. if (this.volumeControl.hasClass('vjs-hidden') && this.muteToggle.hasClass('vjs-hidden')) {
  11533. this.addClass('vjs-hidden');
  11534. }
  11535. // if only mute toggle is visible we don't want
  11536. // volume panel expanding when hovered or active
  11537. if (this.volumeControl.hasClass('vjs-hidden') && !this.muteToggle.hasClass('vjs-hidden')) {
  11538. this.addClass('vjs-mute-toggle-only');
  11539. }
  11540. };
  11541. /**
  11542. * Create the `Component`'s DOM element
  11543. *
  11544. * @return {Element}
  11545. * The element that was created.
  11546. */
  11547. VolumePanel.prototype.createEl = function createEl() {
  11548. var orientationClass = 'vjs-volume-panel-horizontal';
  11549. if (!this.options_.inline) {
  11550. orientationClass = 'vjs-volume-panel-vertical';
  11551. }
  11552. return _Component.prototype.createEl.call(this, 'div', {
  11553. className: 'vjs-volume-panel vjs-control ' + orientationClass
  11554. });
  11555. };
  11556. return VolumePanel;
  11557. }(Component);
  11558. /**
  11559. * Default options for the `VolumeControl`
  11560. *
  11561. * @type {Object}
  11562. * @private
  11563. */
  11564. VolumePanel.prototype.options_ = {
  11565. children: ['muteToggle', 'volumeControl']
  11566. };
  11567. Component.registerComponent('VolumePanel', VolumePanel);
  11568. /**
  11569. * @file menu.js
  11570. */
  11571. /**
  11572. * The Menu component is used to build popup menus, including subtitle and
  11573. * captions selection menus.
  11574. *
  11575. * @extends Component
  11576. */
  11577. var Menu = function (_Component) {
  11578. inherits(Menu, _Component);
  11579. /**
  11580. * Create an instance of this class.
  11581. *
  11582. * @param {Player} player
  11583. * the player that this component should attach to
  11584. *
  11585. * @param {Object} [options]
  11586. * Object of option names and values
  11587. *
  11588. */
  11589. function Menu(player, options) {
  11590. classCallCheck(this, Menu);
  11591. var _this = possibleConstructorReturn(this, _Component.call(this, player, options));
  11592. if (options) {
  11593. _this.menuButton_ = options.menuButton;
  11594. }
  11595. _this.focusedChild_ = -1;
  11596. _this.on('keydown', _this.handleKeyPress);
  11597. return _this;
  11598. }
  11599. /**
  11600. * Add a {@link MenuItem} to the menu.
  11601. *
  11602. * @param {Object|string} component
  11603. * The name or instance of the `MenuItem` to add.
  11604. *
  11605. */
  11606. Menu.prototype.addItem = function addItem(component) {
  11607. this.addChild(component);
  11608. component.on('click', bind(this, function (event) {
  11609. // Unpress the associated MenuButton, and move focus back to it
  11610. if (this.menuButton_) {
  11611. this.menuButton_.unpressButton();
  11612. // don't focus menu button if item is a caption settings item
  11613. // because focus will move elsewhere and it logs an error on IE8
  11614. if (component.name() !== 'CaptionSettingsMenuItem') {
  11615. this.menuButton_.focus();
  11616. }
  11617. }
  11618. }));
  11619. };
  11620. /**
  11621. * Create the `Menu`s DOM element.
  11622. *
  11623. * @return {Element}
  11624. * the element that was created
  11625. */
  11626. Menu.prototype.createEl = function createEl$$1() {
  11627. var contentElType = this.options_.contentElType || 'ul';
  11628. this.contentEl_ = createEl(contentElType, {
  11629. className: 'vjs-menu-content'
  11630. });
  11631. this.contentEl_.setAttribute('role', 'menu');
  11632. var el = _Component.prototype.createEl.call(this, 'div', {
  11633. append: this.contentEl_,
  11634. className: 'vjs-menu'
  11635. });
  11636. el.appendChild(this.contentEl_);
  11637. // Prevent clicks from bubbling up. Needed for Menu Buttons,
  11638. // where a click on the parent is significant
  11639. on(el, 'click', function (event) {
  11640. event.preventDefault();
  11641. event.stopImmediatePropagation();
  11642. });
  11643. return el;
  11644. };
  11645. Menu.prototype.dispose = function dispose() {
  11646. this.contentEl_ = null;
  11647. _Component.prototype.dispose.call(this);
  11648. };
  11649. /**
  11650. * Handle a `keydown` event on this menu. This listener is added in the constructor.
  11651. *
  11652. * @param {EventTarget~Event} event
  11653. * A `keydown` event that happened on the menu.
  11654. *
  11655. * @listens keydown
  11656. */
  11657. Menu.prototype.handleKeyPress = function handleKeyPress(event) {
  11658. // Left and Down Arrows
  11659. if (event.which === 37 || event.which === 40) {
  11660. event.preventDefault();
  11661. this.stepForward();
  11662. // Up and Right Arrows
  11663. } else if (event.which === 38 || event.which === 39) {
  11664. event.preventDefault();
  11665. this.stepBack();
  11666. }
  11667. };
  11668. /**
  11669. * Move to next (lower) menu item for keyboard users.
  11670. */
  11671. Menu.prototype.stepForward = function stepForward() {
  11672. var stepChild = 0;
  11673. if (this.focusedChild_ !== undefined) {
  11674. stepChild = this.focusedChild_ + 1;
  11675. }
  11676. this.focus(stepChild);
  11677. };
  11678. /**
  11679. * Move to previous (higher) menu item for keyboard users.
  11680. */
  11681. Menu.prototype.stepBack = function stepBack() {
  11682. var stepChild = 0;
  11683. if (this.focusedChild_ !== undefined) {
  11684. stepChild = this.focusedChild_ - 1;
  11685. }
  11686. this.focus(stepChild);
  11687. };
  11688. /**
  11689. * Set focus on a {@link MenuItem} in the `Menu`.
  11690. *
  11691. * @param {Object|string} [item=0]
  11692. * Index of child item set focus on.
  11693. */
  11694. Menu.prototype.focus = function focus() {
  11695. var item = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  11696. var children = this.children().slice();
  11697. var haveTitle = children.length && children[0].className && /vjs-menu-title/.test(children[0].className);
  11698. if (haveTitle) {
  11699. children.shift();
  11700. }
  11701. if (children.length > 0) {
  11702. if (item < 0) {
  11703. item = 0;
  11704. } else if (item >= children.length) {
  11705. item = children.length - 1;
  11706. }
  11707. this.focusedChild_ = item;
  11708. children[item].el_.focus();
  11709. }
  11710. };
  11711. return Menu;
  11712. }(Component);
  11713. Component.registerComponent('Menu', Menu);
  11714. /**
  11715. * @file menu-button.js
  11716. */
  11717. /**
  11718. * A `MenuButton` class for any popup {@link Menu}.
  11719. *
  11720. * @extends Component
  11721. */
  11722. var MenuButton = function (_Component) {
  11723. inherits(MenuButton, _Component);
  11724. /**
  11725. * Creates an instance of this class.
  11726. *
  11727. * @param {Player} player
  11728. * The `Player` that this class should be attached to.
  11729. *
  11730. * @param {Object} [options={}]
  11731. * The key/value store of player options.
  11732. */
  11733. function MenuButton(player) {
  11734. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  11735. classCallCheck(this, MenuButton);
  11736. var _this = possibleConstructorReturn(this, _Component.call(this, player, options));
  11737. _this.menuButton_ = new Button(player, options);
  11738. _this.menuButton_.controlText(_this.controlText_);
  11739. _this.menuButton_.el_.setAttribute('aria-haspopup', 'true');
  11740. // Add buildCSSClass values to the button, not the wrapper
  11741. var buttonClass = Button.prototype.buildCSSClass();
  11742. _this.menuButton_.el_.className = _this.buildCSSClass() + ' ' + buttonClass;
  11743. _this.menuButton_.removeClass('vjs-control');
  11744. _this.addChild(_this.menuButton_);
  11745. _this.update();
  11746. _this.enabled_ = true;
  11747. _this.on(_this.menuButton_, 'tap', _this.handleClick);
  11748. _this.on(_this.menuButton_, 'click', _this.handleClick);
  11749. _this.on(_this.menuButton_, 'focus', _this.handleFocus);
  11750. _this.on(_this.menuButton_, 'blur', _this.handleBlur);
  11751. _this.on('keydown', _this.handleSubmenuKeyPress);
  11752. return _this;
  11753. }
  11754. /**
  11755. * Update the menu based on the current state of its items.
  11756. */
  11757. MenuButton.prototype.update = function update() {
  11758. var menu = this.createMenu();
  11759. if (this.menu) {
  11760. this.menu.dispose();
  11761. this.removeChild(this.menu);
  11762. }
  11763. this.menu = menu;
  11764. this.addChild(menu);
  11765. /**
  11766. * Track the state of the menu button
  11767. *
  11768. * @type {Boolean}
  11769. * @private
  11770. */
  11771. this.buttonPressed_ = false;
  11772. this.menuButton_.el_.setAttribute('aria-expanded', 'false');
  11773. if (this.items && this.items.length <= this.hideThreshold_) {
  11774. this.hide();
  11775. } else {
  11776. this.show();
  11777. }
  11778. };
  11779. /**
  11780. * Create the menu and add all items to it.
  11781. *
  11782. * @return {Menu}
  11783. * The constructed menu
  11784. */
  11785. MenuButton.prototype.createMenu = function createMenu() {
  11786. var menu = new Menu(this.player_, { menuButton: this });
  11787. /**
  11788. * Hide the menu if the number of items is less than or equal to this threshold. This defaults
  11789. * to 0 and whenever we add items which can be hidden to the menu we'll increment it. We list
  11790. * it here because every time we run `createMenu` we need to reset the value.
  11791. *
  11792. * @protected
  11793. * @type {Number}
  11794. */
  11795. this.hideThreshold_ = 0;
  11796. // Add a title list item to the top
  11797. if (this.options_.title) {
  11798. var title = createEl('li', {
  11799. className: 'vjs-menu-title',
  11800. innerHTML: toTitleCase(this.options_.title),
  11801. tabIndex: -1
  11802. });
  11803. this.hideThreshold_ += 1;
  11804. menu.children_.unshift(title);
  11805. prependTo(title, menu.contentEl());
  11806. }
  11807. this.items = this.createItems();
  11808. if (this.items) {
  11809. // Add menu items to the menu
  11810. for (var i = 0; i < this.items.length; i++) {
  11811. menu.addItem(this.items[i]);
  11812. }
  11813. }
  11814. return menu;
  11815. };
  11816. /**
  11817. * Create the list of menu items. Specific to each subclass.
  11818. *
  11819. * @abstract
  11820. */
  11821. MenuButton.prototype.createItems = function createItems() {};
  11822. /**
  11823. * Create the `MenuButtons`s DOM element.
  11824. *
  11825. * @return {Element}
  11826. * The element that gets created.
  11827. */
  11828. MenuButton.prototype.createEl = function createEl$$1() {
  11829. return _Component.prototype.createEl.call(this, 'div', {
  11830. className: this.buildWrapperCSSClass()
  11831. }, {});
  11832. };
  11833. /**
  11834. * Allow sub components to stack CSS class names for the wrapper element
  11835. *
  11836. * @return {string}
  11837. * The constructed wrapper DOM `className`
  11838. */
  11839. MenuButton.prototype.buildWrapperCSSClass = function buildWrapperCSSClass() {
  11840. var menuButtonClass = 'vjs-menu-button';
  11841. // If the inline option is passed, we want to use different styles altogether.
  11842. if (this.options_.inline === true) {
  11843. menuButtonClass += '-inline';
  11844. } else {
  11845. menuButtonClass += '-popup';
  11846. }
  11847. // TODO: Fix the CSS so that this isn't necessary
  11848. var buttonClass = Button.prototype.buildCSSClass();
  11849. return 'vjs-menu-button ' + menuButtonClass + ' ' + buttonClass + ' ' + _Component.prototype.buildCSSClass.call(this);
  11850. };
  11851. /**
  11852. * Builds the default DOM `className`.
  11853. *
  11854. * @return {string}
  11855. * The DOM `className` for this object.
  11856. */
  11857. MenuButton.prototype.buildCSSClass = function buildCSSClass() {
  11858. var menuButtonClass = 'vjs-menu-button';
  11859. // If the inline option is passed, we want to use different styles altogether.
  11860. if (this.options_.inline === true) {
  11861. menuButtonClass += '-inline';
  11862. } else {
  11863. menuButtonClass += '-popup';
  11864. }
  11865. return 'vjs-menu-button ' + menuButtonClass + ' ' + _Component.prototype.buildCSSClass.call(this);
  11866. };
  11867. /**
  11868. * Get or set the localized control text that will be used for accessibility.
  11869. *
  11870. * > NOTE: This will come from the internal `menuButton_` element.
  11871. *
  11872. * @param {string} [text]
  11873. * Control text for element.
  11874. *
  11875. * @param {Element} [el=this.menuButton_.el()]
  11876. * Element to set the title on.
  11877. *
  11878. * @return {string}
  11879. * - The control text when getting
  11880. */
  11881. MenuButton.prototype.controlText = function controlText(text) {
  11882. var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.menuButton_.el();
  11883. return this.menuButton_.controlText(text, el);
  11884. };
  11885. /**
  11886. * Handle a click on a `MenuButton`.
  11887. * See {@link ClickableComponent#handleClick} for instances where this is called.
  11888. *
  11889. * @param {EventTarget~Event} event
  11890. * The `keydown`, `tap`, or `click` event that caused this function to be
  11891. * called.
  11892. *
  11893. * @listens tap
  11894. * @listens click
  11895. */
  11896. MenuButton.prototype.handleClick = function handleClick(event) {
  11897. // When you click the button it adds focus, which will show the menu.
  11898. // So we'll remove focus when the mouse leaves the button. Focus is needed
  11899. // for tab navigation.
  11900. this.one(this.menu.contentEl(), 'mouseleave', bind(this, function (e) {
  11901. this.unpressButton();
  11902. this.el_.blur();
  11903. }));
  11904. if (this.buttonPressed_) {
  11905. this.unpressButton();
  11906. } else {
  11907. this.pressButton();
  11908. }
  11909. };
  11910. /**
  11911. * Set the focus to the actual button, not to this element
  11912. */
  11913. MenuButton.prototype.focus = function focus() {
  11914. this.menuButton_.focus();
  11915. };
  11916. /**
  11917. * Remove the focus from the actual button, not this element
  11918. */
  11919. MenuButton.prototype.blur = function blur() {
  11920. this.menuButton_.blur();
  11921. };
  11922. /**
  11923. * This gets called when a `MenuButton` gains focus via a `focus` event.
  11924. * Turns on listening for `keydown` events. When they happen it
  11925. * calls `this.handleKeyPress`.
  11926. *
  11927. * @param {EventTarget~Event} event
  11928. * The `focus` event that caused this function to be called.
  11929. *
  11930. * @listens focus
  11931. */
  11932. MenuButton.prototype.handleFocus = function handleFocus() {
  11933. on(document, 'keydown', bind(this, this.handleKeyPress));
  11934. };
  11935. /**
  11936. * Called when a `MenuButton` loses focus. Turns off the listener for
  11937. * `keydown` events. Which Stops `this.handleKeyPress` from getting called.
  11938. *
  11939. * @param {EventTarget~Event} event
  11940. * The `blur` event that caused this function to be called.
  11941. *
  11942. * @listens blur
  11943. */
  11944. MenuButton.prototype.handleBlur = function handleBlur() {
  11945. off(document, 'keydown', bind(this, this.handleKeyPress));
  11946. };
  11947. /**
  11948. * Handle tab, escape, down arrow, and up arrow keys for `MenuButton`. See
  11949. * {@link ClickableComponent#handleKeyPress} for instances where this is called.
  11950. *
  11951. * @param {EventTarget~Event} event
  11952. * The `keydown` event that caused this function to be called.
  11953. *
  11954. * @listens keydown
  11955. */
  11956. MenuButton.prototype.handleKeyPress = function handleKeyPress(event) {
  11957. // Escape (27) key or Tab (9) key unpress the 'button'
  11958. if (event.which === 27 || event.which === 9) {
  11959. if (this.buttonPressed_) {
  11960. this.unpressButton();
  11961. }
  11962. // Don't preventDefault for Tab key - we still want to lose focus
  11963. if (event.which !== 9) {
  11964. event.preventDefault();
  11965. // Set focus back to the menu button's button
  11966. this.menuButton_.el_.focus();
  11967. }
  11968. // Up (38) key or Down (40) key press the 'button'
  11969. } else if (event.which === 38 || event.which === 40) {
  11970. if (!this.buttonPressed_) {
  11971. this.pressButton();
  11972. event.preventDefault();
  11973. }
  11974. }
  11975. };
  11976. /**
  11977. * Handle a `keydown` event on a sub-menu. The listener for this is added in
  11978. * the constructor.
  11979. *
  11980. * @param {EventTarget~Event} event
  11981. * Key press event
  11982. *
  11983. * @listens keydown
  11984. */
  11985. MenuButton.prototype.handleSubmenuKeyPress = function handleSubmenuKeyPress(event) {
  11986. // Escape (27) key or Tab (9) key unpress the 'button'
  11987. if (event.which === 27 || event.which === 9) {
  11988. if (this.buttonPressed_) {
  11989. this.unpressButton();
  11990. }
  11991. // Don't preventDefault for Tab key - we still want to lose focus
  11992. if (event.which !== 9) {
  11993. event.preventDefault();
  11994. // Set focus back to the menu button's button
  11995. this.menuButton_.el_.focus();
  11996. }
  11997. }
  11998. };
  11999. /**
  12000. * Put the current `MenuButton` into a pressed state.
  12001. */
  12002. MenuButton.prototype.pressButton = function pressButton() {
  12003. if (this.enabled_) {
  12004. this.buttonPressed_ = true;
  12005. this.menu.lockShowing();
  12006. this.menuButton_.el_.setAttribute('aria-expanded', 'true');
  12007. // set the focus into the submenu, except on iOS where it is resulting in
  12008. // undesired scrolling behavior when the player is in an iframe
  12009. if (IS_IOS && isInFrame()) {
  12010. // Return early so that the menu isn't focused
  12011. return;
  12012. }
  12013. this.menu.focus();
  12014. }
  12015. };
  12016. /**
  12017. * Take the current `MenuButton` out of a pressed state.
  12018. */
  12019. MenuButton.prototype.unpressButton = function unpressButton() {
  12020. if (this.enabled_) {
  12021. this.buttonPressed_ = false;
  12022. this.menu.unlockShowing();
  12023. this.menuButton_.el_.setAttribute('aria-expanded', 'false');
  12024. }
  12025. };
  12026. /**
  12027. * Disable the `MenuButton`. Don't allow it to be clicked.
  12028. */
  12029. MenuButton.prototype.disable = function disable() {
  12030. this.unpressButton();
  12031. this.enabled_ = false;
  12032. this.addClass('vjs-disabled');
  12033. this.menuButton_.disable();
  12034. };
  12035. /**
  12036. * Enable the `MenuButton`. Allow it to be clicked.
  12037. */
  12038. MenuButton.prototype.enable = function enable() {
  12039. this.enabled_ = true;
  12040. this.removeClass('vjs-disabled');
  12041. this.menuButton_.enable();
  12042. };
  12043. return MenuButton;
  12044. }(Component);
  12045. Component.registerComponent('MenuButton', MenuButton);
  12046. /**
  12047. * @file track-button.js
  12048. */
  12049. /**
  12050. * The base class for buttons that toggle specific track types (e.g. subtitles).
  12051. *
  12052. * @extends MenuButton
  12053. */
  12054. var TrackButton = function (_MenuButton) {
  12055. inherits(TrackButton, _MenuButton);
  12056. /**
  12057. * Creates an instance of this class.
  12058. *
  12059. * @param {Player} player
  12060. * The `Player` that this class should be attached to.
  12061. *
  12062. * @param {Object} [options]
  12063. * The key/value store of player options.
  12064. */
  12065. function TrackButton(player, options) {
  12066. classCallCheck(this, TrackButton);
  12067. var tracks = options.tracks;
  12068. var _this = possibleConstructorReturn(this, _MenuButton.call(this, player, options));
  12069. if (_this.items.length <= 1) {
  12070. _this.hide();
  12071. }
  12072. if (!tracks) {
  12073. return possibleConstructorReturn(_this);
  12074. }
  12075. var updateHandler = bind(_this, _this.update);
  12076. tracks.addEventListener('removetrack', updateHandler);
  12077. tracks.addEventListener('addtrack', updateHandler);
  12078. _this.player_.on('ready', updateHandler);
  12079. _this.player_.on('dispose', function () {
  12080. tracks.removeEventListener('removetrack', updateHandler);
  12081. tracks.removeEventListener('addtrack', updateHandler);
  12082. });
  12083. return _this;
  12084. }
  12085. return TrackButton;
  12086. }(MenuButton);
  12087. Component.registerComponent('TrackButton', TrackButton);
  12088. /**
  12089. * @file menu-item.js
  12090. */
  12091. /**
  12092. * The component for a menu item. `<li>`
  12093. *
  12094. * @extends ClickableComponent
  12095. */
  12096. var MenuItem = function (_ClickableComponent) {
  12097. inherits(MenuItem, _ClickableComponent);
  12098. /**
  12099. * Creates an instance of the this class.
  12100. *
  12101. * @param {Player} player
  12102. * The `Player` that this class should be attached to.
  12103. *
  12104. * @param {Object} [options={}]
  12105. * The key/value store of player options.
  12106. *
  12107. */
  12108. function MenuItem(player, options) {
  12109. classCallCheck(this, MenuItem);
  12110. var _this = possibleConstructorReturn(this, _ClickableComponent.call(this, player, options));
  12111. _this.selectable = options.selectable;
  12112. _this.isSelected_ = options.selected || false;
  12113. _this.multiSelectable = options.multiSelectable;
  12114. _this.selected(_this.isSelected_);
  12115. if (_this.selectable) {
  12116. if (_this.multiSelectable) {
  12117. _this.el_.setAttribute('role', 'menuitemcheckbox');
  12118. } else {
  12119. _this.el_.setAttribute('role', 'menuitemradio');
  12120. }
  12121. } else {
  12122. _this.el_.setAttribute('role', 'menuitem');
  12123. }
  12124. return _this;
  12125. }
  12126. /**
  12127. * Create the `MenuItem's DOM element
  12128. *
  12129. * @param {string} [type=li]
  12130. * Element's node type, not actually used, always set to `li`.
  12131. *
  12132. * @param {Object} [props={}]
  12133. * An object of properties that should be set on the element
  12134. *
  12135. * @param {Object} [attrs={}]
  12136. * An object of attributes that should be set on the element
  12137. *
  12138. * @return {Element}
  12139. * The element that gets created.
  12140. */
  12141. MenuItem.prototype.createEl = function createEl(type, props, attrs) {
  12142. // The control is textual, not just an icon
  12143. this.nonIconControl = true;
  12144. return _ClickableComponent.prototype.createEl.call(this, 'li', assign({
  12145. className: 'vjs-menu-item',
  12146. innerHTML: '<span class="vjs-menu-item-text">' + this.localize(this.options_.label) + '</span>',
  12147. tabIndex: -1
  12148. }, props), attrs);
  12149. };
  12150. /**
  12151. * Any click on a `MenuItem` puts it into the selected state.
  12152. * See {@link ClickableComponent#handleClick} for instances where this is called.
  12153. *
  12154. * @param {EventTarget~Event} event
  12155. * The `keydown`, `tap`, or `click` event that caused this function to be
  12156. * called.
  12157. *
  12158. * @listens tap
  12159. * @listens click
  12160. */
  12161. MenuItem.prototype.handleClick = function handleClick(event) {
  12162. this.selected(true);
  12163. };
  12164. /**
  12165. * Set the state for this menu item as selected or not.
  12166. *
  12167. * @param {boolean} selected
  12168. * if the menu item is selected or not
  12169. */
  12170. MenuItem.prototype.selected = function selected(_selected) {
  12171. if (this.selectable) {
  12172. if (_selected) {
  12173. this.addClass('vjs-selected');
  12174. this.el_.setAttribute('aria-checked', 'true');
  12175. // aria-checked isn't fully supported by browsers/screen readers,
  12176. // so indicate selected state to screen reader in the control text.
  12177. this.controlText(', selected');
  12178. this.isSelected_ = true;
  12179. } else {
  12180. this.removeClass('vjs-selected');
  12181. this.el_.setAttribute('aria-checked', 'false');
  12182. // Indicate un-selected state to screen reader
  12183. this.controlText('');
  12184. this.isSelected_ = false;
  12185. }
  12186. }
  12187. };
  12188. return MenuItem;
  12189. }(ClickableComponent);
  12190. Component.registerComponent('MenuItem', MenuItem);
  12191. /**
  12192. * @file text-track-menu-item.js
  12193. */
  12194. /**
  12195. * The specific menu item type for selecting a language within a text track kind
  12196. *
  12197. * @extends MenuItem
  12198. */
  12199. var TextTrackMenuItem = function (_MenuItem) {
  12200. inherits(TextTrackMenuItem, _MenuItem);
  12201. /**
  12202. * Creates an instance of this class.
  12203. *
  12204. * @param {Player} player
  12205. * The `Player` that this class should be attached to.
  12206. *
  12207. * @param {Object} [options]
  12208. * The key/value store of player options.
  12209. */
  12210. function TextTrackMenuItem(player, options) {
  12211. classCallCheck(this, TextTrackMenuItem);
  12212. var track = options.track;
  12213. var tracks = player.textTracks();
  12214. // Modify options for parent MenuItem class's init.
  12215. options.label = track.label || track.language || 'Unknown';
  12216. options.selected = track.mode === 'showing';
  12217. var _this = possibleConstructorReturn(this, _MenuItem.call(this, player, options));
  12218. _this.track = track;
  12219. var changeHandler = function changeHandler() {
  12220. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  12221. args[_key] = arguments[_key];
  12222. }
  12223. _this.handleTracksChange.apply(_this, args);
  12224. };
  12225. var selectedLanguageChangeHandler = function selectedLanguageChangeHandler() {
  12226. for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  12227. args[_key2] = arguments[_key2];
  12228. }
  12229. _this.handleSelectedLanguageChange.apply(_this, args);
  12230. };
  12231. player.on(['loadstart', 'texttrackchange'], changeHandler);
  12232. tracks.addEventListener('change', changeHandler);
  12233. tracks.addEventListener('selectedlanguagechange', selectedLanguageChangeHandler);
  12234. _this.on('dispose', function () {
  12235. player.off(['loadstart', 'texttrackchange'], changeHandler);
  12236. tracks.removeEventListener('change', changeHandler);
  12237. tracks.removeEventListener('selectedlanguagechange', selectedLanguageChangeHandler);
  12238. });
  12239. // iOS7 doesn't dispatch change events to TextTrackLists when an
  12240. // associated track's mode changes. Without something like
  12241. // Object.observe() (also not present on iOS7), it's not
  12242. // possible to detect changes to the mode attribute and polyfill
  12243. // the change event. As a poor substitute, we manually dispatch
  12244. // change events whenever the controls modify the mode.
  12245. if (tracks.onchange === undefined) {
  12246. var event = void 0;
  12247. _this.on(['tap', 'click'], function () {
  12248. if (_typeof(window.Event) !== 'object') {
  12249. // Android 2.3 throws an Illegal Constructor error for window.Event
  12250. try {
  12251. event = new window.Event('change');
  12252. } catch (err) {
  12253. // continue regardless of error
  12254. }
  12255. }
  12256. if (!event) {
  12257. event = document.createEvent('Event');
  12258. event.initEvent('change', true, true);
  12259. }
  12260. tracks.dispatchEvent(event);
  12261. });
  12262. }
  12263. // set the default state based on current tracks
  12264. _this.handleTracksChange();
  12265. return _this;
  12266. }
  12267. /**
  12268. * This gets called when an `TextTrackMenuItem` is "clicked". See
  12269. * {@link ClickableComponent} for more detailed information on what a click can be.
  12270. *
  12271. * @param {EventTarget~Event} event
  12272. * The `keydown`, `tap`, or `click` event that caused this function to be
  12273. * called.
  12274. *
  12275. * @listens tap
  12276. * @listens click
  12277. */
  12278. TextTrackMenuItem.prototype.handleClick = function handleClick(event) {
  12279. var kind = this.track.kind;
  12280. var kinds = this.track.kinds;
  12281. var tracks = this.player_.textTracks();
  12282. if (!kinds) {
  12283. kinds = [kind];
  12284. }
  12285. _MenuItem.prototype.handleClick.call(this, event);
  12286. if (!tracks) {
  12287. return;
  12288. }
  12289. for (var i = 0; i < tracks.length; i++) {
  12290. var track = tracks[i];
  12291. if (track === this.track && kinds.indexOf(track.kind) > -1) {
  12292. if (track.mode !== 'showing') {
  12293. track.mode = 'showing';
  12294. }
  12295. } else if (track.mode !== 'disabled') {
  12296. track.mode = 'disabled';
  12297. }
  12298. }
  12299. };
  12300. /**
  12301. * Handle text track list change
  12302. *
  12303. * @param {EventTarget~Event} event
  12304. * The `change` event that caused this function to be called.
  12305. *
  12306. * @listens TextTrackList#change
  12307. */
  12308. TextTrackMenuItem.prototype.handleTracksChange = function handleTracksChange(event) {
  12309. var shouldBeSelected = this.track.mode === 'showing';
  12310. // Prevent redundant selected() calls because they may cause
  12311. // screen readers to read the appended control text unnecessarily
  12312. if (shouldBeSelected !== this.isSelected_) {
  12313. this.selected(shouldBeSelected);
  12314. }
  12315. };
  12316. TextTrackMenuItem.prototype.handleSelectedLanguageChange = function handleSelectedLanguageChange(event) {
  12317. if (this.track.mode === 'showing') {
  12318. var selectedLanguage = this.player_.cache_.selectedLanguage;
  12319. // Don't replace the kind of track across the same language
  12320. if (selectedLanguage && selectedLanguage.enabled && selectedLanguage.language === this.track.language && selectedLanguage.kind !== this.track.kind) {
  12321. return;
  12322. }
  12323. this.player_.cache_.selectedLanguage = {
  12324. enabled: true,
  12325. language: this.track.language,
  12326. kind: this.track.kind
  12327. };
  12328. }
  12329. };
  12330. TextTrackMenuItem.prototype.dispose = function dispose() {
  12331. // remove reference to track object on dispose
  12332. this.track = null;
  12333. _MenuItem.prototype.dispose.call(this);
  12334. };
  12335. return TextTrackMenuItem;
  12336. }(MenuItem);
  12337. Component.registerComponent('TextTrackMenuItem', TextTrackMenuItem);
  12338. /**
  12339. * @file off-text-track-menu-item.js
  12340. */
  12341. /**
  12342. * A special menu item for turning of a specific type of text track
  12343. *
  12344. * @extends TextTrackMenuItem
  12345. */
  12346. var OffTextTrackMenuItem = function (_TextTrackMenuItem) {
  12347. inherits(OffTextTrackMenuItem, _TextTrackMenuItem);
  12348. /**
  12349. * Creates an instance of this class.
  12350. *
  12351. * @param {Player} player
  12352. * The `Player` that this class should be attached to.
  12353. *
  12354. * @param {Object} [options]
  12355. * The key/value store of player options.
  12356. */
  12357. function OffTextTrackMenuItem(player, options) {
  12358. classCallCheck(this, OffTextTrackMenuItem);
  12359. // Create pseudo track info
  12360. // Requires options['kind']
  12361. options.track = {
  12362. player: player,
  12363. kind: options.kind,
  12364. kinds: options.kinds,
  12365. 'default': false,
  12366. mode: 'disabled'
  12367. };
  12368. if (!options.kinds) {
  12369. options.kinds = [options.kind];
  12370. }
  12371. if (options.label) {
  12372. options.track.label = options.label;
  12373. } else {
  12374. options.track.label = options.kinds.join(' and ') + ' off';
  12375. }
  12376. // MenuItem is selectable
  12377. options.selectable = true;
  12378. // MenuItem is NOT multiSelectable (i.e. only one can be marked "selected" at a time)
  12379. options.multiSelectable = false;
  12380. return possibleConstructorReturn(this, _TextTrackMenuItem.call(this, player, options));
  12381. }
  12382. /**
  12383. * Handle text track change
  12384. *
  12385. * @param {EventTarget~Event} event
  12386. * The event that caused this function to run
  12387. */
  12388. OffTextTrackMenuItem.prototype.handleTracksChange = function handleTracksChange(event) {
  12389. var tracks = this.player().textTracks();
  12390. var shouldBeSelected = true;
  12391. for (var i = 0, l = tracks.length; i < l; i++) {
  12392. var track = tracks[i];
  12393. if (this.options_.kinds.indexOf(track.kind) > -1 && track.mode === 'showing') {
  12394. shouldBeSelected = false;
  12395. break;
  12396. }
  12397. }
  12398. // Prevent redundant selected() calls because they may cause
  12399. // screen readers to read the appended control text unnecessarily
  12400. if (shouldBeSelected !== this.isSelected_) {
  12401. this.selected(shouldBeSelected);
  12402. }
  12403. };
  12404. OffTextTrackMenuItem.prototype.handleSelectedLanguageChange = function handleSelectedLanguageChange(event) {
  12405. var tracks = this.player().textTracks();
  12406. var allHidden = true;
  12407. for (var i = 0, l = tracks.length; i < l; i++) {
  12408. var track = tracks[i];
  12409. if (['captions', 'descriptions', 'subtitles'].indexOf(track.kind) > -1 && track.mode === 'showing') {
  12410. allHidden = false;
  12411. break;
  12412. }
  12413. }
  12414. if (allHidden) {
  12415. this.player_.cache_.selectedLanguage = {
  12416. enabled: false
  12417. };
  12418. }
  12419. };
  12420. return OffTextTrackMenuItem;
  12421. }(TextTrackMenuItem);
  12422. Component.registerComponent('OffTextTrackMenuItem', OffTextTrackMenuItem);
  12423. /**
  12424. * @file text-track-button.js
  12425. */
  12426. /**
  12427. * The base class for buttons that toggle specific text track types (e.g. subtitles)
  12428. *
  12429. * @extends MenuButton
  12430. */
  12431. var TextTrackButton = function (_TrackButton) {
  12432. inherits(TextTrackButton, _TrackButton);
  12433. /**
  12434. * Creates an instance of this class.
  12435. *
  12436. * @param {Player} player
  12437. * The `Player` that this class should be attached to.
  12438. *
  12439. * @param {Object} [options={}]
  12440. * The key/value store of player options.
  12441. */
  12442. function TextTrackButton(player) {
  12443. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  12444. classCallCheck(this, TextTrackButton);
  12445. options.tracks = player.textTracks();
  12446. return possibleConstructorReturn(this, _TrackButton.call(this, player, options));
  12447. }
  12448. /**
  12449. * Create a menu item for each text track
  12450. *
  12451. * @param {TextTrackMenuItem[]} [items=[]]
  12452. * Existing array of items to use during creation
  12453. *
  12454. * @return {TextTrackMenuItem[]}
  12455. * Array of menu items that were created
  12456. */
  12457. TextTrackButton.prototype.createItems = function createItems() {
  12458. var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  12459. var TrackMenuItem = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : TextTrackMenuItem;
  12460. // Label is an overide for the [track] off label
  12461. // USed to localise captions/subtitles
  12462. var label = void 0;
  12463. if (this.label_) {
  12464. label = this.label_ + ' off';
  12465. }
  12466. // Add an OFF menu item to turn all tracks off
  12467. items.push(new OffTextTrackMenuItem(this.player_, {
  12468. kinds: this.kinds_,
  12469. kind: this.kind_,
  12470. label: label
  12471. }));
  12472. this.hideThreshold_ += 1;
  12473. var tracks = this.player_.textTracks();
  12474. if (!Array.isArray(this.kinds_)) {
  12475. this.kinds_ = [this.kind_];
  12476. }
  12477. for (var i = 0; i < tracks.length; i++) {
  12478. var track = tracks[i];
  12479. // only add tracks that are of an appropriate kind and have a label
  12480. if (this.kinds_.indexOf(track.kind) > -1) {
  12481. var item = new TrackMenuItem(this.player_, {
  12482. track: track,
  12483. // MenuItem is selectable
  12484. selectable: true,
  12485. // MenuItem is NOT multiSelectable (i.e. only one can be marked "selected" at a time)
  12486. multiSelectable: false
  12487. });
  12488. item.addClass('vjs-' + track.kind + '-menu-item');
  12489. items.push(item);
  12490. }
  12491. }
  12492. return items;
  12493. };
  12494. return TextTrackButton;
  12495. }(TrackButton);
  12496. Component.registerComponent('TextTrackButton', TextTrackButton);
  12497. /**
  12498. * @file chapters-track-menu-item.js
  12499. */
  12500. /**
  12501. * The chapter track menu item
  12502. *
  12503. * @extends MenuItem
  12504. */
  12505. var ChaptersTrackMenuItem = function (_MenuItem) {
  12506. inherits(ChaptersTrackMenuItem, _MenuItem);
  12507. /**
  12508. * Creates an instance of this class.
  12509. *
  12510. * @param {Player} player
  12511. * The `Player` that this class should be attached to.
  12512. *
  12513. * @param {Object} [options]
  12514. * The key/value store of player options.
  12515. */
  12516. function ChaptersTrackMenuItem(player, options) {
  12517. classCallCheck(this, ChaptersTrackMenuItem);
  12518. var track = options.track;
  12519. var cue = options.cue;
  12520. var currentTime = player.currentTime();
  12521. // Modify options for parent MenuItem class's init.
  12522. options.selectable = true;
  12523. options.multiSelectable = false;
  12524. options.label = cue.text;
  12525. options.selected = cue.startTime <= currentTime && currentTime < cue.endTime;
  12526. var _this = possibleConstructorReturn(this, _MenuItem.call(this, player, options));
  12527. _this.track = track;
  12528. _this.cue = cue;
  12529. track.addEventListener('cuechange', bind(_this, _this.update));
  12530. return _this;
  12531. }
  12532. /**
  12533. * This gets called when an `ChaptersTrackMenuItem` is "clicked". See
  12534. * {@link ClickableComponent} for more detailed information on what a click can be.
  12535. *
  12536. * @param {EventTarget~Event} [event]
  12537. * The `keydown`, `tap`, or `click` event that caused this function to be
  12538. * called.
  12539. *
  12540. * @listens tap
  12541. * @listens click
  12542. */
  12543. ChaptersTrackMenuItem.prototype.handleClick = function handleClick(event) {
  12544. _MenuItem.prototype.handleClick.call(this);
  12545. this.player_.currentTime(this.cue.startTime);
  12546. this.update(this.cue.startTime);
  12547. };
  12548. /**
  12549. * Update chapter menu item
  12550. *
  12551. * @param {EventTarget~Event} [event]
  12552. * The `cuechange` event that caused this function to run.
  12553. *
  12554. * @listens TextTrack#cuechange
  12555. */
  12556. ChaptersTrackMenuItem.prototype.update = function update(event) {
  12557. var cue = this.cue;
  12558. var currentTime = this.player_.currentTime();
  12559. // vjs.log(currentTime, cue.startTime);
  12560. this.selected(cue.startTime <= currentTime && currentTime < cue.endTime);
  12561. };
  12562. return ChaptersTrackMenuItem;
  12563. }(MenuItem);
  12564. Component.registerComponent('ChaptersTrackMenuItem', ChaptersTrackMenuItem);
  12565. /**
  12566. * @file chapters-button.js
  12567. */
  12568. /**
  12569. * The button component for toggling and selecting chapters
  12570. * Chapters act much differently than other text tracks
  12571. * Cues are navigation vs. other tracks of alternative languages
  12572. *
  12573. * @extends TextTrackButton
  12574. */
  12575. var ChaptersButton = function (_TextTrackButton) {
  12576. inherits(ChaptersButton, _TextTrackButton);
  12577. /**
  12578. * Creates an instance of this class.
  12579. *
  12580. * @param {Player} player
  12581. * The `Player` that this class should be attached to.
  12582. *
  12583. * @param {Object} [options]
  12584. * The key/value store of player options.
  12585. *
  12586. * @param {Component~ReadyCallback} [ready]
  12587. * The function to call when this function is ready.
  12588. */
  12589. function ChaptersButton(player, options, ready) {
  12590. classCallCheck(this, ChaptersButton);
  12591. return possibleConstructorReturn(this, _TextTrackButton.call(this, player, options, ready));
  12592. }
  12593. /**
  12594. * Builds the default DOM `className`.
  12595. *
  12596. * @return {string}
  12597. * The DOM `className` for this object.
  12598. */
  12599. ChaptersButton.prototype.buildCSSClass = function buildCSSClass() {
  12600. return 'vjs-chapters-button ' + _TextTrackButton.prototype.buildCSSClass.call(this);
  12601. };
  12602. ChaptersButton.prototype.buildWrapperCSSClass = function buildWrapperCSSClass() {
  12603. return 'vjs-chapters-button ' + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  12604. };
  12605. /**
  12606. * Update the menu based on the current state of its items.
  12607. *
  12608. * @param {EventTarget~Event} [event]
  12609. * An event that triggered this function to run.
  12610. *
  12611. * @listens TextTrackList#addtrack
  12612. * @listens TextTrackList#removetrack
  12613. * @listens TextTrackList#change
  12614. */
  12615. ChaptersButton.prototype.update = function update(event) {
  12616. if (!this.track_ || event && (event.type === 'addtrack' || event.type === 'removetrack')) {
  12617. this.setTrack(this.findChaptersTrack());
  12618. }
  12619. _TextTrackButton.prototype.update.call(this);
  12620. };
  12621. /**
  12622. * Set the currently selected track for the chapters button.
  12623. *
  12624. * @param {TextTrack} track
  12625. * The new track to select. Nothing will change if this is the currently selected
  12626. * track.
  12627. */
  12628. ChaptersButton.prototype.setTrack = function setTrack(track) {
  12629. if (this.track_ === track) {
  12630. return;
  12631. }
  12632. if (!this.updateHandler_) {
  12633. this.updateHandler_ = this.update.bind(this);
  12634. }
  12635. // here this.track_ refers to the old track instance
  12636. if (this.track_) {
  12637. var remoteTextTrackEl = this.player_.remoteTextTrackEls().getTrackElementByTrack_(this.track_);
  12638. if (remoteTextTrackEl) {
  12639. remoteTextTrackEl.removeEventListener('load', this.updateHandler_);
  12640. }
  12641. this.track_ = null;
  12642. }
  12643. this.track_ = track;
  12644. // here this.track_ refers to the new track instance
  12645. if (this.track_) {
  12646. this.track_.mode = 'hidden';
  12647. var _remoteTextTrackEl = this.player_.remoteTextTrackEls().getTrackElementByTrack_(this.track_);
  12648. if (_remoteTextTrackEl) {
  12649. _remoteTextTrackEl.addEventListener('load', this.updateHandler_);
  12650. }
  12651. }
  12652. };
  12653. /**
  12654. * Find the track object that is currently in use by this ChaptersButton
  12655. *
  12656. * @return {TextTrack|undefined}
  12657. * The current track or undefined if none was found.
  12658. */
  12659. ChaptersButton.prototype.findChaptersTrack = function findChaptersTrack() {
  12660. var tracks = this.player_.textTracks() || [];
  12661. for (var i = tracks.length - 1; i >= 0; i--) {
  12662. // We will always choose the last track as our chaptersTrack
  12663. var track = tracks[i];
  12664. if (track.kind === this.kind_) {
  12665. return track;
  12666. }
  12667. }
  12668. };
  12669. /**
  12670. * Get the caption for the ChaptersButton based on the track label. This will also
  12671. * use the current tracks localized kind as a fallback if a label does not exist.
  12672. *
  12673. * @return {string}
  12674. * The tracks current label or the localized track kind.
  12675. */
  12676. ChaptersButton.prototype.getMenuCaption = function getMenuCaption() {
  12677. if (this.track_ && this.track_.label) {
  12678. return this.track_.label;
  12679. }
  12680. return this.localize(toTitleCase(this.kind_));
  12681. };
  12682. /**
  12683. * Create menu from chapter track
  12684. *
  12685. * @return {Menu}
  12686. * New menu for the chapter buttons
  12687. */
  12688. ChaptersButton.prototype.createMenu = function createMenu() {
  12689. this.options_.title = this.getMenuCaption();
  12690. return _TextTrackButton.prototype.createMenu.call(this);
  12691. };
  12692. /**
  12693. * Create a menu item for each text track
  12694. *
  12695. * @return {TextTrackMenuItem[]}
  12696. * Array of menu items
  12697. */
  12698. ChaptersButton.prototype.createItems = function createItems() {
  12699. var items = [];
  12700. if (!this.track_) {
  12701. return items;
  12702. }
  12703. var cues = this.track_.cues;
  12704. if (!cues) {
  12705. return items;
  12706. }
  12707. for (var i = 0, l = cues.length; i < l; i++) {
  12708. var cue = cues[i];
  12709. var mi = new ChaptersTrackMenuItem(this.player_, { track: this.track_, cue: cue });
  12710. items.push(mi);
  12711. }
  12712. return items;
  12713. };
  12714. return ChaptersButton;
  12715. }(TextTrackButton);
  12716. /**
  12717. * `kind` of TextTrack to look for to associate it with this menu.
  12718. *
  12719. * @type {string}
  12720. * @private
  12721. */
  12722. ChaptersButton.prototype.kind_ = 'chapters';
  12723. /**
  12724. * The text that should display over the `ChaptersButton`s controls. Added for localization.
  12725. *
  12726. * @type {string}
  12727. * @private
  12728. */
  12729. ChaptersButton.prototype.controlText_ = 'Chapters';
  12730. Component.registerComponent('ChaptersButton', ChaptersButton);
  12731. /**
  12732. * @file descriptions-button.js
  12733. */
  12734. /**
  12735. * The button component for toggling and selecting descriptions
  12736. *
  12737. * @extends TextTrackButton
  12738. */
  12739. var DescriptionsButton = function (_TextTrackButton) {
  12740. inherits(DescriptionsButton, _TextTrackButton);
  12741. /**
  12742. * Creates an instance of this class.
  12743. *
  12744. * @param {Player} player
  12745. * The `Player` that this class should be attached to.
  12746. *
  12747. * @param {Object} [options]
  12748. * The key/value store of player options.
  12749. *
  12750. * @param {Component~ReadyCallback} [ready]
  12751. * The function to call when this component is ready.
  12752. */
  12753. function DescriptionsButton(player, options, ready) {
  12754. classCallCheck(this, DescriptionsButton);
  12755. var _this = possibleConstructorReturn(this, _TextTrackButton.call(this, player, options, ready));
  12756. var tracks = player.textTracks();
  12757. var changeHandler = bind(_this, _this.handleTracksChange);
  12758. tracks.addEventListener('change', changeHandler);
  12759. _this.on('dispose', function () {
  12760. tracks.removeEventListener('change', changeHandler);
  12761. });
  12762. return _this;
  12763. }
  12764. /**
  12765. * Handle text track change
  12766. *
  12767. * @param {EventTarget~Event} event
  12768. * The event that caused this function to run
  12769. *
  12770. * @listens TextTrackList#change
  12771. */
  12772. DescriptionsButton.prototype.handleTracksChange = function handleTracksChange(event) {
  12773. var tracks = this.player().textTracks();
  12774. var disabled = false;
  12775. // Check whether a track of a different kind is showing
  12776. for (var i = 0, l = tracks.length; i < l; i++) {
  12777. var track = tracks[i];
  12778. if (track.kind !== this.kind_ && track.mode === 'showing') {
  12779. disabled = true;
  12780. break;
  12781. }
  12782. }
  12783. // If another track is showing, disable this menu button
  12784. if (disabled) {
  12785. this.disable();
  12786. } else {
  12787. this.enable();
  12788. }
  12789. };
  12790. /**
  12791. * Builds the default DOM `className`.
  12792. *
  12793. * @return {string}
  12794. * The DOM `className` for this object.
  12795. */
  12796. DescriptionsButton.prototype.buildCSSClass = function buildCSSClass() {
  12797. return 'vjs-descriptions-button ' + _TextTrackButton.prototype.buildCSSClass.call(this);
  12798. };
  12799. DescriptionsButton.prototype.buildWrapperCSSClass = function buildWrapperCSSClass() {
  12800. return 'vjs-descriptions-button ' + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  12801. };
  12802. return DescriptionsButton;
  12803. }(TextTrackButton);
  12804. /**
  12805. * `kind` of TextTrack to look for to associate it with this menu.
  12806. *
  12807. * @type {string}
  12808. * @private
  12809. */
  12810. DescriptionsButton.prototype.kind_ = 'descriptions';
  12811. /**
  12812. * The text that should display over the `DescriptionsButton`s controls. Added for localization.
  12813. *
  12814. * @type {string}
  12815. * @private
  12816. */
  12817. DescriptionsButton.prototype.controlText_ = 'Descriptions';
  12818. Component.registerComponent('DescriptionsButton', DescriptionsButton);
  12819. /**
  12820. * @file subtitles-button.js
  12821. */
  12822. /**
  12823. * The button component for toggling and selecting subtitles
  12824. *
  12825. * @extends TextTrackButton
  12826. */
  12827. var SubtitlesButton = function (_TextTrackButton) {
  12828. inherits(SubtitlesButton, _TextTrackButton);
  12829. /**
  12830. * Creates an instance of this class.
  12831. *
  12832. * @param {Player} player
  12833. * The `Player` that this class should be attached to.
  12834. *
  12835. * @param {Object} [options]
  12836. * The key/value store of player options.
  12837. *
  12838. * @param {Component~ReadyCallback} [ready]
  12839. * The function to call when this component is ready.
  12840. */
  12841. function SubtitlesButton(player, options, ready) {
  12842. classCallCheck(this, SubtitlesButton);
  12843. return possibleConstructorReturn(this, _TextTrackButton.call(this, player, options, ready));
  12844. }
  12845. /**
  12846. * Builds the default DOM `className`.
  12847. *
  12848. * @return {string}
  12849. * The DOM `className` for this object.
  12850. */
  12851. SubtitlesButton.prototype.buildCSSClass = function buildCSSClass() {
  12852. return 'vjs-subtitles-button ' + _TextTrackButton.prototype.buildCSSClass.call(this);
  12853. };
  12854. SubtitlesButton.prototype.buildWrapperCSSClass = function buildWrapperCSSClass() {
  12855. return 'vjs-subtitles-button ' + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  12856. };
  12857. return SubtitlesButton;
  12858. }(TextTrackButton);
  12859. /**
  12860. * `kind` of TextTrack to look for to associate it with this menu.
  12861. *
  12862. * @type {string}
  12863. * @private
  12864. */
  12865. SubtitlesButton.prototype.kind_ = 'subtitles';
  12866. /**
  12867. * The text that should display over the `SubtitlesButton`s controls. Added for localization.
  12868. *
  12869. * @type {string}
  12870. * @private
  12871. */
  12872. SubtitlesButton.prototype.controlText_ = 'Subtitles';
  12873. Component.registerComponent('SubtitlesButton', SubtitlesButton);
  12874. /**
  12875. * @file caption-settings-menu-item.js
  12876. */
  12877. /**
  12878. * The menu item for caption track settings menu
  12879. *
  12880. * @extends TextTrackMenuItem
  12881. */
  12882. var CaptionSettingsMenuItem = function (_TextTrackMenuItem) {
  12883. inherits(CaptionSettingsMenuItem, _TextTrackMenuItem);
  12884. /**
  12885. * Creates an instance of this class.
  12886. *
  12887. * @param {Player} player
  12888. * The `Player` that this class should be attached to.
  12889. *
  12890. * @param {Object} [options]
  12891. * The key/value store of player options.
  12892. */
  12893. function CaptionSettingsMenuItem(player, options) {
  12894. classCallCheck(this, CaptionSettingsMenuItem);
  12895. options.track = {
  12896. player: player,
  12897. kind: options.kind,
  12898. label: options.kind + ' settings',
  12899. selectable: false,
  12900. 'default': false,
  12901. mode: 'disabled'
  12902. };
  12903. // CaptionSettingsMenuItem has no concept of 'selected'
  12904. options.selectable = false;
  12905. options.name = 'CaptionSettingsMenuItem';
  12906. var _this = possibleConstructorReturn(this, _TextTrackMenuItem.call(this, player, options));
  12907. _this.addClass('vjs-texttrack-settings');
  12908. _this.controlText(', opens ' + options.kind + ' settings dialog');
  12909. return _this;
  12910. }
  12911. /**
  12912. * This gets called when an `CaptionSettingsMenuItem` is "clicked". See
  12913. * {@link ClickableComponent} for more detailed information on what a click can be.
  12914. *
  12915. * @param {EventTarget~Event} [event]
  12916. * The `keydown`, `tap`, or `click` event that caused this function to be
  12917. * called.
  12918. *
  12919. * @listens tap
  12920. * @listens click
  12921. */
  12922. CaptionSettingsMenuItem.prototype.handleClick = function handleClick(event) {
  12923. this.player().getChild('textTrackSettings').open();
  12924. };
  12925. return CaptionSettingsMenuItem;
  12926. }(TextTrackMenuItem);
  12927. Component.registerComponent('CaptionSettingsMenuItem', CaptionSettingsMenuItem);
  12928. /**
  12929. * @file captions-button.js
  12930. */
  12931. /**
  12932. * The button component for toggling and selecting captions
  12933. *
  12934. * @extends TextTrackButton
  12935. */
  12936. var CaptionsButton = function (_TextTrackButton) {
  12937. inherits(CaptionsButton, _TextTrackButton);
  12938. /**
  12939. * Creates an instance of this class.
  12940. *
  12941. * @param {Player} player
  12942. * The `Player` that this class should be attached to.
  12943. *
  12944. * @param {Object} [options]
  12945. * The key/value store of player options.
  12946. *
  12947. * @param {Component~ReadyCallback} [ready]
  12948. * The function to call when this component is ready.
  12949. */
  12950. function CaptionsButton(player, options, ready) {
  12951. classCallCheck(this, CaptionsButton);
  12952. return possibleConstructorReturn(this, _TextTrackButton.call(this, player, options, ready));
  12953. }
  12954. /**
  12955. * Builds the default DOM `className`.
  12956. *
  12957. * @return {string}
  12958. * The DOM `className` for this object.
  12959. */
  12960. CaptionsButton.prototype.buildCSSClass = function buildCSSClass() {
  12961. return 'vjs-captions-button ' + _TextTrackButton.prototype.buildCSSClass.call(this);
  12962. };
  12963. CaptionsButton.prototype.buildWrapperCSSClass = function buildWrapperCSSClass() {
  12964. return 'vjs-captions-button ' + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  12965. };
  12966. /**
  12967. * Create caption menu items
  12968. *
  12969. * @return {CaptionSettingsMenuItem[]}
  12970. * The array of current menu items.
  12971. */
  12972. CaptionsButton.prototype.createItems = function createItems() {
  12973. var items = [];
  12974. if (!(this.player().tech_ && this.player().tech_.featuresNativeTextTracks) && this.player().getChild('textTrackSettings')) {
  12975. items.push(new CaptionSettingsMenuItem(this.player_, { kind: this.kind_ }));
  12976. this.hideThreshold_ += 1;
  12977. }
  12978. return _TextTrackButton.prototype.createItems.call(this, items);
  12979. };
  12980. return CaptionsButton;
  12981. }(TextTrackButton);
  12982. /**
  12983. * `kind` of TextTrack to look for to associate it with this menu.
  12984. *
  12985. * @type {string}
  12986. * @private
  12987. */
  12988. CaptionsButton.prototype.kind_ = 'captions';
  12989. /**
  12990. * The text that should display over the `CaptionsButton`s controls. Added for localization.
  12991. *
  12992. * @type {string}
  12993. * @private
  12994. */
  12995. CaptionsButton.prototype.controlText_ = 'Captions';
  12996. Component.registerComponent('CaptionsButton', CaptionsButton);
  12997. /**
  12998. * @file subs-caps-menu-item.js
  12999. */
  13000. /**
  13001. * SubsCapsMenuItem has an [cc] icon to distinguish captions from subtitles
  13002. * in the SubsCapsMenu.
  13003. *
  13004. * @extends TextTrackMenuItem
  13005. */
  13006. var SubsCapsMenuItem = function (_TextTrackMenuItem) {
  13007. inherits(SubsCapsMenuItem, _TextTrackMenuItem);
  13008. function SubsCapsMenuItem() {
  13009. classCallCheck(this, SubsCapsMenuItem);
  13010. return possibleConstructorReturn(this, _TextTrackMenuItem.apply(this, arguments));
  13011. }
  13012. SubsCapsMenuItem.prototype.createEl = function createEl(type, props, attrs) {
  13013. var innerHTML = '<span class="vjs-menu-item-text">' + this.localize(this.options_.label);
  13014. if (this.options_.track.kind === 'captions') {
  13015. innerHTML += '\n <span aria-hidden="true" class="vjs-icon-placeholder"></span>\n <span class="vjs-control-text"> ' + this.localize('Captions') + '</span>\n ';
  13016. }
  13017. innerHTML += '</span>';
  13018. var el = _TextTrackMenuItem.prototype.createEl.call(this, type, assign({
  13019. innerHTML: innerHTML
  13020. }, props), attrs);
  13021. return el;
  13022. };
  13023. return SubsCapsMenuItem;
  13024. }(TextTrackMenuItem);
  13025. Component.registerComponent('SubsCapsMenuItem', SubsCapsMenuItem);
  13026. /**
  13027. * @file sub-caps-button.js
  13028. */
  13029. /**
  13030. * The button component for toggling and selecting captions and/or subtitles
  13031. *
  13032. * @extends TextTrackButton
  13033. */
  13034. var SubsCapsButton = function (_TextTrackButton) {
  13035. inherits(SubsCapsButton, _TextTrackButton);
  13036. function SubsCapsButton(player) {
  13037. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  13038. classCallCheck(this, SubsCapsButton);
  13039. // Although North America uses "captions" in most cases for
  13040. // "captions and subtitles" other locales use "subtitles"
  13041. var _this = possibleConstructorReturn(this, _TextTrackButton.call(this, player, options));
  13042. _this.label_ = 'subtitles';
  13043. if (['en', 'en-us', 'en-ca', 'fr-ca'].indexOf(_this.player_.language_) > -1) {
  13044. _this.label_ = 'captions';
  13045. }
  13046. _this.menuButton_.controlText(toTitleCase(_this.label_));
  13047. return _this;
  13048. }
  13049. /**
  13050. * Builds the default DOM `className`.
  13051. *
  13052. * @return {string}
  13053. * The DOM `className` for this object.
  13054. */
  13055. SubsCapsButton.prototype.buildCSSClass = function buildCSSClass() {
  13056. return 'vjs-subs-caps-button ' + _TextTrackButton.prototype.buildCSSClass.call(this);
  13057. };
  13058. SubsCapsButton.prototype.buildWrapperCSSClass = function buildWrapperCSSClass() {
  13059. return 'vjs-subs-caps-button ' + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  13060. };
  13061. /**
  13062. * Create caption/subtitles menu items
  13063. *
  13064. * @return {CaptionSettingsMenuItem[]}
  13065. * The array of current menu items.
  13066. */
  13067. SubsCapsButton.prototype.createItems = function createItems() {
  13068. var items = [];
  13069. if (!(this.player().tech_ && this.player().tech_.featuresNativeTextTracks) && this.player().getChild('textTrackSettings')) {
  13070. items.push(new CaptionSettingsMenuItem(this.player_, { kind: this.label_ }));
  13071. this.hideThreshold_ += 1;
  13072. }
  13073. items = _TextTrackButton.prototype.createItems.call(this, items, SubsCapsMenuItem);
  13074. return items;
  13075. };
  13076. return SubsCapsButton;
  13077. }(TextTrackButton);
  13078. /**
  13079. * `kind`s of TextTrack to look for to associate it with this menu.
  13080. *
  13081. * @type {array}
  13082. * @private
  13083. */
  13084. SubsCapsButton.prototype.kinds_ = ['captions', 'subtitles'];
  13085. /**
  13086. * The text that should display over the `SubsCapsButton`s controls.
  13087. *
  13088. *
  13089. * @type {string}
  13090. * @private
  13091. */
  13092. SubsCapsButton.prototype.controlText_ = 'Subtitles';
  13093. Component.registerComponent('SubsCapsButton', SubsCapsButton);
  13094. /**
  13095. * @file audio-track-menu-item.js
  13096. */
  13097. /**
  13098. * An {@link AudioTrack} {@link MenuItem}
  13099. *
  13100. * @extends MenuItem
  13101. */
  13102. var AudioTrackMenuItem = function (_MenuItem) {
  13103. inherits(AudioTrackMenuItem, _MenuItem);
  13104. /**
  13105. * Creates an instance of this class.
  13106. *
  13107. * @param {Player} player
  13108. * The `Player` that this class should be attached to.
  13109. *
  13110. * @param {Object} [options]
  13111. * The key/value store of player options.
  13112. */
  13113. function AudioTrackMenuItem(player, options) {
  13114. classCallCheck(this, AudioTrackMenuItem);
  13115. var track = options.track;
  13116. var tracks = player.audioTracks();
  13117. // Modify options for parent MenuItem class's init.
  13118. options.label = track.label || track.language || 'Unknown';
  13119. options.selected = track.enabled;
  13120. var _this = possibleConstructorReturn(this, _MenuItem.call(this, player, options));
  13121. _this.track = track;
  13122. _this.addClass('vjs-' + track.kind + '-menu-item');
  13123. var changeHandler = function changeHandler() {
  13124. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  13125. args[_key] = arguments[_key];
  13126. }
  13127. _this.handleTracksChange.apply(_this, args);
  13128. };
  13129. tracks.addEventListener('change', changeHandler);
  13130. _this.on('dispose', function () {
  13131. tracks.removeEventListener('change', changeHandler);
  13132. });
  13133. return _this;
  13134. }
  13135. AudioTrackMenuItem.prototype.createEl = function createEl(type, props, attrs) {
  13136. var innerHTML = '<span class="vjs-menu-item-text">' + this.localize(this.options_.label);
  13137. if (this.options_.track.kind === 'main-desc') {
  13138. innerHTML += '\n <span aria-hidden="true" class="vjs-icon-placeholder"></span>\n <span class="vjs-control-text"> ' + this.localize('Descriptions') + '</span>\n ';
  13139. }
  13140. innerHTML += '</span>';
  13141. var el = _MenuItem.prototype.createEl.call(this, type, assign({
  13142. innerHTML: innerHTML
  13143. }, props), attrs);
  13144. return el;
  13145. };
  13146. /**
  13147. * This gets called when an `AudioTrackMenuItem is "clicked". See {@link ClickableComponent}
  13148. * for more detailed information on what a click can be.
  13149. *
  13150. * @param {EventTarget~Event} [event]
  13151. * The `keydown`, `tap`, or `click` event that caused this function to be
  13152. * called.
  13153. *
  13154. * @listens tap
  13155. * @listens click
  13156. */
  13157. AudioTrackMenuItem.prototype.handleClick = function handleClick(event) {
  13158. var tracks = this.player_.audioTracks();
  13159. _MenuItem.prototype.handleClick.call(this, event);
  13160. for (var i = 0; i < tracks.length; i++) {
  13161. var track = tracks[i];
  13162. track.enabled = track === this.track;
  13163. }
  13164. };
  13165. /**
  13166. * Handle any {@link AudioTrack} change.
  13167. *
  13168. * @param {EventTarget~Event} [event]
  13169. * The {@link AudioTrackList#change} event that caused this to run.
  13170. *
  13171. * @listens AudioTrackList#change
  13172. */
  13173. AudioTrackMenuItem.prototype.handleTracksChange = function handleTracksChange(event) {
  13174. this.selected(this.track.enabled);
  13175. };
  13176. return AudioTrackMenuItem;
  13177. }(MenuItem);
  13178. Component.registerComponent('AudioTrackMenuItem', AudioTrackMenuItem);
  13179. /**
  13180. * @file audio-track-button.js
  13181. */
  13182. /**
  13183. * The base class for buttons that toggle specific {@link AudioTrack} types.
  13184. *
  13185. * @extends TrackButton
  13186. */
  13187. var AudioTrackButton = function (_TrackButton) {
  13188. inherits(AudioTrackButton, _TrackButton);
  13189. /**
  13190. * Creates an instance of this class.
  13191. *
  13192. * @param {Player} player
  13193. * The `Player` that this class should be attached to.
  13194. *
  13195. * @param {Object} [options={}]
  13196. * The key/value store of player options.
  13197. */
  13198. function AudioTrackButton(player) {
  13199. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  13200. classCallCheck(this, AudioTrackButton);
  13201. options.tracks = player.audioTracks();
  13202. return possibleConstructorReturn(this, _TrackButton.call(this, player, options));
  13203. }
  13204. /**
  13205. * Builds the default DOM `className`.
  13206. *
  13207. * @return {string}
  13208. * The DOM `className` for this object.
  13209. */
  13210. AudioTrackButton.prototype.buildCSSClass = function buildCSSClass() {
  13211. return 'vjs-audio-button ' + _TrackButton.prototype.buildCSSClass.call(this);
  13212. };
  13213. AudioTrackButton.prototype.buildWrapperCSSClass = function buildWrapperCSSClass() {
  13214. return 'vjs-audio-button ' + _TrackButton.prototype.buildWrapperCSSClass.call(this);
  13215. };
  13216. /**
  13217. * Create a menu item for each audio track
  13218. *
  13219. * @param {AudioTrackMenuItem[]} [items=[]]
  13220. * An array of existing menu items to use.
  13221. *
  13222. * @return {AudioTrackMenuItem[]}
  13223. * An array of menu items
  13224. */
  13225. AudioTrackButton.prototype.createItems = function createItems() {
  13226. var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  13227. // if there's only one audio track, there no point in showing it
  13228. this.hideThreshold_ = 1;
  13229. var tracks = this.player_.audioTracks();
  13230. for (var i = 0; i < tracks.length; i++) {
  13231. var track = tracks[i];
  13232. items.push(new AudioTrackMenuItem(this.player_, {
  13233. track: track,
  13234. // MenuItem is selectable
  13235. selectable: true,
  13236. // MenuItem is NOT multiSelectable (i.e. only one can be marked "selected" at a time)
  13237. multiSelectable: false
  13238. }));
  13239. }
  13240. return items;
  13241. };
  13242. return AudioTrackButton;
  13243. }(TrackButton);
  13244. /**
  13245. * The text that should display over the `AudioTrackButton`s controls. Added for localization.
  13246. *
  13247. * @type {string}
  13248. * @private
  13249. */
  13250. AudioTrackButton.prototype.controlText_ = 'Audio Track';
  13251. Component.registerComponent('AudioTrackButton', AudioTrackButton);
  13252. /**
  13253. * @file playback-rate-menu-item.js
  13254. */
  13255. /**
  13256. * The specific menu item type for selecting a playback rate.
  13257. *
  13258. * @extends MenuItem
  13259. */
  13260. var PlaybackRateMenuItem = function (_MenuItem) {
  13261. inherits(PlaybackRateMenuItem, _MenuItem);
  13262. /**
  13263. * Creates an instance of this class.
  13264. *
  13265. * @param {Player} player
  13266. * The `Player` that this class should be attached to.
  13267. *
  13268. * @param {Object} [options]
  13269. * The key/value store of player options.
  13270. */
  13271. function PlaybackRateMenuItem(player, options) {
  13272. classCallCheck(this, PlaybackRateMenuItem);
  13273. var label = options.rate;
  13274. var rate = parseFloat(label, 10);
  13275. // Modify options for parent MenuItem class's init.
  13276. options.label = label;
  13277. options.selected = rate === 1;
  13278. options.selectable = true;
  13279. options.multiSelectable = false;
  13280. var _this = possibleConstructorReturn(this, _MenuItem.call(this, player, options));
  13281. _this.label = label;
  13282. _this.rate = rate;
  13283. _this.on(player, 'ratechange', _this.update);
  13284. return _this;
  13285. }
  13286. /**
  13287. * This gets called when an `PlaybackRateMenuItem` is "clicked". See
  13288. * {@link ClickableComponent} for more detailed information on what a click can be.
  13289. *
  13290. * @param {EventTarget~Event} [event]
  13291. * The `keydown`, `tap`, or `click` event that caused this function to be
  13292. * called.
  13293. *
  13294. * @listens tap
  13295. * @listens click
  13296. */
  13297. PlaybackRateMenuItem.prototype.handleClick = function handleClick(event) {
  13298. _MenuItem.prototype.handleClick.call(this);
  13299. this.player().playbackRate(this.rate);
  13300. };
  13301. /**
  13302. * Update the PlaybackRateMenuItem when the playbackrate changes.
  13303. *
  13304. * @param {EventTarget~Event} [event]
  13305. * The `ratechange` event that caused this function to run.
  13306. *
  13307. * @listens Player#ratechange
  13308. */
  13309. PlaybackRateMenuItem.prototype.update = function update(event) {
  13310. this.selected(this.player().playbackRate() === this.rate);
  13311. };
  13312. return PlaybackRateMenuItem;
  13313. }(MenuItem);
  13314. /**
  13315. * The text that should display over the `PlaybackRateMenuItem`s controls. Added for localization.
  13316. *
  13317. * @type {string}
  13318. * @private
  13319. */
  13320. PlaybackRateMenuItem.prototype.contentElType = 'button';
  13321. Component.registerComponent('PlaybackRateMenuItem', PlaybackRateMenuItem);
  13322. /**
  13323. * @file playback-rate-menu-button.js
  13324. */
  13325. /**
  13326. * The component for controlling the playback rate.
  13327. *
  13328. * @extends MenuButton
  13329. */
  13330. var PlaybackRateMenuButton = function (_MenuButton) {
  13331. inherits(PlaybackRateMenuButton, _MenuButton);
  13332. /**
  13333. * Creates an instance of this class.
  13334. *
  13335. * @param {Player} player
  13336. * The `Player` that this class should be attached to.
  13337. *
  13338. * @param {Object} [options]
  13339. * The key/value store of player options.
  13340. */
  13341. function PlaybackRateMenuButton(player, options) {
  13342. classCallCheck(this, PlaybackRateMenuButton);
  13343. var _this = possibleConstructorReturn(this, _MenuButton.call(this, player, options));
  13344. _this.updateVisibility();
  13345. _this.updateLabel();
  13346. _this.on(player, 'loadstart', _this.updateVisibility);
  13347. _this.on(player, 'ratechange', _this.updateLabel);
  13348. return _this;
  13349. }
  13350. /**
  13351. * Create the `Component`'s DOM element
  13352. *
  13353. * @return {Element}
  13354. * The element that was created.
  13355. */
  13356. PlaybackRateMenuButton.prototype.createEl = function createEl$$1() {
  13357. var el = _MenuButton.prototype.createEl.call(this);
  13358. this.labelEl_ = createEl('div', {
  13359. className: 'vjs-playback-rate-value',
  13360. innerHTML: '1x'
  13361. });
  13362. el.appendChild(this.labelEl_);
  13363. return el;
  13364. };
  13365. PlaybackRateMenuButton.prototype.dispose = function dispose() {
  13366. this.labelEl_ = null;
  13367. _MenuButton.prototype.dispose.call(this);
  13368. };
  13369. /**
  13370. * Builds the default DOM `className`.
  13371. *
  13372. * @return {string}
  13373. * The DOM `className` for this object.
  13374. */
  13375. PlaybackRateMenuButton.prototype.buildCSSClass = function buildCSSClass() {
  13376. return 'vjs-playback-rate ' + _MenuButton.prototype.buildCSSClass.call(this);
  13377. };
  13378. PlaybackRateMenuButton.prototype.buildWrapperCSSClass = function buildWrapperCSSClass() {
  13379. return 'vjs-playback-rate ' + _MenuButton.prototype.buildWrapperCSSClass.call(this);
  13380. };
  13381. /**
  13382. * Create the playback rate menu
  13383. *
  13384. * @return {Menu}
  13385. * Menu object populated with {@link PlaybackRateMenuItem}s
  13386. */
  13387. PlaybackRateMenuButton.prototype.createMenu = function createMenu() {
  13388. var menu = new Menu(this.player());
  13389. var rates = this.playbackRates();
  13390. if (rates) {
  13391. for (var i = rates.length - 1; i >= 0; i--) {
  13392. menu.addChild(new PlaybackRateMenuItem(this.player(), { rate: rates[i] + 'x' }));
  13393. }
  13394. }
  13395. return menu;
  13396. };
  13397. /**
  13398. * Updates ARIA accessibility attributes
  13399. */
  13400. PlaybackRateMenuButton.prototype.updateARIAAttributes = function updateARIAAttributes() {
  13401. // Current playback rate
  13402. this.el().setAttribute('aria-valuenow', this.player().playbackRate());
  13403. };
  13404. /**
  13405. * This gets called when an `PlaybackRateMenuButton` is "clicked". See
  13406. * {@link ClickableComponent} for more detailed information on what a click can be.
  13407. *
  13408. * @param {EventTarget~Event} [event]
  13409. * The `keydown`, `tap`, or `click` event that caused this function to be
  13410. * called.
  13411. *
  13412. * @listens tap
  13413. * @listens click
  13414. */
  13415. PlaybackRateMenuButton.prototype.handleClick = function handleClick(event) {
  13416. // select next rate option
  13417. var currentRate = this.player().playbackRate();
  13418. var rates = this.playbackRates();
  13419. // this will select first one if the last one currently selected
  13420. var newRate = rates[0];
  13421. for (var i = 0; i < rates.length; i++) {
  13422. if (rates[i] > currentRate) {
  13423. newRate = rates[i];
  13424. break;
  13425. }
  13426. }
  13427. this.player().playbackRate(newRate);
  13428. };
  13429. /**
  13430. * Get possible playback rates
  13431. *
  13432. * @return {Array}
  13433. * All possible playback rates
  13434. */
  13435. PlaybackRateMenuButton.prototype.playbackRates = function playbackRates() {
  13436. return this.options_.playbackRates || this.options_.playerOptions && this.options_.playerOptions.playbackRates;
  13437. };
  13438. /**
  13439. * Get whether playback rates is supported by the tech
  13440. * and an array of playback rates exists
  13441. *
  13442. * @return {boolean}
  13443. * Whether changing playback rate is supported
  13444. */
  13445. PlaybackRateMenuButton.prototype.playbackRateSupported = function playbackRateSupported() {
  13446. return this.player().tech_ && this.player().tech_.featuresPlaybackRate && this.playbackRates() && this.playbackRates().length > 0;
  13447. };
  13448. /**
  13449. * Hide playback rate controls when they're no playback rate options to select
  13450. *
  13451. * @param {EventTarget~Event} [event]
  13452. * The event that caused this function to run.
  13453. *
  13454. * @listens Player#loadstart
  13455. */
  13456. PlaybackRateMenuButton.prototype.updateVisibility = function updateVisibility(event) {
  13457. if (this.playbackRateSupported()) {
  13458. this.removeClass('vjs-hidden');
  13459. } else {
  13460. this.addClass('vjs-hidden');
  13461. }
  13462. };
  13463. /**
  13464. * Update button label when rate changed
  13465. *
  13466. * @param {EventTarget~Event} [event]
  13467. * The event that caused this function to run.
  13468. *
  13469. * @listens Player#ratechange
  13470. */
  13471. PlaybackRateMenuButton.prototype.updateLabel = function updateLabel(event) {
  13472. if (this.playbackRateSupported()) {
  13473. this.labelEl_.innerHTML = this.player().playbackRate() + 'x';
  13474. }
  13475. };
  13476. return PlaybackRateMenuButton;
  13477. }(MenuButton);
  13478. /**
  13479. * The text that should display over the `FullscreenToggle`s controls. Added for localization.
  13480. *
  13481. * @type {string}
  13482. * @private
  13483. */
  13484. PlaybackRateMenuButton.prototype.controlText_ = 'Playback Rate';
  13485. Component.registerComponent('PlaybackRateMenuButton', PlaybackRateMenuButton);
  13486. /**
  13487. * @file spacer.js
  13488. */
  13489. /**
  13490. * Just an empty spacer element that can be used as an append point for plugins, etc.
  13491. * Also can be used to create space between elements when necessary.
  13492. *
  13493. * @extends Component
  13494. */
  13495. var Spacer = function (_Component) {
  13496. inherits(Spacer, _Component);
  13497. function Spacer() {
  13498. classCallCheck(this, Spacer);
  13499. return possibleConstructorReturn(this, _Component.apply(this, arguments));
  13500. }
  13501. /**
  13502. * Builds the default DOM `className`.
  13503. *
  13504. * @return {string}
  13505. * The DOM `className` for this object.
  13506. */
  13507. Spacer.prototype.buildCSSClass = function buildCSSClass() {
  13508. return 'vjs-spacer ' + _Component.prototype.buildCSSClass.call(this);
  13509. };
  13510. /**
  13511. * Create the `Component`'s DOM element
  13512. *
  13513. * @return {Element}
  13514. * The element that was created.
  13515. */
  13516. Spacer.prototype.createEl = function createEl() {
  13517. return _Component.prototype.createEl.call(this, 'div', {
  13518. className: this.buildCSSClass()
  13519. });
  13520. };
  13521. return Spacer;
  13522. }(Component);
  13523. Component.registerComponent('Spacer', Spacer);
  13524. /**
  13525. * @file custom-control-spacer.js
  13526. */
  13527. /**
  13528. * Spacer specifically meant to be used as an insertion point for new plugins, etc.
  13529. *
  13530. * @extends Spacer
  13531. */
  13532. var CustomControlSpacer = function (_Spacer) {
  13533. inherits(CustomControlSpacer, _Spacer);
  13534. function CustomControlSpacer() {
  13535. classCallCheck(this, CustomControlSpacer);
  13536. return possibleConstructorReturn(this, _Spacer.apply(this, arguments));
  13537. }
  13538. /**
  13539. * Builds the default DOM `className`.
  13540. *
  13541. * @return {string}
  13542. * The DOM `className` for this object.
  13543. */
  13544. CustomControlSpacer.prototype.buildCSSClass = function buildCSSClass() {
  13545. return 'vjs-custom-control-spacer ' + _Spacer.prototype.buildCSSClass.call(this);
  13546. };
  13547. /**
  13548. * Create the `Component`'s DOM element
  13549. *
  13550. * @return {Element}
  13551. * The element that was created.
  13552. */
  13553. CustomControlSpacer.prototype.createEl = function createEl() {
  13554. var el = _Spacer.prototype.createEl.call(this, {
  13555. className: this.buildCSSClass()
  13556. });
  13557. // No-flex/table-cell mode requires there be some content
  13558. // in the cell to fill the remaining space of the table.
  13559. el.innerHTML = '\xA0';
  13560. return el;
  13561. };
  13562. return CustomControlSpacer;
  13563. }(Spacer);
  13564. Component.registerComponent('CustomControlSpacer', CustomControlSpacer);
  13565. /**
  13566. * @file control-bar.js
  13567. */
  13568. // Required children
  13569. /**
  13570. * Container of main controls.
  13571. *
  13572. * @extends Component
  13573. */
  13574. var ControlBar = function (_Component) {
  13575. inherits(ControlBar, _Component);
  13576. function ControlBar() {
  13577. classCallCheck(this, ControlBar);
  13578. return possibleConstructorReturn(this, _Component.apply(this, arguments));
  13579. }
  13580. /**
  13581. * Create the `Component`'s DOM element
  13582. *
  13583. * @return {Element}
  13584. * The element that was created.
  13585. */
  13586. ControlBar.prototype.createEl = function createEl() {
  13587. return _Component.prototype.createEl.call(this, 'div', {
  13588. className: 'vjs-control-bar',
  13589. dir: 'ltr'
  13590. });
  13591. };
  13592. return ControlBar;
  13593. }(Component);
  13594. /**
  13595. * Default options for `ControlBar`
  13596. *
  13597. * @type {Object}
  13598. * @private
  13599. */
  13600. ControlBar.prototype.options_ = {
  13601. children: ['playToggle', 'volumePanel', 'currentTimeDisplay', 'timeDivider', 'durationDisplay', 'progressControl', 'liveDisplay', 'remainingTimeDisplay', 'customControlSpacer', 'playbackRateMenuButton', 'chaptersButton', 'descriptionsButton', 'subsCapsButton', 'audioTrackButton', 'fullscreenToggle']
  13602. };
  13603. Component.registerComponent('ControlBar', ControlBar);
  13604. /**
  13605. * @file error-display.js
  13606. */
  13607. /**
  13608. * A display that indicates an error has occurred. This means that the video
  13609. * is unplayable.
  13610. *
  13611. * @extends ModalDialog
  13612. */
  13613. var ErrorDisplay = function (_ModalDialog) {
  13614. inherits(ErrorDisplay, _ModalDialog);
  13615. /**
  13616. * Creates an instance of this class.
  13617. *
  13618. * @param {Player} player
  13619. * The `Player` that this class should be attached to.
  13620. *
  13621. * @param {Object} [options]
  13622. * The key/value store of player options.
  13623. */
  13624. function ErrorDisplay(player, options) {
  13625. classCallCheck(this, ErrorDisplay);
  13626. var _this = possibleConstructorReturn(this, _ModalDialog.call(this, player, options));
  13627. _this.on(player, 'error', _this.open);
  13628. return _this;
  13629. }
  13630. /**
  13631. * Builds the default DOM `className`.
  13632. *
  13633. * @return {string}
  13634. * The DOM `className` for this object.
  13635. *
  13636. * @deprecated Since version 5.
  13637. */
  13638. ErrorDisplay.prototype.buildCSSClass = function buildCSSClass() {
  13639. return 'vjs-error-display ' + _ModalDialog.prototype.buildCSSClass.call(this);
  13640. };
  13641. /**
  13642. * Gets the localized error message based on the `Player`s error.
  13643. *
  13644. * @return {string}
  13645. * The `Player`s error message localized or an empty string.
  13646. */
  13647. ErrorDisplay.prototype.content = function content() {
  13648. var error = this.player().error();
  13649. return error ? this.localize(error.message) : '';
  13650. };
  13651. return ErrorDisplay;
  13652. }(ModalDialog);
  13653. /**
  13654. * The default options for an `ErrorDisplay`.
  13655. *
  13656. * @private
  13657. */
  13658. ErrorDisplay.prototype.options_ = mergeOptions(ModalDialog.prototype.options_, {
  13659. pauseOnOpen: false,
  13660. fillAlways: true,
  13661. temporary: false,
  13662. uncloseable: true
  13663. });
  13664. Component.registerComponent('ErrorDisplay', ErrorDisplay);
  13665. /**
  13666. * @file text-track-settings.js
  13667. */
  13668. var LOCAL_STORAGE_KEY = 'vjs-text-track-settings';
  13669. var COLOR_BLACK = ['#000', 'Black'];
  13670. var COLOR_BLUE = ['#00F', 'Blue'];
  13671. var COLOR_CYAN = ['#0FF', 'Cyan'];
  13672. var COLOR_GREEN = ['#0F0', 'Green'];
  13673. var COLOR_MAGENTA = ['#F0F', 'Magenta'];
  13674. var COLOR_RED = ['#F00', 'Red'];
  13675. var COLOR_WHITE = ['#FFF', 'White'];
  13676. var COLOR_YELLOW = ['#FF0', 'Yellow'];
  13677. var OPACITY_OPAQUE = ['1', 'Opaque'];
  13678. var OPACITY_SEMI = ['0.5', 'Semi-Transparent'];
  13679. var OPACITY_TRANS = ['0', 'Transparent'];
  13680. // Configuration for the various <select> elements in the DOM of this component.
  13681. //
  13682. // Possible keys include:
  13683. //
  13684. // `default`:
  13685. // The default option index. Only needs to be provided if not zero.
  13686. // `parser`:
  13687. // A function which is used to parse the value from the selected option in
  13688. // a customized way.
  13689. // `selector`:
  13690. // The selector used to find the associated <select> element.
  13691. var selectConfigs = {
  13692. backgroundColor: {
  13693. selector: '.vjs-bg-color > select',
  13694. id: 'captions-background-color-%s',
  13695. label: 'Color',
  13696. options: [COLOR_BLACK, COLOR_WHITE, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_YELLOW, COLOR_MAGENTA, COLOR_CYAN]
  13697. },
  13698. backgroundOpacity: {
  13699. selector: '.vjs-bg-opacity > select',
  13700. id: 'captions-background-opacity-%s',
  13701. label: 'Transparency',
  13702. options: [OPACITY_OPAQUE, OPACITY_SEMI, OPACITY_TRANS]
  13703. },
  13704. color: {
  13705. selector: '.vjs-fg-color > select',
  13706. id: 'captions-foreground-color-%s',
  13707. label: 'Color',
  13708. options: [COLOR_WHITE, COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_YELLOW, COLOR_MAGENTA, COLOR_CYAN]
  13709. },
  13710. edgeStyle: {
  13711. selector: '.vjs-edge-style > select',
  13712. id: '%s',
  13713. label: 'Text Edge Style',
  13714. options: [['none', 'None'], ['raised', 'Raised'], ['depressed', 'Depressed'], ['uniform', 'Uniform'], ['dropshadow', 'Dropshadow']]
  13715. },
  13716. fontFamily: {
  13717. selector: '.vjs-font-family > select',
  13718. id: 'captions-font-family-%s',
  13719. label: 'Font Family',
  13720. options: [['proportionalSansSerif', 'Proportional Sans-Serif'], ['monospaceSansSerif', 'Monospace Sans-Serif'], ['proportionalSerif', 'Proportional Serif'], ['monospaceSerif', 'Monospace Serif'], ['casual', 'Casual'], ['script', 'Script'], ['small-caps', 'Small Caps']]
  13721. },
  13722. fontPercent: {
  13723. selector: '.vjs-font-percent > select',
  13724. id: 'captions-font-size-%s',
  13725. label: 'Font Size',
  13726. options: [['0.50', '50%'], ['0.75', '75%'], ['1.00', '100%'], ['1.25', '125%'], ['1.50', '150%'], ['1.75', '175%'], ['2.00', '200%'], ['3.00', '300%'], ['4.00', '400%']],
  13727. 'default': 2,
  13728. parser: function parser(v) {
  13729. return v === '1.00' ? null : Number(v);
  13730. }
  13731. },
  13732. textOpacity: {
  13733. selector: '.vjs-text-opacity > select',
  13734. id: 'captions-foreground-opacity-%s',
  13735. label: 'Transparency',
  13736. options: [OPACITY_OPAQUE, OPACITY_SEMI]
  13737. },
  13738. // Options for this object are defined below.
  13739. windowColor: {
  13740. selector: '.vjs-window-color > select',
  13741. id: 'captions-window-color-%s',
  13742. label: 'Color'
  13743. },
  13744. // Options for this object are defined below.
  13745. windowOpacity: {
  13746. selector: '.vjs-window-opacity > select',
  13747. id: 'captions-window-opacity-%s',
  13748. label: 'Transparency',
  13749. options: [OPACITY_TRANS, OPACITY_SEMI, OPACITY_OPAQUE]
  13750. }
  13751. };
  13752. selectConfigs.windowColor.options = selectConfigs.backgroundColor.options;
  13753. /**
  13754. * Get the actual value of an option.
  13755. *
  13756. * @param {string} value
  13757. * The value to get
  13758. *
  13759. * @param {Function} [parser]
  13760. * Optional function to adjust the value.
  13761. *
  13762. * @return {Mixed}
  13763. * - Will be `undefined` if no value exists
  13764. * - Will be `undefined` if the given value is "none".
  13765. * - Will be the actual value otherwise.
  13766. *
  13767. * @private
  13768. */
  13769. function parseOptionValue(value, parser) {
  13770. if (parser) {
  13771. value = parser(value);
  13772. }
  13773. if (value && value !== 'none') {
  13774. return value;
  13775. }
  13776. }
  13777. /**
  13778. * Gets the value of the selected <option> element within a <select> element.
  13779. *
  13780. * @param {Element} el
  13781. * the element to look in
  13782. *
  13783. * @param {Function} [parser]
  13784. * Optional function to adjust the value.
  13785. *
  13786. * @return {Mixed}
  13787. * - Will be `undefined` if no value exists
  13788. * - Will be `undefined` if the given value is "none".
  13789. * - Will be the actual value otherwise.
  13790. *
  13791. * @private
  13792. */
  13793. function getSelectedOptionValue(el, parser) {
  13794. var value = el.options[el.options.selectedIndex].value;
  13795. return parseOptionValue(value, parser);
  13796. }
  13797. /**
  13798. * Sets the selected <option> element within a <select> element based on a
  13799. * given value.
  13800. *
  13801. * @param {Element} el
  13802. * The element to look in.
  13803. *
  13804. * @param {string} value
  13805. * the property to look on.
  13806. *
  13807. * @param {Function} [parser]
  13808. * Optional function to adjust the value before comparing.
  13809. *
  13810. * @private
  13811. */
  13812. function setSelectedOption(el, value, parser) {
  13813. if (!value) {
  13814. return;
  13815. }
  13816. for (var i = 0; i < el.options.length; i++) {
  13817. if (parseOptionValue(el.options[i].value, parser) === value) {
  13818. el.selectedIndex = i;
  13819. break;
  13820. }
  13821. }
  13822. }
  13823. /**
  13824. * Manipulate Text Tracks settings.
  13825. *
  13826. * @extends ModalDialog
  13827. */
  13828. var TextTrackSettings = function (_ModalDialog) {
  13829. inherits(TextTrackSettings, _ModalDialog);
  13830. /**
  13831. * Creates an instance of this class.
  13832. *
  13833. * @param {Player} player
  13834. * The `Player` that this class should be attached to.
  13835. *
  13836. * @param {Object} [options]
  13837. * The key/value store of player options.
  13838. */
  13839. function TextTrackSettings(player, options) {
  13840. classCallCheck(this, TextTrackSettings);
  13841. options.temporary = false;
  13842. var _this = possibleConstructorReturn(this, _ModalDialog.call(this, player, options));
  13843. _this.updateDisplay = bind(_this, _this.updateDisplay);
  13844. // fill the modal and pretend we have opened it
  13845. _this.fill();
  13846. _this.hasBeenOpened_ = _this.hasBeenFilled_ = true;
  13847. _this.endDialog = createEl('p', {
  13848. className: 'vjs-control-text',
  13849. textContent: _this.localize('End of dialog window.')
  13850. });
  13851. _this.el().appendChild(_this.endDialog);
  13852. _this.setDefaults();
  13853. // Grab `persistTextTrackSettings` from the player options if not passed in child options
  13854. if (options.persistTextTrackSettings === undefined) {
  13855. _this.options_.persistTextTrackSettings = _this.options_.playerOptions.persistTextTrackSettings;
  13856. }
  13857. _this.on(_this.$('.vjs-done-button'), 'click', function () {
  13858. _this.saveSettings();
  13859. _this.close();
  13860. });
  13861. _this.on(_this.$('.vjs-default-button'), 'click', function () {
  13862. _this.setDefaults();
  13863. _this.updateDisplay();
  13864. });
  13865. each(selectConfigs, function (config) {
  13866. _this.on(_this.$(config.selector), 'change', _this.updateDisplay);
  13867. });
  13868. if (_this.options_.persistTextTrackSettings) {
  13869. _this.restoreSettings();
  13870. }
  13871. return _this;
  13872. }
  13873. TextTrackSettings.prototype.dispose = function dispose() {
  13874. this.endDialog = null;
  13875. _ModalDialog.prototype.dispose.call(this);
  13876. };
  13877. /**
  13878. * Create a <select> element with configured options.
  13879. *
  13880. * @param {string} key
  13881. * Configuration key to use during creation.
  13882. *
  13883. * @return {string}
  13884. * An HTML string.
  13885. *
  13886. * @private
  13887. */
  13888. TextTrackSettings.prototype.createElSelect_ = function createElSelect_(key) {
  13889. var _this2 = this;
  13890. var legendId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  13891. var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'label';
  13892. var config = selectConfigs[key];
  13893. var id = config.id.replace('%s', this.id_);
  13894. var selectLabelledbyIds = [legendId, id].join(' ').trim();
  13895. return ['<' + type + ' id="' + id + '" class="' + (type === 'label' ? 'vjs-label' : '') + '">', this.localize(config.label), '</' + type + '>', '<select aria-labelledby="' + selectLabelledbyIds + '">'].concat(config.options.map(function (o) {
  13896. var optionId = id + '-' + o[1].replace(/\W+/g, '');
  13897. return ['<option id="' + optionId + '" value="' + o[0] + '" ', 'aria-labelledby="' + selectLabelledbyIds + ' ' + optionId + '">', _this2.localize(o[1]), '</option>'].join('');
  13898. })).concat('</select>').join('');
  13899. };
  13900. /**
  13901. * Create foreground color element for the component
  13902. *
  13903. * @return {string}
  13904. * An HTML string.
  13905. *
  13906. * @private
  13907. */
  13908. TextTrackSettings.prototype.createElFgColor_ = function createElFgColor_() {
  13909. var legendId = 'captions-text-legend-' + this.id_;
  13910. return ['<fieldset class="vjs-fg-color vjs-track-setting">', '<legend id="' + legendId + '">', this.localize('Text'), '</legend>', this.createElSelect_('color', legendId), '<span class="vjs-text-opacity vjs-opacity">', this.createElSelect_('textOpacity', legendId), '</span>', '</fieldset>'].join('');
  13911. };
  13912. /**
  13913. * Create background color element for the component
  13914. *
  13915. * @return {string}
  13916. * An HTML string.
  13917. *
  13918. * @private
  13919. */
  13920. TextTrackSettings.prototype.createElBgColor_ = function createElBgColor_() {
  13921. var legendId = 'captions-background-' + this.id_;
  13922. return ['<fieldset class="vjs-bg-color vjs-track-setting">', '<legend id="' + legendId + '">', this.localize('Background'), '</legend>', this.createElSelect_('backgroundColor', legendId), '<span class="vjs-bg-opacity vjs-opacity">', this.createElSelect_('backgroundOpacity', legendId), '</span>', '</fieldset>'].join('');
  13923. };
  13924. /**
  13925. * Create window color element for the component
  13926. *
  13927. * @return {string}
  13928. * An HTML string.
  13929. *
  13930. * @private
  13931. */
  13932. TextTrackSettings.prototype.createElWinColor_ = function createElWinColor_() {
  13933. var legendId = 'captions-window-' + this.id_;
  13934. return ['<fieldset class="vjs-window-color vjs-track-setting">', '<legend id="' + legendId + '">', this.localize('Window'), '</legend>', this.createElSelect_('windowColor', legendId), '<span class="vjs-window-opacity vjs-opacity">', this.createElSelect_('windowOpacity', legendId), '</span>', '</fieldset>'].join('');
  13935. };
  13936. /**
  13937. * Create color elements for the component
  13938. *
  13939. * @return {Element}
  13940. * The element that was created
  13941. *
  13942. * @private
  13943. */
  13944. TextTrackSettings.prototype.createElColors_ = function createElColors_() {
  13945. return createEl('div', {
  13946. className: 'vjs-track-settings-colors',
  13947. innerHTML: [this.createElFgColor_(), this.createElBgColor_(), this.createElWinColor_()].join('')
  13948. });
  13949. };
  13950. /**
  13951. * Create font elements for the component
  13952. *
  13953. * @return {Element}
  13954. * The element that was created.
  13955. *
  13956. * @private
  13957. */
  13958. TextTrackSettings.prototype.createElFont_ = function createElFont_() {
  13959. return createEl('div', {
  13960. className: 'vjs-track-settings-font',
  13961. innerHTML: ['<fieldset class="vjs-font-percent vjs-track-setting">', this.createElSelect_('fontPercent', '', 'legend'), '</fieldset>', '<fieldset class="vjs-edge-style vjs-track-setting">', this.createElSelect_('edgeStyle', '', 'legend'), '</fieldset>', '<fieldset class="vjs-font-family vjs-track-setting">', this.createElSelect_('fontFamily', '', 'legend'), '</fieldset>'].join('')
  13962. });
  13963. };
  13964. /**
  13965. * Create controls for the component
  13966. *
  13967. * @return {Element}
  13968. * The element that was created.
  13969. *
  13970. * @private
  13971. */
  13972. TextTrackSettings.prototype.createElControls_ = function createElControls_() {
  13973. var defaultsDescription = this.localize('restore all settings to the default values');
  13974. return createEl('div', {
  13975. className: 'vjs-track-settings-controls',
  13976. innerHTML: ['<button type="button" class="vjs-default-button" title="' + defaultsDescription + '">', this.localize('Reset'), '<span class="vjs-control-text"> ' + defaultsDescription + '</span>', '</button>', '<button type="button" class="vjs-done-button">' + this.localize('Done') + '</button>'].join('')
  13977. });
  13978. };
  13979. TextTrackSettings.prototype.content = function content() {
  13980. return [this.createElColors_(), this.createElFont_(), this.createElControls_()];
  13981. };
  13982. TextTrackSettings.prototype.label = function label() {
  13983. return this.localize('Caption Settings Dialog');
  13984. };
  13985. TextTrackSettings.prototype.description = function description() {
  13986. return this.localize('Beginning of dialog window. Escape will cancel and close the window.');
  13987. };
  13988. TextTrackSettings.prototype.buildCSSClass = function buildCSSClass() {
  13989. return _ModalDialog.prototype.buildCSSClass.call(this) + ' vjs-text-track-settings';
  13990. };
  13991. /**
  13992. * Gets an object of text track settings (or null).
  13993. *
  13994. * @return {Object}
  13995. * An object with config values parsed from the DOM or localStorage.
  13996. */
  13997. TextTrackSettings.prototype.getValues = function getValues() {
  13998. var _this3 = this;
  13999. return reduce(selectConfigs, function (accum, config, key) {
  14000. var value = getSelectedOptionValue(_this3.$(config.selector), config.parser);
  14001. if (value !== undefined) {
  14002. accum[key] = value;
  14003. }
  14004. return accum;
  14005. }, {});
  14006. };
  14007. /**
  14008. * Sets text track settings from an object of values.
  14009. *
  14010. * @param {Object} values
  14011. * An object with config values parsed from the DOM or localStorage.
  14012. */
  14013. TextTrackSettings.prototype.setValues = function setValues(values) {
  14014. var _this4 = this;
  14015. each(selectConfigs, function (config, key) {
  14016. setSelectedOption(_this4.$(config.selector), values[key], config.parser);
  14017. });
  14018. };
  14019. /**
  14020. * Sets all `<select>` elements to their default values.
  14021. */
  14022. TextTrackSettings.prototype.setDefaults = function setDefaults() {
  14023. var _this5 = this;
  14024. each(selectConfigs, function (config) {
  14025. var index = config.hasOwnProperty('default') ? config['default'] : 0;
  14026. _this5.$(config.selector).selectedIndex = index;
  14027. });
  14028. };
  14029. /**
  14030. * Restore texttrack settings from localStorage
  14031. */
  14032. TextTrackSettings.prototype.restoreSettings = function restoreSettings() {
  14033. var values = void 0;
  14034. try {
  14035. values = JSON.parse(window.localStorage.getItem(LOCAL_STORAGE_KEY));
  14036. } catch (err) {
  14037. log.warn(err);
  14038. }
  14039. if (values) {
  14040. this.setValues(values);
  14041. }
  14042. };
  14043. /**
  14044. * Save text track settings to localStorage
  14045. */
  14046. TextTrackSettings.prototype.saveSettings = function saveSettings() {
  14047. if (!this.options_.persistTextTrackSettings) {
  14048. return;
  14049. }
  14050. var values = this.getValues();
  14051. try {
  14052. if (Object.keys(values).length) {
  14053. window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(values));
  14054. } else {
  14055. window.localStorage.removeItem(LOCAL_STORAGE_KEY);
  14056. }
  14057. } catch (err) {
  14058. log.warn(err);
  14059. }
  14060. };
  14061. /**
  14062. * Update display of text track settings
  14063. */
  14064. TextTrackSettings.prototype.updateDisplay = function updateDisplay() {
  14065. var ttDisplay = this.player_.getChild('textTrackDisplay');
  14066. if (ttDisplay) {
  14067. ttDisplay.updateDisplay();
  14068. }
  14069. };
  14070. /**
  14071. * conditionally blur the element and refocus the captions button
  14072. *
  14073. * @private
  14074. */
  14075. TextTrackSettings.prototype.conditionalBlur_ = function conditionalBlur_() {
  14076. this.previouslyActiveEl_ = null;
  14077. this.off(document, 'keydown', this.handleKeyDown);
  14078. var cb = this.player_.controlBar;
  14079. var subsCapsBtn = cb && cb.subsCapsButton;
  14080. var ccBtn = cb && cb.captionsButton;
  14081. if (subsCapsBtn) {
  14082. subsCapsBtn.focus();
  14083. } else if (ccBtn) {
  14084. ccBtn.focus();
  14085. }
  14086. };
  14087. return TextTrackSettings;
  14088. }(ModalDialog);
  14089. Component.registerComponent('TextTrackSettings', TextTrackSettings);
  14090. /**
  14091. * @file resize-manager.js
  14092. */
  14093. /**
  14094. * A Resize Manager. It is in charge of triggering `playerresize` on the player in the right conditions.
  14095. *
  14096. * It'll either create an iframe and use a debounced resize handler on it or use the new {@link https://wicg.github.io/ResizeObserver/|ResizeObserver}.
  14097. *
  14098. * If the ResizeObserver is available natively, it will be used. A polyfill can be passed in as an option.
  14099. * If a `playerresize` event is not needed, the ResizeManager component can be removed from the player, see the example below.
  14100. * @example <caption>How to disable the resize manager</caption>
  14101. * const player = videojs('#vid', {
  14102. * resizeManager: false
  14103. * });
  14104. *
  14105. * @see {@link https://wicg.github.io/ResizeObserver/|ResizeObserver specification}
  14106. *
  14107. * @extends Component
  14108. */
  14109. var ResizeManager = function (_Component) {
  14110. inherits(ResizeManager, _Component);
  14111. /**
  14112. * Create the ResizeManager.
  14113. *
  14114. * @param {Object} player
  14115. * The `Player` that this class should be attached to.
  14116. *
  14117. * @param {Object} [options]
  14118. * The key/value store of ResizeManager options.
  14119. *
  14120. * @param {Object} [options.ResizeObserver]
  14121. * A polyfill for ResizeObserver can be passed in here.
  14122. * If this is set to null it will ignore the native ResizeObserver and fall back to the iframe fallback.
  14123. */
  14124. function ResizeManager(player, options) {
  14125. classCallCheck(this, ResizeManager);
  14126. var RESIZE_OBSERVER_AVAILABLE = options.ResizeObserver || window.ResizeObserver;
  14127. // if `null` was passed, we want to disable the ResizeObserver
  14128. if (options.ResizeObserver === null) {
  14129. RESIZE_OBSERVER_AVAILABLE = false;
  14130. }
  14131. // Only create an element when ResizeObserver isn't available
  14132. var options_ = mergeOptions({ createEl: !RESIZE_OBSERVER_AVAILABLE }, options);
  14133. var _this = possibleConstructorReturn(this, _Component.call(this, player, options_));
  14134. _this.ResizeObserver = options.ResizeObserver || window.ResizeObserver;
  14135. _this.loadListener_ = null;
  14136. _this.resizeObserver_ = null;
  14137. _this.debouncedHandler_ = debounce(function () {
  14138. _this.resizeHandler();
  14139. }, 100, false, _this);
  14140. if (RESIZE_OBSERVER_AVAILABLE) {
  14141. _this.resizeObserver_ = new _this.ResizeObserver(_this.debouncedHandler_);
  14142. _this.resizeObserver_.observe(player.el());
  14143. } else {
  14144. _this.loadListener_ = function () {
  14145. if (!_this.el_ || !_this.el_.contentWindow) {
  14146. return;
  14147. }
  14148. on(_this.el_.contentWindow, 'resize', _this.debouncedHandler_);
  14149. };
  14150. _this.one('load', _this.loadListener_);
  14151. }
  14152. return _this;
  14153. }
  14154. ResizeManager.prototype.createEl = function createEl() {
  14155. return _Component.prototype.createEl.call(this, 'iframe', {
  14156. className: 'vjs-resize-manager'
  14157. });
  14158. };
  14159. /**
  14160. * Called when a resize is triggered on the iframe or a resize is observed via the ResizeObserver
  14161. *
  14162. * @fires Player#playerresize
  14163. */
  14164. ResizeManager.prototype.resizeHandler = function resizeHandler() {
  14165. /**
  14166. * Called when the player size has changed
  14167. *
  14168. * @event Player#playerresize
  14169. * @type {EventTarget~Event}
  14170. */
  14171. // make sure player is still around to trigger
  14172. // prevents this from causing an error after dispose
  14173. if (!this.player_ || !this.player_.trigger) {
  14174. return;
  14175. }
  14176. this.player_.trigger('playerresize');
  14177. };
  14178. ResizeManager.prototype.dispose = function dispose() {
  14179. if (this.debouncedHandler_) {
  14180. this.debouncedHandler_.cancel();
  14181. }
  14182. if (this.resizeObserver_) {
  14183. if (this.player_.el()) {
  14184. this.resizeObserver_.unobserve(this.player_.el());
  14185. }
  14186. this.resizeObserver_.disconnect();
  14187. }
  14188. if (this.el_ && this.el_.contentWindow) {
  14189. off(this.el_.contentWindow, 'resize', this.debouncedHandler_);
  14190. }
  14191. if (this.loadListener_) {
  14192. this.off('load', this.loadListener_);
  14193. }
  14194. this.ResizeObserver = null;
  14195. this.resizeObserver = null;
  14196. this.debouncedHandler_ = null;
  14197. this.loadListener_ = null;
  14198. };
  14199. return ResizeManager;
  14200. }(Component);
  14201. Component.registerComponent('ResizeManager', ResizeManager);
  14202. /**
  14203. * This function is used to fire a sourceset when there is something
  14204. * similar to `mediaEl.load()` being called. It will try to find the source via
  14205. * the `src` attribute and then the `<source>` elements. It will then fire `sourceset`
  14206. * with the source that was found or empty string if we cannot know. If it cannot
  14207. * find a source then `sourceset` will not be fired.
  14208. *
  14209. * @param {Html5} tech
  14210. * The tech object that sourceset was setup on
  14211. *
  14212. * @return {boolean}
  14213. * returns false if the sourceset was not fired and true otherwise.
  14214. */
  14215. var sourcesetLoad = function sourcesetLoad(tech) {
  14216. var el = tech.el();
  14217. // if `el.src` is set, that source will be loaded.
  14218. if (el.hasAttribute('src')) {
  14219. tech.triggerSourceset(el.src);
  14220. return true;
  14221. }
  14222. /**
  14223. * Since there isn't a src property on the media element, source elements will be used for
  14224. * implementing the source selection algorithm. This happens asynchronously and
  14225. * for most cases were there is more than one source we cannot tell what source will
  14226. * be loaded, without re-implementing the source selection algorithm. At this time we are not
  14227. * going to do that. There are three special cases that we do handle here though:
  14228. *
  14229. * 1. If there are no sources, do not fire `sourceset`.
  14230. * 2. If there is only one `<source>` with a `src` property/attribute that is our `src`
  14231. * 3. If there is more than one `<source>` but all of them have the same `src` url.
  14232. * That will be our src.
  14233. */
  14234. var sources = tech.$$('source');
  14235. var srcUrls = [];
  14236. var src = '';
  14237. // if there are no sources, do not fire sourceset
  14238. if (!sources.length) {
  14239. return false;
  14240. }
  14241. // only count valid/non-duplicate source elements
  14242. for (var i = 0; i < sources.length; i++) {
  14243. var url = sources[i].src;
  14244. if (url && srcUrls.indexOf(url) === -1) {
  14245. srcUrls.push(url);
  14246. }
  14247. }
  14248. // there were no valid sources
  14249. if (!srcUrls.length) {
  14250. return false;
  14251. }
  14252. // there is only one valid source element url
  14253. // use that
  14254. if (srcUrls.length === 1) {
  14255. src = srcUrls[0];
  14256. }
  14257. tech.triggerSourceset(src);
  14258. return true;
  14259. };
  14260. /**
  14261. * our implementation of an `innerHTML` descriptor for browsers
  14262. * that do not have one.
  14263. */
  14264. var innerHTMLDescriptorPolyfill = {};
  14265. if (!IS_IE8) {
  14266. innerHTMLDescriptorPolyfill = Object.defineProperty({}, 'innerHTML', {
  14267. get: function get() {
  14268. return this.cloneNode(true).innerHTML;
  14269. },
  14270. set: function set(v) {
  14271. // make a dummy node to use innerHTML on
  14272. var dummy = document.createElement(this.nodeName.toLowerCase());
  14273. // set innerHTML to the value provided
  14274. dummy.innerHTML = v;
  14275. // make a document fragment to hold the nodes from dummy
  14276. var docFrag = document.createDocumentFragment();
  14277. // copy all of the nodes created by the innerHTML on dummy
  14278. // to the document fragment
  14279. while (dummy.childNodes.length) {
  14280. docFrag.appendChild(dummy.childNodes[0]);
  14281. }
  14282. // remove content
  14283. this.innerText = '';
  14284. // now we add all of that html in one by appending the
  14285. // document fragment. This is how innerHTML does it.
  14286. window.Element.prototype.appendChild.call(this, docFrag);
  14287. // then return the result that innerHTML's setter would
  14288. return this.innerHTML;
  14289. }
  14290. });
  14291. }
  14292. /**
  14293. * Get a property descriptor given a list of priorities and the
  14294. * property to get.
  14295. */
  14296. var getDescriptor = function getDescriptor(priority, prop) {
  14297. var descriptor = {};
  14298. for (var i = 0; i < priority.length; i++) {
  14299. descriptor = Object.getOwnPropertyDescriptor(priority[i], prop);
  14300. if (descriptor && descriptor.set && descriptor.get) {
  14301. break;
  14302. }
  14303. }
  14304. descriptor.enumerable = true;
  14305. descriptor.configurable = true;
  14306. return descriptor;
  14307. };
  14308. var getInnerHTMLDescriptor = function getInnerHTMLDescriptor(tech) {
  14309. return getDescriptor([tech.el(), window.HTMLMediaElement.prototype, window.Element.prototype, innerHTMLDescriptorPolyfill], 'innerHTML');
  14310. };
  14311. /**
  14312. * Patches browser internal functions so that we can tell syncronously
  14313. * if a `<source>` was appended to the media element. For some reason this
  14314. * causes a `sourceset` if the the media element is ready and has no source.
  14315. * This happens when:
  14316. * - The page has just loaded and the media element does not have a source.
  14317. * - The media element was emptied of all sources, then `load()` was called.
  14318. *
  14319. * It does this by patching the following functions/properties when they are supported:
  14320. *
  14321. * - `append()` - can be used to add a `<source>` element to the media element
  14322. * - `appendChild()` - can be used to add a `<source>` element to the media element
  14323. * - `insertAdjacentHTML()` - can be used to add a `<source>` element to the media element
  14324. * - `innerHTML` - can be used to add a `<source>` element to the media element
  14325. *
  14326. * @param {Html5} tech
  14327. * The tech object that sourceset is being setup on.
  14328. */
  14329. var firstSourceWatch = function firstSourceWatch(tech) {
  14330. var el = tech.el();
  14331. // make sure firstSourceWatch isn't setup twice.
  14332. if (el.resetSourceWatch_) {
  14333. return;
  14334. }
  14335. var old = {};
  14336. var innerDescriptor = getInnerHTMLDescriptor(tech);
  14337. var appendWrapper = function appendWrapper(appendFn) {
  14338. return function () {
  14339. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  14340. args[_key] = arguments[_key];
  14341. }
  14342. var retval = appendFn.apply(el, args);
  14343. sourcesetLoad(tech);
  14344. return retval;
  14345. };
  14346. };
  14347. ['append', 'appendChild', 'insertAdjacentHTML'].forEach(function (k) {
  14348. if (!el[k]) {
  14349. return;
  14350. }
  14351. // store the old function
  14352. old[k] = el[k];
  14353. // call the old function with a sourceset if a source
  14354. // was loaded
  14355. el[k] = appendWrapper(old[k]);
  14356. });
  14357. Object.defineProperty(el, 'innerHTML', mergeOptions(innerDescriptor, {
  14358. set: appendWrapper(innerDescriptor.set)
  14359. }));
  14360. el.resetSourceWatch_ = function () {
  14361. el.resetSourceWatch_ = null;
  14362. Object.keys(old).forEach(function (k) {
  14363. el[k] = old[k];
  14364. });
  14365. Object.defineProperty(el, 'innerHTML', innerDescriptor);
  14366. };
  14367. // on the first sourceset, we need to revert our changes
  14368. tech.one('sourceset', el.resetSourceWatch_);
  14369. };
  14370. /**
  14371. * our implementation of a `src` descriptor for browsers
  14372. * that do not have one.
  14373. */
  14374. var srcDescriptorPolyfill = {};
  14375. if (!IS_IE8) {
  14376. srcDescriptorPolyfill = Object.defineProperty({}, 'src', {
  14377. get: function get() {
  14378. if (this.hasAttribute('src')) {
  14379. return getAbsoluteURL(window.Element.prototype.getAttribute.call(this, 'src'));
  14380. }
  14381. return '';
  14382. },
  14383. set: function set(v) {
  14384. window.Element.prototype.setAttribute.call(this, 'src', v);
  14385. return v;
  14386. }
  14387. });
  14388. }
  14389. var getSrcDescriptor = function getSrcDescriptor(tech) {
  14390. return getDescriptor([tech.el(), window.HTMLMediaElement.prototype, srcDescriptorPolyfill], 'src');
  14391. };
  14392. /**
  14393. * setup `sourceset` handling on the `Html5` tech. This function
  14394. * patches the following element properties/functions:
  14395. *
  14396. * - `src` - to determine when `src` is set
  14397. * - `setAttribute()` - to determine when `src` is set
  14398. * - `load()` - this re-triggers the source selection algorithm, and can
  14399. * cause a sourceset.
  14400. *
  14401. * If there is no source when we are adding `sourceset` support or during a `load()`
  14402. * we also patch the functions listed in `firstSourceWatch`.
  14403. *
  14404. * @param {Html5} tech
  14405. * The tech to patch
  14406. */
  14407. var setupSourceset = function setupSourceset(tech) {
  14408. if (!tech.featuresSourceset) {
  14409. return;
  14410. }
  14411. var el = tech.el();
  14412. // make sure sourceset isn't setup twice.
  14413. if (el.resetSourceset_) {
  14414. return;
  14415. }
  14416. var srcDescriptor = getSrcDescriptor(tech);
  14417. var oldSetAttribute = el.setAttribute;
  14418. var oldLoad = el.load;
  14419. Object.defineProperty(el, 'src', mergeOptions(srcDescriptor, {
  14420. set: function set(v) {
  14421. var retval = srcDescriptor.set.call(el, v);
  14422. // we use the getter here to get the actual value set on src
  14423. tech.triggerSourceset(el.src);
  14424. return retval;
  14425. }
  14426. }));
  14427. el.setAttribute = function (n, v) {
  14428. var retval = oldSetAttribute.call(el, n, v);
  14429. if (/src/i.test(n)) {
  14430. tech.triggerSourceset(el.src);
  14431. }
  14432. return retval;
  14433. };
  14434. el.load = function () {
  14435. var retval = oldLoad.call(el);
  14436. // if load was called, but there was no source to fire
  14437. // sourceset on. We have to watch for a source append
  14438. // as that can trigger a `sourceset` when the media element
  14439. // has no source
  14440. if (!sourcesetLoad(tech)) {
  14441. tech.triggerSourceset('');
  14442. firstSourceWatch(tech);
  14443. }
  14444. return retval;
  14445. };
  14446. if (el.currentSrc) {
  14447. tech.triggerSourceset(el.currentSrc);
  14448. } else if (!sourcesetLoad(tech)) {
  14449. firstSourceWatch(tech);
  14450. }
  14451. el.resetSourceset_ = function () {
  14452. el.resetSourceset_ = null;
  14453. el.load = oldLoad;
  14454. el.setAttribute = oldSetAttribute;
  14455. Object.defineProperty(el, 'src', srcDescriptor);
  14456. if (el.resetSourceWatch_) {
  14457. el.resetSourceWatch_();
  14458. }
  14459. };
  14460. };
  14461. var _templateObject$2 = taggedTemplateLiteralLoose(['Text Tracks are being loaded from another origin but the crossorigin attribute isn\'t used.\n This may prevent text tracks from loading.'], ['Text Tracks are being loaded from another origin but the crossorigin attribute isn\'t used.\n This may prevent text tracks from loading.']);
  14462. /**
  14463. * @file html5.js
  14464. */
  14465. /**
  14466. * HTML5 Media Controller - Wrapper for HTML5 Media API
  14467. *
  14468. * @mixes Tech~SouceHandlerAdditions
  14469. * @extends Tech
  14470. */
  14471. var Html5 = function (_Tech) {
  14472. inherits(Html5, _Tech);
  14473. /**
  14474. * Create an instance of this Tech.
  14475. *
  14476. * @param {Object} [options]
  14477. * The key/value store of player options.
  14478. *
  14479. * @param {Component~ReadyCallback} ready
  14480. * Callback function to call when the `HTML5` Tech is ready.
  14481. */
  14482. function Html5(options, ready) {
  14483. classCallCheck(this, Html5);
  14484. var _this = possibleConstructorReturn(this, _Tech.call(this, options, ready));
  14485. var source = options.source;
  14486. var crossoriginTracks = false;
  14487. // Set the source if one is provided
  14488. // 1) Check if the source is new (if not, we want to keep the original so playback isn't interrupted)
  14489. // 2) Check to see if the network state of the tag was failed at init, and if so, reset the source
  14490. // anyway so the error gets fired.
  14491. if (source && (_this.el_.currentSrc !== source.src || options.tag && options.tag.initNetworkState_ === 3)) {
  14492. _this.setSource(source);
  14493. } else {
  14494. _this.handleLateInit_(_this.el_);
  14495. }
  14496. // setup sourceset after late sourceset/init
  14497. if (options.enableSourceset) {
  14498. _this.setupSourcesetHandling_();
  14499. }
  14500. if (_this.el_.hasChildNodes()) {
  14501. var nodes = _this.el_.childNodes;
  14502. var nodesLength = nodes.length;
  14503. var removeNodes = [];
  14504. while (nodesLength--) {
  14505. var node = nodes[nodesLength];
  14506. var nodeName = node.nodeName.toLowerCase();
  14507. if (nodeName === 'track') {
  14508. if (!_this.featuresNativeTextTracks) {
  14509. // Empty video tag tracks so the built-in player doesn't use them also.
  14510. // This may not be fast enough to stop HTML5 browsers from reading the tags
  14511. // so we'll need to turn off any default tracks if we're manually doing
  14512. // captions and subtitles. videoElement.textTracks
  14513. removeNodes.push(node);
  14514. } else {
  14515. // store HTMLTrackElement and TextTrack to remote list
  14516. _this.remoteTextTrackEls().addTrackElement_(node);
  14517. _this.remoteTextTracks().addTrack(node.track);
  14518. _this.textTracks().addTrack(node.track);
  14519. if (!crossoriginTracks && !_this.el_.hasAttribute('crossorigin') && isCrossOrigin(node.src)) {
  14520. crossoriginTracks = true;
  14521. }
  14522. }
  14523. }
  14524. }
  14525. for (var i = 0; i < removeNodes.length; i++) {
  14526. _this.el_.removeChild(removeNodes[i]);
  14527. }
  14528. }
  14529. _this.proxyNativeTracks_();
  14530. if (_this.featuresNativeTextTracks && crossoriginTracks) {
  14531. log.warn(tsml(_templateObject$2));
  14532. }
  14533. // prevent iOS Safari from disabling metadata text tracks during native playback
  14534. _this.restoreMetadataTracksInIOSNativePlayer_();
  14535. // Determine if native controls should be used
  14536. // Our goal should be to get the custom controls on mobile solid everywhere
  14537. // so we can remove this all together. Right now this will block custom
  14538. // controls on touch enabled laptops like the Chrome Pixel
  14539. if ((TOUCH_ENABLED || IS_IPHONE || IS_NATIVE_ANDROID) && options.nativeControlsForTouch === true) {
  14540. _this.setControls(true);
  14541. }
  14542. // on iOS, we want to proxy `webkitbeginfullscreen` and `webkitendfullscreen`
  14543. // into a `fullscreenchange` event
  14544. _this.proxyWebkitFullscreen_();
  14545. _this.triggerReady();
  14546. return _this;
  14547. }
  14548. /**
  14549. * Dispose of `HTML5` media element and remove all tracks.
  14550. */
  14551. Html5.prototype.dispose = function dispose() {
  14552. if (this.el_ && this.el_.resetSourceset_) {
  14553. this.el_.resetSourceset_();
  14554. }
  14555. Html5.disposeMediaElement(this.el_);
  14556. this.options_ = null;
  14557. // tech will handle clearing of the emulated track list
  14558. _Tech.prototype.dispose.call(this);
  14559. };
  14560. /**
  14561. * Modify the media element so that we can detect when
  14562. * the source is changed. Fires `sourceset` just after the source has changed
  14563. */
  14564. Html5.prototype.setupSourcesetHandling_ = function setupSourcesetHandling_() {
  14565. setupSourceset(this);
  14566. };
  14567. /**
  14568. * When a captions track is enabled in the iOS Safari native player, all other
  14569. * tracks are disabled (including metadata tracks), which nulls all of their
  14570. * associated cue points. This will restore metadata tracks to their pre-fullscreen
  14571. * state in those cases so that cue points are not needlessly lost.
  14572. *
  14573. * @private
  14574. */
  14575. Html5.prototype.restoreMetadataTracksInIOSNativePlayer_ = function restoreMetadataTracksInIOSNativePlayer_() {
  14576. var textTracks = this.textTracks();
  14577. var metadataTracksPreFullscreenState = void 0;
  14578. // captures a snapshot of every metadata track's current state
  14579. var takeMetadataTrackSnapshot = function takeMetadataTrackSnapshot() {
  14580. metadataTracksPreFullscreenState = [];
  14581. for (var i = 0; i < textTracks.length; i++) {
  14582. var track = textTracks[i];
  14583. if (track.kind === 'metadata') {
  14584. metadataTracksPreFullscreenState.push({
  14585. track: track,
  14586. storedMode: track.mode
  14587. });
  14588. }
  14589. }
  14590. };
  14591. // snapshot each metadata track's initial state, and update the snapshot
  14592. // each time there is a track 'change' event
  14593. takeMetadataTrackSnapshot();
  14594. textTracks.addEventListener('change', takeMetadataTrackSnapshot);
  14595. this.on('dispose', function () {
  14596. return textTracks.removeEventListener('change', takeMetadataTrackSnapshot);
  14597. });
  14598. var restoreTrackMode = function restoreTrackMode() {
  14599. for (var i = 0; i < metadataTracksPreFullscreenState.length; i++) {
  14600. var storedTrack = metadataTracksPreFullscreenState[i];
  14601. if (storedTrack.track.mode === 'disabled' && storedTrack.track.mode !== storedTrack.storedMode) {
  14602. storedTrack.track.mode = storedTrack.storedMode;
  14603. }
  14604. }
  14605. // we only want this handler to be executed on the first 'change' event
  14606. textTracks.removeEventListener('change', restoreTrackMode);
  14607. };
  14608. // when we enter fullscreen playback, stop updating the snapshot and
  14609. // restore all track modes to their pre-fullscreen state
  14610. this.on('webkitbeginfullscreen', function () {
  14611. textTracks.removeEventListener('change', takeMetadataTrackSnapshot);
  14612. // remove the listener before adding it just in case it wasn't previously removed
  14613. textTracks.removeEventListener('change', restoreTrackMode);
  14614. textTracks.addEventListener('change', restoreTrackMode);
  14615. });
  14616. // start updating the snapshot again after leaving fullscreen
  14617. this.on('webkitendfullscreen', function () {
  14618. // remove the listener before adding it just in case it wasn't previously removed
  14619. textTracks.removeEventListener('change', takeMetadataTrackSnapshot);
  14620. textTracks.addEventListener('change', takeMetadataTrackSnapshot);
  14621. // remove the restoreTrackMode handler in case it wasn't triggered during fullscreen playback
  14622. textTracks.removeEventListener('change', restoreTrackMode);
  14623. });
  14624. };
  14625. /**
  14626. * Proxy all native track list events to our track lists if the browser we are playing
  14627. * in supports that type of track list.
  14628. *
  14629. * @private
  14630. */
  14631. Html5.prototype.proxyNativeTracks_ = function proxyNativeTracks_() {
  14632. var _this2 = this;
  14633. NORMAL.names.forEach(function (name) {
  14634. var props = NORMAL[name];
  14635. var elTracks = _this2.el()[props.getterName];
  14636. var techTracks = _this2[props.getterName]();
  14637. if (!_this2['featuresNative' + props.capitalName + 'Tracks'] || !elTracks || !elTracks.addEventListener) {
  14638. return;
  14639. }
  14640. var listeners = {
  14641. change: function change(e) {
  14642. techTracks.trigger({
  14643. type: 'change',
  14644. target: techTracks,
  14645. currentTarget: techTracks,
  14646. srcElement: techTracks
  14647. });
  14648. },
  14649. addtrack: function addtrack(e) {
  14650. techTracks.addTrack(e.track);
  14651. },
  14652. removetrack: function removetrack(e) {
  14653. techTracks.removeTrack(e.track);
  14654. }
  14655. };
  14656. var removeOldTracks = function removeOldTracks() {
  14657. var removeTracks = [];
  14658. for (var i = 0; i < techTracks.length; i++) {
  14659. var found = false;
  14660. for (var j = 0; j < elTracks.length; j++) {
  14661. if (elTracks[j] === techTracks[i]) {
  14662. found = true;
  14663. break;
  14664. }
  14665. }
  14666. if (!found) {
  14667. removeTracks.push(techTracks[i]);
  14668. }
  14669. }
  14670. while (removeTracks.length) {
  14671. techTracks.removeTrack(removeTracks.shift());
  14672. }
  14673. };
  14674. Object.keys(listeners).forEach(function (eventName) {
  14675. var listener = listeners[eventName];
  14676. elTracks.addEventListener(eventName, listener);
  14677. _this2.on('dispose', function (e) {
  14678. return elTracks.removeEventListener(eventName, listener);
  14679. });
  14680. });
  14681. // Remove (native) tracks that are not used anymore
  14682. _this2.on('loadstart', removeOldTracks);
  14683. _this2.on('dispose', function (e) {
  14684. return _this2.off('loadstart', removeOldTracks);
  14685. });
  14686. });
  14687. };
  14688. /**
  14689. * Create the `Html5` Tech's DOM element.
  14690. *
  14691. * @return {Element}
  14692. * The element that gets created.
  14693. */
  14694. Html5.prototype.createEl = function createEl$$1() {
  14695. var el = this.options_.tag;
  14696. // Check if this browser supports moving the element into the box.
  14697. // On the iPhone video will break if you move the element,
  14698. // So we have to create a brand new element.
  14699. // If we ingested the player div, we do not need to move the media element.
  14700. if (!el || !(this.options_.playerElIngest || this.movingMediaElementInDOM)) {
  14701. // If the original tag is still there, clone and remove it.
  14702. if (el) {
  14703. var clone = el.cloneNode(true);
  14704. if (el.parentNode) {
  14705. el.parentNode.insertBefore(clone, el);
  14706. }
  14707. Html5.disposeMediaElement(el);
  14708. el = clone;
  14709. } else {
  14710. el = document.createElement('video');
  14711. // determine if native controls should be used
  14712. var tagAttributes = this.options_.tag && getAttributes(this.options_.tag);
  14713. var attributes = mergeOptions({}, tagAttributes);
  14714. if (!TOUCH_ENABLED || this.options_.nativeControlsForTouch !== true) {
  14715. delete attributes.controls;
  14716. }
  14717. setAttributes(el, assign(attributes, {
  14718. id: this.options_.techId,
  14719. 'class': 'vjs-tech'
  14720. }));
  14721. }
  14722. el.playerId = this.options_.playerId;
  14723. }
  14724. if (typeof this.options_.preload !== 'undefined') {
  14725. setAttribute(el, 'preload', this.options_.preload);
  14726. }
  14727. // Update specific tag settings, in case they were overridden
  14728. // `autoplay` has to be *last* so that `muted` and `playsinline` are present
  14729. // when iOS/Safari or other browsers attempt to autoplay.
  14730. var settingsAttrs = ['loop', 'muted', 'playsinline', 'autoplay'];
  14731. for (var i = 0; i < settingsAttrs.length; i++) {
  14732. var attr = settingsAttrs[i];
  14733. var value = this.options_[attr];
  14734. if (typeof value !== 'undefined') {
  14735. if (value) {
  14736. setAttribute(el, attr, attr);
  14737. } else {
  14738. removeAttribute(el, attr);
  14739. }
  14740. el[attr] = value;
  14741. }
  14742. }
  14743. return el;
  14744. };
  14745. /**
  14746. * This will be triggered if the loadstart event has already fired, before videojs was
  14747. * ready. Two known examples of when this can happen are:
  14748. * 1. If we're loading the playback object after it has started loading
  14749. * 2. The media is already playing the (often with autoplay on) then
  14750. *
  14751. * This function will fire another loadstart so that videojs can catchup.
  14752. *
  14753. * @fires Tech#loadstart
  14754. *
  14755. * @return {undefined}
  14756. * returns nothing.
  14757. */
  14758. Html5.prototype.handleLateInit_ = function handleLateInit_(el) {
  14759. if (el.networkState === 0 || el.networkState === 3) {
  14760. // The video element hasn't started loading the source yet
  14761. // or didn't find a source
  14762. return;
  14763. }
  14764. if (el.readyState === 0) {
  14765. // NetworkState is set synchronously BUT loadstart is fired at the
  14766. // end of the current stack, usually before setInterval(fn, 0).
  14767. // So at this point we know loadstart may have already fired or is
  14768. // about to fire, and either way the player hasn't seen it yet.
  14769. // We don't want to fire loadstart prematurely here and cause a
  14770. // double loadstart so we'll wait and see if it happens between now
  14771. // and the next loop, and fire it if not.
  14772. // HOWEVER, we also want to make sure it fires before loadedmetadata
  14773. // which could also happen between now and the next loop, so we'll
  14774. // watch for that also.
  14775. var loadstartFired = false;
  14776. var setLoadstartFired = function setLoadstartFired() {
  14777. loadstartFired = true;
  14778. };
  14779. this.on('loadstart', setLoadstartFired);
  14780. var triggerLoadstart = function triggerLoadstart() {
  14781. // We did miss the original loadstart. Make sure the player
  14782. // sees loadstart before loadedmetadata
  14783. if (!loadstartFired) {
  14784. this.trigger('loadstart');
  14785. }
  14786. };
  14787. this.on('loadedmetadata', triggerLoadstart);
  14788. this.ready(function () {
  14789. this.off('loadstart', setLoadstartFired);
  14790. this.off('loadedmetadata', triggerLoadstart);
  14791. if (!loadstartFired) {
  14792. // We did miss the original native loadstart. Fire it now.
  14793. this.trigger('loadstart');
  14794. }
  14795. });
  14796. return;
  14797. }
  14798. // From here on we know that loadstart already fired and we missed it.
  14799. // The other readyState events aren't as much of a problem if we double
  14800. // them, so not going to go to as much trouble as loadstart to prevent
  14801. // that unless we find reason to.
  14802. var eventsToTrigger = ['loadstart'];
  14803. // loadedmetadata: newly equal to HAVE_METADATA (1) or greater
  14804. eventsToTrigger.push('loadedmetadata');
  14805. // loadeddata: newly increased to HAVE_CURRENT_DATA (2) or greater
  14806. if (el.readyState >= 2) {
  14807. eventsToTrigger.push('loadeddata');
  14808. }
  14809. // canplay: newly increased to HAVE_FUTURE_DATA (3) or greater
  14810. if (el.readyState >= 3) {
  14811. eventsToTrigger.push('canplay');
  14812. }
  14813. // canplaythrough: newly equal to HAVE_ENOUGH_DATA (4)
  14814. if (el.readyState >= 4) {
  14815. eventsToTrigger.push('canplaythrough');
  14816. }
  14817. // We still need to give the player time to add event listeners
  14818. this.ready(function () {
  14819. eventsToTrigger.forEach(function (type) {
  14820. this.trigger(type);
  14821. }, this);
  14822. });
  14823. };
  14824. /**
  14825. * Set current time for the `HTML5` tech.
  14826. *
  14827. * @param {number} seconds
  14828. * Set the current time of the media to this.
  14829. */
  14830. Html5.prototype.setCurrentTime = function setCurrentTime(seconds) {
  14831. try {
  14832. this.el_.currentTime = seconds;
  14833. } catch (e) {
  14834. log(e, 'Video is not ready. (Video.js)');
  14835. // this.warning(VideoJS.warnings.videoNotReady);
  14836. }
  14837. };
  14838. /**
  14839. * Get the current duration of the HTML5 media element.
  14840. *
  14841. * @return {number}
  14842. * The duration of the media or 0 if there is no duration.
  14843. */
  14844. Html5.prototype.duration = function duration() {
  14845. var _this3 = this;
  14846. // Android Chrome will report duration as Infinity for VOD HLS until after
  14847. // playback has started, which triggers the live display erroneously.
  14848. // Return NaN if playback has not started and trigger a durationupdate once
  14849. // the duration can be reliably known.
  14850. if (this.el_.duration === Infinity && IS_ANDROID && IS_CHROME && this.el_.currentTime === 0) {
  14851. // Wait for the first `timeupdate` with currentTime > 0 - there may be
  14852. // several with 0
  14853. var checkProgress = function checkProgress() {
  14854. if (_this3.el_.currentTime > 0) {
  14855. // Trigger durationchange for genuinely live video
  14856. if (_this3.el_.duration === Infinity) {
  14857. _this3.trigger('durationchange');
  14858. }
  14859. _this3.off('timeupdate', checkProgress);
  14860. }
  14861. };
  14862. this.on('timeupdate', checkProgress);
  14863. return NaN;
  14864. }
  14865. return this.el_.duration || NaN;
  14866. };
  14867. /**
  14868. * Get the current width of the HTML5 media element.
  14869. *
  14870. * @return {number}
  14871. * The width of the HTML5 media element.
  14872. */
  14873. Html5.prototype.width = function width() {
  14874. return this.el_.offsetWidth;
  14875. };
  14876. /**
  14877. * Get the current height of the HTML5 media element.
  14878. *
  14879. * @return {number}
  14880. * The heigth of the HTML5 media element.
  14881. */
  14882. Html5.prototype.height = function height() {
  14883. return this.el_.offsetHeight;
  14884. };
  14885. /**
  14886. * Proxy iOS `webkitbeginfullscreen` and `webkitendfullscreen` into
  14887. * `fullscreenchange` event.
  14888. *
  14889. * @private
  14890. * @fires fullscreenchange
  14891. * @listens webkitendfullscreen
  14892. * @listens webkitbeginfullscreen
  14893. * @listens webkitbeginfullscreen
  14894. */
  14895. Html5.prototype.proxyWebkitFullscreen_ = function proxyWebkitFullscreen_() {
  14896. var _this4 = this;
  14897. if (!('webkitDisplayingFullscreen' in this.el_)) {
  14898. return;
  14899. }
  14900. var endFn = function endFn() {
  14901. this.trigger('fullscreenchange', { isFullscreen: false });
  14902. };
  14903. var beginFn = function beginFn() {
  14904. if ('webkitPresentationMode' in this.el_ && this.el_.webkitPresentationMode !== 'picture-in-picture') {
  14905. this.one('webkitendfullscreen', endFn);
  14906. this.trigger('fullscreenchange', { isFullscreen: true });
  14907. }
  14908. };
  14909. this.on('webkitbeginfullscreen', beginFn);
  14910. this.on('dispose', function () {
  14911. _this4.off('webkitbeginfullscreen', beginFn);
  14912. _this4.off('webkitendfullscreen', endFn);
  14913. });
  14914. };
  14915. /**
  14916. * Check if fullscreen is supported on the current playback device.
  14917. *
  14918. * @return {boolean}
  14919. * - True if fullscreen is supported.
  14920. * - False if fullscreen is not supported.
  14921. */
  14922. Html5.prototype.supportsFullScreen = function supportsFullScreen() {
  14923. if (typeof this.el_.webkitEnterFullScreen === 'function') {
  14924. var userAgent = window.navigator && window.navigator.userAgent || '';
  14925. // Seems to be broken in Chromium/Chrome && Safari in Leopard
  14926. if (/Android/.test(userAgent) || !/Chrome|Mac OS X 10.5/.test(userAgent)) {
  14927. return true;
  14928. }
  14929. }
  14930. return false;
  14931. };
  14932. /**
  14933. * Request that the `HTML5` Tech enter fullscreen.
  14934. */
  14935. Html5.prototype.enterFullScreen = function enterFullScreen() {
  14936. var video = this.el_;
  14937. if (video.paused && video.networkState <= video.HAVE_METADATA) {
  14938. // attempt to prime the video element for programmatic access
  14939. // this isn't necessary on the desktop but shouldn't hurt
  14940. this.el_.play();
  14941. // playing and pausing synchronously during the transition to fullscreen
  14942. // can get iOS ~6.1 devices into a play/pause loop
  14943. this.setTimeout(function () {
  14944. video.pause();
  14945. video.webkitEnterFullScreen();
  14946. }, 0);
  14947. } else {
  14948. video.webkitEnterFullScreen();
  14949. }
  14950. };
  14951. /**
  14952. * Request that the `HTML5` Tech exit fullscreen.
  14953. */
  14954. Html5.prototype.exitFullScreen = function exitFullScreen() {
  14955. this.el_.webkitExitFullScreen();
  14956. };
  14957. /**
  14958. * A getter/setter for the `Html5` Tech's source object.
  14959. * > Note: Please use {@link Html5#setSource}
  14960. *
  14961. * @param {Tech~SourceObject} [src]
  14962. * The source object you want to set on the `HTML5` techs element.
  14963. *
  14964. * @return {Tech~SourceObject|undefined}
  14965. * - The current source object when a source is not passed in.
  14966. * - undefined when setting
  14967. *
  14968. * @deprecated Since version 5.
  14969. */
  14970. Html5.prototype.src = function src(_src) {
  14971. if (_src === undefined) {
  14972. return this.el_.src;
  14973. }
  14974. // Setting src through `src` instead of `setSrc` will be deprecated
  14975. this.setSrc(_src);
  14976. };
  14977. /**
  14978. * Reset the tech by removing all sources and then calling
  14979. * {@link Html5.resetMediaElement}.
  14980. */
  14981. Html5.prototype.reset = function reset() {
  14982. Html5.resetMediaElement(this.el_);
  14983. };
  14984. /**
  14985. * Get the current source on the `HTML5` Tech. Falls back to returning the source from
  14986. * the HTML5 media element.
  14987. *
  14988. * @return {Tech~SourceObject}
  14989. * The current source object from the HTML5 tech. With a fallback to the
  14990. * elements source.
  14991. */
  14992. Html5.prototype.currentSrc = function currentSrc() {
  14993. if (this.currentSource_) {
  14994. return this.currentSource_.src;
  14995. }
  14996. return this.el_.currentSrc;
  14997. };
  14998. /**
  14999. * Set controls attribute for the HTML5 media Element.
  15000. *
  15001. * @param {string} val
  15002. * Value to set the controls attribute to
  15003. */
  15004. Html5.prototype.setControls = function setControls(val) {
  15005. this.el_.controls = !!val;
  15006. };
  15007. /**
  15008. * Create and returns a remote {@link TextTrack} object.
  15009. *
  15010. * @param {string} kind
  15011. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata)
  15012. *
  15013. * @param {string} [label]
  15014. * Label to identify the text track
  15015. *
  15016. * @param {string} [language]
  15017. * Two letter language abbreviation
  15018. *
  15019. * @return {TextTrack}
  15020. * The TextTrack that gets created.
  15021. */
  15022. Html5.prototype.addTextTrack = function addTextTrack(kind, label, language) {
  15023. if (!this.featuresNativeTextTracks) {
  15024. return _Tech.prototype.addTextTrack.call(this, kind, label, language);
  15025. }
  15026. return this.el_.addTextTrack(kind, label, language);
  15027. };
  15028. /**
  15029. * Creates either native TextTrack or an emulated TextTrack depending
  15030. * on the value of `featuresNativeTextTracks`
  15031. *
  15032. * @param {Object} options
  15033. * The object should contain the options to intialize the TextTrack with.
  15034. *
  15035. * @param {string} [options.kind]
  15036. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata).
  15037. *
  15038. * @param {string} [options.label].
  15039. * Label to identify the text track
  15040. *
  15041. * @param {string} [options.language]
  15042. * Two letter language abbreviation.
  15043. *
  15044. * @param {boolean} [options.default]
  15045. * Default this track to on.
  15046. *
  15047. * @param {string} [options.id]
  15048. * The internal id to assign this track.
  15049. *
  15050. * @param {string} [options.src]
  15051. * A source url for the track.
  15052. *
  15053. * @return {HTMLTrackElement}
  15054. * The track element that gets created.
  15055. */
  15056. Html5.prototype.createRemoteTextTrack = function createRemoteTextTrack(options) {
  15057. if (!this.featuresNativeTextTracks) {
  15058. return _Tech.prototype.createRemoteTextTrack.call(this, options);
  15059. }
  15060. var htmlTrackElement = document.createElement('track');
  15061. if (options.kind) {
  15062. htmlTrackElement.kind = options.kind;
  15063. }
  15064. if (options.label) {
  15065. htmlTrackElement.label = options.label;
  15066. }
  15067. if (options.language || options.srclang) {
  15068. htmlTrackElement.srclang = options.language || options.srclang;
  15069. }
  15070. if (options['default']) {
  15071. htmlTrackElement['default'] = options['default'];
  15072. }
  15073. if (options.id) {
  15074. htmlTrackElement.id = options.id;
  15075. }
  15076. if (options.src) {
  15077. htmlTrackElement.src = options.src;
  15078. }
  15079. return htmlTrackElement;
  15080. };
  15081. /**
  15082. * Creates a remote text track object and returns an html track element.
  15083. *
  15084. * @param {Object} options The object should contain values for
  15085. * kind, language, label, and src (location of the WebVTT file)
  15086. * @param {Boolean} [manualCleanup=true] if set to false, the TextTrack will be
  15087. * automatically removed from the video element whenever the source changes
  15088. * @return {HTMLTrackElement} An Html Track Element.
  15089. * This can be an emulated {@link HTMLTrackElement} or a native one.
  15090. * @deprecated The default value of the "manualCleanup" parameter will default
  15091. * to "false" in upcoming versions of Video.js
  15092. */
  15093. Html5.prototype.addRemoteTextTrack = function addRemoteTextTrack(options, manualCleanup) {
  15094. var htmlTrackElement = _Tech.prototype.addRemoteTextTrack.call(this, options, manualCleanup);
  15095. if (this.featuresNativeTextTracks) {
  15096. this.el().appendChild(htmlTrackElement);
  15097. }
  15098. return htmlTrackElement;
  15099. };
  15100. /**
  15101. * Remove remote `TextTrack` from `TextTrackList` object
  15102. *
  15103. * @param {TextTrack} track
  15104. * `TextTrack` object to remove
  15105. */
  15106. Html5.prototype.removeRemoteTextTrack = function removeRemoteTextTrack(track) {
  15107. _Tech.prototype.removeRemoteTextTrack.call(this, track);
  15108. if (this.featuresNativeTextTracks) {
  15109. var tracks = this.$$('track');
  15110. var i = tracks.length;
  15111. while (i--) {
  15112. if (track === tracks[i] || track === tracks[i].track) {
  15113. this.el().removeChild(tracks[i]);
  15114. }
  15115. }
  15116. }
  15117. };
  15118. /**
  15119. * Gets available media playback quality metrics as specified by the W3C's Media
  15120. * Playback Quality API.
  15121. *
  15122. * @see [Spec]{@link https://wicg.github.io/media-playback-quality}
  15123. *
  15124. * @return {Object}
  15125. * An object with supported media playback quality metrics
  15126. */
  15127. Html5.prototype.getVideoPlaybackQuality = function getVideoPlaybackQuality() {
  15128. if (typeof this.el().getVideoPlaybackQuality === 'function') {
  15129. return this.el().getVideoPlaybackQuality();
  15130. }
  15131. var videoPlaybackQuality = {};
  15132. if (typeof this.el().webkitDroppedFrameCount !== 'undefined' && typeof this.el().webkitDecodedFrameCount !== 'undefined') {
  15133. videoPlaybackQuality.droppedVideoFrames = this.el().webkitDroppedFrameCount;
  15134. videoPlaybackQuality.totalVideoFrames = this.el().webkitDecodedFrameCount;
  15135. }
  15136. if (window.performance && typeof window.performance.now === 'function') {
  15137. videoPlaybackQuality.creationTime = window.performance.now();
  15138. } else if (window.performance && window.performance.timing && typeof window.performance.timing.navigationStart === 'number') {
  15139. videoPlaybackQuality.creationTime = window.Date.now() - window.performance.timing.navigationStart;
  15140. }
  15141. return videoPlaybackQuality;
  15142. };
  15143. return Html5;
  15144. }(Tech);
  15145. /* HTML5 Support Testing ---------------------------------------------------- */
  15146. if (isReal()) {
  15147. /**
  15148. * Element for testing browser HTML5 media capabilities
  15149. *
  15150. * @type {Element}
  15151. * @constant
  15152. * @private
  15153. */
  15154. Html5.TEST_VID = document.createElement('video');
  15155. var track = document.createElement('track');
  15156. track.kind = 'captions';
  15157. track.srclang = 'en';
  15158. track.label = 'English';
  15159. Html5.TEST_VID.appendChild(track);
  15160. }
  15161. /**
  15162. * Check if HTML5 media is supported by this browser/device.
  15163. *
  15164. * @return {boolean}
  15165. * - True if HTML5 media is supported.
  15166. * - False if HTML5 media is not supported.
  15167. */
  15168. Html5.isSupported = function () {
  15169. // IE9 with no Media Player is a LIAR! (#984)
  15170. try {
  15171. Html5.TEST_VID.volume = 0.5;
  15172. } catch (e) {
  15173. return false;
  15174. }
  15175. return !!(Html5.TEST_VID && Html5.TEST_VID.canPlayType);
  15176. };
  15177. /**
  15178. * Check if the tech can support the given type
  15179. *
  15180. * @param {string} type
  15181. * The mimetype to check
  15182. * @return {string} 'probably', 'maybe', or '' (empty string)
  15183. */
  15184. Html5.canPlayType = function (type) {
  15185. return Html5.TEST_VID.canPlayType(type);
  15186. };
  15187. /**
  15188. * Check if the tech can support the given source
  15189. * @param {Object} srcObj
  15190. * The source object
  15191. * @param {Object} options
  15192. * The options passed to the tech
  15193. * @return {string} 'probably', 'maybe', or '' (empty string)
  15194. */
  15195. Html5.canPlaySource = function (srcObj, options) {
  15196. return Html5.canPlayType(srcObj.type);
  15197. };
  15198. /**
  15199. * Check if the volume can be changed in this browser/device.
  15200. * Volume cannot be changed in a lot of mobile devices.
  15201. * Specifically, it can't be changed from 1 on iOS.
  15202. *
  15203. * @return {boolean}
  15204. * - True if volume can be controlled
  15205. * - False otherwise
  15206. */
  15207. Html5.canControlVolume = function () {
  15208. // IE will error if Windows Media Player not installed #3315
  15209. try {
  15210. var volume = Html5.TEST_VID.volume;
  15211. Html5.TEST_VID.volume = volume / 2 + 0.1;
  15212. return volume !== Html5.TEST_VID.volume;
  15213. } catch (e) {
  15214. return false;
  15215. }
  15216. };
  15217. /**
  15218. * Check if the volume can be muted in this browser/device.
  15219. * Some devices, e.g. iOS, don't allow changing volume
  15220. * but permits muting/unmuting.
  15221. *
  15222. * @return {bolean}
  15223. * - True if volume can be muted
  15224. * - False otherwise
  15225. */
  15226. Html5.canMuteVolume = function () {
  15227. try {
  15228. var muted = Html5.TEST_VID.muted;
  15229. // in some versions of iOS muted property doesn't always
  15230. // work, so we want to set both property and attribute
  15231. Html5.TEST_VID.muted = !muted;
  15232. if (Html5.TEST_VID.muted) {
  15233. setAttribute(Html5.TEST_VID, 'muted', 'muted');
  15234. } else {
  15235. removeAttribute(Html5.TEST_VID, 'muted', 'muted');
  15236. }
  15237. return muted !== Html5.TEST_VID.muted;
  15238. } catch (e) {
  15239. return false;
  15240. }
  15241. };
  15242. /**
  15243. * Check if the playback rate can be changed in this browser/device.
  15244. *
  15245. * @return {boolean}
  15246. * - True if playback rate can be controlled
  15247. * - False otherwise
  15248. */
  15249. Html5.canControlPlaybackRate = function () {
  15250. // Playback rate API is implemented in Android Chrome, but doesn't do anything
  15251. // https://github.com/videojs/video.js/issues/3180
  15252. if (IS_ANDROID && IS_CHROME && CHROME_VERSION < 58) {
  15253. return false;
  15254. }
  15255. // IE will error if Windows Media Player not installed #3315
  15256. try {
  15257. var playbackRate = Html5.TEST_VID.playbackRate;
  15258. Html5.TEST_VID.playbackRate = playbackRate / 2 + 0.1;
  15259. return playbackRate !== Html5.TEST_VID.playbackRate;
  15260. } catch (e) {
  15261. return false;
  15262. }
  15263. };
  15264. /**
  15265. * Check if we can override a video/audio elements attributes, with
  15266. * Object.defineProperty.
  15267. *
  15268. * @return {boolean}
  15269. * - True if builtin attributes can be overriden
  15270. * - False otherwise
  15271. */
  15272. Html5.canOverrideAttributes = function () {
  15273. if (IS_IE8) {
  15274. return false;
  15275. }
  15276. // if we cannot overwrite the src/innerHTML property, there is no support
  15277. // iOS 7 safari for instance cannot do this.
  15278. try {
  15279. var noop = function noop() {};
  15280. Object.defineProperty(document.createElement('video'), 'src', { get: noop, set: noop });
  15281. Object.defineProperty(document.createElement('audio'), 'src', { get: noop, set: noop });
  15282. Object.defineProperty(document.createElement('video'), 'innerHTML', { get: noop, set: noop });
  15283. Object.defineProperty(document.createElement('audio'), 'innerHTML', { get: noop, set: noop });
  15284. } catch (e) {
  15285. return false;
  15286. }
  15287. return true;
  15288. };
  15289. /**
  15290. * Check to see if native `TextTrack`s are supported by this browser/device.
  15291. *
  15292. * @return {boolean}
  15293. * - True if native `TextTrack`s are supported.
  15294. * - False otherwise
  15295. */
  15296. Html5.supportsNativeTextTracks = function () {
  15297. return IS_ANY_SAFARI || IS_IOS && IS_CHROME;
  15298. };
  15299. /**
  15300. * Check to see if native `VideoTrack`s are supported by this browser/device
  15301. *
  15302. * @return {boolean}
  15303. * - True if native `VideoTrack`s are supported.
  15304. * - False otherwise
  15305. */
  15306. Html5.supportsNativeVideoTracks = function () {
  15307. return !!(Html5.TEST_VID && Html5.TEST_VID.videoTracks);
  15308. };
  15309. /**
  15310. * Check to see if native `AudioTrack`s are supported by this browser/device
  15311. *
  15312. * @return {boolean}
  15313. * - True if native `AudioTrack`s are supported.
  15314. * - False otherwise
  15315. */
  15316. Html5.supportsNativeAudioTracks = function () {
  15317. return !!(Html5.TEST_VID && Html5.TEST_VID.audioTracks);
  15318. };
  15319. /**
  15320. * An array of events available on the Html5 tech.
  15321. *
  15322. * @private
  15323. * @type {Array}
  15324. */
  15325. Html5.Events = ['loadstart', 'suspend', 'abort', 'error', 'emptied', 'stalled', 'loadedmetadata', 'loadeddata', 'canplay', 'canplaythrough', 'playing', 'waiting', 'seeking', 'seeked', 'ended', 'durationchange', 'timeupdate', 'progress', 'play', 'pause', 'ratechange', 'resize', 'volumechange'];
  15326. /**
  15327. * Boolean indicating whether the `Tech` supports volume control.
  15328. *
  15329. * @type {boolean}
  15330. * @default {@link Html5.canControlVolume}
  15331. */
  15332. Html5.prototype.featuresVolumeControl = Html5.canControlVolume();
  15333. /**
  15334. * Boolean indicating whether the `Tech` supports muting volume.
  15335. *
  15336. * @type {bolean}
  15337. * @default {@link Html5.canMuteVolume}
  15338. */
  15339. Html5.prototype.featuresMuteControl = Html5.canMuteVolume();
  15340. /**
  15341. * Boolean indicating whether the `Tech` supports changing the speed at which the media
  15342. * plays. Examples:
  15343. * - Set player to play 2x (twice) as fast
  15344. * - Set player to play 0.5x (half) as fast
  15345. *
  15346. * @type {boolean}
  15347. * @default {@link Html5.canControlPlaybackRate}
  15348. */
  15349. Html5.prototype.featuresPlaybackRate = Html5.canControlPlaybackRate();
  15350. /**
  15351. * Boolean indicating wether the `Tech` supports the `sourceset` event.
  15352. *
  15353. * @type {boolean}
  15354. * @default
  15355. */
  15356. Html5.prototype.featuresSourceset = Html5.canOverrideAttributes();
  15357. /**
  15358. * Boolean indicating whether the `HTML5` tech currently supports the media element
  15359. * moving in the DOM. iOS breaks if you move the media element, so this is set this to
  15360. * false there. Everywhere else this should be true.
  15361. *
  15362. * @type {boolean}
  15363. * @default
  15364. */
  15365. Html5.prototype.movingMediaElementInDOM = !IS_IOS;
  15366. // TODO: Previous comment: No longer appears to be used. Can probably be removed.
  15367. // Is this true?
  15368. /**
  15369. * Boolean indicating whether the `HTML5` tech currently supports automatic media resize
  15370. * when going into fullscreen.
  15371. *
  15372. * @type {boolean}
  15373. * @default
  15374. */
  15375. Html5.prototype.featuresFullscreenResize = true;
  15376. /**
  15377. * Boolean indicating whether the `HTML5` tech currently supports the progress event.
  15378. * If this is false, manual `progress` events will be triggred instead.
  15379. *
  15380. * @type {boolean}
  15381. * @default
  15382. */
  15383. Html5.prototype.featuresProgressEvents = true;
  15384. /**
  15385. * Boolean indicating whether the `HTML5` tech currently supports the timeupdate event.
  15386. * If this is false, manual `timeupdate` events will be triggred instead.
  15387. *
  15388. * @default
  15389. */
  15390. Html5.prototype.featuresTimeupdateEvents = true;
  15391. /**
  15392. * Boolean indicating whether the `HTML5` tech currently supports native `TextTrack`s.
  15393. *
  15394. * @type {boolean}
  15395. * @default {@link Html5.supportsNativeTextTracks}
  15396. */
  15397. Html5.prototype.featuresNativeTextTracks = Html5.supportsNativeTextTracks();
  15398. /**
  15399. * Boolean indicating whether the `HTML5` tech currently supports native `VideoTrack`s.
  15400. *
  15401. * @type {boolean}
  15402. * @default {@link Html5.supportsNativeVideoTracks}
  15403. */
  15404. Html5.prototype.featuresNativeVideoTracks = Html5.supportsNativeVideoTracks();
  15405. /**
  15406. * Boolean indicating whether the `HTML5` tech currently supports native `AudioTrack`s.
  15407. *
  15408. * @type {boolean}
  15409. * @default {@link Html5.supportsNativeAudioTracks}
  15410. */
  15411. Html5.prototype.featuresNativeAudioTracks = Html5.supportsNativeAudioTracks();
  15412. // HTML5 Feature detection and Device Fixes --------------------------------- //
  15413. var canPlayType = Html5.TEST_VID && Html5.TEST_VID.constructor.prototype.canPlayType;
  15414. var mpegurlRE = /^application\/(?:x-|vnd\.apple\.)mpegurl/i;
  15415. var mp4RE = /^video\/mp4/i;
  15416. Html5.patchCanPlayType = function () {
  15417. // Android 4.0 and above can play HLS to some extent but it reports being unable to do so
  15418. // Firefox and Chrome report correctly
  15419. if (ANDROID_VERSION >= 4.0 && !IS_FIREFOX && !IS_CHROME) {
  15420. Html5.TEST_VID.constructor.prototype.canPlayType = function (type) {
  15421. if (type && mpegurlRE.test(type)) {
  15422. return 'maybe';
  15423. }
  15424. return canPlayType.call(this, type);
  15425. };
  15426. // Override Android 2.2 and less canPlayType method which is broken
  15427. } else if (IS_OLD_ANDROID) {
  15428. Html5.TEST_VID.constructor.prototype.canPlayType = function (type) {
  15429. if (type && mp4RE.test(type)) {
  15430. return 'maybe';
  15431. }
  15432. return canPlayType.call(this, type);
  15433. };
  15434. }
  15435. };
  15436. Html5.unpatchCanPlayType = function () {
  15437. var r = Html5.TEST_VID.constructor.prototype.canPlayType;
  15438. Html5.TEST_VID.constructor.prototype.canPlayType = canPlayType;
  15439. return r;
  15440. };
  15441. // by default, patch the media element
  15442. Html5.patchCanPlayType();
  15443. Html5.disposeMediaElement = function (el) {
  15444. if (!el) {
  15445. return;
  15446. }
  15447. if (el.parentNode) {
  15448. el.parentNode.removeChild(el);
  15449. }
  15450. // remove any child track or source nodes to prevent their loading
  15451. while (el.hasChildNodes()) {
  15452. el.removeChild(el.firstChild);
  15453. }
  15454. // remove any src reference. not setting `src=''` because that causes a warning
  15455. // in firefox
  15456. el.removeAttribute('src');
  15457. // force the media element to update its loading state by calling load()
  15458. // however IE on Windows 7N has a bug that throws an error so need a try/catch (#793)
  15459. if (typeof el.load === 'function') {
  15460. // wrapping in an iife so it's not deoptimized (#1060#discussion_r10324473)
  15461. (function () {
  15462. try {
  15463. el.load();
  15464. } catch (e) {
  15465. // not supported
  15466. }
  15467. })();
  15468. }
  15469. };
  15470. Html5.resetMediaElement = function (el) {
  15471. if (!el) {
  15472. return;
  15473. }
  15474. var sources = el.querySelectorAll('source');
  15475. var i = sources.length;
  15476. while (i--) {
  15477. el.removeChild(sources[i]);
  15478. }
  15479. // remove any src reference.
  15480. // not setting `src=''` because that throws an error
  15481. el.removeAttribute('src');
  15482. if (typeof el.load === 'function') {
  15483. // wrapping in an iife so it's not deoptimized (#1060#discussion_r10324473)
  15484. (function () {
  15485. try {
  15486. el.load();
  15487. } catch (e) {
  15488. // satisfy linter
  15489. }
  15490. })();
  15491. }
  15492. };
  15493. /* Native HTML5 element property wrapping ----------------------------------- */
  15494. // Wrap native boolean attributes with getters that check both property and attribute
  15495. // The list is as followed:
  15496. // muted, defaultMuted, autoplay, controls, loop, playsinline
  15497. [
  15498. /**
  15499. * Get the value of `muted` from the media element. `muted` indicates
  15500. * that the volume for the media should be set to silent. This does not actually change
  15501. * the `volume` attribute.
  15502. *
  15503. * @method Html5#muted
  15504. * @return {boolean}
  15505. * - True if the value of `volume` should be ignored and the audio set to silent.
  15506. * - False if the value of `volume` should be used.
  15507. *
  15508. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-muted}
  15509. */
  15510. 'muted',
  15511. /**
  15512. * Get the value of `defaultMuted` from the media element. `defaultMuted` indicates
  15513. * whether the media should start muted or not. Only changes the default state of the
  15514. * media. `muted` and `defaultMuted` can have different values. {@link Html5#muted} indicates the
  15515. * current state.
  15516. *
  15517. * @method Html5#defaultMuted
  15518. * @return {boolean}
  15519. * - The value of `defaultMuted` from the media element.
  15520. * - True indicates that the media should start muted.
  15521. * - False indicates that the media should not start muted
  15522. *
  15523. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-defaultmuted}
  15524. */
  15525. 'defaultMuted',
  15526. /**
  15527. * Get the value of `autoplay` from the media element. `autoplay` indicates
  15528. * that the media should start to play as soon as the page is ready.
  15529. *
  15530. * @method Html5#autoplay
  15531. * @return {boolean}
  15532. * - The value of `autoplay` from the media element.
  15533. * - True indicates that the media should start as soon as the page loads.
  15534. * - False indicates that the media should not start as soon as the page loads.
  15535. *
  15536. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-autoplay}
  15537. */
  15538. 'autoplay',
  15539. /**
  15540. * Get the value of `controls` from the media element. `controls` indicates
  15541. * whether the native media controls should be shown or hidden.
  15542. *
  15543. * @method Html5#controls
  15544. * @return {boolean}
  15545. * - The value of `controls` from the media element.
  15546. * - True indicates that native controls should be showing.
  15547. * - False indicates that native controls should be hidden.
  15548. *
  15549. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-controls}
  15550. */
  15551. 'controls',
  15552. /**
  15553. * Get the value of `loop` from the media element. `loop` indicates
  15554. * that the media should return to the start of the media and continue playing once
  15555. * it reaches the end.
  15556. *
  15557. * @method Html5#loop
  15558. * @return {boolean}
  15559. * - The value of `loop` from the media element.
  15560. * - True indicates that playback should seek back to start once
  15561. * the end of a media is reached.
  15562. * - False indicates that playback should not loop back to the start when the
  15563. * end of the media is reached.
  15564. *
  15565. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-loop}
  15566. */
  15567. 'loop',
  15568. /**
  15569. * Get the value of `playsinline` from the media element. `playsinline` indicates
  15570. * to the browser that non-fullscreen playback is preferred when fullscreen
  15571. * playback is the native default, such as in iOS Safari.
  15572. *
  15573. * @method Html5#playsinline
  15574. * @return {boolean}
  15575. * - The value of `playsinline` from the media element.
  15576. * - True indicates that the media should play inline.
  15577. * - False indicates that the media should not play inline.
  15578. *
  15579. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-video-playsinline}
  15580. */
  15581. 'playsinline'].forEach(function (prop) {
  15582. Html5.prototype[prop] = function () {
  15583. return this.el_[prop] || this.el_.hasAttribute(prop);
  15584. };
  15585. });
  15586. // Wrap native boolean attributes with setters that set both property and attribute
  15587. // The list is as followed:
  15588. // setMuted, setDefaultMuted, setAutoplay, setLoop, setPlaysinline
  15589. // setControls is special-cased above
  15590. [
  15591. /**
  15592. * Set the value of `muted` on the media element. `muted` indicates that the current
  15593. * audio level should be silent.
  15594. *
  15595. * @method Html5#setMuted
  15596. * @param {boolean} muted
  15597. * - True if the audio should be set to silent
  15598. * - False otherwise
  15599. *
  15600. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-muted}
  15601. */
  15602. 'muted',
  15603. /**
  15604. * Set the value of `defaultMuted` on the media element. `defaultMuted` indicates that the current
  15605. * audio level should be silent, but will only effect the muted level on intial playback..
  15606. *
  15607. * @method Html5.prototype.setDefaultMuted
  15608. * @param {boolean} defaultMuted
  15609. * - True if the audio should be set to silent
  15610. * - False otherwise
  15611. *
  15612. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-defaultmuted}
  15613. */
  15614. 'defaultMuted',
  15615. /**
  15616. * Set the value of `autoplay` on the media element. `autoplay` indicates
  15617. * that the media should start to play as soon as the page is ready.
  15618. *
  15619. * @method Html5#setAutoplay
  15620. * @param {boolean} autoplay
  15621. * - True indicates that the media should start as soon as the page loads.
  15622. * - False indicates that the media should not start as soon as the page loads.
  15623. *
  15624. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-autoplay}
  15625. */
  15626. 'autoplay',
  15627. /**
  15628. * Set the value of `loop` on the media element. `loop` indicates
  15629. * that the media should return to the start of the media and continue playing once
  15630. * it reaches the end.
  15631. *
  15632. * @method Html5#setLoop
  15633. * @param {boolean} loop
  15634. * - True indicates that playback should seek back to start once
  15635. * the end of a media is reached.
  15636. * - False indicates that playback should not loop back to the start when the
  15637. * end of the media is reached.
  15638. *
  15639. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-loop}
  15640. */
  15641. 'loop',
  15642. /**
  15643. * Set the value of `playsinline` from the media element. `playsinline` indicates
  15644. * to the browser that non-fullscreen playback is preferred when fullscreen
  15645. * playback is the native default, such as in iOS Safari.
  15646. *
  15647. * @method Html5#setPlaysinline
  15648. * @param {boolean} playsinline
  15649. * - True indicates that the media should play inline.
  15650. * - False indicates that the media should not play inline.
  15651. *
  15652. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-video-playsinline}
  15653. */
  15654. 'playsinline'].forEach(function (prop) {
  15655. Html5.prototype['set' + toTitleCase(prop)] = function (v) {
  15656. this.el_[prop] = v;
  15657. if (v) {
  15658. this.el_.setAttribute(prop, prop);
  15659. } else {
  15660. this.el_.removeAttribute(prop);
  15661. }
  15662. };
  15663. });
  15664. // Wrap native properties with a getter
  15665. // The list is as followed
  15666. // paused, currentTime, buffered, volume, poster, preload, error, seeking
  15667. // seekable, ended, playbackRate, defaultPlaybackRate, played, networkState
  15668. // readyState, videoWidth, videoHeight
  15669. [
  15670. /**
  15671. * Get the value of `paused` from the media element. `paused` indicates whether the media element
  15672. * is currently paused or not.
  15673. *
  15674. * @method Html5#paused
  15675. * @return {boolean}
  15676. * The value of `paused` from the media element.
  15677. *
  15678. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-paused}
  15679. */
  15680. 'paused',
  15681. /**
  15682. * Get the value of `currentTime` from the media element. `currentTime` indicates
  15683. * the current second that the media is at in playback.
  15684. *
  15685. * @method Html5#currentTime
  15686. * @return {number}
  15687. * The value of `currentTime` from the media element.
  15688. *
  15689. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-currenttime}
  15690. */
  15691. 'currentTime',
  15692. /**
  15693. * Get the value of `buffered` from the media element. `buffered` is a `TimeRange`
  15694. * object that represents the parts of the media that are already downloaded and
  15695. * available for playback.
  15696. *
  15697. * @method Html5#buffered
  15698. * @return {TimeRange}
  15699. * The value of `buffered` from the media element.
  15700. *
  15701. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-buffered}
  15702. */
  15703. 'buffered',
  15704. /**
  15705. * Get the value of `volume` from the media element. `volume` indicates
  15706. * the current playback volume of audio for a media. `volume` will be a value from 0
  15707. * (silent) to 1 (loudest and default).
  15708. *
  15709. * @method Html5#volume
  15710. * @return {number}
  15711. * The value of `volume` from the media element. Value will be between 0-1.
  15712. *
  15713. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-a-volume}
  15714. */
  15715. 'volume',
  15716. /**
  15717. * Get the value of `poster` from the media element. `poster` indicates
  15718. * that the url of an image file that can/will be shown when no media data is available.
  15719. *
  15720. * @method Html5#poster
  15721. * @return {string}
  15722. * The value of `poster` from the media element. Value will be a url to an
  15723. * image.
  15724. *
  15725. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-video-poster}
  15726. */
  15727. 'poster',
  15728. /**
  15729. * Get the value of `preload` from the media element. `preload` indicates
  15730. * what should download before the media is interacted with. It can have the following
  15731. * values:
  15732. * - none: nothing should be downloaded
  15733. * - metadata: poster and the first few frames of the media may be downloaded to get
  15734. * media dimensions and other metadata
  15735. * - auto: allow the media and metadata for the media to be downloaded before
  15736. * interaction
  15737. *
  15738. * @method Html5#preload
  15739. * @return {string}
  15740. * The value of `preload` from the media element. Will be 'none', 'metadata',
  15741. * or 'auto'.
  15742. *
  15743. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-preload}
  15744. */
  15745. 'preload',
  15746. /**
  15747. * Get the value of the `error` from the media element. `error` indicates any
  15748. * MediaError that may have occured during playback. If error returns null there is no
  15749. * current error.
  15750. *
  15751. * @method Html5#error
  15752. * @return {MediaError|null}
  15753. * The value of `error` from the media element. Will be `MediaError` if there
  15754. * is a current error and null otherwise.
  15755. *
  15756. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-error}
  15757. */
  15758. 'error',
  15759. /**
  15760. * Get the value of `seeking` from the media element. `seeking` indicates whether the
  15761. * media is currently seeking to a new position or not.
  15762. *
  15763. * @method Html5#seeking
  15764. * @return {boolean}
  15765. * - The value of `seeking` from the media element.
  15766. * - True indicates that the media is currently seeking to a new position.
  15767. * - Flase indicates that the media is not seeking to a new position at this time.
  15768. *
  15769. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-seeking}
  15770. */
  15771. 'seeking',
  15772. /**
  15773. * Get the value of `seekable` from the media element. `seekable` returns a
  15774. * `TimeRange` object indicating ranges of time that can currently be `seeked` to.
  15775. *
  15776. * @method Html5#seekable
  15777. * @return {TimeRange}
  15778. * The value of `seekable` from the media element. A `TimeRange` object
  15779. * indicating the current ranges of time that can be seeked to.
  15780. *
  15781. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-seekable}
  15782. */
  15783. 'seekable',
  15784. /**
  15785. * Get the value of `ended` from the media element. `ended` indicates whether
  15786. * the media has reached the end or not.
  15787. *
  15788. * @method Html5#ended
  15789. * @return {boolean}
  15790. * - The value of `ended` from the media element.
  15791. * - True indicates that the media has ended.
  15792. * - False indicates that the media has not ended.
  15793. *
  15794. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-ended}
  15795. */
  15796. 'ended',
  15797. /**
  15798. * Get the value of `playbackRate` from the media element. `playbackRate` indicates
  15799. * the rate at which the media is currently playing back. Examples:
  15800. * - if playbackRate is set to 2, media will play twice as fast.
  15801. * - if playbackRate is set to 0.5, media will play half as fast.
  15802. *
  15803. * @method Html5#playbackRate
  15804. * @return {number}
  15805. * The value of `playbackRate` from the media element. A number indicating
  15806. * the current playback speed of the media, where 1 is normal speed.
  15807. *
  15808. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-playbackrate}
  15809. */
  15810. 'playbackRate',
  15811. /**
  15812. * Get the value of `defaultPlaybackRate` from the media element. `defaultPlaybackRate` indicates
  15813. * the rate at which the media is currently playing back. This value will not indicate the current
  15814. * `playbackRate` after playback has started, use {@link Html5#playbackRate} for that.
  15815. *
  15816. * Examples:
  15817. * - if defaultPlaybackRate is set to 2, media will play twice as fast.
  15818. * - if defaultPlaybackRate is set to 0.5, media will play half as fast.
  15819. *
  15820. * @method Html5.prototype.defaultPlaybackRate
  15821. * @return {number}
  15822. * The value of `defaultPlaybackRate` from the media element. A number indicating
  15823. * the current playback speed of the media, where 1 is normal speed.
  15824. *
  15825. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-playbackrate}
  15826. */
  15827. 'defaultPlaybackRate',
  15828. /**
  15829. * Get the value of `played` from the media element. `played` returns a `TimeRange`
  15830. * object representing points in the media timeline that have been played.
  15831. *
  15832. * @method Html5#played
  15833. * @return {TimeRange}
  15834. * The value of `played` from the media element. A `TimeRange` object indicating
  15835. * the ranges of time that have been played.
  15836. *
  15837. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-played}
  15838. */
  15839. 'played',
  15840. /**
  15841. * Get the value of `networkState` from the media element. `networkState` indicates
  15842. * the current network state. It returns an enumeration from the following list:
  15843. * - 0: NETWORK_EMPTY
  15844. * - 1: NEWORK_IDLE
  15845. * - 2: NETWORK_LOADING
  15846. * - 3: NETWORK_NO_SOURCE
  15847. *
  15848. * @method Html5#networkState
  15849. * @return {number}
  15850. * The value of `networkState` from the media element. This will be a number
  15851. * from the list in the description.
  15852. *
  15853. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-networkstate}
  15854. */
  15855. 'networkState',
  15856. /**
  15857. * Get the value of `readyState` from the media element. `readyState` indicates
  15858. * the current state of the media element. It returns an enumeration from the
  15859. * following list:
  15860. * - 0: HAVE_NOTHING
  15861. * - 1: HAVE_METADATA
  15862. * - 2: HAVE_CURRENT_DATA
  15863. * - 3: HAVE_FUTURE_DATA
  15864. * - 4: HAVE_ENOUGH_DATA
  15865. *
  15866. * @method Html5#readyState
  15867. * @return {number}
  15868. * The value of `readyState` from the media element. This will be a number
  15869. * from the list in the description.
  15870. *
  15871. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#ready-states}
  15872. */
  15873. 'readyState',
  15874. /**
  15875. * Get the value of `videoWidth` from the video element. `videoWidth` indicates
  15876. * the current width of the video in css pixels.
  15877. *
  15878. * @method Html5#videoWidth
  15879. * @return {number}
  15880. * The value of `videoWidth` from the video element. This will be a number
  15881. * in css pixels.
  15882. *
  15883. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth}
  15884. */
  15885. 'videoWidth',
  15886. /**
  15887. * Get the value of `videoHeight` from the video element. `videoHeigth` indicates
  15888. * the current height of the video in css pixels.
  15889. *
  15890. * @method Html5#videoHeight
  15891. * @return {number}
  15892. * The value of `videoHeight` from the video element. This will be a number
  15893. * in css pixels.
  15894. *
  15895. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth}
  15896. */
  15897. 'videoHeight'].forEach(function (prop) {
  15898. Html5.prototype[prop] = function () {
  15899. return this.el_[prop];
  15900. };
  15901. });
  15902. // Wrap native properties with a setter in this format:
  15903. // set + toTitleCase(name)
  15904. // The list is as follows:
  15905. // setVolume, setSrc, setPoster, setPreload, setPlaybackRate, setDefaultPlaybackRate
  15906. [
  15907. /**
  15908. * Set the value of `volume` on the media element. `volume` indicates the current
  15909. * audio level as a percentage in decimal form. This means that 1 is 100%, 0.5 is 50%, and
  15910. * so on.
  15911. *
  15912. * @method Html5#setVolume
  15913. * @param {number} percentAsDecimal
  15914. * The volume percent as a decimal. Valid range is from 0-1.
  15915. *
  15916. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-a-volume}
  15917. */
  15918. 'volume',
  15919. /**
  15920. * Set the value of `src` on the media element. `src` indicates the current
  15921. * {@link Tech~SourceObject} for the media.
  15922. *
  15923. * @method Html5#setSrc
  15924. * @param {Tech~SourceObject} src
  15925. * The source object to set as the current source.
  15926. *
  15927. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-src}
  15928. */
  15929. 'src',
  15930. /**
  15931. * Set the value of `poster` on the media element. `poster` is the url to
  15932. * an image file that can/will be shown when no media data is available.
  15933. *
  15934. * @method Html5#setPoster
  15935. * @param {string} poster
  15936. * The url to an image that should be used as the `poster` for the media
  15937. * element.
  15938. *
  15939. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-poster}
  15940. */
  15941. 'poster',
  15942. /**
  15943. * Set the value of `preload` on the media element. `preload` indicates
  15944. * what should download before the media is interacted with. It can have the following
  15945. * values:
  15946. * - none: nothing should be downloaded
  15947. * - metadata: poster and the first few frames of the media may be downloaded to get
  15948. * media dimensions and other metadata
  15949. * - auto: allow the media and metadata for the media to be downloaded before
  15950. * interaction
  15951. *
  15952. * @method Html5#setPreload
  15953. * @param {string} preload
  15954. * The value of `preload` to set on the media element. Must be 'none', 'metadata',
  15955. * or 'auto'.
  15956. *
  15957. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-preload}
  15958. */
  15959. 'preload',
  15960. /**
  15961. * Set the value of `playbackRate` on the media element. `playbackRate` indicates
  15962. * the rate at which the media should play back. Examples:
  15963. * - if playbackRate is set to 2, media will play twice as fast.
  15964. * - if playbackRate is set to 0.5, media will play half as fast.
  15965. *
  15966. * @method Html5#setPlaybackRate
  15967. * @return {number}
  15968. * The value of `playbackRate` from the media element. A number indicating
  15969. * the current playback speed of the media, where 1 is normal speed.
  15970. *
  15971. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-playbackrate}
  15972. */
  15973. 'playbackRate',
  15974. /**
  15975. * Set the value of `defaultPlaybackRate` on the media element. `defaultPlaybackRate` indicates
  15976. * the rate at which the media should play back upon initial startup. Changing this value
  15977. * after a video has started will do nothing. Instead you should used {@link Html5#setPlaybackRate}.
  15978. *
  15979. * Example Values:
  15980. * - if playbackRate is set to 2, media will play twice as fast.
  15981. * - if playbackRate is set to 0.5, media will play half as fast.
  15982. *
  15983. * @method Html5.prototype.setDefaultPlaybackRate
  15984. * @return {number}
  15985. * The value of `defaultPlaybackRate` from the media element. A number indicating
  15986. * the current playback speed of the media, where 1 is normal speed.
  15987. *
  15988. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-defaultplaybackrate}
  15989. */
  15990. 'defaultPlaybackRate'].forEach(function (prop) {
  15991. Html5.prototype['set' + toTitleCase(prop)] = function (v) {
  15992. this.el_[prop] = v;
  15993. };
  15994. });
  15995. // wrap native functions with a function
  15996. // The list is as follows:
  15997. // pause, load play
  15998. [
  15999. /**
  16000. * A wrapper around the media elements `pause` function. This will call the `HTML5`
  16001. * media elements `pause` function.
  16002. *
  16003. * @method Html5#pause
  16004. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-pause}
  16005. */
  16006. 'pause',
  16007. /**
  16008. * A wrapper around the media elements `load` function. This will call the `HTML5`s
  16009. * media element `load` function.
  16010. *
  16011. * @method Html5#load
  16012. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-load}
  16013. */
  16014. 'load',
  16015. /**
  16016. * A wrapper around the media elements `play` function. This will call the `HTML5`s
  16017. * media element `play` function.
  16018. *
  16019. * @method Html5#play
  16020. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-play}
  16021. */
  16022. 'play'].forEach(function (prop) {
  16023. Html5.prototype[prop] = function () {
  16024. return this.el_[prop]();
  16025. };
  16026. });
  16027. Tech.withSourceHandlers(Html5);
  16028. /**
  16029. * Native source handler for Html5, simply passes the source to the media element.
  16030. *
  16031. * @proprety {Tech~SourceObject} source
  16032. * The source object
  16033. *
  16034. * @proprety {Html5} tech
  16035. * The instance of the HTML5 tech.
  16036. */
  16037. Html5.nativeSourceHandler = {};
  16038. /**
  16039. * Check if the media element can play the given mime type.
  16040. *
  16041. * @param {string} type
  16042. * The mimetype to check
  16043. *
  16044. * @return {string}
  16045. * 'probably', 'maybe', or '' (empty string)
  16046. */
  16047. Html5.nativeSourceHandler.canPlayType = function (type) {
  16048. // IE9 on Windows 7 without MediaPlayer throws an error here
  16049. // https://github.com/videojs/video.js/issues/519
  16050. try {
  16051. return Html5.TEST_VID.canPlayType(type);
  16052. } catch (e) {
  16053. return '';
  16054. }
  16055. };
  16056. /**
  16057. * Check if the media element can handle a source natively.
  16058. *
  16059. * @param {Tech~SourceObject} source
  16060. * The source object
  16061. *
  16062. * @param {Object} [options]
  16063. * Options to be passed to the tech.
  16064. *
  16065. * @return {string}
  16066. * 'probably', 'maybe', or '' (empty string).
  16067. */
  16068. Html5.nativeSourceHandler.canHandleSource = function (source, options) {
  16069. // If a type was provided we should rely on that
  16070. if (source.type) {
  16071. return Html5.nativeSourceHandler.canPlayType(source.type);
  16072. // If no type, fall back to checking 'video/[EXTENSION]'
  16073. } else if (source.src) {
  16074. var ext = getFileExtension(source.src);
  16075. return Html5.nativeSourceHandler.canPlayType('video/' + ext);
  16076. }
  16077. return '';
  16078. };
  16079. /**
  16080. * Pass the source to the native media element.
  16081. *
  16082. * @param {Tech~SourceObject} source
  16083. * The source object
  16084. *
  16085. * @param {Html5} tech
  16086. * The instance of the Html5 tech
  16087. *
  16088. * @param {Object} [options]
  16089. * The options to pass to the source
  16090. */
  16091. Html5.nativeSourceHandler.handleSource = function (source, tech, options) {
  16092. tech.setSrc(source.src);
  16093. };
  16094. /**
  16095. * A noop for the native dispose function, as cleanup is not needed.
  16096. */
  16097. Html5.nativeSourceHandler.dispose = function () {};
  16098. // Register the native source handler
  16099. Html5.registerSourceHandler(Html5.nativeSourceHandler);
  16100. Tech.registerTech('Html5', Html5);
  16101. var _templateObject$1 = taggedTemplateLiteralLoose(['\n Using the tech directly can be dangerous. I hope you know what you\'re doing.\n See https://github.com/videojs/video.js/issues/2617 for more info.\n '], ['\n Using the tech directly can be dangerous. I hope you know what you\'re doing.\n See https://github.com/videojs/video.js/issues/2617 for more info.\n ']);
  16102. /**
  16103. * @file player.js
  16104. */
  16105. // Subclasses Component
  16106. // The following imports are used only to ensure that the corresponding modules
  16107. // are always included in the video.js package. Importing the modules will
  16108. // execute them and they will register themselves with video.js.
  16109. // Import Html5 tech, at least for disposing the original video tag.
  16110. // The following tech events are simply re-triggered
  16111. // on the player when they happen
  16112. var TECH_EVENTS_RETRIGGER = [
  16113. /**
  16114. * Fired while the user agent is downloading media data.
  16115. *
  16116. * @event Player#progress
  16117. * @type {EventTarget~Event}
  16118. */
  16119. /**
  16120. * Retrigger the `progress` event that was triggered by the {@link Tech}.
  16121. *
  16122. * @private
  16123. * @method Player#handleTechProgress_
  16124. * @fires Player#progress
  16125. * @listens Tech#progress
  16126. */
  16127. 'progress',
  16128. /**
  16129. * Fires when the loading of an audio/video is aborted.
  16130. *
  16131. * @event Player#abort
  16132. * @type {EventTarget~Event}
  16133. */
  16134. /**
  16135. * Retrigger the `abort` event that was triggered by the {@link Tech}.
  16136. *
  16137. * @private
  16138. * @method Player#handleTechAbort_
  16139. * @fires Player#abort
  16140. * @listens Tech#abort
  16141. */
  16142. 'abort',
  16143. /**
  16144. * Fires when the browser is intentionally not getting media data.
  16145. *
  16146. * @event Player#suspend
  16147. * @type {EventTarget~Event}
  16148. */
  16149. /**
  16150. * Retrigger the `suspend` event that was triggered by the {@link Tech}.
  16151. *
  16152. * @private
  16153. * @method Player#handleTechSuspend_
  16154. * @fires Player#suspend
  16155. * @listens Tech#suspend
  16156. */
  16157. 'suspend',
  16158. /**
  16159. * Fires when the current playlist is empty.
  16160. *
  16161. * @event Player#emptied
  16162. * @type {EventTarget~Event}
  16163. */
  16164. /**
  16165. * Retrigger the `emptied` event that was triggered by the {@link Tech}.
  16166. *
  16167. * @private
  16168. * @method Player#handleTechEmptied_
  16169. * @fires Player#emptied
  16170. * @listens Tech#emptied
  16171. */
  16172. 'emptied',
  16173. /**
  16174. * Fires when the browser is trying to get media data, but data is not available.
  16175. *
  16176. * @event Player#stalled
  16177. * @type {EventTarget~Event}
  16178. */
  16179. /**
  16180. * Retrigger the `stalled` event that was triggered by the {@link Tech}.
  16181. *
  16182. * @private
  16183. * @method Player#handleTechStalled_
  16184. * @fires Player#stalled
  16185. * @listens Tech#stalled
  16186. */
  16187. 'stalled',
  16188. /**
  16189. * Fires when the browser has loaded meta data for the audio/video.
  16190. *
  16191. * @event Player#loadedmetadata
  16192. * @type {EventTarget~Event}
  16193. */
  16194. /**
  16195. * Retrigger the `stalled` event that was triggered by the {@link Tech}.
  16196. *
  16197. * @private
  16198. * @method Player#handleTechLoadedmetadata_
  16199. * @fires Player#loadedmetadata
  16200. * @listens Tech#loadedmetadata
  16201. */
  16202. 'loadedmetadata',
  16203. /**
  16204. * Fires when the browser has loaded the current frame of the audio/video.
  16205. *
  16206. * @event Player#loadeddata
  16207. * @type {event}
  16208. */
  16209. /**
  16210. * Retrigger the `loadeddata` event that was triggered by the {@link Tech}.
  16211. *
  16212. * @private
  16213. * @method Player#handleTechLoaddeddata_
  16214. * @fires Player#loadeddata
  16215. * @listens Tech#loadeddata
  16216. */
  16217. 'loadeddata',
  16218. /**
  16219. * Fires when the current playback position has changed.
  16220. *
  16221. * @event Player#timeupdate
  16222. * @type {event}
  16223. */
  16224. /**
  16225. * Retrigger the `timeupdate` event that was triggered by the {@link Tech}.
  16226. *
  16227. * @private
  16228. * @method Player#handleTechTimeUpdate_
  16229. * @fires Player#timeupdate
  16230. * @listens Tech#timeupdate
  16231. */
  16232. 'timeupdate',
  16233. /**
  16234. * Fires when the video's intrinsic dimensions change
  16235. *
  16236. * @event Player#resize
  16237. * @type {event}
  16238. */
  16239. /**
  16240. * Retrigger the `resize` event that was triggered by the {@link Tech}.
  16241. *
  16242. * @private
  16243. * @method Player#handleTechResize_
  16244. * @fires Player#resize
  16245. * @listens Tech#resize
  16246. */
  16247. 'resize',
  16248. /**
  16249. * Fires when the volume has been changed
  16250. *
  16251. * @event Player#volumechange
  16252. * @type {event}
  16253. */
  16254. /**
  16255. * Retrigger the `volumechange` event that was triggered by the {@link Tech}.
  16256. *
  16257. * @private
  16258. * @method Player#handleTechVolumechange_
  16259. * @fires Player#volumechange
  16260. * @listens Tech#volumechange
  16261. */
  16262. 'volumechange',
  16263. /**
  16264. * Fires when the text track has been changed
  16265. *
  16266. * @event Player#texttrackchange
  16267. * @type {event}
  16268. */
  16269. /**
  16270. * Retrigger the `texttrackchange` event that was triggered by the {@link Tech}.
  16271. *
  16272. * @private
  16273. * @method Player#handleTechTexttrackchange_
  16274. * @fires Player#texttrackchange
  16275. * @listens Tech#texttrackchange
  16276. */
  16277. 'texttrackchange'];
  16278. // events to queue when playback rate is zero
  16279. // this is a hash for the sole purpose of mapping non-camel-cased event names
  16280. // to camel-cased function names
  16281. var TECH_EVENTS_QUEUE = {
  16282. canplay: 'CanPlay',
  16283. canplaythrough: 'CanPlayThrough',
  16284. playing: 'Playing',
  16285. seeked: 'Seeked'
  16286. };
  16287. var BREAKPOINT_ORDER = ['tiny', 'xsmall', 'small', 'medium', 'large', 'xlarge', 'huge'];
  16288. var BREAKPOINT_CLASSES = {};
  16289. // grep: vjs-layout-tiny
  16290. // grep: vjs-layout-x-small
  16291. // grep: vjs-layout-small
  16292. // grep: vjs-layout-medium
  16293. // grep: vjs-layout-large
  16294. // grep: vjs-layout-x-large
  16295. // grep: vjs-layout-huge
  16296. BREAKPOINT_ORDER.forEach(function (k) {
  16297. var v = k.charAt(0) === 'x' ? 'x-' + k.substring(1) : k;
  16298. BREAKPOINT_CLASSES[k] = 'vjs-layout-' + v;
  16299. });
  16300. var DEFAULT_BREAKPOINTS = {
  16301. tiny: 210,
  16302. xsmall: 320,
  16303. small: 425,
  16304. medium: 768,
  16305. large: 1440,
  16306. xlarge: 2560,
  16307. huge: Infinity
  16308. };
  16309. /**
  16310. * An instance of the `Player` class is created when any of the Video.js setup methods
  16311. * are used to initialize a video.
  16312. *
  16313. * After an instance has been created it can be accessed globally in two ways:
  16314. * 1. By calling `videojs('example_video_1');`
  16315. * 2. By using it directly via `videojs.players.example_video_1;`
  16316. *
  16317. * @extends Component
  16318. */
  16319. var Player = function (_Component) {
  16320. inherits(Player, _Component);
  16321. /**
  16322. * Create an instance of this class.
  16323. *
  16324. * @param {Element} tag
  16325. * The original video DOM element used for configuring options.
  16326. *
  16327. * @param {Object} [options]
  16328. * Object of option names and values.
  16329. *
  16330. * @param {Component~ReadyCallback} [ready]
  16331. * Ready callback function.
  16332. */
  16333. function Player(tag, options, ready) {
  16334. classCallCheck(this, Player);
  16335. // Make sure tag ID exists
  16336. tag.id = tag.id || options.id || 'vjs_video_' + newGUID();
  16337. // Set Options
  16338. // The options argument overrides options set in the video tag
  16339. // which overrides globally set options.
  16340. // This latter part coincides with the load order
  16341. // (tag must exist before Player)
  16342. options = assign(Player.getTagSettings(tag), options);
  16343. // Delay the initialization of children because we need to set up
  16344. // player properties first, and can't use `this` before `super()`
  16345. options.initChildren = false;
  16346. // Same with creating the element
  16347. options.createEl = false;
  16348. // don't auto mixin the evented mixin
  16349. options.evented = false;
  16350. // we don't want the player to report touch activity on itself
  16351. // see enableTouchActivity in Component
  16352. options.reportTouchActivity = false;
  16353. // If language is not set, get the closest lang attribute
  16354. if (!options.language) {
  16355. if (typeof tag.closest === 'function') {
  16356. var closest = tag.closest('[lang]');
  16357. if (closest && closest.getAttribute) {
  16358. options.language = closest.getAttribute('lang');
  16359. }
  16360. } else {
  16361. var element = tag;
  16362. while (element && element.nodeType === 1) {
  16363. if (getAttributes(element).hasOwnProperty('lang')) {
  16364. options.language = element.getAttribute('lang');
  16365. break;
  16366. }
  16367. element = element.parentNode;
  16368. }
  16369. }
  16370. }
  16371. // Run base component initializing with new options
  16372. // create logger
  16373. var _this = possibleConstructorReturn(this, _Component.call(this, null, options, ready));
  16374. _this.log = createLogger(_this.id_);
  16375. // Tracks when a tech changes the poster
  16376. _this.isPosterFromTech_ = false;
  16377. // Holds callback info that gets queued when playback rate is zero
  16378. // and a seek is happening
  16379. _this.queuedCallbacks_ = [];
  16380. // Turn off API access because we're loading a new tech that might load asynchronously
  16381. _this.isReady_ = false;
  16382. // Init state hasStarted_
  16383. _this.hasStarted_ = false;
  16384. // Init state userActive_
  16385. _this.userActive_ = false;
  16386. // if the global option object was accidentally blown away by
  16387. // someone, bail early with an informative error
  16388. if (!_this.options_ || !_this.options_.techOrder || !_this.options_.techOrder.length) {
  16389. throw new Error('No techOrder specified. Did you overwrite ' + 'videojs.options instead of just changing the ' + 'properties you want to override?');
  16390. }
  16391. // Store the original tag used to set options
  16392. _this.tag = tag;
  16393. // Store the tag attributes used to restore html5 element
  16394. _this.tagAttributes = tag && getAttributes(tag);
  16395. // Update current language
  16396. _this.language(_this.options_.language);
  16397. // Update Supported Languages
  16398. if (options.languages) {
  16399. // Normalise player option languages to lowercase
  16400. var languagesToLower = {};
  16401. Object.getOwnPropertyNames(options.languages).forEach(function (name$$1) {
  16402. languagesToLower[name$$1.toLowerCase()] = options.languages[name$$1];
  16403. });
  16404. _this.languages_ = languagesToLower;
  16405. } else {
  16406. _this.languages_ = Player.prototype.options_.languages;
  16407. }
  16408. // Cache for video property values.
  16409. _this.cache_ = {};
  16410. // Set poster
  16411. _this.poster_ = options.poster || '';
  16412. // Set controls
  16413. _this.controls_ = !!options.controls;
  16414. // Set default values for lastVolume
  16415. _this.cache_.lastVolume = 1;
  16416. // Original tag settings stored in options
  16417. // now remove immediately so native controls don't flash.
  16418. // May be turned back on by HTML5 tech if nativeControlsForTouch is true
  16419. tag.controls = false;
  16420. tag.removeAttribute('controls');
  16421. // the attribute overrides the option
  16422. if (tag.hasAttribute('autoplay')) {
  16423. _this.options_.autoplay = true;
  16424. } else {
  16425. // otherwise use the setter to validate and
  16426. // set the correct value.
  16427. _this.autoplay(_this.options_.autoplay);
  16428. }
  16429. /*
  16430. * Store the internal state of scrubbing
  16431. *
  16432. * @private
  16433. * @return {Boolean} True if the user is scrubbing
  16434. */
  16435. _this.scrubbing_ = false;
  16436. _this.el_ = _this.createEl();
  16437. // Set default value for lastPlaybackRate
  16438. _this.cache_.lastPlaybackRate = _this.defaultPlaybackRate();
  16439. // Make this an evented object and use `el_` as its event bus.
  16440. evented(_this, { eventBusKey: 'el_' });
  16441. // We also want to pass the original player options to each component and plugin
  16442. // as well so they don't need to reach back into the player for options later.
  16443. // We also need to do another copy of this.options_ so we don't end up with
  16444. // an infinite loop.
  16445. var playerOptionsCopy = mergeOptions(_this.options_);
  16446. // Load plugins
  16447. if (options.plugins) {
  16448. var plugins = options.plugins;
  16449. Object.keys(plugins).forEach(function (name$$1) {
  16450. if (typeof this[name$$1] === 'function') {
  16451. this[name$$1](plugins[name$$1]);
  16452. } else {
  16453. throw new Error('plugin "' + name$$1 + '" does not exist');
  16454. }
  16455. }, _this);
  16456. }
  16457. _this.options_.playerOptions = playerOptionsCopy;
  16458. _this.middleware_ = [];
  16459. _this.initChildren();
  16460. // Set isAudio based on whether or not an audio tag was used
  16461. _this.isAudio(tag.nodeName.toLowerCase() === 'audio');
  16462. // Update controls className. Can't do this when the controls are initially
  16463. // set because the element doesn't exist yet.
  16464. if (_this.controls()) {
  16465. _this.addClass('vjs-controls-enabled');
  16466. } else {
  16467. _this.addClass('vjs-controls-disabled');
  16468. }
  16469. // Set ARIA label and region role depending on player type
  16470. _this.el_.setAttribute('role', 'region');
  16471. if (_this.isAudio()) {
  16472. _this.el_.setAttribute('aria-label', _this.localize('Audio Player'));
  16473. } else {
  16474. _this.el_.setAttribute('aria-label', _this.localize('Video Player'));
  16475. }
  16476. if (_this.isAudio()) {
  16477. _this.addClass('vjs-audio');
  16478. }
  16479. if (_this.flexNotSupported_()) {
  16480. _this.addClass('vjs-no-flex');
  16481. }
  16482. // TODO: Make this smarter. Toggle user state between touching/mousing
  16483. // using events, since devices can have both touch and mouse events.
  16484. // if (browser.TOUCH_ENABLED) {
  16485. // this.addClass('vjs-touch-enabled');
  16486. // }
  16487. // iOS Safari has broken hover handling
  16488. if (!IS_IOS) {
  16489. _this.addClass('vjs-workinghover');
  16490. }
  16491. // Make player easily findable by ID
  16492. Player.players[_this.id_] = _this;
  16493. // Add a major version class to aid css in plugins
  16494. var majorVersion = version.split('.')[0];
  16495. _this.addClass('vjs-v' + majorVersion);
  16496. // When the player is first initialized, trigger activity so components
  16497. // like the control bar show themselves if needed
  16498. _this.userActive(true);
  16499. _this.reportUserActivity();
  16500. _this.one('play', _this.listenForUserActivity_);
  16501. _this.on('fullscreenchange', _this.handleFullscreenChange_);
  16502. _this.on('stageclick', _this.handleStageClick_);
  16503. _this.breakpoints(_this.options_.breakpoints);
  16504. _this.responsive(_this.options_.responsive);
  16505. _this.changingSrc_ = false;
  16506. _this.playWaitingForReady_ = false;
  16507. _this.playOnLoadstart_ = null;
  16508. return _this;
  16509. }
  16510. /**
  16511. * Destroys the video player and does any necessary cleanup.
  16512. *
  16513. * This is especially helpful if you are dynamically adding and removing videos
  16514. * to/from the DOM.
  16515. *
  16516. * @fires Player#dispose
  16517. */
  16518. Player.prototype.dispose = function dispose() {
  16519. /**
  16520. * Called when the player is being disposed of.
  16521. *
  16522. * @event Player#dispose
  16523. * @type {EventTarget~Event}
  16524. */
  16525. this.trigger('dispose');
  16526. // prevent dispose from being called twice
  16527. this.off('dispose');
  16528. if (this.styleEl_ && this.styleEl_.parentNode) {
  16529. this.styleEl_.parentNode.removeChild(this.styleEl_);
  16530. this.styleEl_ = null;
  16531. }
  16532. // Kill reference to this player
  16533. Player.players[this.id_] = null;
  16534. if (this.tag && this.tag.player) {
  16535. this.tag.player = null;
  16536. }
  16537. if (this.el_ && this.el_.player) {
  16538. this.el_.player = null;
  16539. }
  16540. if (this.tech_) {
  16541. this.tech_.dispose();
  16542. this.isPosterFromTech_ = false;
  16543. this.poster_ = '';
  16544. }
  16545. if (this.playerElIngest_) {
  16546. this.playerElIngest_ = null;
  16547. }
  16548. if (this.tag) {
  16549. this.tag = null;
  16550. }
  16551. clearCacheForPlayer(this);
  16552. // the actual .el_ is removed here
  16553. _Component.prototype.dispose.call(this);
  16554. };
  16555. /**
  16556. * Create the `Player`'s DOM element.
  16557. *
  16558. * @return {Element}
  16559. * The DOM element that gets created.
  16560. */
  16561. Player.prototype.createEl = function createEl$$1() {
  16562. var tag = this.tag;
  16563. var el = void 0;
  16564. var playerElIngest = this.playerElIngest_ = tag.parentNode && tag.parentNode.hasAttribute && tag.parentNode.hasAttribute('data-vjs-player');
  16565. var divEmbed = this.tag.tagName.toLowerCase() === 'video-js';
  16566. if (playerElIngest) {
  16567. el = this.el_ = tag.parentNode;
  16568. } else if (!divEmbed) {
  16569. el = this.el_ = _Component.prototype.createEl.call(this, 'div');
  16570. }
  16571. // Copy over all the attributes from the tag, including ID and class
  16572. // ID will now reference player box, not the video tag
  16573. var attrs = getAttributes(tag);
  16574. if (divEmbed) {
  16575. el = this.el_ = tag;
  16576. tag = this.tag = document.createElement('video');
  16577. while (el.children.length) {
  16578. tag.appendChild(el.firstChild);
  16579. }
  16580. if (!hasClass(el, 'video-js')) {
  16581. addClass(el, 'video-js');
  16582. }
  16583. el.appendChild(tag);
  16584. playerElIngest = this.playerElIngest_ = el;
  16585. // copy over properties from the video-js element
  16586. // ie8 doesn't support Object.keys nor hasOwnProperty
  16587. // on dom elements so we have to specify properties individually
  16588. ['autoplay', 'controls', 'crossOrigin', 'defaultMuted', 'defaultPlaybackRate', 'loop', 'muted', 'playbackRate', 'src', 'volume'].forEach(function (prop) {
  16589. if (typeof el[prop] !== 'undefined') {
  16590. tag[prop] = el[prop];
  16591. }
  16592. });
  16593. }
  16594. // set tabindex to -1 to remove the video element from the focus order
  16595. tag.setAttribute('tabindex', '-1');
  16596. attrs.tabindex = '-1';
  16597. // Workaround for #4583 (JAWS+IE doesn't announce BPB or play button)
  16598. // See https://github.com/FreedomScientific/VFO-standards-support/issues/78
  16599. // Note that we can't detect if JAWS is being used, but this ARIA attribute
  16600. // doesn't change behavior of IE11 if JAWS is not being used
  16601. if (IE_VERSION) {
  16602. tag.setAttribute('role', 'application');
  16603. attrs.role = 'application';
  16604. }
  16605. // Remove width/height attrs from tag so CSS can make it 100% width/height
  16606. tag.removeAttribute('width');
  16607. tag.removeAttribute('height');
  16608. if ('width' in attrs) {
  16609. delete attrs.width;
  16610. }
  16611. if ('height' in attrs) {
  16612. delete attrs.height;
  16613. }
  16614. Object.getOwnPropertyNames(attrs).forEach(function (attr) {
  16615. // workaround so we don't totally break IE7
  16616. // http://stackoverflow.com/questions/3653444/css-styles-not-applied-on-dynamic-elements-in-internet-explorer-7
  16617. if (attr === 'class') {
  16618. el.className += ' ' + attrs[attr];
  16619. if (divEmbed) {
  16620. tag.className += ' ' + attrs[attr];
  16621. }
  16622. } else {
  16623. el.setAttribute(attr, attrs[attr]);
  16624. if (divEmbed) {
  16625. tag.setAttribute(attr, attrs[attr]);
  16626. }
  16627. }
  16628. });
  16629. // Update tag id/class for use as HTML5 playback tech
  16630. // Might think we should do this after embedding in container so .vjs-tech class
  16631. // doesn't flash 100% width/height, but class only applies with .video-js parent
  16632. tag.playerId = tag.id;
  16633. tag.id += '_html5_api';
  16634. tag.className = 'vjs-tech';
  16635. // Make player findable on elements
  16636. tag.player = el.player = this;
  16637. // Default state of video is paused
  16638. this.addClass('vjs-paused');
  16639. // Add a style element in the player that we'll use to set the width/height
  16640. // of the player in a way that's still overrideable by CSS, just like the
  16641. // video element
  16642. if (window.VIDEOJS_NO_DYNAMIC_STYLE !== true) {
  16643. this.styleEl_ = createStyleElement('vjs-styles-dimensions');
  16644. var defaultsStyleEl = $('.vjs-styles-defaults');
  16645. var head = $('head');
  16646. head.insertBefore(this.styleEl_, defaultsStyleEl ? defaultsStyleEl.nextSibling : head.firstChild);
  16647. }
  16648. this.fill_ = false;
  16649. this.fluid_ = false;
  16650. // Pass in the width/height/aspectRatio options which will update the style el
  16651. this.width(this.options_.width);
  16652. this.height(this.options_.height);
  16653. this.fill(this.options_.fill);
  16654. this.fluid(this.options_.fluid);
  16655. this.aspectRatio(this.options_.aspectRatio);
  16656. // Hide any links within the video/audio tag, because IE doesn't hide them completely.
  16657. var links = tag.getElementsByTagName('a');
  16658. for (var i = 0; i < links.length; i++) {
  16659. var linkEl = links.item(i);
  16660. addClass(linkEl, 'vjs-hidden');
  16661. linkEl.setAttribute('hidden', 'hidden');
  16662. }
  16663. // insertElFirst seems to cause the networkState to flicker from 3 to 2, so
  16664. // keep track of the original for later so we can know if the source originally failed
  16665. tag.initNetworkState_ = tag.networkState;
  16666. // Wrap video tag in div (el/box) container
  16667. if (tag.parentNode && !playerElIngest) {
  16668. tag.parentNode.insertBefore(el, tag);
  16669. }
  16670. // insert the tag as the first child of the player element
  16671. // then manually add it to the children array so that this.addChild
  16672. // will work properly for other components
  16673. //
  16674. // Breaks iPhone, fixed in HTML5 setup.
  16675. prependTo(tag, el);
  16676. this.children_.unshift(tag);
  16677. // Set lang attr on player to ensure CSS :lang() in consistent with player
  16678. // if it's been set to something different to the doc
  16679. this.el_.setAttribute('lang', this.language_);
  16680. this.el_ = el;
  16681. return el;
  16682. };
  16683. /**
  16684. * A getter/setter for the `Player`'s width. Returns the player's configured value.
  16685. * To get the current width use `currentWidth()`.
  16686. *
  16687. * @param {number} [value]
  16688. * The value to set the `Player`'s width to.
  16689. *
  16690. * @return {number}
  16691. * The current width of the `Player` when getting.
  16692. */
  16693. Player.prototype.width = function width(value) {
  16694. return this.dimension('width', value);
  16695. };
  16696. /**
  16697. * A getter/setter for the `Player`'s height. Returns the player's configured value.
  16698. * To get the current height use `currentheight()`.
  16699. *
  16700. * @param {number} [value]
  16701. * The value to set the `Player`'s heigth to.
  16702. *
  16703. * @return {number}
  16704. * The current height of the `Player` when getting.
  16705. */
  16706. Player.prototype.height = function height(value) {
  16707. return this.dimension('height', value);
  16708. };
  16709. /**
  16710. * A getter/setter for the `Player`'s width & height.
  16711. *
  16712. * @param {string} dimension
  16713. * This string can be:
  16714. * - 'width'
  16715. * - 'height'
  16716. *
  16717. * @param {number} [value]
  16718. * Value for dimension specified in the first argument.
  16719. *
  16720. * @return {number}
  16721. * The dimension arguments value when getting (width/height).
  16722. */
  16723. Player.prototype.dimension = function dimension(_dimension, value) {
  16724. var privDimension = _dimension + '_';
  16725. if (value === undefined) {
  16726. return this[privDimension] || 0;
  16727. }
  16728. if (value === '') {
  16729. // If an empty string is given, reset the dimension to be automatic
  16730. this[privDimension] = undefined;
  16731. this.updateStyleEl_();
  16732. return;
  16733. }
  16734. var parsedVal = parseFloat(value);
  16735. if (isNaN(parsedVal)) {
  16736. log.error('Improper value "' + value + '" supplied for for ' + _dimension);
  16737. return;
  16738. }
  16739. this[privDimension] = parsedVal;
  16740. this.updateStyleEl_();
  16741. };
  16742. /**
  16743. * A getter/setter/toggler for the vjs-fluid `className` on the `Player`.
  16744. *
  16745. * Turning this on will turn off fill mode.
  16746. *
  16747. * @param {boolean} [bool]
  16748. * - A value of true adds the class.
  16749. * - A value of false removes the class.
  16750. * - No value will be a getter.
  16751. *
  16752. * @return {boolean|undefined}
  16753. * - The value of fluid when getting.
  16754. * - `undefined` when setting.
  16755. */
  16756. Player.prototype.fluid = function fluid(bool) {
  16757. if (bool === undefined) {
  16758. return !!this.fluid_;
  16759. }
  16760. this.fluid_ = !!bool;
  16761. if (bool) {
  16762. this.addClass('vjs-fluid');
  16763. this.fill(false);
  16764. } else {
  16765. this.removeClass('vjs-fluid');
  16766. }
  16767. this.updateStyleEl_();
  16768. };
  16769. /**
  16770. * A getter/setter/toggler for the vjs-fill `className` on the `Player`.
  16771. *
  16772. * Turning this on will turn off fluid mode.
  16773. *
  16774. * @param {boolean} [bool]
  16775. * - A value of true adds the class.
  16776. * - A value of false removes the class.
  16777. * - No value will be a getter.
  16778. *
  16779. * @return {boolean|undefined}
  16780. * - The value of fluid when getting.
  16781. * - `undefined` when setting.
  16782. */
  16783. Player.prototype.fill = function fill(bool) {
  16784. if (bool === undefined) {
  16785. return !!this.fill_;
  16786. }
  16787. this.fill_ = !!bool;
  16788. if (bool) {
  16789. this.addClass('vjs-fill');
  16790. this.fluid(false);
  16791. } else {
  16792. this.removeClass('vjs-fill');
  16793. }
  16794. };
  16795. /**
  16796. * Get/Set the aspect ratio
  16797. *
  16798. * @param {string} [ratio]
  16799. * Aspect ratio for player
  16800. *
  16801. * @return {string|undefined}
  16802. * returns the current aspect ratio when getting
  16803. */
  16804. /**
  16805. * A getter/setter for the `Player`'s aspect ratio.
  16806. *
  16807. * @param {string} [ratio]
  16808. * The value to set the `Player's aspect ratio to.
  16809. *
  16810. * @return {string|undefined}
  16811. * - The current aspect ratio of the `Player` when getting.
  16812. * - undefined when setting
  16813. */
  16814. Player.prototype.aspectRatio = function aspectRatio(ratio) {
  16815. if (ratio === undefined) {
  16816. return this.aspectRatio_;
  16817. }
  16818. // Check for width:height format
  16819. if (!/^\d+\:\d+$/.test(ratio)) {
  16820. throw new Error('Improper value supplied for aspect ratio. The format should be width:height, for example 16:9.');
  16821. }
  16822. this.aspectRatio_ = ratio;
  16823. // We're assuming if you set an aspect ratio you want fluid mode,
  16824. // because in fixed mode you could calculate width and height yourself.
  16825. this.fluid(true);
  16826. this.updateStyleEl_();
  16827. };
  16828. /**
  16829. * Update styles of the `Player` element (height, width and aspect ratio).
  16830. *
  16831. * @private
  16832. * @listens Tech#loadedmetadata
  16833. */
  16834. Player.prototype.updateStyleEl_ = function updateStyleEl_() {
  16835. if (window.VIDEOJS_NO_DYNAMIC_STYLE === true) {
  16836. var _width = typeof this.width_ === 'number' ? this.width_ : this.options_.width;
  16837. var _height = typeof this.height_ === 'number' ? this.height_ : this.options_.height;
  16838. var techEl = this.tech_ && this.tech_.el();
  16839. if (techEl) {
  16840. if (_width >= 0) {
  16841. techEl.width = _width;
  16842. }
  16843. if (_height >= 0) {
  16844. techEl.height = _height;
  16845. }
  16846. }
  16847. return;
  16848. }
  16849. var width = void 0;
  16850. var height = void 0;
  16851. var aspectRatio = void 0;
  16852. var idClass = void 0;
  16853. // The aspect ratio is either used directly or to calculate width and height.
  16854. if (this.aspectRatio_ !== undefined && this.aspectRatio_ !== 'auto') {
  16855. // Use any aspectRatio that's been specifically set
  16856. aspectRatio = this.aspectRatio_;
  16857. } else if (this.videoWidth() > 0) {
  16858. // Otherwise try to get the aspect ratio from the video metadata
  16859. aspectRatio = this.videoWidth() + ':' + this.videoHeight();
  16860. } else {
  16861. // Or use a default. The video element's is 2:1, but 16:9 is more common.
  16862. aspectRatio = '16:9';
  16863. }
  16864. // Get the ratio as a decimal we can use to calculate dimensions
  16865. var ratioParts = aspectRatio.split(':');
  16866. var ratioMultiplier = ratioParts[1] / ratioParts[0];
  16867. if (this.width_ !== undefined) {
  16868. // Use any width that's been specifically set
  16869. width = this.width_;
  16870. } else if (this.height_ !== undefined) {
  16871. // Or calulate the width from the aspect ratio if a height has been set
  16872. width = this.height_ / ratioMultiplier;
  16873. } else {
  16874. // Or use the video's metadata, or use the video el's default of 300
  16875. width = this.videoWidth() || 300;
  16876. }
  16877. if (this.height_ !== undefined) {
  16878. // Use any height that's been specifically set
  16879. height = this.height_;
  16880. } else {
  16881. // Otherwise calculate the height from the ratio and the width
  16882. height = width * ratioMultiplier;
  16883. }
  16884. // Ensure the CSS class is valid by starting with an alpha character
  16885. if (/^[^a-zA-Z]/.test(this.id())) {
  16886. idClass = 'dimensions-' + this.id();
  16887. } else {
  16888. idClass = this.id() + '-dimensions';
  16889. }
  16890. // Ensure the right class is still on the player for the style element
  16891. this.addClass(idClass);
  16892. setTextContent(this.styleEl_, '\n .' + idClass + ' {\n width: ' + width + 'px;\n height: ' + height + 'px;\n }\n\n .' + idClass + '.vjs-fluid {\n padding-top: ' + ratioMultiplier * 100 + '%;\n }\n ');
  16893. };
  16894. /**
  16895. * Load/Create an instance of playback {@link Tech} including element
  16896. * and API methods. Then append the `Tech` element in `Player` as a child.
  16897. *
  16898. * @param {string} techName
  16899. * name of the playback technology
  16900. *
  16901. * @param {string} source
  16902. * video source
  16903. *
  16904. * @private
  16905. */
  16906. Player.prototype.loadTech_ = function loadTech_(techName, source) {
  16907. var _this2 = this;
  16908. // Pause and remove current playback technology
  16909. if (this.tech_) {
  16910. this.unloadTech_();
  16911. }
  16912. var titleTechName = toTitleCase(techName);
  16913. var camelTechName = techName.charAt(0).toLowerCase() + techName.slice(1);
  16914. // get rid of the HTML5 video tag as soon as we are using another tech
  16915. if (titleTechName !== 'Html5' && this.tag) {
  16916. Tech.getTech('Html5').disposeMediaElement(this.tag);
  16917. this.tag.player = null;
  16918. this.tag = null;
  16919. }
  16920. this.techName_ = titleTechName;
  16921. // Turn off API access because we're loading a new tech that might load asynchronously
  16922. this.isReady_ = false;
  16923. // if autoplay is a string we pass false to the tech
  16924. // because the player is going to handle autoplay on `loadstart`
  16925. var autoplay = typeof this.autoplay() === 'string' ? false : this.autoplay();
  16926. // Grab tech-specific options from player options and add source and parent element to use.
  16927. var techOptions = {
  16928. source: source,
  16929. autoplay: autoplay,
  16930. 'nativeControlsForTouch': this.options_.nativeControlsForTouch,
  16931. 'playerId': this.id(),
  16932. 'techId': this.id() + '_' + camelTechName + '_api',
  16933. 'playsinline': this.options_.playsinline,
  16934. 'preload': this.options_.preload,
  16935. 'loop': this.options_.loop,
  16936. 'muted': this.options_.muted,
  16937. 'poster': this.poster(),
  16938. 'language': this.language(),
  16939. 'playerElIngest': this.playerElIngest_ || false,
  16940. 'vtt.js': this.options_['vtt.js'],
  16941. 'canOverridePoster': !!this.options_.techCanOverridePoster,
  16942. 'enableSourceset': this.options_.enableSourceset
  16943. };
  16944. ALL.names.forEach(function (name$$1) {
  16945. var props = ALL[name$$1];
  16946. techOptions[props.getterName] = _this2[props.privateName];
  16947. });
  16948. assign(techOptions, this.options_[titleTechName]);
  16949. assign(techOptions, this.options_[camelTechName]);
  16950. assign(techOptions, this.options_[techName.toLowerCase()]);
  16951. if (this.tag) {
  16952. techOptions.tag = this.tag;
  16953. }
  16954. if (source && source.src === this.cache_.src && this.cache_.currentTime > 0) {
  16955. techOptions.startTime = this.cache_.currentTime;
  16956. }
  16957. // Initialize tech instance
  16958. var TechClass = Tech.getTech(techName);
  16959. if (!TechClass) {
  16960. throw new Error('No Tech named \'' + titleTechName + '\' exists! \'' + titleTechName + '\' should be registered using videojs.registerTech()\'');
  16961. }
  16962. this.tech_ = new TechClass(techOptions);
  16963. // player.triggerReady is always async, so don't need this to be async
  16964. this.tech_.ready(bind(this, this.handleTechReady_), true);
  16965. textTrackConverter.jsonToTextTracks(this.textTracksJson_ || [], this.tech_);
  16966. // Listen to all HTML5-defined events and trigger them on the player
  16967. TECH_EVENTS_RETRIGGER.forEach(function (event) {
  16968. _this2.on(_this2.tech_, event, _this2['handleTech' + toTitleCase(event) + '_']);
  16969. });
  16970. Object.keys(TECH_EVENTS_QUEUE).forEach(function (event) {
  16971. _this2.on(_this2.tech_, event, function (eventObj) {
  16972. if (_this2.tech_.playbackRate() === 0 && _this2.tech_.seeking()) {
  16973. _this2.queuedCallbacks_.push({
  16974. callback: _this2['handleTech' + TECH_EVENTS_QUEUE[event] + '_'].bind(_this2),
  16975. event: eventObj
  16976. });
  16977. return;
  16978. }
  16979. _this2['handleTech' + TECH_EVENTS_QUEUE[event] + '_'](eventObj);
  16980. });
  16981. });
  16982. this.on(this.tech_, 'loadstart', this.handleTechLoadStart_);
  16983. this.on(this.tech_, 'sourceset', this.handleTechSourceset_);
  16984. this.on(this.tech_, 'waiting', this.handleTechWaiting_);
  16985. this.on(this.tech_, 'ended', this.handleTechEnded_);
  16986. this.on(this.tech_, 'seeking', this.handleTechSeeking_);
  16987. this.on(this.tech_, 'play', this.handleTechPlay_);
  16988. this.on(this.tech_, 'firstplay', this.handleTechFirstPlay_);
  16989. this.on(this.tech_, 'pause', this.handleTechPause_);
  16990. this.on(this.tech_, 'durationchange', this.handleTechDurationChange_);
  16991. this.on(this.tech_, 'fullscreenchange', this.handleTechFullscreenChange_);
  16992. this.on(this.tech_, 'error', this.handleTechError_);
  16993. this.on(this.tech_, 'loadedmetadata', this.updateStyleEl_);
  16994. this.on(this.tech_, 'posterchange', this.handleTechPosterChange_);
  16995. this.on(this.tech_, 'textdata', this.handleTechTextData_);
  16996. this.on(this.tech_, 'ratechange', this.handleTechRateChange_);
  16997. this.usingNativeControls(this.techGet_('controls'));
  16998. if (this.controls() && !this.usingNativeControls()) {
  16999. this.addTechControlsListeners_();
  17000. }
  17001. // Add the tech element in the DOM if it was not already there
  17002. // Make sure to not insert the original video element if using Html5
  17003. if (this.tech_.el().parentNode !== this.el() && (titleTechName !== 'Html5' || !this.tag)) {
  17004. prependTo(this.tech_.el(), this.el());
  17005. }
  17006. // Get rid of the original video tag reference after the first tech is loaded
  17007. if (this.tag) {
  17008. this.tag.player = null;
  17009. this.tag = null;
  17010. }
  17011. };
  17012. /**
  17013. * Unload and dispose of the current playback {@link Tech}.
  17014. *
  17015. * @private
  17016. */
  17017. Player.prototype.unloadTech_ = function unloadTech_() {
  17018. var _this3 = this;
  17019. // Save the current text tracks so that we can reuse the same text tracks with the next tech
  17020. ALL.names.forEach(function (name$$1) {
  17021. var props = ALL[name$$1];
  17022. _this3[props.privateName] = _this3[props.getterName]();
  17023. });
  17024. this.textTracksJson_ = textTrackConverter.textTracksToJson(this.tech_);
  17025. this.isReady_ = false;
  17026. this.tech_.dispose();
  17027. this.tech_ = false;
  17028. if (this.isPosterFromTech_) {
  17029. this.poster_ = '';
  17030. this.trigger('posterchange');
  17031. }
  17032. this.isPosterFromTech_ = false;
  17033. };
  17034. /**
  17035. * Return a reference to the current {@link Tech}.
  17036. * It will print a warning by default about the danger of using the tech directly
  17037. * but any argument that is passed in will silence the warning.
  17038. *
  17039. * @param {*} [safety]
  17040. * Anything passed in to silence the warning
  17041. *
  17042. * @return {Tech}
  17043. * The Tech
  17044. */
  17045. Player.prototype.tech = function tech(safety) {
  17046. if (safety === undefined) {
  17047. log.warn(tsml(_templateObject$1));
  17048. }
  17049. return this.tech_;
  17050. };
  17051. /**
  17052. * Set up click and touch listeners for the playback element
  17053. *
  17054. * - On desktops: a click on the video itself will toggle playback
  17055. * - On mobile devices: a click on the video toggles controls
  17056. * which is done by toggling the user state between active and
  17057. * inactive
  17058. * - A tap can signal that a user has become active or has become inactive
  17059. * e.g. a quick tap on an iPhone movie should reveal the controls. Another
  17060. * quick tap should hide them again (signaling the user is in an inactive
  17061. * viewing state)
  17062. * - In addition to this, we still want the user to be considered inactive after
  17063. * a few seconds of inactivity.
  17064. *
  17065. * > Note: the only part of iOS interaction we can't mimic with this setup
  17066. * is a touch and hold on the video element counting as activity in order to
  17067. * keep the controls showing, but that shouldn't be an issue. A touch and hold
  17068. * on any controls will still keep the user active
  17069. *
  17070. * @private
  17071. */
  17072. Player.prototype.addTechControlsListeners_ = function addTechControlsListeners_() {
  17073. // Make sure to remove all the previous listeners in case we are called multiple times.
  17074. this.removeTechControlsListeners_();
  17075. // Some browsers (Chrome & IE) don't trigger a click on a flash swf, but do
  17076. // trigger mousedown/up.
  17077. // http://stackoverflow.com/questions/1444562/javascript-onclick-event-over-flash-object
  17078. // Any touch events are set to block the mousedown event from happening
  17079. this.on(this.tech_, 'mousedown', this.handleTechClick_);
  17080. // If the controls were hidden we don't want that to change without a tap event
  17081. // so we'll check if the controls were already showing before reporting user
  17082. // activity
  17083. this.on(this.tech_, 'touchstart', this.handleTechTouchStart_);
  17084. this.on(this.tech_, 'touchmove', this.handleTechTouchMove_);
  17085. this.on(this.tech_, 'touchend', this.handleTechTouchEnd_);
  17086. // The tap listener needs to come after the touchend listener because the tap
  17087. // listener cancels out any reportedUserActivity when setting userActive(false)
  17088. this.on(this.tech_, 'tap', this.handleTechTap_);
  17089. };
  17090. /**
  17091. * Remove the listeners used for click and tap controls. This is needed for
  17092. * toggling to controls disabled, where a tap/touch should do nothing.
  17093. *
  17094. * @private
  17095. */
  17096. Player.prototype.removeTechControlsListeners_ = function removeTechControlsListeners_() {
  17097. // We don't want to just use `this.off()` because there might be other needed
  17098. // listeners added by techs that extend this.
  17099. this.off(this.tech_, 'tap', this.handleTechTap_);
  17100. this.off(this.tech_, 'touchstart', this.handleTechTouchStart_);
  17101. this.off(this.tech_, 'touchmove', this.handleTechTouchMove_);
  17102. this.off(this.tech_, 'touchend', this.handleTechTouchEnd_);
  17103. this.off(this.tech_, 'mousedown', this.handleTechClick_);
  17104. };
  17105. /**
  17106. * Player waits for the tech to be ready
  17107. *
  17108. * @private
  17109. */
  17110. Player.prototype.handleTechReady_ = function handleTechReady_() {
  17111. this.triggerReady();
  17112. // Keep the same volume as before
  17113. if (this.cache_.volume) {
  17114. this.techCall_('setVolume', this.cache_.volume);
  17115. }
  17116. // Look if the tech found a higher resolution poster while loading
  17117. this.handleTechPosterChange_();
  17118. // Update the duration if available
  17119. this.handleTechDurationChange_();
  17120. // Chrome and Safari both have issues with autoplay.
  17121. // In Safari (5.1.1), when we move the video element into the container div, autoplay doesn't work.
  17122. // In Chrome (15), if you have autoplay + a poster + no controls, the video gets hidden (but audio plays)
  17123. // This fixes both issues. Need to wait for API, so it updates displays correctly
  17124. if ((this.src() || this.currentSrc()) && this.tag && this.options_.autoplay && this.paused()) {
  17125. try {
  17126. // Chrome Fix. Fixed in Chrome v16.
  17127. delete this.tag.poster;
  17128. } catch (e) {
  17129. log('deleting tag.poster throws in some browsers', e);
  17130. }
  17131. }
  17132. };
  17133. /**
  17134. * Retrigger the `loadstart` event that was triggered by the {@link Tech}. This
  17135. * function will also trigger {@link Player#firstplay} if it is the first loadstart
  17136. * for a video.
  17137. *
  17138. * @fires Player#loadstart
  17139. * @fires Player#firstplay
  17140. * @listens Tech#loadstart
  17141. * @private
  17142. */
  17143. Player.prototype.handleTechLoadStart_ = function handleTechLoadStart_() {
  17144. // TODO: Update to use `emptied` event instead. See #1277.
  17145. this.removeClass('vjs-ended');
  17146. this.removeClass('vjs-seeking');
  17147. // reset the error state
  17148. this.error(null);
  17149. // If it's already playing we want to trigger a firstplay event now.
  17150. // The firstplay event relies on both the play and loadstart events
  17151. // which can happen in any order for a new source
  17152. if (!this.paused()) {
  17153. /**
  17154. * Fired when the user agent begins looking for media data
  17155. *
  17156. * @event Player#loadstart
  17157. * @type {EventTarget~Event}
  17158. */
  17159. this.trigger('loadstart');
  17160. this.trigger('firstplay');
  17161. } else {
  17162. // reset the hasStarted state
  17163. this.hasStarted(false);
  17164. this.trigger('loadstart');
  17165. }
  17166. // autoplay happens after loadstart for the browser,
  17167. // so we mimic that behavior
  17168. this.manualAutoplay_(this.autoplay());
  17169. };
  17170. /**
  17171. * Handle autoplay string values, rather than the typical boolean
  17172. * values that should be handled by the tech. Note that this is not
  17173. * part of any specification. Valid values and what they do can be
  17174. * found on the autoplay getter at Player#autoplay()
  17175. */
  17176. Player.prototype.manualAutoplay_ = function manualAutoplay_(type) {
  17177. var _this4 = this;
  17178. if (!this.tech_ || typeof type !== 'string') {
  17179. return;
  17180. }
  17181. var muted = function muted() {
  17182. var previouslyMuted = _this4.muted();
  17183. _this4.muted(true);
  17184. var playPromise = _this4.play();
  17185. if (!playPromise || !playPromise.then || !playPromise['catch']) {
  17186. return;
  17187. }
  17188. return playPromise['catch'](function (e) {
  17189. // restore old value of muted on failure
  17190. _this4.muted(previouslyMuted);
  17191. });
  17192. };
  17193. var promise = void 0;
  17194. if (type === 'any') {
  17195. promise = this.play();
  17196. if (promise && promise.then && promise['catch']) {
  17197. promise['catch'](function () {
  17198. return muted();
  17199. });
  17200. }
  17201. } else if (type === 'muted') {
  17202. promise = muted();
  17203. } else {
  17204. promise = this.play();
  17205. }
  17206. if (!promise || !promise.then || !promise['catch']) {
  17207. return;
  17208. }
  17209. return promise.then(function () {
  17210. _this4.trigger({ type: 'autoplay-success', autoplay: type });
  17211. })['catch'](function (e) {
  17212. _this4.trigger({ type: 'autoplay-failure', autoplay: type });
  17213. });
  17214. };
  17215. /**
  17216. * Update the internal source caches so that we return the correct source from
  17217. * `src()`, `currentSource()`, and `currentSources()`.
  17218. *
  17219. * > Note: `currentSources` will not be updated if the source that is passed in exists
  17220. * in the current `currentSources` cache.
  17221. *
  17222. *
  17223. * @param {Tech~SourceObject} srcObj
  17224. * A string or object source to update our caches to.
  17225. */
  17226. Player.prototype.updateSourceCaches_ = function updateSourceCaches_() {
  17227. var srcObj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  17228. var src = srcObj;
  17229. var type = '';
  17230. if (typeof src !== 'string') {
  17231. src = srcObj.src;
  17232. type = srcObj.type;
  17233. }
  17234. // make sure all the caches are set to default values
  17235. // to prevent null checking
  17236. this.cache_.source = this.cache_.source || {};
  17237. this.cache_.sources = this.cache_.sources || [];
  17238. // try to get the type of the src that was passed in
  17239. if (src && !type) {
  17240. type = findMimetype(this, src);
  17241. }
  17242. // update `currentSource` cache always
  17243. this.cache_.source = mergeOptions({}, srcObj, { src: src, type: type });
  17244. var matchingSources = this.cache_.sources.filter(function (s) {
  17245. return s.src && s.src === src;
  17246. });
  17247. var sourceElSources = [];
  17248. var sourceEls = this.$$('source');
  17249. var matchingSourceEls = [];
  17250. for (var i = 0; i < sourceEls.length; i++) {
  17251. var sourceObj = getAttributes(sourceEls[i]);
  17252. sourceElSources.push(sourceObj);
  17253. if (sourceObj.src && sourceObj.src === src) {
  17254. matchingSourceEls.push(sourceObj.src);
  17255. }
  17256. }
  17257. // if we have matching source els but not matching sources
  17258. // the current source cache is not up to date
  17259. if (matchingSourceEls.length && !matchingSources.length) {
  17260. this.cache_.sources = sourceElSources;
  17261. // if we don't have matching source or source els set the
  17262. // sources cache to the `currentSource` cache
  17263. } else if (!matchingSources.length) {
  17264. this.cache_.sources = [this.cache_.source];
  17265. }
  17266. // update the tech `src` cache
  17267. this.cache_.src = src;
  17268. };
  17269. /**
  17270. * *EXPERIMENTAL* Fired when the source is set or changed on the {@link Tech}
  17271. * causing the media element to reload.
  17272. *
  17273. * It will fire for the initial source and each subsequent source.
  17274. * This event is a custom event from Video.js and is triggered by the {@link Tech}.
  17275. *
  17276. * The event object for this event contains a `src` property that will contain the source
  17277. * that was available when the event was triggered. This is generally only necessary if Video.js
  17278. * is switching techs while the source was being changed.
  17279. *
  17280. * It is also fired when `load` is called on the player (or media element)
  17281. * because the {@link https://html.spec.whatwg.org/multipage/media.html#dom-media-load|specification for `load`}
  17282. * says that the resource selection algorithm needs to be aborted and restarted.
  17283. * In this case, it is very likely that the `src` property will be set to the
  17284. * empty string `""` to indicate we do not know what the source will be but
  17285. * that it is changing.
  17286. *
  17287. * *This event is currently still experimental and may change in minor releases.*
  17288. * __To use this, pass `enableSourceset` option to the player.__
  17289. *
  17290. * @event Player#sourceset
  17291. * @type {EventTarget~Event}
  17292. * @prop {string} src
  17293. * The source url available when the `sourceset` was triggered.
  17294. * It will be an empty string if we cannot know what the source is
  17295. * but know that the source will change.
  17296. */
  17297. /**
  17298. * Retrigger the `sourceset` event that was triggered by the {@link Tech}.
  17299. *
  17300. * @fires Player#sourceset
  17301. * @listens Tech#sourceset
  17302. * @private
  17303. */
  17304. Player.prototype.handleTechSourceset_ = function handleTechSourceset_(event) {
  17305. var _this5 = this;
  17306. // only update the source cache when the source
  17307. // was not updated using the player api
  17308. if (!this.changingSrc_) {
  17309. var updateSourceCaches = function updateSourceCaches(src) {
  17310. return _this5.updateSourceCaches_(src);
  17311. };
  17312. var playerSrc = this.currentSource().src;
  17313. var eventSrc = event.src;
  17314. // if we have a playerSrc that is not a blob, and a tech src that is a blob
  17315. if (playerSrc && !/^blob:/.test(playerSrc) && /^blob:/.test(eventSrc)) {
  17316. // if both the tech source and the player source were updated we assume
  17317. // something like @videojs/http-streaming did the sourceset and skip updating the source cache.
  17318. if (!this.lastSource_ || this.lastSource_.tech !== eventSrc && this.lastSource_.player !== playerSrc) {
  17319. updateSourceCaches = function updateSourceCaches() {};
  17320. }
  17321. }
  17322. // update the source to the intial source right away
  17323. // in some cases this will be empty string
  17324. updateSourceCaches(eventSrc);
  17325. // if the `sourceset` `src` was an empty string
  17326. // wait for a `loadstart` to update the cache to `currentSrc`.
  17327. // If a sourceset happens before a `loadstart`, we reset the state
  17328. // as this function will be called again.
  17329. if (!event.src) {
  17330. var updateCache = function updateCache(e) {
  17331. if (e.type !== 'sourceset') {
  17332. var techSrc = _this5.techGet('currentSrc');
  17333. _this5.lastSource_.tech = techSrc;
  17334. _this5.updateSourceCaches_(techSrc);
  17335. }
  17336. _this5.tech_.off(['sourceset', 'loadstart'], updateCache);
  17337. };
  17338. this.tech_.one(['sourceset', 'loadstart'], updateCache);
  17339. }
  17340. }
  17341. this.lastSource_ = { player: this.currentSource().src, tech: event.src };
  17342. this.trigger({
  17343. src: event.src,
  17344. type: 'sourceset'
  17345. });
  17346. };
  17347. /**
  17348. * Add/remove the vjs-has-started class
  17349. *
  17350. * @fires Player#firstplay
  17351. *
  17352. * @param {boolean} request
  17353. * - true: adds the class
  17354. * - false: remove the class
  17355. *
  17356. * @return {boolean}
  17357. * the boolean value of hasStarted_
  17358. */
  17359. Player.prototype.hasStarted = function hasStarted(request) {
  17360. if (request === undefined) {
  17361. // act as getter, if we have no request to change
  17362. return this.hasStarted_;
  17363. }
  17364. if (request === this.hasStarted_) {
  17365. return;
  17366. }
  17367. this.hasStarted_ = request;
  17368. if (this.hasStarted_) {
  17369. this.addClass('vjs-has-started');
  17370. this.trigger('firstplay');
  17371. } else {
  17372. this.removeClass('vjs-has-started');
  17373. }
  17374. };
  17375. /**
  17376. * Fired whenever the media begins or resumes playback
  17377. *
  17378. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-play}
  17379. * @fires Player#play
  17380. * @listens Tech#play
  17381. * @private
  17382. */
  17383. Player.prototype.handleTechPlay_ = function handleTechPlay_() {
  17384. this.removeClass('vjs-ended');
  17385. this.removeClass('vjs-paused');
  17386. this.addClass('vjs-playing');
  17387. // hide the poster when the user hits play
  17388. this.hasStarted(true);
  17389. /**
  17390. * Triggered whenever an {@link Tech#play} event happens. Indicates that
  17391. * playback has started or resumed.
  17392. *
  17393. * @event Player#play
  17394. * @type {EventTarget~Event}
  17395. */
  17396. this.trigger('play');
  17397. };
  17398. /**
  17399. * Retrigger the `ratechange` event that was triggered by the {@link Tech}.
  17400. *
  17401. * If there were any events queued while the playback rate was zero, fire
  17402. * those events now.
  17403. *
  17404. * @private
  17405. * @method Player#handleTechRateChange_
  17406. * @fires Player#ratechange
  17407. * @listens Tech#ratechange
  17408. */
  17409. Player.prototype.handleTechRateChange_ = function handleTechRateChange_() {
  17410. if (this.tech_.playbackRate() > 0 && this.cache_.lastPlaybackRate === 0) {
  17411. this.queuedCallbacks_.forEach(function (queued) {
  17412. return queued.callback(queued.event);
  17413. });
  17414. this.queuedCallbacks_ = [];
  17415. }
  17416. this.cache_.lastPlaybackRate = this.tech_.playbackRate();
  17417. /**
  17418. * Fires when the playing speed of the audio/video is changed
  17419. *
  17420. * @event Player#ratechange
  17421. * @type {event}
  17422. */
  17423. this.trigger('ratechange');
  17424. };
  17425. /**
  17426. * Retrigger the `waiting` event that was triggered by the {@link Tech}.
  17427. *
  17428. * @fires Player#waiting
  17429. * @listens Tech#waiting
  17430. * @private
  17431. */
  17432. Player.prototype.handleTechWaiting_ = function handleTechWaiting_() {
  17433. var _this6 = this;
  17434. this.addClass('vjs-waiting');
  17435. /**
  17436. * A readyState change on the DOM element has caused playback to stop.
  17437. *
  17438. * @event Player#waiting
  17439. * @type {EventTarget~Event}
  17440. */
  17441. this.trigger('waiting');
  17442. this.one('timeupdate', function () {
  17443. return _this6.removeClass('vjs-waiting');
  17444. });
  17445. };
  17446. /**
  17447. * Retrigger the `canplay` event that was triggered by the {@link Tech}.
  17448. * > Note: This is not consistent between browsers. See #1351
  17449. *
  17450. * @fires Player#canplay
  17451. * @listens Tech#canplay
  17452. * @private
  17453. */
  17454. Player.prototype.handleTechCanPlay_ = function handleTechCanPlay_() {
  17455. this.removeClass('vjs-waiting');
  17456. /**
  17457. * The media has a readyState of HAVE_FUTURE_DATA or greater.
  17458. *
  17459. * @event Player#canplay
  17460. * @type {EventTarget~Event}
  17461. */
  17462. this.trigger('canplay');
  17463. };
  17464. /**
  17465. * Retrigger the `canplaythrough` event that was triggered by the {@link Tech}.
  17466. *
  17467. * @fires Player#canplaythrough
  17468. * @listens Tech#canplaythrough
  17469. * @private
  17470. */
  17471. Player.prototype.handleTechCanPlayThrough_ = function handleTechCanPlayThrough_() {
  17472. this.removeClass('vjs-waiting');
  17473. /**
  17474. * The media has a readyState of HAVE_ENOUGH_DATA or greater. This means that the
  17475. * entire media file can be played without buffering.
  17476. *
  17477. * @event Player#canplaythrough
  17478. * @type {EventTarget~Event}
  17479. */
  17480. this.trigger('canplaythrough');
  17481. };
  17482. /**
  17483. * Retrigger the `playing` event that was triggered by the {@link Tech}.
  17484. *
  17485. * @fires Player#playing
  17486. * @listens Tech#playing
  17487. * @private
  17488. */
  17489. Player.prototype.handleTechPlaying_ = function handleTechPlaying_() {
  17490. this.removeClass('vjs-waiting');
  17491. /**
  17492. * The media is no longer blocked from playback, and has started playing.
  17493. *
  17494. * @event Player#playing
  17495. * @type {EventTarget~Event}
  17496. */
  17497. this.trigger('playing');
  17498. };
  17499. /**
  17500. * Retrigger the `seeking` event that was triggered by the {@link Tech}.
  17501. *
  17502. * @fires Player#seeking
  17503. * @listens Tech#seeking
  17504. * @private
  17505. */
  17506. Player.prototype.handleTechSeeking_ = function handleTechSeeking_() {
  17507. this.addClass('vjs-seeking');
  17508. /**
  17509. * Fired whenever the player is jumping to a new time
  17510. *
  17511. * @event Player#seeking
  17512. * @type {EventTarget~Event}
  17513. */
  17514. this.trigger('seeking');
  17515. };
  17516. /**
  17517. * Retrigger the `seeked` event that was triggered by the {@link Tech}.
  17518. *
  17519. * @fires Player#seeked
  17520. * @listens Tech#seeked
  17521. * @private
  17522. */
  17523. Player.prototype.handleTechSeeked_ = function handleTechSeeked_() {
  17524. this.removeClass('vjs-seeking');
  17525. /**
  17526. * Fired when the player has finished jumping to a new time
  17527. *
  17528. * @event Player#seeked
  17529. * @type {EventTarget~Event}
  17530. */
  17531. this.trigger('seeked');
  17532. };
  17533. /**
  17534. * Retrigger the `firstplay` event that was triggered by the {@link Tech}.
  17535. *
  17536. * @fires Player#firstplay
  17537. * @listens Tech#firstplay
  17538. * @deprecated As of 6.0 firstplay event is deprecated.
  17539. * As of 6.0 passing the `starttime` option to the player and the firstplay event are deprecated.
  17540. * @private
  17541. */
  17542. Player.prototype.handleTechFirstPlay_ = function handleTechFirstPlay_() {
  17543. // If the first starttime attribute is specified
  17544. // then we will start at the given offset in seconds
  17545. if (this.options_.starttime) {
  17546. log.warn('Passing the `starttime` option to the player will be deprecated in 6.0');
  17547. this.currentTime(this.options_.starttime);
  17548. }
  17549. this.addClass('vjs-has-started');
  17550. /**
  17551. * Fired the first time a video is played. Not part of the HLS spec, and this is
  17552. * probably not the best implementation yet, so use sparingly. If you don't have a
  17553. * reason to prevent playback, use `myPlayer.one('play');` instead.
  17554. *
  17555. * @event Player#firstplay
  17556. * @deprecated As of 6.0 firstplay event is deprecated.
  17557. * @type {EventTarget~Event}
  17558. */
  17559. this.trigger('firstplay');
  17560. };
  17561. /**
  17562. * Retrigger the `pause` event that was triggered by the {@link Tech}.
  17563. *
  17564. * @fires Player#pause
  17565. * @listens Tech#pause
  17566. * @private
  17567. */
  17568. Player.prototype.handleTechPause_ = function handleTechPause_() {
  17569. this.removeClass('vjs-playing');
  17570. this.addClass('vjs-paused');
  17571. /**
  17572. * Fired whenever the media has been paused
  17573. *
  17574. * @event Player#pause
  17575. * @type {EventTarget~Event}
  17576. */
  17577. this.trigger('pause');
  17578. };
  17579. /**
  17580. * Retrigger the `ended` event that was triggered by the {@link Tech}.
  17581. *
  17582. * @fires Player#ended
  17583. * @listens Tech#ended
  17584. * @private
  17585. */
  17586. Player.prototype.handleTechEnded_ = function handleTechEnded_() {
  17587. this.addClass('vjs-ended');
  17588. if (this.options_.loop) {
  17589. this.currentTime(0);
  17590. this.play();
  17591. } else if (!this.paused()) {
  17592. this.pause();
  17593. }
  17594. /**
  17595. * Fired when the end of the media resource is reached (currentTime == duration)
  17596. *
  17597. * @event Player#ended
  17598. * @type {EventTarget~Event}
  17599. */
  17600. this.trigger('ended');
  17601. };
  17602. /**
  17603. * Fired when the duration of the media resource is first known or changed
  17604. *
  17605. * @listens Tech#durationchange
  17606. * @private
  17607. */
  17608. Player.prototype.handleTechDurationChange_ = function handleTechDurationChange_() {
  17609. this.duration(this.techGet_('duration'));
  17610. };
  17611. /**
  17612. * Handle a click on the media element to play/pause
  17613. *
  17614. * @param {EventTarget~Event} event
  17615. * the event that caused this function to trigger
  17616. *
  17617. * @listens Tech#mousedown
  17618. * @private
  17619. */
  17620. Player.prototype.handleTechClick_ = function handleTechClick_(event) {
  17621. if (!isSingleLeftClick(event)) {
  17622. return;
  17623. }
  17624. // When controls are disabled a click should not toggle playback because
  17625. // the click is considered a control
  17626. if (!this.controls_) {
  17627. return;
  17628. }
  17629. if (this.paused()) {
  17630. silencePromise(this.play());
  17631. } else {
  17632. this.pause();
  17633. }
  17634. };
  17635. /**
  17636. * Handle a tap on the media element. It will toggle the user
  17637. * activity state, which hides and shows the controls.
  17638. *
  17639. * @listens Tech#tap
  17640. * @private
  17641. */
  17642. Player.prototype.handleTechTap_ = function handleTechTap_() {
  17643. this.userActive(!this.userActive());
  17644. };
  17645. /**
  17646. * Handle touch to start
  17647. *
  17648. * @listens Tech#touchstart
  17649. * @private
  17650. */
  17651. Player.prototype.handleTechTouchStart_ = function handleTechTouchStart_() {
  17652. this.userWasActive = this.userActive();
  17653. };
  17654. /**
  17655. * Handle touch to move
  17656. *
  17657. * @listens Tech#touchmove
  17658. * @private
  17659. */
  17660. Player.prototype.handleTechTouchMove_ = function handleTechTouchMove_() {
  17661. if (this.userWasActive) {
  17662. this.reportUserActivity();
  17663. }
  17664. };
  17665. /**
  17666. * Handle touch to end
  17667. *
  17668. * @param {EventTarget~Event} event
  17669. * the touchend event that triggered
  17670. * this function
  17671. *
  17672. * @listens Tech#touchend
  17673. * @private
  17674. */
  17675. Player.prototype.handleTechTouchEnd_ = function handleTechTouchEnd_(event) {
  17676. // Stop the mouse events from also happening
  17677. event.preventDefault();
  17678. };
  17679. /**
  17680. * Fired when the player switches in or out of fullscreen mode
  17681. *
  17682. * @private
  17683. * @listens Player#fullscreenchange
  17684. */
  17685. Player.prototype.handleFullscreenChange_ = function handleFullscreenChange_() {
  17686. if (this.isFullscreen()) {
  17687. this.addClass('vjs-fullscreen');
  17688. } else {
  17689. this.removeClass('vjs-fullscreen');
  17690. }
  17691. };
  17692. /**
  17693. * native click events on the SWF aren't triggered on IE11, Win8.1RT
  17694. * use stageclick events triggered from inside the SWF instead
  17695. *
  17696. * @private
  17697. * @listens stageclick
  17698. */
  17699. Player.prototype.handleStageClick_ = function handleStageClick_() {
  17700. this.reportUserActivity();
  17701. };
  17702. /**
  17703. * Handle Tech Fullscreen Change
  17704. *
  17705. * @param {EventTarget~Event} event
  17706. * the fullscreenchange event that triggered this function
  17707. *
  17708. * @param {Object} data
  17709. * the data that was sent with the event
  17710. *
  17711. * @private
  17712. * @listens Tech#fullscreenchange
  17713. * @fires Player#fullscreenchange
  17714. */
  17715. Player.prototype.handleTechFullscreenChange_ = function handleTechFullscreenChange_(event, data) {
  17716. if (data) {
  17717. this.isFullscreen(data.isFullscreen);
  17718. }
  17719. /**
  17720. * Fired when going in and out of fullscreen.
  17721. *
  17722. * @event Player#fullscreenchange
  17723. * @type {EventTarget~Event}
  17724. */
  17725. this.trigger('fullscreenchange');
  17726. };
  17727. /**
  17728. * Fires when an error occurred during the loading of an audio/video.
  17729. *
  17730. * @private
  17731. * @listens Tech#error
  17732. */
  17733. Player.prototype.handleTechError_ = function handleTechError_() {
  17734. var error = this.tech_.error();
  17735. this.error(error);
  17736. };
  17737. /**
  17738. * Retrigger the `textdata` event that was triggered by the {@link Tech}.
  17739. *
  17740. * @fires Player#textdata
  17741. * @listens Tech#textdata
  17742. * @private
  17743. */
  17744. Player.prototype.handleTechTextData_ = function handleTechTextData_() {
  17745. var data = null;
  17746. if (arguments.length > 1) {
  17747. data = arguments[1];
  17748. }
  17749. /**
  17750. * Fires when we get a textdata event from tech
  17751. *
  17752. * @event Player#textdata
  17753. * @type {EventTarget~Event}
  17754. */
  17755. this.trigger('textdata', data);
  17756. };
  17757. /**
  17758. * Get object for cached values.
  17759. *
  17760. * @return {Object}
  17761. * get the current object cache
  17762. */
  17763. Player.prototype.getCache = function getCache() {
  17764. return this.cache_;
  17765. };
  17766. /**
  17767. * Pass values to the playback tech
  17768. *
  17769. * @param {string} [method]
  17770. * the method to call
  17771. *
  17772. * @param {Object} arg
  17773. * the argument to pass
  17774. *
  17775. * @private
  17776. */
  17777. Player.prototype.techCall_ = function techCall_(method, arg) {
  17778. // If it's not ready yet, call method when it is
  17779. this.ready(function () {
  17780. if (method in allowedSetters) {
  17781. return set$1(this.middleware_, this.tech_, method, arg);
  17782. } else if (method in allowedMediators) {
  17783. return mediate(this.middleware_, this.tech_, method, arg);
  17784. }
  17785. try {
  17786. if (this.tech_) {
  17787. this.tech_[method](arg);
  17788. }
  17789. } catch (e) {
  17790. log(e);
  17791. throw e;
  17792. }
  17793. }, true);
  17794. };
  17795. /**
  17796. * Get calls can't wait for the tech, and sometimes don't need to.
  17797. *
  17798. * @param {string} method
  17799. * Tech method
  17800. *
  17801. * @return {Function|undefined}
  17802. * the method or undefined
  17803. *
  17804. * @private
  17805. */
  17806. Player.prototype.techGet_ = function techGet_(method) {
  17807. if (!this.tech_ || !this.tech_.isReady_) {
  17808. return;
  17809. }
  17810. if (method in allowedGetters) {
  17811. return get$1(this.middleware_, this.tech_, method);
  17812. } else if (method in allowedMediators) {
  17813. return mediate(this.middleware_, this.tech_, method);
  17814. }
  17815. // Flash likes to die and reload when you hide or reposition it.
  17816. // In these cases the object methods go away and we get errors.
  17817. // When that happens we'll catch the errors and inform tech that it's not ready any more.
  17818. try {
  17819. return this.tech_[method]();
  17820. } catch (e) {
  17821. // When building additional tech libs, an expected method may not be defined yet
  17822. if (this.tech_[method] === undefined) {
  17823. log('Video.js: ' + method + ' method not defined for ' + this.techName_ + ' playback technology.', e);
  17824. throw e;
  17825. }
  17826. // When a method isn't available on the object it throws a TypeError
  17827. if (e.name === 'TypeError') {
  17828. log('Video.js: ' + method + ' unavailable on ' + this.techName_ + ' playback technology element.', e);
  17829. this.tech_.isReady_ = false;
  17830. throw e;
  17831. }
  17832. // If error unknown, just log and throw
  17833. log(e);
  17834. throw e;
  17835. }
  17836. };
  17837. /**
  17838. * Attempt to begin playback at the first opportunity.
  17839. *
  17840. * @return {Promise|undefined}
  17841. * Returns a promise if the browser supports Promises (or one
  17842. * was passed in as an option). This promise will be resolved on
  17843. * the return value of play. If this is undefined it will fulfill the
  17844. * promise chain otherwise the promise chain will be fulfilled when
  17845. * the promise from play is fulfilled.
  17846. */
  17847. Player.prototype.play = function play() {
  17848. var _this7 = this;
  17849. var PromiseClass = this.options_.Promise || window.Promise;
  17850. if (PromiseClass) {
  17851. return new PromiseClass(function (resolve) {
  17852. _this7.play_(resolve);
  17853. });
  17854. }
  17855. return this.play_();
  17856. };
  17857. /**
  17858. * The actual logic for play, takes a callback that will be resolved on the
  17859. * return value of play. This allows us to resolve to the play promise if there
  17860. * is one on modern browsers.
  17861. *
  17862. * @private
  17863. * @param {Function} [callback]
  17864. * The callback that should be called when the techs play is actually called
  17865. */
  17866. Player.prototype.play_ = function play_() {
  17867. var _this8 = this;
  17868. var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : silencePromise;
  17869. // If this is called while we have a play queued up on a loadstart, remove
  17870. // that listener to avoid getting in a potentially bad state.
  17871. if (this.playOnLoadstart_) {
  17872. this.off('loadstart', this.playOnLoadstart_);
  17873. }
  17874. // If the player/tech is not ready, queue up another call to `play()` for
  17875. // when it is. This will loop back into this method for another attempt at
  17876. // playback when the tech is ready.
  17877. if (!this.isReady_) {
  17878. // Bail out if we're already waiting for `ready`!
  17879. if (this.playWaitingForReady_) {
  17880. return;
  17881. }
  17882. this.playWaitingForReady_ = true;
  17883. this.ready(function () {
  17884. _this8.playWaitingForReady_ = false;
  17885. callback(_this8.play());
  17886. });
  17887. // If the player/tech is ready and we have a source, we can attempt playback.
  17888. } else if (!this.changingSrc_ && (this.src() || this.currentSrc())) {
  17889. callback(this.techGet_('play'));
  17890. return;
  17891. // If the tech is ready, but we do not have a source, we'll need to wait
  17892. // for both the `ready` and a `loadstart` when the source is finally
  17893. // resolved by middleware and set on the player.
  17894. //
  17895. // This can happen if `play()` is called while changing sources or before
  17896. // one has been set on the player.
  17897. } else {
  17898. this.playOnLoadstart_ = function () {
  17899. _this8.playOnLoadstart_ = null;
  17900. callback(_this8.play());
  17901. };
  17902. this.one('loadstart', this.playOnLoadstart_);
  17903. }
  17904. };
  17905. /**
  17906. * Pause the video playback
  17907. *
  17908. * @return {Player}
  17909. * A reference to the player object this function was called on
  17910. */
  17911. Player.prototype.pause = function pause() {
  17912. this.techCall_('pause');
  17913. };
  17914. /**
  17915. * Check if the player is paused or has yet to play
  17916. *
  17917. * @return {boolean}
  17918. * - false: if the media is currently playing
  17919. * - true: if media is not currently playing
  17920. */
  17921. Player.prototype.paused = function paused() {
  17922. // The initial state of paused should be true (in Safari it's actually false)
  17923. return this.techGet_('paused') === false ? false : true;
  17924. };
  17925. /**
  17926. * Get a TimeRange object representing the current ranges of time that the user
  17927. * has played.
  17928. *
  17929. * @return {TimeRange}
  17930. * A time range object that represents all the increments of time that have
  17931. * been played.
  17932. */
  17933. Player.prototype.played = function played() {
  17934. return this.techGet_('played') || createTimeRanges(0, 0);
  17935. };
  17936. /**
  17937. * Returns whether or not the user is "scrubbing". Scrubbing is
  17938. * when the user has clicked the progress bar handle and is
  17939. * dragging it along the progress bar.
  17940. *
  17941. * @param {boolean} [isScrubbing]
  17942. * wether the user is or is not scrubbing
  17943. *
  17944. * @return {boolean}
  17945. * The value of scrubbing when getting
  17946. */
  17947. Player.prototype.scrubbing = function scrubbing(isScrubbing) {
  17948. if (typeof isScrubbing === 'undefined') {
  17949. return this.scrubbing_;
  17950. }
  17951. this.scrubbing_ = !!isScrubbing;
  17952. if (isScrubbing) {
  17953. this.addClass('vjs-scrubbing');
  17954. } else {
  17955. this.removeClass('vjs-scrubbing');
  17956. }
  17957. };
  17958. /**
  17959. * Get or set the current time (in seconds)
  17960. *
  17961. * @param {number|string} [seconds]
  17962. * The time to seek to in seconds
  17963. *
  17964. * @return {number}
  17965. * - the current time in seconds when getting
  17966. */
  17967. Player.prototype.currentTime = function currentTime(seconds) {
  17968. if (typeof seconds !== 'undefined') {
  17969. if (seconds < 0) {
  17970. seconds = 0;
  17971. }
  17972. this.techCall_('setCurrentTime', seconds);
  17973. return;
  17974. }
  17975. // cache last currentTime and return. default to 0 seconds
  17976. //
  17977. // Caching the currentTime is meant to prevent a massive amount of reads on the tech's
  17978. // currentTime when scrubbing, but may not provide much performance benefit afterall.
  17979. // Should be tested. Also something has to read the actual current time or the cache will
  17980. // never get updated.
  17981. this.cache_.currentTime = this.techGet_('currentTime') || 0;
  17982. return this.cache_.currentTime;
  17983. };
  17984. /**
  17985. * Normally gets the length in time of the video in seconds;
  17986. * in all but the rarest use cases an argument will NOT be passed to the method
  17987. *
  17988. * > **NOTE**: The video must have started loading before the duration can be
  17989. * known, and in the case of Flash, may not be known until the video starts
  17990. * playing.
  17991. *
  17992. * @fires Player#durationchange
  17993. *
  17994. * @param {number} [seconds]
  17995. * The duration of the video to set in seconds
  17996. *
  17997. * @return {number}
  17998. * - The duration of the video in seconds when getting
  17999. */
  18000. Player.prototype.duration = function duration(seconds) {
  18001. if (seconds === undefined) {
  18002. // return NaN if the duration is not known
  18003. return this.cache_.duration !== undefined ? this.cache_.duration : NaN;
  18004. }
  18005. seconds = parseFloat(seconds);
  18006. // Standardize on Inifity for signaling video is live
  18007. if (seconds < 0) {
  18008. seconds = Infinity;
  18009. }
  18010. if (seconds !== this.cache_.duration) {
  18011. // Cache the last set value for optimized scrubbing (esp. Flash)
  18012. this.cache_.duration = seconds;
  18013. if (seconds === Infinity) {
  18014. this.addClass('vjs-live');
  18015. } else {
  18016. this.removeClass('vjs-live');
  18017. }
  18018. /**
  18019. * @event Player#durationchange
  18020. * @type {EventTarget~Event}
  18021. */
  18022. this.trigger('durationchange');
  18023. }
  18024. };
  18025. /**
  18026. * Calculates how much time is left in the video. Not part
  18027. * of the native video API.
  18028. *
  18029. * @return {number}
  18030. * The time remaining in seconds
  18031. */
  18032. Player.prototype.remainingTime = function remainingTime() {
  18033. return this.duration() - this.currentTime();
  18034. };
  18035. /**
  18036. * A remaining time function that is intented to be used when
  18037. * the time is to be displayed directly to the user.
  18038. *
  18039. * @return {number}
  18040. * The rounded time remaining in seconds
  18041. */
  18042. Player.prototype.remainingTimeDisplay = function remainingTimeDisplay() {
  18043. return Math.floor(this.duration()) - Math.floor(this.currentTime());
  18044. };
  18045. //
  18046. // Kind of like an array of portions of the video that have been downloaded.
  18047. /**
  18048. * Get a TimeRange object with an array of the times of the video
  18049. * that have been downloaded. If you just want the percent of the
  18050. * video that's been downloaded, use bufferedPercent.
  18051. *
  18052. * @see [Buffered Spec]{@link http://dev.w3.org/html5/spec/video.html#dom-media-buffered}
  18053. *
  18054. * @return {TimeRange}
  18055. * A mock TimeRange object (following HTML spec)
  18056. */
  18057. Player.prototype.buffered = function buffered() {
  18058. var buffered = this.techGet_('buffered');
  18059. if (!buffered || !buffered.length) {
  18060. buffered = createTimeRanges(0, 0);
  18061. }
  18062. return buffered;
  18063. };
  18064. /**
  18065. * Get the percent (as a decimal) of the video that's been downloaded.
  18066. * This method is not a part of the native HTML video API.
  18067. *
  18068. * @return {number}
  18069. * A decimal between 0 and 1 representing the percent
  18070. * that is bufferred 0 being 0% and 1 being 100%
  18071. */
  18072. Player.prototype.bufferedPercent = function bufferedPercent$$1() {
  18073. return bufferedPercent(this.buffered(), this.duration());
  18074. };
  18075. /**
  18076. * Get the ending time of the last buffered time range
  18077. * This is used in the progress bar to encapsulate all time ranges.
  18078. *
  18079. * @return {number}
  18080. * The end of the last buffered time range
  18081. */
  18082. Player.prototype.bufferedEnd = function bufferedEnd() {
  18083. var buffered = this.buffered();
  18084. var duration = this.duration();
  18085. var end = buffered.end(buffered.length - 1);
  18086. if (end > duration) {
  18087. end = duration;
  18088. }
  18089. return end;
  18090. };
  18091. /**
  18092. * Get or set the current volume of the media
  18093. *
  18094. * @param {number} [percentAsDecimal]
  18095. * The new volume as a decimal percent:
  18096. * - 0 is muted/0%/off
  18097. * - 1.0 is 100%/full
  18098. * - 0.5 is half volume or 50%
  18099. *
  18100. * @return {number}
  18101. * The current volume as a percent when getting
  18102. */
  18103. Player.prototype.volume = function volume(percentAsDecimal) {
  18104. var vol = void 0;
  18105. if (percentAsDecimal !== undefined) {
  18106. // Force value to between 0 and 1
  18107. vol = Math.max(0, Math.min(1, parseFloat(percentAsDecimal)));
  18108. this.cache_.volume = vol;
  18109. this.techCall_('setVolume', vol);
  18110. if (vol > 0) {
  18111. this.lastVolume_(vol);
  18112. }
  18113. return;
  18114. }
  18115. // Default to 1 when returning current volume.
  18116. vol = parseFloat(this.techGet_('volume'));
  18117. return isNaN(vol) ? 1 : vol;
  18118. };
  18119. /**
  18120. * Get the current muted state, or turn mute on or off
  18121. *
  18122. * @param {boolean} [muted]
  18123. * - true to mute
  18124. * - false to unmute
  18125. *
  18126. * @return {boolean}
  18127. * - true if mute is on and getting
  18128. * - false if mute is off and getting
  18129. */
  18130. Player.prototype.muted = function muted(_muted) {
  18131. if (_muted !== undefined) {
  18132. this.techCall_('setMuted', _muted);
  18133. return;
  18134. }
  18135. return this.techGet_('muted') || false;
  18136. };
  18137. /**
  18138. * Get the current defaultMuted state, or turn defaultMuted on or off. defaultMuted
  18139. * indicates the state of muted on intial playback.
  18140. *
  18141. * ```js
  18142. * var myPlayer = videojs('some-player-id');
  18143. *
  18144. * myPlayer.src("http://www.example.com/path/to/video.mp4");
  18145. *
  18146. * // get, should be false
  18147. * console.log(myPlayer.defaultMuted());
  18148. * // set to true
  18149. * myPlayer.defaultMuted(true);
  18150. * // get should be true
  18151. * console.log(myPlayer.defaultMuted());
  18152. * ```
  18153. *
  18154. * @param {boolean} [defaultMuted]
  18155. * - true to mute
  18156. * - false to unmute
  18157. *
  18158. * @return {boolean|Player}
  18159. * - true if defaultMuted is on and getting
  18160. * - false if defaultMuted is off and getting
  18161. * - A reference to the current player when setting
  18162. */
  18163. Player.prototype.defaultMuted = function defaultMuted(_defaultMuted) {
  18164. if (_defaultMuted !== undefined) {
  18165. return this.techCall_('setDefaultMuted', _defaultMuted);
  18166. }
  18167. return this.techGet_('defaultMuted') || false;
  18168. };
  18169. /**
  18170. * Get the last volume, or set it
  18171. *
  18172. * @param {number} [percentAsDecimal]
  18173. * The new last volume as a decimal percent:
  18174. * - 0 is muted/0%/off
  18175. * - 1.0 is 100%/full
  18176. * - 0.5 is half volume or 50%
  18177. *
  18178. * @return {number}
  18179. * the current value of lastVolume as a percent when getting
  18180. *
  18181. * @private
  18182. */
  18183. Player.prototype.lastVolume_ = function lastVolume_(percentAsDecimal) {
  18184. if (percentAsDecimal !== undefined && percentAsDecimal !== 0) {
  18185. this.cache_.lastVolume = percentAsDecimal;
  18186. return;
  18187. }
  18188. return this.cache_.lastVolume;
  18189. };
  18190. /**
  18191. * Check if current tech can support native fullscreen
  18192. * (e.g. with built in controls like iOS, so not our flash swf)
  18193. *
  18194. * @return {boolean}
  18195. * if native fullscreen is supported
  18196. */
  18197. Player.prototype.supportsFullScreen = function supportsFullScreen() {
  18198. return this.techGet_('supportsFullScreen') || false;
  18199. };
  18200. /**
  18201. * Check if the player is in fullscreen mode or tell the player that it
  18202. * is or is not in fullscreen mode.
  18203. *
  18204. * > NOTE: As of the latest HTML5 spec, isFullscreen is no longer an official
  18205. * property and instead document.fullscreenElement is used. But isFullscreen is
  18206. * still a valuable property for internal player workings.
  18207. *
  18208. * @param {boolean} [isFS]
  18209. * Set the players current fullscreen state
  18210. *
  18211. * @return {boolean}
  18212. * - true if fullscreen is on and getting
  18213. * - false if fullscreen is off and getting
  18214. */
  18215. Player.prototype.isFullscreen = function isFullscreen(isFS) {
  18216. if (isFS !== undefined) {
  18217. this.isFullscreen_ = !!isFS;
  18218. return;
  18219. }
  18220. return !!this.isFullscreen_;
  18221. };
  18222. /**
  18223. * Increase the size of the video to full screen
  18224. * In some browsers, full screen is not supported natively, so it enters
  18225. * "full window mode", where the video fills the browser window.
  18226. * In browsers and devices that support native full screen, sometimes the
  18227. * browser's default controls will be shown, and not the Video.js custom skin.
  18228. * This includes most mobile devices (iOS, Android) and older versions of
  18229. * Safari.
  18230. *
  18231. * @fires Player#fullscreenchange
  18232. */
  18233. Player.prototype.requestFullscreen = function requestFullscreen() {
  18234. var fsApi = FullscreenApi;
  18235. this.isFullscreen(true);
  18236. if (fsApi.requestFullscreen) {
  18237. // the browser supports going fullscreen at the element level so we can
  18238. // take the controls fullscreen as well as the video
  18239. // Trigger fullscreenchange event after change
  18240. // We have to specifically add this each time, and remove
  18241. // when canceling fullscreen. Otherwise if there's multiple
  18242. // players on a page, they would all be reacting to the same fullscreen
  18243. // events
  18244. on(document, fsApi.fullscreenchange, bind(this, function documentFullscreenChange(e) {
  18245. this.isFullscreen(document[fsApi.fullscreenElement]);
  18246. // If cancelling fullscreen, remove event listener.
  18247. if (this.isFullscreen() === false) {
  18248. off(document, fsApi.fullscreenchange, documentFullscreenChange);
  18249. }
  18250. /**
  18251. * @event Player#fullscreenchange
  18252. * @type {EventTarget~Event}
  18253. */
  18254. this.trigger('fullscreenchange');
  18255. }));
  18256. this.el_[fsApi.requestFullscreen]();
  18257. } else if (this.tech_.supportsFullScreen()) {
  18258. // we can't take the video.js controls fullscreen but we can go fullscreen
  18259. // with native controls
  18260. this.techCall_('enterFullScreen');
  18261. } else {
  18262. // fullscreen isn't supported so we'll just stretch the video element to
  18263. // fill the viewport
  18264. this.enterFullWindow();
  18265. /**
  18266. * @event Player#fullscreenchange
  18267. * @type {EventTarget~Event}
  18268. */
  18269. this.trigger('fullscreenchange');
  18270. }
  18271. };
  18272. /**
  18273. * Return the video to its normal size after having been in full screen mode
  18274. *
  18275. * @fires Player#fullscreenchange
  18276. */
  18277. Player.prototype.exitFullscreen = function exitFullscreen() {
  18278. var fsApi = FullscreenApi;
  18279. this.isFullscreen(false);
  18280. // Check for browser element fullscreen support
  18281. if (fsApi.requestFullscreen) {
  18282. document[fsApi.exitFullscreen]();
  18283. } else if (this.tech_.supportsFullScreen()) {
  18284. this.techCall_('exitFullScreen');
  18285. } else {
  18286. this.exitFullWindow();
  18287. /**
  18288. * @event Player#fullscreenchange
  18289. * @type {EventTarget~Event}
  18290. */
  18291. this.trigger('fullscreenchange');
  18292. }
  18293. };
  18294. /**
  18295. * When fullscreen isn't supported we can stretch the
  18296. * video container to as wide as the browser will let us.
  18297. *
  18298. * @fires Player#enterFullWindow
  18299. */
  18300. Player.prototype.enterFullWindow = function enterFullWindow() {
  18301. this.isFullWindow = true;
  18302. // Storing original doc overflow value to return to when fullscreen is off
  18303. this.docOrigOverflow = document.documentElement.style.overflow;
  18304. // Add listener for esc key to exit fullscreen
  18305. on(document, 'keydown', bind(this, this.fullWindowOnEscKey));
  18306. // Hide any scroll bars
  18307. document.documentElement.style.overflow = 'hidden';
  18308. // Apply fullscreen styles
  18309. addClass(document.body, 'vjs-full-window');
  18310. /**
  18311. * @event Player#enterFullWindow
  18312. * @type {EventTarget~Event}
  18313. */
  18314. this.trigger('enterFullWindow');
  18315. };
  18316. /**
  18317. * Check for call to either exit full window or
  18318. * full screen on ESC key
  18319. *
  18320. * @param {string} event
  18321. * Event to check for key press
  18322. */
  18323. Player.prototype.fullWindowOnEscKey = function fullWindowOnEscKey(event) {
  18324. if (event.keyCode === 27) {
  18325. if (this.isFullscreen() === true) {
  18326. this.exitFullscreen();
  18327. } else {
  18328. this.exitFullWindow();
  18329. }
  18330. }
  18331. };
  18332. /**
  18333. * Exit full window
  18334. *
  18335. * @fires Player#exitFullWindow
  18336. */
  18337. Player.prototype.exitFullWindow = function exitFullWindow() {
  18338. this.isFullWindow = false;
  18339. off(document, 'keydown', this.fullWindowOnEscKey);
  18340. // Unhide scroll bars.
  18341. document.documentElement.style.overflow = this.docOrigOverflow;
  18342. // Remove fullscreen styles
  18343. removeClass(document.body, 'vjs-full-window');
  18344. // Resize the box, controller, and poster to original sizes
  18345. // this.positionAll();
  18346. /**
  18347. * @event Player#exitFullWindow
  18348. * @type {EventTarget~Event}
  18349. */
  18350. this.trigger('exitFullWindow');
  18351. };
  18352. /**
  18353. * Check whether the player can play a given mimetype
  18354. *
  18355. * @see https://www.w3.org/TR/2011/WD-html5-20110113/video.html#dom-navigator-canplaytype
  18356. *
  18357. * @param {string} type
  18358. * The mimetype to check
  18359. *
  18360. * @return {string}
  18361. * 'probably', 'maybe', or '' (empty string)
  18362. */
  18363. Player.prototype.canPlayType = function canPlayType(type) {
  18364. var can = void 0;
  18365. // Loop through each playback technology in the options order
  18366. for (var i = 0, j = this.options_.techOrder; i < j.length; i++) {
  18367. var techName = j[i];
  18368. var tech = Tech.getTech(techName);
  18369. // Support old behavior of techs being registered as components.
  18370. // Remove once that deprecated behavior is removed.
  18371. if (!tech) {
  18372. tech = Component.getComponent(techName);
  18373. }
  18374. // Check if the current tech is defined before continuing
  18375. if (!tech) {
  18376. log.error('The "' + techName + '" tech is undefined. Skipped browser support check for that tech.');
  18377. continue;
  18378. }
  18379. // Check if the browser supports this technology
  18380. if (tech.isSupported()) {
  18381. can = tech.canPlayType(type);
  18382. if (can) {
  18383. return can;
  18384. }
  18385. }
  18386. }
  18387. return '';
  18388. };
  18389. /**
  18390. * Select source based on tech-order or source-order
  18391. * Uses source-order selection if `options.sourceOrder` is truthy. Otherwise,
  18392. * defaults to tech-order selection
  18393. *
  18394. * @param {Array} sources
  18395. * The sources for a media asset
  18396. *
  18397. * @return {Object|boolean}
  18398. * Object of source and tech order or false
  18399. */
  18400. Player.prototype.selectSource = function selectSource(sources) {
  18401. var _this9 = this;
  18402. // Get only the techs specified in `techOrder` that exist and are supported by the
  18403. // current platform
  18404. var techs = this.options_.techOrder.map(function (techName) {
  18405. return [techName, Tech.getTech(techName)];
  18406. }).filter(function (_ref) {
  18407. var techName = _ref[0],
  18408. tech = _ref[1];
  18409. // Check if the current tech is defined before continuing
  18410. if (tech) {
  18411. // Check if the browser supports this technology
  18412. return tech.isSupported();
  18413. }
  18414. log.error('The "' + techName + '" tech is undefined. Skipped browser support check for that tech.');
  18415. return false;
  18416. });
  18417. // Iterate over each `innerArray` element once per `outerArray` element and execute
  18418. // `tester` with both. If `tester` returns a non-falsy value, exit early and return
  18419. // that value.
  18420. var findFirstPassingTechSourcePair = function findFirstPassingTechSourcePair(outerArray, innerArray, tester) {
  18421. var found = void 0;
  18422. outerArray.some(function (outerChoice) {
  18423. return innerArray.some(function (innerChoice) {
  18424. found = tester(outerChoice, innerChoice);
  18425. if (found) {
  18426. return true;
  18427. }
  18428. });
  18429. });
  18430. return found;
  18431. };
  18432. var foundSourceAndTech = void 0;
  18433. var flip = function flip(fn) {
  18434. return function (a, b) {
  18435. return fn(b, a);
  18436. };
  18437. };
  18438. var finder = function finder(_ref2, source) {
  18439. var techName = _ref2[0],
  18440. tech = _ref2[1];
  18441. if (tech.canPlaySource(source, _this9.options_[techName.toLowerCase()])) {
  18442. return { source: source, tech: techName };
  18443. }
  18444. };
  18445. // Depending on the truthiness of `options.sourceOrder`, we swap the order of techs and sources
  18446. // to select from them based on their priority.
  18447. if (this.options_.sourceOrder) {
  18448. // Source-first ordering
  18449. foundSourceAndTech = findFirstPassingTechSourcePair(sources, techs, flip(finder));
  18450. } else {
  18451. // Tech-first ordering
  18452. foundSourceAndTech = findFirstPassingTechSourcePair(techs, sources, finder);
  18453. }
  18454. return foundSourceAndTech || false;
  18455. };
  18456. /**
  18457. * Get or set the video source.
  18458. *
  18459. * @param {Tech~SourceObject|Tech~SourceObject[]|string} [source]
  18460. * A SourceObject, an array of SourceObjects, or a string referencing
  18461. * a URL to a media source. It is _highly recommended_ that an object
  18462. * or array of objects is used here, so that source selection
  18463. * algorithms can take the `type` into account.
  18464. *
  18465. * If not provided, this method acts as a getter.
  18466. *
  18467. * @return {string|undefined}
  18468. * If the `source` argument is missing, returns the current source
  18469. * URL. Otherwise, returns nothing/undefined.
  18470. */
  18471. Player.prototype.src = function src(source) {
  18472. var _this10 = this;
  18473. // getter usage
  18474. if (typeof source === 'undefined') {
  18475. return this.cache_.src || '';
  18476. }
  18477. // filter out invalid sources and turn our source into
  18478. // an array of source objects
  18479. var sources = filterSource(source);
  18480. // if a source was passed in then it is invalid because
  18481. // it was filtered to a zero length Array. So we have to
  18482. // show an error
  18483. if (!sources.length) {
  18484. this.setTimeout(function () {
  18485. this.error({ code: 4, message: this.localize(this.options_.notSupportedMessage) });
  18486. }, 0);
  18487. return;
  18488. }
  18489. // intial sources
  18490. this.changingSrc_ = true;
  18491. this.cache_.sources = sources;
  18492. this.updateSourceCaches_(sources[0]);
  18493. // middlewareSource is the source after it has been changed by middleware
  18494. setSource(this, sources[0], function (middlewareSource, mws) {
  18495. _this10.middleware_ = mws;
  18496. // since sourceSet is async we have to update the cache again after we select a source since
  18497. // the source that is selected could be out of order from the cache update above this callback.
  18498. _this10.cache_.sources = sources;
  18499. _this10.updateSourceCaches_(middlewareSource);
  18500. var err = _this10.src_(middlewareSource);
  18501. if (err) {
  18502. if (sources.length > 1) {
  18503. return _this10.src(sources.slice(1));
  18504. }
  18505. _this10.changingSrc_ = false;
  18506. // We need to wrap this in a timeout to give folks a chance to add error event handlers
  18507. _this10.setTimeout(function () {
  18508. this.error({ code: 4, message: this.localize(this.options_.notSupportedMessage) });
  18509. }, 0);
  18510. // we could not find an appropriate tech, but let's still notify the delegate that this is it
  18511. // this needs a better comment about why this is needed
  18512. _this10.triggerReady();
  18513. return;
  18514. }
  18515. setTech(mws, _this10.tech_);
  18516. });
  18517. };
  18518. /**
  18519. * Set the source object on the tech, returns a boolean that indicates wether
  18520. * there is a tech that can play the source or not
  18521. *
  18522. * @param {Tech~SourceObject} source
  18523. * The source object to set on the Tech
  18524. *
  18525. * @return {Boolean}
  18526. * - True if there is no Tech to playback this source
  18527. * - False otherwise
  18528. *
  18529. * @private
  18530. */
  18531. Player.prototype.src_ = function src_(source) {
  18532. var _this11 = this;
  18533. var sourceTech = this.selectSource([source]);
  18534. if (!sourceTech) {
  18535. return true;
  18536. }
  18537. if (!titleCaseEquals(sourceTech.tech, this.techName_)) {
  18538. this.changingSrc_ = true;
  18539. // load this technology with the chosen source
  18540. this.loadTech_(sourceTech.tech, sourceTech.source);
  18541. this.tech_.ready(function () {
  18542. _this11.changingSrc_ = false;
  18543. });
  18544. return false;
  18545. }
  18546. // wait until the tech is ready to set the source
  18547. // and set it synchronously if possible (#2326)
  18548. this.ready(function () {
  18549. // The setSource tech method was added with source handlers
  18550. // so older techs won't support it
  18551. // We need to check the direct prototype for the case where subclasses
  18552. // of the tech do not support source handlers
  18553. if (this.tech_.constructor.prototype.hasOwnProperty('setSource')) {
  18554. this.techCall_('setSource', source);
  18555. } else {
  18556. this.techCall_('src', source.src);
  18557. }
  18558. this.changingSrc_ = false;
  18559. }, true);
  18560. return false;
  18561. };
  18562. /**
  18563. * Begin loading the src data.
  18564. */
  18565. Player.prototype.load = function load() {
  18566. this.techCall_('load');
  18567. };
  18568. /**
  18569. * Reset the player. Loads the first tech in the techOrder,
  18570. * removes all the text tracks in the existing `tech`,
  18571. * and calls `reset` on the `tech`.
  18572. */
  18573. Player.prototype.reset = function reset() {
  18574. if (this.tech_) {
  18575. this.tech_.clearTracks('text');
  18576. }
  18577. this.loadTech_(this.options_.techOrder[0], null);
  18578. this.techCall_('reset');
  18579. };
  18580. /**
  18581. * Returns all of the current source objects.
  18582. *
  18583. * @return {Tech~SourceObject[]}
  18584. * The current source objects
  18585. */
  18586. Player.prototype.currentSources = function currentSources() {
  18587. var source = this.currentSource();
  18588. var sources = [];
  18589. // assume `{}` or `{ src }`
  18590. if (Object.keys(source).length !== 0) {
  18591. sources.push(source);
  18592. }
  18593. return this.cache_.sources || sources;
  18594. };
  18595. /**
  18596. * Returns the current source object.
  18597. *
  18598. * @return {Tech~SourceObject}
  18599. * The current source object
  18600. */
  18601. Player.prototype.currentSource = function currentSource() {
  18602. return this.cache_.source || {};
  18603. };
  18604. /**
  18605. * Returns the fully qualified URL of the current source value e.g. http://mysite.com/video.mp4
  18606. * Can be used in conjuction with `currentType` to assist in rebuilding the current source object.
  18607. *
  18608. * @return {string}
  18609. * The current source
  18610. */
  18611. Player.prototype.currentSrc = function currentSrc() {
  18612. return this.currentSource() && this.currentSource().src || '';
  18613. };
  18614. /**
  18615. * Get the current source type e.g. video/mp4
  18616. * This can allow you rebuild the current source object so that you could load the same
  18617. * source and tech later
  18618. *
  18619. * @return {string}
  18620. * The source MIME type
  18621. */
  18622. Player.prototype.currentType = function currentType() {
  18623. return this.currentSource() && this.currentSource().type || '';
  18624. };
  18625. /**
  18626. * Get or set the preload attribute
  18627. *
  18628. * @param {boolean} [value]
  18629. * - true means that we should preload
  18630. * - false maens that we should not preload
  18631. *
  18632. * @return {string}
  18633. * The preload attribute value when getting
  18634. */
  18635. Player.prototype.preload = function preload(value) {
  18636. if (value !== undefined) {
  18637. this.techCall_('setPreload', value);
  18638. this.options_.preload = value;
  18639. return;
  18640. }
  18641. return this.techGet_('preload');
  18642. };
  18643. /**
  18644. * Get or set the autoplay option. When this is a boolean it will
  18645. * modify the attribute on the tech. When this is a string the attribute on
  18646. * the tech will be removed and `Player` will handle autoplay on loadstarts.
  18647. *
  18648. * @param {boolean|string} [value]
  18649. * - true: autoplay using the browser behavior
  18650. * - false: do not autoplay
  18651. * - 'play': call play() on every loadstart
  18652. * - 'muted': call muted() then play() on every loadstart
  18653. * - 'any': call play() on every loadstart. if that fails call muted() then play().
  18654. * - *: values other than those listed here will be set `autoplay` to true
  18655. *
  18656. * @return {boolean|string}
  18657. * The current value of autoplay when getting
  18658. */
  18659. Player.prototype.autoplay = function autoplay(value) {
  18660. // getter usage
  18661. if (value === undefined) {
  18662. return this.options_.autoplay || false;
  18663. }
  18664. var techAutoplay = void 0;
  18665. // if the value is a valid string set it to that
  18666. if (typeof value === 'string' && /(any|play|muted)/.test(value)) {
  18667. this.options_.autoplay = value;
  18668. this.manualAutoplay_(value);
  18669. techAutoplay = false;
  18670. // any falsy value sets autoplay to false in the browser,
  18671. // lets do the same
  18672. } else if (!value) {
  18673. this.options_.autoplay = false;
  18674. // any other value (ie truthy) sets autoplay to true
  18675. } else {
  18676. this.options_.autoplay = true;
  18677. }
  18678. techAutoplay = techAutoplay || this.options_.autoplay;
  18679. // if we don't have a tech then we do not queue up
  18680. // a setAutoplay call on tech ready. We do this because the
  18681. // autoplay option will be passed in the constructor and we
  18682. // do not need to set it twice
  18683. if (this.tech_) {
  18684. this.techCall_('setAutoplay', techAutoplay);
  18685. }
  18686. };
  18687. /**
  18688. * Set or unset the playsinline attribute.
  18689. * Playsinline tells the browser that non-fullscreen playback is preferred.
  18690. *
  18691. * @param {boolean} [value]
  18692. * - true means that we should try to play inline by default
  18693. * - false means that we should use the browser's default playback mode,
  18694. * which in most cases is inline. iOS Safari is a notable exception
  18695. * and plays fullscreen by default.
  18696. *
  18697. * @return {string|Player}
  18698. * - the current value of playsinline
  18699. * - the player when setting
  18700. *
  18701. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-video-playsinline}
  18702. */
  18703. Player.prototype.playsinline = function playsinline(value) {
  18704. if (value !== undefined) {
  18705. this.techCall_('setPlaysinline', value);
  18706. this.options_.playsinline = value;
  18707. return this;
  18708. }
  18709. return this.techGet_('playsinline');
  18710. };
  18711. /**
  18712. * Get or set the loop attribute on the video element.
  18713. *
  18714. * @param {boolean} [value]
  18715. * - true means that we should loop the video
  18716. * - false means that we should not loop the video
  18717. *
  18718. * @return {string}
  18719. * The current value of loop when getting
  18720. */
  18721. Player.prototype.loop = function loop(value) {
  18722. if (value !== undefined) {
  18723. this.techCall_('setLoop', value);
  18724. this.options_.loop = value;
  18725. return;
  18726. }
  18727. return this.techGet_('loop');
  18728. };
  18729. /**
  18730. * Get or set the poster image source url
  18731. *
  18732. * @fires Player#posterchange
  18733. *
  18734. * @param {string} [src]
  18735. * Poster image source URL
  18736. *
  18737. * @return {string}
  18738. * The current value of poster when getting
  18739. */
  18740. Player.prototype.poster = function poster(src) {
  18741. if (src === undefined) {
  18742. return this.poster_;
  18743. }
  18744. // The correct way to remove a poster is to set as an empty string
  18745. // other falsey values will throw errors
  18746. if (!src) {
  18747. src = '';
  18748. }
  18749. if (src === this.poster_) {
  18750. return;
  18751. }
  18752. // update the internal poster variable
  18753. this.poster_ = src;
  18754. // update the tech's poster
  18755. this.techCall_('setPoster', src);
  18756. this.isPosterFromTech_ = false;
  18757. // alert components that the poster has been set
  18758. /**
  18759. * This event fires when the poster image is changed on the player.
  18760. *
  18761. * @event Player#posterchange
  18762. * @type {EventTarget~Event}
  18763. */
  18764. this.trigger('posterchange');
  18765. };
  18766. /**
  18767. * Some techs (e.g. YouTube) can provide a poster source in an
  18768. * asynchronous way. We want the poster component to use this
  18769. * poster source so that it covers up the tech's controls.
  18770. * (YouTube's play button). However we only want to use this
  18771. * source if the player user hasn't set a poster through
  18772. * the normal APIs.
  18773. *
  18774. * @fires Player#posterchange
  18775. * @listens Tech#posterchange
  18776. * @private
  18777. */
  18778. Player.prototype.handleTechPosterChange_ = function handleTechPosterChange_() {
  18779. if ((!this.poster_ || this.options_.techCanOverridePoster) && this.tech_ && this.tech_.poster) {
  18780. var newPoster = this.tech_.poster() || '';
  18781. if (newPoster !== this.poster_) {
  18782. this.poster_ = newPoster;
  18783. this.isPosterFromTech_ = true;
  18784. // Let components know the poster has changed
  18785. this.trigger('posterchange');
  18786. }
  18787. }
  18788. };
  18789. /**
  18790. * Get or set whether or not the controls are showing.
  18791. *
  18792. * @fires Player#controlsenabled
  18793. *
  18794. * @param {boolean} [bool]
  18795. * - true to turn controls on
  18796. * - false to turn controls off
  18797. *
  18798. * @return {boolean}
  18799. * The current value of controls when getting
  18800. */
  18801. Player.prototype.controls = function controls(bool) {
  18802. if (bool === undefined) {
  18803. return !!this.controls_;
  18804. }
  18805. bool = !!bool;
  18806. // Don't trigger a change event unless it actually changed
  18807. if (this.controls_ === bool) {
  18808. return;
  18809. }
  18810. this.controls_ = bool;
  18811. if (this.usingNativeControls()) {
  18812. this.techCall_('setControls', bool);
  18813. }
  18814. if (this.controls_) {
  18815. this.removeClass('vjs-controls-disabled');
  18816. this.addClass('vjs-controls-enabled');
  18817. /**
  18818. * @event Player#controlsenabled
  18819. * @type {EventTarget~Event}
  18820. */
  18821. this.trigger('controlsenabled');
  18822. if (!this.usingNativeControls()) {
  18823. this.addTechControlsListeners_();
  18824. }
  18825. } else {
  18826. this.removeClass('vjs-controls-enabled');
  18827. this.addClass('vjs-controls-disabled');
  18828. /**
  18829. * @event Player#controlsdisabled
  18830. * @type {EventTarget~Event}
  18831. */
  18832. this.trigger('controlsdisabled');
  18833. if (!this.usingNativeControls()) {
  18834. this.removeTechControlsListeners_();
  18835. }
  18836. }
  18837. };
  18838. /**
  18839. * Toggle native controls on/off. Native controls are the controls built into
  18840. * devices (e.g. default iPhone controls), Flash, or other techs
  18841. * (e.g. Vimeo Controls)
  18842. * **This should only be set by the current tech, because only the tech knows
  18843. * if it can support native controls**
  18844. *
  18845. * @fires Player#usingnativecontrols
  18846. * @fires Player#usingcustomcontrols
  18847. *
  18848. * @param {boolean} [bool]
  18849. * - true to turn native controls on
  18850. * - false to turn native controls off
  18851. *
  18852. * @return {boolean}
  18853. * The current value of native controls when getting
  18854. */
  18855. Player.prototype.usingNativeControls = function usingNativeControls(bool) {
  18856. if (bool === undefined) {
  18857. return !!this.usingNativeControls_;
  18858. }
  18859. bool = !!bool;
  18860. // Don't trigger a change event unless it actually changed
  18861. if (this.usingNativeControls_ === bool) {
  18862. return;
  18863. }
  18864. this.usingNativeControls_ = bool;
  18865. if (this.usingNativeControls_) {
  18866. this.addClass('vjs-using-native-controls');
  18867. /**
  18868. * player is using the native device controls
  18869. *
  18870. * @event Player#usingnativecontrols
  18871. * @type {EventTarget~Event}
  18872. */
  18873. this.trigger('usingnativecontrols');
  18874. } else {
  18875. this.removeClass('vjs-using-native-controls');
  18876. /**
  18877. * player is using the custom HTML controls
  18878. *
  18879. * @event Player#usingcustomcontrols
  18880. * @type {EventTarget~Event}
  18881. */
  18882. this.trigger('usingcustomcontrols');
  18883. }
  18884. };
  18885. /**
  18886. * Set or get the current MediaError
  18887. *
  18888. * @fires Player#error
  18889. *
  18890. * @param {MediaError|string|number} [err]
  18891. * A MediaError or a string/number to be turned
  18892. * into a MediaError
  18893. *
  18894. * @return {MediaError|null}
  18895. * The current MediaError when getting (or null)
  18896. */
  18897. Player.prototype.error = function error(err) {
  18898. if (err === undefined) {
  18899. return this.error_ || null;
  18900. }
  18901. // restoring to default
  18902. if (err === null) {
  18903. this.error_ = err;
  18904. this.removeClass('vjs-error');
  18905. if (this.errorDisplay) {
  18906. this.errorDisplay.close();
  18907. }
  18908. return;
  18909. }
  18910. this.error_ = new MediaError(err);
  18911. // add the vjs-error classname to the player
  18912. this.addClass('vjs-error');
  18913. // log the name of the error type and any message
  18914. // ie8 just logs "[object object]" if you just log the error object
  18915. log.error('(CODE:' + this.error_.code + ' ' + MediaError.errorTypes[this.error_.code] + ')', this.error_.message, this.error_);
  18916. /**
  18917. * @event Player#error
  18918. * @type {EventTarget~Event}
  18919. */
  18920. this.trigger('error');
  18921. return;
  18922. };
  18923. /**
  18924. * Report user activity
  18925. *
  18926. * @param {Object} event
  18927. * Event object
  18928. */
  18929. Player.prototype.reportUserActivity = function reportUserActivity(event) {
  18930. this.userActivity_ = true;
  18931. };
  18932. /**
  18933. * Get/set if user is active
  18934. *
  18935. * @fires Player#useractive
  18936. * @fires Player#userinactive
  18937. *
  18938. * @param {boolean} [bool]
  18939. * - true if the user is active
  18940. * - false if the user is inactive
  18941. *
  18942. * @return {boolean}
  18943. * The current value of userActive when getting
  18944. */
  18945. Player.prototype.userActive = function userActive(bool) {
  18946. if (bool === undefined) {
  18947. return this.userActive_;
  18948. }
  18949. bool = !!bool;
  18950. if (bool === this.userActive_) {
  18951. return;
  18952. }
  18953. this.userActive_ = bool;
  18954. if (this.userActive_) {
  18955. this.userActivity_ = true;
  18956. this.removeClass('vjs-user-inactive');
  18957. this.addClass('vjs-user-active');
  18958. /**
  18959. * @event Player#useractive
  18960. * @type {EventTarget~Event}
  18961. */
  18962. this.trigger('useractive');
  18963. return;
  18964. }
  18965. // Chrome/Safari/IE have bugs where when you change the cursor it can
  18966. // trigger a mousemove event. This causes an issue when you're hiding
  18967. // the cursor when the user is inactive, and a mousemove signals user
  18968. // activity. Making it impossible to go into inactive mode. Specifically
  18969. // this happens in fullscreen when we really need to hide the cursor.
  18970. //
  18971. // When this gets resolved in ALL browsers it can be removed
  18972. // https://code.google.com/p/chromium/issues/detail?id=103041
  18973. if (this.tech_) {
  18974. this.tech_.one('mousemove', function (e) {
  18975. e.stopPropagation();
  18976. e.preventDefault();
  18977. });
  18978. }
  18979. this.userActivity_ = false;
  18980. this.removeClass('vjs-user-active');
  18981. this.addClass('vjs-user-inactive');
  18982. /**
  18983. * @event Player#userinactive
  18984. * @type {EventTarget~Event}
  18985. */
  18986. this.trigger('userinactive');
  18987. };
  18988. /**
  18989. * Listen for user activity based on timeout value
  18990. *
  18991. * @private
  18992. */
  18993. Player.prototype.listenForUserActivity_ = function listenForUserActivity_() {
  18994. var mouseInProgress = void 0;
  18995. var lastMoveX = void 0;
  18996. var lastMoveY = void 0;
  18997. var handleActivity = bind(this, this.reportUserActivity);
  18998. var handleMouseMove = function handleMouseMove(e) {
  18999. // #1068 - Prevent mousemove spamming
  19000. // Chrome Bug: https://code.google.com/p/chromium/issues/detail?id=366970
  19001. if (e.screenX !== lastMoveX || e.screenY !== lastMoveY) {
  19002. lastMoveX = e.screenX;
  19003. lastMoveY = e.screenY;
  19004. handleActivity();
  19005. }
  19006. };
  19007. var handleMouseDown = function handleMouseDown() {
  19008. handleActivity();
  19009. // For as long as the they are touching the device or have their mouse down,
  19010. // we consider them active even if they're not moving their finger or mouse.
  19011. // So we want to continue to update that they are active
  19012. this.clearInterval(mouseInProgress);
  19013. // Setting userActivity=true now and setting the interval to the same time
  19014. // as the activityCheck interval (250) should ensure we never miss the
  19015. // next activityCheck
  19016. mouseInProgress = this.setInterval(handleActivity, 250);
  19017. };
  19018. var handleMouseUp = function handleMouseUp(event) {
  19019. handleActivity();
  19020. // Stop the interval that maintains activity if the mouse/touch is down
  19021. this.clearInterval(mouseInProgress);
  19022. };
  19023. // Any mouse movement will be considered user activity
  19024. this.on('mousedown', handleMouseDown);
  19025. this.on('mousemove', handleMouseMove);
  19026. this.on('mouseup', handleMouseUp);
  19027. // Listen for keyboard navigation
  19028. // Shouldn't need to use inProgress interval because of key repeat
  19029. this.on('keydown', handleActivity);
  19030. this.on('keyup', handleActivity);
  19031. // Run an interval every 250 milliseconds instead of stuffing everything into
  19032. // the mousemove/touchmove function itself, to prevent performance degradation.
  19033. // `this.reportUserActivity` simply sets this.userActivity_ to true, which
  19034. // then gets picked up by this loop
  19035. // http://ejohn.org/blog/learning-from-twitter/
  19036. var inactivityTimeout = void 0;
  19037. this.setInterval(function () {
  19038. // Check to see if mouse/touch activity has happened
  19039. if (!this.userActivity_) {
  19040. return;
  19041. }
  19042. // Reset the activity tracker
  19043. this.userActivity_ = false;
  19044. // If the user state was inactive, set the state to active
  19045. this.userActive(true);
  19046. // Clear any existing inactivity timeout to start the timer over
  19047. this.clearTimeout(inactivityTimeout);
  19048. var timeout = this.options_.inactivityTimeout;
  19049. if (timeout <= 0) {
  19050. return;
  19051. }
  19052. // In <timeout> milliseconds, if no more activity has occurred the
  19053. // user will be considered inactive
  19054. inactivityTimeout = this.setTimeout(function () {
  19055. // Protect against the case where the inactivityTimeout can trigger just
  19056. // before the next user activity is picked up by the activity check loop
  19057. // causing a flicker
  19058. if (!this.userActivity_) {
  19059. this.userActive(false);
  19060. }
  19061. }, timeout);
  19062. }, 250);
  19063. };
  19064. /**
  19065. * Gets or sets the current playback rate. A playback rate of
  19066. * 1.0 represents normal speed and 0.5 would indicate half-speed
  19067. * playback, for instance.
  19068. *
  19069. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-playbackrate
  19070. *
  19071. * @param {number} [rate]
  19072. * New playback rate to set.
  19073. *
  19074. * @return {number}
  19075. * The current playback rate when getting or 1.0
  19076. */
  19077. Player.prototype.playbackRate = function playbackRate(rate) {
  19078. if (rate !== undefined) {
  19079. // NOTE: this.cache_.lastPlaybackRate is set from the tech handler
  19080. // that is registered above
  19081. this.techCall_('setPlaybackRate', rate);
  19082. return;
  19083. }
  19084. if (this.tech_ && this.tech_.featuresPlaybackRate) {
  19085. return this.cache_.lastPlaybackRate || this.techGet_('playbackRate');
  19086. }
  19087. return 1.0;
  19088. };
  19089. /**
  19090. * Gets or sets the current default playback rate. A default playback rate of
  19091. * 1.0 represents normal speed and 0.5 would indicate half-speed playback, for instance.
  19092. * defaultPlaybackRate will only represent what the intial playbackRate of a video was, not
  19093. * not the current playbackRate.
  19094. *
  19095. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-defaultplaybackrate
  19096. *
  19097. * @param {number} [rate]
  19098. * New default playback rate to set.
  19099. *
  19100. * @return {number|Player}
  19101. * - The default playback rate when getting or 1.0
  19102. * - the player when setting
  19103. */
  19104. Player.prototype.defaultPlaybackRate = function defaultPlaybackRate(rate) {
  19105. if (rate !== undefined) {
  19106. return this.techCall_('setDefaultPlaybackRate', rate);
  19107. }
  19108. if (this.tech_ && this.tech_.featuresPlaybackRate) {
  19109. return this.techGet_('defaultPlaybackRate');
  19110. }
  19111. return 1.0;
  19112. };
  19113. /**
  19114. * Gets or sets the audio flag
  19115. *
  19116. * @param {boolean} bool
  19117. * - true signals that this is an audio player
  19118. * - false signals that this is not an audio player
  19119. *
  19120. * @return {boolean}
  19121. * The current value of isAudio when getting
  19122. */
  19123. Player.prototype.isAudio = function isAudio(bool) {
  19124. if (bool !== undefined) {
  19125. this.isAudio_ = !!bool;
  19126. return;
  19127. }
  19128. return !!this.isAudio_;
  19129. };
  19130. /**
  19131. * A helper method for adding a {@link TextTrack} to our
  19132. * {@link TextTrackList}.
  19133. *
  19134. * In addition to the W3C settings we allow adding additional info through options.
  19135. *
  19136. * @see http://www.w3.org/html/wg/drafts/html/master/embedded-content-0.html#dom-media-addtexttrack
  19137. *
  19138. * @param {string} [kind]
  19139. * the kind of TextTrack you are adding
  19140. *
  19141. * @param {string} [label]
  19142. * the label to give the TextTrack label
  19143. *
  19144. * @param {string} [language]
  19145. * the language to set on the TextTrack
  19146. *
  19147. * @return {TextTrack|undefined}
  19148. * the TextTrack that was added or undefined
  19149. * if there is no tech
  19150. */
  19151. Player.prototype.addTextTrack = function addTextTrack(kind, label, language) {
  19152. if (this.tech_) {
  19153. return this.tech_.addTextTrack(kind, label, language);
  19154. }
  19155. };
  19156. /**
  19157. * Create a remote {@link TextTrack} and an {@link HTMLTrackElement}. It will
  19158. * automatically removed from the video element whenever the source changes, unless
  19159. * manualCleanup is set to false.
  19160. *
  19161. * @param {Object} options
  19162. * Options to pass to {@link HTMLTrackElement} during creation. See
  19163. * {@link HTMLTrackElement} for object properties that you should use.
  19164. *
  19165. * @param {boolean} [manualCleanup=true] if set to false, the TextTrack will be
  19166. *
  19167. * @return {HtmlTrackElement}
  19168. * the HTMLTrackElement that was created and added
  19169. * to the HtmlTrackElementList and the remote
  19170. * TextTrackList
  19171. *
  19172. * @deprecated The default value of the "manualCleanup" parameter will default
  19173. * to "false" in upcoming versions of Video.js
  19174. */
  19175. Player.prototype.addRemoteTextTrack = function addRemoteTextTrack(options, manualCleanup) {
  19176. if (this.tech_) {
  19177. return this.tech_.addRemoteTextTrack(options, manualCleanup);
  19178. }
  19179. };
  19180. /**
  19181. * Remove a remote {@link TextTrack} from the respective
  19182. * {@link TextTrackList} and {@link HtmlTrackElementList}.
  19183. *
  19184. * @param {Object} track
  19185. * Remote {@link TextTrack} to remove
  19186. *
  19187. * @return {undefined}
  19188. * does not return anything
  19189. */
  19190. Player.prototype.removeRemoteTextTrack = function removeRemoteTextTrack() {
  19191. var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  19192. _ref3$track = _ref3.track,
  19193. track = _ref3$track === undefined ? arguments[0] : _ref3$track;
  19194. // destructure the input into an object with a track argument, defaulting to arguments[0]
  19195. // default the whole argument to an empty object if nothing was passed in
  19196. if (this.tech_) {
  19197. return this.tech_.removeRemoteTextTrack(track);
  19198. }
  19199. };
  19200. /**
  19201. * Gets available media playback quality metrics as specified by the W3C's Media
  19202. * Playback Quality API.
  19203. *
  19204. * @see [Spec]{@link https://wicg.github.io/media-playback-quality}
  19205. *
  19206. * @return {Object|undefined}
  19207. * An object with supported media playback quality metrics or undefined if there
  19208. * is no tech or the tech does not support it.
  19209. */
  19210. Player.prototype.getVideoPlaybackQuality = function getVideoPlaybackQuality() {
  19211. return this.techGet_('getVideoPlaybackQuality');
  19212. };
  19213. /**
  19214. * Get video width
  19215. *
  19216. * @return {number}
  19217. * current video width
  19218. */
  19219. Player.prototype.videoWidth = function videoWidth() {
  19220. return this.tech_ && this.tech_.videoWidth && this.tech_.videoWidth() || 0;
  19221. };
  19222. /**
  19223. * Get video height
  19224. *
  19225. * @return {number}
  19226. * current video height
  19227. */
  19228. Player.prototype.videoHeight = function videoHeight() {
  19229. return this.tech_ && this.tech_.videoHeight && this.tech_.videoHeight() || 0;
  19230. };
  19231. /**
  19232. * The player's language code
  19233. * NOTE: The language should be set in the player options if you want the
  19234. * the controls to be built with a specific language. Changing the lanugage
  19235. * later will not update controls text.
  19236. *
  19237. * @param {string} [code]
  19238. * the language code to set the player to
  19239. *
  19240. * @return {string}
  19241. * The current language code when getting
  19242. */
  19243. Player.prototype.language = function language(code) {
  19244. if (code === undefined) {
  19245. return this.language_;
  19246. }
  19247. this.language_ = String(code).toLowerCase();
  19248. };
  19249. /**
  19250. * Get the player's language dictionary
  19251. * Merge every time, because a newly added plugin might call videojs.addLanguage() at any time
  19252. * Languages specified directly in the player options have precedence
  19253. *
  19254. * @return {Array}
  19255. * An array of of supported languages
  19256. */
  19257. Player.prototype.languages = function languages() {
  19258. return mergeOptions(Player.prototype.options_.languages, this.languages_);
  19259. };
  19260. /**
  19261. * returns a JavaScript object reperesenting the current track
  19262. * information. **DOES not return it as JSON**
  19263. *
  19264. * @return {Object}
  19265. * Object representing the current of track info
  19266. */
  19267. Player.prototype.toJSON = function toJSON() {
  19268. var options = mergeOptions(this.options_);
  19269. var tracks = options.tracks;
  19270. options.tracks = [];
  19271. for (var i = 0; i < tracks.length; i++) {
  19272. var track = tracks[i];
  19273. // deep merge tracks and null out player so no circular references
  19274. track = mergeOptions(track);
  19275. track.player = undefined;
  19276. options.tracks[i] = track;
  19277. }
  19278. return options;
  19279. };
  19280. /**
  19281. * Creates a simple modal dialog (an instance of the {@link ModalDialog}
  19282. * component) that immediately overlays the player with arbitrary
  19283. * content and removes itself when closed.
  19284. *
  19285. * @param {string|Function|Element|Array|null} content
  19286. * Same as {@link ModalDialog#content}'s param of the same name.
  19287. * The most straight-forward usage is to provide a string or DOM
  19288. * element.
  19289. *
  19290. * @param {Object} [options]
  19291. * Extra options which will be passed on to the {@link ModalDialog}.
  19292. *
  19293. * @return {ModalDialog}
  19294. * the {@link ModalDialog} that was created
  19295. */
  19296. Player.prototype.createModal = function createModal(content, options) {
  19297. var _this12 = this;
  19298. options = options || {};
  19299. options.content = content || '';
  19300. var modal = new ModalDialog(this, options);
  19301. this.addChild(modal);
  19302. modal.on('dispose', function () {
  19303. _this12.removeChild(modal);
  19304. });
  19305. modal.open();
  19306. return modal;
  19307. };
  19308. /**
  19309. * Change breakpoint classes when the player resizes.
  19310. *
  19311. * @private
  19312. */
  19313. Player.prototype.updateCurrentBreakpoint_ = function updateCurrentBreakpoint_() {
  19314. if (!this.responsive()) {
  19315. return;
  19316. }
  19317. var currentBreakpoint = this.currentBreakpoint();
  19318. var currentWidth = this.currentWidth();
  19319. for (var i = 0; i < BREAKPOINT_ORDER.length; i++) {
  19320. var candidateBreakpoint = BREAKPOINT_ORDER[i];
  19321. var maxWidth = this.breakpoints_[candidateBreakpoint];
  19322. if (currentWidth <= maxWidth) {
  19323. // The current breakpoint did not change, nothing to do.
  19324. if (currentBreakpoint === candidateBreakpoint) {
  19325. return;
  19326. }
  19327. // Only remove a class if there is a current breakpoint.
  19328. if (currentBreakpoint) {
  19329. this.removeClass(BREAKPOINT_CLASSES[currentBreakpoint]);
  19330. }
  19331. this.addClass(BREAKPOINT_CLASSES[candidateBreakpoint]);
  19332. this.breakpoint_ = candidateBreakpoint;
  19333. break;
  19334. }
  19335. }
  19336. };
  19337. /**
  19338. * Removes the current breakpoint.
  19339. *
  19340. * @private
  19341. */
  19342. Player.prototype.removeCurrentBreakpoint_ = function removeCurrentBreakpoint_() {
  19343. var className = this.currentBreakpointClass();
  19344. this.breakpoint_ = '';
  19345. if (className) {
  19346. this.removeClass(className);
  19347. }
  19348. };
  19349. /**
  19350. * Get or set breakpoints on the player.
  19351. *
  19352. * Calling this method with an object or `true` will remove any previous
  19353. * custom breakpoints and start from the defaults again.
  19354. *
  19355. * @param {Object|boolean} [breakpoints]
  19356. * If an object is given, it can be used to provide custom
  19357. * breakpoints. If `true` is given, will set default breakpoints.
  19358. * If this argument is not given, will simply return the current
  19359. * breakpoints.
  19360. *
  19361. * @param {number} [breakpoints.tiny]
  19362. * The maximum width for the "vjs-layout-tiny" class.
  19363. *
  19364. * @param {number} [breakpoints.xsmall]
  19365. * The maximum width for the "vjs-layout-x-small" class.
  19366. *
  19367. * @param {number} [breakpoints.small]
  19368. * The maximum width for the "vjs-layout-small" class.
  19369. *
  19370. * @param {number} [breakpoints.medium]
  19371. * The maximum width for the "vjs-layout-medium" class.
  19372. *
  19373. * @param {number} [breakpoints.large]
  19374. * The maximum width for the "vjs-layout-large" class.
  19375. *
  19376. * @param {number} [breakpoints.xlarge]
  19377. * The maximum width for the "vjs-layout-x-large" class.
  19378. *
  19379. * @param {number} [breakpoints.huge]
  19380. * The maximum width for the "vjs-layout-huge" class.
  19381. *
  19382. * @return {Object}
  19383. * An object mapping breakpoint names to maximum width values.
  19384. */
  19385. Player.prototype.breakpoints = function breakpoints(_breakpoints) {
  19386. // Used as a getter.
  19387. if (_breakpoints === undefined) {
  19388. return assign(this.breakpoints_);
  19389. }
  19390. this.breakpoint_ = '';
  19391. this.breakpoints_ = assign({}, DEFAULT_BREAKPOINTS, _breakpoints);
  19392. // When breakpoint definitions change, we need to update the currently
  19393. // selected breakpoint.
  19394. this.updateCurrentBreakpoint_();
  19395. // Clone the breakpoints before returning.
  19396. return assign(this.breakpoints_);
  19397. };
  19398. /**
  19399. * Get or set a flag indicating whether or not this player should adjust
  19400. * its UI based on its dimensions.
  19401. *
  19402. * @param {boolean} value
  19403. * Should be `true` if the player should adjust its UI based on its
  19404. * dimensions; otherwise, should be `false`.
  19405. *
  19406. * @return {boolean}
  19407. * Will be `true` if this player should adjust its UI based on its
  19408. * dimensions; otherwise, will be `false`.
  19409. */
  19410. Player.prototype.responsive = function responsive(value) {
  19411. // Used as a getter.
  19412. if (value === undefined) {
  19413. return this.responsive_;
  19414. }
  19415. value = Boolean(value);
  19416. var current = this.responsive_;
  19417. // Nothing changed.
  19418. if (value === current) {
  19419. return;
  19420. }
  19421. // The value actually changed, set it.
  19422. this.responsive_ = value;
  19423. // Start listening for breakpoints and set the initial breakpoint if the
  19424. // player is now responsive.
  19425. if (value) {
  19426. this.on('playerresize', this.updateCurrentBreakpoint_);
  19427. this.updateCurrentBreakpoint_();
  19428. // Stop listening for breakpoints if the player is no longer responsive.
  19429. } else {
  19430. this.off('playerresize', this.updateCurrentBreakpoint_);
  19431. this.removeCurrentBreakpoint_();
  19432. }
  19433. return value;
  19434. };
  19435. /**
  19436. * Get current breakpoint name, if any.
  19437. *
  19438. * @return {string}
  19439. * If there is currently a breakpoint set, returns a the key from the
  19440. * breakpoints object matching it. Otherwise, returns an empty string.
  19441. */
  19442. Player.prototype.currentBreakpoint = function currentBreakpoint() {
  19443. return this.breakpoint_;
  19444. };
  19445. /**
  19446. * Get the current breakpoint class name.
  19447. *
  19448. * @return {string}
  19449. * The matching class name (e.g. `"vjs-layout-tiny"` or
  19450. * `"vjs-layout-large"`) for the current breakpoint. Empty string if
  19451. * there is no current breakpoint.
  19452. */
  19453. Player.prototype.currentBreakpointClass = function currentBreakpointClass() {
  19454. return BREAKPOINT_CLASSES[this.breakpoint_] || '';
  19455. };
  19456. /**
  19457. * Gets tag settings
  19458. *
  19459. * @param {Element} tag
  19460. * The player tag
  19461. *
  19462. * @return {Object}
  19463. * An object containing all of the settings
  19464. * for a player tag
  19465. */
  19466. Player.getTagSettings = function getTagSettings(tag) {
  19467. var baseOptions = {
  19468. sources: [],
  19469. tracks: []
  19470. };
  19471. var tagOptions = getAttributes(tag);
  19472. var dataSetup = tagOptions['data-setup'];
  19473. if (hasClass(tag, 'vjs-fill')) {
  19474. tagOptions.fill = true;
  19475. }
  19476. if (hasClass(tag, 'vjs-fluid')) {
  19477. tagOptions.fluid = true;
  19478. }
  19479. // Check if data-setup attr exists.
  19480. if (dataSetup !== null) {
  19481. // Parse options JSON
  19482. // If empty string, make it a parsable json object.
  19483. var _safeParseTuple = safeParseTuple(dataSetup || '{}'),
  19484. err = _safeParseTuple[0],
  19485. data = _safeParseTuple[1];
  19486. if (err) {
  19487. log.error(err);
  19488. }
  19489. assign(tagOptions, data);
  19490. }
  19491. assign(baseOptions, tagOptions);
  19492. // Get tag children settings
  19493. if (tag.hasChildNodes()) {
  19494. var children = tag.childNodes;
  19495. for (var i = 0, j = children.length; i < j; i++) {
  19496. var child = children[i];
  19497. // Change case needed: http://ejohn.org/blog/nodename-case-sensitivity/
  19498. var childName = child.nodeName.toLowerCase();
  19499. if (childName === 'source') {
  19500. baseOptions.sources.push(getAttributes(child));
  19501. } else if (childName === 'track') {
  19502. baseOptions.tracks.push(getAttributes(child));
  19503. }
  19504. }
  19505. }
  19506. return baseOptions;
  19507. };
  19508. /**
  19509. * Determine wether or not flexbox is supported
  19510. *
  19511. * @return {boolean}
  19512. * - true if flexbox is supported
  19513. * - false if flexbox is not supported
  19514. */
  19515. Player.prototype.flexNotSupported_ = function flexNotSupported_() {
  19516. var elem = document.createElement('i');
  19517. // Note: We don't actually use flexBasis (or flexOrder), but it's one of the more
  19518. // common flex features that we can rely on when checking for flex support.
  19519. return !('flexBasis' in elem.style || 'webkitFlexBasis' in elem.style || 'mozFlexBasis' in elem.style || 'msFlexBasis' in elem.style ||
  19520. // IE10-specific (2012 flex spec)
  19521. 'msFlexOrder' in elem.style);
  19522. };
  19523. return Player;
  19524. }(Component);
  19525. /**
  19526. * Get the {@link VideoTrackList}
  19527. * @link https://html.spec.whatwg.org/multipage/embedded-content.html#videotracklist
  19528. *
  19529. * @return {VideoTrackList}
  19530. * the current video track list
  19531. *
  19532. * @method Player.prototype.videoTracks
  19533. */
  19534. /**
  19535. * Get the {@link AudioTrackList}
  19536. * @link https://html.spec.whatwg.org/multipage/embedded-content.html#audiotracklist
  19537. *
  19538. * @return {AudioTrackList}
  19539. * the current audio track list
  19540. *
  19541. * @method Player.prototype.audioTracks
  19542. */
  19543. /**
  19544. * Get the {@link TextTrackList}
  19545. *
  19546. * @link http://www.w3.org/html/wg/drafts/html/master/embedded-content-0.html#dom-media-texttracks
  19547. *
  19548. * @return {TextTrackList}
  19549. * the current text track list
  19550. *
  19551. * @method Player.prototype.textTracks
  19552. */
  19553. /**
  19554. * Get the remote {@link TextTrackList}
  19555. *
  19556. * @return {TextTrackList}
  19557. * The current remote text track list
  19558. *
  19559. * @method Player.prototype.remoteTextTracks
  19560. */
  19561. /**
  19562. * Get the remote {@link HtmlTrackElementList} tracks.
  19563. *
  19564. * @return {HtmlTrackElementList}
  19565. * The current remote text track element list
  19566. *
  19567. * @method Player.prototype.remoteTextTrackEls
  19568. */
  19569. ALL.names.forEach(function (name$$1) {
  19570. var props = ALL[name$$1];
  19571. Player.prototype[props.getterName] = function () {
  19572. if (this.tech_) {
  19573. return this.tech_[props.getterName]();
  19574. }
  19575. // if we have not yet loadTech_, we create {video,audio,text}Tracks_
  19576. // these will be passed to the tech during loading
  19577. this[props.privateName] = this[props.privateName] || new props.ListClass();
  19578. return this[props.privateName];
  19579. };
  19580. });
  19581. /**
  19582. * Global player list
  19583. *
  19584. * @type {Object}
  19585. */
  19586. Player.players = {};
  19587. var navigator = window.navigator;
  19588. /*
  19589. * Player instance options, surfaced using options
  19590. * options = Player.prototype.options_
  19591. * Make changes in options, not here.
  19592. *
  19593. * @type {Object}
  19594. * @private
  19595. */
  19596. Player.prototype.options_ = {
  19597. // Default order of fallback technology
  19598. techOrder: Tech.defaultTechOrder_,
  19599. html5: {},
  19600. flash: {},
  19601. // default inactivity timeout
  19602. inactivityTimeout: 2000,
  19603. // default playback rates
  19604. playbackRates: [],
  19605. // Add playback rate selection by adding rates
  19606. // 'playbackRates': [0.5, 1, 1.5, 2],
  19607. // Included control sets
  19608. children: ['mediaLoader', 'posterImage', 'textTrackDisplay', 'loadingSpinner', 'bigPlayButton', 'controlBar', 'errorDisplay', 'textTrackSettings'],
  19609. language: navigator && (navigator.languages && navigator.languages[0] || navigator.userLanguage || navigator.language) || 'en',
  19610. // locales and their language translations
  19611. languages: {},
  19612. // Default message to show when a video cannot be played.
  19613. notSupportedMessage: 'No compatible source was found for this media.',
  19614. breakpoints: {},
  19615. responsive: false
  19616. };
  19617. if (!IS_IE8) {
  19618. Player.prototype.options_.children.push('resizeManager');
  19619. }
  19620. [
  19621. /**
  19622. * Returns whether or not the player is in the "ended" state.
  19623. *
  19624. * @return {Boolean} True if the player is in the ended state, false if not.
  19625. * @method Player#ended
  19626. */
  19627. 'ended',
  19628. /**
  19629. * Returns whether or not the player is in the "seeking" state.
  19630. *
  19631. * @return {Boolean} True if the player is in the seeking state, false if not.
  19632. * @method Player#seeking
  19633. */
  19634. 'seeking',
  19635. /**
  19636. * Returns the TimeRanges of the media that are currently available
  19637. * for seeking to.
  19638. *
  19639. * @return {TimeRanges} the seekable intervals of the media timeline
  19640. * @method Player#seekable
  19641. */
  19642. 'seekable',
  19643. /**
  19644. * Returns the current state of network activity for the element, from
  19645. * the codes in the list below.
  19646. * - NETWORK_EMPTY (numeric value 0)
  19647. * The element has not yet been initialised. All attributes are in
  19648. * their initial states.
  19649. * - NETWORK_IDLE (numeric value 1)
  19650. * The element's resource selection algorithm is active and has
  19651. * selected a resource, but it is not actually using the network at
  19652. * this time.
  19653. * - NETWORK_LOADING (numeric value 2)
  19654. * The user agent is actively trying to download data.
  19655. * - NETWORK_NO_SOURCE (numeric value 3)
  19656. * The element's resource selection algorithm is active, but it has
  19657. * not yet found a resource to use.
  19658. *
  19659. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#network-states
  19660. * @return {number} the current network activity state
  19661. * @method Player#networkState
  19662. */
  19663. 'networkState',
  19664. /**
  19665. * Returns a value that expresses the current state of the element
  19666. * with respect to rendering the current playback position, from the
  19667. * codes in the list below.
  19668. * - HAVE_NOTHING (numeric value 0)
  19669. * No information regarding the media resource is available.
  19670. * - HAVE_METADATA (numeric value 1)
  19671. * Enough of the resource has been obtained that the duration of the
  19672. * resource is available.
  19673. * - HAVE_CURRENT_DATA (numeric value 2)
  19674. * Data for the immediate current playback position is available.
  19675. * - HAVE_FUTURE_DATA (numeric value 3)
  19676. * Data for the immediate current playback position is available, as
  19677. * well as enough data for the user agent to advance the current
  19678. * playback position in the direction of playback.
  19679. * - HAVE_ENOUGH_DATA (numeric value 4)
  19680. * The user agent estimates that enough data is available for
  19681. * playback to proceed uninterrupted.
  19682. *
  19683. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-readystate
  19684. * @return {number} the current playback rendering state
  19685. * @method Player#readyState
  19686. */
  19687. 'readyState'].forEach(function (fn) {
  19688. Player.prototype[fn] = function () {
  19689. return this.techGet_(fn);
  19690. };
  19691. });
  19692. TECH_EVENTS_RETRIGGER.forEach(function (event) {
  19693. Player.prototype['handleTech' + toTitleCase(event) + '_'] = function () {
  19694. return this.trigger(event);
  19695. };
  19696. });
  19697. /**
  19698. * Fired when the player has initial duration and dimension information
  19699. *
  19700. * @event Player#loadedmetadata
  19701. * @type {EventTarget~Event}
  19702. */
  19703. /**
  19704. * Fired when the player has downloaded data at the current playback position
  19705. *
  19706. * @event Player#loadeddata
  19707. * @type {EventTarget~Event}
  19708. */
  19709. /**
  19710. * Fired when the current playback position has changed *
  19711. * During playback this is fired every 15-250 milliseconds, depending on the
  19712. * playback technology in use.
  19713. *
  19714. * @event Player#timeupdate
  19715. * @type {EventTarget~Event}
  19716. */
  19717. /**
  19718. * Fired when the volume changes
  19719. *
  19720. * @event Player#volumechange
  19721. * @type {EventTarget~Event}
  19722. */
  19723. /**
  19724. * Reports whether or not a player has a plugin available.
  19725. *
  19726. * This does not report whether or not the plugin has ever been initialized
  19727. * on this player. For that, [usingPlugin]{@link Player#usingPlugin}.
  19728. *
  19729. * @method Player#hasPlugin
  19730. * @param {string} name
  19731. * The name of a plugin.
  19732. *
  19733. * @return {boolean}
  19734. * Whether or not this player has the requested plugin available.
  19735. */
  19736. /**
  19737. * Reports whether or not a player is using a plugin by name.
  19738. *
  19739. * For basic plugins, this only reports whether the plugin has _ever_ been
  19740. * initialized on this player.
  19741. *
  19742. * @method Player#usingPlugin
  19743. * @param {string} name
  19744. * The name of a plugin.
  19745. *
  19746. * @return {boolean}
  19747. * Whether or not this player is using the requested plugin.
  19748. */
  19749. Component.registerComponent('Player', Player);
  19750. /**
  19751. * @file plugin.js
  19752. */
  19753. /**
  19754. * The base plugin name.
  19755. *
  19756. * @private
  19757. * @constant
  19758. * @type {string}
  19759. */
  19760. var BASE_PLUGIN_NAME = 'plugin';
  19761. /**
  19762. * The key on which a player's active plugins cache is stored.
  19763. *
  19764. * @private
  19765. * @constant
  19766. * @type {string}
  19767. */
  19768. var PLUGIN_CACHE_KEY = 'activePlugins_';
  19769. /**
  19770. * Stores registered plugins in a private space.
  19771. *
  19772. * @private
  19773. * @type {Object}
  19774. */
  19775. var pluginStorage = {};
  19776. /**
  19777. * Reports whether or not a plugin has been registered.
  19778. *
  19779. * @private
  19780. * @param {string} name
  19781. * The name of a plugin.
  19782. *
  19783. * @returns {boolean}
  19784. * Whether or not the plugin has been registered.
  19785. */
  19786. var pluginExists = function pluginExists(name) {
  19787. return pluginStorage.hasOwnProperty(name);
  19788. };
  19789. /**
  19790. * Get a single registered plugin by name.
  19791. *
  19792. * @private
  19793. * @param {string} name
  19794. * The name of a plugin.
  19795. *
  19796. * @returns {Function|undefined}
  19797. * The plugin (or undefined).
  19798. */
  19799. var getPlugin = function getPlugin(name) {
  19800. return pluginExists(name) ? pluginStorage[name] : undefined;
  19801. };
  19802. /**
  19803. * Marks a plugin as "active" on a player.
  19804. *
  19805. * Also, ensures that the player has an object for tracking active plugins.
  19806. *
  19807. * @private
  19808. * @param {Player} player
  19809. * A Video.js player instance.
  19810. *
  19811. * @param {string} name
  19812. * The name of a plugin.
  19813. */
  19814. var markPluginAsActive = function markPluginAsActive(player, name) {
  19815. player[PLUGIN_CACHE_KEY] = player[PLUGIN_CACHE_KEY] || {};
  19816. player[PLUGIN_CACHE_KEY][name] = true;
  19817. };
  19818. /**
  19819. * Triggers a pair of plugin setup events.
  19820. *
  19821. * @private
  19822. * @param {Player} player
  19823. * A Video.js player instance.
  19824. *
  19825. * @param {Plugin~PluginEventHash} hash
  19826. * A plugin event hash.
  19827. *
  19828. * @param {Boolean} [before]
  19829. * If true, prefixes the event name with "before". In other words,
  19830. * use this to trigger "beforepluginsetup" instead of "pluginsetup".
  19831. */
  19832. var triggerSetupEvent = function triggerSetupEvent(player, hash, before) {
  19833. var eventName = (before ? 'before' : '') + 'pluginsetup';
  19834. player.trigger(eventName, hash);
  19835. player.trigger(eventName + ':' + hash.name, hash);
  19836. };
  19837. /**
  19838. * Takes a basic plugin function and returns a wrapper function which marks
  19839. * on the player that the plugin has been activated.
  19840. *
  19841. * @private
  19842. * @param {string} name
  19843. * The name of the plugin.
  19844. *
  19845. * @param {Function} plugin
  19846. * The basic plugin.
  19847. *
  19848. * @returns {Function}
  19849. * A wrapper function for the given plugin.
  19850. */
  19851. var createBasicPlugin = function createBasicPlugin(name, plugin) {
  19852. var basicPluginWrapper = function basicPluginWrapper() {
  19853. // We trigger the "beforepluginsetup" and "pluginsetup" events on the player
  19854. // regardless, but we want the hash to be consistent with the hash provided
  19855. // for advanced plugins.
  19856. //
  19857. // The only potentially counter-intuitive thing here is the `instance` in
  19858. // the "pluginsetup" event is the value returned by the `plugin` function.
  19859. triggerSetupEvent(this, { name: name, plugin: plugin, instance: null }, true);
  19860. var instance = plugin.apply(this, arguments);
  19861. markPluginAsActive(this, name);
  19862. triggerSetupEvent(this, { name: name, plugin: plugin, instance: instance });
  19863. return instance;
  19864. };
  19865. Object.keys(plugin).forEach(function (prop) {
  19866. basicPluginWrapper[prop] = plugin[prop];
  19867. });
  19868. return basicPluginWrapper;
  19869. };
  19870. /**
  19871. * Takes a plugin sub-class and returns a factory function for generating
  19872. * instances of it.
  19873. *
  19874. * This factory function will replace itself with an instance of the requested
  19875. * sub-class of Plugin.
  19876. *
  19877. * @private
  19878. * @param {string} name
  19879. * The name of the plugin.
  19880. *
  19881. * @param {Plugin} PluginSubClass
  19882. * The advanced plugin.
  19883. *
  19884. * @returns {Function}
  19885. */
  19886. var createPluginFactory = function createPluginFactory(name, PluginSubClass) {
  19887. // Add a `name` property to the plugin prototype so that each plugin can
  19888. // refer to itself by name.
  19889. PluginSubClass.prototype.name = name;
  19890. return function () {
  19891. triggerSetupEvent(this, { name: name, plugin: PluginSubClass, instance: null }, true);
  19892. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  19893. args[_key] = arguments[_key];
  19894. }
  19895. var instance = new (Function.prototype.bind.apply(PluginSubClass, [null].concat([this].concat(args))))();
  19896. // The plugin is replaced by a function that returns the current instance.
  19897. this[name] = function () {
  19898. return instance;
  19899. };
  19900. triggerSetupEvent(this, instance.getEventHash());
  19901. return instance;
  19902. };
  19903. };
  19904. /**
  19905. * Parent class for all advanced plugins.
  19906. *
  19907. * @mixes module:evented~EventedMixin
  19908. * @mixes module:stateful~StatefulMixin
  19909. * @fires Player#beforepluginsetup
  19910. * @fires Player#beforepluginsetup:$name
  19911. * @fires Player#pluginsetup
  19912. * @fires Player#pluginsetup:$name
  19913. * @listens Player#dispose
  19914. * @throws {Error}
  19915. * If attempting to instantiate the base {@link Plugin} class
  19916. * directly instead of via a sub-class.
  19917. */
  19918. var Plugin = function () {
  19919. /**
  19920. * Creates an instance of this class.
  19921. *
  19922. * Sub-classes should call `super` to ensure plugins are properly initialized.
  19923. *
  19924. * @param {Player} player
  19925. * A Video.js player instance.
  19926. */
  19927. function Plugin(player) {
  19928. classCallCheck(this, Plugin);
  19929. if (this.constructor === Plugin) {
  19930. throw new Error('Plugin must be sub-classed; not directly instantiated.');
  19931. }
  19932. this.player = player;
  19933. // Make this object evented, but remove the added `trigger` method so we
  19934. // use the prototype version instead.
  19935. evented(this);
  19936. delete this.trigger;
  19937. stateful(this, this.constructor.defaultState);
  19938. markPluginAsActive(player, this.name);
  19939. // Auto-bind the dispose method so we can use it as a listener and unbind
  19940. // it later easily.
  19941. this.dispose = bind(this, this.dispose);
  19942. // If the player is disposed, dispose the plugin.
  19943. player.on('dispose', this.dispose);
  19944. }
  19945. /**
  19946. * Get the version of the plugin that was set on <pluginName>.VERSION
  19947. */
  19948. Plugin.prototype.version = function version() {
  19949. return this.constructor.VERSION;
  19950. };
  19951. /**
  19952. * Each event triggered by plugins includes a hash of additional data with
  19953. * conventional properties.
  19954. *
  19955. * This returns that object or mutates an existing hash.
  19956. *
  19957. * @param {Object} [hash={}]
  19958. * An object to be used as event an event hash.
  19959. *
  19960. * @returns {Plugin~PluginEventHash}
  19961. * An event hash object with provided properties mixed-in.
  19962. */
  19963. Plugin.prototype.getEventHash = function getEventHash() {
  19964. var hash = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  19965. hash.name = this.name;
  19966. hash.plugin = this.constructor;
  19967. hash.instance = this;
  19968. return hash;
  19969. };
  19970. /**
  19971. * Triggers an event on the plugin object and overrides
  19972. * {@link module:evented~EventedMixin.trigger|EventedMixin.trigger}.
  19973. *
  19974. * @param {string|Object} event
  19975. * An event type or an object with a type property.
  19976. *
  19977. * @param {Object} [hash={}]
  19978. * Additional data hash to merge with a
  19979. * {@link Plugin~PluginEventHash|PluginEventHash}.
  19980. *
  19981. * @returns {boolean}
  19982. * Whether or not default was prevented.
  19983. */
  19984. Plugin.prototype.trigger = function trigger$$1(event) {
  19985. var hash = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  19986. return trigger(this.eventBusEl_, event, this.getEventHash(hash));
  19987. };
  19988. /**
  19989. * Handles "statechanged" events on the plugin. No-op by default, override by
  19990. * subclassing.
  19991. *
  19992. * @abstract
  19993. * @param {Event} e
  19994. * An event object provided by a "statechanged" event.
  19995. *
  19996. * @param {Object} e.changes
  19997. * An object describing changes that occurred with the "statechanged"
  19998. * event.
  19999. */
  20000. Plugin.prototype.handleStateChanged = function handleStateChanged(e) {};
  20001. /**
  20002. * Disposes a plugin.
  20003. *
  20004. * Subclasses can override this if they want, but for the sake of safety,
  20005. * it's probably best to subscribe the "dispose" event.
  20006. *
  20007. * @fires Plugin#dispose
  20008. */
  20009. Plugin.prototype.dispose = function dispose() {
  20010. var name = this.name,
  20011. player = this.player;
  20012. /**
  20013. * Signals that a advanced plugin is about to be disposed.
  20014. *
  20015. * @event Plugin#dispose
  20016. * @type {EventTarget~Event}
  20017. */
  20018. this.trigger('dispose');
  20019. this.off();
  20020. player.off('dispose', this.dispose);
  20021. // Eliminate any possible sources of leaking memory by clearing up
  20022. // references between the player and the plugin instance and nulling out
  20023. // the plugin's state and replacing methods with a function that throws.
  20024. player[PLUGIN_CACHE_KEY][name] = false;
  20025. this.player = this.state = null;
  20026. // Finally, replace the plugin name on the player with a new factory
  20027. // function, so that the plugin is ready to be set up again.
  20028. player[name] = createPluginFactory(name, pluginStorage[name]);
  20029. };
  20030. /**
  20031. * Determines if a plugin is a basic plugin (i.e. not a sub-class of `Plugin`).
  20032. *
  20033. * @param {string|Function} plugin
  20034. * If a string, matches the name of a plugin. If a function, will be
  20035. * tested directly.
  20036. *
  20037. * @returns {boolean}
  20038. * Whether or not a plugin is a basic plugin.
  20039. */
  20040. Plugin.isBasic = function isBasic(plugin) {
  20041. var p = typeof plugin === 'string' ? getPlugin(plugin) : plugin;
  20042. return typeof p === 'function' && !Plugin.prototype.isPrototypeOf(p.prototype);
  20043. };
  20044. /**
  20045. * Register a Video.js plugin.
  20046. *
  20047. * @param {string} name
  20048. * The name of the plugin to be registered. Must be a string and
  20049. * must not match an existing plugin or a method on the `Player`
  20050. * prototype.
  20051. *
  20052. * @param {Function} plugin
  20053. * A sub-class of `Plugin` or a function for basic plugins.
  20054. *
  20055. * @returns {Function}
  20056. * For advanced plugins, a factory function for that plugin. For
  20057. * basic plugins, a wrapper function that initializes the plugin.
  20058. */
  20059. Plugin.registerPlugin = function registerPlugin(name, plugin) {
  20060. if (typeof name !== 'string') {
  20061. throw new Error('Illegal plugin name, "' + name + '", must be a string, was ' + (typeof name === 'undefined' ? 'undefined' : _typeof(name)) + '.');
  20062. }
  20063. if (pluginExists(name)) {
  20064. log.warn('A plugin named "' + name + '" already exists. You may want to avoid re-registering plugins!');
  20065. } else if (Player.prototype.hasOwnProperty(name)) {
  20066. throw new Error('Illegal plugin name, "' + name + '", cannot share a name with an existing player method!');
  20067. }
  20068. if (typeof plugin !== 'function') {
  20069. throw new Error('Illegal plugin for "' + name + '", must be a function, was ' + (typeof plugin === 'undefined' ? 'undefined' : _typeof(plugin)) + '.');
  20070. }
  20071. pluginStorage[name] = plugin;
  20072. // Add a player prototype method for all sub-classed plugins (but not for
  20073. // the base Plugin class).
  20074. if (name !== BASE_PLUGIN_NAME) {
  20075. if (Plugin.isBasic(plugin)) {
  20076. Player.prototype[name] = createBasicPlugin(name, plugin);
  20077. } else {
  20078. Player.prototype[name] = createPluginFactory(name, plugin);
  20079. }
  20080. }
  20081. return plugin;
  20082. };
  20083. /**
  20084. * De-register a Video.js plugin.
  20085. *
  20086. * @param {string} name
  20087. * The name of the plugin to be deregistered.
  20088. */
  20089. Plugin.deregisterPlugin = function deregisterPlugin(name) {
  20090. if (name === BASE_PLUGIN_NAME) {
  20091. throw new Error('Cannot de-register base plugin.');
  20092. }
  20093. if (pluginExists(name)) {
  20094. delete pluginStorage[name];
  20095. delete Player.prototype[name];
  20096. }
  20097. };
  20098. /**
  20099. * Gets an object containing multiple Video.js plugins.
  20100. *
  20101. * @param {Array} [names]
  20102. * If provided, should be an array of plugin names. Defaults to _all_
  20103. * plugin names.
  20104. *
  20105. * @returns {Object|undefined}
  20106. * An object containing plugin(s) associated with their name(s) or
  20107. * `undefined` if no matching plugins exist).
  20108. */
  20109. Plugin.getPlugins = function getPlugins() {
  20110. var names = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Object.keys(pluginStorage);
  20111. var result = void 0;
  20112. names.forEach(function (name) {
  20113. var plugin = getPlugin(name);
  20114. if (plugin) {
  20115. result = result || {};
  20116. result[name] = plugin;
  20117. }
  20118. });
  20119. return result;
  20120. };
  20121. /**
  20122. * Gets a plugin's version, if available
  20123. *
  20124. * @param {string} name
  20125. * The name of a plugin.
  20126. *
  20127. * @returns {string}
  20128. * The plugin's version or an empty string.
  20129. */
  20130. Plugin.getPluginVersion = function getPluginVersion(name) {
  20131. var plugin = getPlugin(name);
  20132. return plugin && plugin.VERSION || '';
  20133. };
  20134. return Plugin;
  20135. }();
  20136. /**
  20137. * Gets a plugin by name if it exists.
  20138. *
  20139. * @static
  20140. * @method getPlugin
  20141. * @memberOf Plugin
  20142. * @param {string} name
  20143. * The name of a plugin.
  20144. *
  20145. * @returns {Function|undefined}
  20146. * The plugin (or `undefined`).
  20147. */
  20148. Plugin.getPlugin = getPlugin;
  20149. /**
  20150. * The name of the base plugin class as it is registered.
  20151. *
  20152. * @type {string}
  20153. */
  20154. Plugin.BASE_PLUGIN_NAME = BASE_PLUGIN_NAME;
  20155. Plugin.registerPlugin(BASE_PLUGIN_NAME, Plugin);
  20156. /**
  20157. * Documented in player.js
  20158. *
  20159. * @ignore
  20160. */
  20161. Player.prototype.usingPlugin = function (name) {
  20162. return !!this[PLUGIN_CACHE_KEY] && this[PLUGIN_CACHE_KEY][name] === true;
  20163. };
  20164. /**
  20165. * Documented in player.js
  20166. *
  20167. * @ignore
  20168. */
  20169. Player.prototype.hasPlugin = function (name) {
  20170. return !!pluginExists(name);
  20171. };
  20172. /**
  20173. * Signals that a plugin is about to be set up on a player.
  20174. *
  20175. * @event Player#beforepluginsetup
  20176. * @type {Plugin~PluginEventHash}
  20177. */
  20178. /**
  20179. * Signals that a plugin is about to be set up on a player - by name. The name
  20180. * is the name of the plugin.
  20181. *
  20182. * @event Player#beforepluginsetup:$name
  20183. * @type {Plugin~PluginEventHash}
  20184. */
  20185. /**
  20186. * Signals that a plugin has just been set up on a player.
  20187. *
  20188. * @event Player#pluginsetup
  20189. * @type {Plugin~PluginEventHash}
  20190. */
  20191. /**
  20192. * Signals that a plugin has just been set up on a player - by name. The name
  20193. * is the name of the plugin.
  20194. *
  20195. * @event Player#pluginsetup:$name
  20196. * @type {Plugin~PluginEventHash}
  20197. */
  20198. /**
  20199. * @typedef {Object} Plugin~PluginEventHash
  20200. *
  20201. * @property {string} instance
  20202. * For basic plugins, the return value of the plugin function. For
  20203. * advanced plugins, the plugin instance on which the event is fired.
  20204. *
  20205. * @property {string} name
  20206. * The name of the plugin.
  20207. *
  20208. * @property {string} plugin
  20209. * For basic plugins, the plugin function. For advanced plugins, the
  20210. * plugin class/constructor.
  20211. */
  20212. /**
  20213. * @file extend.js
  20214. * @module extend
  20215. */
  20216. /**
  20217. * A combination of node inherits and babel's inherits (after transpile).
  20218. * Both work the same but node adds `super_` to the subClass
  20219. * and Bable adds the superClass as __proto__. Both seem useful.
  20220. *
  20221. * @param {Object} subClass
  20222. * The class to inherit to
  20223. *
  20224. * @param {Object} superClass
  20225. * The class to inherit from
  20226. *
  20227. * @private
  20228. */
  20229. var _inherits = function _inherits(subClass, superClass) {
  20230. if (typeof superClass !== 'function' && superClass !== null) {
  20231. throw new TypeError('Super expression must either be null or a function, not ' + (typeof superClass === 'undefined' ? 'undefined' : _typeof(superClass)));
  20232. }
  20233. subClass.prototype = Object.create(superClass && superClass.prototype, {
  20234. constructor: {
  20235. value: subClass,
  20236. enumerable: false,
  20237. writable: true,
  20238. configurable: true
  20239. }
  20240. });
  20241. if (superClass) {
  20242. // node
  20243. subClass.super_ = superClass;
  20244. }
  20245. };
  20246. /**
  20247. * Function for subclassing using the same inheritance that
  20248. * videojs uses internally
  20249. *
  20250. * @static
  20251. * @const
  20252. *
  20253. * @param {Object} superClass
  20254. * The class to inherit from
  20255. *
  20256. * @param {Object} [subClassMethods={}]
  20257. * The class to inherit to
  20258. *
  20259. * @return {Object}
  20260. * The new object with subClassMethods that inherited superClass.
  20261. */
  20262. var extendFn = function extendFn(superClass) {
  20263. var subClassMethods = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  20264. var subClass = function subClass() {
  20265. superClass.apply(this, arguments);
  20266. };
  20267. var methods = {};
  20268. if ((typeof subClassMethods === 'undefined' ? 'undefined' : _typeof(subClassMethods)) === 'object') {
  20269. if (subClassMethods.constructor !== Object.prototype.constructor) {
  20270. subClass = subClassMethods.constructor;
  20271. }
  20272. methods = subClassMethods;
  20273. } else if (typeof subClassMethods === 'function') {
  20274. subClass = subClassMethods;
  20275. }
  20276. _inherits(subClass, superClass);
  20277. // Extend subObj's prototype with functions and other properties from props
  20278. for (var name in methods) {
  20279. if (methods.hasOwnProperty(name)) {
  20280. subClass.prototype[name] = methods[name];
  20281. }
  20282. }
  20283. return subClass;
  20284. };
  20285. /**
  20286. * @file video.js
  20287. * @module videojs
  20288. */
  20289. // Include the built-in techs
  20290. // HTML5 Element Shim for IE8
  20291. if (typeof HTMLVideoElement === 'undefined' && isReal()) {
  20292. document.createElement('video');
  20293. document.createElement('audio');
  20294. document.createElement('track');
  20295. document.createElement('video-js');
  20296. }
  20297. /**
  20298. * Normalize an `id` value by trimming off a leading `#`
  20299. *
  20300. * @param {string} id
  20301. * A string, maybe with a leading `#`.
  20302. *
  20303. * @returns {string}
  20304. * The string, without any leading `#`.
  20305. */
  20306. var normalizeId = function normalizeId(id) {
  20307. return id.indexOf('#') === 0 ? id.slice(1) : id;
  20308. };
  20309. /**
  20310. * Doubles as the main function for users to create a player instance and also
  20311. * the main library object.
  20312. * The `videojs` function can be used to initialize or retrieve a player.
  20313. *
  20314. * @param {string|Element} id
  20315. * Video element or video element ID
  20316. *
  20317. * @param {Object} [options]
  20318. * Optional options object for config/settings
  20319. *
  20320. * @param {Component~ReadyCallback} [ready]
  20321. * Optional ready callback
  20322. *
  20323. * @return {Player}
  20324. * A player instance
  20325. */
  20326. function videojs(id, options, ready) {
  20327. var player = videojs.getPlayer(id);
  20328. if (player) {
  20329. if (options) {
  20330. log.warn('Player "' + id + '" is already initialised. Options will not be applied.');
  20331. }
  20332. if (ready) {
  20333. player.ready(ready);
  20334. }
  20335. return player;
  20336. }
  20337. var el = typeof id === 'string' ? $('#' + normalizeId(id)) : id;
  20338. if (!isEl(el)) {
  20339. throw new TypeError('The element or ID supplied is not valid. (videojs)');
  20340. }
  20341. if (!document.body.contains(el)) {
  20342. log.warn('The element supplied is not included in the DOM');
  20343. }
  20344. options = options || {};
  20345. videojs.hooks('beforesetup').forEach(function (hookFunction) {
  20346. var opts = hookFunction(el, mergeOptions(options));
  20347. if (!isObject(opts) || Array.isArray(opts)) {
  20348. log.error('please return an object in beforesetup hooks');
  20349. return;
  20350. }
  20351. options = mergeOptions(options, opts);
  20352. });
  20353. // We get the current "Player" component here in case an integration has
  20354. // replaced it with a custom player.
  20355. var PlayerComponent = Component.getComponent('Player');
  20356. player = new PlayerComponent(el, options, ready);
  20357. videojs.hooks('setup').forEach(function (hookFunction) {
  20358. return hookFunction(player);
  20359. });
  20360. return player;
  20361. }
  20362. /**
  20363. * An Object that contains lifecycle hooks as keys which point to an array
  20364. * of functions that are run when a lifecycle is triggered
  20365. */
  20366. videojs.hooks_ = {};
  20367. /**
  20368. * Get a list of hooks for a specific lifecycle
  20369. * @function videojs.hooks
  20370. *
  20371. * @param {string} type
  20372. * the lifecyle to get hooks from
  20373. *
  20374. * @param {Function|Function[]} [fn]
  20375. * Optionally add a hook (or hooks) to the lifecycle that your are getting.
  20376. *
  20377. * @return {Array}
  20378. * an array of hooks, or an empty array if there are none.
  20379. */
  20380. videojs.hooks = function (type, fn) {
  20381. videojs.hooks_[type] = videojs.hooks_[type] || [];
  20382. if (fn) {
  20383. videojs.hooks_[type] = videojs.hooks_[type].concat(fn);
  20384. }
  20385. return videojs.hooks_[type];
  20386. };
  20387. /**
  20388. * Add a function hook to a specific videojs lifecycle.
  20389. *
  20390. * @param {string} type
  20391. * the lifecycle to hook the function to.
  20392. *
  20393. * @param {Function|Function[]}
  20394. * The function or array of functions to attach.
  20395. */
  20396. videojs.hook = function (type, fn) {
  20397. videojs.hooks(type, fn);
  20398. };
  20399. /**
  20400. * Add a function hook that will only run once to a specific videojs lifecycle.
  20401. *
  20402. * @param {string} type
  20403. * the lifecycle to hook the function to.
  20404. *
  20405. * @param {Function|Function[]}
  20406. * The function or array of functions to attach.
  20407. */
  20408. videojs.hookOnce = function (type, fn) {
  20409. videojs.hooks(type, [].concat(fn).map(function (original) {
  20410. var wrapper = function wrapper() {
  20411. videojs.removeHook(type, wrapper);
  20412. return original.apply(undefined, arguments);
  20413. };
  20414. return wrapper;
  20415. }));
  20416. };
  20417. /**
  20418. * Remove a hook from a specific videojs lifecycle.
  20419. *
  20420. * @param {string} type
  20421. * the lifecycle that the function hooked to
  20422. *
  20423. * @param {Function} fn
  20424. * The hooked function to remove
  20425. *
  20426. * @return {boolean}
  20427. * The function that was removed or undef
  20428. */
  20429. videojs.removeHook = function (type, fn) {
  20430. var index = videojs.hooks(type).indexOf(fn);
  20431. if (index <= -1) {
  20432. return false;
  20433. }
  20434. videojs.hooks_[type] = videojs.hooks_[type].slice();
  20435. videojs.hooks_[type].splice(index, 1);
  20436. return true;
  20437. };
  20438. // Add default styles
  20439. if (window.VIDEOJS_NO_DYNAMIC_STYLE !== true && isReal()) {
  20440. var style = $('.vjs-styles-defaults');
  20441. if (!style) {
  20442. style = createStyleElement('vjs-styles-defaults');
  20443. var head = $('head');
  20444. if (head) {
  20445. head.insertBefore(style, head.firstChild);
  20446. }
  20447. setTextContent(style, '\n .video-js {\n width: 300px;\n height: 150px;\n }\n\n .vjs-fluid {\n padding-top: 56.25%\n }\n ');
  20448. }
  20449. }
  20450. // Run Auto-load players
  20451. // You have to wait at least once in case this script is loaded after your
  20452. // video in the DOM (weird behavior only with minified version)
  20453. autoSetupTimeout(1, videojs);
  20454. /**
  20455. * Current software version. Follows semver.
  20456. *
  20457. * @type {string}
  20458. */
  20459. videojs.VERSION = version;
  20460. /**
  20461. * The global options object. These are the settings that take effect
  20462. * if no overrides are specified when the player is created.
  20463. *
  20464. * @type {Object}
  20465. */
  20466. videojs.options = Player.prototype.options_;
  20467. /**
  20468. * Get an object with the currently created players, keyed by player ID
  20469. *
  20470. * @return {Object}
  20471. * The created players
  20472. */
  20473. videojs.getPlayers = function () {
  20474. return Player.players;
  20475. };
  20476. /**
  20477. * Get a single player based on an ID or DOM element.
  20478. *
  20479. * This is useful if you want to check if an element or ID has an associated
  20480. * Video.js player, but not create one if it doesn't.
  20481. *
  20482. * @param {string|Element} id
  20483. * An HTML element - `<video>`, `<audio>`, or `<video-js>` -
  20484. * or a string matching the `id` of such an element.
  20485. *
  20486. * @returns {Player|undefined}
  20487. * A player instance or `undefined` if there is no player instance
  20488. * matching the argument.
  20489. */
  20490. videojs.getPlayer = function (id) {
  20491. var players = Player.players;
  20492. var tag = void 0;
  20493. if (typeof id === 'string') {
  20494. var nId = normalizeId(id);
  20495. var player = players[nId];
  20496. if (player) {
  20497. return player;
  20498. }
  20499. tag = $('#' + nId);
  20500. } else {
  20501. tag = id;
  20502. }
  20503. if (isEl(tag)) {
  20504. var _tag = tag,
  20505. _player = _tag.player,
  20506. playerId = _tag.playerId;
  20507. // Element may have a `player` property referring to an already created
  20508. // player instance. If so, return that.
  20509. if (_player || players[playerId]) {
  20510. return _player || players[playerId];
  20511. }
  20512. }
  20513. };
  20514. /**
  20515. * Returns an array of all current players.
  20516. *
  20517. * @return {Array}
  20518. * An array of all players. The array will be in the order that
  20519. * `Object.keys` provides, which could potentially vary between
  20520. * JavaScript engines.
  20521. *
  20522. */
  20523. videojs.getAllPlayers = function () {
  20524. return (
  20525. // Disposed players leave a key with a `null` value, so we need to make sure
  20526. // we filter those out.
  20527. Object.keys(Player.players).map(function (k) {
  20528. return Player.players[k];
  20529. }).filter(Boolean)
  20530. );
  20531. };
  20532. /**
  20533. * Expose players object.
  20534. *
  20535. * @memberOf videojs
  20536. * @property {Object} players
  20537. */
  20538. videojs.players = Player.players;
  20539. /**
  20540. * Get a component class object by name
  20541. *
  20542. * @borrows Component.getComponent as videojs.getComponent
  20543. */
  20544. videojs.getComponent = Component.getComponent;
  20545. /**
  20546. * Register a component so it can referred to by name. Used when adding to other
  20547. * components, either through addChild `component.addChild('myComponent')` or through
  20548. * default children options `{ children: ['myComponent'] }`.
  20549. *
  20550. * > NOTE: You could also just initialize the component before adding.
  20551. * `component.addChild(new MyComponent());`
  20552. *
  20553. * @param {string} name
  20554. * The class name of the component
  20555. *
  20556. * @param {Component} comp
  20557. * The component class
  20558. *
  20559. * @return {Component}
  20560. * The newly registered component
  20561. */
  20562. videojs.registerComponent = function (name$$1, comp) {
  20563. if (Tech.isTech(comp)) {
  20564. log.warn('The ' + name$$1 + ' tech was registered as a component. It should instead be registered using videojs.registerTech(name, tech)');
  20565. }
  20566. Component.registerComponent.call(Component, name$$1, comp);
  20567. };
  20568. /**
  20569. * Get a Tech class object by name
  20570. *
  20571. * @borrows Tech.getTech as videojs.getTech
  20572. */
  20573. videojs.getTech = Tech.getTech;
  20574. /**
  20575. * Register a Tech so it can referred to by name.
  20576. * This is used in the tech order for the player.
  20577. *
  20578. * @borrows Tech.registerTech as videojs.registerTech
  20579. */
  20580. videojs.registerTech = Tech.registerTech;
  20581. /**
  20582. * Register a middleware to a source type.
  20583. *
  20584. * @param {String} type A string representing a MIME type.
  20585. * @param {function(player):object} middleware A middleware factory that takes a player.
  20586. */
  20587. videojs.use = use;
  20588. /**
  20589. * An object that can be returned by a middleware to signify
  20590. * that the middleware is being terminated.
  20591. *
  20592. * @type {object}
  20593. * @memberOf {videojs}
  20594. * @property {object} middleware.TERMINATOR
  20595. */
  20596. // Object.defineProperty is not available in IE8
  20597. if (!IS_IE8 && Object.defineProperty) {
  20598. Object.defineProperty(videojs, 'middleware', {
  20599. value: {},
  20600. writeable: false,
  20601. enumerable: true
  20602. });
  20603. Object.defineProperty(videojs.middleware, 'TERMINATOR', {
  20604. value: TERMINATOR,
  20605. writeable: false,
  20606. enumerable: true
  20607. });
  20608. } else {
  20609. videojs.middleware = { TERMINATOR: TERMINATOR };
  20610. }
  20611. /**
  20612. * A suite of browser and device tests from {@link browser}.
  20613. *
  20614. * @type {Object}
  20615. * @private
  20616. */
  20617. videojs.browser = browser;
  20618. /**
  20619. * Whether or not the browser supports touch events. Included for backward
  20620. * compatibility with 4.x, but deprecated. Use `videojs.browser.TOUCH_ENABLED`
  20621. * instead going forward.
  20622. *
  20623. * @deprecated since version 5.0
  20624. * @type {boolean}
  20625. */
  20626. videojs.TOUCH_ENABLED = TOUCH_ENABLED;
  20627. /**
  20628. * Subclass an existing class
  20629. * Mimics ES6 subclassing with the `extend` keyword
  20630. *
  20631. * @borrows extend:extendFn as videojs.extend
  20632. */
  20633. videojs.extend = extendFn;
  20634. /**
  20635. * Merge two options objects recursively
  20636. * Performs a deep merge like lodash.merge but **only merges plain objects**
  20637. * (not arrays, elements, anything else)
  20638. * Other values will be copied directly from the second object.
  20639. *
  20640. * @borrows merge-options:mergeOptions as videojs.mergeOptions
  20641. */
  20642. videojs.mergeOptions = mergeOptions;
  20643. /**
  20644. * Change the context (this) of a function
  20645. *
  20646. * > NOTE: as of v5.0 we require an ES5 shim, so you should use the native
  20647. * `function() {}.bind(newContext);` instead of this.
  20648. *
  20649. * @borrows fn:bind as videojs.bind
  20650. */
  20651. videojs.bind = bind;
  20652. /**
  20653. * Register a Video.js plugin.
  20654. *
  20655. * @borrows plugin:registerPlugin as videojs.registerPlugin
  20656. * @method registerPlugin
  20657. *
  20658. * @param {string} name
  20659. * The name of the plugin to be registered. Must be a string and
  20660. * must not match an existing plugin or a method on the `Player`
  20661. * prototype.
  20662. *
  20663. * @param {Function} plugin
  20664. * A sub-class of `Plugin` or a function for basic plugins.
  20665. *
  20666. * @return {Function}
  20667. * For advanced plugins, a factory function for that plugin. For
  20668. * basic plugins, a wrapper function that initializes the plugin.
  20669. */
  20670. videojs.registerPlugin = Plugin.registerPlugin;
  20671. /**
  20672. * Deregister a Video.js plugin.
  20673. *
  20674. * @borrows plugin:deregisterPlugin as videojs.deregisterPlugin
  20675. * @method deregisterPlugin
  20676. *
  20677. * @param {string} name
  20678. * The name of the plugin to be deregistered. Must be a string and
  20679. * must match an existing plugin or a method on the `Player`
  20680. * prototype.
  20681. *
  20682. */
  20683. videojs.deregisterPlugin = Plugin.deregisterPlugin;
  20684. /**
  20685. * Deprecated method to register a plugin with Video.js
  20686. *
  20687. * @deprecated
  20688. * videojs.plugin() is deprecated; use videojs.registerPlugin() instead
  20689. *
  20690. * @param {string} name
  20691. * The plugin name
  20692. *
  20693. * @param {Plugin|Function} plugin
  20694. * The plugin sub-class or function
  20695. */
  20696. videojs.plugin = function (name$$1, plugin) {
  20697. log.warn('videojs.plugin() is deprecated; use videojs.registerPlugin() instead');
  20698. return Plugin.registerPlugin(name$$1, plugin);
  20699. };
  20700. /**
  20701. * Gets an object containing multiple Video.js plugins.
  20702. *
  20703. * @param {Array} [names]
  20704. * If provided, should be an array of plugin names. Defaults to _all_
  20705. * plugin names.
  20706. *
  20707. * @return {Object|undefined}
  20708. * An object containing plugin(s) associated with their name(s) or
  20709. * `undefined` if no matching plugins exist).
  20710. */
  20711. videojs.getPlugins = Plugin.getPlugins;
  20712. /**
  20713. * Gets a plugin by name if it exists.
  20714. *
  20715. * @param {string} name
  20716. * The name of a plugin.
  20717. *
  20718. * @return {Function|undefined}
  20719. * The plugin (or `undefined`).
  20720. */
  20721. videojs.getPlugin = Plugin.getPlugin;
  20722. /**
  20723. * Gets a plugin's version, if available
  20724. *
  20725. * @param {string} name
  20726. * The name of a plugin.
  20727. *
  20728. * @return {string}
  20729. * The plugin's version or an empty string.
  20730. */
  20731. videojs.getPluginVersion = Plugin.getPluginVersion;
  20732. /**
  20733. * Adding languages so that they're available to all players.
  20734. * Example: `videojs.addLanguage('es', { 'Hello': 'Hola' });`
  20735. *
  20736. * @param {string} code
  20737. * The language code or dictionary property
  20738. *
  20739. * @param {Object} data
  20740. * The data values to be translated
  20741. *
  20742. * @return {Object}
  20743. * The resulting language dictionary object
  20744. */
  20745. videojs.addLanguage = function (code, data) {
  20746. var _mergeOptions;
  20747. code = ('' + code).toLowerCase();
  20748. videojs.options.languages = mergeOptions(videojs.options.languages, (_mergeOptions = {}, _mergeOptions[code] = data, _mergeOptions));
  20749. return videojs.options.languages[code];
  20750. };
  20751. /**
  20752. * Log messages
  20753. *
  20754. * @borrows log:log as videojs.log
  20755. */
  20756. videojs.log = log;
  20757. videojs.createLogger = createLogger;
  20758. /**
  20759. * Creates an emulated TimeRange object.
  20760. *
  20761. * @borrows time-ranges:createTimeRanges as videojs.createTimeRange
  20762. */
  20763. /**
  20764. * @borrows time-ranges:createTimeRanges as videojs.createTimeRanges
  20765. */
  20766. videojs.createTimeRange = videojs.createTimeRanges = createTimeRanges;
  20767. /**
  20768. * Format seconds as a time string, H:MM:SS or M:SS
  20769. * Supplying a guide (in seconds) will force a number of leading zeros
  20770. * to cover the length of the guide
  20771. *
  20772. * @borrows format-time:formatTime as videojs.formatTime
  20773. */
  20774. videojs.formatTime = formatTime;
  20775. /**
  20776. * Replaces format-time with a custom implementation, to be used in place of the default.
  20777. *
  20778. * @borrows format-time:setFormatTime as videojs.setFormatTime
  20779. *
  20780. * @method setFormatTime
  20781. *
  20782. * @param {Function} customFn
  20783. * A custom format-time function which will be called with the current time and guide (in seconds) as arguments.
  20784. * Passed fn should return a string.
  20785. */
  20786. videojs.setFormatTime = setFormatTime;
  20787. /**
  20788. * Resets format-time to the default implementation.
  20789. *
  20790. * @borrows format-time:resetFormatTime as videojs.resetFormatTime
  20791. *
  20792. * @method resetFormatTime
  20793. */
  20794. videojs.resetFormatTime = resetFormatTime;
  20795. /**
  20796. * Resolve and parse the elements of a URL
  20797. *
  20798. * @borrows url:parseUrl as videojs.parseUrl
  20799. *
  20800. */
  20801. videojs.parseUrl = parseUrl;
  20802. /**
  20803. * Returns whether the url passed is a cross domain request or not.
  20804. *
  20805. * @borrows url:isCrossOrigin as videojs.isCrossOrigin
  20806. */
  20807. videojs.isCrossOrigin = isCrossOrigin;
  20808. /**
  20809. * Event target class.
  20810. *
  20811. * @borrows EventTarget as videojs.EventTarget
  20812. */
  20813. videojs.EventTarget = EventTarget;
  20814. /**
  20815. * Add an event listener to element
  20816. * It stores the handler function in a separate cache object
  20817. * and adds a generic handler to the element's event,
  20818. * along with a unique id (guid) to the element.
  20819. *
  20820. * @borrows events:on as videojs.on
  20821. */
  20822. videojs.on = on;
  20823. /**
  20824. * Trigger a listener only once for an event
  20825. *
  20826. * @borrows events:one as videojs.one
  20827. */
  20828. videojs.one = one;
  20829. /**
  20830. * Removes event listeners from an element
  20831. *
  20832. * @borrows events:off as videojs.off
  20833. */
  20834. videojs.off = off;
  20835. /**
  20836. * Trigger an event for an element
  20837. *
  20838. * @borrows events:trigger as videojs.trigger
  20839. */
  20840. videojs.trigger = trigger;
  20841. /**
  20842. * A cross-browser XMLHttpRequest wrapper. Here's a simple example:
  20843. *
  20844. * @param {Object} options
  20845. * settings for the request.
  20846. *
  20847. * @return {XMLHttpRequest|XDomainRequest}
  20848. * The request object.
  20849. *
  20850. * @see https://github.com/Raynos/xhr
  20851. */
  20852. videojs.xhr = xhr;
  20853. /**
  20854. * TextTrack class
  20855. *
  20856. * @borrows TextTrack as videojs.TextTrack
  20857. */
  20858. videojs.TextTrack = TextTrack;
  20859. /**
  20860. * export the AudioTrack class so that source handlers can create
  20861. * AudioTracks and then add them to the players AudioTrackList
  20862. *
  20863. * @borrows AudioTrack as videojs.AudioTrack
  20864. */
  20865. videojs.AudioTrack = AudioTrack;
  20866. /**
  20867. * export the VideoTrack class so that source handlers can create
  20868. * VideoTracks and then add them to the players VideoTrackList
  20869. *
  20870. * @borrows VideoTrack as videojs.VideoTrack
  20871. */
  20872. videojs.VideoTrack = VideoTrack;
  20873. /**
  20874. * Determines, via duck typing, whether or not a value is a DOM element.
  20875. *
  20876. * @borrows dom:isEl as videojs.isEl
  20877. * @deprecated Use videojs.dom.isEl() instead
  20878. */
  20879. /**
  20880. * Determines, via duck typing, whether or not a value is a text node.
  20881. *
  20882. * @borrows dom:isTextNode as videojs.isTextNode
  20883. * @deprecated Use videojs.dom.isTextNode() instead
  20884. */
  20885. /**
  20886. * Creates an element and applies properties.
  20887. *
  20888. * @borrows dom:createEl as videojs.createEl
  20889. * @deprecated Use videojs.dom.createEl() instead
  20890. */
  20891. /**
  20892. * Check if an element has a CSS class
  20893. *
  20894. * @borrows dom:hasElClass as videojs.hasClass
  20895. * @deprecated Use videojs.dom.hasClass() instead
  20896. */
  20897. /**
  20898. * Add a CSS class name to an element
  20899. *
  20900. * @borrows dom:addElClass as videojs.addClass
  20901. * @deprecated Use videojs.dom.addClass() instead
  20902. */
  20903. /**
  20904. * Remove a CSS class name from an element
  20905. *
  20906. * @borrows dom:removeElClass as videojs.removeClass
  20907. * @deprecated Use videojs.dom.removeClass() instead
  20908. */
  20909. /**
  20910. * Adds or removes a CSS class name on an element depending on an optional
  20911. * condition or the presence/absence of the class name.
  20912. *
  20913. * @borrows dom:toggleElClass as videojs.toggleClass
  20914. * @deprecated Use videojs.dom.toggleClass() instead
  20915. */
  20916. /**
  20917. * Apply attributes to an HTML element.
  20918. *
  20919. * @borrows dom:setElAttributes as videojs.setAttribute
  20920. * @deprecated Use videojs.dom.setAttributes() instead
  20921. */
  20922. /**
  20923. * Get an element's attribute values, as defined on the HTML tag
  20924. * Attributes are not the same as properties. They're defined on the tag
  20925. * or with setAttribute (which shouldn't be used with HTML)
  20926. * This will return true or false for boolean attributes.
  20927. *
  20928. * @borrows dom:getElAttributes as videojs.getAttributes
  20929. * @deprecated Use videojs.dom.getAttributes() instead
  20930. */
  20931. /**
  20932. * Empties the contents of an element.
  20933. *
  20934. * @borrows dom:emptyEl as videojs.emptyEl
  20935. * @deprecated Use videojs.dom.emptyEl() instead
  20936. */
  20937. /**
  20938. * Normalizes and appends content to an element.
  20939. *
  20940. * The content for an element can be passed in multiple types and
  20941. * combinations, whose behavior is as follows:
  20942. *
  20943. * - String
  20944. * Normalized into a text node.
  20945. *
  20946. * - Element, TextNode
  20947. * Passed through.
  20948. *
  20949. * - Array
  20950. * A one-dimensional array of strings, elements, nodes, or functions (which
  20951. * return single strings, elements, or nodes).
  20952. *
  20953. * - Function
  20954. * If the sole argument, is expected to produce a string, element,
  20955. * node, or array.
  20956. *
  20957. * @borrows dom:appendContents as videojs.appendContet
  20958. * @deprecated Use videojs.dom.appendContent() instead
  20959. */
  20960. /**
  20961. * Normalizes and inserts content into an element; this is identical to
  20962. * `appendContent()`, except it empties the element first.
  20963. *
  20964. * The content for an element can be passed in multiple types and
  20965. * combinations, whose behavior is as follows:
  20966. *
  20967. * - String
  20968. * Normalized into a text node.
  20969. *
  20970. * - Element, TextNode
  20971. * Passed through.
  20972. *
  20973. * - Array
  20974. * A one-dimensional array of strings, elements, nodes, or functions (which
  20975. * return single strings, elements, or nodes).
  20976. *
  20977. * - Function
  20978. * If the sole argument, is expected to produce a string, element,
  20979. * node, or array.
  20980. *
  20981. * @borrows dom:insertContent as videojs.insertContent
  20982. * @deprecated Use videojs.dom.insertContent() instead
  20983. */
  20984. ['isEl', 'isTextNode', 'createEl', 'hasClass', 'addClass', 'removeClass', 'toggleClass', 'setAttributes', 'getAttributes', 'emptyEl', 'appendContent', 'insertContent'].forEach(function (k) {
  20985. videojs[k] = function () {
  20986. log.warn('videojs.' + k + '() is deprecated; use videojs.dom.' + k + '() instead');
  20987. return Dom[k].apply(null, arguments);
  20988. };
  20989. });
  20990. /**
  20991. * A safe getComputedStyle with an IE8 fallback.
  20992. *
  20993. * This is because in Firefox, if the player is loaded in an iframe with `display:none`,
  20994. * then `getComputedStyle` returns `null`, so, we do a null-check to make sure
  20995. * that the player doesn't break in these cases.
  20996. * See https://bugzilla.mozilla.org/show_bug.cgi?id=548397 for more details.
  20997. *
  20998. * @borrows computed-style:computedStyle as videojs.computedStyle
  20999. */
  21000. videojs.computedStyle = computedStyle;
  21001. /**
  21002. * Export the Dom utilities for use in external plugins
  21003. * and Tech's
  21004. */
  21005. videojs.dom = Dom;
  21006. /**
  21007. * Export the Url utilities for use in external plugins
  21008. * and Tech's
  21009. */
  21010. videojs.url = Url;
  21011. module.exports = videojs;