<commit_before>/*jshint boss:true, expr:true, onevar:false */

/**
 * Create a selection plugin for the RedNose DataTable widget.
 */
var CSS_SELECTED = 'selected',
    CSS_DATA     = 'data',
    CSS_COLUMNS  = 'columns',

    CSS_BOOTSTRAP_ICON_WHITE = 'icon-white',

    DATA_RECORD = 'data-yui3-record',

    /**
    Fired when a row is selected.

    @event select
    **/
    EVT_SELECT = 'select';

function DataTableSelectPlugin () {
    DataTableSelectPlugin.superclass.constructor.apply(this, arguments);
}

/**
 * The identity of the plugin.
 */
DataTableSelectPlugin.NAME = 'dataTableSelectPlugin';

/**
 * The namespace for the plugin.
 */
DataTableSelectPlugin.NS = 'selectable';

/**
 * Static property used to define the default attribute configuration of the
 * plugin.
 */
DataTableSelectPlugin.ATTRS = {

    /**
     * The row currently selected.
     */
    selectedRow : {
        value: null
    }
};

// TODO: Persist selection after sorting.
Y.extend(DataTableSelectPlugin, Y.Plugin.Base, {

    /**
     * Bind the click events and set up a listener for the selectedRow attribute.
     */
    initializer: function () {
        var table      = this.get('host'),
            contentBox = table.get('contentBox');

        this.after('selectedRowChange', this._afterSelectedRowChange, this);

        contentBox.on('click', this._handleClick, this);
        contentBox.on('clickoutside', this._handleClickOutside, this);
    },

    setSelection: function (selection) {
        var host = this.get('host'),
            row  = host.getRow(selection);

        if (row) {
            this.set('selectedRow', row);
        }
    },

    getSelection: function () {
        var row = this.get('selectedRow');

        if (row === null) {
            return null;
        }

        return this._getModelFromTableRow(row);
    },

    /**
     * Handles the click event, and updates the selectedRow attribute,
     * which fires an event on change.
     */
    _handleClick: function (e) {
        var target = e.target,
            host   = this.get('host');

        if (target.test('a')) {
            // Don't trigger selection for URL clicks.
            return false;
        }

        if (target.ancestor('.' + host.getClassName(CSS_DATA) + ' tr')) {
            // This is a table row, update the selection.
            this.set('selectedRow', target.ancestor('.' + host.getClassName(CSS_DATA) +  ' tr'));

        } else if (target.ancestor('.' + host.getClassName(CSS_COLUMNS))) {
            // This is a table column, ignore.
            return false;

        } else {
            // Clicked outside the rows, reset the selection.
            this.set('selectedRow', null);
        }

        return true;
    },

    /**<commit_msg>Added doubleclick event.<commit_after>/*jshint boss:true, expr:true, onevar:false */

/**
 * Create a selection plugin for the RedNose DataTable widget.
 */
var CSS_SELECTED = 'selected',
    CSS_DATA     = 'data',
    CSS_COLUMNS  = 'columns',

    CSS_BOOTSTRAP_ICON_WHITE = 'icon-white',

    DATA_RECORD = 'data-yui3-record',

    /**
     Fired when a row is selected.

     @event select
     **/
    EVT_SELECT = 'select';

    /**
     Fired when a row is doubleclicked.

     @event dblclick
     **/
    EVT_DBLCLICK = 'dblclick';

function DataTableSelectPlugin () {
    DataTableSelectPlugin.superclass.constructor.apply(this, arguments);
}

/**
 * The identity of the plugin.
 */
DataTableSelectPlugin.NAME = 'dataTableSelectPlugin';

/**
 * The namespace for the plugin.
 */
DataTableSelectPlugin.NS = 'selectable';

/**
 * Static property used to define the default attribute configuration of the
 * plugin.
 */
DataTableSelectPlugin.ATTRS = {

    /**
     * The row currently selected.
     */
    selectedRow : {
        value: null
    }
};

// TODO: Persist selection after sorting.
Y.extend(DataTableSelectPlugin, Y.Plugin.Base, {

    /**
     * Bind the click events and set up a listener for the selectedRow attribute.
     */
    initializer: function () {
        var table      = this.get('host'),
            contentBox = table.get('contentBox');

        this.after('selectedRowChange', this._afterSelectedRowChange, this);

        contentBox.on('click', this._handleClick, this);
        contentBox.on('dblclick', this._handleDblClick, this);
        contentBox.on('clickoutside', this._handleClickOutside, this);
    },

    setSelection: function (selection) {
        var host = this.get('host'),
            row  = host.getRow(selection);

        if (row) {
            this.set('selectedRow', row);
        }
    },

    getSelection: function () {
        var row = this.get('selectedRow');

        if (row === null) {
            return null;
        }

        return this._getModelFromTableRow(row);
    },

    /**
     * Handles the click event, and updates the selectedRow attribute,
     * which fires an event on change.
     */
    _handleClick: function (e) {
        var target = e.target,
            host   = this.get('host');

        if (target.test('a')) {
            // Don't trigger selection for URL clicks.
            return false;
        }

        if (target.ancestor('.' + host.getClassName(CSS_DATA) + ' tr')) {
            // This is a table row, update the selection.
            this.set('selectedRow', target.ancestor('.' + host.getClassName(CSS_DATA) +  ' tr'));

        } else if (target.ancestor('.' + host.getClassName(CSS_COLUMNS))) {
            // This is a table column, ignore.
            return false;

        } else {
            // Clicked outside the rows, reset the selection.
            this.set('selectedRow', null);
        }

        return true;
    },

    _handleDblClick: function(e) {
        var table = this.get('host');

        // Fires the double click event from the host
        table.fire(EVT_DBLCLICK);
    },

    /**
{'fraction_non_alphanumeric': 0.12546689303904923, 'fraction_numerical': 0.00033955857385398983, 'mean_word_length': 2.179168915272531, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1687426', 'n_tokens_mistral': 1748, 'n_tokens_neox': 1691, 'n_words': 439}