From 4a79a4b1dac594e9a34f07dddeeded5370e678c1 Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Tue, 30 Mar 2010 15:28:57 +0000 Subject: [PATCH] Made SVG icons no longer require a viewBox to display properly git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1489 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/extensions/helloworld-icon.xml | 6 ++---- editor/svgicons/jquery.svgicons.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/editor/extensions/helloworld-icon.xml b/editor/extensions/helloworld-icon.xml index 68b6d964..0b1ba1a0 100644 --- a/editor/extensions/helloworld-icon.xml +++ b/editor/extensions/helloworld-icon.xml @@ -5,11 +5,10 @@ in the extension. The SVG inside the group makes up the actual icon, and needs use a viewBox instead of width/height for it to scale properly. - Multiple icons can be included, each within their own group. A final element - with ID "svg_eof" must be included too. + Multiple icons can be included, each within their own group. --> - + Layer 1 @@ -19,5 +18,4 @@ - \ No newline at end of file diff --git a/editor/svgicons/jquery.svgicons.js b/editor/svgicons/jquery.svgicons.js index 4ead0a9c..f12b6917 100644 --- a/editor/svgicons/jquery.svgicons.js +++ b/editor/svgicons/jquery.svgicons.js @@ -293,6 +293,17 @@ $(function() { var svgroot = svgdoc.createElementNS(svgns, "svg"); svgroot.setAttributeNS(svgns, 'viewBox', [0,0,icon_w,icon_h].join(' ')); + // Make flexible by converting width/height to viewBox + var w = svg.getAttribute('width'); + var h = svg.getAttribute('height'); + svg.removeAttribute('width'); + svg.removeAttribute('height'); + + var vb = svg.getAttribute('viewBox'); + if(!vb) { + svg.setAttribute('viewBox', [0,0,w,h].join(' ')); + } + $(svgroot).attr({ "xmlns": svgns, "width": icon_w,