コード例 #1
0
 /**
  * Determines type of item based on its properties.
  * @return {!ItemType} Type of the item
  */
 type() {
   if (referenceCollection.isCitation(this.href)) {
     return ItemType.reference
   } else if (this.target.tagName === 'IMG' && this.target.getAttribute( 'data-image-gallery' ) === 'true') {
     return ItemType.image
   } else if (this.target.tagName === 'SPAN' && this.target.parentElement.getAttribute( 'data-data-image-gallery' ) === 'true') {
     return ItemType.imagePlaceholder
   } else if (this.href) {
     return ItemType.link
   }
   return ItemType.unknown
 }
コード例 #2
0
function handleReference( href, linkNode, linkText ) {
    var targetElem = document.getElementById(href.slice(1));
    if (linkNode && pagelib.ReferenceCollection.isCitation(href)){
        var adjacentReferences = pagelib.ReferenceCollection.collectNearbyReferences(document, linkNode);
        bridge.sendMessage( 'referenceClicked', adjacentReferences );
    } else if ( href.slice(1, 5).toLowerCase() === "cite" ) {
        try {
            var refTexts = targetElem.getElementsByClassName( "reference-text" );
            if ( refTexts.length > 0 ) {
                targetElem = refTexts[0];
            }
            bridge.sendMessage( 'referenceClicked', { "selectedIndex": 0, "referencesGroup": [ { "html": targetElem.innerHTML, "text": linkText } ] });
        } catch (e) {
            targetElem.scrollIntoView();
        }
    } else {
        if ( targetElem === null ) {
            console.log( "reference target not found: " + href );
        } else {
            // If it is a link to another anchor in the current page, just scroll to it
            targetElem.scrollIntoView();
        }
    }
}
コード例 #3
0
const sendMessageForReferenceWithTarget = target => {
  const nearbyReferences = referenceCollection.collectNearbyReferences( document, target )
  nearbyReferences.referencesGroup.forEach(reformatReferenceItemRectToBridgeToCGRect)
  window.webkit.messageHandlers.referenceClicked.postMessage(nearbyReferences)
}