Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] Ability to use SVG.js from inside an SVG document #19

Closed
ctzurcanu opened this issue Mar 28, 2013 · 7 comments
Closed

[question] Ability to use SVG.js from inside an SVG document #19

ctzurcanu opened this issue Mar 28, 2013 · 7 comments

Comments

@ctzurcanu
Copy link

It would be nice to have SVG.js able to work from inside the SVG. In this case you could build your SVG editor as a SVG document and achieve from the very beginning resolution independency.
If this has been done already, needs documenting. For now I get
"Uncaught TypeError: Cannot set property 'cssText' of null svg.min.js:2
SVG.Doc.stage svg.min.js:2
SVG.Doc svg.min.js:2
SVG svg.min.js:2
(anonymous function)"

sorry. the code has more text, but gitbub's MD does not want to show it...



<script type="text/javascript" xlink:href="js/svg.min.js"></script>

<script type="text/javascript"> <![CDATA[

function doSomething()) {
var draw = SVG("viewport");
// do some svg.js work
}
]]> </script>

@ctzurcanu
Copy link
Author

This hack will let the library create a SVG element inside the initial SVG doc. Ideally the document root should become the SVG object used by the lib.

the "dirty" fix:
line 1606


  SVG.Doc.prototype.stage = function() {
    var check
      , element = this
      , xmlns = "http://www.w3.org/2000/svg"  //changed 
      , wrapper = document.createElementNS(xmlns,'g') //changed 

@ctzurcanu ctzurcanu reopened this Mar 28, 2013
@wout
Copy link
Member

wout commented Mar 28, 2013

I'm not quite sure what you want to achieve. If it is an svg document inside the parent svg document you can use the nested() method:

var draw = SVG('canvas')
var svg = draw.nested()

@ctzurcanu
Copy link
Author

Yes.. this is because github does not let me post all the code correctly :|

I will try to explain: I have a file1.svg that points to svg.js lib (there is no HTML here)

<script src="js/svg.js" type="text/javascript" charset="utf-8"></script>

of course the SVG DOM does not work the same as HTML DOM and you don't need to create the root element. In SVG it already exists and I would like to use the extant.

@wout
Copy link
Member

wout commented Mar 28, 2013

Ok, I can see now what you are getting at.

@wout
Copy link
Member

wout commented Mar 29, 2013

Can you send me an example of your setup to my email address (in my profile). Then I can fiddle with it.

@ctzurcanu
Copy link
Author

v.0.12 addresses this.

@wout
Copy link
Member

wout commented Mar 29, 2013

This feature is described here:
https://github.com/wout/svg.js#svg-document

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants