<commit_before>/**
 *  Copyright (C) 2009-2010 Orbeon, Inc.
 *
 *  This program is free software; you can redistribute it and/or modify it under the terms of the
 *  GNU Lesser General Public License as published by the Free Software Foundation; either version
 *  2.1 of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU Lesser General Public License for more details.
 *
 *  The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
 */
/*
 *  JavaScript implementation for the datatable component (new generation)
 *
 */

/**
 * Implementation of datatable constructor. Creates column resizers.
 *
 * @method ORBEON.widgets.datatable
 * @param element
 *            {DOM Element} The DOM element that contains the table.
 * @param index
 *            {integer} Index (position) of the table in the document. Currently
 *            not used, but might be useful to generate IDs.
 */
ORBEON.widgets.datatable = function (container, index, innerTableWidth) {

    YAHOO.log("Creating datatable index " + index, "info");
    // Store useful stuff as properties
    this.initProperties(container, index, innerTableWidth);

    this.finish();
}

ORBEON.widgets.datatable.prototype.initProperties = function (container, index, innerTableWidth) {
    this.index = index;
    this.innerTableWidth = innerTableWidth;
    this.container = YAHOO.util.Selector.query('div.yui-dt', container, false)[0];
    YAHOO.util.Dom.addClass(this.container, 'fr-dt-initialized');

    this.scrollV = YAHOO.util.Dom.hasClass(this.container, 'fr-scrollV');
    this.scrollH = YAHOO.util.Dom.hasClass(this.container, 'fr-scrollH');
    this.scroll = this.scrollV || this.scrollH;
    this.headBodySplit = this.scroll;

    var tables = YAHOO.util.Selector.query('table', this.container, false);
    this.header = tables[0];
    this.header.style.height = "";

    if (this.headBodySplit) {
        this.table = tables[1];
    } else {
        this.table = tables[0];
    }

    this.thead = YAHOO.util.Selector.query('thead', this.header, true);
    this.tbody = YAHOO.util.Selector.query('tbody', this.table, true);
    this.getAndSetColumns();
    var plainId = this.table.getAttribute('id');
    //the following doesn't work in all the cases!
    //this.id = plainId.substring(0, plainId.length - '-table'.length);
    //Let's take something safer at least in the short term...
    this.id = plainId;
    this.originalWidth = ORBEON.widgets.datatable.utils.getStyle(this.table, 'width', 'auto');
    this.originalHeight = ORBEON.widgets.datatable.utils.getStyle(this.table, 'height', 'auto');
    this.height = ORBEON.widgets.datatable.utils.getStyle(this.table, 'height', 'auto');
    this.hasFixedWidthContainer = this.originalWidth != 'auto';
    this.hasFixedWidthTable = this.hasFixedWidthContainer && ! this.scrollH;
    this.adjustHeightForIE = false;
    if (this.scrollV) {
        this.headerScrollContainer = this.header.parentNode;
        this.headerContainer = this.headerScrollContainer.parentNode;
    } else {
        this.headerContainer = this.header.parentNode;        
    }
    this.bodyContainer = this.table.parentNode;

    // Save original styles

    this.significantNodes = [this.container, this.table, this.thead, this.tbody];
    if (this.headBodySplit) {
        this.significantNodes.push(this.header);
        this.significantNodes.push(this.headerContainer);
        this.significantNodes.push(this.bodyContainer);
        if (this.scrollV) {
            this.significantNodes.push(this.headerScrollContainer);
        }
    }

    for (var i = 0; i < this.significantNodes.length; i++) {
        var node=this.significantNodes[i];
        node.savedWidth = node.style.width;
        node.savedHeight = node.style.height;
        node.savedClassName = node.className;
    }

}

