source: branches/comu-ver2/html/user_data/packages/default/js/site.js @ 18358

Revision 18358, 10.5 KB checked in by satou, 14 years ago (diff)

#562 支払方法選択画面でリロードしないように改良(jQuery×AJAX)

Line 
1/*
2 * This file is part of EC-CUBE
3 *
4 * Copyright(c) 2000-2007 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 fnIsopener() {
24    var ua = navigator.userAgent;
25    if( !!window.opener ) {
26        if( ua.indexOf('MSIE 4')!=-1 && ua.indexOf('Win')!=-1 ) {
27            return !window.opener.closed;
28        } else {
29            return typeof window.opener.document == 'object';
30        }
31    } else {
32        return false;
33    }
34}
35
36// 郵便番号入力呼び出し.
37function fnCallAddress(php_url, tagname1, tagname2, input1, input2) {
38    zip1 = document.form1[tagname1].value;
39    zip2 = document.form1[tagname2].value;
40
41    if(zip1.length == 3 && zip2.length == 4) {
42        $.get(
43            php_url,
44            {zip1: zip1, zip2: zip2, input1: input1, input2: input2},
45            function(data) {
46                arrdata = data.split("|");
47                if (arrdata.length > 1) {
48                    fnPutAddress(input1, input2, arrdata[0], arrdata[1], arrdata[2]);
49                } else {
50                    alert(data);
51                }
52            }
53        );
54    } else {
55        alert("郵便番号を正しく入力して下さい。");
56    }
57}
58
59// 郵便番号から検索した住所を渡す.
60function fnPutAddress(input1, input2, state, city, town) {
61    if(state != "") {
62        // 項目に値を入力する.
63        document.form1[input1].selectedIndex = state;
64        document.form1[input2].value = city + town;
65    }
66}
67
68function fnOpenNoMenu(URL) {
69    window.open(URL,"nomenu","scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no,status=no");
70}
71
72function fnOpenWindow(URL,name,width,height) {
73    window.open(URL,name,"width="+width+",height="+height+",scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no,status=no");
74}
75
76function fnSetFocus(name) {
77    if(document.form1[name]) {
78        document.form1[name].focus();
79    }
80}
81
82// セレクトボックスに項目を割り当てる.
83function fnSetSelect(name1, name2, val) {
84    sele1 = document.form1[name1];
85    sele2 = document.form1[name2];
86
87    if(sele1 && sele2) {
88        index=sele1.selectedIndex;
89
90        // セレクトボックスのクリア
91        count=sele2.options.length
92        for(i = count; i >= 0; i--) {
93            sele2.options[i]=null;
94        }
95
96        // セレクトボックスに値を割り当てる。
97        len = lists[index].length
98        for(i = 0; i < len; i++) {
99            sele2.options[i]=new Option(lists[index][i], vals[index][i]);
100            if(val != "" && vals[index][i] == val) {
101                sele2.options[i].selected = true;
102            }
103        }
104    }
105}
106
107// Enterキー入力をキャンセルする。(IEに対応)
108function fnCancelEnter()
109{
110    if (gCssUA.indexOf("WIN") != -1 && gCssUA.indexOf("MSIE") != -1) {
111        if (window.event.keyCode == 13)
112        {
113            return false;
114        }
115    }
116    return true;
117}
118
119// モードとキーを指定してSUBMITを行う。
120function fnModeSubmit(mode, keyname, keyid) {
121    switch(mode) {
122    case 'delete_category':
123        if(!window.confirm('選択したカテゴリとカテゴリ内のすべてのカテゴリを削除します')){
124            return;
125        }
126        break;
127    case 'delete':
128        if(!window.confirm('一度削除したデータは、元に戻せません。\n削除しても宜しいですか?')){
129            return;
130        }
131        break;
132    case 'confirm':
133        if(!window.confirm('登録しても宜しいですか')){
134            return;
135        }
136        break;
137    case 'delete_all':
138        if(!window.confirm('検索結果をすべて削除しても宜しいですか')){
139            return;
140        }
141        break;
142    default:
143        break;
144    }
145    document.form1['mode'].value = mode;
146    if(keyname != "" && keyid != "") {
147        document.form1[keyname].value = keyid;
148    }
149    document.form1.submit();
150}
151
152function fnFormModeSubmit(form, mode, keyname, keyid) {
153    switch(mode) {
154    case 'delete':
155        if(!window.confirm('一度削除したデータは、元に戻せません。\n削除しても宜しいですか?')){
156            return;
157        }
158        break;
159    case 'confirm':
160        if(!window.confirm('登録しても宜しいですか')){
161            return;
162        }
163        break;
164    case 'regist':
165        if(!window.confirm('登録しても宜しいですか')){
166            return;
167        }
168        break;
169    default:
170        break;
171    }
172    document.forms[form]['mode'].value = mode;
173    if(keyname != "" && keyid != "") {
174        document.forms[form][keyname].value = keyid;
175    }
176    document.forms[form].submit();
177}
178
179function fnSetFormSubmit(form, key, val) {
180    document.forms[form][key].value = val;
181    document.forms[form].submit();
182    return false;
183}
184
185function fnSetVal(key, val) {
186    fnSetFormVal('form1', key, val);
187}
188
189function fnSetFormVal(form, key, val) {
190    document.forms[form][key].value = val;
191}
192
193function fnChangeAction(url) {
194    document.form1.action = url;
195}
196
197// ページナビで使用する。
198function fnNaviPage(pageno) {
199    document.form1['pageno'].value = pageno;
200    document.form1.submit();
201}
202
203function fnSearchPageNavi(pageno) {
204    document.form1['pageno'].value = pageno;
205    document.form1['mode'].value = 'search';
206    document.form1.submit();
207    }
208
209function fnSubmit(){
210    document.form1.submit();
211}
212
213// ポイント入力制限。
214function fnCheckInputPoint() {
215    if(document.form1['point_check']) {
216        list = new Array(
217                        'use_point'
218                        );
219
220        if(!document.form1['point_check'][0].checked) {
221            color = "#dddddd";
222            flag = true;
223        } else {
224            color = "";
225            flag = false;
226        }
227
228        len = list.length
229        for(i = 0; i < len; i++) {
230            if(document.form1[list[i]]) {
231                document.form1[list[i]].disabled = flag;
232                document.form1[list[i]].style.backgroundColor = color;
233            }
234        }
235    }
236}
237
238// 別のお届け先入力制限。
239function fnCheckInputDeliv() {
240    if(!document.form1) {
241        return;
242    }
243    if(document.form1['deliv_check']) {
244        list = new Array(
245                        'deliv_name01',
246                        'deliv_name02',
247                        'deliv_kana01',
248                        'deliv_kana02',
249                        'deliv_pref',
250                        'deliv_zip01',
251                        'deliv_zip02',
252                        'deliv_addr01',
253                        'deliv_addr02',
254                        'deliv_tel01',
255                        'deliv_tel02',
256                        'deliv_tel03'
257                        );
258
259        if(!document.form1['deliv_check'].checked) {
260            fnChangeDisabled(list, '#dddddd');
261        } else {
262            fnChangeDisabled(list, '');
263        }
264    }
265}
266
267
268// 購入時会員登録入力制限。
269function fnCheckInputMember() {
270    if(document.form1['member_check']) {
271        list = new Array(
272                        'password',
273                        'password_confirm',
274                        'reminder',
275                        'reminder_answer'
276                        );
277
278        if(!document.form1['member_check'].checked) {
279            fnChangeDisabled(list, '#dddddd');
280        } else {
281            fnChangeDisabled(list, '');
282        }
283    }
284}
285
286// 最初に設定されていた色を保存しておく。
287var g_savecolor = new Array();
288
289function fnChangeDisabled(list, color) {
290    len = list.length;
291
292    for(i = 0; i < len; i++) {
293        if(document.form1[list[i]]) {
294            if(color == "") {
295                // 有効にする。
296                document.form1[list[i]].disabled = false;
297                document.form1[list[i]].style.backgroundColor = g_savecolor[list[i]];
298            } else {
299                // 無効にする。
300                document.form1[list[i]].disabled = true;
301                g_savecolor[list[i]] = document.form1[list[i]].style.backgroundColor;
302                document.form1[list[i]].style.backgroundColor = color;//"#f0f0f0";
303            }
304        }
305    }
306}
307
308
309// ログイン時の入力チェック
310function fnCheckLogin(formname) {
311    var lstitem = new Array();
312
313    if(formname == 'login_mypage'){
314    lstitem[0] = 'mypage_login_email';
315    lstitem[1] = 'mypage_login_pass';
316    }else{
317    lstitem[0] = 'login_email';
318    lstitem[1] = 'login_pass';
319    }
320    var max = lstitem.length;
321    var errflg = false;
322    var cnt = 0;
323
324    // 必須項目のチェック
325    for(cnt = 0; cnt < max; cnt++) {
326        if(document.forms[formname][lstitem[cnt]].value == "") {
327            errflg = true;
328            break;
329        }
330    }
331
332    // 必須項目が入力されていない場合
333    if(errflg == true) {
334        alert('メールアドレス/パスワードを入力して下さい。');
335        return false;
336    }
337}
338
339// 時間の計測.
340function fnPassTime(){
341    end_time = new Date();
342    time = end_time.getTime() - start_time.getTime();
343    alert((time/1000));
344}
345start_time = new Date();
346
347//親ウィンドウのページを変更する.
348function fnUpdateParent(url) {
349    // 親ウィンドウの存在確認
350    if(fnIsopener()) {
351        window.opener.location.href = url;
352    } else {
353        window.close();
354    }
355}
356
357//特定のキーをSUBMITする.
358function fnKeySubmit(keyname, keyid) {
359    if(keyname != "" && keyid != "") {
360        document.form1[keyname].value = keyid;
361    }
362    document.form1.submit();
363}
364
365//文字数をカウントする。
366//引数1:フォーム名称
367//引数2:文字数カウント対象
368//引数3:カウント結果格納対象
369function fnCharCount(form,sch,cnt) {
370    document.forms[form][cnt].value= document.forms[form][sch].value.length;
371}
372
373
374// テキストエリアのサイズを変更する.
375function ChangeSize(button, TextArea, Max, Min, row_tmp){
376
377    if(TextArea.rows <= Min){
378        TextArea.rows=Max; button.value="小さくする"; row_tmp.value=Max;
379    }else{
380        TextArea.rows =Min; button.value="大きくする"; row_tmp.value=Min;
381    }
382}
383
384// お届け時間のリアル反映
385function fnSetDelivTime(mode, r_key, s_id) {
386    var f_key, f_val;
387    var f_cnt = document.form1.length;
388    var f_data = "mode=" + mode;
389
390    // formデータの形成
391    for (i = 0; i < f_cnt; i++) {
392        f_key = document.form1[i].name;
393        f_val = document.form1[i].value;
394        if (f_key != "mode") {
395            if (f_key == r_key) {
396                if (document.form1[i].checked === true) {
397                    f_data += "&" + f_key + "=" + f_val;
398                }
399            } else {
400                f_data += "&" + f_key + "=" + f_val;
401            }
402        }
403    }
404
405    // AJAX
406    $.ajax({
407        type: "POST",
408        url: document.form1.action,
409        data: f_data,
410        dataType: "json",
411        success: function(data) {
412            var elm_s = "select#" + s_id;
413            var elm_o = elm_s + " option";
414            $(elm_o).remove();
415            $(elm_s).append($('<option>').attr({value: ""}).text("指定なし"));
416            for (i = 0; i < data.length; i++) {
417                if (data[i].time_id > 0) {
418                    $(elm_s).append($('<option>').attr({value: data[i].time_id}).text(data[i].deliv_time));
419                    $(elm_s).width();
420                }
421            }
422        }
423    });
424}
Note: See TracBrowser for help on using the repository browser.