1$(function(){ 2 var favorite = new Favorite(); 3 favorite.bind("add_favorite"); 4 5 // ãæ°ã«å ¥ãåé¤ãã¿ã³ã«clickã¤ãã³ãããã¤ã³ã 6 $(document).on("click", ".del_favorite", Favorite.prototype.clickDelButton); 7}); 8 9(function(window, undefined) { 10 var $favorite; 11 var $buttons; 12 var submitflag = true; 13 var is_submit_process = false; 14 15 function Favorite() {} 16 17 Favorite.prototype.bind = function(button_class) { 18 $buttons = $("." + button_class); 19 20 // ãæ°ã«å ¥ãç»é²ãã¿ã³ã«clickã¤ãã³ãããã¤ã³ã 21 $(document).on("click", "." + button_class, this.clickAddButton); 22 23 $favorite = this; 24 25 // ãæ°ã«å ¥ãç»é²ç¶æ ããã§ã㯠26 $favorite.checkStatus($buttons); 27 } 28 29 /** 30 * ãæ°ã«å ¥ãç»é²ç¶æ ããã§ã㯠31 */ 32 Favorite.prototype.checkStatus = function($buttons) { 33 if ($buttons.length == 0) { 34 return; 35 } 36 37 // ç¾å¨ç»é²æ¸ã®ãæ°ã«å ¥ããå ¨ã¦åå¾ 38 $.post("/apis/favorite/cookie.json", {}, function(data, textStatus) { 39 if (data.status == "success") { 40 var list = data.list; 41 $buttons.each(function() { 42 var $target = $(this); 43 44 var params = $favorite.getGoodsKey($target); 45 46 var is_registed = false; 47 48 // åãã¿ã³ã®è¦ç´ ãç»é²æ¸ã§ããããå¤å® 49 for (index in list) { 50 var goods = list[index]; 51 52 var detail_disp_manage_code = goods['detail_disp_manage_code'] || ""; 53 var color_code = goods['color_code'] || ""; 54 var size_code = goods['size_code'] || ""; 55 56 var params_detail_disp_manage_code = params['detail_disp_manage_code'] || ""; 57 var params_color_code = params['color_code'] || ""; 58 var params_size_code = params['size_code'] || ""; 59 60 if (detail_disp_manage_code == params_detail_disp_manage_code 61 && (color_code == "" || params_color_code == "" || color_code == params_color_code) 62 && (size_code == "" || params_size_code == "" || size_code == params_size_code)) { 63 is_registed = true; 64 } 65 } 66 if (is_registed) { 67 $target.addClass("active"); 68 } 69 }); 70 } else { 71 // ã¨ã©ã¼ã¯ç¡è¦ 72 } 73 }, "json"); 74 } 75 76 /** 77 * ãæ°ã«å ¥ããã¿ã³æ¼ä¸ã¤ãã³ã 78 */ 79 Favorite.prototype.clickAddButton = function() { 80 var $target = $(this); 81 82 if (submitflag) { 83 // è¦ç´ ã«è¨å®ããã¦ãããã¼ãåå¾ 84 var params = $favorite.getGoodsKey($target); 85 86 submitflag = false; 87 88 $favorite.addFavorite(params, $target); 89 } 90 } 91 92 /** 93 * ãæ°ã«å ¥ãåé¤ãã¿ã³æ¼ä¸ã¤ãã³ã 94 */ 95 Favorite.prototype.clickDelButton = function() { 96 var $target = $(this); 97 98 if (submitflag) { 99 // è¦ç´ ã«è¨å®ããã¦ãããã¼ãåå¾ 100 var params = $favorite.getGoodsKey($target); 101 102 submitflag = false; 103 104 $favorite.deleteFavorite(params, $target); 105 106 $target.parents('.favorite-item').fadeOut(); 107 } 108 return false; 109 } 110 111 /** 112 * è¦ç´ ã«è¨å®ããã¦ãããã¼ãåå¾ 113 */ 114 Favorite.prototype.getGoodsKey = function($target) { 115 // è¦ç´ ã«è¨å®ããã¦ãããã¼ãåå¾ 116 var params = {}; 117 var data_list = $target.data(); 118 for (key in data_list) { 119 if (key == "detail_disp_manage_code" || key == "color_code" || key == "size_code" || key == 'set_type' || key == 'currency') { 120 params[key] = data_list[key]; 121 } 122 } 123 return params; 124 } 125 126 /** 127 * ãæ°ã«å ¥ãç»é²å¦ç 128 */ 129 Favorite.prototype.addFavorite = function(params, $target) { 130 var $object = this; 131 132 $.post("/apis/favorite/cookie/add.json", params, function(data, textStatus) { 133 if (data.status == "success") { 134 $target.addClass("active"); 135 submitflag = true; 136 $('body').append(data.tracking_tag); 137 138 // ãæ°ã«å ¥ãç»é²ãGAã«éä¿¡ 139 var goods = data.favorite_goods; 140 141 if (Object.keys(goods).length) { 142 var goods_data = $object.convertToGaArray(goods); 143 144 if (data.delete_flag) { 145 $(this).gtm_google_analytics_ec().send_remove_from_wishlist(goods_data); 146 } else { 147 $(this).gtm_google_analytics_ec().send_add_to_wishlist(goods_data); 148 } 149 } 150 151 } else { 152 // ã¨ã©ã¼è¡¨ç¤º 153 var error_message = ''; 154 submitflag = true; 155 for (key in data.errors) { 156 error_message = data.errors[key]; 157 break; 158 } 159 160 // @TODOï¼ã¨ã©ã¼ã¡ãã»ã¼ã¸è¡¨ç¤ºå¦ç 161 error_message = '' + error_message.replace("<br />", "\n") + ''; 162 alert(error_message); 163 } 164 }, "json"); 165 } 166 167 /** 168 * ãæ°ã«å ¥ãåé¤å¦ç 169 */ 170 Favorite.prototype.deleteFavorite = function(params, $target) { 171 var $object = this; 172 173 $.post("/apis/favorite/cookie/del.json", params, function(data, textStatus) { 174 if (data.status == "success") { 175 $target.removeClass("active"); 176 submitflag = true; 177 $('body').append(data.tracking_tag); 178 179 // ãæ°ã«å ¥ãåé¤ãGAã«éä¿¡ 180 var goods = data.favorite_goods; 181 182 if (Object.keys(goods).length) { 183 var goods_data = $object.convertToGaArray(goods); 184 185 $(this).gtm_google_analytics_ec().send_remove_from_wishlist(goods_data); 186 } 187 188 } else { 189 // ã¨ã©ã¼è¡¨ç¤º 190 var error_message = ''; 191 submitflag = true; 192 for (key in data.errors) { 193 error_message = data.errors[key]; 194 break; 195 } 196 197 // @TODOï¼ã¨ã©ã¼ã¡ãã»ã¼ã¸è¡¨ç¤ºå¦ç 198 alert(error_message); 199 } 200 }, "json"); 201 } 202 203 /** 204 * ã«ã¼ãç»é²ãã¿ã³æ¼ä¸ã¤ãã³ã 205 */ 206 $(document).on("click", ".favorite_add_cart", function() { 207 var favorite = new Favorite(); 208 var $target = $(this); 209 210 var fuelcsrf = new FuelCsrf(); 211 var promise; 212 if (fuelcsrf.getFuelCsrfInputName() == "" || typeof fuelcsrf.getFuelCsrfInputName() == "undefined") { 213 promise = fuelcsrf.init(); 214 } else {
215 promise = fuelcsrf.update(); 216 } 217 218 if (typeof promise !== "undefined") { 219 promise.then(function() { 220 // è¦ç´ ã«è¨å®ããã¦ãããã¼ãåå¾ 221 var params = favorite.getGoodsKey($target); 222 params[fuelcsrf.getFuelCsrfInputName()] = fuelcsrf.getFuelCsrfInputValue(); 223 // ã«ã¼ãã«è¿½å ããé㯠1 åã§åºå® 224 params['pod'] = '1'; 225 226 // ã»ããååã®å ´åã¯ã«ã¼ãã«è¿½å ããªã 227 if (params['set_type'] != 1) { 228 favorite.addCart(params, $target); 229 } 230 }); 231 } 232 233 return false; 234 }) 235 236 /** 237 * ã«ã¼ãç»é²å¦ç 238 */ 239 Favorite.prototype.addCart = function(params, $target) { 240 // å¦çä¸ã®å ´åã¯ã¹ããã 241 if (is_submit_process === true) 242 { 243 return false; 244 } 245 246 is_submit_process = true; 247 248 var $add_cart_process_modal = $(".add_cart_process_pop"); 249 250 var timer_add_cart_process_modal = setTimeout(function() { 251 $add_cart_process_modal.fadeIn("fast"); 252 }, 500); 253 254 var uri = "cart/add.json"; 255 $.post(base_url_ssl + apis_url_base + uri, params, function(data, textStatus) { 256 if (data.status == "success") { 257 clearTimeout(timer_add_cart_process_modal); 258 var count = Number($(".header_cart_count").text()); 259 // ã«ã¼ã追å éã¯ä¸åã§åºå® 260 var add_count = 1; 261 $(".header_cart_count").text(count + add_count); 262 $(".header_cart_count_sp").text(count + add_count); 263 264 // ã«ã¼ã追å ãGAã«éä¿¡ 265 $(this).gtm_google_analytics_ec().add_action_by_goods_list([data.goods_list.last_add_goods]); 266 267 // LTV-Labãã©ããã³ã° 268 ltvlab_tracking_add_to_cart([data.goods_list.last_add_goods]); 269 270 $add_cart_process_modal.fadeOut("fast"); 271 is_submit_process = false; 272 273 // ã«ã¼ããã¼ã¸ã«é·ç§» 274 window.location.href = base_url_ssl + "/cart"; 275 } else { 276 // ã¨ã©ã¼è¡¨ç¤º 277 var error_message = ''; 278 for (key in data.errors) { 279 error_message = data.errors[key]; 280 break; 281 } 282 283 // ã¨ã©ã¼ã¡ãã»ã¼ã¸è¡¨ç¤ºå¦ç 284 var messages = ""; 285 if (typeof error_message == "object") { 286 for (var i in error_message) { 287 if (typeof error_message[i] == "object") { 288 for (var j in error_message[i]) { 289 if (typeof error_message[i][j] == "object") { 290 for (var k in error_message[i][j]) { 291 messages += error_message[i][j][k].replace( /<br \/>/g , "\n" ) + "\n"; 292 } 293 } else { 294 messages += error_message[i][j].replace( /<br \/>/g , "\n" ) + "\n"; 295 } 296 } 297 } else { 298 messages += error_message[i].replace( /<br \/>/g , "\n" ) + "\n"; 299 } 300 } 301 } else { 302 messages = error_message.replace( /<br \/>/g , "\n" ) ; 303 } 304 305 // å¾ æ©æéã®è¨å®ãããå ´åã¯å¾ æ©ããã 306 if (data.wait_seconds) 307 { 308 var timer = false; 309 if (timer !== false) { 310 clearTimeout(timer); 311 } 312 timer = setTimeout(function() { 313 clearTimeout(timer_add_cart_process_modal); 314 315 alert(messages); 316 $add_cart_process_modal.fadeOut("fast"); 317 318 is_submit_process = false; 319 320 }, data.wait_seconds * 1000); 321 } 322 else 323 { 324 clearTimeout(timer_add_cart_process_modal); 325 326 alert(messages); 327 $add_cart_process_modal.fadeOut("fast"); 328 is_submit_process = false; 329 } 330 } 331 332 }, "json"); 333 } 334 335 Favorite.prototype.convertToGaArray = function(goods) { 336 var category_name = ""; 337 338 for (i in goods.category) { 339 category_name = category_name + goods.category[i].category_name + "/"; 340 } 341 342 category_name = category_name.slice(0, -1); 343 344 return {"id": goods.commodity_number, "name": goods.goods_name1, "brand": goods.brand_name, 345 "category": category_name, "variant": goods.color_name + " / " + goods.size_name, 346 "price": goods.price, "quantity": 1}; 347 } 348 349 window.Favorite = Favorite; 350})(window);
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.