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

Revision 23187, 19.9 KB checked in by h_yoshimoto, 12 years ago (diff)

#2348 r23171 - r23176 r23178 - r23180 をマージ

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