@gitlab/ui
Version:
GitLab UI Components
34 lines (31 loc) • 867 B
JavaScript
/**
* Mixin that handles the rel attribute/property for _blank targets
* adds the "noopener noreferrer" to the rel attribute if the target has the aforementioned value
* and if the target or rel haven't been set before
*/
var rel_mixin = {
props: {
target: {
type: String,
required: false,
default: null
}
},
computed: {
relType: function relType() {
if (this.target === '_blank' && this.hostname !== window.location.hostname) {
return this.secureRel;
}
return this.$attrs.rel;
},
hostname: function hostname() {
var anchor = document.createElement('a');
anchor.href = this.$attrs.href;
return anchor.hostname;
},
secureRel: function secureRel() {
return "".concat(this.$attrs.rel || '', " noopener noreferrer").trim();
}
}
};
export default rel_mixin;