Pinking shears
git-svn-id: http://svn.automattic.com/wordpress/trunk@16439 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
847499e531
commit
c50cc5c57a
|
@ -26,7 +26,7 @@
|
||||||
title : ed.getLang('advanced.link_desc'),
|
title : ed.getLang('advanced.link_desc'),
|
||||||
cmd : 'WP_Link'
|
cmd : 'WP_Link'
|
||||||
});
|
});
|
||||||
|
|
||||||
ed.addShortcut('alt+shift+a', ed.getLang('advanced.link_desc'), 'WP_Link');
|
ed.addShortcut('alt+shift+a', ed.getLang('advanced.link_desc'), 'WP_Link');
|
||||||
|
|
||||||
// Add a node change handler, selects the button in the UI when a link is selected
|
// Add a node change handler, selects the button in the UI when a link is selected
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
(function($){
|
(function($){
|
||||||
var inputs = {}, results = {}, ed,
|
var inputs = {}, results = {}, ed,
|
||||||
wpLink = {
|
wpLink = {
|
||||||
timeToTriggerRiver: 150,
|
timeToTriggerRiver: 150,
|
||||||
|
@ -15,8 +15,8 @@
|
||||||
var e;
|
var e;
|
||||||
// Init shared vars
|
// Init shared vars
|
||||||
ed = tinyMCEPopup.editor;
|
ed = tinyMCEPopup.editor;
|
||||||
|
|
||||||
|
|
||||||
// URL
|
// URL
|
||||||
inputs.url = $('#url-field');
|
inputs.url = $('#url-field');
|
||||||
// Secondary options
|
// Secondary options
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
results.recent = $('#most-recent-results');
|
results.recent = $('#most-recent-results');
|
||||||
results.search.data('river', wpLink.riverDefaults() );
|
results.search.data('river', wpLink.riverDefaults() );
|
||||||
results.recent.data('river', wpLink.riverDefaults() );
|
results.recent.data('river', wpLink.riverDefaults() );
|
||||||
|
|
||||||
// Bind event handlers
|
// Bind event handlers
|
||||||
$('#wp-update').click( wpLink.update );
|
$('#wp-update').click( wpLink.update );
|
||||||
$('#wp-cancel').click( function() { tinyMCEPopup.close(); } );
|
$('#wp-cancel').click( function() { tinyMCEPopup.close(); } );
|
||||||
|
@ -46,11 +46,11 @@
|
||||||
if ( "_blank" == ed.dom.getAttrib(e, 'target') )
|
if ( "_blank" == ed.dom.getAttrib(e, 'target') )
|
||||||
inputs.openInNewTab.attr('checked','checked');
|
inputs.openInNewTab.attr('checked','checked');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Focus the URL field
|
// Focus the URL field
|
||||||
inputs.url.focus();
|
inputs.url.focus();
|
||||||
},
|
},
|
||||||
|
|
||||||
update : function() {
|
update : function() {
|
||||||
var el,
|
var el,
|
||||||
ed = tinyMCEPopup.editor,
|
ed = tinyMCEPopup.editor,
|
||||||
|
@ -60,10 +60,10 @@
|
||||||
target : inputs.openInNewTab.attr('checked') ? '_blank' : ''
|
target : inputs.openInNewTab.attr('checked') ? '_blank' : ''
|
||||||
}, e, b,
|
}, e, b,
|
||||||
defaultContent = attrs.title ? attrs.title : attrs.href;
|
defaultContent = attrs.title ? attrs.title : attrs.href;
|
||||||
|
|
||||||
tinyMCEPopup.restoreSelection();
|
tinyMCEPopup.restoreSelection();
|
||||||
e = ed.dom.getParent(ed.selection.getNode(), 'A');
|
e = ed.dom.getParent(ed.selection.getNode(), 'A');
|
||||||
|
|
||||||
// If the values are empty...
|
// If the values are empty...
|
||||||
if ( ! attrs.href ) {
|
if ( ! attrs.href ) {
|
||||||
// ...and nothing is selected, we should return
|
// ...and nothing is selected, we should return
|
||||||
|
@ -81,12 +81,12 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tinyMCEPopup.execCommand("mceBeginUndoLevel");
|
tinyMCEPopup.execCommand("mceBeginUndoLevel");
|
||||||
|
|
||||||
if (e == null) {
|
if (e == null) {
|
||||||
ed.getDoc().execCommand("unlink", false, null);
|
ed.getDoc().execCommand("unlink", false, null);
|
||||||
|
|
||||||
// If no selection exists, create a new link from scratch.
|
// If no selection exists, create a new link from scratch.
|
||||||
if ( ed.selection.isCollapsed() ) {
|
if ( ed.selection.isCollapsed() ) {
|
||||||
el = ed.dom.create('a', { href: "#mce_temp_url#" }, defaultContent);
|
el = ed.dom.create('a', { href: "#mce_temp_url#" }, defaultContent);
|
||||||
|
@ -117,7 +117,7 @@
|
||||||
tinyMCEPopup.execCommand("mceEndUndoLevel");
|
tinyMCEPopup.execCommand("mceEndUndoLevel");
|
||||||
tinyMCEPopup.close();
|
tinyMCEPopup.close();
|
||||||
},
|
},
|
||||||
|
|
||||||
selectInternalLink : function() {
|
selectInternalLink : function() {
|
||||||
var t = $(this);
|
var t = $(this);
|
||||||
if ( t.hasClass('unselectable') )
|
if ( t.hasClass('unselectable') )
|
||||||
|
@ -127,24 +127,24 @@
|
||||||
inputs.url.val( t.children('.item-permalink').val() );
|
inputs.url.val( t.children('.item-permalink').val() );
|
||||||
inputs.title.val( t.children('.item-title').text() );
|
inputs.title.val( t.children('.item-title').text() );
|
||||||
},
|
},
|
||||||
|
|
||||||
maybeLoadRiver : function() {
|
maybeLoadRiver : function() {
|
||||||
var t = $(this),
|
var t = $(this),
|
||||||
ul = t.children('ul'),
|
ul = t.children('ul'),
|
||||||
river = t.data('river'),
|
river = t.data('river'),
|
||||||
bottom = t.scrollTop() + t.height();
|
bottom = t.scrollTop() + t.height();
|
||||||
|
|
||||||
if ( bottom != ul.height() || river.active || river.allLoaded )
|
if ( bottom != ul.height() || river.active || river.allLoaded )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
var newTop = t.scrollTop(),
|
var newTop = t.scrollTop(),
|
||||||
newBottom = newTop + t.height(),
|
newBottom = newTop + t.height(),
|
||||||
waiting = t.find('.river-waiting');
|
waiting = t.find('.river-waiting');
|
||||||
|
|
||||||
if ( bottom != newBottom || newBottom != ul.height() || river.active || river.allLoaded )
|
if ( bottom != newBottom || newBottom != ul.height() || river.active || river.allLoaded )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
river.active = true;
|
river.active = true;
|
||||||
waiting.show();
|
waiting.show();
|
||||||
t.scrollTop( newTop + waiting.outerHeight() );
|
t.scrollTop( newTop + waiting.outerHeight() );
|
||||||
|
@ -163,18 +163,18 @@
|
||||||
searchInternalLinks : function() {
|
searchInternalLinks : function() {
|
||||||
var t = $(this), waiting,
|
var t = $(this), waiting,
|
||||||
title = t.val();
|
title = t.val();
|
||||||
|
|
||||||
if ( title.length > 2 ) {
|
if ( title.length > 2 ) {
|
||||||
results.recent.hide();
|
results.recent.hide();
|
||||||
results.search.show();
|
results.search.show();
|
||||||
|
|
||||||
// Don't search if the keypress didn't change the title.
|
// Don't search if the keypress didn't change the title.
|
||||||
if ( wpLink.lastSearch == title )
|
if ( wpLink.lastSearch == title )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wpLink.lastSearch = title;
|
wpLink.lastSearch = title;
|
||||||
waiting = t.siblings('img.waiting').show();
|
waiting = t.siblings('img.waiting').show();
|
||||||
|
|
||||||
results.search.data('river', wpLink.riverDefaults() );
|
results.search.data('river', wpLink.riverDefaults() );
|
||||||
results.search.scrollTop(0);
|
results.search.scrollTop(0);
|
||||||
wpLink.linkAJAX( results.search, { title : title }, function(){ waiting.hide(); });
|
wpLink.linkAJAX( results.search, { title : title }, function(){ waiting.hide(); });
|
||||||
|
@ -183,29 +183,29 @@
|
||||||
results.recent.show();
|
results.recent.show();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
linkAJAX : function( $panel, params, callback, opts ) {
|
linkAJAX : function( $panel, params, callback, opts ) {
|
||||||
var response;
|
var response;
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
if ( ! $panel.hasClass('query-results') )
|
if ( ! $panel.hasClass('query-results') )
|
||||||
$panel = $panel.parents('.query-results');
|
$panel = $panel.parents('.query-results');
|
||||||
|
|
||||||
if ( ! $panel.length )
|
if ( ! $panel.length )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
response = wpLink.delayedCallback( function( results ) {
|
response = wpLink.delayedCallback( function( results ) {
|
||||||
wpLink.processAJAXResponse( $panel, results, callback, opts );
|
wpLink.processAJAXResponse( $panel, results, callback, opts );
|
||||||
}, opts.delay );
|
}, opts.delay );
|
||||||
|
|
||||||
$.post( ajaxurl, $.extend({
|
$.post( ajaxurl, $.extend({
|
||||||
action : 'wp-link-ajax'
|
action : 'wp-link-ajax'
|
||||||
}, params ), response, "json" );
|
}, params ), response, "json" );
|
||||||
},
|
},
|
||||||
|
|
||||||
processAJAXResponse: function( $panel, results, callback, opts ) {
|
processAJAXResponse: function( $panel, results, callback, opts ) {
|
||||||
var list = '';
|
var list = '';
|
||||||
|
|
||||||
if ( !results ) {
|
if ( !results ) {
|
||||||
if ( !opts.append ) {
|
if ( !opts.append ) {
|
||||||
list += '<li class="no-matches-found unselectable"><span class="item-title"><em>'
|
list += '<li class="no-matches-found unselectable"><span class="item-title"><em>'
|
||||||
|
@ -220,28 +220,28 @@
|
||||||
list += '</span><span class="item-info">' + this['info'] + '</span></li>';
|
list += '</span><span class="item-info">' + this['info'] + '</span></li>';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set results
|
// Set results
|
||||||
$panel.children('ul')[ opts.append ? 'append' : 'html' ]( list );
|
$panel.children('ul')[ opts.append ? 'append' : 'html' ]( list );
|
||||||
|
|
||||||
// Run callback
|
// Run callback
|
||||||
if ( callback )
|
if ( callback )
|
||||||
callback( results );
|
callback( results );
|
||||||
},
|
},
|
||||||
|
|
||||||
delayedCallback : function( func, delay ) {
|
delayedCallback : function( func, delay ) {
|
||||||
var timeoutTriggered, funcTriggered, funcArgs, funcContext;
|
var timeoutTriggered, funcTriggered, funcArgs, funcContext;
|
||||||
|
|
||||||
if ( ! delay )
|
if ( ! delay )
|
||||||
return func;
|
return func;
|
||||||
|
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
if ( funcTriggered )
|
if ( funcTriggered )
|
||||||
return func.apply( funcContext, funcArgs );
|
return func.apply( funcContext, funcArgs );
|
||||||
// Otherwise, wait.
|
// Otherwise, wait.
|
||||||
timeoutTriggered = true;
|
timeoutTriggered = true;
|
||||||
}, delay);
|
}, delay);
|
||||||
|
|
||||||
return function() {
|
return function() {
|
||||||
if ( timeoutTriggered )
|
if ( timeoutTriggered )
|
||||||
return func.apply( this, arguments );
|
return func.apply( this, arguments );
|
||||||
|
@ -252,6 +252,6 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready( wpLink.init );
|
$(document).ready( wpLink.init );
|
||||||
})(jQuery);
|
})(jQuery);
|
|
@ -3,7 +3,7 @@
|
||||||
function wp_link_query( $args = array() ) {
|
function wp_link_query( $args = array() ) {
|
||||||
$pts = get_post_types( array( 'publicly_queryable' => true ), 'objects' );
|
$pts = get_post_types( array( 'publicly_queryable' => true ), 'objects' );
|
||||||
$pt_names = array_keys( $pts );
|
$pt_names = array_keys( $pts );
|
||||||
|
|
||||||
$query = array(
|
$query = array(
|
||||||
'post_type' => $pt_names,
|
'post_type' => $pt_names,
|
||||||
'suppress_filters' => true,
|
'suppress_filters' => true,
|
||||||
|
@ -28,7 +28,7 @@ function wp_link_query( $args = array() ) {
|
||||||
// Check if any posts were found.
|
// Check if any posts were found.
|
||||||
if ( ! $get_posts->post_count )
|
if ( ! $get_posts->post_count )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Build results.
|
// Build results.
|
||||||
$results = array();
|
$results = array();
|
||||||
foreach ( $posts as $post ) {
|
foreach ( $posts as $post ) {
|
||||||
|
@ -36,7 +36,7 @@ function wp_link_query( $args = array() ) {
|
||||||
$info = mysql2date( __( 'Y/m/d' ), $post->post_date );
|
$info = mysql2date( __( 'Y/m/d' ), $post->post_date );
|
||||||
else
|
else
|
||||||
$info = $pts[ $post->post_type ]->labels->singular_name;
|
$info = $pts[ $post->post_type ]->labels->singular_name;
|
||||||
|
|
||||||
$results[] = array(
|
$results[] = array(
|
||||||
'ID' => $post->ID,
|
'ID' => $post->ID,
|
||||||
'title' => esc_html( strip_tags($post->post_title) ),
|
'title' => esc_html( strip_tags($post->post_title) ),
|
||||||
|
@ -58,7 +58,7 @@ function wp_link_ajax( $request ) {
|
||||||
|
|
||||||
if ( ! isset( $results ) )
|
if ( ! isset( $results ) )
|
||||||
die( '0' );
|
die( '0' );
|
||||||
|
|
||||||
echo json_encode( $results );
|
echo json_encode( $results );
|
||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue