@simhub2/justflipit 3.0.1 → 3.1.1

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.
@@ -1,11 +1,11 @@
1
1
  /*!
2
- * Modern justFlipIt v3.0.0
2
+ * justFlipIt v3.1.1
3
3
  * https://github.com/SimHub/justFlipIt
4
4
  *
5
- * Copyright simon Lackmann
5
+ * Copyright SimHub
6
6
  * Released under the MIT license
7
7
  *
8
- * Date: 2023
8
+ * Date: 2025
9
9
  */
10
10
 
11
11
  (function (root, factory) {
@@ -20,14 +20,13 @@
20
20
  "use strict";
21
21
 
22
22
  // Feature detection
23
- const supportsGrid =
24
- typeof CSS !== "undefined" &&
23
+ const supportsGrid = typeof CSS !== "undefined" &&
25
24
  CSS.supports &&
26
25
  CSS.supports("display", "grid");
27
- const supportsWebAnimations =
28
- typeof Element !== "undefined" && "animate" in Element.prototype;
29
- const supportsCustomProperties =
30
- window.CSS && CSS.supports && CSS.supports("color", "var(--test)");
26
+ const supportsWebAnimations = typeof Element !== "undefined" &&
27
+ "animate" in Element.prototype;
28
+ const supportsCustomProperties = window.CSS && CSS.supports &&
29
+ CSS.supports("color", "var(--test)");
31
30
 
32
31
  // Style generation based on browser support
33
32
  function generateStyles() {
@@ -217,6 +216,8 @@
217
216
  Style: [], // Custom styles
218
217
  Duration: 400, // Animation duration in ms
219
218
  Easing: "ease-in-out", // Animation easing function
219
+ preserveClasses: true, // NEU
220
+ preserveStyles: true, // NEU
220
221
  },
221
222
  options,
222
223
  );
@@ -256,79 +257,61 @@
256
257
  const originalElement = this.element;
257
258
  const originalClassName = this.originalClassName;
258
259
 
259
- // Create panel structure
260
+ // Panel-Struktur erzeugen
260
261
  const hoverPanel = document.createElement(this.originalTagName);
261
262
  addClass(hoverPanel, "hover");
262
263
  addClass(hoverPanel, "_justFlipIt_panel");
263
-
264
- // Create front wrapper
265
264
  const frontWrapper = document.createElement("div");
266
265
  addClass(frontWrapper, "front");
267
-
268
- // Clone element for back side if no template provided
269
- const clone = originalElement.cloneNode(true);
270
- clone.className = ""; // Remove classes
271
-
272
- // Create back wrapper
273
266
  const backWrapper = document.createElement("div");
274
267
  addClass(backWrapper, this.backClass);
275
- if (originalClassName) {
276
- originalClassName.split(" ").forEach((cls) => {
277
- if (cls) addClass(backWrapper, cls);
268
+
269
+ // NEU: Klassen übernehmen (Panel, .front, .backY)
270
+ if (this.settings.preserveClasses && originalElement.classList.length) {
271
+ originalElement.classList.forEach((cls) => {
272
+ if (!hoverPanel.classList.contains(cls)) {
273
+ hoverPanel.classList.add(cls);
274
+ }
275
+ if (frontWrapper && !frontWrapper.classList.contains(cls)) {
276
+ frontWrapper.classList.add(cls);
277
+ }
278
+ if (backWrapper && !backWrapper.classList.contains(cls)) {
279
+ backWrapper.classList.add(cls);
280
+ }
278
281
  });
279
282
  }
280
283
 
281
- // PATCH: Styles übernehmen und Original komplett transparent machen
282
- copyStyles(originalElement, frontWrapper);
283
- copyStyles(originalElement, backWrapper);
284
+ // NEU: Inline-Styles übernehmen (nur auf Panel)
285
+ if (
286
+ this.settings.preserveStyles && originalElement.getAttribute("style")
287
+ ) {
288
+ hoverPanel.setAttribute(
289
+ "style",
290
+ (hoverPanel.getAttribute("style") || "") +
291
+ ";" + originalElement.getAttribute("style"),
292
+ );
293
+ }
284
294
 
285
- // NEU: Wende benutzerdefinierte Animationseinstellungen an
286
- applyAnimationSettings(
287
- frontWrapper,
288
- this.settings.Duration,
289
- this.settings.Easing,
290
- );
291
- applyAnimationSettings(
292
- backWrapper,
293
- this.settings.Duration,
294
- this.settings.Easing,
295
- );
295
+ // Nur den INHALT übernehmen!
296
+ frontWrapper.innerHTML = originalElement.innerHTML;
296
297
 
297
- // Mache das Original komplett transparent und ohne Border/Shadow/usw.
298
- originalElement.style.all = "inherit"; // Reset alles zur Sicherheit
299
- originalElement.style.background = "transparent";
300
- originalElement.style.backgroundColor = "transparent";
301
- originalElement.style.backgroundImage = "none";
302
- originalElement.style.border = "none";
303
- originalElement.style.borderRadius = "0";
304
- originalElement.style.boxShadow = "none";
305
- originalElement.style.outline = "none";
306
-
307
- // If template provided, use that instead of clone
308
298
  if (this.settings.Template) {
309
299
  backWrapper.innerHTML = this.settings.Template;
310
300
  } else {
311
- backWrapper.appendChild(clone);
301
+ backWrapper.innerHTML = originalElement.innerHTML;
312
302
  }
313
303
 
314
- // Restructure DOM
304
+ // Panel einfügen und Original entfernen
315
305
  originalElement.parentNode.insertBefore(hoverPanel, originalElement);
316
- frontWrapper.appendChild(originalElement);
317
306
  hoverPanel.appendChild(frontWrapper);
318
307
  hoverPanel.appendChild(backWrapper);
308
+ originalElement.parentNode.removeChild(originalElement);
319
309
 
320
- // Copy original classes to hover panel
321
- if (originalClassName) {
322
- originalClassName.split(" ").forEach((cls) => {
323
- if (cls) addClass(hoverPanel, cls);
324
- });
325
- }
326
-
327
- // Apply styles
310
+ // Panel-Größe und Styles übernehmen
328
311
  hoverPanel.style.width = this.elementWidth;
329
312
  hoverPanel.style.height = this.elementHeight;
330
313
 
331
- // Apply custom styles
314
+ // Custom Styles aus Option anwenden
332
315
  if (this.settings.Style && this.settings.Style.length) {
333
316
  this.settings.Style.forEach((styleObj) => {
334
317
  if (styleObj.el) {
@@ -344,10 +327,10 @@
344
327
  });
345
328
  }
346
329
 
347
- // Set up event handlers
330
+ // Events setzen
348
331
  this._setupEvents(hoverPanel);
349
332
 
350
- // Store reference to original element
333
+ // Referenzen speichern
351
334
  this.hoverPanel = hoverPanel;
352
335
  this.frontWrapper = frontWrapper;
353
336
  this.backWrapper = backWrapper;
@@ -1 +1 @@
1
- ((t,e)=>{"function"==typeof define&&define.amd?define([],e):"object"==typeof module&&module.exports?module.exports=e():t.justFlipIt=e()})("undefined"!=typeof self?self:this,function(){"undefined"!=typeof CSS&&CSS.supports&&CSS.supports("display","grid");let a="undefined"!=typeof Element&&"animate"in Element.prototype;window.CSS&&CSS.supports&&CSS.supports("color","var(--test)");function i(t,e){return window.getComputedStyle(t,null).getPropertyValue(e)}function o(t,e){t.classList?t.classList.add(e):t.className+=" "+e}function n(t,e,s){e=`transform ${e/1e3}s `+s;t.style.transition=e,t.style.WebkitTransition=e,t.style.MozTransition=e}function l(t,e){let s=window.getComputedStyle(t);["background","backgroundColor","backgroundImage","backgroundPosition","backgroundRepeat","backgroundSize","borderRadius","borderTopLeftRadius","borderTopRightRadius","borderBottomLeftRadius","borderBottomRightRadius","border","borderTop","borderRight","borderBottom","borderLeft","boxShadow","color","opacity"].forEach(t=>{s[t]&&"none"!==s[t]&&"initial"!==s[t]&&""!==s[t]&&(e.style[t]=s[t])})}function s(t,e,s,i,r="ease-in-out"){a?t.animate([{transform:e},{transform:s}],{duration:i,easing:r,fill:"forwards"}):(t.style.transform=s,t.style.webkitTransform=s,t.style.mozTransform=s)}let r=new WeakMap;class p{constructor(t,e={}){var s;document.querySelector('[data-justflipitstyle="justFlipIt"]')||((s=document.createElement("style")).setAttribute("data-justflipitstyle","justFlipIt"),s.textContent="._justFlipIt_panel {perspective:1000px;-webkit-perspective:1000px;-moz-perspective:1000px;position:relative;}._justFlipIt_panel .front{height:inherit;width:inherit;position:absolute;top:0;z-index:900;transform-style:preserve-3d;backface-visibility:hidden;transition:transform .4s ease-in-out;}._justFlipIt_panel .back, ._justFlipIt_panel .backY{height:inherit;width:inherit;position:absolute;top:0;z-index:1000;transform-style:preserve-3d;backface-visibility:hidden;transition:transform .4s ease-in-out;}._justFlipIt_panel .front{-webkit-transform-style:preserve-3d;-moz-transform-style:preserve-3d;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden;-webkit-transition:transform .4s ease-in-out;-moz-transition:transform .4s ease-in-out;}._justFlipIt_panel .back, ._justFlipIt_panel .backY{-webkit-transform-style:preserve-3d;-moz-transform-style:preserve-3d;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden;-webkit-transition:transform .4s ease-in-out;-moz-transition:transform .4s ease-in-out;}._justFlipIt_panel .back{transform:rotateX(-180deg);-webkit-transform:rotateX(-180deg);-moz-transform:rotateX(-180deg);}._justFlipIt_panel._flip_ .front{transform:rotateX(180deg);-webkit-transform:rotateX(180deg);-moz-transform:rotateX(180deg);}._justFlipIt_panel._flip_ .back{transform:rotateX(0);-webkit-transform:rotateX(0);-moz-transform:rotateX(0);}._justFlipIt_panel .backY{transform:rotateY(-180deg);-webkit-transform:rotateY(-180deg);-moz-transform:rotateY(-180deg);}._justFlipIt_panel._flipY_ .front{transform:rotateY(180deg);-webkit-transform:rotateY(180deg);-moz-transform:rotateY(180deg);}._justFlipIt_panel._flipY_ .backY{transform:rotateY(0);-webkit-transform:rotateY(0);-moz-transform:rotateY(0);}._justFlipIt_panel {background: transparent !important; box-shadow: none !important;}._justFlipIt_panel > * {box-sizing: border-box;}",document.head.appendChild(s)),this.element=t,this.settings=Object.assign({},{Template:"",Click:!1,FlipX:!1,Style:[],Duration:400,Easing:"ease-in-out"},e),this.elementWidth=i(t,"width"),this.elementHeight=i(t,"height"),this.elementBackgroundColor=i(t,"background-color"),this.originalClassName=t.className,this.originalTagName=t.tagName.toLowerCase(),this.originalId=t.id||"",!0===this.settings.FlipX?(this.flipClass="_flip_",this.backClass="back",this.rotateStart="rotateX(0deg)",this.rotateFront="rotateX(180deg)",this.rotateBack="rotateX(-180deg)",this.rotateReset="rotateX(0deg)"):(this.flipClass="_flipY_",this.backClass="backY",this.rotateStart="rotateY(0deg)",this.rotateFront="rotateY(180deg)",this.rotateBack="rotateY(-180deg)",this.rotateReset="rotateY(0deg)"),this._init(),r.set(t,this)}_init(){var t=this.element,e=this.originalClassName;let s=document.createElement(this.originalTagName);o(s,"hover"),o(s,"_justFlipIt_panel");var i=document.createElement("div"),r=(o(i,"front"),t.cloneNode(!0));r.className="";let a=document.createElement("div");o(a,this.backClass),e&&e.split(" ").forEach(t=>{t&&o(a,t)}),l(t,i),l(t,a),n(i,this.settings.Duration,this.settings.Easing),n(a,this.settings.Duration,this.settings.Easing),t.style.all="inherit",t.style.background="transparent",t.style.backgroundColor="transparent",t.style.backgroundImage="none",t.style.border="none",t.style.borderRadius="0",t.style.boxShadow="none",t.style.outline="none",this.settings.Template?a.innerHTML=this.settings.Template:a.appendChild(r),t.parentNode.insertBefore(s,t),i.appendChild(t),s.appendChild(i),s.appendChild(a),e&&e.split(" ").forEach(t=>{t&&o(s,t)}),s.style.width=this.elementWidth,s.style.height=this.elementHeight,this.settings.Style&&this.settings.Style.length&&this.settings.Style.forEach(e=>{e.el&&("self"===e.el.toLowerCase()?Object.assign(s.style,e.style):s.querySelectorAll(e.el).forEach(t=>{Object.assign(t.style,e.style)}))}),this._setupEvents(s),this.hoverPanel=s,this.frontWrapper=i,this.backWrapper=a}_setupEvents(t){!0===this.settings.Click?t.addEventListener("click",t=>{t.preventDefault(),this._toggleFlip()}):"string"==typeof this.settings.Click?t.querySelectorAll(this.settings.Click).forEach(t=>{t.addEventListener("click",()=>{this._toggleFlip()})}):(t.addEventListener("mouseenter",()=>{this._flip(!0)}),t.addEventListener("mouseleave",()=>{this._flip(!1)}))}_toggleFlip(){t=this.hoverPanel,e=this.flipClass;var t,e=t.classList?t.classList.contains(e):new RegExp("(^| )"+e+"( |$)","gi").test(t.className);this._flip(!e)}_flip(t){var e;t?(o(this.hoverPanel,this.flipClass),a&&(s(this.frontWrapper,this.rotateStart,this.rotateFront,this.settings.Duration,this.settings.Easing),s(this.backWrapper,this.rotateBack,this.rotateReset,this.settings.Duration,this.settings.Easing))):(t=this.hoverPanel,e=this.flipClass,t.classList?t.classList.remove(e):t.className=t.className.replace(new RegExp("(^|\\b)"+e.split(" ").join("|")+"(\\b|$)","gi")," "),a&&(s(this.frontWrapper,this.rotateFront,this.rotateStart,this.settings.Duration,this.settings.Easing),s(this.backWrapper,this.rotateReset,this.rotateBack,this.settings.Duration,this.settings.Easing)))}destroy(){var t=this.hoverPanel,e=t.querySelector(".front > *");e.className=this.originalClassName,t.parentNode.insertBefore(e,t),t.parentNode.removeChild(t),r.delete(this.element)}}function t(t,e={}){var s;return"string"==typeof t?(s=document.querySelectorAll(t),Array.from(s).map(t=>new p(t,e))):t instanceof Element?new p(t,e):t.length?Array.from(t).map(t=>new p(t,e)):void 0}return t.destroy=function(t){var e;"string"==typeof t?(e=document.querySelectorAll(t),Array.from(e).forEach(t=>{t=r.get(t);t&&t.destroy()})):t instanceof Element?(e=r.get(t))&&e.destroy():t.length&&Array.from(t).forEach(t=>{t=r.get(t);t&&t.destroy()})},t});
1
+ ((t,e)=>{"function"==typeof define&&define.amd?define([],e):"object"==typeof module&&module.exports?module.exports=e():t.justFlipIt=e()})("undefined"!=typeof self?self:this,function(){"undefined"!=typeof CSS&&CSS.supports&&CSS.supports("display","grid");let a="undefined"!=typeof Element&&"animate"in Element.prototype;window.CSS&&CSS.supports&&CSS.supports("color","var(--test)");function i(t,e){return window.getComputedStyle(t,null).getPropertyValue(e)}function r(t,e){t.classList?t.classList.add(e):t.className+=" "+e}function s(t,e,s,i,r="ease-in-out"){a?t.animate([{transform:e},{transform:s}],{duration:i,easing:r,fill:"forwards"}):(t.style.transform=s,t.style.webkitTransform=s,t.style.mozTransform=s)}let n=new WeakMap;class o{constructor(t,e={}){var s;document.querySelector('[data-justflipitstyle="justFlipIt"]')||((s=document.createElement("style")).setAttribute("data-justflipitstyle","justFlipIt"),s.textContent="._justFlipIt_panel {perspective:1000px;-webkit-perspective:1000px;-moz-perspective:1000px;position:relative;}._justFlipIt_panel .front{height:inherit;width:inherit;position:absolute;top:0;z-index:900;transform-style:preserve-3d;backface-visibility:hidden;transition:transform .4s ease-in-out;}._justFlipIt_panel .back, ._justFlipIt_panel .backY{height:inherit;width:inherit;position:absolute;top:0;z-index:1000;transform-style:preserve-3d;backface-visibility:hidden;transition:transform .4s ease-in-out;}._justFlipIt_panel .front{-webkit-transform-style:preserve-3d;-moz-transform-style:preserve-3d;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden;-webkit-transition:transform .4s ease-in-out;-moz-transition:transform .4s ease-in-out;}._justFlipIt_panel .back, ._justFlipIt_panel .backY{-webkit-transform-style:preserve-3d;-moz-transform-style:preserve-3d;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden;-webkit-transition:transform .4s ease-in-out;-moz-transition:transform .4s ease-in-out;}._justFlipIt_panel .back{transform:rotateX(-180deg);-webkit-transform:rotateX(-180deg);-moz-transform:rotateX(-180deg);}._justFlipIt_panel._flip_ .front{transform:rotateX(180deg);-webkit-transform:rotateX(180deg);-moz-transform:rotateX(180deg);}._justFlipIt_panel._flip_ .back{transform:rotateX(0);-webkit-transform:rotateX(0);-moz-transform:rotateX(0);}._justFlipIt_panel .backY{transform:rotateY(-180deg);-webkit-transform:rotateY(-180deg);-moz-transform:rotateY(-180deg);}._justFlipIt_panel._flipY_ .front{transform:rotateY(180deg);-webkit-transform:rotateY(180deg);-moz-transform:rotateY(180deg);}._justFlipIt_panel._flipY_ .backY{transform:rotateY(0);-webkit-transform:rotateY(0);-moz-transform:rotateY(0);}._justFlipIt_panel {background: transparent !important; box-shadow: none !important;}._justFlipIt_panel > * {box-sizing: border-box;}",document.head.appendChild(s)),this.element=t,this.settings=Object.assign({},{Template:"",Click:!1,FlipX:!1,Style:[],Duration:400,Easing:"ease-in-out",preserveClasses:!0,preserveStyles:!0},e),this.elementWidth=i(t,"width"),this.elementHeight=i(t,"height"),this.elementBackgroundColor=i(t,"background-color"),this.originalClassName=t.className,this.originalTagName=t.tagName.toLowerCase(),this.originalId=t.id||"",!0===this.settings.FlipX?(this.flipClass="_flip_",this.backClass="back",this.rotateStart="rotateX(0deg)",this.rotateFront="rotateX(180deg)",this.rotateBack="rotateX(-180deg)",this.rotateReset="rotateX(0deg)"):(this.flipClass="_flipY_",this.backClass="backY",this.rotateStart="rotateY(0deg)",this.rotateFront="rotateY(180deg)",this.rotateBack="rotateY(-180deg)",this.rotateReset="rotateY(0deg)"),this._init(),n.set(t,this)}_init(){var t=this.element;this.originalClassName;let s=document.createElement(this.originalTagName),e=(r(s,"hover"),r(s,"_justFlipIt_panel"),document.createElement("div")),i=(r(e,"front"),document.createElement("div"));r(i,this.backClass),this.settings.preserveClasses&&t.classList.length&&t.classList.forEach(t=>{s.classList.contains(t)||s.classList.add(t),e&&!e.classList.contains(t)&&e.classList.add(t),i&&!i.classList.contains(t)&&i.classList.add(t)}),this.settings.preserveStyles&&t.getAttribute("style")&&s.setAttribute("style",(s.getAttribute("style")||"")+";"+t.getAttribute("style")),e.innerHTML=t.innerHTML,this.settings.Template?i.innerHTML=this.settings.Template:i.innerHTML=t.innerHTML,t.parentNode.insertBefore(s,t),s.appendChild(e),s.appendChild(i),t.parentNode.removeChild(t),s.style.width=this.elementWidth,s.style.height=this.elementHeight,this.settings.Style&&this.settings.Style.length&&this.settings.Style.forEach(e=>{e.el&&("self"===e.el.toLowerCase()?Object.assign(s.style,e.style):s.querySelectorAll(e.el).forEach(t=>{Object.assign(t.style,e.style)}))}),this._setupEvents(s),this.hoverPanel=s,this.frontWrapper=e,this.backWrapper=i}_setupEvents(t){!0===this.settings.Click?t.addEventListener("click",t=>{t.preventDefault(),this._toggleFlip()}):"string"==typeof this.settings.Click?t.querySelectorAll(this.settings.Click).forEach(t=>{t.addEventListener("click",()=>{this._toggleFlip()})}):(t.addEventListener("mouseenter",()=>{this._flip(!0)}),t.addEventListener("mouseleave",()=>{this._flip(!1)}))}_toggleFlip(){t=this.hoverPanel,e=this.flipClass;var t,e=t.classList?t.classList.contains(e):new RegExp("(^| )"+e+"( |$)","gi").test(t.className);this._flip(!e)}_flip(t){var e;t?(r(this.hoverPanel,this.flipClass),a&&(s(this.frontWrapper,this.rotateStart,this.rotateFront,this.settings.Duration,this.settings.Easing),s(this.backWrapper,this.rotateBack,this.rotateReset,this.settings.Duration,this.settings.Easing))):(t=this.hoverPanel,e=this.flipClass,t.classList?t.classList.remove(e):t.className=t.className.replace(new RegExp("(^|\\b)"+e.split(" ").join("|")+"(\\b|$)","gi")," "),a&&(s(this.frontWrapper,this.rotateFront,this.rotateStart,this.settings.Duration,this.settings.Easing),s(this.backWrapper,this.rotateReset,this.rotateBack,this.settings.Duration,this.settings.Easing)))}destroy(){var t=this.hoverPanel,e=t.querySelector(".front > *");e.className=this.originalClassName,t.parentNode.insertBefore(e,t),t.parentNode.removeChild(t),n.delete(this.element)}}function t(t,e={}){var s;return"string"==typeof t?(s=document.querySelectorAll(t),Array.from(s).map(t=>new o(t,e))):t instanceof Element?new o(t,e):t.length?Array.from(t).map(t=>new o(t,e)):void 0}return t.destroy=function(t){var e;"string"==typeof t?(e=document.querySelectorAll(t),Array.from(e).forEach(t=>{t=n.get(t);t&&t.destroy()})):t instanceof Element?(e=n.get(t))&&e.destroy():t.length&&Array.from(t).forEach(t=>{t=n.get(t);t&&t.destroy()})},t});
@@ -1,11 +1,11 @@
1
1
  /*!
2
- * Vanilla JS justFlipIt v3.0.0
2
+ * justFlipIt v3.1.1
3
3
  * https://github.com/SimHub/justFlipIt
4
4
  *
5
- * Copyright simon Lackmann
5
+ * Copyright SimHub
6
6
  * Released under the MIT license
7
7
  *
8
- * Date: 2023
8
+ * Date: 2025
9
9
  */
10
10
 
11
11
  (function (root, factory) {
@@ -160,9 +160,10 @@
160
160
  Click: false,
161
161
  FlipX: false,
162
162
  Style: [],
163
- // NEU: Standard-Animationsoptionen
164
163
  Duration: 400,
165
164
  Easing: "ease-in-out",
165
+ preserveClasses: true, // NEU
166
+ preserveStyles: true, // NEU
166
167
  },
167
168
  options,
168
169
  );
@@ -186,63 +187,62 @@
186
187
  _init() {
187
188
  const originalElement = this.element;
188
189
  const originalClassName = this.originalClassName;
190
+
191
+ // Panel-Struktur erzeugen
189
192
  const hoverPanel = document.createElement(this.originalTagName);
190
193
  addClass(hoverPanel, "hover");
191
194
  addClass(hoverPanel, "_justFlipIt_panel");
192
195
  const frontWrapper = document.createElement("div");
193
196
  addClass(frontWrapper, "front");
194
- const clone = originalElement.cloneNode(true);
195
- clone.className = "";
196
197
  const backWrapper = document.createElement("div");
197
198
  addClass(backWrapper, this.backClass);
198
- if (originalClassName) {
199
- originalClassName.split(" ").forEach((cls) => {
200
- if (cls) addClass(backWrapper, cls);
199
+
200
+ // NEU: Klassen übernehmen (Panel, .front, .backY)
201
+ if (this.settings.preserveClasses && originalElement.classList.length) {
202
+ originalElement.classList.forEach((cls) => {
203
+ if (!hoverPanel.classList.contains(cls)) {
204
+ hoverPanel.classList.add(cls);
205
+ }
206
+ if (frontWrapper && !frontWrapper.classList.contains(cls)) {
207
+ frontWrapper.classList.add(cls);
208
+ }
209
+ if (backWrapper && !backWrapper.classList.contains(cls)) {
210
+ backWrapper.classList.add(cls);
211
+ }
201
212
  });
202
213
  }
203
214
 
204
- // PATCH: Styles übernehmen und Original komplett transparent machen
205
- copyStyles(originalElement, frontWrapper);
206
- copyStyles(originalElement, backWrapper);
207
-
208
- // Mache das Original komplett transparent und ohne Border/Shadow/usw.
209
- originalElement.style.all = "inherit"; // Reset alles zur Sicherheit
210
- originalElement.style.background = "transparent";
211
- originalElement.style.backgroundColor = "transparent";
212
- originalElement.style.backgroundImage = "none";
213
- originalElement.style.border = "none";
214
- originalElement.style.borderRadius = "0";
215
- originalElement.style.boxShadow = "none";
216
- originalElement.style.outline = "none";
215
+ // NEU: Inline-Styles übernehmen (nur auf Panel)
216
+ if (
217
+ this.settings.preserveStyles && originalElement.getAttribute("style")
218
+ ) {
219
+ hoverPanel.setAttribute(
220
+ "style",
221
+ (hoverPanel.getAttribute("style") || "") +
222
+ ";" + originalElement.getAttribute("style"),
223
+ );
224
+ }
217
225
 
218
- // NEU: Wende benutzerdefinierte Animationseinstellungen an
219
- applyAnimationSettings(
220
- frontWrapper,
221
- this.settings.Duration,
222
- this.settings.Easing,
223
- );
224
- applyAnimationSettings(
225
- backWrapper,
226
- this.settings.Duration,
227
- this.settings.Easing,
228
- );
226
+ // Nur den INHALT übernehmen!
227
+ frontWrapper.innerHTML = originalElement.innerHTML;
229
228
 
230
229
  if (this.settings.Template) {
231
230
  backWrapper.innerHTML = this.settings.Template;
232
231
  } else {
233
- backWrapper.appendChild(clone);
232
+ backWrapper.innerHTML = originalElement.innerHTML;
234
233
  }
234
+
235
+ // Panel einfügen und Original entfernen
235
236
  originalElement.parentNode.insertBefore(hoverPanel, originalElement);
236
- frontWrapper.appendChild(originalElement);
237
237
  hoverPanel.appendChild(frontWrapper);
238
238
  hoverPanel.appendChild(backWrapper);
239
- if (originalClassName) {
240
- originalClassName.split(" ").forEach((cls) => {
241
- if (cls) addClass(hoverPanel, cls);
242
- });
243
- }
239
+ originalElement.parentNode.removeChild(originalElement);
240
+
241
+ // Panel-Größe und Styles übernehmen
244
242
  hoverPanel.style.width = this.elementWidth;
245
243
  hoverPanel.style.height = this.elementHeight;
244
+
245
+ // Custom Styles aus Option anwenden
246
246
  if (this.settings.Style && this.settings.Style.length) {
247
247
  this.settings.Style.forEach((styleObj) => {
248
248
  if (styleObj.el) {
@@ -257,7 +257,11 @@
257
257
  }
258
258
  });
259
259
  }
260
+
261
+ // Events setzen
260
262
  this._setupEvents(hoverPanel);
263
+
264
+ // Referenzen speichern
261
265
  this.hoverPanel = hoverPanel;
262
266
  this.frontWrapper = frontWrapper;
263
267
  this.backWrapper = backWrapper;
@@ -1 +1 @@
1
- ((t,e)=>{"function"==typeof define&&define.amd?define([],e):"object"==typeof module&&module.exports?module.exports=e():t.justFlipIt=e()})("undefined"!=typeof self?self:this,function(){function a(t,e){return window.getComputedStyle(t,null).getPropertyValue(e)}function o(t,e){t.classList?t.classList.add(e):t.className+=" "+e}function e(t,e){var i,s;t.classList?t.classList.toggle(e):(0<=(s=(i=t.className.split(" ")).indexOf(e))?i.splice(s,1):i.push(e),t.className=i.join(" "))}function r(t,e){let i=window.getComputedStyle(t);["background","backgroundColor","backgroundImage","backgroundPosition","backgroundRepeat","backgroundSize","borderRadius","borderTopLeftRadius","borderTopRightRadius","borderBottomLeftRadius","borderBottomRightRadius","border","borderTop","borderRight","borderBottom","borderLeft","boxShadow","color","opacity"].forEach(t=>{i[t]&&"none"!==i[t]&&"initial"!==i[t]&&""!==i[t]&&(e.style[t]=i[t])})}function l(t,e,i){e=`all ${e/1e3}s `+i;t.style.transition=e,t.style.WebkitTransition=e,t.style.MozTransition=e,t.style.msTransition=e,t.style.OTransition=e}let d=new WeakMap;class s{constructor(t,e={}){var i,s,n;document.querySelector('[data-justflipitstyle="justFlipIt_One"]')||((i=document.createElement("style")).setAttribute("data-justflipitstyle","justFlipIt_One"),i.textContent="._justFlipIt_panel {perspective:1000px;-webkit-perspective:1000px;-moz-perspective:1000px;}._justFlipIt_panel .front{height:inherit;width:inherit;position:absolute;top:0;z-index:900;-webkit-transform:rotateX(0) rotateX(0);-moz-transform:rotateX(0) rotateX(0);-webkit-transform-style:preserve-3d;-moz-transform-style:preserve-3d;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden;-webkit-transition:all .4s ease-in-out;-moz-transition:all .4s ease-in-out;-ms-transition:all .4s ease-in-out;-o-transition:all .4s ease-in-out;transition:all .4s ease-in-out}._justFlipIt_panel .back{height:inherit;width:inherit;position:absolute;top:0;z-index:1000;-webkit-transform:rotateX(-180deg);-moz-transform:rotateX(-180deg);-webkit-transform-style:preserve-3d;-moz-transform-style:preserve-3d;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden;-webkit-transition:all .4s ease-in-out;-moz-transition:all .4s ease-in-out;-ms-transition:all .4s ease-in-out;-o-transition:all .4s ease-in-out;transition:all .4s ease-in-out}._justFlipIt_panel._flip_ .front{z-index:900;-webkit-transform:rotateX(180deg);-moz-transform:rotateX(180deg)}._justFlipIt_panel._flip_ .back{z-index:1000;-webkit-transform:rotateX(0) rotateX(0);-moz-transform:rotateX(0) rotateX(0)}",(s=document.createElement("style")).setAttribute("data-justflipitstyle","justFlipIt_Two"),s.textContent="._justFlipIt_panel .backY{height:inherit;width:inherit;position:absolute;top:0;z-index:1000;-webkit-transform:rotateY(-180deg);-moz-transform:rotateY(-180deg);-webkit-transform-style:preserve-3d;-moz-transform-style:preserve-3d;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden;-webkit-transition:all .4s ease-in-out;-moz-transition:all .4s ease-in-out;-ms-transition:all .4s ease-in-out;-o-transition:all .4s ease-in-out;transition:all .4s ease-in-out}._justFlipIt_panel._flipY_ .front{z-index:900;-webkit-transform:rotateY(180deg);-moz-transform:rotateY(180deg)}._justFlipIt_panel._flipY_ .backY{z-index:1000;-webkit-transform:rotateX(0) rotateY(0);-moz-transform:rotateX(0) rotateY(0)}",(n=document.createElement("style")).setAttribute("data-justflipitstyle","justFlipIt_Transparent"),n.textContent="._justFlipIt_panel {background: transparent !important; box-shadow: none !important;}._justFlipIt_panel > * {box-sizing: border-box;}",document.head.appendChild(i),document.head.appendChild(s),document.head.appendChild(n)),this.element=t,this.settings=Object.assign({},{Template:"",Click:!1,FlipX:!1,Style:[],Duration:400,Easing:"ease-in-out"},e),this.elementWidth=a(t,"width"),this.elementHeight=a(t,"height"),this.elementBackgroundColor=a(t,"background-color"),this.originalClassName=t.className,this.originalTagName=t.tagName.toLowerCase(),this.originalId=t.id||"",!0===this.settings.FlipX?(this.flipClass="_flip_",this.backClass="back"):(this.flipClass="_flipY_",this.backClass="backY"),this._init(),d.set(t,this)}_init(){var t=this.element,e=this.originalClassName;let i=document.createElement(this.originalTagName);o(i,"hover"),o(i,"_justFlipIt_panel");var s=document.createElement("div"),n=(o(s,"front"),t.cloneNode(!0));n.className="";let a=document.createElement("div");o(a,this.backClass),e&&e.split(" ").forEach(t=>{t&&o(a,t)}),r(t,s),r(t,a),t.style.all="inherit",t.style.background="transparent",t.style.backgroundColor="transparent",t.style.backgroundImage="none",t.style.border="none",t.style.borderRadius="0",t.style.boxShadow="none",t.style.outline="none",l(s,this.settings.Duration,this.settings.Easing),l(a,this.settings.Duration,this.settings.Easing),this.settings.Template?a.innerHTML=this.settings.Template:a.appendChild(n),t.parentNode.insertBefore(i,t),s.appendChild(t),i.appendChild(s),i.appendChild(a),e&&e.split(" ").forEach(t=>{t&&o(i,t)}),i.style.width=this.elementWidth,i.style.height=this.elementHeight,this.settings.Style&&this.settings.Style.length&&this.settings.Style.forEach(e=>{e.el&&("self"===e.el.toLowerCase()?Object.assign(i.style,e.style):i.querySelectorAll(e.el).forEach(t=>{Object.assign(t.style,e.style)}))}),this._setupEvents(i),this.hoverPanel=i,this.frontWrapper=s,this.backWrapper=a}_setupEvents(i){!0===this.settings.Click?i.addEventListener("click",t=>{t.preventDefault(),e(i,this.flipClass)}):"string"==typeof this.settings.Click?i.querySelectorAll(this.settings.Click).forEach(t=>{t.addEventListener("click",()=>{e(i,this.flipClass)})}):(i.addEventListener("mouseenter",()=>{o(i,this.flipClass)}),i.addEventListener("mouseleave",()=>{var t,e;t=i,e=this.flipClass,t.classList?t.classList.remove(e):t.className=t.className.replace(new RegExp("(^|\\b)"+e.split(" ").join("|")+"(\\b|$)","gi")," ")}))}destroy(){var t=this.hoverPanel,e=t.querySelector(".front > *");e.className=this.originalClassName,t.parentNode.insertBefore(e,t),t.parentNode.removeChild(t),d.delete(this.element)}}function t(t,e={}){var i;return"string"==typeof t?(i=document.querySelectorAll(t),Array.from(i).map(t=>new s(t,e))):t instanceof Element?new s(t,e):t.length?Array.from(t).map(t=>new s(t,e)):void 0}return t.destroy=function(t){var e;"string"==typeof t?(e=document.querySelectorAll(t),Array.from(e).forEach(t=>{t=d.get(t);t&&t.destroy()})):t instanceof Element?(e=d.get(t))&&e.destroy():t.length&&Array.from(t).forEach(t=>{t=d.get(t);t&&t.destroy()})},t});
1
+ ((t,e)=>{"function"==typeof define&&define.amd?define([],e):"object"==typeof module&&module.exports?module.exports=e():t.justFlipIt=e()})("undefined"!=typeof self?self:this,function(){function n(t,e){return window.getComputedStyle(t,null).getPropertyValue(e)}function a(t,e){t.classList?t.classList.add(e):t.className+=" "+e}function e(t,e){var s,i;t.classList?t.classList.toggle(e):(0<=(i=(s=t.className.split(" ")).indexOf(e))?s.splice(i,1):s.push(e),t.className=s.join(" "))}let l=new WeakMap;class i{constructor(t,e={}){var s,i,a;document.querySelector('[data-justflipitstyle="justFlipIt_One"]')||((s=document.createElement("style")).setAttribute("data-justflipitstyle","justFlipIt_One"),s.textContent="._justFlipIt_panel {perspective:1000px;-webkit-perspective:1000px;-moz-perspective:1000px;}._justFlipIt_panel .front{height:inherit;width:inherit;position:absolute;top:0;z-index:900;-webkit-transform:rotateX(0) rotateX(0);-moz-transform:rotateX(0) rotateX(0);-webkit-transform-style:preserve-3d;-moz-transform-style:preserve-3d;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden;-webkit-transition:all .4s ease-in-out;-moz-transition:all .4s ease-in-out;-ms-transition:all .4s ease-in-out;-o-transition:all .4s ease-in-out;transition:all .4s ease-in-out}._justFlipIt_panel .back{height:inherit;width:inherit;position:absolute;top:0;z-index:1000;-webkit-transform:rotateX(-180deg);-moz-transform:rotateX(-180deg);-webkit-transform-style:preserve-3d;-moz-transform-style:preserve-3d;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden;-webkit-transition:all .4s ease-in-out;-moz-transition:all .4s ease-in-out;-ms-transition:all .4s ease-in-out;-o-transition:all .4s ease-in-out;transition:all .4s ease-in-out}._justFlipIt_panel._flip_ .front{z-index:900;-webkit-transform:rotateX(180deg);-moz-transform:rotateX(180deg)}._justFlipIt_panel._flip_ .back{z-index:1000;-webkit-transform:rotateX(0) rotateX(0);-moz-transform:rotateX(0) rotateX(0)}",(i=document.createElement("style")).setAttribute("data-justflipitstyle","justFlipIt_Two"),i.textContent="._justFlipIt_panel .backY{height:inherit;width:inherit;position:absolute;top:0;z-index:1000;-webkit-transform:rotateY(-180deg);-moz-transform:rotateY(-180deg);-webkit-transform-style:preserve-3d;-moz-transform-style:preserve-3d;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden;-webkit-transition:all .4s ease-in-out;-moz-transition:all .4s ease-in-out;-ms-transition:all .4s ease-in-out;-o-transition:all .4s ease-in-out;transition:all .4s ease-in-out}._justFlipIt_panel._flipY_ .front{z-index:900;-webkit-transform:rotateY(180deg);-moz-transform:rotateY(180deg)}._justFlipIt_panel._flipY_ .backY{z-index:1000;-webkit-transform:rotateX(0) rotateY(0);-moz-transform:rotateX(0) rotateY(0)}",(a=document.createElement("style")).setAttribute("data-justflipitstyle","justFlipIt_Transparent"),a.textContent="._justFlipIt_panel {background: transparent !important; box-shadow: none !important;}._justFlipIt_panel > * {box-sizing: border-box;}",document.head.appendChild(s),document.head.appendChild(i),document.head.appendChild(a)),this.element=t,this.settings=Object.assign({},{Template:"",Click:!1,FlipX:!1,Style:[],Duration:400,Easing:"ease-in-out",preserveClasses:!0,preserveStyles:!0},e),this.elementWidth=n(t,"width"),this.elementHeight=n(t,"height"),this.elementBackgroundColor=n(t,"background-color"),this.originalClassName=t.className,this.originalTagName=t.tagName.toLowerCase(),this.originalId=t.id||"",!0===this.settings.FlipX?(this.flipClass="_flip_",this.backClass="back"):(this.flipClass="_flipY_",this.backClass="backY"),this._init(),l.set(t,this)}_init(){var t=this.element;this.originalClassName;let s=document.createElement(this.originalTagName),e=(a(s,"hover"),a(s,"_justFlipIt_panel"),document.createElement("div")),i=(a(e,"front"),document.createElement("div"));a(i,this.backClass),this.settings.preserveClasses&&t.classList.length&&t.classList.forEach(t=>{s.classList.contains(t)||s.classList.add(t),e&&!e.classList.contains(t)&&e.classList.add(t),i&&!i.classList.contains(t)&&i.classList.add(t)}),this.settings.preserveStyles&&t.getAttribute("style")&&s.setAttribute("style",(s.getAttribute("style")||"")+";"+t.getAttribute("style")),e.innerHTML=t.innerHTML,this.settings.Template?i.innerHTML=this.settings.Template:i.innerHTML=t.innerHTML,t.parentNode.insertBefore(s,t),s.appendChild(e),s.appendChild(i),t.parentNode.removeChild(t),s.style.width=this.elementWidth,s.style.height=this.elementHeight,this.settings.Style&&this.settings.Style.length&&this.settings.Style.forEach(e=>{e.el&&("self"===e.el.toLowerCase()?Object.assign(s.style,e.style):s.querySelectorAll(e.el).forEach(t=>{Object.assign(t.style,e.style)}))}),this._setupEvents(s),this.hoverPanel=s,this.frontWrapper=e,this.backWrapper=i}_setupEvents(s){!0===this.settings.Click?s.addEventListener("click",t=>{t.preventDefault(),e(s,this.flipClass)}):"string"==typeof this.settings.Click?s.querySelectorAll(this.settings.Click).forEach(t=>{t.addEventListener("click",()=>{e(s,this.flipClass)})}):(s.addEventListener("mouseenter",()=>{a(s,this.flipClass)}),s.addEventListener("mouseleave",()=>{var t,e;t=s,e=this.flipClass,t.classList?t.classList.remove(e):t.className=t.className.replace(new RegExp("(^|\\b)"+e.split(" ").join("|")+"(\\b|$)","gi")," ")}))}destroy(){var t=this.hoverPanel,e=t.querySelector(".front > *");e.className=this.originalClassName,t.parentNode.insertBefore(e,t),t.parentNode.removeChild(t),l.delete(this.element)}}function t(t,e={}){var s;return"string"==typeof t?(s=document.querySelectorAll(t),Array.from(s).map(t=>new i(t,e))):t instanceof Element?new i(t,e):t.length?Array.from(t).map(t=>new i(t,e)):void 0}return t.destroy=function(t){var e;"string"==typeof t?(e=document.querySelectorAll(t),Array.from(e).forEach(t=>{t=l.get(t);t&&t.destroy()})):t instanceof Element?(e=l.get(t))&&e.destroy():t.length&&Array.from(t).forEach(t=>{t=l.get(t);t&&t.destroy()})},t});
@@ -24,6 +24,16 @@ declare namespace justFlipIt {
24
24
  * Custom styles to apply to elements
25
25
  */
26
26
  Style?: StyleOption[];
27
+
28
+ /**
29
+ * If true, all CSS classes from the original element are copied to the flip panel (default: true)
30
+ */
31
+ preserveClasses?: boolean;
32
+
33
+ /**
34
+ * If true, all inline styles from the original element are copied to the flip panel (default: true)
35
+ */
36
+ preserveStyles?: boolean;
27
37
  }
28
38
 
29
39
  /**