Improve internal linking river feedback. props koopersmith, see #11420.
git-svn-id: http://svn.automattic.com/wordpress/trunk@16407 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
07a19372f5
commit
c09b2e5b22
|
@ -1,6 +1,8 @@
|
|||
(function($){
|
||||
var inputs = {}, results = {}, ed,
|
||||
wpLink = {
|
||||
timeToTriggerRiver: 150,
|
||||
minRiverAJAXDuration: 200,
|
||||
lastSearch: '',
|
||||
riverDefaults: function() {
|
||||
return {
|
||||
|
@ -130,22 +132,34 @@
|
|||
var t = $(this),
|
||||
ul = t.children('ul'),
|
||||
river = t.data('river'),
|
||||
waiting = t.find('.river-waiting');
|
||||
bottom = t.scrollTop() + t.height();
|
||||
|
||||
if( t.scrollTop() + t.height() != ul.height() || river.active || river.allLoaded )
|
||||
if ( bottom != ul.height() || river.active || river.allLoaded )
|
||||
return;
|
||||
|
||||
river.active = true;
|
||||
waiting.show();
|
||||
|
||||
wpLink.linkAJAX( t, { page : river.page }, function(r) {
|
||||
river.page++;
|
||||
river.active = false;
|
||||
river.allLoaded = !r;
|
||||
waiting.hide();
|
||||
}, true);
|
||||
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 );
|
||||
},
|
||||
|
||||
searchInternalLinks : function() {
|
||||
var t = $(this), waiting,
|
||||
title = t.val();
|
||||
|
@ -170,40 +184,72 @@
|
|||
}
|
||||
},
|
||||
|
||||
linkAJAX : function( $panel, params, callback, append ) {
|
||||
linkAJAX : function( $panel, params, callback, opts ) {
|
||||
var response;
|
||||
opts = opts || {};
|
||||
|
||||
if ( ! $panel.hasClass('query-results') )
|
||||
$panel = $panel.parents('.query-results');
|
||||
|
||||
if ( ! $panel.length )
|
||||
return;
|
||||
|
||||
response = wpLink.delayedCallback( function( results ) {
|
||||
wpLink.processAJAXResponse( $panel, results, callback, opts );
|
||||
}, opts.delay );
|
||||
|
||||
$.post( ajaxurl, $.extend({
|
||||
action : 'wp-link-ajax'
|
||||
}, 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>';
|
||||
});
|
||||
}, 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>';
|
||||
}
|
||||
|
||||
// Set results
|
||||
$panel.children('ul')[ append ? 'append' : 'html' ]( list );
|
||||
|
||||
// Run callback
|
||||
if ( callback )
|
||||
callback( results );
|
||||
}, "json" );
|
||||
} 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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +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);
|
||||
(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);
|
|
@ -23,7 +23,7 @@ var ajaxurl = '<?php echo admin_url( 'admin-ajax.php' ); ?>',
|
|||
<?php
|
||||
wp_print_scripts( array( 'jquery', 'jquery-ui-widget' ) );
|
||||
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.dev' : '';
|
||||
$src = "plugins/wplink/js/wplink$suffix.js?ver=20101116";
|
||||
$src = "plugins/wplink/js/wplink$suffix.js?ver=20101116b";
|
||||
?>
|
||||
<script type="text/javascript" src="<?php echo $src; ?>"></script>
|
||||
<?php
|
||||
|
@ -70,7 +70,7 @@ label span {
|
|||
float: left;
|
||||
width: 220px;
|
||||
}
|
||||
img.waiting {
|
||||
.link-search-wrapper img.waiting {
|
||||
margin: 8px 1px 0 4px;
|
||||
float: left;
|
||||
display: none;
|
||||
|
|
Loading…
Reference in New Issue