CB-7689 Adds insertCSS support for windows platform

This commit is contained in:
Vladimir Kotikov 2015-04-01 16:57:58 +03:00
parent dfd0999581
commit e2865db2ea
2 changed files with 43 additions and 1 deletions

View File

@ -377,6 +377,7 @@ Due to [MSDN docs](https://msdn.microsoft.com/en-us/library/windows.ui.xaml.cont
- Amazon Fire OS
- Android
- iOS
- Windows
### Quick Example

View File

@ -213,7 +213,7 @@ var IAB = {
IAB.close(win);
}, 0);
});
if (!isWebViewAvailable) {
// iframe navigation is not yet supported
backButton.disabled = true;
@ -277,9 +277,50 @@ var IAB = {
});
});
}
},
injectStyleCode: function (win, fail, args) {
var code = args[0],
hasCallback = args[1];
if (isWebViewAvailable && browserWrap && popup) {
injectCSS(popup, code, hasCallback && win);
}
},
injectStyleFile: function (win, fail, args) {
var filePath = args[0],
hasCallback = args[1];
filePath = filePath && urlutil.makeAbsolute(filePath);
if (isWebViewAvailable && browserWrap && popup) {
var uri = new Windows.Foundation.Uri(filePath);
Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).then(function (file) {
return Windows.Storage.FileIO.readTextAsync(file);
}).done(function (code) {
injectCSS(popup, code, hasCallback && win);
}, function () {
// no-op, just catch an error
});
}
}
};
function injectCSS (webView, cssCode, callback) {
// This will automatically escape all thing that we need (quotes, slashes, etc.)
var escapedCode = JSON.stringify(cssCode);
var evalWrapper = "(function(d){var c=d.createElement('style');c.innerHTML=%s;d.head.appendChild(c);})(document)"
.replace('%s', escapedCode);
var op = webView.invokeScriptAsync("eval", evalWrapper);
op.oncomplete = function() {
callback && callback([]);
};
op.onerror = function () { };
op.start();
}
module.exports = IAB;
require("cordova/exec/proxy").add("InAppBrowser", module.exports);