diff --git a/public/css/lutim.css b/public/css/lutim.css index dd0bd25..d6cd68c 100644 --- a/public/css/lutim.css +++ b/public/css/lutim.css @@ -45,3 +45,6 @@ label.always-encrypt { #install-app img { height: 22px; } +#install-app { + display: none; +} diff --git a/templates/index.html.ep b/templates/index.html.ep index 901857c..2d59cf7 100644 --- a/templates/index.html.ep +++ b/templates/index.html.ep @@ -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; diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep index f2e8190..f733deb 100644 --- a/templates/layouts/default.html.ep +++ b/templates/layouts/default.html.ep @@ -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 %> % if (defined(config('piwik_img'))) { % } + %= 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