Sha256: bced5f1a4bcdd51030fba81046dc46d0b07261eff7d1ad060abfbd2edee2623e
Contents?: true
Size: 1.39 KB
Versions: 1
Compression:
Stored size: 1.39 KB
Contents
class IsItMobile VERSION = '1.0.0.3' 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.3 | lib/is_it_mobile.rb |