<commit_before>/**
 * Tatoeba Project, free collaborative creation of multilingual corpuses project
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

(function() {
    'use strict';

    angular
        .module('app')
        .directive(
            'languageDropdown',
            languageDropdown
        );

    function languageDropdown() {
        return {
            scope: true,
            controller: LanguageDropdownController,
            controllerAs: 'vm'
        };
    }

    function LanguageDropdownController($scope) {
        var vm = this;
        var languages = [];
        var name = '';

        vm.previousSelectedItem = languages[0];
        vm.selectedItem = null;
        vm.searchText = '';

        vm.init = init;
        vm.querySearch = querySearch;
        vm.onSelectedItemChange = onSelectedItemChange;
        vm.onSearchTextChange = onSearchTextChange;
        vm.onBlur = onBlur;
        vm.onFocus = onFocus;

        /////////////////////////////////////////////////////////////////////////

        $scope.$on('setLang', function(event, data){
            if (data.name && data.name === name) {
                setLang(data.lang);
            }
        });

        /////////////////////////////////////////////////////////////////////////

        function init(data, selectedLang, dropdownName) {
            var isPriority;
            name = dropdownName;
            
            Object.keys(data).forEach((key1) => {
                if (typeof data[key1] === 'object'){
                    var items = data[key1];
                    isPriority = !isPriority && key1 !== '0';
                    Object.keys(items).forEach((key2) => {
                        languages.push({code: key2, name: items[key2], isPriority: isPriority});
                    });
                } else {
                    languages.push({code: key1, name: data[key1]});
                }
            });

            if (selectedLang) {
                setLang(selectedLang);
            }
        }

        function querySearch(value) {
            if (value) {
                var search = value.toLowerCase();
                return languages.filter((item) => {
                    var language = item.name.toLowerCase();
                    return language.indexOf(search) > -1;
                }).sort(function(itemA, itemB) {
                    var nameA = itemA.name.toLowerCase();
                    var nameB = itemB.name.toLowerCase();
                    return nameA.indexOf(search) > nameB.indexOf(search);
                });
            } else {
                return languages;
            }
        }

        function onSelectedItemChange(item) {
            if (vm.selectedItem) {
                $scope.$parent.$broadcast('languageChange', {name: name, lang: vm.selectedItem.code});
            }            
        }

        function setLang(lang) {
            vm.selectedItem = languages.find((item) => {
                return item.code === lang;
            });
            $scope.$parent.$broadcast('languageChange', {name: name, lang: lang});
        }

        function onSearchTextChange() {
            console.log(vm.searchText);
            vm.searchText = vm.searchText.replace(/\t/, ' ');
        }

        function onBlur() {
            if (!vm.selectedItem) {
                vm.selectedItem = vm.previousSelectedItem;
            }
        }

        function onFocus() {
            if (vm.selectedItem) {
                vm.previousSelectedItem = vm.selectedItem;
                vm.searchText = '';
            }
        }
    }

})();<commit_msg>Remove Javascript arrows<commit_after>/**
 * Tatoeba Project, free collaborative creation of multilingual corpuses project
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

(function() {
    'use strict';

    angular
        .module('app')
        .directive(
            'languageDropdown',
            languageDropdown
        );

    function languageDropdown() {
        return {
            scope: true,
            controller: LanguageDropdownController,
            controllerAs: 'vm'
        };
    }

    function LanguageDropdownController($scope) {
        var vm = this;
        var languages = [];
        var name = '';

        vm.previousSelectedItem = languages[0];
        vm.selectedItem = null;
        vm.searchText = '';

        vm.init = init;
        vm.querySearch = querySearch;
        vm.onSelectedItemChange = onSelectedItemChange;
        vm.onSearchTextChange = onSearchTextChange;
        vm.onBlur = onBlur;
        vm.onFocus = onFocus;

        /////////////////////////////////////////////////////////////////////////

        $scope.$on('setLang', function(event, data){
            if (data.name && data.name === name) {
                setLang(data.lang);
            }
        });

        /////////////////////////////////////////////////////////////////////////

        function init(data, selectedLang, dropdownName) {
            var isPriority;
            name = dropdownName;
            
            Object.keys(data).forEach(function (key1) {
                if (typeof data[key1] === 'object'){
                    var items = data[key1];
                    isPriority = !isPriority && key1 !== '0';
                    Object.keys(items).forEach(function (key2) {
                        languages.push({code: key2, name: items[key2], isPriority: isPriority});
                    });
                } else {
                    languages.push({code: key1, name: data[key1]});
                }
            });

            if (selectedLang) {
                setLang(selectedLang);
            }
        }

        function querySearch(value) {
            if (value) {
                var search = value.toLowerCase();
                return languages.filter(function (item) {
                    var language = item.name.toLowerCase();
                    return language.indexOf(search) > -1;
                }).sort(function(itemA, itemB) {
                    var nameA = itemA.name.toLowerCase();
                    var nameB = itemB.name.toLowerCase();
                    return nameA.indexOf(search) > nameB.indexOf(search);
                });
            } else {
                return languages;
            }
        }

        function onSelectedItemChange(item) {
            if (vm.selectedItem) {
                $scope.$parent.$broadcast('languageChange', {name: name, lang: vm.selectedItem.code});
            }            
        }

        function setLang(lang) {
            vm.selectedItem = languages.find(function (item) {
                return item.code === lang;
            });
            $scope.$parent.$broadcast('languageChange', {name: name, lang: lang});
        }

        function onSearchTextChange() {
            console.log(vm.searchText);
            vm.searchText = vm.searchText.replace(/\t/, ' ');
        }

        function onBlur() {
            if (!vm.selectedItem) {
                vm.selectedItem = vm.previousSelectedItem;
            }
        }

        function onFocus() {
            if (vm.selectedItem) {
                vm.previousSelectedItem = vm.selectedItem;
                vm.searchText = '';
            }
        }
    }

})();
{'fraction_non_alphanumeric': 0.13550580236783497, 'fraction_numerical': 0.0030477083577540734, 'mean_word_length': 1.442599484683653, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1556399', 'n_tokens_mistral': 2128, 'n_tokens_neox': 2044, 'n_words': 538}