質問するログイン新規登録

質問編集履歴

3

コードを追加しました

2018/09/24 04:56

投稿

MyQuestioner
MyQuestioner

スコア57

title CHANGED
File without changes
body CHANGED
@@ -16,7 +16,7 @@
16
16
  return '&#' + c.charCodeAt( 0 ) + ';';
17
17
 
18
18
  ```
19
- 該当箇所を含む一連のコードです。
19
+ 該当箇所(cacheKey)を含む一連のコードです。
20
20
  ```ここに言語を入力
21
21
  /**
22
22
  * Applys attributes to the dates on the datepicker. This is necessary since we cant
@@ -32,7 +32,7 @@
32
32
 
33
33
  while ( checkDate < dateRange.endDate ) {
34
34
 
35
- var cacheKey = window.btoa( checkDate.toString().replace( /[\u00A0-\u2666]/g, function( c ) {
35
+ var cacheKey = btoa( checkDate.toString().replace( /[\u00A0-\u2666]/g, function( c ) {
36
36
  return '&#' + c.charCodeAt( 0 ) + ';';
37
37
  } ) );
38
38
 
@@ -69,6 +69,194 @@
69
69
  }
70
70
 
71
71
  }
72
+
73
+ /**
74
+ * If caching is being requested beforeShowDay will use this method to load styles from cache if available.
75
+ *
76
+ * @version 1.10.11
77
+ * @since 1.10.11
78
+ * @param {object} date - Date to apply attributes to.
79
+ */
80
+ WC_Bookings_DatePicker.prototype.maybe_load_from_cache = function maybe_load_from_cache( date ) {
81
+
82
+ var cacheKey = btoa( date.toString().replace( /[\u00A0-\u2666]/g, function( c ) {
83
+ return '&#' + c.charCodeAt( 0 ) + ';';
84
+ } ) );
85
+
86
+ var defaultClass = ( '1' === this.customData.default_availability ) ? 'bookable' : 'not-bookable' ;
87
+ var attributes = [ true, defaultClass, '' ];
88
+ var cachedAttributes = this.cache.attributes[ cacheKey ];
89
+
90
+ if ( cachedAttributes ) {
91
+ cachedAttributes = [ cachedAttributes.selectable, cachedAttributes.class.join( ' ' ), cachedAttributes.title ];
92
+ } else if ( this.bookingsData ) {
93
+ var attrs = this.getDateElementAttributes( date );
94
+ attributes = [ attrs.selectable, attrs.class.join(' '), attrs.title ];
95
+ }
96
+
97
+ return cachedAttributes || attributes;
98
+
99
+ }
100
+
101
+ /**
102
+ * Returns the default parameters.
103
+ *
104
+ * @version 1.10.11
105
+ * @since 1.10.11
106
+ */
107
+ WC_Bookings_DatePicker.prototype.get_default_params = function get_default_params() {
108
+
109
+ return this.defaultParams || {};
110
+
111
+ }
112
+
113
+ /**
114
+ * Set and override the default parameters.
115
+ *
116
+ * @version 1.10.11
117
+ * @since 1.10.11
118
+ * @param {object} params - Parameters to be set or overridden.
119
+ */
120
+ WC_Bookings_DatePicker.prototype.set_default_params = function set_default_params( params ) {
121
+
122
+ var _defaultParams = {
123
+ showWeek : false,
124
+ showOn : false,
125
+ numberOfMonths : 1,
126
+ showButtonPanel : false,
127
+ showOtherMonths : true,
128
+ selectOtherMonths : true,
129
+ gotoCurrent : true,
130
+ dateFormat : $.datepicker.ISO_8601,
131
+ }
132
+
133
+ if ( typeof params !== 'object' ) {
134
+ throw new Error( 'Cannot set params with typeof ' + typeof params );
135
+ return;
136
+ }
137
+
138
+ this.defaultParams = $.extend( _defaultParams, params ) || {};
139
+
140
+ }
141
+
142
+ /**
143
+ * Get the data from the server for a block of time.
144
+ *
145
+ * @since 1.10.11
146
+ * @param {string} year - Year being requested.
147
+ * @param {string} month - Month being requested.
148
+ * @returns {object} Deferred object to be resolved after the http request
149
+ */
150
+ WC_Bookings_DatePicker.prototype.get_data = function get_data( year, month ) {
151
+ year = undefined !== year ? year : new Date().getFullYear();
152
+ month = undefined !== month ? month : new Date().getMonth() + 1;
153
+
154
+ /**
155
+ * Overlay styles when jQuery.block is called to block the DOM.
156
+ */
157
+ var blockUIOverlayCSS = {
158
+ background: '#fff',
159
+ opacity: 0.6,
160
+ };
161
+
162
+ /**
163
+ * Get a date range based on the start date.
164
+ *
165
+ * @since 1.10.11
166
+ * @param {string} startDate - Optional start date to get the date range from.
167
+ * @returns {object} Object referencing the start date and end date for the range calculated.
168
+ */
169
+ var get_date_range = function get_date_range( startDate ) {
170
+
171
+ if ( ! startDate ) {
172
+ startDate = new Date( [ year, month, '01' ].join( '/' ) );
173
+ }
174
+
175
+ var range = this.get_number_of_days_in_month( month );
176
+ return this.get_padded_date_range( startDate, range );
177
+
178
+ }.bind(this);
179
+
180
+ var deferred = $.Deferred();
181
+ var dateRange = get_date_range();
182
+
183
+ startDateString = dateRange.startDate.toString()
184
+ startDateString = btoa( startDateString.replace( /[\u00A0-\u2666]/g, function( c ) {
185
+ return '&#' + c.charCodeAt( 0 ) + ';';
186
+ } ) );
187
+
188
+ endDateString = dateRange.endDate.toString();
189
+ endDateString = btoa( endDateString.replace( /[\u00A0-\u2666]/g, function( c ) {
190
+ return '&#' + c.charCodeAt( 0 ) + ';';
191
+ } ) );
192
+
193
+ var cacheKey = startDateString + endDateString;
194
+
195
+ if ( this.opts.cache && this.cache.data[ cacheKey ] ) {
196
+
197
+ deferred.resolveWith( this, [ dateRange, this.cache.data[ cacheKey ] ] );
198
+
199
+ } else {
200
+
201
+ var params = {
202
+ 'product_id': this.get_custom_data( 'product_id' ),
203
+ 'wc-ajax' : 'wc_bookings_find_booked_day_blocks',
204
+ 'security' : this.$form.data( 'nonce' ),
205
+ }
206
+
207
+ this.$picker.block( {
208
+ message: null,
209
+ overlayCSS: blockUIOverlayCSS,
210
+ } );
211
+
212
+ params.min_date = dateRange.startDate;
213
+ params.max_date = dateRange.endDate;
214
+
215
+ $.ajax({
216
+ context: this,
217
+ url: wc_bookings_date_picker_args.ajax_url,
218
+ method: 'GET',
219
+ data: params,
220
+ })
221
+ .done( function( data ) {
222
+
223
+ this.bookingsData = this.bookingsDate || {};
224
+
225
+ $.each( data, function( key, val ) {
226
+
227
+ if ( $.isArray( val ) || typeof val === 'object' ) {
228
+
229
+ var emptyType = ( $.isArray( val ) ) ? [] : {};
230
+
231
+ this.bookingsData[ key ] = this.bookingsData[ key ] || emptyType;
232
+
233
+ $.extend( this.bookingsData[ key ], val );
234
+
235
+ } else {
236
+
237
+ this.bookingsData[ key ] = val;
238
+
239
+ }
240
+
241
+ }.bind( this ) );
242
+
243
+ this.cache.data[ cacheKey ] = data;
244
+
245
+ if ( ! year && ! month && this.bookingsData.min_date ) {
246
+ dateRange = get_date_range( this.get_default_date( this.bookingsData.min_date ) );
247
+ }
248
+
249
+ deferred.resolveWith( this, [ dateRange, data ] );
250
+
251
+ this.$picker.unblock();
252
+
253
+ }.bind( this ) );
254
+
255
+ }
256
+
257
+ return deferred;
258
+
259
+ }
72
260
  ```
73
261
 
74
262
  どうもChrome自体の問題のようなのですが(Firefoxの開発ツールではエラーは表示されません)エラー内容で検索しても目ぼしい情報が得られないためお知恵をお借りしたいです。

2

タグの追加

2018/09/24 04:56

投稿

MyQuestioner
MyQuestioner

スコア57

title CHANGED
File without changes
body CHANGED
File without changes

1

コードを追加しました

2018/09/24 03:27

投稿

MyQuestioner
MyQuestioner

スコア57

title CHANGED
File without changes
body CHANGED
@@ -16,4 +16,59 @@
16
16
  return '&#' + c.charCodeAt( 0 ) + ';';
17
17
 
18
18
  ```
