var _____WB$wombat$assign$function_____ = function(name) {return (self._wb_wombat && self._wb_wombat.local_init && self._wb_wombat.local_init(name)) || self[name]; }; if (!self.__WB_pmw) { self.__WB_pmw = function(obj) { this.__WB_source = obj; return this; } } { let window = _____WB$wombat$assign$function_____("window"); let self = _____WB$wombat$assign$function_____("self"); let document = _____WB$wombat$assign$function_____("document"); let location = _____WB$wombat$assign$function_____("location"); let top = _____WB$wombat$assign$function_____("top"); let parent = _____WB$wombat$assign$function_____("parent"); let frames = _____WB$wombat$assign$function_____("frames"); let opener = _____WB$wombat$assign$function_____("opener"); $k.editor.plugins.bold = function () { //this.css('font-weight', 'bold'); var _obj = this; _obj.execCommand(function () { var edittingList = _obj.selector.find('.kui-editting'); $.each(edittingList, function (i, o) { //alert($(o).css('font-weight')) if ($(o).css('font-weight') == 700) {//700:bold,400:normal $(o).css('font-weight',''); } else { $(o).css('font-weight', 'bold'); } }); }); }; $k.editor.plugins.underline = function () { //this.css('text-decoration', 'underline'); var _obj = this; _obj.execCommand(function () { var edittingList = _obj.selector.find('.kui-editting'); $.each(edittingList, function (i, o) { if ($(o).css('text-decoration') == 'underline') { $(o).css('text-decoration', ''); } else { $(o).css('text-decoration', 'underline'); } }); }); }; $k.editor.plugins.italic = function () { //this.css('font-style', 'italic'); var _obj = this; _obj.execCommand(function () { var edittingList = _obj.selector.find('.kui-editting'); $.each(edittingList, function (i, o) { if ($(o).css('font-style') == 'italic') { $(o).css('font-style', ''); } else { $(o).css('font-style', 'italic'); } }); }); }; $k.editor.plugins.lineThrough = function () { //this.css('text-decoration', 'line-through'); var _obj = this; _obj.execCommand(function () { var edittingList = _obj.selector.find('.kui-editting'); $.each(edittingList, function (i, o) { if ($(o).css('text-decoration') == 'line-through') { $(o).css('text-decoration', ''); } else { $(o).css('text-decoration', 'line-through'); } }); }); }; $k.editor.plugins.textAlignLeft = function () { this.css('display', 'block'); this.css('text-align', 'left'); }; $k.editor.plugins.textAlignCenter = function () { this.css('display', 'block'); this.css('text-align', 'center'); }; $k.editor.plugins.textAlignRight = function () { this.css('display', 'block'); this.css('text-align', 'right'); }; $k.editor.plugins.removeHyperLink = function () { var _obj = this; var _range = _obj.getRange(); var _parent = $(_range.startContainer).parent(); if (_parent[0].tagName == "A" && _parent.html() == _range.toString()) {//选中的内容等于a标签中的内容 _parent[0].outerHTML = _parent.html(); } } $k.editor.plugins.removeFormat = function () { var _obj = this; _obj.execCommand(function () { _obj.selector.find('.kui-editting').removeAttr('style'); }); } $k.editor.plugins.getImg = function () { var _obj = this; var _range = _obj.getRange(); if (_range&&_range.startContainer&&_range.startContainer.data == undefined) { var node = _range.startContainer.childNodes[_range.startOffset]; if (node&&node.tagName == "IMG") { return node; } } return null; } $k.editor.plugins.getMedia = function () { var _obj = this; var _range = _obj.getRange(); if (_range && _range.startContainer && _range.startContainer.data == undefined) { var node = _range.startContainer.childNodes[_range.startOffset]; if (node && (node.tagName == "OBJECT"||node.tagName=="VIDEO"||node.tagName=="AUDIO")) { return node; } } return null; } $k.editor.plugins.getTable = function () { var _obj = this; var _range = _obj.getRange(); if (_range && _range.startContainer && _range.startContainer.data == undefined) { //debugger; var table = $k.editor.plugins.findByTagName(_range.startContainer, "TABLE"); return table; } return null; } $k.editor.plugins.findByTagName = function (node,tagName) { //debugger; if (!node) { return null; } if (node.tagName == "BODY") { return null; } if (node.tagName == "TABLE") { return node; } return $k.editor.plugins.findByTagName($(node).parent()[0],tagName) } $k.editor.plugins.findElement = function (node, el) { //debugger; if (!node) { return null; } if (node.tagName == "BODY") { return null; } if (node==el) { return node; } return $k.editor.plugins.findElement($(node).parent()[0], el) } $k.editor.plugins.insertDate = function () { //debugger; var _obj = this; var strDate = $c.date.format(new Date(), 'yyyy-MM-dd'); _obj.insertHTML(strDate); } $k.editor.plugins.insertTime = function () { var _obj = this; var strTime = $c.date.format(new Date(), 'hh:mm:ss'); //debugger; _obj.insertHTML(strTime); } $k.editor.plugins.isRangeInEditorArea = function () { var _obj=this; var _range = _obj.getRange(); if (!_range) { return false; } var elFinded = $k.editor.plugins.findElement(_range.startContainer, _obj.selector[0]); if(elFinded) { return true; } return false; } $k.editor.plugins.ulList = function () { var _obj = this; _obj.insertHTML(''); } $k.editor.plugins.olList = function () { var _obj = this; _obj.insertHTML('
'); } $k.editor.plugins.inIdent = function () { //增加缩进 var _obj = this; _obj.execCommand(function () { var editting = _obj.selector.find('.kui-editting:eq(0)'); var cssLeft = editting.css('margin-left'); var left = cssLeft.substr(0, cssLeft.length - 2); left = parseFloat(left); editting.css('margin-left',left+10); }); } $k.editor.plugins.outIdent = function () { //减少缩进 var _obj = this; _obj.execCommand(function () { var editting = _obj.selector.find('.kui-editting:eq(0)'); var cssLeft = editting.css('margin-left'); var left = cssLeft.substr(0, cssLeft.length - 2); left = parseFloat(left); editting.css('margin-left', left - 10); }); } $k.editor.plugins.blockQuote = function () { //引用 var _obj = this; _obj.execCommand(function () { var editting = _obj.selector.find('.kui-editting:eq(0)'); editting[0].outerHTML = '
' + editting.html() + '
'; },false); } $k.editor.plugins.insertHR = function () { //插入横线 var _obj = this; _obj.insertHTML('
'); } $k.editor.plugins.sub = function () { //下标 var _obj = this; _obj.execCommand(function () { var editting = _obj.selector.find('.kui-editting:eq(0)'); editting[0].outerHTML = '' + editting.html() + ''; }, false); } $k.editor.plugins.sup = function () { //上标 var _obj = this; _obj.execCommand(function () { var editting = _obj.selector.find('.kui-editting:eq(0)'); editting[0].outerHTML = '' + editting.html() + ''; }, false); } $k.editor.plugins.preview = function () { var _obj = this; top.kwindow.win({ content: 'url:/scripts/kui/editor/plugins/preview/preview.html?v5', title: '预览', //showTitleBar: false, //min: false, //max: false, //close: false, args:{html:_obj.selector.html()}, style: { width: 550, height: 600 }, onClosed: function (args) { if (args.success == true) { //alert(args.html); _obj.insertHTML(args.html + '
'); } } }); } $k.editor.plugins.viewSource = function () { var _obj = this; top.kwindow.win({ title: '编辑源代码', content: 'url:/scripts/kui/editor/plugins/viewSource/viewSource.html?v5', style: { width: 900, height: '90%' }, contentPartStyle: { padding_left: '15px' }, args: { content: $.trim(_obj.selector.html()) }, onClosed: function (args) { if (args.success == true) { $('#content').html(args.content); } } }); } $k.editor.plugins.insertSource = function () { var _obj = this; top.kwindow.win({ content: 'url:/scripts/kui/editor/plugins/insertHtml/insertHtml.html?v5', title: '插入html', style: { width: 900, height: '90%' }, contentPartStyle: { padding_left: '15px' }, onClosed: function (args) { if (args.success == true) { _obj.insertHTML(args.html); } } }); } $k.editor.plugins.insertMedia = function () { var _obj = this; var args = {}; var media = _obj.getMedia(); if (media) { args.media = media.outerHTML; } top.kwindow.win({ title: (media ? '编辑媒体' : '插入媒体'), content: 'url:/scripts/kui/editor/plugins/insertMedia/insertMedia.html?v6', args: args, style: { width: 600, height: 550 }, onClosed: function (args) { if (args.success == true && args.html) { if (media) { media.outerHTML = args.html; } else { _obj.insertHTML(args.html); } } } }); } $k.editor.plugins.textColor = function () { var _obj = this; top.kwindow.win({ content: 'url:/scripts/kui/colorpicker.html', showTitleBar: false, min: false, max: false, close: false, style: { width: 356, height: 226 }, onClosed: function (args) { if (args.success == true) { _obj.css('color', args.color); } } }); } $k.editor.plugins.bgColor = function () { var _obj = this; top.kwindow.win({ content: 'url:/scripts/kui/colorpicker.html', showTitleBar: false, min: false, max: false, close: false, style: { width: 356, height: 226 }, onClosed: function (args) { if (args.success == true) { _obj.css('background-color', args.color); } } }); } $k.editor.plugins.insertCode = function () { var _obj = this; top.kwindow.win({ content: 'url:/scripts/kui/editor/plugins/insertCode/insertCode.html?v5', title: '插入代码', //showTitleBar: false, min: false, max: false, //close: false, style: { width: 560, height: 510 }, onClosed: function (args) { if (args.success == true) { //alert(args.html); _obj.insertHTML(args.html + '
'); } } }); } $k.editor.plugins.setHyperLink = function (url, target, title) { var _obj = this; _obj.execCommand(function () { var edittingList = _obj.selector.find('.kui-editting'); $.each(edittingList, function (i, o) { //alert(o.tagName); if (o.tagName == "A") {//已经是a标签,修改a标签属性. $(o).attr('href', url); $(o).attr('target', target); if (title) { $(o).attr('title', title); } } else {//增加a标签. var _html = $(o).html(); $(o).html(''); var el = $('' + _html + '').appendTo($(o)); if (title) { el.attr('title', title); } el.addClass('kui-editting'); o.outerHTML = $(o).html(); } }); }); }; $k.editor.plugins.getHyperLink = function () { var _obj = this; var _range = _obj.getRange(); var _parent = $(_range.startContainer).parent(); //if (_parent[0].tagName == "A" && _range.startOffset == 0 && _range.endOffset == 0) {//选中的内容等于a标签中的内容 if (_parent[0].tagName == "A" && _parent.html() == _range.toString()) {//选中的内容等于a标签中的内容 return { url: _parent.attr('href'), target: _parent.attr('target'), title: _parent.attr('title') }; } return null; } $k.editor.plugins.hyperLink = function () { var _obj = this; /*对于有输入框的这种情况,需要打开一个新页面来输入,如果在同一页面,输入框获得焦点后,选中内容不再是选中状态了*/ var args = {}; var link = _obj.getHyperLink(); if (link) { //args.url = link.url; //args.target = link.target; //args.title = link.title; $.extend(args, link); } //alert(args.url); top.kwindow.win({ title: '设置超链接', content: 'url:/scripts/kui/editor/hyperlink.html', //showTitleBar: false, //min: false, //max: false, //close: false, args: args, style: { width: 500, height: 300 }, onClosed: function (args) { if (args.success == true) { if (args.url) { _obj.setHyperLink(args.url, args.target, args.title); } } } }); } $k.editor.plugins.insertImage = function () { var _obj = this; var args = {}; var img = _obj.getImg(); if (img) { //$.extend(args, img); args.img = img.outerHTML; } top.kwindow.win({ title: (img ? '编辑图片' : '插入图片'), content: 'url:/scripts/kui/editor/plugins/insertImage/insertImage.html?v2', args: args, style: { width: 500, height: 300 }, onClosed: function (args) { if (args.success == true && args.html) { if (img) { img.outerHTML = args.html; } else { _obj.insertHTML(args.html); } } } }); } $k.editor.plugins.insertTable = function () { var _obj = this; var args = {}; var table = _obj.getTable(); if (table) { args.table = table.outerHTML; } top.kwindow.win({ title: (table ? '编辑表格' : '插入表格'), content: 'url:/scripts/kui/editor/plugins/insertTable/insertTable.html?v2', args: args, style: { width: 500, height: 300 }, onClosed: function (args) { if (args.success == true && args.html) { //alert(args.html) if (table) { table.outerHTML = args.html; } else { _obj.insertHTML(args.html); } } } }); } $(function () { form('.kui-editor-h-n').select({ name: 'kui-editor-h-n', data: [{ text: '段落', value: '' }, { text: '

标题1

', value: 'h1' }, { text: '

标题2

', value: 'h2' }, { text: '

标题3

', value: 'h3' }, { text: '

标题4

', value: 'h4' }, { text: '
标题5
', value: 'h5' }, { text: '
标题6
', value: 'h6' }], onChange: function (_item, o, _form) { if (o.value) { var _editor = window[_form.selector.attr("editor")]; _editor.execCommand(function () { $.each(_editor.selector.find('.kui-editting'), function (i, _editting) { //_editting.outerHTML = '<' + o.value + ' class="kui-editting">' + $(_editting).html() + ''; $(_editting).html('<' + o.value + ' class="kui-editting">' + $(_editting).html() + ''); $(_editting).removeClass('kui-editting'); }) }, false); } }, value: '' }); form('.kui-editor-font-size').select({ name: 'fontSize', data: [{ text: '字体大小', value: '' }, { text: '12px', value: '12px' }, { text: '13px', value: '13px' }, { text: '14px', value: '14px' }, { text: '15px', value: '15px' }, { text: '16px', value: '16px' }, { text: '18px', value: '18px' }, { text: '4(14pt)', value: '13pt' }, { text: '5(18pt)', value: '18pt' }], onChange: function (_item, o,_form) { if (o.value) { var _editor = window[_form.selector.attr("editor")]; _editor.css('font-size', o.value); } }, value: '' }); form('.kui-editor-font-family').select({ name: 'fontFamily', data: [ { text: '字体', value: '' }, { text: '宋体', value: '宋体' }, { text: '微软雅黑', value: 'Microsoft YaHei' }, { text: '黑体', value: '黑体' }, { text: '仿宋', value: '仿宋' }, { text: '楷体', value: '楷体' }, { text: '隶书', value: '隶书' }, { text: '幼圆', value: '幼圆' }, { text: 'Arial', value: 'arial,helvetica,sans-serif' }, { text: 'Comic Sans MS', value: 'comic sans ms,sans-serif' }, { text: 'Courier New', value: 'courier new,courier' }, { text: 'Tahoma', value: 'tahoma,arial,helvetica,sans-serif' }, { text: 'Times New Roman', value: 'times new roman,times' }, { text: 'Verdana', value: 'verdana,geneva' }, { text: 'Webdings', value: 'webdings' }, { text: 'Wingdings', value: 'wingdings,zapf dingbats' }, ], onChange: function (_item, o,_form) { if (o.value) { var _editor = window[_form.selector.attr("editor")]; _editor.css('font-family', o.value); } }, value: '' }); top.uploader = $.extend(top.uploader, {}); $.each($('.kui-editor-image-uploader'), function (i, btnUploader) { var guid = Guid.NewGuid(); var uploader = new $c.ajaxFileUpload2(guid, '/file/upload2/', $(btnUploader), function (filepath, filename, code, msg) { if (code == 0) { if (msg) { alert(msg); } return; } var _editor = window[$(btnUploader).attr("editor")]; _editor.insertHTML('
'); }, function (up, fileName) { var format = $c.file.getFileFormat(fileName); if ($c.file.isImg(fileName)) { //待完善:显示正在上传提示. return true; } alert('只能上传图片'); return false; }, { type:'kui-editor', maxLength: 2, fileType: '.jpg,.jpeg,.png,.gif,.bmp' }); uploader.init(); top.uploader[guid] = uploader; }); //kui-editor-image-uploader }) }