core.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. var env = require("../core/env");
  2. var urn = 'urn:schemas-microsoft-com:vml';
  3. var win = typeof window === 'undefined' ? null : window;
  4. var vmlInited = false;
  5. var doc = win && win.document;
  6. function createNode(tagName) {
  7. return doCreateNode(tagName);
  8. } // Avoid assign to an exported variable, for transforming to cjs.
  9. var doCreateNode;
  10. if (doc && !env.canvasSupported) {
  11. try {
  12. !doc.namespaces.zrvml && doc.namespaces.add('zrvml', urn);
  13. doCreateNode = function (tagName) {
  14. return doc.createElement('<zrvml:' + tagName + ' class="zrvml">');
  15. };
  16. } catch (e) {
  17. doCreateNode = function (tagName) {
  18. return doc.createElement('<' + tagName + ' xmlns="' + urn + '" class="zrvml">');
  19. };
  20. }
  21. } // From raphael
  22. function initVML() {
  23. if (vmlInited || !doc) {
  24. return;
  25. }
  26. vmlInited = true;
  27. var styleSheets = doc.styleSheets;
  28. if (styleSheets.length < 31) {
  29. doc.createStyleSheet().addRule('.zrvml', 'behavior:url(#default#VML)');
  30. } else {
  31. // http://msdn.microsoft.com/en-us/library/ms531194%28VS.85%29.aspx
  32. styleSheets[0].addRule('.zrvml', 'behavior:url(#default#VML)');
  33. }
  34. }
  35. exports.doc = doc;
  36. exports.createNode = createNode;
  37. exports.initVML = initVML;