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

added hasLink, and removeLink public methods #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ var linkInfo = {rel: "icon", type: "image/png", href: "/icon.png"};
DocHead.addLink(linkInfo);
~~~

#### DocHead.hasLink(metaInfo)

Check if a Link tag with a matching `.href` attribute exists in the head.

~~~js
var linkInfo = {rel: "icon", type: "image/png", href: "/icon.png"};
DocHead.hasLink(linkInfo);
~~~

#### DocHead.removeLink(metaInfo)

Removes all link tags with a matching `.href` attribute.

~~~js
var linkInfo = {rel: "icon", type: "image/png", href: "/icon.png"};
DocHead.removeLink(linkInfo);
~~~

#### DocHead.addLdJsonScript(jsonObj)

Add a Script tag with type of `application/ld+json`.
Expand Down
30 changes: 30 additions & 0 deletions lib/both.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ DocHead = {
addLink(info) {
this._addTag(info, 'link');
},
hasLink(info) {
if (Meteor.isClient) {
return this._hasTag(info, 'link');
}
},
removeLink(info) {
if (Meteor.isClient) {
this._removeTag(info, 'link');
}
},
getTitle() {
if (Meteor.isClient) {
titleDependency.depend();
Expand All @@ -49,6 +59,26 @@ DocHead = {
this._addToHead(meta);
}
},
_hasTag(info, tag) {
return !!this._findTagByHref(info.href, tag);
},
_removeTag(info, tag) {
const elements = document.querySelectorAll(tag);
for (let element of elements) {
if (element.getAttribute('href') === info.href) {
element.parentNode.removeChild(element);
}
}
},
_findTagByHref(href, tag) {
const elements = document.querySelectorAll(tag);
for (let element of elements) {
if (element.getAttribute('href') === href) {
return element;
}
}
return null
},
_addToHead(html) {
// only work there is kadira:flow-router-ssr
if (!FlowRouter) {
Expand Down