This repository was archived by the owner on Sep 10, 2019. It is now read-only.
Updates to iconic directive to broadcast when svg injection is completed #444
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First off, I'm new to using GitHub, so forgive me if I'm not following the proper practices for submitting requests.
I recently switched a project I built using Foundation for Apps to use HTML5 mode, mainly for prettier urls. I followed the instructions laid out in the documentation. After doing so, I noticed the iconic SVGs weren't loading properly. After some investigation I found that the issue was caused by the iconic urls only containing hash fragments. As called out in the HTML5 mode documentation:
For more info see AngularJS issue #8934. I found a solution which will rewrite all urls in FuncIRI notation to an absolute url using the specified base: https://github.com/jeffbcross/angular-svg-base. The library works great for content loaded that angular is aware of, however, the svg injector library being used in the framework does not notify angular once an svg is added to the DOM. The solution to the fix is to compile the new SVG element once it's been added to the DOM using angular's $compile.
My proposal is to have the framework broadcast a message when iconic has finished updating the DOM to include the injected SVG. Luckily, the svg injection library provides a callback for such a case. This is only required for HTML5 mode, as the hash fragment urls will work properly otherwise. The proposed solution does not directly call $compile as not all apps would need angular to be aware of the injected svg element, only those which have specified the url base in the head of index.html (i.e. apps using html5 mode).
Also included in the changes is a fix to the iconic directive for which a previous change broke backwards compatibility. The previous change caused elements which already used data-src to become invalidated and replaced with 'assets/img/iconic/undefined.svg'. That change can be moved to another PR if desired.