Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: syntax errors in JS example sections #18186

Merged
merged 5 commits into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions files/en-us/web/api/webxr_device_api/rendering/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Ideally, you want this code to be fast enough that it can maintain a 60 FPS fram

In this version of the WebXR rendering callback, we use a very straightforward approach that works great for relatively simple projects. This pseudocode outlines that process:

```js
```
for each view in the pose's views list:
get the WebXR GL layer's viewport
set the WebGL viewport to match
Expand Down Expand Up @@ -244,7 +244,7 @@ An advantage of WebXR's approach of using a single WebGL framebuffer to contain

The resulting pseudocode looks like this:

```js
```
for each object in the scene
bindProgram()
bindUniforms()
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/window/clearimmediate/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ None ({{jsxref("undefined")}}).
```js
let immediateID = setImmediate(() => {
// Run some code
}
});

document.getElementById("button")
.addEventListener(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Alternatively, you can use the `window.ongamepaddisconnected` event handler prop
```js
window.ongamepaddisconnected = event => {
console.log('Lost connection with the gamepad.');
});
};
```

## Specifications
Expand Down
18 changes: 9 additions & 9 deletions files/en-us/web/api/window/open/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ function openRequestedPopup() {
## Best practices

```js
<script type="text/javascript">
var windowObjectReference = null; // global variable
function openFFPromotionPopup() {
if(windowObjectReference == null || windowObjectReference.closed)
Expand All @@ -142,8 +141,9 @@ function openFFPromotionPopup() {
the window or to reload the referenced resource. */
};
}
</script>
(...)
```

```html
<p><a
href="http://www.spreadfirefox.com/"
target="PromoteFirefoxWindowName"
Expand Down Expand Up @@ -172,7 +172,6 @@ You can also parameterize the function to make it versatile, functional in more
situations, therefore re-usable in scripts and webpages:

```js
<script type="text/javascript">
var windowObjectReference = null; // global variable
function openRequestedPopup(url, windowName) {
if(windowObjectReference == null || windowObjectReference.closed) {
Expand All @@ -181,8 +180,9 @@ function openRequestedPopup(url, windowName) {
windowObjectReference.focus();
};
}
</script>
(...)
```

```html
<p><a
href="http://www.spreadfirefox.com/"
target="PromoteFirefoxWindow"
Expand All @@ -195,7 +195,6 @@ You can also make such function able to open only 1 secondary window and to reus
single secondary window for other links in this manner:

```js
<script type="text/javascript">
var windowObjectReference = null; // global variable
var PreviousUrl; /* global variable that will store the
url currently in the secondary window */
Expand All @@ -217,8 +216,9 @@ function openRequestedSinglePopup(url) {
/* explanation: we store the current url in order to compare url
in the event of another call of this function. */
}
</script>
(...)
```

```html
<p><a
href="http://www.spreadfirefox.com/"
target="SingleSecondaryWindowName"
Expand Down
4 changes: 2 additions & 2 deletions files/en-us/web/api/window/prompt/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ Under some conditions — for example, when the user switches tabs — the brows
```js
prompt()
prompt(message)
prompt(message, default)
prompt(message, defaultValue)
```

### Parameters

- `message` {{optional_inline}}
- : A string of text to display to the user. Can be omitted if there is nothing to show
in the prompt window.
- `default` {{optional_inline}}
- `defaultValue` {{optional_inline}}
- : A string containing the default value displayed in the text input field. Note that
in Internet Explorer 7 and 8, if you do not provide this parameter, the string
`"undefined"` is the default value.
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/window/transitionrun_event/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ This code adds a listener to the `transitionrun` event:

```js
window.addEventListener('transitionrun', () => {
console.log('Transition is running but hasn't necessarily started transitioning yet');
console.log("Transition is running but hasn't necessarily started transitioning yet");
});
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Or use the `onvrdisplaydisconnect` event handler property:
window.onvrdisplaydisconnect = function() {
info.textContent = 'Display disconnected.';
reportDisplays();
);
};
```

## Specifications
Expand Down
8 changes: 3 additions & 5 deletions files/en-us/web/api/windowclient/focused/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ self.addEventListener('notificationclick', function(event) {
for (var i = 0; i < clientList.length; i++) {
var client = clientList[i];
if (client.url == '/' && 'focus' in client) {
if(!client.focused)
return client.focus();
}
if (!client.focused) return client.focus();
}
}
if (clients.openWindow)
return clients.openWindow('/');

if (clients.openWindow) return clients.openWindow('/');
}));
});
```
Expand Down
9 changes: 3 additions & 6 deletions files/en-us/web/api/windowclient/visibilitystate/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,14 @@ event.waitUntil(clients.matchAll({
for (let i = 0; i < clientList.length; i++) {
let client = clientList[i];
if (client.url == '/' && 'focus' in client) {
if (client.visibilityState === 'hidden')
return client.focus();
}
if (client.visibilityState === 'hidden') return client.focus();
}
}

if (clients.openWindow) {
return clients.openWindow('/');
}
}));
});
})
);
```

