|  | @@ -0,0 +1,110 @@
 | 
	
		
			
				|  |  | +// js
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +function Versioner(){
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    this.version_prefix = "v/";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    this.main = ()=>{
 | 
	
		
			
				|  |  | +        this.main_frame = document.getElementById("Versioner_mainframe");
 | 
	
		
			
				|  |  | +        this.selector = document.getElementById("Versioner_selector");
 | 
	
		
			
				|  |  | +        this.data_script = document.createElement("script");
 | 
	
		
			
				|  |  | +        this.data_script.src = "versions.js" + "?js_reload="+this.randomString();
 | 
	
		
			
				|  |  | +        this.data_script.addEventListener("load", this.loadData.bind(this));
 | 
	
		
			
				|  |  | +        document.body.append(this.data_script)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        this.main_frame.addEventListener("load", this.updateMainFrame.bind(this));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        this.selector.addEventListener("change", ((e)=>{
 | 
	
		
			
				|  |  | +            this.version = this.selector.selectedOptions[0].value;
 | 
	
		
			
				|  |  | +            this.updateUri(true);
 | 
	
		
			
				|  |  | +        }).bind(this));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    this.loadData = ()=>{
 | 
	
		
			
				|  |  | +        this.data = VERSIONER_DATA;
 | 
	
		
			
				|  |  | +        console.log(this.data);
 | 
	
		
			
				|  |  | +        this.updateOptions()
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    this.updateMainFrame = (e)=>{
 | 
	
		
			
				|  |  | +        var subp = e.target.contentWindow.location.pathname;
 | 
	
		
			
				|  |  | +        if(subp.search(location.pathname)==0){
 | 
	
		
			
				|  |  | +            var sub_relpath = subp.slice(location.pathname.length);
 | 
	
		
			
				|  |  | +            this.path = sub_relpath.slice(this.version.length);
 | 
	
		
			
				|  |  | +            this.path = this.path.slice(this.version_prefix.length)
 | 
	
		
			
				|  |  | +            this.updateUri(false);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    this.updateUri = (reload)=>{
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        var version = this.getParameterByName("v");
 | 
	
		
			
				|  |  | +        if (this.version){
 | 
	
		
			
				|  |  | +        } else if (version) {
 | 
	
		
			
				|  |  | +            this.version = version;
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            this.version = this.default_version;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        var path = this.getParameterByName("p");
 | 
	
		
			
				|  |  | +        if (!this.path){
 | 
	
		
			
				|  |  | +            this.path = path;
 | 
	
		
			
				|  |  | +        } 
 | 
	
		
			
				|  |  | +        if (!this.path){
 | 
	
		
			
				|  |  | +            this.path = "";
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        var query = "?v="+ this.version +"&p=" + this.path;
 | 
	
		
			
				|  |  | +        window.history.replaceState("","",query);
 | 
	
		
			
				|  |  | +        if(reload){
 | 
	
		
			
				|  |  | +            this.main_frame.src = this.version_prefix + this.version + this.path;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    this.updateOptions = ()=>{
 | 
	
		
			
				|  |  | +        this.data["versions"].forEach((el)=>{
 | 
	
		
			
				|  |  | +            var opt_exists = false;
 | 
	
		
			
				|  |  | +            for (var i = 0; i<this.selector.options.length; i++){
 | 
	
		
			
				|  |  | +                if (el == this.selector.options[i].value){
 | 
	
		
			
				|  |  | +                    opt_exists = true;
 | 
	
		
			
				|  |  | +                    break;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (!opt_exists){
 | 
	
		
			
				|  |  | +                var opt = document.createElement("option");
 | 
	
		
			
				|  |  | +                opt.value = el;
 | 
	
		
			
				|  |  | +                opt.text = el;
 | 
	
		
			
				|  |  | +                this.selector.appendChild(opt);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        })
 | 
	
		
			
				|  |  | +        this.default_version = this.data["versions"][0];
 | 
	
		
			
				|  |  | +        this.updateUri(true);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    this.randomString = ()=>{
 | 
	
		
			
				|  |  | +        return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    // Get URL arguments
 | 
	
		
			
				|  |  | +    this.getParameterByName = (name, url)=>{
 | 
	
		
			
				|  |  | +        if (!url) url = window.location.href;
 | 
	
		
			
				|  |  | +        name = name.replace(/[\[\]]/g, "\\$&");
 | 
	
		
			
				|  |  | +        var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
 | 
	
		
			
				|  |  | +            results = regex.exec(url);
 | 
	
		
			
				|  |  | +        if (!results) return null;
 | 
	
		
			
				|  |  | +        if (!results[2]) return "";
 | 
	
		
			
				|  |  | +        return decodeURIComponent(results[2].replace(/\+/g, " "));
 | 
	
		
			
				|  |  | +    };
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    this.onload = ()=>{
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +    };
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    window.addEventListener("load",()=>{
 | 
	
		
			
				|  |  | +        this.main.apply(this);
 | 
	
		
			
				|  |  | +    })
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +var versioner = new Versioner();
 |