Skip to content
This repository was archived by the owner on Nov 26, 2020. It is now read-only.

Custom click listener - closes #132#137

Merged
hebertialmeida merged 14 commits into
FolioReader:masterfrom
smartmobilefactory:issue/132
Sep 15, 2016
Merged

Custom click listener - closes #132#137
hebertialmeida merged 14 commits into
FolioReader:masterfrom
smartmobilefactory:issue/132

Conversation

@tschob
Copy link
Copy Markdown
Member

@tschob tschob commented Sep 7, 2016

Comment thread Source/FolioReaderConfig.swift Outdated
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 {
Copy link
Copy Markdown
Member

@hebertialmeida hebertialmeida Sep 7, 2016

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

Copy link
Copy Markdown
Member Author

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?

@hebertialmeida
Copy link
Copy Markdown
Member

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?

@hebertialmeida hebertialmeida changed the title Issue/132 Custom click listener - #132 Sep 7, 2016
@hebertialmeida hebertialmeida changed the title Custom click listener - #132 Custom click listener - closes #132 Sep 7, 2016
@tschob
Copy link
Copy Markdown
Member Author

tschob commented Sep 8, 2016

Yes, an exmaple sounds useful. I will adjust the StoryboardExample to include a click listener on chapters within the "The Silver Chair" epub.

@hebertialmeida
Copy link
Copy Markdown
Member

I have tested, click handler conflicts with UIMenu, when you click on a highlight the menu do not show.

@tschob tschob closed this Sep 14, 2016
@tschob tschob reopened this Sep 14, 2016
Comment thread Source/Resources/Bridge.js Outdated

function addClassBasedOnClickListener(schemeName, className, parameterName) {
// Get all elements with the given className
var elements = document.getElementsByClassName(className);
Copy link
Copy Markdown
Member

@hebertialmeida hebertialmeida Sep 15, 2016

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]");

Copy link
Copy Markdown
Member Author

@tschob tschob Sep 15, 2016

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.

Comment thread Source/FolioReaderConfig.swift Outdated
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)) {
Copy link
Copy Markdown
Member

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?

@hebertialmeida hebertialmeida merged commit 3ee4176 into FolioReader:master Sep 15, 2016
@hebertialmeida
Copy link
Copy Markdown
Member

Thanks guys, big improvements here! 👏

@tschob tschob deleted the issue/132 branch September 16, 2016 09:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants