diff --git a/src/components/Translation/index.js b/src/components/Translation/index.js index 98a316429..172f85baf 100644 --- a/src/components/Translation/index.js +++ b/src/components/Translation/index.js @@ -1,23 +1,55 @@ /* eslint-disable react/prefer-stateless-function */ import React, { Component, PropTypes } from 'react'; +import { connect } from 'react-redux'; import { translationType } from 'types'; +import { loadFootNote } from 'redux/actions/footNote'; const styles = require('./style.scss'); -export default class Translation extends Component { +class Translation extends Component { static propTypes = { translation: translationType.isRequired, - index: PropTypes.number + index: PropTypes.number, + loadFootNote: PropTypes.func.isRequired, }; + componentDidMount() { + const { index } = this.props; + let trans; + + if (__CLIENT__) { + trans = document.getElementById(`trans${index}`).children[1]; // eslint-disable-line no-undef + trans.addEventListener('click', this.fetchFootNote, true); + } + } + + componentWillUnmount() { + const { index } = this.props; + let trans; + + if (__CLIENT__) { + trans = document.getElementById(`trans${index}`).children[1]; // eslint-disable-line no-undef + trans.removeEventListener('click', this.fetchFootNote, true); + } + } + + fetchFootNote = (event) => { + const { loadFootNote } = this.props; // eslint-disable-line no-shadow + + if (event.target.nodeName === 'SUP' && event.target.attributes.foot_note) { + event.preventDefault(); + loadFootNote(event.target.attributes.foot_note.value); + } + } + render() { const { translation, index } = this.props; const lang = translation.languageName; const isArabic = lang === 'arabic'; return ( -
+

{translation.resourceName}

({}), // eslint-disable-line no-unused-vars + { loadFootNote } +)(Translation); diff --git a/src/components/Verse/index.js b/src/components/Verse/index.js index a92aa3852..dcca09fc3 100644 --- a/src/components/Verse/index.js +++ b/src/components/Verse/index.js @@ -95,11 +95,10 @@ class Verse extends Component { renderTranslations() { const { verse, match } = this.props; - const array = match || verse.translations || []; - return array.map((translation, index) => ( - + return array.map(translation => ( + )); } diff --git a/src/containers/App/index.js b/src/containers/App/index.js index 7caa8e740..4d533d6be 100644 --- a/src/containers/App/index.js +++ b/src/containers/App/index.js @@ -15,6 +15,11 @@ import metricsConfig from 'helpers/metrics'; import Footer from 'components/Footer'; import NoScript from 'components/NoScript'; import { removeMedia } from 'redux/actions/media'; +import { removeFootNote } from 'redux/actions/footNote'; + +import Loader from 'quran-components/lib/Loader'; + +import { footNoteType } from 'types'; import authConnect from './connect'; @@ -28,10 +33,13 @@ class App extends Component { content: PropTypes.object }).isRequired, removeMedia: PropTypes.func.isRequired, + removeFootNote: PropTypes.func.isRequired, children: PropTypes.element, main: PropTypes.element, nav: PropTypes.element, sidebar: PropTypes.element, + footNote: footNoteType, + loadingFootNote: PropTypes.bool }; static contextTypes = { @@ -49,10 +57,20 @@ class App extends Component { sidebar, children, media, + footNote, + loadingFootNote, removeMedia, // eslint-disable-line no-shadow + removeFootNote, // eslint-disable-line no-shadow ...props } = this.props; debug('component:APPLICATION', 'Render'); + let footNoteText; + + if (footNote) { + footNoteText = footNote.text; + } else { + footNoteText = ; + } return (
@@ -91,6 +109,7 @@ class App extends Component { {children || main}