insert-chart-button.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. jQuery(document).ready(function($) {
  2. var charts;
  3. (function() {
  4. tinymce.PluginManager.add('easy_charts_insert_chart_tc_button', function(editor, url) {
  5. editor.addButton('easy_charts_insert_chart_tc_button', {
  6. icon: 'icon dashicons-chart-pie',
  7. tooltip: 'Insert Easy Chart',
  8. onclick: function() {
  9. $.ajax({
  10. url: ajaxurl,
  11. type: 'POST',
  12. dataType: 'json',
  13. data: {
  14. 'action': 'easy_charts_get_published_charts'
  15. },
  16. })
  17. .done(function(updated_data) {
  18. charts = updated_data
  19. editor.windowManager.open({
  20. title: 'Insert chart',
  21. body: [{
  22. type: 'listbox',
  23. name: 'level',
  24. label: 'Select Chart',
  25. 'values': charts
  26. }],
  27. onsubmit: function(e) {
  28. editor.insertContent(e.data.level);
  29. }
  30. });
  31. })
  32. .fail(function() {})
  33. .always(function() {});
  34. }
  35. });
  36. });
  37. })();
  38. });