Здравствуйте, столкнулся с проблемой плохо оптимизированного кода, его нужно скоротить, а знаний как это делать не хватает, не подскажите как будет лучше его скоротить?
Скрипт уменьшен на 2\3 поскольку в пост нельзя больше 10 к символов вставлять, найбольше места занимает часть с IF\ELSE.
Спасибо.
PS. сократить нужно только if else не изменяя другую часть кода.
var cppm;
if (width < 768) {
if ($('.ppm[data-toggle="popover"]').hasClass("xs-bottom")) {
cppm = 'bottom';
} else if ($('.ppm[data-toggle="popover"]').hasClass("xs-top")) {
cppm = 'top';
} else if ($('.ppm[data-toggle="popover"]').hasClass("xs-left")) {
cppm = 'left';
} else if ($('.ppm[data-toggle="popover"]').hasClass("xs-right")) {
cppm = 'right';
}
} else if (width >= 768 && width < 992) {
if ($('.ppm[data-toggle="popover"]').hasClass("sm-bottom")) {
cppm = 'bottom';
} else if ($('.ppm[data-toggle="popover"]').hasClass("sm-top")) {
cppm = 'top';
} else if ($('.ppm[data-toggle="popover"]').hasClass("sm-left")) {
cppm = 'left';
} else if ($('.ppm[data-toggle="popover"]').hasClass("sm-right")) {
cppm = 'right';
}
} else if (width >= 992 && width < 1200) {
if ($('.ppm[data-toggle="popover"]').hasClass("md-bottom")) {
cppm = 'bottom';
} else if ($('.ppm[data-toggle="popover"]').hasClass("md-top")) {
cppm = 'top';
} else if ($('.ppm[data-toggle="popover"]').hasClass("md-left")) {
cppm = 'left';
} else if ($('.ppm[data-toggle="popover"]').hasClass("md-right")) {
cppm = 'right';
}
} else if (width >= 1200 && width < 1600) {
if ($('.ppm[data-toggle="popover"]').hasClass("lg-bottom")) {
cppm = 'bottom';
} else if ($('.ppm[data-toggle="popover"]').hasClass("lg-top")) {
cppm = 'top';
} else if ($('.ppm[data-toggle="popover"]').hasClass("lg-left")) {
cppm = 'left';
} else if ($('.ppm[data-toggle="popover"]').hasClass("lg-right")) {
cppm = 'right';
}
} else if (width >= 1600) {
if ($('.ppm[data-toggle="popover"]').hasClass("xlg-bottom")) {
cppm = 'bottom';
} else if ($('.ppm[data-toggle="popover"]').hasClass("xlg-top")) {
cppm = 'top';
} else if ($('.ppm[data-toggle="popover"]').hasClass("xlg-left")) {
cppm = 'left';
} else if ($('.ppm[data-toggle="popover"]').hasClass("xlg-right")) {
cppm = 'right';
}
}
var pchedt;
if (width < 768) {
if ($('.has-error [data-toggle="popover"]').hasClass("xs-bottom")) {
pchedt = 'bottom';
} else if ($('.has-error [data-toggle="popover"]').hasClass("xs-top")) {
pchedt = 'top';
} else if ($('.has-error [data-toggle="popover"]').hasClass("xs-left")) {
pchedt = 'left';
} else if ($('.has-error [data-toggle="popover"]').hasClass("xs-right")) {
pchedt = 'right';
}
} else if (width >= 768 && width < 992) {
if ($('.has-error [data-toggle="popover"]').hasClass("sm-bottom")) {
pchedt = 'bottom';
} else if ($('.has-error [data-toggle="popover"]').hasClass("sm-top")) {
pchedt = 'top';
} else if ($('.has-error [data-toggle="popover"]').hasClass("sm-left")) {
pchedt = 'left';
} else if ($('.has-error [data-toggle="popover"]').hasClass("sm-right")) {
pchedt = 'right';
}
} else if (width >= 992 && width < 1200) {
if ($('.has-error [data-toggle="popover"]').hasClass("md-bottom")) {
pchedt = 'bottom';
} else if ($('.has-error [data-toggle="popover"]').hasClass("md-top")) {
pchedt = 'top';
} else if ($('.has-error [data-toggle="popover"]').hasClass("md-left")) {
pchedt = 'left';
} else if ($('.has-error [data-toggle="popover"]').hasClass("md-right")) {
pchedt = 'right';
}
} else if (width >= 1200 && width < 1600) {
if ($('.has-error [data-toggle="popover"]').hasClass("lg-bottom")) {
pchedt = 'bottom';
} else if ($('.has-error [data-toggle="popover"]').hasClass("lg-top")) {
pchedt = 'top';
} else if ($('.has-error [data-toggle="popover"]').hasClass("lg-left")) {
pchedt = 'left';
} else if ($('.has-error [data-toggle="popover"]').hasClass("lg-right")) {
pchedt = 'right';
}
} else if (width >= 1600) {
if ($('.has-error [data-toggle="popover"]').hasClass("xlg-bottom")) {
pchedt = 'bottom';
} else if ($('.has-error [data-toggle="popover"]').hasClass("xlg-top")) {
pchedt = 'top';
} else if ($('.has-error [data-toggle="popover"]').hasClass("xlg-left")) {
pchedt = 'left';
} else if ($('.has-error [data-toggle="popover"]').hasClass("xlg-right")) {
pchedt = 'right';
}
}
var pche;
if (width < 768) {
if ($('.has-error [data-toggle="popover"]').hasClass("xs-bottom")) {
pche = 'bottom';
} else if ($('.has-error [data-toggle="popover"]').hasClass("xs-top")) {
pche = 'top';
} else if ($('.has-error [data-toggle="popover"]').hasClass("xs-left")) {
pche = 'left';
} else if ($('.has-error [data-toggle="popover"]').hasClass("xs-right")) {
pche = 'right';
}
} else if (width >= 768 && width < 992) {
if ($('.has-error [data-toggle="popover"]').hasClass("sm-bottom")) {
pche = 'bottom';
} else if ($('.has-error [data-toggle="popover"]').hasClass("sm-top")) {
pche = 'top';
} else if ($('.has-error [data-toggle="popover"]').hasClass("sm-left")) {
pche = 'left';
} else if ($('.has-error [data-toggle="popover"]').hasClass("sm-right")) {
pche = 'right';
}
} else if (width >= 992 && width < 1200) {
if ($('.has-error [data-toggle="popover"]').hasClass("md-bottom")) {
pche = 'bottom';
} else if ($('.has-error [data-toggle="popover"]').hasClass("md-top")) {
pche = 'top';
} else if ($('.has-error [data-toggle="popover"]').hasClass("md-left")) {
pche = 'left';
} else if ($('.has-error [data-toggle="popover"]').hasClass("md-right")) {
pche = 'right';
}
} else if (width >= 1200 && width < 1600) {
if ($('.has-error [data-toggle="popover"]').hasClass("lg-bottom")) {
pche = 'bottom';
} else if ($('.has-error [data-toggle="popover"]').hasClass("lg-top")) {
pche = 'top';
} else if ($('.has-error [data-toggle="popover"]').hasClass("lg-left")) {
pche = 'left';
} else if ($('.has-error [data-toggle="popover"]').hasClass("lg-right")) {
pche = 'right';
}
} else if (width >= 1600) {
if ($('.has-error [data-toggle="popover"]').hasClass("xlg-bottom")) {
pche = 'bottom';
} else if ($('.has-error [data-toggle="popover"]').hasClass("xlg-top")) {
pche = 'top';
} else if ($('.has-error [data-toggle="popover"]').hasClass("xlg-left")) {
pche = 'left';
} else if ($('.has-error [data-toggle="popover"]').hasClass("xlg-right")) {
pche = 'right';
}
}
var a = {
trigger: "hover",
container: "body",
placement: "top",
html: !0,
viewport: {
selector: "body",
padding: 2
},
template: '<div class="popover"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
},
b = {
trigger: "hover",
container: "body",
placement: "top",
html: !0,
template: '<div class="popover"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
},
c = {
trigger: "hover",
container: "body",
placement: pchedt,
html: !0,
template: '<div class="popover popover-error"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
},
d = {
trigger: "hover",
container: "body",
placement: pche,
html: !0,
template: '<div class="popover popover-error"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
},
e = {
trigger: "hover",
container: "body",
placement: cppm,
delay: {
show: 500,
hide: 10
},
html: !0,
template: '<div class="popover"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
},
f = {
trigger: "hover",
container: "body",
placement: pcao,
html: !0,
template: '<div class="popover"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
};
$(".mobile-checkout").length > 0 ? ($('.ppm[data-toggle="popover"]').popover(e),
$('.spm[data-toggle="popover"]').popover(e1),
$('.has-error [data-toggle="popover"]').popover(d),
$('[data-toggle="popover"]').popover(b)) : ($('.ppm[data-toggle="popover"]').popover(e),
$('.has-error [data-toggle="popover"]').popover(c),
$('[data-toggle="popover"]').popover(a))