MCPcopy Create free account
hub / github.com/bigskysoftware/_hyperscript / toggle

Method toggle

www/js/_hyperscript-max.js:8029–8090  ·  view source on GitHub ↗
(context, on, classRef, classRef2, classRefs, betweenValues)

Source from the content-addressed store, hash-verified

8027 return new _ToggleCommand(classRef, classRef2, classRefs, attributeRef, attributeRef2, onExpr, time, evt, from, visibility, betweenClass, betweenAttr, hideShowStrategy, betweenValues, toggleExpr, styleProp);
8028 }
8029 toggle(context, on, classRef, classRef2, classRefs, betweenValues) {
8030 if (this.betweenValues) {
8031 if (this.visibility) {
8032 context.meta.runtime.implicitLoop(on, (target) => {
8033 var current2 = target.style[this.styleProp] || getComputedStyle(target)[this.styleProp];
8034 var idx2 = betweenValues.findIndex((v) => v == current2);
8035 target.style[this.styleProp] = betweenValues[(idx2 + 1) % betweenValues.length];
8036 });
8037 } else {
8038 var current = this.toggleExpr.evaluate(context);
8039 var idx = betweenValues.findIndex((v) => v == current);
8040 var next = betweenValues[(idx + 1) % betweenValues.length];
8041 var lhsValues = {};
8042 for (var key in this.toggleExpr.lhs) {
8043 var val = this.toggleExpr.lhs[key];
8044 lhsValues[key] = val && val.evaluate ? val.evaluate(context) : val;
8045 }
8046 this.toggleExpr.set(context, lhsValues, next);
8047 }
8048 return;
8049 }
8050 context.meta.runtime.nullCheck(on, this.onExpr);
8051 if (this.visibility) {
8052 context.meta.runtime.implicitLoop(on, (target) => {
8053 this.hideShowStrategy("toggle", target, null, context.meta.runtime);
8054 });
8055 } else if (this.betweenClass) {
8056 context.meta.runtime.implicitLoop(on, (target) => {
8057 if (target.classList.contains(classRef.className)) {
8058 target.classList.remove(classRef.className);
8059 target.classList.add(classRef2.className);
8060 } else {
8061 target.classList.add(classRef.className);
8062 target.classList.remove(classRef2.className);
8063 }
8064 });
8065 } else if (this.betweenAttr) {
8066 context.meta.runtime.implicitLoop(on, (target) => {
8067 if (target.hasAttribute(this.attributeRef.name) && target.getAttribute(this.attributeRef.name) === this.attributeRef.value) {
8068 target.removeAttribute(this.attributeRef.name);
8069 target.setAttribute(this.attributeRef2.name, this.attributeRef2.value);
8070 } else {
8071 if (target.hasAttribute(this.attributeRef2.name)) target.removeAttribute(this.attributeRef2.name);
8072 target.setAttribute(this.attributeRef.name, this.attributeRef.value);
8073 }
8074 });
8075 } else if (classRefs) {
8076 context.meta.runtime.forEach(classRefs, (classRef3) => {
8077 context.meta.runtime.implicitLoop(on, (target) => {
8078 target.classList.toggle(classRef3.className);
8079 });
8080 });
8081 } else {
8082 context.meta.runtime.implicitLoop(on, (target) => {
8083 if (target.hasAttribute(this.attributeRef.name)) {
8084 target.removeAttribute(this.attributeRef.name);
8085 } else {
8086 target.setAttribute(this.attributeRef.name, this.attributeRef.value);

Callers 1

resolveMethod · 0.95

Calls 7

getComputedStyleFunction · 0.50
implicitLoopMethod · 0.45
evaluateMethod · 0.45
setMethod · 0.45
nullCheckMethod · 0.45
containsMethod · 0.45
forEachMethod · 0.45

Tested by

no test coverage detected