Files
esun3d/app/code/Esun/Video/view/frontend/web/js/load-player-html5-mixin.js
2026-09-15 10:35:56 +08:00

35 lines
1.3 KiB
JavaScript

define(['jquery'], function ($) {
'use strict';
return function (Widget) {
Widget = Widget || ($.mage && $.mage.productVideoLoader);
if (!Widget || !Widget.prototype || Widget.prototype._esunHtml5VideoPatched) {
return Widget;
}
var originalCreate = Widget.prototype._create;
Widget.prototype._esunHtml5VideoPatched = true;
Widget.prototype._create = function () {
var video;
if (this.element.data('type') !== 'html5') {
return originalCreate.apply(this, arguments);
}
video = $('<video controls autoplay playsinline></video>').attr('src', this.element.data('code'));
if (this.element.data('loop')) {
video.attr('loop', 'loop');
}
this.element.empty().append(video).addClass('responsive');
this.element.closest('.fotorama__stage__frame').addClass('fotorama__product-video--loaded');
this._player = {
play: function () { video.get(0).play(); },
pause: function () { video.get(0).pause(); },
stop: function () { video.get(0).pause(); video.get(0).currentTime = 0; },
playing: function () { return !video.get(0).paused; }
};
};
return Widget;
};
});