Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
MathPrettyPrinter
Commits
f1fcf685
Commit
f1fcf685
authored
Aug 15, 2018
by
Jean-Marc Ronck
Browse files
Merge branch 'bugfixes' into 'master'
Bug Fixes See merge request
!11
parents
c77bf77e
0e2c6211
Pipeline
#68387
passed with stages
in 2 minutes and 29 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
f1fcf685
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<groupId>
de.monticore.lang.monticar
</groupId>
<groupId>
de.monticore.lang.monticar
</groupId>
<artifactId>
math-pretty-printer
</artifactId>
<artifactId>
math-pretty-printer
</artifactId>
<version>
0.3.
0
-SNAPSHOT
</version>
<version>
0.3.
1
-SNAPSHOT
</version>
<properties>
<properties>
...
@@ -149,6 +149,31 @@
...
@@ -149,6 +149,31 @@
<version>
2.8.1
</version>
<version>
2.8.1
</version>
</plugin>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-assembly-plugin
</artifactId>
<version>
2.6
</version>
<configuration>
<descriptorRefs>
<descriptorRef>
jar-with-dependencies
</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>
de.monticore.lang.monticar.mpp.core.application.Application
</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>
assemble-all
</id>
<phase>
package
</phase>
<goals>
<goal>
single
</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Other Configuration -->
<!-- Other Configuration -->
<plugin>
<plugin>
<artifactId>
maven-compiler-plugin
</artifactId>
<artifactId>
maven-compiler-plugin
</artifactId>
...
...
src/main/java/de/monticore/lang/monticar/mpp/core/tex/SVGGenerator.java
View file @
f1fcf685
...
@@ -50,7 +50,7 @@ public class SVGGenerator {
...
@@ -50,7 +50,7 @@ public class SVGGenerator {
icon
.
setInsets
(
new
Insets
(
0
,
0
,
0
,
0
));
icon
.
setInsets
(
new
Insets
(
0
,
0
,
0
,
0
));
graphics
.
setSVGCanvasSize
(
new
Dimension
(
icon
.
getIconWidth
(),
icon
.
getIconHeight
()));
graphics
.
setSVGCanvasSize
(
new
Dimension
(
icon
.
getIconWidth
(),
icon
.
getIconHeight
()));
graphics
.
setColor
(
new
Color
(
37
,
37
,
37
));
graphics
.
setColor
(
new
Color
(
37
,
37
,
37
,
0
));
graphics
.
fillRect
(
0
,
0
,
icon
.
getIconWidth
(),
icon
.
getIconHeight
());
graphics
.
fillRect
(
0
,
0
,
icon
.
getIconWidth
(),
icon
.
getIconHeight
());
icon
.
paintIcon
(
null
,
graphics
,
0
,
0
);
icon
.
paintIcon
(
null
,
graphics
,
0
,
0
);
...
...
src/main/java/de/monticore/lang/monticar/mpp/montimath/MathPrettyPrinter.java
View file @
f1fcf685
package
de.monticore.lang.monticar.mpp.montimath
;
package
de.monticore.lang.monticar.mpp.montimath
;
import
de.monticore.assignmentexpressions._ast.ASTMinusPrefixExpression
;
import
de.monticore.ast.Comment
;
import
de.monticore.ast.Comment
;
import
de.monticore.commonexpressions._ast.*
;
import
de.monticore.commonexpressions._ast.*
;
import
de.monticore.lang.math._ast.*
;
import
de.monticore.lang.math._ast.*
;
...
@@ -10,6 +11,7 @@ import de.monticore.lang.matrixexpressions._ast.*;
...
@@ -10,6 +11,7 @@ import de.monticore.lang.matrixexpressions._ast.*;
import
de.monticore.lang.monticar.ranges._ast.ASTRange
;
import
de.monticore.lang.monticar.ranges._ast.ASTRange
;
import
de.monticore.lang.monticar.types2._ast.ASTDimension
;
import
de.monticore.lang.monticar.types2._ast.ASTDimension
;
import
de.monticore.lang.monticar.types2._ast.ASTElementType
;
import
de.monticore.lang.monticar.types2._ast.ASTElementType
;
import
de.monticore.literals.literals._ast.ASTDoubleLiteral
;
import
de.monticore.literals.literals._ast.ASTIntLiteral
;
import
de.monticore.literals.literals._ast.ASTIntLiteral
;
import
de.monticore.literals.literals._ast.ASTSignedIntLiteral
;
import
de.monticore.literals.literals._ast.ASTSignedIntLiteral
;
import
de.monticore.numberunit._ast.ASTNumberWithInf
;
import
de.monticore.numberunit._ast.ASTNumberWithInf
;
...
@@ -272,7 +274,8 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
...
@@ -272,7 +274,8 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
@Override
@Override
public
void
visit
(
ASTMathAssignmentStatement
node
)
{
public
void
visit
(
ASTMathAssignmentStatement
node
)
{
this
.
printComments
(
node
.
get_PreCommentList
());
this
.
printComments
(
node
.
get_PreCommentList
());
this
.
printer
.
print
(
node
.
getName
());
if
(
node
.
isPresentName
())
this
.
printer
.
print
(
node
.
getName
());
}
}
@Override
@Override
...
@@ -348,7 +351,7 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
...
@@ -348,7 +351,7 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
}
}
@Override
@Override
public
void
visit
(
ASTLessThanExpression
node
)
{
public
void
re
visit
(
ASTLessThanExpression
node
)
{
this
.
printSpace
();
this
.
printSpace
();
this
.
printer
.
print
(
node
.
getOperator
());
this
.
printer
.
print
(
node
.
getOperator
());
this
.
printSpace
();
this
.
printSpace
();
...
@@ -367,14 +370,14 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
...
@@ -367,14 +370,14 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
}*/
}*/
@Override
@Override
public
void
visit
(
ASTLessEqualExpression
node
)
{
public
void
re
visit
(
ASTLessEqualExpression
node
)
{
this
.
printSpace
();
this
.
printSpace
();
this
.
printer
.
print
(
node
.
getOperator
());
this
.
printer
.
print
(
node
.
getOperator
());
this
.
printSpace
();
this
.
printSpace
();
}
}
@Override
@Override
public
void
visit
(
ASTGreaterThanExpression
node
)
{
public
void
re
visit
(
ASTGreaterThanExpression
node
)
{
this
.
printSpace
();
this
.
printSpace
();
this
.
printer
.
print
(
node
.
getOperator
());
this
.
printer
.
print
(
node
.
getOperator
());
this
.
printSpace
();
this
.
printSpace
();
...
@@ -555,6 +558,13 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
...
@@ -555,6 +558,13 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
this
.
printSpace
();
this
.
printSpace
();
}
}
@Override
public
void
revisit
(
ASTNotEqualsExpression
node
)
{
this
.
printSpace
();
this
.
printer
.
print
(
node
.
getOperator
());
this
.
printSpace
();
}
@Override
@Override
public
void
revisit
(
ASTGreaterEqualExpression
node
)
{
public
void
revisit
(
ASTGreaterEqualExpression
node
)
{
this
.
printSpace
();
this
.
printSpace
();
...
@@ -576,6 +586,13 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
...
@@ -576,6 +586,13 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
this
.
printSpace
();
this
.
printSpace
();
}
}
@Override
public
void
revisit
(
ASTBooleanAndOpExpression
node
)
{
this
.
printSpace
();
this
.
printer
.
print
(
node
.
getOperator
());
this
.
printSpace
();
}
@Override
@Override
public
void
revisit
(
ASTMathArithmeticPowerOfExpression
node
)
{
public
void
revisit
(
ASTMathArithmeticPowerOfExpression
node
)
{
this
.
printCircumFlex
();
this
.
printCircumFlex
();
...
@@ -632,4 +649,14 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
...
@@ -632,4 +649,14 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
this
.
printer
.
print
(
".\\"
);
this
.
printer
.
print
(
".\\"
);
this
.
printSpace
();
this
.
printSpace
();
}
}
@Override
public
void
visit
(
ASTDoubleLiteral
node
)
{
this
.
printer
.
print
(
node
.
getValue
());
}
@Override
public
void
visit
(
ASTMinusPrefixExpression
node
)
{
this
.
printer
.
print
(
"-"
);
}
}
}
src/main/java/de/monticore/lang/monticar/mpp/montimath/MathStructuredVisitor.java
View file @
f1fcf685
...
@@ -99,12 +99,15 @@ public interface MathStructuredVisitor extends MathVisitor {
...
@@ -99,12 +99,15 @@ public interface MathStructuredVisitor extends MathVisitor {
@Override
@Override
default
void
handle
(
ASTLessThanExpression
node
)
{
default
void
handle
(
ASTLessThanExpression
node
)
{
this
.
getRealThis
().
traversePartOne
(
node
);
this
.
getRealThis
().
visit
(
node
);
this
.
getRealThis
().
visit
(
node
);
this
.
getRealThis
().
traversePartOne
(
node
);
this
.
getRealThis
().
revisit
(
node
);
this
.
getRealThis
().
traversePartTwo
(
node
);
this
.
getRealThis
().
traversePartTwo
(
node
);
this
.
getRealThis
().
endVisit
(
node
);
this
.
getRealThis
().
endVisit
(
node
);
}
}
default
void
revisit
(
ASTLessThanExpression
node
)
{}
default
void
traversePartOne
(
ASTLessThanExpression
node
)
{
default
void
traversePartOne
(
ASTLessThanExpression
node
)
{
if
(
null
!=
node
.
getLeftExpression
())
{
if
(
null
!=
node
.
getLeftExpression
())
{
node
.
getLeftExpression
().
accept
(
this
.
getRealThis
());
node
.
getLeftExpression
().
accept
(
this
.
getRealThis
());
...
@@ -119,12 +122,15 @@ public interface MathStructuredVisitor extends MathVisitor {
...
@@ -119,12 +122,15 @@ public interface MathStructuredVisitor extends MathVisitor {
@Override
@Override
default
void
handle
(
ASTLessEqualExpression
node
)
{
default
void
handle
(
ASTLessEqualExpression
node
)
{
this
.
getRealThis
().
traversePartOne
(
node
);
this
.
getRealThis
().
visit
(
node
);
this
.
getRealThis
().
visit
(
node
);
this
.
getRealThis
().
traversePartOne
(
node
);
this
.
getRealThis
().
revisit
(
node
);
this
.
getRealThis
().
traversePartTwo
(
node
);
this
.
getRealThis
().
traversePartTwo
(
node
);
this
.
getRealThis
().
endVisit
(
node
);
this
.
getRealThis
().
endVisit
(
node
);
}
}
default
void
revisit
(
ASTLessEqualExpression
node
)
{}
default
void
traversePartOne
(
ASTLessEqualExpression
node
)
{
default
void
traversePartOne
(
ASTLessEqualExpression
node
)
{
if
(
null
!=
node
.
getLeftExpression
())
{
if
(
null
!=
node
.
getLeftExpression
())
{
node
.
getLeftExpression
().
accept
(
this
.
getRealThis
());
node
.
getLeftExpression
().
accept
(
this
.
getRealThis
());
...
...
src/main/java/de/monticore/lang/monticar/mpp/montimath/TeXMathPrettyPrinter.java
View file @
f1fcf685
...
@@ -10,6 +10,7 @@ import de.monticore.lang.monticar.types2._ast.ASTDimension;
...
@@ -10,6 +10,7 @@ import de.monticore.lang.monticar.types2._ast.ASTDimension;
import
de.monticore.lang.monticar.types2._ast.ASTElementType
;
import
de.monticore.lang.monticar.types2._ast.ASTElementType
;
import
de.monticore.lang.matrixexpressions._ast.*
;
import
de.monticore.lang.matrixexpressions._ast.*
;
import
de.monticore.numberunit._ast.ASTTimeDiv
;
import
de.monticore.numberunit._ast.ASTTimeDiv
;
import
de.monticore.numberunit._ast.ASTUnitBaseDimWithPrefix
;
public
class
TeXMathPrettyPrinter
extends
MathPrettyPrinter
implements
TeXMathStructuredVisitor
{
public
class
TeXMathPrettyPrinter
extends
MathPrettyPrinter
implements
TeXMathStructuredVisitor
{
protected
boolean
needsParenthesis
;
protected
boolean
needsParenthesis
;
...
@@ -27,6 +28,11 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
...
@@ -27,6 +28,11 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
this
.
printer
.
print
(
printedNode
);
this
.
printer
.
print
(
printedNode
);
}
}
@Override
public
void
endVisit
(
ASTElementType
node
)
{
this
.
printer
.
print
(
"\\;"
);
}
@Override
@Override
public
void
revisit
(
ASTDimension
ast
)
{
public
void
revisit
(
ASTDimension
ast
)
{
this
.
printSpace
();
this
.
printSpace
();
...
@@ -65,15 +71,22 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
...
@@ -65,15 +71,22 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
@Override
@Override
public
void
revisit
(
ASTMathAssignmentDeclarationStatement
node
)
{
public
void
revisit
(
ASTMathAssignmentDeclarationStatement
node
)
{
this
.
printer
.
print
(
"~"
);
String
printedNode
=
String
.
format
(
"\\text{%s}"
,
node
.
getName
());
this
.
printer
.
print
(
node
.
getName
());
this
.
printer
.
print
(
"~"
);
//this.printer.print("~");
this
.
printer
.
print
(
printedNode
);
//this.printer.print("~");
}
}
@Override
@Override
public
void
visit
(
ASTMathAssignmentStatement
node
)
{
public
void
visit
(
ASTMathAssignmentStatement
node
)
{
this
.
printer
.
print
(
node
.
getName
());
if
(
node
.
isPresentName
())
{
this
.
printer
.
print
(
"~"
);
String
printedNode
=
String
.
format
(
"\\text{%s}"
,
node
.
getName
());
this
.
printer
.
print
(
printedNode
);
}
//this.printer.print("~");
}
}
@Override
@Override
...
@@ -83,7 +96,7 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
...
@@ -83,7 +96,7 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
@Override
@Override
public
void
endVisit
(
ASTMathDeclarationStatement
node
)
{
public
void
endVisit
(
ASTMathDeclarationStatement
node
)
{
this
.
printer
.
print
(
"~"
);
//
this.printer.print("~");
this
.
printer
.
print
(
node
.
getName
());
this
.
printer
.
print
(
node
.
getName
());
this
.
printSemicolon
();
this
.
printSemicolon
();
this
.
printer
.
println
();
this
.
printer
.
println
();
...
@@ -93,10 +106,12 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
...
@@ -93,10 +106,12 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
public
void
visit
(
ASTTimeDiv
node
)
{
public
void
visit
(
ASTTimeDiv
node
)
{
//TODO: Create LaTeX
//TODO: Create LaTeX
if
(
node
.
isPresentIsDiv
())
{
if
(
node
.
isPresentIsDiv
())
{
this
.
printer
.
print
(
"\\;"
);
this
.
printer
.
print
(
node
.
getIsDiv
());
this
.
printer
.
print
(
node
.
getIsDiv
());
}
}
if
(
node
.
isPresentIsTime
())
{
if
(
node
.
isPresentIsTime
())
{
this
.
printer
.
print
(
"\\;"
);
this
.
printer
.
print
(
"\\cdot"
);
this
.
printer
.
print
(
"\\cdot"
);
}
}
}
}
...
@@ -187,14 +202,14 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
...
@@ -187,14 +202,14 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
}
}
@Override
@Override
public
void
visit
(
ASTLessThanExpression
node
)
{
public
void
re
visit
(
ASTLessThanExpression
node
)
{
this
.
printSpace
();
this
.
printSpace
();
this
.
printer
.
print
(
"<"
);
this
.
printer
.
print
(
"<"
);
this
.
printSpace
();
this
.
printSpace
();
}
}
@Override
@Override
public
void
visit
(
ASTLessEqualExpression
node
)
{
public
void
re
visit
(
ASTLessEqualExpression
node
)
{
this
.
printSpace
();
this
.
printSpace
();
this
.
printer
.
print
(
"\\leqslant"
);
this
.
printer
.
print
(
"\\leqslant"
);
this
.
printSpace
();
this
.
printSpace
();
...
@@ -228,6 +243,13 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
...
@@ -228,6 +243,13 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
this
.
printSpace
();
this
.
printSpace
();
}
}
@Override
public
void
revisit
(
ASTNotEqualsExpression
node
)
{
this
.
printSpace
();
this
.
printer
.
print
(
"\\neq"
);
this
.
printSpace
();
}
@Override
@Override
public
void
visit
(
ASTMathIfExpression
node
)
{
/* NOOP */
}
public
void
visit
(
ASTMathIfExpression
node
)
{
/* NOOP */
}
...
@@ -257,4 +279,23 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
...
@@ -257,4 +279,23 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
public
void
endVisit
(
ASTMathArithmeticMatrixEERightDivideExpression
node
)
{
public
void
endVisit
(
ASTMathArithmeticMatrixEERightDivideExpression
node
)
{
this
.
printer
.
print
(
"^{\\circ(-1)}"
);
this
.
printer
.
print
(
"^{\\circ(-1)}"
);
}
}
@Override
public
void
visit
(
ASTNameExpression
node
)
{
String
printedNode
=
String
.
format
(
"\\text{%s}"
,
node
.
getName
());
this
.
printer
.
print
(
printedNode
);
}
@Override
public
void
visit
(
ASTUnitBaseDimWithPrefix
node
)
{
this
.
printer
.
print
(
"\\;"
);
this
.
printer
.
print
(
node
.
getName
());
}
@Override
public
void
endVisit
(
ASTDimension
node
)
{
this
.
printRightCurlyBracket
();
this
.
printer
.
print
(
"\\;"
);
}
}
}
src/main/resources/templates/script.ftl
View file @
f1fcf685
...
@@ -96,6 +96,7 @@
...
@@ -96,6 +96,7 @@
position
:
fixed
;
position
:
fixed
;
top
:
0
;
top
:
0
;
right
:
0
;
right
:
0
;
z-index
:
2
;
}
}
input
{
input
{
...
@@ -122,6 +123,16 @@
...
@@ -122,6 +123,16 @@
input.latex {
input.latex {
background-image: url("data:image/svg+xml;charset=UTF-8,%3c?xml version='
1.0
' encoding='
UTF-8
' standalone='
no
'?%3e%3csvg xmlns='
http
://
www
.
w3
.
org
/
2000
/
svg
' version='
1.1
' height='
568.88px
' width='
588.42px
'%3e%3cpath style='
fill
:
black
;
stroke
:
none
' d='
M
10.499686
,
177.03840
L
31.174931
,
178.56990
C
52.615925
,
154.32116
61.039171
,
82.595924
187.38789
,
96.634671
C
182.79339
,
403.95560
48.021426
,
436.37234
56.444675
,
499.41907
C
59.507674
,
535.15406
87.840417
,
557.10556
118.47041
,
558.38181
C
215.21014
,
555.06356
210.87089
,
424.63084
240.99038
,
95.868921
L
365.80760
,
95.868921
C
359.17110
,
211.75239
341.04836
,
327.63586
339.00636
,
441.22208
C
340.53786
,
516.77606
386.48285
,
557.10556
446.97708
,
557.61606
C
546.52456
,
560.93431
577.92030
,
444.79558
577.92030
,
395.27709
L
556.47931
,
395.27710
C
554.43731
,
436.11709
534.78306
,
465.47083
492.92207
,
467.25758
C
378.82535
,
468.78908
441.61683
,
266.63113
442.38258
,
97.400421
L
577.92030
,
98.166171
L
577.15455
,
11.636437
C
13.807491
,
8.9075799
85.312284
,
-2.1366151
10.499686
,
177.03840
z
'
/
%
3
e
%
3
c
/
svg
%
3
e
"
);
background-image: url("data:image/svg+xml;charset=UTF-8,%3c?xml version='
1.0
' encoding='
UTF-8
' standalone='
no
'?%3e%3csvg xmlns='
http
://
www
.
w3
.
org
/
2000
/
svg
' version='
1.1
' height='
568.88px
' width='
588.42px
'%3e%3cpath style='
fill
:
black
;
stroke
:
none
' d='
M
10.499686
,
177.03840
L
31.174931
,
178.56990
C
52.615925
,
154.32116
61.039171
,
82.595924
187.38789
,
96.634671
C
182.79339
,
403.95560
48.021426
,
436.37234
56.444675
,
499.41907
C
59.507674
,
535.15406
87.840417
,
557.10556
118.47041
,
558.38181
C
215.21014
,
555.06356
210.87089
,
424.63084
240.99038
,
95.868921
L
365.80760
,
95.868921
C
359.17110
,
211.75239
341.04836
,
327.63586
339.00636
,
441.22208
C
340.53786
,
516.77606
386.48285
,
557.10556
446.97708
,
557.61606
C
546.52456
,
560.93431
577.92030
,
444.79558
577.92030
,
395.27709
L
556.47931
,
395.27710
C
554.43731
,
436.11709
534.78306
,
465.47083
492.92207
,
467.25758
C
378.82535
,
468.78908
441.61683
,
266.63113
442.38258
,
97.400421
L
577.92030
,
98.166171
L
577.15455
,
11.636437
C
13.807491
,
8.9075799
85.312284
,
-2.1366151
10.499686
,
177.03840
z
'
/
%
3
e
%
3
c
/
svg
%
3
e
"
);
}
}
tr
.marked
{
transition-duration
:
2s
;
background-color
:
#FFA500
;
color
:
#000
;
}
tr
.marked
img
{
filter
:
invert
(
100%
);
}
--
>
--
>
</style>
</style>
<noscript>
<noscript>
...
@@ -179,11 +190,52 @@
...
@@ -179,11 +190,52 @@
<script>
<script>
var
radios
=
document
.
querySelectorAll
(
"
input[name='View']
"
);
var
radios
=
document
.
querySelectorAll
(
"
input[name='View']
"
);
var
card
=
document
.
querySelector
(
"
.card
"
);
var
card
=
document
.
querySelector
(
"
.card
"
);
var
front
=
document
.
querySelectorAll
(
"
.card-face-front tr
"
);
var
back
=
document
.
querySelectorAll
(
"
.card-face-back tr
"
);
function
clickButton
(
index
)
{
radios
[
index
].
click
();
}
function
selectRange
(
start
,
end
)
{
for
(
var
i
=
start
-
1
;
i
<
(
end
||
start
);
i
++
)
{
front
[
i
].
classList
.
add
(
"
marked
"
);
back
[
i
].
classList
.
add
(
"
marked
"
);
}
}
function
scroll
(
index
,
start
)
{
start
=
start
-
1
;
window
.
scrollTo
(
0
,
index
===
0
?
front
[
start
].
offsetTop
:
back
[
start
].
offsetTop
);
}
function
onChange
(
event
)
{
function
onChange
(
event
)
{
card
.
classList
.
toggle
(
"
flipped
"
);
card
.
classList
.
toggle
(
"
flipped
"
);
}
}
function
onHashChange
()
{
window
.
setTimeout
(
function
()
{
var
hash
=
window
.
location
.
hash
;
var
parts
=
hash
.
substring
(
1
).
split
(
'
:
'
);
var
index
=
parts
[
0
];
var
start
=
parts
[
1
];
var
end
=
parts
[
2
];
if
(
index
)
{
clickButton
(
index
);
if
(
start
)
{
scroll
(
index
,
start
);
selectRange
(
start
,
end
);
}
}
},
0
);
}
radios
.
forEach
(
function
(
element
)
{
element
.
addEventListener
(
"
change
"
,
onChange
)
});
radios
.
forEach
(
function
(
element
)
{
element
.
addEventListener
(
"
change
"
,
onChange
)
});
onHashChange
();
window
.
addEventListener
(
"
hashchange
"
,
onHashChange
);
</script>
</script>
</html>
</html>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment