diff --git a/assets/javascripts/views/layout/resizer.coffee b/assets/javascripts/views/layout/resizer.coffee index e1d48c09..46b2fec0 100644 --- a/assets/javascripts/views/layout/resizer.coffee +++ b/assets/javascripts/views/layout/resizer.coffee @@ -20,13 +20,15 @@ class app.views.Resizer extends app.View MIN = 250 MAX = 600 - resize: (newSize) -> - return unless newSize > 0 - newSize = Math.min(Math.max(Math.round(newSize), MIN), MAX) - app.settings.setSize(newSize) - newSize = "#{newSize}px" + resize: (value, save) -> + return unless value > 0 + value = Math.min(Math.max(Math.round(value), MIN), MAX) + newSize = "#{value}px" @style.innerHTML = @style.innerHTML.replace(new RegExp(@size, 'g'), newSize) @size = newSize + if save + app.settings.setSize(value) + app.appCache?.updateInBackground() return onDragStart: (event) => @@ -38,9 +40,9 @@ class app.views.Resizer extends app.View onDrag: (event) => return if @lastDrag and @lastDrag > Date.now() - 50 @lastDrag = Date.now() - @resize event.clientX + @resize(event.clientX, false) return onDragEnd: (event) => - @resize event.screenX - window.screenX + @resize(event.screenX - window.screenX, true) return diff --git a/test/app_test.rb b/test/app_test.rb index ce72d4ac..601032a2 100644 --- a/test/app_test.rb +++ b/test/app_test.rb @@ -81,6 +81,17 @@ class AppTest < MiniTest::Spec assert_includes last_response.body, '# dark' refute_includes last_response.body, '# light' end + + it "sets default size" do + get '/manifest.appcache' + assert_includes last_response.body, '18rem' + end + + it "sets size from cookie" do + set_cookie('size=42') + get '/manifest.appcache' + assert_includes last_response.body, '42px' + end end describe "/[doc]" do diff --git a/views/manifest.erb b/views/manifest.erb index 112df10a..ff3d0ba0 100644 --- a/views/manifest.erb +++ b/views/manifest.erb @@ -1,5 +1,5 @@ CACHE MANIFEST -# <%= cookies[:dark].nil? ? 'light' : 'dark' %> +# <%= cookies[:dark].nil? ? 'light' : 'dark' %> <%= size %> CACHE: /