Making WordPress.org

Changeset 298


Ignore:
Timestamp:
01/19/2014 07:19:54 PM (13 years ago)
Author:
nacin
Message:

Trac:

  • After comment previews, re-hide CCs and re-show any image previews.
  • Point new tickets in the 'WordPress.org site' component to meta.trac.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/style/trac/wp-trac.js

    r297 r298  
    3131        wpTrac = {
    3232
    33                 gardener : typeof wpBugGardener !== 'undefined',
    34 
    35                 init : function() {
     33                gardener: typeof wpBugGardener !== 'undefined',
     34
     35                init: function() {
    3636                        wpTrac.hacks();
    3737                        if ( ! $(document.body).hasClass( 'plugins' ) ) {
     
    4141                },
    4242
    43                 hacks: function() {
    44                         // Change 'Comments' and 'Stars' columns to dashicons glyphs to save space
    45                         $('th a[href*="sort=Comments"]').html('<div class="dashicons dashicons-admin-comments"></div>');
    46                         $('th a[href*="sort=Stars"]').html('<div class="dashicons dashicons-star-empty"></div>');
    47 
     43                // These ticket hacks need to be re-run after ticket previews.
     44                postPreviewHacks: function() {
    4845                        // Automatically preview images.
    4946                        $('li.trac-field-attachment').each( function() {
     
    7774                                el.children().appendTo( el.prev().children('.trac-ticket-buttons') ).end().end().remove();
    7875                        });
     76                },
     77
     78                hacks: function() {
     79                        var content = $( '#content' );
     80
     81                        // Change 'Comments' and 'Stars' columns to dashicons glyphs to save space
     82                        $('th a[href*="sort=Comments"]').html('<div class="dashicons dashicons-admin-comments"></div>');
     83                        $('th a[href*="sort=Stars"]').html('<div class="dashicons dashicons-star-empty"></div>');
     84
     85                        if ( content.hasClass( 'ticket' ) ) {
     86                                if ( $(document.body).hasClass( 'core' ) ) {
     87                                        wpTrac.coreToMeta();
     88                                }
     89
     90                                // A collection of ticket hacks that must be run again after previews.
     91                                wpTrac.postPreviewHacks();
     92                                content.on( 'wpTracPostPreview', wpTrac.postPreviewHacks );
     93
     94                                // Allow 'Modify Ticket' to be shown even after a Trac preview tries to close it,
     95                                // but only if it was already open.
     96                                (function(){
     97                                        var action, hadClass,
     98                                                form = $('#propertyform'),
     99                                                modify = $('#modify').parent();
     100
     101                                        if ( ! form.length ) {
     102                                                return;
     103                                        }
     104                                        action = form.attr('action');
     105                                        $(document).ajaxSend( function( event, XMLHttpRequest, ajaxOptions ) {
     106                                                if ( 0 !== action.indexOf( ajaxOptions.url ) ) {
     107                                                        return;
     108                                                }
     109                                                hadClass = modify.hasClass('collapsed');
     110                                        });
     111                                        $(document).ajaxComplete( function( event, XMLHttpRequest, ajaxOptions ) {
     112                                                if ( 0 !== action.indexOf( ajaxOptions.url ) ) {
     113                                                        return;
     114                                                }
     115                                                if ( ! hadClass ) {
     116                                                        modify.removeClass('collapsed');
     117                                                }
     118                                                content.triggerHandler( 'wpTracPostPreview' );
     119                                        });
     120                                })();
     121                        }
    79122
    80123                        // Add After the Deadline (only add it if it loaded)
     
    92135                        // Push live comment previews above 'Modify Ticket'
    93136                        $('#ticketchange').insertAfter('#trac-add-comment');
    94 
    95                         // Allow 'Modify Ticket' to be shown even after a Trac preview tries to close it,
    96                         // but only if it was already open.
    97                         (function(){
    98                                 var action, hadClass,
    99                                         form = $('#propertyform'),
    100                                         modify = $('#modify').parent();
    101 
    102                                 if ( ! form.length ) {
    103                                         return;
    104                                 }
    105                                 action = form.attr('action');
    106                                 $(document).ajaxSend( function( event, XMLHttpRequest, ajaxOptions ) {
    107                                         if ( 0 !== action.indexOf( ajaxOptions.url ) ) {
    108                                                 return;
    109                                         }
    110                                         hadClass = modify.hasClass('collapsed');
    111                                 });
    112                                 $(document).ajaxComplete( function( event, XMLHttpRequest, ajaxOptions ) {
    113                                         if ( hadClass || 0 !== action.indexOf( ajaxOptions.url ) ) {
    114                                                 return;
    115                                         }
    116                                         modify.removeClass('collapsed');
    117                                 });
    118                         })();
    119137
    120138                        // Toggle the security notice on component change, if rendered
     
    224242                                });
    225243                        }
     244                },
     245
     246                coreToMeta: function() {
     247                        var component = $('#field-component');
     248                        if ( window.location.pathname !== '/newticket' ) {
     249                                if ( ! wpTrac.gardener && component.val() !== 'WordPress.org site' ) {
     250                                        component.children('option[value="WordPress.org site"]').remove();
     251                                }
     252                                return;
     253                        }
     254
     255                        component.change( function() {
     256                                var toggle = $('input[name="attachment"]').parent().add('.ticketdraft').add('.wp-notice').add('div.buttons');
     257                                if ( $(this).val() !== 'WordPress.org site' ) {
     258                                        toggle.show();
     259                                        $('.wp-notice.component').remove();
     260                                        return;
     261                                }
     262                                toggle.hide();
     263                                $('div.buttons').after( '<div class="wp-notice component"><p><strong>The WordPress.org site now has its own Trac</strong> at ' +
     264                                        '<a href="//meta.trac.wordpress.org/">meta.trac.wordpress.org</a>.</p><p>Would you mind opening this ticket over there instead? ' +
     265                                        '<a href="//meta.trac.wordpress.org/newticket" id="new-meta-ticket">Click here</a> to copy your summary and description over.</p></div>' );
     266                        });
     267       
     268                        $('#propertyform').on( 'click', '#new-meta-ticket', function() {
     269                                var url, href = $(this).attr( 'href' );
     270                                url = href + '?' + $.param({ summary: $('#field-summary').val(), description: $('#field-description').val() });
     271                                if ( url.length > 1500 ) {
     272                                        url = href + '?' + $.param({
     273                                                summary: $('#field-summary').val(),
     274                                                description: "(Couldn't copy over your description as it was too long. Please paste it here. Your old window was not closed.)"
     275                                        });
     276                                        window.open( url );
     277                                } else {
     278                                        window.location.href = url;
     279                                }
     280                                return false;
     281                        });
    226282                },
    227283
     
    442498                                }
    443499                                if ( content.hasClass( 'ticket' ) ) {
    444                                         $( '#changelog div.change' ).has( 'li.trac-field-cc' ).each( function() {
    445                                                 var change = $(this), changes = change.children( 'ul.changes' );
    446                                                 /* Three possibilities:
    447                                                    The comment is just a single CC (hide the whole comment)
    448                                                    The comment is a CC plus a comment (hide the CC line)
    449                                                    The comment contains multiple property changes (hide only the CC line)
    450                                                 */
    451                                                 if ( changes.children( 'li' ).length === 1 ) {
    452                                                         if ( change.children( 'div.comment' ).length === 0 ) {
    453                                                                 change.hide();
    454                                                         } else {
    455                                                                 changes.hide();
    456                                                         }
     500                                        hide_cc_comments();
     501                                        content.on( 'wpTracPostPreview', hide_cc_comments );
     502                                }
     503                        }
     504
     505                        function hide_cc_comments() {
     506                                $( '#changelog div.change' ).has( 'li.trac-field-cc' ).each( function() {
     507                                        var change = $(this), changes = change.children( 'ul.changes' );
     508                                        /* Three possibilities:
     509                                           The comment is just a single CC (hide the whole comment)
     510                                           The comment is a CC plus a comment (hide the CC line)
     511                                           The comment contains multiple property changes (hide only the CC line)
     512                                        */
     513                                        if ( changes.children( 'li' ).length === 1 ) {
     514                                                if ( change.children( 'div.comment' ).length === 0 ) {
     515                                                        change.hide();
    457516                                                } else {
    458                                                         changes.children( 'li.trac-field-cc' ).hide();
     517                                                        changes.hide();
    459518                                                }
    460                                         });
    461                                 }
     519                                        } else {
     520                                                changes.children( 'li.trac-field-cc' ).hide();
     521                                        }
     522                                });
    462523                        }
    463524
Note: See TracChangeset for help on using the changeset viewer.