-
Notifications
You must be signed in to change notification settings - Fork 644
/
function.js
259 lines (231 loc) · 8.72 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
* 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.
*/
//mainNavArea toggle
var mainNavArea = function() {
$(function() {
$('.c-headerBar__toggleBtn').on('click', function() {
$('.c-mainNavArea').toggleClass('is-active');
$('.c-curtain').toggleClass('is-active');
});
$('.c-curtain').on('click', function() {
$('.c-mainNavArea').toggleClass('is-active');
$('.c-curtain').toggleClass('is-active');
});
})
};
mainNavArea();
//Bootstrap ツールチップ
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl)
});
/** @deprecated プラグイン等の後方互換用 */
var toolTip = function() {
$(function() {
$('[data-tooltip="true"]').tooltip();
})
};
toolTip();
// popover ポップオーバー
var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'))
var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
return new bootstrap.Popover(popoverTriggerEl)
});
/** @deprecated プラグイン等の後方互換用 */
var popoverAll = function() {
$(function() {
$('[data-toggle="popover"]').popover();
})
};
popoverAll();
//collapseIconChange collapseと連動するアイコン変化
var collapseIconMinus = function() {
$(function() {
$('.ec-collapse').on('shown.bs.collapse', function() {
var id = $(this).attr('id');
var icon = $('[href="#' + id + '"]').find('i');
icon.removeClass('fa-plus-square-o');
icon.addClass('fa-minus-square-o');
})
})
};
collapseIconMinus();
var collapseIconPlus = function() {
$(function() {
$('.ec-collapse').on('hidden.bs.collapse', function() {
var id = $(this).attr('id');
var icon = $('[href="#' + id + '"]').find('i');
icon.removeClass('fa-minus-square-o');
icon.addClass('fa-plus-square-o');
})
})
};
collapseIconPlus();
//cardCollapseIconChange カードコンポーネントのcollapseと連動するアイコン変化
var cardCollapseIconDown = function() {
$(function() {
$('.ec-cardCollapse').on('hidden.bs.collapse', function() {
var id = $(this).attr('id');
var icon = $('[href="#' + id + '"]').find('i');
icon.removeClass('fa-angle-up');
icon.addClass('fa-angle-down');
})
})
};
cardCollapseIconDown();
var cardCollapseIconUp = function() {
$(function() {
$('.ec-cardCollapse').on('shown.bs.collapse', function() {
var id = $(this).attr('id');
var icon = $('[href="#' + id + '"]').find('i');
icon.addClass('fa-angle-up');
})
})
};
cardCollapseIconUp();
// toggle bulk button
var toggleBtnBulk = function(checkboxSelector, btnSelector) {
$(function() {
if ($(checkboxSelector + ':checked').length) {
$(btnSelector).fadeIn('fast').addClass('d-block').removeClass('d-none');
} else {
$(btnSelector).fadeOut('fast', function() {
$(this).addClass('d-none').removeClass('d-block');
})
}
});
};
/////////// 2重submit制御.
if (typeof Ladda !== 'undefined') {
// a[token-for-anchor] を押下されるとJavaScriptで formを作成してPOSTする仕様になっていて、
// aタグにdisable属性を付与しても駄目(form生成&postしてしまう)だったので、cssでpointer-event:none;しています。
// https://github.com/EC-CUBE/ec-cube/pull/5971
Ladda.bind('button[type=submit],a[token-for-anchor]', {timeout: 2000});
$('button[type=submit].btn-ec-regular').attr('data-spinner-color', '#595959');
}
// 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);
$this.css('pointer-events','none');
var data = $this.data();
if (data.confirm != false) {
if (!confirm(data.message ? data.message : '削除してもよろしいですか?')) {
return false;
}
}
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();
});
});
// 入力チェックエラー発生時にエラー発生箇所までスクロールさせる
$(window).on('load', function() {
var el = $('.form-error-message');
if (el.length) {
// Open panel when has error
openPanel(el);
var errorOffset = el.first().offset().top;
var screenHeight = $(window).height();
var errorMargin = parseInt(screenHeight / 10) + $('header').outerHeight();
$('html, body').animate({
scrollTop: (errorOffset - errorMargin)
}, 500);
}
function openPanel(el) {
var $collapse = el.parents('.ec-cardCollapse');
$collapse.addClass('show');
var id = $collapse.attr('id');
var icon = $('[href="#' + id + '"]').find('i');
icon.removeClass('fa-angle-down');
icon.addClass('fa-angle-up');
}
});
var searchWord = function (searchText, el) {
var targetText;
// 検索ボックスに値が入っていない場合
if (searchText == '') {
// 全て表示する
el.show();
return;
}
// 検索ボックスに値が入ってる場合
// 表示を全て空にする
el.hide();
// 検索ワードが(子を含めて)含まれる要素のみ表示
el.each(function () {
targetText = $(this).text();
// 検索対象となるリストに入力された文字列が存在するかどうかを判断
if (targetText.toLowerCase().indexOf(searchText.toLowerCase()) != -1) {
// 存在する場合はそのリストのテキストを用意した配列に格納
$(this).show();
}
});
};
// 一覧ページのソート機能
$(function() {
if ($('.js-listSort').length < 1) {
return;
}
// 現在のソート状況をボタン表示に反映
const sortkey = $('.js-listSort-key').val();
const target = $('.js-listSort').filter('[data-sortkey="' + sortkey + '"]');
if (target.length === 1) {
target.addClass('listSort-current');
if ($('.js-listSort-type').val() === 'd') {
target.find('.fa').addClass('fa-arrow-down').removeClass('fa-arrow-up');
}
}
// ソート実施
$('.js-listSort').on({
click: function (e) {
const sortkey = $(e.currentTarget).data('sortkey');
const sorttype = ($('.js-listSort-key').val() === sortkey && $('.js-listSort-type').val() !== 'd') ? 'd' : 'a';
$('.js-listSort-key').val(sortkey);
$('.js-listSort-type').val(sorttype);
$('#search_form').submit();
e.preventDefault();
}
});
});
// input[type="datetime-local"]、初期クリック時に当日の0時0分を設定
$(function() {
if( $('[type="datetime-local"]').length ){
$('[type="datetime-local"]').on('click',function(){
if( $(this).val() === '' && !$(this).hasClass('is_adjusted') ){
$(this).addClass('is_adjusted');
let date = new Date();
let adjusted_date = date.toLocaleDateString().split('/').map((e)=>{ return ( String(e).length < 2 )? "0"+e : e ; }).join('-');
$(this).val( adjusted_date + 'T00:00');
}
});
}
});