Skip to content
This repository was archived by the owner on Jun 28, 2021. It is now read-only.

Commit 028b596

Browse files
naveed-ahmadmmahalwy
authored andcommitted
Text based fonts (#672)
* added word rendering comparision * regenerated surah name icon fonts using private unicode area * render text fonts for supported browsers only * moved user agent to options tree * fixed lint breaks * fixed floating of ayah number word * added empty space after 'word' word :)
1 parent 94ca8f6 commit 028b596

File tree

1,227 files changed

+375
-307
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,227 files changed

+375
-307
lines changed

src/components/Verse/index.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import React, { Component, PropTypes } from 'react';
22
import Link from 'react-router/lib/Link';
33
import { Element } from 'react-scroll';
4+
import { connect } from 'react-redux';
45

56
import { verseType, matchType, surahType } from 'types';
67
import Share from 'components/Share';
78
import Copy from 'components/Copy';
89
import LocaleFormattedMessage from 'components/LocaleFormattedMessage';
910
import Word from 'components/Word';
1011
import Translation from 'components/Translation';
11-
1212
import debug from 'helpers/debug';
1313

1414
const styles = require('./style.scss');
1515

16-
export default class Verse extends Component {
16+
class Verse extends Component {
1717
static propTypes = {
1818
isSearched: PropTypes.bool,
1919
verse: verseType.isRequired,
@@ -41,7 +41,8 @@ export default class Verse extends Component {
4141
tooltip: PropTypes.string,
4242
currentWord: PropTypes.number, // gets passed in an integer, null by default
4343
iscurrentVerse: PropTypes.bool,
44-
currentVerse: PropTypes.string
44+
currentVerse: PropTypes.string,
45+
userAgent: PropTypes.func
4546
};
4647

4748

@@ -128,9 +129,10 @@ export default class Verse extends Component {
128129
}
129130

130131
renderText() {
131-
const { verse, tooltip, currentVerse, isPlaying, audioActions, isSearched } = this.props;
132+
const { verse, tooltip, currentVerse, isPlaying, audioActions, isSearched, userAgent } = this.props; // eslint-disable-line max-len
132133
// NOTE: Some 'word's are glyphs (jeem). Not words and should not be clicked for audio
133134
let wordAudioPosition = -1;
135+
const renderText = userAgent.isChrome || userAgent.isOpera || userAgent.isBot;
134136

135137
const text = verse.words.map(word => ( // eslint-disable-line
136138
<Word
@@ -142,18 +144,15 @@ export default class Verse extends Component {
142144
audioActions={audioActions}
143145
audioPosition={word.wordId ? wordAudioPosition += 1 : null}
144146
isSearched={isSearched}
147+
useTextFont={renderText}
145148
/>
146149
));
147150

148151
return (
149152
<h1 className={`${styles.font} text-right text-arabic`}>
150-
{text}
151-
<p
152-
dir="rtl"
153-
lang="ar"
154-
className={`text-tashkeel text-p${verse.pageNumber}`}
155-
dangerouslySetInnerHTML={{ __html: verse.textMadani }}
156-
/>
153+
<p>
154+
{text}
155+
</p>
157156
</h1>
158157
);
159158
}
@@ -292,3 +291,7 @@ export default class Verse extends Component {
292291
);
293292
}
294293
}
294+
295+
export default connect(state => ({
296+
userAgent: state.options.userAgent
297+
}))(Verse);

src/components/Verse/style.scss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
text-align: right;
7474
float: left;
7575

76-
b{
76+
b, span{
7777
float: right;
7878
border-color: transparent;
7979
border-width: 0px 0px 1px 0px;
@@ -106,6 +106,14 @@
106106
}
107107
}
108108

109+
p{
110+
display: block;
111+
clear: both;
112+
text-align: right;
113+
direction: rtl;
114+
float: right;
115+
}
116+
109117
@media (max-width: $screen-xs-max) {
110118
font-size: 300%;
111119
line-height: 130%;
@@ -134,3 +142,4 @@
134142
width: 100%;
135143
margin: 0px auto;
136144
}
145+

src/components/Word/index.js

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React, { Component, PropTypes } from 'react';
22
import bindTooltip from 'utils/bindTooltip';
3+
import { zeroPad } from 'helpers/StringHelpers';
4+
35
/* eslint-disable no-unused-vars */
46
const CHAR_TYPE_WORD = 'word';
57
const CHAR_TYPE_END = 'end';
@@ -15,7 +17,8 @@ export default class Word extends Component {
1517
audioPosition: PropTypes.number,
1618
currentVerse: PropTypes.string.isRequired,
1719
isPlaying: PropTypes.bool,
18-
isSearched: PropTypes.bool
20+
isSearched: PropTypes.bool,
21+
useTextFont: PropTypes.bool // tmp change to compare text and code based rendering
1922
};
2023

2124
buildTooltip = (word, tooltip) => {
@@ -58,27 +61,40 @@ export default class Word extends Component {
5861
}
5962

6063
render() {
61-
const { tooltip, word, currentVerse, isPlaying, audioPosition } = this.props;
64+
const { tooltip, word, currentVerse, isPlaying, audioPosition, useTextFont } = this.props;
6265

63-
let id = null;
66+
let text;
67+
let spacer;
6468
const highlight = currentVerse === word.verseKey && isPlaying ? 'highlight' : '';
65-
const className = `${word.className} ${highlight} ${word.highlight ? word.highlight : ''}`;
69+
const className = `${useTextFont ? 'text-' : ''}${word.charType === CHAR_TYPE_WORD ? word.className : 'p0'} ${word.charType} ${highlight} ${word.highlight ? word.highlight : ''}`;
70+
const id = `word-${word.verseKey.replace(/:/, '-')}-${audioPosition || word.position}`;
71+
72+
if (word.charType === CHAR_TYPE_END) {
73+
text = zeroPad(word.verseKey.split(':')[1], 3, 0);
74+
} else if (!useTextFont || word.charType === CHAR_TYPE_PAUSE) {
75+
text = word.codeV3;
76+
} else {
77+
text = word.textMadani;
78+
}
6679

6780
if (word.charType === CHAR_TYPE_WORD) {
68-
id = `word-${word.verseKey.replace(/:/, '-')}-${audioPosition || word.position}`;
81+
spacer = '&nbsp;';
6982
}
7083

7184
return (
72-
<b // eslint-disable-line
73-
{ ...bindTooltip}
74-
key={word.code}
75-
id={id}
76-
onDoubleClick={this.handleSegmentPlay}
77-
onClick={this.handleWordPlay}
78-
className={`${className} pointer`}
79-
title={this.buildTooltip(word, tooltip)}
80-
dangerouslySetInnerHTML={{ __html: word.code }}
81-
/>
85+
<span>
86+
<b // eslint-disable-line
87+
{ ...bindTooltip}
88+
key={word.code}
89+
id={id}
90+
onDoubleClick={this.handleSegmentPlay}
91+
onClick={this.handleWordPlay}
92+
className={`${className} pointer`}
93+
title={this.buildTooltip(word, tooltip)}
94+
dangerouslySetInnerHTML={{ __html: text }}
95+
/>
96+
<small dangerouslySetInnerHTML={{ __html: spacer }} />
97+
</span>
8298
);
8399
}
84100

src/containers/App/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import config from 'config';
1414
import metricsConfig from 'helpers/metrics';
1515
import Footer from 'components/Footer';
1616
import NoScript from 'components/NoScript';
17-
import FontStyles from 'components/FontStyles';
1817
import { removeMedia } from 'redux/actions/media';
1918

2019
import authConnect from './connect';
@@ -58,7 +57,6 @@ class App extends Component {
5857
return (
5958
<div>
6059
<Helmet {...config.app.head} />
61-
<FontStyles />
6260
<NoScript>
6361
<div className="row noscript-warning">
6462
<div className="col-md-12">

src/helpers/StringHelpers.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function zeroPad(num, places, padChar = '0') { // eslint-disable-line
2+
const zero = (places - num.toString().length) + 1;
3+
4+
return Array(+(zero > 0 && zero)).join(padChar) + num;
5+
}

src/redux/actions/audioplayer.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
SET_USER_AGENT,
32
SET_CURRENT_FILE,
43
SET_CURRENT_WORD,
54
PLAY_CURRENT_WORD,
@@ -13,13 +12,6 @@ import {
1312
BUILD_ON_CLIENT,
1413
UPDATE } from 'redux/constants/audioplayer.js';
1514

16-
export function setUserAgent(userAgent) {
17-
return {
18-
type: SET_USER_AGENT,
19-
userAgent
20-
};
21-
}
22-
2315
export function setCurrentFile(file) {
2416
return {
2517
type: SET_CURRENT_FILE,

src/redux/actions/options.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
LOAD_RECITERS,
55
LOAD_RECITERS_SUCCESS,
66
LOAD_RECITERS_FAIL,
7+
SET_USER_AGENT,
78
LOAD_TRANSLATIONS,
89
LOAD_TRANSLATIONS_SUCCESS,
910
LOAD_TRANSLATIONS_FAIL
@@ -30,6 +31,13 @@ export const loadRecitations = () => ({
3031
promise: client => client.get('/api/v3/options/recitations')
3132
});
3233

34+
export function setUserAgent(userAgent) {
35+
return {
36+
type: SET_USER_AGENT,
37+
userAgent
38+
};
39+
}
40+
3341
export const loadTranslations = () => ({
3442
types: [LOAD_TRANSLATIONS, LOAD_TRANSLATIONS_SUCCESS, LOAD_TRANSLATIONS_FAIL],
3543
promise: client => client.get('/api/v3/options/translations')

src/redux/constants/audioplayer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export const SET_USER_AGENT = '@@quran/audioplayer/SET_USER_AGENT';
21
export const SET_CURRENT_FILE = '@@quran/audioplayer/SET_CURRENT_FILE';
32
export const SET_CURRENT_WORD = '@@quran/audioplayer/SET_CURRENT_WORD';
43
export const PLAY_CURRENT_WORD = '@@quran/audioplayer/PLAY_CURRENT_WORD';

src/redux/constants/options.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export const SET_OPTION = '@@quran/options/SET_OPTION';
22
export const TOGGLE_NIGHT_MODE = '@@quran/options/TOGGLE_NIGHT_MODE';
3+
export const SET_USER_AGENT = '@@quran/options/SET_USER_AGENT';
34

45
export const LOAD_RECITERS = '@@quran/verses/LOAD_RECITERS';
56
export const LOAD_RECITERS_SUCCESS = '@@quran/verses/LOAD_RECITERS_SUCCESS';

src/redux/modules/audioplayer.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { buildSegments, extractSegments } from 'helpers/buildSegments';
44
import debug from 'helpers/debug';
55

66
import {
7-
SET_USER_AGENT,
87
SET_CURRENT_FILE,
98
SET_CURRENT_WORD,
109
PLAY_CURRENT_WORD,
@@ -30,7 +29,6 @@ export { NEXT, SET_AYAH };
3029

3130
const initialState = {
3231
files: {},
33-
userAgent: null,
3432
currentFile: null,
3533
currentVerse: null,
3634
currentWord: null,
@@ -143,13 +141,6 @@ export default function reducer(state = initialState, action = {}) {
143141
...payload
144142
};
145143
}
146-
case SET_USER_AGENT: {
147-
const { userAgent } = action;
148-
return {
149-
...state,
150-
userAgent
151-
};
152-
}
153144
case PLAY: {
154145
if (state.currentFile) {
155146
state.currentFile.play();

0 commit comments

Comments
 (0)