Changeset 31832
- Timestamp:
- 03/19/2015 07:07:48 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/tinymce/plugins/wpview/plugin.js
r31819 r31832 168 168 // view wrappers. 169 169 editor.on( 'BeforeSetContent', function( event ) { 170 var pastedStr = event.content, 171 trim = tinymce.trim, 172 node; 173 174 if ( ! pastedStr ) { 170 var node; 171 172 if ( ! event.content ) { 175 173 return; 176 174 } 177 175 178 if ( selected ) {179 removeView( selected );180 }181 182 176 node = editor.selection.getNode(); 183 177 184 pastedStr = pastedStr.replace( /<[^>]+>/g, '' );185 pastedStr = trim( pastedStr );186 187 178 // When a url is pasted, only try to embed it when pasted in an empty paragrapgh. 188 if ( /^https?:\/\/\S+$/i.test( pastedStr ) ) { 189 event.content = pastedStr; 190 191 node = editor.dom.getParent( node, function( node ) { 192 if ( node.parentNode === editor.getBody() ) { 193 return node; 194 } 195 } ); 196 197 if ( node.nodeName !== 'P' || trim( node.textContent || node.innerText ) ) { 198 return; 199 } 179 if ( event.content.match( /^\s*(https?:\/\/[^\s"]+)\s*$/i ) && 180 ( node.nodeName !== 'P' || node.parentNode !== editor.getBody() || ! editor.dom.isEmpty( node ) ) ) { 181 182 return; 200 183 } 201 184 202 185 event.content = wp.mce.views.setMarkers( event.content ); 186 }); 187 188 // When pasting strip all tags and check if the string is an URL. 189 // Then replace the pasted content with the cleaned URL. 190 editor.on( 'pastePreProcess', function( event ) { 191 var pastedStr = event.content; 192 193 if ( pastedStr ) { 194 pastedStr = tinymce.trim( pastedStr.replace( /<[^>]+>/g, '' ) ); 195 196 if ( /^https?:\/\/\S+$/i.test( pastedStr ) ) { 197 event.content = pastedStr; 198 } 199 } 203 200 }); 204 201
Note: See TracChangeset
for help on using the changeset viewer.