Attachment 'autoscroll.diff'

Download

   1 # HG changeset patch
   2 # User Roger Haase <crosseyedpenquin@yahoo.com>
   3 # Date 1279902239 25200
   4 # Node ID 08c781f306fc09e467b4ab1363eac42be155f1c6
   5 # Parent  58a9aa0d67bd0175b761e0e6c321ab8d08a9ff4f
   6 simplify auto scroll initialization; fix bug in IE init discovered when using IE7 on pages with wide tables
   7 
   8 diff -r 58a9aa0d67bd -r 08c781f306fc MoinMoin/web/static/htdocs/common/js/common.js
   9 --- a/MoinMoin/web/static/htdocs/common/js/common.js	Mon Jul 05 23:21:21 2010 +0000
  10 +++ b/MoinMoin/web/static/htdocs/common/js/common.js	Fri Jul 23 09:23:59 2010 -0700
  11 @@ -655,6 +655,7 @@
  12  
  13  // run during page load when user may edit current page OR is viewing draft preview
  14  function setSpanTags(isPreview) {
  15 +    var startTime = new Date();
  16      // find all the SPAN tags with an ID beginning with "line-"
  17      var spanTags = document.getElementsByTagName('span');
  18      var marks = [];
  19 @@ -679,7 +680,7 @@
  20          var mark = marks[i];
  21          // skip span tags generated by embedded parsers
  22          if (i > skipTo) {
  23 -            // split the ID into parts: looks line "line-22" or "line-22-1"
  24 +            // split the ID into parts: looks like "line-22" or "line-22-1"
  25              var lineParts = mark.id.split('-');
  26              var line = lineParts[1];
  27              if (lineParts.length == 3) {
  28 @@ -716,11 +717,12 @@
  29              }
  30          }
  31      }
  32 -    if (autoScrollDebugOn)  {
  33 +    if (autoScrollDebugOn && document.getElementById('content'))  {
  34          for (i = 0; i < marks.length-1; ++i) {
  35              marks[i].innerHTML = ' ' + marks[i].id + ' ';
  36              marks[i].style. color = "red";
  37          }
  38 +        showStartStopTimes(startTime);
  39      }
  40  }
  41  
  42 @@ -749,54 +751,33 @@
  43      }
  44  }
  45  
  46 -// Now to resolve the problem of how to best execute scrollTextareaInit
  47 -// -- We want to run as soon as DOM is loaded, perhaps many seconds before last big image is loaded
  48 -// -- If we wait for body.onload, the user may see and doubleclick on text before we are ready 
  49 -// -- If every browser supported DOMContentLoaded, we could do:
  50 -//         document.addEventListener("DOMContentLoaded", scrollTextareaInit, false);
  51 -// -- If we had jQuery, we could do:
  52 -//         jQuery(scrollTextareaInit);
  53 -// -- Another possibility is to add a bit of script near the end of the mypage.HTML, hoping the DOM is ready
  54 -//         '<script type="text/javascript" language="javascript">scrollTextareaInit()</script>'
  55 -// -- Our choice is to speed up most current browsers and do slow but sure for the rest:
  56 -
  57 -// run scrollTextareaInit one time;  this function will be called twice for almost all browsers,
  58 -scrollTextareaInitComplete = 0;
  59 -function runScrollTextareaInitOnce() {
  60 -    // uncomment next line to test - most browsers will display this alert twice 
  61 -    //~ alert('scrollTextareaInitComplete=' + scrollTextareaInitComplete);
  62 -    if (scrollTextareaInitComplete) {
  63 -        return;
  64 -    }
  65 -    scrollTextareaInitComplete = 1;
  66 -    var startTime = new Date();
  67 +// The DOM ready check for Internet Explorer
  68 +function ieScrollCheck() {
  69 +	try {
  70 +		// If IE is used, use the trick by Diego Perini
  71 +		document.documentElement.doScroll("left");
  72 +	} catch( error ) {
  73 +		setTimeout( ieScrollCheck, 1 );
  74 +		return;
  75 +	}
  76      scrollTextareaInit();
  77 -    if (autoScrollDebugOn && document.getElementById('content')) {
  78 -        showStartStopTimes(startTime);
  79 -    }
  80  }
  81  
  82 -// speed up most browsers -- run my function As Soon As Possible
  83 -function runASAP(func) {
  84 +// run auto scroll init As Soon As Possible -- prior to onload for modern browsers
  85 +function runASAP() {
  86      if (document.addEventListener) { 
  87          // Firefox 3.6, Chrome 4.0.249.89, Safari for Windows 4.04, Opera 10.5beta, and maybe older versions
  88 -        // schedule func to be run when DOM complete
  89 -        document.addEventListener("DOMContentLoaded", func, false);
  90 +        // schedule func to be run when DOM complete, usually before last image loaded
  91 +        document.addEventListener("DOMContentLoaded", scrollTextareaInit, false);
  92      } else {
  93 -        // trick discovered by Diego Perini to test for IE DOM complete
  94          if (document.documentElement.doScroll && window == window.top) {
  95 -            try {
  96 -                document.documentElement.doScroll("left");
  97 -                // DOM is complete; run func now
  98 -                func();
  99 -            } catch(e) {
 100 -                // wait and try again
 101 -                setTimeout(arguments.callee, 1);
 102 -            }
 103 +            // IE 5-8 and not using frames
 104 +            ieScrollCheck();
 105 +        } else {
 106 +            addLoadEvent(scrollTextareaInit);
 107          }
 108      }
 109  }
 110 -runASAP(runScrollTextareaInitOnce);
 111 -// ensure init will be run by obsolete browsers
 112 -addLoadEvent(runScrollTextareaInitOnce);
 113 +// auto scroll initialization starts here
 114 +runASAP();
 115  

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2010-07-23 17:38:15, 4.7 KB) [[attachment:autoscroll.diff]]
  • [get | view] (2010-07-23 17:37:35, 27.2 KB) [[attachment:common.js]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.