<commit_before>/*======================================================================
 *  Exhibit.ViewPanel
 *  http://simile.mit.edu/wiki/Exhibit/API/ViewPanel
 *======================================================================
 */
Exhibit.ViewPanel = function(div, uiContext) {
    this._uiContext = uiContext;
    this._div = div;
    
    this._viewConstructors = [];
    this._viewConfigs = [];
    this._viewLabels = [];
    this._viewTooltips = [];
    this._viewDomConfigs = [];
    
    this._viewIndex = 0;
    this._view = null;
}

Exhibit.ViewPanel.create = function(configuration, div, uiContext) {
    var viewPanel = new Exhibit.ViewPanel(div, uiContext);
    
    if ("views" in configuration) {
        for (var i = 0; i < configuration.views.length; i++) {
            var viewConfig = configuration.views[i];
            
            var viewClass = ("viewClass" in view) ? view.viewClass : Exhibit.TileView;
            
            var label = null;
            if ("label" in viewConfig) {
                label = viewConfig.label;
            } else if ("l10n" in viewClass && "viewLabel" in viewClass.l10n) {
                label = viewClass.l10n.viewLabel;
            } else {
                label = "" + viewClass;
            }
            
            var tooltip = null;
            if ("tooltip" in viewConfig) {
                tooltip = viewConfig.tooltip;
            } else if ("l10n" in viewClass && "viewTooltip" in viewClass.l10n) {
                tooltip = viewClass.l10n.viewTooltip;
            } else {
                tooltip = label;
            }
                
            viewPanel._viewConstructors.push(viewClass);
            viewPanel._viewConfigs.push(viewConfig);
            viewPanel._viewLabels.push(label);
            viewPanel._viewTooltips.push(tooltip);
            viewPanel._viewDomConfigs.push(null);
        }
    }
    
    if ("initialView" in configuration) {
        viewPanel._viewIndex = configuration.initialView;
    }
    
    viewPanel._internalValidate();
    viewPanel._initializeUI();
    
    return viewPanel;
};

