Skip to content

Commit cc941bb

Browse files
prettier
1 parent fd42e37 commit cc941bb

File tree

12 files changed

+799
-597
lines changed

12 files changed

+799
-597
lines changed

src/ck-editor.js

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,51 @@
11
function init(Survey) {
2-
var widget = {
3-
name: "editor",
4-
title: "Editor",
5-
iconName: "icon-editor",
6-
widgetIsLoaded: function() { return typeof CKEDITOR != "undefined"; },
7-
isFit : function(question) {
8-
return question.getType() === 'editor';
9-
},
10-
htmlTemplate: "<textarea rows='10' cols='80' style: {width:'100%'}></textarea>",
11-
activatedByChanged: function(activatedBy) {
12-
Survey.JsonObject.metaData.addClass("editor", [], null, "empty");
13-
Survey.JsonObject.metaData.addProperty("editor", {name: "height", default: 300});
14-
},
15-
afterRender: function(question, el) {
16-
CKEDITOR.editorConfig = function (config) {
17-
config.language = 'es';
18-
config.height = question.height;
19-
config.toolbarCanCollapse = true;
20-
};
21-
var editor = CKEDITOR.replace(el);
22-
var isValueChanging = false;
23-
var updateValueHandler = function() {
24-
if(isValueChanging) return;
25-
editor.setData(question.value);
26-
};
27-
editor.on('change', function() {
28-
isValueChanging = true;
29-
question.value = editor.getData();
30-
isValueChanging = false;
31-
});
32-
question.valueChangedCallback = updateValueHandler;
33-
updateValueHandler();
34-
},
35-
willUnmount: function(question, el) {
36-
}
37-
}
2+
var widget = {
3+
name: 'editor',
4+
title: 'Editor',
5+
iconName: 'icon-editor',
6+
widgetIsLoaded: function() {
7+
return typeof CKEDITOR != 'undefined'
8+
},
9+
isFit: function(question) {
10+
return question.getType() === 'editor'
11+
},
12+
htmlTemplate:
13+
"<textarea rows='10' cols='80' style: {width:'100%'}></textarea>",
14+
activatedByChanged: function(activatedBy) {
15+
Survey.JsonObject.metaData.addClass('editor', [], null, 'empty')
16+
Survey.JsonObject.metaData.addProperty('editor', {
17+
name: 'height',
18+
default: 300,
19+
})
20+
},
21+
afterRender: function(question, el) {
22+
CKEDITOR.editorConfig = function(config) {
23+
config.language = 'es'
24+
config.height = question.height
25+
config.toolbarCanCollapse = true
26+
}
27+
var editor = CKEDITOR.replace(el)
28+
var isValueChanging = false
29+
var updateValueHandler = function() {
30+
if (isValueChanging) return
31+
editor.setData(question.value)
32+
}
33+
editor.on('change', function() {
34+
isValueChanging = true
35+
question.value = editor.getData()
36+
isValueChanging = false
37+
})
38+
question.valueChangedCallback = updateValueHandler
39+
updateValueHandler()
40+
},
41+
willUnmount: function(question, el) {},
42+
}
3843

39-
Survey.CustomWidgetCollection.Instance.addCustomWidget(widget, "customtype");
44+
Survey.CustomWidgetCollection.Instance.addCustomWidget(widget, 'customtype')
4045
}
4146

