<!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>[16407] trunk/wp-includes/js/tinymce:
Improve internal linking river feedback.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/16407">16407</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2010-11-16 18:30:34 +0000 (Tue, 16 Nov 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Improve internal linking river feedback. props koopersmith, see <a href="http://trac.wordpress.org/ticket/11420">#11420</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<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="#trunkwpincludesjstinymcewpmcelinkphp">trunk/wp-includes/js/tinymce/wp-mce-link.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesjstinymcepluginswplinkjswplinkdevjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/tinymce/plugins/wplink/js/wplink.dev.js (16406 => 16407)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/tinymce/plugins/wplink/js/wplink.dev.js        2010-11-16 17:51:45 UTC (rev 16406)
+++ trunk/wp-includes/js/tinymce/plugins/wplink/js/wplink.dev.js        2010-11-16 18:30:34 UTC (rev 16407)
</span><span class="lines">@@ -1,6 +1,8 @@
</span><span class="cx"> (function($){        
</span><span class="cx">         var inputs = {}, results = {}, ed,
</span><span class="cx">         wpLink = {
</span><ins>+                timeToTriggerRiver: 150,
+                minRiverAJAXDuration: 200,
</ins><span class="cx">                 lastSearch: '',
</span><span class="cx">                 riverDefaults: function() {
</span><span class="cx">                         return {
</span><span class="lines">@@ -130,22 +132,34 @@
</span><span class="cx">                         var t = $(this),
</span><span class="cx">                                 ul = t.children('ul'),
</span><span class="cx">                                 river = t.data('river'),
</span><del>-                                waiting = t.find('.river-waiting');
</del><ins>+                                bottom = t.scrollTop() + t.height();
</ins><span class="cx">                         
</span><del>-                        if( t.scrollTop() + t.height() != ul.height() || river.active || river.allLoaded )
</del><ins>+                        if ( bottom != ul.height() || river.active || river.allLoaded )
</ins><span class="cx">                                 return;
</span><span class="cx">                         
</span><del>-                        river.active = true;
-                        waiting.show();
-                        
-                        wpLink.linkAJAX( t, { page : river.page }, function(r) {
-                                river.page++;
-                                river.active = false;
-                                river.allLoaded = !r;
-                                waiting.hide();
-                        }, true);
</del><ins>+                        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 );
</ins><span class="cx">                 },
</span><del>-                
</del><span class="cx">                 searchInternalLinks : function() {
</span><span class="cx">                         var t = $(this), waiting,
</span><span class="cx">                                 title = t.val();
</span><span class="lines">@@ -170,40 +184,72 @@
</span><span class="cx">                         }
</span><span class="cx">                 },
</span><span class="cx">                 
</span><del>-                linkAJAX : function( $panel, params, callback, append ) {
</del><ins>+                linkAJAX : function( $panel, params, callback, opts ) {
+                        var response;
+                        opts = opts || {};
+                        
</ins><span class="cx">                         if ( ! $panel.hasClass('query-results') )
</span><span class="cx">                                 $panel = $panel.parents('.query-results');
</span><span class="cx">                         
</span><span class="cx">                         if ( ! $panel.length )
</span><span class="cx">                                 return;
</span><span class="cx">                         
</span><ins>+                        response = wpLink.delayedCallback( function( results ) {
+                                wpLink.processAJAXResponse( $panel, results, callback, opts );
+                        }, opts.delay );
+                        
</ins><span class="cx">                         $.post( ajaxurl, $.extend({
</span><span class="cx">                                 action : 'wp-link-ajax'
</span><del>-                        }, params ), function( results ) {
-                                var list = '';
-                                
-                                if ( !results ) {
-                                        if ( !append ) {
-                                                list += '<li class="no-matches-found unselectable"><span class="item-title"><em>'
-                                                + wpLinkL10n.noMatchesFound
-                                                + '</em></span></li>';
-                                        }
-                                } else {
-                                        $.each( results, function() {
-                                                list += '<li><input type="hidden" class="item-permalink" value="' + this['permalink'] + '" />';
-                                                list += '<span class="item-title">';
-                                                list += this['title'] ? this['title'] : '<em>'+ wpLinkL10n.untitled + '</em>';
-                                                list += '</span><span class="item-info">' + this['info'] + '</span></li>';
-                                        });
</del><ins>+                        }, params ), response, "json" );
+                },
+                
+                processAJAXResponse: function( $panel, results, callback, opts ) {
+                        var list = '';
+                        
+                        if ( !results ) {
+                                if ( !opts.append ) {
+                                        list += '<li class="no-matches-found unselectable"><span class="item-title"><em>'
+                                        + wpLinkL10n.noMatchesFound
+                                        + '</em></span></li>';
</ins><span class="cx">                                 }
</span><del>-                                
-                                // Set results
-                                $panel.children('ul')[ append ? 'append' : 'html' ]( list );
-                                
-                                // Run callback
-                                if ( callback )
-                                        callback( results );
-                        }, "json" );
</del><ins>+                        } else {
+                                $.each( results, function() {
+                                        list += '<li><input type="hidden" class="item-permalink" value="' + this['permalink'] + '" />';
+                                        list += '<span class="item-title">';
+                                        list += this['title'] ? this['title'] : '<em>'+ wpLinkL10n.untitled + '</em>';
+                                        list += '</span><span class="item-info">' + this['info'] + '</span></li>';
+                                });
+                        }
+                        
+                        // Set results
+                        $panel.children('ul')[ opts.append ? 'append' : 'html' ]( list );
+                        
+                        // Run callback
+                        if ( callback )
+                                callback( results );
+                },
+                
+                delayedCallback : function( func, delay ) {
+                        var timeoutTriggered, funcTriggered, funcArgs, funcContext;
+                        
+                        if ( ! delay )
+                                return func;
+                        
+                        setTimeout( function() {
+                                if ( funcTriggered )
+                                        return func.apply( funcContext, funcArgs );
+                                // Otherwise, wait.
+                                timeoutTriggered = true;
+                        }, delay);
+                        
+                        return function() {
+                                if ( timeoutTriggered )
+                                        return func.apply( this, arguments );
+                                // Otherwise, wait.
+                                funcArgs = arguments;
+                                funcContext = this;
+                                funcTriggered = true;
+                        };
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">         
</span></span></pre></div>
<a id="trunkwpincludesjstinymcepluginswplinkjswplinkjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/tinymce/plugins/wplink/js/wplink.js (16406 => 16407)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/tinymce/plugins/wplink/js/wplink.js        2010-11-16 17:51:45 UTC (rev 16406)
+++ trunk/wp-includes/js/tinymce/plugins/wplink/js/wplink.js        2010-11-16 18:30:34 UTC (rev 16407)
</span><span class="lines">@@ -1 +1 @@
</span><del>-(function(d){var a={},c={},b,e={lastSearch:"",riverDefaults:function(){return{page:2,allLoaded:false,active:false}},init:function(){var f;b=tinyMCEPopup.editor;a.url=d("#url-field");a.title=d("#link-title-field");a.openInNewTab=d("#link-target-checkbox");a.search=d("#search-field");c.search=d("#search-results");c.recent=d("#most-recent-results");c.search.data("river",e.riverDefaults());c.recent.data("river",e.riverDefaults());d("#wp-update").click(e.update);d("#wp-cancel").click(function(){tinyMCEPopup.close()});d(".query-results").delegate("li","click",e.selectInternalLink);d(".query-results").scroll(e.maybeLoadRiver);a.search.keyup(e.searchInternalLinks);if(f=b.dom.getParent(b.selection.getNode(),"A")){a.url.val(f.href);a.title.val(b.dom.getAttrib(f,"title"));if("_blank"==b.dom.getAttrib(f,"target")){a.openInNewTab.attr("checked","checked")}}a.url.focus()},update:function(){var j,g=tinyMCEPopup.editor,h={href:a.url.val(),title:a.title.val(),target:a.openInNewTab.attr("checked")?"_blank":""},k,f,i=h.title?h.title:h.href;tinyMCEPopup.restoreSelection();k=g.dom.getParent(g.selection.getNode(),"A");if(!h.href){if(g.selection.isCollapsed()){tinyMCEPopup.close();return}else{if(k){tinyMCEPopup.execCommand("mceBeginUndoLevel");f=g.selection.getBookmark();g.dom.remove(k,1);g.selection.moveToBookmark(f);tinyMCEPopup.execCommand("mceEndUndoLevel");tinyMCEPopup.close();return}}}tinyMCEPopup.execCommand("mceBeginUndoLevel");if(k==null){g.getDoc().execCommand("unlink",false,null);if(g.selection.isCollapsed()){j=g.dom.create("a",{href:"#mce_temp_url#"},i);g.selection.setNode(j)}else{tinyMCEPopup.execCommand("CreateLink",false,"#mce_temp_url#",{skip_undo:1})}tinymce.each(g.dom.select("a"),function(l){if(g.dom.getAttrib(l,"href")=="#mce_temp_url#"){k=l;g.dom.setAttribs(k,h)}})}else{g.dom.setAttribs(k,h)}if(k.childNodes.length!=1||k.firstChild.nodeName!="IMG"){g.focus();g.selection.select(k);g.selection.collapse(0);tinyMCEPopup.storeSelection()}tinyMCEPopup.execCommand("mceEndUndoLevel");tinyMCEPopup.close()},selectInternalLink:function(){var f=d(this);if(f.hasClass("unselectable")){return}f.siblings(".selected").removeClass("selected");f.addClass("selected");a.url.val(f.children(".item-permalink").val());a.title.val(f.children(".item-title").text())},maybeLoadRiver:function(){var g=d(this),f=g.children("ul"),h=g.data("river"),i=g.find(".river-waiting");if(g.scrollTop()+g.height()!=f.height()||h.active||h.allLoaded){return}h.active=true;i.show();e.linkAJAX(g,{page:h.page},function(j){h.page++;h.active=false;h.allLoaded=!j;i.hide()},true)},searchInternalLinks:function(){var f=d(this),h,g=f.val();if(g.length>2){c.recent.hide();c.search.show();if(e.lastSearch==g){return}e.lastSearch=g;h=f.siblings("img.waiting").show();c.search.data("river",e.riverDefaults());c.search.scrollTop(0);e.linkAJAX(c.search,{title:g},function(){h.hide()})}else{c.search.hide();c.recent.show()}},linkAJAX:function(h,g,i,f){if(!h.hasClass("query-results")){h=h.parents(".query-results")}if(!h.length){return}d.post(ajaxurl,d.extend({action:"wp-link-ajax"},g),function(j){var k="";if(!j){if(!f){k+='<li class="no-matches-found unselectable"><span class="item-title"><em>'+wpLinkL10n.noMatchesFound+"</em></span></li>"}}else{d.each(j,function(){k+='<li><input type="hidden" class="item-permalink" value="'+this["permalink"]+'" />';k+='<span class="item-title">';k+=this["title"]?this["title"]:"<em>"+wpLinkL10n.untitled+"</em>";k+='</span><span class="item-info">'+this["info"]+"</span></li>"})}h.children("ul")[f?"append":"html"](k);if(i){i(j)}},"json")}};d(document).ready(e.init)})(jQuery);
</del><span class="cx">\ No newline at end of file
</span><ins>+(function(d){var a={},c={},b,e={timeToTriggerRiver:150,minRiverAJAXDuration:200,lastSearch:"",riverDefaults:function(){return{page:2,allLoaded:false,active:false}},init:function(){var f;b=tinyMCEPopup.editor;a.url=d("#url-field");a.title=d("#link-title-field");a.openInNewTab=d("#link-target-checkbox");a.search=d("#search-field");c.search=d("#search-results");c.recent=d("#most-recent-results");c.search.data("river",e.riverDefaults());c.recent.data("river",e.riverDefaults());d("#wp-update").click(e.update);d("#wp-cancel").click(function(){tinyMCEPopup.close()});d(".query-results").delegate("li","click",e.selectInternalLink);d(".query-results").scroll(e.maybeLoadRiver);a.search.keyup(e.searchInternalLinks);if(f=b.dom.getParent(b.selection.getNode(),"A")){a.url.val(f.href);a.title.val(b.dom.getAttrib(f,"title"));if("_blank"==b.dom.getAttrib(f,"target")){a.openInNewTab.attr("checked","checked")}}a.url.focus()},update:function(){var j,g=tinyMCEPopup.editor,h={href:a.url.val(),title:a.title.val(),target:a.openInNewTab.attr("checked")?"_blank":""},k,f,i=h.title?h.title:h.href;tinyMCEPopup.restoreSelection();k=g.dom.getParent(g.selection.getNode(),"A");if(!h.href){if(g.selection.isCollapsed()){tinyMCEPopup.close();return}else{if(k){tinyMCEPopup.execCommand("mceBeginUndoLevel");f=g.selection.getBookmark();g.dom.remove(k,1);g.selection.moveToBookmark(f);tinyMCEPopup.execCommand("mceEndUndoLevel");tinyMCEPopup.close();return}}}tinyMCEPopup.execCommand("mceBeginUndoLevel");if(k==null){g.getDoc().execCommand("unlink",false,null);if(g.selection.isCollapsed()){j=g.dom.create("a",{href:"#mce_temp_url#"},i);g.selection.setNode(j)}else{tinyMCEPopup.execCommand("CreateLink",false,"#mce_temp_url#",{skip_undo:1})}tinymce.each(g.dom.select("a"),function(l){if(g.dom.getAttrib(l,"href")=="#mce_temp_url#"){k=l;g.dom.setAttribs(k,h)}})}else{g.dom.setAttribs(k,h)}if(k.childNodes.length!=1||k.firstChild.nodeName!="IMG"){g.focus();g.selection.select(k);g.selection.collapse(0);tinyMCEPopup.storeSelection()}tinyMCEPopup.execCommand("mceEndUndoLevel");tinyMCEPopup.close()},selectInternalLink:function(){var f=d(this);if(f.hasClass("unselectable")){return}f.siblings(".selected").removeClass("selected");f.addClass("selected");a.url.val(f.children(".item-permalink").val());a.title.val(f.children(".item-title").text())},maybeLoadRiver:function(){var h=d(this),g=h.children("ul"),i=h.data("river"),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(".river-waiting");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>2){c.recent.hide();c.search.show();if(e.lastSearch==g){return}e.lastSearch=g;h=f.siblings("img.waiting").show();c.search.data("river",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("query-results")){i=i.parents(".query-results")}if(!i.length){return}f=e.delayedCallback(function(k){e.processAJAXResponse(i,k,j,g)},g.delay);d.post(ajaxurl,d.extend({action:"wp-link-ajax"},h),f,"json")},processAJAXResponse:function(i,f,j,g){var h="";if(!f){if(!g.append){h+='<li class="no-matches-found unselectable"><span class="item-title"><em>'+wpLinkL10n.noMatchesFound+"</em></span></li>"}}else{d.each(f,function(){h+='<li><input type="hidden" class="item-permalink" value="'+this["permalink"]+'" />';h+='<span class="item-title">';h+=this["title"]?this["title"]:"<em>"+wpLinkL10n.untitled+"</em>";h+='</span><span class="item-info">'+this["info"]+"</span></li>"})}i.children("ul")[g.append?"append":"html"](h);if(j){j(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);
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludesjstinymcewpmcelinkphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/tinymce/wp-mce-link.php (16406 => 16407)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/tinymce/wp-mce-link.php        2010-11-16 17:51:45 UTC (rev 16406)
+++ trunk/wp-includes/js/tinymce/wp-mce-link.php        2010-11-16 18:30:34 UTC (rev 16407)
</span><span class="lines">@@ -23,7 +23,7 @@
</span><span class="cx"> <?php
</span><span class="cx"> wp_print_scripts( array( 'jquery', 'jquery-ui-widget' ) );
</span><span class="cx"> $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.dev' : '';
</span><del>-$src = "plugins/wplink/js/wplink$suffix.js?ver=20101116";
</del><ins>+$src = "plugins/wplink/js/wplink$suffix.js?ver=20101116b";
</ins><span class="cx"> ?>
</span><span class="cx"> <script type="text/javascript" src="<?php echo $src; ?>"></script>
</span><span class="cx"> <?php
</span><span class="lines">@@ -70,7 +70,7 @@
</span><span class="cx">         float: left;
</span><span class="cx">         width: 220px;
</span><span class="cx"> }
</span><del>-img.waiting {
</del><ins>+.link-search-wrapper img.waiting {
</ins><span class="cx">         margin: 8px 1px 0 4px;
</span><span class="cx">         float: left;
</span><span class="cx">         display: none;
</span></span></pre>
</div>
</div>
</body>
</html>