<commit_before>
"use strict";

// Base function.
var bqPolyloader = function(options) {

    this.document = window.document || {};
    this.supportWc = this._wcSupport();
    this.urls = {};
    this.urls.wclibrary = options.wclibraryurl || '';
    this.currentPage = 'main';
    this.pages = options.pages || [];
    this._firstLoad = true;
    this.coreComponents = options.coreComponents || [];


    // Sort pages by priority
    this._sortByPriority();

    // load webcomponents if necessary
    if (this.suppportWc === false) {
        this._loadWC();
        console.log('%c Oh my heavens! Your browser needs polyfills ', 'background: #222; color: #bada55');
    } else {
        console.log('%c Polyloader || Yeahh running Webcomponents native ', 'background: #444; color: #bada55');
        this._lazyLoadPolymerAndElements();
    }
};

//
// Check WebComponents support method.
//
bqPolyloader.prototype._wcSupport = function() {

    var document = this.document;

    return ('registerElement' in document && 'import' in document.createElement('link') && 'content' in document.createElement('template'));
};
//
// Load WebComponents library if wc is not supported.
//
bqPolyloader.prototype._loadWC = function() {

    var wcPoly = this.document.createElement('script');
    wcPoly.src = this.urls.wclibrary;
    wcPoly.onload = this._lazyLoadPolymerAndElements();
    this.document.head.appendChild(wcPoly);
};
//
// Lazy loader elements
//
bqPolyloader.prototype._lazyLoadPolymerAndElements = function() {
    
    var self = this;

    if(this.supportWc && this._firstLoad){
        // Let's use Shadow DOM if we have it, because awesome.
        window.Polymer = window.Polymer || {};
        window.Polymer.dom = 'shadow';
        self._firstLoad = false;
    }

    this.coreComponents.forEach(function(elementURL) {

        var elImport = self.document.createElement('link');
        elImport.rel = 'import';
        elImport.href = elementURL;

        self.document.head.appendChild(elImport);

    });
};
//
// Load Pages Elements method
//
bqPolyloader.prototype._loadPagesElements = function() {
    
    var self = this;

    for(var kk = 0; kk < this.pagesSortedByPriority.length; kk++){
        for (var i = this.pagesSortedByPriority[kk][1].elements.length - 1; i >= 0; i--) {
            
            var elImport = self.document.createElement('link');
            elImport.rel = 'import';
            elImport.href = this.pagesSortedByPriority[kk][1].elements[i];

            self.document.head.appendChild(elImport);
        }
    }
};
//
//  Page changer method.
//
bqPolyloader.prototype.loadPage = function(pageId){<commit_msg>fix bug with initial loading<commit_after>
"use strict";

// Base function.
var bqPolyloader = function(options) {

    this.supportWc = this._wcSupport();
    this.urls = {};
    this.urls.wclibrary = options.wclibraryurl || '';
    this.currentPage = 'main';
    this.pages = options.pages || [];
    this._firstLoad = true;
    this.coreComponents = options.coreComponents || [];


    // Sort pages by priority
    this._sortByPriority();

    // load webcomponents if necessary
    if (this.supportWc === false) {
        this._loadWC();
        console.log('%c Oh my heavens! Your browser needs polyfills ', 'background: #222; color: #bada55');
    } else {
        console.log('%c Polyloader || Yeahh running Webcomponents native ', 'background: #444; color: #bada55');
        this._lazyLoadPolymerAndElements();
    }
};

//
// Check WebComponents support method.
//
bqPolyloader.prototype._wcSupport = function() {

    return ('registerElement' in document && 'import' in document.createElement('link') && 'content' in document.createElement('template'));
};
//
// Load WebComponents library if wc is not supported.
//
bqPolyloader.prototype._loadWC = function() {

    var wcPoly = document.createElement('script');
    wcPoly.src = this.urls.wclibrary;
    wcPoly.onload = this._lazyLoadPolymerAndElements();
    document.getElementsByTagName('head')[0].appendChild(wcPoly);
};
//
// Lazy loader elements
//
bqPolyloader.prototype._lazyLoadPolymerAndElements = function() {
    
    var self = this;

    // Let's use Shadow DOM if we have it, because awesome.
    window.Polymer = window.Polymer || {};

    // default shady-dom
    if(this.supportWc){
        window.Polymer.dom = 'shadow';
    }
    
    this.coreComponents.forEach(function(elementURL) {

        var elImport = self.document.createElement('link');
        elImport.rel = 'import';
        elImport.href = elementURL;

        self.document.head.appendChild(elImport);

    });
   
};
//
// Load Pages Elements method
//
bqPolyloader.prototype._loadPagesElements = function() {
    
    var self = this;

    for(var kk = 0; kk < this.pagesSortedByPriority.length; kk++){
        for (var i = this.pagesSortedByPriority[kk][1].elements.length - 1; i >= 0; i--) {
            
            var elImport = self.document.createElement('link');
            elImport.rel = 'import';
            elImport.href = this.pagesSortedByPriority[kk][1].elements[i];

            self.document.head.appendChild(elImport);
        }
    }
};
//
//  Page changer method.
//
bqPolyloader.prototype.loadPage = function(pageId){
{'fraction_non_alphanumeric': 0.14038424957199924, 'fraction_numerical': 0.005896899372265551, 'mean_word_length': 2.877581120943953, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1912218', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1576, 'n_words': 333}