Magento – Country flag images

imagelanguage

Are there default country flag images somewhere, or is it my resposibilitiy to supply these images if I want a flag-ased language selector? I could not find any, but there is a flags.phtml for the switch block. Am I missing something?

Best Answer

This JS-Snippet will extend Textlinks to the standard select (additional CSS needed to hide standard select). Works for 1.9. You might want to use images instead text:

// Helper
Element.addMethods("SELECT", (function() {
    function getSelectedOptionHTML(element) {
        if (!(element = $(element))) return;
        var index = element.selectedIndex;
        return index >= 0 ? element.options[index].innerHTML : undefined;
    }

    return {
        getSelectedOptionHTML: getSelectedOptionHTML
    };
})());


// Language Chooser: Extend Text Links
var languageselected = $('select-language').getSelectedOptionHTML();
var activeLangClass = "active";
if ($(".your-flag-container")){
    $(".your-flag-container")[0].remove();
}
$$('#select-language option').each(function(item) {
    var t = item.text;
    var v = item.value;


    var tpl = "<span class='your-flag-container'><a class='your-single-flag your-single-flag-" + t + "' href='" + v + "' title='" + t + "' >" + t + "</a></span>";
    $$(".form-language")[0].insert(tpl);
});

$$(".your-single-flag-" + languageselected)[0].addClassName(activeLangClass);
Related Topic