summaryrefslogtreecommitdiff
path: root/webhelper/webhelper.js
diff options
context:
space:
mode:
Diffstat (limited to 'webhelper/webhelper.js')
-rw-r--r--webhelper/webhelper.js78
1 files changed, 40 insertions, 38 deletions
diff --git a/webhelper/webhelper.js b/webhelper/webhelper.js
index 8b78931..ccce9e7 100644
--- a/webhelper/webhelper.js
+++ b/webhelper/webhelper.js
@@ -16,47 +16,46 @@ const Application = new Lang.Class({
_webActions: { },
-// This callback does the translation from URI to action
-// this._webview.connect('navigation-policy-decision-requested',
-// Lang.bind(this, this._webHelper.onNavigationRequested));
+ // This callback does the translation from URI to action
+ // webview.connect('navigation-policy-decision-requested',
+ // Lang.bind(this, this.web_actions_handler));
- _onNavigationRequested : function(web_view, frame, request,
- navigation_action, policy_decision,
- user_data) {
+ web_actions_handler: function(webview, frame, request, action, policy_decision) {
let uri = request.get_uri();
- if(uri.indexOf(EOS_URI_SCHEME) == 0) {
- // get the name and parameters for the desired function
- let f_call = uri.substring(EOS_URI_SCHEME.length, uri.length).split('?');
- var function_name = f_call[0];
- var parameters = {};
-
- if(f_call[1]) {
- // there are parameters
- let params = f_call[1].split('&');
- params.forEach(function(entry) {
- let param = entry.split('=');
-
- if(param.length == 2) {
- param[0] = decodeURIComponent(param[0]);
- param[1] = decodeURIComponent(param[1]);
- // and now we add it...
- parameters[param[0]] = param[1];
- }
- });
- }
-
- if(this._webActions[function_name])
- Lang.bind(this, this._webActions[function_name])(parameters);
- else
- print('Unknown function '+function_name);
-
- policy_decision.ignore();
- return true;
- } else {
+ if(uri.indexOf(EOS_URI_SCHEME) !== 0) {
// this is a regular URL, just navigate there
return false;
}
+
+ // get the name and parameters for the desired function
+ let f_call = uri.substring(EOS_URI_SCHEME.length, uri.length).split('?');
+ var function_name = f_call[0];
+ var parameters = {};
+
+ if(f_call[1]) {
+ // there are parameters
+ let params = f_call[1].split('&');
+ params.forEach(function(entry) {
+ let param = entry.split('=');
+
+ if(param.length == 2) {
+ param[0] = decodeURIComponent(param[0]);
+ param[1] = decodeURIComponent(param[1]);
+ // and now we add it...
+ parameters[param[0]] = param[1];
+ }
+ });
+ }
+
+ if(this._webActions[function_name])
+ Lang.bind(this, this._webActions[function_name])(parameters);
+ else
+ throw new Error("Undefined WebHelper action '%s'. Did you add it " +
+ "to your app's _webActions object?".format(function_name));
+
+ policy_decision.ignore();
+ return true;
},
// convenience functions
@@ -69,7 +68,7 @@ const Application = new Lang.Class({
return dom.get_element_by_id(id);
},
- _translateHTML: function(webview, lang) {
+ translate_html: function(webview) {
let dom = webview.get_dom_document();
// WebKit.DOMNodeList
@@ -79,8 +78,11 @@ const Application = new Lang.Class({
// WebKit.DOMNode
let element = translatable.item(i);
- // TODO here is where we would do the translation
- element.inner_html = '<i>' + element.inner_text + '</i>';
+ // Translate the text
+ if(typeof this._translationFunction !== 'function')
+ throw new Error("No suitable translation function was found. " +
+ "Did you forget to set '_translationFunction' on your app?");
+ element.inner_html = this._translationFunction(element.inner_text);
}
}
});