Cdnfsd_TransparentCDN_Page_View.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * File: Cdnfsd_TransparentCDN_Page_View.js
  3. *
  4. * @since 0.15.0
  5. */
  6. jQuery( document ).ready( function( $ ) {
  7. box = document.getElementById( 'tcdn_test_status' );
  8. if ( box ){
  9. box.innerHTML = transparent_configuration_strings.test_string;
  10. $( '#transparentcdn_test' ).on( 'click', function( e ) {
  11. var url = 'https://api.transparentcdn.com/v1/oauth2/access_token/',
  12. p = document.getElementById( 'tcdn_test_text' ),
  13. client_id = 'client_id' +
  14. '=' +
  15. document.getElementById( 'cdnfsd_transparentcdn_clientid' ).value,
  16. client_secret = 'client_secret' +
  17. '=' +
  18. document.getElementById( 'cdnfsd_transparentcdn_clientsecret' ).value,
  19. grant_type = 'grant_type=client_credentials',
  20. params = grant_type +
  21. '&' +
  22. client_id +
  23. '&' +
  24. client_secret,
  25. req = new XMLHttpRequest();
  26. e.preventDefault();
  27. req.open( 'POST', url, true );
  28. req.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' );
  29. req.onreadystatechange = function(e) {
  30. if ( 4 == req.readyState ) {
  31. if ( 200 == req.status ) {
  32. box.innerHTML = transparent_configuration_strings.test_success;
  33. box.className = 'w3tc-status w3tc-success';
  34. } else {
  35. box.innerHTML = transparent_configuration_strings.test_failure;
  36. box.className = 'w3tc-status w3tc-error';
  37. }
  38. }
  39. };
  40. req.send( params );
  41. });
  42. }
  43. });