WordPress.org

Make WordPress Core

Changeset 16407


Ignore:
Timestamp:
11/16/2010 06:30:34 PM (10 years ago)
Author:
nacin
Message:

Improve internal linking river feedback. props koopersmith, see #11420.

Location:
trunk/wp-includes/js/tinymce
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/tinymce/plugins/wplink/js/wplink.dev.js

    r16399 r16407  
    22    var inputs = {}, results = {}, ed,
    33    wpLink = {
     4        timeToTriggerRiver: 150,
     5        minRiverAJAXDuration: 200,
    46        lastSearch: '',
    57        riverDefaults: function() {
     
    131133                ul = t.children('ul'),
    132134                river = t.data('river'),
    133                 waiting = t.find('.river-waiting');
    134            
    135             if( t.scrollTop() + t.height() != ul.height() || river.active || river.allLoaded )
     135                bottom = t.scrollTop() + t.height();
     136           
     137            if ( bottom != ul.height() || river.active || river.allLoaded )
    136138                return;
    137139           
    138             river.active = true;
    139             waiting.show();
    140            
    141             wpLink.linkAJAX( t, { page : river.page }, function(r) {
    142                 river.page++;
    143                 river.active = false;
    144                 river.allLoaded = !r;
    145                 waiting.hide();
    146             }, true);
    147         },
    148        
     140            setTimeout(function() {
     141                var newTop = t.scrollTop(),
     142                    newBottom = newTop + t.height(),
     143                    waiting = t.find('.river-waiting');
     144               
     145                if ( bottom != newBottom || newBottom != ul.height() || river.active || river.allLoaded )
     146                    return;
     147               
     148                river.active = true;
     149                waiting.show();
     150                t.scrollTop( newTop + waiting.outerHeight() );
     151
     152                wpLink.linkAJAX( t, { page : river.page }, function(r) {
     153                    river.page++;
     154                    river.active = false;
     155                    river.allLoaded = !r;
     156                    waiting.hide();
     157                }, {
     158                    append : true,
     159                    delay : wpLink.minRiverAJAXDuration
     160                });
     161            }, wpLink.timeToTriggerRiver );
     162        },
    149163        searchInternalLinks : function() {
    150164            var t = $(this), waiting,
     
    171185        },
    172186       
    173         linkAJAX : function( $panel, params, callback, append ) {
     187        linkAJAX : function( $panel, params, callback, opts ) {
     188            var response;
     189            opts = opts || {};
     190           
    174191            if ( ! $panel.hasClass('query-results') )
    175192                $panel = $panel.parents('.query-results');
     
    178195                return;
    179196           
     197            response = wpLink.delayedCallback( function( results ) {
     198                wpLink.processAJAXResponse( $panel, results, callback, opts );
     199            }, opts.delay );
     200           
    180201            $.post( ajaxurl, $.extend({
    181202                action : 'wp-link-ajax'
    182             }, params ), function( results ) {
    183                 var list = '';
    184                
    185                 if ( !results ) {
    186                     if ( !append ) {
    187                         list += '<li class="no-matches-found unselectable"><span class="item-title"><em>'
    188                         + wpLinkL10n.noMatchesFound
    189                         + '</em></span></li>';
    190                     }
    191                 } else {
    192                     $.each( results, function() {
    193                         list += '<li><input type="hidden" class="item-permalink" value="' + this['permalink'] + '" />';
    194                         list += '<span class="item-title">';
    195                         list += this['title'] ? this['title'] : '<em>'+ wpLinkL10n.untitled + '</em>';
    196                         list += '</span><span class="item-info">' + this['info'] + '</span></li>';
    197                     });
     203            }, params ), response, "json" );
     204        },
     205       
     206        processAJAXResponse: function( $panel, results, callback, opts ) {
     207            var list = '';
     208           
     209            if ( !results ) {
     210                if ( !opts.append ) {
     211                    list += '<li class="no-matches-found unselectable"><span class="item-title"><em>'
     212                    + wpLinkL10n.noMatchesFound
     213                    + '</em></span></li>';
    198214                }
    199                
    200                 // Set results
    201                 $panel.children('ul')[ append ? 'append' : 'html' ]( list );
    202                
    203                 // Run callback
    204                 if ( callback )
    205                     callback( results );
    206             }, "json" );
     215            } else {
     216                $.each( results, function() {
     217                    list += '<li><input type="hidden" class="item-permalink" value="' + this['permalink'] + '" />';
     218                    list += '<span class="item-title">';
     219                    list += this['title'] ? this['title'] : '<em>'+ wpLinkL10n.untitled + '</em>';
     220                    list += '</span><span class="item-info">' + this['info'] + '</span></li>';
     221                });
     222            }
     223           
     224            // Set results
     225            $panel.children('ul')[ opts.append ? 'append' : 'html' ]( list );
     226           
     227            // Run callback
     228            if ( callback )
     229                callback( results );
     230        },
     231       
     232        delayedCallback : function( func, delay ) {
     233            var timeoutTriggered, funcTriggered, funcArgs, funcContext;
     234           
     235            if ( ! delay )
     236                return func;
     237           
     238            setTimeout( function() {
     239                if ( funcTriggered )
     240                    return func.apply( funcContext, funcArgs );
     241                // Otherwise, wait.
     242                timeoutTriggered = true;
     243            }, delay);
     244           
     245            return function() {
     246                if ( timeoutTriggered )
     247                    return func.apply( this, arguments );
     248                // Otherwise, wait.
     249                funcArgs = arguments;
     250                funcContext = this;
     251                funcTriggered = true;
     252            };
    207253        }
    208254    }
  • trunk/wp-includes/js/tinymce/plugins/wplink/js/wplink.js

    r16399 r16407  
    1 (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);
     1(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);
  • trunk/wp-includes/js/tinymce/wp-mce-link.php

    r16399 r16407  
    2424wp_print_scripts( array( 'jquery', 'jquery-ui-widget' ) );
    2525$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.dev' : '';
    26 $src = "plugins/wplink/js/wplink$suffix.js?ver=20101116";
     26$src = "plugins/wplink/js/wplink$suffix.js?ver=20101116b";
    2727?>
    2828<script type="text/javascript" src="<?php echo $src; ?>"></script>
     
    7171    width: 220px;
    7272}
    73 img.waiting {
     73.link-search-wrapper img.waiting {
    7474    margin: 8px 1px 0 4px;
    7575    float: left;
Note: See TracChangeset for help on using the changeset viewer.