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-75d572ba1dddmaster
parent
e557f346e9
commit
282f81f27a
|
@ -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_; }
|
||||
|
||||
})();
|
|
@ -218,21 +218,26 @@ var selectedElements = new Array(1);
|
|||
//
|
||||
// Parameters:
|
||||
// id - String with the element's new ID
|
||||
var getElem = function(id) {
|
||||
if(svgroot.querySelector) {
|
||||
var getElem = null;
|
||||
if (svgedit.browsersupport.supportsSelectors()) {
|
||||
getElem = function(id) {
|
||||
// querySelector lookup
|
||||
return svgroot.querySelector('#'+id);
|
||||
} else if(svgdoc.evaluate) {
|
||||
};
|
||||
} else if (svgedit.browsersupport.supportsXpath()) {
|
||||
getElem = function(id) {
|
||||
// xpath lookup
|
||||
return svgdoc.evaluate('svg:svg[@id="svgroot"]//svg:*[@id="'+id+'"]', container, function() { return "http://www.w3.org/2000/svg"; }, 9, null).singleNodeValue;
|
||||
} else {
|
||||
return svgdoc.evaluate('svg:svg[@id="svgroot"]//svg:*[@id="'+id+'"]',
|
||||
container, function() { return "http://www.w3.org/2000/svg"; },
|
||||
9, null).singleNodeValue;
|
||||
};
|
||||
} else {
|
||||
getElem = function(id) {
|
||||
// jQuery lookup: twice as slow as xpath in FF
|
||||
return $(svgroot).find('[id=' + id + ']')[0];
|
||||
}
|
||||
|
||||
// getElementById lookup: includes icons, not good
|
||||
// return svgdoc.getElementById(id);
|
||||
};
|
||||
};
|
||||
}
|
||||
canvas.getElem = getElem;
|
||||
|
||||
// Function: assignAttributes
|
||||
// Assigns multiple attributes to an element.
|
||||
|
@ -2657,7 +2662,7 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
|||
tlist.appendItem(svgroot.createSVGTransform());
|
||||
tlist.appendItem(svgroot.createSVGTransform());
|
||||
|
||||
if(svgedit.browsersupport.nonScalingStroke) {
|
||||
if(svgedit.browsersupport.supportsNonScalingStroke()) {
|
||||
mouse_target.style.vectorEffect = 'non-scaling-stroke';
|
||||
var all = mouse_target.getElementsByTagName('*'), len = all.length;
|
||||
for(var i = 0; i < all.length; i++) {
|
||||
|
@ -3318,7 +3323,7 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
|||
} // no change in mouse position
|
||||
|
||||
// Remove non-scaling stroke
|
||||
if(svgedit.browsersupport.nonScalingStroke) {
|
||||
if(svgedit.browsersupport.supportsNonScalingStroke()) {
|
||||
var elem = selectedElements[0];
|
||||
elem.removeAttribute('style');
|
||||
svgedit.utilities.walkTree(elem, function(elem) {
|
||||
|
@ -3898,7 +3903,7 @@ var textActions = canvas.textActions = function() {
|
|||
|
||||
$(curtext).css('cursor', 'text');
|
||||
|
||||
// if(svgedit.browsersupport.editableText) {
|
||||
// if(svgedit.browsersupport.supportsEditableText()) {
|
||||
// curtext.setAttribute('editable', 'simple');
|
||||
// return;
|
||||
// }
|
||||
|
@ -3938,7 +3943,7 @@ var textActions = canvas.textActions = function() {
|
|||
|
||||
curtext = false;
|
||||
|
||||
// if(svgedit.browsersupport.editableText) {
|
||||
// if(svgedit.browsersupport.supportsEditableText()) {
|
||||
// curtext.removeAttribute('editable');
|
||||
// }
|
||||
},
|
||||
|
@ -3954,7 +3959,7 @@ var textActions = canvas.textActions = function() {
|
|||
init: function(inputElem) {
|
||||
if(!curtext) return;
|
||||
|
||||
// if(svgedit.browsersupport.editableText) {
|
||||
// if(svgedit.browsersupport.supportsEditableText()) {
|
||||
// curtext.select();
|
||||
// return;
|
||||
// }
|
||||
|
@ -4042,7 +4047,7 @@ var pathActions = canvas.pathActions = function() {
|
|||
// Support insertItemBefore on paths for FF2
|
||||
var list = elem.pathSegList;
|
||||
|
||||
if(svgedit.browsersupport.pathInsertItemBefore) {
|
||||
if(svgedit.browsersupport.supportsPathInsertItemBefore()) {
|
||||
list.insertItemBefore(newseg, index);
|
||||
return;
|
||||
}
|
||||
|
@ -4889,7 +4894,7 @@ var pathActions = canvas.pathActions = function() {
|
|||
var func = 'createSVGPathSeg' + pathFuncs[type];
|
||||
var seg = path[func].apply(path, pts);
|
||||
|
||||
if(svgedit.browsersupport.pathReplaceItem) {
|
||||
if(svgedit.browsersupport.supportsPathReplaceItem()) {
|
||||
path.pathSegList.replaceItem(seg, index);
|
||||
} else {
|
||||
var segList = path.pathSegList;
|
||||
|
@ -9835,7 +9840,7 @@ this.getPrivateMethods = function() {
|
|||
canvas.textActions = textActions;
|
||||
}
|
||||
|
||||
if (!svgedit.browsersupport.textCharPos) {
|
||||
if (!svgedit.browsersupport.supportsTextCharPos()) {
|
||||
disableAdvancedTextEdit();
|
||||
}
|
||||
})();
|
||||
|
|
|
@ -261,7 +261,7 @@ svgedit.transformlist.removeElementFromListMap = function(elem) {
|
|||
// Parameters:
|
||||
// elem - DOM element to get a transformlist from
|
||||
svgedit.transformlist.getTransformList = function(elem) {
|
||||
if (!svgedit.browsersupport.nativeTransformLists) {
|
||||
if (!svgedit.browsersupport.supportsNativeTransformLists()) {
|
||||
var id = elem.id;
|
||||
if(!id) {
|
||||
// Get unique ID for temporary element
|
||||
|
|
Loading…
Reference in New Issue