| 1 |
// Add debug actions to flyout menu |
| 2 |
|
| 3 |
$(function () { |
| 4 |
$("[data-toggle='rst-debug-badge']").on("click", function () { |
| 5 |
$("[data-toggle='rst-versions']").toggleClass("rst-badge"); |
| 6 |
}); |
| 7 |
}); |
| 8 |
|
| 9 |
|
| 10 |
const EVENT_READTHEDOCS_ADDONS_DATA_READY = "readthedocs-addons-data-ready"; |
| 11 |
|
| 12 |
fetch("_static/addons.mocked.json", { method: "GET" }) |
| 13 |
.then((response) => { |
| 14 |
if (!response.ok) { |
| 15 |
throw new Error("Error downloading Read the Docs Addons mocked data"); |
| 16 |
} |
| 17 |
return response.json(); |
| 18 |
}) |
| 19 |
.then((data) => { |
| 20 |
return dispatchEvent( |
| 21 |
EVENT_READTHEDOCS_ADDONS_DATA_READY, |
| 22 |
new ReadTheDocsEventData(data), |
| 23 |
); |
| 24 |
}); |
| 25 |
|
| 26 |
|
| 27 |
// ``ReadTheDocsEventData`` and ``dispatchEvent`` |
| 28 |
// are borrowed and adapted from Read the Docs Addons. |
| 29 |
// https://github.com/readthedocs/addons |
| 30 |
class ReadTheDocsEventData { |
| 31 |
constructor(data) { |
| 32 |
this._data = data; |
| 33 |
} |
| 34 |
|
| 35 |
data() { |
| 36 |
return this._data; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
function dispatchEvent(eventName, data) { |
| 41 |
const event = new CustomEvent(eventName, { detail: data }); |
| 42 |
document.dispatchEvent(event); |
| 43 |
} |