ORBEON.widgets.datatable.prototype.finish = function () {

    this.setSizes();

    if (this.scrollH) {
        YAHOO.util.Event.addListener(this.bodyContainer, 'scroll', ORBEON.widgets.datatable.scrollHandler, this, true);
        this.width = this.container.clientWidth;
        if (this.tableWidth > this.width) {
            this.bodyContainer.style.overflowX = "scroll";
        }
    } else {
        this.width = this.tableWidth;
    }

    this.initColumns();
    
    // Now that the table has been properly sized, reconsider its
    // "resizeability"

    if (this.hasFixedWidthContainer && this.hasFixedWidthTable) {
        // These are fixed width tables without horizontal scroll bars
        // and as we don't know how to resize their columns properly,
        // we'd better consider that as variable width
        this.hasFixedWidthContainer = false;
        this.hasFixedWidthTable = false;
    }
    YAHOO.log("Datatable index " + this.index + 'created with width: ' + this.width + ', table width: ' + this.tableWidth, "info")

}

ORBEON.widgets.datatable.prototype.setSizes = function () {

    var width = this.originalWidth;
    var pxWidth = this.getActualOriginalTableWidth();
    var containerWidth =this.container.clientWidth;


    // See how big the table would be without its size restriction  (for scrollable tables)
    // To do so, temporarily remove the yui-dt-bd class to the table container so that its header is shown

    //if (this.headBodySplit) {
    //    YAHOO.util.Dom.addClass(this.table.parentNode, 'fr-datatable-offscreen');
    //    YAHOO.util.Dom.removeClass(this.table.parentNode, 'yui-dt-bd');
    //}

    // Remove width restrictions if needed
    //if (this.scrollH) {
    //    if (this.innerTableWidth != null) {
    //        YAHOO.util.Dom.setStyle(this.table, 'width', this.innerTableWidth);
    //    } else {
    //        YAHOO.util.Dom.setStyle(this.table, 'width', 'auto');
    //    }
    //}

    // Remove height restrictions if needed
    //if (this.scrollV) {
    //    YAHOO.util.Dom.setStyle(this.table, 'height', 'auto');
    //}

    // Measure the table width
    this.tableWidth = this.table.clientWidth;
    if (this.tableWidth < pxWidth) {
        this.tableWidth = pxWidth;
    }

    // Measure the table and header heights
    //this.tableHeight = this.table.clientHeight;
    this.headerHeight = this.table.tHead.rows[0].clientHeight;
    this.tableHeight = this.table.clientHeight;

    // Do some magic adjustments
    if (this.scrollH) {
        if (pxWidth > this.tableWidth) {
            // Can be the case if table width was expressed as %
            this.tableWidth = pxWidth;
        }
        if (this.innerTableWidth != null) {
            this.tableWidth = this.table.clientWidth;
        } else {
            var minWidth;
            if (this.scrollV) {
                minWidth = this.tableWidth - 19;
            } else {
                if (YAHOO.env.ua.ie > 0 && YAHOO.env.ua.ie < 8) {
                    minWidth = this.tableWidth - 1;
                } else {
                    minWidth = this.tableWidth;
                }

            }
            this.tableWidth = this.optimizeWidth(minWidth);
        }
    } else if (this.scrollV) {
        if (this.hasFixedWidthTable) {
            width = this.tableWidth + 'px';
            this.tableWidth = this.tableWidth - 19;
        } else {
            width = (this.tableWidth + 19) + 'px';
        }
    } else {
        width = (this.tableWidth + 0) + 'px';
    }

    // At last, we know how the table will be sized, it's time to set these sizes

    YAHOO.util.Dom.setStyle(this.table, 'width', this.tableWidth + 'px');

    this.adjustHeightForIE = this.adjustHeightForIE || (this.scrollH && ! this.scrollV && this.height == 'auto' && YAHOO.env.ua.ie > 0 && YAHOO.env.ua.ie < 8);
    if (this.adjustHeightForIE) {
        this.height = (this.tableHeight + 22) + 'px';
        this.adjustHeightForIE = true;
    }

    // Resize the containers if not already done<commit_msg>Datatable: adjust table width by 2px...<commit_after>/**
 *  Copyright (C) 2009-2010 Orbeon, Inc.
 *
 *  This program is free software; you can redistribute it and/or modify it under the terms of the
 *  GNU Lesser General Public License as published by the Free Software Foundation; either version
 *  2.1 of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU Lesser General Public License for more details.
 *
 *  The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
 */
/*
 *  JavaScript implementation for the datatable component (new generation)
 *
 */

/**
 * Implementation of datatable constructor. Creates column resizers.
 *
 * @method ORBEON.widgets.datatable
 * @param element
 *            {DOM Element} The DOM element that contains the table.
 * @param index
 *            {integer} Index (position) of the table in the document. Currently
 *            not used, but might be useful to generate IDs.
 */
ORBEON.widgets.datatable = function (container, index, innerTableWidth) {

    YAHOO.log("Creating datatable index " + index, "info");
    // Store useful stuff as properties
    this.initProperties(container, index, innerTableWidth);

    this.finish();
}

ORBEON.widgets.datatable.prototype.initProperties = function (container, index, innerTableWidth) {
    this.index = index;
    this.innerTableWidth = innerTableWidth;
    this.container = YAHOO.util.Selector.query('div.yui-dt', container, false)[0];
    YAHOO.util.Dom.addClass(this.container, 'fr-dt-initialized');

    this.scrollV = YAHOO.util.Dom.hasClass(this.container, 'fr-scrollV');
    this.scrollH = YAHOO.util.Dom.hasClass(this.container, 'fr-scrollH');
    this.scroll = this.scrollV || this.scrollH;
    this.headBodySplit = this.scroll;

    var tables = YAHOO.util.Selector.query('table', this.container, false);
    this.header = tables[0];
    this.header.style.height = "";

    if (this.headBodySplit) {
        this.table = tables[1];
    } else {
        this.table = tables[0];
    }

    this.thead = YAHOO.util.Selector.query('thead', this.header, true);
    this.tbody = YAHOO.util.Selector.query('tbody', this.table, true);
    this.getAndSetColumns();
    var plainId = this.table.getAttribute('id');
    //the following doesn't work in all the cases!
    //this.id = plainId.substring(0, plainId.length - '-table'.length);
    //Let's take something safer at least in the short term...
    this.id = plainId;
    this.originalWidth = ORBEON.widgets.datatable.utils.getStyle(this.table, 'width', 'auto');
    this.originalHeight = ORBEON.widgets.datatable.utils.getStyle(this.table, 'height', 'auto');
    this.height = ORBEON.widgets.datatable.utils.getStyle(this.table, 'height', 'auto');
    this.hasFixedWidthContainer = this.originalWidth != 'auto';
    this.hasFixedWidthTable = this.hasFixedWidthContainer && ! this.scrollH;
    this.adjustHeightForIE = false;
    if (this.scrollV) {
        this.headerScrollContainer = this.header.parentNode;
        this.headerContainer = this.headerScrollContainer.parentNode;
    } else {
        this.headerContainer = this.header.parentNode;        
    }
    this.bodyContainer = this.table.parentNode;

    // Save original styles

    this.significantNodes = [this.container, this.table, this.thead, this.tbody];
    if (this.headBodySplit) {
        this.significantNodes.push(this.header);
        this.significantNodes.push(this.headerContainer);
        this.significantNodes.push(this.bodyContainer);
        if (this.scrollV) {
            this.significantNodes.push(this.headerScrollContainer);
        }
    }

    for (var i = 0; i < this.significantNodes.length; i++) {
        var node=this.significantNodes[i];
        node.savedWidth = node.style.width;
        node.savedHeight = node.style.height;
        node.savedClassName = node.className;
    }

}

ORBEON.widgets.datatable.prototype.finish = function () {

    this.setSizes();

    if (this.scrollH) {
        YAHOO.util.Event.addListener(this.bodyContainer, 'scroll', ORBEON.widgets.datatable.scrollHandler, this, true);
        this.width = this.container.clientWidth;
        if (this.tableWidth > this.width) {
            this.bodyContainer.style.overflowX = "scroll";
        }
    } else {
        this.width = this.tableWidth;
    }

    this.initColumns();
    
    // Now that the table has been properly sized, reconsider its
    // "resizeability"

    if (this.hasFixedWidthContainer && this.hasFixedWidthTable) {
        // These are fixed width tables without horizontal scroll bars
        // and as we don't know how to resize their columns properly,
        // we'd better consider that as variable width
        this.hasFixedWidthContainer = false;
        this.hasFixedWidthTable = false;
    }
    YAHOO.log("Datatable index " + this.index + 'created with width: ' + this.width + ', table width: ' + this.tableWidth, "info")

}

ORBEON.widgets.datatable.prototype.setSizes = function () {

    var width = this.originalWidth;
    var pxWidth = this.getActualOriginalTableWidth();
    var containerWidth =this.container.clientWidth;


    // See how big the table would be without its size restriction  (for scrollable tables)
    // To do so, temporarily remove the yui-dt-bd class to the table container so that its header is shown

    //if (this.headBodySplit) {
    //    YAHOO.util.Dom.addClass(this.table.parentNode, 'fr-datatable-offscreen');
    //    YAHOO.util.Dom.removeClass(this.table.parentNode, 'yui-dt-bd');
    //}

    // Remove width restrictions if needed
    //if (this.scrollH) {
    //    if (this.innerTableWidth != null) {
    //        YAHOO.util.Dom.setStyle(this.table, 'width', this.innerTableWidth);
    //    } else {
    //        YAHOO.util.Dom.setStyle(this.table, 'width', 'auto');
    //    }
    //}

    // Remove height restrictions if needed
    //if (this.scrollV) {
    //    YAHOO.util.Dom.setStyle(this.table, 'height', 'auto');
    //}

    // Measure the table width
    this.tableWidth = this.table.clientWidth;
    if (this.tableWidth < pxWidth) {
        this.tableWidth = pxWidth;
    }

    // Measure the table and header heights
    //this.tableHeight = this.table.clientHeight;
    this.headerHeight = this.table.tHead.rows[0].clientHeight;
    this.tableHeight = this.table.clientHeight;

    // Do some magic adjustments
    if (this.scrollH) {
        if (pxWidth > this.tableWidth) {
            // Can be the case if table width was expressed as %
            this.tableWidth = pxWidth;
        }
        if (this.innerTableWidth != null) {
            this.tableWidth = this.table.clientWidth;
        } else {
            var minWidth;
            if (this.scrollV) {
                minWidth = this.tableWidth - 19;
            } else {
                if (YAHOO.env.ua.ie > 0 && YAHOO.env.ua.ie < 8) {
                    minWidth = this.tableWidth - 1;
                } else {
                    minWidth = this.tableWidth;
                }

            }
            this.tableWidth = this.optimizeWidth(minWidth);
        }
    } else if (this.scrollV) {
        if (this.hasFixedWidthTable) {
            width = this.tableWidth + 'px';
            this.tableWidth = this.tableWidth - 19;
        } else {
            width = (this.tableWidth + 19) + 'px';
        }
    } else {
        width = (this.tableWidth + 2) + 'px';
    }

    // At last, we know how the table will be sized, it's time to set these sizes

    YAHOO.util.Dom.setStyle(this.table, 'width', this.tableWidth + 'px');

    this.adjustHeightForIE = this.adjustHeightForIE || (this.scrollH && ! this.scrollV && this.height == 'auto' && YAHOO.env.ua.ie > 0 && YAHOO.env.ua.ie < 8);
    if (this.adjustHeightForIE) {
        this.height = (this.tableHeight + 22) + 'px';
        this.adjustHeightForIE = true;
    }

    // Resize the containers if not already done
{'fraction_non_alphanumeric': 0.12004950495049505, 'fraction_numerical': 0.0038985148514851485, 'mean_word_length': 2.569913850231942, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6033993', 'n_tokens_mistral': 4951, 'n_tokens_neox': 4741, 'n_words': 1192}