Changeset 10876
- Timestamp:
- 04/07/2021 03:51:17 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/js/forums.js
r10702 r10876 26 26 $( '#new-post textarea' ).on( 'paste', function( e ) { 27 27 var $this = $(this), 28 $val = $this.val(),29 paste = ( e.originalEvent.clipboardData || window.clipboardData ).getData('text') ;28 val = $this.val(), 29 paste = ( e.originalEvent.clipboardData || window.clipboardData ).getData('text').trim(); 30 30 31 31 // If no pasted text, or no textarea value, skip. 32 if ( ! paste.length || ! $val.length ) {32 if ( ! paste.length || ! val.length ) { 33 33 return; 34 34 } 35 35 36 36 if ( 37 paste.length < 1000 && // Super long pastes get code wrapped38 paste.split("\n").length < 10// in addition to many-lines pastes.37 paste.length < 500 && // Super long pastes get code wrapped 38 paste.split("\n").length < 5 // in addition to many-lines pastes. 39 39 ) { 40 return; 41 } 42 43 // See if the author is pasting into a code block already 44 if ( '`' === val.substr( $this.prop('selectionStart') - 1 , 1 ) ) { 45 return; 46 } 47 48 // If the code being pasted is already wrapped in backticks (well, starts with OR ends with), skip. 49 if ( 50 '`' === paste.substr( 0, 1 ) || 51 '`' === paste.substr( -1, 1 ) 52 ) { 40 53 return; 41 54 } 42 55 43 56 $this.val( 44 $val.substring( 0, $this.prop('selectionStart') ) +// Text before cusor/selection45 "`" + paste .trim().replace(/^`|`$/g, '') + "`" + // The pasted text, trimming ` off it andwrapping with `46 $val.substring( $this.prop('selectionEnd'), $val.length ) // Text after cursor position/selection57 val.substr( 0, $this.prop('selectionStart') ) + // Text before cusor/selection 58 "`" + paste + "`" + // The pasted text, wrapping with ` 59 val.substr( $this.prop('selectionEnd'), val.length ) // Text after cursor position/selection 47 60 ); 48 61
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)