Skip to content

Commit

Permalink
added tablet view
Browse files Browse the repository at this point in the history
  • Loading branch information
SentulAsia committed Feb 11, 2012
1 parent 191f0a2 commit 4a67d29
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
14 changes: 12 additions & 2 deletions README.md
Expand Up @@ -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
Expand Down Expand Up @@ -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
18 changes: 18 additions & 0 deletions lib/mobile-fu.rb
Expand Up @@ -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.
Expand All @@ -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.

Expand Down

0 comments on commit 4a67d29

Please sign in to comment.