No Description

plnkrOpener.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. $(document).ready(function() {
  2. function formPostData(url, fields) {
  3. var form = $('<form style="display: none;" method="post" action="' + url + '"></form>');
  4. $.each(fields, function(name, value) {
  5. var input = $('<input type="hidden" name="' + name + '">');
  6. input.attr('value', value);
  7. form.append(input);
  8. });
  9. $(document).find('body').append(form);
  10. form[0].submit(function(e) {
  11. e.preventDefault();
  12. });
  13. form.remove();
  14. }
  15. function plnkrOpener() {
  16. var ctrl = {};
  17. ctrl.example = {
  18. path: ctrl.examplePath,
  19. manifest: undefined,
  20. files: undefined,
  21. name: 'bootstrap-select example'
  22. };
  23. ctrl.open = function() {
  24. var postData = {
  25. 'tags[0]': 'jquery',
  26. 'tags[1]': 'bootstrap-select',
  27. 'private': true
  28. };
  29. ctrl.example.files = [
  30. {
  31. name: 'index.html',
  32. url: 'test.html',
  33. content: ''
  34. },
  35. {
  36. name: 'bootstrap-select.js',
  37. url: 'https://raw.githubusercontent.com/silviomoreto/bootstrap-select/master/dist/js/bootstrap-select.js',
  38. content: ''
  39. },
  40. {
  41. name: 'bootstrap-select.css',
  42. url: 'https://raw.githubusercontent.com/silviomoreto/bootstrap-select/master/dist/css/bootstrap-select.css',
  43. content: ''
  44. }
  45. ]
  46. function getData(file) {
  47. return $.ajax({
  48. method: 'GET',
  49. url: file.url
  50. })
  51. .then(function(data) {
  52. file.content = data;
  53. postData['files[' + file.name + ']'] = file.content;
  54. });
  55. }
  56. var files = [];
  57. $.each(ctrl.example.files, function(i, file) {
  58. files.push(getData(file));
  59. });
  60. function sendData() {
  61. postData.description = ctrl.example.name;
  62. formPostData('https://plnkr.co/edit/?p=preview', postData);
  63. };
  64. $.when.apply(this, files).done(function() {
  65. sendData();
  66. });
  67. };
  68. return ctrl.open()
  69. }
  70. plnkrOpener();
  71. });