<commit_before>// -------------------------------------------------------------------------- \\
// File: PushSelectView.js                                                    \\
// Module: View                                                               \\
// Requires: Core, Foundation, DOM                                            \\
// Author: <NAME>                                                       \\
// License: © 2010–2012 Opera Software ASA. All rights reserved.              \\
// -------------------------------------------------------------------------- \\

"use strict";

( function ( NS, undefined ) {

var PushSelectView = NS.Class({

    Extends: NS.View,

    options: [],

    // --- Render ---

    className: 'PushSelectView',

    _render: function ( layer ) {
        layer.appendChild( this._renderSelect() );
    },
    _renderSelect: function () {
        var el = NS.Element.create,
            selected = this.get( 'value' );

        return el( 'div',
            this.get( 'options' ).map( function ( option, i ) {
                return el( 'span', NS.extend({
                    className: ( option.className || '' ) +
                        ( option.value === selected ? ' selected' : '' ),
                    'data-index': i
                }, option, true ) );
            })
        );
    },

    // --- Keep state in sync with render ---

    _selectOption: function ( event ) {
        var i = event.target.get( 'data-index' );
        if ( i != null ) {
            this.set( 'value', this.get( 'options' ).getObjectAt( i ).value );
        }
    }.on( 'click' ),

    // --- Keep render in sync with state ---

    optionsDidChange: function () {
        if ( this.get( 'isRendered' ) ) {
            var layer = this.get( 'layer' );
            layer.replaceChild( this._renderSelect(), layer.firstChild );
        }
    }.observes( 'options' ),

    updateLayer: function ( _, __, oldValue, newValue ) {
        if ( this.get( 'isRendered' ) ) {
            var Element = NS.Element,
                childNodes = this.get( 'layer' ).firstChild.childNodes;
            this.get( 'options' ).forEach( function ( option, i ) {
                if ( option.value === oldValue ) {
                    Element.removeClass( childNodes[ i ], 'selected' );
                }
                if ( option.value === newValue ) {
                    Element.addClass( childNodes[ i ], 'selected' );
                }
            });
        }
    }.observes( 'value' )
});

NS.PushSelectView = PushSelectView;

}( this.O ) );
<commit_msg>Make PushSelectView more accessible to screen readers<commit_after>// -------------------------------------------------------------------------- \\
// File: PushSelectView.js                                                    \\
// Module: View                                                               \\
// Requires: Core, Foundation, DOM                                            \\
// Author: <NAME>                                                       \\
// License: © 2010–2012 Opera Software ASA. All rights reserved.              \\
// -------------------------------------------------------------------------- \\

"use strict";

( function ( NS, undefined ) {

var PushSelectView = NS.Class({

    Extends: NS.View,

    options: [],

    // --- Render ---

    className: 'PushSelectView',

    _render: function ( layer ) {
        layer.appendChild( this._renderSelect() );
    },
    _renderSelect: function () {
        var el = NS.Element.create,
            selected = this.get( 'value' );

        return el( 'div',
            this.get( 'options' ).reduce( function ( children, option, i ) {
                if ( i ) {
                    children.push( '​' ); // Zero-width space
                }
                children.push(
                    el( 'a', NS.extend({
                        className: ( option.className || '' ) +
                            ( option.value === selected ? ' selected' : '' ),
                        'data-index': i
                    }, option, true ) )
                );
                return children;
            }, [] )
        );
    },

    // --- Keep state in sync with render ---

    _selectOption: function ( event ) {
        var i = event.target.get( 'data-index' );
        if ( i != null ) {
            this.set( 'value', this.get( 'options' ).getObjectAt( i ).value );
        }
    }.on( 'click' ),

    // --- Keep render in sync with state ---

    optionsDidChange: function () {
        if ( this.get( 'isRendered' ) ) {
            var layer = this.get( 'layer' );
            layer.replaceChild( this._renderSelect(), layer.firstChild );
        }
    }.observes( 'options' ),

    updateLayer: function ( _, __, oldValue, newValue ) {
        if ( this.get( 'isRendered' ) ) {
            var Element = NS.Element,
                childNodes = this.get( 'layer' ).firstChild.childNodes;
            this.get( 'options' ).forEach( function ( option, i ) {
                if ( option.value === oldValue ) {
                    Element.removeClass( childNodes[ i * 2 ], 'selected' );
                }
                if ( option.value === newValue ) {
                    Element.addClass( childNodes[ i * 2 ], 'selected' );
                }
            });
        }
    }.observes( 'value' )
});

NS.PushSelectView = PushSelectView;

}( this.O ) );

{'fraction_non_alphanumeric': 0.18903452095255677, 'fraction_numerical': 0.003322872438619162, 'mean_word_length': 1.0695187165775402, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5518848', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1291, 'n_words': 323}