1 Demo.PopupButtonWidgetTest = function DemoPopupButtonWidgetTest( config ) {
2 Demo.PopupButtonWidgetTest.parent.call( this, config );
4 OO.inheritClass( Demo.PopupButtonWidgetTest, OO.ui.ProcessDialog );
5 Demo.PopupButtonWidgetTest.static.title = 'PopupButtonWidget test';
6 Demo.PopupButtonWidgetTest.static.actions = [
7 { action: 'save', label: 'Done', flags: [ 'primary', 'progressive' ] },
8 { action: 'cancel', label: 'Cancel', flags: [ 'safe', 'back' ] }
10 Demo.PopupButtonWidgetTest.prototype.initialize = function () {
11 Demo.PopupButtonWidgetTest.parent.prototype.initialize.apply( this, arguments );
13 this.panel = new OO.ui.PanelLayout( {
18 this.$center = $( '<td>' ).attr( { colspan: 3, rowspan: 3 } );
20 this.toggleOverlayWidget = new OO.ui.ToggleSwitchWidget( { value: true } );
21 this.toggleAnchorWidget = new OO.ui.ToggleSwitchWidget( { value: true } );
22 this.showAllWidget = new OO.ui.ButtonWidget( { label: 'Toggle all' } );
24 this.toggleOverlayWidget.connect( this, { change: 'makeTable' } );
25 this.toggleAnchorWidget.connect( this, { change: 'makeTable' } );
26 this.showAllWidget.connect( this, { click: 'toggleAll' } );
28 this.fieldset = new OO.ui.FieldsetLayout( {
30 new OO.ui.FieldLayout( this.toggleAnchorWidget, {
32 label: 'Enable anchors'
34 new OO.ui.FieldLayout( this.toggleOverlayWidget, {
38 new OO.ui.FieldLayout( this.showAllWidget, {
44 this.$center.append( this.fieldset.$element );
48 this.$body.append( this.panel.$element );
50 Demo.PopupButtonWidgetTest.prototype.makeContents = function () {
51 var loremIpsum = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' +
52 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\u200E';
54 .add( $( '<p>' ).text( loremIpsum ) )
55 .add( $( '<p>' ).text( loremIpsum ) )
56 .add( $( '<p>' ).text( loremIpsum ) );
58 Demo.PopupButtonWidgetTest.prototype.makeTable = function () {
64 this.$table = $( '<table>' ).append(
67 $( '<td>' ).append( this.getButton( 'above', 'backwards' ).$element ),
68 $( '<td>' ).append( this.getButton( 'above', 'center' ).$element ),
69 $( '<td>' ).append( this.getButton( 'above', 'forwards' ).$element ),
73 $( '<td>' ).append( this.getButton( 'before', 'backwards' ).$element ),
75 $( '<td>' ).append( this.getButton( 'after', 'backwards' ).$element ).css( 'text-align', this.getDir() === 'rtl' ? 'left' : 'right' )
78 $( '<td>' ).append( this.getButton( 'before', 'center' ).$element ),
79 $( '<td>' ).append( this.getButton( 'after', 'center' ).$element ).css( 'text-align', this.getDir() === 'rtl' ? 'left' : 'right' )
82 $( '<td>' ).append( this.getButton( 'before', 'forwards' ).$element ),
83 $( '<td>' ).append( this.getButton( 'after', 'forwards' ).$element ).css( 'text-align', this.getDir() === 'rtl' ? 'left' : 'right' )
87 $( '<td>' ).append( this.getButton( 'below', 'backwards' ).$element ),
88 $( '<td>' ).append( this.getButton( 'below', 'center' ).$element ),
89 $( '<td>' ).append( this.getButton( 'below', 'forwards' ).$element ),
93 this.panel.$element.append( this.$table );
95 Demo.PopupButtonWidgetTest.prototype.getButton = function ( position, align ) {
96 var button = new OO.ui.PopupButtonWidget( {
97 $overlay: ( this.toggleOverlayWidget.getValue() ? this.$overlay : null ),
98 label: $( '<span>' ).append( position + '<br>' + align ),
102 anchor: this.toggleAnchorWidget.getValue(),
104 $content: this.makeContents()
108 this.buttons.push( button );
111 Demo.PopupButtonWidgetTest.prototype.toggleAll = function () {
112 this.buttons.forEach( function ( button ) {
113 button.getPopup().toggle();
116 Demo.PopupButtonWidgetTest.prototype.getActionProcess = function ( action ) {
118 return new OO.ui.Process( function () {
119 this.close( { action: action } );
122 return Demo.PopupButtonWidgetTest.parent.prototype.getActionProcess.call( this, action );