jqwidgets-ng
Version:
[](https://jqwidgets.com/license/)
947 lines (870 loc) • 122 kB
JavaScript
/* tslint:disable */
/* eslint-disable */
(function(){
if (typeof document === 'undefined') {
return;
}
(function ($) {
$.jqx.jqxWidget("jqxRichTextArea", "", {});
$.extend($.jqx._jqxRichTextArea.prototype, {
defineInstance: function () {
var settings = {
width: null,
height: null,
disabled: false,
pasteMode: "html",
editable: true,
lineBreak: "default",
changeType: null,
toolbarPosition: "top",
fontFamily: "sans-serif",
commands:
{
"bold": { tooltip: "Bold", command: "bold", type: 'toggleButton' },
"italic": { tooltip: "Italic", command: "italic", type: 'toggleButton' },
"underline": { tooltip: "Underline", command: "underline", type: 'toggleButton' },
"format": {
placeHolder: "Format Block", tooltip: "Format Block", command: "formatblock",
value: [
{ value: 'p', label: 'Paragraph' },
{ value: 'h1', label: 'Header 1' },
{ value: 'h2', label: 'Header 2' },
{ value: 'h3', label: 'Header 3' },
{ value: 'h4', label: 'Header 4' }
], type: 'list', width: 120, dropDownWidth: 190, height: 25
},
"font": {
placeHolder: "Font", tooltip: "Font Name", command: "fontname",
value:
[
{ 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" },
{ label: "Impact", value: "Impact,Charcoal,sans-serif" },
{ label: "Lucida Console", value: "'Lucida Console',Monaco,monospace" },
{ label: 'Tahoma', value: 'Tahoma,Geneva,sans-serif' },
{ label: "Times New Roman", value: "'Times New Roman',Times,serif" },
{ label: 'Trebuchet MS', value: '"Trebuchet MS",Helvetica,sans-serif' },
{ label: 'Verdana', value: "Verdana,Geneva,sans-serif" }
],
type: 'list', width: 160, height: 25, dropDownWidth: 160
},
"left": { tooltip: "Align Left", command: "justifyleft", type: 'toggleButton' },
"center": { tooltip: "Align Center", command: "justifycenter", type: 'toggleButton' },
"right": { tooltip: "Align Right", command: "justifyright", type: 'toggleButton' },
"outdent": { tooltip: "Indent Less", command: "outdent", type: 'button' },
"indent": { tooltip: "Indent More", command: "indent", type: 'button' },
"ul": { tooltip: "Insert unordered list", command: "insertunorderedlist", type: 'toggleButton' },
"ol": { tooltip: "Insert ordered list", command: "insertorderedlist", type: 'toggleButton' },
"clean": { tooltip: "Remove Formatting", command: "removeformat", type: 'button' }
},
createCommand: null,
defaultLocalization:
{
"bold": "Bold",
"italic": "Italic",
"underline": "Underline",
"format": "Format Block",
"font": "Font Name",
"size": "Font Size",
"color": "Text Color",
"background": "Fill Color",
"left": "Align Left",
"center": "Align Center",
"right": "Align Right",
"outdent": "Indent Less",
"indent": "Indent More",
"ul": "Insert unordered list",
"ol": "Insert ordered list",
"image": "Insert image",
"link": "Insert link",
"html": "View source",
"clean": "Remove Formatting",
"Remove": "Remove",
"Ok": "Ok",
"Cancel": "Cancel",
"Change": "Change",
"Go to link": "Go to link",
"Open in a new window/tab": "Open in a new window/tab",
"Align": "Align",
"VSpace": "VSpace",
"HSpace": "HSpace",
"Width": "Width",
"Height": "Height",
"Title": "Title",
"URL": "URL",
"Insert Image": "Insert Image",
"Insert Link": "Insert Link",
"Alt Text": "Alt Text",
"not set": "<not set>",
"Left": "Left",
"Right": "Right",
"Paragraph": "Paragraph",
"Header": "Header",
"Arial": "Arial",
"Comic Sans MS": "Comic Sans MS",
"Courier New": "Courier New",
"Georgia": "Georgia",
"Impact": "Impact",
"Lucida Console": "Lucida Console",
"Tahoma": "Tahoma",
"Times New Roman": "Times New Roman",
"Trebuchet MS": "Trebuchet MS",
"Verdana": "Verdana"
},
localization: null,
tools: "bold italic underline | format | left center right | outdent indent | ul ol | clean ",
readOnly: false,
stylesheets: new Array(),
keyPressed: null,
events: ['change']
}
if (this === $.jqx._jqxRichTextArea.prototype) {
return settings;
}
$.extend(true, this, settings);
this.localization = this.defaultLocalization;
return settings;
},
createInstance: function (args) {
var that = this;
that.textArea = that.host;
var isContentEditable = that.host.attr('contenteditable');
that.host.addClass(that.toThemeProperty('jqx-widget'));
var editor = $("<div class='jqx-editor'><div class='jqx-editor-container'><div class='jqx-editor-toolbar-container' aria-label='Formatting options' role='toolbar'><div class='jqx-editor-toolbar'></div></div><div class='jqx-editor-content'><iframe src='javascript:\"<html></html>\"' allowtransparency='true' frameborder='0'></iframe></div></div></div>");
that.widget = editor;
that.widget[0].className = that.widget[0].className + " " + that.element.className;
try {
that.widget[0].style = that.element.style;
}
catch (error) {
}
var content = $.trim(that.host.html()) + "​";
if (that.lineBreak == "default" || that.lineBreak == "div") {
content = "<div>" + content + "</div>";
}
else if (that.lineBreak == "p") {
content = "<p>" + content + "</p>";
}
content = content.replace(/</ig, '<');
content = content.replace(/>/ig, '>');
that.host.css('display', 'none');
that.host.after(editor);
editor.find('iframe').after(that.host);
that.container = editor.find('.jqx-editor-container');
that.toolbarContainer = editor.find('.jqx-editor-toolbar-container');
that.toolbar = editor.find('.jqx-editor-toolbar');
that.iframe = editor.find('iframe');
that.content = editor.find('.jqx-editor-content');
var initIFrame = function () {
that.editorDocument = that.iframe[0].contentWindow.document;
that.selection = new jqxSelection(that.editorDocument);
var loaded = 0;
that.addHandler(that.iframe, 'load', function () {
loaded++;
if (loaded > 1) {
that.iframe.off('load');
that.content.find("iframe").remove();
var iframe = $("<iframe src='javascript:\"<html></html>\"' allowtransparency='true' frameborder='0'></iframe>").appendTo(that.content);
that.iframe = editor.find('iframe');
initIFrame();
}
});
if (!$.jqx.browser.mozilla) {
that.editorDocument.designMode = 'On';
}
that.editorDocument.open();
var rtlStyle = that.rtl ? "direction:rtl;" : "";
var selectionStyle = $.jqx.browser.msie ? "::selection{color: #fff; background: #328EFD;};" +
"::-moz-selection{color: #fff; background: #328eD;};" +
"::selection:window-inactive {background: #c7c7c7; color: #000;}" +
"::-moz-selection:window-inactive {background: #c7c7c7; color: #000;}" +
"html{font-size:13px; height:100%;}body{padding-top:1px;margin-top:-1px; padding-right: 1px; overflow-x: hidden;" +
"word-wrap: break-word;-webkit-nbsp-mode: space;-webkit-line-break: after-white-space;"
: "";
that.editorDocument.write(
"<!DOCTYPE html><html><head>" +
"<meta charset='utf-8' />" +
"<style>" +
"html,body{padding:0; margin:0; font-size: 13px; font-family: " + that.fontFamily + "; background:#fff; min-height:100%; " + rtlStyle + "}" +
selectionStyle +
"}" +
"h1{font-size:2em;margin:.67em 0}" +
"h2{font-size: 1.5em; margin: .75em 0}" +
"h3{font-size: 1.17em; margin: .83em 0}" +
"h4{font-size:1em; margin: 1.12em 0 }" +
"h5{font-size: .83em; margin: 1.5em 0}" +
"h6{font-size: .75em; margin: 1.67em 0}" +
"p{margin: 0px;padding:0 .2em}" +
"ul,ol{padding-left:2.5em}" +
"a{color:#00a}" +
"code{font-size:1.23em}" +
".jqx-editor-paste-element {position: absolute; left: -1000px; height: 1px; overflow: hidden; top: -1000px;}" +
".jqx-editor-focus {border: 1px solid #aaa !important;}" +
"</style>" +
$.map(that.stylesheets, function (href) {
return "<link rel='stylesheet' href='" + href + "'>";
}).join("") +
"</head><body autocorrect='off' contenteditable='true'></body></html>"
);
that.contentEditableElement = that.editorDocument.body;
that._textArea = that.element;
var hostData = that.host.data();
hostData.jqxRichTextArea.host = editor;
hostData.jqxRichTextArea.element = editor[0];
that.element = editor[0];
editor[0].id = that._textArea.id;
that._textArea.id = that._textArea.id + "TextArea";
$(that.element).addClass(that.toThemeProperty('jqx-widget'));
that.host = $(that.element);
that.host.data(hostData);
try {
that.editorDocument.execCommand("useCSS", false, false);
that.editorDocument.execCommand("enableInlineTableEditing", null, false);
}
catch (e) {
}
try {
that.editorDocument.execCommand("styleWithCSS", 0, true);
}
catch (e) {
}
that.editorDocument.close();
that.editor = $(that.editorDocument.body);
that.editor.html(content).attr('spellcheck', false).attr('autocorrect', 'off');
}
initIFrame();
},
focus: function () {
var that = this;
if ($.jqx.browser.mozilla) {
if (!that.focused) {
if (that.iframe) {
that.iframe.focus();
}
that.selection.selectNode(that.editor[0].firstChild, true);
that.selection.getRange().collapse(true);
}
}
that.editor.focus();
var range = that.range != null ? that.range : that.getRange();
that.selectRange(range);
},
refresh: function (initialRefresh) {
var that = this;
$.each(this.defaultLocalization, function (index, value) {
if (!that.localization[index]) {
that.localization[index] = value;
}
});
that._removeHandlers();
that.toolbar.addClass(that.toThemeProperty('jqx-widget-header'));
if (that.content) {
that.widget.css('width', that.width);
that.widget.css('height', that.height);
that.widget.addClass(that.toThemeProperty("jqx-editor"));
that.widget.addClass(that.toThemeProperty("jqx-widget"));
that.widget.addClass(that.toThemeProperty("jqx-rc-all"));
that.widget.addClass(that.toThemeProperty("jqx-widget-header"));
that.content.addClass(that.toThemeProperty('jqx-widget-content'));
that.container.addClass(that.toThemeProperty('jqx-editor-container'));
}
else {
that.toolbarContainer.addClass(that.toThemeProperty('jqx-widget-header'));
that.toolbarContainer.addClass(that.toThemeProperty("jqx-editor-toolbar-inline"));
that.toolbarContainer.addClass(that.toThemeProperty("jqx-widget"));
that.toolbarContainer.addClass(that.toThemeProperty("jqx-rc-all"));
that.toolbarContainer.hide();
that.toolbarContainer.css('position', 'absolute');
that.editor.addClass(that.toThemeProperty("jqx-editor-inline"));
that.toolbarContainer.css('width', that.host.outerWidth() + 'px');
}
var index = that.toolbarContainer.index();
var toolsValue = that.tools;
// render toolbar.
if (toolsValue !== false) {
var tools = toolsValue.split(" ");
var toolGroups = toolsValue.split(" | ");
var addTools = function (ownerElement, tools) {
$.each(tools, function (index, value) {
var tool = that.commands[this];
if (!tool) {
if (that.createCommand) {
tool = that.createCommand(this.toString());
if (!tool) {
return true;
}
if (!that.commands[this]) {
that.commands[this] = tool;
}
}
else {
return true;
}
}
else if (that.createCommand) {
var toolExt = that.createCommand(this.toString());
tool = $.extend(tool, toolExt);
}
if (that.localization[this]) {
tool.tooltip = that.localization[this];
}
switch (tool.type) {
case 'list':
if (tool.widget) {
tool.widget.jqxDropDownList('destroy');
}
var rendererFunc = function (index, label, value) {
if (tool.command == "formatblock") {
return '<' + value + ' unselectable="on" style="padding: 0px; margin: 0px;">' + label + '</' + value + '>';
}
else if (tool.command == "fontname") {
return '<span unselectable="on" style="font-family: ' + value + ';">' + label + '<span>';
}
else if (tool.command == "fontsize") {
return '<span unselectable="on" style="font-size: ' + value + ';">' + label + '<span>';
}
};
var selectionRendererFunc = function () {
var iconClass = that.toThemeProperty('jqx-editor-toolbar-icon') + " " + that.toThemeProperty('jqx-editor-toolbar-icon-' + tool.command);
var icon = "<div unselectable='on' style='margin-top: 0px; padding:0px;' class='" + iconClass + "'></div>";
return icon;
}
var fontRelated = tool.command == "formatblock" || tool.command == "fontname" || tool.command == "fontsize";
var dataValue = tool.value || [];
var dataSource = new Array();
var placeHolder = tool.placeHolder || "Please Choose:";
if (tool.command == "fontname") {
$.each(dataValue, function () {
var label = that.localization[this.label];
dataSource.push({ label: label, value: this.value });
});
}
else if (tool.command == "formatblock") {
placeHolder = that.localization["format"];
$.each(dataValue, function () {
if (this.label.indexOf("Header") >= 0) {
var label = this.label.replace("Header", that.localization["Header"]);
}
else {
var label = that.localization[this.label];
}
dataSource.push({ label: label, value: this.value });
});
}
else {
dataSource = dataValue;
}
var settings = {
enableBrowserBoundsDetection: true,
touchMode: that.touchMode,
width: tool.width || 100,
height: tool.height || 25,
dropDownWidth: tool.dropDownWidth || 'auto',
autoDropDownHeight: (tool.value && tool.value.length) < 12 ? true : false,
placeHolder: placeHolder,
source: dataSource,
theme: that.theme,
hint: false,
keyboardSelection: false,
focusable: false,
disabled: that.disabled,
rtl: that.rtl,
selectionRenderer: tool.command == "fontsize" ? selectionRendererFunc : null,
renderer: fontRelated ? rendererFunc : null
}
var listClass = 'jqx-disableselect ' + that.toThemeProperty('jqx-editor-dropdownlist') + " " + that.toThemeProperty('jqx-editor-toolbar-item');
var widget = $("<div unselectable='on' class='" + listClass + "'></div>");
widget.appendTo(ownerElement);
widget.jqxDropDownList(settings);
if (tool.init) {
tool.init(widget);
}
var value = null;
var newValue = null;
var closeType = "";
that.addHandler(widget, "mousedown", function (event) {
if ($('.jqx-editor-dropdownpicker').length > 0) {
$('.jqx-editor-dropdownpicker').jqxDropDownButton('close');
}
if ($('.jqx-editor-dropdownlist').length > 0) {
var lists = $('.jqx-editor-dropdownlist');
$.each(lists, function (index, value) {
if (value != widget[0]) {
$(value).jqxDropDownList('close');
}
});
}
});
that.addHandler(widget, "open", function (event) {
if (!that.focused) {
that.focus();
}
that.updating = true;
that.activeElement = widget;
value = widget.val();
closeType = "";
});
that.addHandler(widget, "change", function (event) {
that.updating = false;
that.activeElement = null;
newValue = widget.val();
closeType = event.args.type;
if ($.jqx.browser.msie && $.jqx.browser.version < 9) {
that.focus();
}
});
that.addHandler(widget, "close", function (event) {
that.updating = false;
that.activeElement = null;
if (value != newValue) {
if (closeType == "mouse" || closeType == "keyboard") {
that._refreshTools();
}
}
});
that._addCommandHandler(widget, 'change', tool.command, null, tool);
break;
case 'colorPicker':
if (tool.widget) {
$(tool.colorPicker).remove();
tool.widget.jqxDropDownButton('destroy');
}
var picker = $('<div unselectable="on" style="padding-top: 4px;"></div>').attr('id', 'picker-' + tool.command);
var listClass = 'jqx-disableselect ' + that.toThemeProperty('jqx-editor-dropdownpicker') + " " + that.toThemeProperty('jqx-editor-toolbar-item');
var widget = $("<div unselectable='on' class='" + listClass + "'></div>");
widget.appendTo(ownerElement);
widget.append(picker);
widget.jqxDropDownButton({
hint: false,
touchMode: that.touchMode,
disabled: that.disabled,
enableBrowserBoundsDetection: true,
width: tool.width || 45,
height: tool.height || 25,
rtl: that.rtl,
focusable: false,
theme: that.theme
});
var content = $('<div unselectable="on" style="z-index: 55;">');
var iconClass = that.toThemeProperty('jqx-editor-toolbar-icon') + " " + that.toThemeProperty('jqx-editor-toolbar-icon-' + tool.command);
var icon = $("<div unselectable='on' class='" + iconClass + "'></div>");
content.append(icon);
var bar = $('<div unselectable="on" class="jqx-editor-color-bar">').attr('id', 'bar-' + tool.command).css('background-color', tool.value);
content.append(bar);
widget.jqxDropDownButton('setContent', content);
picker.append($(that.colorPickerTemplate));
tool.colorPicker = picker;
if (tool.init) {
tool.init(widget);
}
picker.find('tr').attr('role', 'row').attr('unselectable', 'on');
picker.find('td').attr('role', 'gridcell').attr('unselectable', 'on').css('-webkit-user-select', 'none');
picker.find('div').attr('unselectable', 'on');
that.addHandler(widget, "mousedown", function (event) {
if ($('.jqx-editor-dropdownlist').length > 0) {
$('.jqx-editor-dropdownlist').jqxDropDownList('close');
}
if ($('.jqx-editor-dropdownpicker').length > 0) {
var lists = $('.jqx-editor-dropdownpicker');
$.each(lists, function (index, value) {
if (value != widget[0]) {
$(value).jqxDropDownButton('close');
}
});
}
});
that.addHandler(widget, "open", function () {
if (!that.focused) {
that.focus();
}
that.updating = true;
that.activeElement = picker;
});
that.addHandler(widget, "close", function (event) {
that.updating = false;
that.activeElement = null;
if (value != newValue) {
if (closeType == "mouse" || closeType == "keyboard") {
that._refreshTools();
}
}
});
that.addHandler(picker, "keydown", function (event) {
var key = event.keyCode;
var activeColor = $(picker).find('.jqx-editor-color-picker-selected-cell');
var rows = picker.find('tr');
var rowsCount = rows.length;
var columnsCount = activeColor.parent().children().length;
var columnIndex = activeColor.index();
var rowIndex = -999;
var row = activeColor.parent();
$.each(rows, function (index, value) {
if (this == row[0]) {
rowIndex = index;
return false;
}
});
switch (key) {
case 27: // esc
widget.jqxDropDownButton('close');
break;
case 13: // esc
$(activeColor).trigger('mousedown');
break;
case 38: // up
rowIndex--;
break;
case 40: // down
rowIndex++;
break;
case 39: // right
columnIndex++;
break;
case 37: // left
columnIndex--;
break;
}
if (rowIndex >= 0 && rowIndex <= rowsCount) {
if (columnIndex >= 0 && columnIndex <= columnsCount) {
var row = picker.find('tr')[rowIndex];
var cell = $(row).children()[columnIndex];
var color = $(cell).children().css('background-color');
tool.val(color);
}
}
});
var pickerColors = $(picker).find('td');
tool.val = function (color) {
var hexColor = that._rgbToHex(color);
$.each(pickerColors, function () {
var color = $(this).children().css('background-color');
var pickerColor = that._rgbToHex(color);
if (pickerColor == hexColor) {
pickerColors.removeClass('jqx-editor-color-picker-selected-cell');
$(this).addClass('jqx-editor-color-picker-selected-cell');
$('#bar-' + tool.command).css('background', color);
return false;
}
});
}
tool.val(tool.value);
that._addCommandHandler(pickerColors, 'mousedown', tool.command, null, tool);
break;
case "button":
case "toggleButton":
default:
if (tool.widget) {
if (tool.type == "button") {
tool.widget.jqxButton('destroy');
}
else {
tool.widget.jqxToggleButton('destroy');
}
}
var command = tool.command;
var action = tool.action;
var iconClass = that.toThemeProperty('jqx-editor-toolbar-icon') + " " + that.toThemeProperty('jqx-editor-toolbar-icon-' + command);
var icon = $("<div unselectable='on' class='" + iconClass + "'></div>");
var widget = $("<div unselectable='on'></div>").addClass('jqx-disableselect').addClass(that.toThemeProperty('jqx-editor-toolbar-button'));
if (!tool.init) {
widget.append(icon);
}
else {
if (command) {
widget.append(icon);
}
}
widget.appendTo(ownerElement);
if (tool.type == "button") {
widget.jqxButton({
disabled: that.disabled,
rtl: that.rtl,
theme: that.theme
});
}
else if (tool.type == "toggleButton") {
widget.jqxToggleButton({
disabled: that.disabled,
rtl: that.rtl,
uiToggle: false,
theme: that.theme
});
}
if (tool.init) {
tool.init(widget);
}
tool.toggled = false;
tool.toggle = function () {
tool.toggled = !tool.toggled;
}
that.addHandler(widget, 'mousedown', function (event) {
if (event.preventDefault) {
event.preventDefault();
}
if (event.stopPropagation) {
event.stopPropagation();
}
return false;
});
if (!$.jqx.mobile.isTouchDevice()) {
that._addCommandHandler(widget, 'click', command, action, tool);
}
else {
that._addCommandHandler(widget, 'mousedown', command, action, tool);
}
break;
}
tool.widget = widget;
if (widget) {
try {
if (tool.tooltip != "") {
tool.widget.attr('title', tool.tooltip);
tool.widget.attr('data-tooltip', tool.tooltip);
}
if (tool.command) {
tool.widget.attr('data-command', tool.command);
}
tool.widget.attr('aria-label', tool.tooltip);
}
catch (error) {
}
if (tool.type == "button" || tool.type == "toggleButton") {
if (tools.length > 2) {
if (index == 0) {
widget.css('border-right-radius', '0px');
widget.addClass(that.toThemeProperty('jqx-rc-l'));
}
else if (index == tools.length - 1) {
widget.css('border-left-radius', '0px');
widget.addClass(that.toThemeProperty('jqx-rc-r'));
}
widget.removeClass(that.toThemeProperty('jqx-rc-all'));
}
if (index != 0 && index != tools.length - 1 && tools.length > 2) {
widget.css('border-left-radius', '0px');
widget.css('border-right-radius', '0px');
widget.removeClass(that.toThemeProperty('jqx-rc-all'));
}
else if (tools.length == 2) {
if (index == 0) {
widget.css('border-right-radius', '0px');
widget.addClass(that.toThemeProperty('jqx-rc-l'));
}
else {
widget.css('border-left-radius', '0px');
widget.addClass(that.toThemeProperty('jqx-rc-r'));
}
widget.removeClass(that.toThemeProperty('jqx-rc-all'));
}
else if (tools.length == 1) {
widget.css('margin-right', '0px');
}
}
}
});
}
that.toolbar.css('direction', !this.rtl ? 'ltr' : 'rtl');
if (toolGroups.length == 0) {
addTools(that.toolbar, tools);
}
else {
for (var i = 0; i < toolGroups.length; i++) {
var toolGroup = toolGroups[i];
var tools = toolGroup.split(" ");
var groupClass = that.toThemeProperty('jqx-editor-toolbar-group') + " " + that.toThemeProperty('jqx-fill-state-normal');
var ownerElement = $("<div class='" + groupClass + "'></div>");
ownerElement.addClass(that.toThemeProperty('jqx-rc-all'));
that.toolbar.append(ownerElement);
addTools(ownerElement, tools);
}
var groups = that.toolbar.find('.jqx-editor-toolbar-group')
var groupsLength = groups.length;
for (var i = 0; i < groupsLength; i++) {
if ($(groups[i]).children().length == 0) {
$(groups[i]).remove();
}
}
}
if ($.jqx.browser.msie && $.jqx.browser.version < 8) {
$(".jqx-editor-toolbar-group").css('float', 'left');
$(".jqx-editor-toolbar-group").children().css('float', 'left');
$(".jqx-editor-toolbar-group").css('zoom', '1');
$(".jqx-editor-toolbar-group").children().css('zoom', '1');
}
}
that._arrange();
that._addHandlers();
},
_arrange: function () {
var that = this;
if (that.content) {
if (that.tools == "" || that.tools == false) {
that.content.height(that.container.outerHeight() - parseInt(that.container.css('padding-top')) - parseInt(that.container.css('padding-bottom')) - 6);
that.content.css('margin-top', '4px');
that.toolbar.hide();
}
else {
that.toolbar.show();
that.content.css('margin-top', '0px');
that.content.height(that.container.outerHeight() - that.toolbar.outerHeight() - parseInt(that.container.css('padding-top')) - parseInt(that.container.css('padding-bottom')) - 2);
if (that.toolbarPosition != "top") {
that.content.css('margin-top', '4px');
that.content.css('margin-bottom', '0px');
}
}
if ($.jqx.browser.msie && $.jqx.browser.version < 8) {
that.content.css('margin-top', '4px');
that.content.height(that.container.height() - that.toolbar.outerHeight() - 2 * parseInt(that.container.css('padding-bottom')) - 10);
that.content.width(that.container.width() - 2 * parseInt(that.container.css('padding-left')) - 2);
}
if (that.editor.height() < that.content.height()) {
that.editor.height(that.content.height());
}
}
},
propertyChangedHandler: function (object, key, oldvalue, value) {
var that = object;
if (that.isInitialized == undefined || that.isInitialized == false)
return;
if (key == "pasteMode" || key == "lineBreak" || key == "editable") {
return;
}
if (key == "disabled") {
object._refreshTools();
}
if (key == "width" || key == "height" || key == "toolbarPosition") {
object._arrange();
return;
}
if (key == "theme") {
$.jqx.utilities.setTheme(oldvalue, value, object.host);
}
object.refresh();
},
selectRange: function (range) {
var that = this;
if (!range) range = that.getRange();
that.selection.selectRange(range);
},
getRange: function () {
var that = this;
return that.selection.getRange();
},
getSelectedElement: function () {
var range, root, start, end;
var that = this;
try {
if (that.editorDocument.getSelection) {
var selection = that.editorDocument.getSelection();
range = selection.getRangeAt(selection.rangeCount - 1);
start = range.startContainer;
end = range.endContainer;
root = range.commonAncestorContainer;
if (start.nodeName == "#text") root = root.parentNode;
if (start.nodeName == "#text") start = start.parentNode;
if (start.nodeName.toLowerCase() == "body") start = start.firstChild;
if (end.nodeName == "#text") end = end.parentNode;
if (end.nodeName.toLowerCase() == "body") end = end.lastChild;
if (start == end) root = start;
return end;
} else if (that.editorDocument.selection) {
range = that.editorDocument.selection.createRange()
if (!range.duplicate) return null;
root = range.parentElement();
var r1 = range.duplicate();
var r2 = range.duplicate();
r1.collapse(true);
r2.moveToElementText(r1.parentElement());
r2.setEndPoint("EndToStart", r1);
start = r1.parentElement();
r1 = range.duplicate();
r2 = range.duplicate();
r2.collapse(false);
r1.moveToElementText(r2.parentElement());
r1.setEndPoint("StartToEnd", r2);
end = r2.parentElement();
if (start.nodeName.toLowerCase() == "body") start = start.firstChild;
if (end.nodeName.toLowerCase() == "body") end = end.lastChild;
if (start == end) root = start;
return end;
}
}
catch (error) {
return null;
}
return null;
},
val: function (value) {
if (value != undefined && typeof value != 'object') {
this.editor.html(value)
}
if (this._documentMode === "source") {
return this.editor.find('pre:first').html();
}
return this.editor.html();
},
_addHandlers: function () {
var that = this;
that.addHandler(that.toolbar, "mousedown.editor" + that.element.id, function (event) {
if (event.preventDefault)
event.preventDefault();
if (event.stopPropagation)
event.stopPropagation();
return false;
});
var blur = function () {
if (that._textArea) {
if (!that.updating) {
that._textArea.value = that.val();
}
}
if (that.changed) {
that._raiseEvent("change");
that.changed = false;
}
that.focused = false;
}
var focus = function () {
that.focused = true;
if (that.inline) {
that.host.addClass(that.toThemeProperty('jqx-fill-state-focus'));
that.host.addClass(that.toThemeProperty('jqx-editor-inline-focus'));
that.host.addClass(that.toThemeProperty('jqx-rc-all'));
if (that.tools == "" || that.tools == null)
return;
that.toolbarContainer.fadeIn('fast');
var location = that.host.coord();
if (that.toolbarPosition != "bottom") {
that.toolbarContainer.offset({ left: location.left, top: location.top - that.toolbarContainer.outerHeight() - 5 });
}
else {
that.toolbarContainer.offset({ left: location.left, top: location.top + 5 + that.host.height() });
}
}
}
if ($.jqx.browser.mozilla) {
this.addHandler($(document), "mousedown.editor" + that.element.id, function (event) {
blur();
});
}
that.addHandler(that.editor, "blur.editor" + that.element.id, function (event) {
blur();
});
that.addHandler(that.editor, "focus.editor" + that.element.id, function (event) {
focus();
});
that.addHandler(that.editor, "beforedeactivate.editor" + that.element.id, function (event) {
that.range = that.getRange();
});
that.addHandler(that.editor, "mousedown.editor" + that.element.id, function (event) {
if (!event.target.href) {
if (that.linkPopup) that.linkPopup.remove();
}
that.range = that.getRange();
if ($.jqx.browser.mozilla) {
focus();
event.stopPropagation();
}
if ($('.jqx