Making WordPress.org

Changeset 1957


Ignore:
Timestamp:
10/10/2015 09:25:06 PM (8 years ago)
Author:
ocean90
Message:

Trac: Add autocomplete for usernames and attachments.

For now the list of usernames includes users who have commented to the ticket. Core Trac includes also committers.

Props helen, johnbillion, DrewAPicture, ocean90.
See #830.

Location:
sites/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/trac.wordpress.org/templates/core/site-specific.html

    r1955 r1957  
    5151};
    5252
     53var wpTracAutoCompleteUsers = {
     54    include: $.map( wpTracContributorLabels, function( v, k ) { return k } ),
     55    exclude: [
     56        'slackbot',
     57        'ircbot',
     58    ]
     59};
     60
    5361</script>
    5462</body>
  • sites/trunk/trac.wordpress.org/templates/site.html

    r1954 r1957  
    300300    </script>
    301301
     302    <script py:if="req.authname">
     303    var wpTracCurrentUser = "${req.authname}";
     304    </script>
     305
    302306    <!--! JavaScript -->
     307    <script src="//s.w.org/style/trac/jquery.caret.min.js?ver=2015-02-01"></script>
     308    <script src="//s.w.org/style/trac/jquery.atwho.min.js?ver=1.0.1"></script>
    303309    <script src="//s.w.org/style/trac/wp-trac.js?${scripts_version}"></script>
    304310
  • sites/trunk/wordpress.org/public_html/style/trac/wp-trac.css

    r1934 r1957  
    16491649}
    16501650
     1651/**
     1652 * Autocomplete via At.js.
     1653 */
     1654
     1655.atwho-container {
     1656    font-size: 1.3em
     1657}
     1658
     1659.atwho-view {
     1660    position: absolute;
     1661    top: 0;
     1662    left: 0;
     1663    display: none;
     1664    margin-top: 18px;
     1665    background: #fff;
     1666    color: black;
     1667    border: 1px solid #ccc;
     1668    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
     1669    min-width: 120px;
     1670    max-height: 200px;
     1671    overflow: auto;
     1672    z-index: 11110 !important;
     1673}
     1674
     1675.atwho-view .cur {
     1676    background: #0073aa;
     1677    color: #fff;
     1678}
     1679
     1680.atwho-view .cur small {
     1681    color: #fff;
     1682}
     1683
     1684.atwho-view strong {
     1685    color: #0073aa;
     1686}
     1687
     1688.atwho-view .cur strong {
     1689    color: #fff;
     1690    font: bold;
     1691}
     1692
     1693.atwho-view ul {
     1694    /* width: 100px; */
     1695    list-style: none;
     1696    padding: 0;
     1697    margin: auto;
     1698}
     1699
     1700.atwho-view ul li {
     1701    display: block;
     1702    padding: 5px 10px;
     1703    border-bottom: 1px solid #ccc;
     1704    cursor: pointer;
     1705}
     1706
     1707.atwho-view ul li:last-child {
     1708    border-bottom: 0;
     1709}
     1710
     1711.atwho-view small {
     1712    font-size: smaller;
     1713    color: #777;
     1714    font-weight: normal;
     1715}
     1716
     1717
    16511718/* =Responsive / Mobile
    16521719----------------------------------------------- */
  • sites/trunk/wordpress.org/public_html/style/trac/wp-trac.js

    r1955 r1957  
    4444
    4545        gardener: typeof wpBugGardener !== 'undefined',
     46        currentUser: wpTracCurrentUser,
    4647
    4748        init: function() {
     
    5455                wpTrac.showContributorLabels( wpTracContributorLabels );
    5556            }
     57
     58            wpTrac.autocomplete.init();
    5659
    5760            if ( ! $(document.body).hasClass( 'plugins' ) ) {
     
    7477            });
    7578        },
     79
    7680        // These ticket hacks need to be re-run after ticket previews.
    7781        postPreviewHacks: function() {
     
    411415            });
    412416        },
     417
     418        autocomplete: (function() {
     419            var users,
     420                attachments,
     421                settings = {};
     422
     423            return {
     424                init: function() {
     425                    if ( ! $( '#comment' ).length ) {
     426                        return;
     427                    }
     428
     429                    if ( 'undefined' !== typeof wpTracAutoCompleteUsers ) {
     430                        settings = wpTracAutoCompleteUsers;
     431                    }
     432
     433                    users = this.getUsers();
     434                    attachments  = this.getAttachments();
     435
     436                    $( '#comment' ).atwho({
     437                        at:  '@',
     438                        data: users
     439                    }).atwho({
     440                        at: '[att',
     441                        insertTpl: '${atwho-at}achment:${name}]',
     442                        displayTpl: '<li>${display}</li>',
     443                        data: attachments
     444                    });
     445                },
     446
     447                getUsers: function() {
     448                    var users  = [], exclude = [];
     449
     450                    if ( 'undefined' !== settings.exclude ) {
     451                        exclude = settings.exclude;
     452                    }
     453
     454                    // Most recent should show up first.
     455                    $( $( '.change .username' ).get().reverse() ).each( function() {
     456                        var username = $(this).data( 'username' );
     457                        if (
     458                            typeof username !== 'undefined' &&
     459                            -1 === $.inArray( username, users ) &&
     460                            -1 === $.inArray( username, exclude )
     461                        ) {
     462                            users.push( $(this).data( 'username' ) );
     463                        }
     464                    });
     465
     466                    // Add additional users.
     467                    if ( 'undefined' !== typeof settings.include ) {
     468                        $.each( settings.include, function( k, username ) {
     469                            if ( -1 === $.inArray( username, users ) ) {
     470                                users.push( username );
     471                            }
     472                        });
     473                    }
     474
     475                    // Exclude current user.
     476                    if ( 'undefined' !== wpTrac.currentUser ) {
     477                        users = $.grep( users, function( user ) {
     478                            return user != wpTrac.currentUser;
     479                        });
     480                    }
     481
     482                    return users;
     483                },
     484
     485                getAttachments: function() {
     486                    var attachments = [];
     487
     488                    // Most recent should show up first.
     489                    $ ($( 'dl.attachments dt' ).get().reverse() ).each( function() {
     490                        attachments.push({
     491                            display: $( this ).text(),
     492                            name: $( this ).find( 'a[title="View attachment"]' ).text()
     493                        });
     494                    });
     495
     496                    return attachments;
     497                }
     498            };
     499        }()),
    413500
    414501        workflow: (function() {
Note: See TracChangeset for help on using the changeset viewer.