2016-02-29 20:38:27 +01:00
|
|
|
|
2012-08-23 02:04:18 +02:00
|
|
|
var wpLink;
|
|
|
|
|
2016-02-29 20:38:27 +01:00
|
|
|
( function( $, wpLinkL10n ) {
|
2016-02-27 22:33:26 +01:00
|
|
|
var editor, correctedURL, linkNode,
|
2014-08-01 01:28:19 +02:00
|
|
|
inputs = {},
|
|
|
|
isTouch = ( 'ontouchend' in document );
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2015-03-11 03:40:27 +01:00
|
|
|
function getLink() {
|
2016-02-27 22:33:26 +01:00
|
|
|
return linkNode || editor.dom.getParent( editor.selection.getNode(), 'a[href]' );
|
2015-03-11 03:40:27 +01:00
|
|
|
}
|
|
|
|
|
2012-08-23 02:04:18 +02:00
|
|
|
wpLink = {
|
|
|
|
textarea: '',
|
|
|
|
|
2014-03-11 01:04:14 +01: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-11 03:40:27 +01:00
|
|
|
|
|
|
|
// Input
|
|
|
|
inputs.text = $( '#wp-link-text' );
|
|
|
|
inputs.url = $( '#wp-link-url' );
|
|
|
|
inputs.openInNewTab = $( '#wp-link-target' );
|
|
|
|
|
2016-02-24 07:20:26 +01:00
|
|
|
if ( $.ui && $.ui.autocomplete ) {
|
|
|
|
wpLink.setAutocomplete();
|
|
|
|
}
|
2014-07-29 05:16:17 +02:00
|
|
|
|
2016-02-27 01:52:26 +01:00
|
|
|
inputs.dialog.on( 'keydown', wpLink.keydown );
|
|
|
|
inputs.submit.on( 'click', function( event ) {
|
2014-03-11 01:04:14 +01:00
|
|
|
event.preventDefault();
|
2012-08-23 02:04:18 +02:00
|
|
|
wpLink.update();
|
|
|
|
});
|
2016-02-24 07:20:26 +01:00
|
|
|
|
2014-03-12 04:07:15 +01:00
|
|
|
inputs.close.add( inputs.backdrop ).add( '#wp-link-cancel a' ).click( function( event ) {
|
2014-03-11 01:04:14 +01:00
|
|
|
event.preventDefault();
|
2012-08-23 02:04:18 +02:00
|
|
|
wpLink.close();
|
|
|
|
});
|
|
|
|
|
2016-02-24 07:20:26 +01:00
|
|
|
inputs.url.on( 'paste', function() {
|
|
|
|
setTimeout( wpLink.correctURL, 0 );
|
|
|
|
} );
|
|
|
|
},
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2016-02-24 07:20:26 +01:00
|
|
|
setAutocomplete: function() {
|
|
|
|
var $input = inputs.url,
|
|
|
|
cache, last;
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2016-02-24 07:20:26 +01:00
|
|
|
$input.on( 'keydown', function() {
|
|
|
|
$input.removeAttr( 'aria-activedescendant' );
|
|
|
|
} ).autocomplete( {
|
|
|
|
source: function( request, response ) {
|
|
|
|
if ( last === request.term ) {
|
|
|
|
response( cache );
|
|
|
|
return;
|
|
|
|
}
|
2014-07-29 05:16:17 +02:00
|
|
|
|
2016-02-24 07:20:26 +01:00
|
|
|
if ( /^https?:/.test( request.term ) || request.term.indexOf( '.' ) !== -1 ) {
|
|
|
|
return response();
|
|
|
|
}
|
2014-04-02 04:27:16 +02:00
|
|
|
|
2016-02-24 07:20:26 +01:00
|
|
|
$.post( window.ajaxurl, {
|
|
|
|
action: 'wp-link-ajax',
|
|
|
|
page: 1,
|
|
|
|
search: request.term,
|
|
|
|
_ajax_linking_nonce: $( '#_ajax_linking_nonce' ).val()
|
|
|
|
}, function( data ) {
|
|
|
|
cache = data;
|
|
|
|
response( data );
|
|
|
|
}, 'json' );
|
|
|
|
|
|
|
|
last = request.term;
|
|
|
|
},
|
|
|
|
focus: function( event, ui ) {
|
|
|
|
$input.attr( 'aria-activedescendant', 'mce-wp-autocomplete-' + ui.item.ID );
|
|
|
|
},
|
|
|
|
select: function( event, ui ) {
|
|
|
|
$input.val( ui.item.permalink );
|
|
|
|
|
2016-02-29 20:38:27 +01:00
|
|
|
if ( inputs.wrap.hasClass( 'has-text-field' ) && $.trim( inputs.text.val() ) === '' ) {
|
2016-02-24 07:20:26 +01:00
|
|
|
inputs.text.val( ui.item.title );
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
open: function() {
|
|
|
|
$input.attr( 'aria-expanded', 'true' );
|
|
|
|
},
|
|
|
|
close: function() {
|
|
|
|
$input.attr( 'aria-expanded', 'false' );
|
|
|
|
},
|
|
|
|
minLength: 2,
|
|
|
|
position: {
|
|
|
|
my: 'left top+2'
|
2016-03-02 21:06:26 +01:00
|
|
|
},
|
|
|
|
messages: {
|
|
|
|
noResults: ( typeof window.uiAutocompleteL10n !== 'undefined' ) ? window.uiAutocompleteL10n.noResults : '',
|
|
|
|
results: function( number ) {
|
|
|
|
if ( typeof window.uiAutocompleteL10n !== 'undefined' ) {
|
|
|
|
if ( number > 1 ) {
|
|
|
|
return window.uiAutocompleteL10n.manyResults.replace( '%d', number );
|
|
|
|
}
|
|
|
|
|
|
|
|
return window.uiAutocompleteL10n.oneResult;
|
|
|
|
}
|
|
|
|
}
|
2016-02-24 07:20:26 +01:00
|
|
|
}
|
|
|
|
} ).autocomplete( 'instance' )._renderItem = function( ul, item ) {
|
|
|
|
return $( '<li role="option" id="mce-wp-autocomplete-' + item.ID + '">' )
|
|
|
|
.append( '<span class="item-title">' + item.title + '</span> <span class="item-date alignright">' + item.info + '</span>' )
|
|
|
|
.appendTo( ul );
|
|
|
|
};
|
|
|
|
|
|
|
|
$input.attr( {
|
|
|
|
'aria-owns': $input.autocomplete( 'widget' ).attr( 'id' )
|
|
|
|
} )
|
|
|
|
.on( 'focus', function() {
|
|
|
|
$input.autocomplete( 'search' );
|
|
|
|
} )
|
|
|
|
.autocomplete( 'widget' )
|
|
|
|
.addClass( 'wplink-autocomplete' )
|
|
|
|
.attr( 'role', 'listbox' );
|
2015-03-03 01:01:28 +01:00
|
|
|
|
2015-03-03 22:21:25 +01:00
|
|
|
|
2015-06-29 01:07:25 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// If URL wasn't corrected last time and doesn't start with http:, https:, ? # or /, prepend http://
|
|
|
|
correctURL: function () {
|
|
|
|
var url = $.trim( inputs.url.val() );
|
|
|
|
|
|
|
|
if ( url && correctedURL !== url && ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( url ) ) {
|
|
|
|
inputs.url.val( 'http://' + url );
|
|
|
|
correctedURL = url;
|
|
|
|
}
|
2012-08-23 02:04:18 +02:00
|
|
|
},
|
|
|
|
|
2016-02-27 22:33:26 +01:00
|
|
|
open: function( editorId, url, text, node ) {
|
2015-06-26 22:29:24 +02:00
|
|
|
var ed,
|
|
|
|
$body = $( document.body );
|
2014-06-09 17:35:14 +02:00
|
|
|
|
2015-06-26 22:29:24 +02:00
|
|
|
$body.addClass( 'modal-open' );
|
2016-02-27 22:33:26 +01:00
|
|
|
linkNode = node;
|
2014-12-02 09:09:25 +01:00
|
|
|
|
2012-08-23 02:04:18 +02: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-29 00:53:15 +01:00
|
|
|
if ( editorId ) {
|
|
|
|
window.wpActiveEditor = editorId;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! window.wpActiveEditor ) {
|
2012-08-23 02:04:18 +02: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-29 00:53:15 +01:00
|
|
|
}
|
|
|
|
|
2014-03-11 01:04:14 +01:00
|
|
|
this.textarea = $( '#' + window.wpActiveEditor ).get( 0 );
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2016-02-29 20:38:27 +01:00
|
|
|
if ( typeof window.tinymce !== 'undefined' ) {
|
2015-08-06 04:17:25 +02:00
|
|
|
// Make sure the link wrapper is the last element in the body,
|
|
|
|
// or the inline editor toolbar may show above the backdrop.
|
|
|
|
$body.append( inputs.backdrop, inputs.wrap );
|
2015-06-26 22:29:24 +02:00
|
|
|
|
2016-02-29 20:38:27 +01:00
|
|
|
ed = window.tinymce.get( window.wpActiveEditor );
|
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-29 00:53:15 +01:00
|
|
|
|
2014-03-11 01:04:14 +01:00
|
|
|
if ( ed && ! ed.isHidden() ) {
|
|
|
|
editor = ed;
|
|
|
|
} else {
|
|
|
|
editor = null;
|
|
|
|
}
|
|
|
|
|
2016-02-29 20:38:27 +01:00
|
|
|
if ( editor && window.tinymce.isIE && ! editor.windowManager.wplinkBookmark ) {
|
2016-02-24 07:20:26 +01:00
|
|
|
editor.windowManager.wplinkBookmark = 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-29 00:53:15 +01:00
|
|
|
}
|
|
|
|
}
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2014-03-11 01:04:14 +01:00
|
|
|
if ( ! wpLink.isMCE() && document.selection ) {
|
|
|
|
this.textarea.focus();
|
|
|
|
this.range = document.selection.createRange();
|
2012-08-23 02:04:18 +02:00
|
|
|
}
|
|
|
|
|
2014-03-11 01:04:14 +01:00
|
|
|
inputs.wrap.show();
|
|
|
|
inputs.backdrop.show();
|
|
|
|
|
2016-02-24 07:20:26 +01:00
|
|
|
wpLink.refresh( url, text );
|
2015-03-11 03:40:27 +01:00
|
|
|
|
2014-08-01 04:04:17 +02:00
|
|
|
$( document ).trigger( 'wplink-open', inputs.wrap );
|
2012-08-23 02:04:18 +02:00
|
|
|
},
|
|
|
|
|
2014-03-11 01:04:14 +01:00
|
|
|
isMCE: function() {
|
|
|
|
return editor && ! editor.isHidden();
|
2012-08-23 02:04:18 +02:00
|
|
|
},
|
|
|
|
|
2016-02-24 07:20:26 +01:00
|
|
|
refresh: function( url, text ) {
|
|
|
|
var linkText = '';
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2014-08-01 01:28:19 +02:00
|
|
|
if ( wpLink.isMCE() ) {
|
2016-02-24 07:20:26 +01:00
|
|
|
wpLink.mceRefresh( url, text );
|
2014-08-01 01:28:19 +02:00
|
|
|
} else {
|
2015-04-21 15:59:30 +02: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
|
2016-02-24 07:20:26 +01:00
|
|
|
linkText = document.selection.createRange().text || text || '';
|
2015-04-21 15:59:30 +02:00
|
|
|
} else if ( typeof this.textarea.selectionStart !== 'undefined' &&
|
|
|
|
( this.textarea.selectionStart !== this.textarea.selectionEnd ) ) {
|
|
|
|
// W3C
|
2016-02-24 07:20:26 +01:00
|
|
|
text = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd ) || text || '';
|
2015-04-21 15:59:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inputs.text.val( text );
|
2012-08-23 02:04:18 +02:00
|
|
|
wpLink.setDefaultValues();
|
2014-08-01 01:28:19 +02: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.
|
2016-02-25 04:48:26 +01:00
|
|
|
window.setTimeout( function() {
|
|
|
|
inputs.url.focus()[0].select();
|
2016-02-27 01:52:26 +01:00
|
|
|
} );
|
2014-08-01 01:28:19 +02:00
|
|
|
}
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2015-03-03 22:21:25 +01:00
|
|
|
correctedURL = inputs.url.val().replace( /^http:\/\//, '' );
|
2012-08-23 02:04:18 +02:00
|
|
|
},
|
|
|
|
|
2015-03-11 03:40:27 +01:00
|
|
|
hasSelectedText: function( linkNode ) {
|
2016-02-24 07:20:26 +01:00
|
|
|
var node, nodes, i, html = editor.selection.getContent();
|
2015-03-11 03:40:27 +01:00
|
|
|
|
|
|
|
// Partial html and not a fully selected anchor element
|
|
|
|
if ( /</.test( html ) && ( ! /^<a [^>]+>[^<]+<\/a>$/.test( html ) || html.indexOf('href=') === -1 ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( linkNode ) {
|
2016-02-24 07:20:26 +01:00
|
|
|
nodes = linkNode.childNodes;
|
2015-03-11 03:40:27 +01:00
|
|
|
|
|
|
|
if ( nodes.length === 0 ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i = nodes.length - 1; i >= 0; i-- ) {
|
2016-02-24 07:20:26 +01:00
|
|
|
node = nodes[i];
|
|
|
|
|
2016-02-29 20:38:27 +01:00
|
|
|
if ( node.nodeType != 3 && ! window.tinymce.dom.BookmarkManager.isBookmarkNode( node ) ) {
|
2015-03-11 03:40:27 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2016-02-24 07:20:26 +01:00
|
|
|
mceRefresh: function( url, text ) {
|
2016-02-26 01:21:26 +01:00
|
|
|
var linkText,
|
|
|
|
linkNode = getLink(),
|
2015-03-11 03:40:27 +01:00
|
|
|
onlyText = this.hasSelectedText( linkNode );
|
|
|
|
|
|
|
|
if ( linkNode ) {
|
2016-02-26 01:21:26 +01:00
|
|
|
linkText = linkNode.innerText || linkNode.textContent;
|
|
|
|
|
2016-02-29 20:38:27 +01:00
|
|
|
if ( ! $.trim( linkText ) ) {
|
2016-02-26 01:21:26 +01:00
|
|
|
linkText = text || '';
|
|
|
|
}
|
|
|
|
|
2016-02-24 07:20:26 +01:00
|
|
|
url = url || editor.dom.getAttrib( linkNode, 'href' );
|
2016-02-20 22:36:25 +01:00
|
|
|
|
2016-02-27 22:33:26 +01:00
|
|
|
if ( url !== '_wp_link_placeholder' ) {
|
|
|
|
inputs.url.val( url );
|
|
|
|
inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode, 'target' ) );
|
|
|
|
inputs.submit.val( wpLinkL10n.update );
|
|
|
|
} else {
|
|
|
|
this.setDefaultValues( linkText );
|
2016-02-20 22:36:25 +01:00
|
|
|
}
|
2015-03-11 03:40:27 +01:00
|
|
|
} else {
|
2016-02-27 22:33:26 +01:00
|
|
|
linkText = editor.selection.getContent({ format: 'text' }) || text || '';
|
|
|
|
this.setDefaultValues( linkText );
|
2015-03-11 03:40:27 +01:00
|
|
|
}
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2015-03-11 03:40:27 +01:00
|
|
|
if ( onlyText ) {
|
2016-02-27 22:33:26 +01:00
|
|
|
inputs.text.val( linkText );
|
2015-03-11 03:40:27 +01:00
|
|
|
inputs.wrap.addClass( 'has-text-field' );
|
2012-08-23 02:04:18 +02:00
|
|
|
} else {
|
2015-03-11 03:40:27 +01:00
|
|
|
inputs.text.val( '' );
|
|
|
|
inputs.wrap.removeClass( 'has-text-field' );
|
2012-08-23 02:04:18 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-02-27 22:33:26 +01:00
|
|
|
close: function( reset ) {
|
2014-12-02 09:09:25 +01:00
|
|
|
$( document.body ).removeClass( 'modal-open' );
|
|
|
|
|
2016-02-27 22:33:26 +01:00
|
|
|
if ( reset !== 'noReset' ) {
|
|
|
|
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-29 00:53:15 +01:00
|
|
|
|
2016-02-27 22:33:26 +01:00
|
|
|
if ( wpLink.range ) {
|
|
|
|
wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
|
|
|
|
wpLink.range.select();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( editor.plugins.wplink ) {
|
|
|
|
editor.plugins.wplink.close();
|
|
|
|
}
|
2016-02-26 01:21:26 +01:00
|
|
|
|
2016-02-27 22:33:26 +01:00
|
|
|
editor.focus();
|
|
|
|
}
|
2012-08-23 02:04:18 +02:00
|
|
|
}
|
2014-03-11 01:04:14 +01:00
|
|
|
|
|
|
|
inputs.backdrop.hide();
|
|
|
|
inputs.wrap.hide();
|
2015-03-03 01:01:28 +01:00
|
|
|
|
|
|
|
correctedURL = false;
|
|
|
|
|
2014-08-01 04:04:17 +02:00
|
|
|
$( document ).trigger( 'wplink-close', inputs.wrap );
|
2012-08-23 02:04:18 +02: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-29 00:53:15 +01:00
|
|
|
getAttrs: function() {
|
2015-06-29 01:07:25 +02:00
|
|
|
wpLink.correctURL();
|
|
|
|
|
2012-08-23 02:04:18 +02:00
|
|
|
return {
|
2015-03-03 22:21:25 +01:00
|
|
|
href: $.trim( inputs.url.val() ),
|
2014-03-11 01:04:14 +01:00
|
|
|
target: inputs.openInNewTab.prop( 'checked' ) ? '_blank' : ''
|
2012-08-23 02:04:18 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-06-16 22:20:26 +02: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-29 00:53:15 +01:00
|
|
|
update: function() {
|
2015-03-11 03:40:27 +01:00
|
|
|
if ( wpLink.isMCE() ) {
|
2012-08-23 02:04:18 +02:00
|
|
|
wpLink.mceUpdate();
|
2015-03-11 03:40:27 +01:00
|
|
|
} else {
|
2012-08-23 02:04:18 +02:00
|
|
|
wpLink.htmlUpdate();
|
2015-03-11 03:40:27 +01:00
|
|
|
}
|
2012-08-23 02:04:18 +02: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-29 00:53:15 +01:00
|
|
|
htmlUpdate: function() {
|
2015-03-11 03:40:27 +01:00
|
|
|
var attrs, text, html, begin, end, cursor, selection,
|
2012-08-23 02:04:18 +02:00
|
|
|
textarea = wpLink.textarea;
|
|
|
|
|
2015-03-11 03:40:27 +01:00
|
|
|
if ( ! textarea ) {
|
2012-08-23 02:04:18 +02:00
|
|
|
return;
|
2015-03-11 03:40:27 +01:00
|
|
|
}
|
2012-08-23 02:04:18 +02:00
|
|
|
|
|
|
|
attrs = wpLink.getAttrs();
|
2015-03-11 03:40:27 +01:00
|
|
|
text = inputs.text.val();
|
2012-08-23 02:04:18 +02:00
|
|
|
|
|
|
|
// If there's no href, return.
|
2015-03-11 03:40:27 +01:00
|
|
|
if ( ! attrs.href ) {
|
2012-08-23 02:04:18 +02:00
|
|
|
return;
|
2015-03-11 03:40:27 +01:00
|
|
|
}
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2015-06-16 22:20:26 +02:00
|
|
|
html = wpLink.buildHtml(attrs);
|
2012-08-23 02:04:18 +02: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-11 03:40:27 +01:00
|
|
|
wpLink.range.text = html + ( text || wpLink.range.text ) + '</a>';
|
2012-08-23 02:04:18 +02:00
|
|
|
wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
|
|
|
|
wpLink.range.select();
|
|
|
|
|
|
|
|
wpLink.range = null;
|
|
|
|
} else if ( typeof textarea.selectionStart !== 'undefined' ) {
|
|
|
|
// W3C
|
2015-03-11 03:40:27 +01:00
|
|
|
begin = textarea.selectionStart;
|
|
|
|
end = textarea.selectionEnd;
|
|
|
|
selection = text || textarea.value.substring( begin, end );
|
|
|
|
html = html + selection + '</a>';
|
|
|
|
cursor = begin + html.length;
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2013-11-26 22:45:09 +01:00
|
|
|
// If no text is selected, place the cursor inside the closing tag.
|
2015-03-11 03:40:27 +01:00
|
|
|
if ( begin === end && ! selection ) {
|
|
|
|
cursor -= 4;
|
|
|
|
}
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2015-03-11 03:40:27 +01:00
|
|
|
textarea.value = (
|
|
|
|
textarea.value.substring( 0, begin ) +
|
|
|
|
html +
|
|
|
|
textarea.value.substring( end, textarea.value.length )
|
|
|
|
);
|
2012-08-23 02:04:18 +02: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-29 00:53:15 +01:00
|
|
|
mceUpdate: function() {
|
2015-03-11 03:40:27 +01: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-29 00:53:15 +01:00
|
|
|
|
2014-03-11 01:04:14 +01: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-29 00:53:15 +01:00
|
|
|
|
2016-02-29 20:38:27 +01:00
|
|
|
if ( window.tinymce.isIE && editor.windowManager.wplinkBookmark ) {
|
2016-02-24 07:20:26 +01:00
|
|
|
editor.selection.moveToBookmark( editor.windowManager.wplinkBookmark );
|
|
|
|
editor.windowManager.wplinkBookmark = 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-29 00:53:15 +01:00
|
|
|
}
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2015-03-11 03:40:27 +01:00
|
|
|
if ( ! attrs.href ) {
|
2014-03-11 01:04:14 +01:00
|
|
|
editor.execCommand( 'unlink' );
|
2016-02-27 22:33:26 +01:00
|
|
|
wpLink.close();
|
2012-08-23 02:04:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-11 03:40:27 +01:00
|
|
|
link = getLink();
|
2015-08-06 22:58:25 +02:00
|
|
|
|
|
|
|
if ( inputs.wrap.hasClass( 'has-text-field' ) ) {
|
|
|
|
text = inputs.text.val() || attrs.href;
|
|
|
|
}
|
2015-03-11 03:40:27 +01: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-29 00:53:15 +01:00
|
|
|
if ( link ) {
|
2015-03-11 03:40:27 +01:00
|
|
|
if ( text ) {
|
|
|
|
if ( 'innerText' in link ) {
|
|
|
|
link.innerText = text;
|
|
|
|
} else {
|
|
|
|
link.textContent = text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-11 01:04:14 +01:00
|
|
|
editor.dom.setAttribs( link, attrs );
|
2012-08-23 02:04:18 +02:00
|
|
|
} else {
|
2015-03-11 03:40:27 +01:00
|
|
|
if ( text ) {
|
2015-10-21 22:38:26 +02:00
|
|
|
editor.selection.setNode( editor.dom.create( 'a', attrs, editor.dom.encode( text ) ) );
|
2015-03-11 03:40:27 +01:00
|
|
|
} else {
|
|
|
|
editor.execCommand( 'mceInsertLink', false, attrs );
|
|
|
|
}
|
2012-08-23 02:04:18 +02:00
|
|
|
}
|
2015-06-25 01:23:26 +02:00
|
|
|
|
2016-02-27 22:33:26 +01:00
|
|
|
wpLink.close( 'noReset' );
|
|
|
|
editor.focus();
|
2015-06-25 01:23:26 +02:00
|
|
|
editor.nodeChanged();
|
2012-08-23 02:04:18 +02:00
|
|
|
},
|
|
|
|
|
2016-02-27 01:52:26 +01:00
|
|
|
keydown: function( event ) {
|
|
|
|
var id;
|
|
|
|
|
|
|
|
// Escape key.
|
|
|
|
if ( 27 === event.keyCode ) {
|
|
|
|
wpLink.close();
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
// Tab key.
|
|
|
|
} else if ( 9 === event.keyCode ) {
|
|
|
|
id = event.target.id;
|
|
|
|
|
|
|
|
// wp-link-submit must always be the last focusable element in the dialog.
|
|
|
|
// following focusable elements will be skipped on keyboard navigation.
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-02-27 22:33:26 +01:00
|
|
|
getUrlFromSelection: function( selection ) {
|
2016-02-28 03:19:25 +01:00
|
|
|
var emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
|
2015-03-11 18:40:27 +01:00
|
|
|
urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i;
|
2015-03-11 03:40:27 +01:00
|
|
|
|
2016-02-27 22:33:26 +01:00
|
|
|
if ( ! selection ) {
|
|
|
|
if ( this.isMCE() ) {
|
|
|
|
selection = editor.selection.getContent({ format: 'text' });
|
|
|
|
} 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 );
|
|
|
|
}
|
2015-03-11 03:40:27 +01:00
|
|
|
}
|
2014-06-09 17:35:14 +02:00
|
|
|
|
2016-02-29 20:38:27 +01:00
|
|
|
selection = $.trim( selection );
|
2016-02-27 22:33:26 +01:00
|
|
|
|
2014-06-13 23:14:16 +02:00
|
|
|
if ( selection && emailRegexp.test( selection ) ) {
|
2014-06-09 17:35:14 +02:00
|
|
|
// Selection is email address
|
2016-02-27 22:33:26 +01:00
|
|
|
return 'mailto:' + selection;
|
2014-06-13 23:14:16 +02:00
|
|
|
} else if ( selection && urlRegexp.test( selection ) ) {
|
2014-06-09 17:35:14 +02:00
|
|
|
// Selection is URL
|
2016-02-27 22:33:26 +01:00
|
|
|
return selection.replace( /&|�?38;/gi, '&' );
|
2014-06-09 17:35:14 +02:00
|
|
|
}
|
|
|
|
|
2016-02-27 22:33:26 +01:00
|
|
|
return '';
|
|
|
|
},
|
|
|
|
|
|
|
|
setDefaultValues: function( selection ) {
|
|
|
|
inputs.url.val( this.getUrlFromSelection( selection ) );
|
|
|
|
|
2012-08-23 02:04:18 +02:00
|
|
|
// Update save prompt.
|
|
|
|
inputs.submit.val( wpLinkL10n.save );
|
|
|
|
}
|
2013-11-07 11:42:09 +01:00
|
|
|
};
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2014-03-11 01:04:14 +01:00
|
|
|
$( document ).ready( wpLink.init );
|
2016-02-29 20:38:27 +01:00
|
|
|
})( jQuery, window.wpLinkL10n );
|