annotate webapp/src/main/webapp/jquery/svg/jquery.svg.js @ 1151:139ad480333b

update jquery svg plugin to ver. 1.4.6
author hertzhaft
date Mon, 26 Nov 2012 23:49:41 +0100
parents 301ef9bf1965
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1 /* http://keith-wood.name/svg.html
1151
139ad480333b update jquery svg plugin to ver. 1.4.6
hertzhaft
parents: 1050
diff changeset
2 SVG for jQuery v1.4.5.
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
3 Written by Keith Wood (kbwood{at}iinet.com.au) August 2007.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
4 Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
5 MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
6 Please attribute the author if you use it. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
7
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
8 (function($) { // Hide scope, no $ conflict
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
9
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
10 /* SVG manager.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
11 Use the singleton instance of this class, $.svg,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
12 to interact with the SVG functionality. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
13 function SVGManager() {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
14 this._settings = []; // Settings to be remembered per SVG object
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
15 this._extensions = []; // List of SVG extensions added to SVGWrapper
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
16 // for each entry [0] is extension name, [1] is extension class (function)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
17 // the function takes one parameter - the SVGWrapper instance
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
18 this.regional = []; // Localisations, indexed by language, '' for default (English)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
19 this.regional[''] = {errorLoadingText: 'Error loading',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
20 notSupportedText: 'This browser does not support SVG'};
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
21 this.local = this.regional['']; // Current localisation
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
22 this._uuid = new Date().getTime();
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
23 this._renesis = detectActiveX('RenesisX.RenesisCtrl');
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
24 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
25
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
26 /* Determine whether a given ActiveX control is available.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
27 @param classId (string) the ID for the ActiveX control
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
28 @return (boolean) true if found, false if not */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
29 function detectActiveX(classId) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
30 try {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
31 return !!(window.ActiveXObject && new ActiveXObject(classId));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
32 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
33 catch (e) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
34 return false;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
35 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
36 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
37
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
38 var PROP_NAME = 'svgwrapper';
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
39
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
40 $.extend(SVGManager.prototype, {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
41 /* Class name added to elements to indicate already configured with SVG. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
42 markerClassName: 'hasSVG',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
43
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
44 /* SVG namespace. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
45 svgNS: 'http://www.w3.org/2000/svg',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
46 /* XLink namespace. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
47 xlinkNS: 'http://www.w3.org/1999/xlink',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
48
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
49 /* SVG wrapper class. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
50 _wrapperClass: SVGWrapper,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
51
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
52 /* Camel-case versions of attribute names containing dashes or are reserved words. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
53 _attrNames: {class_: 'class', in_: 'in',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
54 alignmentBaseline: 'alignment-baseline', baselineShift: 'baseline-shift',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
55 clipPath: 'clip-path', clipRule: 'clip-rule',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
56 colorInterpolation: 'color-interpolation',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
57 colorInterpolationFilters: 'color-interpolation-filters',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
58 colorRendering: 'color-rendering', dominantBaseline: 'dominant-baseline',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
59 enableBackground: 'enable-background', fillOpacity: 'fill-opacity',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
60 fillRule: 'fill-rule', floodColor: 'flood-color',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
61 floodOpacity: 'flood-opacity', fontFamily: 'font-family',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
62 fontSize: 'font-size', fontSizeAdjust: 'font-size-adjust',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
63 fontStretch: 'font-stretch', fontStyle: 'font-style',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
64 fontVariant: 'font-variant', fontWeight: 'font-weight',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
65 glyphOrientationHorizontal: 'glyph-orientation-horizontal',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
66 glyphOrientationVertical: 'glyph-orientation-vertical',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
67 horizAdvX: 'horiz-adv-x', horizOriginX: 'horiz-origin-x',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
68 imageRendering: 'image-rendering', letterSpacing: 'letter-spacing',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
69 lightingColor: 'lighting-color', markerEnd: 'marker-end',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
70 markerMid: 'marker-mid', markerStart: 'marker-start',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
71 stopColor: 'stop-color', stopOpacity: 'stop-opacity',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
72 strikethroughPosition: 'strikethrough-position',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
73 strikethroughThickness: 'strikethrough-thickness',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
74 strokeDashArray: 'stroke-dasharray', strokeDashOffset: 'stroke-dashoffset',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
75 strokeLineCap: 'stroke-linecap', strokeLineJoin: 'stroke-linejoin',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
76 strokeMiterLimit: 'stroke-miterlimit', strokeOpacity: 'stroke-opacity',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
77 strokeWidth: 'stroke-width', textAnchor: 'text-anchor',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
78 textDecoration: 'text-decoration', textRendering: 'text-rendering',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
79 underlinePosition: 'underline-position', underlineThickness: 'underline-thickness',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
80 vertAdvY: 'vert-adv-y', vertOriginY: 'vert-origin-y',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
81 wordSpacing: 'word-spacing', writingMode: 'writing-mode'},
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
82
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
83 /* Add the SVG object to its container. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
84 _attachSVG: function(container, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
85 var svg = (container.namespaceURI == this.svgNS ? container : null);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
86 var container = (svg ? null : container);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
87 if ($(container || svg).hasClass(this.markerClassName)) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
88 return;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
89 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
90 if (typeof settings == 'string') {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
91 settings = {loadURL: settings};
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
92 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
93 else if (typeof settings == 'function') {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
94 settings = {onLoad: settings};
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
95 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
96 $(container || svg).addClass(this.markerClassName);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
97 try {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
98 if (!svg) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
99 svg = document.createElementNS(this.svgNS, 'svg');
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
100 svg.setAttribute('version', '1.1');
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
101 if (container.clientWidth > 0) {
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
102 svg.setAttribute('width', container.clientWidth);
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
103 }
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
104 if (container.clientHeight > 0) {
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
105 svg.setAttribute('height', container.clientHeight);
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
106 }
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
107 container.appendChild(svg);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
108 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
109 this._afterLoad(container, svg, settings || {});
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
110 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
111 catch (e) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
112 if ($.browser.msie) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
113 if (!container.id) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
114 container.id = 'svg' + (this._uuid++);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
115 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
116 this._settings[container.id] = settings;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
117 container.innerHTML = '<embed type="image/svg+xml" width="100%" ' +
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
118 'height="100%" src="' + (settings.initPath || '') + 'blank.svg" ' +
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
119 'pluginspage="http://www.adobe.com/svg/viewer/install/main.html"/>';
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
120 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
121 else {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
122 container.innerHTML = '<p class="svg_error">' +
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
123 this.local.notSupportedText + '</p>';
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
124 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
125 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
126 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
127
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
128 /* SVG callback after loading - register SVG root. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
129 _registerSVG: function() {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
130 for (var i = 0; i < document.embeds.length; i++) { // Check all
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
131 var container = document.embeds[i].parentNode;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
132 if (!$(container).hasClass($.svg.markerClassName) || // Not SVG
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
133 $.data(container, PROP_NAME)) { // Already done
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
134 continue;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
135 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
136 var svg = null;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
137 try {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
138 svg = document.embeds[i].getSVGDocument();
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
139 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
140 catch(e) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
141 setTimeout($.svg._registerSVG, 250); // Renesis takes longer to load
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
142 return;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
143 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
144 svg = (svg ? svg.documentElement : null);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
145 if (svg) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
146 $.svg._afterLoad(container, svg);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
147 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
148 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
149 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
150
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
151 /* Post-processing once loaded. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
152 _afterLoad: function(container, svg, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
153 var settings = settings || this._settings[container.id];
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
154 this._settings[container ? container.id : ''] = null;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
155 var wrapper = new this._wrapperClass(svg, container);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
156 $.data(container || svg, PROP_NAME, wrapper);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
157 try {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
158 if (settings.loadURL) { // Load URL
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
159 wrapper.load(settings.loadURL, settings);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
160 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
161 if (settings.settings) { // Additional settings
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
162 wrapper.configure(settings.settings);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
163 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
164 if (settings.onLoad && !settings.loadURL) { // Onload callback
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
165 settings.onLoad.apply(container || svg, [wrapper]);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
166 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
167 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
168 catch (e) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
169 alert(e);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
170 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
171 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
172
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
173 /* Return the SVG wrapper created for a given container.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
174 @param container (string) selector for the container or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
175 (element) the container for the SVG object or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
176 jQuery collection - first entry is the container
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
177 @return (SVGWrapper) the corresponding SVG wrapper element, or null if not attached */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
178 _getSVG: function(container) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
179 container = (typeof container == 'string' ? $(container)[0] :
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
180 (container.jquery ? container[0] : container));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
181 return $.data(container, PROP_NAME);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
182 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
183
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
184 /* Remove the SVG functionality from a div.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
185 @param container (element) the container for the SVG object */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
186 _destroySVG: function(container) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
187 var $container = $(container);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
188 if (!$container.hasClass(this.markerClassName)) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
189 return;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
190 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
191 $container.removeClass(this.markerClassName);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
192 if (container.namespaceURI != this.svgNS) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
193 $container.empty();
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
194 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
195 $.removeData(container, PROP_NAME);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
196 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
197
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
198 /* Extend the SVGWrapper object with an embedded class.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
199 The constructor function must take a single parameter that is
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
200 a reference to the owning SVG root object. This allows the
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
201 extension to access the basic SVG functionality.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
202 @param name (string) the name of the SVGWrapper attribute to access the new class
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
203 @param extClass (function) the extension class constructor */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
204 addExtension: function(name, extClass) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
205 this._extensions.push([name, extClass]);
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
206 },
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
207
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
208 /* Does this node belong to SVG?
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
209 @param node (element) the node to be tested
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
210 @return (boolean) true if an SVG node, false if not */
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
211 isSVGElem: function(node) {
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
212 return (node.nodeType == 1 && node.namespaceURI == $.svg.svgNS);
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
213 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
214 });
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
215
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
216 /* The main SVG interface, which encapsulates the SVG element.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
217 Obtain a reference from $().svg('get') */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
218 function SVGWrapper(svg, container) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
219 this._svg = svg; // The SVG root node
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
220 this._container = container; // The containing div
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
221 for (var i = 0; i < $.svg._extensions.length; i++) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
222 var extension = $.svg._extensions[i];
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
223 this[extension[0]] = new extension[1](this);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
224 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
225 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
226
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
227 $.extend(SVGWrapper.prototype, {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
228
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
229 /* Retrieve the width of the SVG object. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
230 _width: function() {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
231 return (this._container ? this._container.clientWidth : this._svg.width);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
232 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
233
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
234 /* Retrieve the height of the SVG object. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
235 _height: function() {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
236 return (this._container ? this._container.clientHeight : this._svg.height);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
237 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
238
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
239 /* Retrieve the root SVG element.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
240 @return the top-level SVG element */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
241 root: function() {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
242 return this._svg;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
243 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
244
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
245 /* Configure a SVG node.
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
246 @param node (element, optional) the node to configure
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
247 @param settings (object) additional settings for the root
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
248 @param clear (boolean) true to remove existing attributes first,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
249 false to add to what is already there (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
250 @return (SVGWrapper) this root */
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
251 configure: function(node, settings, clear) {
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
252 if (!node.nodeName) {
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
253 clear = settings;
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
254 settings = node;
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
255 node = this._svg;
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
256 }
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
257 if (clear) {
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
258 for (var i = node.attributes.length - 1; i >= 0; i--) {
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
259 var attr = node.attributes.item(i);
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
260 if (!(attr.nodeName == 'onload' || attr.nodeName == 'version' ||
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
261 attr.nodeName.substring(0, 5) == 'xmlns')) {
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
262 node.attributes.removeNamedItem(attr.nodeName);
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
263 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
264 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
265 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
266 for (var attrName in settings) {
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
267 node.setAttribute($.svg._attrNames[attrName] || attrName, settings[attrName]);
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
268 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
269 return this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
270 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
271
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
272 /* Locate a specific element in the SVG document.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
273 @param id (string) the element's identifier
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
274 @return (element) the element reference, or null if not found */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
275 getElementById: function(id) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
276 return this._svg.ownerDocument.getElementById(id);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
277 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
278
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
279 /* Change the attributes for a SVG node.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
280 @param element (SVG element) the node to change
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
281 @param settings (object) the new settings
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
282 @return (SVGWrapper) this root */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
283 change: function(element, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
284 if (element) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
285 for (var name in settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
286 if (settings[name] == null) {
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
287 element.removeAttribute($.svg._attrNames[name] || name);
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
288 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
289 else {
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
290 element.setAttribute($.svg._attrNames[name] || name, settings[name]);
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
291 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
292 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
293 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
294 return this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
295 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
296
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
297 /* Check for parent being absent and adjust arguments accordingly. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
298 _args: function(values, names, optSettings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
299 names.splice(0, 0, 'parent');
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
300 names.splice(names.length, 0, 'settings');
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
301 var args = {};
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
302 var offset = 0;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
303 if (values[0] != null && values[0].jquery) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
304 values[0] = values[0][0];
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
305 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
306 if (values[0] != null && !(typeof values[0] == 'object' && values[0].nodeName)) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
307 args['parent'] = null;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
308 offset = 1;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
309 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
310 for (var i = 0; i < values.length; i++) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
311 args[names[i + offset]] = values[i];
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
312 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
313 if (optSettings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
314 $.each(optSettings, function(i, value) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
315 if (typeof args[value] == 'object') {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
316 args.settings = args[value];
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
317 args[value] = null;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
318 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
319 });
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
320 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
321 return args;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
322 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
323
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
324 /* Add a title.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
325 @param parent (element or jQuery) the parent node for the new title (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
326 @param text (string) the text of the title
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
327 @param settings (object) additional settings for the title (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
328 @return (element) the new title node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
329 title: function(parent, text, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
330 var args = this._args(arguments, ['text']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
331 var node = this._makeNode(args.parent, 'title', args.settings || {});
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
332 node.appendChild(this._svg.ownerDocument.createTextNode(args.text));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
333 return node;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
334 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
335
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
336 /* Add a description.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
337 @param parent (element or jQuery) the parent node for the new description (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
338 @param text (string) the text of the description
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
339 @param settings (object) additional settings for the description (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
340 @return (element) the new description node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
341 describe: function(parent, text, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
342 var args = this._args(arguments, ['text']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
343 var node = this._makeNode(args.parent, 'desc', args.settings || {});
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
344 node.appendChild(this._svg.ownerDocument.createTextNode(args.text));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
345 return node;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
346 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
347
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
348 /* Add a definitions node.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
349 @param parent (element or jQuery) the parent node for the new definitions (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
350 @param id (string) the ID of this definitions (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
351 @param settings (object) additional settings for the definitions (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
352 @return (element) the new definitions node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
353 defs: function(parent, id, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
354 var args = this._args(arguments, ['id'], ['id']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
355 return this._makeNode(args.parent, 'defs', $.extend(
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
356 (args.id ? {id: args.id} : {}), args.settings || {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
357 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
358
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
359 /* Add a symbol definition.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
360 @param parent (element or jQuery) the parent node for the new symbol (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
361 @param id (string) the ID of this symbol
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
362 @param x1 (number) the left coordinate for this symbol
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
363 @param y1 (number) the top coordinate for this symbol
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
364 @param width (number) the width of this symbol
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
365 @param height (number) the height of this symbol
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
366 @param settings (object) additional settings for the symbol (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
367 @return (element) the new symbol node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
368 symbol: function(parent, id, x1, y1, width, height, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
369 var args = this._args(arguments, ['id', 'x1', 'y1', 'width', 'height']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
370 return this._makeNode(args.parent, 'symbol', $.extend({id: args.id,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
371 viewBox: args.x1 + ' ' + args.y1 + ' ' + args.width + ' ' + args.height},
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
372 args.settings || {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
373 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
374
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
375 /* Add a marker definition.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
376 @param parent (element or jQuery) the parent node for the new marker (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
377 @param id (string) the ID of this marker
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
378 @param refX (number) the x-coordinate for the reference point
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
379 @param refY (number) the y-coordinate for the reference point
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
380 @param mWidth (number) the marker viewport width
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
381 @param mHeight (number) the marker viewport height
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
382 @param orient (string or int) 'auto' or angle (degrees) (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
383 @param settings (object) additional settings for the marker (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
384 @return (element) the new marker node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
385 marker: function(parent, id, refX, refY, mWidth, mHeight, orient, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
386 var args = this._args(arguments, ['id', 'refX', 'refY',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
387 'mWidth', 'mHeight', 'orient'], ['orient']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
388 return this._makeNode(args.parent, 'marker', $.extend(
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
389 {id: args.id, refX: args.refX, refY: args.refY, markerWidth: args.mWidth,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
390 markerHeight: args.mHeight, orient: args.orient || 'auto'}, args.settings || {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
391 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
392
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
393 /* Add a style node.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
394 @param parent (element or jQuery) the parent node for the new node (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
395 @param styles (string) the CSS styles
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
396 @param settings (object) additional settings for the node (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
397 @return (element) the new style node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
398 style: function(parent, styles, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
399 var args = this._args(arguments, ['styles']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
400 var node = this._makeNode(args.parent, 'style', $.extend(
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
401 {type: 'text/css'}, args.settings || {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
402 node.appendChild(this._svg.ownerDocument.createTextNode(args.styles));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
403 if ($.browser.opera) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
404 $('head').append('<style type="text/css">' + args.styles + '</style>');
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
405 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
406 return node;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
407 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
408
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
409 /* Add a script node.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
410 @param parent (element or jQuery) the parent node for the new node (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
411 @param script (string) the JavaScript code
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
412 @param type (string) the MIME type for the code (optional, default 'text/javascript')
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
413 @param settings (object) additional settings for the node (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
414 @return (element) the new script node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
415 script: function(parent, script, type, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
416 var args = this._args(arguments, ['script', 'type'], ['type']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
417 var node = this._makeNode(args.parent, 'script', $.extend(
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
418 {type: args.type || 'text/javascript'}, args.settings || {}));
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
419 node.appendChild(this._svg.ownerDocument.createTextNode(args.script));
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
420 if (!$.browser.mozilla) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
421 $.globalEval(args.script);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
422 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
423 return node;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
424 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
425
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
426 /* Add a linear gradient definition.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
427 Specify all of x1, y1, x2, y2 or none of them.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
428 @param parent (element or jQuery) the parent node for the new gradient (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
429 @param id (string) the ID for this gradient
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
430 @param stops (string[][]) the gradient stops, each entry is
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
431 [0] is offset (0.0-1.0 or 0%-100%), [1] is colour,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
432 [2] is opacity (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
433 @param x1 (number) the x-coordinate of the gradient start (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
434 @param y1 (number) the y-coordinate of the gradient start (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
435 @param x2 (number) the x-coordinate of the gradient end (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
436 @param y2 (number) the y-coordinate of the gradient end (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
437 @param settings (object) additional settings for the gradient (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
438 @return (element) the new gradient node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
439 linearGradient: function(parent, id, stops, x1, y1, x2, y2, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
440 var args = this._args(arguments,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
441 ['id', 'stops', 'x1', 'y1', 'x2', 'y2'], ['x1']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
442 var sets = $.extend({id: args.id},
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
443 (args.x1 != null ? {x1: args.x1, y1: args.y1, x2: args.x2, y2: args.y2} : {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
444 return this._gradient(args.parent, 'linearGradient',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
445 $.extend(sets, args.settings || {}), args.stops);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
446 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
447
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
448 /* Add a radial gradient definition.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
449 Specify all of cx, cy, r, fx, fy or none of them.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
450 @param parent (element or jQuery) the parent node for the new gradient (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
451 @param id (string) the ID for this gradient
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
452 @param stops (string[][]) the gradient stops, each entry
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
453 [0] is offset, [1] is colour, [2] is opacity (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
454 @param cx (number) the x-coordinate of the largest circle centre (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
455 @param cy (number) the y-coordinate of the largest circle centre (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
456 @param r (number) the radius of the largest circle (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
457 @param fx (number) the x-coordinate of the gradient focus (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
458 @param fy (number) the y-coordinate of the gradient focus (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
459 @param settings (object) additional settings for the gradient (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
460 @return (element) the new gradient node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
461 radialGradient: function(parent, id, stops, cx, cy, r, fx, fy, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
462 var args = this._args(arguments,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
463 ['id', 'stops', 'cx', 'cy', 'r', 'fx', 'fy'], ['cx']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
464 var sets = $.extend({id: args.id}, (args.cx != null ?
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
465 {cx: args.cx, cy: args.cy, r: args.r, fx: args.fx, fy: args.fy} : {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
466 return this._gradient(args.parent, 'radialGradient',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
467 $.extend(sets, args.settings || {}), args.stops);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
468 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
469
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
470 /* Add a gradient node. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
471 _gradient: function(parent, name, settings, stops) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
472 var node = this._makeNode(parent, name, settings);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
473 for (var i = 0; i < stops.length; i++) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
474 var stop = stops[i];
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
475 this._makeNode(node, 'stop', $.extend(
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
476 {offset: stop[0], stopColor: stop[1]},
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
477 (stop[2] != null ? {stopOpacity: stop[2]} : {})));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
478 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
479 return node;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
480 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
481
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
482 /* Add a pattern definition.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
483 Specify all of vx, vy, xwidth, vheight or none of them.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
484 @param parent (element or jQuery) the parent node for the new pattern (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
485 @param id (string) the ID for this pattern
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
486 @param x (number) the x-coordinate for the left edge of the pattern
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
487 @param y (number) the y-coordinate for the top edge of the pattern
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
488 @param width (number) the width of the pattern
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
489 @param height (number) the height of the pattern
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
490 @param vx (number) the minimum x-coordinate for view box (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
491 @param vy (number) the minimum y-coordinate for the view box (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
492 @param vwidth (number) the width of the view box (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
493 @param vheight (number) the height of the view box (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
494 @param settings (object) additional settings for the pattern (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
495 @return (element) the new pattern node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
496 pattern: function(parent, id, x, y, width, height, vx, vy, vwidth, vheight, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
497 var args = this._args(arguments, ['id', 'x', 'y', 'width', 'height',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
498 'vx', 'vy', 'vwidth', 'vheight'], ['vx']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
499 var sets = $.extend({id: args.id, x: args.x, y: args.y,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
500 width: args.width, height: args.height}, (args.vx != null ?
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
501 {viewBox: args.vx + ' ' + args.vy + ' ' + args.vwidth + ' ' + args.vheight} : {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
502 return this._makeNode(args.parent, 'pattern', $.extend(sets, args.settings || {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
503 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
504
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
505 /* Add a clip path definition.
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
506 @param parent (element) the parent node for the new element (optional)
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
507 @param id (string) the ID for this path
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
508 @param units (string) either 'userSpaceOnUse' (default) or 'objectBoundingBox' (optional)
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
509 @return (element) the new clipPath node */
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
510 clipPath: function(parent, id, units, settings) {
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
511 var args = this._args(arguments, ['id', 'units']);
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
512 args.units = args.units || 'userSpaceOnUse';
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
513 return this._makeNode(args.parent, 'clipPath', $.extend(
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
514 {id: args.id, clipPathUnits: args.units}, args.settings || {}));
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
515 },
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
516
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
517 /* Add a mask definition.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
518 @param parent (element or jQuery) the parent node for the new mask (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
519 @param id (string) the ID for this mask
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
520 @param x (number) the x-coordinate for the left edge of the mask
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
521 @param y (number) the y-coordinate for the top edge of the mask
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
522 @param width (number) the width of the mask
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
523 @param height (number) the height of the mask
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
524 @param settings (object) additional settings for the mask (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
525 @return (element) the new mask node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
526 mask: function(parent, id, x, y, width, height, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
527 var args = this._args(arguments, ['id', 'x', 'y', 'width', 'height']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
528 return this._makeNode(args.parent, 'mask', $.extend(
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
529 {id: args.id, x: args.x, y: args.y, width: args.width, height: args.height},
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
530 args.settings || {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
531 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
532
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
533 /* Create a new path object.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
534 @return (SVGPath) a new path object */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
535 createPath: function() {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
536 return new SVGPath();
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
537 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
538
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
539 /* Create a new text object.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
540 @return (SVGText) a new text object */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
541 createText: function() {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
542 return new SVGText();
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
543 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
544
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
545 /* Add an embedded SVG element.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
546 Specify all of vx, vy, vwidth, vheight or none of them.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
547 @param parent (element or jQuery) the parent node for the new node (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
548 @param x (number) the x-coordinate for the left edge of the node
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
549 @param y (number) the y-coordinate for the top edge of the node
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
550 @param width (number) the width of the node
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
551 @param height (number) the height of the node
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
552 @param vx (number) the minimum x-coordinate for view box (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
553 @param vy (number) the minimum y-coordinate for the view box (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
554 @param vwidth (number) the width of the view box (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
555 @param vheight (number) the height of the view box (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
556 @param settings (object) additional settings for the node (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
557 @return (element) the new node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
558 svg: function(parent, x, y, width, height, vx, vy, vwidth, vheight, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
559 var args = this._args(arguments, ['x', 'y', 'width', 'height',
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
560 'vx', 'vy', 'vwidth', 'vheight'], ['vx']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
561 var sets = $.extend({x: args.x, y: args.y, width: args.width, height: args.height},
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
562 (args.vx != null ? {viewBox: args.vx + ' ' + args.vy + ' ' +
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
563 args.vwidth + ' ' + args.vheight} : {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
564 return this._makeNode(args.parent, 'svg', $.extend(sets, args.settings || {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
565 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
566
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
567 /* Create a group.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
568 @param parent (element or jQuery) the parent node for the new group (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
569 @param id (string) the ID of this group (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
570 @param settings (object) additional settings for the group (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
571 @return (element) the new group node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
572 group: function(parent, id, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
573 var args = this._args(arguments, ['id'], ['id']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
574 return this._makeNode(args.parent, 'g', $.extend({id: args.id}, args.settings || {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
575 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
576
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
577 /* Add a usage reference.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
578 Specify all of x, y, width, height or none of them.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
579 @param parent (element or jQuery) the parent node for the new node (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
580 @param x (number) the x-coordinate for the left edge of the node (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
581 @param y (number) the y-coordinate for the top edge of the node (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
582 @param width (number) the width of the node (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
583 @param height (number) the height of the node (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
584 @param ref (string) the ID of the definition node
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
585 @param settings (object) additional settings for the node (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
586 @return (element) the new node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
587 use: function(parent, x, y, width, height, ref, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
588 var args = this._args(arguments, ['x', 'y', 'width', 'height', 'ref']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
589 if (typeof args.x == 'string') {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
590 args.ref = args.x;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
591 args.settings = args.y;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
592 args.x = args.y = args.width = args.height = null;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
593 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
594 var node = this._makeNode(args.parent, 'use', $.extend(
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
595 {x: args.x, y: args.y, width: args.width, height: args.height},
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
596 args.settings || {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
597 node.setAttributeNS($.svg.xlinkNS, 'href', args.ref);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
598 return node;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
599 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
600
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
601 /* Add a link, which applies to all child elements.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
602 @param parent (element or jQuery) the parent node for the new link (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
603 @param ref (string) the target URL
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
604 @param settings (object) additional settings for the link (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
605 @return (element) the new link node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
606 link: function(parent, ref, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
607 var args = this._args(arguments, ['ref']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
608 var node = this._makeNode(args.parent, 'a', args.settings);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
609 node.setAttributeNS($.svg.xlinkNS, 'href', args.ref);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
610 return node;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
611 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
612
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
613 /* Add an image.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
614 @param parent (element or jQuery) the parent node for the new image (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
615 @param x (number) the x-coordinate for the left edge of the image
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
616 @param y (number) the y-coordinate for the top edge of the image
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
617 @param width (number) the width of the image
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
618 @param height (number) the height of the image
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
619 @param ref (string) the path to the image
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
620 @param settings (object) additional settings for the image (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
621 @return (element) the new image node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
622 image: function(parent, x, y, width, height, ref, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
623 var args = this._args(arguments, ['x', 'y', 'width', 'height', 'ref']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
624 var node = this._makeNode(args.parent, 'image', $.extend(
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
625 {x: args.x, y: args.y, width: args.width, height: args.height},
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
626 args.settings || {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
627 node.setAttributeNS($.svg.xlinkNS, 'href', args.ref);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
628 return node;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
629 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
630
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
631 /* Draw a path.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
632 @param parent (element or jQuery) the parent node for the new shape (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
633 @param path (string or SVGPath) the path to draw
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
634 @param settings (object) additional settings for the shape (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
635 @return (element) the new shape node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
636 path: function(parent, path, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
637 var args = this._args(arguments, ['path']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
638 return this._makeNode(args.parent, 'path', $.extend(
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
639 {d: (args.path.path ? args.path.path() : args.path)}, args.settings || {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
640 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
641
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
642 /* Draw a rectangle.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
643 Specify both of rx and ry or neither.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
644 @param parent (element or jQuery) the parent node for the new shape (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
645 @param x (number) the x-coordinate for the left edge of the rectangle
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
646 @param y (number) the y-coordinate for the top edge of the rectangle
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
647 @param width (number) the width of the rectangle
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
648 @param height (number) the height of the rectangle
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
649 @param rx (number) the x-radius of the ellipse for the rounded corners (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
650 @param ry (number) the y-radius of the ellipse for the rounded corners (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
651 @param settings (object) additional settings for the shape (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
652 @return (element) the new shape node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
653 rect: function(parent, x, y, width, height, rx, ry, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
654 var args = this._args(arguments, ['x', 'y', 'width', 'height', 'rx', 'ry'], ['rx']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
655 return this._makeNode(args.parent, 'rect', $.extend(
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
656 {x: args.x, y: args.y, width: args.width, height: args.height},
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
657 (args.rx ? {rx: args.rx, ry: args.ry} : {}), args.settings || {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
658 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
659
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
660 /* Draw a circle.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
661 @param parent (element or jQuery) the parent node for the new shape (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
662 @param cx (number) the x-coordinate for the centre of the circle
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
663 @param cy (number) the y-coordinate for the centre of the circle
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
664 @param r (number) the radius of the circle
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
665 @param settings (object) additional settings for the shape (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
666 @return (element) the new shape node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
667 circle: function(parent, cx, cy, r, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
668 var args = this._args(arguments, ['cx', 'cy', 'r']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
669 return this._makeNode(args.parent, 'circle', $.extend(
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
670 {cx: args.cx, cy: args.cy, r: args.r}, args.settings || {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
671 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
672
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
673 /* Draw an ellipse.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
674 @param parent (element or jQuery) the parent node for the new shape (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
675 @param cx (number) the x-coordinate for the centre of the ellipse
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
676 @param cy (number) the y-coordinate for the centre of the ellipse
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
677 @param rx (number) the x-radius of the ellipse
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
678 @param ry (number) the y-radius of the ellipse
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
679 @param settings (object) additional settings for the shape (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
680 @return (element) the new shape node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
681 ellipse: function(parent, cx, cy, rx, ry, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
682 var args = this._args(arguments, ['cx', 'cy', 'rx', 'ry']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
683 return this._makeNode(args.parent, 'ellipse', $.extend(
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
684 {cx: args.cx, cy: args.cy, rx: args.rx, ry: args.ry}, args.settings || {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
685 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
686
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
687 /* Draw a line.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
688 @param parent (element or jQuery) the parent node for the new shape (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
689 @param x1 (number) the x-coordinate for the start of the line
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
690 @param y1 (number) the y-coordinate for the start of the line
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
691 @param x2 (number) the x-coordinate for the end of the line
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
692 @param y2 (number) the y-coordinate for the end of the line
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
693 @param settings (object) additional settings for the shape (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
694 @return (element) the new shape node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
695 line: function(parent, x1, y1, x2, y2, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
696 var args = this._args(arguments, ['x1', 'y1', 'x2', 'y2']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
697 return this._makeNode(args.parent, 'line', $.extend(
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
698 {x1: args.x1, y1: args.y1, x2: args.x2, y2: args.y2}, args.settings || {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
699 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
700
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
701 /* Draw a polygonal line.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
702 @param parent (element or jQuery) the parent node for the new shape (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
703 @param points (number[][]) the x-/y-coordinates for the points on the line
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
704 @param settings (object) additional settings for the shape (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
705 @return (element) the new shape node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
706 polyline: function(parent, points, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
707 var args = this._args(arguments, ['points']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
708 return this._poly(args.parent, 'polyline', args.points, args.settings);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
709 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
710
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
711 /* Draw a polygonal shape.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
712 @param parent (element or jQuery) the parent node for the new shape (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
713 @param points (number[][]) the x-/y-coordinates for the points on the shape
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
714 @param settings (object) additional settings for the shape (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
715 @return (element) the new shape node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
716 polygon: function(parent, points, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
717 var args = this._args(arguments, ['points']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
718 return this._poly(args.parent, 'polygon', args.points, args.settings);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
719 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
720
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
721 /* Draw a polygonal line or shape. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
722 _poly: function(parent, name, points, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
723 var ps = '';
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
724 for (var i = 0; i < points.length; i++) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
725 ps += points[i].join() + ' ';
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
726 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
727 return this._makeNode(parent, name, $.extend(
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
728 {points: $.trim(ps)}, settings || {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
729 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
730
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
731 /* Draw text.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
732 Specify both of x and y or neither of them.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
733 @param parent (element or jQuery) the parent node for the text (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
734 @param x (number or number[]) the x-coordinate(s) for the text (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
735 @param y (number or number[]) the y-coordinate(s) for the text (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
736 @param value (string) the text content or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
737 (SVGText) text with spans and references
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
738 @param settings (object) additional settings for the text (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
739 @return (element) the new text node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
740 text: function(parent, x, y, value, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
741 var args = this._args(arguments, ['x', 'y', 'value']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
742 if (typeof args.x == 'string' && arguments.length < 4) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
743 args.value = args.x;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
744 args.settings = args.y;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
745 args.x = args.y = null;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
746 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
747 return this._text(args.parent, 'text', args.value, $.extend(
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
748 {x: (args.x && isArray(args.x) ? args.x.join(' ') : args.x),
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
749 y: (args.y && isArray(args.y) ? args.y.join(' ') : args.y)},
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
750 args.settings || {}));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
751 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
752
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
753 /* Draw text along a path.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
754 @param parent (element or jQuery) the parent node for the text (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
755 @param path (string) the ID of the path
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
756 @param value (string) the text content or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
757 (SVGText) text with spans and references
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
758 @param settings (object) additional settings for the text (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
759 @return (element) the new text node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
760 textpath: function(parent, path, value, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
761 var args = this._args(arguments, ['path', 'value']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
762 var node = this._text(args.parent, 'textPath', args.value, args.settings || {});
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
763 node.setAttributeNS($.svg.xlinkNS, 'href', args.path);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
764 return node;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
765 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
766
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
767 /* Draw text. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
768 _text: function(parent, name, value, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
769 var node = this._makeNode(parent, name, settings);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
770 if (typeof value == 'string') {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
771 node.appendChild(node.ownerDocument.createTextNode(value));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
772 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
773 else {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
774 for (var i = 0; i < value._parts.length; i++) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
775 var part = value._parts[i];
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
776 if (part[0] == 'tspan') {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
777 var child = this._makeNode(node, part[0], part[2]);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
778 child.appendChild(node.ownerDocument.createTextNode(part[1]));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
779 node.appendChild(child);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
780 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
781 else if (part[0] == 'tref') {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
782 var child = this._makeNode(node, part[0], part[2]);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
783 child.setAttributeNS($.svg.xlinkNS, 'href', part[1]);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
784 node.appendChild(child);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
785 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
786 else if (part[0] == 'textpath') {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
787 var set = $.extend({}, part[2]);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
788 set.href = null;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
789 var child = this._makeNode(node, part[0], set);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
790 child.setAttributeNS($.svg.xlinkNS, 'href', part[2].href);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
791 child.appendChild(node.ownerDocument.createTextNode(part[1]));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
792 node.appendChild(child);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
793 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
794 else { // straight text
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
795 node.appendChild(node.ownerDocument.createTextNode(part[1]));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
796 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
797 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
798 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
799 return node;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
800 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
801
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
802 /* Add a custom SVG element.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
803 @param parent (element or jQuery) the parent node for the new element (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
804 @param name (string) the name of the element
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
805 @param settings (object) additional settings for the element (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
806 @return (element) the new custom node */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
807 other: function(parent, name, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
808 var args = this._args(arguments, ['name']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
809 return this._makeNode(args.parent, args.name, args.settings || {});
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
810 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
811
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
812 /* Create a shape node with the given settings. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
813 _makeNode: function(parent, name, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
814 parent = parent || this._svg;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
815 var node = this._svg.ownerDocument.createElementNS($.svg.svgNS, name);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
816 for (var name in settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
817 var value = settings[name];
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
818 if (value != null && value != null &&
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
819 (typeof value != 'string' || value != '')) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
820 node.setAttribute($.svg._attrNames[name] || name, value);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
821 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
822 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
823 parent.appendChild(node);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
824 return node;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
825 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
826
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
827 /* Add an existing SVG node to the diagram.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
828 @param parent (element or jQuery) the parent node for the new node (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
829 @param node (element) the new node to add or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
830 (string) the jQuery selector for the node or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
831 (jQuery collection) set of nodes to add
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
832 @return (SVGWrapper) this wrapper */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
833 add: function(parent, node) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
834 var args = this._args((arguments.length == 1 ? [null, parent] : arguments), ['node']);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
835 var svg = this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
836 args.parent = args.parent || this._svg;
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
837 args.node = (args.node.jquery ? args.node : $(args.node));
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
838 try {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
839 if ($.svg._renesis) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
840 throw 'Force traversal';
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
841 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
842 args.parent.appendChild(args.node.cloneNode(true));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
843 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
844 catch (e) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
845 args.node.each(function() {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
846 var child = svg._cloneAsSVG(this);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
847 if (child) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
848 args.parent.appendChild(child);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
849 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
850 });
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
851 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
852 return this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
853 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
854
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
855 /* Clone an existing SVG node and add it to the diagram.
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
856 @param parent (element or jQuery) the parent node for the new node (optional)
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
857 @param node (element) the new node to add or
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
858 (string) the jQuery selector for the node or
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
859 (jQuery collection) set of nodes to add
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
860 @return (element[]) collection of new nodes */
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
861 clone: function(parent, node) {
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
862 var svg = this;
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
863 var args = this._args((arguments.length == 1 ? [null, parent] : arguments), ['node']);
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
864 args.parent = args.parent || this._svg;
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
865 args.node = (args.node.jquery ? args.node : $(args.node));
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
866 var newNodes = [];
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
867 args.node.each(function() {
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
868 var child = svg._cloneAsSVG(this);
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
869 if (child) {
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
870 child.id = '';
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
871 args.parent.appendChild(child);
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
872 newNodes.push(child);
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
873 }
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
874 });
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
875 return newNodes;
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
876 },
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
877
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
878 /* SVG nodes must belong to the SVG namespace, so clone and ensure this is so.
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
879 @param node (element) the SVG node to clone
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
880 @return (element) the cloned node */
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
881 _cloneAsSVG: function(node) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
882 var newNode = null;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
883 if (node.nodeType == 1) { // element
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
884 newNode = this._svg.ownerDocument.createElementNS(
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
885 $.svg.svgNS, this._checkName(node.nodeName));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
886 for (var i = 0; i < node.attributes.length; i++) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
887 var attr = node.attributes.item(i);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
888 if (attr.nodeName != 'xmlns' && attr.nodeValue) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
889 if (attr.prefix == 'xlink') {
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
890 newNode.setAttributeNS($.svg.xlinkNS,
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
891 attr.localName || attr.baseName, attr.nodeValue);
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
892 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
893 else {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
894 newNode.setAttribute(this._checkName(attr.nodeName), attr.nodeValue);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
895 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
896 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
897 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
898 for (var i = 0; i < node.childNodes.length; i++) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
899 var child = this._cloneAsSVG(node.childNodes[i]);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
900 if (child) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
901 newNode.appendChild(child);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
902 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
903 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
904 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
905 else if (node.nodeType == 3) { // text
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
906 if ($.trim(node.nodeValue)) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
907 newNode = this._svg.ownerDocument.createTextNode(node.nodeValue);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
908 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
909 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
910 else if (node.nodeType == 4) { // CDATA
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
911 if ($.trim(node.nodeValue)) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
912 try {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
913 newNode = this._svg.ownerDocument.createCDATASection(node.nodeValue);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
914 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
915 catch (e) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
916 newNode = this._svg.ownerDocument.createTextNode(
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
917 node.nodeValue.replace(/&/g, '&amp;').
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
918 replace(/</g, '&lt;').replace(/>/g, '&gt;'));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
919 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
920 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
921 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
922 return newNode;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
923 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
924
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
925 /* Node names must be lower case and without SVG namespace prefix. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
926 _checkName: function(name) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
927 name = (name.substring(0, 1) >= 'A' && name.substring(0, 1) <= 'Z' ?
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
928 name.toLowerCase() : name);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
929 return (name.substring(0, 4) == 'svg:' ? name.substring(4) : name);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
930 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
931
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
932 /* Load an external SVG document.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
933 @param url (string) the location of the SVG document or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
934 the actual SVG content
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
935 @param settings (boolean) see addTo below or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
936 (function) see onLoad below or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
937 (object) additional settings for the load with attributes below:
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
938 addTo (boolean) true to add to what's already there,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
939 or false to clear the canvas first
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
940 changeSize (boolean) true to allow the canvas size to change,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
941 or false to retain the original
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
942 onLoad (function) callback after the document has loaded,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
943 'this' is the container, receives SVG object and
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
944 optional error message as a parameter
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
945 parent (string or element or jQuery) the parent to load
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
946 into, defaults to top-level svg element
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
947 @return (SVGWrapper) this root */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
948 load: function(url, settings) {
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
949 settings = (typeof settings == 'boolean' ? {addTo: settings} :
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
950 (typeof settings == 'function' ? {onLoad: settings} :
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
951 (typeof settings == 'string' ? {parent: settings} :
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
952 (typeof settings == 'object' && settings.nodeName ? {parent: settings} :
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
953 (typeof settings == 'object' && settings.jquery ? {parent: settings} :
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
954 settings || {})))));
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
955 if (!settings.parent && !settings.addTo) {
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
956 this.clear(false);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
957 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
958 var size = [this._svg.getAttribute('width'), this._svg.getAttribute('height')];
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
959 var wrapper = this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
960 // Report a problem with the load
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
961 var reportError = function(message) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
962 message = $.svg.local.errorLoadingText + ': ' + message;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
963 if (settings.onLoad) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
964 settings.onLoad.apply(wrapper._container || wrapper._svg, [wrapper, message]);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
965 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
966 else {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
967 wrapper.text(null, 10, 20, message);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
968 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
969 };
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
970 // Create a DOM from SVG content
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
971 var loadXML4IE = function(data) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
972 var xml = new ActiveXObject('Microsoft.XMLDOM');
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
973 xml.validateOnParse = false;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
974 xml.resolveExternals = false;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
975 xml.async = false;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
976 xml.loadXML(data);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
977 if (xml.parseError.errorCode != 0) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
978 reportError(xml.parseError.reason);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
979 return null;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
980 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
981 return xml;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
982 };
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
983 // Load the SVG DOM
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
984 var loadSVG = function(data) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
985 if (!data) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
986 return;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
987 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
988 if (data.documentElement.nodeName != 'svg') {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
989 var errors = data.getElementsByTagName('parsererror');
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
990 var messages = (errors.length ? errors[0].getElementsByTagName('div') : []); // Safari
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
991 reportError(!errors.length ? '???' :
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
992 (messages.length ? messages[0] : errors[0]).firstChild.nodeValue);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
993 return;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
994 }
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
995 var parent = (settings.parent ? $(settings.parent)[0] : wrapper._svg);
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
996 var attrs = {};
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
997 for (var i = 0; i < data.documentElement.attributes.length; i++) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
998 var attr = data.documentElement.attributes.item(i);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
999 if (!(attr.nodeName == 'version' || attr.nodeName.substring(0, 5) == 'xmlns')) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1000 attrs[attr.nodeName] = attr.nodeValue;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1001 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1002 }
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
1003 wrapper.configure(parent, attrs, !settings.parent);
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1004 var nodes = data.documentElement.childNodes;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1005 for (var i = 0; i < nodes.length; i++) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1006 try {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1007 if ($.svg._renesis) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1008 throw 'Force traversal';
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1009 }
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
1010 parent.appendChild(wrapper._svg.ownerDocument.importNode(nodes[i], true));
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1011 if (nodes[i].nodeName == 'script') {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1012 $.globalEval(nodes[i].textContent);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1013 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1014 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1015 catch (e) {
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
1016 wrapper.add(parent, nodes[i]);
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1017 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1018 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1019 if (!settings.changeSize) {
1050
301ef9bf1965 update jquery.svg.js
hertzhaft
parents: 903
diff changeset
1020 wrapper.configure(parent, {width: size[0], height: size[1]});
756
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1021 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1022 if (settings.onLoad) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1023 settings.onLoad.apply(wrapper._container || wrapper._svg, [wrapper]);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1024 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1025 };
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1026 if (url.match('<svg')) { // Inline SVG
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1027 loadSVG($.browser.msie ? loadXML4IE(url) :
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1028 new DOMParser().parseFromString(url, 'text/xml'));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1029 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1030 else { // Remote SVG
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1031 $.ajax({url: url, dataType: ($.browser.msie ? 'text' : 'xml'),
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1032 success: function(xml) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1033 loadSVG($.browser.msie ? loadXML4IE(xml) : xml);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1034 }, error: function(http, message, exc) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1035 reportError(message + (exc ? ' ' + exc.message : ''));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1036 }});
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1037 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1038 return this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1039 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1040
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1041 /* Delete a specified node.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1042 @param node (element or jQuery) the drawing node to remove
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1043 @return (SVGWrapper) this root */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1044 remove: function(node) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1045 node = (node.jquery ? node[0] : node);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1046 node.parentNode.removeChild(node);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1047 return this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1048 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1049
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1050 /* Delete everything in the current document.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1051 @param attrsToo (boolean) true to clear any root attributes as well,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1052 false to leave them (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1053 @return (SVGWrapper) this root */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1054 clear: function(attrsToo) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1055 if (attrsToo) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1056 this.configure({}, true);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1057 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1058 while (this._svg.firstChild) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1059 this._svg.removeChild(this._svg.firstChild);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1060 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1061 return this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1062 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1063
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1064 /* Serialise the current diagram into an SVG text document.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1065 @param node (SVG element) the starting node (optional)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1066 @return (string) the SVG as text */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1067 toSVG: function(node) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1068 node = node || this._svg;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1069 return (typeof XMLSerializer == 'undefined' ? this._toSVG(node) :
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1070 new XMLSerializer().serializeToString(node));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1071 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1072
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1073 /* Serialise one node in the SVG hierarchy. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1074 _toSVG: function(node) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1075 var svgDoc = '';
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1076 if (!node) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1077 return svgDoc;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1078 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1079 if (node.nodeType == 3) { // Text
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1080 svgDoc = node.nodeValue;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1081 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1082 else if (node.nodeType == 4) { // CDATA
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1083 svgDoc = '<![CDATA[' + node.nodeValue + ']]>';
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1084 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1085 else { // Element
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1086 svgDoc = '<' + node.nodeName;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1087 if (node.attributes) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1088 for (var i = 0; i < node.attributes.length; i++) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1089 var attr = node.attributes.item(i);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1090 if (!($.trim(attr.nodeValue) == '' || attr.nodeValue.match(/^\[object/) ||
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1091 attr.nodeValue.match(/^function/))) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1092 svgDoc += ' ' + (attr.namespaceURI == $.svg.xlinkNS ? 'xlink:' : '') +
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1093 attr.nodeName + '="' + attr.nodeValue + '"';
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1094 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1095 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1096 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1097 if (node.firstChild) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1098 svgDoc += '>';
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1099 var child = node.firstChild;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1100 while (child) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1101 svgDoc += this._toSVG(child);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1102 child = child.nextSibling;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1103 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1104 svgDoc += '</' + node.nodeName + '>';
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1105 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1106 else {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1107 svgDoc += '/>';
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1108 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1109 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1110 return svgDoc;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1111 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1112 });
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1113
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1114 /* Helper to generate an SVG path.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1115 Obtain an instance from the SVGWrapper object.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1116 String calls together to generate the path and use its value:
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1117 var path = root.createPath();
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1118 root.path(null, path.move(100, 100).line(300, 100).line(200, 300).close(), {fill: 'red'});
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1119 or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1120 root.path(null, path.move(100, 100).line([[300, 100], [200, 300]]).close(), {fill: 'red'}); */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1121 function SVGPath() {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1122 this._path = '';
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1123 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1124
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1125 $.extend(SVGPath.prototype, {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1126 /* Prepare to create a new path.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1127 @return (SVGPath) this path */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1128 reset: function() {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1129 this._path = '';
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1130 return this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1131 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1132
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1133 /* Move the pointer to a position.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1134 @param x (number) x-coordinate to move to or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1135 (number[][]) x-/y-coordinates to move to
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1136 @param y (number) y-coordinate to move to (omitted if x is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1137 @param relative (boolean) true for coordinates relative to the current point,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1138 false for coordinates being absolute
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1139 @return (SVGPath) this path */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1140 move: function(x, y, relative) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1141 relative = (isArray(x) ? y : relative);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1142 return this._coords((relative ? 'm' : 'M'), x, y);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1143 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1144
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1145 /* Draw a line to a position.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1146 @param x (number) x-coordinate to move to or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1147 (number[][]) x-/y-coordinates to move to
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1148 @param y (number) y-coordinate to move to (omitted if x is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1149 @param relative (boolean) true for coordinates relative to the current point,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1150 false for coordinates being absolute
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1151 @return (SVGPath) this path */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1152 line: function(x, y, relative) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1153 relative = (isArray(x) ? y : relative);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1154 return this._coords((relative ? 'l' : 'L'), x, y);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1155 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1156
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1157 /* Draw a horizontal line to a position.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1158 @param x (number) x-coordinate to draw to or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1159 (number[]) x-coordinates to draw to
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1160 @param relative (boolean) true for coordinates relative to the current point,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1161 false for coordinates being absolute
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1162 @return (SVGPath) this path */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1163 horiz: function(x, relative) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1164 this._path += (relative ? 'h' : 'H') + (isArray(x) ? x.join(' ') : x);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1165 return this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1166 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1167
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1168 /* Draw a vertical line to a position.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1169 @param y (number) y-coordinate to draw to or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1170 (number[]) y-coordinates to draw to
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1171 @param relative (boolean) true for coordinates relative to the current point,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1172 false for coordinates being absolute
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1173 @return (SVGPath) this path */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1174 vert: function(y, relative) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1175 this._path += (relative ? 'v' : 'V') + (isArray(y) ? y.join(' ') : y);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1176 return this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1177 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1178
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1179 /* Draw a cubic Bézier curve.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1180 @param x1 (number) x-coordinate of beginning control point or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1181 (number[][]) x-/y-coordinates of control and end points to draw to
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1182 @param y1 (number) y-coordinate of beginning control point (omitted if x1 is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1183 @param x2 (number) x-coordinate of ending control point (omitted if x1 is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1184 @param y2 (number) y-coordinate of ending control point (omitted if x1 is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1185 @param x (number) x-coordinate of curve end (omitted if x1 is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1186 @param y (number) y-coordinate of curve end (omitted if x1 is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1187 @param relative (boolean) true for coordinates relative to the current point,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1188 false for coordinates being absolute
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1189 @return (SVGPath) this path */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1190 curveC: function(x1, y1, x2, y2, x, y, relative) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1191 relative = (isArray(x1) ? y1 : relative);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1192 return this._coords((relative ? 'c' : 'C'), x1, y1, x2, y2, x, y);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1193 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1194
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1195 /* Continue a cubic Bézier curve.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1196 Starting control point is the reflection of the previous end control point.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1197 @param x2 (number) x-coordinate of ending control point or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1198 (number[][]) x-/y-coordinates of control and end points to draw to
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1199 @param y2 (number) y-coordinate of ending control point (omitted if x2 is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1200 @param x (number) x-coordinate of curve end (omitted if x2 is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1201 @param y (number) y-coordinate of curve end (omitted if x2 is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1202 @param relative (boolean) true for coordinates relative to the current point,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1203 false for coordinates being absolute
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1204 @return (SVGPath) this path */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1205 smoothC: function(x2, y2, x, y, relative) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1206 relative = (isArray(x2) ? y2 : relative);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1207 return this._coords((relative ? 's' : 'S'), x2, y2, x, y);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1208 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1209
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1210 /* Draw a quadratic Bézier curve.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1211 @param x1 (number) x-coordinate of control point or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1212 (number[][]) x-/y-coordinates of control and end points to draw to
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1213 @param y1 (number) y-coordinate of control point (omitted if x1 is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1214 @param x (number) x-coordinate of curve end (omitted if x1 is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1215 @param y (number) y-coordinate of curve end (omitted if x1 is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1216 @param relative (boolean) true for coordinates relative to the current point,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1217 false for coordinates being absolute
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1218 @return (SVGPath) this path */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1219 curveQ: function(x1, y1, x, y, relative) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1220 relative = (isArray(x1) ? y1 : relative);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1221 return this._coords((relative ? 'q' : 'Q'), x1, y1, x, y);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1222 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1223
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1224 /* Continue a quadratic Bézier curve.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1225 Control point is the reflection of the previous control point.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1226 @param x (number) x-coordinate of curve end or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1227 (number[][]) x-/y-coordinates of points to draw to
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1228 @param y (number) y-coordinate of curve end (omitted if x is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1229 @param relative (boolean) true for coordinates relative to the current point,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1230 false for coordinates being absolute
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1231 @return (SVGPath) this path */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1232 smoothQ: function(x, y, relative) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1233 relative = (isArray(x) ? y : relative);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1234 return this._coords((relative ? 't' : 'T'), x, y);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1235 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1236
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1237 /* Generate a path command with (a list of) coordinates. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1238 _coords: function(cmd, x1, y1, x2, y2, x3, y3) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1239 if (isArray(x1)) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1240 for (var i = 0; i < x1.length; i++) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1241 var cs = x1[i];
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1242 this._path += (i == 0 ? cmd : ' ') + cs[0] + ',' + cs[1] +
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1243 (cs.length < 4 ? '' : ' ' + cs[2] + ',' + cs[3] +
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1244 (cs.length < 6 ? '': ' ' + cs[4] + ',' + cs[5]));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1245 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1246 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1247 else {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1248 this._path += cmd + x1 + ',' + y1 +
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1249 (x2 == null ? '' : ' ' + x2 + ',' + y2 +
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1250 (x3 == null ? '' : ' ' + x3 + ',' + y3));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1251 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1252 return this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1253 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1254
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1255 /* Draw an arc to a position.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1256 @param rx (number) x-radius of arc or
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1257 (number/boolean[][]) x-/y-coordinates and flags for points to draw to
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1258 @param ry (number) y-radius of arc (omitted if rx is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1259 @param xRotate (number) x-axis rotation (degrees, clockwise) (omitted if rx is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1260 @param large (boolean) true to draw the large part of the arc,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1261 false to draw the small part (omitted if rx is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1262 @param clockwise (boolean) true to draw the clockwise arc,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1263 false to draw the anti-clockwise arc (omitted if rx is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1264 @param x (number) x-coordinate of arc end (omitted if rx is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1265 @param y (number) y-coordinate of arc end (omitted if rx is array)
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1266 @param relative (boolean) true for coordinates relative to the current point,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1267 false for coordinates being absolute
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1268 @return (SVGPath) this path */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1269 arc: function(rx, ry, xRotate, large, clockwise, x, y, relative) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1270 relative = (isArray(rx) ? ry : relative);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1271 this._path += (relative ? 'a' : 'A');
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1272 if (isArray(rx)) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1273 for (var i = 0; i < rx.length; i++) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1274 var cs = rx[i];
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1275 this._path += (i == 0 ? '' : ' ') + cs[0] + ',' + cs[1] + ' ' +
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1276 cs[2] + ' ' + (cs[3] ? '1' : '0') + ',' +
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1277 (cs[4] ? '1' : '0') + ' ' + cs[5] + ',' + cs[6];
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1278 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1279 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1280 else {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1281 this._path += rx + ',' + ry + ' ' + xRotate + ' ' +
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1282 (large ? '1' : '0') + ',' + (clockwise ? '1' : '0') + ' ' + x + ',' + y;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1283 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1284 return this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1285 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1286
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1287 /* Close the current path.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1288 @return (SVGPath) this path */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1289 close: function() {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1290 this._path += 'z';
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1291 return this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1292 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1293
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1294 /* Return the string rendering of the specified path.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1295 @return (string) stringified path */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1296 path: function() {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1297 return this._path;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1298 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1299 });
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1300
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1301 SVGPath.prototype.moveTo = SVGPath.prototype.move;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1302 SVGPath.prototype.lineTo = SVGPath.prototype.line;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1303 SVGPath.prototype.horizTo = SVGPath.prototype.horiz;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1304 SVGPath.prototype.vertTo = SVGPath.prototype.vert;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1305 SVGPath.prototype.curveCTo = SVGPath.prototype.curveC;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1306 SVGPath.prototype.smoothCTo = SVGPath.prototype.smoothC;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1307 SVGPath.prototype.curveQTo = SVGPath.prototype.curveQ;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1308 SVGPath.prototype.smoothQTo = SVGPath.prototype.smoothQ;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1309 SVGPath.prototype.arcTo = SVGPath.prototype.arc;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1310
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1311 /* Helper to generate an SVG text object.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1312 Obtain an instance from the SVGWrapper object.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1313 String calls together to generate the text and use its value:
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1314 var text = root.createText();
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1315 root.text(null, x, y, text.string('This is ').
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1316 span('red', {fill: 'red'}).string('!'), {fill: 'blue'}); */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1317 function SVGText() {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1318 this._parts = []; // The components of the text object
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1319 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1320
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1321 $.extend(SVGText.prototype, {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1322 /* Prepare to create a new text object.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1323 @return (SVGText) this text */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1324 reset: function() {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1325 this._parts = [];
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1326 return this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1327 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1328
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1329 /* Add a straight string value.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1330 @param value (string) the actual text
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1331 @return (SVGText) this text object */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1332 string: function(value) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1333 this._parts[this._parts.length] = ['text', value];
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1334 return this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1335 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1336
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1337 /* Add a separate text span that has its own settings.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1338 @param value (string) the actual text
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1339 @param settings (object) the settings for this text
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1340 @return (SVGText) this text object */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1341 span: function(value, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1342 this._parts[this._parts.length] = ['tspan', value, settings];
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1343 return this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1344 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1345
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1346 /* Add a reference to a previously defined text string.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1347 @param id (string) the ID of the actual text
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1348 @param settings (object) the settings for this text
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1349 @return (SVGText) this text object */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1350 ref: function(id, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1351 this._parts[this._parts.length] = ['tref', id, settings];
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1352 return this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1353 },
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1354
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1355 /* Add text drawn along a path.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1356 @param id (string) the ID of the path
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1357 @param value (string) the actual text
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1358 @param settings (object) the settings for this text
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1359 @return (SVGText) this text object */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1360 path: function(id, value, settings) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1361 this._parts[this._parts.length] = ['textpath', value,
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1362 $.extend({href: id}, settings || {})];
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1363 return this;
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1364 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1365 });
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1366
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1367 /* Attach the SVG functionality to a jQuery selection.
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1368 @param command (string) the command to run (optional, default 'attach')
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1369 @param options (object) the new settings to use for these SVG instances
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1370 @return jQuery (object) for chaining further calls */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1371 $.fn.svg = function(options) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1372 var otherArgs = Array.prototype.slice.call(arguments, 1);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1373 if (typeof options == 'string' && options == 'get') {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1374 return $.svg['_' + options + 'SVG'].apply($.svg, [this[0]].concat(otherArgs));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1375 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1376 return this.each(function() {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1377 if (typeof options == 'string') {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1378 $.svg['_' + options + 'SVG'].apply($.svg, [this].concat(otherArgs));
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1379 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1380 else {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1381 $.svg._attachSVG(this, options || {});
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1382 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1383 });
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1384 };
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1385
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1386 /* Determine whether an object is an array. */
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1387 function isArray(a) {
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1388 return (a && a.constructor == Array);
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1389 }
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1390
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1391 // Singleton primary SVG interface
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1392 $.svg = new SVGManager();
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1393
ccf67eaf97ee added jQuery ui and svg javascripts
hertzhaft
parents:
diff changeset
1394 })(jQuery);