2013-09-27 01:53:33 +08:00
|
|
|
/*
|
2013-08-13 04:51:54 +08:00
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
2015-04-14 04:33:03 +08:00
|
|
|
*/
|
2013-08-13 04:51:54 +08:00
|
|
|
|
2017-06-13 01:34:08 +08:00
|
|
|
/* jslint sloppy:true */
|
|
|
|
/* global Windows:true, require, document, setTimeout, window, module */
|
2013-08-13 04:51:54 +08:00
|
|
|
|
|
|
|
var browserWrap;
|
|
|
|
|
|
|
|
var IAB = {
|
|
|
|
|
2013-09-27 01:53:33 +08:00
|
|
|
close: function (win, lose) {
|
2013-08-13 04:51:54 +08:00
|
|
|
if (browserWrap) {
|
|
|
|
browserWrap.parentNode.removeChild(browserWrap);
|
|
|
|
browserWrap = null;
|
|
|
|
}
|
|
|
|
},
|
2013-09-27 01:53:33 +08:00
|
|
|
show: function (win, lose) {
|
|
|
|
/* empty block, ran out of bacon?
|
2015-04-14 04:33:03 +08:00
|
|
|
if (browserWrap) {
|
2013-08-13 04:51:54 +08:00
|
|
|
|
2017-06-13 01:34:08 +08:00
|
|
|
} */
|
2013-08-13 04:51:54 +08:00
|
|
|
},
|
2015-02-05 20:20:57 +08:00
|
|
|
hide: function (win, lose) {
|
|
|
|
/* empty block, ran out of bacon?
|
|
|
|
if (browserWrap) {
|
|
|
|
|
2017-06-13 01:34:08 +08:00
|
|
|
} */
|
2015-02-05 20:20:57 +08:00
|
|
|
},
|
2013-09-27 01:53:33 +08:00
|
|
|
open: function (win, lose, args) {
|
2017-06-13 01:34:08 +08:00
|
|
|
var strUrl = args[0];
|
|
|
|
var target = args[1];
|
|
|
|
var url;
|
|
|
|
var elem;
|
2013-09-27 01:53:33 +08:00
|
|
|
|
2017-06-13 01:34:08 +08:00
|
|
|
if (target === '_system') {
|
2013-09-27 01:53:33 +08:00
|
|
|
url = new Windows.Foundation.Uri(strUrl);
|
2013-08-13 04:51:54 +08:00
|
|
|
Windows.System.Launcher.launchUriAsync(url);
|
2017-06-13 01:34:08 +08:00
|
|
|
} else if (target === '_blank') {
|
2013-08-13 04:51:54 +08:00
|
|
|
if (!browserWrap) {
|
2017-06-13 01:34:08 +08:00
|
|
|
browserWrap = document.createElement('div');
|
|
|
|
browserWrap.style.position = 'absolute';
|
|
|
|
browserWrap.style.width = (window.innerWidth - 80) + 'px';
|
|
|
|
browserWrap.style.height = (window.innerHeight - 80) + 'px';
|
|
|
|
browserWrap.style.borderWidth = '40px';
|
|
|
|
browserWrap.style.borderStyle = 'solid';
|
|
|
|
browserWrap.style.borderColor = 'rgba(0,0,0,0.25)';
|
|
|
|
browserWrap.style.zIndex = '9999999';
|
2013-08-13 04:51:54 +08:00
|
|
|
|
|
|
|
browserWrap.onclick = function () {
|
|
|
|
setTimeout(function () {
|
|
|
|
IAB.close();
|
|
|
|
}, 0);
|
2013-09-27 01:53:33 +08:00
|
|
|
};
|
2013-08-13 04:51:54 +08:00
|
|
|
|
|
|
|
document.body.appendChild(browserWrap);
|
|
|
|
}
|
2015-04-14 04:33:03 +08:00
|
|
|
var localFile = (strUrl.indexOf('ms-appdata:///') > -1);
|
|
|
|
if (localFile) {
|
2017-06-13 01:34:08 +08:00
|
|
|
elem = document.createElement('x-ms-webview');
|
|
|
|
elem.style.width = (window.innerWidth - 80) + 'px';
|
|
|
|
elem.style.height = (window.innerHeight - 80) + 'px';
|
|
|
|
elem.style.borderWidth = '0px';
|
|
|
|
elem.name = 'targetFrame';
|
2015-04-14 04:33:03 +08:00
|
|
|
elem.src = strUrl;
|
|
|
|
|
2017-06-13 01:34:08 +08:00
|
|
|
window.addEventListener('resize', function () {
|
2015-04-14 04:33:03 +08:00
|
|
|
if (browserWrap && elem) {
|
2017-06-13 01:34:08 +08:00
|
|
|
elem.style.width = (window.innerWidth - 80) + 'px';
|
|
|
|
elem.style.height = (window.innerHeight - 80) + 'px';
|
2015-04-14 04:33:03 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2017-06-13 01:34:08 +08:00
|
|
|
elem = document.createElement('iframe');
|
|
|
|
elem.style.width = (window.innerWidth - 80) + 'px';
|
|
|
|
elem.style.height = (window.innerHeight - 80) + 'px';
|
|
|
|
elem.style.borderWidth = '0px';
|
|
|
|
elem.name = 'targetFrame';
|
2015-04-14 04:33:03 +08:00
|
|
|
elem.src = strUrl;
|
|
|
|
|
2017-06-13 01:34:08 +08:00
|
|
|
window.addEventListener('resize', function () {
|
2015-04-14 04:33:03 +08:00
|
|
|
if (browserWrap && elem) {
|
2017-06-13 01:34:08 +08:00
|
|
|
elem.style.width = (window.innerWidth - 80) + 'px';
|
|
|
|
elem.style.height = (window.innerHeight - 80) + 'px';
|
2015-04-14 04:33:03 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-08-13 04:51:54 +08:00
|
|
|
|
|
|
|
browserWrap.appendChild(elem);
|
2013-09-27 01:53:33 +08:00
|
|
|
} else {
|
2013-08-13 04:51:54 +08:00
|
|
|
window.location = strUrl;
|
|
|
|
}
|
|
|
|
|
2017-06-13 01:34:08 +08:00
|
|
|
// var object = new WinJS.UI.HtmlControl(elem, { uri: strUrl });
|
2013-08-13 04:51:54 +08:00
|
|
|
},
|
|
|
|
|
2013-09-27 01:53:33 +08:00
|
|
|
injectScriptCode: function (code, bCB) {
|
2013-08-13 04:51:54 +08:00
|
|
|
|
|
|
|
// "(function(d) { var c = d.createElement('script'); c.src = %@; d.body.appendChild(c); })(document)"
|
|
|
|
},
|
|
|
|
|
2013-09-27 01:53:33 +08:00
|
|
|
injectScriptFile: function (file, bCB) {
|
2013-08-13 04:51:54 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = IAB;
|
|
|
|
|
2017-06-13 01:34:08 +08:00
|
|
|
require('cordova/exec/proxy').add('InAppBrowser', module.exports);
|