Skip to content
Snippets Groups Projects
Commit f87a03a9 authored by Rolf Niepraschk's avatar Rolf Niepraschk
Browse files

"vl-jq-utils.js" nach "web-apps"

parent 37701101
No related branches found
No related tags found
No related merge requests found
/**
* @author Rolf Niepraschk (Rolf.Niepraschk@ptb.de)
* version: 2013-09-05
*/
// https://github.com/umdjs/umd/blob/master/jqueryPlugin.js
/*
* Defines a jQuery plugin that works with AMD and browser globals.
* https://github.com/umdjs/umd/blob/master/jqueryPlugin.js
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
requirejs.config(
{
paths: {
'jquery.rule': 'jquery.rule-1.0.2-min'
},
shim: {
'jquery.rule': [ 'jquery' ]
}
});
define(['jquery','jquery.rule'], factory);
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
/**
* Transformiert jedes selektierte Jquery-Objekt zu inline-SVG. Eine
* der folgenden Voraussetzungen muss erfüllt sein:
* 1. Die Funktion getSVGDocument ist existent (object- oder embed-Tag)
* 2. Es handelt sich um ein img-Tag, dessen src-Attribut SVG-Code adressiert.
* 3. Die css-Eigenschaft 'background-image' ist wirksam und adressiert
* SVG-Code.
* @param {function} ready Aufruf nach kompletter Abarbeitung (optional)
* @return {object} Jquery-Objekte
*/
function toInlineSVG(ready) {
var selector = this.selector, backgClasses = [], length = this.length;
function makeSVG($target, $s, id, cl, index) {
if ($s.length) {// komplette Jquery-Struktur (SVG-Dokument)?
var $svg = $s.find('svg').removeAttr('xmlns:a').attr('id', id);
if (cl) $svg.attr('class', cl);
$svg.replaceAll($target);
}
if (index+1 == length) {
var cl = '.' + backgClasses.join(' ').split(/\s/).join(',.');
$.rule(cl).append('background-image:none;');
if (typeof ready == 'function') ready();
}
}
if (this.length) {
this.each(function(idx, el){
var $el = $(el);
// Id und Klassen retten.
var id = $el.attr('id'), cl = $el.attr('class');
if (el.getSVGDocument) {// Funktion existent?
var $svg = $(el.getSVGDocument());
makeSVG($el, $svg, id, cl, idx);
} else if (el.tagName == 'IMG') {
var url = $el.attr('src');
$.get(url, function(data) {
makeSVG($el, $(data), id, cl, idx);
});
} else {
var url = document.defaultView.getComputedStyle(el, null).
getPropertyValue('background-image').replace(/^url\(["']?/, '').
replace(/["']?\)$/, '');
if (url.length) {// background-image?
backgClasses.push(cl);
$.get(url, function(data) {
makeSVG($el, $(data), id, cl, idx);
});
}
}
});
} else {
if (typeof ready == 'function') ready();
}
//return this;
}
$.fn.toInlineSVG = toInlineSVG;
}));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment