Skip to content

Commit f685bd0

Browse files
Merge pull request #211 from technote-space/feature/#209
feat: support rtl (#209)
2 parents 573ec0a + f6845c9 commit f685bd0

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

__tests__/functions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ describe('getCss', () => {
162162
duration: ZERO_SEC,
163163
'padding_bottom': 'a',
164164
cssFilter: css => css,
165+
rtl: true,
165166
});
166167
expect(css).toHaveProperty('background-position');
167-
expect(css['background-position']).toBe('left -100% center');
168+
expect(css['background-position']).toBe('right 0 center');
168169
});
169170

170171
it('should get stripe css', () => {

bin/gh-pages/plugin.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,17 @@ $(() => {
7575
<p>
7676
Dolly'll never go away again
7777
</p>
78-
78+
<p style="direction: rtl">
79+
<bdo lang="ar" dir="rtl">
80+
<span class="marker-animation" data-ma_rtl="true" data-ma_repeat="true">
81+
هذا اختبار اللغة العربية.
82+
</span>
83+
هل هذه المكتبة تعمل بشكل صحيح؟
84+
<span class="marker-animation" data-ma_rtl="true" data-ma_color="#00ffcc">
85+
إذا كان لديك أي مشاكل ، يرجى الإبلاغ عنها.
86+
</span>
87+
</bdo>
88+
</p>
7989
<p>
8090
<a class="btn btn-light-blue reset-animation">Reset</a>
8191
</p>

src/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ export const SETTINGS_DEFAULTS = {
1212
cssFilter: function(css) {
1313
return css;
1414
},
15+
rtl: false,
1516
};

src/functions.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,31 @@ export const isStatic = options => options.stripe || (ZERO_SEC === options.delay
6161
*/
6262
export const getCss = options => options.cssFilter(options.stripe ? getStripeCss(options) : getMarkerCss(options));
6363

64+
/**
65+
* @param {object} options options
66+
* @returns {string} direction
67+
*/
68+
const getDirection = options => options.rtl ? 'right' : 'left';
69+
70+
/**
71+
* @param {object} options options
72+
* @returns {string} percentage
73+
*/
74+
const getStartPercentage = options => options.rtl ? '0' : '-100%';
75+
76+
/**
77+
* @param {object} options options
78+
* @returns {string} percentage
79+
*/
80+
const getGoalPercentage = options => options.rtl ? '100%' : '0';
81+
6482
/**
6583
* @param {object} options options
6684
* @returns {object} css
6785
*/
6886
const getCommonCss = options => Object.assign({
6987
'display': 'inline',
70-
'background-position': 'left 0 center',
88+
'background-position': `${getDirection(options)} ${getGoalPercentage(options)} center`,
7189
'padding-bottom': options.padding_bottom,
7290
}, options.font_weight ? {
7391
'font-weight': options.font_weight,
@@ -82,7 +100,7 @@ const getMarkerCss = options => Object.assign({}, getCommonCss(options), {
82100
'background-repeat': 'repeat-x',
83101
'background-image': `linear-gradient(to right, rgba(255,255,255,0) 50%, ${options.color} 50%)`,
84102
}, isStatic(options) ? {
85-
'background-position': 'left -100% center',
103+
'background-position': `${getDirection(options)} ${getStartPercentage(options)} center`,
86104
} : {});
87105

88106
/**
@@ -133,7 +151,7 @@ export const stop = target => {
133151
export const onInView = (target, options) => {
134152
target.stop(true, true).css({
135153
transition: `background-position ${options.duration} ${options.function} ${options.delay}`,
136-
'background-position': 'left -100% center',
154+
'background-position': `${getDirection(options)} ${getStartPercentage(options)} center`,
137155
});
138156
if (!options.repeat) {
139157
stop(target);

0 commit comments

Comments
 (0)