Sets or gets the jqxEditor's createCommand property. The property allows you to add new commands or override existing commands.
Code examples
Set the createCommand
property in order to create new commands.
$('#editor').jqxEditor({
height: 400,
width: 800,
tools: 'datetime | print clear | backcolor | font bold italic underline',
createCommand: function (name) {
switch (name) {
case "datetime":
return {
type: 'list',
tooltip: "Insert Date/Time",
init: function (widget) {
widget.jqxDropDownList({ placeHolder: "Insert Custom HTML", width: 160, source: ['Insert Time', 'Insert Date'], autoDropDownHeight: true });
},
refresh: function (widget, style) {
// do something here when the selection is changed.
widget.jqxDropDownList('clearSelection');
},
action: function (widget, editor) {
var widgetValue = widget.val();
var date = new Date();
// return object with command and value members.
return { command: "inserthtml", value: widgetValue == "Insert Time" ? date.getHours() + ":" + date.getMinutes() : date.getDate() + "-" + date.getMonth() + "-" + date.getFullYear() };
}
}
case "print":
return {
type: 'button',
tooltip: 'Print',
init: function (widget) {
widget.jqxButton({ height: 25, width: 40 });
widget.html("<span style='line-height: 23px;'>Print</span>");
},
refresh: function (widget, style) {
// do something here when the selection is changed.
},
action: function (widget, editor) {
// return nothing and perform a custom action.
$('#editor').jqxEditor('print');
}
}
case "clear":
return {
type: 'button',
tooltip: 'Clear',
init: function (widget) {
widget.jqxButton({ height: 25, width: 40 });
widget.html("<span style='line-height: 23px;'>Clear</span>");
},
refresh: function (widget, style) {
// do something here when the selection is changed.
},
action: function (widget, editor) {
// return nothing and perform a custom action.
$('#editor').val('');
}
}
case "backcolor":
return {
type: 'colorPicker',
tooltip: 'Background',
init: function (widget) {
widget.jqxDropDownButton({ width: 160 });
widget.jqxDropDownButton('setContent', '<span style="line-height: 23px;">Choose Background</span>');
},
refresh: function (widget, style) {
// do something here when the selection is changed.
},
action: function (widget, editor) {
// return nothing and perform a custom action.
var color = widget.val();
editor.css('background', color);
}
}
}
}
});
Set the createCommand
property to override existing commands.
$('#editor').jqxEditor({
height: 400,
width: 800,
tools: "bold italic underline | font size | left center right | outdent indent",
createCommand: function (name) {
switch (name) {
case "font":
return {
init: function (widget) {
widget.jqxDropDownList({
source: [{ label: 'Arial', value: 'Arial, Helvetica, sans-serif' },
{ label: 'Comic Sans MS', value: '"Comic Sans MS", cursive, sans-serif' },
{ label: 'Courier New', value: '"Courier New", Courier, monospace' },
{ label: 'Georgia', value: "Georgia,serif" }]
});
}
}
case "size":
return {
init: function (widget) {
widget.jqxDropDownList({
source: [
{ label: "8pt", value: "xx-small" },
{ label: "12pt", value: "small" },
{ label: "18pt", value: "large" },
{ label: "36pt", value: "xx-large" }
]
});
}
}
}
}
});
Get the createCommand
property.
var createCommand = $('#jqxEditor').jqxEditor('createCommand');