equal
deleted
inserted
replaced
52 inputs.queryNotice = $( '#query-notice-message' ); |
52 inputs.queryNotice = $( '#query-notice-message' ); |
53 inputs.queryNoticeTextDefault = inputs.queryNotice.find( '.query-notice-default' ); |
53 inputs.queryNoticeTextDefault = inputs.queryNotice.find( '.query-notice-default' ); |
54 inputs.queryNoticeTextHint = inputs.queryNotice.find( '.query-notice-hint' ); |
54 inputs.queryNoticeTextHint = inputs.queryNotice.find( '.query-notice-hint' ); |
55 |
55 |
56 // Bind event handlers. |
56 // Bind event handlers. |
57 inputs.dialog.keydown( wpLink.keydown ); |
57 inputs.dialog.on( 'keydown', wpLink.keydown ); |
58 inputs.dialog.keyup( wpLink.keyup ); |
58 inputs.dialog.on( 'keyup', wpLink.keyup ); |
59 inputs.submit.click( function( event ) { |
59 inputs.submit.on( 'click', function( event ) { |
60 event.preventDefault(); |
60 event.preventDefault(); |
61 wpLink.update(); |
61 wpLink.update(); |
62 }); |
62 }); |
63 |
63 |
64 inputs.close.add( inputs.backdrop ).add( '#wp-link-cancel button' ).click( function( event ) { |
64 inputs.close.add( inputs.backdrop ).add( '#wp-link-cancel button' ).on( 'click', function( event ) { |
65 event.preventDefault(); |
65 event.preventDefault(); |
66 wpLink.close(); |
66 wpLink.close(); |
67 }); |
67 }); |
68 |
68 |
69 rivers.elements.on( 'river-select', wpLink.updateFields ); |
69 rivers.elements.on( 'river-select', wpLink.updateFields ); |
91 inputs.url.on( 'blur', wpLink.correctURL ); |
91 inputs.url.on( 'blur', wpLink.correctURL ); |
92 }, |
92 }, |
93 |
93 |
94 // If URL wasn't corrected last time and doesn't start with http:, https:, ? # or /, prepend http://. |
94 // If URL wasn't corrected last time and doesn't start with http:, https:, ? # or /, prepend http://. |
95 correctURL: function () { |
95 correctURL: function () { |
96 var url = $.trim( inputs.url.val() ); |
96 var url = inputs.url.val().trim(); |
97 |
97 |
98 if ( url && correctedURL !== url && ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( url ) ) { |
98 if ( url && correctedURL !== url && ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( url ) ) { |
99 inputs.url.val( 'http://' + url ); |
99 inputs.url.val( 'http://' + url ); |
100 correctedURL = url; |
100 correctedURL = url; |
101 } |
101 } |
179 wpLink.setDefaultValues(); |
179 wpLink.setDefaultValues(); |
180 } |
180 } |
181 |
181 |
182 if ( isTouch ) { |
182 if ( isTouch ) { |
183 // Close the onscreen keyboard. |
183 // Close the onscreen keyboard. |
184 inputs.url.focus().blur(); |
184 inputs.url.trigger( 'focus' ).trigger( 'blur' ); |
185 } else { |
185 } else { |
186 /* |
186 /* |
187 * Focus the URL field and highlight its contents. |
187 * Focus the URL field and highlight its contents. |
188 * If this is moved above the selection changes, |
188 * If this is moved above the selection changes, |
189 * IE will show a flashing cursor over the dialog. |
189 * IE will show a flashing cursor over the dialog. |
190 */ |
190 */ |
191 window.setTimeout( function() { |
191 window.setTimeout( function() { |
192 inputs.url[0].select(); |
192 inputs.url[0].select(); |
193 inputs.url.focus(); |
193 inputs.url.trigger( 'focus' ); |
194 } ); |
194 } ); |
195 } |
195 } |
196 |
196 |
197 // Load the most recent results if this is the first time opening the panel. |
197 // Load the most recent results if this is the first time opening the panel. |
198 if ( ! rivers.recent.ul.children().length ) { |
198 if ( ! rivers.recent.ul.children().length ) { |
236 |
236 |
237 if ( linkNode.length ) { |
237 if ( linkNode.length ) { |
238 linkText = linkNode.text(); |
238 linkText = linkNode.text(); |
239 href = linkNode.attr( 'href' ); |
239 href = linkNode.attr( 'href' ); |
240 |
240 |
241 if ( ! $.trim( linkText ) ) { |
241 if ( ! linkText.trim() ) { |
242 linkText = text || ''; |
242 linkText = text || ''; |
243 } |
243 } |
244 |
244 |
245 if ( searchStr && ( urlRegexp.test( searchStr ) || emailRegexp.test( searchStr ) ) ) { |
245 if ( searchStr && ( urlRegexp.test( searchStr ) || emailRegexp.test( searchStr ) ) ) { |
246 href = searchStr; |
246 href = searchStr; |
310 |
310 |
311 getAttrs: function() { |
311 getAttrs: function() { |
312 wpLink.correctURL(); |
312 wpLink.correctURL(); |
313 |
313 |
314 return { |
314 return { |
315 href: $.trim( inputs.url.val() ), |
315 href: inputs.url.val().trim(), |
316 target: inputs.openInNewTab.prop( 'checked' ) ? '_blank' : null |
316 target: inputs.openInNewTab.prop( 'checked' ) ? '_blank' : null |
317 }; |
317 }; |
318 }, |
318 }, |
319 |
319 |
320 buildHtml: function(attrs) { |
320 buildHtml: function(attrs) { |
423 |
423 |
424 editor.undoManager.transact( function() { |
424 editor.undoManager.transact( function() { |
425 if ( ! $link.length ) { |
425 if ( ! $link.length ) { |
426 editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder', 'data-wp-temp-link': 1 } ); |
426 editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder', 'data-wp-temp-link': 1 } ); |
427 $link = editor.$( 'a[data-wp-temp-link="1"]' ).removeAttr( 'data-wp-temp-link' ); |
427 $link = editor.$( 'a[data-wp-temp-link="1"]' ).removeAttr( 'data-wp-temp-link' ); |
428 hasText = $.trim( $link.text() ); |
428 hasText = $link.text().trim(); |
429 } |
429 } |
430 |
430 |
431 if ( ! $link.length ) { |
431 if ( ! $link.length ) { |
432 editor.execCommand( 'unlink' ); |
432 editor.execCommand( 'unlink' ); |
433 } else { |
433 } else { |
481 } else if ( typeof this.textarea.selectionStart !== 'undefined' ) { |
481 } else if ( typeof this.textarea.selectionStart !== 'undefined' ) { |
482 selection = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd ); |
482 selection = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd ); |
483 } |
483 } |
484 } |
484 } |
485 |
485 |
486 selection = $.trim( selection ); |
486 selection = selection || ''; |
|
487 selection = selection.trim(); |
487 |
488 |
488 if ( selection && emailRegexp.test( selection ) ) { |
489 if ( selection && emailRegexp.test( selection ) ) { |
489 // Selection is email address. |
490 // Selection is email address. |
490 return 'mailto:' + selection; |
491 return 'mailto:' + selection; |
491 } else if ( selection && urlRegexp.test( selection ) ) { |
492 } else if ( selection && urlRegexp.test( selection ) ) { |
555 id = event.target.id; |
556 id = event.target.id; |
556 |
557 |
557 // wp-link-submit must always be the last focusable element in the dialog. |
558 // wp-link-submit must always be the last focusable element in the dialog. |
558 // Following focusable elements will be skipped on keyboard navigation. |
559 // Following focusable elements will be skipped on keyboard navigation. |
559 if ( id === 'wp-link-submit' && ! event.shiftKey ) { |
560 if ( id === 'wp-link-submit' && ! event.shiftKey ) { |
560 inputs.close.focus(); |
561 inputs.close.trigger( 'focus' ); |
561 event.preventDefault(); |
562 event.preventDefault(); |
562 } else if ( id === 'wp-link-close' && event.shiftKey ) { |
563 } else if ( id === 'wp-link-close' && event.shiftKey ) { |
563 inputs.submit.focus(); |
564 inputs.submit.trigger( 'focus' ); |
564 event.preventDefault(); |
565 event.preventDefault(); |
565 } |
566 } |
566 } |
567 } |
567 |
568 |
568 // Up Arrow and Down Arrow keys. |
569 // Up Arrow and Down Arrow keys. |
623 this.waiting = element.find('.river-waiting'); |
624 this.waiting = element.find('.river-waiting'); |
624 |
625 |
625 this.change( search ); |
626 this.change( search ); |
626 this.refresh(); |
627 this.refresh(); |
627 |
628 |
628 $( '#wp-link .query-results, #wp-link #link-selector' ).scroll( function() { |
629 $( '#wp-link .query-results, #wp-link #link-selector' ).on( 'scroll', function() { |
629 self.maybeLoad(); |
630 self.maybeLoad(); |
630 }); |
631 }); |
631 element.on( 'click', 'li', function( event ) { |
632 element.on( 'click', 'li', function( event ) { |
632 self.select( $( this ), event ); |
633 self.select( $( this ), event ); |
633 }); |
634 }); |
795 callback( r, query ); |
796 callback( r, query ); |
796 }, 'json' ); |
797 }, 'json' ); |
797 } |
798 } |
798 }); |
799 }); |
799 |
800 |
800 $( document ).ready( wpLink.init ); |
801 $( wpLink.init ); |
801 })( jQuery, window.wpLinkL10n, window.wp ); |
802 })( jQuery, window.wpLinkL10n, window.wp ); |