Made icons work in IE9 (with a few minor bugs)

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1680 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2010-08-25 15:10:43 +00:00
parent 631b2b4054
commit 9df823863a
4 changed files with 96 additions and 31 deletions

View File

@ -733,8 +733,8 @@
</g> </g>
<g id="fontsize"> <g id="fontsize">
<svg width="50" height="50" xmlns="http://www.w3.org/2000/svg" xmlns:xml="http://www.w3.org/XML/1998/namespace"> <svg width="50" height="50" xmlns="http://www.w3.org/2000/svg">
<text fill="#606060" stroke="none" x="14.451" y="41.4587" id="svg_2" font-size="26" font-family="serif" text-anchor="middle" xml:space="preserve">T</text> <text fill="#606060" stroke="none" x="14.451" y="41.4587" id="svg_2" font-size="26" font-family="serif" text-anchor="middle">T</text>
<text fill="#000000" stroke="none" x="28.853" y="41.8685" font-size="52" font-family="serif" text-anchor="middle" xml:space="preserve" id="svg_3">T</text> <text fill="#000000" stroke="none" x="28.853" y="41.8685" font-size="52" font-family="serif" text-anchor="middle" xml:space="preserve" id="svg_3">T</text>
</svg> </svg>
</g> </g>

View File

@ -11,6 +11,8 @@
*/ */
(function() { (function() {
// TODO: Find out what causes bugs in jQuery animate for IE9
if($.browser.msie) $.fx.off = true;
if(!window.svgEditor) window.svgEditor = function($) { if(!window.svgEditor) window.svgEditor = function($) {
var svgCanvas; var svgCanvas;

View File

@ -403,13 +403,13 @@ var Utils = this.Utils = function() {
var out; var out;
try{ try{
var dXML = ($.browser.msie)?new ActiveXObject("Microsoft.XMLDOM"):new DOMParser(); var dXML = (window.DOMParser)?new DOMParser():new ActiveXObject("Microsoft.XMLDOM");
dXML.async = false; dXML.async = false;
} catch(e){ } catch(e){
throw new Error("XML Parser could not be instantiated"); throw new Error("XML Parser could not be instantiated");
}; };
try{ try{
if($.browser.msie) out = (dXML.loadXML(sXML))?dXML:false; if(dXML.loadXML) out = (dXML.loadXML(sXML))?dXML:false;
else out = dXML.parseFromString(sXML, "text/xml"); else out = dXML.parseFromString(sXML, "text/xml");
} }
catch(e){ throw new Error("Error parsing XML string"); }; catch(e){ throw new Error("Error parsing XML string"); };
@ -422,7 +422,6 @@ var Utils = this.Utils = function() {
// TODO: declare the variables and set them as null, then move this setup stuff to // TODO: declare the variables and set them as null, then move this setup stuff to
// an initialization function - probably just use clear() // an initialization function - probably just use clear()
console.log('r');
var canvas = this, var canvas = this,
// Namespace constants // Namespace constants
@ -4315,10 +4314,10 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
} }
start_x *= current_zoom; start_x *= current_zoom;
start_y *= current_zoom; start_y *= current_zoom;
console.log('p',[evt.pageX, evt.pageY]); // console.log('p',[evt.pageX, evt.pageY]);
console.log('c',[evt.clientX, evt.clientY]); // console.log('c',[evt.clientX, evt.clientY]);
console.log('o',[evt.offsetX, evt.offsetY]); // console.log('o',[evt.offsetX, evt.offsetY]);
console.log('s',[start_x, start_y]); // console.log('s',[start_x, start_y]);
assignAttributes(rubberBox, { assignAttributes(rubberBox, {
'x': start_x, 'x': start_x,

View File

@ -128,6 +128,38 @@ $(function() {
(function($) { (function($) {
function makeSVG(el) {
// manually create a copy of the element
var new_el = document.createElementNS(el.namespaceURI, el.nodeName);
$.each(el.attributes, function(i, attr) {
var ns = attr.namespaceURI;
if(ns) {
new_el.setAttributeNS(ns, attr.nodeName, attr.nodeValue);
} else {
new_el.setAttribute(attr.nodeName, attr.nodeValue);
}
if(attr.nodeName == 'transform') {
console.log('val1:', attr.nodeValue);
console.log('val2:', new_el.getAttribute('transform'));
}
});
// now create copies of all children
$.each(el.childNodes, function(i, child) {
switch(child.nodeType) {
case 1: // element node
new_el.appendChild(makeSVG(child));
break;
case 3: // text node
new_el.textContent = child.nodeValue;
break;
default:
break;
}
});
return new_el;
}
var svg_icons = {}; var svg_icons = {};
$.svgIcons = function(file, opts) { $.svgIcons = function(file, opts) {
@ -168,7 +200,19 @@ $(function() {
}); });
} else { } else {
if(err.responseXML) { if(err.responseXML) {
// Is there a non-ActiveX solution in IE9?
svgdoc = err.responseXML; svgdoc = err.responseXML;
if(!svgdoc.childNodes.length) {
if(window.ActiveXObject) {
svgdoc = new ActiveXObject("Microsoft.XMLDOM");
svgdoc.loadXML(err.responseText);
} else {
$(useFallback);
}
} else {
$(useFallback);
}
$(function() { $(function() {
getIcons('ajax'); getIcons('ajax');
}); });
@ -220,20 +264,29 @@ $(function() {
} }
} }
}); });
elems = $(svgdoc.firstChild).children(); //.getElementsByTagName('foreignContent');
var testSrc = data_pre + 'PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNzUiIGhlaWdodD0iMjc1Ij48L3N2Zz4%3D';
testImg = $(new Image()).attr({ elems = $(svgdoc.firstChild).children(); //.getElementsByTagName('foreignContent');
src: testSrc,
width: 0, if(!opts.no_img) {
height: 0
}).appendTo('body') var testSrc = data_pre + 'PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNzUiIGhlaWdodD0iMjc1Ij48L3N2Zz4%3D';
.load(function () {
// Safari 4 crashes, Opera and Chrome don't testImg = $(new Image()).attr({
makeIcons(!isSafari); src: testSrc,
}).error(function () { width: 0,
makeIcons(); height: 0
}); }).appendTo('body')
.load(function () {
// Safari 4 crashes, Opera and Chrome don't
makeIcons(!isSafari);
}).error(function () {
makeIcons();
});
} else {
setTimeout(function() {
if(!icons_made) makeIcons();
},500);
}
} }
function makeIcons(toImage, fallback) { function makeIcons(toImage, fallback) {
@ -290,9 +343,12 @@ $(function() {
var id = elem.getAttribute('id'); var id = elem.getAttribute('id');
if(id == 'svg_eof') return; if(id == 'svg_eof') return;
holder = $('#' + id); holder = $('#' + id);
if(elem.getElementsByTagNameNS) {
var svg = elem.getElementsByTagNameNS(svgns, 'svg')[0]; var svg = elem.getElementsByTagNameNS(svgns, 'svg')[0];
var svgroot = svgdoc.createElementNS(svgns, "svg"); } else {
var svg = elem.getElementsByTagName('svg')[0];
}
var svgroot = document.createElementNS(svgns, "svg");
svgroot.setAttributeNS(svgns, 'viewBox', [0,0,icon_w,icon_h].join(' ')); svgroot.setAttributeNS(svgns, 'viewBox', [0,0,icon_w,icon_h].join(' '));
// Make flexible by converting width/height to viewBox // Make flexible by converting width/height to viewBox
@ -318,7 +374,13 @@ $(function() {
// With cloning, causes issue in Opera/Win/Non-EN // With cloning, causes issue in Opera/Win/Non-EN
if(!isOpera) svg = svg.cloneNode(true); if(!isOpera) svg = svg.cloneNode(true);
svgroot.appendChild(svg); // TODO: Figure out why makeSVG is necessary for IE9
try {
svgroot.appendChild(svg);
} catch(e) {
// For IE9
svgroot.appendChild(makeSVG(svg));
}
if(toImage) { if(toImage) {
// Without cloning, Safari will crash // Without cloning, Safari will crash
@ -339,8 +401,12 @@ $(function() {
$.each(opts.placement, function(sel, id) { $.each(opts.placement, function(sel, id) {
if(!svg_icons[id]) return; if(!svg_icons[id]) return;
$(sel).each(function(i) { $(sel).each(function(i) {
var copy = svg_icons[id].clone(); // TODO: Figure out why makeSVG is necessary for IE9
if(i > 0 && !toImage) copy = fixIDs(copy, i, true); try {
var copy = svg_icons[id].clone();
} catch(e) {
var copy = makeSVG(svg_icons[id][0]);
}
setIcon($(this), copy, id); setIcon($(this), copy, id);
}) })
}); });
@ -348,11 +414,9 @@ $(function() {
if(!fallback) { if(!fallback) {
if(toImage) temp_holder.remove(); if(toImage) temp_holder.remove();
if(data_el) data_el.remove(); if(data_el) data_el.remove();
testImg.remove(); if(testImg) testImg.remove();
} }
if(opts.resize) $.resizeSvgIcons(opts.resize); if(opts.resize) $.resizeSvgIcons(opts.resize);
icons_made = true; icons_made = true;
if(opts.callback) opts.callback(svg_icons); if(opts.callback) opts.callback(svg_icons);