Closed jo-pol closed 9 years ago
Ajax.get, use the result for document.write, manipulate the dom of that result => download problems
The preview works fine: Live demo, the problematic source code
The download has the following problems (worst last):
The web-app is created following handson-scalajs. Despite Depending on Libraries, I could not find a working sbt/import incantation of scala-xml for my sbt files, it probably is not (yet?) compiled with scala-js. It would allow to manipulate the SVG before the document.write and fix the last problem.
I tried to call the javascript from the SVG documents (a dozen or so) to fix the other problems. But at least the firefox-svg combination does not seem to support importing javascripts, only inline scripts. I also tried window.open with the svg template, that would solve the second problem, but I got a blocked pop-up in return.
The templates are too big (300KB) for a data uri
Window.open with the template could fix the third problem. But it causes a pop-up block, at least in the test situation. Also document.getElementsByTagName does not seem to work on the new window, though it does from an inline script from within the SVG document.
Any other solutions or suggestions to get the download work properly? A client-side solution is a requirement.
A data-URI attempt worked for FF, chrome and safari. IE implements a data-URI only for images, and saves such an image as PNG, not as SVG. See also base64 encoding.
The code tried in grounds.scala:
case xhr =>
// generateDiagram (xhr.responseText, htmlDoc)
val encoded = scala.scalajs.js.URIUtils.encodeURIComponent(xhr.responseText)
htmlDoc.getElementById("message").innerHTML =
s"<a href='data:application/octet-stream,$encoded'>download</a>"
The tested code above just downloads the template, not the configured diagram, but that can propably be fixed with a stringified version of the preview.
This issue was moved to jo-pol/dibl-tensioned#8
This issue was moved to jo-pol/dibl-tensioned#9
The original problems are fixed, but note that you have to right-click and select "save image", do not save the page.
After applying "show in other tab" while generating a ground and saving the generated page locally, an application like InkScape will not open the saved diagram.
When opening a diagram saved with Safari or IE the diagram does not contain the chosen stitches but the original template. FF and Chrome are fixed for this matter.
Partial workaround: Open the saved file with a plain text editor, strip the few HTML lines at the top and bottom and save the result with an SVG extension. InkScape will open the modified file.