r83124 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83123‎ | r83124 | r83125 >
Date:23:17, 2 March 2011
Author:foxtrott
Status:deferred
Tags:
Comment:
improved autosizing of popup form
Modified paths:
  • /trunk/extensions/SemanticForms/libs/SF_popupform.js (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/libs/SF_popupform.js
@@ -57,15 +57,18 @@
5858 var background;
5959 var container;
6060 var iframe;
 61+ var content;
6162 var waitIndicator;
6263 var instance = 0;
6364
6465 var doc;
65 - var docWidth;
66 - var docHeight;
 66+// var docW;
 67+// var docH;
6768
6869 var brokenBrowser, brokenChrome;
6970
 71+ var padding = 20;
 72+
7073 function handlePopupFormInput( ptarget, elem ) {
7174
7275 showForm();
@@ -204,7 +207,7 @@
205208 container.show();
206209
207210 // GuMaxDD has #content but keeps headlines in #gumax-content-body
208 - var content = iframecontents.find("#gumax-content-body");
 211+ content = iframecontents.find("#gumax-content-body");
209212
210213 // normal skins use #content (e.g. Vector, Monobook)
211214 if ( content.length == 0 ) content = iframecontents.find("#content");
@@ -220,11 +223,12 @@
221224 var siblings = content
222225 .css( {
223226 margin: 0,
224 - padding: "1em",
 227+ padding: padding,
225228 width: "auto",
226229 height: "auto",
227230 minWidth: "0px",
228 - minHeight:"0px"
 231+ minHeight:"0px",
 232+ overflow: "visible"
229233 } )
230234 .parents().css( {
231235 margin: 0,
@@ -232,7 +236,8 @@
233237 width: "auto",
234238 height: "auto",
235239 minWidth: "0px",
236 - minHeight:"0px"
 240+ minHeight:"0px",
 241+ overflow: "visible"
237242 })
238243 .andSelf().siblings();
239244
@@ -276,37 +281,15 @@
277282 //.children().css("position", "static");
278283 }
279284
280 - // find content document
281 - doc = iframe[0].contentWindow || iframe[0].contentDocument;
 285+// // find content document
 286+// doc = iframe[0].contentWindow || iframe[0].contentDocument;
 287+//
 288+// if (doc.document) {
 289+// doc = doc.document;
 290+// }
282291
283 - if (doc.document) {
284 - doc = doc.document;
285 - }
 292+ container.show();
286293
287 - // first try if the content enforces its dimensions (e.g. GuMaxDD)
288 - docWidth = content.outerWidth(true);
289 - docHeight = content.outerHeight(true);
290 -
291 - // then try if it grows to its dimensions given enough space (e.g. Vector)
292 - var origPos = content[0].style.position;
293 - content[0].style.position = "fixed";
294 -
295 - if ( content.outerWidth(true) > docWidth || content.outerHeight(true) > docHeight ) {
296 - docWidth = content.outerWidth(true);
297 - docHeight = content.outerHeight(true);
298 - }
299 -
300 - content[0].style.position = origPos;
301 -
302 - // default for broken browsers
303 - if ( docWidth == 0 || docHeight == 0 ) {
304 -
305 - docWidth = jQuery(window).width();
306 - docHeight = jQuery(window).height();
307 -
308 - }
309 -
310 -
311294 // adjust frame size to dimensions just calculated
312295 adjustFrameSize();
313296
@@ -465,46 +448,109 @@
466449
467450 function adjustFrameSize() {
468451
469 - var availW = jQuery(window).width();
470 - var availH = jQuery(window).height();
 452+ // Inputs
471453
472 - var w, h;
 454+ var availW = Math.floor( jQuery(window).width() * .8 );
 455+ var availH = Math.floor( jQuery(window).height() * .8 );
473456
474 - // Standard max height/width is 80% of viewport, but we will allow
475 - // up to 85% to avoid scrollbars with nearly nothing to scroll
476 - if ( docWidth > availW * .85 || docHeight > availH * .85 ) {
 457+ var emergencyW = Math.floor( jQuery(window).width() * .85 );
 458+ var emergencyH = Math.floor( jQuery(window).height() * .85 );
477459
478 - iframe[0].style.overflow = "auto";
 460+ // FIXME: these might not be the true values
 461+ var scrollW = 20;
 462+ var scrollH = 20;
479463
480 - // For now, just ignore docWidth and docHeight - at
481 - // least on Vector, they're getting set to values
482 - // that are far too small.
483 - // TODO: fix this
484 - //if ( docWidth > availW * .85 ) {
485 - w = ( availW * .8 );
486 - //} else {
487 - // w = docWidth + 20;
488 - //}
489464
490 - //if ( docHeight > availH * .85 ) {
491 - h = ( availH * .8 );
492 - //} else {
493 - // h = docHeight + 20;
494 - //}
 465+ // find the dimensions of the document
495466
 467+ // set max dimensions for layout of content
 468+ container
 469+ .width( emergencyW )
 470+ .height( emergencyH );
 471+
 472+ var origPos = content[0].style.position; // save original positioning
 473+ content[0].style.position = "fixed";
 474+
 475+ // initiate layout
 476+ content
 477+ .width( 'auto' )
 478+ .height( 'auto' );
 479+
 480+ // get dimension values
 481+ var docW = content.width();
 482+ var docH = content.height();
 483+
 484+ var docpW = docW + 2 * padding;
 485+ var docpH = docH + 2 * padding;
 486+
 487+ content[0].style.position = origPos; // reset original positioning
 488+
 489+ // Flags
 490+
 491+ var needsHScroll = docpW > emergencyW || ( docpW > emergencyW - scrollW && docpH > emergencyH );
 492+ var needsVScroll = docpH > emergencyH || ( docpH > emergencyH - scrollH && docpW > emergencyW );
 493+
 494+ var needsWStretch =
 495+ ( docpW > availW && docpW <= emergencyW ) && ( docpH <= emergencyH ) ||
 496+ ( docpW > availW - scrollW && docpW <= emergencyW - scrollW ) && ( docpH > emergencyH );
 497+
 498+ var needsHStretch =
 499+ ( docpH > availH && docpH <= emergencyH ) && ( docpW <= emergencyW ) ||
 500+ ( docpH > availH - scrollH && docpH <= emergencyH - scrollH ) && ( docpW > emergencyW );
 501+
 502+ // Outputs
 503+
 504+ var frameW;
 505+ var frameH;
 506+
 507+ var contW;
 508+ var contH;
 509+
 510+ if ( needsWStretch ) {
 511+ contW = docW;
 512+ frameW = docpW;
 513+ } else if ( docpW > availW ) { // form does not even fit with stretching
 514+ contW = docW;
 515+ frameW = availW;
496516 } else {
497 - iframe[0].style.overflow = "hidden";
498 - w = docWidth;
499 - h = docHeight;
 517+ //contW = Math.max( Math.min( 1.5 * docW, availW ), availW / 2 );
 518+ contW = docW;
 519+ frameW = docpW;
500520 }
501521
 522+ if ( needsVScroll ){
 523+ frameW += scrollW;
 524+ }
 525+
 526+ if ( needsHStretch ) {
 527+ contH = docH;
 528+ frameH = docpH;
 529+ } else if ( docpH > availH ) { // form does not even fit with stretching
 530+ contH = docH;
 531+ frameH = availH;
 532+ } else {
 533+ //contH = Math.min( 1.1 * docH, availH);
 534+ contH = docH;
 535+ frameH = docpH;
 536+ }
 537+
 538+ if ( needsHScroll ){
 539+ frameH += scrollH;
 540+ }
 541+
502542 with ( container[0].style ) {
503 - width = ( w ) + "px";
504 - height = ( h ) + "px";
505 - top = (( - h ) / 2) + "px";
506 - left = (( - w ) / 2) + "px";
507 - }
 543+ top = (( - frameH ) / 2) + "px";
 544+ left = (( - frameW ) / 2) + "px";
 545+ }
508546
 547+ container
 548+ .width( frameW )
 549+ .height ( frameH )
 550+
 551+ content
 552+ .width ( contW )
 553+ .height ( contH );
 554+
509555 }
510556
511557 function closeFrameAndFollowLink( link ){