2010-10-26 07:25:21 +00:00
|
|
|
/**
|
2011-01-13 07:47:21 +00:00
|
|
|
* Package: svgedit.browser
|
2010-10-26 07:25:21 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2
|
|
|
|
*
|
|
|
|
* Copyright(c) 2010 Jeff Schiller
|
|
|
|
* Copyright(c) 2010 Alexis Deveria
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Dependencies:
|
|
|
|
// 1) jQuery (for $.alert())
|
|
|
|
|
2011-01-18 06:46:45 +00:00
|
|
|
var svgedit = svgedit || {};
|
2010-10-26 07:25:21 +00:00
|
|
|
|
2011-01-18 06:46:45 +00:00
|
|
|
(function() {
|
2010-10-26 16:33:44 +00:00
|
|
|
|
2011-01-13 07:47:21 +00:00
|
|
|
if (!svgedit.browser) {
|
|
|
|
svgedit.browser = {};
|
2010-10-29 05:09:39 +00:00
|
|
|
}
|
2010-10-26 07:25:21 +00:00
|
|
|
|
2011-01-16 03:18:19 +00:00
|
|
|
var supportsSvg_ = (function() {
|
|
|
|
return !!document.createElementNS && !!document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGRect;
|
|
|
|
})();
|
|
|
|
svgedit.browser.supportsSvg = function() { return supportsSvg_; }
|
|
|
|
if(!svgedit.browser.supportsSvg()) {
|
2011-01-18 06:46:45 +00:00
|
|
|
window.location = "browser-not-supported.html";
|
2011-01-16 03:18:19 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
|
2010-10-26 07:25:21 +00:00
|
|
|
var svgns = 'http://www.w3.org/2000/svg';
|
|
|
|
var userAgent = navigator.userAgent;
|
2010-11-08 18:03:33 +00:00
|
|
|
var svg = document.createElementNS(svgns, 'svg');
|
2010-10-26 07:25:21 +00:00
|
|
|
|
|
|
|
// Note: Browser sniffing should only be used if no other detection method is possible
|
2010-11-07 20:14:05 +00:00
|
|
|
var isOpera_ = !!window.opera;
|
|
|
|
var isWebkit_ = userAgent.indexOf("AppleWebKit") >= 0;
|
|
|
|
var isGecko_ = userAgent.indexOf('Gecko/') >= 0;
|
|
|
|
|
2011-01-13 07:38:27 +00:00
|
|
|
var supportsSelectors_ = (function() {
|
|
|
|
return !!svg.querySelector;
|
|
|
|
})();
|
|
|
|
|
|
|
|
var supportsXpath_ = (function() {
|
|
|
|
return !!document.evaluate;
|
|
|
|
})();
|
2010-10-26 07:25:21 +00:00
|
|
|
|
|
|
|
// segList functions (for FF1.5 and 2.0)
|
2011-01-13 07:38:27 +00:00
|
|
|
var supportsPathReplaceItem_ = (function() {
|
2010-11-08 18:03:33 +00:00
|
|
|
var path = document.createElementNS(svgns, 'path');
|
2010-10-26 07:25:21 +00:00
|
|
|
path.setAttribute('d','M0,0 10,10');
|
|
|
|
var seglist = path.pathSegList;
|
|
|
|
var seg = path.createSVGPathSegLinetoAbs(5,5);
|
|
|
|
try {
|
|
|
|
seglist.replaceItem(seg, 0);
|
|
|
|
return true;
|
|
|
|
} catch(err) {}
|
|
|
|
return false;
|
2011-01-13 07:38:27 +00:00
|
|
|
})();
|
2010-10-26 07:25:21 +00:00
|
|
|
|
2011-01-13 07:38:27 +00:00
|
|
|
var supportsPathInsertItemBefore_ = (function() {
|
2010-10-26 07:25:21 +00:00
|
|
|
var path = document.createElementNS(svgns,'path');
|
|
|
|
path.setAttribute('d','M0,0 10,10');
|
|
|
|
var seglist = path.pathSegList;
|
|
|
|
var seg = path.createSVGPathSegLinetoAbs(5,5);
|
|
|
|
try {
|
|
|
|
seglist.insertItemBefore(seg, 0);
|
|
|
|
return true;
|
|
|
|
} catch(err) {}
|
|
|
|
return false;
|
2011-01-13 07:38:27 +00:00
|
|
|
})();
|
2010-10-26 07:25:21 +00:00
|
|
|
|
|
|
|
// text character positioning
|
2011-01-13 07:38:27 +00:00
|
|
|
var supportsTextCharPos_ = (function() {
|
2010-10-26 07:25:21 +00:00
|
|
|
var retValue = false;
|
|
|
|
var svgcontent = document.createElementNS(svgns, 'svg');
|
|
|
|
document.documentElement.appendChild(svgcontent);
|
|
|
|
try {
|
|
|
|
var text = document.createElementNS(svgns,'text');
|
|
|
|
text.textContent = 'a';
|
|
|
|
svgcontent.appendChild(text);
|
|
|
|
text.getStartPositionOfChar(0);
|
|
|
|
retValue = true;
|
|
|
|
} catch(err) {}
|
|
|
|
document.documentElement.removeChild(svgcontent);
|
|
|
|
return retValue;
|
2011-01-13 07:38:27 +00:00
|
|
|
})();
|
2010-10-26 07:25:21 +00:00
|
|
|
|
2011-01-13 07:38:27 +00:00
|
|
|
var supportsEditableText_ = (function() {
|
2010-10-26 07:25:21 +00:00
|
|
|
// TODO: Find better way to check support for this
|
2011-01-13 07:38:27 +00:00
|
|
|
return isOpera_;
|
|
|
|
})();
|
2010-10-26 07:25:21 +00:00
|
|
|
|
2011-01-13 07:38:27 +00:00
|
|
|
var supportsGoodDecimals_ = (function() {
|
2010-10-26 07:25:21 +00:00
|
|
|
// Correct decimals on clone attributes (Opera < 10.5/win/non-en)
|
2010-11-08 18:03:33 +00:00
|
|
|
var rect = document.createElementNS(svgns, 'rect');
|
2010-10-26 07:25:21 +00:00
|
|
|
rect.setAttribute('x',.1);
|
|
|
|
var crect = rect.cloneNode(false);
|
|
|
|
var retValue = (crect.getAttribute('x').indexOf(',') == -1);
|
|
|
|
if(!retValue) {
|
|
|
|
$.alert("NOTE: This version of Opera is known to contain bugs in SVG-edit.\n\
|
|
|
|
Please upgrade to the <a href='http://opera.com'>latest version</a> in which the problems have been fixed.");
|
|
|
|
}
|
|
|
|
return retValue;
|
2011-01-13 07:38:27 +00:00
|
|
|
})();
|
2010-10-26 07:25:21 +00:00
|
|
|
|
2011-01-13 07:38:27 +00:00
|
|
|
var supportsNonScalingStroke_ = (function() {
|
2010-11-08 18:03:33 +00:00
|
|
|
var rect = document.createElementNS(svgns, 'rect');
|
2010-10-26 07:25:21 +00:00
|
|
|
rect.setAttribute('style','vector-effect:non-scaling-stroke');
|
|
|
|
return rect.style.vectorEffect === 'non-scaling-stroke';
|
2011-01-13 07:38:27 +00:00
|
|
|
})();
|
2010-10-26 07:25:21 +00:00
|
|
|
|
2011-01-13 07:38:27 +00:00
|
|
|
var supportsNativeSVGTransformLists_ = (function() {
|
2010-11-08 18:03:33 +00:00
|
|
|
var rect = document.createElementNS(svgns, 'rect');
|
|
|
|
var rxform = rect.transform.baseVal;
|
|
|
|
|
|
|
|
var t1 = svg.createSVGTransform();
|
|
|
|
rxform.appendItem(t1);
|
|
|
|
return rxform.getItem(0) == t1;
|
2011-01-13 07:38:27 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
// Public API
|
|
|
|
|
2011-01-13 07:47:21 +00:00
|
|
|
svgedit.browser.isOpera = function() { return isOpera_; }
|
|
|
|
svgedit.browser.isWebkit = function() { return isWebkit_; }
|
|
|
|
svgedit.browser.isGecko = function() { return isGecko_; }
|
2011-01-13 07:38:27 +00:00
|
|
|
|
2011-01-13 07:47:21 +00:00
|
|
|
svgedit.browser.supportsSelectors = function() { return supportsSelectors_; }
|
|
|
|
svgedit.browser.supportsXpath = function() { return supportsXpath_; }
|
2010-11-08 18:03:33 +00:00
|
|
|
|
2011-01-13 07:47:21 +00:00
|
|
|
svgedit.browser.supportsPathReplaceItem = function() { return supportsPathReplaceItem_; }
|
|
|
|
svgedit.browser.supportsPathInsertItemBefore = function() { return supportsPathInsertItemBefore_; }
|
|
|
|
svgedit.browser.supportsTextCharPos = function() { return supportsTextCharPos_; }
|
|
|
|
svgedit.browser.supportsEditableText = function() { return supportsEditableText_; }
|
|
|
|
svgedit.browser.supportsGoodDecimals = function() { return supportsGoodDecimals_; }
|
|
|
|
svgedit.browser.supportsNonScalingStroke = function() { return supportsNonScalingStroke_; }
|
|
|
|
svgedit.browser.supportsNativeTransformLists = function() { return supportsNativeSVGTransformLists_; }
|
2010-10-26 07:25:21 +00:00
|
|
|
|
2011-01-16 03:18:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
})();
|