source: branches/version-2_13_0/html/js/eccube.js @ 23104

Revision 23104, 18.4 KB checked in by h_yoshimoto, 11 years ago (diff)

#2348 r23077 - r23081 をマージ

Line 
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        var formElement = $("form#" + form);
160        switch(mode) {
161            case 'delete':
162                if(!window.confirm('一度削除したデータは、元に戻せません。\n削除しても宜しいですか?')){
163                    return;
164                }
165                break;
166            case 'confirm':
167                if(!window.confirm('登録しても宜しいですか')){
168                    return;
169                }
170                break;
171            case 'regist':
172                if(!window.confirm('登録しても宜しいですか')){
173                    return;
174                }
175                break;
176            default:
177                break;
178        }
179        formElement.find("input[name='mode']").val(mode);
180        if(keyname != "" && keyid != "") {
181            formElement.find("*[name=" + keyname + "]").val(keyid);
182        }
183        formElement.submit();
184    };
185
186    eccube.setValueAndSubmit = function(form, key, val) {
187        var formElement = $("form#" + form);
188        formElement.find("*[name=" + key + "]").val(val);
189        formElement.submit();
190        return false;
191    };
192
193    eccube.setValue = function(key, val, form) {
194        if (typeof form === 'undefined') {
195            form = 'form1';
196        }
197        var formElement = $("form#" + form);
198        formElement.find("*[name=" + key + "]").val(val);
199    };
200
201    eccube.changeAction = function(url) {
202        document.form1.action = url;
203    };
204
205    // ページナビで使用する。
206    eccube.movePage = function(pageno, mode, form) {
207        if (typeof form === 'undefined') {
208            form = 'form1';
209        }
210        var formElement = $("form#" + form);
211        formElement.find("input[name=pageno]").val(pageno);
212        if (typeof mode !== 'undefined') {
213            formElement.find("input[name='mode']").val('search');
214        }
215        formElement.submit();
216    };
217
218    eccube.submitForm = function(form){
219        if (typeof form === 'undefined') {
220            form = 'form1';
221        }
222        $("form#" + form).submit();
223    };
224
225    // ポイント入力制限。
226    eccube.togglePointForm = function() {
227        if(document.form1['point_check']) {
228            var list = ['use_point'];
229            var color;
230            var flag;
231
232            if(!document.form1['point_check'][0].checked) {
233                color = "#dddddd";
234                flag = true;
235            } else {
236                color = "";
237                flag = false;
238            }
239
240            var len = list.length;
241            for(i = 0; i < len; i++) {
242                if(document.form1[list[i]]) {
243                    var current_color = document.form1[list[i]].style.backgroundColor;
244                    if (color != "#dddddd" && (current_color == "#ffe8e8" || current_color == "rgb(255, 232, 232)"))
245                    {
246                        continue;
247                    }
248                    document.form1[list[i]].disabled = flag;
249                    document.form1[list[i]].style.backgroundColor = color;
250                }
251            }
252        }
253    };
254
255    // 別のお届け先入力制限。
256    eccube.toggleDeliveryForm = function() {
257        if(!document.form1) {
258            return;
259        }
260        if(document.form1['deliv_check']) {
261            var list = [
262                'shipping_name01',
263                'shipping_name02',
264                'shipping_kana01',
265                'shipping_kana02',
266                'shipping_pref',
267                'shipping_zip01',
268                'shipping_zip02',
269                'shipping_addr01',
270                'shipping_addr02',
271                'shipping_tel01',
272                'shipping_tel02',
273                'shipping_tel03'
274            ];
275
276            if(!document.form1['deliv_check'].checked) {
277                eccube.changeDisabled(list, '#dddddd');
278            } else {
279                eccube.changeDisabled(list, '');
280            }
281        }
282    };
283
284    // 最初に設定されていた色を保存しておく。
285    eccube.savedColor = [];
286
287    eccube.changeDisabled = function(list, color) {
288        var len = list.length;
289
290        for(i = 0; i < len; i++) {
291            if(document.form1[list[i]]) {
292                if(color == "") {
293                    // 有効にする。
294                    document.form1[list[i]].disabled = false;
295                    document.form1[list[i]].style.backgroundColor = eccube.savedColor[list[i]];
296                } else {
297                    // 無効にする。
298                    document.form1[list[i]].disabled = true;
299                    eccube.savedColor[list[i]] = document.form1[list[i]].style.backgroundColor;
300                    document.form1[list[i]].style.backgroundColor = color;//"#f0f0f0";
301                }
302            }
303        }
304    };
305
306    // ログイン時の入力チェック
307    eccube.checkLoginFormInputted = function(form, emailKey, passKey) {
308        var formElement = $("form#" + form);
309        var checkItems = [];
310
311        if (typeof emailKey === 'undefined') {
312            checkItems[0] = 'login_email';
313        } else {
314            checkItems[0] = emailKey;
315        }
316        if (typeof passKey === 'undefined') {
317            checkItems[1] = 'login_pass';
318        } else {
319            checkItems[1] = passKey;
320        }
321
322        var max = checkItems.length;
323        var errorFlag = false;
324
325        // 必須項目のチェック
326        for(var cnt = 0; cnt < max; cnt++) {
327            if(formElement.find("input[name=" + checkItems[cnt] + "]").val() == "") {
328                errorFlag = true;
329                break;
330            }
331        }
332
333        // 必須項目が入力されていない場合
334        if(errorFlag == true) {
335            alert('メールアドレス/パスワードを入力して下さい。');
336            return false;
337        } else {
338            return true;
339        }
340    };
341
342    //親ウィンドウのページを変更する.
343    eccube.changeParentUrl = function(url) {
344        // 親ウィンドウの存在確認
345        if(eccube.isOpener()) {
346            window.opener.location.href = url;
347        } else {
348            window.close();
349        }
350    };
351
352    //文字数をカウントする。
353    //引数1:フォーム名称
354    //引数2:文字数カウント対象
355    //引数3:カウント結果格納対象
356    eccube.countChars = function(form,sch,cnt) {
357        var formElement = $("form#" + form);
358        formElement.find("input[name="+cnt+"]").val(formElement.find("*[name="+sch+"]").val().length);
359    };
360
361    // テキストエリアのサイズを変更する.
362    eccube.toggleRows = function(buttonSelector, textAreaSelector, max, min) {
363        if ($(textAreaSelector).attr('rows') <= min) {
364            $(textAreaSelector).attr('rows', max);
365            $(buttonSelector).text('縮小');
366        } else {
367            $(textAreaSelector).attr('rows', min);
368            $(buttonSelector).text('拡大');
369        }
370    };
371
372    /**
373     * 規格2のプルダウンを設定する.
374     */
375    eccube.setClassCategories = function($form, product_id, $sele1, $sele2, selected_id2) {
376        if ($sele1 && $sele1.length) {
377            var classcat_id1 = $sele1.val() ? $sele1.val() : '';
378            if ($sele2 && $sele2.length) {
379                // 規格2の選択肢をクリア
380                $sele2.children().remove();
381
382                var classcat2;
383
384                // 商品一覧時
385                if (eccube.productsClassCategories !== undefined) {
386                    classcat2 = eccube.productsClassCategories[product_id][classcat_id1];
387                }
388                // 詳細表示時
389                else {
390                    classcat2 = eccube.classCategories[classcat_id1];
391                }
392
393                // 規格2の要素を設定
394                for (var key in classcat2) {
395                    var id = classcat2[key]['classcategory_id2'];
396                    var name = classcat2[key]['name'];
397                    var option = $('<option />').val(id ? id : '').text(name);
398                    if (id == selected_id2) {
399                        option.attr('selected', true);
400                    }
401                    $sele2.append(option);
402                }
403                eccube.checkStock($form, product_id, $sele1.val() ? $sele1.val() : '__unselected2',
404                    $sele2.val() ? $sele2.val() : '');
405            }
406        }
407    };
408
409    /**
410     * 規格の選択状態に応じて, フィールドを設定する.
411     */
412    eccube.checkStock = function($form, product_id, classcat_id1, classcat_id2) {
413
414        classcat_id2 = classcat_id2 ? classcat_id2 : '';
415
416        var classcat2;
417
418        // 商品一覧時
419        if (typeof eccube.productsClassCategories != 'undefined') {
420            classcat2 = eccube.productsClassCategories[product_id][classcat_id1]['#' + classcat_id2];
421        }
422        // 詳細表示時
423        else {
424            classcat2 = eccube.classCategories[classcat_id1]['#' + classcat_id2];
425        }
426
427        // 商品コード
428        var $product_code_default = $form.find('[id^=product_code_default]');
429        var $product_code_dynamic = $form.find('[id^=product_code_dynamic]');
430        if (classcat2
431            && typeof classcat2['product_code'] != 'undefined') {
432            $product_code_default.hide();
433            $product_code_dynamic.show();
434            $product_code_dynamic.text(classcat2['product_code']);
435        } else {
436            $product_code_default.show();
437            $product_code_dynamic.hide();
438        }
439
440        // 在庫(品切れ)
441        var $cartbtn_default = $form.find('[id^=cartbtn_default]');
442        var $cartbtn_dynamic = $form.find('[id^=cartbtn_dynamic]');
443        if (classcat2 && classcat2['stock_find'] === false) {
444
445            $cartbtn_dynamic.text('申し訳ございませんが、只今品切れ中です。').show();
446            $cartbtn_default.hide();
447        } else {
448            $cartbtn_dynamic.hide();
449            $cartbtn_default.show();
450        }
451
452        // 通常価格
453        var $price01_default = $form.find('[id^=price01_default]');
454        var $price01_dynamic = $form.find('[id^=price01_dynamic]');
455        if (classcat2
456            && typeof classcat2['price01'] != 'undefined'
457            && String(classcat2['price01']).length >= 1) {
458
459            $price01_dynamic.text(classcat2['price01']).show();
460            $price01_default.hide();
461        } else {
462            $price01_dynamic.hide();
463            $price01_default.show();
464        }
465
466        // 販売価格
467        var $price02_default = $form.find('[id^=price02_default]');
468        var $price02_dynamic = $form.find('[id^=price02_dynamic]');
469        if (classcat2
470            && typeof classcat2['price02'] != 'undefined'
471            && String(classcat2['price02']).length >= 1) {
472
473            $price02_dynamic.text(classcat2['price02']).show();
474            $price02_default.hide();
475        } else {
476            $price02_dynamic.hide();
477            $price02_default.show();
478        }
479
480        // ポイント
481        var $point_default = $form.find('[id^=point_default]');
482        var $point_dynamic = $form.find('[id^=point_dynamic]');
483        if (classcat2
484            && typeof classcat2['point'] != 'undefined'
485            && String(classcat2['point']).length >= 1) {
486
487            $point_dynamic.text(classcat2['point']).show();
488            $point_default.hide();
489        } else {
490            $point_dynamic.hide();
491            $point_default.show();
492        }
493
494        // 商品規格
495        var $product_class_id_dynamic = $form.find('[id^=product_class_id]');
496        if (classcat2
497            && typeof classcat2['product_class_id'] != 'undefined'
498            && String(classcat2['product_class_id']).length >= 1) {
499
500            $product_class_id_dynamic.val(classcat2['product_class_id']);
501        } else {
502            $product_class_id_dynamic.val('');
503        }
504    };
505
506    // グローバルに使用できるようにする
507    window.eccube = eccube;
508
509    /**
510     * Initialize.
511     */
512    $(function() {
513        // 規格1選択時
514        $('select[name=classcategory_id1]')
515            .change(function() {
516                var $form = $(this).parents('form');
517                var product_id = $form.find('input[name=product_id]').val();
518                var $sele1 = $(this);
519                var $sele2 = $form.find('select[name=classcategory_id2]');
520
521                // 規格1のみの場合
522                if (!$sele2.length) {
523                    eccube.checkStock($form, product_id, $sele1.val(), '0');
524                    // 規格2ありの場合
525                } else {
526                    eccube.setClassCategories($form, product_id, $sele1, $sele2);
527                }
528            });
529
530        // 規格2選択時
531        $('select[name=classcategory_id2]')
532            .change(function() {
533                var $form = $(this).parents('form');
534                var product_id = $form.find('input[name=product_id]').val();
535                var $sele1 = $form.find('select[name=classcategory_id1]');
536                var $sele2 = $(this);
537                eccube.checkStock($form, product_id, $sele1.val(), $sele2.val());
538            });
539    });
540})(window);
Note: See TracBrowser for help on using the repository browser.