Guest User

Untitled

a guest
May 21st, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.35 KB | None | 0 0
  1. $(":file").change(function () {
  2. if (this.files && this.files[0]) {
  3. console.log(this.files[0]);
  4. var reader = new FileReader();
  5. reader.onload = imageIsLoaded;
  6. reader.readAsDataURL(this.files[0]);
  7.  
  8. //run after reader function is compeleted
  9.  
  10. var a = document.body.appendChild(
  11. document.createElement("a")
  12. );
  13. a.download = "export.svg";
  14. a.href = "data:image/svg+xml," + $('#ss').find('svg')[0];
  15. a.innerHTML = "[Export conent]";
  16. }
  17. });
  18.  
  19. function imageIsLoaded(e) {
  20. var ret = atob(e.target.result.split(',')[1]);
  21. $('#ss').html(ret);
  22.  
  23. var placement_ids = [];++
  24.  
  25. //($('#PLACEMENTS > g').length);
  26.  
  27. $('#PLACEMENTS > g').each(function(){
  28. id = $(this).attr('id');
  29.  
  30. if (id.indexOf("_1_") >= 0 ){
  31. id = id.replace("_1_", "")
  32. }
  33.  
  34. if (id.length <= 3){
  35. id = [id.slice(0, 2), "0", id.slice(2)].join('');
  36. }
  37.  
  38. $(this).attr('id',id);
  39.  
  40.  
  41. rect = $(this).find('rect');
  42. rect_id = rect.attr('id');
  43.  
  44. rect_id = rect_id.replace("_x5F", "");
  45.  
  46. rect_id = rect_id.replace("_3_", "");
  47.  
  48.  
  49. if (rect_id.length <= 8){
  50. rect_id = [rect_id.slice(0, 2), "0", rect_id.slice(2)].join('');
  51. }
  52.  
  53. rect.attr('id', rect_id);
  54.  
  55. rect_x = rect.attr('x');
  56. rect_y = rect.attr('y');
  57. rect_w = rect.attr('width');
  58. rect_h = rect.attr('height');
  59.  
  60. if (id == "PL01"){
  61. $('#PL01').attr('available-decoration','TEAM_NAME,PLAYER_NAME,LOGO,GRAPHIC,NUMBERS');
  62. $(this).append("<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='"+ rect_x +"px' height='"+ rect_h +"px' id='PL01_LOGO_GRAPHIC' y='"+ rect_y +"px' width='"+ rect_w +"px' version='1.1' preserveAspectRatio='xMidYMid' viewBox='0 0 256 405'><g></g></svg>");
  63. }
  64. if (id == "PL02"){
  65. $('#PL02').attr('available-decoration','TEAM_NAME,PLAYER_NAME,LOGO,GRAPHIC,NUMBERS');
  66. $(this).append("<svg id='PL02_LOGO_GRAPHIC' y='"+ rect_y +"px' height='"+ rect_h +"px' x='"+ rect_x +"px' width='"+ rect_w +"px' viewBox='0 0 256 256' version='1.1' preserveAspectRatio='xMidYMid'><g></g></svg>");
  67. }
  68. if (id == "PL03"){
  69. $('#PL03').attr('available-decoration','TEAM_NAME,PLAYER_NAME,LOGO,GRAPHIC,NUMBERS');
  70. $(this).append("<svg id='PL03_LOGO_GRAPHIC' y='"+ rect_y +"px' height='"+ rect_h +"px' x='"+ rect_x +"px' width='"+ rect_w +"px' viewBox='0 0 256 256' version='1.1' preserveAspectRatio='xMidYMid'><g></g></svg>");
  71. }
  72. if (id == "PL05"){
  73. $('#PL05').attr('available-decoration','LOGO,NUMBERS');
  74. rect_t = rect.attr('transform');
  75. $(this).append("<g id='PL05_ClipPath'><defs><rect id='SVGID_1_' x='"+ rect_x +"' y='"+ rect_y +"' transform='" + rect_t + "' width='" + rect_w + "' height='" + rect_h + "'></rect></defs><clipPath id='SVGID_2_'><use xlink:href='#SVGID_1_' overflow='visible'></use></clipPath><g clip-path='url(#SVGID_2_)'><!--?xml version='1.0' encoding='UTF-8'?--><svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='" + rect_w * 2 + "' height='" + rect_h + 9 + "' viewBox='0 0 250 250' version='1.1' preserveAspectRatio='xMidYMid' x='14.571' y='29.721px' id='PL05_LOGO_GRAPHIC' style='overflow: visible;'><g data-rotate-degree='45' data-scale='true' transform='rotate(45 128 124) scale(-1,1) translate(-250, 0)'></g></svg></g></g>");
  76.  
  77. }
  78. if (id == "PL06"){
  79. $('#PL06').attr('available-decoration','LOGO,NUMBERS');
  80. $(this).append("<g id='PL061_LOGO_x5F_GRAPHIC'><defs></defs><clipPath id='SVGID_2_1'><use xlink:href='#PL06_RECT' overflow='visible'></use></clipPath><g clip-path='url(#SVGID_2_1)'><!--?xml version='1.0' encoding='UTF-8'?--><svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' height='" + rect_h + "' style='overflow: visible;' x='" + rect_x + "' id='PL06_LOGO_GRAPHIC' y='" + rect_y + "' width='" + rect_w + "' version='1.1' preserveAspectRatio='xMidYMid' viewBox='0 0 300 300' enable-background='new 0 0 300 300' xml:space='preserve'><g data-rotate-degree='-45' data-scale='true' transform='rotate(-45 128 124) scale(-1,1) translate(-300, 0)'></g></svg></g></g>");
  81. }
  82. if (id == "PL37"){
  83. $('#PL37').attr('available-decoration','TEAM_NAME,PLAYER_NAME');
  84. }
  85.  
  86.  
  87. $(this).append( "<foreignObject id='" + id + "_fo' x='" + rect_x +"' y='" + rect_y +"' fill='none' width='" + rect_w +"' height='" + rect_h +"'><canvas width='" + rect_w +"' height='" + rect_h +"' id='"+ id +"_canvas'></canvas></foreignObject>" );
  88.  
  89. placement_ids.push(id);
  90.  
  91.  
  92. });
  93.  
  94. $('#PLACEMENTS').attr('used-placements',placement_ids);
  95.  
  96.  
  97.  
  98.  
  99. }
Add Comment
Please, Sign In to add comment