PluginProbe
Stream – Activity Log & Audit Trail / 3.6.1
Stream – Activity Log & Audit Trail v3.6.1
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
← All changes | ui/js/admin.js +482 -421 3.1 → 3.6.1 View file →
@@ -1,508 +1,569 @@
1 -/* globals wp_stream, ajaxurl */
2 -jQuery( function( $ ) {
1 +/* globals wp_stream, ajaxurl, jQuery */
2 +jQuery(
3 + function( $ ) {
4 + // Shorter timeago strings for English locale
5 + if ( 'en' === wp_stream.locale && 'undefined' !== typeof $.timeago ) {
6 + $.timeago.settings.strings.seconds = 'seconds';
7 + $.timeago.settings.strings.minute = 'a minute';
8 + $.timeago.settings.strings.hour = 'an hour';
9 + $.timeago.settings.strings.hours = '%d hours';
10 + $.timeago.settings.strings.month = 'a month';
11 + $.timeago.settings.strings.year = 'a year';
12 + }
3 13
4 - // Shorter timeago strings for English locale
5 - if ( 'en' === wp_stream.locale && 'undefined' !== typeof $.timeago ) {
6 - $.timeago.settings.strings.seconds = 'seconds';
7 - $.timeago.settings.strings.minute = 'a minute';
8 - $.timeago.settings.strings.hour = 'an hour';
9 - $.timeago.settings.strings.hours = '%d hours';
10 - $.timeago.settings.strings.month = 'a month';
11 - $.timeago.settings.strings.year = 'a year';
12 - }
14 + $( 'li.toplevel_page_wp_stream ul li.wp-first-item.current' ).parent().parent().find( '.update-plugins' ).remove();
13 15
14 - $( 'li.toplevel_page_wp_stream ul li.wp-first-item.current' ).parent().parent().find( '.update-plugins' ).remove();
16 + $( '.toplevel_page_wp_stream :input.chosen-select' ).each(
17 + function( i, el ) {
18 + var args = {},
19 + templateResult = function( record ) {
20 + var $result = $( '<span>' ),
21 + $elem = $( record.element ),
22 + icon = '';
15 23
16 - $( '.toplevel_page_wp_stream :input.chosen-select' ).each( function( i, el ) {
17 - var args = {},
18 - templateResult = function( record ) {
19 - var $result = $( '<span>' ),
20 - $elem = $( record.element ),
21 - icon = '';
24 + if ( '- ' === record.text.substring( 0, 2 ) ) {
25 + record.text = record.text.substring( 2 );
26 + }
22 27
23 - if ( '- ' === record.text.substring( 0, 2 ) ) {
24 - record.text = record.text.substring( 2 );
25 - }
28 + if ( 'undefined' !== typeof record.id && 'string' === typeof record.id ) {
29 + if ( record.id.indexOf( 'group-' ) === 0 ) {
30 + $result.addClass( 'parent' );
31 + } else if ( $elem.hasClass( 'level-2' ) ) {
32 + $result.addClass( 'child' );
33 + }
34 + }
26 35
27 - if ( 'undefined' !== typeof record.id ) {
28 - if ( record.id.indexOf( 'group-' ) === 0 ) {
29 - $result.addClass( 'parent' );
30 - } else if ( $elem.hasClass( 'level-2' ) ) {
31 - $result.addClass( 'child' );
32 - }
33 - }
36 + if ( undefined !== record.icon ) {
37 + icon = record.icon;
38 + } else if ( undefined !== $elem && '' !== $elem.data( 'icon' ) ) {
39 + icon = $elem.data( 'icon' );
40 + }
34 41
35 - if ( undefined !== record.icon ) {
36 - icon = record.icon;
37 - } else if ( undefined !== $elem && '' !== $elem.data( 'icon' ) ) {
38 - icon = $elem.data( 'icon' );
39 - }
42 + if ( icon ) {
43 + $result.html( '<img src="' + icon + '" class="wp-stream-select2-icon">' );
44 + }
45 + $result.append( record.text );
40 46
41 - if ( icon ) {
42 - $result.html( '<img src="' + icon + '" class="wp-stream-select2-icon">' );
43 - }
44 - $result.append( record.text );
45 -
46 - return $result;
47 - },
48 - templateSelection = function( record ) {
49 - if ( '- ' === record.text.substring( 0, 2 ) ) {
50 - record.text = record.text.substring( 2 );
51 - }
52 - return record.text;
53 - };
54 -
55 - if ( $( el ).find( 'option' ).not( ':selected' ).not( ':empty' ).length > 0 ) {
56 - args = {
57 - minimumResultsForSearch: 10,
58 - templateResult: templateResult,
59 - templateSelection: templateSelection,
60 - allowClear: true,
61 - width: '165px'
62 - };
63 - } else {
64 - args = {
65 - minimumInputLength: 3,
66 - allowClear: true,
67 - width: '165px',
68 - ajax: {
69 - url: ajaxurl,
70 - dataType: 'json',
71 - quietMillis: 100,
72 - data: function( term ) {
73 - return {
74 - action: 'wp_stream_filters',
75 - nonce: $( '#stream_filters_user_search_nonce' ).val(),
76 - filter: $( el ).attr( 'name' ),
77 - q: term.term
78 - };
47 + return $result;
79 48 },
80 - processResults: function( data ) {
81 - var results = [];
82 - $.each( data, function( index, item ){
83 - results.push({
84 - id: item.id,
85 - text: item.label
86 - });
87 - });
88 - return {
89 - results: results
90 - };
91 - }
92 - },
93 - templateResult: templateResult,
94 - templateSelection: templateSelection
95 - };
96 - }
49 + templateSelection = function( record ) {
50 + if ( '- ' === record.text.substring( 0, 2 ) ) {
51 + record.text = record.text.substring( 2 );
52 + }
53 + return record.text;
54 + };
97 55
98 - $( el ).select2( args );
99 - });
56 + if ( $( el ).find( 'option' ).not( ':selected' ).not( ':empty' ).length > 0 ) {
57 + args = {
58 + minimumResultsForSearch: 10,
59 + templateResult: templateResult,
60 + templateSelection: templateSelection,
61 + allowClear: true,
62 + width: '165px',
63 + };
64 + } else {
65 + args = {
66 + minimumInputLength: 3,
67 + allowClear: true,
68 + width: '165px',
69 + ajax: {
70 + url: ajaxurl,
71 + delay: 500,
72 + dataType: 'json',
73 + quietMillis: 100,
74 + data: function( term ) {
75 + return {
76 + action: 'wp_stream_filters',
77 + nonce: $( '#stream_filters_user_search_nonce' ).val(),
78 + filter: $( el ).attr( 'name' ),
79 + q: term.term,
80 + };
81 + },
82 + processResults: function( data ) {
83 + var results = [];
84 + $.each(
85 + data, function( index, item ) {
86 + results.push(
87 + {
88 + id: item.id,
89 + text: item.label,
90 + }
91 + );
92 + }
93 + );
94 + return {
95 + results: results,
96 + };
97 + },
98 + },
99 + templateResult: templateResult,
100 + templateSelection: templateSelection,
101 + };
102 + }
100 103
101 - var $queryVars = $.streamGetQueryVars();
102 - var $contextInput = $( '.toplevel_page_wp_stream select.chosen-select[name="context"]' );
104 + $( el ).select2( args );
105 + }
106 + );
103 107
104 - if ( ( 'undefined' === typeof $queryVars.context || '' === $queryVars.context ) && 'undefined' !== typeof $queryVars.connector ) {
105 - $contextInput.val( 'group-' + $queryVars.connector );
106 - $contextInput.trigger( 'change' );
107 - }
108 + var $queryVars = $.streamGetQueryVars();
109 + var $contextInput = $( '.toplevel_page_wp_stream select.chosen-select[name="context"]' );
108 110
109 - $( 'input[type=submit]', '#record-filter-form' ).click( function() {
110 - $( 'input[type=submit]', $( this ).parents( 'form' ) ).removeAttr( 'clicked' );
111 - $( this ).attr( 'clicked', 'true' );
112 - });
113 -
114 - $( '#record-filter-form' ).submit( function() {
115 - var $context = $( '.toplevel_page_wp_stream :input.chosen-select[name="context"]' ),
116 - $option = $context.find( 'option:selected' ),
117 - $connector = $context.parent().find( '.record-filter-connector' ),
118 - optionConnector = $option.data( 'group' ),
119 - optionClass = $option.prop( 'class' ),
120 - $recordAction = $( '.recordactions select' );
121 -
122 - if ( $( '#record-actions-submit' ).attr( 'clicked' ) !== 'true' ) {
123 - $recordAction.val( '' );
111 + if ( ( 'undefined' === typeof $queryVars.context || '' === $queryVars.context ) && 'undefined' !== typeof $queryVars.connector ) {
112 + $contextInput.val( 'group-' + $queryVars.connector );
113 + $contextInput.trigger( 'change' );
124 114 }
125 115
126 - $connector.val( optionConnector );
116 + $( 'input[type=submit]', '#record-filter-form' ).click(
117 + function() {
118 + $( 'input[type=submit]', $( this ).parents( 'form' ) ).removeAttr( 'clicked' );
119 + $( this ).attr( 'clicked', 'true' );
120 + }
121 + );
127 122
128 - if ( 'level-1' === optionClass ) {
129 - $option.val( '' );
130 - }
131 - });
123 + $( '#record-filter-form' ).submit(
124 + function() {
125 + var $context = $( '.toplevel_page_wp_stream :input.chosen-select[name="context"]' ),
126 + $option = $context.find( 'option:selected' ),
127 + $connector = $context.parent().find( '.record-filter-connector' ),
128 + optionConnector = $option.data( 'group' ),
129 + optionClass = $option.prop( 'class' ),
130 + $recordAction = $( '.recordactions select' );
132 131
133 - $( window ).load( function() {
134 - $( '.toplevel_page_wp_stream input[type="search"]' ).off( 'mousedown' );
135 - });
132 + if ( $( '#record-actions-submit' ).attr( 'clicked' ) !== 'true' ) {
133 + $recordAction.val( '' );
134 + }
136 135
137 - // Confirmation on some important actions
138 - $( 'body' ).on( 'click', '#wp_stream_advanced_delete_all_records, #wp_stream_network_advanced_delete_all_records', function( e ) {
139 - if ( ! window.confirm( wp_stream.i18n.confirm_purge ) ) {
140 - e.preventDefault();
141 - }
142 - });
136 + $connector.val( optionConnector );
143 137
144 - $( 'body' ).on( 'click', '#wp_stream_advanced_reset_site_settings, #wp_stream_network_advanced_reset_site_settings', function( e ) {
145 - if ( ! window.confirm( wp_stream.i18n.confirm_defaults ) ) {
146 - e.preventDefault();
147 - }
148 - });
138 + if ( 'level-1' === optionClass ) {
139 + $option.val( '' );
140 + }
141 + }
142 + );
149 143
150 - $( 'body' ).on( 'click', '#wp_stream_uninstall', function( e ) {
151 - if ( ! window.confirm( wp_stream.i18n.confirm_uninstall ) ) {
152 - e.preventDefault();
153 - }
154 - });
144 + $( window ).on(
145 + 'load',
146 + function() {
147 + $( '.toplevel_page_wp_stream input[type="search"]' ).off( 'mousedown' );
148 + }
149 + );
155 150
156 - // Admin page tabs
157 - var $tabs = $( '.wp_stream_screen .nav-tab-wrapper' ),
158 - $panels = $( '.wp_stream_screen .nav-tab-content table.form-table' ),
159 - $activeTab = $tabs.find( '.nav-tab-active' ),
160 - defaultIndex = $activeTab.length > 0 ? $tabs.find( 'a' ).index( $activeTab ) : 0,
161 - hashIndex = window.location.hash.match( /^#(\d+)$/ ),
162 - currentHash = ( null !== hashIndex ? hashIndex[ 1 ] : defaultIndex ),
163 - syncFormAction = function( index ) {
164 - var $optionsForm = $( 'input[name="option_page"][value^="wp_stream"]' ).closest( 'form' );
165 - if ( $optionsForm.length === 0 ) {
166 - return;
151 + // Confirmation on some important actions
152 + $( 'body' ).on(
153 + 'click', '#wp_stream_advanced_delete_all_records, #wp_stream_network_advanced_delete_all_records', function( e ) {
154 + if ( ! window.confirm( wp_stream.i18n.confirm_purge ) ) {
155 + e.preventDefault();
156 + }
167 157 }
168 - var currentAction = $optionsForm.attr( 'action' );
158 + );
169 159
170 - $optionsForm.prop( 'action', currentAction.replace( /(^[^#]*).*$/, '$1#' + index ) );
171 - };
160 + $( 'body' ).on(
161 + 'click', '#wp_stream_advanced_reset_site_settings, #wp_stream_network_advanced_reset_site_settings', function( e ) {
162 + if ( ! window.confirm( wp_stream.i18n.confirm_defaults ) ) {
163 + e.preventDefault();
164 + }
165 + }
166 + );
172 167
173 - $tabs.on( 'click', 'a', function() {
174 - var index = $tabs.find( 'a' ).index( $( this ) ),
175 - hashIndex = window.location.hash.match( /^#(\d+)$/ );
168 + $( 'body' ).on(
169 + 'click', '#wp_stream_uninstall', function( e ) {
170 + if ( ! window.confirm( wp_stream.i18n.confirm_uninstall ) ) {
171 + e.preventDefault();
172 + }
173 + }
174 + );
176 175
177 - $panels.hide().eq( index ).show();
178 - $tabs
179 - .find( 'a' )
180 - .removeClass( 'nav-tab-active' )
181 - .filter( $( this ) )
182 - .addClass( 'nav-tab-active' );
176 + // Admin page tabs
177 + var $tabs = $( '.wp_stream_screen .nav-tab-wrapper' ),
178 + $panels = $( '.wp_stream_screen .nav-tab-content table.form-table' ),
179 + $activeTab = $tabs.find( '.nav-tab-active' ),
180 + defaultIndex = $activeTab.length > 0 ? $tabs.find( 'a' ).index( $activeTab ) : 0,
181 + hashIndexStart = window.location.hash.match( /^#(\d+)$/ ),
182 + currentHash = ( null !== hashIndexStart ? hashIndexStart[ 1 ] : defaultIndex ),
183 + syncFormAction = function( index ) {
184 + var $optionsForm = $( 'input[name="option_page"][value^="wp_stream"]' ).closest( 'form' );
185 + if ( $optionsForm.length === 0 ) {
186 + return;
187 + }
188 + var currentAction = $optionsForm.attr( 'action' );
183 189
184 - if ( '' === window.location.hash || null !== hashIndex ) {
185 - window.location.hash = index;
186 - }
190 + $optionsForm.prop( 'action', currentAction.replace( /(^[^#]*).*$/, '$1#' + index ) );
191 + };
187 192
188 - syncFormAction( index );
193 + $tabs.on(
194 + 'click', 'a', function() {
195 + var index = $tabs.find( 'a' ).index( $( this ) ),
196 + hashIndex = window.location.hash.match( /^#(\d+)$/ );
189 197
190 - return false;
191 - });
198 + $panels.hide().eq( index ).show();
199 + $tabs
200 + .find( 'a' )
201 + .removeClass( 'nav-tab-active' )
202 + .filter( $( this ) )
203 + .addClass( 'nav-tab-active' );
192 204
193 - $tabs.children().eq( currentHash ).trigger( 'click' );
205 + if ( '' === window.location.hash || null !== hashIndex ) {
206 + window.location.hash = index;
207 + }
194 208
195 - // Live Updates screen option
196 - $( document ).ready( function() {
209 + syncFormAction( index );
197 210
198 - // Enable Live Updates checkbox ajax
199 - $( '#enable_live_update' ).click( function() {
200 - var nonce = $( '#stream_live_update_nonce' ).val(),
201 - user = $( '#enable_live_update_user' ).val(),
202 - checked = 'unchecked',
203 - heartbeat = 'true';
204 -
205 - if ( $( '#enable_live_update' ).is( ':checked' ) ) {
206 - checked = 'checked';
211 + return false;
207 212 }
213 + );
208 214
209 - heartbeat = $( '#enable_live_update' ).data( 'heartbeat' );
215 + $tabs.children().eq( currentHash ).trigger( 'click' );
210 216
211 - $.ajax({
212 - type: 'POST',
213 - url: ajaxurl,
214 - data: {
215 - action: 'stream_enable_live_update',
216 - nonce: nonce,
217 - user: user,
218 - checked: checked,
219 - heartbeat: heartbeat
220 - },
221 - dataType: 'json',
222 - beforeSend: function() {
223 - $( '.stream-live-update-checkbox .spinner' ).show().css( { 'display': 'inline-block' } );
224 - },
225 - success: function( response ) {
226 - $( '.stream-live-update-checkbox .spinner' ).hide();
217 + // Live Updates screen option
218 + $( document ).ready(
219 + function() {
220 + // Enable Live Updates checkbox ajax
221 + $( '#enable_live_update' ).click(
222 + function() {
223 + var nonce = $( '#stream_live_update_nonce' ).val(),
224 + user = $( '#enable_live_update_user' ).val(),
225 + checked = 'unchecked',
226 + heartbeat = 'true';
227 227
228 - if ( false === response.success ) {
229 - $( '#enable_live_update' ).prop( 'checked', false );
230 -
231 - if ( response.data ) {
232 - window.alert( response.data );
228 + if ( $( '#enable_live_update' ).is( ':checked' ) ) {
229 + checked = 'checked';
233 230 }
234 - }
235 - }
236 - });
237 - });
238 231
239 - function toggle_filter_submit() {
240 - var all_hidden = true;
232 + heartbeat = $( '#enable_live_update' ).data( 'heartbeat' );
241 233
242 - // If all filters are hidden, hide the button
243 - if ( $( 'div.metabox-prefs [name="date-hide"]' ).is( ':checked' ) ) {
244 - all_hidden = false;
245 - }
234 + $.ajax(
235 + {
236 + type: 'POST',
237 + url: ajaxurl,
238 + data: {
239 + action: 'stream_enable_live_update',
240 + nonce: nonce,
241 + user: user,
242 + checked: checked,
243 + heartbeat: heartbeat,
244 + },
245 + dataType: 'json',
246 + beforeSend: function() {
247 + $( '.stream-live-update-checkbox .spinner' ).show().css( { display: 'inline-block' } );
248 + },
249 + success: function( response ) {
250 + $( '.stream-live-update-checkbox .spinner' ).hide();
246 251
247 - var divs = $( 'div.alignleft.actions div.select2-container' );
252 + if ( false === response.success ) {
253 + $( '#enable_live_update' ).prop( 'checked', false );
248 254
249 - divs.each( function() {
250 - if ( ! $( this ).is( ':hidden' ) ) {
251 - all_hidden = false;
252 - return false;
253 - }
254 - });
255 + if ( response.data ) {
256 + window.alert( response.data );
257 + }
258 + }
259 + },
260 + }
261 + );
262 + }
263 + );
255 264
256 - if ( all_hidden ) {
257 - $( 'input#record-query-submit' ).hide();
258 - $( 'span.filter_info' ).show();
259 - } else {
260 - $( 'input#record-query-submit' ).show();
261 - $( 'span.filter_info' ).hide();
262 - }
263 - }
265 + function toggle_filter_submit() {
266 + var all_hidden = true;
264 267
265 - if ( $( 'div.metabox-prefs [name="date-hide"]' ).is( ':checked' ) ) {
266 - $( 'div.date-interval' ).show();
267 - } else {
268 - $( 'div.date-interval' ).hide();
269 - }
268 + // If all filters are hidden, hide the button
269 + if ( $( 'div.metabox-prefs [name="date-hide"]' ).is( ':checked' ) ) {
270 + all_hidden = false;
271 + }
270 272
271 - $( 'div.actions select.chosen-select' ).each( function() {
272 - var name = $( this ).prop( 'name' );
273 + var divs = $( 'div.alignleft.actions div.select2-container' );
273 274
274 - if ( $( 'div.metabox-prefs [name="' + name + '-hide"]' ).is( ':checked' ) ) {
275 - $( this ).prev( '.select2-container' ).show();
276 - } else {
277 - $( this ).prev( '.select2-container' ).hide();
278 - }
279 - });
275 + divs.each(
276 + function() {
277 + if ( ! $( this ).is( ':hidden' ) ) {
278 + all_hidden = false;
279 + return false;
280 + }
281 + }
282 + );
280 283
281 - toggle_filter_submit();
284 + if ( all_hidden ) {
285 + $( 'input#record-query-submit' ).hide();
286 + $( 'span.filter_info' ).show();
287 + } else {
288 + $( 'input#record-query-submit' ).show();
289 + $( 'span.filter_info' ).hide();
290 + }
291 + }
282 292
283 - $( 'div.metabox-prefs [type="checkbox"]' ).click( function() {
284 - var id = $( this ).prop( 'id' );
285 -
286 - if ( 'date-hide' === id ) {
287 - if ( $( this ).is( ':checked' ) ) {
293 + if ( $( 'div.metabox-prefs [name="date-hide"]' ).is( ':checked' ) ) {
288 294 $( 'div.date-interval' ).show();
289 295 } else {
290 296 $( 'div.date-interval' ).hide();
291 297 }
292 - } else {
293 - id = id.replace( '-hide', '' );
294 298
295 - if ( $( this ).is( ':checked' ) ) {
296 - $( '[name="' + id + '"]' ).prev( '.select2-container' ).show();
297 - } else {
298 - $( '[name="' + id + '"]' ).prev( '.select2-container' ).hide();
299 - }
300 - }
299 + $( 'div.actions select.chosen-select' ).each(
300 + function() {
301 + var name = $( this ).prop( 'name' );
301 302
302 - toggle_filter_submit();
303 - });
303 + if ( $( 'div.metabox-prefs [name="' + name + '-hide"]' ).is( ':checked' ) ) {
304 + $( this ).prev( '.select2-container' ).show();
305 + } else {
306 + $( this ).prev( '.select2-container' ).hide();
307 + }
308 + }
309 + );
304 310
305 - $( '#ui-datepicker-div' ).addClass( 'stream-datepicker' );
306 - });
311 + toggle_filter_submit();
307 312
308 - // Relative time
309 - $( 'table.wp-list-table' ).on( 'updated', function() {
310 - var timeObjects = $( this ).find( 'time.relative-time' );
311 - timeObjects.each( function( i, el ) {
312 - var timeEl = $( el );
313 - timeEl.removeClass( 'relative-time' );
314 - $( '<strong><time datetime="' + timeEl.attr( 'datetime' ) + '" class="timeago"/></time></strong><br/>' )
315 - .prependTo( timeEl.parent().parent() )
316 - .find( 'time.timeago' )
317 - .timeago();
318 - });
319 - }).trigger( 'updated' );
313 + $( 'div.metabox-prefs [type="checkbox"]' ).click(
314 + function() {
315 + var id = $( this ).prop( 'id' );
320 316
321 - var intervals = {
322 - init: function( $wrapper ) {
323 - this.wrapper = $wrapper;
324 - this.save_interval( this.wrapper.find( '.button-primary' ), this.wrapper );
317 + if ( 'date-hide' === id ) {
318 + if ( $( this ).is( ':checked' ) ) {
319 + $( 'div.date-interval' ).show();
320 + } else {
321 + $( 'div.date-interval' ).hide();
322 + }
323 + } else {
324 + id = id.replace( '-hide', '' );
325 325
326 - this.$ = this.wrapper.each( function( i, val ) {
327 - var container = $( val ),
328 - dateinputs = container.find( '.date-inputs' ),
329 - from = container.find( '.field-from' ),
330 - to = container.find( '.field-to' ),
331 - to_remove = to.prev( '.date-remove' ),
332 - from_remove = from.prev( '.date-remove' ),
333 - predefined = container.children( '.field-predefined' ),
334 - datepickers = $( '' ).add( to ).add( from );
326 + if ( $( this ).is( ':checked' ) ) {
327 + $( '[name="' + id + '"]' ).prev( '.select2-container' ).show();
328 + } else {
329 + $( '[name="' + id + '"]' ).prev( '.select2-container' ).hide();
330 + }
331 + }
335 332
336 - if ( jQuery.datepicker ) {
333 + toggle_filter_submit();
334 + }
335 + );
337 336
338 - // Apply a GMT offset due to Date() using the visitor's local time
339 - var siteGMTOffsetHours = parseFloat( wp_stream.gmt_offset ),
340 - localGMTOffsetHours = new Date().getTimezoneOffset() / 60 * -1,
341 - totalGMTOffsetHours = siteGMTOffsetHours - localGMTOffsetHours,
342 - localTime = new Date(),
343 - siteTime = new Date( localTime.getTime() + ( totalGMTOffsetHours * 60 * 60 * 1000 ) ),
344 - maxOffset = 0,
345 - minOffset = null;
337 + $( '#ui-datepicker-div' ).addClass( 'stream-datepicker' );
338 + }
339 + );
346 340
347 - // Check if the site date is different from the local date, and set a day offset
348 - if ( localTime.getDate() !== siteTime.getDate() || localTime.getMonth() !== siteTime.getMonth() ) {
349 - if ( localTime.getTime() < siteTime.getTime() ) {
350 - maxOffset = '+1d';
351 - } else {
352 - maxOffset = '-1d';
353 - }
341 + // Relative time
342 + $( 'table.wp-list-table' ).on(
343 + 'updated', function() {
344 + var timeObjects = $( this ).find( 'time.relative-time' );
345 + timeObjects.each(
346 + function( i, el ) {
347 + var timeEl = $( el );
348 + timeEl.removeClass( 'relative-time' );
349 + $( '<strong><time datetime="' + timeEl.attr( 'datetime' ) + '" class="timeago"/></time></strong><br/>' )
350 + .prependTo( timeEl.parent().parent() )
351 + .find( 'time.timeago' )
352 + .timeago();
354 353 }
354 + );
355 + }
356 + ).trigger( 'updated' );
355 357
356 - datepickers.datepicker({
357 - dateFormat: 'yy/mm/dd',
358 - minDate: minOffset,
359 - maxDate: maxOffset,
360 - defaultDate: siteTime,
361 - beforeShow: function() {
362 - $( this ).prop( 'disabled', true );
363 - },
364 - onClose: function() {
365 - $( this ).prop( 'disabled', false );
366 - }
367 - });
358 + var intervals = {
359 + init: function( $wrapper ) {
360 + this.wrapper = $wrapper;
361 + this.save_interval( this.wrapper.find( '.button-primary' ), this.wrapper );
368 362
369 - datepickers.datepicker( 'widget' ).addClass( 'stream-datepicker' );
370 - }
363 + this.$ = this.wrapper.each(
364 + function( i, val ) {
365 + var container = $( val ),
366 + dateinputs = container.find( '.date-inputs' ),
367 + from = container.find( '.field-from' ),
368 + to = container.find( '.field-to' ),
369 + to_remove = to.prev( '.date-remove' ),
370 + from_remove = from.prev( '.date-remove' ),
371 + predefined = container.children( '.field-predefined' ),
372 + datepickers = $( '' ).add( to ).add( from );
371 373
372 - predefined.select2({
373 - 'allowClear': true
374 - });
374 + if ( jQuery.datepicker ) {
375 + // Apply a GMT offset due to Date() using the visitor's local time
376 + var siteGMTOffsetHours = parseFloat( wp_stream.gmt_offset ),
377 + localGMTOffsetHours = new Date().getTimezoneOffset() / 60 * -1,
378 + totalGMTOffsetHours = siteGMTOffsetHours - localGMTOffsetHours,
379 + localTime = new Date(),
380 + siteTime = new Date( localTime.getTime() + ( totalGMTOffsetHours * 60 * 60 * 1000 ) ),
381 + maxOffset = 0,
382 + minOffset = null;
375 383
376 - if ( '' !== from.val() ) {
377 - from_remove.show();
378 - }
384 + // Check if the site date is different from the local date, and set a day offset
385 + if ( localTime.getDate() !== siteTime.getDate() || localTime.getMonth() !== siteTime.getMonth() ) {
386 + if ( localTime.getTime() < siteTime.getTime() ) {
387 + maxOffset = '+1d';
388 + } else {
389 + maxOffset = '-1d';
390 + }
391 + }
379 392
380 - if ( '' !== to.val() ) {
381 - to_remove.show();
382 - }
393 + datepickers.datepicker(
394 + {
395 + dateFormat: 'yy/mm/dd',
396 + minDate: minOffset,
397 + maxDate: maxOffset,
398 + defaultDate: siteTime,
399 + beforeShow: function() {
400 + $( this ).prop( 'disabled', true );
401 + },
402 + onClose: function() {
403 + $( this ).prop( 'disabled', false );
404 + },
405 + }
406 + );
383 407
384 - predefined.on({
385 - 'change': function () {
386 - var value = $( this ).val(),
387 - option = predefined.find( '[value="' + value + '"]' ),
388 - to_val = option.data( 'to' ),
389 - from_val = option.data( 'from' );
408 + datepickers.datepicker( 'widget' ).addClass( 'stream-datepicker' );
409 + }
390 410
391 - if ( 'custom' === value ) {
392 - dateinputs.show();
393 - return false;
394 - } else {
395 - dateinputs.hide();
396 - datepickers.datepicker( 'hide' );
411 + predefined.select2(
412 + {
413 + allowClear: true,
414 + }
415 + );
416 +
417 + if ( '' !== from.val() ) {
418 + from_remove.show();
397 419 }
398 420
399 - from.val( from_val ).trigger( 'change', [ true ] );
400 - to.val( to_val ).trigger( 'change', [ true ] );
421 + if ( '' !== to.val() ) {
422 + to_remove.show();
423 + }
401 424
402 - if ( jQuery.datepicker && datepickers.datepicker( 'widget' ).is( ':visible' ) ) {
403 - datepickers.datepicker( 'refresh' ).datepicker( 'hide' );
404 - }
405 - },
406 - 'select2-removed': function() {
407 - predefined.val( '' ).trigger( 'change' );
408 - },
409 - 'check_options': function () {
410 - if ( '' !== to.val() && '' !== from.val() ) {
411 - var option = predefined
412 - .find( 'option' )
413 - .filter( '[data-to="' + to.val() + '"]' )
414 - .filter( '[data-from="' + from.val() + '"]' );
415 - if ( 0 !== option.length ) {
416 - predefined.val( option.attr( 'value' ) ).trigger( 'change', [ true ] );
417 - } else {
418 - predefined.val( 'custom' ).trigger( 'change', [ true ] );
425 + predefined.on(
426 + {
427 + change: function() {
428 + var value = $( this ).val(),
429 + option = predefined.find( '[value="' + value + '"]' ),
430 + to_val = option.data( 'to' ),
431 + from_val = option.data( 'from' );
432 +
433 + if ( 'custom' === value ) {
434 + dateinputs.show();
435 + return false;
436 + }
437 + dateinputs.hide();
438 + datepickers.datepicker( 'hide' );
439 +
440 + from.val( from_val ).trigger( 'change', [ true ] );
441 + to.val( to_val ).trigger( 'change', [ true ] );
442 +
443 + if ( jQuery.datepicker && datepickers.datepicker( 'widget' ).is( ':visible' ) ) {
444 + datepickers.datepicker( 'refresh' ).datepicker( 'hide' );
445 + }
446 + },
447 + 'select2-removed': function() {
448 + predefined.val( '' ).trigger( 'change' );
449 + },
450 + check_options: function() {
451 + if ( '' !== to.val() && '' !== from.val() ) {
452 + var option = predefined
453 + .find( 'option' )
454 + .filter( '[data-to="' + to.val() + '"]' )
455 + .filter( '[data-from="' + from.val() + '"]' );
456 + if ( 0 !== option.length ) {
457 + predefined.val( option.attr( 'value' ) ).trigger( 'change', [ true ] );
458 + } else {
459 + predefined.val( 'custom' ).trigger( 'change', [ true ] );
460 + }
461 + } else if ( '' === to.val() && '' === from.val() ) {
462 + predefined.val( '' ).trigger( 'change', [ true ] );
463 + } else {
464 + predefined.val( 'custom' ).trigger( 'change', [ true ] );
465 + }
466 + },
419 467 }
420 - } else if ( '' === to.val() && '' === from.val() ) {
421 - predefined.val( '' ).trigger( 'change', [ true ] );
422 - } else {
423 - predefined.val( 'custom' ).trigger( 'change', [ true ] );
424 - }
425 - }
426 - });
468 + );
427 469
428 - from.on( 'change', function() {
429 - if ( '' !== from.val() ) {
430 - from_remove.show();
431 - to.datepicker( 'option', 'minDate', from.val() );
432 - } else {
433 - from_remove.hide();
434 - }
470 + from.on(
471 + 'change', function() {
472 + if ( '' !== from.val() ) {
473 + from_remove.show();
474 + to.datepicker( 'option', 'minDate', from.val() );
475 + } else {
476 + from_remove.hide();
477 + }
435 478
436 - if ( true === arguments[ arguments.length - 1 ] ) {
437 - return false;
438 - }
479 + if ( true === arguments[ arguments.length - 1 ] ) {
480 + return false;
481 + }
439 482
440 - predefined.trigger( 'check_options' );
441 - });
483 + predefined.trigger( 'check_options' );
484 + }
485 + );
442 486
443 - to.on( 'change', function() {
444 - if ( '' !== to.val() ) {
445 - to_remove.show();
446 - from.datepicker( 'option', 'maxDate', to.val() );
447 - } else {
448 - to_remove.hide();
449 - }
487 + to.on(
488 + 'change', function() {
489 + if ( '' !== to.val() ) {
490 + to_remove.show();
491 + from.datepicker( 'option', 'maxDate', to.val() );
492 + } else {
493 + to_remove.hide();
494 + }
450 495
451 - if ( true === arguments[ arguments.length - 1 ] ) {
452 - return false;
453 - }
496 + if ( true === arguments[ arguments.length - 1 ] ) {
497 + return false;
498 + }
454 499
455 - predefined.trigger( 'check_options' );
456 - });
500 + predefined.trigger( 'check_options' );
501 + }
502 + );
457 503
458 - // Trigger change on load
459 - predefined.trigger( 'change' );
504 + // Trigger change on load
505 + predefined.trigger( 'change' );
460 506
461 - $( '' ).add( from_remove ).add( to_remove ).on( 'click', function() {
462 - $( this ).next( 'input' ).val( '' ).trigger( 'change' );
463 - });
464 - });
465 - },
507 + $( '' ).add( from_remove ).add( to_remove ).on(
508 + 'click', function() {
509 + $( this ).next( 'input' ).val( '' ).trigger( 'change' );
510 + }
511 + );
512 + }
513 + );
514 + },
466 515
467 - save_interval: function( $btn ) {
468 - var $wrapper = this.wrapper;
469 - $btn.click( function() {
470 - var data = {
471 - key: $wrapper.find( 'select.field-predefined' ).find( ':selected' ).val(),
472 - start: $wrapper.find( '.date-inputs .field-from' ).val(),
473 - end: $wrapper.find( '.date-inputs .field-to' ).val()
474 - };
516 + save_interval: function( $btn ) {
517 + var $wrapper = this.wrapper;
518 + $btn.click(
519 + function() {
520 + var data = {
521 + key: $wrapper.find( 'select.field-predefined' ).find( ':selected' ).val(),
522 + start: $wrapper.find( '.date-inputs .field-from' ).val(),
523 + end: $wrapper.find( '.date-inputs .field-to' ).val(),
524 + };
475 525
476 - // Add params to URL
477 - $( this ).attr( 'href', $( this ).attr( 'href' ) + '&' + $.param( data ) );
478 - });
479 - }
480 - };
526 + // Add params to URL
527 + $( this ).attr( 'href', $( this ).attr( 'href' ) + '&' + $.param( data ) );
528 + }
529 + );
530 + },
531 + };
481 532
482 - $( document ).ready( function() {
483 - intervals.init( $( '.date-interval' ) );
533 + $( document ).ready(
534 + function() {
535 + intervals.init( $( '.date-interval' ) );
484 536
485 - // Disable option groups whose children are all disabled
486 - $( 'select[name="context"] .level-1' ).each( function() {
487 - var all_disabled = true;
537 + // Disable option groups whose children are all disabled
538 + $( 'select[name="context"] .level-1' ).each(
539 + function() {
540 + var all_disabled = true;
488 541
489 - $( this ).nextUntil( '.level-1' ).each( function() {
490 - if ( $( this ).is( ':not(:disabled)' ) ) {
491 - all_disabled = false;
492 - return false;
493 - }
494 - });
542 + $( this ).nextUntil( '.level-1' ).each(
543 + function() {
544 + if ( $( this ).is( ':not(:disabled)' ) ) {
545 + all_disabled = false;
546 + return false;
547 + }
548 + }
549 + );
495 550
496 - if ( true === all_disabled ) {
497 - $( this ).prop( 'disabled', true );
551 + if ( true === all_disabled ) {
552 + $( this ).prop( 'disabled', true );
553 + }
554 + }
555 + );
498 556 }
499 - });
500 - });
557 + );
558 + }
559 +);
501 560
502 -});
503 -
504 -jQuery.extend({
505 - streamGetQueryVars: function( str ) {
506 - return ( str || document.location.search ).replace( /(^\?)/, '' ).split( '&' ).map( function( n ) { return n = n.split( '=' ), this[n[0]] = n[1], this; }.bind( {} ) )[0];
561 +jQuery.extend(
562 + {
563 + streamGetQueryVars: function( str ) {
564 + return ( str || document.location.search ).replace( /(^\?)/, '' ).split( '&' ).map( function( n ) {
565 + return n = n.split( '=' ), this[n[0]] = n[1], this;
566 + }.bind( {} ) )[0];
567 + },
507 568 }
508 -});
569 +);