PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.5.0
Post Views Counter v1.5.0
1.7.13 1.7.12 1.7.11 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.2 1.3.2.1 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.7.10 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9
post-views-counter / js / counter.js
post-views-counter / js Last commit date
admin-dashboard.js 1 year ago admin-post.js 5 years ago admin-quick-edit.js 1 year ago admin-settings.js 1 year ago admin-widgets.js 5 years ago block-editor.min.js 1 year ago counter.js 1 year ago counter.min.js 1 year ago dummy.js 1 year ago frontend.js 1 year ago frontend.min.js 1 year ago
counter.js
69 lines
1 PostViewsCounterManual = {
2 /**
3 * Initialize counter.
4 *
5 * @param {object} args
6 *
7 * @return {void}
8 */
9 init: function( args ) {
10 let params = {
11 action: 'pvc-view-posts',
12 pvc_nonce: args.nonce,
13 ids: args.ids
14 };
15
16 let newParams = Object.keys( params ).map( function( el ) {
17 // add extra "data" array
18 return encodeURIComponent( el ) + '=' + encodeURIComponent( params[el] );
19 } ).join( '&' ).replace( /%20/g, '+' );
20
21 const _this = this;
22
23 return fetch( args.url, {
24 method: 'POST',
25 mode: 'cors',
26 cache: 'no-cache',
27 credentials: 'same-origin',
28 headers: {
29 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
30 },
31 body: newParams
32 } ).then( function( response ) {
33 // invalid response?
34 if ( ! response.ok )
35 throw Error( response.statusText );
36
37 return response.json();
38 } ).then( function( response ) {
39 try {
40 if ( typeof response === 'object' && response !== null )
41 _this.triggerEvent( 'pvcCheckPost', response );
42 } catch( error ) {
43 console.log( 'Invalid JSON data' );
44 console.log( error );
45 }
46 } ).catch( function( error ) {
47 console.log( 'Invalid response' );
48 console.log( error );
49 } );
50 },
51
52 /**
53 * Prepare the data to be sent with the request.
54 *
55 * @param {string} eventName
56 * @param {object} data
57 *
58 * @return {void}
59 */
60 triggerEvent: function( eventName, data ) {
61 const newEvent = new CustomEvent( eventName, {
62 bubbles: true,
63 detail: data
64 } );
65
66 // trigger event
67 document.dispatchEvent( newEvent );
68 }
69 }