r56198 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56197‎ | r56198 | r56199 >
Date:18:19, 11 September 2009
Author:catrope
Status:ok
Tags:
Comment:
EditToolbar: Automatically resize dialogs to fit their content without breaking lines. This doesn't work perfectly yet, but it's pretty close.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.dialogs.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js
@@ -936,7 +936,6 @@
937937 });
938938 },
939939 dialog: {
940 - width: 550, // FIXME: autoresize width
941940 buttons: {
942941 'edittoolbar-tool-link-insert': function() {
943942 function escapeInternalText( s ) {
@@ -1069,7 +1068,6 @@
10701069 $j( '#edittoolbar-table-dimensions-columns' ).val( 2 );
10711070 },
10721071 dialog: {
1073 - width: 350, // FIXME: autoresize
10741072 buttons: {
10751073 'edittoolbar-tool-table-insert': function() {
10761074 var rows = parseInt( $j( '#edittoolbar-table-dimensions-rows' ).val() );
@@ -1139,7 +1137,6 @@
11401138 });
11411139 },
11421140 dialog: {
1143 - width: 350, // FIXME: autoresize width
11441141 buttons: {
11451142 'edittoolbar-tool-replace-button': function() {
11461143 var searchStr = $j( '#edittoolbar-replace-search' ).val();
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.dialogs.js
@@ -67,9 +67,51 @@
6868 .data( 'context', context )
6969 .appendTo( $( 'body' ) )
7070 .each( module.init )
71 - .dialog( configuration );
 71+ .dialog( configuration )
 72+ .bind( 'dialogopen', $.wikiEditor.modules.dialogs.fn.resize )
 73+ .find( '.ui-tabs' ).bind( 'tabsshow', function() {
 74+ $(this).closest( '.ui-dialog-content' ).each(
 75+ $.wikiEditor.modules.dialogs.fn.resize );
 76+ });
7277 }
7378 }
 79+ },
 80+
 81+ /**
 82+ * Resize a dialog so its contents fit
 83+ *
 84+ * Usage: dialog.each( resize ); or dialog.bind( 'blah', resize );
 85+ */
 86+ resize: function() {
 87+ var wrapper = $(this).closest( '.ui-dialog' );
 88+ // Make sure elements don't wrapped so we get an accurate idea
 89+ // of whether they really fit. Also temporarily show hidden
 90+ // elements.
 91+
 92+ // Work around jQuery bug where <div style="display:inline;" />
 93+ // inside a dialog is both :visible and :hidden
 94+ var oldHidden = $(this).find( '*' ).not( ':visible' );
 95+
 96+ // Save the style attributes of the hidden elements to restore
 97+ // them later. Calling hide() after show() messes up for
 98+ // elements hidden with a class
 99+ oldHidden.each( function() {
 100+ $(this).data( 'oldstyle', $(this).attr( 'style' ) );
 101+ });
 102+ oldHidden.show();
 103+ var oldWS = $(this).css( 'white-space' );
 104+ $(this).css( 'white-space', 'nowrap' );
 105+
 106+ if ( wrapper.width() <= $(this).get(0).scrollWidth ) {
 107+ $(this).width( $(this).get(0).scrollWidth );
 108+ wrapper.width( wrapper.get(0).scrollWidth );
 109+ $(this).dialog( { 'width': wrapper.width() } );
 110+ }
 111+
 112+ $(this).css( 'white-space', oldWS );
 113+ oldHidden.each( function() {
 114+ $(this).attr( 'style', $(this).data( 'oldstyle' ) );
 115+ });
74116 }
75117 },
76118 'modules': {}

Status & tagging log