Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new pagelib reference collection bits. #2295

Merged
merged 17 commits into from Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 23 additions & 4 deletions www/js/clickHandling.js
@@ -1,4 +1,4 @@
const refs = require('./refs')
const referenceCollection = require('wikimedia-page-library').ReferenceCollection
const utilities = require('./utilities')
const tableCollapser = require('wikimedia-page-library').CollapseTable

Expand Down Expand Up @@ -29,7 +29,7 @@ class ClickedItem {
* @return {!ItemType} Type of the item
*/
type() {
if (refs.isCitation(this.href)) {
if (referenceCollection.isCitation(this.href)) {
return ItemType.reference
} else if (this.target.tagName === 'IMG' && this.target.getAttribute( 'data-image-gallery' ) === 'true') {
return ItemType.image
Expand Down Expand Up @@ -110,12 +110,31 @@ const sendMessageForImagePlaceholderWithTarget = innerPlaceholderSpan => {
})
}

/**
* Use "X", "Y", "Width" and "Height" keys so we can use CGRectMakeWithDictionaryRepresentation in
* native land to convert to CGRect.
* @param {!ReferenceItem} referenceItem
* @return {void}
*/
const reformatReferenceItemRectToBridgeToCGRect = referenceItem => {
referenceItem.rect = {
Copy link
Contributor Author

@montehurd montehurd May 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was needed so the pagelib didn't have to know about iOS specific CGRect bridging details. The pagelib keeps the rect as a standard JS ClientRect.

X: referenceItem.rect.left,
Y: referenceItem.rect.top,
Width: referenceItem.rect.width,
Height: referenceItem.rect.height
}
}

/**
* Sends message for a reference click.
* @param {!Element} target an anchor element
* @return {void}
*/
const sendMessageForReferenceWithTarget = target => refs.sendNearbyReferences( target )
const sendMessageForReferenceWithTarget = target => {
const nearbyReferences = referenceCollection.collectNearbyReferences( document, target )
nearbyReferences.referencesGroup.forEach(reformatReferenceItemRectToBridgeToCGRect)
window.webkit.messageHandlers.referenceClicked.postMessage(nearbyReferences)
}

/**
* Handler for the click event.
Expand Down Expand Up @@ -154,4 +173,4 @@ const handleClickEvent = event => {
document.addEventListener('click', event => {
event.preventDefault()
handleClickEvent(event)
}, false)
}, false)
130 changes: 0 additions & 130 deletions www/js/refs.js

This file was deleted.