Skip to content

Commit

Permalink
ja: Format /web/api using Prettier (part 3)
Browse files Browse the repository at this point in the history
  • Loading branch information
queengooborg committed Jul 28, 2023
1 parent 881e54e commit 29715d7
Show file tree
Hide file tree
Showing 100 changed files with 1,284 additions and 1,105 deletions.
42 changes: 27 additions & 15 deletions files/ja/web/api/datatransferitem/webkitgetasentry/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,17 @@ HTMLは、ドロップゾーンそのものを、ID `"dropzone"` を持つ {{HTM
vertical-align: middle;
text-align: center;
color: black;
font: bold 2em "Arial", sans-serif;
font:
bold 2em "Arial",
sans-serif;
width: 300px;
height: 100px;
}

body {
font: 14px "Arial", sans-serif;
font:
14px "Arial",
sans-serif;
}
```

Expand All @@ -94,7 +98,7 @@ function scanFiles(item, container) {
elem.textContent = item.name;
container.appendChild(elem);

if (item.isDirectory) {
if (item.isDirectory) {
let directoryReader = item.createReader();
let directoryContainer = document.createElement("ul");
container.appendChild(directoryContainer);
Expand Down Expand Up @@ -123,28 +127,36 @@ function scanFiles(item, container) {
次に、イベントハンドラーが決まります。まず、{{domxref("HTMLElement/dragover_event", "dragover")}} イベントが既定のハンドラーで処理されないようにして、ドロップゾーンがドロップを受け取れるようにします。

```js
dropzone.addEventListener("dragover", (event) => {
event.preventDefault();
}, false);
dropzone.addEventListener(
"dragover",
(event) => {
event.preventDefault();
},
false,
);
```

このコースのイベントハンドラーは、もちろん {{domxref("HTMLElement/drop_event", "drop")}} イベントに対するハンドラーであり、すべてを開始させます。

```js
dropzone.addEventListener("drop", (event) => {
let items = event.dataTransfer.items;
dropzone.addEventListener(
"drop",
(event) => {
let items = event.dataTransfer.items;

event.preventDefault();
listing.textContent = "";
event.preventDefault();
listing.textContent = "";

for (let i=0; i<items.length; i++) {
let item = items[i].webkitGetAsEntry();
for (let i = 0; i < items.length; i++) {
let item = items[i].webkitGetAsEntry();

if (item) {
if (item) {
scanFiles(item, listing);
}
}
}
}, false);
},
false,
);
```

これは、ドロップされたアイテムを表す {{domxref("DataTransferItem")}} オブジェクトのリストを `event.dataTransfer.items` から取得します。
Expand Down
13 changes: 8 additions & 5 deletions files/ja/web/api/datatransferitemlist/add/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function dragstart_handler(ev) {
dataList.add(ev.target.id, "text/plain");
// Add some other items to the drag payload
dataList.add("<p>Paragraph…</p>", "text/html");
dataList.add("http://www.example.org","text/uri-list");
dataList.add("http://www.example.org", "text/uri-list");
}

function drop_handler(ev) {
Expand All @@ -95,17 +95,20 @@ function drop_handler(ev) {
const data = event.dataTransfer.items;
// Loop through the dropped items and log their data
for (let i = 0; i < data.length; i++) {
if ((data[i].kind === 'string') && (data[i].type.match('^text/plain'))) {
if (data[i].kind === "string" && data[i].type.match("^text/plain")) {
// This item is the target node
data[i].getAsString((s) => {
ev.target.appendChild(document.getElementById(s));
});
} else if ((data[i].kind === 'string') && (data[i].type.match('^text/html'))) {
} else if (data[i].kind === "string" && data[i].type.match("^text/html")) {
// Drag data item is HTML
data[i].getAsString((s) => {
console.log(`… Drop: HTML = ${s}`);
});
} else if ((data[i].kind === 'string') && (data[i].type.match('^text/uri-list'))) {
} else if (
data[i].kind === "string" &&
data[i].type.match("^text/uri-list")
) {
// Drag data item is URI
data[i].getAsString((s) => {
console.log(`… Drop: URI = ${s}`);
Expand All @@ -118,7 +121,7 @@ function dragover_handler(ev) {
console.log("dragOver");
ev.preventDefault();
// Set the dropEffect to move
ev.dataTransfer.dropEffect = "move"
ev.dataTransfer.dropEffect = "move";
}

function dragend_handler(ev) {
Expand Down
30 changes: 15 additions & 15 deletions files/ja/web/api/datatransferitemlist/clear/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ clear()
### CSS

```css
div {
margin: 0em;
padding: 2em;
}
#source {
color: blue;
border: 1px solid black;
}
#target {
border: 1px solid black;
}
div {
margin: 0em;
padding: 2em;
}
#source {
color: blue;
border: 1px solid black;
}
#target {
border: 1px solid black;
}
```

### JavaScript
Expand All @@ -84,17 +84,17 @@ function dropHandler(ev) {

// Loop through the dropped items and log their data
for (const item of ev.dataTransfer.items) {
if (item.kind === 'string' && item.type.match(/^text\/plain/)) {
if (item.kind === "string" && item.type.match(/^text\/plain/)) {
// This item is the target node
item.getAsString((s) => {
ev.target.appendChild(document.getElementById(s));
});
} else if (item.kind === 'string' && item.type.match(/^text\/html/)) {
} else if (item.kind === "string" && item.type.match(/^text\/html/)) {
// Drag data item is HTML
item.getAsString((s) => {
console.log(`… Drop: HTML = ${s}`);
});
} else if (item.kind === 'string' && item.type.match(/^text\/uri-list/)) {
} else if (item.kind === "string" && item.type.match(/^text\/uri-list/)) {
// Drag data item is URI
item.getAsString((s) => {
console.log(`… Drop: URI = ${s}`);
Expand All @@ -108,7 +108,7 @@ function dragoverHandler(ev) {
ev.preventDefault();

// Set the dropEffect to move
ev.dataTransfer.dropEffect = "move"
ev.dataTransfer.dropEffect = "move";
}

function dragendHandler(ev) {
Expand Down
10 changes: 5 additions & 5 deletions files/ja/web/api/datatransferitemlist/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function dragstartHandler(ev) {

// Add some other items to the drag payload
dataList.add("<p>Paragraph…</p>", "text/html");
dataList.add("http://www.example.org","text/uri-list");
dataList.add("http://www.example.org", "text/uri-list");
}

function dropHandler(ev) {
Expand All @@ -55,17 +55,17 @@ function dropHandler(ev) {

// Loop through the dropped items and log their data
for (const item of ev.dataTransfer.items) {
if (item.kind === 'string' && item.type.match(/^text\/plain/)) {
if (item.kind === "string" && item.type.match(/^text\/plain/)) {
// This item is the target node
item.getAsString((s) => {
ev.target.appendChild(document.getElementById(s));
});
} else if (item.kind === 'string' && item.type.match(/^text\/html/)) {
} else if (item.kind === "string" && item.type.match(/^text\/html/)) {
// Drag data item is HTML
item.getAsString((s) => {
console.log(`… Drop: HTML = ${s}`);
});
} else if (item.kind === 'string' && item.type.match(/^text\/uri-list/)) {
} else if (item.kind === "string" && item.type.match(/^text\/uri-list/)) {
// Drag data item is URI
item.getAsString((s) => {
console.log(`… Drop: URI = ${s}`);
Expand All @@ -79,7 +79,7 @@ function dragoverHandler(ev) {
ev.preventDefault();

// Set the dropEffect to move
ev.dataTransfer.dropEffect = "move"
ev.dataTransfer.dropEffect = "move";
}

function dragendHandler(ev) {
Expand Down
13 changes: 8 additions & 5 deletions files/ja/web/api/datatransferitemlist/length/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function dragstart_handler(ev) {
dataList.add(ev.target.id, "text/plain");
// Add some other items to the drag payload
dataList.add("<p>Paragraph…</p>", "text/html");
dataList.add("http://www.example.org","text/uri-list");
dataList.add("http://www.example.org", "text/uri-list");
}

function drop_handler(ev) {
Expand All @@ -37,17 +37,20 @@ function drop_handler(ev) {
const data = ev.dataTransfer.items;
// Loop through the dropped items and log their data
for (let i = 0; i < data.length; i++) {
if ((data[i].kind === 'string') && (data[i].type.match('^text/plain'))) {
if (data[i].kind === "string" && data[i].type.match("^text/plain")) {
// This item is the target node
data[i].getAsString((s) => {
ev.target.appendChild(document.getElementById(s));
});
} else if ((data[i].kind === 'string') && (data[i].type.match('^text/html'))) {
} else if (data[i].kind === "string" && data[i].type.match("^text/html")) {
// Drag data item is HTML
data[i].getAsString((s) => {
console.log(`… Drop: HTML = ${s}`);
});
} else if ((data[i].kind === 'string') && (data[i].type.match('^text/uri-list'))) {
} else if (
data[i].kind === "string" &&
data[i].type.match("^text/uri-list")
) {
// Drag data item is URI
data[i].getAsString((s) => {
console.log(`… Drop: URI = ${s}`);
Expand All @@ -60,7 +63,7 @@ function dragover_handler(ev) {
console.log("dragOver");
ev.preventDefault();
// Set the dropEffect to move
ev.dataTransfer.dropEffect = "move"
ev.dataTransfer.dropEffect = "move";
}

function dragend_handler(ev) {
Expand Down
39 changes: 18 additions & 21 deletions files/ja/web/api/datatransferitemlist/remove/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,36 +69,33 @@ div {

```js
function dragstart_handler(ev) {
console.log('dragStart');
console.log("dragStart");
// Add this element's id to the drag payload so the drop handler will
// know which element to add to its tree
const dataList = ev.dataTransfer.items;
dataList.add(ev.target.id, 'text/plain');
dataList.add(ev.target.id, "text/plain");
// Add some other items to the drag payload
dataList.add('<p>Paragraph…</p>', 'text/html');
dataList.add('http://www.example.org','text/uri-list');
dataList.add("<p>Paragraph…</p>", "text/html");
dataList.add("http://www.example.org", "text/uri-list");
}

