2016-11-23 23:48:47 +11:00
|
|
|
/*
|
|
|
|
|
* Copyright 2016 Michael Gratton <mike@vee.net>
|
|
|
|
|
*
|
|
|
|
|
* This software is licensed under the GNU Lesser General Public License
|
|
|
|
|
* (version 2.1 or later). See the COPYING file in this distribution.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-11-24 23:42:28 +11:00
|
|
|
/**
|
|
|
|
|
* Application logic for ClientWebView and subclasses.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-01-04 01:15:08 +11:00
|
|
|
let PageState = function() {
|
2016-11-25 22:00:06 +11:00
|
|
|
this.init.apply(this, arguments);
|
|
|
|
|
};
|
2016-11-25 16:30:50 +11:00
|
|
|
PageState.prototype = {
|
2016-11-25 22:00:06 +11:00
|
|
|
init: function() {
|
|
|
|
|
this.allowRemoteImages = false;
|
2016-11-27 21:03:52 +11:00
|
|
|
this.is_loaded = false;
|
2016-11-25 22:00:06 +11:00
|
|
|
|
2017-01-04 01:15:08 +11:00
|
|
|
let state = this;
|
|
|
|
|
let timeoutId = window.setInterval(function() {
|
2016-11-25 22:00:06 +11:00
|
|
|
state.preferredHeightChanged();
|
2016-11-27 21:03:52 +11:00
|
|
|
if (state.is_loaded) {
|
2016-11-25 22:00:06 +11:00
|
|
|
window.clearTimeout(timeoutId);
|
|
|
|
|
}
|
|
|
|
|
}, 50);
|
|
|
|
|
},
|
2017-01-04 01:10:38 +11:00
|
|
|
getPreferredHeight: function() {
|
|
|
|
|
return window.document.documentElement.offsetHeight;
|
|
|
|
|
},
|
2016-11-27 21:03:52 +11:00
|
|
|
loaded: function() {
|
|
|
|
|
this.is_loaded = true;
|
|
|
|
|
},
|
2016-11-25 16:30:50 +11:00
|
|
|
loadRemoteImages: function() {
|
|
|
|
|
this.allowRemoteImages = true;
|
2017-01-04 01:15:08 +11:00
|
|
|
let images = document.getElementsByTagName("IMG");
|
|
|
|
|
for (let i = 0; i < images.length; i++) {
|
|
|
|
|
let img = images.item(i);
|
|
|
|
|
let src = img.src;
|
2016-11-25 16:30:50 +11:00
|
|
|
img.src = "";
|
|
|
|
|
img.src = src;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
remoteImageLoadBlocked: function() {
|
|
|
|
|
window.webkit.messageHandlers.remoteImageLoadBlocked.postMessage(null);
|
2016-11-25 22:00:06 +11:00
|
|
|
},
|
|
|
|
|
preferredHeightChanged: function() {
|
2017-01-04 01:10:38 +11:00
|
|
|
let height = this.getPreferredHeight();
|
2016-11-25 22:00:06 +11:00
|
|
|
if (height > 0) {
|
|
|
|
|
window.webkit.messageHandlers.preferredHeightChanged.postMessage(
|
|
|
|
|
height
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-11-27 11:24:09 +11:00
|
|
|
},
|
|
|
|
|
selectionChanged: function() {
|
2017-01-04 01:15:08 +11:00
|
|
|
let has_selection = !window.getSelection().isCollapsed;
|
2016-11-27 11:24:09 +11:00
|
|
|
window.webkit.messageHandlers.selectionChanged.postMessage(has_selection);
|
2016-11-25 16:30:50 +11:00
|
|
|
}
|
|
|
|
|
};
|