Module: ActionController::MobileFuForJqueryMobile::InstanceMethods

Defined in:
lib/mobile-fu-for-jquery-mobile.rb

Instance Method Summary collapse

Instance Method Details

#force_mobile_formatObject

Forces the request format to be :mobile



113
114
115
116
117
118
# File 'lib/mobile-fu-for-jquery-mobile.rb', line 113

def force_mobile_format
  unless request.xhr?
    request.format = :mobile
    session[:mobile_view] = true if session[:mobile_view].nil?
  end
end

#force_tablet_formatObject

Forces the request format to be :tablet



121
122
123
124
125
126
# File 'lib/mobile-fu-for-jquery-mobile.rb', line 121

def force_tablet_format
  unless request.xhr?
    request.format = :tablet
    session[:tablet_view] = true if session[:tablet_view].nil?
  end
end

#in_mobile_view?Boolean

Returns either true or false depending on whether or not the format of the request is either :mobile or not.

Returns:

  • (Boolean)


145
146
147
148
# File 'lib/mobile-fu-for-jquery-mobile.rb', line 145

def in_mobile_view?
  return false unless request.format
  request.format.to_sym == :mobile
end

#in_tablet_view?Boolean

Returns either true or false depending on whether or not the format of the request is either :tablet or not.

Returns:

  • (Boolean)


153
154
155
156
# File 'lib/mobile-fu-for-jquery-mobile.rb', line 153

def in_tablet_view?
  return false unless request.format
  request.format.to_sym == :tablet
end

#is_device?(type) ⇒ Boolean

Can check for a specific user agent e.g., is_device?(‘iphone’) or is_device?(‘mobileexplorer’)

Returns:

  • (Boolean)


176
177
178
# File 'lib/mobile-fu-for-jquery-mobile.rb', line 176

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

#is_mobile_device?Boolean

Returns:

  • (Boolean)


165
166
167
# File 'lib/mobile-fu-for-jquery-mobile.rb', line 165

def is_mobile_device?
  !is_tablet_device? && !!mobile_device
end

#is_tablet_device?Boolean

Returns either true or false depending on whether or not the user agent of the device making the request is matched to a device in our regex.

Returns:

  • (Boolean)


161
162
163
# File 'lib/mobile-fu-for-jquery-mobile.rb', line 161

def is_tablet_device?
  ::MobileFuForJqueryMobile::Tablet.is_a_tablet_device? request.user_agent
end

#mobile_action?Boolean

Returns true if current action is supposed to use mobile format See #has_mobile_fu_for

Returns:

  • (Boolean)


182
183
184
185
186
187
188
# File 'lib/mobile-fu-for-jquery-mobile.rb', line 182

def mobile_action?
  if self.class.instance_variable_get("@mobile_include_actions").nil? #Now we know we dont have any includes, maybe excludes?
    return !mobile_exempt?
  else
    self.class.instance_variable_get("@mobile_include_actions").try(:include?, params[:action].try(:to_sym))
  end
end

#mobile_deviceObject



169
170
171
# File 'lib/mobile-fu-for-jquery-mobile.rb', line 169

def mobile_device
  request.headers['X_MOBILE_DEVICE']
end

#mobile_exempt?Boolean

Returns true if current action isn’t supposed to use mobile format See #has_no_mobile_fu_for

Returns:

  • (Boolean)


193
194
195
# File 'lib/mobile-fu-for-jquery-mobile.rb', line 193

def mobile_exempt?
  self.class.instance_variable_get("@mobile_exempt_actions").try(:include?, params[:action].try(:to_sym))
end

#set_mobile_formatObject

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 or ‘Tablet’ view.



132
133
134
135
136
137
138
139
140
# File 'lib/mobile-fu-for-jquery-mobile.rb', line 132

def set_mobile_format
  if request.format.html? && mobile_action? && is_mobile_device? && (!request.xhr? || request.headers["jqm-Ajax-Request"])
    request.format = :mobile unless session[:mobile_view] == false
    session[:mobile_view] = true if session[:mobile_view].nil?
  elsif request.format.html? && mobile_action? && is_tablet_device? && (!request.xhr? || request.headers["jqm-Ajax-Request"])
    request.format = :tablet unless session[:tablet_view] == false
    session[:tablet_view] = true if session[:tablet_view].nil?
  end
end

#set_request_format(force_mobile = false) ⇒ Object Also known as: set_device_type



107
108
109
# File 'lib/mobile-fu-for-jquery-mobile.rb', line 107

def set_request_format(force_mobile = false)
  force_mobile ? force_mobile_format : set_mobile_format
end