wp/wp-includes/js/tinymce/plugins/wplink/plugin.js
changeset 21 48c4eec2b7e6
parent 16 a86126ab1dd4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    54 
    54 
    55 	tinymce.ui.Factory.add( 'WPLinkInput', tinymce.ui.Control.extend( {
    55 	tinymce.ui.Factory.add( 'WPLinkInput', tinymce.ui.Control.extend( {
    56 		renderHtml: function() {
    56 		renderHtml: function() {
    57 			return (
    57 			return (
    58 				'<div id="' + this._id + '" class="wp-link-input">' +
    58 				'<div id="' + this._id + '" class="wp-link-input">' +
    59 					'<input type="text" value="" placeholder="' + tinymce.translate( 'Paste URL or type to search' ) + '" />' +
    59 					'<label for="' + this._id + '_label">' + tinymce.translate( 'Paste URL or type to search' ) + '</label><input id="' + this._id + '_label" type="text" value="" />' +
    60 					'<input type="text" style="display:none" value="" />' +
    60 					'<input type="text" style="display:none" value="" />' +
    61 				'</div>'
    61 				'</div>'
    62 			);
    62 			);
    63 		},
    63 		},
    64 		setURL: function( url ) {
    64 		setURL: function( url ) {
    65 			this.getEl().firstChild.value = url;
    65 			this.getEl().firstChild.nextSibling.value = url;
    66 		},
    66 		},
    67 		getURL: function() {
    67 		getURL: function() {
    68 			return tinymce.trim( this.getEl().firstChild.value );
    68 			return tinymce.trim( this.getEl().firstChild.nextSibling.value );
    69 		},
    69 		},
    70 		getLinkText: function() {
    70 		getLinkText: function() {
    71 			var text = this.getEl().firstChild.nextSibling.value;
    71 			var text = this.getEl().firstChild.nextSibling.nextSibling.value;
    72 
    72 
    73 			if ( ! tinymce.trim( text ) ) {
    73 			if ( ! tinymce.trim( text ) ) {
    74 				return '';
    74 				return '';
    75 			}
    75 			}
    76 
    76 
    77 			return text.replace( /[\r\n\t ]+/g, ' ' );
    77 			return text.replace( /[\r\n\t ]+/g, ' ' );
    78 		},
    78 		},
    79 		reset: function() {
    79 		reset: function() {
    80 			var urlInput = this.getEl().firstChild;
    80 			var urlInput = this.getEl().firstChild.nextSibling;
    81 
    81 
    82 			urlInput.value = '';
    82 			urlInput.value = '';
    83 			urlInput.nextSibling.value = '';
    83 			urlInput.nextSibling.value = '';
    84 		}
    84 		}
    85 	} ) );
    85 	} ) );
    96 		var emailRegex = /^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}$/i;
    96 		var emailRegex = /^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}$/i;
    97 		var urlRegex1 = /^https?:\/\/([^\s/?.#-][^\s\/?.#]*\.?)+(\/[^\s"]*)?$/i;
    97 		var urlRegex1 = /^https?:\/\/([^\s/?.#-][^\s\/?.#]*\.?)+(\/[^\s"]*)?$/i;
    98 		var urlRegex2 = /^https?:\/\/[^\/]+\.[^\/]+($|\/)/i;
    98 		var urlRegex2 = /^https?:\/\/[^\/]+\.[^\/]+($|\/)/i;
    99 		var speak = ( typeof window.wp !== 'undefined' && window.wp.a11y && window.wp.a11y.speak ) ? window.wp.a11y.speak : function() {};
    99 		var speak = ( typeof window.wp !== 'undefined' && window.wp.a11y && window.wp.a11y.speak ) ? window.wp.a11y.speak : function() {};
   100 		var hasLinkError = false;
   100 		var hasLinkError = false;
       
   101 		var __ = window.wp.i18n.__;
       
   102 		var _n = window.wp.i18n._n;
       
   103 		var sprintf = window.wp.i18n.sprintf;
   101 
   104 
   102 		function getSelectedLink() {
   105 		function getSelectedLink() {
   103 			var href, html,
   106 			var href, html,
   104 				node = editor.selection.getStart(),
   107 				node = editor.selection.getStart(),
   105 				link = editor.dom.getParent( node, 'a[href]' );
   108 				link = editor.dom.getParent( node, 'a[href]' );
   389 
   392 
   390 		editor.addButton( 'wp_link_input', {
   393 		editor.addButton( 'wp_link_input', {
   391 			type: 'WPLinkInput',
   394 			type: 'WPLinkInput',
   392 			onPostRender: function() {
   395 			onPostRender: function() {
   393 				var element = this.getEl(),
   396 				var element = this.getEl(),
   394 					input = element.firstChild,
   397 					input = element.firstChild.nextSibling,
   395 					$input, cache, last;
   398 					$input, cache, last;
   396 
   399 
   397 				inputInstance = this;
   400 				inputInstance = this;
   398 
   401 
   399 				if ( $ && $.ui && $.ui.autocomplete ) {
   402 				if ( $ && $.ui && $.ui.autocomplete ) {
   433 							 */
   436 							 */
   434 							event.preventDefault();
   437 							event.preventDefault();
   435 						},
   438 						},
   436 						select: function( event, ui ) {
   439 						select: function( event, ui ) {
   437 							$input.val( ui.item.permalink );
   440 							$input.val( ui.item.permalink );
   438 							$( element.firstChild.nextSibling ).val( ui.item.title );
   441 							$( element.firstChild.nextSibling.nextSibling ).val( ui.item.title );
   439 
   442 
   440 							if ( 9 === event.keyCode && typeof window.wpLinkL10n !== 'undefined' ) {
   443 							if ( 9 === event.keyCode && typeof window.wpLinkL10n !== 'undefined' ) {
   441 								// Audible confirmation message when a link has been selected.
   444 								// Audible confirmation message when a link has been selected.
   442 								speak( window.wpLinkL10n.linkSelected );
   445 								speak( window.wpLinkL10n.linkSelected );
   443 							}
   446 							}
   455 						minLength: 2,
   458 						minLength: 2,
   456 						position: {
   459 						position: {
   457 							my: 'left top+2'
   460 							my: 'left top+2'
   458 						},
   461 						},
   459 						messages: {
   462 						messages: {
   460 							noResults: ( typeof window.uiAutocompleteL10n !== 'undefined' ) ? window.uiAutocompleteL10n.noResults : '',
   463 							noResults: __( 'No results found.' ) ,
   461 							results: function( number ) {
   464 							results: function( number ) {
   462 								if ( typeof window.uiAutocompleteL10n !== 'undefined' ) {
   465 								return sprintf(
   463 									if ( number > 1 ) {
   466 									/* translators: %d: Number of search results found. */
   464 										return window.uiAutocompleteL10n.manyResults.replace( '%d', number );
   467 									_n(
   465 									}
   468 										'%d result found. Use up and down arrow keys to navigate.',
   466 
   469 										'%d results found. Use up and down arrow keys to navigate.',
   467 									return window.uiAutocompleteL10n.oneResult;
   470 										number
   468 								}
   471 									),
       
   472 									number
       
   473 								);
   469 							}
   474 							}
   470 						}
   475 						}
   471 					} ).autocomplete( 'instance' )._renderItem = function( ul, item ) {
   476 					} ).autocomplete( 'instance' )._renderItem = function( ul, item ) {
   472 						var fallbackTitle = ( typeof window.wpLinkL10n !== 'undefined' ) ? window.wpLinkL10n.noTitle : '',
   477 						var fallbackTitle = ( typeof window.wpLinkL10n !== 'undefined' ) ? window.wpLinkL10n.noTitle : '',
   473 							title = item.title ? item.title : fallbackTitle;
   478 							title = item.title ? item.title : fallbackTitle;