diff --git a/lib/Lutim.pm b/lib/Lutim.pm index 4d155c5..1b88463 100644 --- a/lib/Lutim.pm +++ b/lib/Lutim.pm @@ -321,6 +321,10 @@ sub startup { to('Controller#stats')-> name('stats'); + $r->get('/manifest.webapp')-> + to('Controller#webapp')-> + name('manifest.webapp'); + $r->post('/')-> to('Controller#add')-> name('add'); diff --git a/lib/Lutim/Controller.pm b/lib/Lutim/Controller.pm index d2b9b6d..494cc05 100644 --- a/lib/Lutim/Controller.pm +++ b/lib/Lutim/Controller.pm @@ -46,6 +46,19 @@ sub stats { ); } +sub webapp { + my $c = shift; + + my $headers = Mojo::Headers->new(); + $headers->add('Content-Type' => 'application/x-web-app-manifest+json'); + $c->res->content->headers($headers); + + $c->render( + template => 'manifest', + format => 'webapp' + ); +} + sub delete { my $c = shift; my $short = $c->param('short'); diff --git a/lib/Lutim/I18N/en.pm b/lib/Lutim/I18N/en.pm index 99f0e3e..89a7b96 100644 --- a/lib/Lutim/I18N/en.pm +++ b/lib/Lutim/I18N/en.pm @@ -82,6 +82,7 @@ our %Lexicon = ( 'image_deleted' => 'The image [_1] has been successfully deleted', 'invalid_token' => 'The delete token is invalid.', 'already_deleted' => 'The image [_1] has already been deleted.', + 'install_as_webapp' => 'Install webapp', ); 1; diff --git a/lib/Lutim/I18N/fr.pm b/lib/Lutim/I18N/fr.pm index 9b57cb9..37d7065 100644 --- a/lib/Lutim/I18N/fr.pm +++ b/lib/Lutim/I18N/fr.pm @@ -82,6 +82,7 @@ our %Lexicon = ( 'image_deleted' => 'L\'image [_1] a été supprimée avec succès.', 'invalid_token' => 'Le jeton de suppression est invalide.', 'already_deleted' => 'L\'image [_1] a déjà été supprimée.', + 'install_as_webapp' => 'Installer la webapp', ); 1; diff --git a/public/css/lutim.css b/public/css/lutim.css index 9929ca7..dd0bd25 100644 --- a/public/css/lutim.css +++ b/public/css/lutim.css @@ -1,6 +1,15 @@ -body { - padding-top: 40px; - padding-bottom: 40px; +@media (max-width: 767px) { + body { + padding-top: 5px; + padding-bottom: 5px; + } +} + +@media (min-width: 768px) { + body { + padding-top: 40px; + padding-bottom: 40px; + } } .container { @@ -32,3 +41,7 @@ label.always-encrypt { color: #000000; text-decoration: none; } + +#install-app img { + height: 22px; +} diff --git a/public/img/lutim128.png b/public/img/lutim128.png index c7f1d56..392d446 100644 Binary files a/public/img/lutim128.png and b/public/img/lutim128.png differ diff --git a/public/img/rocket.png b/public/img/rocket.png new file mode 100644 index 0000000..f855a02 Binary files /dev/null and b/public/img/rocket.png differ diff --git a/templates/index.html.ep b/templates/index.html.ep index eb93da4..7783053 100644 --- a/templates/index.html.ep +++ b/templates/index.html.ep @@ -122,7 +122,7 @@
@@ -191,7 +191,6 @@ $('#'+id).prop('aria-valuenow', percent); $('#'+id).prop('style', 'width: '+percent+'%;'); $('#'+id+'-text').html(percentStr); - }, onUploadSuccess: function(id, data){ $('#'+id+'-div').remove(); @@ -241,6 +240,66 @@ } } + function fileUpload(file) { + var fd = new FormData(); + fd.append('file', file); + + fd.append('format', 'json'); + fd.append('first-view', ($("#first-view").prop('checked')) ? 1 : 0); + fd.append('crypt', ($("#crypt").prop('checked')) ? 1 : 0); + fd.append('delete-day', ($("#delete-day").val())); + + $(".messages").append('
'+file.name+'
0%
'); + // Ajax Submit + $.ajax({ + url: '<%== url_for('add') %>', + type: 'POST', + dataType: 'json', + data: fd, + cache: false, + contentType: false, + processData: false, + forceSync: false, + xhr: function(){ + var xhrobj = $.ajaxSettings.xhr(); + if(xhrobj.upload){ + xhrobj.upload.addEventListener('progress', function(event) { + var percent = 0; + var position = event.loaded || event.position; + var total = event.total || e.totalSize; + if(event.lengthComputable){ + percent = Math.ceil(position / total * 100); + } + + var percentStr = ' '+percent+'%'; + $('#1').prop('aria-valuenow', percent); + $('#1').prop('style', 'width: '+percent+'%;'); + $('#1-text').html(percentStr); + }, false); + } + + return xhrobj; + }, + success: function (data, message, xhr){ + $('#1-div').remove(); + $(".messages").append(message(data.success, data.msg)); + }, + error: function (xhr, status, errMsg){ + $(".messages").append(message(false, '')); + }, + }); + } + 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); + //blob = document.getElementById("lutim-file").value; + } + }); + }; $('document').ready(function() { var firstview = ($("#first-view").prop('checked')) ? 1 : 0; var deleteday = ($("#delete-day").prop('checked')) ? 1 : 0; diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep index cc451c9..4a44aed 100644 --- a/templates/layouts/default.html.ep +++ b/templates/layouts/default.html.ep @@ -18,29 +18,6 @@ %= asset 'about.css' % } else { %= asset 'index.css' - - % } @@ -63,7 +40,8 @@ <%= link_to 'https://github.com/ldidry/lutim' => (title => l 'fork-me') => begin %><% end %>  <%= link_to $twitter_url => (title => l 'share-twitter') => begin %><% end %>  <%= link_to 'https://flattr.com/submit/auto?user_id=_SKy_&url='.$url.'&title=Lutim&category=software' => (title => 'Flattr this') => begin %><% end %>  - <%= link_to 'bitcoin:1K3n4MXNRSMHk28oTfXEvDunWFthePvd8v?label=lutim' => (title => 'Give Bitcoins') => begin %><% end %> + <%= link_to 'bitcoin:1K3n4MXNRSMHk28oTfXEvDunWFthePvd8v?label=lutim' => (title => 'Give Bitcoins') => begin %><% end %>  + mozilla rocket logo <%=l 'install_as_webapp' %>

@@ -82,6 +60,21 @@ % } 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); + }; + }); + % end <%= content %> % if (defined(config('piwik_img'))) {