-
Notifications
You must be signed in to change notification settings - Fork 644
/
function.js
216 lines (181 loc) · 6.69 KB
/
function.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
$(function() {
$('.pagetop').hide();
$(window).on('scroll', function() {
// ページトップフェードイン
if ($(this).scrollTop() > 300) {
$('.pagetop').fadeIn();
} else {
$('.pagetop').fadeOut();
}
// PC表示の時のみに適用
if (window.innerWidth > 767) {
if ($('.ec-orderRole').length) {
var side = $(".ec-orderRole__summary"),
wrap = $(".ec-orderRole").first(),
min_move = wrap.offset().top,
max_move = wrap.height(),
margin_bottom = max_move - min_move;
var scrollTop = $(window).scrollTop();
if (scrollTop > min_move && scrollTop < max_move) {
var margin_top = scrollTop - min_move;
side.css({"margin-top": margin_top});
} else if (scrollTop < min_move) {
side.css({"margin-top": 0});
} else if (scrollTop > max_move) {
side.css({"margin-top": margin_bottom});
}
}
}
return false;
});
$('.ec-headerNavSP').on('click', function() {
$('.ec-layoutRole').toggleClass('is_active');
$('.ec-drawerRole').toggleClass('is_active');
$('.ec-drawerRoleClose').toggleClass('is_active');
$('body').toggleClass('have_curtain');
});
$('.ec-overlayRole').on('click', function() {
$('body').removeClass('have_curtain');
$('.ec-layoutRole').removeClass('is_active');
$('.ec-drawerRole').removeClass('is_active');
$('.ec-drawerRoleClose').removeClass('is_active');
});
$('.ec-drawerRoleClose').on('click', function() {
$('body').removeClass('have_curtain');
$('.ec-layoutRole').removeClass('is_active');
$('.ec-drawerRole').removeClass('is_active');
$('.ec-drawerRoleClose').removeClass('is_active');
});
// TODO: カート展開時のアイコン変更処理
$('.ec-headerRole__cart').on('click', '.ec-cartNavi', function() {
// $('.ec-cartNavi').toggleClass('is-active');
$('.ec-cartNaviIsset').toggleClass('is-active');
$('.ec-cartNaviNull').toggleClass('is-active')
});
$('.ec-headerRole__cart').on('click', '.ec-cartNavi--cancel', function() {
// $('.ec-cartNavi').toggleClass('is-active');
$('.ec-cartNaviIsset').toggleClass('is-active');
$('.ec-cartNaviNull').toggleClass('is-active')
});
$('.ec-orderMail__link').on('click', function() {
$(this).siblings('.ec-orderMail__body').slideToggle();
});
$('.ec-orderMail__close').on('click', function() {
$(this).parent().slideToggle();
});
$('.is_inDrawer').each(function() {
var html = $(this).html();
$(html).appendTo('.ec-drawerRole');
});
$('.ec-blockTopBtn').on('click', function() {
$('html,body').animate({'scrollTop': 0}, 500);
});
// スマホのドロワーメニュー内の下層カテゴリ表示
// TODO FIXME スマホのカテゴリ表示方法
$('.ec-itemNav ul a').click(function() {
var child = $(this).siblings();
if (child.length > 0) {
if (child.is(':visible')) {
return true;
} else {
child.slideToggle();
return false;
}
}
});
// イベント実行時のオーバーレイ処理
// classに「load-overlay」が記述されていると画面がオーバーレイされる
$('.load-overlay').on({
click: function() {
loadingOverlay();
},
change: function() {
loadingOverlay();
}
});
// submit処理についてはオーバーレイ処理を行う
$(document).on('click', 'input[type="submit"], button[type="submit"]', function() {
// html5 validate対応
var valid = true;
var form = getAncestorOfTagType(this, 'FORM');
if (typeof form !== 'undefined' && !form.hasAttribute('novalidate')) {
// form validation
if (typeof form.checkValidity === 'function') {
valid = form.checkValidity();
}
}
if (valid) {
loadingOverlay();
}
});
});
$(window).on('pageshow', function() {
loadingOverlay('hide');
});
/**
* オーバーレイ処理を行う関数
*/
function loadingOverlay(action) {
if (action == 'hide') {
$('.bg-load-overlay').remove();
} else {
$overlay = $('<div class="bg-load-overlay">');
$('body').append($overlay);
}
}
/**
* 要素FORMチェック
*/
function getAncestorOfTagType(elem, type) {
while (elem.parentNode && elem.tagName !== type) {
elem = elem.parentNode;
}
return (type === elem.tagName) ? elem : undefined;
}
// anchorをクリックした時にformを裏で作って指定のメソッドでリクエストを飛ばす
// Twigには以下のように埋め込む
// <a href="PATH" {{ csrf_token_for_anchor() }} data-method="(put/delete/postのうちいずれか)" data-confirm="xxxx" data-message="xxxx">
//
// オプション要素
// data-confirm : falseを定義すると確認ダイアログを出さない。デフォルトはダイアログを出す
// data-message : 確認ダイアログを出す際のメッセージをデフォルトから変更する
//
$(function() {
var createForm = function(action, data) {
var $form = $('<form action="' + action + '" method="post"></form>');
for (input in data) {
if (data.hasOwnProperty(input)) {
$form.append('<input name="' + input + '" value="' + data[input] + '">');
}
}
return $form;
};
$('a[token-for-anchor]').click(function(e) {
e.preventDefault();
var $this = $(this);
var data = $this.data();
if (data.confirm != false) {
if (!confirm(data.message ? data.message : eccube_lang['common.delete_confirm'] )) {
return false;
}
}
// 削除時はオーバーレイ処理を入れる
loadingOverlay();
var $form = createForm($this.attr('href'), {
_token: $this.attr('token-for-anchor'),
_method: data.method
}).hide();
$('body').append($form); // Firefox requires form to be on the page to allow submission
$form.submit();
});
});