it('should add and remove className on element', () => { addClass(div, 'clazz clazz') expect(div.className).to.equal('clazz') addClass(div, 'clazz2') removeClass(div, 'clazz') expect(div.className).to.equal('clazz2') })
showMenu(evt) { // Offset relative to player element const off = this.getOffset(evt); this.el.style.left = off.x + 'px'; this.el.style.top = off.y + 'px'; this.outCount = 0; addClass(this.playerElement, 'jw-flag-rightclick-open'); addClass(this.el, 'jw-open'); clearTimeout(this._menuTimeout); this._menuTimeout = setTimeout(() => this.hideMenu(), 3000); return false; }
beforeEach(function () { testDiv = document.createElement("div"); document.body.appendChild(testDiv); var videoEl = document.createElement('video'); testDiv.appendChild(videoEl); player = videojs(videoEl, {}); dom.addClass(player.el(), 'vjs-test-player'); vpaidAdUnit = { 'handshakeVersion': utilities.noop, 'initAd': utilities.noop, 'startAd': utilities.noop, 'stopAd': utilities.noop, 'skipAd': utilities.noop, 'resizeAd': utilities.noop, 'pauseAd': utilities.noop, 'expandAd': utilities.noop, 'collapseAd': utilities.noop, 'subscribe': utilities.noop, 'unsubscribe': utilities.noop, 'unloadAdUnit': utilities.noop, 'on': sinon.spy() }; adUnitWrapper = new VPAIDAdUnitWrapper(vpaidAdUnit, {responseTimeout: 5000}); });
const setupInstream = function() { addClass(_playerElement, 'jw-flag-ads'); if (_controls) { _controls.setupInstream(); } };
this.removeControls = function () { if (_controls) { _controls.disable(_model); _controls = null; } addClass(_playerElement, 'jw-flag-controls-hidden'); };
toggleIdleClass(oldState, newState, idleButton) { if (!(idleButton === 'stroke' || idleButton === 'fill')) { return; } if (oldState === 'idle') { removeClass(this.icon, 'jw-ab-idle-' + idleButton); } else if (newState === 'idle') { addClass(this.icon, 'jw-ab-idle-' + idleButton); } }
export function SimpleTooltip(attachToElement, name, text, openCallback, closeCallback) { const tooltipElement = document.createElement('div'); tooltipElement.className = `jw-reset jw-tooltip jw-tooltip-${name}`; const textElement = document.createElement('div'); textElement.className = 'jw-text'; textElement.textContent = text; tooltipElement.appendChild(textElement); attachToElement.appendChild(tooltipElement); const instance = { open() { if (instance.touchEvent) { return; } tooltipElement.setAttribute('aria-expanded', 'true'); addClass(tooltipElement, 'jw-open'); if (openCallback) { openCallback(); } }, close() { if (instance.touchEvent) { return; } tooltipElement.setAttribute('aria-expanded', 'false'); removeClass(tooltipElement, 'jw-open'); if (closeCallback) { closeCallback(); } }, setText(newText) { tooltipElement.querySelector('.jw-text').textContent = newText; } }; attachToElement.addEventListener('mouseover', instance.open); attachToElement.addEventListener('focus', instance.open); attachToElement.addEventListener('blur', instance.close); attachToElement.addEventListener('mouseout', instance.close); attachToElement.addEventListener('touchstart', () => { instance.touchEvent = true; }, { passive: true }); return instance; }
it("must not set the style and the native poster if there is no tech", function () { dom.removeClass(tech, 'vjs-tech');//We remove the so the method can not find the tech var snapshot = playerUtils.getPlayerSnapshot(player); assert.deepEqual(snapshot, { ended: false, src: "http://vjs.zencdn.net/v/oceans.mp4", currentTime: 0, type: 'video/mp4', playing: false, suppressedTracks: [] }); dom.addClass(tech, 'vjs-tech'); });
_onorientationchange: function(){ var body = document.body; if(window.orientation === 180 || window.orientation === 0){ // alert("竖屏状态!"); Dom.addClass(body, 'vertical'); Dom.removeClass(body, 'horizontal'); } if(window.orientation === 90 || window.orientation === -90){ // alert("横屏状态!"); Dom.addClass(body, 'horizontal'); Dom.removeClass(body, 'vertical'); } //PC端木有orientation if(window.orientation === undefined){ if(window.innerHeight < window.innerWidth){ Dom.addClass(body, 'horizontal'); Dom.removeClass(body, 'vertical'); }else{ Dom.addClass(body, 'vertical'); Dom.removeClass(body, 'horizontal'); } } }
this.removeControls = function () { _logo.setContainer(_playerElement); if (_controls) { _controls.removeActiveListeners(_logo.element()); _controls.disable(_model); _controls = null; } const overlay = document.querySelector('.jw-overlays'); if (overlay) { overlay.removeEventListener('mousemove', _userActivityCallback); } addClass(_playerElement, 'jw-flag-controls-hidden'); };
this.setup = function () { _preview.setup(_playerElement.querySelector('.jw-preview')); _title.setup(_playerElement.querySelector('.jw-title')); _logo = new Logo(_model); _logo.setup(); _logo.setContainer(_playerElement); _logo.on(LOGO_CLICK, _logoClickHandler); // captions rendering _captionsRenderer.setup(_playerElement.id, _model.get('captions')); // captions should be placed behind controls, and not hidden when controls are hidden _playerElement.insertBefore(_captionsRenderer.element(), _title.element()); // Display Click and Double Click Handling displayClickHandler = clickHandlerHelper(_api, _model, _videoLayer); focusHelper = flagNoFocus(_playerElement); fullscreenHelpers = requestFullscreenHelper(_playerElement, document, _fullscreenChangeHandler); _model.on('change:hideAdsControls', function (model, val) { toggleClass(_playerElement, 'jw-flag-ads-hide-controls', val); }); _model.on('change:scrubbing', function (model, val) { toggleClass(_playerElement, 'jw-flag-dragging', val); }); _model.on('change:playRejected', function (model, val) { toggleClass(_playerElement, 'jw-flag-play-rejected', val); }); // Native fullscreen (coming through from the provider) _model.on(NATIVE_FULLSCREEN, _fullscreenChangeHandler); _model.on(`change:${MEDIA_VISUAL_QUALITY}`, () => { _resizeMedia(); }); const playerViewModel = _model.player; playerViewModel.on('change:errorEvent', _errorHandler); _model.on('change:mediaType', _onMediaTypeChange); _model.change('stretching', onStretchChange); _model.change('flashBlocked', onFlashBlockedChange); const width = _model.get('width'); const height = _model.get('height'); _resizePlayer(width, height); _model.change('aspectratio', onAspectRatioChange); if (_model.get('controls')) { updateContainerStyles(width, height); } else { addClass(_playerElement, 'jw-flag-controls-hidden'); } if (_isIE) { addClass(_playerElement, 'jw-ie'); } const skin = _model.get('skin') || {}; if (skin.name) { replaceClass(_playerElement, /jw-skin-\S+/, 'jw-skin-' + skin.name); } const skinColors = normalizeSkin(skin); handleColorOverrides(_model.get('id'), skinColors); // adds video tag to video layer _model.set('mediaContainer', _videoLayer); _model.set('iFrame', Features.iframe); _model.set('activeTab', activeTab()); _model.set('touchMode', _isMobile && (typeof height === 'string' || height >= CONTROLBAR_ONLY_HEIGHT)); viewsManager.add(this); this.isSetup = true; _model.trigger('viewSetup', _playerElement); const inDOM = document.body.contains(_playerElement); if (inDOM) { viewsManager.observe(_playerElement); } _model.set('inDom', inDOM); };
it("must not hide the blackPoster if is already hidden", function () { dom.addClass(blackPoster.el(), 'vjs-hidden'); player.trigger('vast.adStart'); player.trigger('vast.adsCancel'); sinon.assert.notCalled(blackPoster.hide); });
this.show = function () { addClass(_display, 'jw-captions-enabled'); };
const onMouseDown = function () { _focusFromClick = true; addClass(elementContext, 'jw-no-focus'); };