lib/world_flags/helper/view/util.rb in world-flags-0.6.0 vs lib/world_flags/helper/view/util.rb in world-flags-0.6.1
- old
+ new
@@ -27,19 +27,26 @@
def self.flag_options code, title, name, options = {}
locale = I18n.locale
extra_options = title ? {:title => title } : {}
selected = flag_selected?(code, options) ? ' selected' : ''
- language_name = WorldFlags.language(code, locale)
- country_name = WorldFlags.country(code, locale)
-
# add semi class if not selected
semi = (selected.blank? ? ' semi' : '') if options[:with_semi]
xclass = options[:class] ? " #{options[:class]}" : ''
+ if WorldFlags.country_name_enabled?
+ country_name = WorldFlags.country(code, locale)
+ end
+ country_option = country_name ? {:'data-country_name' => country_name} : {}
+
+ if WorldFlags.language_name_enabled?
+ language_name = WorldFlags.language(code, locale)
+ end
+ language_option = language_name ? {:'data-language_name' => language_name} : {}
+
flag_locale = WorldFlags.locale(code)
- {:class => "flag #{code}#{selected}#{semi}#{xclass}", :'data-country_name' => country_name, :'data-language_name' => language_name, :'data-cc' => code, :'data-locale' => flag_locale}.merge(options[:html] || {}).merge(extra_options)
+ {:class => "flag #{code}#{selected}#{semi}#{xclass}", :'data-cc' => code, :'data-locale' => flag_locale}.merge(options[:html] || {}).merge(extra_options).merge(country_option).merge(language_option)
end
def self.flag_selected? code, options = {}
code = code.to_sym
sel = options[:selected] || options[code]
\ No newline at end of file