Sha256: b7bcfd944e12796b5f670718debd2506c87104dddcb4f16f37c6e5dd64ed05b3

Contents?: true

Size: 1.06 KB

Versions: 98

Compression:

Stored size: 1.06 KB

Contents

var storage = require("lalala/modules/storage"),
    $chooser;


exports.init = function(){
  $chooser = $('.locale_chooser select').first();

  if ($chooser.length > 0) {
    setup();
  }
};


function setup() {
  var locale = storage.locale,
      default_locale;

  if (!locale) {
    locale = "__EMPTY__";
  }

  if ($chooser.find('option[value='+locale+']').length === 0) {
    locale = "__EMPTY__";
  }

  if (locale == "__EMPTY__") {
    default_locale = $chooser.find('option[data-default]').first();
    if (default_locale.length === 0) {
      default_locale = $chooser.find('option').first();
    }
    locale = default_locale.attr('value');
  }

  switch_locale(locale);

  $chooser.val(locale);
  $chooser.on('change', on_switch_locale);
}


function on_switch_locale(e) {
  switch_locale($(this).val());
}


function switch_locale(locale) {
  var translated = $(".translated[data-locale]"),
      current    = translated.filter("*[data-locale="+locale+"]"),
      other      = translated.not(current);

  other.hide();
  current.show();

  storage.locale = locale;
}

Version data entries

98 entries across 98 versions & 1 rubygems

Version Path
lalala-4.0.0.dev.264 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.260 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.258 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.256 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.255 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.254 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.249 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.246 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.244 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.243 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.242 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.240 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.239 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.236 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.231 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.229 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.227 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.224 app/assets/javascripts/lalala/modules/locale_chooser.module.js