From 9aedc9dc5228aec37354500992570adce83801cb Mon Sep 17 00:00:00 2001 From: Amit Moryossef Date: Wed, 7 Jun 2017 23:24:27 +0300 Subject: [PATCH] refactor(platform): enforce direction values (#11823) * fix(lint): unused import * feat(platform): enforce direction value * style(platform): make sure not to change indentation * refactor(platform): rename PageDirection to DocumentDirection --- src/platform/platform.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/platform/platform.ts b/src/platform/platform.ts index a67c0f15d6..5a252505e4 100644 --- a/src/platform/platform.ts +++ b/src/platform/platform.ts @@ -4,6 +4,7 @@ import { getCss, isTextInput } from '../util/dom'; import { QueryParams } from './query-params'; import { removeArrayItem } from '../util/util'; +export type DocumentDirection = 'ltr' | 'rtl'; /** * @name Platform @@ -34,7 +35,7 @@ export class Platform { private _win: Window; private _doc: HTMLDocument; private _versions: {[name: string]: PlatformVersion} = {}; - private _dir: string; + private _dir: DocumentDirection; private _lang: string; private _ua: string; private _qp = new QueryParams(); @@ -313,11 +314,11 @@ export class Platform { * `` or ``. This method is useful if the * direction needs to be dynamically changed per user/session. * [W3C: Structural markup and right-to-left text in HTML](http://www.w3.org/International/questions/qa-html-dir) - * @param {string} dir Examples: `rtl`, `ltr` + * @param {DocumentDirection} dir Examples: `rtl`, `ltr` * @param {boolean} updateDocument */ - setDir(dir: string, updateDocument: boolean) { - this._dir = dir = (dir || '').toLowerCase(); + setDir(dir: DocumentDirection, updateDocument: boolean) { + this._dir = dir; this.isRTL = (dir === 'rtl'); if (updateDocument !== false) { @@ -330,9 +331,9 @@ export class Platform { * We recommend the app's `index.html` file already has the correct `dir` * attribute value set, such as `` or ``. * [W3C: Structural markup and right-to-left text in HTML](http://www.w3.org/International/questions/qa-html-dir) - * @returns {string} + * @returns {DocumentDirection} */ - dir(): string { + dir(): DocumentDirection { return this._dir; } @@ -1181,7 +1182,7 @@ export function setupPlatform(doc: HTMLDocument, platformConfigs: {[key: string] const docElement = doc.documentElement; plt.setDocument(doc); const dir = docElement.dir; - plt.setDir(dir || 'ltr', !dir); + plt.setDir(dir === 'rtl' ? 'rtl' : 'ltr', !dir); plt.setLang(docElement.lang, false); // set css properties