@cocreate/element-prototype
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -0,1 +1,8 @@ | ||
# [1.4.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.3.0...v1.4.0) (2023-01-10) | ||
### Features | ||
* run CoCReate,pass on elementsprior t inserting. merge domEditor and alements together ([d39f8ff](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/d39f8ffd287ed82754314a401b7c33e7bf902450)) | ||
# [1.3.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.2.28...v1.3.0) (2023-01-09) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "@cocreate/element-prototype", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "A simple element-prototype component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -64,11 +64,32 @@ import {getAttributes} from '@cocreate/utils'; | ||
else if (el.tagName === 'DIV') { | ||
if (el.hasAttribute("value")) { | ||
el.setAttribute("value", value); | ||
else if (el.tagName === 'SCRIPT') | ||
setScript(el, value); | ||
else { | ||
if (el.hasAttribute('contenteditable') && el == document.activeElement) return; | ||
if (el.tagName === 'DIV') { | ||
if (!el.classList.contains('domEditor') || !el.hasAttribute('get-value') || !el.hasAttribute('get-value-closest')) | ||
return | ||
} | ||
if (el.classList.contains('domEditor') || el.hasAttribute('get-value') || el.hasAttribute('get-value-closest')) { | ||
if (el.getAttribute('data-domEditor') == "replace") { | ||
let newElement = document.createElement("div"); | ||
newElement.innerHTML = value; | ||
if (valueType == 'string' || valueType == 'text') | ||
el.textContent = value; | ||
else { | ||
let newElement = document.createElement("div"); | ||
newElement.innerHTML = value; | ||
setPass(newElement) | ||
let CoCreateJS = newElement.querySelector('script[src*="CoCreate.js"], script[src*="CoCreate.min.js"]') | ||
if (CoCreateJS) | ||
CoCreateJS.remove() | ||
let CoCreateCSS = newElement.querySelector('link[href*="CoCreate.css"], link[href*="CoCreate.min.css"]') | ||
if (CoCreateCSS) | ||
CoCreateCSS.remove() | ||
let css = newElement.querySelector('link[collection], link[document]') | ||
if (css) | ||
css.remove() | ||
if (el.getAttribute('domEditor') == "replace") { | ||
let parentNode = el.parentNode; | ||
@@ -83,21 +104,7 @@ if (parentNode) { | ||
} | ||
} else { | ||
el.innerHTML = newElement.innerHTML; | ||
} | ||
else { | ||
if (valueType == 'string' || valueType == 'text') | ||
el.textContent = value; | ||
else | ||
el.innerHTML = value; | ||
} | ||
} | ||
} | ||
else if (el.tagName === 'SCRIPT'){ | ||
setScript(el, value); | ||
} | ||
else { | ||
if (el.hasAttribute('contenteditable') && el == document.activeElement) return; | ||
if (valueType == 'string' || valueType == 'text') | ||
el.textContent = value; | ||
else | ||
el.innerHTML = value; | ||
if (el.hasAttribute("value")) { | ||
@@ -107,2 +114,3 @@ el.setAttribute("value", value); | ||
} | ||
if (el.getAttribute('contenteditable')) | ||
@@ -123,2 +131,10 @@ dispatchEvents(el); | ||
function setPass(el) { | ||
if (CoCreate.pass) { | ||
let passElements = el.querySelectorAll('[pass_id]'); | ||
if (passElements) | ||
CoCreate.pass.initElements(passElements) | ||
} | ||
} | ||
function setScript(script, value) { | ||
@@ -125,0 +141,0 @@ let newScript = document.createElement('script'); |
50235
365