1/* 2 * 모ë 3 */ 4'use strict'; 5 6/* 7 * í´ëì¤ ì ì¸ 8 */ 9class SP_CAFE24_CATEGORY { 10 11 /* 12 * ì´ê¸°í 13 */ 14 constructor() { 15 16 const _ = this; 17 18 /* 19 ** SPSTRAP ë¼ì´ë¸ë¬ë¦¬ ì°ê²° 20 ** ë 립 ìíì 목ì ì¼ë¡ íë¤. 21 */ 22 _.spstrap = window.SPSTRAP; 23 24 _.init(); 25 26 } 27 28 /* 29 ** ìµì´ìí 30 **/ 31 init() { 32 33 const _ = this; 34 35 _.categoryMouseHover(); 36 37 } 38 39 /* 40 ** ì¹´í ê³ ë¦¬ íì± 41 **/ 42 parseCategory(container, json) { 43 44 const _ = this; 45 46 let rowdata; 47 let rowobj; 48 let rowlink; 49 let mCate = []; 50 51 let scope; 52 let rowhtml; 53 let cate_no; 54 let subCategory; 55 56 /* 57 ** ë©ì¸ ì¹´í ê³ ë¦¬ ë°°ì´ ë§ë¤ê¸° 58 ** Html ìì ë§í¬ì ì´ ë°ëì ì¡´ì¬í´ì¼ íë¤. 59 ** 기본ì ì¼ë¡ Html ìì ëë¶ë¥ë¥¼ ì ë ¥íë¯ë¡ 문ì ìë¤. 60 */ 61 container.querySelectorAll(':scope > ul > li').forEach( row => { 62 63 rowdata = row.dataset; 64 rowlink = row.querySelector(':scope > a') ? row.querySelector(':scope > a').getAttribute('href') : '' ; 65 if (rowlink) { 66 rowobj = { 67 link_product_list: rowlink, 68 name: rowdata.name, 69 param: rowdata.param, 70 cate_no: Number.parseInt(rowdata.cate_no) || 0, 71 cate_origin_no: rowdata.cate_no, 72 parent_cate_no: 1, 73 design_page_url: rowdata.design_page_url, 74 like_count: 0, 75 } 76 mCate.push(rowobj); 77 } 78 79 }); 80 81 /* 82 ** ì¹´í ê³ ë¦¬ë¥¼ ìíë 모ë 컨í ì´ëì ì ê·¼íë¤. 83 */ 84 document.querySelectorAll('[sp--js-category]').forEach( element => { 85 86 // ì¹´í ê³ ë¦¬ ìì±ì ì¤ì½í 87 scope = { 88 all: element.dataset.all, // ì 체보기 ë²í¼ 89 link: element.dataset.link, // ë§í¬íì 90 index: element.dataset.index || 0 , // ë¶ëª¨ ì¸ë±ì¤ 91 } 92 subCategory = element.querySelectorAll(':scope > ul > li'); 93 94 // ì´ë¯¸ ëë¶ë¥ê° ìë¤ë©´ 95 if (subCategory.length) { 96 97 scope.depth = 'sub'; 98 subCategory.forEach( sub => { 99 100 cate_no = sub.dataset.cate_no; 101 rowdata = _.findMainCategory(cate_no, mCate); 102 rowhtml = _.makeCategory(scope, rowdata, json); 103 104 // ìë¸ ì¹´í ê³ ë¦¬ì ë£ì´ì¤ë¤. 105 _.spstrap.handler.append(sub, rowhtml); 106 107 }); 108 109 // ì 체를 ì§ì´ë£ì ê±°ë¼ë©´ 110 } else { 111 112 /* 113 ì본 : 2021.07.08 ë³ê²½ â 114 rowdata = scope.index ? _.findMainCategory(scope.index, mCate) : mCate ; 115 */ 116 117 scope.depth = 'main'; 118 rowdata = scope.index ? _.findMainCategory(scope.index, json) : mCate ; 119 rowhtml = _.makeCategory(scope, rowdata, json); 120 121 // 컨í ì´ëì ë£ì´ì¤ë¤. 122 _.spstrap.handler.append(element, rowhtml); 123 124 } 125 126 // 기 ìí ì²´í¬ 127 element.classList.add('sp--initialized-category'); 128 129 }); 130 131 // íì¬ ë§í¬ë¥¼ íì±í 132 _.spstrap.event.currentLink(); 133 134 } 135 136 /* 137 ** ìë ì¹´í ê³ ë¦¬ì íì ì¹´í ê³ ë¦¬ ê°ì ¸ì¤ê¸° 138 */ 139 getCustomCategorySubCategory(name) { 140 141 const _ = this; 142 143 let container = document.querySelector('.sp__layout_header__category [data-name="'+ name +'"] .sp--dropdown-layer'); 144 if (container) { 145 return container.outerHTML; 146 } else { 147 return ''; 148 } 149 150 } 151 152 /* 153 ** ì¹´í ê³ ë¦¬ HTML ë§ë¤ê¸° 154 **/ 155 makeCategory(scope, mCate, json) { 156 157 const _ = this; 158 159 let nCate = [], oCate = [], eCate = []; 160 let mCount, nCount, oCount, eCount, contents; 161 162 // ëë¶ë¥ ----- 163 mCount = 1; 164 contents = ''; 165 mCate.forEach( mcate => { 166 167 // ì¤ë¶ë¥ ----- 168 nCount = 1; 169 nCate = _.findSubCategory(mcate.cate_no, json); 170 171 // ìë ì¹´í ê³ ë¦¬ì íì ì¹´í ê³ ë¦¬ ê°ì ¸ì
171¤ê¸° 172 let customCategorySubCategory = ''; 173 if (mcate.name && mcate.cate_no === 0) { 174 customCategorySubCategory = _.getCustomCategorySubCategory(mcate.name); 175 } 176 177 // ëë©ë´ë¶í° íìí ê²½ì° 178 if (!scope.index && scope.depth === 'main') { 179 contents += mCount === 1 ? `<ul>` : '' ; 180 contents += `<li sub="${(nCate.length || customCategorySubCategory) ? true : false}" data-cate_no="${mcate.cate_no ? mcate.cate_no : mcate.cate_origin_no}">${_.makeCategoryLink(scope, mcate)}`; 181 } 182 183 // ìë ì¹´í ê³ ë¦¬ì íì ì¹´í ê³ ë¦¬ ìë¤ë©´ ì¶ê° 184 if(customCategorySubCategory){ 185 contents += customCategorySubCategory; 186 } 187 188 nCate.forEach( ncate => { 189 190 // ìë¶ë¥ ----- 191 oCount = 1; 192 oCate = _.findSubCategory(ncate.cate_no, json); 193 194 contents += nCount === 1 ? `<div class="sp--dropdown-layer" name="${_.spstrap.regex.stripTag(mcate.name)}" depth="n"><ul>` : '' ; 195 contents += scope.all && nCount === 1 ? `<li data-cate_no="${mcate.cate_no}">${_.makeCategoryLink(scope, mcate, scope.all)}</li>` : '' ; 196 contents += `<li sub="${oCate.length ? true : false}" data-cate_no="${ncate.cate_no}">${_.makeCategoryLink(scope, ncate)}`; 197 198 oCate.forEach( ocate => { 199 200 // ìì¸ë¶ë¥ ----- 201 eCount = 1; 202 eCate = _.findSubCategory(ocate.cate_no, json); 203 204 contents += oCount === 1 ? `<div class="sp--dropdown-layer" name="${_.spstrap.regex.stripTag(ncate.name)}" depth="o"><ul>` : '' ; 205 contents += scope.all && oCount === 1 ? `<li data-cate_no="${ncate.cate_no}">${_.makeCategoryLink(scope, ncate, scope.all)}</li>` : '' ; 206 contents += `<li sub="${eCate.length ? true : false}" data-cate_no="${ocate.cate_no}">${_.makeCategoryLink(scope, ocate)}`; 207 208 eCate.forEach( ecate => { 209 210 contents += eCount === 1 ? `<div class="sp--dropdown-layer" name="${_.spstrap.regex.stripTag(ocate.name)}" depth="e"><ul>` : '' ; 211 contents += scope.all && eCount === 1 ? `<li data-cate_no="${ocate.cate_no}">${_.makeCategoryLink(scope, ocate, scope.all)}</li>` : '' ; 212 contents += `<li data-cate_no="${ecate.cate_no}">${_.makeCategoryLink(scope, ecate)}</li>`; 213 contents += eCount >= eCate.length ? `</ul></div>` : '' ; 214 eCount++; 215 216 }); 217 218 contents += `</li>`; 219 contents += oCount >= oCate.length ? `</ul></div>` : '' ; 220 oCount++; 221 222 }); 223 224 contents += `</li>`; 225 contents += nCount >= nCate.length ? `</ul></div>` : '' ; 226 nCount++; 227 228 }); 229 230 // ëë©ë´ë¶í° íìí ê²½ì° 231 if (!scope.index && scope.depth === 'main') { 232 contents += `</li>`; 233 contents += mCount >= mCate.length ? `</ul>` : '' ; 234 mCount++; 235 } 236 237 //mCount++; 238 239 }); 240 241 return contents; 242 243 } 244 245 /* 246 ** ë©ì¸ ì¹´í ê³ ë¦¬ íí° 247 **/ 248 findMainCategory(cate_no, json) { 249 250 return json.filter(category => category.cate_no == cate_no); 251 252 } 253 254 /* 255 ** ìë¸ ì¹´í ê³ ë¦¬ íí° 256 **/ 257 findSubCategory(cate_no, json) { 258 259 if (cate_no && json) { 260 return json.filter(category => category.parent_cate_no == cate_no); 261 } else { 262 return []; 263 } 264 265 } 266 267 /* 268 ** ì¹´í ê³ ë¦¬ ë§í¬ ë§ë¤ê¸° 269 **/ 270 makeCategoryLink(scope, element, all) { 271 272 const _ = this; 273 274 if (all) { 275 276 if (scope.link === 'seo') { 277 return `<a href="${element.link_product_list}" class="sp--currentlink">${all}</a>`; 278 } else { 279 if (element.param) { 280 return `<a href="/${element.design_page_url}${element.param}" class="sp--currentlink">${all}</a>`; 281 } else { 282 return `<a href="${element.design_page_url}" class="sp--currentlink">${all}</a>`; 283 } 284 } 285 286 } else { 287 288 if (scope.link === 'seo') { 289 return `<a href="${element.link_product_list}" class="sp--currentlink">${element.name}</a>`; 290 } else { 291 if (element.param) { 292 return `<a href="/${element.design_page_url}${element.param}" class="sp--currentlink">${element.name}</a>`; 293 } else { 294 return `<a href="${element.design_page_url}" class="sp--currentlink">${element.name}</a>`; 295 } 296 } 297 298 } 299 300 } 301 302 /* 303 ** ì¹´í ê³ ë¦¬ ë§ì°ì¤ ì¤ë² í ì¤í¸ 304 */ 305 categoryMouseHover() { 306 307 const _ = this; 308 309 let data = { 310 container: '.sp__layout_header__category', 311 input: '[sp--js-category-hover] span', 312 init: '.sp--cafe24-initialized-categoryhover' 313 } 314 315 let target; 316 let textData; 317 let textContents; 318 let container = document.querySelector(data.container); 319 let array = document.querySelectorAll(data.input +`:not(${data.init})`); 320 array.forEach( text => { 321 322 textData = text.dataset; 323 target = container.querySelector('.sp__layout_header__category li[data-cate_no="'+ textData.category +'"] > a'); 324 325 if (target && typeof target === 'object') { 326 textContents = ` 327 <i class="xans-layout-category--hover"> 328 ${text.innerHTML} 329 </i> 330 `; 331 _.spstrap.handler.append(target, textContents); 332 } 333 334 // 기 ìí ì²´í¬ 335 text.classList.add(_.spstrap.var.trim(data.init)); 336 337 }); 338 339 } 340 341} 342 343/* 344 * ìì±í기 345 */ 346const SP_CAFE24_CATEGORY_NEW = new SP_CAFE24_CATEGORY(); 347 348/* 349 * ë´ë³´ë´ê¸° 350 */ 351export { 352 SP_CAFE24_CATEGORY_NEW as SP_CAFE24_CATEGORY 353}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.