Skip to content

Commit

Permalink
Merge branch '1.7' into 1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
andrerom committed Oct 19, 2017
2 parents 8b0177d + d53cab0 commit fbf6c16
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 42 deletions.
22 changes: 13 additions & 9 deletions Resources/public/js/views/fields/ez-media-editview.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ YUI.add('ez-media-editview', function (Y) {

/**
* Sets the event handler on the video/audio element to handle the
* *being updated* state, the width/height placeholder and a potential
* *being updated* state, the width/height field value and a potential
* file format error
*
* @method _watchPlayerEvents
Expand All @@ -74,7 +74,9 @@ YUI.add('ez-media-editview', function (Y) {

this._attachedViewEvents.push(player.on('loadedmetadata', function () {
container.removeClass(IS_BEING_UPDATED);
that._updateWidthHeightPlaceholder(player.get('videoWidth'), player.get('videoHeight'));
if (!that.get('width') || !that.get('height')) {
that._updateWidthHeightFieldValue(player.get('videoWidth'), player.get('videoHeight'));
}
}));
this._attachedViewEvents.push(player.on('error', function () {
container.removeClass(IS_BEING_UPDATED);
Expand All @@ -83,26 +85,28 @@ YUI.add('ez-media-editview', function (Y) {
},

/**
* Sets the placeholder attribute on the width and height input with the
* Sets the value on the width and height input with the
* given values
*
* @method _updateWidthHeightPlaceholder
* @method _updateWidthHeightFieldValue
* @param {String|Number} widthValue
* @param {String|Number} heightValue
*/
_updateWidthHeightPlaceholder: function (widthValue, heightValue) {
_updateWidthHeightFieldValue: function (widthValue, heightValue) {
var container = this.get('container'),
width = container.one('input[name=width]'),
height = container.one('input[name=height]');

if ( width && height ) {
width.setAttribute('placeholder', widthValue);
height.setAttribute('placeholder', heightValue);
width.setAttribute('value', widthValue);
height.setAttribute('value', heightValue);
this._set('width', widthValue);
this._set('height', heightValue);
}
},

/**
* Adds the unsupported class and resets the width/height placeholder
* Adds the unsupported class and resets the width/height field value
* when the file can not read by the browser
*
* @method _mediaError
Expand All @@ -112,7 +116,7 @@ YUI.add('ez-media-editview', function (Y) {
var error = player.get('error');

if ( error && error.code === error.MEDIA_ERR_SRC_NOT_SUPPORTED ) {
this._updateWidthHeightPlaceholder("", "");
this._updateWidthHeightFieldValue("", "");
this.get('container').addClass(IS_UNSUPPORTED);
}
},
Expand Down
36 changes: 3 additions & 33 deletions Tests/js/views/fields/assets/ez-media-editview-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,13 +802,11 @@ YUI.add('ez-media-editview-tests', function (Y) {
"Should track the loadedmetadata event": function () {
var c = this.view.get('container'),
videoWidth = 200, videoHeight = 100,
video, width, height;
video;

this.view.render();

video = c.one('.ez-media-player');
width = c.one('input[name=width]');
height = c.one('input[name=height]');
video.getDOMNode().videoWidth = videoWidth;
video.getDOMNode().videoHeight = videoHeight;
c.addClass('is-media-being-updated');
Expand All @@ -817,14 +815,6 @@ YUI.add('ez-media-editview-tests', function (Y) {
c.hasClass('is-media-being-updated'),
"The 'is-media-being-updated' class should be removed from the container"
);
Assert.areEqual(
videoWidth, width.getAttribute('placeholder'),
"The width input should have the placeholder attribute filled with the video width"
);
Assert.areEqual(
videoHeight, height.getAttribute('placeholder'),
"The height input should have the placeholder attribute filled with the video height"
);
},

"Should track the loadedmetadata event (audio)": function () {
Expand All @@ -845,12 +835,10 @@ YUI.add('ez-media-editview-tests', function (Y) {

"Should track the error event": function () {
var c = this.view.get('container'),
video, width, height;
video;

this["Should track the loadedmetadata event"]();
video = c.one('.ez-media-player');
width = c.one('input[name=width]');
height = c.one('input[name=height]');

c.addClass('is-media-being-updated');
video.getDOMNode().error = {
Expand All @@ -867,14 +855,6 @@ YUI.add('ez-media-editview-tests', function (Y) {
c.hasClass('is-media-unsupported'),
"The 'is-media-unsupported' class should be added on the container"
);
Assert.areEqual(
"", width.getAttribute('placeholder'),
"The width placeholder should be empty"
);
Assert.areEqual(
"", height.getAttribute('placeholder'),
"The height placeholder should be empty"
);
},

"Should track the error event (audio)": function () {
Expand All @@ -901,12 +881,10 @@ YUI.add('ez-media-editview-tests', function (Y) {

"Should ignore error other than unsupported file format": function () {
var c = this.view.get('container'),
video, width, height;
video;

this["Should track the loadedmetadata event"]();
video = c.one('.ez-media-player');
width = c.one('input[name=width]');
height = c.one('input[name=height]');

c.addClass('is-media-being-updated');
video.getDOMNode().error = {
Expand All @@ -923,14 +901,6 @@ YUI.add('ez-media-editview-tests', function (Y) {
c.hasClass('is-media-unsupported'),
"The 'is-media-unsupported' class should not be added on the container"
);
Assert.areNotEqual(
"", width.getAttribute('placeholder'),
"The width placeholder should be kept"
);
Assert.areNotEqual(
"", height.getAttribute('placeholder'),
"The height placeholder should be kept"
);
},
});

Expand Down

0 comments on commit fbf6c16

Please sign in to comment.