commit 3fab03148ef812c59345f8d570dffd475e4f2175
parent bdeb1b26b72cba3ec3ff831e8eb75a78fde5b132
Author: Jan Dankert <devnull@localhost>
Date: Fri, 17 Nov 2017 22:52:21 +0100
Neues JQuery-Plugin zum Inline-Rendering von SVG-Dateien (notwendige für Umstellung auf SVG-Icons).
Diffstat:
3 files changed, 131 insertions(+), 0 deletions(-)
diff --git a/action/IndexAction.class.php b/action/IndexAction.class.php
@@ -291,6 +291,7 @@ class IndexAction extends Action
$js[] = OR_THEMES_EXT_DIR . 'default/js/plugin/jquery-plugin-orTree';
$js[] = OR_THEMES_EXT_DIR . 'default/js/plugin/jquery-plugin-orLoadView';
$js[] = OR_THEMES_EXT_DIR . 'default/js/plugin/jquery-plugin-orAutoheight';
+ $js[] = OR_THEMES_EXT_DIR . 'default/js/plugin/jquery-plugin-svg';
$js[] = OR_THEMES_EXT_DIR . 'default/js/jquery-qrcode';
$js[] = OR_THEMES_EXT_DIR . '../editor/markitup/markitup/jquery.markitup';
$js[] = OR_THEMES_EXT_DIR . '../editor/editor/ckeditor';
diff --git a/themes/default/js/plugin/jquery-plugin-svg.js b/themes/default/js/plugin/jquery-plugin-svg.js
@@ -0,0 +1,64 @@
+/*! jQuery SVG to Inline v0.1.4
+* https://github.com/tiagoporto/jquery-svg-to-inline
+* Copyright (c) 2016 Tiago Porto (tiagoporto.com)
+* Released under the MIT license
+*/
+
+'use strict';
+
+$.fn.svgToInline = function (options) {
+ 'use strict';
+
+ var trigger = {
+ class: this.selector.replace('.', ''),
+ useClass: options && options.useTriggerClass || false
+ };
+
+ this.each(function () {
+ var svg = {
+ currency: $(this),
+ oldClass: '',
+ newClass: '',
+ path: $(this).attr('data') || $(this).attr('src')
+ },
+ request = {
+ element: '',
+ svgTag: '',
+ svgTagWithoutClass: ''
+ },
+ inputClass = $(this).attr('class').split(' '),
+ inputClassLenght = inputClass.length;
+
+ if (inputClassLenght > 0) {
+ for (var i = 0; i < inputClassLenght; ++i) {
+ var space = '';
+
+ if (inputClass[i] === trigger.class && !trigger.useClass) {
+ continue;
+ }
+
+ i !== inputClass.length - 1 && (space = ' ');
+ inputClass[i] && (svg.newClass += inputClass[i] + space);
+ }
+ }
+
+ $.ajax({
+ url: svg.path,
+ dataType: 'text',
+ success: function success(response) {
+ request.element = response.replace(/<[?!][\s\w\"-\/:=?]+>/g, ''), request.svgTag = request.element.match(/<svg[\w\s\t\n:="\\'\/.#-]+>/g);
+ request.svgTagWithoutClass = request.svgTag[0].replace(/class=\"[\w\s-_]+\"/, '');
+ svg.oldClass = request.svgTag[0].match(/class=\"(.*?)\"/);
+
+ // If exist class in svg add to svg.newClass
+ svg.oldClass && svg.oldClass[1] && svg.newClass && (svg.newClass = svg.oldClass[1] + ' ' + svg.newClass);
+
+ svg.newClass !== '' && (svg.newClass = 'class="' + svg.newClass + '"');
+
+ request.svgTagWithoutClass = request.svgTagWithoutClass.replace('>', ' ' + svg.newClass + '>');
+
+ svg.currency.replaceWith(request.element.replace(/<svg[\w\s\t\n:="\\'\/.#-]+>/g, request.svgTagWithoutClass));
+ }
+ });
+ });
+};+
\ No newline at end of file
diff --git a/themes/default/js/plugin/jquery-plugin-svg.min.js b/themes/default/js/plugin/jquery-plugin-svg.min.js
@@ -0,0 +1,64 @@
+/*! jQuery SVG to Inline v0.1.4
+* https://github.com/tiagoporto/jquery-svg-to-inline
+* Copyright (c) 2016 Tiago Porto (tiagoporto.com)
+* Released under the MIT license
+*/
+
+'use strict';
+
+$.fn.svgToInline = function (options) {
+ 'use strict';
+
+ var trigger = {
+ class: this.selector.replace('.', ''),
+ useClass: options && options.useTriggerClass || false
+ };
+
+ this.each(function () {
+ var svg = {
+ currency: $(this),
+ oldClass: '',
+ newClass: '',
+ path: $(this).attr('data') || $(this).attr('src')
+ },
+ request = {
+ element: '',
+ svgTag: '',
+ svgTagWithoutClass: ''
+ },
+ inputClass = $(this).attr('class').split(' '),
+ inputClassLenght = inputClass.length;
+
+ if (inputClassLenght > 0) {
+ for (var i = 0; i < inputClassLenght; ++i) {
+ var space = '';
+
+ if (inputClass[i] === trigger.class && !trigger.useClass) {
+ continue;
+ }
+
+ i !== inputClass.length - 1 && (space = ' ');
+ inputClass[i] && (svg.newClass += inputClass[i] + space);
+ }
+ }
+
+ $.ajax({
+ url: svg.path,
+ dataType: 'text',
+ success: function success(response) {
+ request.element = response.replace(/<[?!][\s\w\"-\/:=?]+>/g, ''), request.svgTag = request.element.match(/<svg[\w\s\t\n:="\\'\/.#-]+>/g);
+ request.svgTagWithoutClass = request.svgTag[0].replace(/class=\"[\w\s-_]+\"/, '');
+ svg.oldClass = request.svgTag[0].match(/class=\"(.*?)\"/);
+
+ // If exist class in svg add to svg.newClass
+ svg.oldClass && svg.oldClass[1] && svg.newClass && (svg.newClass = svg.oldClass[1] + ' ' + svg.newClass);
+
+ svg.newClass !== '' && (svg.newClass = 'class="' + svg.newClass + '"');
+
+ request.svgTagWithoutClass = request.svgTagWithoutClass.replace('>', ' ' + svg.newClass + '>');
+
+ svg.currency.replaceWith(request.element.replace(/<svg[\w\s\t\n:="\\'\/.#-]+>/g, request.svgTagWithoutClass));
+ }
+ });
+ });
+};+
\ No newline at end of file