Skip to content
This repository was archived by the owner on Sep 23, 2023. It is now read-only.

Use ES6 classes for custom OOUI widgets #561

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions js/DetailsFieldLayout.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
window.DetailsFieldLayout = function DetailsFieldLayout( fieldWidget, config ) {
// Allow passing positional parameters inside the config object
if ( OO.isPlainObject( fieldWidget ) && config === undefined ) {
config = fieldWidget;
fieldWidget = config.fieldWidget;
}
window.DetailsFieldLayout = class DetailsFieldLayout extends OO.ui.FieldLayout {
constructor( fieldWidget, config ) {
// Allow passing positional parameters inside the config object
if ( OO.isPlainObject( fieldWidget ) && config === undefined ) {
config = fieldWidget;
fieldWidget = config.fieldWidget;
}

config = config || {};
config = config || {};

// Parent constructor
window.DetailsFieldLayout.super.call( this, fieldWidget, $.extend( {}, config, {
// <summary> tag is no longer clickable if there's a <label> inside,
// use a <span> instead
$label: $( '<span>' )
} ) );
// Parent constructor
super( fieldWidget, $.extend( {}, config, {
// <summary> tag is no longer clickable if there's a <label> inside,
// use a <span> instead
$label: $( '<span>' )
} ) );

// HACK: Replace header with an identical <summary> tag
// and body with an identical <details> tag
this.$body.detach();
// HACK: Replace header with an identical <summary> tag
// and body with an identical <details> tag
this.$body.detach();

this.$header = $( '<summary>' );
this.$header.addClass( 'oo-ui-fieldLayout-header' );
this.$body = $( '<details>' );
this.$body.addClass( 'oo-ui-fieldLayout-body' );
// This adds the content back
this.align = null;
this.setAlignment( config.align );
this.$header = $( '<summary>' );
this.$header.addClass( 'oo-ui-fieldLayout-header' );
this.$body = $( '<details>' );
this.$body.addClass( 'oo-ui-fieldLayout-body' );
// This adds the content back
this.align = null;
this.setAlignment( config.align );

this.$element.append( this.$body );
this.$element.append( this.$body );
}
};

OO.inheritClass( window.DetailsFieldLayout, OO.ui.FieldLayout );
Loading