Skip to content
Browse files

added tablet view

  • Loading branch information...
1 parent 191f0a2 commit 4a67d298349be2c741992d40d6bcf8aa10a2e42d @SentulAsia SentulAsia committed
Showing with 30 additions and 2 deletions.
  1. +12 −2 README.md
  2. +18 −0 lib/mobile-fu.rb
View
14 README.md
@@ -33,11 +33,15 @@ Then add the line below to config/initializers/mime_types.rb
I recommend that you setup a before_filter that will redirect to a specific page
depending on whether or not it is a mobile request. How can you check this?
- is_mobile_device? # => Returns true or false depending on the device
+ is_mobile_device? # => Returns true or false depending on the device or
+
+ is_tablet_device? # => Returns true if the device is a tablet
You can also determine which format is currently set in by calling the following:
- in_mobile_view? # => Returns true or false depending on current req. format
+ in_mobile_view? # => Returns true or false depending on current req. format or
+
+ in_tablet_view? # => Returns true if the current req. format is for tablet view
Also, if you want the ability to allow a user to switch between 'mobile' and
'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
before_filter :force_mobile_format
end
+You can also force the tablet view by calling `force_tablet_format` instead
+
+ class ApplicationController < ActionController::Base
+ has_mobile_fu
+ before_filter :force_tablet_format
+ end
Copyright (c) 2008 Brendan G. Lim, Intridea, Inc., released under the MIT license
View
18 lib/mobile-fu.rb
@@ -97,6 +97,14 @@ def force_mobile_format
session[:mobile_view] = true if session[:mobile_view].nil?
end
end
+
+ # Forces the request format to be :tablet
+ def force_tablet_format
+ unless request.xhr?
+ request.format = :tablet
+ session[:tablet_view] = true if session[:tablet_view].nil?
+ end
+ end
# Determines the request format based on whether the device is mobile or if
# the user has opted to use either the 'Standard' view or 'Mobile' view.
@@ -108,6 +116,16 @@ def set_mobile_format
end
end
+ # Determines the request format based on whether the device is tablet or if
+ # the user has opted to use either the 'Standard' view or 'Tablet' view.
+
+ def set_tablet_format
+ if !mobile_exempt? && is_tablet_device? && !request.xhr?
+ request.format = session[:tablet_view] == false ? :html : :tablet
+ session[:tablet_view] = true if session[:tablet_view].nil?
+ end
+ end
+
# Returns either true or false depending on whether or not the format of the
# request is either :mobile or not.

0 comments on commit 4a67d29

Please sign in to comment.
Something went wrong with that request. Please try again.