function drop_handler(ev) {
console.log('Drop');
console.log("Drop");
ev.preventDefault();
const data = event.dataTransfer.items;
// Loop through the dropped items and log their data
for (const item of data) {
if ((item.kind === 'string') &&
(item.type.match('^text/plain'))) {
if (item.kind === "string" && item.type.match("^text/plain")) {
// This item is the target node
item.getAsString((s) => {
ev.target.appendChild(document.getElementById(s));
});
} else if ((item.kind === 'string') &&
(item.type.match('^text/html'))) {
} else if (item.kind === "string" && item.type.match("^text/html")) {
// Drag data item is HTML
item.getAsString((s) => {
console.log(`… Drop: HTML = ${s}`);
});
} else if ((item.kind === 'string') &&
(item.type.match('^text/uri-list'))) {
} else if (item.kind === "string" && item.type.match("^text/uri-list")) {
// Drag data item is URI
item.getAsString((s) => {
console.log(`… Drop: URI = ${s}`);
Expand All @@ -108,32 +105,32 @@ function drop_handler(ev) {
}

function dragover_handler(ev) {
console.log('dragOver');
console.log("dragOver");
ev.preventDefault();
// Set the dropEffect to move
ev.dataTransfer.dropEffect = 'move'
ev.dataTransfer.dropEffect = "move";
}

function dragend_handler(ev) {
console.log('dragEnd');
console.log("dragEnd");
const dataList = ev.dataTransfer.items;
// Clear all the files. Iterate in reverse order to safely remove.
for (let i = dataList.length - 1; i >= 0; i--) {
if (dataList[i].kind === 'file') {
if (dataList[i].kind === "file") {
dataList.remove(i);
}
}
// Clear any remaining drag data
dataList.clear();
}

const source = document.querySelector('#source');
source.addEventListener('dragstart', dragstart_handler);
source.addEventListener('dragend', dragend_handler);
const source = document.querySelector("#source");
source.addEventListener("dragstart", dragstart_handler);
source.addEventListener("dragend", dragend_handler);

const target = document.querySelector('#target');
target.addEventListener('drop', drop_handler);
target.addEventListener('dragover', dragover_handler);
const target = document.querySelector("#target");
target.addEventListener("drop", drop_handler);
target.addEventListener("dragover", dragover_handler);
```

#### 結果
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ new DecompressionStream(format)
この例では、blob を gzip 圧縮を用いて展開します。

```js
const ds = new DecompressionStream('gzip');
const ds = new DecompressionStream("gzip");
const decompressedStream = blob.stream().pipeThrough(ds);
```

Expand Down
2 changes: 1 addition & 1 deletion files/ja/web/api/decompressionstream/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ l10n:
この例では、blob を gzip 圧縮を用いて展開します。

```js
const ds = new DecompressionStream('gzip');
const ds = new DecompressionStream("gzip");
const decompressedStream = blob.stream().pipeThrough(ds);
```

Expand Down
2 changes: 1 addition & 1 deletion files/ja/web/api/decompressionstream/readable/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ l10n:
この例では、`DecompressionStream` から {{domxref("ReadableStream")}} を返します。

```js
let stream = new DecompressionStream('gzip');
let stream = new DecompressionStream("gzip");
console.log(stream.readable); // ReadableStream
```

Expand Down
2 changes: 1 addition & 1 deletion files/ja/web/api/decompressionstream/writable/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ l10n:
この例では、`DecompressionStream` から {{domxref("WritableStream")}} を返します。

```js
let stream = new DecompressionStream('gzip');
let stream = new DecompressionStream("gzip");
console.log(stream.writeable); // WritableStream
```

Expand Down
Loading

0 comments on commit 29715d7

Please sign in to comment.