mirror of
https://framagit.org/fiat-tux/hat-softwares/lutim.git
synced 2026-08-02 15:02:53 +02:00
Hide install-app button by default, reveal it when necessary
+ avoid mozSetMessageHandler error in console when not available
This commit is contained in:
@@ -45,3 +45,6 @@ label.always-encrypt {
|
||||
#install-app img {
|
||||
height: 22px;
|
||||
}
|
||||
#install-app {
|
||||
display: none;
|
||||
}
|
||||
|
||||
+10
-8
@@ -290,14 +290,16 @@
|
||||
});
|
||||
}
|
||||
window.onload = function() {
|
||||
navigator.mozSetMessageHandler('activity', function handler(activityRequest) {
|
||||
var activityName = activityRequest.source.name;
|
||||
if (activityName == 'share') {
|
||||
activity = activityRequest;
|
||||
blob = activity.source.data.blobs[0];
|
||||
fileUpload(blob);
|
||||
}
|
||||
});
|
||||
if (navigator.mozSetMessageHandler !== undefined) {
|
||||
navigator.mozSetMessageHandler('activity', function handler(activityRequest) {
|
||||
var activityName = activityRequest.source.name;
|
||||
if (activityName == 'share') {
|
||||
activity = activityRequest;
|
||||
blob = activity.source.data.blobs[0];
|
||||
fileUpload(blob);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
$('document').ready(function() {
|
||||
var firstview = ($("#first-view").prop('checked')) ? 1 : 0;
|
||||
|
||||
@@ -70,47 +70,36 @@
|
||||
% } elsif (!(current_route 'about')) {
|
||||
%= asset 'index.js'
|
||||
% }
|
||||
%= javascript begin
|
||||
$('#install-app').click(function() {
|
||||
var manifestUrl = '<%== url_for('manifest.webapp')->to_abs() %>';
|
||||
var request = window.navigator.mozApps.install(manifestUrl);
|
||||
request.onsuccess = function () {
|
||||
// Save the App object that is returned
|
||||
var appRecord = this.result;
|
||||
//alert('Installation successful!');
|
||||
};
|
||||
request.onerror = function () {
|
||||
// Display the error information from the DOMError object
|
||||
alert('Install failed, error: ' + this.error.name);
|
||||
};
|
||||
});
|
||||
//hide app install button when app already install
|
||||
var button = document.getElementById('install-app');
|
||||
var installCheck = navigator.mozApps.checkInstalled(manifestUrl);
|
||||
installCheck.onsuccess = function() {
|
||||
if(installCheck.result) {
|
||||
button.style.display = "none";
|
||||
}
|
||||
|
||||
//Hide app install button on the webapp
|
||||
if (navigator.mozApps) {
|
||||
var checkIfInstalled = navigator.mozApps.getSelf();
|
||||
checkIfInstalled.onsuccess = function () {
|
||||
if (checkIfInstalled.result) {
|
||||
// Already installed
|
||||
var installationInstructions = document.querySelector("#install-app");
|
||||
if (installationInstructions) {
|
||||
installationInstructions.style.display = "none";
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
% end
|
||||
<%= content %>
|
||||
</div>
|
||||
% if (defined(config('piwik_img'))) {
|
||||
<img src="<%== config('piwik_img') %>" style="border:0" alt="" />
|
||||
% }
|
||||
%= javascript begin
|
||||
// Are we in a mozilla navigator? (well, are we in a navigator which can handle webapps?)
|
||||
if (navigator.mozApps !== undefined) {
|
||||
var manifestUrl = '<%== url_for('manifest.webapp')->to_abs() %>';
|
||||
var installCheck = navigator.mozApps.checkInstalled(manifestUrl);
|
||||
installCheck.onsuccess = function() {
|
||||
if(installCheck.result === null) {
|
||||
var button = $('#install-app');
|
||||
// Show app install button when app is not installed
|
||||
button.css('display','inline-block');
|
||||
button.click(function() {
|
||||
var request = window.navigator.mozApps.install(manifestUrl);
|
||||
request.onsuccess = function () {
|
||||
// Save the App object that is returned
|
||||
var appRecord = this.result;
|
||||
button.css('display','none');
|
||||
};
|
||||
request.onerror = function () {
|
||||
// Display the error information from the DOMError object
|
||||
alert('Install failed, error: ' + this.error.name);
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
% end
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user