Skip to content

Commit

Permalink
Format /web/api/[x-z]* using Prettier (#24073)
Browse files Browse the repository at this point in the history
* Format /web/api/[x-z]* using Prettier

* docs(API): use example.com for domains, use file name that won't trigger spellcheck errors

* Reformat

* Update files/en-us/web/api/xrinputsourcearray/length/index.md

Co-authored-by: Brian Thomas Smith <[email protected]>

* Change image file name

---------

Co-authored-by: Brian Thomas Smith <[email protected]>
  • Loading branch information
queengooborg and bsmth authored May 10, 2023
1 parent 584921f commit 76637f9
Show file tree
Hide file tree
Showing 161 changed files with 896 additions and 658 deletions.
5 changes: 0 additions & 5 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,3 @@ build/
/files/en-us/web/html/**/*.md
/files/en-us/web/javascript/**/*.md
/files/en-us/web/web_components/**/*.md

# The /web/api folder is so large, it has been divided into multiple parts
/files/en-us/web/api/**/*.md
# Alphabetically 'allow' this range incrementally
!/files/en-us/web/api/[a-w]*/**/*.md
14 changes: 2 additions & 12 deletions files/en-us/web/api/webxr_device_api/cameras/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,25 +204,15 @@ If the same scaling factor is to be applied in every direction, you can create a

```js-nolint
function createScalingMatrix(f) {
return [
f, 0, 0, 0,
0, f, 0, 0,
0, 0, f, 0,
0, 0, 0, 1
];
return [f, 0, 0, 0, 0, f, 0, 0, 0, 0, f, 0, 0, 0, 0, 1];
}
```

With the transform matrix in hand, we apply the transform `scaleTransform` to the vector (or vertex) `myVector`:

```js-nolint
let myVector = [2, 1, -3];
let scaleTransform = [
2, 0, 0, 0,
0, 2, 0, 0,
0, 0, 2, 0,
0, 0, 0, 1
];
let scaleTransform = [2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1];
vec4.transformMat4(myVector, myVector, scaleTransform);
```

Expand Down
50 changes: 25 additions & 25 deletions files/en-us/web/api/xmlhttprequest/abort_event/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ The `abort` event is fired when a request has been aborted, for example because
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.

```js
addEventListener('abort', (event) => { })
addEventListener("abort", (event) => {});

onabort = (event) => { }
onabort = (event) => {};
```

## Event type
Expand Down Expand Up @@ -83,44 +83,44 @@ input {
#### JavaScript

```js
const xhrButtonSuccess = document.querySelector('.xhr.success');
const xhrButtonError = document.querySelector('.xhr.error');
const xhrButtonAbort = document.querySelector('.xhr.abort');
const log = document.querySelector('.event-log');
const xhrButtonSuccess = document.querySelector(".xhr.success");
const xhrButtonError = document.querySelector(".xhr.error");
const xhrButtonAbort = document.querySelector(".xhr.abort");
const log = document.querySelector(".event-log");

function handleEvent(e) {
log.textContent = `${log.textContent}${e.type}: ${e.loaded} bytes transferred\n`;
log.textContent = `${log.textContent}${e.type}: ${e.loaded} bytes transferred\n`;
}

function addListeners(xhr) {
xhr.addEventListener('loadstart', handleEvent);
xhr.addEventListener('load', handleEvent);
xhr.addEventListener('loadend', handleEvent);
xhr.addEventListener('progress', handleEvent);
xhr.addEventListener('error', handleEvent);
xhr.addEventListener('abort', handleEvent);
xhr.addEventListener("loadstart", handleEvent);
xhr.addEventListener("load", handleEvent);
xhr.addEventListener("loadend", handleEvent);
xhr.addEventListener("progress", handleEvent);
xhr.addEventListener("error", handleEvent);
xhr.addEventListener("abort", handleEvent);
}

function runXHR(url) {
log.textContent = '';
log.textContent = "";

const xhr = new XMLHttpRequest();
addListeners(xhr);
xhr.open("GET", url);
xhr.send();
return xhr;
const xhr = new XMLHttpRequest();
addListeners(xhr);
xhr.open("GET", url);
xhr.send();
return xhr;
}

xhrButtonSuccess.addEventListener('click', () => {
runXHR('dgszyjnxcaipwzy.jpg');
xhrButtonSuccess.addEventListener("click", () => {
runXHR("my-picture.jpg");
});

xhrButtonError.addEventListener('click', () => {
runXHR('https://somewhere.org/i-dont-exist');
xhrButtonError.addEventListener("click", () => {
runXHR("https://example.com/some-path");
});

xhrButtonAbort.addEventListener('click', () => {
runXHR('dgszyjnxcaipwzy.jpg').abort();
xhrButtonAbort.addEventListener("click", () => {
runXHR("my-picture.jpg").abort();
});
```

Expand Down
50 changes: 25 additions & 25 deletions files/en-us/web/api/xmlhttprequest/error_event/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ The `error` event is fired when the request encountered an error.
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.

```js
addEventListener('error', (event) => { })
addEventListener("error", (event) => {});

onerror = (event) => { }
onerror = (event) => {};
```

## Event type
Expand Down Expand Up @@ -83,44 +83,44 @@ input {
#### JavaScript

```js
const xhrButtonSuccess = document.querySelector('.xhr.success');
const xhrButtonError = document.querySelector('.xhr.error');
const xhrButtonAbort = document.querySelector('.xhr.abort');
const log = document.querySelector('.event-log');
const xhrButtonSuccess = document.querySelector(".xhr.success");
const xhrButtonError = document.querySelector(".xhr.error");
const xhrButtonAbort = document.querySelector(".xhr.abort");
const log = document.querySelector(".event-log");

function handleEvent(e) {
log.textContent = `${log.textContent}${e.type}: ${e.loaded} bytes transferred\n`;
log.textContent = `${log.textContent}${e.type}: ${e.loaded} bytes transferred\n`;
}

function addListeners(xhr) {
xhr.addEventListener('loadstart', handleEvent);
xhr.addEventListener('load', handleEvent);
xhr.addEventListener('loadend', handleEvent);
xhr.addEventListener('progress', handleEvent);
xhr.addEventListener('error', handleEvent);
xhr.addEventListener('abort', handleEvent);
xhr.addEventListener("loadstart", handleEvent);
xhr.addEventListener("load", handleEvent);
xhr.addEventListener("loadend", handleEvent);
xhr.addEventListener("progress", handleEvent);
xhr.addEventListener("error", handleEvent);
xhr.addEventListener("abort", handleEvent);
}

function runXHR(url) {
log.textContent = '';
log.textContent = "";

const xhr = new XMLHttpRequest();
addListeners(xhr);
xhr.open("GET", url);
xhr.send();
return xhr;
const xhr = new XMLHttpRequest();
addListeners(xhr);
xhr.open("GET", url);
xhr.send();
return xhr;
}

xhrButtonSuccess.addEventListener('click', () => {
runXHR('dgszyjnxcaipwzy.jpg');
xhrButtonSuccess.addEventListener("click", () => {
runXHR("dgszyjnxcaipwzy.jpg");
});

xhrButtonError.addEventListener('click', () => {
runXHR('https://somewhere.org/i-dont-exist');
xhrButtonError.addEventListener("click", () => {
runXHR("https://somewhere.org/i-dont-exist");
});

xhrButtonAbort.addEventListener('click', () => {
runXHR('dgszyjnxcaipwzy.jpg').abort();
xhrButtonAbort.addEventListener("click", () => {
runXHR("dgszyjnxcaipwzy.jpg").abort();
});
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ request.send();

request.onreadystatechange = () => {
if (request.readyState === this.HEADERS_RECEIVED) {

// Get the raw header string
const headers = request.getAllResponseHeaders();

Expand All @@ -82,13 +81,13 @@ request.onreadystatechange = () => {
// Create a map of header names to values
const headerMap = {};
arr.forEach((line) => {
const parts = line.split(': ');
const parts = line.split(": ");
const header = parts.shift();
const value = parts.join(': ');
const value = parts.join(": ");
headerMap[header] = value;
});
}
}
};
```

Once this is done, you can, for example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ client.onreadystatechange = () => {
client.abort();
}
}
}
};
```

## Specifications
Expand Down
24 changes: 16 additions & 8 deletions files/en-us/web/api/xmlhttprequest/html_in_xmlhttprequest/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Retrieving an HTML resource as a DOM using {{domxref("XMLHttpRequest")}} works j
const xhr = new XMLHttpRequest();
xhr.onload = () => {
console.log(xhr.responseXML.title);
}
};
xhr.open("GET", "file.html");
xhr.responseType = "document";
xhr.send();
Expand All @@ -41,9 +41,9 @@ function HTMLinXHR() {
return false;
}
const req = new window.XMLHttpRequest();
req.open('GET', window.location.href, false);
req.open("GET", window.location.href, false);
try {
req.responseType = 'document';
req.responseType = "document";
} catch (e) {
return true;
}
Expand All @@ -70,7 +70,9 @@ If the file is named `detect.html`, the following function can be used for detec
```js
function detectHtmlInXhr(callback) {
if (!window.XMLHttpRequest) {
setTimeout(function() { callback(false); }, 0);
setTimeout(function () {
callback(false);
}, 0);

return;
}
Expand All @@ -79,21 +81,27 @@ function detectHtmlInXhr(callback) {
xhr.onreadystatechange = () => {
if (xhr.readyState === 4 && !done) {
done = true;
callback(!!(xhr.responseXML && xhr.responseXML.title && xhr.responseXML.title === "&&<"));
callback(
!!(
xhr.responseXML &&
xhr.responseXML.title &&
xhr.responseXML.title === "&&<"
)
);
}
}
};
xhr.onabort = xhr.onerror = () => {
if (!done) {
done = true;
callback(false);
}
}
};
try {
xhr.open("GET", "detect.html");
xhr.responseType = "document";
xhr.send();
} catch (e) {
setTimeout(function() {
setTimeout(function () {
if (!done) {
done = true;
callback(false);
Expand Down
50 changes: 25 additions & 25 deletions files/en-us/web/api/xmlhttprequest/load_event/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ The `load` event is fired when an {{domxref("XMLHttpRequest")}} transaction comp
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.

```js
addEventListener('load', (event) => { })
addEventListener("load", (event) => {});

onload = (event) => { }
onload = (event) => {};
```

## Event type
Expand Down Expand Up @@ -83,44 +83,44 @@ input {
#### JavaScript

```js
const xhrButtonSuccess = document.querySelector('.xhr.success');
const xhrButtonError = document.querySelector('.xhr.error');
const xhrButtonAbort = document.querySelector('.xhr.abort');
const log = document.querySelector('.event-log');
const xhrButtonSuccess = document.querySelector(".xhr.success");
const xhrButtonError = document.querySelector(".xhr.error");
const xhrButtonAbort = document.querySelector(".xhr.abort");
const log = document.querySelector(".event-log");

function handleEvent(e) {
log.textContent = `${log.textContent}${e.type}: ${e.loaded} bytes transferred\n`;
log.textContent = `${log.textContent}${e.type}: ${e.loaded} bytes transferred\n`;
}

function addListeners(xhr) {
xhr.addEventListener('loadstart', handleEvent);
xhr.addEventListener('load', handleEvent);
xhr.addEventListener('loadend', handleEvent);
xhr.addEventListener('progress', handleEvent);
xhr.addEventListener('error', handleEvent);
xhr.addEventListener('abort', handleEvent);
xhr.addEventListener("loadstart", handleEvent);
xhr.addEventListener("load", handleEvent);
xhr.addEventListener("loadend", handleEvent);
xhr.addEventListener("progress", handleEvent);
xhr.addEventListener("error", handleEvent);
xhr.addEventListener("abort", handleEvent);
}

function runXHR(url) {
log.textContent = '';
log.textContent = "";

const xhr = new XMLHttpRequest();
addListeners(xhr);
xhr.open("GET", url);
xhr.send();
return xhr;
const xhr = new XMLHttpRequest();
addListeners(xhr);
xhr.open("GET", url);
xhr.send();
return xhr;
}

xhrButtonSuccess.addEventListener('click', () => {
runXHR('image.jpg');
xhrButtonSuccess.addEventListener("click", () => {
runXHR("image.jpg");
});

xhrButtonError.addEventListener('click', () => {
runXHR('https://somewhere.org/i-dont-exist');
xhrButtonError.addEventListener("click", () => {
runXHR("https://somewhere.org/i-dont-exist");
});

xhrButtonAbort.addEventListener('click', () => {
runXHR('image.jpg').abort();
xhrButtonAbort.addEventListener("click", () => {
runXHR("image.jpg").abort();
});
```

Expand Down
Loading

0 comments on commit 76637f9

Please sign in to comment.