1 | /* |
---|
2 | * This file is part of EC-CUBE |
---|
3 | * |
---|
4 | * Copyright(c) 2000-2013 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 | // 名前空間の重複を防ぐ |
---|
27 | if (window.eccube === undefined) { |
---|
28 | window.eccube = {}; |
---|
29 | } |
---|
30 | |
---|
31 | var eccube = window.eccube; |
---|
32 | |
---|
33 | eccube.win01 = function(URL,Winname,Wwidth,Wheight){ |
---|
34 | var WIN; |
---|
35 | WIN = window.open(URL,Winname,"width="+Wwidth+",height="+Wheight+",scrollbars=no,resizable=no,toolbar=no,location=no,directories=no,status=no"); |
---|
36 | WIN.focus(); |
---|
37 | }; |
---|
38 | |
---|
39 | eccube.win02 = function(URL,Winname,Wwidth,Wheight){ |
---|
40 | var WIN; |
---|
41 | WIN = window.open(URL,Winname,"width="+Wwidth+",height="+Wheight+",scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no,status=no"); |
---|
42 | WIN.focus(); |
---|
43 | }; |
---|
44 | |
---|
45 | eccube.win03 = function(URL,Winname,Wwidth,Wheight){ |
---|
46 | var WIN; |
---|
47 | WIN = window.open(URL,Winname,"width="+Wwidth+",height="+Wheight+",scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no,status=no,menubar=no"); |
---|
48 | WIN.focus(); |
---|
49 | }; |
---|
50 | |
---|
51 | eccube.winSubmit = function(URL,formName,Winname,Wwidth,Wheight){ |
---|
52 | var WIN = window.open(URL,Winname,"width="+Wwidth+",height="+Wheight+",scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no,status=no,menubar=no"); |
---|
53 | document.forms[formName].target = Winname; |
---|
54 | WIN.focus(); |
---|
55 | }; |
---|
56 | |
---|
57 | eccube.openWindow = function(URL,name,width,height) { |
---|
58 | window.open(URL,name,"width="+width+",height="+height+",scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no,status=no"); |
---|
59 | }; |
---|
60 | |
---|
61 | // 親ウィンドウの存在確認. |
---|
62 | eccube.isOpener = function() { |
---|
63 | var ua = navigator.userAgent; |
---|
64 | if( !!window.opener ) { |
---|
65 | if( ua.indexOf('MSIE 4')!=-1 && ua.indexOf('Win')!=-1 ) { |
---|
66 | return !window.opener.closed; |
---|
67 | } else { |
---|
68 | return typeof window.opener.document == 'object'; |
---|
69 | } |
---|
70 | } else { |
---|
71 | return false; |
---|
72 | } |
---|
73 | }; |
---|
74 | |
---|
75 | eccube.chgImg = function(fileName,img){ |
---|
76 | if (typeof(img) == "object") { |
---|
77 | img.src = fileName; |
---|
78 | } else { |
---|
79 | document.images[img].src = fileName; |
---|
80 | } |
---|
81 | }; |
---|
82 | |
---|
83 | eccube.chgImgImageSubmit = function(fileName,imgObj){ |
---|
84 | imgObj.src = fileName; |
---|
85 | }; |
---|
86 | |
---|
87 | // 郵便番号入力呼び出し. |
---|
88 | eccube.getAddress = function(php_url, tagname1, tagname2, input1, input2) { |
---|
89 | var zip1 = document.form1[tagname1].value; |
---|
90 | var zip2 = document.form1[tagname2].value; |
---|
91 | |
---|
92 | if(zip1.length == 3 && zip2.length == 4) { |
---|
93 | $.get( |
---|
94 | php_url, |
---|
95 | {zip1: zip1, zip2: zip2, input1: input1, input2: input2}, |
---|
96 | function(data) { |
---|
97 | var arrData = data.split("|"); |
---|
98 | if (arrData.length > 1) { |
---|
99 | eccube.putAddress(input1, input2, arrData[0], arrData[1], arrData[2]); |
---|
100 | } else { |
---|
101 | alert(data); |
---|
102 | } |
---|
103 | } |
---|
104 | ); |
---|
105 | } else { |
---|
106 | alert("郵便番号を正しく入力して下さい。"); |
---|
107 | } |
---|
108 | }; |
---|
109 | |
---|
110 | // 郵便番号から検索した住所を渡す. |
---|
111 | eccube.putAddress = function(input1, input2, state, city, town) { |
---|
112 | if(state != "") { |
---|
113 | // 項目に値を入力する. |
---|
114 | document.form1[input1].selectedIndex = state; |
---|
115 | document.form1[input2].value = city + town; |
---|
116 | } |
---|
117 | }; |
---|
118 | |
---|
119 | eccube.setFocus = function(name) { |
---|
120 | if(document.form1[name]) { |
---|
121 | document.form1[name].focus(); |
---|
122 | } |
---|
123 | }; |
---|
124 | |
---|
125 | // モードとキーを指定してSUBMITを行う。 |
---|
126 | eccube.setModeAndSubmit = function(mode, keyname, keyid) { |
---|
127 | switch(mode) { |
---|
128 | case 'delete_category': |
---|
129 | if(!window.confirm('選択したカテゴリとカテゴリ内の全てのカテゴリを削除します')){ |
---|
130 | return; |
---|
131 | } |
---|
132 | break; |
---|
133 | case 'delete': |
---|
134 | if(!window.confirm('一度削除したデータは、元に戻せません。\n削除しても宜しいですか?')){ |
---|
135 | return; |
---|
136 | } |
---|
137 | break; |
---|
138 | case 'confirm': |
---|
139 | if(!window.confirm('登録しても宜しいですか')){ |
---|
140 | return; |
---|
141 | } |
---|
142 | break; |
---|
143 | case 'delete_all': |
---|
144 | if(!window.confirm('検索結果を全て削除しても宜しいですか')){ |
---|
145 | return; |
---|
146 | } |
---|
147 | break; |
---|
148 | default: |
---|
149 | break; |
---|
150 | } |
---|
151 | document.form1['mode'].value = mode; |
---|
152 | if(keyname != "" && keyid != "") { |
---|
153 | document.form1[keyname].value = keyid; |
---|
154 | } |
---|
155 | document.form1.submit(); |
---|
156 | }; |
---|
157 | |
---|
158 | eccube.fnFormModeSubmit = function(form, mode, keyname, keyid) { |
---|
159 | switch(mode) { |
---|
160 | case 'delete': |
---|
161 | if(!window.confirm('一度削除したデータは、元に戻せません。\n削除しても宜しいですか?')){ |
---|
162 | return; |
---|
163 | } |
---|
164 | break; |
---|
165 | case 'confirm': |
---|
166 | if(!window.confirm('登録しても宜しいですか')){ |
---|
167 | return; |
---|
168 | } |
---|
169 | break; |
---|
170 | case 'regist': |
---|
171 | if(!window.confirm('登録しても宜しいですか')){ |
---|
172 | return; |
---|
173 | } |
---|
174 | break; |
---|
175 | default: |
---|
176 | break; |
---|
177 | } |
---|
178 | document.forms[form]['mode'].value = mode; |
---|
179 | if(keyname != "" && keyid != "") { |
---|
180 | document.forms[form][keyname].value = keyid; |
---|
181 | } |
---|
182 | document.forms[form].submit(); |
---|
183 | }; |
---|
184 | |
---|
185 | eccube.setValueAndSubmit = function(form, key, val) { |
---|
186 | document.forms[form][key].value = val; |
---|
187 | document.forms[form].submit(); |
---|
188 | return false; |
---|
189 | }; |
---|
190 | |
---|
191 | eccube.setValue = function(key, val, form) { |
---|
192 | if (typeof form === 'undefined') { |
---|
193 | form = 'form1'; |
---|
194 | } |
---|
195 | document.forms[form][key].value = val; |
---|
196 | }; |
---|
197 | |
---|
198 | eccube.changeAction = function(url) { |
---|
199 | document.form1.action = url; |
---|
200 | }; |
---|
201 | |
---|
202 | // ページナビで使用する。 |
---|
203 | eccube.movePage = function(pageno, mode, form) { |
---|
204 | if (typeof form !== 'undefined') { |
---|
205 | form = 'form1'; |
---|
206 | } |
---|
207 | document.forms[form]['pageno'].value = pageno; |
---|
208 | if (typeof mode !== 'undefined') { |
---|
209 | document.forms[form]['mode'].value = 'search'; |
---|
210 | } |
---|
211 | document.forms[form].submit(); |
---|
212 | }; |
---|
213 | |
---|
214 | eccube.submitForm = function(form){ |
---|
215 | if (typeof form !== 'undefined') { |
---|
216 | form = 'form1'; |
---|
217 | } |
---|
218 | document.forms[form].submit(); |
---|
219 | }; |
---|
220 | |
---|
221 | // ポイント入力制限。 |
---|
222 | eccube.togglePointForm = function() { |
---|
223 | if(document.form1['point_check']) { |
---|
224 | var list = ['use_point']; |
---|
225 | var color; |
---|
226 | var flag; |
---|
227 | |
---|
228 | if(!document.form1['point_check'][0].checked) { |
---|
229 | color = "#dddddd"; |
---|
230 | flag = true; |
---|
231 | } else { |
---|
232 | color = ""; |
---|
233 | flag = false; |
---|
234 | } |
---|
235 | |
---|
236 | var len = list.length; |
---|
237 | for(i = 0; i < len; i++) { |
---|
238 | if(document.form1[list[i]]) { |
---|
239 | var current_color = document.form1[list[i]].style.backgroundColor; |
---|
240 | if (color != "#dddddd" && (current_color == "#ffe8e8" || current_color == "rgb(255, 232, 232)")) |
---|
241 | { |
---|
242 | continue; |
---|
243 | } |
---|
244 | document.form1[list[i]].disabled = flag; |
---|
245 | document.form1[list[i]].style.backgroundColor = color; |
---|
246 | } |
---|
247 | } |
---|
248 | } |
---|
249 | }; |
---|
250 | |
---|
251 | // 別のお届け先入力制限。 |
---|
252 | eccube.toggleDeliveryForm = function() { |
---|
253 | if(!document.form1) { |
---|
254 | return; |
---|
255 | } |
---|
256 | if(document.form1['deliv_check']) { |
---|
257 | var list = [ |
---|
258 | 'shipping_name01', |
---|
259 | 'shipping_name02', |
---|
260 | 'shipping_kana01', |
---|
261 | 'shipping_kana02', |
---|
262 | 'shipping_pref', |
---|
263 | 'shipping_zip01', |
---|
264 | 'shipping_zip02', |
---|
265 | 'shipping_addr01', |
---|
266 | 'shipping_addr02', |
---|
267 | 'shipping_tel01', |
---|
268 | 'shipping_tel02', |
---|
269 | 'shipping_tel03' |
---|
270 | ]; |
---|
271 | |
---|
272 | if(!document.form1['deliv_check'].checked) { |
---|
273 | eccube.changeDisabled(list, '#dddddd'); |
---|
274 | } else { |
---|
275 | eccube.changeDisabled(list, ''); |
---|
276 | } |
---|
277 | } |
---|
278 | }; |
---|
279 | |
---|
280 | // 最初に設定されていた色を保存しておく。 |
---|
281 | eccube.savedColor = []; |
---|
282 | |
---|
283 | eccube.changeDisabled = function(list, color) { |
---|
284 | var len = list.length; |
---|
285 | |
---|
286 | for(i = 0; i < len; i++) { |
---|
287 | if(document.form1[list[i]]) { |
---|
288 | if(color == "") { |
---|
289 | // 有効にする。 |
---|
290 | document.form1[list[i]].disabled = false; |
---|
291 | document.form1[list[i]].style.backgroundColor = eccube.savedColor[list[i]]; |
---|
292 | } else { |
---|
293 | // 無効にする。 |
---|
294 | document.form1[list[i]].disabled = true; |
---|
295 | eccube.savedColor[list[i]] = document.form1[list[i]].style.backgroundColor; |
---|
296 | document.form1[list[i]].style.backgroundColor = color;//"#f0f0f0"; |
---|
297 | } |
---|
298 | } |
---|
299 | } |
---|
300 | }; |
---|
301 | |
---|
302 | // ログイン時の入力チェック |
---|
303 | eccube.checkLoginFormInputted = function(form, emailKey, passKey) { |
---|
304 | var checkItems = []; |
---|
305 | |
---|
306 | if (typeof emailKey === 'undefined') { |
---|
307 | checkItems[0] = 'login_email'; |
---|
308 | } else { |
---|
309 | checkItems[0] = emailKey; |
---|
310 | } |
---|
311 | if (typeof passKey === 'undefined') { |
---|
312 | checkItems[1] = 'login_pass'; |
---|
313 | } else { |
---|
314 | checkItems[1] = passKey; |
---|
315 | } |
---|
316 | |
---|
317 | var max = checkItems.length; |
---|
318 | var errorFlag = false; |
---|
319 | |
---|
320 | // 必須項目のチェック |
---|
321 | for(var cnt = 0; cnt < max; cnt++) { |
---|
322 | if(document.forms[form][checkItems[cnt]].value == "") { |
---|
323 | errorFlag = true; |
---|
324 | break; |
---|
325 | } |
---|
326 | } |
---|
327 | |
---|
328 | // 必須項目が入力されていない場合 |
---|
329 | if(errorFlag == true) { |
---|
330 | alert('メールアドレス/パスワードを入力して下さい。'); |
---|
331 | return false; |
---|
332 | } else { |
---|
333 | return true; |
---|
334 | } |
---|
335 | }; |
---|
336 | |
---|
337 | //親ウィンドウのページを変更する. |
---|
338 | eccube.changeParentUrl = function(url) { |
---|
339 | // 親ウィンドウの存在確認 |
---|
340 | if(eccube.isOpener()) { |
---|
341 | window.opener.location.href = url; |
---|
342 | } else { |
---|
343 | window.close(); |
---|
344 | } |
---|
345 | }; |
---|
346 | |
---|
347 | //文字数をカウントする。 |
---|
348 | //引数1:フォーム名称 |
---|
349 | //引数2:文字数カウント対象 |
---|
350 | //引数3:カウント結果格納対象 |
---|
351 | eccube.countChars = function(form,sch,cnt) { |
---|
352 | document.forms[form][cnt].value= document.forms[form][sch].value.length; |
---|
353 | }; |
---|
354 | |
---|
355 | // テキストエリアのサイズを変更する. |
---|
356 | eccube.toggleRows = function(buttonSelector, textAreaSelector, max, min) { |
---|
357 | if ($(textAreaSelector).attr('rows') <= min) { |
---|
358 | $(textAreaSelector).attr('rows', max); |
---|
359 | $(buttonSelector).text('縮小'); |
---|
360 | } else { |
---|
361 | $(textAreaSelector).attr('rows', min); |
---|
362 | $(buttonSelector).text('拡大'); |
---|
363 | } |
---|
364 | }; |
---|
365 | |
---|
366 | /** |
---|
367 | * 規格2のプルダウンを設定する. |
---|
368 | */ |
---|
369 | eccube.setClassCategories = function($form, product_id, $sele1, $sele2, selected_id2) { |
---|
370 | if ($sele1 && $sele1.length) { |
---|
371 | var classcat_id1 = $sele1.val() ? $sele1.val() : ''; |
---|
372 | if ($sele2 && $sele2.length) { |
---|
373 | // 規格2の選択肢をクリア |
---|
374 | $sele2.children().remove(); |
---|
375 | |
---|
376 | var classcat2; |
---|
377 | |
---|
378 | // 商品一覧時 |
---|
379 | if (eccube.productsClassCategories !== undefined) { |
---|
380 | classcat2 = eccube.productsClassCategories[product_id][classcat_id1]; |
---|
381 | } |
---|
382 | // 詳細表示時 |
---|
383 | else { |
---|
384 | classcat2 = eccube.classCategories[classcat_id1]; |
---|
385 | } |
---|
386 | |
---|
387 | // 規格2の要素を設定 |
---|
388 | for (var key in classcat2) { |
---|
389 | var id = classcat2[key]['classcategory_id2']; |
---|
390 | var name = classcat2[key]['name']; |
---|
391 | var option = $('<option />').val(id ? id : '').text(name); |
---|
392 | if (id == selected_id2) { |
---|
393 | option.attr('selected', true); |
---|
394 | } |
---|
395 | $sele2.append(option); |
---|
396 | } |
---|
397 | eccube.checkStock($form, product_id, $sele1.val() ? $sele1.val() : '__unselected2', |
---|
398 | $sele2.val() ? $sele2.val() : ''); |
---|
399 | } |
---|
400 | } |
---|
401 | }; |
---|
402 | |
---|
403 | /** |
---|
404 | * 規格の選択状態に応じて, フィールドを設定する. |
---|
405 | */ |
---|
406 | eccube.checkStock = function($form, product_id, classcat_id1, classcat_id2) { |
---|
407 | |
---|
408 | classcat_id2 = classcat_id2 ? classcat_id2 : ''; |
---|
409 | |
---|
410 | var classcat2; |
---|
411 | |
---|
412 | // 商品一覧時 |
---|
413 | if (typeof eccube.productsClassCategories != 'undefined') { |
---|
414 | classcat2 = eccube.productsClassCategories[product_id][classcat_id1]['#' + classcat_id2]; |
---|
415 | } |
---|
416 | // 詳細表示時 |
---|
417 | else { |
---|
418 | classcat2 = eccube.classCategories[classcat_id1]['#' + classcat_id2]; |
---|
419 | } |
---|
420 | |
---|
421 | // 商品コード |
---|
422 | var $product_code_default = $form.find('[id^=product_code_default]'); |
---|
423 | var $product_code_dynamic = $form.find('[id^=product_code_dynamic]'); |
---|
424 | if (classcat2 |
---|
425 | && typeof classcat2['product_code'] != 'undefined') { |
---|
426 | $product_code_default.hide(); |
---|
427 | $product_code_dynamic.show(); |
---|
428 | $product_code_dynamic.text(classcat2['product_code']); |
---|
429 | } else { |
---|
430 | $product_code_default.show(); |
---|
431 | $product_code_dynamic.hide(); |
---|
432 | } |
---|
433 | |
---|
434 | // 在庫(品切れ) |
---|
435 | var $cartbtn_default = $form.find('[id^=cartbtn_default]'); |
---|
436 | var $cartbtn_dynamic = $form.find('[id^=cartbtn_dynamic]'); |
---|
437 | if (classcat2 && classcat2['stock_find'] === false) { |
---|
438 | |
---|
439 | $cartbtn_dynamic.text('申し訳ございませんが、只今品切れ中です。').show(); |
---|
440 | $cartbtn_default.hide(); |
---|
441 | } else { |
---|
442 | $cartbtn_dynamic.hide(); |
---|
443 | $cartbtn_default.show(); |
---|
444 | } |
---|
445 | |
---|
446 | // 通常価格 |
---|
447 | var $price01_default = $form.find('[id^=price01_default]'); |
---|
448 | var $price01_dynamic = $form.find('[id^=price01_dynamic]'); |
---|
449 | if (classcat2 |
---|
450 | && typeof classcat2['price01'] != 'undefined' |
---|
451 | && String(classcat2['price01']).length >= 1) { |
---|
452 | |
---|
453 | $price01_dynamic.text(classcat2['price01']).show(); |
---|
454 | $price01_default.hide(); |
---|
455 | } else { |
---|
456 | $price01_dynamic.hide(); |
---|
457 | $price01_default.show(); |
---|
458 | } |
---|
459 | |
---|
460 | // 販売価格 |
---|
461 | var $price02_default = $form.find('[id^=price02_default]'); |
---|
462 | var $price02_dynamic = $form.find('[id^=price02_dynamic]'); |
---|
463 | if (classcat2 |
---|
464 | && typeof classcat2['price02'] != 'undefined' |
---|
465 | && String(classcat2['price02']).length >= 1) { |
---|
466 | |
---|
467 | $price02_dynamic.text(classcat2['price02']).show(); |
---|
468 | $price02_default.hide(); |
---|
469 | } else { |
---|
470 | $price02_dynamic.hide(); |
---|
471 | $price02_default.show(); |
---|
472 | } |
---|
473 | |
---|
474 | // ポイント |
---|
475 | var $point_default = $form.find('[id^=point_default]'); |
---|
476 | var $point_dynamic = $form.find('[id^=point_dynamic]'); |
---|
477 | if (classcat2 |
---|
478 | && typeof classcat2['point'] != 'undefined' |
---|
479 | && String(classcat2['point']).length >= 1) { |
---|
480 | |
---|
481 | $point_dynamic.text(classcat2['point']).show(); |
---|
482 | $point_default.hide(); |
---|
483 | } else { |
---|
484 | $point_dynamic.hide(); |
---|
485 | $point_default.show(); |
---|
486 | } |
---|
487 | |
---|
488 | // 商品規格 |
---|
489 | var $product_class_id_dynamic = $form.find('[id^=product_class_id]'); |
---|
490 | if (classcat2 |
---|
491 | && typeof classcat2['product_class_id'] != 'undefined' |
---|
492 | && String(classcat2['product_class_id']).length >= 1) { |
---|
493 | |
---|
494 | $product_class_id_dynamic.val(classcat2['product_class_id']); |
---|
495 | } else { |
---|
496 | $product_class_id_dynamic.val(''); |
---|
497 | } |
---|
498 | }; |
---|
499 | |
---|
500 | // グローバルに使用できるようにする |
---|
501 | window.eccube = eccube; |
---|
502 | |
---|
503 | /** |
---|
504 | * Initialize. |
---|
505 | */ |
---|
506 | $(function() { |
---|
507 | // 規格1選択時 |
---|
508 | $('select[name=classcategory_id1]') |
---|
509 | .change(function() { |
---|
510 | var $form = $(this).parents('form'); |
---|
511 | var product_id = $form.find('input[name=product_id]').val(); |
---|
512 | var $sele1 = $(this); |
---|
513 | var $sele2 = $form.find('select[name=classcategory_id2]'); |
---|
514 | |
---|
515 | // 規格1のみの場合 |
---|
516 | if (!$sele2.length) { |
---|
517 | eccube.checkStock($form, product_id, $sele1.val(), '0'); |
---|
518 | // 規格2ありの場合 |
---|
519 | } else { |
---|
520 | eccube.setClassCategories($form, product_id, $sele1, $sele2); |
---|
521 | } |
---|
522 | }); |
---|
523 | |
---|
524 | // 規格2選択時 |
---|
525 | $('select[name=classcategory_id2]') |
---|
526 | .change(function() { |
---|
527 | var $form = $(this).parents('form'); |
---|
528 | var product_id = $form.find('input[name=product_id]').val(); |
---|
529 | var $sele1 = $form.find('select[name=classcategory_id1]'); |
---|
530 | var $sele2 = $(this); |
---|
531 | eccube.checkStock($form, product_id, $sele1.val(), $sele2.val()); |
---|
532 | }); |
---|
533 | }); |
---|
534 | })(window); |
---|