voltron-svg 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3448802c6861d90ae98bc4144c5350c6a6812faa
|
|
4
|
+
data.tar.gz: a34f1de164a5b6590da425181155554df638f517
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b9643432fe2240547f93a8b03de927b0dffb146e9186993f6cda7f3c81aee1657325795396ddcfde754e2d0098690352350b222449e6acaa1a741d58719e4aad
|
|
7
|
+
data.tar.gz: 199ebd0d2fbd323a50395cbaf7a14229170cc7134c03e6eacd18297b1abe29d63edc056e855ba65c11caf72f201fc2c7c987a35eea348ae55ce9e95625c15c3b
|
|
@@ -5,5 +5,4 @@
|
|
|
5
5
|
* Copyright (c) 2014-2015 Waybury <hello@waybury.com>
|
|
6
6
|
* @license MIT
|
|
7
7
|
*/
|
|
8
|
-
!function(t,e){"use strict";function r(t){t=t.split(" ");for(var e={},r=t.length,n=[];r--;)e.hasOwnProperty(t[r])||(e[t[r]]=1,n.unshift(t[r]));return n.join(" ")}var n="file:"===t.location.protocol,i=e.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure","1.1"),o=Array.prototype.forEach||function(t,e){if(void 0===this||null===this||"function"!=typeof t)throw new TypeError;var r,n=this.length>>>0;for(r=0;n>r;++r)r in this&&t.call(e,this[r],r,this)},a={},l=0,s=[],u=[],c={},f=function(t){return t.cloneNode(!0)},p=function(t,e){u[t]=u[t]||[],u[t].push(e)},d=function(t){for(var e=0,r=u[t].length;r>e;e++)!function(e){setTimeout(function(){u[t][e](f(a[t]))},0)}(e)},v=function(e,r){if(void 0!==a[e])a[e]instanceof SVGSVGElement?r(f(a[e])):p(e,r);else{if(!t.XMLHttpRequest)return r("Browser does not support XMLHttpRequest"),!1;a[e]={},p(e,r);var i=new XMLHttpRequest;i.onreadystatechange=function(){if(4===i.readyState){if(404===i.status||null===i.responseXML)return r("Unable to load SVG file: "+e),n&&r("Note: SVG injection ajax calls do not work locally without adjusting security setting in your browser. Or consider using a local webserver."),r(),!1;if(!(200===i.status||n&&0===i.status))return r("There was a problem injecting the SVG: "+i.status+" "+i.statusText),!1;if(i.responseXML instanceof Document)a[e]=i.responseXML.documentElement;else if(DOMParser&&DOMParser instanceof Function){var t;try{var o=new DOMParser;t=o.parseFromString(i.responseText,"text/xml")}catch(l){t=void 0}if(!t||t.getElementsByTagName("parsererror").length)return r("Unable to parse SVG file: "+e),!1;a[e]=t.documentElement}d(e)}},i.open("GET",e),i.overrideMimeType&&i.overrideMimeType("text/xml"),i.send()}},h=function(e,n,a,u){var f=e.getAttribute("data-src")||e.getAttribute("src");if(!/\.svg/i.test(f))return void u("Attempted to inject a file with a non-svg extension: "+f);if(!i){var p=e.getAttribute("data-fallback")||e.getAttribute("data-png");return void(p?(e.setAttribute("src",p),u(null)):a?(e.setAttribute("src",a+"/"+f.split("/").pop().replace(".svg",".png")),u(null)):u("This browser does not support SVG and no PNG fallback was defined."))}-1===s.indexOf(e)&&(s.push(e),e.setAttribute("src",""),v(f,function(i){if("undefined"==typeof i||"string"==typeof i)return u(i),!1;var a=e.getAttribute("id");a&&i.setAttribute("id",a);var p=e.getAttribute("title");p&&i.setAttribute("title",p);var d=[].concat(i.getAttribute("class")||[],"injected-svg",e.getAttribute("class")||[]).join(" ");i.setAttribute("class",r(d));var v=e.getAttribute("style");v&&i.setAttribute("style",v);var h=[].filter.call(e.attributes,function(t){return/^data-\w[\w\-]*$/.test(t.name)});o.call(h,function(t){t.name&&t.value&&i.setAttribute(t.name,t.value)});var g,m,b,y,A,w={clipPath:["clip-path"],"color-profile":["color-profile"],cursor:["cursor"],filter:["filter"],linearGradient:["fill","stroke"],marker:["marker","marker-start","marker-mid","marker-end"],mask:["mask"],pattern:["fill","stroke"],radialGradient:["fill","stroke"]};Object.keys(w).forEach(function(t){g=t,b=w[t],m=i.querySelectorAll("defs "+g+"[id]");for(var e=0,r=m.length;r>e;e++){y=m[e].id,A=y+"-"+l;var n;o.call(b,function(t){n=i.querySelectorAll("["+t+'*="'+y+'"]');for(var e=0,r=n.length;r>e;e++)n[e].setAttribute(t,"url(#"+A+")")}),m[e].id=A}}),i.removeAttribute("xmlns:a");for(var x,S,k=i.querySelectorAll("script"),j=[],G=0,T=k.length;T>G;G++)S=k[G].getAttribute("type"),S&&"application/ecmascript"!==S&&"application/javascript"!==S||(x=k[G].innerText||k[G].textContent,j.push(x),i.removeChild(k[G]));if(j.length>0&&("always"===n||"once"===n&&!c[f])){for(var M=0,V=j.length;V>M;M++)new Function(j[M])(t);c[f]=!0}var E=i.querySelectorAll("style");o.call(E,function(t){t.textContent+=""}),e.parentNode.replaceChild(i,e),delete s[s.indexOf(e)],e=null,l++,u(i)}))},g=function(t,e,r){e=e||{};var n=e.evalScripts||"always",i=e.pngFallback||!1,a=e.each;if(void 0!==t.length){var l=0;o.call(t,function(e){h(e,n,i,function(e){a&&"function"==typeof a&&a(e),r&&t.length===++l&&r(l)})})}else t?h(t,n,i,function(e){a&&"function"==typeof a&&a(e),r&&r(1),t=null}):r&&r(0)};"object"==typeof module&&"object"==typeof module.exports?module.exports=exports=g:"function"==typeof define&&define.amd?define(function(){return g}):"object"==typeof t&&(t.SVGInjector=g)}(window,document);
|
|
9
|
-
//# sourceMappingURL=svg-injector.map.js
|
|
8
|
+
!function(t,e){"use strict";function r(t){t=t.split(" ");for(var e={},r=t.length,n=[];r--;)e.hasOwnProperty(t[r])||(e[t[r]]=1,n.unshift(t[r]));return n.join(" ")}var n="file:"===t.location.protocol,i=e.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure","1.1"),o=Array.prototype.forEach||function(t,e){if(void 0===this||null===this||"function"!=typeof t)throw new TypeError;var r,n=this.length>>>0;for(r=0;n>r;++r)r in this&&t.call(e,this[r],r,this)},a={},l=0,s=[],u=[],c={},f=function(t){return t.cloneNode(!0)},p=function(t,e){u[t]=u[t]||[],u[t].push(e)},d=function(t){for(var e=0,r=u[t].length;r>e;e++)!function(e){setTimeout(function(){u[t][e](f(a[t]))},0)}(e)},v=function(e,r){if(void 0!==a[e])a[e]instanceof SVGSVGElement?r(f(a[e])):p(e,r);else{if(!t.XMLHttpRequest)return r("Browser does not support XMLHttpRequest"),!1;a[e]={},p(e,r);var i=new XMLHttpRequest;i.onreadystatechange=function(){if(4===i.readyState){if(404===i.status||null===i.responseXML)return r("Unable to load SVG file: "+e),n&&r("Note: SVG injection ajax calls do not work locally without adjusting security setting in your browser. Or consider using a local webserver."),r(),!1;if(!(200===i.status||n&&0===i.status))return r("There was a problem injecting the SVG: "+i.status+" "+i.statusText),!1;if(i.responseXML instanceof Document)a[e]=i.responseXML.documentElement;else if(DOMParser&&DOMParser instanceof Function){var t;try{var o=new DOMParser;t=o.parseFromString(i.responseText,"text/xml")}catch(l){t=void 0}if(!t||t.getElementsByTagName("parsererror").length)return r("Unable to parse SVG file: "+e),!1;a[e]=t.documentElement}d(e)}},i.open("GET",e),i.overrideMimeType&&i.overrideMimeType("text/xml"),i.send()}},h=function(e,n,a,u){var f=e.getAttribute("data-src")||e.getAttribute("src");if(!/\.svg/i.test(f))return void u("Attempted to inject a file with a non-svg extension: "+f);if(!i){var p=e.getAttribute("data-fallback")||e.getAttribute("data-png");return void(p?(e.setAttribute("src",p),u(null)):a?(e.setAttribute("src",a+"/"+f.split("/").pop().replace(".svg",".png")),u(null)):u("This browser does not support SVG and no PNG fallback was defined."))}-1===s.indexOf(e)&&(s.push(e),e.setAttribute("src",""),v(f,function(i){if("undefined"==typeof i||"string"==typeof i)return u(i),!1;var a=e.getAttribute("id");a&&i.setAttribute("id",a);var p=e.getAttribute("title");p&&i.setAttribute("title",p);var d=[].concat(i.getAttribute("class")||[],"injected-svg",e.getAttribute("class")||[]).join(" ");i.setAttribute("class",r(d));var v=e.getAttribute("style");v&&i.setAttribute("style",v);var h=[].filter.call(e.attributes,function(t){return/^data-\w[\w\-]*$/.test(t.name)});o.call(h,function(t){t.name&&t.value&&i.setAttribute(t.name,t.value)});var g,m,b,y,A,w={clipPath:["clip-path"],"color-profile":["color-profile"],cursor:["cursor"],filter:["filter"],linearGradient:["fill","stroke"],marker:["marker","marker-start","marker-mid","marker-end"],mask:["mask"],pattern:["fill","stroke"],radialGradient:["fill","stroke"]};Object.keys(w).forEach(function(t){g=t,b=w[t],m=i.querySelectorAll("defs "+g+"[id]");for(var e=0,r=m.length;r>e;e++){y=m[e].id,A=y+"-"+l;var n;o.call(b,function(t){n=i.querySelectorAll("["+t+'*="'+y+'"]');for(var e=0,r=n.length;r>e;e++)n[e].setAttribute(t,"url(#"+A+")")}),m[e].id=A}}),i.removeAttribute("xmlns:a");for(var x,S,k=i.querySelectorAll("script"),j=[],G=0,T=k.length;T>G;G++)S=k[G].getAttribute("type"),S&&"application/ecmascript"!==S&&"application/javascript"!==S||(x=k[G].innerText||k[G].textContent,j.push(x),i.removeChild(k[G]));if(j.length>0&&("always"===n||"once"===n&&!c[f])){for(var M=0,V=j.length;V>M;M++)new Function(j[M])(t);c[f]=!0}var E=i.querySelectorAll("style");o.call(E,function(t){t.textContent+=""}),e.parentNode.replaceChild(i,e),delete s[s.indexOf(e)],e=null,l++,u(i)}))},g=function(t,e,r){e=e||{};var n=e.evalScripts||"always",i=e.pngFallback||!1,a=e.each;if(void 0!==t.length){var l=0;o.call(t,function(e){h(e,n,i,function(e){a&&"function"==typeof a&&a(e),r&&t.length===++l&&r(l)})})}else t?h(t,n,i,function(e){a&&"function"==typeof a&&a(e),r&&r(1),t=null}):r&&r(0)};"object"==typeof module&&"object"==typeof module.exports?module.exports=exports=g:"function"==typeof define&&define.amd?define(function(){return g}):"object"==typeof t&&(t.SVGInjector=g)}(window,document);
|
|
@@ -1,130 +1,39 @@
|
|
|
1
|
-
//= require
|
|
1
|
+
//= require svg-injector
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
svg.setAttribute('height', parseFloat(dims[1]));
|
|
14
|
-
}
|
|
3
|
+
Voltron.addModule('SVG', function(){
|
|
4
|
+
return {
|
|
5
|
+
initialize: function(){
|
|
6
|
+
var svgs = document.querySelectorAll('img[data-svg="true"]:not(.injected-svg)');
|
|
7
|
+
var options = {
|
|
8
|
+
each: function(svg){
|
|
9
|
+
if(svg.getAttribute && svg.getAttribute('data-size')){
|
|
10
|
+
var dims = svg.getAttribute('data-size').split('x');
|
|
11
|
+
svg.setAttribute('width', parseFloat(dims[0]));
|
|
12
|
+
svg.setAttribute('height', parseFloat(dims[1]));
|
|
15
13
|
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
SVGInjector(svgs, options);
|
|
17
|
+
},
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
getTag: function(svg, image, options){
|
|
20
|
+
options = $.extend({ src: svg, size: '16x16', svg: true, fallback: image }, options);
|
|
21
|
+
if(/^[0-9]+$/.test(options['size'].toString())) options['size'] = (options['size'] + 'x' + options['size']);
|
|
22
|
+
var size = options['size'].split('x');
|
|
23
|
+
if(!options['width']) options['width'] = size[0];
|
|
24
|
+
if(!options['height']) options['height'] = size[1];
|
|
25
|
+
return $('<img />', this.getDataAttribute(options, ['size', 'svg', 'fallback']));
|
|
26
|
+
},
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
}
|
|
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);
|
|
68
|
-
}
|
|
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);
|
|
28
|
+
getDataAttribute: function(options, attributes){
|
|
29
|
+
for(var i=0; i<attributes.length; i++){
|
|
30
|
+
var attr = attributes[i];
|
|
31
|
+
if(options[attr]){
|
|
32
|
+
options['data-' + attr] = options[attr];
|
|
33
|
+
delete options[attr];
|
|
109
34
|
}
|
|
110
|
-
readyEventHandlersInstalled = true;
|
|
111
35
|
}
|
|
36
|
+
return options;
|
|
112
37
|
}
|
|
113
|
-
})("docReady", window);
|
|
114
|
-
|
|
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
|
-
}
|
|
125
|
-
};
|
|
126
|
-
SVGInjector(svgs, options);
|
|
127
38
|
};
|
|
128
|
-
|
|
129
|
-
docReady(injectSVG);
|
|
130
|
-
}
|
|
39
|
+
}, true);
|
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.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eric Hainer
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-
|
|
11
|
+
date: 2017-03-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: voltron
|
|
@@ -151,8 +151,8 @@ files:
|
|
|
151
151
|
- LICENSE.txt
|
|
152
152
|
- README.md
|
|
153
153
|
- Rakefile
|
|
154
|
+
- app/assets/javascripts/svg-injector.js
|
|
154
155
|
- app/assets/javascripts/voltron-svg.js
|
|
155
|
-
- app/assets/javascripts/voltron/svg-injector.js
|
|
156
156
|
- bin/console
|
|
157
157
|
- bin/setup
|
|
158
158
|
- lib/generators/voltron/svg/install_generator.rb
|
|
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
182
182
|
version: '0'
|
|
183
183
|
requirements: []
|
|
184
184
|
rubyforge_project:
|
|
185
|
-
rubygems_version: 2.
|
|
185
|
+
rubygems_version: 2.5.2
|
|
186
186
|
signing_key:
|
|
187
187
|
specification_version: 4
|
|
188
188
|
summary: Adds SVG helpers and on-the-fly generation of fallback images to rails
|