aboutsummaryrefslogtreecommitdiffstats
path: root/meta/safariextz/vapi-common.js
diff options
context:
space:
mode:
Diffstat (limited to 'meta/safariextz/vapi-common.js')
-rw-r--r--meta/safariextz/vapi-common.js70
1 files changed, 37 insertions, 33 deletions
diff --git a/meta/safariextz/vapi-common.js b/meta/safariextz/vapi-common.js
index 1af6ad9..2021d77 100644
--- a/meta/safariextz/vapi-common.js
+++ b/meta/safariextz/vapi-common.js
@@ -27,45 +27,44 @@
'use strict';
-/******************************************************************************/
-
self.vAPI = self.vAPI || {};
/******************************************************************************/
// http://www.w3.org/International/questions/qa-scripts#directions
-var setScriptDirection = function(langugae) {
+
+var setScriptDirection = function(language) {
document.body.setAttribute(
'dir',
- ~['ar', 'he', 'fa', 'ps', 'ur'].indexOf(langugae) ? 'rtl' : 'ltr'
+ ~['ar', 'he', 'fa', 'ps', 'ur'].indexOf(language) ? 'rtl' : 'ltr'
);
};
/******************************************************************************/
vAPI.download = function(details) {
- if (!details.url) {
+ if ( !details.url ) {
return;
}
var a = document.createElement('a');
- if ('download' in a) {
+ if ( 'download' in a ) {
a.href = details.url;
a.setAttribute('download', details.filename || '');
a.dispatchEvent(new MouseEvent('click'));
+ return;
}
- else {
- var messager = vAPI.messaging.channel('_download');
- messager.send({
- what: 'gotoURL',
- details: {
- url: details.url,
- index: -1
- }
- });
- messager.close();
- }
+
+ var messager = vAPI.messaging.channel('_download');
+ messager.send({
+ what: 'gotoURL',
+ details: {
+ url: details.url,
+ index: -1
+ }
+ });
+ messager.close();
};
/******************************************************************************/
@@ -76,22 +75,29 @@ vAPI.getURL = function(path) {
/******************************************************************************/
-var xhr = new XMLHttpRequest;
-xhr.overrideMimeType('application/json;charset=utf-8');
-xhr.open('GET', './locales.json', false);
-xhr.send();
-vAPI.i18nData = JSON.parse(xhr.responseText);
+// supported languages
+// first language is the default
+vAPI.i18nData = [
+ "en", "ar", "cs", "da", "de", "el", "es", "et", "fi", "fr", "he", "hi",
+ "hr", "hu", "id", "it", "ja", "mr", "nb", "nl", "pl", "pt_BR", "pt_PT",
+ "ro", "ru", "sv", "tr", "uk", "vi", "zh_CN"
+];
+
+vAPI.i18n = navigator.language.replace('-', '_');
+
+if (vAPI.i18nData.indexOf(vAPI.i18n) === -1) {
+ vAPI.i18n = vAPI.i18n.slice(0, 2);
-if (vAPI.i18nData[vAPI.i18n = navigator.language.replace('-', '_')]
- || vAPI.i18nData[vAPI.i18n = vAPI.i18n.slice(0, 2)]) {
- vAPI.i18nLocale = vAPI.i18n;
-} else {
- vAPI.i18nLocale = vAPI.i18nData._;
+ if (vAPI.i18nData.indexOf(vAPI.i18n) === -1) {
+ vAPI.i18n = vAPI.i18nData[0];
+ }
}
-xhr = new XMLHttpRequest;
+setScriptDirection(vAPI.i18n);
+
+var xhr = new XMLHttpRequest;
xhr.overrideMimeType('application/json;charset=utf-8');
-xhr.open('GET', './_locales/' + vAPI.i18nLocale + '/messages.json', false);
+xhr.open('GET', './_locales/' + vAPI.i18n + '/messages.json', false);
xhr.send();
vAPI.i18nData = JSON.parse(xhr.responseText);
@@ -103,12 +109,10 @@ vAPI.i18n = function(s) {
return this.i18nData[s] || s;
};
-setScriptDirection(vAPI.i18nLocale);
-
/******************************************************************************/
// update popover size to its content
-if (safari.self.identifier === 'popover' && safari.self) {
+if (safari.self.identifier === 'popover') {
var onLoaded = function() {
// Initial dimensions are set in Info.plist
var pWidth = safari.self.width;
@@ -142,7 +146,7 @@ if (safari.self.identifier === 'popover' && safari.self) {
}
};
- window.addEventListener('load', );
+ window.addEventListener('load', onLoaded);
}
/******************************************************************************/