|
| 1 | +// ===================================================== |
| 2 | +// Additional Platforms Quick Start Module |
| 3 | +// ===================================================== |
| 4 | + |
| 5 | +// Platform data loaded from JSON files (generated by gen_additional_platforms.py) |
| 6 | +var ecosystemPlatformData = {{ platformData }}; |
| 7 | + |
| 8 | +// HTML content loaded from _get_started/additional_platforms/ directory |
| 9 | +// (pre-converted by Python script with syntax highlighting) |
| 10 | +var ecosystemHtmlContent = {{ markdownContent }}; |
| 11 | + |
| 12 | +// Get platform IDs from loaded data |
| 13 | +var ecosystemPlatformIds = Object.keys(ecosystemPlatformData); |
| 14 | + |
| 15 | +// Ecosystem platform selections - simplified (no pm, no version) |
| 16 | +var ecosystemOpts = { |
| 17 | + build: 'stable', |
| 18 | + os: 'linux', |
| 19 | + platform: null |
| 20 | +}; |
| 21 | + |
| 22 | +// Initialize additional platforms when document is ready |
| 23 | +$(function() { |
| 24 | + initPlatformContentContainer(); |
| 25 | + initAdditionalPlatforms(); |
| 26 | + initAdditionalPlatformButtons(); |
| 27 | + updatePlatformButtonStates(); |
| 28 | + updateBuildButtonStates(); |
| 29 | + syncComputePlatformHeight(); |
| 30 | + initPlatformContentDisplay(); |
| 31 | +}); |
| 32 | + |
| 33 | +// Initialize platform content container - dynamically create divs for each platform |
| 34 | +function initPlatformContentContainer() { |
| 35 | + var container = $('#additional-platforms-installation'); |
| 36 | + if (!container.length) return; |
| 37 | + |
| 38 | + // Clear any existing static content |
| 39 | + container.empty(); |
| 40 | + |
| 41 | + // Create platform content divs dynamically based on HTML content |
| 42 | + ecosystemPlatformIds.forEach(function(platformId) { |
| 43 | + if (ecosystemHtmlContent[platformId]) { |
| 44 | + var contentDiv = $('<div class="platform-content ' + platformId + '"></div>'); |
| 45 | + // HTML content is already pre-converted with syntax highlighting |
| 46 | + contentDiv.html(ecosystemHtmlContent[platformId]); |
| 47 | + container.append(contentDiv); |
| 48 | + } |
| 49 | + }); |
| 50 | +} |
| 51 | + |
| 52 | +// Note: Markdown is pre-converted to HTML by Python script (gen_additional_platforms.py) |
| 53 | +// using markdown library with codehilite extension for syntax highlighting. |
| 54 | +// No need for client-side markdown parsing. |
| 55 | + |
| 56 | +// Initialize platform content display - hide all initially |
| 57 | +function initPlatformContentDisplay() { |
| 58 | + $('#additional-platforms-installation .platform-content').hide(); |
| 59 | +} |
| 60 | + |
| 61 | +// Sync left heading height with right compute platform buttons height |
| 62 | +function syncComputePlatformHeight() { |
| 63 | + var rightHeight = $('.compute-platform').outerHeight(); |
| 64 | + if (rightHeight > 0) { |
| 65 | + $('.compute-platform-heading').css('min-height', rightHeight + 'px'); |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +// Populate compute platform buttons |
| 70 | +function initAdditionalPlatformButtons() { |
| 71 | + var platformRow = $('.compute-platform'); |
| 72 | + if (!platformRow.length) return; |
| 73 | + |
| 74 | + // Generate platform buttons |
| 75 | + ecosystemPlatformIds.forEach(function(platformId) { |
| 76 | + var platform = ecosystemPlatformData[platformId]; |
| 77 | + if (!platform) return; |
| 78 | + var displayName = platform.name; |
| 79 | + var btn = $('<div class="col-md-3 option block" id="' + platformId + '"><div class="option-text">' + displayName + '</div></div>'); |
| 80 | + platformRow.append(btn); |
| 81 | + }); |
| 82 | + |
| 83 | + // Sync height after buttons are generated |
| 84 | + syncComputePlatformHeight(); |
| 85 | + |
| 86 | + // Bind platform button click |
| 87 | + $('.compute-platform > .option').on('click', function() { |
| 88 | + var platformId = this.id; |
| 89 | + var platform = ecosystemPlatformData[platformId]; |
| 90 | + if (!platform) return; |
| 91 | + |
| 92 | + // Check if supported on current OS |
| 93 | + var supportedOS = getSupportedOS(platformId); |
| 94 | + if (!supportedOS.includes(ecosystemOpts.os)) { |
| 95 | + $('#command').html('<i>' + platform.name + ' is not supported on ' + ecosystemOpts.os + '</i>'); |
| 96 | + return; |
| 97 | + } |
| 98 | + |
| 99 | + // Select this platform |
| 100 | + $('.compute-platform > .option').removeClass('selected'); |
| 101 | + $(this).addClass('selected'); |
| 102 | + ecosystemOpts.platform = platformId; |
| 103 | + |
| 104 | + updateBuildButtonStates(); |
| 105 | + updateEcosystemCommand(); |
| 106 | + updatePlatformContentDisplay(); |
| 107 | + }); |
| 108 | +} |
| 109 | + |
| 110 | +// Get supported OS list from platform data structure |
| 111 | +function getSupportedOS(platformId) { |
| 112 | + var platform = ecosystemPlatformData[platformId]; |
| 113 | + if (!platform) return []; |
| 114 | + |
| 115 | + var osSet = new Set(); |
| 116 | + ['stable', 'preview'].forEach(function(build) { |
| 117 | + if (platform[build]) { |
| 118 | + Object.keys(platform[build]).forEach(function(os) { |
| 119 | + osSet.add(os); |
| 120 | + }); |
| 121 | + } |
| 122 | + }); |
| 123 | + return Array.from(osSet); |
| 124 | +} |
| 125 | + |
| 126 | +// Get supported build list for a platform |
| 127 | +function getSupportedBuilds(platformId) { |
| 128 | + var platform = ecosystemPlatformData[platformId]; |
| 129 | + if (!platform) return []; |
| 130 | + var builds = []; |
| 131 | + if (platform.stable) builds.push('stable'); |
| 132 | + if (platform.preview) builds.push('preview'); |
| 133 | + return builds; |
| 134 | +} |
| 135 | + |
| 136 | +// Update platform button states (disabled/enabled) based on OS |
| 137 | +function updatePlatformButtonStates() { |
| 138 | + $('.compute-platform > .option').each(function() { |
| 139 | + var platformId = this.id; |
| 140 | + if (!platformId) return; |
| 141 | + |
| 142 | + var supportedOS = getSupportedOS(platformId); |
| 143 | + var isSupported = supportedOS.includes(ecosystemOpts.os); |
| 144 | + |
| 145 | + if (isSupported) { |
| 146 | + $(this).css('text-decoration', ''); |
| 147 | + } else { |
| 148 | + $(this).css('text-decoration', 'line-through'); |
| 149 | + } |
| 150 | + }); |
| 151 | + |
| 152 | + // If currently selected platform is not supported on new OS, deselect it |
| 153 | + if (ecosystemOpts.platform) { |
| 154 | + var supportedOS = getSupportedOS(ecosystemOpts.platform); |
| 155 | + if (!supportedOS.includes(ecosystemOpts.os)) { |
| 156 | + ecosystemOpts.platform = null; |
| 157 | + $('.compute-platform > .option').removeClass('selected'); |
| 158 | + $('#command').html('Select a compute platform to see the installation command.'); |
| 159 | + updatePlatformContentDisplay(); |
| 160 | + } |
| 161 | + } |
| 162 | +} |
| 163 | + |
| 164 | +// Update build button states (disabled/enabled) based on selected platform |
| 165 | +function updateBuildButtonStates() { |
| 166 | + $('.pytorch-build > .option').each(function() { |
| 167 | + var buildId = this.id; |
| 168 | + if (!buildId) return; |
| 169 | + |
| 170 | + if (!ecosystemOpts.platform) { |
| 171 | + // No platform selected - show all builds as available |
| 172 | + $(this).css('text-decoration', ''); |
| 173 | + return; |
| 174 | + } |
| 175 | + |
| 176 | + var supportedBuilds = getSupportedBuilds(ecosystemOpts.platform); |
| 177 | + var isSupported = supportedBuilds.includes(buildId); |
| 178 | + |
| 179 | + if (isSupported) { |
| 180 | + $(this).css('text-decoration', ''); |
| 181 | + } else { |
| 182 | + $(this).css('text-decoration', 'line-through'); |
| 183 | + } |
| 184 | + }); |
| 185 | + |
| 186 | + // If currently selected build is not supported by the platform, auto-switch to a supported build |
| 187 | + if (ecosystemOpts.platform) { |
| 188 | + var supportedBuilds = getSupportedBuilds(ecosystemOpts.platform); |
| 189 | + if (!supportedBuilds.includes(ecosystemOpts.build)) { |
| 190 | + // Switch to the first supported build |
| 191 | + if (supportedBuilds.length > 0) { |
| 192 | + ecosystemOpts.build = supportedBuilds[0]; |
| 193 | + $('.pytorch-build > .option').removeClass('selected'); |
| 194 | + $('.pytorch-build > .option#' + ecosystemOpts.build).addClass('selected'); |
| 195 | + } |
| 196 | + } |
| 197 | + } |
| 198 | +} |
| 199 | + |
| 200 | +// Update platform content display based on selected platform |
| 201 | +function updatePlatformContentDisplay() { |
| 202 | + // Hide all platform content first |
| 203 | + $('#additional-platforms-installation .platform-content').hide(); |
| 204 | + |
| 205 | + // Show selected platform content |
| 206 | + if (ecosystemOpts.platform) { |
| 207 | + $('#additional-platforms-installation .platform-content.' + ecosystemOpts.platform).show(); |
| 208 | + } |
| 209 | +} |
| 210 | + |
| 211 | +// Initialize all click events for build/os blocks |
| 212 | +function initAdditionalPlatforms() { |
| 213 | + // PyTorch Build - prevent selecting unsupported builds |
| 214 | + $('.pytorch-build > .option').on('click', function() { |
| 215 | + var buildId = this.id; |
| 216 | + |
| 217 | + // Check if this build is supported by the selected platform |
| 218 | + if (ecosystemOpts.platform) { |
| 219 | + var supportedBuilds = getSupportedBuilds(ecosystemOpts.platform); |
| 220 | + if (!supportedBuilds.includes(buildId)) { |
| 221 | + // Don't allow selecting unsupported build |
| 222 | + return; |
| 223 | + } |
| 224 | + } |
| 225 | + |
| 226 | + $('.pytorch-build > .option').removeClass('selected'); |
| 227 | + $(this).addClass('selected'); |
| 228 | + ecosystemOpts.build = buildId; |
| 229 | + updateEcosystemCommand(); |
| 230 | + }); |
| 231 | + |
| 232 | + // OS - with platform support check |
| 233 | + $('.os-ecosystem > .option').on('click', function() { |
| 234 | + $('.os-ecosystem > .option').removeClass('selected'); |
| 235 | + $(this).addClass('selected'); |
| 236 | + ecosystemOpts.os = this.id; |
| 237 | + |
| 238 | + updatePlatformButtonStates(); |
| 239 | + updateBuildButtonStates(); |
| 240 | + updateEcosystemCommand(); |
| 241 | + }); |
| 242 | +} |
| 243 | + |
| 244 | +// Update ecosystem command based on selections - simplified |
| 245 | +function updateEcosystemCommand() { |
| 246 | + if (!ecosystemOpts.platform) { |
| 247 | + $('#command').html('Select a compute platform to see the installation command.'); |
| 248 | + $('#support-channel').html('Select a compute platform to see the support channel.'); |
| 249 | + return; |
| 250 | + } |
| 251 | + |
| 252 | + var platform = ecosystemPlatformData[ecosystemOpts.platform]; |
| 253 | + if (!platform) { |
| 254 | + $('#command').html('Loading platform data...'); |
| 255 | + $('#support-channel').html('Loading platform data...'); |
| 256 | + return; |
| 257 | + } |
| 258 | + |
| 259 | + // Check if OS is supported |
| 260 | + var supportedOS = getSupportedOS(ecosystemOpts.platform); |
| 261 | + if (!supportedOS.includes(ecosystemOpts.os)) { |
| 262 | + $('#command').html('<i>' + platform.name + ' is not supported on ' + ecosystemOpts.os + '</i>'); |
| 263 | + $('#support-channel').html('<i>Select a supported platform to see the support channel.</i>'); |
| 264 | + return; |
| 265 | + } |
| 266 | + |
| 267 | + // Get command directly from platform[build][os] |
| 268 | + try { |
| 269 | + var buildData = platform[ecosystemOpts.build]; |
| 270 | + if (!buildData || !buildData[ecosystemOpts.os]) { |
| 271 | + $('#command').html('<i>Configuration not available for this combination</i>'); |
| 272 | + $('#support-channel').html('<i>Select a valid combination to see the support channel.</i>'); |
| 273 | + return; |
| 274 | + } |
| 275 | + |
| 276 | + var cmd = buildData[ecosystemOpts.os]; |
| 277 | + |
| 278 | + if (cmd) { |
| 279 | + $('#command').html('<pre>' + cmd + '</pre>'); |
| 280 | + } else { |
| 281 | + $('#command').html('<i>Configuration not available for this combination</i>'); |
| 282 | + } |
| 283 | + |
| 284 | + // Update support channel |
| 285 | + if (platform.support_channel) { |
| 286 | + $('#support-channel').html('<a href="' + platform.support_channel + '" target="_blank">' + platform.support_channel + '</a>'); |
| 287 | + } else { |
| 288 | + $('#support-channel').html('<i>No support channel available for this platform.</i>'); |
| 289 | + } |
| 290 | + } catch (e) { |
| 291 | + $('#command').html('<i>Configuration not available for this combination</i>'); |
| 292 | + $('#support-channel').html('<i>Configuration not available</i>'); |
| 293 | + } |
| 294 | +} |
0 commit comments