-
Notifications
You must be signed in to change notification settings - Fork 772
Custom click listener - closes #132 #137
Changes from 7 commits
4c1c3f0
4dc7a12
1be980e
f086630
38bb056
9e9f825
12bda49
4d888f1
bff575e
41b52cc
ac27c5d
3350432
5467a1a
2649840
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
|
||
import UIKit | ||
|
||
// MARK: - FolioReaderScrollDirection | ||
|
||
/** | ||
Defines the Reader scrolling direction | ||
*/ | ||
|
@@ -37,12 +39,54 @@ public enum FolioReaderScrollDirection: Int { | |
} | ||
} | ||
|
||
// MARK: - ClassBasedOnCLickListener | ||
|
||
/** | ||
A `ClassBasedOnCLickListener` takes a closure which is performed if a given html `class` is clicked. The closure will reveice the content of the specified parameter. | ||
|
||
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 { | ||
|
||
/// The name of the URL scheme which should be used. Note: Make sure that the given `String` is a valid as scheme name. | ||
public var schemeName : String | ||
|
||
/// The HTML class name to which the listener should be added. | ||
public var className : String | ||
|
||
/// The name of the parameter whose content should be passed to the `onClickAction` action | ||
public var parameterName : String | ||
|
||
/// The closure which will be called if the specified class was clicked. | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. In addition we would change the |
||
self.schemeName = schemeName.lowercaseString | ||
self.className = className | ||
self.parameterName = parameterName | ||
self.onClickAction = onClickAction | ||
} | ||
} | ||
|
||
// MARK: - FolioReaderConfig | ||
|
||
/** | ||
Defines the Reader custom configuration | ||
*/ | ||
public class FolioReaderConfig: NSObject { | ||
|
||
|
||
// MARK: ClassBasedOnCLickListener | ||
|
||
/** | ||
Array of `ClassBasedOnCLickListener` objects. A `ClassBasedOnCLickListener` takes a closure which is performed if a given html `class` is clicked. The closure will reveice the content of the specified parameter. | ||
|
||
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 var classBasedOnClickListeners = [ClassBasedOnCLickListener]() | ||
|
||
// MARK: Colors | ||
|
||
/// Base header custom TintColor | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,7 +152,6 @@ var callHighlightURL = function(elm) { | |
window.location = URLBase + encodeURIComponent(currentHighlightRect); | ||
} | ||
|
||
|
||
// Reading time | ||
function getReadingTime() { | ||
var text = document.body.innerText; | ||
|
@@ -579,4 +578,22 @@ function wrappingSentencesWithinPTags(){ | |
} | ||
|
||
guessSenetences(); | ||
} | ||
|
||
// Class based onClick listener | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about it, maybe we could use the JavaScript Reference: 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 commentThe reason will be displayed to describe this comment to others. Learn more. More option sound good, I'll give it a try. |
||
for (elementIndex = 0; elementIndex < elements.length; elementIndex++) { | ||
var element = elements[elementIndex]; | ||
// Get the content from the given parameterName | ||
var parameterContent = element.getAttribute(parameterName); | ||
// Add the on click logic | ||
element.setAttribute("onclick", "onClassBasedListenerClick(\"" + schemeName + "\", \"" + parameterContent + "\");"); | ||
} | ||
} | ||
|
||
var onClassBasedListenerClick = function(schemeName, parameterContent) { | ||
window.location = schemeName + "://" + encodeURIComponent(parameterContent); | ||
} |
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 beClassBasedOnClickListener
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 useOnClickListener
or sth. similiar wouln't be clear about it's function and usage.What name do you have in mind?