Changeset 31713
- Timestamp:
- 03/11/2015 02:39:02 AM (10 years ago)
- Location:
- trunk/src/wp-includes
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-editor.php
r31222 r31713 1449 1449 <div id="link-options"> 1450 1450 <p class="howto"><?php _e( 'Enter the destination URL' ); ?></p> 1451 <div >1452 <label><span><?php _e( ' URL' ); ?></span><input id="url-field" type="text" name="href" /></label>1451 <div class="wp-link-text-field"> 1452 <label><span><?php _e( 'Text' ); ?></span><input id="wp-link-text" type="text" /></label> 1453 1453 </div> 1454 1454 <div> 1455 <label><span><?php _e( ' Title' ); ?></span><input id="link-title-field" type="text" name="linktitle" /></label>1455 <label><span><?php _e( 'URL' ); ?></span><input id="wp-link-url" type="text" /></label> 1456 1456 </div> 1457 1457 <div class="link-target"> 1458 <label><span> </span><input type="checkbox" id=" link-target-checkbox" /> <?php _e( 'Open link in a new window/tab' ); ?></label>1458 <label><span> </span><input type="checkbox" id="wp-link-target" /> <?php _e( 'Open link in a new window/tab' ); ?></label> 1459 1459 </div> 1460 1460 </div> … … 1464 1464 <label> 1465 1465 <span class="search-label"><?php _e( 'Search' ); ?></span> 1466 <input type="search" id=" search-field" class="link-search-field" autocomplete="off" />1466 <input type="search" id="wp-link-search" class="link-search-field" autocomplete="off" /> 1467 1467 <span class="spinner"></span> 1468 1468 </label> -
trunk/src/wp-includes/css/editor.css
r31573 r31713 1194 1194 box-shadow: 0 3px 6px rgba( 0, 0, 0, 0.3 ); 1195 1195 width: 500px; 1196 height: 250px;1197 1196 overflow: hidden; 1198 1197 margin-left: -250px; … … 1230 1229 } 1231 1230 1231 #wp-link-wrap .wp-link-text-field { 1232 display: none; 1233 } 1234 1235 #wp-link-wrap.has-text-field .wp-link-text-field { 1236 display: block; 1237 } 1238 1232 1239 #link-modal-title { 1233 1240 background: #fcfcfc; … … 1396 1403 right: 16px; 1397 1404 bottom: 16px; 1405 top: 172px; 1406 } 1407 1408 .has-text-field #wp-link .query-results { 1398 1409 top: 205px; 1399 1410 } … … 1530 1541 @media screen and ( max-width: 782px ) { 1531 1542 #wp-link-wrap { 1532 height: 280px;1533 1543 margin-top: -140px; 1534 1544 } 1535 1545 1536 1546 #wp-link-wrap.search-panel-visible .query-results { 1547 top: 195px; 1548 } 1549 1550 #wp-link-wrap.search-panel-visible.has-text-field .query-results { 1537 1551 top: 235px; 1538 1552 } -
trunk/src/wp-includes/js/tinymce/plugins/wplink/plugin.js
r31691 r31713 1 1 /* global tinymce */ 2 2 tinymce.PluginManager.add( 'wplink', function( editor ) { 3 var linkButton;4 5 // Register a command so that it can be invoked by using tinyMCE.activeEditor.execCommand( 'WP_Link' );6 3 editor.addCommand( 'WP_Link', function() { 7 if ( ( ! linkButton || ! linkButton.disabled() ) && typeof window.wpLink !== 'undefined' ) { 8 window.wpLink.open( editor.id ); 9 } 4 window.wpLink && window.wpLink.open( editor.id ); 10 5 }); 11 6 … … 15 10 editor.addShortcut( 'ctrl+k', '', 'WP_Link' ); 16 11 17 function setState( button, node ) {18 var parent = editor.dom.getParent( node, 'a' ),19 getView = editor.plugins.wpview ? editor.plugins.wpview.getView : function() { return false; };20 21 button.disabled( ( editor.selection.isCollapsed() && ! parent ) || ( parent && ! parent.href ) || getView( node ) );22 button.active( parent && parent.href );23 }24 25 12 editor.addButton( 'link', { 26 13 icon: 'link', … … 28 15 shortcut: 'Alt+Shift+A', 29 16 cmd: 'WP_Link', 30 31 onPostRender: function() { 32 linkButton = this; 33 34 editor.on( 'nodechange', function( event ) { 35 setState( linkButton, event.element ); 36 }); 37 } 17 stateSelector: 'a[href]' 38 18 }); 39 19 … … 41 21 icon: 'unlink', 42 22 tooltip: 'Remove link', 43 cmd: 'unlink', 44 45 onPostRender: function() { 46 var unlinkButton = this; 47 48 editor.on( 'nodechange', function( event ) { 49 setState( unlinkButton, event.element ); 50 }); 51 } 23 cmd: 'unlink' 52 24 }); 53 25 -
trunk/src/wp-includes/js/wplink.js
r31606 r31713 7 7 rivers = {}, 8 8 isTouch = ( 'ontouchend' in document ); 9 10 function getLink() { 11 return editor.dom.getParent( editor.selection.getNode(), 'a' ); 12 } 9 13 10 14 wpLink = { … … 22 26 inputs.submit = $( '#wp-link-submit' ); 23 27 inputs.close = $( '#wp-link-close' ); 24 // URL 25 inputs.url = $( '#url-field' ); 28 29 // Input 30 inputs.text = $( '#wp-link-text' ); 31 inputs.url = $( '#wp-link-url' ); 26 32 inputs.nonce = $( '#_ajax_linking_nonce' ); 27 // Secondary options 28 inputs.title = $( '#link-title-field' ); 29 // Advanced Options 30 inputs.openInNewTab = $( '#link-target-checkbox' ); 31 inputs.search = $( '#search-field' ); 33 inputs.openInNewTab = $( '#wp-link-target' ); 34 inputs.search = $( '#wp-link-search' ); 35 32 36 // Build Rivers 33 37 rivers.search = new River( $( '#search-results' ) ); … … 130 134 131 135 wpLink.refresh(); 136 132 137 $( document ).trigger( 'wplink-open', inputs.wrap ); 133 138 }, … … 145 150 wpLink.mceRefresh(); 146 151 } else { 152 inputs.wrap.removeClass( 'has-text-field' ); 153 inputs.text.val( '' ); 147 154 wpLink.setDefaultValues(); 148 155 } … … 155 162 // If this is moved above the selection changes, 156 163 // IE will show a flashing cursor over the dialog. 157 inputs.url.focus()[0].select(); 164 if ( inputs.wrap.hasClass( 'has-text-field' ) ) { 165 inputs.text.focus(); 166 } else { 167 inputs.url.focus()[0].select(); 168 } 158 169 } 159 170 … … 166 177 }, 167 178 179 hasSelectedText: function( linkNode ) { 180 var html = editor.selection.getContent(); 181 182 // Partial html and not a fully selected anchor element 183 if ( /</.test( html ) && ( ! /^<a [^>]+>[^<]+<\/a>$/.test( html ) || html.indexOf('href=') === -1 ) ) { 184 return false; 185 } 186 187 if ( linkNode ) { 188 var nodes = linkNode.childNodes, i; 189 190 if ( nodes.length === 0 ) { 191 return false; 192 } 193 194 for ( i = nodes.length - 1; i >= 0; i-- ) { 195 if ( nodes[i].nodeType != 3 ) { 196 return false; 197 } 198 } 199 } 200 201 return true; 202 }, 203 168 204 mceRefresh: function() { 169 var e; 170 171 // If link exists, select proper values. 172 if ( e = editor.dom.getParent( editor.selection.getNode(), 'A' ) ) { 173 // Set URL and description. 174 inputs.url.val( editor.dom.getAttrib( e, 'href' ) ); 175 inputs.title.val( editor.dom.getAttrib( e, 'title' ) ); 176 // Set open in new tab. 177 inputs.openInNewTab.prop( 'checked', ( '_blank' === editor.dom.getAttrib( e, 'target' ) ) ); 178 // Update save prompt. 205 var text, 206 selectedNode = editor.selection.getNode(), 207 linkNode = editor.dom.getParent( selectedNode, 'a[href]' ), 208 onlyText = this.hasSelectedText( linkNode ); 209 210 if ( linkNode ) { 211 text = linkNode.innerText || linkNode.textContent; 212 inputs.url.val( editor.dom.getAttrib( linkNode, 'href' ) ); 213 inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode, 'target' ) ); 179 214 inputs.submit.val( wpLinkL10n.update ); 180 181 // If there's no link, set the default values. 182 } else { 183 wpLink.setDefaultValues(); 215 } else { 216 text = editor.selection.getContent({ format: 'text' }); 217 this.setDefaultValues(); 218 } 219 220 if ( onlyText ) { 221 inputs.text.val( text || '' ); 222 inputs.wrap.addClass( 'has-text-field' ); 223 } else { 224 inputs.text.val( '' ); 225 inputs.wrap.removeClass( 'has-text-field' ); 184 226 } 185 227 }, … … 210 252 return { 211 253 href: $.trim( inputs.url.val() ), 212 title: $.trim( inputs.title.val() ),213 254 target: inputs.openInNewTab.prop( 'checked' ) ? '_blank' : '' 214 255 }; … … 216 257 217 258 update: function() { 218 if ( wpLink.isMCE() ) 259 if ( wpLink.isMCE() ) { 219 260 wpLink.mceUpdate(); 220 else261 } else { 221 262 wpLink.htmlUpdate(); 263 } 222 264 }, 223 265 224 266 htmlUpdate: function() { 225 var attrs, html, begin, end, cursor, title, selection,267 var attrs, text, html, begin, end, cursor, selection, 226 268 textarea = wpLink.textarea; 227 269 228 if ( ! textarea ) 229 return; 270 if ( ! textarea ) { 271 return; 272 } 230 273 231 274 attrs = wpLink.getAttrs(); 275 text = inputs.text.val(); 232 276 233 277 // If there's no href, return. 234 if ( ! attrs.href ) 235 return; 278 if ( ! attrs.href ) { 279 return; 280 } 236 281 237 282 // Build HTML 238 283 html = '<a href="' + attrs.href + '"'; 239 240 if ( attrs.title ) {241 title = attrs.title.replace( /</g, '<' ).replace( />/g, '>' ).replace( /"/g, '"' );242 html += ' title="' + title + '"';243 }244 284 245 285 if ( attrs.target ) { … … 255 295 // inside the closing tag. 256 296 textarea.focus(); 257 wpLink.range.text = html + wpLink.range.text+ '</a>';297 wpLink.range.text = html + ( text || wpLink.range.text ) + '</a>'; 258 298 wpLink.range.moveToBookmark( wpLink.range.getBookmark() ); 259 299 wpLink.range.select(); … … 262 302 } else if ( typeof textarea.selectionStart !== 'undefined' ) { 263 303 // W3C 264 begin 265 end 266 selection =textarea.value.substring( begin, end );267 html 268 cursor 304 begin = textarea.selectionStart; 305 end = textarea.selectionEnd; 306 selection = text || textarea.value.substring( begin, end ); 307 html = html + selection + '</a>'; 308 cursor = begin + html.length; 269 309 270 310 // If no text is selected, place the cursor inside the closing tag. 271 if ( begin == end ) 272 cursor -= '</a>'.length; 273 274 textarea.value = textarea.value.substring( 0, begin ) + html + 275 textarea.value.substring( end, textarea.value.length ); 311 if ( begin === end && ! selection ) { 312 cursor -= 4; 313 } 314 315 textarea.value = ( 316 textarea.value.substring( 0, begin ) + 317 html + 318 textarea.value.substring( end, textarea.value.length ) 319 ); 276 320 277 321 // Update cursor position … … 284 328 285 329 mceUpdate: function() { 286 var link,287 attrs = wpLink.getAttrs();330 var attrs = wpLink.getAttrs(), 331 link, text; 288 332 289 333 wpLink.close(); … … 294 338 } 295 339 296 link = editor.dom.getParent( editor.selection.getNode(), 'a[href]' ); 297 298 // If the values are empty, unlink and return 299 if ( ! attrs.href || attrs.href == 'http://' ) { 340 if ( ! attrs.href ) { 300 341 editor.execCommand( 'unlink' ); 301 342 return; 302 343 } 303 344 345 link = getLink(); 346 text = inputs.text.val(); 347 304 348 if ( link ) { 349 if ( text ) { 350 if ( 'innerText' in link ) { 351 link.innerText = text; 352 } else { 353 link.textContent = text; 354 } 355 } 356 305 357 editor.dom.setAttribs( link, attrs ); 306 358 } else { 307 editor.execCommand( 'mceInsertLink', false, attrs ); 308 } 309 310 // Move the cursor to the end of the selection 311 editor.selection.collapse(); 359 if ( text ) { 360 editor.selection.setNode( editor.dom.create( 'a', attrs, text ) ); 361 } else { 362 editor.execCommand( 'mceInsertLink', false, attrs ); 363 } 364 } 312 365 }, 313 366 314 367 updateFields: function( e, li ) { 315 368 inputs.url.val( li.children( '.item-permalink' ).val() ); 316 inputs.title.val( li.hasClass( 'no-title' ) ? '' : li.children( '.item-title' ).text() );317 369 }, 318 370 319 371 setDefaultValues: function() { 320 var selection = editor && editor.selection.getContent(),372 var selection, 321 373 emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i, 322 urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i; 374 urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i, 375 text; 376 377 if ( this.isMCE() ) { 378 selection = editor.selection.getContent(); 379 } else if ( document.selection && wpLink.range ) { 380 selection = wpLink.range.text; 381 } else if ( typeof this.textarea.selectionStart !== 'undefined' ) { 382 selection = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd ); 383 } 323 384 324 385 if ( selection && emailRegexp.test( selection ) ) { … … 332 393 inputs.url.val( '' ); 333 394 } 334 335 // Set description to default.336 inputs.title.val( '' );337 395 338 396 // Update save prompt.
Note: See TracChangeset
for help on using the changeset viewer.