Skip to content
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
21 changes: 21 additions & 0 deletions lib/get-property-info/svg/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var SVG_NAMESPACE = require('./svg-namespaces.js').SVG_NAMESPACE;
var SVG_ELEMENTS = require('./svg-namespaces.js').SVG_ELEMENTS;
var SVG_PROPERTIES = require('./svg-namespaces.js').SVG_PROPERTIES;

function thisIsSVGTag(tag) {
return SVG_ELEMENTS.hasOwnProperty(tag);
}

function getSVGNamespace() {
return SVG_NAMESPACE;
}

function SVGAttributeNamespace(value) {
if (SVG_PROPERTIES.hasOwnProperty(value)) {
return SVG_PROPERTIES[value];
}
}

module.exports.thisIsSVGTag = thisIsSVGTag;
module.exports.getSVGNamespace = getSVGNamespace;
module.exports.SVGAttributeNamespace = SVGAttributeNamespace;
35 changes: 35 additions & 0 deletions lib/get-property-info/svg/svg-attribute-hook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

function AttributeHook(namespace, value) {
if (!(this instanceof AttributeHook)) {
return new AttributeHook(namespace, value);
}

this.namespace = namespace;
this.value = value;
}

AttributeHook.prototype.hook = function (node, prop, prev) {
if (prev && prev.type === 'AttributeHook' &&
prev.value === this.value &&
prev.namespace === this.namespace) {
return;
}

node.setAttributeNS(this.namespace, prop, this.value);
};

AttributeHook.prototype.unhook = function (node, prop, next) {
if (next && next.type === 'AttributeHook' &&
next.namespace === this.namespace) {
return;
}

var colonPosition = prop.indexOf(':');
var localName = colonPosition > -1 ? prop.substr(colonPosition + 1) : prop;
node.removeAttributeNS(this.namespace, localName);
};

AttributeHook.prototype.type = 'AttributeHook';

module.exports = AttributeHook;
Loading