Sha256: b1fbd76fcded8068c1f280d9afac11ff357833b18c1244feb26fe5d08a4011cb
Contents?: true
Size: 1.39 KB
Versions: 1
Compression:
Stored size: 1.39 KB
Contents
class IsItMobile VERSION = '1.0.0.2' POPULAR_MOBILE_USER_AGENT_BEGINNINGS = ['w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac', 'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno','ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-', 'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-','newt','noki','oper','palm','pana','pant','phil','play','port','prox', 'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar','sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-', 'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp','wapr','webc','winw','winw','xda','xda-'] module ForRails def self.included(base) base.class_eval do before_filter :wrangle_format_if_request_is_mobile end end protected def wrangle_format_if_request_is_mobile request.format = :mobile if IsItMobile.mobile?( request.env['HTTP_USER_AGENT'] || '', request.env['HTTP_ACCEPT'] || '' ) end end # Check if the given user agent is for a mobile device. def self.mobile?( user_agent, accepts ) return !!( user_agent =~ /(mobile|up.browser|up.link|mmp|symbian|phone|midp|wap|mini|ppc;|playstation|palm|wii|nitro)/i || accepts.index('application/vnd.wap.xhtml+xml') || POPULAR_MOBILE_USER_AGENT_BEGINNINGS.include?(user_agent[0,4])) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
is_it_mobile-1.0.0.2 | lib/is_it_mobile.rb |