88 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			88 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| 
 | |
| 
 | |
| 
 | |
| const tools = new Map();
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| /**
 | |
|  * This functions imports other js file. I hate this solution, but other didn't work.
 | |
|  * 
 | |
|  * @function
 | |
|  * @name importScript
 | |
|  * @kind function
 | |
|  * @param {any} url
 | |
|  * @returns {void}
 | |
|  */
 | |
| function importScript(url) {
 | |
|     var script = document.createElement("script");  // create a script DOM node
 | |
|     script.src = url;  // set its src to the provided URL
 | |
|     document.head.appendChild(script);
 | |
| }
 | |
| 
 | |
| /**
 | |
|  * Function called after page is loaded
 | |
|  * 
 | |
|  * @function
 | |
|  * @name init
 | |
|  * @kind function
 | |
|  * @returns {void}
 | |
|  */
 | |
| function init() {
 | |
|     importScript("/assets/scripts/dyn_host.js");
 | |
|     
 | |
|     tools.set("xpath", "tools/xpath.html");
 | |
|     tools.set("xsd", "tools/xsd.html");
 | |
|     tools.set("xslt", "tools/xslt.html");
 | |
|     tools.set("xmlform", "tools/xmlFormatter.html");
 | |
|     tools.set("jsonform", "tools/jsonFormatter.html");
 | |
|     tools.set("mock", getMockHost());
 | |
| 
 | |
|     loadLastPage();
 | |
|     changeActiveTools('xmlTool', 'XML');
 | |
| }
 | |
| 
 | |
| /**
 | |
|  * Function that updates list of tools depending on chosen category
 | |
|  * 
 | |
|  * @function
 | |
|  * @name changeActiveTools
 | |
|  * @kind function
 | |
|  * @param {any} activeClass class of elements that have to be shown
 | |
|  * @param {any} activeCategoryButton class of category button that has to be active
 | |
|  */
 | |
| function changeActiveTools(activeClass, activeCategoryButton) {
 | |
|     let tools = document.getElementById("toolList").children
 | |
|     
 | |
|     for (i = 0; i < tools.length; i++) {
 | |
|         if (tools[i].classList.contains(activeClass)) {
 | |
|             tools[i].style.display = "block";
 | |
|         }
 | |
|         else {
 | |
|             tools[i].style.display = "none";
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     let categories = document.getElementById("menu").children
 | |
| 
 | |
|     for (i = 0; i < categories.length; i++) {
 | |
|         if (categories[i].innerText == activeCategoryButton) {
 | |
|             categories[i].classList.add("active")
 | |
|         }
 | |
|         else {
 | |
|             categories[i].classList.remove("active")
 | |
|         }
 | |
|     }
 | |
| }
 | |
| 
 | |
| function changeTool(tool) {
 | |
|     const url = tools.get(tool);
 | |
|     localStorage.setItem("lastPage", tool);
 | |
|     document.getElementById("iframe").src = tools.get(lastPage);
 | |
| }
 | |
| 
 | |
| function loadLastPage() {
 | |
|     const lastPage = localStorage.getItem("lastPage");
 | |
|     document.getElementById("iframe").src = tools.get(lastPage);
 | |
| } |