Changeset 8054
- Timestamp:
- 01/09/2019 02:26:21 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/style/trac/wp-trac.js
r8052 r8054 78 78 wpTrac.autocomplete.init(); 79 79 wpTrac.linkMentions(); 80 wpTrac.linkGutenbergIssues(); 80 81 81 82 if ( ! $body.hasClass( 'plugins' ) ) { … … 105 106 }, 106 107 107 linkMentions: function( ) {108 linkMentions: function( selector ) { 108 109 // See https://github.com/regexps/mentions-regex/blob/master/index.js#L21 109 110 var mentionsRegEx = /(^|[^a-zA-Z0-9_@!@#$%&*])(?:(?:@|@)(?!\/))([a-zA-Z0-9/_\-.]{1,20})(?:\b(?!@|@)|$)/g, 110 111 mentionsInAttrRegEx = new RegExp( '="[^"]*?' + mentionsRegEx.source + '[\\s\\S]*?"' ); 111 112 112 $( 'div.change .comment, #ticket .description' ).each( function() {113 $( selector || 'div.change .comment, #ticket .description' ).each( function() { 113 114 var $comment = $( this ).html(); 114 115 … … 134 135 135 136 // Restore mentions in HTML attributes. 137 if ( placeholders.length ) { 138 $comment = $comment.replace( '__PLACEHOLDER__', function() { 139 return placeholders.shift(); 140 } ); 141 } 142 143 $( this ).html( $comment ); 144 } 145 }); 146 }, 147 148 linkGutenbergIssues: function( selector ) { 149 var gutenRegEx = /\bGB[-]?(\d+)(<\/a>)?\b/gi, 150 gutenInAttrRegEx = new RegExp( '="[^"]*?' + gutenRegEx.source + '[\\s\\S]*?"' ); 151 152 $( selector || 'div.change .comment, #ticket .description' ).each( function() { 153 var $comment = $( this ).html(); 154 155 if ( gutenRegEx.test( $comment ) ) { 156 var placeholders = []; 157 158 if ( gutenInAttrRegEx.test( $comment ) ) { 159 // Preserve matches in HTML attributes. 160 $comment = $comment.replace( gutenInAttrRegEx, function( match ) { 161 placeholders.push( match ); 162 return '__PLACEHOLDER__'; 163 } ); 164 } 165 166 $comment = $comment.replace( gutenRegEx, function( match, issueNumber, closing_a_present ) { 167 if ( closing_a_present ) { 168 // Already linked 169 return match; 170 } 171 172 return '<a class="gutenberg-issue github ext-link" href="https://github.com/WordPress/Gutenberg/issues/' + issueNumber + '"><span class="icon">​</span>' + match + '</a>'; 173 } ); 174 175 // Restore matches in HTML attributes. 136 176 if ( placeholders.length ) { 137 177 $comment = $comment.replace( '__PLACEHOLDER__', function() { … … 174 214 }; 175 215 }); 216 217 wpTrac.linkGutenbergIssues( '.ticketdraft .comment' ); 218 wpTrac.linkMentions( '.ticketdraft .comment' ); 176 219 }, 177 220
Note: See TracChangeset
for help on using the changeset viewer.