Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mehmetsagir/8a06c4a16fecd126206aa85ead62bf2b to your computer and use it in GitHub Desktop.

Select an option

Save mehmetsagir/8a06c4a16fecd126206aa85ead62bf2b to your computer and use it in GitHub Desktop.
resize
/**
* AutoResize Sistemi - Refaktör Edilmiş Sürüm
* E-ticaret platformları için görsel optimizasyonu ve yeniden boyutlandırma sistemi
*
* @yazar Mehmet Sağır
* @sürüm 4.24.3
* @açıklama Fancybox içerisinde olan görsellerin de yeniden boyutlandırılabilmesi için elementsForListe içerisine '.ProductPreviewItem', '.PreviewallImagesItem' class'ları eklenmiştir.
*/
// String'lerde startsWith kontrolü için yardımcı fonksiyon
String.prototype.customStartsWidth = function (prefix) {
return this.toString().substring(0, prefix.length) === prefix;
};
/**
* Konfigürasyon sabitleri
*/
const CONFIG = {
CDN: {
SOURCE_URL: "https://static.ticimax.cloud",
IMAGE_URL: "https://static.ticimax.cloud/cdn-cgi/image"
},
DEFAULT_QUALITY: 80,
MIN_WIDTH: 2,
ALLOWED_EXTENSIONS: ["jpg", "jpeg", "png", "gif"],
TARGET_ROOT_ELEMENT: "#divIcerik",
BANNED_URLS: ["blank.png", "load.gif"],
BANNED_ELEMENTS: ["#div-drift-container > div > img"],
CUSTOM_AUTO_RESIZE_WIDTH_PATHS: [
"urunresimleri",
"ilgiliurunresim",
"aksesuarurunresim"
]
};
/**
* Image attribute configurations
*/
const IMAGE_ATTRIBUTES = [
{ attributeName: "src", fullWidth: false },
{ attributeName: "data-original", fullWidth: false },
{ attributeName: "data-bigimg", fullWidth: true },
{ attributeName: "data-second", fullWidth: false },
{ attributeName: "data-src", fullWidth: false },
{ attributeName: "data-zoom", fullWidth: true }
];
/**
* Target folder configurations
*/
const TARGET_FOLDERS = [
{
name: "urunresimleri",
checkThumb: true,
forceBigKey: true,
customValues: { quality: 85 },
imageType: "product"
},
{
name: "ilgiliurunresim",
checkThumb: true,
forceBigKey: false,
customValues: { quality: 85 },
imageType: "product"
},
{
name: "aksesuarurunresim",
checkThumb: true,
forceBigKey: false,
customValues: { quality: 85 },
imageType: "product"
},
{
name: "sayfatasarim",
checkThumb: false,
forceBigKey: false,
customValues: { quality: 99 },
imageType: "design"
},
{
name: "editoruploads",
checkThumb: false,
forceBigKey: false,
customValues: { quality: 99 },
imageType: "design"
},
{
name: "images",
checkThumb: false,
forceBigKey: false,
customValues: { quality: 99 },
imageType: "design"
},
{
name: "dosyalar",
checkThumb: false,
forceBigKey: false,
customValues: { quality: 99 },
imageType: "design"
},
{
name: "kampanyabanner",
checkThumb: false,
forceBigKey: false,
customValues: { quality: 99 },
imageType: "design"
},
{
name: "marka",
checkThumb: false,
forceBigKey: false,
customValues: { quality: 99 },
imageType: "brand"
},
{
name: "blog",
checkThumb: false,
forceBigKey: false,
customValues: { quality: 99 },
imageType: "blog"
}
];
/**
* Yeniden boyutlandırma için zorunlu genişlik ayarları (responsive tasarım)
*/
const FORCE_WIDTH_CONFIG = {
enable: true,
devices: [
{ minWidth: 541, forceWidth: 540 }
]
};
/**
* Eleman durum seçicileri
*/
const ELEMENT_STATES = {
elementsForDetay: [".productDetailContainer", ".SmallImages"],
elementsForListe: [".productItem", ".ProductPreviewItem", ".PreviewallImagesItem"]
};
/**
* Observer (gözlemci) ayarları
*/
const OBSERVER_CONFIG = {
body: {
container: document.documentElement || document.body,
config: {
subtree: true,
attributes: true,
attributeFilter: ["src", "data-src", "data-second", "data-ayar"]
}
},
element: {
config: { childList: true, subtree: true }
}
};
/**
* Ortak işlemler için yardımcı sınıf
*/
class AutoResizeUtils {
static isMobileDevice() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
static hasAttr(element, attributeName) {
if (!$(element).length) return false;
const attributeValue = $(element).attr(attributeName);
return typeof attributeValue !== 'undefined' && attributeValue !== false;
}
static addAttributeWithCounter(element, attrName) {
if (this.hasAttr(element, attrName)) {
const attrValue = parseInt($(element).attr(attrName)) + 1;
$(element).attr(attrName, attrValue);
} else {
$(element).attr(attrName, 1);
}
}
}
/**
* Ana AutoResize sınıfı
*/
class AutoResize {
constructor() {
this.initializeProperties();
this.importCustomerSizes();
}
initializeProperties() {
this.sourceTargetCdnUrl = CONFIG.CDN.SOURCE_URL;
this.cdnUrl = CONFIG.CDN.IMAGE_URL;
this.allowedSrcAttributes = IMAGE_ATTRIBUTES;
this.targetUrlFolders = TARGET_FOLDERS;
this.quality = CONFIG.DEFAULT_QUALITY;
this.allowedImgExtensions = CONFIG.ALLOWED_EXTENSIONS;
this.forceWidth = FORCE_WIDTH_CONFIG;
this.targetRootElement = CONFIG.TARGET_ROOT_ELEMENT;
this.resizeTickRunning = false;
this.bannedElement = CONFIG.BANNED_ELEMENTS;
this.bannedUrl = CONFIG.BANNED_URLS;
this.minWidth = CONFIG.MIN_WIDTH;
this.customAutoResizeWidthAllowedPaths = CONFIG.CUSTOM_AUTO_RESIZE_WIDTH_PATHS;
this.bodyObserver = { ...OBSERVER_CONFIG.body, instance: null };
this.elementObserver = { ...OBSERVER_CONFIG.element, instance: null };
this.customerSizeSettings = null;
this.elementsForTargetState = ELEMENT_STATES;
this.bannerFolders = this.targetUrlFolders.filter(item => item.imageType === "design");
this.autoResizeRunningStatus = false;
this.version = "4.24.3";
this.releaseDescription = "(TV9-20269) Fancybox icerisinde olan gorsellerin de resize olabilmesi icin elementsForListe icerisine '.ProductPreviewItem', '.PreviewallImagesItem' class'lari eklenmistir.";
this.author = "Mehmet Sağır";
}
/**
* AutoResize sistemini başlatır
*/
init() {
$(document).trigger("AutoResize-Initializing");
this.resize($(this.targetRootElement));
this.changeUrl();
$(document).trigger("AutoResize-Initialized");
this.injectBodyObserver();
this.injectElementObserver();
}
/**
* Müşteri boyut ayarlarını global konfigürasyondan alır
*/
importCustomerSizes() {
if (window.siteSettings?.siteYonetimAyar?.resimAyar?.imageCustomResizeActive) {
this.customerSizeSettings = window.siteSettings.siteYonetimAyar.resimAyar.imageCustomResize;
// Detay sayfaları için yasaklı kapsayıcıları ekle
if (this.customerSizeSettings?.mobil?.detay) {
this.customerSizeSettings.mobil.detay.bannedInclusives = ["#BenzerUrunDiv"];
}
if (this.customerSizeSettings?.web?.detay) {
this.customerSizeSettings.web.detay.bannedInclusives = ["#BenzerUrunDiv"];
}
}
}
/**
* Periyodik yeniden boyutlandırma için ana tick fonksiyonu
*/
tick() {
if (this.resizeTickRunning) return;
this.resizeTickRunning = true;
this.resizeTickSetToWorkAgain = false;
this.resize($(this.targetRootElement), null);
this.changeUrl();
$(document).trigger("AutoResize-Tick");
this.resizeTickRunning = false;
this.injectBodyObserver();
}
/**
* Hedef elementteki veya belirli bir görseldeki resimleri yeniden boyutlandırır
*/
resize(targetElement = null, img = null) {
if (!targetElement && !img) return;
let images = [];
if (img) {
images = $(img).toArray();
} else if (targetElement) {
images = $(targetElement).find("img").toArray();
}
if (!images.length) return;
images.forEach(img => {
if (!AutoResizeUtils.hasAttr(img, "resize-banned")) {
this.changeSize(img);
}
});
}
/**
* Belirli bir görselin boyutunu değiştirir
*/
changeSize(img, customAttr = null, customWidth = null) {
const changeSizeForAttr = (attr) => {
const findAttr = this.allowedSrcAttributes.find(a => a.attributeName === attr.attributeName);
const finalAttr = findAttr || { attributeName: attr, fullWidth: false };
let width = customWidth || (finalAttr.fullWidth ? "-" : this.getWidth(img));
const attrValue = $(img).attr(finalAttr.attributeName);
// URL yasaklı desen içeriyorsa atla
if (this.bannedUrl.some(banned => attrValue.indexOf(banned) > -1)) return;
const createdNewUrl = this.createUrl(attrValue, width, img);
if (attrValue !== createdNewUrl) {
const oldAttrValue = attrValue;
$(img).attr(finalAttr.attributeName, createdNewUrl);
$(img).attr(finalAttr.attributeName + "-last", oldAttrValue);
$(document).trigger("element-attribute-resized", [img, finalAttr, oldAttrValue, createdNewUrl]);
}
};
if (customAttr) {
if (AutoResizeUtils.hasAttr(img, customAttr) && this.checkStartWith($(img).attr(customAttr))) {
changeSizeForAttr({ attributeName: customAttr, fullWidth: false });
}
} else {
this.allowedSrcAttributes.forEach(attr => {
if (AutoResizeUtils.hasAttr(img, attr.attributeName) && this.checkStartWith($(img).attr(attr.attributeName))) {
changeSizeForAttr(attr);
}
});
}
}
/**
* URL'nin CDN ile başlayıp başlamadığını ve geçerli olup olmadığını kontrol eder
*/
checkStartWith(url) {
if (!url) return false;
const checkUrl = url.customStartsWidth(`${this.sourceTargetCdnUrl}/`) ||
url.customStartsWidth(`${this.cdnUrl}/`);
const checkExt = this.checkExtension(url);
const folderCheckStatus = this.targetUrlFolders.some(folder =>
url.toLowerCase().indexOf(folder.name.toLowerCase()) > 0
);
return checkUrl && checkExt && folderCheckStatus;
}
/**
* URL'nin izin verilen görsel uzantısına sahip olup olmadığını kontrol eder
*/
checkExtension(url) {
if (!url) return false;
const splitted = url.toLowerCase().split("?");
const ext = splitted[0].substring(splitted[0].lastIndexOf(".") + 1).toLowerCase();
return this.allowedImgExtensions.includes(ext);
}
/**
* CDN parametreleriyle optimize edilmiş URL oluşturur
*/
createUrl(url, width, img = null) {
let cleanedUrl = "";
let createUrl = "";
if (width !== "-") {
width = Math.floor(width);
}
// Mevcut CDN parametrelerini temizle
if (url.indexOf("format=") > 0) {
cleanedUrl = url
.replace(`${this.sourceTargetCdnUrl}/`, "")
.replace(`${this.cdnUrl}/`, "")
.replace("cdn-cgi/image/", "")
.replace(/width=[0-9-]+,quality=[0-9]+,format=[A-Za-z0-9]+\//gi, "");
} else {
cleanedUrl = url
.replace(`${this.sourceTargetCdnUrl}/`, "")
.replace(`${this.cdnUrl}/`, "")
.replace("cdn-cgi/image/", "")
.replace(/width=[0-9-]+,quality=[0-9]+\//gi, "");
}
createUrl = cleanedUrl;
let quality = this.quality;
let webp = "none";
if (img) {
const customerSizeData = this.getCustomerSizeData(img);
quality = customerSizeData.quality;
webp = customerSizeData.webp;
if (parseInt(quality) === 0) {
quality = this.quality;
}
// Mobil cihazlar için zorunlu genişlik uygula
if (customerSizeData.width === this.minWidth && width !== "-" &&
this.forceWidth.devices.length && this.forceWidth.enable) {
const currentWindowWidth = $(window).width();
for (const device of this.forceWidth.devices) {
if (currentWindowWidth < device.minWidth) {
width = device.forceWidth;
}
}
}
}
let createdUrl = "";
if (webp === "none") {
createdUrl = `${this.cdnUrl}/width=${width},quality=${quality}/${createUrl}`.toLowerCase();
} else {
createdUrl = `${this.cdnUrl}/width=${width},quality=${quality},format=${webp}/${createUrl}`.toLowerCase();
}
// Klasöre özel ayarları uygula
for (const folder of this.targetUrlFolders) {
if (createdUrl.indexOf(folder.name) > -1) {
if (quality === this.quality && folder.customValues?.quality) {
if (webp === "none") {
createdUrl = `${this.cdnUrl}/width=${width},quality=${folder.customValues.quality}/${createUrl}`.toLowerCase();
} else {
createdUrl = `${this.cdnUrl}/width=${width},quality=${folder.customValues.quality},format=${webp}/${createUrl}`.toLowerCase();
}
}
if (folder.checkThumb) {
createdUrl = createdUrl.replace("/thumb/", "/buyuk/");
}
if (folder.forceBigKey) {
if (createdUrl.indexOf(`/${folder.name}/`) > -1 && createdUrl.indexOf(`/${folder.name}/buyuk/`) === -1) {
createdUrl = createdUrl.replace(`/${folder.name}/`, `/${folder.name}/buyuk/`);
}
}
return createdUrl;
}
}
return "";
}
/**
* Görsel için en uygun genişliği hesaplar
*/
getWidth(img) {
let width = this.minWidth;
width = this._getWidthForCustomerSizes(img, width);
width = this._getWidthForCustomAutoResizeWidth(img, width);
width = this._getWidthForOwlItem(img, width);
width = this._getWidthForTargetAttributeOrParent(img, width);
width = this._getWidthForRecursiveOfParents(img, width);
const finalWidth = width === "-" ? width : Math.floor(width);
if (finalWidth !== "-" && finalWidth <= this.minWidth) {
return "-";
}
return finalWidth;
}
/**
* Özel otomatik yeniden boyutlandırma genişliği için genişlik alır
*/
_getWidthForCustomAutoResizeWidth(img, width) {
if (width !== this.minWidth) return width;
if (typeof customAutoResizeWidth !== "undefined") {
const url = $(img).attr("src") || $(img).attr("data-src") || $(img).attr("data-original");
const allowed = this.customAutoResizeWidthAllowedPaths.some(path => url.indexOf(path) > -1);
if (allowed) {
width = customAutoResizeWidth;
}
}
return width;
}
/**
* Owl carousel elemanları için genişlik alır
*/
_getWidthForOwlItem(img, width) {
if (width !== this.minWidth) return width;
if ($(img).closest("section.landing-block").length) {
const blockElement = $(img).closest("section.landing-block");
if (blockElement.length && AutoResizeUtils.hasAttr(blockElement, "data-ayar")) {
const dataAyar = JSON.parse($(blockElement).attr("data-ayar"));
if (dataAyar.itemCount === undefined) {
width = this.minWidth;
} else if (dataAyar.itemCount === "auto") {
width = "-";
} else {
width = $(blockElement).width() / dataAyar.itemCount;
}
}
}
return width;
}
/**
* Hedef attribute veya parent için genişlik alır
*/
_getWidthForTargetAttributeOrParent(img, width) {
if (width !== this.minWidth) return width;
const targetElement = $(img).attr("data-resize-target");
if (targetElement && targetElement.length > 0) {
width = $(img).closest(targetElement).width();
} else {
width = $(img).parent().width();
}
return width;
}
/**
* Parent'ları özyinelemeli kontrol ederek genişlik alır
*/
_getWidthForRecursiveOfParents(img, width) {
if (width !== this.minWidth) return width;
const recursiveFnc = (el) => {
const w = $(el).parent().width();
return w < this.minWidth ? this.minWidth : w;
};
let targetE = $(img);
while (width === this.minWidth) {
targetE = $(targetE).parent();
width = recursiveFnc(targetE);
}
return width;
}
/**
* Müşteri boyut ayarları için genişlik alır
*/
_getWidthForCustomerSizes(img, width) {
if (width !== this.minWidth) return width;
if (!this.customerSizeSettings) return width;
return this.getCustomerSizeData(img).width;
}
/**
* Yeniden boyutlandırma aralığını durdurur
*/
stopResizeInterval() {
clearInterval(this.resizeInterval);
}
/**
* Anchor elemanları için URL'leri değiştirir
*/
changeUrl() {
const aElements = $("a").toArray();
aElements.forEach(a => {
if (this.checkStartWith($(a).attr("href"))) {
const newUrl = this.createUrl($(a).attr("href"), "-");
if ($(a).attr("href") !== newUrl) {
$(a).attr("href", newUrl);
if (AutoResizeUtils.hasAttr(a, "data-exthumbimage")) {
$(a).attr("data-exthumbimage", newUrl);
}
AutoResizeUtils.addAttributeWithCounter(a, "resize-changed");
}
}
});
}
/**
* DOM değişiklikleri için body observer'ı enjekte eder
*/
injectBodyObserver() {
if (this.bodyObserver.instance) {
this.bodyObserver.instance.disconnect();
}
this.bodyObserver.instance = new MutationObserver(() => {
window.autoResize.stopBodyObserver();
window.autoResize.tick();
});
this.bodyObserver.instance.observe(this.bodyObserver.container, this.bodyObserver.config);
}
/**
* Yeni elemanlar için element observer'ı enjekte eder
*/
injectElementObserver() {
if (this.elementObserver.instance) {
this.elementObserver.instance.disconnect();
}
this.elementObserver.instance = new MutationObserver((mutationsList) => {
mutationsList.forEach(mutation => {
if (mutation.type === 'childList') {
mutation.addedNodes.forEach(node => {
window.autoResize.stopElementObserver();
$(document).trigger("AutoResize-ElementObserver", [node, mutation, mutationsList]);
window.autoResize.injectElementObserver();
});
}
});
});
this.elementObserver.instance.observe(document.body, this.elementObserver.config);
}
/**
* Body observer'ı durdurur
*/
stopBodyObserver() {
if (this.bodyObserver.instance) {
this.bodyObserver.instance.disconnect();
}
}
/**
* Element observer'ı durdurur
*/
stopElementObserver() {
if (this.elementObserver.instance) {
this.elementObserver.instance.disconnect();
}
}
/**
* Görsel için müşteri boyut verilerini alır
*/
getCustomerSizeData(img) {
const result = {
width: this.minWidth,
quality: this.quality,
webp: "none"
};
if (!this.customerSizeSettings) {
return result;
}
const logic = (state1, state2) => {
if (!state1 || !state2) return result;
if (img) {
if (this.customerSizeSettings[state1][state2].bannedInclusives?.length > 0) {
for (const inclusive of this.customerSizeSettings[state1][state2].bannedInclusives) {
if ($(img).closest(inclusive).length > 0) {
return result;
}
}
}
result.width = this.customerSizeSettings[state1][state2].aktif ?
this.customerSizeSettings[state1][state2].size : this.minWidth;
result.quality = this.customerSizeSettings[state1][state2].aktif ?
this.customerSizeSettings[state1][state2].kalite : this.quality;
result.webp = this.customerSizeSettings[state1][state2].aktif ?
(this.customerSizeSettings[state1][state2].webpAktif ? "webp" : "none") : "none";
} else {
result.webp = this.customerSizeSettings[state1][state2].aktif ?
(this.customerSizeSettings[state1][state2].webpAktif ? "webp" : "none") : "none";
}
return result;
};
const state = this._getCustomerSizeState(img);
const onMobile = AutoResizeUtils.isMobileDevice();
$(img).attr("resize-customer-size-state", `${onMobile ? "mobil" : "web"}-${state}`);
const logicResult = logic((onMobile ? "mobil" : "web"), state);
if (parseInt(logicResult.width) === 0) {
logicResult.width = this.minWidth;
}
return logicResult;
}
/**
* Görsel için müşteri boyut durumunu alır
*/
_getCustomerSizeState(img) {
let targetState = "";
// Liste elemanları için kontrol et
for (const state of this.elementsForTargetState.elementsForListe) {
if ($(img).closest($(state)).length > 0) {
targetState = "liste";
break;
}
}
// Detay elemanları için kontrol et
if (targetState.length === 0 && this.elementsForTargetState.elementsForDetay.length > 0) {
for (const state of this.elementsForTargetState.elementsForDetay) {
if ($(img).closest($(state)).length > 0) {
targetState = "detay";
break;
}
}
}
// Banner klasörleri için kontrol et
if (targetState.length === 0) {
for (const folder of this.bannerFolders) {
if (targetState.length > 0) continue;
for (const attr of this.allowedSrcAttributes) {
if (AutoResizeUtils.hasAttr(img, attr.attributeName)) {
if ($(img).attr(attr.attributeName).indexOf(folder.name) > -1) {
targetState = "banner";
break;
}
}
}
}
}
return targetState;
}
}
/**
* AutoResize için eklenti sistemi
*/
class AutoResizePlugins {
constructor() {
this.version = "1.31.0";
this.releaseDescription = "(TV9-17904) Tüm eklentilere AutoResize çalışma durum kontrolü elendi. Böylece AutoResize kapalı olan sitede hiçbir eklenti çalışmayacak (gerek planlanmış, gerekse de dışarıdan tetiklemelerde)...";
this.author = "Mehmet Sağır";
this.initializeEventListeners();
}
/**
* Tüm olay dinleyicilerini başlatır
*/
initializeEventListeners() {
$(document).on("AutoResize-Initializing", () => {
this.resizedElementMarker();
this.lazyloadEnterCallbackInjecter();
this.fixerLazyLoadGifAndBlankPngStayStuck();
});
$(document).on("AutoResize-Tick", () => {
this.basketProductsResizer();
this.basketPageResizer();
this.myAccountFavoritesPageResizer();
this.fixerZoomV1DataZoomAttribute();
this.fixerZoomPreview();
this.ticiTopBlockContentResizer();
this.ticiBottomBlockContentResizer();
this.rightSideCardFixer();
this.fixerLazyLoadUnChangedSrc();
this.refresherOwl();
this.refreshLazy();
this.globalLiteCardResizer();
this.fixerProductDetailDrift();
this.fixerCampaignOffer();
});
$(document).on("AutoResize-Initialized", () => {
this.productDetailZoomV2MidImageSrcOrganizer();
this.basketPageSummaryProductImgFixer();
this.blockSelectFixer();
this.basketProductsResizer();
this.basketPageResizer();
this.myAccountFavoritesPageResizer();
this.fixerZoomV1DataZoomAttribute();
this.fixerZoomPreview();
this.ticiTopBlockContentResizer();
this.ticiBottomBlockContentResizer();
this.rightSideCardFixer();
this.productDetailDriftSizeFixer();
this.fixerMobileOwlSlider();
this.lgResizer();
this.fixerTablinks2();
});
$(document).on("AutoResize-ElementObserver", (event, node, mutation, mutationsList) => {
this.relatedProductResizer(node);
this.productPreviewItemResizer(node);
});
}
/**
* AutoResize'in çalışıp çalışmadığını kontrol eder
*/
isAutoResizeRunning() {
return window.autoResize.autoResizeRunningStatus;
}
/**
* Ürün detay zoom V2 orta görsel kaynak düzenleyicisi
*/
productDetailZoomV2MidImageSrcOrganizer() {
if (!this.isAutoResizeRunning()) return;
$(document).on("window.zoom.V2.setActiveSlide.owl.initialized", () => {
setTimeout(() => {
try {
const images = $("#divProductImageCarousel").find("img").toArray();
images.forEach(img => {
$(img).attr("src", $(img).attr("data-original"));
});
} catch (error) {
console.error("productDetailZoomV2MidImageSrcOrganizer'da hata:", error);
}
}, 500);
});
}
/**
* Sepet ürünlerini yeniden boyutlandırır
*/
basketProductsResizer() {
if (!this.isAutoResizeRunning()) return;
const products = $(".fancybox-iframe").contents().find("img.urunSepetResim").toArray();
products.forEach(product => {
window.autoResize.changeSize(product);
});
}
/**
* Sepet sayfasını yeniden boyutlandırır
*/
basketPageResizer() {
if (!this.isAutoResizeRunning()) return;
window.autoResize.resize($(".sepetimBody .BasketPage"));
}
/**
* Sepet sayfası özet ürün görsellerini düzeltir
*/
basketPageSummaryProductImgFixer() {
if (!this.isAutoResizeRunning()) return;
$(document).on("click", "#divSiparisOzet", () => {
window.autoResize.resize($("#divSiparisOzet"), null);
});
}
/**
* Hesabım favoriler sayfasını yeniden boyutlandırır
*/
myAccountFavoritesPageResizer() {
if (!this.isAutoResizeRunning()) return;
window.autoResize.resize($(".hsbmFvrProductContent"));
}
/**
* Blok seçim işlevselliğini düzeltir
*/
blockSelectFixer() {
if (!this.isAutoResizeRunning()) return;
const resetLazy = () => {
const clearLazyInstance = () => {
if (window.lazyLoadInstance) {
window.lazyLoadInstance.destroy();
window.lazyLoadInstance = null;
}
};
const resetSlider = () => {
const elements = $("#ProductPageProductList").find(".productList-Image-Owl").toArray();
elements.forEach(element => {
$(element).trigger("destroy.owl.carousel").removeClass("owl-loaded");
$(element).removeClass("entered");
$(element).removeClass("owl-loaded");
$(element).removeClass("owl-carousel");
$(element).removeClass("owl-drag");
$(element).removeAttr("data-ll-status");
$(element).find(".productSliderImage").attr("src", "/Uploads/images/load.gif");
const img = $(element).find(".owl-item.active").find(".productSliderImage");
window.autoResize.changeSize(img, "data-src");
window.autoResize.changeSize(img, "src");
$(element).find(".owl-item.active").removeClass("active");
});
};
const resetImages = () => {
clearLazyInstance();
const elements = $("#ProductPageProductList").find("img.lazyImage").toArray();
elements.forEach(element => {
$(element).removeClass("entered");
$(element).removeClass("loaded");
$(element).removeAttr("data-ll-status");
$(element).attr("src", this.lazyloadingImg);
});
lazyLoad();
};
resetSlider();
resetImages();
};
$('body').on('click', '.blockSelect', function () {
window.dispatchEvent(new Event('resize'));
$(".productImage img").hide();
setTimeout(() => {
resetLazy();
$(".productImage img").show();
}, 300);
});
}
/**
* Yeniden boyutlandırılmış elemanları işaretler
*/
resizedElementMarker() {
if (!this.isAutoResizeRunning()) return;
$(document).on("element-attribute-resized", (event, img, attr, oldAttrValue, createdNewUrl) => {
AutoResizeUtils.addAttributeWithCounter(img, "resize-resized");
});
}
/**
* Zoom V1 data zoom attribute'unu düzeltir
*/
fixerZoomV1DataZoomAttribute() {
if (!this.isAutoResizeRunning()) return;
const targetDivs = $(".AltImgCapSmallImg");
const width = $(".imageZoomPreview").width();
if (!targetDivs.length) return;
targetDivs.each((index, div) => {
const targetImg = $(div).children("img");
if (targetImg.length) {
window.autoResize.changeSize(targetImg, "data-original");
$(targetImg).attr("src", $(targetImg).attr("data-original"));
if (typeof $(targetImg).attr("data-cloudzoom") !== 'undefined') {
try {
const convertedObject = JSON.parse($(targetImg).attr("data-cloudzoom"));
if (convertedObject) {
convertedObject.image = window.autoResize.createUrl(convertedObject.image, width, targetImg);
convertedObject.zoomImage = window.autoResize.createUrl(convertedObject.zoomImage, "-", targetImg);
}
$(targetImg).attr("data-cloudzoom", JSON.stringify(convertedObject));
} catch (error) {
console.error("Cloudzoom verilerini ayrıştırırken hata:", error);
}
}
}
});
}
/**
* Lazy load enter callback'ini enjekte eder
*/
lazyloadEnterCallbackInjecter() {
if (!this.isAutoResizeRunning()) return;
$(document).on("LazyLoad_CallbackEnter", (event, element) => {
if (AutoResizeUtils.hasAttr(element, "data-original") && element.dataset.resizeTarget !== "#divProductImageCarousel") {
window.autoResize.changeSize(element, "data-original");
}
if (AutoResizeUtils.hasAttr(element, "data-second")) {
window.autoResize.changeSize(element, "data-second");
}
if (AutoResizeUtils.hasAttr(element, "data-zoom")) {
window.autoResize.changeSize(element, "data-zoom", "-");
}
if ($(element).hasClass("productList-Image-Owl")) {
const images = $(element).find(".productSliderImage").toArray();
images.forEach(img => {
window.autoResize.changeSize(img, "data-src");
});
}
});
}
/**
* Zoom V1 mobil küçük resimlerini düzeltir
*/
fixerZoomV1MobileThumbs() {
if (!this.isAutoResizeRunning()) return;
const images = $(".lightItem").toArray();
images.forEach(img => {
const imgElement = $(img).find(">img");
window.autoResize.changeSize(imgElement, "data-original");
$(imgElement).attr("src", $(imgElement).attr("data-original"));
});
}
/**
* Zoom önizlemesini düzeltir
*/
fixerZoomPreview() {
if (!this.isAutoResizeRunning()) return;
const targetElement = $("#imgUrunResim");
if (targetElement.length && $(targetElement).attr("data-cloudzoom")) {
try {
const cloudZoomData = JSON.parse($(targetElement).attr("data-cloudzoom"));
if (cloudZoomData) {
$(targetElement).attr("src", cloudZoomData.zoomImage);
window.autoResize.changeSize($(targetElement));
}
} catch (error) {
console.error("fixerZoomPreview'da hata:", error);
}
}
}
/**
* Tici üst blok içeriğini yeniden boyutlandırır
*/
ticiTopBlockContentResizer() {
if (!this.isAutoResizeRunning()) return;
window.autoResize.resize($(".ticiTopBlockContent"));
}
/**
* Tici alt blok içeriğini yeniden boyutlandırır
*/
ticiBottomBlockContentResizer() {
if (!this.isAutoResizeRunning()) return;
window.autoResize.resize($(".ticiBottomBlockContent"));
}
/**
* Sağ taraf kartını düzeltir
*/
rightSideCardFixer() {
if (!this.isAutoResizeRunning()) return;
window.autoResize.resize($("#divCartMiniContent"));
}
/**
* Ürün detay drift boyutunu düzeltir
*/
productDetailDriftSizeFixer() {
if (!this.isAutoResizeRunning()) return;
if ($('#divProductImageCarousel').length && $("#div-drift-container").length) {
const imageHeight = $('#divProductImageCarousel').height();
const containerHeight = $("#div-drift-container").height();
if (containerHeight !== imageHeight) {
$("#div-drift-container").height(imageHeight);
}
}
}
/**
* Mobil owl slider'ı düzeltir
*/
fixerMobileOwlSlider() {
if (!this.isAutoResizeRunning()) return;
if (AutoResizeUtils.isMobileDevice() && $(".productList-Image-Owl").length) {
setTimeout(() => {
$(".productList-Image-Owl").trigger('refresh.owl.carousel');
}, 750);
}
}
/**
* Lazy load GIF ve boş PNG takılma sorunlarını düzeltir
*/
fixerLazyLoadGifAndBlankPngStayStuck() {
if (!this.isAutoResizeRunning()) return;
$(document).on("LazyLoad_CallbackEnter", (event, element) => {
const hasOriginal = AutoResizeUtils.hasAttr(element, "data-original") &&
$(element).attr("data-original").length > 0;
const hasBannedSrc = $(element).attr("src") &&
($(element).attr("src").indexOf("blank.png") > -1 ||
$(element).attr("src").indexOf("load.gif") > -1);
if (!hasOriginal && hasBannedSrc) {
$(element).attr("data-original", window.siteSettings.storageLink + "/uploads/images/resim-hazirlaniyor/tr.jpg");
window.autoResize.changeSize(element, "data-original");
}
});
}
/**
* Lazy load değişmemiş kaynağı düzeltir
*/
fixerLazyLoadUnChangedSrc() {
if (!this.isAutoResizeRunning()) return;
setTimeout(() => {
const images = $("img.lazyImage.entered.loaded[data-ll-status='loaded'][src*='load.gif'], img.lazyImage.entered.loaded[data-ll-status='loaded'][src*='blank.png']").toArray();
images.forEach(img => {
if (AutoResizeUtils.hasAttr(img, "data-original")) {
$(img).attr("src", $(img).attr("data-original"));
}
});
}, 1000);
}
/**
* Owl carousel'i yeniler
*/
refresherOwl() {
if (!this.isAutoResizeRunning()) return;
const loadedOwlElements = $(".owl-carousel.owl-loaded.owl-drag").toArray();
loadedOwlElements.forEach(owlE => {
const inclusive = $(owlE).closest("section.landing-block");
if (!inclusive.length) return;
if (!AutoResizeUtils.hasAttr(inclusive, "data-ayar")) return;
try {
const dataAyar = JSON.parse($(inclusive).attr("data-ayar"));
if (!dataAyar) return;
if ((dataAyar.itemCount === "auto" || dataAyar.itemCount === undefined) &&
!AutoResizeUtils.hasAttr(owlE, "resize-refreshed")) {
$(owlE).attr("resize-refreshed", true);
if (dataAyar.itemCount === "auto") {
waitForRealImagesToLoad("#ulMarkaSliderTemplateData img").then(() => {
$('#ulMarkaSliderTemplateData').trigger("destroy.owl.carousel").removeClass("owl-loaded").addClass('owl-carousel');
const ayarStr = $('#ulMarkaSliderTemplateData').parents("section").attr("data-ayar") ?
$('#ulMarkaSliderTemplateData').parents("section").attr("data-ayar").replace(/'/g, '"') : undefined;
const ayar = JSON.parse(ayarStr);
markaSliderOwl($('#ulMarkaSliderTemplateData'), ayar);
});
} else {
$(owlE).trigger('refresh.owl.carousel');
}
}
} catch (error) {
console.error("refresherOwl'da hata:", error);
}
});
}
/**
* Lazy loading'i yeniler
*/
refreshLazy() {
if (!this.isAutoResizeRunning()) return;
lazyLoad();
}
/**
* Global lite kartını yeniden boyutlandırır
*/
globalLiteCardResizer() {
if (!this.isAutoResizeRunning()) return;
if ($("#globalLiteCart").length) {
window.autoResize.resize($("#globalLiteCart"));
}
}
/**
* İlgili ürünleri yeniden boyutlandırır
*/
relatedProductResizer(node) {
if (!this.isAutoResizeRunning()) return;
if (node.id === "relatedProduct") {
window.autoResize.resize($("#relatedProduct"));
}
}
/**
* Ürün önizleme elemanlarını yeniden boyutlandırır
*/
productPreviewItemResizer(node) {
if (!this.isAutoResizeRunning()) return;
if ($(node).hasClass("fancybox-overlay")) {
window.autoResize.resize(node);
}
}
/**
* Lightbox galerisini yeniden boyutlandırır
*/
lgResizer() {
if (!this.isAutoResizeRunning()) return;
$(document).on("window.zoom.V2.setActiveSlide.owl.initialized", () => {
setTimeout(() => {
try {
window.autoResize.resize($(".lg-outer"));
} catch (error) {
console.error("lgResizer'da hata:", error);
}
}, 500);
});
}
/**
* Tab linklerini düzeltir 2
*/
fixerTablinks2() {
if (!this.isAutoResizeRunning()) return;
$(".tablinks2").on("click", () => {
window.autoResize.resize($(".tabcontent2"));
});
}
/**
* Ürün detay drift'ini düzeltir
*/
fixerProductDetailDrift() {
if (!this.isAutoResizeRunning()) return;
if ($('#divProductImageCarousel').length && $("#div-drift-container").length) {
window.autoResize.changeSize($('#div-drift-container img')[0], 'src', '-');
}
}
/**
* Kampanya teklifini düzeltir
*/
fixerCampaignOffer() {
if (!this.isAutoResizeRunning()) return;
if ($('.fancybox-inner #divKampanyaTeklifText').length) {
window.autoResize.changeSize($('.fancybox-inner #divKampanyaTeklifText img')[0], 'src', '-');
}
}
}
/**
* AutoResize sistemini başlatır
*/
function initializeAutoResize() {
// Resize olayını tetikle
window.dispatchEvent(new Event('resize'));
// Eklentileri başlat
window.autoResizePlugins = new AutoResizePlugins();
// Ana AutoResize örneğini başlat
window.autoResize = new AutoResize();
// Kategori liste görünümü öğe görsel yükleme fonksiyonu varsa çağır
if (typeof categoryListViewItemImgLoad === 'function') {
categoryListViewItemImgLoad();
}
}
/**
* AutoResize'in etkinleştirilip etkinleştirilmeyeceğini kontrol eder ve başlatır
*/
function checkStatusForAutoResizeIsEnable() {
if (window?.siteSettings?.siteYonetimAyar?.resimAyar &&
window?.siteSettings?.siteYonetimAyar?.resimAyar.imageCustomResizeActive) {
window.autoResize.autoResizeRunningStatus = true;
window.autoResize.init();
}
}
// Sistemi başlat
initializeAutoResize();
checkStatusForAutoResizeIsEnable();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment