cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [1/6] js commit: [CB-2305] Add InAppBrowser.executeScript and InAppBrowser.insertCSS APIs
Date Wed, 27 Mar 2013 18:45:08 GMT
Updated Branches:
  refs/heads/2.6.x 47593b2bc -> a2c5b0e22


[CB-2305] Add InAppBrowser.executeScript and InAppBrowser.insertCSS APIs


Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/9a65e32a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/9a65e32a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/9a65e32a

Branch: refs/heads/2.6.x
Commit: 9a65e32a21a696f94fb41cf39cf7ce7b1830c915
Parents: bbf1562
Author: Ian Clelland <iclelland@chromium.org>
Authored: Fri Mar 15 23:27:55 2013 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Sat Mar 23 12:59:42 2013 -0400

----------------------------------------------------------------------
 lib/common/plugin/InAppBrowser.js |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/9a65e32a/lib/common/plugin/InAppBrowser.js
----------------------------------------------------------------------
diff --git a/lib/common/plugin/InAppBrowser.js b/lib/common/plugin/InAppBrowser.js
index 6422315..6e0b79b 100644
--- a/lib/common/plugin/InAppBrowser.js
+++ b/lib/common/plugin/InAppBrowser.js
@@ -49,6 +49,34 @@ InAppBrowser.prototype = {
         if (eventname in this.channels) {
             this.channels[eventname].unsubscribe(f);
         }
+    },
+    executeScript: function(injectDetails, cb) {
+        var script,
+            sourceString;
+        if (injectDetails.code) {
+            exec(cb, null, "InAppBrowser", "injectScriptCode", [injectDetails.code]);
+        } else if (injectDetails.file) {
+            sourceString = JSON.stringify(injectDetails.file);
+            script = "(function(d) { var c = d.createElement('script'); c.src = " + sourceString
+ "; d.body.appendChild(c); })(document)";
+            exec(cb, null, "InAppBrowser", "injectScriptCode", [script]);
+        } else {
+            throw new Error('executeScript requires exactly one of code or file to be specified');
+        }
+    },
+    insertCSS: function(injectDetails, cb) {
+        var script,
+            sourceString;
+        if (injectDetails.code) {
+       	    sourceString = JSON.stringify(injectDetails.code);
+            script = "(function(d) { var c = d.createElement('style'); c.innerHTML = " +
sourceString + "; d.body.appendChild(c); })(document)";
+            exec(cb, null, "InAppBrowser", "injectScriptCode", [script]);
+        } else if (injectDetails.file) {
+            sourceString = JSON.stringify(injectDetails.file);
+            script = "(function(d) { var c = d.createElement('link'); c.rel='stylesheet',
c.type='text/css'; c.href = " + sourceString + "; d.body.appendChild(c); })(document)";
+            exec(cb, null, "InAppBrowser", "injectScriptCode", [script]);
+        } else {
+            throw new Error('insertCSS requires exactly one of code or file to be specified');
+        }
     }
 };
 


Mime
View raw message