From 388feba7c0e2e0c8730939d08e2fbd9c32b625ae Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Sat, 12 Jul 2014 21:50:56 +0200 Subject: [PATCH] Replace some js in external file --- public/js/lutim.js | 23 +++++++++++++++++++++++ templates/layouts/default.html.ep | 29 +++-------------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/public/js/lutim.js b/public/js/lutim.js index 5463eff..8ee0e18 100644 --- a/public/js/lutim.js +++ b/public/js/lutim.js @@ -1,3 +1,26 @@ $('document').ready(function() { $('.jsonly').show(); + // Are we in a mozilla navigator? (well, are we in a navigator which can handle webapps?) + if (navigator.mozApps !== undefined) { + 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); + }; + }); + } + } + } }); diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep index e404a15..152aa58 100644 --- a/templates/layouts/default.html.ep +++ b/templates/layouts/default.html.ep @@ -65,6 +65,9 @@ <%= stash('stop_upload') %> % } + %= javascript begin + var manifestUrl = '<%== url_for('manifest.webapp')->to_abs() %>'; + % end % if (current_route 'stats') { %= asset 'stats.js' % } elsif (!(current_route 'about')) { @@ -75,31 +78,5 @@ % 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