Skip to content

Commit 4a67d29

Browse files
committed
added tablet view
1 parent 191f0a2 commit 4a67d29

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

README.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ Then add the line below to config/initializers/mime_types.rb
3333
I recommend that you setup a before_filter that will redirect to a specific page
3434
depending on whether or not it is a mobile request. How can you check this?
3535

36-
is_mobile_device? # => Returns true or false depending on the device
36+
is_mobile_device? # => Returns true or false depending on the device or
37+
38+
is_tablet_device? # => Returns true if the device is a tablet
3739

3840
You can also determine which format is currently set in by calling the following:
3941

40-
in_mobile_view? # => Returns true or false depending on current req. format
42+
in_mobile_view? # => Returns true or false depending on current req. format or
43+
44+
in_tablet_view? # => Returns true if the current req. format is for tablet view
4145

4246
Also, if you want the ability to allow a user to switch between 'mobile' and
4347
'standard' format (:html), you can just adjust the mobile_view session variable
@@ -87,5 +91,11 @@ mobile device emulator, or you can call `force_mobile_format` in a before filter
8791
before_filter :force_mobile_format
8892
end
8993

94+
You can also force the tablet view by calling `force_tablet_format` instead
95+
96+
class ApplicationController < ActionController::Base
97+
has_mobile_fu
98+
before_filter :force_tablet_format
99+
end
90100

91101
Copyright (c) 2008 Brendan G. Lim, Intridea, Inc., released under the MIT license

lib/mobile-fu.rb

+18
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ def force_mobile_format
9797
session[:mobile_view] = true if session[:mobile_view].nil?
9898
end
9999
end
100+
101+
# Forces the request format to be :tablet
102+
def force_tablet_format
103+
unless request.xhr?
104+
request.format = :tablet
105+
session[:tablet_view] = true if session[:tablet_view].nil?
106+
end
107+
end
100108

101109
# Determines the request format based on whether the device is mobile or if
102110
# the user has opted to use either the 'Standard' view or 'Mobile' view.
@@ -108,6 +116,16 @@ def set_mobile_format
108116
end
109117
end
110118

119+
# Determines the request format based on whether the device is tablet or if
120+
# the user has opted to use either the 'Standard' view or 'Tablet' view.
121+
122+
def set_tablet_format
123+
if !mobile_exempt? && is_tablet_device? && !request.xhr?
124+
request.format = session[:tablet_view] == false ? :html : :tablet
125+
session[:tablet_view] = true if session[:tablet_view].nil?
126+
end
127+
end
128+
111129
# Returns either true or false depending on whether or not the format of the
112130
# request is either :mobile or not.
113131

0 commit comments

Comments
 (0)