06170410d176f5800357d6d2c583a971ececaf36.svn-base 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. function Support(document) {
  2. this.rangeBounds = this.testRangeBounds(document);
  3. this.cors = this.testCORS();
  4. this.svg = this.testSVG();
  5. }
  6. Support.prototype.testRangeBounds = function(document) {
  7. var range, testElement, rangeBounds, rangeHeight, support = false;
  8. if (document.createRange) {
  9. range = document.createRange();
  10. if (range.getBoundingClientRect) {
  11. testElement = document.createElement('boundtest');
  12. testElement.style.height = "123px";
  13. testElement.style.display = "block";
  14. document.body.appendChild(testElement);
  15. range.selectNode(testElement);
  16. rangeBounds = range.getBoundingClientRect();
  17. rangeHeight = rangeBounds.height;
  18. if (rangeHeight === 123) {
  19. support = true;
  20. }
  21. document.body.removeChild(testElement);
  22. }
  23. }
  24. return support;
  25. };
  26. Support.prototype.testCORS = function() {
  27. return typeof((new Image()).crossOrigin) !== "undefined";
  28. };
  29. Support.prototype.testSVG = function() {
  30. var img = new Image();
  31. var canvas = document.createElement("canvas");
  32. var ctx = canvas.getContext("2d");
  33. img.src = "data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'></svg>";
  34. try {
  35. ctx.drawImage(img, 0, 0);
  36. canvas.toDataURL();
  37. } catch(e) {
  38. return false;
  39. }
  40. return true;
  41. };
  42. module.exports = Support;