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.1.0.dev.392 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.393 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.391 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.390 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.389 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.388 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.387 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.386 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.385 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.384 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.382 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.381 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.376 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.375 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.374 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.372 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.368 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.367 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.366 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.360 app/assets/javascripts/lalala/modules/locale_chooser.module.js