inputs.queryNoticeTextHint.addClass( 'screen-reader-text' ).hide();
} );
- inputs.search.keyup( function() {
+ inputs.search.on( 'keyup input', function() {
var self = this;
window.clearTimeout( searchTimer );
}, 500 );
});
- 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 );
+ setTimeout( wpLink.correctURL, 0 );
} );
- inputs.url.on( 'blur', correctURL );
+ inputs.url.on( 'blur', wpLink.correctURL );
+ },
+
+ // 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;
+ }
},
open: function( editorId ) {
- var ed;
+ var ed,
+ $body = $( document.body );
- $( document.body ).addClass( 'modal-open' );
+ $body.addClass( 'modal-open' );
wpLink.range = null;
this.textarea = $( '#' + window.wpActiveEditor ).get( 0 );
if ( typeof tinymce !== 'undefined' ) {
+ // 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 );
+
ed = tinymce.get( wpActiveEditor );
if ( ed && ! ed.isHidden() ) {
},
getAttrs: function() {
+ wpLink.correctURL();
+
return {
href: $.trim( inputs.url.val() ),
target: inputs.openInNewTab.prop( 'checked' ) ? '_blank' : ''
};
},
+ buildHtml: function(attrs) {
+ var html = '<a href="' + attrs.href + '"';
+
+ if ( attrs.target ) {
+ html += ' target="' + attrs.target + '"';
+ }
+
+ return html + '>';
+ },
+
update: function() {
if ( wpLink.isMCE() ) {
wpLink.mceUpdate();
return;
}
- // Build HTML
- html = '<a href="' + attrs.href + '"';
-
- if ( attrs.target ) {
- html += ' target="' + attrs.target + '"';
- }
-
- html += '>';
+ html = wpLink.buildHtml(attrs);
// Insert HTML
if ( document.selection && wpLink.range ) {
}
link = getLink();
- text = inputs.text.val();
+
+ if ( inputs.wrap.hasClass( 'has-text-field' ) ) {
+ text = inputs.text.val() || attrs.href;
+ }
if ( link ) {
if ( text ) {
editor.execCommand( 'mceInsertLink', false, attrs );
}
}
+
+ editor.nodeChanged();
},
updateFields: function( e, li ) {