Skip to content

Commit 9f8c577

Browse files
made jquery widgets works in angular and reactjs boilerptlates
fixed sortablejs widget #23 #21
1 parent 0fdfc15 commit 9f8c577

File tree

9 files changed

+48
-43
lines changed

9 files changed

+48
-43
lines changed

src/bootstrap-slider.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function init(Survey) {
66
title: "Bootstrap Slider",
77
iconName: "icon-bootstrap-slider",
88
widgetIsLoaded: function() {
9-
return typeof Slider != "undefined";
9+
return typeof Slider !== "undefined";
1010
},
1111
isFit: function(question) {
1212
return question.getType() === "bootstrapslider";
@@ -37,7 +37,10 @@ function init(Survey) {
3737
inputEl.setAttribute("data-slider-min", question.rangeMin);
3838
inputEl.setAttribute("data-slider-max", question.rangeMax);
3939
inputEl.setAttribute("data-slider-step", question.step);
40-
inputEl.setAttribute("data-slider-value", question.value || question.rangeMin);
40+
inputEl.setAttribute(
41+
"data-slider-value",
42+
question.value || question.rangeMin
43+
);
4144
el.appendChild(inputEl);
4245
var slider = new Slider(inputEl, {
4346
id: question.name + "_" + question.id,

src/easy-autocomplete.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
function init(Survey) {
1+
function init(Survey, $) {
2+
$ = $ || window.$;
23
var widget = {
34
name: "autocomplete",
45
widgetIsLoaded: function() {
5-
return typeof $ === "function" && !!$.fn.easyAutocomplete;
6+
return !!$.fn.easyAutocomplete;
67
},
78
isFit: function(question) {
89
return question.getType() === "text";
@@ -79,7 +80,7 @@ function init(Survey) {
7980
}
8081

8182
if (typeof Survey !== "undefined") {
82-
init(Survey);
83+
init(Survey, window.$);
8384
}
8485

8586
export default init;

src/icheck.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
function init(Survey) {
1+
function init(Survey, $) {
2+
$ = $ || window.$;
23
var widget = {
34
className: "iradio_square-blue",
45
name: "icheck",
56
widgetIsLoaded: function() {
6-
return typeof $ == "function" && !!$.fn.iCheck;
7+
return !!$.fn.iCheck;
78
},
89
isFit: function(question) {
910
var t = question.getType();
@@ -58,7 +59,7 @@ function init(Survey) {
5859
}
5960

6061
if (typeof Survey !== "undefined") {
61-
init(Survey);
62+
init(Survey, window.$);
6263
}
6364

6465
export default init;

src/image-picker.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
function init(Survey) {
1+
function init(Survey, $) {
2+
$ = $ || window.$;
23
var widget = {
34
name: "imagepicker",
45
title: "Image picker",
56
iconName: "icon-imagepicker",
67
widgetIsLoaded: function() {
7-
return typeof $ == "function" && !!$.fn.imagepicker;
8+
return !!$.fn.imagepicker;
89
},
910
isFit: function(question) {
1011
return question.getType() === "imagepicker";
@@ -68,7 +69,7 @@ function init(Survey) {
6869
}
6970

7071
if (typeof Survey !== "undefined") {
71-
init(Survey);
72+
init(Survey, window.$);
7273
}
7374

7475
export default init;

src/jquery-bar-rating.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
function init(Survey) {
1+
function init(Survey, $) {
2+
$ = $ || window.$;
23
var widget = {
34
name: "barrating",
45
title: "Bar rating",
56
iconName: "icon-barrating",
67
widgetIsLoaded: function() {
7-
return typeof $ === "function" && !!$.fn.barrating;
8+
return !!$.fn.barrating;
89
},
910
defaultJSON: { choices: [1, 2, 3, 4, 5] },
1011
isFit: function(question) {
@@ -70,7 +71,7 @@ function init(Survey) {
7071
}
7172

7273
if (typeof Survey !== "undefined") {
73-
init(Survey);
74+
init(Survey, window.$);
7475
}
7576

7677
export default init;

src/jquery-ui-datepicker.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
function init(Survey) {
1+
function init(Survey, $) {
2+
$ = $ || window.$;
23
var widget = {
34
name: "datepicker",
45
title: "Date picker",
56
iconName: "icon-datepicker",
67
widgetIsLoaded: function() {
7-
return typeof $ == "function" && !!$.fn.datepicker;
8+
return !!$.fn.datepicker;
89
},
910
isFit: function(question) {
1011
return question.getType() === "datepicker";
@@ -15,25 +16,25 @@ function init(Survey) {
1516
Survey.JsonObject.metaData.addClass(
1617
"datepicker",
1718
[
18-
{
19-
name: "dateFormat",
20-
default: "mm/dd/yy",
21-
choices: [
22-
"mm/dd/yy",
23-
"yy-mm-dd",
24-
"d M, y",
25-
"d MM, y",
26-
"DD, d MM, yy",
27-
"'day' d 'of' MM 'in the year' yy"
28-
]
29-
},
3019
{ name: "inputType", visible: false },
3120
{ name: "inputFormat", visible: false },
3221
{ name: "inputMask", visible: false }
3322
],
3423
null,
3524
"text"
3625
);
26+
Survey.JsonObject.metaData.addProperty("datepicker", {
27+
name: "dateFormat",
28+
default: "mm/dd/yy",
29+
choices: [
30+
"mm/dd/yy",
31+
"yy-mm-dd",
32+
"d M, y",
33+
"d MM, y",
34+
"DD, d MM, yy",
35+
"'day' d 'of' MM 'in the year' yy"
36+
]
37+
});
3738
},
3839
afterRender: function(question, el) {
3940
var $el = $(el).is(".widget-datepicker")
@@ -70,7 +71,7 @@ function init(Survey) {
7071
}
7172

7273
if (typeof Survey !== "undefined") {
73-
init(Survey);
74+
init(Survey, window.$);
7475
}
7576

7677
export default init;

src/select2-tagbox.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import $ from "jquery";
2-
3-
function init(Survey) {
1+
function init(Survey, $) {
2+
$ = $ || window.$;
43
var widget = {
54
name: "tagbox",
65
title: "Tag box",
@@ -65,7 +64,7 @@ function init(Survey) {
6564
}
6665

6766
if (typeof Survey !== "undefined") {
68-
init(Survey);
67+
init(Survey, window.$);
6968
}
7069

7170
export default init;

src/select2.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import $ from "jquery";
2-
3-
function init(Survey) {
1+
function init(Survey, $) {
2+
$ = $ || window.$;
43
var widget = {
54
activatedBy: "property",
65
name: "select2",
@@ -15,9 +14,7 @@ function init(Survey) {
1514
question.getType() === "dropdown"
1615
);
1716
if (widget.activatedBy == "type")
18-
return (
19-
typeof Select2 !== undefined && question.getType() === "dropdown"
20-
);
17+
return typeof question.getType() === "dropdown";
2118
if (widget.activatedBy == "customtype")
2219
return question.getType() === "select2";
2320
return false;
@@ -93,7 +90,7 @@ function init(Survey) {
9390
}
9491

9592
if (typeof Survey !== "undefined") {
96-
init(Survey);
93+
init(Survey, window.$);
9794
}
9895

9996
export default init;

src/sortablejs.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function init(Survey) {
7474
});
7575
emptyEl.style.display = wasInResults ? "none" : "";
7676
};
77-
question.resultEl = Sortable.create($(resultEl)[0], {
77+
question.resultEl = Sortable.create(resultEl, {
7878
animation: 150,
7979
group: question.name,
8080
onSort: function(evt) {
@@ -84,7 +84,8 @@ function init(Survey) {
8484
} else {
8585
emptyEl.style.display = "none";
8686
for (var i = 0; i < resultEl.children.length; i++) {
87-
if(typeof resultEl.children[i].dataset.value === 'undefined') continue;
87+
if (typeof resultEl.children[i].dataset.value === "undefined")
88+
continue;
8889
result.push(resultEl.children[i].dataset.value);
8990
}
9091
}
@@ -93,7 +94,7 @@ function init(Survey) {
9394
isUpdatingQuestionValue = false;
9495
}
9596
});
96-
question.sourceEl = Sortable.create($(sourceEl)[0], {
97+
question.sourceEl = Sortable.create(sourceEl, {
9798
animation: 150,
9899
group: question.name
99100
});

0 commit comments

Comments
 (0)