|
8 | 8 |
|
9 | 9 | import UIKit |
10 | 10 |
|
| 11 | +// MARK: - FolioReaderScrollDirection |
| 12 | + |
11 | 13 | /** |
12 | 14 | Defines the Reader scrolling direction |
13 | 15 | */ |
@@ -37,12 +39,58 @@ public enum FolioReaderScrollDirection: Int { |
37 | 39 | } |
38 | 40 | } |
39 | 41 |
|
| 42 | +// MARK: - ClassBasedOnClickListener |
| 43 | + |
| 44 | +/** |
| 45 | +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. |
| 46 | + |
| 47 | +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. |
| 48 | + |
| 49 | +*/ |
| 50 | +public struct ClassBasedOnClickListener { |
| 51 | + |
| 52 | + /// The name of the URL scheme which should be used. Note: Make sure that the given `String` is a valid as scheme name. |
| 53 | + public var schemeName : String |
| 54 | + |
| 55 | + /// The query selector for the elements which the listener should be added to. See https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector for further information about query selectors. |
| 56 | + public var querySelector : String |
| 57 | + |
| 58 | + /// The name of the attribute whose content should be passed to the `onClickAction` action. |
| 59 | + public var attributeName : String |
| 60 | + |
| 61 | + /// Whether the listener should be added to all found elements or only to the first one. See https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelectorAll for further information. The default value is `true`. |
| 62 | + public var selectAll : Bool |
| 63 | + |
| 64 | + /// The closure which will be called if the specified class was clicked. |
| 65 | + public var onClickAction : ((parameterContent: String?) -> Void) |
| 66 | + |
| 67 | + /// Initializes a `ClassBasedOnClickListener` instance. Append it to the `classBasedOnClickListeners` property from the `FolioReaderConfig` to receive on click events. The default `selectAll` value is `true`. |
| 68 | + public init(schemeName: String, querySelector: String, attributeName: String, selectAll: Bool = true, onClickAction: ((attributeContent: String?) -> Void)) { |
| 69 | + self.schemeName = schemeName.lowercaseString |
| 70 | + self.querySelector = querySelector |
| 71 | + self.attributeName = attributeName |
| 72 | + self.selectAll = selectAll |
| 73 | + self.onClickAction = onClickAction |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +// MARK: - FolioReaderConfig |
40 | 78 |
|
41 | 79 | /** |
42 | 80 | Defines the Reader custom configuration |
43 | 81 | */ |
44 | 82 | public class FolioReaderConfig: NSObject { |
45 | | - |
| 83 | + |
| 84 | + // MARK: ClassBasedOnClickListener |
| 85 | + |
| 86 | + /** |
| 87 | + 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. |
| 88 | + |
| 89 | + 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. |
| 90 | + |
| 91 | + */ |
| 92 | + public var classBasedOnClickListeners = [ClassBasedOnClickListener]() |
| 93 | + |
46 | 94 | // MARK: Colors |
47 | 95 |
|
48 | 96 | /// Base header custom TintColor |
|
0 commit comments