InAppBrowserProxy.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. *
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. *
  20. */
  21. /*jslint sloppy:true */
  22. /*global Windows:true, require, document, setTimeout, window, module */
  23. var cordova = require('cordova'),
  24. channel = require('cordova/channel');
  25. var browserWrap;
  26. var IAB = {
  27. close: function (win, lose) {
  28. if (browserWrap) {
  29. browserWrap.parentNode.removeChild(browserWrap);
  30. browserWrap = null;
  31. }
  32. },
  33. show: function (win, lose) {
  34. /* empty block, ran out of bacon?
  35. if (browserWrap) {
  36. }*/
  37. },
  38. open: function (win, lose, args) {
  39. var strUrl = args[0],
  40. target = args[1],
  41. features = args[2],
  42. url,
  43. elem;
  44. if (target === "_system") {
  45. url = new Windows.Foundation.Uri(strUrl);
  46. Windows.System.Launcher.launchUriAsync(url);
  47. } else if (target === "_blank") {
  48. if (!browserWrap) {
  49. browserWrap = document.createElement("div");
  50. browserWrap.style.position = "absolute";
  51. browserWrap.style.width = (window.innerWidth - 80) + "px";
  52. browserWrap.style.height = (window.innerHeight - 80) + "px";
  53. browserWrap.style.borderWidth = "40px";
  54. browserWrap.style.borderStyle = "solid";
  55. browserWrap.style.borderColor = "rgba(0,0,0,0.25)";
  56. browserWrap.onclick = function () {
  57. setTimeout(function () {
  58. IAB.close();
  59. }, 0);
  60. };
  61. document.body.appendChild(browserWrap);
  62. }
  63. elem = document.createElement("iframe");
  64. elem.style.width = (window.innerWidth - 80) + "px";
  65. elem.style.height = (window.innerHeight - 80) + "px";
  66. elem.style.borderWidth = "0px";
  67. elem.name = "targetFrame";
  68. elem.src = strUrl;
  69. window.addEventListener("resize", function () {
  70. if (browserWrap && elem) {
  71. elem.style.width = (window.innerWidth - 80) + "px";
  72. elem.style.height = (window.innerHeight - 80) + "px";
  73. }
  74. });
  75. browserWrap.appendChild(elem);
  76. } else {
  77. window.location = strUrl;
  78. }
  79. //var object = new WinJS.UI.HtmlControl(elem, { uri: strUrl });
  80. },
  81. injectScriptCode: function (code, bCB) {
  82. // "(function(d) { var c = d.createElement('script'); c.src = %@; d.body.appendChild(c); })(document)"
  83. },
  84. injectScriptFile: function (file, bCB) {
  85. }
  86. };
  87. module.exports = IAB;
  88. require("cordova/exec/proxy").add("InAppBrowser", module.exports);