TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
/* global ajaxurl, tinymce, wpLinkL10n, setUserSetting, wpActiveEditor */
|
2012-08-22 20:04:18 -04:00
|
|
|
var wpLink;
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
( function( $ ) {
|
2014-04-01 22:27:16 -04:00
|
|
|
var inputs = {}, rivers = {}, editor, searchTimer, River, Query;
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
wpLink = {
|
|
|
|
timeToTriggerRiver: 150,
|
|
|
|
minRiverAJAXDuration: 200,
|
|
|
|
riverBottomThreshold: 5,
|
|
|
|
keySensitivity: 100,
|
|
|
|
lastSearch: '',
|
|
|
|
textarea: '',
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
init: function() {
|
|
|
|
inputs.wrap = $('#wp-link-wrap');
|
|
|
|
inputs.dialog = $( '#wp-link' );
|
|
|
|
inputs.backdrop = $( '#wp-link-backdrop' );
|
|
|
|
inputs.submit = $( '#wp-link-submit' );
|
|
|
|
inputs.close = $( '#wp-link-close' );
|
2012-08-22 20:04:18 -04:00
|
|
|
// URL
|
2014-03-10 20:04:14 -04:00
|
|
|
inputs.url = $( '#url-field' );
|
|
|
|
inputs.nonce = $( '#_ajax_linking_nonce' );
|
2012-08-22 20:04:18 -04:00
|
|
|
// Secondary options
|
2014-03-10 20:04:14 -04:00
|
|
|
inputs.title = $( '#link-title-field' );
|
2012-08-22 20:04:18 -04:00
|
|
|
// Advanced Options
|
2014-03-10 20:04:14 -04:00
|
|
|
inputs.openInNewTab = $( '#link-target-checkbox' );
|
|
|
|
inputs.search = $( '#search-field' );
|
2012-08-22 20:04:18 -04:00
|
|
|
// Build Rivers
|
2014-03-10 20:04:14 -04:00
|
|
|
rivers.search = new River( $( '#search-results' ) );
|
|
|
|
rivers.recent = new River( $( '#most-recent-results' ) );
|
|
|
|
rivers.elements = inputs.dialog.find( '.query-results' );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
// Bind event handlers
|
|
|
|
inputs.dialog.keydown( wpLink.keydown );
|
|
|
|
inputs.dialog.keyup( wpLink.keyup );
|
2014-03-10 20:04:14 -04:00
|
|
|
inputs.submit.click( function( event ) {
|
|
|
|
event.preventDefault();
|
2012-08-22 20:04:18 -04:00
|
|
|
wpLink.update();
|
|
|
|
});
|
2014-03-11 23:07:15 -04:00
|
|
|
inputs.close.add( inputs.backdrop ).add( '#wp-link-cancel a' ).click( function( event ) {
|
2014-03-10 20:04:14 -04:00
|
|
|
event.preventDefault();
|
2012-08-22 20:04:18 -04:00
|
|
|
wpLink.close();
|
|
|
|
});
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
$( '#wp-link-search-toggle' ).click( wpLink.toggleInternalLinking );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
rivers.elements.on( 'river-select', wpLink.updateFields );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2014-04-01 22:27:16 -04:00
|
|
|
inputs.search.keyup( function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
window.clearTimeout( searchTimer );
|
|
|
|
searchTimer = window.setTimeout( function() {
|
|
|
|
wpLink.searchInternalLinks.call( self );
|
|
|
|
}, 500 );
|
|
|
|
});
|
2012-08-22 20:04:18 -04:00
|
|
|
},
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
open: function( editorId ) {
|
|
|
|
var ed;
|
2014-06-09 11:35:14 -04:00
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
wpLink.range = null;
|
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
if ( editorId ) {
|
|
|
|
window.wpActiveEditor = editorId;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! window.wpActiveEditor ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
return;
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
}
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
this.textarea = $( '#' + window.wpActiveEditor ).get( 0 );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
if ( typeof tinymce !== 'undefined' ) {
|
|
|
|
ed = tinymce.get( wpActiveEditor );
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
if ( ed && ! ed.isHidden() ) {
|
|
|
|
editor = ed;
|
|
|
|
} else {
|
|
|
|
editor = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( editor && tinymce.isIE ) {
|
|
|
|
editor.windowManager.bookmark = editor.selection.getBookmark();
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
}
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
if ( ! wpLink.isMCE() && document.selection ) {
|
|
|
|
this.textarea.focus();
|
|
|
|
this.range = document.selection.createRange();
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
inputs.wrap.show();
|
|
|
|
inputs.backdrop.show();
|
|
|
|
|
|
|
|
wpLink.refresh();
|
2012-08-22 20:04:18 -04:00
|
|
|
},
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
isMCE: function() {
|
|
|
|
return editor && ! editor.isHidden();
|
2012-08-22 20:04:18 -04:00
|
|
|
},
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
refresh: function() {
|
2012-08-22 20:04:18 -04:00
|
|
|
// Refresh rivers (clear links, check visibility)
|
|
|
|
rivers.search.refresh();
|
|
|
|
rivers.recent.refresh();
|
|
|
|
|
|
|
|
if ( wpLink.isMCE() )
|
|
|
|
wpLink.mceRefresh();
|
|
|
|
else
|
|
|
|
wpLink.setDefaultValues();
|
|
|
|
|
|
|
|
// Focus the URL field and highlight its contents.
|
|
|
|
// If this is moved above the selection changes,
|
|
|
|
// IE will show a flashing cursor over the dialog.
|
|
|
|
inputs.url.focus()[0].select();
|
|
|
|
// Load the most recent results if this is the first time opening the panel.
|
|
|
|
if ( ! rivers.recent.ul.children().length )
|
|
|
|
rivers.recent.ajax();
|
|
|
|
},
|
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
mceRefresh: function() {
|
2012-08-22 20:04:18 -04:00
|
|
|
var e;
|
|
|
|
|
|
|
|
// If link exists, select proper values.
|
2014-03-10 20:04:14 -04:00
|
|
|
if ( e = editor.dom.getParent( editor.selection.getNode(), 'A' ) ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
// Set URL and description.
|
2014-03-10 20:04:14 -04:00
|
|
|
inputs.url.val( editor.dom.getAttrib( e, 'href' ) );
|
|
|
|
inputs.title.val( editor.dom.getAttrib( e, 'title' ) );
|
2012-08-22 20:04:18 -04:00
|
|
|
// Set open in new tab.
|
2014-03-10 20:04:14 -04:00
|
|
|
inputs.openInNewTab.prop( 'checked', ( '_blank' === editor.dom.getAttrib( e, 'target' ) ) );
|
2012-08-22 20:04:18 -04:00
|
|
|
// Update save prompt.
|
|
|
|
inputs.submit.val( wpLinkL10n.update );
|
|
|
|
|
|
|
|
// If there's no link, set the default values.
|
|
|
|
} else {
|
|
|
|
wpLink.setDefaultValues();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
close: function() {
|
2012-08-22 20:04:18 -04:00
|
|
|
if ( ! wpLink.isMCE() ) {
|
|
|
|
wpLink.textarea.focus();
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
if ( wpLink.range ) {
|
|
|
|
wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
|
|
|
|
wpLink.range.select();
|
|
|
|
}
|
2014-03-10 20:04:14 -04:00
|
|
|
} else {
|
|
|
|
editor.focus();
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
2014-03-10 20:04:14 -04:00
|
|
|
|
|
|
|
inputs.backdrop.hide();
|
|
|
|
inputs.wrap.hide();
|
2012-08-22 20:04:18 -04:00
|
|
|
},
|
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
getAttrs: function() {
|
2012-08-22 20:04:18 -04:00
|
|
|
return {
|
2014-03-10 20:04:14 -04:00
|
|
|
href: inputs.url.val(),
|
|
|
|
title: inputs.title.val(),
|
|
|
|
target: inputs.openInNewTab.prop( 'checked' ) ? '_blank' : ''
|
2012-08-22 20:04:18 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
update: function() {
|
2012-08-22 20:04:18 -04:00
|
|
|
if ( wpLink.isMCE() )
|
|
|
|
wpLink.mceUpdate();
|
|
|
|
else
|
|
|
|
wpLink.htmlUpdate();
|
|
|
|
},
|
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
htmlUpdate: function() {
|
2014-02-03 16:27:12 -05:00
|
|
|
var attrs, html, begin, end, cursor, title, selection,
|
2012-08-22 20:04:18 -04:00
|
|
|
textarea = wpLink.textarea;
|
|
|
|
|
|
|
|
if ( ! textarea )
|
|
|
|
return;
|
|
|
|
|
|
|
|
attrs = wpLink.getAttrs();
|
|
|
|
|
|
|
|
// If there's no href, return.
|
|
|
|
if ( ! attrs.href || attrs.href == 'http://' )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Build HTML
|
|
|
|
html = '<a href="' + attrs.href + '"';
|
|
|
|
|
2014-02-03 15:17:11 -05:00
|
|
|
if ( attrs.title ) {
|
2014-02-02 16:12:12 -05:00
|
|
|
title = attrs.title.replace( /</g, '<' ).replace( />/g, '>' ).replace( /"/g, '"' );
|
|
|
|
html += ' title="' + title + '"';
|
2014-02-03 15:17:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( attrs.target ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
html += ' target="' + attrs.target + '"';
|
2014-02-03 15:17:11 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
html += '>';
|
|
|
|
|
|
|
|
// Insert HTML
|
|
|
|
if ( document.selection && wpLink.range ) {
|
|
|
|
// IE
|
|
|
|
// Note: If no text is selected, IE will not place the cursor
|
|
|
|
// inside the closing tag.
|
|
|
|
textarea.focus();
|
|
|
|
wpLink.range.text = html + wpLink.range.text + '</a>';
|
|
|
|
wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
|
|
|
|
wpLink.range.select();
|
|
|
|
|
|
|
|
wpLink.range = null;
|
|
|
|
} else if ( typeof textarea.selectionStart !== 'undefined' ) {
|
|
|
|
// W3C
|
|
|
|
begin = textarea.selectionStart;
|
|
|
|
end = textarea.selectionEnd;
|
|
|
|
selection = textarea.value.substring( begin, end );
|
|
|
|
html = html + selection + '</a>';
|
|
|
|
cursor = begin + html.length;
|
|
|
|
|
2013-11-26 16:45:09 -05:00
|
|
|
// If no text is selected, place the cursor inside the closing tag.
|
2012-08-22 20:04:18 -04:00
|
|
|
if ( begin == end )
|
|
|
|
cursor -= '</a>'.length;
|
|
|
|
|
2013-11-14 23:28:10 -05:00
|
|
|
textarea.value = textarea.value.substring( 0, begin ) + html +
|
|
|
|
textarea.value.substring( end, textarea.value.length );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
// Update cursor position
|
|
|
|
textarea.selectionStart = textarea.selectionEnd = cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpLink.close();
|
|
|
|
textarea.focus();
|
|
|
|
},
|
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
mceUpdate: function() {
|
|
|
|
var link,
|
|
|
|
attrs = wpLink.getAttrs();
|
|
|
|
|
|
|
|
wpLink.close();
|
2014-03-10 20:04:14 -04:00
|
|
|
editor.focus();
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
|
|
|
|
if ( tinymce.isIE ) {
|
2014-03-10 20:04:14 -04:00
|
|
|
editor.selection.moveToBookmark( editor.windowManager.bookmark );
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
link = editor.dom.getParent( editor.selection.getNode(), 'a[href]' );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
// If the values are empty, unlink and return
|
|
|
|
if ( ! attrs.href || attrs.href == 'http://' ) {
|
2014-03-10 20:04:14 -04:00
|
|
|
editor.execCommand( 'unlink' );
|
2012-08-22 20:04:18 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
if ( link ) {
|
2014-03-10 20:04:14 -04:00
|
|
|
editor.dom.setAttribs( link, attrs );
|
2012-08-22 20:04:18 -04:00
|
|
|
} else {
|
2014-03-10 20:04:14 -04:00
|
|
|
editor.execCommand( 'mceInsertLink', false, attrs );
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
// Move the cursor to the end of the selection
|
2014-03-10 20:04:14 -04:00
|
|
|
editor.selection.collapse();
|
2012-08-22 20:04:18 -04:00
|
|
|
},
|
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
updateFields: function( e, li, originalEvent ) {
|
2014-03-10 20:04:14 -04:00
|
|
|
inputs.url.val( li.children( '.item-permalink' ).val() );
|
|
|
|
inputs.title.val( li.hasClass( 'no-title' ) ? '' : li.children( '.item-title' ).text() );
|
2013-11-14 23:28:10 -05:00
|
|
|
if ( originalEvent && originalEvent.type == 'click' )
|
2012-08-22 20:04:18 -04:00
|
|
|
inputs.url.focus();
|
|
|
|
},
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
|
|
|
|
setDefaultValues: function() {
|
2014-06-09 11:35:14 -04:00
|
|
|
var selection = tinymce.activeEditor.selection.getContent();
|
|
|
|
|
|
|
|
if ( /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(selection) ) {
|
|
|
|
// Selection is email address
|
|
|
|
inputs.url.val( 'mailto:' + selection );
|
|
|
|
} else if ( /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test( selection ) ) {
|
|
|
|
// Selection is URL
|
|
|
|
inputs.url.val( selection );
|
|
|
|
} else {
|
|
|
|
// Set URL to default.
|
|
|
|
inputs.url.val( 'http://' );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set description to default.
|
2014-03-10 20:04:14 -04:00
|
|
|
inputs.title.val( '' );
|
2013-08-15 17:44:09 -04:00
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
// Update save prompt.
|
|
|
|
inputs.submit.val( wpLinkL10n.save );
|
|
|
|
},
|
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
searchInternalLinks: function() {
|
2014-03-10 20:04:14 -04:00
|
|
|
var t = $( this ), waiting,
|
2012-08-22 20:04:18 -04:00
|
|
|
search = t.val();
|
|
|
|
|
|
|
|
if ( search.length > 2 ) {
|
|
|
|
rivers.recent.hide();
|
|
|
|
rivers.search.show();
|
|
|
|
|
|
|
|
// Don't search if the keypress didn't change the title.
|
|
|
|
if ( wpLink.lastSearch == search )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wpLink.lastSearch = search;
|
2014-04-01 22:27:16 -04:00
|
|
|
waiting = t.parent().find('.spinner').show();
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
rivers.search.change( search );
|
2014-03-10 20:04:14 -04:00
|
|
|
rivers.search.ajax( function() {
|
|
|
|
waiting.hide();
|
|
|
|
});
|
2012-08-22 20:04:18 -04:00
|
|
|
} else {
|
|
|
|
rivers.search.hide();
|
|
|
|
rivers.recent.show();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
next: function() {
|
2012-08-22 20:04:18 -04:00
|
|
|
rivers.search.next();
|
|
|
|
rivers.recent.next();
|
|
|
|
},
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
|
|
|
|
prev: function() {
|
2012-08-22 20:04:18 -04:00
|
|
|
rivers.search.prev();
|
|
|
|
rivers.recent.prev();
|
|
|
|
},
|
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
keydown: function( event ) {
|
2014-03-10 20:04:14 -04:00
|
|
|
var fn, id,
|
|
|
|
key = $.ui.keyCode;
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
if ( key.ESCAPE === event.keyCode ) {
|
2014-02-03 00:31:14 -05:00
|
|
|
wpLink.close();
|
|
|
|
event.stopImmediatePropagation();
|
2014-03-10 20:04:14 -04:00
|
|
|
} else if ( key.TAB === event.keyCode ) {
|
|
|
|
id = event.target.id;
|
|
|
|
|
|
|
|
if ( id === 'wp-link-submit' && ! event.shiftKey ) {
|
|
|
|
inputs.close.focus();
|
|
|
|
event.preventDefault();
|
|
|
|
} else if ( id === 'wp-link-close' && event.shiftKey ) {
|
|
|
|
inputs.submit.focus();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2014-02-03 00:31:14 -05:00
|
|
|
}
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
if ( event.keyCode !== key.UP && event.keyCode !== key.DOWN ) {
|
2013-11-14 23:28:10 -05:00
|
|
|
return;
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
2013-11-14 23:28:10 -05:00
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
fn = event.keyCode === key.UP ? 'prev' : 'next';
|
2013-11-14 23:28:10 -05:00
|
|
|
clearInterval( wpLink.keyInterval );
|
|
|
|
wpLink[ fn ]();
|
|
|
|
wpLink.keyInterval = setInterval( wpLink[ fn ], wpLink.keySensitivity );
|
2012-08-22 20:04:18 -04:00
|
|
|
event.preventDefault();
|
|
|
|
},
|
2013-11-14 23:28:10 -05:00
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
keyup: function( event ) {
|
|
|
|
var key = $.ui.keyCode;
|
|
|
|
|
2013-11-14 23:28:10 -05:00
|
|
|
if ( event.which === key.UP || event.which === key.DOWN ) {
|
|
|
|
clearInterval( wpLink.keyInterval );
|
|
|
|
event.preventDefault();
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
delayedCallback: function( func, delay ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
var timeoutTriggered, funcTriggered, funcArgs, funcContext;
|
|
|
|
|
|
|
|
if ( ! delay )
|
|
|
|
return func;
|
|
|
|
|
|
|
|
setTimeout( function() {
|
|
|
|
if ( funcTriggered )
|
|
|
|
return func.apply( funcContext, funcArgs );
|
|
|
|
// Otherwise, wait.
|
|
|
|
timeoutTriggered = true;
|
2014-03-10 20:04:14 -04:00
|
|
|
}, delay );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
return function() {
|
|
|
|
if ( timeoutTriggered )
|
|
|
|
return func.apply( this, arguments );
|
|
|
|
// Otherwise, wait.
|
|
|
|
funcArgs = arguments;
|
|
|
|
funcContext = this;
|
|
|
|
funcTriggered = true;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
toggleInternalLinking: function() {
|
|
|
|
var visible = inputs.wrap.hasClass( 'search-panel-visible' );
|
|
|
|
|
|
|
|
inputs.wrap.toggleClass( 'search-panel-visible', ! visible );
|
|
|
|
setUserSetting( 'wplink', visible ? '0' : '1' );
|
|
|
|
inputs[ ! visible ? 'search' : 'url' ].focus();
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
2013-11-07 05:42:09 -05:00
|
|
|
};
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
River = function( element, search ) {
|
|
|
|
var self = this;
|
|
|
|
this.element = element;
|
2014-03-10 20:04:14 -04:00
|
|
|
this.ul = element.children( 'ul' );
|
|
|
|
this.contentHeight = element.children( '#link-selector-height' );
|
2014-04-01 22:27:16 -04:00
|
|
|
this.waiting = element.find('.river-waiting');
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
this.change( search );
|
|
|
|
this.refresh();
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
$( '#wp-link .query-results, #wp-link #link-selector' ).scroll( function() {
|
|
|
|
self.maybeLoad();
|
|
|
|
});
|
|
|
|
element.on( 'click', 'li', function( event ) {
|
|
|
|
self.select( $( this ), event );
|
|
|
|
});
|
2012-08-22 20:04:18 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.extend( River.prototype, {
|
|
|
|
refresh: function() {
|
|
|
|
this.deselect();
|
2014-03-10 20:04:14 -04:00
|
|
|
this.visible = this.element.is( ':visible' );
|
2012-08-22 20:04:18 -04:00
|
|
|
},
|
|
|
|
show: function() {
|
|
|
|
if ( ! this.visible ) {
|
|
|
|
this.deselect();
|
|
|
|
this.element.show();
|
|
|
|
this.visible = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hide: function() {
|
|
|
|
this.element.hide();
|
|
|
|
this.visible = false;
|
|
|
|
},
|
|
|
|
// Selects a list item and triggers the river-select event.
|
|
|
|
select: function( li, event ) {
|
|
|
|
var liHeight, elHeight, liTop, elTop;
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
if ( li.hasClass( 'unselectable' ) || li == this.selected )
|
2012-08-22 20:04:18 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
this.deselect();
|
2014-03-10 20:04:14 -04:00
|
|
|
this.selected = li.addClass( 'selected' );
|
2012-08-22 20:04:18 -04:00
|
|
|
// Make sure the element is visible
|
|
|
|
liHeight = li.outerHeight();
|
|
|
|
elHeight = this.element.height();
|
|
|
|
liTop = li.position().top;
|
|
|
|
elTop = this.element.scrollTop();
|
|
|
|
|
|
|
|
if ( liTop < 0 ) // Make first visible element
|
|
|
|
this.element.scrollTop( elTop + liTop );
|
|
|
|
else if ( liTop + liHeight > elHeight ) // Make last visible element
|
|
|
|
this.element.scrollTop( elTop + liTop - elHeight + liHeight );
|
|
|
|
|
|
|
|
// Trigger the river-select event
|
2014-03-10 20:04:14 -04:00
|
|
|
this.element.trigger( 'river-select', [ li, event, this ] );
|
2012-08-22 20:04:18 -04:00
|
|
|
},
|
|
|
|
deselect: function() {
|
|
|
|
if ( this.selected )
|
2014-03-10 20:04:14 -04:00
|
|
|
this.selected.removeClass( 'selected' );
|
2012-08-22 20:04:18 -04:00
|
|
|
this.selected = false;
|
|
|
|
},
|
|
|
|
prev: function() {
|
|
|
|
if ( ! this.visible )
|
|
|
|
return;
|
|
|
|
|
|
|
|
var to;
|
|
|
|
if ( this.selected ) {
|
2014-03-10 20:04:14 -04:00
|
|
|
to = this.selected.prev( 'li' );
|
2012-08-22 20:04:18 -04:00
|
|
|
if ( to.length )
|
|
|
|
this.select( to );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
next: function() {
|
|
|
|
if ( ! this.visible )
|
|
|
|
return;
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
var to = this.selected ? this.selected.next( 'li' ) : $( 'li:not(.unselectable):first', this.element );
|
2012-08-22 20:04:18 -04:00
|
|
|
if ( to.length )
|
|
|
|
this.select( to );
|
|
|
|
},
|
|
|
|
ajax: function( callback ) {
|
|
|
|
var self = this,
|
|
|
|
delay = this.query.page == 1 ? 0 : wpLink.minRiverAJAXDuration,
|
|
|
|
response = wpLink.delayedCallback( function( results, params ) {
|
|
|
|
self.process( results, params );
|
|
|
|
if ( callback )
|
|
|
|
callback( results, params );
|
|
|
|
}, delay );
|
|
|
|
|
|
|
|
this.query.ajax( response );
|
|
|
|
},
|
|
|
|
change: function( search ) {
|
|
|
|
if ( this.query && this._search == search )
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._search = search;
|
|
|
|
this.query = new Query( search );
|
2014-03-10 20:04:14 -04:00
|
|
|
this.element.scrollTop( 0 );
|
2012-08-22 20:04:18 -04:00
|
|
|
},
|
|
|
|
process: function( results, params ) {
|
|
|
|
var list = '', alt = true, classes = '',
|
|
|
|
firstPage = params.page == 1;
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
if ( ! results ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
if ( firstPage ) {
|
2013-11-14 23:28:10 -05:00
|
|
|
list += '<li class="unselectable"><span class="item-title"><em>' +
|
|
|
|
wpLinkL10n.noMatchesFound + '</em></span></li>';
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$.each( results, function() {
|
|
|
|
classes = alt ? 'alternate' : '';
|
2013-11-14 23:28:10 -05:00
|
|
|
classes += this.title ? '' : ' no-title';
|
2012-08-22 20:04:18 -04:00
|
|
|
list += classes ? '<li class="' + classes + '">' : '<li>';
|
2013-11-14 23:28:10 -05:00
|
|
|
list += '<input type="hidden" class="item-permalink" value="' + this.permalink + '" />';
|
2012-08-22 20:04:18 -04:00
|
|
|
list += '<span class="item-title">';
|
2013-11-14 23:28:10 -05:00
|
|
|
list += this.title ? this.title : wpLinkL10n.noTitle;
|
|
|
|
list += '</span><span class="item-info">' + this.info + '</span></li>';
|
2012-08-22 20:04:18 -04:00
|
|
|
alt = ! alt;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.ul[ firstPage ? 'html' : 'append' ]( list );
|
|
|
|
},
|
|
|
|
maybeLoad: function() {
|
|
|
|
var self = this,
|
|
|
|
el = this.element,
|
|
|
|
bottom = el.scrollTop() + el.height();
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
if ( ! this.query.ready() || bottom < this.contentHeight.height() - wpLink.riverBottomThreshold )
|
2012-08-22 20:04:18 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
var newTop = el.scrollTop(),
|
|
|
|
newBottom = newTop + el.height();
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
if ( ! self.query.ready() || newBottom < self.contentHeight.height() - wpLink.riverBottomThreshold )
|
2012-08-22 20:04:18 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
self.waiting.show();
|
|
|
|
el.scrollTop( newTop + self.waiting.outerHeight() );
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
self.ajax( function() {
|
|
|
|
self.waiting.hide();
|
|
|
|
});
|
2012-08-22 20:04:18 -04:00
|
|
|
}, wpLink.timeToTriggerRiver );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Query = function( search ) {
|
|
|
|
this.page = 1;
|
|
|
|
this.allLoaded = false;
|
|
|
|
this.querying = false;
|
|
|
|
this.search = search;
|
|
|
|
};
|
|
|
|
|
|
|
|
$.extend( Query.prototype, {
|
|
|
|
ready: function() {
|
2014-03-10 20:04:14 -04:00
|
|
|
return ! ( this.querying || this.allLoaded );
|
2012-08-22 20:04:18 -04:00
|
|
|
},
|
|
|
|
ajax: function( callback ) {
|
|
|
|
var self = this,
|
|
|
|
query = {
|
|
|
|
action : 'wp-link-ajax',
|
|
|
|
page : this.page,
|
|
|
|
'_ajax_linking_nonce' : inputs.nonce.val()
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( this.search )
|
|
|
|
query.search = this.search;
|
|
|
|
|
|
|
|
this.querying = true;
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
$.post( ajaxurl, query, function( r ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
self.page++;
|
|
|
|
self.querying = false;
|
2014-03-10 20:04:14 -04:00
|
|
|
self.allLoaded = ! r;
|
2012-08-22 20:04:18 -04:00
|
|
|
callback( r, query );
|
2013-11-14 23:28:10 -05:00
|
|
|
}, 'json' );
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
$( document ).ready( wpLink.init );
|
|
|
|
})( jQuery );
|