in core/standalone/src/main/resources/playground/ui/playgroundFunctions.js [18:127]
$(document).ready(function(){
// This is the location of the supporting API
// The host value may get replaced in PlaygroundLauncher to a specific host
window.APIHOST='http://localhost:3233'
// To install in a different namespace, change this value
window.PLAYGROUND='whisk.system'
// Keys for cookies
window.colorKey = 'colorId'
window.languageKey = 'language'
window.playgroundIdKey = 'playgroundId'
window.actionKey = 'actionName'
// Initialize GUI elements
window.editor = initializeEditor()
window.colorSetting = initializeColor()
// The language table (a JS object acting as an associative array)
// Maps from language symbol to structure (1) repeating the symbol as 'name', (2) the editor mode,
// (3) the whisk runtime 'kind' to use for the language, and (4) the starting example code for that language.
window.languages = {
JavaScript: {
name: "JavaScript",
editMode: "ace/mode/javascript",
kind: "nodejs:default",
example:`function main(args) {
let name = args.name || 'stranger'
let greeting = 'Hello ' + name + '!'
console.log(greeting)
return {"body": greeting}
}`
},
Python: {
name: "Python",
editMode: "ace/mode/python",
kind: "python:default",
example: `def main(args):
if 'name' in args:
name = args['name']
else:
name = "stranger"
greeting = "Hello " + name + "!"
print(greeting)
return {"body": greeting}
`
},
Swift: {
name: "Swift",
editMode: "ace/mode/swift",
kind: "swift:default",
example:`func main(args: [String:Any]) -> [String:Any] {
if let name = args["name"] as? String {
let greeting = "Hello \\(name)!"
print(greeting)
return [ "body" : greeting ]
} else {
let greeting = "Hello stranger!"
print(greeting)
return [ "body" : greeting ]
}
}`
},
Go: {
name: 'Go',
editMode: 'ace/mode/go',
kind: `go:default`,
example: `package main
func Main(args map[string]interface{}) map[string]interface{} {
name, ok := args["name"].(string)
if !ok {
name = "stranger"
}
msg := make(map[string]interface{})
msg["body"] = "Hello, " + name + "!"
return msg
}`
},
PHP: {
name: 'PHP',
editMode: 'ace/mode/php',
kind: `php:default`,
example: `<?php
function main(array $args) : array {
$name = $args["name"] ?? "stranger";
$greeting = "Hello $name!";
echo $greeting;
return ["body" => $greeting];
}`
}
}
// Other initialization
window.playgroundId = initializePlaygroundId()
window.EditSession = require("ace/edit_session").EditSession // Per ACE doc
window.activeSessions = [] // Contains triples {actionName, EditSession, webbiness} for actions visited in this browser session
window.editorContentsChanged = false // A 'dirty' flag consulted as part of autosave logic
window.language = initializeLanguage() // Requires languages table to exist
window.actionList = [] // Populated asynchronously by initializeUserPackage. Contains pairs {actionName, actionKind}
window.currentAction = null // Name of the action displayed in the editor and actionSelector. Initialized by initializeActionSelector.
window.entryFollowup = null // Function to execute when name entry completes (for renameAction and startNewAction). Null except during name entry.
document.onkeydown = detectEscapeKey // Examine key presses to see if they indicate a desire to cancel name input mode
initializeUserPackage().then(initializeActionSelector).then(startAutosave)
});