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

Revision 23115, 19.1 KB checked in by m_uehara, 11 years ago (diff)

#2348 r23107 - r23114 をマージ

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