@@ -731,6 +731,12 @@ search
731
731
header = if tagname = "div" then "true" else "false"
732
732
bind
733
733
hello <- [ class: [ header]]
734
+ ~~~
735
+
736
+ Commit an element with a greeting
737
+ ~~~
738
+ commit
739
+ [ #html/element tagname: "div" text: "Hello world!"]
734
740
~~~ </code>
735
741
</td>
736
742
</tr>
@@ -755,7 +761,8 @@ commit a div to the browser with the text "Hover over me!" that will change its
755
761
~~~
756
762
commit
757
763
[ #ui/div #html/listener/hover text: "Hover over me!"]
758
- ~~~ </code>
764
+ ~~~
765
+ </code>
759
766
</td>
760
767
</tr>
761
768
</table>
@@ -775,13 +782,20 @@ commit
775
782
</td>
776
783
<td>
777
784
<code>
778
- if a #ui/a element with the hover listener is being hovered over, add a style to make the font bold
785
+ commit a div to the browser with the text "Hover over me!" that will change its record if it is hovered over
786
+ ~~~
787
+ commit
788
+ [ #ui/div #html/listener/hover text: "Hover over me!"]
789
+ ~~~
790
+
791
+ Display a message when an element with the #html/listener/hover`
779
792
~~~
780
793
search
781
- element = [ #ui/a #html/hovered]
794
+ [ #html/hovered]
782
795
bind
783
- element.style <- [ font-weight: bold]
784
- ~~~ </code>
796
+ [ #ui/text text: "an element is being hovered"]
797
+ ~~~
798
+ </code>
785
799
</td>
786
800
</tr>
787
801
</table>
@@ -801,14 +815,21 @@ bind
801
815
</td>
802
816
<td>
803
817
<code>
804
- when the mouse enters an anchor tag, make the color red; the color will not revert when the mouse leaves
818
+ Do something on hover-in
805
819
~~~
806
820
search
807
- [ #html/event/hover-in element: anchor]
808
- anchor = [ #ui/a]
809
- bind
810
- anchor.style <- [ color: red]
811
- ~~~ </code>
821
+ direction = if [ #html/event/hover-in] then "in"
822
+ else if [ #html/event/hover-out] then "out"
823
+ commit
824
+ [ #ui/text text: "Hovered {{direction}}"]
825
+ ~~~
826
+
827
+ Monitor hover on an element
828
+ ~~~
829
+ commit
830
+ [ #ui/text #html/listener/hover text: "Hover over me" style: [ width: "100px" height: "100px" background-color: "rgb(226, 79, 94)" display: "block" color: "white" padding: "10px"]]
831
+ ~~~
832
+ </code>
812
833
</td>
813
834
</tr>
814
835
</table>
@@ -872,9 +893,18 @@ bind
872
893
looks for a right click in any h1 element and posts the message "Right clicked!"
873
894
~~~
874
895
search
875
- [ #html/event/mouse-up element: [ #ui/h1] button: "right"]
896
+ event = if [ #html/event/mouse-up button] then "up"
897
+ else if [ #html/event/mouse-down button] then "down"
898
+ else if [ #html/event/click button] then "click"
899
+ else if [ #html/event/double-click button] then "double-click"
876
900
commit
877
- [ #ui/div text: "Right clicked!"]
901
+ [ #ui/text text: "{{event}}"]
902
+ ~~~
903
+
904
+ Monitor clicks on an element
905
+ ~~~
906
+ commit
907
+ [ #ui/text text: "Click me" style: [ width: "100px" height: "100px" background-color: "rgb(226, 79, 94)" display: "block" color: "white" padding: "10px"]]
878
908
~~~ </code>
879
909
</td>
880
910
</tr>
@@ -894,11 +924,14 @@ commit
894
924
</ul>
895
925
</td>
896
926
<td>
897
- <code>commits an h1 element whose context menu won’t open if right clicked
927
+ <code>
928
+ commits an h1 element whose context menu won’t open if right clicked
898
929
~~~
899
930
commit
900
931
[ #ui/h1 #html/listener/context-menu text: "Don’t inspect me"]
901
- ~~~ </code>
932
+ [ #ui/h1 text: "Inspect me"]
933
+ ~~~
934
+ </code>
902
935
</td>
903
936
</tr>
904
937
</table>
@@ -934,13 +967,21 @@ commit
934
967
</td>
935
968
<td>
936
969
<code>
937
- when the escape key is released, commits a gentle reminder for the user
970
+ Prints a message with the code of the key pressed
971
+ ~~~
972
+ search
973
+ [ #html/event/key-down key-code]
974
+ commit
975
+ [ #ui/div #key-msg key-code text: "Pressed {{key-code}}"]
938
976
~~~
939
- search
940
- [ #html/event/key-up key: "escape"]
941
977
978
+ Remove messages for keys that are released
979
+ ~~~
980
+ search
981
+ [ #html/event/key-up key-code]
982
+ message = [ #key-msg key-code]
942
983
commit
943
- [ #ui/div text: "THERE IS NO ESCAPE" ]
984
+ message := none
944
985
~~~ </code>
945
986
</td>
946
987
</tr>
@@ -962,13 +1003,22 @@ commit
962
1003
</td>
963
1004
<td>
964
1005
<code>
965
- when the important element loses focus, commits a message to help the user
1006
+ Display a message on focus
966
1007
~~~
967
1008
search
968
- [ #html/event/blur element: [ #important]]
1009
+ [ #html/event/focus element]
1010
+
1011
+ commit
1012
+ [ #ui/text text: "{{element.placeholder}} was focused"]
1013
+ ~~~
1014
+
1015
+ Monitor clicks on an element
1016
+ ~~~
969
1017
commit
970
- [ #ui/text text: "Stay focused!"]
971
- ~~~ </code>
1018
+ [ #ui/input placeholder: "First Name"]
1019
+ [ #ui/input placeholder: "Last Name"]
1020
+ ~~~
1021
+ </code>
972
1022
</td>
973
1023
</tr>
974
1024
</table>
@@ -988,13 +1038,23 @@ commit
988
1038
</td>
989
1039
<td>
990
1040
<code>
1041
+ Commit some buttons and form elements
1042
+ ~~~
1043
+ commit
1044
+ [ #ui/input field: "first-name" placeholder: "First Name"]
1045
+ [ #ui/input field: "last-name" placeholder: "Last Name"]
1046
+ [ #ui/button text: "Focus first name" target: "first-name"]
1047
+ [ #ui/button text: "Focus last name" target: "last-name"]
1048
+ ~~~
1049
+
991
1050
when a form element is found in the browser with the name "first-name", focuses on that element
992
1051
~~~
993
1052
search
994
- first = [ #ui/input name: "first-name"]
1053
+ [ #html/event/click element: [ #ui/button target]]
1054
+ input = [ #ui/input field: target]
995
1055
996
1056
commit
997
- first <- [ #html/trigger/focus]
1057
+ input.tag <- [ #html/trigger/focus]
998
1058
~~~ </code>
999
1059
</td>
1000
1060
</tr>
0 commit comments