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.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-11-25 22:00:06 +11:00
|
|
|
var PageState = function() {
|
|
|
|
|
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;
|
|
|
|
|
this.loaded = false;
|
|
|
|
|
|
|
|
|
|
var state = this;
|
|
|
|
|
var timeoutId = window.setInterval(function() {
|
|
|
|
|
state.preferredHeightChanged();
|
|
|
|
|
if (state.loaded) {
|
|
|
|
|
window.clearTimeout(timeoutId);
|
|
|
|
|
}
|
|
|
|
|
}, 50);
|
|
|
|
|
},
|
2016-11-25 16:30:50 +11:00
|
|
|
loadRemoteImages: function() {
|
|
|
|
|
this.allowRemoteImages = true;
|
|
|
|
|
var images = document.getElementsByTagName("IMG");
|
|
|
|
|
for (var i = 0; i < images.length; i++) {
|
|
|
|
|
var img = images.item(i);
|
|
|
|
|
var src = img.src;
|
|
|
|
|
img.src = "";
|
|
|
|
|
img.src = src;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
remoteImageLoadBlocked: function() {
|
|
|
|
|
window.webkit.messageHandlers.remoteImageLoadBlocked.postMessage(null);
|
2016-11-25 22:00:06 +11:00
|
|
|
},
|
|
|
|
|
preferredHeightChanged: function() {
|
|
|
|
|
var height = window.document.documentElement.offsetHeight;
|
|
|
|
|
if (height > 0) {
|
|
|
|
|
window.webkit.messageHandlers.preferredHeightChanged.postMessage(
|
|
|
|
|
height
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-11-27 11:24:09 +11:00
|
|
|
},
|
|
|
|
|
selectionChanged: function() {
|
|
|
|
|
var has_selection = !window.getSelection().isCollapsed;
|
|
|
|
|
window.webkit.messageHandlers.selectionChanged.postMessage(has_selection);
|
2016-11-25 16:30:50 +11:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var geary = new PageState();
|
2016-11-24 23:42:28 +11:00
|
|
|
window.onload = function() {
|
2016-11-25 22:00:06 +11:00
|
|
|
geary.loaded = true;
|
2016-11-24 23:42:28 +11:00
|
|
|
};
|