-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery-ui-svg.js
56 lines (40 loc) · 1.4 KB
/
jquery-ui-svg.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*!
* SVG based on jQuery UI Widget
* Author: SliceMeNice <[email protected]>
* Licensed under the MIT license
*
* Requires UI version 1.9+
*/
( function ( $, document, undefined ) {
$.widget( 'smn.svg', {
options: {
referenceAttributeName: 'data-svg-ref',
svgContentClass: 'svg_content'
},
_create: function () {
var widget = this;
var svgIdentifier = widget.element.attr( widget.options.referenceAttributeName );
if ( !svgIdentifier ) {
throw 'The provided element has no attribute "' + widget.options.referenceAttributeName + '" or the attribute is empty.'
}
var symbolSource = $( '#' + svgIdentifier ).get( 0 );
if ( !symbolSource ) {
throw 'Could not find an SVG symbol source with id "' + svgIdentifier + '".';
}
var svg = document.createElementNS( 'http://www.w3.org/2000/svg', 'svg' );
for ( var k = 0; k < symbolSource.childNodes.length; ++k ) {
svg.appendChild( symbolSource.childNodes[ k ].cloneNode( true ) );
}
svg.setAttribute( 'viewBox', symbolSource.getAttribute( 'viewBox' ) );
widget.$svgContent = $( '<div></div>' );
widget.$svgContent.addClass( widget.options.svgContentClass );
widget.$svgContent.append( svg );
widget.element.append( widget.$svgContent );
},
_destroy: function () {
var widget = this;
widget.$svgContent.remove();
widget.$svgContent = undefined;
}
} );
} )( jQuery, document );