-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Add widget support #797
base: main
Are you sure you want to change the base?
Add widget support #797
Conversation
Codecov Report
@@ Coverage Diff @@
## master #797 +/- ##
=======================================
Coverage 70.62% 70.63%
=======================================
Files 53 53
Lines 3707 3708 +1
Branches 2060 2061 +1
=======================================
+ Hits 2618 2619 +1
Misses 1087 1087
Partials 2 2
Help us with your feedback. Take ten seconds to tell us how you rate us. |
Will fix the code coverage 👍 |
I have simply done a quick review as this is still in draft.
|
@juuz0 I don't see any changes folowing @mgautierfr! Any problem? How should I test the feature? Where is the documentation? |
d279aff
to
fb3eaf5
Compare
@juuz0 Can you please rebase (and resolve the conflicts) now that we have merged the "no jquery" PR? |
@kelson42 Done. |
602b807
to
f42d773
Compare
@kelson42 Any updates here? :) |
Extracts function updateBookCount() from the unnamed function in resize event.
Adds an endpoint /widget to provide kiwix serve widget.
Gives a name to the IIFE wrapping code in index.js - kiwixServe and exposes updateBookCount through it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @juuz0 For this first version. It start to be like I expected. Here a few question/remarks:
- The CSS example does not work for me (i see nothing in red). Are you sure it is OK?
- We should have a way to filter normaly (via URL) like on library.kiwix.org, it seems to not be the case
- The ability to show one or many ZIM files based on their name (
M/Name
) should work as well on welcome page (and should probably be done via a dedicated PR). - http://localhost:8181/widget?book=gutenberg_fa_all_2022-01 does not deliver only one book with the
M/Name
value =gutenberg_fa_all_2022-01
I've checked again, it works on my side with the example in the docs. What browser do you use? I tried on Vivaldi (Chromium based) and Firefox. Exact code of html file?
These work for me again!
Yes I confirm this mistake, happened during a recent rebase.
Looking through the C++ code, I have found there's indeed a way to filer by book name already. Though with two problems:
|
I test with Firefox, the code comes from the your documentation: $ cat widget.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Widget Test</title>
</head>
<body>
<iframe src="http://localhost:8181/widget" width=1000 height=1000></iframe>
<script>
window.onload = function() {
var receiver = document.getElementById('receiver').contentWindow;
function sendMessage() {
let msg = {
css: `
.book__header {
color:red;
}`,
js: `
function widgetTest() {
console.log("Testing widget");
}
widgetTest();
`
}
receiver.postMessage(msg, 'http://192.168.18.8:8080/widget');
}
sendMessage();
}
</script>
</body>
</html> and the result looks like I see nothing which is different than without custom CSS. Considering that there is nothing which has the DOM
Indeed, seems to work. Sorry I can not reproduce the problem.
All of this seems to be the same problem and actually is 100% independent of the widget system IMO. Can you please open a ticket dedicated to this (and also work on the solution). An other detail, "Powered by Kiwix" should not be part of the widget IMO. I continue with my testing.... |
Modulo the remarks done earlier, this first version of the new |
The documentation does have the
|
Adds handling for parameters: disablefilter - disable search filters disableclick - disable book click action disabledownload - disable download button disabledesc - disable description
Added an event listener for message event. The idea is the website which embeds the widget will send a message using postMessage(). The expected message is: { css: // custom CSS code js: // custom JS code }
Added documentation for current widget usage, currently supported arguments, using custom CSS/JS
Done. |
@juuz0 Please create a dedicated ticket + PR for selecting ZIM files based on there ZIM |
document.querySelector(nodeQuery).innerHTML += optionStr; | ||
const entryList = data.querySelectorAll('entry'); | ||
const nodeQueryElem = document.querySelector(nodeQuery); | ||
if (entryList && nodeQueryElem) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When nodeQueryElem == null
doesn't the loadAndDisplayOptions()
function become a no-op? If so why run fetch(query)
at all?
disableclick (value = N/A) | ||
Disables clicking the book to open it for reading. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me (Firefox 103.0) a blank tab is opened
const hideNavRule = ` | ||
.kiwixNav { | ||
display: none; | ||
}`; | ||
const hideResultsLabelRule = ` | ||
.kiwixHomeBody__results { | ||
display: none; | ||
}`; | ||
const hideTagFilterRule = ` | ||
.book__tags { | ||
pointer-events: none; | ||
}`; | ||
insertNewCssRules(widgetStyles, [hideNavRule, hideResultsLabelRule, hideTagFilterRule]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that if you introduce custom CSS handling first, then disableSearchFilters()
, disableDownload()
, disableDescription()
and hideFooter()
can be rewritten via addCustomCss()
in a simpler way.
@juuz0 Any feedback? |
This pull request has been automatically marked as stale because it has not had recent activity. It will be now be reviewed manually. Thank you for your contributions. |
Widget endpoint: /widget
Fixes #585