-
Notifications
You must be signed in to change notification settings - Fork 772
Custom click listener - closes #132 #137
Custom click listener - closes #132 #137
Conversation
…tory/FolioReaderKit into feature/Pana/NativeJS
Eg. A ClassBasedOnCLickListener with the className "quote" and parameterName "id" with the given epub html content "<section class="quote" id="12345">" would call the given closure on a click on this section with the String "12345" as parameter. | ||
|
||
*/ | ||
public struct ClassBasedOnCLickListener { |
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.
We could simplify this name, it is a little confused for me, what do you think?
Also there is a typo ClassBasedOnCLickListener
should be ClassBasedOnClickListener
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.
Ok, I will fix it to ClassBasedOnClickListener
. I'm don't have a better naming yet as the current one describes the function really good. To just use OnClickListener
or sth. similiar wouln't be clear about it's function and usage.
What name do you have in mind?
This is a advanced usage, what do you think, could we write a sample with a custom book for this? or include a custom book on existing samples? |
Yes, an exmaple sounds useful. I will adjust the StoryboardExample to include a click listener on chapters within the "The Silver Chair" epub. |
I have tested, click handler conflicts with UIMenu, when you click on a highlight the menu do not show. |
|
||
function addClassBasedOnClickListener(schemeName, className, parameterName) { | ||
// Get all elements with the given className | ||
var elements = document.getElementsByClassName(className); |
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 was thinking about it, maybe we could use the JavaScript querySelector
or querySelectorAll
, instead of just getElementsByClassName
. The querySelector
is like jQuery, so we can do like "#someID"
, ".someclass"
, "h1"
or any kind of complex selection.
Reference:
https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelectorAll
https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
Complex query:
var el = document.querySelector("div.user-panel.main input[name=login]");
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.
More option sound good, I'll give it a try.
public var onClickAction : ((parameterContent: String?) -> Void) | ||
|
||
/// Initializes a `ClassBasedOnClickListener` instance. Append it to the `classBasedOnClickListeners` property from the `FolioReaderConfig` to receive on click events. | ||
public init(schemeName: String, className: String, parameterName: String, onClickAction: ((parameterContent: String?) -> Void)) { |
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.
In addition we would change the className
to querySelector
and maybe add a new Bool
attribute selectAll
with true
by default, so I can choose to select only first element or all elements. What do you think?
Thanks guys, big improvements here! 👏 |
Implements https://github.com/FolioReader/FolioReaderKit/issues/132