Skip to content

Commit 8e3f245

Browse files
committed
Merge pull request #5 from Mcpoowl/master
Added onClick functionality
2 parents bae6a3a + 12781f1 commit 8e3f245

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ For more information on contributing to this repository visit [Contributing to a
1515

1616
* Embed raw HTML
1717
* Embed raw JavaScript
18+
* Load external HTML / JS file
1819

1920
## Dependencies
2021
* Mendix 5.x environment
@@ -25,5 +26,9 @@ For more information on contributing to this repository visit [Contributing to a
2526
Select how the snippet should be rendered. The JavaScript with jQuery option will make sure that jQuery 1.11.3 is loaded and should be available on window.jQuery for the snippet.
2627
* Contents :
2728
The HTML or Javascript to embed.
29+
* External File :
30+
The path to the HTML or JavaScript file you want to add. The root is the theme folder. Will override the Contents section if used.
31+
* On click microflow :
32+
The microflow which should be executed on click. This can be used to, for example, show a page when the snippet is being clicked.
2833
* Documentation :
2934
Documentation of this widget. Should explain its purpose.

src/HTMLSnippet/HTMLSnippet.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
<category>Behavior</category>
3535
<description>The path to the HTML or Javascript you want to add. The root folder is theme folder. Will override the Contents if used.</description>
3636
</property>
37+
38+
<!-- The onclick microflow -->
39+
<property key="onclickmf" type="microflow" required="false">
40+
<caption> On click microflow </caption>
41+
<category>Behavior</category>
42+
<description>The microflow to execute on click</description>
43+
<returnType type="Void"/>
44+
</property>
3745

3846
<!-- description of what the html/js should do -->
3947
<property key="documentation" type="string" multiline="true" required="false">

src/HTMLSnippet/widget/HTMLSnippet.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ require([
1010
return declare('HTMLSnippet.widget.HTMLSnippet', [_WidgetBase], {
1111
postCreate: function () {
1212
var external = this.contentsPath !== '' ? true : false;
13+
14+
this._setupEvents();
1315

1416
switch (this.contenttype) {
1517
case 'html':
@@ -57,6 +59,32 @@ require([
5759
break;
5860
}
5961
},
62+
63+
_setupEvents: function () {
64+
if (this.onclickmf) {
65+
this.connect(this.domNode, "click", this._executeMicroflow)};
66+
},
67+
68+
_executeMicroflow: function () {
69+
if (this.onclickmf) {
70+
mx.data.action({
71+
store: {
72+
caller: this.mxform
73+
},
74+
params: {
75+
actionname: this.onclickmf
76+
},
77+
callback: function () {
78+
// ok
79+
},
80+
error: function () {
81+
// error
82+
}
83+
84+
});
85+
}
86+
},
87+
6088

6189
evalJs: function () {
6290
try {

test/widgets/HTMLSnippet.mpk

870 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)