PageSourceSearch

https://auralee.jp/assets/front/js/favorite_cookie.js?1686819200

js auralee.jp collected 2026-09-28 12:41:53 UTC 9,845 bytes, 350 lines download raw bytes

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.