Skip to content

Commit

Permalink
Adding in a helper method to check for a specific mobile device and a…
Browse files Browse the repository at this point in the history
…dding in 'ipod' to the list of mobile user agents
  • Loading branch information
Brendan G. Lim committed Sep 8, 2008
1 parent cbb26ff commit 1a66ccd
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions lib/mobile_fu.rb
@@ -1,36 +1,16 @@
# Copyright (c) 2008 Brendan G. Lim (brendan@intridea.com)
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

module ActionController
module MobileFu

# These are various strings that can be found in mobile devices. Please feel free
# to add on to this list.


MOBILE_USER_AGENTS = 'palm|palmos|palmsource|iphone|blackberry|nokia|phone|midp|mobi|pda|' +
'wap|java|nokia|hand|symbian|chtml|wml|ericsson|lg|audiovox|motorola|' +
'samsung|sanyo|sharp|telit|tsm|mobile|mini|windows ce|smartphone|' +
'240x320|320x320|mobileexplorer|j2me|sgh|portable|sprint|vodafone|' +
'docomo|kddi|softbank|pdxgw|j-phone|astel|minimo|plucker|netfront|' +
'xiino|mot-v|mot-e|portalmmm|sagem|sie-s|sie-m|android'
'xiino|mot-v|mot-e|portalmmm|sagem|sie-s|sie-m|android|ipod'

def self.included(base)
base.extend(ClassMethods)
Expand Down Expand Up @@ -60,6 +40,8 @@ def has_mobile_fu(test_mode = false)
end

helper_method :is_mobile_device?
helper_method :is_mobile_view?
helper_method :is_device?
end

def is_mobile_device?
Expand All @@ -69,6 +51,10 @@ def is_mobile_device?
def in_mobile_view?
@@in_mobile_view
end

def is_device?(type)
@@is_device
end
end

module InstanceMethods
Expand Down Expand Up @@ -103,6 +89,10 @@ def in_mobile_view?
def is_mobile_device?
request.user_agent.to_s.downcase =~ Regexp.new(ActionController::MobileFu::MOBILE_USER_AGENTS)
end

def is_device?(type)
request.user_agent.to_s.downcase.include?(type.to_s.downcase)
end
end

end
Expand Down

0 comments on commit 1a66ccd

Please sign in to comment.