dom-render
Advanced tools
Comparing version 1.0.21 to 1.0.22
@@ -176,2 +176,28 @@ 'use strict'; | ||
}; | ||
ScriptUtils.loadElement = function (name, attribute, target) { | ||
if (target === void 0) { target = document.head; } | ||
return new Promise(function (resolve, reject) { | ||
var tag = document.createElement(name); | ||
tag.onload = resolve; | ||
tag.onerror = reject; | ||
for (var _i = 0, _a = Object.entries(attribute); _i < _a.length; _i++) { | ||
var _b = _a[_i], key = _b[0], value = _b[1]; | ||
tag.setAttribute(key, value); | ||
} | ||
target.append(tag); | ||
}); | ||
}; | ||
ScriptUtils.loadStyleSheet = function (href, attribute) { | ||
if (attribute === void 0) { attribute = {}; } | ||
attribute.type = 'text/css'; | ||
attribute.rel = 'stylesheet'; | ||
attribute.href = href; | ||
return ScriptUtils.loadElement('link', attribute); | ||
}; | ||
ScriptUtils.loadScript = function (src, attribute) { | ||
if (attribute === void 0) { attribute = {}; } | ||
attribute.type = 'text/javascript'; | ||
attribute.src = src; | ||
return ScriptUtils.loadElement('script', attribute); | ||
}; | ||
return ScriptUtils; | ||
@@ -190,2 +216,4 @@ }()); | ||
this.attrPrefix + 'style', | ||
this.attrPrefix + 'class', | ||
this.attrPrefix + 'window-event-popstate', | ||
this.attrPrefix + 'on-init' | ||
@@ -196,2 +224,11 @@ ]; | ||
}); | ||
window.addEventListener('popstate', function (e) { | ||
document.querySelectorAll('[dr-window-event-popstate]').forEach(function (it) { | ||
var _a; | ||
var script = it.getAttribute('dr-window-event-popstate'); | ||
if (script) { | ||
(_a = Function("\"use strict\"; const $target = this.$target; " + script + " ").bind(Object.assign({ $target: it }, it.obj))()) !== null && _a !== void 0 ? _a : {}; | ||
} | ||
}); | ||
}); | ||
} | ||
@@ -223,2 +260,6 @@ class_1.prototype.findAttrElements = function (fragment, config) { | ||
}); | ||
this.procAttr(childNodes, this.attrPrefix + 'window-event-popstate', function (it, attribute) { | ||
it.obj = obj; | ||
console.log('-->', it, it.obj); | ||
}); | ||
this.procAttr(childNodes, this.attrPrefix + 'on-init', function (it, varName) { | ||
@@ -244,3 +285,2 @@ if (varName) { | ||
it.addEventListener('input', function (eit) { | ||
console.log('input change--->link'); | ||
if (typeof _this.getValue(obj, varName) === 'function') { | ||
@@ -307,2 +347,23 @@ _this.getValue(obj, varName)(it.value, eit); | ||
}); | ||
this.procAttr(elements, this.attrPrefix + 'class', function (it, attribute) { | ||
var _a; | ||
var script = attribute; | ||
if (script) { | ||
script = 'return ' + script; | ||
} | ||
if (_this.isUsingThisVar(script, varName) || varName === undefined) { | ||
var data = (_a = Function("\"use strict\"; const $target = this.$target; " + script + " ").bind(Object.assign({ $target: it }, obj))()) !== null && _a !== void 0 ? _a : {}; | ||
for (var _i = 0, _b = Object.entries(data); _i < _b.length; _i++) { | ||
var _c = _b[_i], key = _c[0], value = _c[1]; | ||
if (it instanceof HTMLElement) { | ||
if (value) { | ||
it.classList.add(key); | ||
} | ||
else { | ||
it.classList.remove(key); | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
@@ -754,4 +815,6 @@ class_1.prototype.addDrEvent = function (obj, eventName, elements) { | ||
if (filter.length === 0) { | ||
var proxyAfter = _this.proxy(objProxy, target, it); | ||
obj[it] = proxyAfter; | ||
if (!Object.isFrozen(obj)) { | ||
var proxyAfter = _this.proxy(objProxy, target, it); | ||
obj[it] = proxyAfter; | ||
} | ||
} | ||
@@ -767,2 +830,3 @@ } | ||
var _this = this; | ||
var _a, _b; | ||
this._targets.add(target); | ||
@@ -785,2 +849,3 @@ var rawSets = RawSet.checkPointCreates(target, this.config); | ||
}); | ||
(_b = (_a = this._domRender_proxy) === null || _a === void 0 ? void 0 : _a.onInitRender) === null || _b === void 0 ? void 0 : _b.call(_a); | ||
}; | ||
@@ -787,0 +852,0 @@ DomRenderProxy.prototype.render = function (raws) { |
@@ -29,4 +29,6 @@ "use strict"; | ||
if (filter.length === 0) { | ||
var proxyAfter = _this.proxy(objProxy, target, it); | ||
obj[it] = proxyAfter; | ||
if (!Object.isFrozen(obj)) { | ||
var proxyAfter = _this.proxy(objProxy, target, it); | ||
obj[it] = proxyAfter; | ||
} | ||
} | ||
@@ -42,2 +44,3 @@ } | ||
var _this = this; | ||
var _a, _b; | ||
this._targets.add(target); | ||
@@ -60,2 +63,3 @@ var rawSets = RawSet_1.RawSet.checkPointCreates(target, this.config); | ||
}); | ||
(_b = (_a = this._domRender_proxy) === null || _a === void 0 ? void 0 : _a.onInitRender) === null || _b === void 0 ? void 0 : _b.call(_a); | ||
}; | ||
@@ -62,0 +66,0 @@ DomRenderProxy.prototype.render = function (raws) { |
@@ -15,2 +15,4 @@ "use strict"; | ||
this.attrPrefix + 'style', | ||
this.attrPrefix + 'class', | ||
this.attrPrefix + 'window-event-popstate', | ||
this.attrPrefix + 'on-init' | ||
@@ -21,2 +23,11 @@ ]; | ||
}); | ||
window.addEventListener('popstate', function (e) { | ||
document.querySelectorAll('[dr-window-event-popstate]').forEach(function (it) { | ||
var _a; | ||
var script = it.getAttribute('dr-window-event-popstate'); | ||
if (script) { | ||
(_a = Function("\"use strict\"; const $target = this.$target; " + script + " ").bind(Object.assign({ $target: it }, it.obj))()) !== null && _a !== void 0 ? _a : {}; | ||
} | ||
}); | ||
}); | ||
} | ||
@@ -48,2 +59,6 @@ class_1.prototype.findAttrElements = function (fragment, config) { | ||
}); | ||
this.procAttr(childNodes, this.attrPrefix + 'window-event-popstate', function (it, attribute) { | ||
it.obj = obj; | ||
console.log('-->', it, it.obj); | ||
}); | ||
this.procAttr(childNodes, this.attrPrefix + 'on-init', function (it, varName) { | ||
@@ -69,3 +84,2 @@ if (varName) { | ||
it.addEventListener('input', function (eit) { | ||
console.log('input change--->link'); | ||
if (typeof _this.getValue(obj, varName) === 'function') { | ||
@@ -132,2 +146,23 @@ _this.getValue(obj, varName)(it.value, eit); | ||
}); | ||
this.procAttr(elements, this.attrPrefix + 'class', function (it, attribute) { | ||
var _a; | ||
var script = attribute; | ||
if (script) { | ||
script = 'return ' + script; | ||
} | ||
if (_this.isUsingThisVar(script, varName) || varName === undefined) { | ||
var data = (_a = Function("\"use strict\"; const $target = this.$target; " + script + " ").bind(Object.assign({ $target: it }, obj))()) !== null && _a !== void 0 ? _a : {}; | ||
for (var _i = 0, _b = Object.entries(data); _i < _b.length; _i++) { | ||
var _c = _b[_i], key = _c[0], value = _c[1]; | ||
if (it instanceof HTMLElement) { | ||
if (value) { | ||
it.classList.add(key); | ||
} | ||
else { | ||
it.classList.remove(key); | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
@@ -134,0 +169,0 @@ class_1.prototype.addDrEvent = function (obj, eventName, elements) { |
{ | ||
"name": "dom-render", | ||
"version": "1.0.21", | ||
"version": "1.0.22", | ||
"main": "DomRender.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -5,2 +5,11 @@ export declare class ScriptUtils { | ||
static eval(script: string, thisTarget: any): any; | ||
static loadElement(name: string, attribute: { | ||
[key: string]: string; | ||
}, target?: Element): Promise<unknown>; | ||
static loadStyleSheet(href: string, attribute?: { | ||
[key: string]: string; | ||
}): Promise<unknown>; | ||
static loadScript(src: string, attribute?: { | ||
[key: string]: string; | ||
}): Promise<unknown>; | ||
} |
@@ -47,4 +47,30 @@ "use strict"; | ||
}; | ||
ScriptUtils.loadElement = function (name, attribute, target) { | ||
if (target === void 0) { target = document.head; } | ||
return new Promise(function (resolve, reject) { | ||
var tag = document.createElement(name); | ||
tag.onload = resolve; | ||
tag.onerror = reject; | ||
for (var _i = 0, _a = Object.entries(attribute); _i < _a.length; _i++) { | ||
var _b = _a[_i], key = _b[0], value = _b[1]; | ||
tag.setAttribute(key, value); | ||
} | ||
target.append(tag); | ||
}); | ||
}; | ||
ScriptUtils.loadStyleSheet = function (href, attribute) { | ||
if (attribute === void 0) { attribute = {}; } | ||
attribute.type = 'text/css'; | ||
attribute.rel = 'stylesheet'; | ||
attribute.href = href; | ||
return ScriptUtils.loadElement('link', attribute); | ||
}; | ||
ScriptUtils.loadScript = function (src, attribute) { | ||
if (attribute === void 0) { attribute = {}; } | ||
attribute.type = 'text/javascript'; | ||
attribute.src = src; | ||
return ScriptUtils.loadElement('script', attribute); | ||
}; | ||
return ScriptUtils; | ||
}()); | ||
exports.ScriptUtils = ScriptUtils; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
113474
2293
5