Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timob 8435 3 1 x #4579

Merged
merged 2 commits into from
Aug 20, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 34 additions & 29 deletions mobileweb/titanium/Ti/UI/WebView.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
define(["Ti/_/declare", "Ti/_/UI/Widget", "Ti/_/dom", "Ti/_/event", "Ti/_/lang", "Ti/_/text!Ti/_/UI/WebViewBridge.js", "Ti/App", "Ti/API", "Ti/UI"],
function(declare, Widget, dom, event, lang, bridge, App, API, UI) {
/*global define, window*/
define(['Ti/_/declare', 'Ti/_/UI/Widget', 'Ti/_/dom', 'Ti/_/event', 'Ti/_/lang', 'Ti/_/text!Ti/_/UI/WebViewBridge.js', 'Ti/App', 'Ti/API', 'Ti/UI', 'Ti/_/style'],
function(declare, Widget, dom, event, lang, bridge, App, API, UI, style) {

var on = require.on;

return declare("Ti.UI.WebView", Widget, {
return declare('Ti.UI.WebView', Widget, {

constructor: function() {
App.addEventListener(this.widgetId + ":unload", lang.hitch(this, function() {
App.addEventListener(this.widgetId + ':unload', lang.hitch(this, function() {
this._loading(1);
}));
this.backgroundColor = "#fff";
this.backgroundColor = '#fff';
style.set(this.domNode, {
overflow: 'auto',
overflowScrolling: 'touch'
});
},

destroy: function() {
App.removeEventListener(this.widgetId + ":unload");
App.removeEventListener(this.widgetId + ':unload');
this._destroy();
Widget.prototype.destroy.apply(this, arguments);
},
Expand All @@ -29,27 +34,27 @@ define(["Ti/_/declare", "Ti/_/UI/Widget", "Ti/_/dom", "Ti/_/event", "Ti/_/lang",
if (this._parent) {
this._destroy();
this._loading(1);

var url = this.url || "",
var url = this.url || '',
match = url.match(/(https?)\:\/\/([^\:\/]*)(:?\d*)(.*)/),
loc = window.location,
isSameDomain = !match || (match[0] + ":" === loc.protocol && match[1] + match[2] === window.location.host),
iframe = this._iframe = dom.create("iframe", {
isSameDomain = !match || (match[0] + ':' === loc.protocol && match[1] + match[2] === window.location.host),
iframe = this._iframe = dom.create('iframe', {
frameborder: 0,
marginwidth: 0,
marginheight: 0,
hspace: 0,
vspace: 0,
scrolling: this.showScrollbars ? "auto" : "no",
src: url || require.toUrl("Ti/_/UI/blank.html"),
scrolling: this.showScrollbars ? 'auto' : 'no',
src: url || require.toUrl('Ti/_/UI/blank.html'),
style: {
width: "100%",
height: "100%"
width: '100%',
height: '100%',
position: 'absolute'
}
}, this.domNode);

this._iframeHandles = [
on(iframe, "load", this, function(evt) {
on(iframe, 'load', this, function() {
var i = Math.max(isSameDomain | 0, 0),
cw = iframe.contentWindow,
prop,
Expand All @@ -69,21 +74,21 @@ define(["Ti/_/declare", "Ti/_/UI/Widget", "Ti/_/dom", "Ti/_/event", "Ti/_/lang",

if (i > 0) {
url = cw.location.href;
this.evalJS(bridge.replace("WEBVIEW_ID", this.widgetId + ":unload"));
this.evalJS(bridge.replace('WEBVIEW_ID', this.widgetId + ':unload'));
(html = this.properties.__values__.html) && this._setContent(html);
} else {
API.warn("Unable to inject WebView bridge into cross-domain URL, ignore browser security message");
API.warn('Unable to inject WebView bridge into cross-domain URL, ignore browser security message');
}

this._loading();
this.fireEvent("load", {
this.fireEvent('load', {
url: url ? (this.properties.__values__.url = url) : this.url
});
}),
on(iframe, "error", this, function() {
on(iframe, 'error', this, function() {
this._loading();
this.fireEvent("error", {
message: "Page failed to load",
this.fireEvent('error', {
message: 'Page failed to load',
url: this.url
});
})
Expand All @@ -93,7 +98,7 @@ define(["Ti/_/declare", "Ti/_/UI/Widget", "Ti/_/dom", "Ti/_/event", "Ti/_/lang",
}
},

_setParent: function(view) {
_setParent: function() {
Widget.prototype._setParent.apply(this, arguments);

// we are being added to a parent, need to manually fire
Expand All @@ -113,7 +118,7 @@ define(["Ti/_/declare", "Ti/_/UI/Widget", "Ti/_/dom", "Ti/_/event", "Ti/_/lang",
},

_loading: function(v) {
this.loading || v && this.fireEvent("beforeload", {
this.loading || v && this.fireEvent('beforeload', {
url: this.url
});
this.constants.loading = !!v;
Expand Down Expand Up @@ -171,7 +176,7 @@ define(["Ti/_/declare", "Ti/_/UI/Widget", "Ti/_/dom", "Ti/_/event", "Ti/_/lang",
_defaultWidth: UI.FILL,

_defaultHeight: UI.FILL,

_getContentSize: function() {
return {
width: this._iframe ? this._iframe.clientWidth : 0,
Expand All @@ -194,9 +199,9 @@ define(["Ti/_/declare", "Ti/_/UI/Widget", "Ti/_/dom", "Ti/_/event", "Ti/_/lang",
set: function(value) {
var data = value;
switch (data && data.declaredClass) {
case "Ti.Filesystem.File":
case 'Ti.Filesystem.File':
data = data.read();
case "Ti.Blob":
case 'Ti.Blob':
data = data.toString();
default:
this.html = data;
Expand All @@ -220,14 +225,14 @@ define(["Ti/_/declare", "Ti/_/UI/Widget", "Ti/_/dom", "Ti/_/event", "Ti/_/lang",

showScrollbars: {
set: function(value) {
this._iframe && dom.attr.set(this._iframe, "scrolling", value ? "auto" : "no");
this._iframe && dom.attr.set(this._iframe, 'scrolling', value ? 'auto' : 'no');
return value;
},
value: true
},

url: {
post: function(value) {
url: {
post: function() {
var values = this.properties.__values__;
values.data = void 0;
values.html = void 0;
Expand Down