1 | /* |
---|
2 | * This file is part of EC-CUBE |
---|
3 | * |
---|
4 | * Copyright(c) 2000-2014 LOCKON CO.,LTD. All Rights Reserved. |
---|
5 | * |
---|
6 | * http://www.lockon.co.jp/ |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
21 | */ |
---|
22 | |
---|
23 | (function( window, undefined ){ |
---|
24 | |
---|
25 | // 名前空間の重複を防ぐ |
---|
26 | if (window.eccube === undefined) { |
---|
27 | window.eccube = {}; |
---|
28 | } |
---|
29 | |
---|
30 | var eccube = window.eccube; |
---|
31 | |
---|
32 | eccube.smartRollover = function() { |
---|
33 | if (document.getElementsByTagName) { |
---|
34 | var images = $("img"); |
---|
35 | var re = /_off¥./; |
---|
36 | |
---|
37 | images.each(function(){ |
---|
38 | var target = $(this); |
---|
39 | if (target.attr("src").match(re)) { |
---|
40 | target.on("vmouseover", function(){ |
---|
41 | this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on.")); |
---|
42 | }); |
---|
43 | target.on("vmouseout", function(){ |
---|
44 | this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off.")); |
---|
45 | }); |
---|
46 | } |
---|
47 | }); |
---|
48 | } |
---|
49 | }; |
---|
50 | |
---|
51 | if (window.addEventListener) { |
---|
52 | window.addEventListener("load", eccube.smartRollover, false); |
---|
53 | } else if (window.attachEvent) { |
---|
54 | window.attachEvent("onload", eccube.smartRollover); |
---|
55 | } |
---|
56 | |
---|
57 | /*------------------------------------------ |
---|
58 | お気に入りを登録する |
---|
59 | ------------------------------------------*/ |
---|
60 | eccube.addFavoriteSphone = function(favoriteProductId) { |
---|
61 | eccube.showLoading(); |
---|
62 | //送信データを準備 |
---|
63 | var postData = {}; |
---|
64 | var form = $("#form1"); |
---|
65 | form.find(':input').each(function(){ |
---|
66 | postData[$(this).attr('name')] = $(this).val(); |
---|
67 | }); |
---|
68 | postData.mode = "add_favorite_sphone"; |
---|
69 | postData.favorite_product_id = favoriteProductId; |
---|
70 | |
---|
71 | $.ajax({ |
---|
72 | type: "POST", |
---|
73 | url: form.attr('action'), |
---|
74 | data: postData, |
---|
75 | cache: false, |
---|
76 | dataType: "text", |
---|
77 | error: function(XMLHttpRequest, textStatus){ |
---|
78 | window.alert(textStatus); |
---|
79 | eccube.hideLoading(); |
---|
80 | }, |
---|
81 | success: function(result){ |
---|
82 | if (result === "true") { |
---|
83 | window.alert("お気に入りに登録しました"); |
---|
84 | $(".btn_favorite").html("<p>お気に入り登録済み</p>"); |
---|
85 | } else { |
---|
86 | window.alert("お気に入りの登録に失敗しました"); |
---|
87 | } |
---|
88 | eccube.hideLoading(); |
---|
89 | } |
---|
90 | }); |
---|
91 | }; |
---|
92 | |
---|
93 | /** |
---|
94 | * ローディング画像を表示する |
---|
95 | */ |
---|
96 | eccube.showLoading = function() { |
---|
97 | var over = '<div class="loading-overlay"><span class="loading-image"></span></div>'; |
---|
98 | $(over).appendTo('body'); |
---|
99 | }; |
---|
100 | |
---|
101 | /** |
---|
102 | * ローディング画像を削除する |
---|
103 | */ |
---|
104 | eccube.hideLoading = function() { |
---|
105 | $('.loading-overlay').remove(); |
---|
106 | }; |
---|
107 | |
---|
108 | // グローバルに使用できるようにする |
---|
109 | window.eccube = eccube; |
---|
110 | |
---|
111 | /*------------------------------------------ |
---|
112 | 初期化 |
---|
113 | ------------------------------------------*/ |
---|
114 | $(function(){ |
---|
115 | //level?クラスを持つノード全てを走査し初期化 |
---|
116 | $("#categorytree").find("li").each(function(){ |
---|
117 | if ($(this).find("> ul").length) { |
---|
118 | //▶を表示し、リストオープンイベントを追加 |
---|
119 | var tgt = $(this).find("> span.category_header"); |
---|
120 | var linkObj = $("<a>"); |
---|
121 | linkObj.html('+'); |
---|
122 | tgt |
---|
123 | .click(function(){ |
---|
124 | $(this).siblings("ul").toggle('fast', function(){ |
---|
125 | if ($(this).css('display') === 'none') { |
---|
126 | tgt.children('a').html('+'); |
---|
127 | } else { |
---|
128 | tgt.children('a').html('-'); |
---|
129 | } |
---|
130 | }); |
---|
131 | }) |
---|
132 | .addClass('plus') |
---|
133 | .append(linkObj); |
---|
134 | } |
---|
135 | }); |
---|
136 | }); |
---|
137 | })(window); |
---|