Merge branch 'MDL-74113-master' of https://github.com/HuongNV13/moodle

This commit is contained in:
Víctor Déniz 2022-04-04 19:20:44 +01:00
commit bcb7b5b838
4 changed files with 132 additions and 3 deletions

View File

@ -459,6 +459,12 @@ Y.namespace('M.atto_media').Button = Y.Base.create('button', Y.M.editor_atto.Edi
this.editor.delegate('dblclick', this._displayDialogue, 'video', this);
this.editor.delegate('click', this._handleClick, 'video', this);
// For some reason, clicking the video on Firefox does not trigger the click event, while in Chrome it does.
// We also need to handle the play/pause instead.
this._attachPlayPauseEvents();
var changeHandler = this._attachPlayPauseEvents.bind(this);
this.get('host').on('change', changeHandler, null);
this.addButton({
icon: 'e/insert_edit_video',
callback: this._displayDialogue,
@ -468,6 +474,26 @@ Y.namespace('M.atto_media').Button = Y.Base.create('button', Y.M.editor_atto.Edi
}
},
/**
* Attaches Play/Pause events to the video nodes.
*
* @private
*/
_attachPlayPauseEvents: function() {
if (this._handlePlayEndBound === undefined) {
this._handlePlayEndBound = this._handlePlayEnd.bind(this);
}
var videos = this.editor.getDOMNode().querySelectorAll('video');
videos.forEach(function(video) {
// Prevent duplicated event listeners.
video.removeEventListener('play', this._handlePlayEndBound);
video.removeEventListener('pause', this._handlePlayEndBound);
// Add event listeners.
video.addEventListener('play', this._handlePlayEndBound);
video.addEventListener('pause', this._handlePlayEndBound);
}.bind(this));
},
/**
* Gets the root context for all templates, with extra supplied context.
*
@ -503,6 +529,23 @@ Y.namespace('M.atto_media').Button = Y.Base.create('button', Y.M.editor_atto.Edi
}
},
/**
* Handles a play/end on a media element.
*
* @method _handlePlayEnd
* @param {Event} e
* @private
*/
_handlePlayEnd: function(e) {
var medium = Y.one(e.target);
var selection = this.get('host').getSelectionFromNode(medium);
if (this.get('host').getSelection() !== selection) {
this.get('host').setSelection(selection);
this.get('host')._hasSelectionChanged(e);
}
},
/**
* Display the media editing tool.
*

File diff suppressed because one or more lines are too long

View File

@ -459,6 +459,12 @@ Y.namespace('M.atto_media').Button = Y.Base.create('button', Y.M.editor_atto.Edi
this.editor.delegate('dblclick', this._displayDialogue, 'video', this);
this.editor.delegate('click', this._handleClick, 'video', this);
// For some reason, clicking the video on Firefox does not trigger the click event, while in Chrome it does.
// We also need to handle the play/pause instead.
this._attachPlayPauseEvents();
var changeHandler = this._attachPlayPauseEvents.bind(this);
this.get('host').on('change', changeHandler, null);
this.addButton({
icon: 'e/insert_edit_video',
callback: this._displayDialogue,
@ -468,6 +474,26 @@ Y.namespace('M.atto_media').Button = Y.Base.create('button', Y.M.editor_atto.Edi
}
},
/**
* Attaches Play/Pause events to the video nodes.
*
* @private
*/
_attachPlayPauseEvents: function() {
if (this._handlePlayEndBound === undefined) {
this._handlePlayEndBound = this._handlePlayEnd.bind(this);
}
var videos = this.editor.getDOMNode().querySelectorAll('video');
videos.forEach(function(video) {
// Prevent duplicated event listeners.
video.removeEventListener('play', this._handlePlayEndBound);
video.removeEventListener('pause', this._handlePlayEndBound);
// Add event listeners.
video.addEventListener('play', this._handlePlayEndBound);
video.addEventListener('pause', this._handlePlayEndBound);
}.bind(this));
},
/**
* Gets the root context for all templates, with extra supplied context.
*
@ -503,6 +529,23 @@ Y.namespace('M.atto_media').Button = Y.Base.create('button', Y.M.editor_atto.Edi
}
},
/**
* Handles a play/end on a media element.
*
* @method _handlePlayEnd
* @param {Event} e
* @private
*/
_handlePlayEnd: function(e) {
var medium = Y.one(e.target);
var selection = this.get('host').getSelectionFromNode(medium);
if (this.get('host').getSelection() !== selection) {
this.get('host').setSelection(selection);
this.get('host')._hasSelectionChanged(e);
}
},
/**
* Display the media editing tool.
*

View File

@ -457,6 +457,12 @@ Y.namespace('M.atto_media').Button = Y.Base.create('button', Y.M.editor_atto.Edi
this.editor.delegate('dblclick', this._displayDialogue, 'video', this);
this.editor.delegate('click', this._handleClick, 'video', this);
// For some reason, clicking the video on Firefox does not trigger the click event, while in Chrome it does.
// We also need to handle the play/pause instead.
this._attachPlayPauseEvents();
var changeHandler = this._attachPlayPauseEvents.bind(this);
this.get('host').on('change', changeHandler, null);
this.addButton({
icon: 'e/insert_edit_video',
callback: this._displayDialogue,
@ -466,6 +472,26 @@ Y.namespace('M.atto_media').Button = Y.Base.create('button', Y.M.editor_atto.Edi
}
},
/**
* Attaches Play/Pause events to the video nodes.
*
* @private
*/
_attachPlayPauseEvents: function() {
if (this._handlePlayEndBound === undefined) {
this._handlePlayEndBound = this._handlePlayEnd.bind(this);
}
var videos = this.editor.getDOMNode().querySelectorAll('video');
videos.forEach(function(video) {
// Prevent duplicated event listeners.
video.removeEventListener('play', this._handlePlayEndBound);
video.removeEventListener('pause', this._handlePlayEndBound);
// Add event listeners.
video.addEventListener('play', this._handlePlayEndBound);
video.addEventListener('pause', this._handlePlayEndBound);
}.bind(this));
},
/**
* Gets the root context for all templates, with extra supplied context.
*
@ -501,6 +527,23 @@ Y.namespace('M.atto_media').Button = Y.Base.create('button', Y.M.editor_atto.Edi
}
},
/**
* Handles a play/end on a media element.
*
* @method _handlePlayEnd
* @param {Event} e
* @private
*/
_handlePlayEnd: function(e) {
var medium = Y.one(e.target);
var selection = this.get('host').getSelectionFromNode(medium);
if (this.get('host').getSelection() !== selection) {
this.get('host').setSelection(selection);
this.get('host')._hasSelectionChanged(e);
}
},
/**
* Display the media editing tool.
*