This repository has been archived by the owner on Nov 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 772
Custom click listener - closes #132 #137
Merged
hebertialmeida
merged 14 commits into
FolioReader:master
from
smartmobilefactory:issue/132
Sep 15, 2016
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4c1c3f0
add listenerBlock and listernerDirectory in ReaderConfig.
PanajotisMaroungas 4dc7a12
Minor refactoring
PanajotisMaroungas 1be980e
Merge with solved conflicts
f086630
Merge with solved conflicts
38bb056
Merge branch 'feature/StoryboardSupport' of github.com:smartmobilefac…
9e9f825
Provide external code access to custom class based on click listeners
12bda49
Fix typo
4d888f1
Fix typo in ClassBasedOnCLickListener
bff575e
Add a simple ClassBasedOnClickListener example to the StoryboardExamp…
41b52cc
Use valid URL scheme name
ac27c5d
Fix not working highlight click if using a class based click listener
3350432
Merge branch 'master' of github.com:FolioReader/FolioReaderKit into i…
5467a1a
Escape parameter content of class based onclick listeners
2649840
Refactor class based on click listener to use `querySelector(All)`
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,14 +145,14 @@ var getRectForSelectedText = function(elm) { | |
// Method that call that a hightlight was clicked | ||
// with URL scheme and rect informations | ||
var callHighlightURL = function(elm) { | ||
var URLBase = "highlight://"; | ||
event.stopPropagation(); | ||
var URLBase = "highlight://"; | ||
var currentHighlightRect = getRectForSelectedText(elm); | ||
thisHighlight = elm; | ||
|
||
window.location = URLBase + encodeURIComponent(currentHighlightRect); | ||
} | ||
|
||
|
||
// Reading time | ||
function getReadingTime() { | ||
var text = document.body.innerText; | ||
|
@@ -579,4 +579,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 + "\", \"" + encodeURIComponent(parameterContent) + "\");"); | ||
} | ||
} | ||
|
||
var onClassBasedListenerClick = function(schemeName, parameterContent) { | ||
window.location = schemeName + "://" + parameterContent; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
toquerySelector
and maybe add a newBool
attributeselectAll
withtrue
by default, so I can choose to select only first element or all elements. What do you think?