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