質問編集履歴
3
コードを追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,7 +34,7 @@
|
|
34
34
|
|
35
35
|
```
|
36
36
|
|
37
|
-
該当箇所を含む一連のコードです。
|
37
|
+
該当箇所(cacheKey)を含む一連のコードです。
|
38
38
|
|
39
39
|
```ここに言語を入力
|
40
40
|
|
@@ -66,7 +66,7 @@
|
|
66
66
|
|
67
67
|
|
68
68
|
|
69
|
-
var cacheKey =
|
69
|
+
var cacheKey = btoa( checkDate.toString().replace( /[\u00A0-\u2666]/g, function( c ) {
|
70
70
|
|
71
71
|
return '&#' + c.charCodeAt( 0 ) + ';';
|
72
72
|
|
@@ -140,6 +140,382 @@
|
|
140
140
|
|
141
141
|
}
|
142
142
|
|
143
|
+
|
144
|
+
|
145
|
+
/**
|
146
|
+
|
147
|
+
* If caching is being requested beforeShowDay will use this method to load styles from cache if available.
|
148
|
+
|
149
|
+
*
|
150
|
+
|
151
|
+
* @version 1.10.11
|
152
|
+
|
153
|
+
* @since 1.10.11
|
154
|
+
|
155
|
+
* @param {object} date - Date to apply attributes to.
|
156
|
+
|
157
|
+
*/
|
158
|
+
|
159
|
+
WC_Bookings_DatePicker.prototype.maybe_load_from_cache = function maybe_load_from_cache( date ) {
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
var cacheKey = btoa( date.toString().replace( /[\u00A0-\u2666]/g, function( c ) {
|
164
|
+
|
165
|
+
return '&#' + c.charCodeAt( 0 ) + ';';
|
166
|
+
|
167
|
+
} ) );
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
var defaultClass = ( '1' === this.customData.default_availability ) ? 'bookable' : 'not-bookable' ;
|
172
|
+
|
173
|
+
var attributes = [ true, defaultClass, '' ];
|
174
|
+
|
175
|
+
var cachedAttributes = this.cache.attributes[ cacheKey ];
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
if ( cachedAttributes ) {
|
180
|
+
|
181
|
+
cachedAttributes = [ cachedAttributes.selectable, cachedAttributes.class.join( ' ' ), cachedAttributes.title ];
|
182
|
+
|
183
|
+
} else if ( this.bookingsData ) {
|
184
|
+
|
185
|
+
var attrs = this.getDateElementAttributes( date );
|
186
|
+
|
187
|
+
attributes = [ attrs.selectable, attrs.class.join(' '), attrs.title ];
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
return cachedAttributes || attributes;
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
/**
|
202
|
+
|
203
|
+
* Returns the default parameters.
|
204
|
+
|
205
|
+
*
|
206
|
+
|
207
|
+
* @version 1.10.11
|
208
|
+
|
209
|
+
* @since 1.10.11
|
210
|
+
|
211
|
+
*/
|
212
|
+
|
213
|
+
WC_Bookings_DatePicker.prototype.get_default_params = function get_default_params() {
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
return this.defaultParams || {};
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
/**
|
226
|
+
|
227
|
+
* Set and override the default parameters.
|
228
|
+
|
229
|
+
*
|
230
|
+
|
231
|
+
* @version 1.10.11
|
232
|
+
|
233
|
+
* @since 1.10.11
|
234
|
+
|
235
|
+
* @param {object} params - Parameters to be set or overridden.
|
236
|
+
|
237
|
+
*/
|
238
|
+
|
239
|
+
WC_Bookings_DatePicker.prototype.set_default_params = function set_default_params( params ) {
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
var _defaultParams = {
|
244
|
+
|
245
|
+
showWeek : false,
|
246
|
+
|
247
|
+
showOn : false,
|
248
|
+
|
249
|
+
numberOfMonths : 1,
|
250
|
+
|
251
|
+
showButtonPanel : false,
|
252
|
+
|
253
|
+
showOtherMonths : true,
|
254
|
+
|
255
|
+
selectOtherMonths : true,
|
256
|
+
|
257
|
+
gotoCurrent : true,
|
258
|
+
|
259
|
+
dateFormat : $.datepicker.ISO_8601,
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
if ( typeof params !== 'object' ) {
|
266
|
+
|
267
|
+
throw new Error( 'Cannot set params with typeof ' + typeof params );
|
268
|
+
|
269
|
+
return;
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
this.defaultParams = $.extend( _defaultParams, params ) || {};
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
/**
|
284
|
+
|
285
|
+
* Get the data from the server for a block of time.
|
286
|
+
|
287
|
+
*
|
288
|
+
|
289
|
+
* @since 1.10.11
|
290
|
+
|
291
|
+
* @param {string} year - Year being requested.
|
292
|
+
|
293
|
+
* @param {string} month - Month being requested.
|
294
|
+
|
295
|
+
* @returns {object} Deferred object to be resolved after the http request
|
296
|
+
|
297
|
+
*/
|
298
|
+
|
299
|
+
WC_Bookings_DatePicker.prototype.get_data = function get_data( year, month ) {
|
300
|
+
|
301
|
+
year = undefined !== year ? year : new Date().getFullYear();
|
302
|
+
|
303
|
+
month = undefined !== month ? month : new Date().getMonth() + 1;
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
/**
|
308
|
+
|
309
|
+
* Overlay styles when jQuery.block is called to block the DOM.
|
310
|
+
|
311
|
+
*/
|
312
|
+
|
313
|
+
var blockUIOverlayCSS = {
|
314
|
+
|
315
|
+
background: '#fff',
|
316
|
+
|
317
|
+
opacity: 0.6,
|
318
|
+
|
319
|
+
};
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
/**
|
324
|
+
|
325
|
+
* Get a date range based on the start date.
|
326
|
+
|
327
|
+
*
|
328
|
+
|
329
|
+
* @since 1.10.11
|
330
|
+
|
331
|
+
* @param {string} startDate - Optional start date to get the date range from.
|
332
|
+
|
333
|
+
* @returns {object} Object referencing the start date and end date for the range calculated.
|
334
|
+
|
335
|
+
*/
|
336
|
+
|
337
|
+
var get_date_range = function get_date_range( startDate ) {
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
if ( ! startDate ) {
|
342
|
+
|
343
|
+
startDate = new Date( [ year, month, '01' ].join( '/' ) );
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
var range = this.get_number_of_days_in_month( month );
|
350
|
+
|
351
|
+
return this.get_padded_date_range( startDate, range );
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
}.bind(this);
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
var deferred = $.Deferred();
|
360
|
+
|
361
|
+
var dateRange = get_date_range();
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
startDateString = dateRange.startDate.toString()
|
366
|
+
|
367
|
+
startDateString = btoa( startDateString.replace( /[\u00A0-\u2666]/g, function( c ) {
|
368
|
+
|
369
|
+
return '&#' + c.charCodeAt( 0 ) + ';';
|
370
|
+
|
371
|
+
} ) );
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
endDateString = dateRange.endDate.toString();
|
376
|
+
|
377
|
+
endDateString = btoa( endDateString.replace( /[\u00A0-\u2666]/g, function( c ) {
|
378
|
+
|
379
|
+
return '&#' + c.charCodeAt( 0 ) + ';';
|
380
|
+
|
381
|
+
} ) );
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
var cacheKey = startDateString + endDateString;
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
if ( this.opts.cache && this.cache.data[ cacheKey ] ) {
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
deferred.resolveWith( this, [ dateRange, this.cache.data[ cacheKey ] ] );
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
} else {
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
var params = {
|
402
|
+
|
403
|
+
'product_id': this.get_custom_data( 'product_id' ),
|
404
|
+
|
405
|
+
'wc-ajax' : 'wc_bookings_find_booked_day_blocks',
|
406
|
+
|
407
|
+
'security' : this.$form.data( 'nonce' ),
|
408
|
+
|
409
|
+
}
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
this.$picker.block( {
|
414
|
+
|
415
|
+
message: null,
|
416
|
+
|
417
|
+
overlayCSS: blockUIOverlayCSS,
|
418
|
+
|
419
|
+
} );
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
params.min_date = dateRange.startDate;
|
424
|
+
|
425
|
+
params.max_date = dateRange.endDate;
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
$.ajax({
|
430
|
+
|
431
|
+
context: this,
|
432
|
+
|
433
|
+
url: wc_bookings_date_picker_args.ajax_url,
|
434
|
+
|
435
|
+
method: 'GET',
|
436
|
+
|
437
|
+
data: params,
|
438
|
+
|
439
|
+
})
|
440
|
+
|
441
|
+
.done( function( data ) {
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
this.bookingsData = this.bookingsDate || {};
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
$.each( data, function( key, val ) {
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
if ( $.isArray( val ) || typeof val === 'object' ) {
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
var emptyType = ( $.isArray( val ) ) ? [] : {};
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
this.bookingsData[ key ] = this.bookingsData[ key ] || emptyType;
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
$.extend( this.bookingsData[ key ], val );
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
} else {
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
this.bookingsData[ key ] = val;
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
}
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
}.bind( this ) );
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
this.cache.data[ cacheKey ] = data;
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
if ( ! year && ! month && this.bookingsData.min_date ) {
|
490
|
+
|
491
|
+
dateRange = get_date_range( this.get_default_date( this.bookingsData.min_date ) );
|
492
|
+
|
493
|
+
}
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
deferred.resolveWith( this, [ dateRange, data ] );
|
498
|
+
|
499
|
+
|
500
|
+
|
501
|
+
this.$picker.unblock();
|
502
|
+
|
503
|
+
|
504
|
+
|
505
|
+
}.bind( this ) );
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
}
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
return deferred;
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
}
|
518
|
+
|
143
519
|
```
|
144
520
|
|
145
521
|
|
2
タグの追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
1
コードを追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,4 +34,114 @@
|
|
34
34
|
|
35
35
|
```
|
36
36
|
|
37
|
+
該当箇所を含む一連のコードです。
|
38
|
+
|
39
|
+
```ここに言語を入力
|
40
|
+
|
41
|
+
/**
|
42
|
+
|
43
|
+
* Applys attributes to the dates on the datepicker. This is necessary since we cant
|
44
|
+
|
45
|
+
* defer beforeShowDay until after our data is loaded.
|
46
|
+
|
47
|
+
*
|
48
|
+
|
49
|
+
* @version 1.10.11
|
50
|
+
|
51
|
+
* @since 1.10.11
|
52
|
+
|
53
|
+
* @param {object} dateRange - Date range for attributes to be applied to.
|
54
|
+
|
55
|
+
*/
|
56
|
+
|
57
|
+
WC_Bookings_DatePicker.prototype.applyStylesToDates = function applyStylesToDates( dateRange ) {
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
var checkDate = dateRange.startDate;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
while ( checkDate < dateRange.endDate ) {
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
var cacheKey = window.btoa( checkDate.toString().replace( /[\u00A0-\u2666]/g, function( c ) {
|
70
|
+
|
71
|
+
return '&#' + c.charCodeAt( 0 ) + ';';
|
72
|
+
|
73
|
+
} ) );
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
if ( ! this.cache.attributes[ cacheKey ] ) {
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
var attributes = this.getDateElementAttributes( checkDate );
|
82
|
+
|
83
|
+
var selector = $( 'td[data-month="' + checkDate.getMonth() + '"] a', this.$picker ).filter(function() {
|
84
|
+
|
85
|
+
return $(this).text() == checkDate.getDate();
|
86
|
+
|
87
|
+
}).parent();
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
if ( ! attributes.selectable ) {
|
92
|
+
|
93
|
+
attributes.class.push( 'ui-datepicker-unselectable' );
|
94
|
+
|
95
|
+
attributes.class.push( 'ui-state-disabled' );
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
if ( checkDate.setHours( 0, 0, 0, 0 ) === new Date().setHours( 0, 0, 0, 0 ) ) {
|
102
|
+
|
103
|
+
attributes.class.push( 'ui-datepicker-today' );
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
$.each( attributes, function( key, val ) {
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
selector.attr( key, ( $.isArray( val ) ) ? val.join( ' ' ) : val );
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
});
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
if ( this.opts.cache ) {
|
122
|
+
|
123
|
+
this.cache.attributes[ cacheKey ] = attributes;
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
checkDate.setDate( checkDate.getDate() + 1 );
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
```
|
144
|
+
|
145
|
+
|
146
|
+
|
37
147
|
どうもChrome自体の問題のようなのですが(Firefoxの開発ツールではエラーは表示されません)エラー内容で検索しても目ぼしい情報が得られないためお知恵をお借りしたいです。
|