Sha256: 61bbe648c93e8bddbed4206a50895ef5e5293cc3284e2f3d1c44ad200cc74a30

Contents?: true

Size: 1.05 KB

Versions: 89

Compression:

Stored size: 1.05 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

89 entries across 89 versions & 1 rubygems

Version Path
lalala-4.0.0.dev.113 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.111 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.109 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.107 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.94 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.92 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.90 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.84 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.80 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.79 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.78 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.77 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.74 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.73 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.72 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.71 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.66 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.65 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.64 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.63 app/assets/javascripts/lalala/modules/locale_chooser.module.js