当前位置: 首页> 教育> 培训 > 广州自助建设网站平台_收费标准_百度精准获客平台_百度入口网址

广州自助建设网站平台_收费标准_百度精准获客平台_百度入口网址

时间:2025/7/12 8:20:36来源:https://blog.csdn.net/sccd2009/article/details/144396622 浏览次数:0次
广州自助建设网站平台_收费标准_百度精准获客平台_百度入口网址

背景

       由于项目的需求使用fastadmin推荐的编辑器kindeditor,使用过程中发现没有段后距这个bug。查询搜索了所有的网上来源,都没有解决方案。鉴宇客户非常需要该功能,奋战几天写端代码实现了该功能。

插件实现    

KindEditor.plugin('paragraph', function(K) {var self = this, name = 'paragraph', lang = self.lang(name + '.');self.clickToolbar(name, function() {const iframe = document.querySelector("iframe").contentDocument;var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});if (commonNode) {curVal = commonNode.css('margin-bottom');}var menu = self.createMenu({name : name,width : 150});K.each(lang.paragaph, function(i, row) {K.each(row, function(key, val) {menu.addItem({title : val,checked : curVal === key + 'px',click : function() {// wrapTextNodes(iframe.body)self.cmd.toggle('<span style="margin-bottom:' + key + 'px;display: block"></span>', {span : '.margin-bottom=' + key});const words = iframe.getSelection().toString()if (iframe.getSelection().rangeCount > 1) {var range = iframe.getSelection().getRangeAt(0);var selectedElement = range.commonAncestorContainer;if (selectedElement.nodeType === Node.TEXT_NODE) {selectedElement = selectedElement.parentNode;}const tag = iframe.body.querySelectorAll("p");const wordsList = words.split("\n\n");let choseCount = 0;for (const el of Array.from(tag)) {let hasChose = false;for (const text of wordsList) {if (el.textContent === text) hasChose = true;}choseCount += hasChose ? 1 : 0;if (hasChose === true) {el.style.marginBottom = curVal + 'px';el.classList.add('selectedMenuItem'); // 添加选中效果} else {el.classList.remove('selectedMenuItem'); // 移除选中效果}}} else {let parentNodelet html = []const copyNodes = [...Array.from(iframe.body.childNodes)]iframe.body.innerHTML = ''copyNodes.forEach(el => {if (!parentNode) parentNode = el.parentNodeif (el.nodeType === 3) {const span = document.createElement('span')span.innerText = el.textContentspan.style.display='block'span.style.marginBottom = valconsole.log(iframe.body, span)iframe.body.appendChild(span)// el.parentNode.replaceChild(span, node)}else {el.style.display = 'block'el.style.marginBottom = valiframe.body.appendChild(el)}})}self.updateState();self.addBookmark();self.hideMenu();}});});});});
});

效果图

初步达到预期效果。后期还有优化地方,共同努力。

关键字:广州自助建设网站平台_收费标准_百度精准获客平台_百度入口网址

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: