Commit ab52a1ec authored by Thierry BUGEAT's avatar Thierry BUGEAT

Display images in offline mode. Bug userLocale.

parent a780d743
......@@ -214,6 +214,8 @@
<script src="libs/l10n.js"></script>
<link rel="resource" type="application/l10n" href="locales/locales.ini" />
<script type="text/javascript" src="locales/locales.js"></script>
<!-- Libs -->
<script type="text/javascript" src="libs/myCore.js"></script>
......
......@@ -97,7 +97,9 @@
},
"search": {
"visible": false // Form search entries by keyword is visible or not
}
},
"imagesPreviouslyDisplayed": [] // Store images previously displayed.
// Used for displaying images in offline mode.
}
}
......@@ -1761,40 +1763,12 @@
var className = 'my-'+params.entries.theme+'-date';
var elements = document.getElementsByClassName(className);
for (var i = 0; i < elements.length; i++) {
if (isInViewport(elements[i]) && (elements[i].textContent == "")) {
if (ui.isInViewport(elements[i]) && (elements[i].textContent == "")) {
var _publishedDate = elements[i].getAttribute('publishedDate');
elements[i].textContent = new Date(_publishedDate).toLocaleTimeString(userLocale);
}
}
}
/**
* Load images who are visibles in viewport
* */
function loadImages() {
var images = document.getElementsByTagName('img');
for (var i = 0; i < images.length; i++) {
if (isInViewport(images[i])
&& (images[i].getAttribute('data-src') != "")
&& (images[i].getAttribute('src') == "images/loading.png")
){
images[i].setAttribute('src', images[i].getAttribute('data-src'));
}
}
}
/**
* Check if element is visible in viewport
* @param {object} elem DOM element
* @return {boolean} true / false
* */
function isInViewport(element) {
var rect = element.getBoundingClientRect()
var windowHeight = window.innerHeight || document.documentElement.clientHeight
var windowWidth = window.innerWidth || document.documentElement.clientWidth
return rect.bottom > 0 && rect.top < windowHeight && rect.right > 0 && rect.left < windowWidth
}
// ======================
// --- Ready to start ---
......@@ -1890,7 +1864,7 @@
// ============================
setInterval(function() {
loadImages();
ui.loadImages();
}, 200);
// ======================
......
......@@ -295,7 +295,7 @@ MyUi.prototype._smoothScrollTo = function (screenX, duration) {
main.style.cssText = 'transition: transform 0.25s linear; transform: translateX('+_x+');';
}); // Schedule the execution for later
};
}
/**
* Show/Hide small entries
......@@ -324,7 +324,7 @@ MyUi.prototype._smallEntries = function (status) {
_MyUi._onclick(_small_entries[i], _tmp);
}
}
};
}
/**
* Change element opacity
......@@ -333,7 +333,7 @@ MyUi.prototype._smallEntries = function (status) {
* */
MyUi.prototype.fade = function (_this) {
_this.style.cssText = "opacity : 0.4;";
};
}
MyUi.prototype.selectThemeIcon = function () {
......@@ -356,4 +356,52 @@ MyUi.prototype._vibrate = function () {
if (params.settings.ui.vibrate) {
window.navigator.vibrate(50);
}
};
}
/**
* Load images who are visibles in viewport.
* Use images from navigator cache if network is offline.
* */
MyUi.prototype.loadImages = function () {
var images = document.getElementsByTagName('img');
for (var i = 0; i < images.length; i++) {
var _dataSrc = images[i].getAttribute('data-src');
if (navigator.onLine) {
if (_MyUi.isInViewport(images[i])
&& (_dataSrc != "")
&& (images[i].getAttribute('src') == "images/loading.png")
){
images[i].setAttribute('src', _dataSrc);
if (!liveValues.entries.imagesPreviouslyDisplayed.contains(_dataSrc)) {
liveValues.entries.imagesPreviouslyDisplayed.push(_dataSrc);
}
}
} else {
if (_MyUi.isInViewport(images[i])
&& liveValues.entries.imagesPreviouslyDisplayed.contains(_dataSrc)
){
images[i].setAttribute('src', _dataSrc);
}
}
}
}
/**
* Check if element is visible in viewport
* @param {object} elem DOM element
* @return {boolean} true / false
* */
MyUi.prototype.isInViewport = function (element) {
var rect = element.getBoundingClientRect()
var windowHeight = window.innerHeight || document.documentElement.clientHeight
var windowWidth = window.innerWidth || document.documentElement.clientWidth
return rect.bottom > 0 && rect.top < windowHeight && rect.right > 0 && rect.left < windowWidth
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment