From 6d49ef0dac78eef45a6b5bbfc5abe52ff193587f Mon Sep 17 00:00:00 2001 From: Deathamns Date: Tue, 21 Oct 2014 16:45:54 +0200 Subject: [PATCH] Avoid using Chrome's @@bidi_* type i18n messages ... for the sake of portability. When including vapi-common.js in an HTML file, then the body element there will have a "dir" attribute filled with the current locale's direction (ltr or rtl). The following languages are considered right-to-left: ar, he, fa, ps, ur. Everything else is left-to-right. After the "dir" attribute is set, we can decide in CSS which elements should have different styling for rtl languages (e.g., body[dir=rtl] #id). --- src/1p-filters.html | 2 +- src/3p-filters.html | 2 +- src/about.html | 2 +- src/asset-viewer.html | 2 +- src/background.html | 4 +- src/css/3p-filters.css | 38 ++++++++++----- src/css/common.css | 30 +++++++----- src/css/dashboard-common.css | 6 --- src/css/dashboard.css | 68 +++++++++++++++++++++++++++ src/css/popup.css | 10 ++-- src/css/stats.css | 82 +++++++++++++++++++++++++++++++++ src/dashboard.html | 89 ++++-------------------------------- src/js/dashboard.js | 4 +- src/js/messaging.js | 2 +- src/js/vapi-client.js | 2 +- src/js/vapi-common.js | 18 ++++++-- src/popup.html | 2 +- src/settings.html | 2 +- src/stats.html | 88 +---------------------------------- src/whitelist.html | 2 +- 20 files changed, 241 insertions(+), 214 deletions(-) create mode 100644 src/css/dashboard.css create mode 100644 src/css/stats.css diff --git a/src/1p-filters.html b/src/1p-filters.html index 957b3d857..7c959d02b 100644 --- a/src/1p-filters.html +++ b/src/1p-filters.html @@ -1,7 +1,7 @@ - + µBlock — Your filters diff --git a/src/3p-filters.html b/src/3p-filters.html index 9a424bab0..5e6198add 100644 --- a/src/3p-filters.html +++ b/src/3p-filters.html @@ -1,7 +1,7 @@ - + µBlock — Ubiquitous rules diff --git a/src/about.html b/src/about.html index 081b981de..20a47c172 100644 --- a/src/about.html +++ b/src/about.html @@ -1,7 +1,7 @@ - + µBlock — About diff --git a/src/asset-viewer.html b/src/asset-viewer.html index b3b6ffe8e..103b9d89e 100644 --- a/src/asset-viewer.html +++ b/src/asset-viewer.html @@ -1,7 +1,7 @@ - + µBlock — Asset - + +
- µBlock - - - - - - + + + + + + +
diff --git a/src/js/dashboard.js b/src/js/dashboard.js index 8040d92d4..6779f2735 100644 --- a/src/js/dashboard.js +++ b/src/js/dashboard.js @@ -29,7 +29,7 @@ /******************************************************************************/ var loadDashboardPanel = function(tab, q) { - var tabButton = uDom('[data-dashboard-panel-url="' + tab + '"]'); + var tabButton = uDom('[href="#' + tab + '"]'); if ( !tabButton ) { return; } @@ -42,7 +42,7 @@ var loadDashboardPanel = function(tab, q) { /******************************************************************************/ var onTabClickHandler = function(e) { - loadDashboardPanel(uDom(this).attr('data-dashboard-panel-url')); + loadDashboardPanel(this.hash.slice(1)); e.preventDefault(); }; diff --git a/src/js/messaging.js b/src/js/messaging.js index 878f0290f..ee3890fae 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -377,7 +377,7 @@ var onMessage = function(request, sender, callback) { case 'elementPickerArguments': response = { i18n: { - '@@bidi_dir': vAPI.i18n('@@bidi_dir'), + '@@bidi_dir': document.body.getAttribute('dir'), create: vAPI.i18n('pickerCreate'), pick: vAPI.i18n('pickerPick'), quit: vAPI.i18n('pickerQuit'), diff --git a/src/js/vapi-client.js b/src/js/vapi-client.js index 6de84f66f..34153cc09 100644 --- a/src/js/vapi-client.js +++ b/src/js/vapi-client.js @@ -38,7 +38,7 @@ var messagingConnector = function(response) { // Safari bug // Deleting the response.requestId below (only in some cases, probably // when frames are present on the page) will remove it from all the - // following messages too, however with the following line it won't + // following messages too, however with the following line it won't. vAPI.safari && console.log; delete vAPI.messaging.listeners[response.requestId]; diff --git a/src/js/vapi-common.js b/src/js/vapi-common.js index 752cb2b0a..3ece2ad31 100644 --- a/src/js/vapi-common.js +++ b/src/js/vapi-common.js @@ -5,6 +5,14 @@ window.vAPI = window.vAPI || {}; +// http://www.w3.org/International/questions/qa-scripts#directions +var setScriptDirection = function(langugae) { + document.body.setAttribute( + 'dir', + ~['ar', 'he', 'fa', 'ps', 'ur'].indexOf(langugae) ? 'rtl' : 'ltr' + ); +}; + vAPI.download = function(details) { if (!details.url) { return; @@ -40,6 +48,8 @@ if (window.chrome) { vAPI.i18n = function(s) { return chrome.i18n.getMessage(s) || s; }; + + setScriptDirection(vAPI.i18n('@@ui_locale')); } else if (window.safari) { vAPI.getURL = function(path) { return safari.extension.baseURI + path; @@ -53,14 +63,14 @@ if (window.chrome) { if (vAPI.i18nData[vAPI.i18n = navigator.language.replace('-', '_')] || vAPI.i18nData[vAPI.i18n = vAPI.i18n.slice(0, 2)]) { - vAPI.i18nAlpha2 = vAPI.i18n; + vAPI.i18nLocale = vAPI.i18n; } else { - vAPI.i18nAlpha2 = vAPI.i18nData._; + vAPI.i18nLocale = vAPI.i18nData._; } xhr = new XMLHttpRequest; xhr.overrideMimeType('application/json;charset=utf-8'); - xhr.open('GET', './_locales/' + vAPI.i18nAlpha2 + '/messages.json', false); + xhr.open('GET', './_locales/' + vAPI.i18nLocale + '/messages.json', false); xhr.send(); vAPI.i18nData = JSON.parse(xhr.responseText); @@ -72,6 +82,8 @@ if (window.chrome) { return this.i18nData[s] || s; }; + setScriptDirection(vAPI.i18nLocale); + // update popover size to its content if (safari.self.identifier === 'popover' && safari.self) { window.addEventListener('load', function() { diff --git a/src/popup.html b/src/popup.html index c86b5128a..535dfc07f 100644 --- a/src/popup.html +++ b/src/popup.html @@ -2,7 +2,7 @@ - + µBlock diff --git a/src/settings.html b/src/settings.html index 8b8056943..1f96982ae 100644 --- a/src/settings.html +++ b/src/settings.html @@ -1,7 +1,7 @@ - + µBlock — Settings diff --git a/src/stats.html b/src/stats.html index 990cdf305..b6ca1f5d7 100644 --- a/src/stats.html +++ b/src/stats.html @@ -1,95 +1,11 @@ - + µBlock — Statistics - + diff --git a/src/whitelist.html b/src/whitelist.html index 77abe7c8e..3980cbcb9 100644 --- a/src/whitelist.html +++ b/src/whitelist.html @@ -1,7 +1,7 @@ - + µBlock — Whitelist