Skip to content

Commit 282e36c

Browse files
committed
Add documentation for widget
Added documentation for current widget usage, currently supported arguments, using custom CSS/JS
1 parent aead410 commit 282e36c

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

Diff for: docs/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Welcome to libkiwix's documentation!
1212

1313
usage
1414
api/ref_api
15+
widget

Diff for: docs/widget.rst

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
Kiwix serve widget
2+
====================
3+
4+
Introduction
5+
------------
6+
7+
The kiwix-serve widget provides an easy to embed way to show the `kiwix-serve` homepage.
8+
9+
Usage
10+
-----
11+
12+
To use the widget, simply add an iframe with its `src` attribute set to the `widget` endpoint.
13+
Example HTML Page ::
14+
15+
<!DOCTYPE html>
16+
<html lang="en">
17+
<head>
18+
<title>Widget Test</title>
19+
</head>
20+
<body>
21+
<iframe src="http://192.168.18.8:8080/widget?disabledesc&disablefilter&disabledownload" width=1000 height=1000></iframe>
22+
</body>
23+
</html>
24+
25+
This creates an iframe with the kiwix-serve homepage contents.
26+
27+
Arguments are explained below.
28+
29+
Possible Arguments
30+
-------------------
31+
32+
Currently, the following arguments are supported.
33+
34+
disabledesc (value = N/A)
35+
Disables the description part of a tile.
36+
37+
disablefilter (value = N/A)
38+
Disables the search filters: language, category, tag and search function.
39+
40+
disableclick (value = N/A)
41+
Disables clicking the book to open it for reading.
42+
43+
disabledownload (value = N/A)
44+
Disables the download button (if avaialable at all) on the tile.
45+
46+
book (value = yes)
47+
Multivalue argument. Takes the name of books to display.
48+
49+
Example::
50+
51+
<iframe src="http://192.168.18.8:8080/widget?book=wikiversity_en_all&book=bitcoin_en_all">
52+
53+
Custom CSS and JS
54+
-----------------
55+
56+
You can add your custom CSS rules and Javascript code to the widget.
57+
58+
To do that, use the following code as template::
59+
60+
<iframe id="receiver" src="http://192.168.18.8:8080/widget?disabledesc=&disablefilter=&disabledownload=" width="1000" height="1000">
61+
<p>Your browser does not support iframes.</p>
62+
</iframe>
63+
64+
<script>
65+
window.onload = function() {
66+
var receiver = document.getElementById('receiver').contentWindow;
67+
function sendMessage() {
68+
let msg = {
69+
css: `
70+
.book__header {
71+
color:red;
72+
}`,
73+
js: `
74+
function widgetTest() {
75+
console.log("Testing widget");
76+
}
77+
widgetTest();
78+
`
79+
}
80+
receiver.postMessage(msg, 'http://192.168.18.8:8080/widget');
81+
}
82+
sendMessage();
83+
}
84+
</script>
85+
86+
87+
The CSS/JS fields are optional, you may send both or only one.
88+

0 commit comments

Comments
 (0)