Internal linking functionality updates. Scrap pagination for a river of results. props koopersmith, see #11420.
git-svn-id: http://svn.automattic.com/wordpress/trunk@16399 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
16327a7dbb
commit
2f107efd02
|
@ -14,7 +14,7 @@
|
|||
ed.windowManager.open({
|
||||
file : tinymce.baseURL + '/wp-mce-link.php',
|
||||
width : 480,
|
||||
height : 400,
|
||||
height : 430,
|
||||
inline : 1
|
||||
}, {
|
||||
plugin_url : url // Plugin absolute URL
|
||||
|
|
|
@ -1 +1 @@
|
|||
(function(){tinymce.create("tinymce.plugins.wpLink",{init:function(a,b){a.addCommand("WP_Link",function(){a.windowManager.open({file:tinymce.baseURL+"/wp-mce-link.php",width:480,height:400,inline:1},{plugin_url:b})});a.addButton("link",{title:a.getLang("advanced.link_desc"),cmd:"WP_Link"});a.addShortcut("alt+shift+a",a.getLang("advanced.link_desc"),"WP_Link");a.onNodeChange.add(function(d,c,e){c.setActive("wplink",e.nodeName=="A")})},getInfo:function(){return{longname:"WordPress Link Dialog",author:"WordPress",authorurl:"http://wordpress.org",infourl:"",version:"1.0"}}});tinymce.PluginManager.add("wplink",tinymce.plugins.wpLink)})();
|
||||
(function(){tinymce.create("tinymce.plugins.wpLink",{init:function(a,b){a.addCommand("WP_Link",function(){a.windowManager.open({file:tinymce.baseURL+"/wp-mce-link.php",width:480,height:430,inline:1},{plugin_url:b})});a.addButton("link",{title:a.getLang("advanced.link_desc"),cmd:"WP_Link"});a.addShortcut("alt+shift+a",a.getLang("advanced.link_desc"),"WP_Link");a.onNodeChange.add(function(d,c,e){c.setActive("wplink",e.nodeName=="A")})},getInfo:function(){return{longname:"WordPress Link Dialog",author:"WordPress",authorurl:"http://wordpress.org",infourl:"",version:"1.0"}}});tinymce.PluginManager.add("wplink",tinymce.plugins.wpLink)})();
|
|
@ -1,8 +1,16 @@
|
|||
(function($){
|
||||
var inputs = {}, results = {}, ed,
|
||||
wpLink = {
|
||||
lastSearch: '',
|
||||
riverDefaults: function() {
|
||||
return {
|
||||
page : 2,
|
||||
allLoaded: false,
|
||||
active: false
|
||||
};
|
||||
},
|
||||
init : function() {
|
||||
var e, etarget, eclass;
|
||||
var e;
|
||||
// Init shared vars
|
||||
ed = tinyMCEPopup.editor;
|
||||
|
||||
|
@ -17,12 +25,14 @@
|
|||
// Result lists
|
||||
results.search = $('#search-results');
|
||||
results.recent = $('#most-recent-results');
|
||||
results.search.data('river', wpLink.riverDefaults() );
|
||||
results.recent.data('river', wpLink.riverDefaults() );
|
||||
|
||||
// Bind event handlers
|
||||
$('#wp-update').click( wpLink.update );
|
||||
$('#wp-cancel').click( function() { tinyMCEPopup.close(); } );
|
||||
$('.query-results').delegate('li', 'click', wpLink.selectInternalLink );
|
||||
$('.wp-results-pagelinks').delegate('a', 'click', wpLink.selectPageLink );
|
||||
$('.query-results').scroll( wpLink.maybeLoadRiver );
|
||||
inputs.search.keyup( wpLink.searchInternalLinks );
|
||||
|
||||
// If link exists, select proper values.
|
||||
|
@ -34,6 +44,9 @@
|
|||
if ( "_blank" == ed.dom.getAttrib(e, 'target') )
|
||||
inputs.openInNewTab.attr('checked','checked');
|
||||
}
|
||||
|
||||
// Focus the URL field
|
||||
inputs.url.focus();
|
||||
},
|
||||
|
||||
update : function() {
|
||||
|
@ -74,7 +87,7 @@
|
|||
|
||||
// If no selection exists, create a new link from scratch.
|
||||
if ( ed.selection.isCollapsed() ) {
|
||||
var el = ed.dom.create('a', { href: "#mce_temp_url#" }, defaultContent);
|
||||
el = ed.dom.create('a', { href: "#mce_temp_url#" }, defaultContent);
|
||||
ed.selection.setNode(el);
|
||||
// If a selection exists, wrap it in a link.
|
||||
} else {
|
||||
|
@ -113,23 +126,43 @@
|
|||
inputs.title.val( t.children('.item-title').text() );
|
||||
},
|
||||
|
||||
selectPageLink : function(e) {
|
||||
var page = e.target.href.match(/page=(\d+)/);
|
||||
maybeLoadRiver : function() {
|
||||
var t = $(this),
|
||||
ul = t.children('ul'),
|
||||
river = t.data('river'),
|
||||
waiting = t.find('.river-waiting');
|
||||
|
||||
page = page ? page[1] : 1; // If there's no match, it's the first page.
|
||||
e.preventDefault(); // Prevent the link from redirecting.
|
||||
if( t.scrollTop() + t.height() != ul.height() || river.active || river.allLoaded )
|
||||
return;
|
||||
|
||||
wpLink.linkAJAX( $(this), { page : page });
|
||||
river.active = true;
|
||||
waiting.show();
|
||||
|
||||
wpLink.linkAJAX( t, { page : river.page }, function(r) {
|
||||
river.page++;
|
||||
river.active = false;
|
||||
river.allLoaded = !r;
|
||||
waiting.hide();
|
||||
}, true);
|
||||
},
|
||||
|
||||
searchInternalLinks : function() {
|
||||
var t = $(this), waiting,
|
||||
title = t.val();
|
||||
|
||||
if ( title ) {
|
||||
if ( title.length > 2 ) {
|
||||
results.recent.hide();
|
||||
results.search.show();
|
||||
|
||||
// Don't search if the keypress didn't change the title.
|
||||
if ( wpLink.lastSearch == title )
|
||||
return;
|
||||
|
||||
wpLink.lastSearch = title;
|
||||
waiting = t.siblings('img.waiting').show();
|
||||
|
||||
results.search.data('river', wpLink.riverDefaults() );
|
||||
results.search.scrollTop(0);
|
||||
wpLink.linkAJAX( results.search, { title : title }, function(){ waiting.hide(); });
|
||||
} else {
|
||||
results.search.hide();
|
||||
|
@ -137,7 +170,7 @@
|
|||
}
|
||||
},
|
||||
|
||||
linkAJAX : function( $panel, params, callback ) {
|
||||
linkAJAX : function( $panel, params, callback, append ) {
|
||||
if ( ! $panel.hasClass('query-results') )
|
||||
$panel = $panel.parents('.query-results');
|
||||
|
||||
|
@ -146,38 +179,31 @@
|
|||
|
||||
$.post( ajaxurl, $.extend({
|
||||
action : 'wp-link-ajax'
|
||||
}, params ), function(r) {
|
||||
var pagelinks = $panel.children('.wp-results-pagelinks');
|
||||
}, 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>';
|
||||
});
|
||||
}
|
||||
|
||||
// Set results
|
||||
$panel.children('ul').html( wpLink.generateListMarkup( r['results'] ) );
|
||||
|
||||
// Handle page links
|
||||
if ( r['page_links'] )
|
||||
pagelinks.html( r['page_links'] ).show();
|
||||
else
|
||||
pagelinks.hide();
|
||||
$panel.children('ul')[ append ? 'append' : 'html' ]( list );
|
||||
|
||||
// Run callback
|
||||
if ( callback )
|
||||
callback( r['results'] );
|
||||
callback( results );
|
||||
}, "json" );
|
||||
},
|
||||
|
||||
generateListMarkup : function( results ) {
|
||||
var s = '';
|
||||
|
||||
if ( ! results )
|
||||
return '<li class="no-matches-found unselectable"><span class="item-title"><em>' + wpLinkL10n.noMatchesFound + '</em></span></li>';
|
||||
|
||||
$.each( results, function() {
|
||||
s+= '<li><input type="hidden" class="item-permalink" value="' + this['permalink'] + '" />';
|
||||
s+= '<span class="item-title">'
|
||||
s+= this['title'] ? this['title'] : '<em>'+ wpLinkL10n.untitled + '</em>';
|
||||
s+= '</span><span class="item-info">' + this['info'] + '</span>';
|
||||
s+= '</li>';
|
||||
});
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
(function(d){var a={},c={},b,e={init:function(){var h,g,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");d("#wp-update").click(e.update);d("#wp-cancel").click(function(){tinyMCEPopup.close()});d(".query-results").delegate("li","click",e.selectInternalLink);d(".wp-results-pagelinks").delegate("a","click",e.selectPageLink);a.search.keyup(e.searchInternalLinks);if(h=b.dom.getParent(b.selection.getNode(),"A")){a.url.val(h.href);a.title.val(b.dom.getAttrib(h,"title"));if("_blank"==b.dom.getAttrib(h,"target")){a.openInNewTab.attr("checked","checked")}}},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()){var 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())},selectPageLink:function(g){var f=g.target.href.match(/page=(\d+)/);f=f?f[1]:1;g.preventDefault();e.linkAJAX(d(this),{page:f})},searchInternalLinks:function(){var f=d(this),h,g=f.val();if(g){c.recent.hide();c.search.show();h=f.siblings("img.waiting").show();e.linkAJAX(c.search,{title:g},function(){h.hide()})}else{c.search.hide();c.recent.show()}},linkAJAX:function(g,f,h){if(!g.hasClass("query-results")){g=g.parents(".query-results")}if(!g.length){return}d.post(ajaxurl,d.extend({action:"wp-link-ajax"},f),function(j){var i=g.children(".wp-results-pagelinks");g.children("ul").html(e.generateListMarkup(j.results));if(j.page_links){i.html(j.page_links).show()}else{i.hide()}if(h){h(j.results)}},"json")},generateListMarkup:function(f){var g="";if(!f){return'<li class="no-matches-found unselectable"><span class="item-title"><em>'+wpLinkL10n.noMatchesFound+"</em></span></li>"}d.each(f,function(){g+='<li><input type="hidden" class="item-permalink" value="'+this["permalink"]+'" />';g+='<span class="item-title">';g+=this["title"]?this["title"]:"<em>"+wpLinkL10n.untitled+"</em>";g+='</span><span class="item-info">'+this["info"]+"</span>";g+="</li>"});return g}};d(document).ready(e.init)})(jQuery);
|
||||
(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);
|
|
@ -20,12 +20,7 @@ function wp_link_query( $args = array() ) {
|
|||
if ( isset( $args['s'] ) )
|
||||
$query['s'] = $args['s'];
|
||||
|
||||
$pagination = array(
|
||||
'current' => $args['pagenum'],
|
||||
'per_page' => $query['posts_per_page'],
|
||||
);
|
||||
|
||||
$query['offset'] = $pagination['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
|
||||
$query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
|
||||
|
||||
// Do main query.
|
||||
$get_posts = new WP_Query;
|
||||
|
@ -47,27 +42,10 @@ function wp_link_query( $args = array() ) {
|
|||
'title' => esc_html( strip_tags($post->post_title) ),
|
||||
'permalink' => get_permalink( $post->ID ),
|
||||
'info' => $info,
|
||||
);;
|
||||
);
|
||||
}
|
||||
|
||||
// Remaining pagination values.
|
||||
$pagination['max'] = $get_posts->max_num_pages;
|
||||
$pagination['page_links'] = paginate_links( array(
|
||||
'prev_text' => __('«'),
|
||||
'next_text' => __('»'),
|
||||
'total' => $pagination['max'],
|
||||
'current' => $pagination['current']
|
||||
) );
|
||||
|
||||
// Build response.
|
||||
$resp = array(
|
||||
'query' => $get_posts,
|
||||
'objects' => $posts,
|
||||
'results' => $results,
|
||||
'pages' => $pagination,
|
||||
);
|
||||
|
||||
return $resp;
|
||||
return $results;
|
||||
}
|
||||
|
||||
function wp_link_ajax( $request ) {
|
||||
|
@ -76,16 +54,12 @@ function wp_link_ajax( $request ) {
|
|||
$args['s'] = stripslashes( $request['title'] );
|
||||
$args['pagenum'] = ! empty( $request['page'] ) ? absint( $request['page'] ) : 1;
|
||||
|
||||
$resp = wp_link_query( $args );
|
||||
$results = wp_link_query( $args );
|
||||
|
||||
if ( ! isset( $resp ) )
|
||||
if ( ! isset( $results ) )
|
||||
die( '0' );
|
||||
|
||||
$json = array( 'results' => $resp['results'] );
|
||||
if ( isset( $resp['pages'] ) && !empty( $resp['pages']['page_links'] ) )
|
||||
$json['page_links'] = $resp['pages']['page_links'];
|
||||
|
||||
echo json_encode( $json );
|
||||
echo json_encode( $results );
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
|
|
|
@ -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=20101115";
|
||||
$src = "plugins/wplink/js/wplink$suffix.js?ver=20101116";
|
||||
?>
|
||||
<script type="text/javascript" src="<?php echo $src; ?>"></script>
|
||||
<?php
|
||||
|
@ -127,6 +127,14 @@ img.waiting {
|
|||
#search-results {
|
||||
display: none;
|
||||
}
|
||||
.river-waiting {
|
||||
display: none;
|
||||
padding: 10px 0;
|
||||
}
|
||||
.river-waiting img.waiting {
|
||||
margin: 0 auto;
|
||||
display: block;
|
||||
}
|
||||
.submitbox {
|
||||
padding: 5px 5px 0;
|
||||
font-size: 11px;
|
||||
|
@ -157,7 +165,7 @@ img.waiting {
|
|||
<span><?php _e( 'Title' ); ?></span><input id="link-title-field" type="text" />
|
||||
</label>
|
||||
<label for="link-target-checkbox" id="open-in-new-tab">
|
||||
<input type="checkbox" id="link-target-checkbox" /><span><?php _e( 'Open in new tab' ); ?></span>
|
||||
<input type="checkbox" id="link-target-checkbox" /><span><?php _e( 'Open link in a new window/tab' ); ?></span>
|
||||
</label>
|
||||
</div>
|
||||
<div id="search-panel">
|
||||
|
@ -181,7 +189,7 @@ img.waiting {
|
|||
<div id="most-recent-results" class="query-results">
|
||||
<ul>
|
||||
<li class="unselectable"><em><?php _e( 'No search term specified. Showing recent items.' ); ?></em></li>
|
||||
<?php foreach ( $most_recent['results'] as $item ) : ?>
|
||||
<?php foreach ( $most_recent as $item ) : ?>
|
||||
<li>
|
||||
<input type="hidden" class="item-permalink" value="<?php echo esc_url( $item['permalink'] ); ?>" />
|
||||
<span class="item-title"><?php echo $item['title']; ?></span>
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue