icon-manager.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. (function($, undefined) {
  2. 'use strict';
  3. window.VAMTAM = window.VAMTAM || {};
  4. window.VAMTAM.icon_manager = {
  5. init: function() {
  6. var file_frame,
  7. selected_zip;
  8. $(document).on('click', '.vamtam-upload-icon-font', function( e ) {
  9. file_frame = wp.media.frames.file_frame = wp.media({
  10. multiple: false,
  11. library: {
  12. type: 'application/zip'
  13. }
  14. });
  15. file_frame.on( 'select', function() {
  16. var attachment = file_frame.state().get('selection').first();
  17. selected_zip = attachment.id;
  18. $( '.vamtam-icon-font-setup .step-1 .step-in-progress' ).text( attachment.attributes.filename ).show();
  19. $( '.vamtam-icon-font-setup .postbox-container.step-2' ).removeClass( 'inactive' );
  20. });
  21. file_frame.open();
  22. e.preventDefault();
  23. });
  24. $(document).on('click', '.vamtam-process-icon-font', function( e ) {
  25. e.preventDefault();
  26. var self = $(this);
  27. self.siblings( '.step-in-progress' ).show();
  28. $.ajax({
  29. type: 'POST',
  30. url: ajaxurl,
  31. data: {
  32. action: 'vamtam-process-icon-font',
  33. selected: selected_zip,
  34. _ajax_nonce: $(this).data('nonce')
  35. },
  36. dataType: 'json',
  37. success: function(data) {
  38. self.siblings( '.step-in-progress' ).hide();
  39. var result = '';
  40. if ( 'error' in data ) {
  41. result = data.error;
  42. } else {
  43. for ( var name in data ) {
  44. result += 'custom-' + name + ': <svg width="32" height="32" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">';
  45. for( var i = 0; i < data[name].length; i++ ) {
  46. result += '<path d="' + data[name][i] + '" fill="#666"/>';
  47. }
  48. result += '</svg><br>';
  49. }
  50. }
  51. // $( '.vamtam-icon-font-setup .postbox-container' ).addClass( 'inactive' );
  52. $( '.vamtam-icon-font-setup .postbox-container.step-3' ).removeClass( 'inactive' ).find( '.result-generated' ).html( result ).parent().show();
  53. }
  54. });
  55. });
  56. },
  57. };
  58. window.VAMTAM.icon_manager.init();
  59. })(jQuery);