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.219 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.218 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.217 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.216 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.215 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.212 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.208 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.202 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.201 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.198 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.195 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.194 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.193 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.192 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.191 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.190 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.189 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.188 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.187 app/assets/javascripts/lalala/modules/locale_chooser.module.js
lalala-4.0.0.dev.186 app/assets/javascripts/lalala/modules/locale_chooser.module.js