Changeset 3167
- Timestamp:
- 05/18/2016 11:11:33 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/style/trac/wp-trac.js
r3151 r3167 52 52 ]; 53 53 54 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Using_special_characters55 function escapeRegExp( string ) {56 return string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );57 }58 59 54 wpTrac = { 60 55 … … 103 98 linkMentions: function() { 104 99 // See https://github.com/regexps/mentions-regex/blob/master/index.js#L21 105 var mentionsRegEx = /(^|[^a-zA-Z0-9_@!@#$%&*])(?:(?:@|@)(?!\/))([a-zA-Z0-9/_.]{1,20})(?:\b(?!@|@)|$)/g; 100 var mentionsRegEx = /(^|[^a-zA-Z0-9_@!@#$%&*])(?:(?:@|@)(?!\/))([a-zA-Z0-9/_.]{1,20})(?:\b(?!@|@)|$)/g, 101 mentionsInAttrRegEx = new RegExp( '="[^"]*?' + mentionsRegEx.source + '[\\s\\S]*?"' ); 106 102 107 103 $( 'div.change .comment, #ticket .description' ).each( function() { 108 104 $comment = $( this ).html(); 109 105 if ( mentionsRegEx.test( $comment ) ) { 106 var placeholders = []; 107 108 if ( mentionsInAttrRegEx.test( $comment ) ) { 109 // Preserve mentions in HTML attributes. 110 $comment = $comment.replace( mentionsInAttrRegEx, function( match ) { 111 placeholders.push( match ); 112 return '__PLACEHOLDER__'; 113 } ); 114 } 115 110 116 $comment = $comment.replace( mentionsRegEx, function( match, pre, username ) { 111 117 if ( -1 !== $.inArray( username, reservedTerms ) ) { … … 113 119 } 114 120 115 var matchInAttr = new RegExp( '=".*' + escapeRegExp( match ) + '.*"' );116 if ( matchInAttr.test( $comment ) ) {117 return match;118 }119 120 121 var meClass = ( username === wpTrac.currentUser ) ? ' me' : ''; 121 122 return pre + '<a class="mention' + meClass + '" href="https://profiles.wordpress.org/' + username + '">@' + username + '</a>'; 122 123 } ); 124 125 // Restore mentions in HTML attributes. 126 if ( placeholders.length ) { 127 $comment = $comment.replace( '__PLACEHOLDER__', function() { 128 return placeholders.shift(); 129 } ); 130 } 131 123 132 $( this ).html( $comment ); 124 133 }
Note: See TracChangeset
for help on using the changeset viewer.