Exhibit.ViewPanel.createFromDOM = function(div, uiContext) {
    var viewPanel = new Exhibit.ViewPanel(div, uiContext);
    
    var node = div.firstChild;
    while (node != null) {
        if (node.nodeType == 1) {
            node.style.display = "none";
            
            var role = Exhibit.getRoleAttribute(node);
            if (role == "view") {
                var viewClass = Exhibit.TileView;
                
                var viewClassString = Exhibit.getAttribute(node, "viewClass");
                if (viewClassString != null && viewClassString.length > 0) {
                    viewClass = Exhibit.UI.viewClassNameToViewClass(viewClassString);
                    if (viewClass == null) {
                        SimileAjax.Debug.warn("Unknown viewClass " + viewClassString);
                    }
                }
                
                var label = Exhibit.getAttribute(node, "label");
                var tooltip = Exhibit.getAttribute(node, "title");
                
                if (label == null) {
                    if ("viewLabel" in viewClass.l10n) {
                        label = viewClass.l10n.viewLabel;
                    } else {
                        label = "" + viewClass;
                    }
                }
                if (tooltip == null) {
                    if ("l10n" in viewClass && "viewTooltip" in viewClass.l10n) {
                        tooltip = viewClass.l10n.viewTooltip;
                    } else {
                        tooltip = label;
                    }
                }
                
                viewPanel._viewConstructors.push(viewClass);
                viewPanel._viewConfigs.push(null);
                viewPanel._viewLabels.push(label);
                viewPanel._viewTooltips.push(tooltip);
                viewPanel._viewDomConfigs.push(node);
            }
        }
        node = node.nextSibling;
    }
    Exhibit.UIContext.registerLensesFromDOM(div, viewPanel._uiContext.getLensRegistry());
    
    var initialView = Exhibit.getAttribute(div, "initialView");
    if (initialView != null) {
        try {
            viewPanel._viewIndex = parseInt(initialView);
        } catch (e) {
        }
        
    }
    
    viewPanel._internalValidate();
    viewPanel._initializeUI();
    
    return viewPanel;<commit_msg>Fixed bug in parsing initial view index.<commit_after>/*======================================================================
 *  Exhibit.ViewPanel
 *  http://simile.mit.edu/wiki/Exhibit/API/ViewPanel
 *======================================================================
 */
Exhibit.ViewPanel = function(div, uiContext) {
    this._uiContext = uiContext;
    this._div = div;
    
    this._viewConstructors = [];
    this._viewConfigs = [];
    this._viewLabels = [];
    this._viewTooltips = [];
    this._viewDomConfigs = [];
    
    this._viewIndex = 0;
    this._view = null;
}

Exhibit.ViewPanel.create = function(configuration, div, uiContext) {
    var viewPanel = new Exhibit.ViewPanel(div, uiContext);
    
    if ("views" in configuration) {
        for (var i = 0; i < configuration.views.length; i++) {
            var viewConfig = configuration.views[i];
            
            var viewClass = ("viewClass" in view) ? view.viewClass : Exhibit.TileView;
            
            var label = null;
            if ("label" in viewConfig) {
                label = viewConfig.label;
            } else if ("l10n" in viewClass && "viewLabel" in viewClass.l10n) {
                label = viewClass.l10n.viewLabel;
            } else {
                label = "" + viewClass;
            }
            
            var tooltip = null;
            if ("tooltip" in viewConfig) {
                tooltip = viewConfig.tooltip;
            } else if ("l10n" in viewClass && "viewTooltip" in viewClass.l10n) {
                tooltip = viewClass.l10n.viewTooltip;
            } else {
                tooltip = label;
            }
                
            viewPanel._viewConstructors.push(viewClass);
            viewPanel._viewConfigs.push(viewConfig);
            viewPanel._viewLabels.push(label);
            viewPanel._viewTooltips.push(tooltip);
            viewPanel._viewDomConfigs.push(null);
        }
    }
    
    if ("initialView" in configuration) {
        viewPanel._viewIndex = configuration.initialView;
    }
    
    viewPanel._internalValidate();
    viewPanel._initializeUI();
    
    return viewPanel;
};

Exhibit.ViewPanel.createFromDOM = function(div, uiContext) {
    var viewPanel = new Exhibit.ViewPanel(div, uiContext);
    
    var node = div.firstChild;
    while (node != null) {
        if (node.nodeType == 1) {
            node.style.display = "none";
            
            var role = Exhibit.getRoleAttribute(node);
            if (role == "view") {
                var viewClass = Exhibit.TileView;
                
                var viewClassString = Exhibit.getAttribute(node, "viewClass");
                if (viewClassString != null && viewClassString.length > 0) {
                    viewClass = Exhibit.UI.viewClassNameToViewClass(viewClassString);
                    if (viewClass == null) {
                        SimileAjax.Debug.warn("Unknown viewClass " + viewClassString);
                    }
                }
                
                var label = Exhibit.getAttribute(node, "label");
                var tooltip = Exhibit.getAttribute(node, "title");
                
                if (label == null) {
                    if ("viewLabel" in viewClass.l10n) {
                        label = viewClass.l10n.viewLabel;
                    } else {
                        label = "" + viewClass;
                    }
                }
                if (tooltip == null) {
                    if ("l10n" in viewClass && "viewTooltip" in viewClass.l10n) {
                        tooltip = viewClass.l10n.viewTooltip;
                    } else {
                        tooltip = label;
                    }
                }
                
                viewPanel._viewConstructors.push(viewClass);
                viewPanel._viewConfigs.push(null);
                viewPanel._viewLabels.push(label);
                viewPanel._viewTooltips.push(tooltip);
                viewPanel._viewDomConfigs.push(node);
            }
        }
        node = node.nextSibling;
    }
    Exhibit.UIContext.registerLensesFromDOM(div, viewPanel._uiContext.getLensRegistry());
    
    var initialView = Exhibit.getAttribute(div, "initialView");
    if (initialView != null && initialView.length > 0) {
        try {
            var n = parseInt(initialView);
            if (!isNaN(n)) {
                viewPanel._viewIndex = n;
            }
        } catch (e) {
        }
    }
    
    viewPanel._internalValidate();
    viewPanel._initializeUI();
    
    return viewPanel;
{'fraction_non_alphanumeric': 0.13171923589515772, 'fraction_numerical': 0.005886272767658818, 'mean_word_length': 1.5846727898966706, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '2003423', 'n_tokens_mistral': 2447, 'n_tokens_neox': 2312, 'n_words': 438}