MCPcopy Index your code
hub / github.com/bigskysoftware/_hyperscript / toggle

Method toggle

tools/common/_hyperscript.iife.js:7607–7668  ·  view source on GitHub ↗
(context, on, classRef, classRef2, classRefs, betweenValues)

Source from the content-addressed store, hash-verified

7605 return new _ToggleCommand(classRef, classRef2, classRefs, attributeRef, attributeRef2, onExpr, time, evt, from, visibility, betweenClass, betweenAttr, hideShowStrategy, betweenValues, toggleExpr, styleProp);
7606 }
7607 toggle(context, on, classRef, classRef2, classRefs, betweenValues) {
7608 if (this.betweenValues) {
7609 if (this.visibility) {
7610 context.meta.runtime.implicitLoop(on, (target) => {
7611 var current2 = target.style[this.styleProp] || getComputedStyle(target)[this.styleProp];
7612 var idx2 = betweenValues.findIndex((v) => v == current2);
7613 target.style[this.styleProp] = betweenValues[(idx2 + 1) % betweenValues.length];
7614 });
7615 } else {
7616 var current = this.toggleExpr.evaluate(context);
7617 var idx = betweenValues.findIndex((v) => v == current);
7618 var next = betweenValues[(idx + 1) % betweenValues.length];
7619 var lhsValues = {};
7620 for (var key in this.toggleExpr.lhs) {
7621 var val = this.toggleExpr.lhs[key];
7622 lhsValues[key] = val && val.evaluate ? val.evaluate(context) : val;
7623 }
7624 this.toggleExpr.set(context, lhsValues, next);
7625 }
7626 return;
7627 }
7628 context.meta.runtime.nullCheck(on, this.onExpr);
7629 if (this.visibility) {
7630 context.meta.runtime.implicitLoop(on, (target) => {
7631 this.hideShowStrategy("toggle", target, null, context.meta.runtime);
7632 });
7633 } else if (this.betweenClass) {
7634 context.meta.runtime.implicitLoop(on, (target) => {
7635 if (target.classList.contains(classRef.className)) {
7636 target.classList.remove(classRef.className);
7637 target.classList.add(classRef2.className);
7638 } else {
7639 target.classList.add(classRef.className);
7640 target.classList.remove(classRef2.className);
7641 }
7642 });
7643 } else if (this.betweenAttr) {
7644 context.meta.runtime.implicitLoop(on, (target) => {
7645 if (target.hasAttribute(this.attributeRef.name) && target.getAttribute(this.attributeRef.name) === this.attributeRef.value) {
7646 target.removeAttribute(this.attributeRef.name);
7647 target.setAttribute(this.attributeRef2.name, this.attributeRef2.value);
7648 } else {
7649 if (target.hasAttribute(this.attributeRef2.name)) target.removeAttribute(this.attributeRef2.name);
7650 target.setAttribute(this.attributeRef.name, this.attributeRef.value);
7651 }
7652 });
7653 } else if (classRefs) {
7654 context.meta.runtime.forEach(classRefs, (classRef3) => {
7655 context.meta.runtime.implicitLoop(on, (target) => {
7656 target.classList.toggle(classRef3.className);
7657 });
7658 });
7659 } else {
7660 context.meta.runtime.implicitLoop(on, (target) => {
7661 if (target.hasAttribute(this.attributeRef.name)) {
7662 target.removeAttribute(this.attributeRef.name);
7663 } else {
7664 target.setAttribute(this.attributeRef.name, this.attributeRef.value);

Callers 1

resolveMethod · 0.95

Calls 7

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

Tested by

no test coverage detected