<commit_before>/**
*  Copyright (C) 2009 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 (element, index) {
    
    YAHOO.log("Creating datatable index " + index, "info")
    // Store useful stuff as properties
    this.table = element;
    this.header = this.table;
    this.headerColumns = this.header.tHead.rows[0].cells;
    this.bodyRows = this.table.tBodies[0].rows;
    this.bodyColumns = this.table.tBodies[0].rows[2].cells;
    var plainId = this.table.id;
    this.id = plainId.substring(0, plainId.length - '-table'.length);
    this.height = ORBEON.widgets.datatable.utils.getStyle(this.table, 'height', 'auto');
    this.scrollV = YAHOO.util.Dom.hasClass(this.table, 'fr-scrollV');
    this.scrollH = YAHOO.util.Dom.hasClass(this.table, 'fr-scrollH');
    this.scroll = this.scrollV || this.scrollH;
    this.headBodySplit = this.scroll;
    var width = ORBEON.widgets.datatable.utils.getStyle(this.table, 'width', 'auto');
    this.hasFixedWidthContainer = width != 'auto';
    this.hasFixedWidthTable = this.hasFixedWidthContainer && ! this.scrollH;
    
    this.restructure();
    
    this.resize();
    
    this.createColResizers();
     

    // 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;
    }
        
}

ORBEON.widgets.datatable.prototype.restructure = function () {
	// Create a global container
    this.container = document.createElement('div');
    YAHOO.util.Dom.addClass(this.container, 'yui-dt');
    YAHOO.util.Dom.addClass(this.container, 'yui-dt-scrollable');
    
    // Create a container for the header (or the whole table if there is no scrolling)
    this.headerContainer = document.createElement('div');
    YAHOO.util.Dom.addClass(this.headerContainer, 'yui-dt-hd');
    
    // Assemble all that stuff
    this.table.parentNode.replaceChild(this.container, this.table);
    this.container.appendChild(this.headerContainer);
    this.headerContainer.appendChild(this.header);
}

ORBEON.widgets.datatable.prototype.resize = function () {
	
    var width = ORBEON.widgets.datatable.utils.getStyle(this.table, 'width', 'auto');
    var pxWidth = this.table.clientWidth;
    if (width.equals != 'auto') {
        // Convert % and other units into px...
        width = pxWidth + 'px';
    }

    // See how big the table would be without its size restriction
    if (this.scrollH) {
        YAHOO.util.Dom.setStyle(this.table, 'width', 'auto');
    }
    if (this.scrollV) {
        YAHOO.util.Dom.setStyle(this.table, 'height', 'auto');
    }
    
    this.tableWidth = this.table.clientWidth;
    this.tableHeight = this.table.clientHeight;
    if (this.scrollH) {
        if (pxWidth > this.tableWidth) {
            // Can be the case if table width was expressed as %
            this.tableWidth = pxWidth;
        }
        this.tableWidth = this.optimizeWidth(this.table.clientWidth, this.table.clientHeight, 2500, this.getTableHeightForWidth(2500)) + 50;
    } 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 + 'px';
    }
    YAHOO.util.Dom.setStyle(this.table, 'width', this.tableWidth + 'px');
    
    if (this.scrollH && ! this.scrollV && this.height == 'auto' && YAHOO.env.ua.ie > 0) {
        this.height = (this.tableHeight + 22) + 'px';
    }
    
    this.thead = YAHOO.util.Selector.query('thead', this.table, true);
    this.tbody = YAHOO.util.Selector.query('tbody', this.table, true);
    
    // Resize the container
    YAHOO.util.Dom.setStyle(this.container, 'width', width);
    if (this.height != 'auto') {
        YAHOO.util.Dom.setStyle(this.container, 'height', this.height);
    }
    
    // Resize the header container
    YAHOO.util.Dom.setStyle(this.headerContainer, 'width', width);
    if (this.height != 'auto' && this.headBodySplit) {
        YAHOO.util.Dom.setStyle(this.headerContainer, 'height', this.thead.clientHeight + 'px');
    } else if (! this.headBodySplit && this.height == 'auto') {
        YAHOO.util.Dom.setStyle(this.headerContainer, 'border', '1px solid #7F7F7F')
    }
    
    if (this.headBodySplit) {
        
        // Create a container for the body
        this.bodyContainer = document.createElement('div');
        YAHOO.util.Dom.setStyle(this.bodyContainer, 'width', width);
        YAHOO.util.Dom.addClass(this.bodyContainer, 'yui-dt-bd');
        
        // Duplicate the table to populate the body
        
        this.table = this.header.cloneNode(true);
        ORBEON.widgets.datatable.removeIdAttributes(this.table);
        
        // Move the tbody elements to keep event handler bindings in the visible tbody
        var tBody = YAHOO.util.Selector.query('tbody', this.header, true);
        this.header.removeChild(tBody);
        this.table.replaceChild(tBody, YAHOO.util.Selector.query('tbody', this.table, true));
        
        
        
        // Do more resizing
        if (this.height != 'auto') {
            YAHOO.util.Dom.setStyle(this.bodyContainer, 'height', (this.container.clientHeight - this.thead.clientHeight - 5) + 'px');
        }
        
        // And more assembly
        this.container.appendChild(this.bodyContainer);<commit_msg>Backporting the IE layout bug to the new version of the datatable.<commit_after>/**
*  Copyright (C) 2009 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 (element, index) {
    
    YAHOO.log("Creating datatable index " + index, "info")
    // Store useful stuff as properties
    this.table = element;
    this.header = this.table;
    this.headerColumns = this.header.tHead.rows[0].cells;
    this.bodyRows = this.table.tBodies[0].rows;
    this.bodyColumns = this.table.tBodies[0].rows[2].cells;
    var plainId = this.table.id;
    this.id = plainId.substring(0, plainId.length - '-table'.length);
    this.height = ORBEON.widgets.datatable.utils.getStyle(this.table, 'height', 'auto');
    this.scrollV = YAHOO.util.Dom.hasClass(this.table, 'fr-scrollV');
    this.scrollH = YAHOO.util.Dom.hasClass(this.table, 'fr-scrollH');
    this.scroll = this.scrollV || this.scrollH;
    this.headBodySplit = this.scroll;
    var width = ORBEON.widgets.datatable.utils.getStyle(this.table, 'width', 'auto');
    this.hasFixedWidthContainer = width != 'auto';
    this.hasFixedWidthTable = this.hasFixedWidthContainer && ! this.scrollH;
    
    this.restructure();
    
    this.resize();
    
    this.createColResizers();
     

    // 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;
    }
        
}

ORBEON.widgets.datatable.prototype.restructure = function () {
	// Create a global container
    this.container = document.createElement('div');
    YAHOO.util.Dom.addClass(this.container, 'yui-dt');
    YAHOO.util.Dom.addClass(this.container, 'yui-dt-scrollable');
    
    // Create a container for the header (or the whole table if there is no scrolling)
    this.headerContainer = document.createElement('div');
    YAHOO.util.Dom.addClass(this.headerContainer, 'yui-dt-hd');
    
    // Assemble all that stuff
    this.table.parentNode.replaceChild(this.container, this.table);
    this.container.appendChild(this.headerContainer);
    this.headerContainer.appendChild(this.header);
}

ORBEON.widgets.datatable.prototype.resize = function () {
	
    var width = ORBEON.widgets.datatable.utils.getStyle(this.table, 'width', 'auto');
    var pxWidth = this.table.clientWidth;
    if (width.equals != 'auto') {
        // Convert % and other units into px...
        width = pxWidth + 'px';
    }

    // See how big the table would be without its size restriction
    if (this.scrollH) {
        YAHOO.util.Dom.setStyle(this.table, 'width', 'auto');
    }
    if (this.scrollV) {
        YAHOO.util.Dom.setStyle(this.table, 'height', 'auto');
    }
    
    this.tableWidth = this.table.clientWidth;
    this.tableHeight = this.table.clientHeight;
    if (this.scrollH) {
        if (pxWidth > this.tableWidth) {
            // Can be the case if table width was expressed as %
            this.tableWidth = pxWidth;
        }
        this.tableWidth = this.optimizeWidth(this.table.clientWidth, this.table.clientHeight, 2500, this.getTableHeightForWidth(2500)) + 50;
    } 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 + 'px';
    }
    YAHOO.util.Dom.setStyle(this.table, 'width', this.tableWidth + 'px');
    
    if (this.scrollH && ! this.scrollV && this.height == 'auto' && YAHOO.env.ua.ie > 0) {
        this.height = (this.tableHeight + 22) + 'px';
    }
    
    this.thead = YAHOO.util.Selector.query('thead', this.table, true);
    this.tbody = YAHOO.util.Selector.query('tbody', this.table, true);
    
    // Resize the container
    YAHOO.util.Dom.setStyle(this.container, 'width', width);
    if (this.height != 'auto') {
        YAHOO.util.Dom.setStyle(this.container, 'height', this.height);
    }
    
    // Resize the header container
    YAHOO.util.Dom.setStyle(this.headerContainer, 'width', width);
    if (this.height != 'auto' && this.headBodySplit) {
        YAHOO.util.Dom.setStyle(this.headerContainer, 'height', this.thead.rows[0].clientHeight + 'px');
    } else if (! this.headBodySplit && this.height == 'auto') {
        YAHOO.util.Dom.setStyle(this.headerContainer, 'border', '1px solid #7F7F7F')
    }
    
    if (this.headBodySplit) {
        
        // Create a container for the body
        this.bodyContainer = document.createElement('div');
        YAHOO.util.Dom.setStyle(this.bodyContainer, 'width', width);
        YAHOO.util.Dom.addClass(this.bodyContainer, 'yui-dt-bd');
        
        // Duplicate the table to populate the body
        
        this.table = this.header.cloneNode(true);
        ORBEON.widgets.datatable.removeIdAttributes(this.table);
        
        // Move the tbody elements to keep event handler bindings in the visible tbody
        var tBody = YAHOO.util.Selector.query('tbody', this.header, true);
        this.header.removeChild(tBody);
        this.table.replaceChild(tBody, YAHOO.util.Selector.query('tbody', this.table, true));
        
        
        
        // Do more resizing
        if (this.height != 'auto') {
            YAHOO.util.Dom.setStyle(this.bodyContainer, 'height', (this.container.clientHeight - this.thead.rows[0].clientHeight - 5) + 'px');
        }
        
        // And more assembly
        this.container.appendChild(this.bodyContainer);
{'fraction_non_alphanumeric': 0.12436115843270869, 'fraction_numerical': 0.005036663950818458, 'mean_word_length': 2.802309208673613, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6271844', 'n_tokens_mistral': 4199, 'n_tokens_neox': 4054, 'n_words': 1018}