42-
if (typeof Survey !== "undefined") {
43-
init(Survey);
47+
if (typeof Survey !== 'undefined') {
48+
init(Survey)
4449
}
4550

46-
export default init;
51+
export default init

src/icheck.js

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,64 @@
11
function init(Survey) {
2-
var widget = {
3-
className: "iradio_square-blue",
4-
name: "icheck",
5-
widgetIsLoaded: function() { return typeof $ == 'function' && !!$.fn.iCheck; },
6-
isFit : function(question) {
7-
var t = question.getType(); return t === 'radiogroup' || t === 'checkbox' || t === 'matrix';
8-
},
9-
isDefaultRender: true,
10-
afterRender: function(question, el) {
11-
var rootWidget = this;
12-
var $el = $(el);
13-
$el.find('input').data({"iCheck": undefined});
14-
15-
$el.find('input').iCheck({
16-
checkboxClass: rootWidget.className,
17-
radioClass: rootWidget.className
18-
});
19-
var select = function() {
20-
if(question.getType() != "matrix") {
21-
$el.find("input[value=" + question.value + "]").iCheck('check');
22-
} else {
23-
question.generatedVisibleRows.forEach(function(row, index, rows) {
24-
if (row.value) {
25-
$(el).find("input[name='" + row.fullName + "'][value=" + row.value + "]").iCheck('check');
26-
}
27-
});
28-
}
2+
var widget = {
3+
className: 'iradio_square-blue',
4+
name: 'icheck',
5+
widgetIsLoaded: function() {
6+
return typeof $ == 'function' && !!$.fn.iCheck
7+
},
8+
isFit: function(question) {
9+
var t = question.getType()
10+
return t === 'radiogroup' || t === 'checkbox' || t === 'matrix'
11+
},
12+
isDefaultRender: true,
13+
afterRender: function(question, el) {
14+
var rootWidget = this
15+
var $el = $(el)
16+
$el.find('input').data({ iCheck: undefined })
17+
18+
$el.find('input').iCheck({
19+
checkboxClass: rootWidget.className,
20+
radioClass: rootWidget.className,
21+
})
22+
var select = function() {
23+
if (question.getType() != 'matrix') {
24+
$el.find('input[value=' + question.value + ']').iCheck('check')
25+
} else {
26+
question.generatedVisibleRows.forEach(function(row, index, rows) {
27+
if (row.value) {
28+
$(el)
29+
.find(
30+
"input[name='" + row.fullName + "'][value=" + row.value + ']'
31+
)
32+
.iCheck('check')
33+
}
34+
})
35+
}
36+
}
37+
$el.find('input').on('ifChecked', function(event) {
38+
if (question.getType() != 'matrix') {
39+
question.value = event.target.value
40+
} else {
41+
question.generatedVisibleRows.forEach(function(row, index, rows) {
42+
if (row.fullName === event.target.name) {
43+
row.value = event.target.value
2944
}
30-
$el.find('input').on('ifChecked', function(event) {
31-
if(question.getType() != "matrix") {
32-
question.value = event.target.value;
33-
} else {
34-
question.generatedVisibleRows.forEach(function(row, index, rows) {
35-
if (row.fullName === event.target.name) {
36-
row.value = event.target.value
37-
}
38-
});
39-
}
40-
});
41-
question.valueChangedCallback = select;
42-
select();
43-
},
44-
willUnmount: function(question, el) {
45-
var $el = $(el);
46-
$el.find('input').iCheck('destroy');
47-
}
48-
}
45+
})
46+
}
47+
})
48+
question.valueChangedCallback = select
49+
select()
50+
},
51+
willUnmount: function(question, el) {
52+
var $el = $(el)
53+
$el.find('input').iCheck('destroy')
54+
},
55+
}
4956

50-
Survey.CustomWidgetCollection.Instance.addCustomWidget(widget, "type");
57+
Survey.CustomWidgetCollection.Instance.addCustomWidget(widget, 'type')
5158
}
5259

53-
if (typeof Survey !== "undefined") {
54-
init(Survey);
60+
if (typeof Survey !== 'undefined') {
61+
init(Survey)
5562
}
5663

57-
export default init;
64+
export default init

src/image-picker.js

Lines changed: 66 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,74 @@
11
function init(Survey) {
2-
var widget = {
3-
name: "imagepicker",
4-
title: "Image picker",
5-
iconName: "icon-imagepicker",
6-
widgetIsLoaded: function() { return typeof $ == 'function' && !!$.fn.imagepicker; },
7-
isFit : function(question) { return question.getType() === 'imagepicker'; },
8-
isDefaultRender: true,
9-
activatedByChanged: function(activatedBy) {
10-
Survey.JsonObject.metaData.addClass("imageitemvalues", [{name: "imageLink"}], null, "itemvalue");
11-
Survey.JsonObject.metaData.addClass("imagepicker", [{name: "choices:imageitemvalues", onGetValue: function (obj) { return Survey.ItemValue.getData(obj.choices); }, onSetValue: function (obj, value) { obj.choices = value; }},
12-
{name:"showLabel:boolean", default: false}, {name:"hasOther", visible: false}, {name: "otherText", visible: false}, {name: "optionsCaption", visible: false},
13-
{name: "otherErrorText", visible: false}, {name: "storeOthersAsComment", visible: false}, {name: "renderAs", visible: false}], null, "dropdown");
14-
},
15-
afterRender: function(question, el) {
16-
var $el = $(el).is("select") ? $(el) : $(el).find("select");
17-
var options = $el.find('option');
18-
var choices = question.choices;
2+
var widget = {
3+
name: 'imagepicker',
4+
title: 'Image picker',
5+
iconName: 'icon-imagepicker',
6+
widgetIsLoaded: function() {
7+
return typeof $ == 'function' && !!$.fn.imagepicker
8+
},
9+
isFit: function(question) {
10+
return question.getType() === 'imagepicker'
11+
},
12+
isDefaultRender: true,
13+
activatedByChanged: function(activatedBy) {
14+
Survey.JsonObject.metaData.addClass(
15+
'imageitemvalues',
16+
[{ name: 'imageLink' }],
17+
null,
18+
'itemvalue'
19+
)
20+
Survey.JsonObject.metaData.addClass(
21+
'imagepicker',
22+
[
23+
{
24+
name: 'choices:imageitemvalues',
25+
onGetValue: function(obj) {
26+
return Survey.ItemValue.getData(obj.choices)
27+
},
28+
onSetValue: function(obj, value) {
29+
obj.choices = value
30+
},
31+
},
32+
{ name: 'showLabel:boolean', default: false },
33+
{ name: 'hasOther', visible: false },
34+
{ name: 'otherText', visible: false },
35+
{ name: 'optionsCaption', visible: false },
36+
{ name: 'otherErrorText', visible: false },
37+
{ name: 'storeOthersAsComment', visible: false },
38+
{ name: 'renderAs', visible: false },
39+
],
40+
null,
41+
'dropdown'
42+
)
43+
},
44+
afterRender: function(question, el) {
45+
var $el = $(el).is('select') ? $(el) : $(el).find('select')
46+
var options = $el.find('option')
47+
var choices = question.choices
1948

20-
for (var i=1; i < options.length && i-1 < choices.length; i++) {
21-
$(options[i]).data("imgSrc", choices[i-1].imageLink);
22-
options[i].selected = question.value == options[i].value;
23-
}
24-
$el.imagepicker({
25-
hide_select : true,
26-
show_label : question.showLabel,
27-
selected: function(opts) {
28-
question.value = opts.picker.select[0].value;
29-
}
30-
})
49+
for (var i = 1; i < options.length && i - 1 < choices.length; i++) {
50+
$(options[i]).data('imgSrc', choices[i - 1].imageLink)
51+
options[i].selected = question.value == options[i].value
52+
}
53+
$el.imagepicker({
54+
hide_select: true,
55+
show_label: question.showLabel,
56+
selected: function(opts) {
57+
question.value = opts.picker.select[0].value
3158
},
32-
willUnmount: function(question, el) {
33-
var $el = $(el).find("select");
34-
$el.data('picker').destroy();
35-
}
36-
}
59+
})
60+
},
61+
willUnmount: function(question, el) {
62+
var $el = $(el).find('select')
63+
$el.data('picker').destroy()
64+
},
65+
}
3766

38-
Survey.CustomWidgetCollection.Instance.addCustomWidget(widget, "customtype");
67+
Survey.CustomWidgetCollection.Instance.addCustomWidget(widget, 'customtype')
3968
}
4069

41-
if (typeof Survey !== "undefined") {
42-
init(Survey);
70+
if (typeof Survey !== 'undefined') {
71+
init(Survey)
4372
}
4473

45-
export default init;
74+
export default init

0 commit comments

Comments
 (0)