19
+ 該当箇所を含む一連のコードです。
20
+ ```ここに言語を入力
21
+ /**
22
+ * Applys attributes to the dates on the datepicker. This is necessary since we cant
23
+ * defer beforeShowDay until after our data is loaded.
24
+ *
25
+ * @version 1.10.11
26
+ * @since 1.10.11
27
+ * @param {object} dateRange - Date range for attributes to be applied to.
28
+ */
29
+ WC_Bookings_DatePicker.prototype.applyStylesToDates = function applyStylesToDates( dateRange ) {
30
+
31
+ var checkDate = dateRange.startDate;
32
+
33
+ while ( checkDate < dateRange.endDate ) {
34
+
35
+ var cacheKey = window.btoa( checkDate.toString().replace( /[\u00A0-\u2666]/g, function( c ) {
36
+ return '&#' + c.charCodeAt( 0 ) + ';';
37
+ } ) );
38
+
39
+ if ( ! this.cache.attributes[ cacheKey ] ) {
40
+
41
+ var attributes = this.getDateElementAttributes( checkDate );
42
+ var selector = $( 'td[data-month="' + checkDate.getMonth() + '"] a', this.$picker ).filter(function() {
43
+ return $(this).text() == checkDate.getDate();
44
+ }).parent();
45
+
46
+ if ( ! attributes.selectable ) {
47
+ attributes.class.push( 'ui-datepicker-unselectable' );
48
+ attributes.class.push( 'ui-state-disabled' );
49
+ }
50
+
51
+ if ( checkDate.setHours( 0, 0, 0, 0 ) === new Date().setHours( 0, 0, 0, 0 ) ) {
52
+ attributes.class.push( 'ui-datepicker-today' );
53
+ }
54
+
55
+ $.each( attributes, function( key, val ) {
56
+
57
+ selector.attr( key, ( $.isArray( val ) ) ? val.join( ' ' ) : val );
58
+
59
+ });
60
+
61
+ if ( this.opts.cache ) {
62
+ this.cache.attributes[ cacheKey ] = attributes;
63
+ }
64
+
65
+ }
66
+
67
+ checkDate.setDate( checkDate.getDate() + 1 );
68
+
69
+ }
70
+
71
+ }
72
+ ```
73
+
19
74
  どうもChrome自体の問題のようなのですが(Firefoxの開発ツールではエラーは表示されません)エラー内容で検索しても目ぼしい情報が得られないためお知恵をお借りしたいです。