jenkins-bot has submitted this change and it was merged. Change subject: SelectFileWidget: Fix drop and drop hover exception in Firefox ......................................................................
SelectFileWidget: Fix drop and drop hover exception in Firefox dt.types.indexOf doesn't work because dt.types is only Array-like. Bonus: refactor code and comments for clarity. Change-Id: Ib20625a7160456b36e77e7a905fc2f5ad3ae39d2 --- M src/widgets/SelectFileWidget.js 1 file changed, 17 insertions(+), 17 deletions(-) Approvals: Jforrester: Looks good to me, approved jenkins-bot: Verified diff --git a/src/widgets/SelectFileWidget.js b/src/widgets/SelectFileWidget.js index ac8945b..4419f85 100644 --- a/src/widgets/SelectFileWidget.js +++ b/src/widgets/SelectFileWidget.js @@ -312,7 +312,8 @@ * @param {jQuery.Event} e Drag event */ OO.ui.SelectFileWidget.prototype.onDragEnterOrOver = function ( e ) { - var file = null, + var file, + droppableFile = false, dt = e.originalEvent.dataTransfer; e.preventDefault(); @@ -325,23 +326,22 @@ return false; } - if ( dt && dt.files && dt.files[ 0 ] ) { - file = dt.files[ 0 ]; - if ( !this.isFileAcceptable( file ) ) { - file = null; - } - } else if ( dt && dt.types && dt.types.indexOf( 'Files' ) !== -1 ) { - // We know we have files so set 'file' to something truthy, we just - // can't know any details about them. - // * https://bugzilla.mozilla.org/show_bug.cgi?id=640534 - file = 'Files exist, but details are unknown'; - } + file = OO.getProp( dt, 'files', 0 ); if ( file ) { - this.$element.addClass( 'oo-ui-selectFileWidget-canDrop' ); - this.setActive( true ); - } else { - this.$element.removeClass( 'oo-ui-selectFileWidget-canDrop' ); - this.setActive( false ); + if ( this.isFileAcceptable( file ) ) { + droppableFile = true; + } + // dt.types is Array-like, but not an Array + } else if ( Array.prototype.indexOf.call( OO.getProp( dt, 'types' ) || [], 'Files' ) !== -1 ) { + // File information is not available at this point for security so just assume + // it is acceptable for now. + // https://bugzilla.mozilla.org/show_bug.cgi?id=640534 + droppableFile = true; + } + + this.$element.toggleClass( 'oo-ui-selectFileWidget-canDrop', droppableFile ); + this.setActive( droppableFile ); + if ( !droppableFile ) { dt.dropEffect = 'none'; } -- To view, visit https://gerrit.wikimedia.org/r/234529 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib20625a7160456b36e77e7a905fc2f5ad3ae39d2 Gerrit-PatchSet: 3 Gerrit-Project: oojs/ui Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits