diff --git a/editor/browsersupport.js b/editor/browsersupport.js index e073435c..76395f55 100644 --- a/editor/browsersupport.js +++ b/editor/browsersupport.js @@ -12,15 +12,19 @@ (function() { -BrowserSupport = {}; +if (window.svgedit == undefined) { + window.svgedit = {}; +} + +svgedit.BrowserSupport = {}; var svgns = 'http://www.w3.org/2000/svg'; var userAgent = navigator.userAgent; // Note: Browser sniffing should only be used if no other detection method is possible -BrowserSupport.isOpera = !!window.opera; -BrowserSupport.isWebkit = userAgent.indexOf("AppleWebKit") >= 0; -BrowserSupport.isGecko = userAgent.indexOf('Gecko/') >= 0; +svgedit.BrowserSupport.isOpera = !!window.opera; +svgedit.BrowserSupport.isWebkit = userAgent.indexOf("AppleWebKit") >= 0; +svgedit.BrowserSupport.isGecko = userAgent.indexOf('Gecko/') >= 0; // segList functions (for FF1.5 and 2.0) function getPathReplaceItem() { @@ -65,7 +69,7 @@ function getTextCharPos() { function getEditableText() { // TODO: Find better way to check support for this - return BrowserSupport.isOpera; + return svgedit.BrowserSupport.isOpera; } function getGoodDecimals() { @@ -87,11 +91,11 @@ function getNonScalingStroke() { return rect.style.vectorEffect === 'non-scaling-stroke'; } -BrowserSupport.pathReplaceItem = getPathReplaceItem(); -BrowserSupport.pathInsertItemBefore = getPathInsertItemBefore(); -BrowserSupport.textCharPos = getTextCharPos(); -BrowserSupport.editableText = getEditableText(); -BrowserSupport.goodDecimals = getGoodDecimals(); -BrowserSupport.nonScalingStroke = getNonScalingStroke(); +svgedit.BrowserSupport.pathReplaceItem = getPathReplaceItem(); +svgedit.BrowserSupport.pathInsertItemBefore = getPathInsertItemBefore(); +svgedit.BrowserSupport.textCharPos = getTextCharPos(); +svgedit.BrowserSupport.editableText = getEditableText(); +svgedit.BrowserSupport.goodDecimals = getGoodDecimals(); +svgedit.BrowserSupport.nonScalingStroke = getNonScalingStroke(); })(); \ No newline at end of file diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 4cd11859..59d945f8 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -89,10 +89,10 @@ if(window.opera) { // config - An object that contains configuration data $.SvgCanvas = function(container, config) { -var isOpera = BrowserSupport.isOpera, - isWebkit = BrowserSupport.isWebkit, - isGecko = BrowserSupport.isGecko, - support = BrowserSupport, +var support = svgedit.BrowserSupport, + isOpera = support.isOpera, + isWebkit = support.isWebkit, + isGecko = support.isGecko, // this defines which elements and attributes that we support svgWhiteList = { @@ -196,7 +196,7 @@ if(config) { // Static class for various utility functions // See svgutils.js. -var Utils = this.Utils = SVGEditUtilities; +var Utils = this.Utils = svgedit.Utilities; // Function: snapToGrid // round value to for snapping @@ -8563,12 +8563,10 @@ this.importSvgString = function(xmlString) { addToSelection([use_el]); return true; - // TODO: Find way to add this in a recalculateDimensions-parsable way // if (vb[0] != 0 || vb[1] != 0) // ts = "translate(" + (-vb[0]) + "," + (-vb[1]) + ") " + ts; - } catch(e) { console.log(e); return false; @@ -11306,7 +11304,7 @@ function disableAdvancedTextEdit() { } (function() { - if (!BrowserSupport.textCharPos) { + if (!svgedit.BrowserSupport.textCharPos) { disableAdvancedTextEdit(); } diff --git a/editor/svgutils.js b/editor/svgutils.js index 5d892332..a04823a5 100644 --- a/editor/svgutils.js +++ b/editor/svgutils.js @@ -7,15 +7,22 @@ * Copyright(c) 2010 Jeff Schiller */ -// NOTE: Requires jQuery to be loaded. +// Dependencies: +// 1) jQuery -SVGEditUtilities = { +(function() { + +if (window.svgedit == undefined) { + window.svgedit = {}; +} + +svgedit.Utilities = { }; // String used to encode base64. -SVGEditUtilities._keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; +svgedit.Utilities._keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; -// Function: SVGEditUtilities.toXml +// Function: svgedit.Utilities.toXml // Converts characters in a string to XML-friendly entities. // // Example: "&" becomes "&" @@ -25,11 +32,11 @@ SVGEditUtilities._keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz // // Returns: // The converted string -SVGEditUtilities.toXml = function(str) { +svgedit.Utilities.toXml = function(str) { return $('
').text(str).html(); }; -// Function: SVGEditUtilities.fromXml +// Function: svgedit.Utilities.fromXml // Converts XML entities in a string to single characters. // Example: "&" becomes "&" // @@ -38,7 +45,7 @@ SVGEditUtilities.toXml = function(str) { // // Returns: // The converted string -SVGEditUtilities.fromXml = function(str) { +svgedit.Utilities.fromXml = function(str) { return $('').html(str).text(); }; @@ -52,12 +59,12 @@ SVGEditUtilities.fromXml = function(str) { // Function: Utils.encode64 // Converts a string to base64 -SVGEditUtilities.encode64 = function(input) { +svgedit.Utilities.encode64 = function(input) { // base64 strings are 4/3 larger than the original string // input = Utils.encodeUTF8(input); // convert non-ASCII characters input = Utils.convertToXMLReferences(input); if(window.btoa) return window.btoa(input); // Use native if available - var _keyStr = SVGEditUtilities._keyStr; + var _keyStr = svgedit.Utilities._keyStr; var output = new Array( Math.floor( (input.length + 2) / 3 ) * 4 ); var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; @@ -90,7 +97,7 @@ SVGEditUtilities.encode64 = function(input) { // Function: Utils.decode64 // Converts a string from base64 -SVGEditUtilities.decode64 = function(input) { +svgedit.Utilities.decode64 = function(input) { if(window.atob) return window.atob(input); var output = ""; var chr1, chr2, chr3 = ""; @@ -150,9 +157,9 @@ SVGEditUtilities.decode64 = function(input) { // return output; // }, -// Function: Utils.convertToXMLReferences +// Function: svgedit.Utilities.convertToXMLReferences // Converts a string to use XML references -SVGEditUtilities.convertToXMLReferences = function(input) { +svgedit.Utilities.convertToXMLReferences = function(input) { var output = ''; for (var n = 0; n < input.length; n++){ var c = input.charCodeAt(n); @@ -175,7 +182,7 @@ SVGEditUtilities.convertToXMLReferences = function(input) { // // Returns: // Boolean that's true if rectangles intersect -SVGEditUtilities.rectsIntersect = function(r1, r2) { +svgedit.Utilities.rectsIntersect = function(r1, r2) { return r2.x < (r1.x+r1.width) && (r2.x+r2.width) > r1.x && r2.y < (r1.y+r1.height) && @@ -197,7 +204,7 @@ SVGEditUtilities.rectsIntersect = function(r1, r2) { // x - The angle-snapped x value // y - The angle-snapped y value // snapangle - The angle at which to snap -SVGEditUtilities.snapToAngle = function(x1,y1,x2,y2) { +svgedit.Utilities.snapToAngle = function(x1,y1,x2,y2) { var snap = Math.PI/4; // 45 degrees var dx = x2 - x1; var dy = y2 - y1; @@ -213,7 +220,7 @@ SVGEditUtilities.snapToAngle = function(x1,y1,x2,y2) { // Function: text2xml // Cross-browser compatible method of converting a string to an XML tree // found this function here: http://groups.google.com/group/jquery-dev/browse_thread/thread/c6d11387c580a77f -SVGEditUtilities.text2xml = function(sXML) { +svgedit.Utilities.text2xml = function(sXML) { if(sXML.indexOf('