<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[29523] trunk/src/wp-admin/js: Editor scrolling:</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/29523">29523</a></dd>
<dt>Author</dt> <dd>azaozz</dd>
<dt>Date</dt> <dd>2014-08-18 00:34:45 +0000 (Mon, 18 Aug 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Editor scrolling:
- Properly handle change of sidebar height when opening, closing or hiding postboxes.
- Add a flag when to start pinning. Set it to few pixels more than the initial editor height.
See <a href="http://core.trac.wordpress.org/ticket/28328">#28328</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminjseditorexpandjs">trunk/src/wp-admin/js/editor-expand.js</a></li>
<li><a href="#trunksrcwpadminjspostboxjs">trunk/src/wp-admin/js/postbox.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminjseditorexpandjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/js/editor-expand.js (29522 => 29523)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/js/editor-expand.js   2014-08-17 21:32:10 UTC (rev 29522)
+++ trunk/src/wp-admin/js/editor-expand.js      2014-08-18 00:34:45 UTC (rev 29523)
</span><span class="lines">@@ -226,13 +226,13 @@
</span><span class="cx">                  adminBarHeight = windowWidth > 600 ? $adminBar.height() : 0,
</span><span class="cx">                  resize = type !== 'scroll',
</span><span class="cx">                  visual = ( mceEditor && ! mceEditor.isHidden() ),
</span><del>-                       buffer = autoresizeMinHeight + adminBarHeight,
</del><ins>+                        buffer = autoresizeMinHeight,
</ins><span class="cx">                   postBodyTop = $postBody.offset().top,
</span><span class="cx">                  borderWidth = 1,
</span><span class="cx">                  contentWrapWidth = $contentWrap.width(),
</span><span class="cx">                  sideSortablesHeight = $sideSortables.height(),
</span><del>-                       $top, $editor, sidebarTop, footerTop,
-                       toolsHeight, topPos, topHeight, editorPos, editorHeight, editorWidth, statusBarHeight;
</del><ins>+                        $top, $editor, sidebarTop, footerTop, canPin,
+                       toolsHeight, topPos, topHeight, editorPos, editorHeight, statusBarHeight;
</ins><span class="cx"> 
</span><span class="cx">          if ( visual ) {
</span><span class="cx">                  $top = $visualTop;
</span><span class="lines">@@ -247,37 +247,14 @@
</span><span class="cx">          topHeight = $top.outerHeight();
</span><span class="cx">          editorPos = $editor.offset().top;
</span><span class="cx">          editorHeight = $editor.outerHeight();
</span><del>-               editorWidth = $editor.outerWidth();
</del><span class="cx">           statusBarHeight = visual ? $statusBar.outerHeight() : 0;
</span><span class="cx"> 
</span><ins>+               // Should we pin?
+               canPin = visual ? autoresizeMinHeight + topHeight : autoresizeMinHeight + 20; // 20px from textarea padding
+               canPin = editorHeight > ( canPin + 5 );
</ins><span class="cx"> 
</span><del>-               // Maybe pin the top.
-               if ( ( ! fixedTop || resize ) &&
-                       // Handle scrolling down.
-                       ( windowPos >= ( topPos - toolsHeight - adminBarHeight ) &&
-                       // Handle scrolling up.
-                       windowPos <= ( topPos - toolsHeight - adminBarHeight + editorHeight - buffer ) ) ) {
-
-                       fixedTop = true;
-
-                       $top.css( {
-                               position: 'fixed',
-                               top: adminBarHeight + toolsHeight,
-                               width: contentWrapWidth - ( borderWidth * 2 ) - ( visual ? 0 : ( $top.outerWidth() - $top.width() ) ),
-                               borderTop: '1px solid #e5e5e5'
-                       } );
-
-                       $tools.css( {
-                               position: 'fixed',
-                               top: adminBarHeight,
-                               width: contentWrapWidth
-                       } );
-               // Maybe unpin the top.
-               } else if ( fixedTop || resize ) {
-                       // Handle scrolling up.
-                       if ( windowPos <= ( topPos - toolsHeight -  adminBarHeight ) ) {
-                               fixedTop = false;
-
</del><ins>+                if ( ! canPin ) {
+                       if ( resize ) {
</ins><span class="cx">                           $top.css( {
</span><span class="cx">                                  position: 'absolute',
</span><span class="cx">                                  top: 0,
</span><span class="lines">@@ -290,53 +267,102 @@
</span><span class="cx">                                  top: 0,
</span><span class="cx">                                  width: contentWrapWidth
</span><span class="cx">                          } );
</span><del>-                       // Handle scrolling down.
-                       } else if ( windowPos >= ( topPos - toolsHeight - adminBarHeight + editorHeight - buffer ) ) {
-                               fixedTop = false;
</del><span class="cx"> 
</span><ins>+                               $bottom.css( {
+                                       position: 'relative',
+                                       bottom: 'auto',
+                                       width: '100%',
+                                       borderTop: 'none'
+                               } );
+                       }
+               } else {
+                       // Maybe pin the top.
+                       if ( ( ! fixedTop || resize ) &&
+                               // Handle scrolling down.
+                               ( windowPos >= ( topPos - toolsHeight - adminBarHeight ) &&
+                               // Handle scrolling up.
+                               windowPos <= ( topPos - toolsHeight - adminBarHeight + editorHeight - buffer ) ) ) {
+
+                               fixedTop = true;
+
</ins><span class="cx">                           $top.css( {
</span><del>-                                       position: 'absolute',
-                                       top: editorHeight - buffer,
-                                       width: contentWrapWidth - ( borderWidth * 2 ) - ( visual ? 0 : ( $top.outerWidth() - $top.width() ) )
</del><ins>+                                        position: 'fixed',
+                                       top: adminBarHeight + toolsHeight,
+                                       width: contentWrapWidth - ( borderWidth * 2 ) - ( visual ? 0 : ( $top.outerWidth() - $top.width() ) ),
+                                       borderTop: '1px solid #e5e5e5'
</ins><span class="cx">                           } );
</span><span class="cx"> 
</span><span class="cx">                          $tools.css( {
</span><del>-                                       position: 'absolute',
-                                       top: editorHeight - buffer + borderWidth, // border
</del><ins>+                                        position: 'fixed',
+                                       top: adminBarHeight,
</ins><span class="cx">                                   width: contentWrapWidth
</span><span class="cx">                          } );
</span><ins>+                       // Maybe unpin the top.
+                       } else if ( fixedTop || resize ) {
+                               // Handle scrolling up.
+                               if ( windowPos <= ( topPos - toolsHeight - adminBarHeight ) ) {
+                                       fixedTop = false;
+
+                                       $top.css( {
+                                               position: 'absolute',
+                                               top: 0,
+                                               borderTop: 'none',
+                                               width: contentWrapWidth - ( borderWidth * 2 ) - ( visual ? 0 : ( $top.outerWidth() - $top.width() ) )
+                                       } );
+
+                                       $tools.css( {
+                                               position: 'absolute',
+                                               top: 0,
+                                               width: contentWrapWidth
+                                       } );
+                               // Handle scrolling down.
+                               } else if ( windowPos >= ( topPos - toolsHeight - adminBarHeight + editorHeight - buffer ) ) {
+                                       fixedTop = false;
+
+                                       $top.css( {
+                                               position: 'absolute',
+                                               top: editorHeight - buffer,
+                                               width: contentWrapWidth - ( borderWidth * 2 ) - ( visual ? 0 : ( $top.outerWidth() - $top.width() ) )
+                                       } );
+
+                                       $tools.css( {
+                                               position: 'absolute',
+                                               top: editorHeight - buffer + borderWidth, // border
+                                               width: contentWrapWidth
+                                       } );
+                               }
</ins><span class="cx">                   }
</span><del>-               }
</del><span class="cx"> 
</span><del>-               // Maybe adjust the bottom bar.
-               if ( ( ! fixedBottom || resize ) &&
-                       // +[n] for the border around the .wp-editor-container.
-                       ( windowPos + windowHeight ) <= ( editorPos + editorHeight + bottomHeight + statusBarHeight + borderWidth ) ) {
</del><ins>+                        // Maybe adjust the bottom bar.
+                       if ( ( ! fixedBottom || resize ) &&
+                               // +[n] for the border around the .wp-editor-container.
+                               ( windowPos + windowHeight ) <= ( editorPos + editorHeight + bottomHeight + statusBarHeight + borderWidth ) ) {
</ins><span class="cx"> 
</span><del>-                       fixedBottom = true;
</del><ins>+                                fixedBottom = true;
</ins><span class="cx"> 
</span><del>-                       $bottom.css( {
-                               position: 'fixed',
-                               bottom: 0,
-                               width: editorWidth + ( borderWidth * 2 ),
-                               borderTop: '1px solid #dedede'
-                       } );
-               } else if ( ( fixedBottom || resize ) &&
-                               ( windowPos + windowHeight ) > ( editorPos + editorHeight + bottomHeight + statusBarHeight - borderWidth ) ) {
-                       fixedBottom = false;
</del><ins>+                                $bottom.css( {
+                                       position: 'fixed',
+                                       bottom: 0,
+                                       width: contentWrapWidth,
+                                       borderTop: '1px solid #dedede'
+                               } );
+                       } else if ( ( fixedBottom || resize ) &&
+                                       ( windowPos + windowHeight ) > ( editorPos + editorHeight + bottomHeight + statusBarHeight - borderWidth ) ) {
+                               fixedBottom = false;
</ins><span class="cx"> 
</span><del>-                       $bottom.css( {
-                               position: 'relative',
-                               bottom: 'auto',
-                               width: '100%',
-                               borderTop: 'none'
-                       } );
</del><ins>+                                $bottom.css( {
+                                       position: 'relative',
+                                       bottom: 'auto',
+                                       width: '100%',
+                                       borderTop: 'none'
+                               } );
+                       }
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          // Sidebar pinning
</span><span class="cx">          if ( $postboxContainer.width() < 300 && windowWidth > 600 && // sidebar position is changed with @media from CSS, make sure it is on the side
</span><span class="cx">                  $document.height() > ( $sideSortables.height() + postBodyTop + 120 ) && // the sidebar is not the tallest element
</span><del>-                       windowHeight < editorHeight * 0.7 ) { // the editor is taller than the viewport
</del><ins>+                        windowHeight < editorHeight ) { // the editor is taller than the viewport
</ins><span class="cx"> 
</span><span class="cx">                  if ( sideSortablesHeight > windowHeight || fixedSideTop || fixedSideBottom ) {
</span><span class="cx">                          // Reset when scrolling to the top
</span><span class="lines">@@ -454,7 +480,7 @@
</span><span class="cx"> 
</span><span class="cx">  function afterScroll() {
</span><span class="cx">          clearTimeout( scrollTimer );
</span><del>-               scrollTimer = setTimeout( adjust, 200 );
</del><ins>+                scrollTimer = setTimeout( adjust, 100 );
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  function on() {
</span><span class="lines">@@ -473,8 +499,18 @@
</span><span class="cx">          } );
</span><span class="cx"> 
</span><span class="cx">          // Adjust when collapsing the menu, changing the columns, changing the body class.
</span><del>-               $document.on( 'wp-collapse-menu.editor-expand postboxes-columnchange.editor-expand editor-classchange.editor-expand', adjust );
</del><ins>+                $document.on( 'wp-collapse-menu.editor-expand postboxes-columnchange.editor-expand editor-classchange.editor-expand', adjust )
+                       .on( 'postbox-toggled.editor-expand', function() {
+                               if ( ! fixedSideTop && ! fixedSideBottom && window.pageYOffset > 20 ) {
+                                       fixedSideBottom = true;
+                                       window.scrollBy( 0, -1 );
+                                       adjust();
+                                       window.scrollBy( 0, 1 );
+                               }
</ins><span class="cx"> 
</span><ins>+                               adjust();
+                       });
+
</ins><span class="cx">           $textEditor.on( 'focus.editor-expand input.editor-expand propertychange.editor-expand', textEditorResize );
</span><span class="cx">          $textEditor.on( 'keyup.editor-expand', textEditorKeyup );
</span><span class="cx">          mceBind();
</span><span class="lines">@@ -509,14 +545,9 @@
</span><span class="cx"> 
</span><span class="cx">          $wrap.removeClass( 'wp-editor-expand' );
</span><span class="cx"> 
</span><del>-               // Adjust when the window is scrolled or resized.
-               $window.off( 'scroll.editor-expand resize.editor-expand' );
-
-               // Adjust when collapsing the menu, changing the columns, changing the body class.
-               $document.off( 'wp-collapse-menu.editor-expand postboxes-columnchange.editor-expand editor-classchange.editor-expand', adjust );
-
-               $textEditor.off( 'focus.editor-expand input.editor-expand propertychange.editor-expand', textEditorResize );
-               $textEditor.off( 'keyup.editor-expand', textEditorKeyup );
</del><ins>+                $window.off( '.editor-expand' );
+               $document.off( '.editor-expand' );
+               $textEditor.off( '.editor-expand' );
</ins><span class="cx">           mceUnbind();
</span><span class="cx"> 
</span><span class="cx">          // Adjust when entering/exiting fullscreen mode.
</span></span></pre></div>
<a id="trunksrcwpadminjspostboxjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/js/postbox.js (29522 => 29523)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/js/postbox.js 2014-08-17 21:32:10 UTC (rev 29522)
+++ trunk/src/wp-admin/js/postbox.js    2014-08-18 00:34:45 UTC (rev 29523)
</span><span class="lines">@@ -3,6 +3,8 @@
</span><span class="cx"> var postboxes;
</span><span class="cx"> 
</span><span class="cx"> (function($) {
</span><ins>+       var $document = $( document );
+
</ins><span class="cx">   postboxes = {
</span><span class="cx">          add_postbox_toggles : function(page, args) {
</span><span class="cx">                  var self = this;
</span><span class="lines">@@ -26,6 +28,8 @@
</span><span class="cx">                                  else if ( p.hasClass('closed') && $.isFunction(postboxes.pbhide) )
</span><span class="cx">                                          self.pbhide(id);
</span><span class="cx">                          }
</span><ins>+
+                               $document.trigger( 'postbox-toggled', p );
</ins><span class="cx">                   });
</span><span class="cx"> 
</span><span class="cx">                  $('.postbox .hndle a').click( function(e) {
</span><span class="lines">@@ -39,19 +43,21 @@
</span><span class="cx">                  });
</span><span class="cx"> 
</span><span class="cx">                  $('.hide-postbox-tog').bind('click.postboxes', function() {
</span><del>-                               var box = $(this).val();
</del><ins>+                                var boxId = $(this).val(),
+                                       $postbox = $( '#' + boxId );
</ins><span class="cx"> 
</span><span class="cx">                          if ( $(this).prop('checked') ) {
</span><del>-                                       $('#' + box).show();
</del><ins>+                                        $postbox.show();
</ins><span class="cx">                                   if ( $.isFunction( postboxes.pbshow ) )
</span><span class="cx">                                          self.pbshow( box );
</span><span class="cx">                          } else {
</span><del>-                                       $('#' + box).hide();
</del><ins>+                                        $postbox.hide();
</ins><span class="cx">                                   if ( $.isFunction( postboxes.pbhide ) )
</span><span class="cx">                                          self.pbhide( box );
</span><span class="cx">                          }
</span><span class="cx">                          self.save_state(page);
</span><span class="cx">                          self._mark_area();
</span><ins>+                               $document.trigger( 'postbox-toggled', $postbox );
</ins><span class="cx">                   });
</span><span class="cx"> 
</span><span class="cx">                  $('.columns-prefs input[type="radio"]').bind('click.postboxes', function(){
</span></span></pre>
</div>
</div>

</body>
</html>