Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
feather
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
feather
Commits
e80f8052
Commit
e80f8052
authored
Oct 11, 2017
by
Brad Bohen
Committed by
Cole Bemis
Oct 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Updated replace() to pass id from placeholder element (#193)
parent
b7d22291
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
7 deletions
+11
-7
README.md
README.md
+3
-3
replace.js
src/replace.js
+3
-1
to-svg.js
src/to-svg.js
+5
-3
No files found.
README.md
View file @
e80f8052
...
...
@@ -229,13 +229,13 @@ You can pass `feather.replace()` an `options` object:
</script>
```
All
classes on a placeholder element (i.e.
`<i>`
) will be copied to the
`<svg>`
tag:
The id and
classes on a placeholder element (i.e.
`<i>`
) will be copied to the
`<svg>`
tag:
```
html
<i
class=
"foo bar"
data-feather=
"circle"
></i>
<i
id=
"my-circle-icon"
class=
"foo bar"
data-feather=
"circle"
></i>
<!--
<i> will be replaced with:
<svg class="feather feather-circle foo bar" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle></svg>
<svg
id="my-circle-icon"
class="feather feather-circle foo bar" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle></svg>
-->
<script>
...
...
src/replace.js
View file @
e80f8052
...
...
@@ -42,11 +42,13 @@ function replaceElement(element, options) {
}
const
elementClassAttr
=
element
.
getAttribute
(
'
class
'
)
||
''
;
const
elementIdAttr
=
element
.
getAttribute
(
'
id
'
);
const
classNames
=
(
options
.
class
?
`
${
options
.
class
}
${
elementClassAttr
}
`
:
elementClassAttr
);
const
svgString
=
toSvg
(
key
,
Object
.
assign
({},
options
,
{
class
:
classNames
}));
const
svgOptions
=
Object
.
assign
({},
options
,
{
class
:
classNames
,
id
:
elementIdAttr
});
const
svgString
=
toSvg
(
key
,
svgOptions
);
const
svgDocument
=
new
DOMParser
().
parseFromString
(
svgString
,
'
image/svg+xml
'
);
const
svgElement
=
svgDocument
.
querySelector
(
'
svg
'
);
...
...
src/to-svg.js
View file @
e80f8052
...
...
@@ -35,7 +35,7 @@ export default function toSvg(key, options = {}) {
combinedOptions
.
class
=
addDefaultClassNames
(
combinedOptions
.
class
,
key
);
const
attributes
=
optionsToAt
r
ributes
(
combinedOptions
);
const
attributes
=
optionsToAt
t
ributes
(
combinedOptions
);
return
`<svg
${
attributes
}
>
${
icons
[
key
]}
</svg>`
;
}
...
...
@@ -64,11 +64,13 @@ function addDefaultClassNames(classNames, key) {
* @param {Object} options
* @returns {string}
*/
function
optionsToAt
r
ributes
(
options
)
{
function
optionsToAt
t
ributes
(
options
)
{
const
attributes
=
[];
Object
.
keys
(
options
).
forEach
(
key
=>
{
attributes
.
push
(
`
${
key
}
="
${
options
[
key
]}
"`
);
if
(
options
[
key
])
{
attributes
.
push
(
`
${
key
}
="
${
options
[
key
]}
"`
);
}
});
return
attributes
.
join
(
'
'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment