携帯の文字入力の入力モード?をキャリアによって自動で変換してくれるようなもの
を作ってみました。
※jpmobileを使ってます。
module MobileExtraHelper
def mob_im_options(options)
if options["im_type"]
options[:im_type] = options["im_type"]
options.delete("im_type")
end
return options unless options[:im_type]
case options[:im_type]
when 1, 'h', 'M', 'hiragana', /^hira$/i, 410 # かな
options[:im_type] = 410
when 2, 'hk' 'katakana', /^kana$/i, 411 # カナ
options[:im_type] = 411
when 3, 'en', 'm', 'alphabet', /^latn$/i, 215 # 半角英字
options[:im_type] = 215
when 4, 'n', 'N', /num/i, 10 # 半角数字
options[:im_type] = 10
else
options[:im_type] = nil
end
request ||= @template.request if @template
if defined?(request) && defined?(request.mobile) && options[:im_type]
case request.mobile
when Jpmobile::Mobile::Docomo
options[:style] ||= ""
options[:style] << ';' if options[:style] =~ /¥s/
case options[:im_type]
when 410
options[:istyle] = 1
options[:style] << "-wap-input-format:"*<ja:h>""
when 411
options[:istyle] = 2
options[:style] << "-wap-input-format:"*<ja:hk>""
when 215
options[:istyle] = 3
options[:style] << "-wap-input-format:"*<ja:en>""
when 10
options[:istyle] = 4
options[:style] << "-wap-input-format:"*<ja:n>""
end
when Jpmobile::Mobile::Au
options[:format] =
case options[:im_type]
when 410, 411
"M"
when 215
"m"
when 10
"N"
end
when Jpmobile::Mobile::Softbank
options[:mode] =
case options[:im_type]
when 410
"hiragana"
when 411
"hankakukana"
when 215
"alphabet"
when 10
"numeric"
end
else
options[:mode] =
case options[:im_type]
when 410
"hiragana1"
when 411
"hankakukana1"
when 215
"alphabet1"
when 10
"numeric1"
end
end
end
options.delete(:im_type)
return options
end
end
ActionView::Base.send(:include, MobileExtraHelper)
# 続き↓
module ActionView::Helpers
module TagHelper
private
def tag_options_with_mob_im(options, escape = true)
mob_im_options(options)
tag_options_without_mob_im(options, escape)
end
alias_method_chain :tag_options, :mob_im
end
class FormBuilder
include MobileExtraHelper
private
def objectify_options_with_mob_im(options)
mob_im_options(options)
objectify_options_without_mob_im(options)
end
alias_method_chain :objectify_options, :mob_im
end
class InstanceTag
include MobileExtraHelper
end
module DateHelper
include MobileExtraHelper
end
end