svg-element.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Wrapper for SVG element.
  3. * @constructor
  4. * @extends jvm.AbstractElement
  5. * @param {String} name Tag name of the element
  6. * @param {Object} config Set of parameters to initialize element with
  7. */
  8. jvm.SVGElement = function(name, config){
  9. jvm.SVGElement.parentClass.apply(this, arguments);
  10. }
  11. jvm.inherits(jvm.SVGElement, jvm.AbstractElement);
  12. jvm.SVGElement.svgns = "http://www.w3.org/2000/svg";
  13. /**
  14. * Creates DOM element.
  15. * @param {String} tagName Name of element
  16. * @private
  17. * @returns DOMElement
  18. */
  19. jvm.SVGElement.prototype.createElement = function( tagName ){
  20. return document.createElementNS( jvm.SVGElement.svgns, tagName );
  21. };
  22. /**
  23. * Adds CSS class for underlying DOM element.
  24. * @param {String} className Name of CSS class name
  25. */
  26. jvm.SVGElement.prototype.addClass = function( className ){
  27. this.node.setAttribute('class', className);
  28. };
  29. /**
  30. * Returns constructor for element by name prefixed with 'VML'.
  31. * @param {String} ctr Name of basic constructor to return
  32. * proper implementation for.
  33. * @returns Function
  34. * @private
  35. */
  36. jvm.SVGElement.prototype.getElementCtr = function( ctr ){
  37. return jvm['SVG'+ctr];
  38. };
  39. jvm.SVGElement.prototype.getBBox = function(){
  40. return this.node.getBBox();
  41. };