Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Refactor code
dominik-zeglen496e8506350c
diff --git a/saleor/static/dashboard/js/components/utils.js b/saleor/static/dashboard/js/components/utils.jsindex 09b748d3e2..a5ecf2d219 100644--- a/saleor/static/dashboard/js/components/utils.js+++ b/saleor/static/dashboard/js/components/utils.js@@ -11,43 +11,35 @@ try {} catch (e) {}-export function onScroll(func) {+function appendOption ($select, option) {+ $select.append($('<option></option>')+ .attr('value', option.id).text(option.text));+}++export function onScroll (func) {window.addEventListener('scroll', func, supportsPassive ? {passive: true} : false);}-export function initSelects() {+export function initSelects () {$('select:not(.browser-default):not(.enable-ajax-select2):not([multiple])').material_select();$('select[multiple]:not(.browser-default):not(.enable-ajax-select2)').select2({width: '100%'});- let $ajaxSelect2Elements = $('select.enable-ajax-select2');- $ajaxSelect2Elements.each(function() {- let $select = $(this);+ $('select.enable-ajax-select2').each((i, select) => {+ const $select = $(select);+ const initial = $select.data('initial');- if ($select.attr('data-initial')) {- function appendOption(select, option) {- $select.append($('<option></option>').attr(- 'value', option.id).text(option.text));- }-- let initial = $select.data('initial');- if (initial instanceof Array) {- let selected = []- initial.forEach(function(item) {- appendOption($select, item);- selected.push(item.id);- });- $select.val(selected);- }- else {- appendOption($select, initial);- $select.val(initial.id);- }- };+ if (initial) {+ const initialData = initial instanceof Array ? initial : [initial];+ const selected = initialData.map((item) => {+ appendOption($select, item);+ return (item.id);+ });+ $select.val(selected);+ }- let url = $select.data('url');$select.select2({ajax: {- url: url,+ url: $select.data('url'),delay: 250},width: '100%',