voltron-svg 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/voltron-svg.js +118 -122
- data/lib/voltron/svg/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2acd5225f79a370f67e5847d61deb97e05fe97c
|
4
|
+
data.tar.gz: 7ed8b5fb3f6baf871e5dc1a0b66c6ef95bfb5905
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 387ae6cefeb855175327f6cd82e84d4b4c672aa8311b598375de981732c525d751d5f9d15d412e582543b1af5cab34ae98f700379392e97093e6b1871ab99f18
|
7
|
+
data.tar.gz: 4bebf67ecbdbe0560336b364e7181b1b6a97ac132a6927bd982c92275331cd73f8558ba407c37fdba1e2d2d07e932e23945f39130c02e99b0d36b8079a25760a
|
@@ -1,134 +1,130 @@
|
|
1
1
|
//= require voltron/svg-injector
|
2
2
|
|
3
3
|
if(Voltron){
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
if(!options['width']) options['width'] = size[0];
|
15
|
-
if(!options['height']) options['height'] = size[1];
|
16
|
-
return $('<img />', this.getDataAttribute(options, ['size', 'svg', 'fallback']));
|
17
|
-
},
|
18
|
-
|
19
|
-
getDataAttribute: function(options, attributes){
|
20
|
-
for(var i=0; i<attributes.length; i++){
|
21
|
-
var attr = attributes[i];
|
22
|
-
if(options[attr]){
|
23
|
-
options['data-' + attr] = options[attr];
|
24
|
-
delete options[attr];
|
25
|
-
}
|
26
|
-
}
|
27
|
-
return options;
|
28
|
-
},
|
29
|
-
|
30
|
-
inject: function(){
|
31
|
-
var svgs = document.querySelectorAll('img[data-svg="true"]:not(.injected-svg)');
|
32
|
-
var options = {
|
33
|
-
each: function(svg){
|
34
|
-
if(svg.getAttribute('data-size')){
|
35
|
-
var dims = svg.getAttribute('data-size').split('x');
|
36
|
-
svg.setAttribute('width', parseFloat(dims[0]));
|
37
|
-
svg.setAttribute('height', parseFloat(dims[1]));
|
38
|
-
}
|
39
|
-
}
|
40
|
-
};
|
41
|
-
SVGInjector(svgs, options);
|
4
|
+
Voltron.addModule('SVG', function(){
|
5
|
+
return {
|
6
|
+
initialize: function(){
|
7
|
+
var svgs = document.querySelectorAll('img[data-svg="true"]:not(.injected-svg)');
|
8
|
+
var options = {
|
9
|
+
each: function(svg){
|
10
|
+
if(svg.getAttribute && svg.getAttribute('data-size')){
|
11
|
+
var dims = svg.getAttribute('data-size').split('x');
|
12
|
+
svg.setAttribute('width', parseFloat(dims[0]));
|
13
|
+
svg.setAttribute('height', parseFloat(dims[1]));
|
42
14
|
}
|
15
|
+
}
|
43
16
|
};
|
44
|
-
|
45
|
-
}
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
readyFired = true;
|
64
|
-
for (var i = 0; i < readyList.length; i++) {
|
65
|
-
// if a callback here happens to add new ready handlers,
|
66
|
-
// the docReady() function will see that it already fired
|
67
|
-
// and will schedule the callback to run right after
|
68
|
-
// this event loop finishes so all handlers will still execute
|
69
|
-
// in order and no new ones will be added to the readyList
|
70
|
-
// while we are processing the list
|
71
|
-
readyList[i].fn.call(window, readyList[i].ctx);
|
72
|
-
}
|
73
|
-
// allow any closures held by these functions to free
|
74
|
-
readyList = [];
|
75
|
-
}
|
17
|
+
SVGInjector(svgs, options);
|
18
|
+
},
|
19
|
+
|
20
|
+
getTag: function(svg, image, options){
|
21
|
+
options = $.extend(options, { src: svg, size: '16x16', svg: true, fallback: image });
|
22
|
+
if(/^[0-9]+$/.test(options['size'].toString())) options['size'] = (options['size'] + 'x' + options['size']);
|
23
|
+
var size = options['size'].split('x');
|
24
|
+
if(!options['width']) options['width'] = size[0];
|
25
|
+
if(!options['height']) options['height'] = size[1];
|
26
|
+
return $('<img />', this.getDataAttribute(options, ['size', 'svg', 'fallback']));
|
27
|
+
},
|
28
|
+
|
29
|
+
getDataAttribute: function(options, attributes){
|
30
|
+
for(var i=0; i<attributes.length; i++){
|
31
|
+
var attr = attributes[i];
|
32
|
+
if(options[attr]){
|
33
|
+
options['data-' + attr] = options[attr];
|
34
|
+
delete options[attr];
|
35
|
+
}
|
76
36
|
}
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
37
|
+
return options;
|
38
|
+
}
|
39
|
+
};
|
40
|
+
}, true);
|
41
|
+
}else{
|
42
|
+
(function(funcName, baseObj) {
|
43
|
+
"use strict";
|
44
|
+
// The public function name defaults to window.docReady
|
45
|
+
// but you can modify the last line of this function to pass in a different object or method name
|
46
|
+
// if you want to put them in a different namespace and those will be used instead of
|
47
|
+
// window.docReady(...)
|
48
|
+
funcName = funcName || "docReady";
|
49
|
+
baseObj = baseObj || window;
|
50
|
+
var readyList = [];
|
51
|
+
var readyFired = false;
|
52
|
+
var readyEventHandlersInstalled = false;
|
53
|
+
|
54
|
+
// call this when the document is ready
|
55
|
+
// this function protects itself against being called more than once
|
56
|
+
function ready() {
|
57
|
+
if (!readyFired) {
|
58
|
+
// this must be set to true before we start calling callbacks
|
59
|
+
readyFired = true;
|
60
|
+
for (var i = 0; i < readyList.length; i++) {
|
61
|
+
// if a callback here happens to add new ready handlers,
|
62
|
+
// the docReady() function will see that it already fired
|
63
|
+
// and will schedule the callback to run right after
|
64
|
+
// this event loop finishes so all handlers will still execute
|
65
|
+
// in order and no new ones will be added to the readyList
|
66
|
+
// while we are processing the list
|
67
|
+
readyList[i].fn.call(window, readyList[i].ctx);
|
82
68
|
}
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
69
|
+
// allow any closures held by these functions to free
|
70
|
+
readyList = [];
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
function readyStateChange() {
|
75
|
+
if ( document.readyState === "complete" ) {
|
76
|
+
ready();
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
// This is the one public interface
|
81
|
+
// docReady(fn, context);
|
82
|
+
// the context argument is optional - if present, it will be passed
|
83
|
+
// as an argument to the callback
|
84
|
+
baseObj[funcName] = function(callback, context) {
|
85
|
+
// if ready has already fired, then just schedule the callback
|
86
|
+
// to fire asynchronously, but right away
|
87
|
+
if (readyFired) {
|
88
|
+
setTimeout(function() {callback(context);}, 1);
|
89
|
+
return;
|
90
|
+
} else {
|
91
|
+
// add the function and context to the list
|
92
|
+
readyList.push({fn: callback, ctx: context});
|
93
|
+
}
|
94
|
+
// if document already ready to go, schedule the ready function to run
|
95
|
+
// IE only safe when readyState is "complete", others safe when readyState is "interactive"
|
96
|
+
if (document.readyState === "complete" || (!document.attachEvent && document.readyState === "interactive")) {
|
97
|
+
setTimeout(ready, 1);
|
98
|
+
} else if (!readyEventHandlersInstalled) {
|
99
|
+
// otherwise if we don't have event handlers installed, install them
|
100
|
+
if (document.addEventListener) {
|
101
|
+
// first choice is DOMContentLoaded event
|
102
|
+
document.addEventListener("DOMContentLoaded", ready, false);
|
103
|
+
// backup is window load event
|
104
|
+
window.addEventListener("load", ready, false);
|
105
|
+
} else {
|
106
|
+
// must be IE
|
107
|
+
document.attachEvent("onreadystatechange", readyStateChange);
|
108
|
+
window.attachEvent("onload", ready);
|
116
109
|
}
|
117
|
-
|
110
|
+
readyEventHandlersInstalled = true;
|
111
|
+
}
|
112
|
+
}
|
113
|
+
})("docReady", window);
|
118
114
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
};
|
130
|
-
SVGInjector(svgs, options);
|
115
|
+
window.injectSVG = function(){
|
116
|
+
var svgs = document.querySelectorAll('img[data-svg="true"]');
|
117
|
+
var options = {
|
118
|
+
each: function(svg){
|
119
|
+
if(svg.getAttribute('data-size')){
|
120
|
+
var dims = svg.getAttribute('data-size').split('x');
|
121
|
+
svg.setAttribute('width', parseFloat(dims[0]));
|
122
|
+
svg.setAttribute('height', parseFloat(dims[1]));
|
123
|
+
}
|
124
|
+
}
|
131
125
|
};
|
126
|
+
SVGInjector(svgs, options);
|
127
|
+
};
|
132
128
|
|
133
|
-
|
129
|
+
docReady(injectSVG);
|
134
130
|
}
|
data/lib/voltron/svg/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: voltron-svg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Hainer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: voltron
|