source: branches/version-2_13-dev/html/js/eccube.js @ 23058

Revision 23058, 16.9 KB checked in by pineray, 11 years ago (diff)

#2341 EC-CUBE独自のJSをまとめる
使用されていないスタイルを定義するcss.jsを削除.

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