## Specifications
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/workerglobalscope/location/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ console.log(location);

inside a worker (which would basically be the equivalent of `self.console.log(self.location);`, as these are being called on the worker scope, which can be referenced with {{domxref("WorkerGlobalScope.self")}}), you will get a {{domxref("WorkerLocation")}} object written to the console — something like the following:

```js
```
WorkerLocation {hash: "", search: "", pathname: "/worker.js", port: "8000", hostname: "localhost"…}
hash: ""
host: "localhost:8000"
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/workerglobalscope/navigator/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ console.log(navigator);

inside a worker (which would basically be the equivalent of `self.console.log(self.navigator);`, as these are being called on the worker scope, which can be referenced with {{domxref("WorkerGlobalScope.self")}}), you will get a {{domxref("WorkerNavigator")}} object written to the console — something like the following:

```js
```
Object {onLine: true, userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) Ap…ML, like Gecko) Chrome/40.0.2214.93 Safari/537.36", product: "Gecko", platform: "MacIntel", appVersion: "5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKi…ML, like Gecko) Chrome/40.0.2214.93 Safari/537.36"…}
appCodeName: "Mozilla"
appName: "Netscape"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The same snippet, but using `addEventListener()`:
```js
self.addEventListener('offline', function() {
console.log('Your worker is now offline');
}
});
```

## Specifications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The same snippet, but using `addEventListener()`:
```js
self.addEventListener('online', function() {
console.log('Your worker is now online');
}
});
```

## Specifications
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/workerglobalscope/self/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ console.log(self);

inside a worker, you will get a worker global scope of the same type as that worker object written to the console — something like the following:

```js
```
DedicatedWorkerGlobalScope {
undefined: undefined, Infinity: Infinity, Math: MathConstructor, NaN: NaN, Intl: Object…}
Infinity: Infinity
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/workernavigator/useragent/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ several pieces of info. Each of these pieces of info comes from other navigator
properties which are also settable by the user. Gecko-based browsers comply with the
following general structure:

```js
```
userAgent = appCodeName/appVersion number (Platform; Security; OS-or-CPU;
Localization; rv: revision-version-number) product/productSub
Application-Name Application-Name-version
Expand Down
8 changes: 4 additions & 4 deletions files/en-us/web/api/writablestream/abort/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ A {{jsxref("Promise")}}, which fulfills with the value given in the `reason` par
```js
const writableStream = new WritableStream({
write(chunk) {
...
// ...
},
close() {
...
// ...
},
abort(err) {
...
// ...
}
}, queuingStrategy);

...
// ...

// abort the stream later on, when required
writableStream.abort();
Expand Down
8 changes: 4 additions & 4 deletions files/en-us/web/api/writablestream/locked/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ A boolean value indicating whether or not the writable stream is locked.
```js
const writableStream = new WritableStream({
write(chunk) {
...
// ...
},
close() {
...
// ...
},
abort(err) {
...
// ...
}
}, queuingStrategy);

...
// ...

const writer = writableStream.getWriter();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ const writableStream = new WritableStream({
controller.error('My error is broken');
},
write(chunk, controller) {
...
// ...
},
close(controller) {
...
// ...
},
abort(err) {
...
// ...
}
});
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ const writableStream = new WritableStream({
controller.error('My stream is broken');
},
write(chunk, controller) {
...
// ...
},
close(controller) {
...
// ...
},
abort(err) {
...
// ...
}
});
```
Expand Down
10 changes: 5 additions & 5 deletions files/en-us/web/api/writablestreamdefaultwriter/abort/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ parameter.
```js
const writableStream = new WritableStream({
write(chunk) {
...
// ...
},
close() {
...
// ...
},
abort(err) {
...
// ...
}
}, queuingStrategy);

...
// ...

const writer = writableStream.getWriter();

...
// ...

// abort the stream when desired
writer.abort.then((reason) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ const writableStream = new WritableStream({
start(controller) {
},
write(chunk, controller) {
...
// ...
},
close(controller) {
...
// ...
},
abort(err) {
...
// ...
}
}, queuingStrategy);

...
// ...

const writer = writableStream.getWriter();

..
// ..

// check if the stream is closed
writer.closed.then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ closed.
```js
const writableStream = new WritableStream({
write(chunk) {
...
// ...
},
close() {
...
// ...
},
abort(err) {
...
// ...
}
}, queuingStrategy);

...
// ...

const writer = writableStream.getWriter();

...
// ...

// return stream's desired size
let size = writer.desiredSize;
Expand Down
Loading