<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[16479] trunk: Internal linking cleanups.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/16479">16479</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2010-11-19 05:31:07 +0000 (Fri, 19 Nov 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Internal linking cleanups. Fix combination of pagination and searching. Add a margin of error (ha, get it?) to triggering the river. props koopersmith, see <a href="http://trac.wordpress.org/ticket/11420">#11420</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminadminajaxphp">trunk/wp-admin/admin-ajax.php</a></li>
<li><a href="#trunkwpadminincludesinternallinkingphp">trunk/wp-admin/includes/internal-linking.php</a></li>
<li><a href="#trunkwpincludesjstinymcepluginswplinkcsswplinkcss">trunk/wp-includes/js/tinymce/plugins/wplink/css/wplink.css</a></li>
<li><a href="#trunkwpincludesjstinymcepluginswplinkcsswplinkdevcss">trunk/wp-includes/js/tinymce/plugins/wplink/css/wplink.dev.css</a></li>
<li><a href="#trunkwpincludesjstinymcepluginswplinkjswplinkdevjs">trunk/wp-includes/js/tinymce/plugins/wplink/js/wplink.dev.js</a></li>
<li><a href="#trunkwpincludesjstinymcepluginswplinkjswplinkjs">trunk/wp-includes/js/tinymce/plugins/wplink/js/wplink.js</a></li>
<li><a href="#trunkwpincludesscriptloaderphp">trunk/wp-includes/script-loader.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminadminajaxphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/admin-ajax.php (16478 => 16479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/admin-ajax.php        2010-11-19 05:06:48 UTC (rev 16478)
+++ trunk/wp-admin/admin-ajax.php        2010-11-19 05:31:07 UTC (rev 16479)
</span><span class="lines">@@ -1078,8 +1078,8 @@
</span><span class="cx"> 
</span><span class="cx">         $args = array();
</span><span class="cx"> 
</span><del>-        if ( isset( $_POST['title'] ) )
-                $args['s'] = stripslashes( $_POST['title'] );
</del><ins>+        if ( isset( $_POST['search'] ) )
+                $args['s'] = stripslashes( $_POST['search'] );
</ins><span class="cx">         $args['pagenum'] = ! empty( $_POST['page'] ) ? absint( $_POST['page'] ) : 1;
</span><span class="cx"> 
</span><span class="cx">         $results = wp_link_query( $args );
</span></span></pre></div>
<a id="trunkwpadminincludesinternallinkingphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/internal-linking.php (16478 => 16479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/internal-linking.php        2010-11-19 05:06:48 UTC (rev 16478)
+++ trunk/wp-admin/includes/internal-linking.php        2010-11-19 05:31:07 UTC (rev 16479)
</span><span class="lines">@@ -94,29 +94,14 @@
</span><span class="cx">                         &lt;/label&gt;
</span><span class="cx">                 &lt;/div&gt;
</span><span class="cx">                 &lt;div id=&quot;search-results&quot; class=&quot;query-results&quot;&gt;
</span><del>-                        &lt;ul&gt;
-                                &lt;li class=&quot;loading-results unselectable&quot;&gt;&lt;em&gt;&lt;?php _e( 'Loading...' ); ?&gt;&lt;/em&gt;&lt;/li&gt;
-                        &lt;/ul&gt;
</del><ins>+                        &lt;ul&gt;&lt;/ul&gt;
</ins><span class="cx">                         &lt;div class=&quot;river-waiting&quot;&gt;
</span><span class="cx">                                 &lt;img class=&quot;waiting&quot; src=&quot;&lt;?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?&gt;&quot; alt=&quot;&quot; /&gt;
</span><span class="cx">                         &lt;/div&gt;
</span><span class="cx">                 &lt;/div&gt;
</span><del>-                &lt;?php $most_recent = wp_link_query(); ?&gt;
</del><span class="cx">                 &lt;div id=&quot;most-recent-results&quot; class=&quot;query-results&quot;&gt;
</span><del>-                        &lt;ul&gt;
-                                &lt;li class=&quot;unselectable&quot;&gt;&lt;em&gt;&lt;?php _e( 'No search term specified. Showing recent items.' ); ?&gt;&lt;/em&gt;&lt;/li&gt;
-                                &lt;?php
-                                $alt = true;
-                                foreach ( $most_recent as $item ) : ?&gt;
-                                        &lt;li&lt;?php if ( $alt ) echo ' class=&quot;alternate&quot;'; ?&gt;&gt;
-                                                &lt;input type=&quot;hidden&quot; class=&quot;item-permalink&quot; value=&quot;&lt;?php echo esc_url( $item['permalink'] ); ?&gt;&quot; /&gt;
-                                                &lt;span class=&quot;item-title&quot;&gt;&lt;?php echo $item['title']; ?&gt;&lt;/span&gt;
-                                                &lt;span class=&quot;item-info&quot;&gt;&lt;?php echo esc_html( $item['info'] ); ?&gt;&lt;/span&gt;
-                                        &lt;/li&gt;
-                                &lt;?php
-                                $alt = ! $alt;
-                                endforeach; ?&gt;
-                        &lt;/ul&gt;
</del><ins>+                        &lt;div class=&quot;query-notice&quot;&gt;&lt;em&gt;&lt;?php _e( 'No search term specified. Showing recent items.' ); ?&gt;&lt;/em&gt;&lt;/div&gt;
+                        &lt;ul&gt;&lt;/ul&gt;
</ins><span class="cx">                         &lt;div class=&quot;river-waiting&quot;&gt;
</span><span class="cx">                                 &lt;img class=&quot;waiting&quot; src=&quot;&lt;?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?&gt;&quot; alt=&quot;&quot; /&gt;
</span><span class="cx">                         &lt;/div&gt;
</span></span></pre></div>
<a id="trunkwpincludesjstinymcepluginswplinkcsswplinkcss"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/tinymce/plugins/wplink/css/wplink.css (16478 => 16479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/tinymce/plugins/wplink/css/wplink.css        2010-11-19 05:06:48 UTC (rev 16478)
+++ trunk/wp-includes/js/tinymce/plugins/wplink/css/wplink.css        2010-11-19 05:31:07 UTC (rev 16479)
</span><span class="lines">@@ -1 +1 @@
</span><del>-#wp-link p.howto{margin:3px;}#link-options{padding:10px 0 14px;border-bottom:1px solid #dfdfdf;margin:0 6px 14px;}#wp-link label input[type=&quot;text&quot;]{width:360px;margin-top:5px;}#wp-link label span{display:inline-block;width:80px;text-align:right;padding-right:5px;}#wp-link .link-search-wrapper{margin:5px 5px 9px;display:block;overflow:hidden;}#wp-link .link-search-wrapper span{float:left;margin-top:6px;}#wp-link .link-search-wrapper input[type=&quot;text&quot;]{float:left;width:220px;}#wp-link .link-search-wrapper img.waiting{margin:8px 1px 0 4px;float:left;display:none;}#open-in-new-tab{display:inline-block;padding:3px 0 0;margin:0 0 0 87px;}#open-in-new-tab span{width:auto;margin-left:6px;font-size:11px;}.query-results{border:1px #dfdfdf solid;margin:0 5px 5px;background:#fff;height:185px;overflow:auto;}.query-results li{margin-bottom:0;border-bottom:1px solid #f1f1f1;color:#555;padding:4px 6px;cursor:pointer;}.query-results li:hover{background:#eaf2fa;color:#333;}#wp-link .query-results li.unselectable:hover{background:#fff;cursor:auto;color:#555;}#wp-link .query-results li.unselectable{border-bottom:1px solid #dfdfdf;}#wp-link .query-results li.selected{background:#f1f1f1;color:#333;}#wp-link .query-results li.selected .item-title{font-weight:bold;}#wp-link .item-info{text-transform:uppercase;color:#aaa;font-size:11px;float:right;}#search-results{display:none;}#wp-link .river-waiting{display:none;padding:10px 0;}#wp-link .river-waiting img.waiting{margin:0 auto;display:block;}#wp-link .submitbox{padding:5px 5px 0;font-size:11px;overflow:auto;height:29px;}#wp-link-cancel{line-height:25px;float:left;}#wp-link-update{line-height:23px;float:right;}#wp-link-update a{display:inline-block;}
</del><span class="cx">\ No newline at end of file
</span><ins>+#wp-link p.howto{margin:3px;}#link-options{padding:10px 0 14px;border-bottom:1px solid #dfdfdf;margin:0 6px 14px;}#wp-link label input[type=&quot;text&quot;]{width:360px;margin-top:5px;}#wp-link label span{display:inline-block;width:80px;text-align:right;padding-right:5px;}#wp-link .link-search-wrapper{margin:5px 5px 9px;display:block;overflow:hidden;}#wp-link .link-search-wrapper span{float:left;margin-top:6px;}#wp-link .link-search-wrapper input[type=&quot;text&quot;]{float:left;width:220px;}#wp-link .link-search-wrapper img.waiting{margin:8px 1px 0 4px;float:left;display:none;}#wp-link .link-target{width:auto;padding:3px 0 0;margin:0 0 0 87px;font-size:11px;}#wp-link .query-results{border:1px #dfdfdf solid;margin:0 5px 5px;background:#fff;height:185px;overflow:auto;}#wp-link li,#wp-link .query-notice{margin-bottom:0;border-bottom:1px solid #f1f1f1;color:#333;padding:4px 6px;cursor:pointer;}#wp-link li:hover{background:#eaf2fa;color:#151515;}#wp-link li.unselectable{border-bottom:1px solid #dfdfdf;}#wp-link li.unselectable:hover{background:#fff;cursor:auto;color:#333;}#wp-link li.selected{background:#ddd;color:#333;}#wp-link li.selected .item-title{font-weight:bold;}#wp-link .item-info{text-transform:uppercase;color:#666;font-size:11px;float:right;}#search-results{display:none;}#wp-link .river-waiting{display:none;padding:10px 0;}#wp-link .river-waiting img.waiting{margin:0 auto;display:block;}#wp-link .submitbox{padding:5px 10px;font-size:11px;overflow:auto;height:29px;}#wp-link-cancel{line-height:25px;float:left;}#wp-link-update{line-height:23px;float:right;}#wp-link-update a{display:inline-block;}
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludesjstinymcepluginswplinkcsswplinkdevcss"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/tinymce/plugins/wplink/css/wplink.dev.css (16478 => 16479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/tinymce/plugins/wplink/css/wplink.dev.css        2010-11-19 05:06:48 UTC (rev 16478)
+++ trunk/wp-includes/js/tinymce/plugins/wplink/css/wplink.dev.css        2010-11-19 05:31:07 UTC (rev 16479)
</span><span class="lines">@@ -47,7 +47,8 @@
</span><span class="cx">         height: 185px;
</span><span class="cx">         overflow: auto;
</span><span class="cx"> }
</span><del>-#wp-link li {
</del><ins>+#wp-link li,
+#wp-link .query-notice {
</ins><span class="cx">         margin-bottom: 0;
</span><span class="cx">         border-bottom: 1px solid #f1f1f1;
</span><span class="cx">         color: #333;
</span><span class="lines">@@ -66,7 +67,7 @@
</span><span class="cx">         cursor: auto;
</span><span class="cx">         color: #333;
</span><span class="cx"> }
</span><del>-#wp-link  li.selected {
</del><ins>+#wp-link li.selected {
</ins><span class="cx">         background: #ddd;
</span><span class="cx">         color: #333;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkwpincludesjstinymcepluginswplinkjswplinkdevjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/tinymce/plugins/wplink/js/wplink.dev.js (16478 => 16479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/tinymce/plugins/wplink/js/wplink.dev.js        2010-11-19 05:06:48 UTC (rev 16478)
+++ trunk/wp-includes/js/tinymce/plugins/wplink/js/wplink.dev.js        2010-11-19 05:31:07 UTC (rev 16479)
</span><span class="lines">@@ -1,16 +1,13 @@
</span><ins>+var wpLink;
+
</ins><span class="cx"> (function($){
</span><del>-        var inputs = {}, results = {}, ed,
</del><ins>+        var inputs = {}, rivers = {}, ed, River, Query;
+        
</ins><span class="cx">         wpLink = {
</span><span class="cx">                 timeToTriggerRiver: 150,
</span><span class="cx">                 minRiverAJAXDuration: 200,
</span><ins>+                riverBottomThreshold: 5,
</ins><span class="cx">                 lastSearch: '',
</span><del>-                riverDefaults: function() {
-                        return {
-                                page : 2,
-                                allLoaded: false,
-                                active: false
-                        };
-                },
</del><span class="cx">                 init : function() {
</span><span class="cx">                         inputs.dialog = $('#wp-link');
</span><span class="cx">                         // URL
</span><span class="lines">@@ -20,19 +17,16 @@
</span><span class="cx">                         // Advanced Options
</span><span class="cx">                         inputs.openInNewTab = $('#link-target-checkbox');
</span><span class="cx">                         inputs.search = $('#search-field');
</span><del>-                        // Result lists
-                        results.search = $('#search-results');
-                        results.recent = $('#most-recent-results');
-                        results.search.data('river', wpLink.riverDefaults() );
-                        results.recent.data('river', wpLink.riverDefaults() );
-                        results.group = $('.query-results', inputs.dialog);
</del><ins>+                        // Build Rivers
+                        rivers.search = new River( $('#search-results') );
+                        rivers.recent = new River( $('#most-recent-results') );
+                        rivers.elements = $('.query-results', inputs.dialog);
</ins><span class="cx"> 
</span><span class="cx">                         // Bind event handlers
</span><span class="cx">                         $('#wp-link-update').click( wpLink.update );
</span><span class="cx">                         $('#wp-link-cancel').click( function() { tinyMCEPopup.close(); } );
</span><span class="cx">                         
</span><del>-                        results.group.delegate('li', 'click', wpLink.selectInternalLink )
-                        results.group.scroll( wpLink.maybeLoadRiver );
</del><ins>+                        rivers.elements.delegate('li', 'click', wpLink.selectInternalLink )
</ins><span class="cx">                         
</span><span class="cx">                         inputs.search.keyup( wpLink.searchInternalLinks );
</span><span class="cx">                         
</span><span class="lines">@@ -55,9 +49,12 @@
</span><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         // Clear previously selected links
</span><del>-                        results.group.find('.selected').removeClass('selected');
</del><ins>+                        rivers.elements.find('.selected').removeClass('selected');
</ins><span class="cx">                         // Focus the URL field
</span><span class="cx">                         inputs.url.focus();
</span><ins>+                        // Load the most recent results if this is the first time opening the panel.
+                        if ( ! rivers.recent.ul.children().length )
+                                rivers.recent.ajax();
</ins><span class="cx">                 },
</span><span class="cx"> 
</span><span class="cx">                 update : function() {
</span><span class="lines">@@ -137,86 +134,90 @@
</span><span class="cx">                         inputs.title.val( t.children('.item-title').text() );
</span><span class="cx">                 },
</span><span class="cx"> 
</span><del>-                maybeLoadRiver : function() {
-                        var t = $(this),
-                                ul = t.children('ul'),
-                                river = t.data('river'),
-                                bottom = t.scrollTop() + t.height();
-
-                        if ( bottom != ul.height() || river.active || river.allLoaded )
-                                return;
-
-                        setTimeout(function() {
-                                var newTop = t.scrollTop(),
-                                        newBottom = newTop + t.height(),
-                                        waiting = t.find('.river-waiting');
-
-                                if ( bottom != newBottom || newBottom != ul.height() || river.active || river.allLoaded )
-                                        return;
-
-                                river.active = true;
-                                waiting.show();
-                                t.scrollTop( newTop + waiting.outerHeight() );
-
-                                wpLink.linkAJAX( t, { page : river.page }, function(r) {
-                                        river.page++;
-                                        river.active = false;
-                                        river.allLoaded = !r;
-                                        waiting.hide();
-                                }, {
-                                        append : true,
-                                        delay : wpLink.minRiverAJAXDuration
-                                });
-                        }, wpLink.timeToTriggerRiver );
-                },
</del><span class="cx">                 searchInternalLinks : function() {
</span><span class="cx">                         var t = $(this), waiting,
</span><del>-                                title = t.val();
</del><ins>+                                search = t.val();
</ins><span class="cx"> 
</span><del>-                        if ( title.length &gt; 2 ) {
-                                results.recent.hide();
-                                results.search.show();
</del><ins>+                        if ( search.length &gt; 2 ) {
+                                rivers.recent.element.hide();
+                                rivers.search.element.show();
</ins><span class="cx"> 
</span><span class="cx">                                 // Don't search if the keypress didn't change the title.
</span><del>-                                if ( wpLink.lastSearch == title )
</del><ins>+                                if ( wpLink.lastSearch == search )
</ins><span class="cx">                                         return;
</span><span class="cx"> 
</span><del>-                                wpLink.lastSearch = title;
</del><ins>+                                wpLink.lastSearch = search;
</ins><span class="cx">                                 waiting = t.siblings('img.waiting').show();
</span><span class="cx"> 
</span><del>-                                results.search.data('river', wpLink.riverDefaults() );
-                                results.search.scrollTop(0);
-                                wpLink.linkAJAX( results.search, { title : title }, function(){ waiting.hide(); });
</del><ins>+                                rivers.search.change( search );
+                                rivers.search.ajax( function(){ waiting.hide(); });
</ins><span class="cx">                         } else {
</span><del>-                                results.search.hide();
-                                results.recent.show();
</del><ins>+                                rivers.search.element.hide();
+                                rivers.recent.element.show();
</ins><span class="cx">                         }
</span><span class="cx">                 },
</span><span class="cx"> 
</span><del>-                linkAJAX : function( $panel, params, callback, opts ) {
-                        var response;
-                        opts = opts || {};
</del><ins>+                delayedCallback : function( func, delay ) {
+                        var timeoutTriggered, funcTriggered, funcArgs, funcContext;
</ins><span class="cx"> 
</span><del>-                        if ( ! $panel.hasClass('query-results') )
-                                $panel = $panel.parents('.query-results');
</del><ins>+                        if ( ! delay )
+                                return func;
</ins><span class="cx"> 
</span><del>-                        if ( ! $panel.length )
-                                return;
</del><ins>+                        setTimeout( function() {
+                                if ( funcTriggered )
+                                        return func.apply( funcContext, funcArgs );
+                                // Otherwise, wait.
+                                timeoutTriggered = true;
+                        }, delay);
</ins><span class="cx"> 
</span><del>-                        response = wpLink.delayedCallback( function( results ) {
-                                wpLink.processAJAXResponse( $panel, results, callback, opts );
-                        }, opts.delay );
-
-                        $.post( ajaxurl, $.extend({
-                                action : 'wp-link-ajax'
-                        }, params ), response, &quot;json&quot; );
</del><ins>+                        return function() {
+                                if ( timeoutTriggered )
+                                        return func.apply( this, arguments );
+                                // Otherwise, wait.
+                                funcArgs = arguments;
+                                funcContext = this;
+                                funcTriggered = true;
+                        };
+                }
+        }
+        
+        River = function( element, search ) {
+                var self = this;
+                this.element = element;
+                this.ul = element.children('ul');
+                this.waiting = element.find('.river-waiting');
+                
+                this.change( search );
+                
+                element.scroll( function(){ self.maybeLoad(); });
+        };
+        
+        $.extend( River.prototype, {
+                ajax: function( callback ) {
+                        var self = this,
+                                delay = this.query.page == 1 ? 0 : wpLink.minRiverAJAXDuration,
+                                response = wpLink.delayedCallback( function( results, params ) {
+                                        self.process( results, params );
+                                        if ( callback )
+                                                callback( results, params );
+                                }, delay );
+                        
+                        this.query.ajax( response );
</ins><span class="cx">                 },
</span><ins>+                change: function( search ) {
+                        if ( this.query &amp;&amp; this._search == search )
+                                return;
+                        
+                        this._search = search;
+                        this.query = new Query( search );
+                        this.element.scrollTop(0);
+                },
+                process: function( results, params ) {
+                        var list = '', alt = true,
+                                firstPage = params.page == 1;
</ins><span class="cx"> 
</span><del>-                processAJAXResponse: function( $panel, results, callback, opts ) {
-                        var list = '', alt = true;
-
</del><span class="cx">                         if ( !results ) {
</span><del>-                                if ( !opts.append ) {
</del><ins>+                                if ( firstPage ) {
</ins><span class="cx">                                         list += '&lt;li class=&quot;unselectable&quot;&gt;&lt;span class=&quot;item-title&quot;&gt;&lt;em&gt;'
</span><span class="cx">                                         + wpLinkL10n.noMatchesFound
</span><span class="cx">                                         + '&lt;/em&gt;&lt;/span&gt;&lt;/li&gt;';
</span><span class="lines">@@ -232,37 +233,62 @@
</span><span class="cx">                                 });
</span><span class="cx">                         }
</span><span class="cx"> 
</span><del>-                        // Set results
-                        $panel.children('ul')[ opts.append ? 'append' : 'html' ]( list );
-
-                        // Run callback
-                        if ( callback )
-                                callback( results );
</del><ins>+                        this.ul[ firstPage ? 'html' : 'append' ]( list );
</ins><span class="cx">                 },
</span><ins>+                maybeLoad: function() {
+                        var self = this,
+                                el = this.element,
+                                bottom = el.scrollTop() + el.height();
</ins><span class="cx"> 
</span><del>-                delayedCallback : function( func, delay ) {
-                        var timeoutTriggered, funcTriggered, funcArgs, funcContext;
</del><ins>+                        if ( ! this.query.ready() || bottom &lt; this.ul.height() - wpLink.riverBottomThreshold )
+                                return;
</ins><span class="cx"> 
</span><del>-                        if ( ! delay )
-                                return func;
</del><ins>+                        setTimeout(function() {
+                                var newTop = el.scrollTop(),
+                                        newBottom = newTop + el.height();
</ins><span class="cx"> 
</span><del>-                        setTimeout( function() {
-                                if ( funcTriggered )
-                                        return func.apply( funcContext, funcArgs );
-                                // Otherwise, wait.
-                                timeoutTriggered = true;
-                        }, delay);
</del><ins>+                                if ( ! self.query.ready() || newBottom &lt; self.ul.height() - wpLink.riverBottomThreshold )
+                                        return;
</ins><span class="cx"> 
</span><del>-                        return function() {
-                                if ( timeoutTriggered )
-                                        return func.apply( this, arguments );
-                                // Otherwise, wait.
-                                funcArgs = arguments;
-                                funcContext = this;
-                                funcTriggered = true;
-                        };
</del><ins>+                                self.waiting.show();
+                                el.scrollTop( newTop + self.waiting.outerHeight() );
+
+                                self.ajax( function() { self.waiting.hide(); });
+                        }, wpLink.timeToTriggerRiver );
</ins><span class="cx">                 }
</span><del>-        }
</del><ins>+        });
+        
+        Query = function( search ) {
+                this.page = 1;
+                this.allLoaded = false;
+                this.querying = false;
+                this.search = search;
+        };
+        
+        $.extend( Query.prototype, {
+                ready: function() {
+                        return !( this.querying || this.allLoaded );
+                },
+                ajax: function( callback ) {
+                        var self = this,
+                                query = {
+                                        action : 'wp-link-ajax',
+                                        page : this.page
+                                };
</ins><span class="cx"> 
</span><ins>+                        if ( this.search )
+                                query.search = this.search;
+
+                        this.querying = true;
+                        
+                        $.post( ajaxurl, query, function(r) {
+                                self.page++;
+                                self.querying = false;
+                                self.allLoaded = !r;
+                                callback( r, query );
+                        }, &quot;json&quot; );
+                }
+        });
+
</ins><span class="cx">         $(document).ready( wpLink.init );
</span><span class="cx"> })(jQuery);
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludesjstinymcepluginswplinkjswplinkjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/tinymce/plugins/wplink/js/wplink.js (16478 => 16479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/tinymce/plugins/wplink/js/wplink.js        2010-11-19 05:06:48 UTC (rev 16478)
+++ trunk/wp-includes/js/tinymce/plugins/wplink/js/wplink.js        2010-11-19 05:31:07 UTC (rev 16479)
</span><span class="lines">@@ -1 +1 @@
</span><del>-(function(d){var a={},c={},b,e={timeToTriggerRiver:150,minRiverAJAXDuration:200,lastSearch:&quot;&quot;,riverDefaults:function(){return{page:2,allLoaded:false,active:false}},init:function(){a.dialog=d(&quot;#wp-link&quot;);a.url=d(&quot;#url-field&quot;);a.title=d(&quot;#link-title-field&quot;);a.openInNewTab=d(&quot;#link-target-checkbox&quot;);a.search=d(&quot;#search-field&quot;);c.search=d(&quot;#search-results&quot;);c.recent=d(&quot;#most-recent-results&quot;);c.search.data(&quot;river&quot;,e.riverDefaults());c.recent.data(&quot;river&quot;,e.riverDefaults());c.group=d(&quot;.query-results&quot;,a.dialog);d(&quot;#wp-link-update&quot;).click(e.update);d(&quot;#wp-link-cancel&quot;).click(function(){tinyMCEPopup.close()});c.group.delegate(&quot;li&quot;,&quot;click&quot;,e.selectInternalLink);c.group.scroll(e.maybeLoadRiver);a.search.keyup(e.searchInternalLinks);a.dialog.bind(&quot;dialogopen&quot;,e.refresh)},refresh:function(){var f;b=tinyMCEPopup.editor;if(f=b.dom.getParent(b.selection.getNode(),&quot;A&quot;)){a.url.val(f.href);a.title.val(b.dom.getAttrib(f,&quot;title&quot;));if(&quot;_blank&quot;==b.dom.getAttrib(f,&quot;target&quot;)){a.openInNewTab.attr(&quot;checked&quot;,&quot;checked&quot;)}}c.group.find(&quot;.selected&quot;).removeClass(&quot;selected&quot;);a.url.focus()},update:function(){var j,g=tinyMCEPopup.editor,h={href:a.url.val(),title:a.title.val(),target:a.openInNewTab.attr(&quot;checked&quot;)?&quot;_blank&quot;:&quot;&quot;},k,f,i=h.title?h.title:h.href;tinyMCEPopup.restoreSelection();k=g.dom.getParent(g.selection.getNode(),&quot;A&quot;);if(!h.href){if(g.selection.isCollapsed()){tinyMCEPopup.close();return}else{if(k){tinyMCEPopup.execCommand(&quot;mceBeginUndoLevel&quot;);f=g.selection.getBookmark();g.dom.remove(k,1);g.selection.moveToBookmark(f);tinyMCEPopup.execCommand(&quot;mceEndUndoLevel&quot;);tinyMCEPopup.close();return}}}tinyMCEPopup.execCommand(&quot;mceBeginUndoLevel&quot;);if(k==null){g.getDoc().execCommand(&quot;unlink&quot;,false,null);if(g.selection.isCollapsed()){j=g.dom.create(&quot;a&quot;,{href:&quot;#mce_temp_url#&quot;},i);g.selection.setNode(j)}else{tinyMCEPopup.execCommand(&quot;CreateLink&quot;,false,&quot;#mce_temp_url#&quot;,{skip_undo:1})}tinymce.each(g.dom.select(&quot;a&quot;),function(l){if(g.dom.getAttrib(l,&quot;href&quot;)==&quot;#mce_temp_url#&quot;){k=l;g.dom.setAttribs(k,h)}})}else{g.dom.setAttribs(k,h)}if(k.childNodes.length!=1||k.firstChild.nodeName!=&quot;IMG&quot;){g.focus();g.selection.select(k);g.selection.collapse(0);tinyMCEPopup.storeSelection()}tinyMCEPopup.execCommand(&quot;mceEndUndoLevel&quot;);tinyMCEPopup.close()},selectInternalLink:function(){var f=d(this);if(f.hasClass(&quot;unselectable&quot;)){return}f.siblings(&quot;.selected&quot;).removeClass(&quot;selected&quot;);f.addClass(&quot;selected&quot;);a.url.val(f.children(&quot;.item-permalink&quot;).val());a.title.val(f.children(&quot;.item-title&quot;).text())},maybeLoadRiver:function(){var h=d(this),g=h.children(&quot;ul&quot;),i=h.data(&quot;river&quot;),f=h.scrollTop()+h.height();if(f!=g.height()||i.active||i.allLoaded){return}setTimeout(function(){var j=h.scrollTop(),k=j+h.height(),l=h.find(&quot;.river-waiting&quot;);if(f!=k||k!=g.height()||i.active||i.allLoaded){return}i.active=true;l.show();h.scrollTop(j+l.outerHeight());e.linkAJAX(h,{page:i.page},function(m){i.page++;i.active=false;i.allLoaded=!m;l.hide()},{append:true,delay:e.minRiverAJAXDuration})},e.timeToTriggerRiver)},searchInternalLinks:function(){var f=d(this),h,g=f.val();if(g.length&gt;2){c.recent.hide();c.search.show();if(e.lastSearch==g){return}e.lastSearch=g;h=f.siblings(&quot;img.waiting&quot;).show();c.search.data(&quot;river&quot;,e.riverDefaults());c.search.scrollTop(0);e.linkAJAX(c.search,{title:g},function(){h.hide()})}else{c.search.hide();c.recent.show()}},linkAJAX:function(i,h,j,g){var f;g=g||{};if(!i.hasClass(&quot;query-results&quot;)){i=i.parents(&quot;.query-results&quot;)}if(!i.length){return}f=e.delayedCallback(function(k){e.processAJAXResponse(i,k,j,g)},g.delay);d.post(ajaxurl,d.extend({action:&quot;wp-link-ajax&quot;},h),f,&quot;json&quot;)},processAJAXResponse:function(j,f,k,g){var h=&quot;&quot;,i=true;if(!f){if(!g.append){h+='&lt;li class=&quot;unselectable&quot;&gt;&lt;span class=&quot;item-title&quot;&gt;&lt;em&gt;'+wpLinkL10n.noMatchesFound+&quot;&lt;/em&gt;&lt;/span&gt;&lt;/li&gt;&quot;}}else{d.each(f,function(){h+=i?'&lt;li class=&quot;alternate&quot;&gt;':&quot;&lt;li&gt;&quot;;h+='&lt;input type=&quot;hidden&quot; class=&quot;item-permalink&quot; value=&quot;'+this[&quot;permalink&quot;]+'&quot; /&gt;';h+='&lt;span class=&quot;item-title&quot;&gt;';h+=this[&quot;title&quot;]?this[&quot;title&quot;]:&quot;&lt;em&gt;&quot;+wpLinkL10n.untitled+&quot;&lt;/em&gt;&quot;;h+='&lt;/span&gt;&lt;span class=&quot;item-info&quot;&gt;'+this[&quot;info&quot;]+&quot;&lt;/span&gt;&lt;/li&gt;&quot;;i=!i})}j.children(&quot;ul&quot;)[g.append?&quot;append&quot;:&quot;html&quot;](h);if(k){k(f)}},delayedCallback:function(h,f){var k,j,i,g;if(!f){return h}setTimeout(function(){if(j){return h.apply(g,i)}k=true},f);return function(){if(k){return h.apply(this,arguments)}i=arguments;g=this;j=true}}};d(document).ready(e.init)})(jQuery);
</del><span class="cx">\ No newline at end of file
</span><ins>+var wpLink;(function(f){var b={},e={},d,a,c;wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,lastSearch:&quot;&quot;,init:function(){b.dialog=f(&quot;#wp-link&quot;);b.url=f(&quot;#url-field&quot;);b.title=f(&quot;#link-title-field&quot;);b.openInNewTab=f(&quot;#link-target-checkbox&quot;);b.search=f(&quot;#search-field&quot;);e.search=new a(f(&quot;#search-results&quot;));e.recent=new a(f(&quot;#most-recent-results&quot;));e.elements=f(&quot;.query-results&quot;,b.dialog);f(&quot;#wp-link-update&quot;).click(wpLink.update);f(&quot;#wp-link-cancel&quot;).click(function(){tinyMCEPopup.close()});e.elements.delegate(&quot;li&quot;,&quot;click&quot;,wpLink.selectInternalLink);b.search.keyup(wpLink.searchInternalLinks);b.dialog.bind(&quot;dialogopen&quot;,wpLink.refresh)},refresh:function(){var g;d=tinyMCEPopup.editor;if(g=d.dom.getParent(d.selection.getNode(),&quot;A&quot;)){b.url.val(g.href);b.title.val(d.dom.getAttrib(g,&quot;title&quot;));if(&quot;_blank&quot;==d.dom.getAttrib(g,&quot;target&quot;)){b.openInNewTab.attr(&quot;checked&quot;,&quot;checked&quot;)}}e.elements.find(&quot;.selected&quot;).removeClass(&quot;selected&quot;);b.url.focus();if(!e.recent.ul.children().length){e.recent.ajax()}},update:function(){var k,h=tinyMCEPopup.editor,i={href:b.url.val(),title:b.title.val(),target:b.openInNewTab.attr(&quot;checked&quot;)?&quot;_blank&quot;:&quot;&quot;},l,g,j=i.title?i.title:i.href;tinyMCEPopup.restoreSelection();l=h.dom.getParent(h.selection.getNode(),&quot;A&quot;);if(!i.href){if(h.selection.isCollapsed()){tinyMCEPopup.close();return}else{if(l){tinyMCEPopup.execCommand(&quot;mceBeginUndoLevel&quot;);g=h.selection.getBookmark();h.dom.remove(l,1);h.selection.moveToBookmark(g);tinyMCEPopup.execCommand(&quot;mceEndUndoLevel&quot;);tinyMCEPopup.close();return}}}tinyMCEPopup.execCommand(&quot;mceBeginUndoLevel&quot;);if(l==null){h.getDoc().execCommand(&quot;unlink&quot;,false,null);if(h.selection.isCollapsed()){k=h.dom.create(&quot;a&quot;,{href:&quot;#mce_temp_url#&quot;},j);h.selection.setNode(k)}else{tinyMCEPopup.execCommand(&quot;CreateLink&quot;,false,&quot;#mce_temp_url#&quot;,{skip_undo:1})}tinymce.each(h.dom.select(&quot;a&quot;),function(m){if(h.dom.getAttrib(m,&quot;href&quot;)==&quot;#mce_temp_url#&quot;){l=m;h.dom.setAttribs(l,i)}})}else{h.dom.setAttribs(l,i)}if(l.childNodes.length!=1||l.firstChild.nodeName!=&quot;IMG&quot;){h.focus();h.selection.select(l);h.selection.collapse(0);tinyMCEPopup.storeSelection()}tinyMCEPopup.execCommand(&quot;mceEndUndoLevel&quot;);tinyMCEPopup.close()},selectInternalLink:function(){var g=f(this);if(g.hasClass(&quot;unselectable&quot;)){return}g.siblings(&quot;.selected&quot;).removeClass(&quot;selected&quot;);g.addClass(&quot;selected&quot;);b.url.val(g.children(&quot;.item-permalink&quot;).val());b.title.val(g.children(&quot;.item-title&quot;).text())},searchInternalLinks:function(){var h=f(this),i,g=h.val();if(g.length&gt;2){e.recent.element.hide();e.search.element.show();if(wpLink.lastSearch==g){return}wpLink.lastSearch=g;i=h.siblings(&quot;img.waiting&quot;).show();e.search.change(g);e.search.ajax(function(){i.hide()})}else{e.search.element.hide();e.recent.element.show()}},delayedCallback:function(i,g){var l,k,j,h;if(!g){return i}setTimeout(function(){if(k){return i.apply(h,j)}l=true},g);return function(){if(l){return i.apply(this,arguments)}j=arguments;h=this;k=true}}};a=function(i,h){var g=this;this.element=i;this.ul=i.children(&quot;ul&quot;);this.waiting=i.find(&quot;.river-waiting&quot;);this.change(h);i.scroll(function(){g.maybeLoad()})};f.extend(a.prototype,{ajax:function(j){var h=this,i=this.query.page==1?0:wpLink.minRiverAJAXDuration,g=wpLink.delayedCallback(function(k,l){h.process(k,l);if(j){j(k,l)}},i);this.query.ajax(g)},change:function(g){if(this.query&amp;&amp;this._search==g){return}this._search=g;this.query=new c(g);this.element.scrollTop(0)},process:function(g,k){var h=&quot;&quot;,i=true,j=k.page==1;if(!g){if(j){h+='&lt;li class=&quot;unselectable&quot;&gt;&lt;span class=&quot;item-title&quot;&gt;&lt;em&gt;'+wpLinkL10n.noMatchesFound+&quot;&lt;/em&gt;&lt;/span&gt;&lt;/li&gt;&quot;}}else{f.each(g,function(){h+=i?'&lt;li class=&quot;alternate&quot;&gt;':&quot;&lt;li&gt;&quot;;h+='&lt;input type=&quot;hidden&quot; class=&quot;item-permalink&quot; value=&quot;'+this[&quot;permalink&quot;]+'&quot; /&gt;';h+='&lt;span class=&quot;item-title&quot;&gt;';h+=this[&quot;title&quot;]?this[&quot;title&quot;]:&quot;&lt;em&gt;&quot;+wpLinkL10n.untitled+&quot;&lt;/em&gt;&quot;;h+='&lt;/span&gt;&lt;span class=&quot;item-info&quot;&gt;'+this[&quot;info&quot;]+&quot;&lt;/span&gt;&lt;/li&gt;&quot;;i=!i})}this.ul[j?&quot;html&quot;:&quot;append&quot;](h)},maybeLoad:function(){var h=this,i=this.element,g=i.scrollTop()+i.height();if(!this.query.ready()||g&lt;this.ul.height()-wpLink.riverBottomThreshold){return}setTimeout(function(){var j=i.scrollTop(),k=j+i.height();if(!h.query.ready()||k&lt;h.ul.height()-wpLink.riverBottomThreshold){return}h.waiting.show();i.scrollTop(j+h.waiting.outerHeight());h.ajax(function(){h.waiting.hide()})},wpLink.timeToTriggerRiver)}});c=function(g){this.page=1;this.allLoaded=false;this.querying=false;this.search=g};f.extend(c.prototype,{ready:function(){return !(this.querying||this.allLoaded)},ajax:function(i){var g=this,h={action:&quot;wp-link-ajax&quot;,page:this.page};if(this.search){h.search=this.search}this.querying=true;f.post(ajaxurl,h,function(j){g.page++;g.querying=false;g.allLoaded=!j;i(j,h)},&quot;json&quot;)}});f(document).ready(wpLink.init)})(jQuery);
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludesscriptloaderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/script-loader.php (16478 => 16479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/script-loader.php        2010-11-19 05:06:48 UTC (rev 16478)
+++ trunk/wp-includes/script-loader.php        2010-11-19 05:31:07 UTC (rev 16479)
</span><span class="lines">@@ -269,7 +269,7 @@
</span><span class="cx">                 'noShortlink' =&gt; __( 'No shortlink available for this page.' ),
</span><span class="cx">         ) );
</span><span class="cx"> 
</span><del>-        $scripts-&gt;add( 'wplink', &quot;/wp-includes/js/tinymce/plugins/wplink/js/wplink$suffix.js&quot;, array('jquery'), '20101117' );
</del><ins>+        $scripts-&gt;add( 'wplink', &quot;/wp-includes/js/tinymce/plugins/wplink/js/wplink$suffix.js&quot;, array('jquery'), '20101119' );
</ins><span class="cx">         $scripts-&gt;localize( 'wplink', 'wpLinkL10n', array(
</span><span class="cx">                 'untitled' =&gt; __('Untitled'),
</span><span class="cx">                 'noMatchesFound' =&gt; __('No matches found.'),
</span><span class="lines">@@ -511,7 +511,7 @@
</span><span class="cx">         $styles-&gt;add( 'nav-menu', &quot;/wp-admin/css/nav-menu$suffix.css&quot;, array(), '20100907' );
</span><span class="cx">         $styles-&gt;add( 'admin-bar', &quot;/wp-includes/css/admin-bar$suffix.css&quot;, array(), '20101117' );
</span><span class="cx">         $styles-&gt;add( 'wp-jquery-ui-dialog', &quot;/wp-includes/css/jquery-ui-dialog$suffix.css&quot;, array(), '20101118' );
</span><del>-        $styles-&gt;add( 'wplink', &quot;/wp-includes/js/tinymce/plugins/wplink/css/wplink$suffix.css&quot;, array(), '20101118' );
</del><ins>+        $styles-&gt;add( 'wplink', &quot;/wp-includes/js/tinymce/plugins/wplink/css/wplink$suffix.css&quot;, array(), '20101119' );
</ins><span class="cx"> 
</span><span class="cx">         foreach ( $rtl_styles as $rtl_style ) {
</span><span class="cx">                 $styles-&gt;add_data( $rtl_style, 'rtl', true );
</span></span></pre>
</div>
</div>

</body>
</html>