fixes #2005
This commit is contained in:
62
app/assets/stylesheets/mobile.css.scss
Normal file
62
app/assets/stylesheets/mobile.css.scss
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
*= require "./common/010_reset"
|
||||||
|
*= require "./common/020_base"
|
||||||
|
*= require "./common/030_links"
|
||||||
|
*/
|
||||||
|
|
||||||
|
body {
|
||||||
|
padding: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* paginator */
|
||||||
|
div.paginator {
|
||||||
|
font-size: 20pt;
|
||||||
|
font-weight: bold;
|
||||||
|
text-align: center;
|
||||||
|
|
||||||
|
li {
|
||||||
|
display: inline;
|
||||||
|
|
||||||
|
a, span {
|
||||||
|
border: 1px solid #EAEAEA;
|
||||||
|
padding: 3px 18px;
|
||||||
|
margin: 0 3px;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* posts/index */
|
||||||
|
article.post-preview {
|
||||||
|
margin: 15px 0;
|
||||||
|
width: 150px;
|
||||||
|
text-align: center;
|
||||||
|
vertical-align: middle;
|
||||||
|
display: inline-block;
|
||||||
|
a {
|
||||||
|
width: 150px;
|
||||||
|
display: block;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
img {
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* posts/show */
|
||||||
|
img#image {
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#tags {
|
||||||
|
margin-top: 10px;
|
||||||
|
|
||||||
|
li {
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.search-tag {
|
||||||
|
font-size: 24pt;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/controllers/mobile/posts_controller.rb
Normal file
18
app/controllers/mobile/posts_controller.rb
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
class Mobile::PostsController < ApplicationController
|
||||||
|
layout "mobile"
|
||||||
|
before_filter :set_mobile_mode
|
||||||
|
|
||||||
|
def index
|
||||||
|
@post_set = PostSets::Post.new(params[:tags], params[:page], CurrentUser.user.per_page, false)
|
||||||
|
@posts = @post_set.posts
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@post = Post.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def set_mobile_mode
|
||||||
|
CurrentUser.mobile_mode = true
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -11,6 +11,7 @@ class CurrentUser
|
|||||||
ensure
|
ensure
|
||||||
self.user = old_user
|
self.user = old_user
|
||||||
self.ip_addr = old_ip_addr
|
self.ip_addr = old_ip_addr
|
||||||
|
self.mobile_mode = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -30,6 +31,14 @@ class CurrentUser
|
|||||||
Thread.current[:current_ip_addr]
|
Thread.current[:current_ip_addr]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.mobile_mode=(mode)
|
||||||
|
Thread.current[:mobile_mode] = mode
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.mobile_mode?
|
||||||
|
Thread.current[:mobile_mode]
|
||||||
|
end
|
||||||
|
|
||||||
def self.id
|
def self.id
|
||||||
if user.nil?
|
if user.nil?
|
||||||
nil
|
nil
|
||||||
|
|||||||
@@ -118,6 +118,10 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def file_url_for(user)
|
def file_url_for(user)
|
||||||
|
if CurrentUser.mobile_mode?
|
||||||
|
return large_file_url
|
||||||
|
end
|
||||||
|
|
||||||
case user.default_image_size
|
case user.default_image_size
|
||||||
when "large"
|
when "large"
|
||||||
if image_width > Danbooru.config.large_image_width
|
if image_width > Danbooru.config.large_image_width
|
||||||
@@ -132,6 +136,10 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def file_path_for(user)
|
def file_path_for(user)
|
||||||
|
if CurrentUser.mobile_mode?
|
||||||
|
return large_file_path
|
||||||
|
end
|
||||||
|
|
||||||
case user.default_image_size
|
case user.default_image_size
|
||||||
when "large"
|
when "large"
|
||||||
if image_width > Danbooru.config.large_image_width
|
if image_width > Danbooru.config.large_image_width
|
||||||
@@ -155,6 +163,14 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
module ImageMethods
|
module ImageMethods
|
||||||
|
def device_scale
|
||||||
|
if large_image_width > 320
|
||||||
|
320.0 / (large_image_width + 10)
|
||||||
|
else
|
||||||
|
1.0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def twitter_card_supported?
|
def twitter_card_supported?
|
||||||
image_width.to_i >= 280 && image_height.to_i >= 150
|
image_width.to_i >= 280 && image_height.to_i >= 150
|
||||||
end
|
end
|
||||||
@@ -181,6 +197,10 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def image_width_for(user)
|
def image_width_for(user)
|
||||||
|
if CurrentUser.mobile_mode?
|
||||||
|
return large_image_width
|
||||||
|
end
|
||||||
|
|
||||||
case user.default_image_size
|
case user.default_image_size
|
||||||
when "large"
|
when "large"
|
||||||
large_image_width
|
large_image_width
|
||||||
@@ -191,6 +211,10 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def image_height_for(user)
|
def image_height_for(user)
|
||||||
|
if CurrentUser.mobile_mode?
|
||||||
|
return large_image_height
|
||||||
|
end
|
||||||
|
|
||||||
case user.default_image_size
|
case user.default_image_size
|
||||||
when "large"
|
when "large"
|
||||||
large_image_height
|
large_image_height
|
||||||
|
|||||||
@@ -20,7 +20,11 @@ class PostPresenter < Presenter
|
|||||||
else
|
else
|
||||||
tag_param = nil
|
tag_param = nil
|
||||||
end
|
end
|
||||||
html << %{<a href="#{path}/#{post.id}#{tag_param}">}
|
if options[:mobile]
|
||||||
|
html << %{<a href="/m#{path}/#{post.id}#{tag_param}">}
|
||||||
|
else
|
||||||
|
html << %{<a href="#{path}/#{post.id}#{tag_param}">}
|
||||||
|
end
|
||||||
html << %{<img src="#{post.preview_file_url}" alt="#{h(post.tag_string)}">}
|
html << %{<img src="#{post.preview_file_url}" alt="#{h(post.tag_string)}">}
|
||||||
html << %{</a>}
|
html << %{</a>}
|
||||||
html << %{</article>}
|
html << %{</article>}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ module PostSetPresenters
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_previews_html(template)
|
def post_previews_html(template, options = {})
|
||||||
html = ""
|
html = ""
|
||||||
|
|
||||||
if posts.empty?
|
if posts.empty?
|
||||||
@@ -12,7 +12,7 @@ module PostSetPresenters
|
|||||||
end
|
end
|
||||||
|
|
||||||
posts.each do |post|
|
posts.each do |post|
|
||||||
html << PostPresenter.preview(post, :tags => @post_set.tag_string, :raw => @post_set.raw)
|
html << PostPresenter.preview(post, :tags => @post_set.tag_string, :raw => @post_set.raw, :mobile => options[:mobile])
|
||||||
html << "\n"
|
html << "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ module PostSetPresenters
|
|||||||
RelatedTagCalculator.calculate_from_post_set_to_array(post_set).map(&:first)
|
RelatedTagCalculator.calculate_from_post_set_to_array(post_set).map(&:first)
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_list_html(template)
|
def tag_list_html(template, options = {})
|
||||||
tag_set_presenter.tag_list_html(template)
|
tag_set_presenter.tag_list_html(template, options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
20
app/views/layouts/mobile.html.erb
Normal file
20
app/views/layouts/mobile.html.erb
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title><%= yield :page_title %></title>
|
||||||
|
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
|
||||||
|
<%= csrf_meta_tag %>
|
||||||
|
<%= stylesheet_link_tag "mobile", :media => "screen" %>
|
||||||
|
<%= javascript_include_tag "mobile" %>
|
||||||
|
<%= Danbooru.config.custom_html_header_content %>
|
||||||
|
<%= yield :html_header %>
|
||||||
|
</head>
|
||||||
|
<body lang="en">
|
||||||
|
<header id="top">
|
||||||
|
<h1><%= link_to Danbooru.config.app_name, "/" %></h1>
|
||||||
|
</header>
|
||||||
|
<div id="page">
|
||||||
|
<%= yield :layout %>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
16
app/views/mobile/posts/index.html.erb
Normal file
16
app/views/mobile/posts/index.html.erb
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<%= form_tag(m_posts_path, :method => "get") do %>
|
||||||
|
<%= text_field_tag("tags", params[:tags], :size => 30) %>
|
||||||
|
<%= submit_tag "Go", :name => nil %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= @post_set.presenter.post_previews_html(self, :mobile => true) %>
|
||||||
|
|
||||||
|
<%= numbered_paginator(@post_set.posts) %>
|
||||||
|
|
||||||
|
<div id="tags">
|
||||||
|
<%= @post_set.presenter.tag_list_html(self, :name_only => true, :path_prefix => "/m/posts") %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= content_for(:html_header) do %>
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
|
<% end %>
|
||||||
14
app/views/mobile/posts/show.html.erb
Normal file
14
app/views/mobile/posts/show.html.erb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<%= form_tag(m_posts_path, :method => "get") do %>
|
||||||
|
<%= text_field_tag("tags", params[:tags], :size => 20) %>
|
||||||
|
<%= submit_tag "Go", :name => nil %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= @post.presenter.image_html(self) %>
|
||||||
|
|
||||||
|
<div id="tags">
|
||||||
|
<%= @post.presenter.tag_list_html(self, :name_only => true, :path_prefix => "/m/posts") %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= content_for(:html_header) do %>
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=<%= @post.device_scale %>">
|
||||||
|
<% end %>
|
||||||
@@ -3,6 +3,9 @@ Danbooru::Application.routes.draw do
|
|||||||
resources :users, :only => [:edit, :update]
|
resources :users, :only => [:edit, :update]
|
||||||
resource :alias_and_implication_import, :only => [:new, :create]
|
resource :alias_and_implication_import, :only => [:new, :create]
|
||||||
end
|
end
|
||||||
|
namespace :mobile do
|
||||||
|
resources :posts, :only => [:index, :show]
|
||||||
|
end
|
||||||
namespace :moderator do
|
namespace :moderator do
|
||||||
resource :dashboard, :only => [:show]
|
resource :dashboard, :only => [:show]
|
||||||
resources :ip_addrs, :only => [:index] do
|
resources :ip_addrs, :only => [:index] do
|
||||||
@@ -257,6 +260,8 @@ Danbooru::Application.routes.draw do
|
|||||||
resources :wpages, :controller => "wiki_pages"
|
resources :wpages, :controller => "wiki_pages"
|
||||||
resources :ftopics, :controller => "forum_topics"
|
resources :ftopics, :controller => "forum_topics"
|
||||||
resources :fposts, :controller => "forum_posts"
|
resources :fposts, :controller => "forum_posts"
|
||||||
|
match "/m/posts", :controller => "mobile/posts", :action => "index"
|
||||||
|
match "/m/posts/:id", :controller => "mobile/posts", :action => "show"
|
||||||
|
|
||||||
# legacy aliases
|
# legacy aliases
|
||||||
match "/artist" => redirect {|params, req| "/artists?page=#{req.params[:page]}&search[name]=#{CGI::escape(req.params[:name].to_s)}"}
|
match "/artist" => redirect {|params, req| "/artists?page=#{req.params[:page]}&search[name]=#{CGI::escape(req.params[:name].to_s)}"}
|
||||||
|
|||||||
Reference in New Issue
Block a user