Rewrite browsersupport JS module to only expose functions. Added detection for Selectors and XPath support. Updated svgcanvas.js to create its getElem() function based on browsersupport.
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1909 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
@@ -29,12 +29,16 @@ var isOpera_ = !!window.opera;
|
||||
var isWebkit_ = userAgent.indexOf("AppleWebKit") >= 0;
|
||||
var isGecko_ = userAgent.indexOf('Gecko/') >= 0;
|
||||
|
||||
svgedit.browsersupport.isOpera = function() { return isOpera_; }
|
||||
svgedit.browsersupport.isWebkit = function() { return isWebkit_; }
|
||||
svgedit.browsersupport.isGecko = function() { return isGecko_; }
|
||||
var supportsSelectors_ = (function() {
|
||||
return !!svg.querySelector;
|
||||
})();
|
||||
|
||||
var supportsXpath_ = (function() {
|
||||
return !!document.evaluate;
|
||||
})();
|
||||
|
||||
// segList functions (for FF1.5 and 2.0)
|
||||
function supportPathReplaceItem() {
|
||||
var supportsPathReplaceItem_ = (function() {
|
||||
var path = document.createElementNS(svgns, 'path');
|
||||
path.setAttribute('d','M0,0 10,10');
|
||||
var seglist = path.pathSegList;
|
||||
@@ -44,9 +48,9 @@ function supportPathReplaceItem() {
|
||||
return true;
|
||||
} catch(err) {}
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
|
||||
function supportPathInsertItemBefore() {
|
||||
var supportsPathInsertItemBefore_ = (function() {
|
||||
var path = document.createElementNS(svgns,'path');
|
||||
path.setAttribute('d','M0,0 10,10');
|
||||
var seglist = path.pathSegList;
|
||||
@@ -56,10 +60,10 @@ function supportPathInsertItemBefore() {
|
||||
return true;
|
||||
} catch(err) {}
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
|
||||
// text character positioning
|
||||
function supportTextCharPos() {
|
||||
var supportsTextCharPos_ = (function() {
|
||||
var retValue = false;
|
||||
var svgcontent = document.createElementNS(svgns, 'svg');
|
||||
document.documentElement.appendChild(svgcontent);
|
||||
@@ -72,14 +76,14 @@ function supportTextCharPos() {
|
||||
} catch(err) {}
|
||||
document.documentElement.removeChild(svgcontent);
|
||||
return retValue;
|
||||
}
|
||||
})();
|
||||
|
||||
function supportEditableText() {
|
||||
var supportsEditableText_ = (function() {
|
||||
// TODO: Find better way to check support for this
|
||||
return svgedit.browsersupport.isOpera();
|
||||
}
|
||||
return isOpera_;
|
||||
})();
|
||||
|
||||
function supportGoodDecimals() {
|
||||
var supportsGoodDecimals_ = (function() {
|
||||
// Correct decimals on clone attributes (Opera < 10.5/win/non-en)
|
||||
var rect = document.createElementNS(svgns, 'rect');
|
||||
rect.setAttribute('x',.1);
|
||||
@@ -90,29 +94,38 @@ function supportGoodDecimals() {
|
||||
Please upgrade to the <a href='http://opera.com'>latest version</a> in which the problems have been fixed.");
|
||||
}
|
||||
return retValue;
|
||||
}
|
||||
})();
|
||||
|
||||
function supportNonScalingStroke() {
|
||||
var supportsNonScalingStroke_ = (function() {
|
||||
var rect = document.createElementNS(svgns, 'rect');
|
||||
rect.setAttribute('style','vector-effect:non-scaling-stroke');
|
||||
return rect.style.vectorEffect === 'non-scaling-stroke';
|
||||
}
|
||||
})();
|
||||
|
||||
function supportNativeSVGTransformLists() {
|
||||
var supportsNativeSVGTransformLists_ = (function() {
|
||||
var rect = document.createElementNS(svgns, 'rect');
|
||||
var rxform = rect.transform.baseVal;
|
||||
|
||||
var t1 = svg.createSVGTransform();
|
||||
rxform.appendItem(t1);
|
||||
return rxform.getItem(0) == t1;
|
||||
}
|
||||
})();
|
||||
|
||||
svgedit.browsersupport.pathReplaceItem = supportPathReplaceItem();
|
||||
svgedit.browsersupport.pathInsertItemBefore = supportPathInsertItemBefore();
|
||||
svgedit.browsersupport.textCharPos = supportTextCharPos();
|
||||
svgedit.browsersupport.editableText = supportEditableText();
|
||||
svgedit.browsersupport.goodDecimals = supportGoodDecimals();
|
||||
svgedit.browsersupport.nonScalingStroke = supportNonScalingStroke();
|
||||
svgedit.browsersupport.nativeTransformLists = supportNativeSVGTransformLists();
|
||||
// Public API
|
||||
|
||||
svgedit.browsersupport.isOpera = function() { return isOpera_; }
|
||||
svgedit.browsersupport.isWebkit = function() { return isWebkit_; }
|
||||
svgedit.browsersupport.isGecko = function() { return isGecko_; }
|
||||
|
||||
svgedit.browsersupport.supportsSelectors = function() { return supportsSelectors_; }
|
||||
svgedit.browsersupport.supportsXpath = function() { return supportsXpath_; }
|
||||
|
||||
svgedit.browsersupport.supportsPathReplaceItem = function() { return supportsPathReplaceItem_; }
|
||||
svgedit.browsersupport.supportsPathInsertItemBefore = function() { return supportsPathInsertItemBefore_; }
|
||||
svgedit.browsersupport.supportsTextCharPos = function() { return supportsTextCharPos_; }
|
||||
svgedit.browsersupport.supportsEditableText = function() { return supportsEditableText_; }
|
||||
svgedit.browsersupport.supportsGoodDecimals = function() { return supportsGoodDecimals_; }
|
||||
svgedit.browsersupport.supportsNonScalingStroke = function() { return supportsNonScalingStroke_; }
|
||||
svgedit.browsersupport.supportsNativeTransformLists = function() { return supportsNativeSVGTransformLists_; }
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user