### JavaScript Document Ready Handler and Page Routing Source: https://github.com/turanar/stellaris-tech-tree/blob/master/index.html Executes code once the DOM is fully loaded. It checks for URL search parameters to determine if a specific route should be loaded immediately, enabling direct linking to specific tech tree versions. It also initializes a global `window.routes` array, defining a list of available Stellaris tech tree versions with their names, routes, and titles for navigation. ```javascript $(document).ready(function(){ if (window.location.search) { const page = window.routes.find(r => r.route === window.location.search.slice(1)); if (page) { load_page(page.route, page.title); } } }); window.routes = [ { name: 'Orion 3.6.0', route: 'orion-3.6.0', title: 'Stellaris 3.6.0 (Orion)' }, { name: 'Fornax 3.5.3', route: 'vanilla', title: 'Stellaris 3.5.3 (Fornax)' }, { name: 'Cepheus 3.4.3', route: 'cepheus-3.4.3', title: 'Stellaris 3.4.3 (Cepheus)' }, { name: 'Herbert 3.2.2', route: 'herbert-3.2.2', title: 'Stellaris 3.2.2 (Herbert)' }, { name: 'Lem 3.1.1', route: 'lem-3.1.1', title: 'Stellaris 3.1.1 (Lem)' }, { name: 'Stellaris 3.0.1', route: 'dick-3.0.1', title: 'Stellaris 3.0.1 (Dick)' }, { name: 'Stellaris 2.7.1', route: 'wells-2.7.1', title: 'Stellaris 2.7.1 (Wells)' }, { name: 'Stellaris 2.6.0', route: 'verne-2.6.0', title: 'Stellaris 2.6.0 (Verne)' }, { name: 'Stellaris 2.5.0', route: 'shelley-2.5.0', title: 'Stellaris 2.5.0 (Shelley)' }, { name: 'Stellaris 2.3.3', route: 'wolfe-2.3.3', title: 'Stellaris 2.3.3 (Wolfe)' }, { name: 'Stellaris 2.3.0', route: 'wolfe-2.3.0', title: 'Stellaris 2.3.0 (Wolfe)' } ]; ``` -------------------------------- ### Initialize Dynamic Stellaris Version Navigation Source: https://github.com/turanar/stellaris-tech-tree/blob/master/index.html This JavaScript code defines an array of Stellaris game versions, each with a display name, internal route, and page title. Upon document readiness, it dynamically generates navigation list items from this array. Clicking on a list item triggers the `load_page` function, passing the associated route and title to load the respective content. ```javascript const routes = [ { name: 'Stellaris 2.2.7', route: 'leguin-2.2.7', title: 'Stellaris 2.2.7 (Leguin)' }, { name: 'Stellaris 2.2.4', route: 'leguin-2.2.4', title: 'Stellaris 2.2.4 (Leguin)' }, { name: 'Stellaris 2.2.3', route: 'leguin-2.2.3', title: 'Stellaris 2.2.3 (Leguin)' }, { name: 'Stellaris 2.2.0', route: 'leguin-2.2.0', title: 'Stellaris 2.2.0 (Leguin)' } ]; $(document).ready(function(){ routes.forEach(page => { const ele = $("
  • " + page.name + "
  • "); ele.on("click", function() { load_page(page.route, page.title); }); $('#tech-pages').append(ele); }); }); ``` -------------------------------- ### jQuery Data Loading and Template Rendering for UI Source: https://github.com/turanar/stellaris-tech-tree/blob/master/jobs/index.html JavaScript code using jQuery to fetch JSON data from 'jobs.json', iterate through it, render each item using a JsRender template (`#node-template`), and append the generated HTML to the `.job-tree` container. It also includes a regex replacement for custom icon placeholders. ```JavaScript $(document).ready(function() { $.getJSON('jobs.json', function(jsonData) { $(jsonData).each(function(e, item) { var tmpl = $.templates("#node-template"); var html = tmpl.render(item); html = html.replace(new RegExp(/£(\w+)£/,'g'), ''); $(".job-tree").append(html); }) }); }); ``` -------------------------------- ### Stellaris Dynamic Node HTML Template Source: https://github.com/turanar/stellaris-tech-tree/blob/master/jobs/index.html Provides the HTML structure for a reusable 'node' component, likely used to display game entities like jobs or technologies. It includes placeholders (`{{:name}}`, `{{:effect}}`, etc.) for data binding, suggesting a templating engine like JsRender is in use. ```HTML
    {{:name}}
    {{:effect}}
    {{:description}}
    ``` -------------------------------- ### HTML Template for Stellaris Tech Node Display Source: https://github.com/turanar/stellaris-tech-tree/blob/master/index.html A comprehensive HTML template using a templating engine (likely JsRender or similar) to display detailed information about a Stellaris tech node. It includes dynamic content for node name, tier, cost, weight, and specific empire type compatibility (gestalt, machine, hive, megacorp), along with sections for description, weight modifiers, requirements, prerequisites, and research effects. ```html

    {{:name}}

    {{if tier < 1}} {{:category}} - Starting {{else}} {{:category}} - Tier {{:tier}} {{/if}}

    {{if tier > 0}} Cost: {{:cost}}, Weight: {{:base_weight}} {{/if}}

    {{if is_gestalt === true}} {{/if}} {{if is_gestalt === false}} {{/if}} {{if is_machine_empire === true}} {{/if}} {{if is_machine_empire === false}} {{if is_drive_assimilator === true}} {{/if}} {{if is_rogue_servitor === true}} {{/if}} {{/if}} {{if is_hive_empire === true}} {{/if}} {{if is_hive_empire === false}} {{/if}} {{if is_megacorp === true}} {{/if}} {{if is_megacorp === false}} {{/if}}

    Description
    {{:description}}
    {{if weight_modifiers.length > 0}}
    Weight Modifiers
    {{:weight_modifiers.join('
    ')}}
    {{/if}} {{if potential.length > 0}}
    Requirements
    {{:potential.join('
    ')}}
    {{/if}} {{if prerequisites.length > 1}}
    Required Technologies
    {{for prerequisites}} {{/for}}
    {{for prerequisites_names}} {{:name}}
    {{/for}}
    {{/if}} {{if feature_unlocks.length > 0}}
    Research Effects
    {{:feature_unlocks.join('
    ')}}
    {{/if}}
    ``` -------------------------------- ### JavaScript Function to Load Dynamic Page Content Source: https://github.com/turanar/stellaris-tech-tree/blob/master/index.html Defines a JavaScript function `load_page` that dynamically updates the browser's history, sets the document title, loads a CSS file, and then loads an HTML body, subsequently injecting multiple JavaScript files. This function is central to the single-page application-like navigation, allowing different tech tree versions to be displayed without full page refreshes. ```javascript const load_page = (param, title) => { history.pushState({pageID: param}, param, `${param}/`); document.title = title || param; $('').appendTo('head').attr({ type: 'text/css', rel: 'stylesheet', href: '../assets/css/tech-tree.css' }); $('body').load('../assets/html/body.html', function() { $('