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.425 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.420 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.419 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.418 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.417 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.416 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.415 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.414 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.413 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.412 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.411 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.410 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.409 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.407 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.408 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.398 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.397 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.396 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.395 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.1.0.dev.394 app/assets/javascripts/lalala/modules/locale_chooser.module.js