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( $ ) {
|
2015-03-02 19:01:28 -05:00
|
|
|
var editor, searchTimer, River, Query, correctedURL,
|
2014-07-31 19:28:19 -04:00
|
|
|
inputs = {},
|
|
|
|
rivers = {},
|
|
|
|
isTouch = ( 'ontouchend' in document );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-03-10 22:40:27 -04:00
|
|
|
function getLink() {
|
|
|
|
return editor.dom.getParent( editor.selection.getNode(), 'a' );
|
|
|
|
}
|
|
|
|
|
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' );
|
2015-03-10 22:40:27 -04:00
|
|
|
|
|
|
|
// Input
|
|
|
|
inputs.text = $( '#wp-link-text' );
|
|
|
|
inputs.url = $( '#wp-link-url' );
|
2014-03-10 20:04:14 -04:00
|
|
|
inputs.nonce = $( '#_ajax_linking_nonce' );
|
2015-03-10 22:40:27 -04:00
|
|
|
inputs.openInNewTab = $( '#wp-link-target' );
|
|
|
|
inputs.search = $( '#wp-link-search' );
|
|
|
|
|
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
|
|
|
|
2014-07-28 23:16:17 -04:00
|
|
|
// Get search notice text
|
|
|
|
inputs.queryNotice = $( '#query-notice-message' );
|
|
|
|
inputs.queryNoticeTextDefault = inputs.queryNotice.find( '.query-notice-default' );
|
|
|
|
inputs.queryNoticeTextHint = inputs.queryNotice.find( '.query-notice-hint' );
|
|
|
|
|
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-07-28 23:16:17 -04:00
|
|
|
$( '#wp-link-search-toggle' ).on( '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-07-28 23:16:17 -04:00
|
|
|
// Display 'hint' message when search field or 'query-results' box are focused
|
2014-07-31 19:28:19 -04:00
|
|
|
inputs.search.on( 'focus.wplink', function() {
|
2014-07-28 23:16:17 -04:00
|
|
|
inputs.queryNoticeTextDefault.hide();
|
|
|
|
inputs.queryNoticeTextHint.removeClass( 'screen-reader-text' ).show();
|
|
|
|
} ).on( 'blur.wplink', function() {
|
|
|
|
inputs.queryNoticeTextDefault.show();
|
|
|
|
inputs.queryNoticeTextHint.addClass( 'screen-reader-text' ).hide();
|
|
|
|
} );
|
|
|
|
|
2015-05-25 02:41:25 -04:00
|
|
|
inputs.search.on( 'keyup input', function() {
|
2014-04-01 22:27:16 -04:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
window.clearTimeout( searchTimer );
|
|
|
|
searchTimer = window.setTimeout( function() {
|
|
|
|
wpLink.searchInternalLinks.call( self );
|
|
|
|
}, 500 );
|
|
|
|
});
|
2015-03-02 19:01:28 -05:00
|
|
|
|
2015-03-03 16:21:25 -05:00
|
|
|
function correctURL() {
|
|
|
|
var url = $.trim( inputs.url.val() );
|
|
|
|
|
|
|
|
if ( url && correctedURL !== url && ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( url ) ) {
|
|
|
|
inputs.url.val( 'http://' + url );
|
|
|
|
correctedURL = url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inputs.url.on( 'paste', function() {
|
|
|
|
setTimeout( correctURL, 0 );
|
2015-03-02 19:01:28 -05:00
|
|
|
} );
|
2015-03-03 16:21:25 -05:00
|
|
|
|
|
|
|
inputs.url.on( 'blur', correctURL );
|
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
|
|
|
|
2014-12-02 03:09:25 -05:00
|
|
|
$( document.body ).addClass( 'modal-open' );
|
|
|
|
|
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();
|
2015-03-10 22:40:27 -04:00
|
|
|
|
2014-07-31 22:04:17 -04:00
|
|
|
$( document ).trigger( 'wplink-open', inputs.wrap );
|
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() {
|
2015-04-21 09:59:30 -04:00
|
|
|
var text = '';
|
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
// Refresh rivers (clear links, check visibility)
|
|
|
|
rivers.search.refresh();
|
|
|
|
rivers.recent.refresh();
|
|
|
|
|
2014-07-31 19:28:19 -04:00
|
|
|
if ( wpLink.isMCE() ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
wpLink.mceRefresh();
|
2014-07-31 19:28:19 -04:00
|
|
|
} else {
|
2015-04-21 09:59:30 -04:00
|
|
|
// For the Text editor the "Link text" field is always shown
|
|
|
|
if ( ! inputs.wrap.hasClass( 'has-text-field' ) ) {
|
|
|
|
inputs.wrap.addClass( 'has-text-field' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( document.selection ) {
|
|
|
|
// Old IE
|
|
|
|
text = document.selection.createRange().text || '';
|
|
|
|
} else if ( typeof this.textarea.selectionStart !== 'undefined' &&
|
|
|
|
( this.textarea.selectionStart !== this.textarea.selectionEnd ) ) {
|
|
|
|
// W3C
|
|
|
|
text = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd ) || '';
|
|
|
|
}
|
|
|
|
|
|
|
|
inputs.text.val( text );
|
2012-08-22 20:04:18 -04:00
|
|
|
wpLink.setDefaultValues();
|
2014-07-31 19:28:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( isTouch ) {
|
|
|
|
// Close the onscreen keyboard
|
|
|
|
inputs.url.focus().blur();
|
|
|
|
} else {
|
|
|
|
// 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.
|
2015-03-10 23:01:27 -04:00
|
|
|
inputs.url.focus()[0].select();
|
2014-07-31 19:28:19 -04:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
// Load the most recent results if this is the first time opening the panel.
|
2014-07-31 19:28:19 -04:00
|
|
|
if ( ! rivers.recent.ul.children().length ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
rivers.recent.ajax();
|
2014-07-31 19:28:19 -04:00
|
|
|
}
|
2015-03-03 16:21:25 -05:00
|
|
|
|
|
|
|
correctedURL = inputs.url.val().replace( /^http:\/\//, '' );
|
2012-08-22 20:04:18 -04:00
|
|
|
},
|
|
|
|
|
2015-03-10 22:40:27 -04:00
|
|
|
hasSelectedText: function( linkNode ) {
|
|
|
|
var html = editor.selection.getContent();
|
|
|
|
|
|
|
|
// Partial html and not a fully selected anchor element
|
|
|
|
if ( /</.test( html ) && ( ! /^<a [^>]+>[^<]+<\/a>$/.test( html ) || html.indexOf('href=') === -1 ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( linkNode ) {
|
|
|
|
var nodes = linkNode.childNodes, i;
|
|
|
|
|
|
|
|
if ( nodes.length === 0 ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i = nodes.length - 1; i >= 0; i-- ) {
|
|
|
|
if ( nodes[i].nodeType != 3 ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
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() {
|
2015-03-10 22:40:27 -04:00
|
|
|
var text,
|
|
|
|
selectedNode = editor.selection.getNode(),
|
|
|
|
linkNode = editor.dom.getParent( selectedNode, 'a[href]' ),
|
|
|
|
onlyText = this.hasSelectedText( linkNode );
|
|
|
|
|
|
|
|
if ( linkNode ) {
|
|
|
|
text = linkNode.innerText || linkNode.textContent;
|
|
|
|
inputs.url.val( editor.dom.getAttrib( linkNode, 'href' ) );
|
|
|
|
inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode, 'target' ) );
|
2012-08-22 20:04:18 -04:00
|
|
|
inputs.submit.val( wpLinkL10n.update );
|
2015-03-10 22:40:27 -04:00
|
|
|
} else {
|
|
|
|
text = editor.selection.getContent({ format: 'text' });
|
|
|
|
this.setDefaultValues();
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-03-10 22:40:27 -04:00
|
|
|
if ( onlyText ) {
|
|
|
|
inputs.text.val( text || '' );
|
|
|
|
inputs.wrap.addClass( 'has-text-field' );
|
2012-08-22 20:04:18 -04:00
|
|
|
} else {
|
2015-03-10 22:40:27 -04:00
|
|
|
inputs.text.val( '' );
|
|
|
|
inputs.wrap.removeClass( 'has-text-field' );
|
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
|
|
|
close: function() {
|
2014-12-02 03:09:25 -05:00
|
|
|
$( document.body ).removeClass( 'modal-open' );
|
|
|
|
|
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();
|
2015-03-02 19:01:28 -05:00
|
|
|
|
|
|
|
correctedURL = false;
|
|
|
|
|
2014-07-31 22:04:17 -04:00
|
|
|
$( document ).trigger( 'wplink-close', inputs.wrap );
|
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 {
|
2015-03-03 16:21:25 -05:00
|
|
|
href: $.trim( inputs.url.val() ),
|
2014-03-10 20:04:14 -04:00
|
|
|
target: inputs.openInNewTab.prop( 'checked' ) ? '_blank' : ''
|
2012-08-22 20:04:18 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-06-16 16:20:26 -04:00
|
|
|
buildHtml: function(attrs) {
|
|
|
|
var html = '<a href="' + attrs.href + '"';
|
|
|
|
|
|
|
|
if ( attrs.target ) {
|
|
|
|
html += ' target="' + attrs.target + '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
return html + '>';
|
|
|
|
},
|
|
|
|
|
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() {
|
2015-03-10 22:40:27 -04:00
|
|
|
if ( wpLink.isMCE() ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
wpLink.mceUpdate();
|
2015-03-10 22:40:27 -04:00
|
|
|
} else {
|
2012-08-22 20:04:18 -04:00
|
|
|
wpLink.htmlUpdate();
|
2015-03-10 22:40:27 -04:00
|
|
|
}
|
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
|
|
|
htmlUpdate: function() {
|
2015-03-10 22:40:27 -04:00
|
|
|
var attrs, text, html, begin, end, cursor, selection,
|
2012-08-22 20:04:18 -04:00
|
|
|
textarea = wpLink.textarea;
|
|
|
|
|
2015-03-10 22:40:27 -04:00
|
|
|
if ( ! textarea ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
return;
|
2015-03-10 22:40:27 -04:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
attrs = wpLink.getAttrs();
|
2015-03-10 22:40:27 -04:00
|
|
|
text = inputs.text.val();
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
// If there's no href, return.
|
2015-03-10 22:40:27 -04:00
|
|
|
if ( ! attrs.href ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
return;
|
2015-03-10 22:40:27 -04:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-06-16 16:20:26 -04:00
|
|
|
html = wpLink.buildHtml(attrs);
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
// 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();
|
2015-03-10 22:40:27 -04:00
|
|
|
wpLink.range.text = html + ( text || wpLink.range.text ) + '</a>';
|
2012-08-22 20:04:18 -04:00
|
|
|
wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
|
|
|
|
wpLink.range.select();
|
|
|
|
|
|
|
|
wpLink.range = null;
|
|
|
|
} else if ( typeof textarea.selectionStart !== 'undefined' ) {
|
|
|
|
// W3C
|
2015-03-10 22:40:27 -04:00
|
|
|
begin = textarea.selectionStart;
|
|
|
|
end = textarea.selectionEnd;
|
|
|
|
selection = text || textarea.value.substring( begin, end );
|
|
|
|
html = html + selection + '</a>';
|
|
|
|
cursor = begin + html.length;
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2013-11-26 16:45:09 -05:00
|
|
|
// If no text is selected, place the cursor inside the closing tag.
|
2015-03-10 22:40:27 -04:00
|
|
|
if ( begin === end && ! selection ) {
|
|
|
|
cursor -= 4;
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-03-10 22:40:27 -04: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() {
|
2015-03-10 22:40:27 -04:00
|
|
|
var attrs = wpLink.getAttrs(),
|
|
|
|
link, text;
|
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
|
|
|
|
|
|
|
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
|
|
|
|
2015-03-10 22:40:27 -04:00
|
|
|
if ( ! attrs.href ) {
|
2014-03-10 20:04:14 -04:00
|
|
|
editor.execCommand( 'unlink' );
|
2012-08-22 20:04:18 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-10 22:40:27 -04:00
|
|
|
link = getLink();
|
2015-06-07 17:11:24 -04:00
|
|
|
text = inputs.text.val() || attrs.href;
|
2015-03-10 22:40:27 -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 ( link ) {
|
2015-03-10 22:40:27 -04:00
|
|
|
if ( text ) {
|
|
|
|
if ( 'innerText' in link ) {
|
|
|
|
link.innerText = text;
|
|
|
|
} else {
|
|
|
|
link.textContent = text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
editor.dom.setAttribs( link, attrs );
|
2012-08-22 20:04:18 -04:00
|
|
|
} else {
|
2015-03-10 22:40:27 -04:00
|
|
|
if ( text ) {
|
|
|
|
editor.selection.setNode( editor.dom.create( 'a', attrs, text ) );
|
|
|
|
} else {
|
|
|
|
editor.execCommand( 'mceInsertLink', false, attrs );
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-07-31 19:28:19 -04:00
|
|
|
updateFields: function( e, li ) {
|
2014-03-10 20:04:14 -04:00
|
|
|
inputs.url.val( li.children( '.item-permalink' ).val() );
|
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
|
|
|
|
|
|
|
setDefaultValues: function() {
|
2015-03-10 22:40:27 -04:00
|
|
|
var selection,
|
2014-06-13 17:26:15 -04:00
|
|
|
emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
|
2015-03-11 13:40:27 -04:00
|
|
|
urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i;
|
2015-03-10 22:40:27 -04:00
|
|
|
|
|
|
|
if ( this.isMCE() ) {
|
|
|
|
selection = editor.selection.getContent();
|
|
|
|
} else if ( document.selection && wpLink.range ) {
|
|
|
|
selection = wpLink.range.text;
|
|
|
|
} else if ( typeof this.textarea.selectionStart !== 'undefined' ) {
|
|
|
|
selection = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd );
|
|
|
|
}
|
2014-06-09 11:35:14 -04:00
|
|
|
|
2014-06-13 17:14:16 -04:00
|
|
|
if ( selection && emailRegexp.test( selection ) ) {
|
2014-06-09 11:35:14 -04:00
|
|
|
// Selection is email address
|
|
|
|
inputs.url.val( 'mailto:' + selection );
|
2014-06-13 17:14:16 -04:00
|
|
|
} else if ( selection && urlRegexp.test( selection ) ) {
|
2014-06-09 11:35:14 -04:00
|
|
|
// Selection is URL
|
2014-06-24 20:37:15 -04:00
|
|
|
inputs.url.val( selection.replace( /&|�?38;/gi, '&' ) );
|
2014-06-09 11:35:14 -04:00
|
|
|
} else {
|
|
|
|
// Set URL to default.
|
2015-03-02 19:01:28 -05:00
|
|
|
inputs.url.val( '' );
|
2014-06-09 11:35:14 -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;
|
2015-04-03 00:52:27 -04:00
|
|
|
waiting = t.parent().find( '.spinner' ).addClass( 'is-active' );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
rivers.search.change( search );
|
2014-03-10 20:04:14 -04:00
|
|
|
rivers.search.ajax( function() {
|
2015-04-03 00:52:27 -04:00
|
|
|
waiting.removeClass( 'is-active' );
|
2014-03-10 20:04:14 -04:00
|
|
|
});
|
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;
|
|
|
|
|
2014-07-28 23:16:17 -04:00
|
|
|
// wp-link-submit must always be the last focusable element in the dialog.
|
|
|
|
// following focusable elements will be skipped on keyboard navigation.
|
2014-03-10 20:04:14 -04:00
|
|
|
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-07-31 19:28:19 -04:00
|
|
|
if ( document.activeElement &&
|
|
|
|
( document.activeElement.id === 'link-title-field' || document.activeElement.id === 'url-field' ) ) {
|
2014-07-25 11:57:16 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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-07-28 23:16:17 -04:00
|
|
|
toggleInternalLinking: function( event ) {
|
2014-03-10 20:04:14 -04:00
|
|
|
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();
|
2014-07-28 23:16:17 -04:00
|
|
|
event.preventDefault();
|
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 ) {
|
2014-07-28 23:16:17 -04:00
|
|
|
list += '<li class="unselectable no-matches-found"><span class="item-title"><em>' +
|
2013-11-14 23:28:10 -05:00
|
|
|
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;
|
|
|
|
|
2015-04-03 00:52:27 -04:00
|
|
|
self.waiting.addClass( 'is-active' );
|
2012-08-22 20:04:18 -04:00
|
|
|
el.scrollTop( newTop + self.waiting.outerHeight() );
|
|
|
|
|
2014-03-10 20:04:14 -04:00
|
|
|
self.ajax( function() {
|
2015-04-03 00:52:27 -04:00
|
|
|
self.waiting.removeClass( 'is-active' );
|
2014-03-10 20:04:14 -04:00
|
|
|
});
|
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 );
|