esvg 4.6.3 → 4.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/esvg/js/core.js.erb +73 -0
- data/lib/esvg/js/embed.js.erb +14 -0
- data/lib/esvg/svgs.rb +12 -89
- data/lib/esvg/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe664ae9953d8b20081e1d3529b1e042d4d04ee27bf6809344dc789a1a39a0ec
|
4
|
+
data.tar.gz: be6e44e7c78d0e29b491e97c31168e3b0c997503b35ab67aeb0f690c0596354e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69d6b09086c7e00930740b007c7795f5b13a93c29952309d1896dc9168047c07b4eee2d5143d815e9b86d13da5673ccd8c15ba1c547b6da7e1d21f6f93ebb393
|
7
|
+
data.tar.gz: '0807ef7dfb18fedfb541d00e45b4b9e7261cb91fe1f96e2fd179987d0d72d82fe3ae1b4bb128ac254adb1b746529590d02dae129b9c97f2884b911a3077636f7'
|
@@ -0,0 +1,73 @@
|
|
1
|
+
(function(){
|
2
|
+
var names
|
3
|
+
|
4
|
+
function attr( source, name ){
|
5
|
+
if (typeof source == 'object')
|
6
|
+
return name+'="'+source.getAttribute(name)+'" '
|
7
|
+
else
|
8
|
+
return name+'="'+source+'" ' }
|
9
|
+
|
10
|
+
function dasherize( input ) {
|
11
|
+
return input.replace(/[\\W,_]/g, '-').replace(/-{2,}/g, '-')
|
12
|
+
}
|
13
|
+
|
14
|
+
function svgName( name ) {
|
15
|
+
return "<%= @config[:prefix] %>-"+dasherize( name )
|
16
|
+
}
|
17
|
+
|
18
|
+
function use( name, options ) {
|
19
|
+
options = options || {}
|
20
|
+
var id = dasherize( name )
|
21
|
+
var symbol = svgs()[id]
|
22
|
+
|
23
|
+
if ( symbol ) {
|
24
|
+
var parent = symbol.parentElement
|
25
|
+
var prefix = parent.dataset.prefix
|
26
|
+
var base = parent.dataset.symbolClass
|
27
|
+
|
28
|
+
var svg = document.createRange().createContextualFragment( '<svg><use xlink:href="#' + prefix + '-' + id + '"/></svg>' ).firstChild;
|
29
|
+
svg.setAttribute( 'class', base + ' ' + prefix + '-' + id + ' ' + ( options.class || '' ).trim() )
|
30
|
+
svg.setAttribute( 'viewBox', symbol.getAttribute( 'viewBox' ) )
|
31
|
+
|
32
|
+
if ( !( options.width || options.height || options.scale ) ) {
|
33
|
+
|
34
|
+
svg.setAttribute('width', symbol.getAttribute('width'))
|
35
|
+
svg.setAttribute('height', symbol.getAttribute('height'))
|
36
|
+
|
37
|
+
} else {
|
38
|
+
|
39
|
+
if ( options.width ) svg.setAttribute( 'width', options.width )
|
40
|
+
if ( options.height ) svg.setAttribute( 'height', options.height )
|
41
|
+
}
|
42
|
+
|
43
|
+
return svg
|
44
|
+
} else {
|
45
|
+
console.error('Cannot find "'+name+'" svg symbol. Ensure that svg scripts are loaded')
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
function svgs(){
|
50
|
+
if ( !names ) {
|
51
|
+
names = {}
|
52
|
+
var symbols = Array.prototype.slice.call( document.querySelectorAll( 'svg[id^=esvg] symbol' ) )
|
53
|
+
symbols.forEach( function( symbol ) {
|
54
|
+
names[symbol.dataset.name] = symbol
|
55
|
+
})
|
56
|
+
}
|
57
|
+
return names
|
58
|
+
}
|
59
|
+
|
60
|
+
var esvg = {
|
61
|
+
svgs: svgs,
|
62
|
+
use: use
|
63
|
+
}
|
64
|
+
|
65
|
+
// Handle Turbolinks page change events
|
66
|
+
if ( window.Turbolinks ) {
|
67
|
+
document.addEventListener( "turbolinks:load", function( event ) { names = null; esvg.svgs() })
|
68
|
+
}
|
69
|
+
|
70
|
+
if( typeof( module ) != 'undefined' ) { module.exports = esvg }
|
71
|
+
else window.esvg = esvg
|
72
|
+
|
73
|
+
})()
|
@@ -0,0 +1,14 @@
|
|
1
|
+
(function(){
|
2
|
+
|
3
|
+
function embed() {
|
4
|
+
if ( !document.body ) return requestAnimationFrame( embed )
|
5
|
+
<%= @embed %>
|
6
|
+
}
|
7
|
+
|
8
|
+
// Handle Turbolinks page change events
|
9
|
+
if ( window.Turbolinks ) {
|
10
|
+
document.addEventListener("turbolinks:load", function(event) { embed() })
|
11
|
+
}
|
12
|
+
|
13
|
+
embed()
|
14
|
+
})()
|
data/lib/esvg/svgs.rb
CHANGED
@@ -176,100 +176,23 @@ module Esvg
|
|
176
176
|
|
177
177
|
private
|
178
178
|
|
179
|
-
def
|
180
|
-
|
179
|
+
def read_js(path)
|
180
|
+
contents = ''
|
181
|
+
path = File.expand_path("js/#{path}.js.erb", File.dirname(__FILE__))
|
181
182
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
if (document.readyState == 'interactive') { embed() }
|
188
|
-
|
189
|
-
// Handle Turbolinks page change events
|
190
|
-
if ( window.Turbolinks ) {
|
191
|
-
document.addEventListener("turbolinks:load", function(event) { embed() })
|
192
|
-
}
|
183
|
+
File.open path do |f|
|
184
|
+
contents = ERB.new(f.read).result(binding)
|
185
|
+
end
|
186
|
+
contents
|
187
|
+
end
|
193
188
|
|
194
|
-
|
195
|
-
|
196
|
-
|
189
|
+
def js( embed )
|
190
|
+
@embed = embed
|
191
|
+
read_js( 'embed' )
|
197
192
|
end
|
198
193
|
|
199
194
|
def js_core
|
200
|
-
|
201
|
-
var names
|
202
|
-
|
203
|
-
function attr( source, name ){
|
204
|
-
if (typeof source == 'object')
|
205
|
-
return name+'="'+source.getAttribute(name)+'" '
|
206
|
-
else
|
207
|
-
return name+'="'+source+'" ' }
|
208
|
-
|
209
|
-
function dasherize( input ) {
|
210
|
-
return input.replace(/[\\W,_]/g, '-').replace(/-{2,}/g, '-')
|
211
|
-
}
|
212
|
-
|
213
|
-
function svgName( name ) {
|
214
|
-
return "#{@config[:prefix]}-"+dasherize( name )
|
215
|
-
}
|
216
|
-
|
217
|
-
function use( name, options ) {
|
218
|
-
options = options || {}
|
219
|
-
var id = dasherize( name )
|
220
|
-
var symbol = svgs()[id]
|
221
|
-
|
222
|
-
if ( symbol ) {
|
223
|
-
var parent = symbol.parentElement
|
224
|
-
var prefix = parent.dataset.prefix
|
225
|
-
var base = parent.dataset.symbolClass
|
226
|
-
|
227
|
-
var svg = document.createRange().createContextualFragment( '<svg><use xlink:href="#' + prefix + '-' + id + '"/></svg>' ).firstChild;
|
228
|
-
svg.setAttribute( 'class', base + ' ' + prefix + '-' + id + ' ' + ( options.class || '' ).trim() )
|
229
|
-
svg.setAttribute( 'viewBox', symbol.getAttribute( 'viewBox' ) )
|
230
|
-
|
231
|
-
if ( !( options.width || options.height || options.scale ) ) {
|
232
|
-
|
233
|
-
svg.setAttribute('width', symbol.getAttribute('width'))
|
234
|
-
svg.setAttribute('height', symbol.getAttribute('height'))
|
235
|
-
|
236
|
-
} else {
|
237
|
-
|
238
|
-
if ( options.width ) svg.setAttribute( 'width', options.width )
|
239
|
-
if ( options.height ) svg.setAttribute( 'height', options.height )
|
240
|
-
}
|
241
|
-
|
242
|
-
return svg
|
243
|
-
} else {
|
244
|
-
console.error('Cannot find "'+name+'" svg symbol. Ensure that svg scripts are loaded')
|
245
|
-
}
|
246
|
-
}
|
247
|
-
|
248
|
-
function svgs(){
|
249
|
-
if ( !names ) {
|
250
|
-
names = {}
|
251
|
-
var symbols = Array.prototype.slice.call( document.querySelectorAll( 'svg[id^=esvg] symbol' ) )
|
252
|
-
symbols.forEach( function( symbol ) {
|
253
|
-
names[symbol.dataset.name] = symbol
|
254
|
-
})
|
255
|
-
}
|
256
|
-
return names
|
257
|
-
}
|
258
|
-
|
259
|
-
var esvg = {
|
260
|
-
svgs: svgs,
|
261
|
-
use: use
|
262
|
-
}
|
263
|
-
|
264
|
-
// Handle Turbolinks page change events
|
265
|
-
if ( window.Turbolinks ) {
|
266
|
-
document.addEventListener( "turbolinks:load", function( event ) { names = null; esvg.svgs() })
|
267
|
-
}
|
268
|
-
|
269
|
-
if( typeof( module ) != 'undefined' ) { module.exports = esvg }
|
270
|
-
else window.esvg = esvg
|
271
|
-
|
272
|
-
})()}
|
195
|
+
read_js( 'core' )
|
273
196
|
end
|
274
197
|
|
275
198
|
def get_alias(name)
|
data/lib/esvg/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: esvg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.6.
|
4
|
+
version: 4.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Mathis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -89,6 +89,8 @@ files:
|
|
89
89
|
- lib/esvg.rb
|
90
90
|
- lib/esvg/helpers.rb
|
91
91
|
- lib/esvg/jekyll_hooks.rb
|
92
|
+
- lib/esvg/js/core.js.erb
|
93
|
+
- lib/esvg/js/embed.js.erb
|
92
94
|
- lib/esvg/railties.rb
|
93
95
|
- lib/esvg/svg.rb
|
94
96
|
- lib/esvg/svgs.rb
|