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

Angular routing and svgPath #679

Closed
mysuf opened this issue Dec 20, 2017 · 14 comments
Closed

Angular routing and svgPath #679

mysuf opened this issue Dec 20, 2017 · 14 comments
Labels
bug:core Bug in core (trumbowyg.js)

Comments

@mysuf
Copy link

mysuf commented Dec 20, 2017

Hi, I am trying to run trumbowyg within angularjs app and I found issue that makes it unusable.

This is code from trumbowyg.js that do that:
t.svgPath = !!t.doc.querySelector('base') ? window.location.href.split('#')[0] : '';

angularjs html5Mode requires base tag so window.location is used for svgPath, but it is not accurate as angulajs has its own $location. It brakes loading svg icons.

What is the purpose of this statement? Iframe?
Thank you

@Alex-D
Copy link
Owner

Alex-D commented Dec 20, 2017

@mysuf
Copy link
Author

mysuf commented Dec 21, 2017

@Alex-D Ofc I did before opened this ticket and there is not an answer to my question. I could miss something so can you please refer to part where it solves this issue? I hacked it via tbwinit event and rewrote xlink:href of all use tags, but it is really ugly solution.. Thanks..

@Alex-D
Copy link
Owner

Alex-D commented Dec 21, 2017

https://alex-d.github.io/Trumbowyg/documentation/#svg-icons

You can set an URL instead of automatic detection.

If it does not works, you can inject icons into your HTML. Check the doc, really...

@mysuf
Copy link
Author

mysuf commented Dec 21, 2017

I think that you dont understand the issue, rly. Just look at row I mentioned above. There is nothing except deleting base tag that could workaround this behaviour. Injecting cant work because trumbowyg create wrong xlinks while building btnPanel. Doc is useless in this case. Please try to investigate issue little more before making judgements.. It is why I asked what is the purpose of that expression..

@Alex-D
Copy link
Owner

Alex-D commented Dec 22, 2017

OK, sorry, I understand the problem, but you were unclear.

Did you think that can do the job:

t.svgPath = options.svgBasePath || !!t.doc.querySelector('base') ? window.location.href.split('#')[0] : '';

svgBasePath should be your base path.

@mysuf
Copy link
Author

mysuf commented Dec 22, 2017

@Alex-D EDIT: it cant work. :/ when I want xlink looks like xlink:href="#trumbowyg-whatever" with base tag on page, it cant be done because svgBasePath="" is evaluated as false.

@mysuf
Copy link
Author

mysuf commented Dec 22, 2017

Better solution would be:
options.svgBasePath = !!t.doc.querySelector('base') ? window.location.href.split('#')[0] : ''; as default and then you can use options.svgBasePath directly in building btnPanel (skip reusing svgPath)

@Alex-D Alex-D reopened this Dec 22, 2017
@Alex-D Alex-D added bug:core Bug in core (trumbowyg.js) and removed question labels Dec 22, 2017
@mysuf
Copy link
Author

mysuf commented Dec 22, 2017

Eh. DefaultOptions declaration is outside of t scope so my last post cant work either.

@mysuf
Copy link
Author

mysuf commented Dec 27, 2017

Please could you provide t.doc.querySelector('base') usecase? I don't know any. svg IDs are created by editor on same page so it should be always in format xlink:href="#trumbowyg-anysvg". Isnt that same as xlink:href="currenturl#trumbowyg-anysvg"? So atm I am up to remove baseSvgPath..

@Alex-D
Copy link
Owner

Alex-D commented Dec 27, 2017

It's usefull when you have the html5mode disabled I guess.

@mysuf
Copy link
Author

mysuf commented Dec 27, 2017

Only html5mode=true requires base tag. According to this issue, using absolute url is only needed to workaround svg object property values in format of url(#some-id) like masks, clip-paths etc. I tried to find any "url(" in icons.svg and found none.

@Alex-D
Copy link
Owner

Alex-D commented Dec 28, 2017

Check this issue; #256

@mysuf
Copy link
Author

mysuf commented Dec 28, 2017

Oh. So that issue is related to Firefox/Safari while Chrome works. Ok. It means that also my current hotfix breaks it in these browsers. Even if I like this editor, I give up and rather use some angular-native editor. As nobody else faced this issue, I think that you can feel free to close it. Thanks for your time.

@LosD
Copy link

LosD commented Dec 28, 2017

This probably won't fix anything for you, since you seem to refer to the old AngularJS (1), while this is for Angular (2+), but since others might run into it, here's what I did for Angular (with Angular CLI):
To get the script working in the first place, it needs to go into .angular-cli.json script section, along with JQuery and plugins:

      "scripts": [
        "../node_modules/jquery/dist/jquery.min.js",
        "../node_modules/trumbowyg/dist/trumbowyg.min.js",
        "../node_modules/trumbowyg/dist/plugins/pasteimage/trumbowyg.pasteimage.min.js"
      ],

To get the CSS to a known directory, you need to make sure that the CLI packages it into the app, on a known location, using the assets section (assets and favicon.ico are there by defaults. I left them in for context):

      "assets": [
        "assets",
        "favicon.ico",
        {
          "glob": "icons.svg",
          "input": "../node_modules/trumbowyg/dist/ui",
          "output": "./dist/"
        }
      ],

(One could probably get away with just copying it to assets, but I preferred leaving it in place)

Then, in main.ts, set the trumbowyg svgPath: $.trumbowyg.svgPath = 'dist/icons.svg';

Optional: This doesn't really work for me, since I have a weird issue where stuff breaks when using JQuery typings with AOT, so I had to go back to any for jQuery plugins, but I made a TypeScript Typings file for Trumbowyg that I believe is reasonably correct:
https://gist.github.com/LosD/7d8b7d0c77be2cb92f4b309f1a3353b8

@Alex-D If you know anything about TypeScript, I'd love a review of the typings for correctness, then I can submit them to DefinitelyTyped, so TypeScript users has the typed API (one thing I know I should probably fix, is that only the JQuery interface is in the public namespace).

@Alex-D Alex-D closed this as completed Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:core Bug in core (trumbowyg.js)
Projects
None yet
Development

No branches or pull requests

3 participants