Skip to content

Commit

Permalink
Merge pull request #2295 from wikimedia/useConsolidatedRefCollection
Browse files Browse the repository at this point in the history
Use new pagelib reference collection bits.
  • Loading branch information
joewalsh committed Jun 29, 2018
2 parents 51504da + c0966dd commit 8654d11
Show file tree
Hide file tree
Showing 8 changed files with 1,006 additions and 1,223 deletions.
173 changes: 31 additions & 142 deletions Wikipedia/assets/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Wikipedia/assets/preview.js

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions Wikipedia/assets/wikimedia-page-library-transform.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Wikipedia/assets/wikimedia-page-library-transform.css.map

Large diffs are not rendered by default.

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 = {
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.

0 comments on commit 8654d11

Please sign in to comment.