From a089d87c9672a8ddfb38d71522857d99e577c70d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Thu, 4 Aug 2022 02:39:27 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E4=BC=98=E5=8C=96=20colorpicker=20?= =?UTF-8?q?=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/colorpicker.js | 96 ++++++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 30 deletions(-) diff --git a/src/modules/colorpicker.js b/src/modules/colorpicker.js index 765f9d51..1ca616d5 100644 --- a/src/modules/colorpicker.js +++ b/src/modules/colorpicker.js @@ -6,13 +6,14 @@ layui.define(['jquery', 'lay'], function(exports){ "use strict"; - var $ = layui.jquery - ,lay = layui.lay - ,device = layui.device() - ,clickOrMousedown = (device.mobile ? 'click' : 'mousedown') + var $ = layui.$; + var lay = layui.lay; + var hint = layui.hint(); + var device = layui.device(); + var clickOrMousedown = (device.mobile ? 'click' : 'mousedown'); //外部接口 - ,colorpicker = { + var colorpicker = { config: {} ,index: layui.colorpicker ? (layui.colorpicker.index + 10000) : 0 @@ -27,16 +28,19 @@ layui.define(['jquery', 'lay'], function(exports){ ,on: function(events, callback){ return layui.onevent.call(this, 'colorpicker', events, callback); } - } + }; - //操作当前实例 - ,thisColorPicker = function(){ - var that = this - ,options = that.config; + // 操作当前实例 + var thisModule = function(){ + var that = this; + var options = that.config; + var id = options.id; + + thisModule.that[id] = that; // 记录当前实例对象 return { config: options - } + }; } //字符常量 @@ -213,15 +217,18 @@ layui.define(['jquery', 'lay'], function(exports){ var othis = options.elem = $(options.elem); options.size && elemColorBox.addClass('layui-colorpicker-'+ options.size); //初始化颜色选择框尺寸 - //插入颜色选择框 + // 插入颜色选择框 othis.addClass('layui-inline').html( that.elemColorBox = elemColorBox ); + + //初始化 id 参数 + options.id = ('id' in options) ? options.id : that.index; - //获取背景色值 + // 获取背景色值 that.color = that.elemColorBox.find('.'+ PICKER_TRIG_SPAN)[0].style.background; - //相关事件 + // 相关事件 that.events(); }; @@ -291,6 +298,9 @@ layui.define(['jquery', 'lay'], function(exports){ that.removePicker(Class.thisElemInd); $('body').append(elemPicker); } + + // 记录当前执行的实例索引 + colorpicker.thisId = options.id; Class.thisElemInd = that.index; //记录最新打开的选择器索引 Class.thisColor = elemColorBox.style.background //记录最新打开的选择器颜色选中值 @@ -301,9 +311,18 @@ layui.define(['jquery', 'lay'], function(exports){ //颜色选择器移除 Class.prototype.removePicker = function(index){ - var that = this - ,options = that.config; - $('#layui-colorpicker'+ (index || that.index)).remove(); + var that = this; + var options = that.config; + var elem = $('#layui-colorpicker'+ (index || that.index)); + + if(elem[0]){ + elem.remove(); + delete colorpicker.thisId; + + // 面板关闭后的回调 + typeof options.close === 'function' && options.close(that.color); + } + return that; }; @@ -640,14 +659,12 @@ layui.define(['jquery', 'lay'], function(exports){ }); } - //颜色选择器输入 + // 颜色选择器输入 Class.prototype.events = function(){ - var that = this - ,options = that.config - - ,elemColorBoxSpan = that.elemColorBox.find('.' + PICKER_TRIG_SPAN) - - //弹出颜色选择器 + var that = this; + var options = that.config; + + // 弹出颜色选择器 that.elemColorBox.on('click' , function(){ that.renderPicker(); if($(ELEM_MAIN)[0]){ @@ -655,11 +672,18 @@ layui.define(['jquery', 'lay'], function(exports){ that.side(); }; }); - - if(!options.elem[0] || that.elemColorBox[0].eventHandler) return; - + }; + + //全局事件 + (function(){ //绑定关闭控件事件 $doc.on(clickOrMousedown, function(e){ + if(!colorpicker.thisId) return; + var that = thisModule.getThis(colorpicker.thisId); + if(!that) return; + + var elemColorBoxSpan = that.elemColorBox.find('.' + PICKER_TRIG_SPAN); + //如果点击的元素是颜色框 if($(e.target).hasClass(ELEM) || $(e.target).parents('.'+ELEM)[0] @@ -685,19 +709,31 @@ layui.define(['jquery', 'lay'], function(exports){ //自适应定位 $win.on('resize', function(){ + if(!colorpicker.thisId) return; + var that = thisModule.getThis(colorpicker.thisId); + if(!that) return; + if(!that.elemPicker || !$(ELEM_MAIN)[0]){ return false; } that.position(); }); - - that.elemColorBox[0].eventHandler = true; + })(); + + // 记录所有实例 + thisModule.that = {}; // 记录所有实例对象 + + // 获取当前实例对象 + thisModule.getThis = function(id){ + var that = thisModule.that[id]; + if(!that) hint.error(id ? (MOD_NAME +' instance with ID \''+ id +'\' not found') : 'ID argument required'); + return that; }; //核心入口 colorpicker.render = function(options){ var inst = new Class(options); - return thisColorPicker.call(inst); + return thisModule.call(inst); }; exports(MOD_NAME, colorpicker); From a10722721a1e407adafcf175b53a4065e171b686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Thu, 4 Aug 2022 02:46:41 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20colorpicker=20?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/colorpicker.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/colorpicker.html b/examples/colorpicker.html index 22a36e0e..dcf840f7 100644 --- a/examples/colorpicker.html +++ b/examples/colorpicker.html @@ -66,6 +66,12 @@ body{padding:20px;} layui.$('#LAY-test1').val(color); document.body.style.backgroundColor = color; } + ,cancel: function(color){ + console.log('cancel', color); + } + ,close: function(color){ + console.log('close', color); + } }); colorpicker.render({ From 01e7390e7aa3b59f7a2f3be18ec0e1127425ecf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Thu, 4 Aug 2022 02:58:29 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20colorpicker=20?= =?UTF-8?q?=E7=9A=84=20cancel=20=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/colorpicker.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/colorpicker.js b/src/modules/colorpicker.js index 1ca616d5..adc50be7 100644 --- a/src/modules/colorpicker.js +++ b/src/modules/colorpicker.js @@ -704,6 +704,8 @@ layui.define(['jquery', 'lay'], function(exports){ } elemColorBoxSpan[0].style.background = that.color || ''; + // 取消选择的回调 + typeof options.cancel === 'function' && options.cancel(that.color); that.removePicker(); }); From 0331c9ec103a1882dde398b9d494a073b6bb1579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Thu, 4 Aug 2022 03:00:26 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20colorpicker=20?= =?UTF-8?q?=E7=9A=84=E6=B3=A8=E9=87=8A=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/colorpicker.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/colorpicker.js b/src/modules/colorpicker.js index adc50be7..dffe1452 100644 --- a/src/modules/colorpicker.js +++ b/src/modules/colorpicker.js @@ -706,6 +706,8 @@ layui.define(['jquery', 'lay'], function(exports){ // 取消选择的回调 typeof options.cancel === 'function' && options.cancel(that.color); + + // 移除面板 that.removePicker(); }); From d31792d36280054d3c52f0ce5adf6b8816c74f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Thu, 4 Aug 2022 15:17:18 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20colorpicker=20?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/colorpicker.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/colorpicker.html b/examples/colorpicker.html index dcf840f7..2243ca83 100644 --- a/examples/colorpicker.html +++ b/examples/colorpicker.html @@ -60,13 +60,14 @@ body{padding:20px;} //,predefine: true //开启预定义颜色 //,colors: ['#F00','#0F0','#00F','rgb(255, 69, 0)','rgba(255, 69, 0, 0.5)'] ,change: function(color){ - document.body.style.backgroundColor = color; + this.done(color); } ,done: function(color){ layui.$('#LAY-test1').val(color); document.body.style.backgroundColor = color; } ,cancel: function(color){ + this.done(color); console.log('cancel', color); } ,close: function(color){ From c8504e5307270b0cb6c1fdb6084b4b69ff41cd62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Thu, 4 Aug 2022 15:18:40 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20tab=20delete=20?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/element.tab.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/element.tab.html b/examples/element.tab.html index 363e9689..c1af1927 100644 --- a/examples/element.tab.html +++ b/examples/element.tab.html @@ -113,6 +113,10 @@ layui.use(['element', 'form'], function(){ element.on('tab(test)', function(data){ console.log(this, data); }); + + element.on('tabDelete(tabDemo)', function(data){ + console.log(this, data); + }); }); From 7ca50bd1cf60d9fc90ac82ec057946af8724718c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Thu, 4 Aug 2022 15:19:59 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E4=BC=98=E5=8C=96=20colorpicker=20?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/colorpicker.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/colorpicker.js b/src/modules/colorpicker.js index dffe1452..97f374b6 100644 --- a/src/modules/colorpicker.js +++ b/src/modules/colorpicker.js @@ -682,6 +682,7 @@ layui.define(['jquery', 'lay'], function(exports){ var that = thisModule.getThis(colorpicker.thisId); if(!that) return; + var options = that.config; var elemColorBoxSpan = that.elemColorBox.find('.' + PICKER_TRIG_SPAN); //如果点击的元素是颜色框 From dc9bdd3a36befdf83c5ef494ef8c99c3834df038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Thu, 4 Aug 2022 15:20:45 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E4=BC=98=E5=8C=96=20dropdown=20=E5=B1=80?= =?UTF-8?q?=E9=83=A8=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/dropdown.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/dropdown.js b/src/modules/dropdown.js index 9bf76a8b..bfaf1a12 100644 --- a/src/modules/dropdown.js +++ b/src/modules/dropdown.js @@ -36,9 +36,9 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){ //操作当前实例 ,thisModule = function(){ - var that = this - ,options = that.config - ,id = options.id; + var that = this; + var options = that.config; + var id = options.id; thisModule.that[id] = that; //记录当前实例对象 From 64cedcb038cdf474c5d5108995ff3dc866026fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Thu, 4 Aug 2022 15:20:57 +0800 Subject: [PATCH 09/14] =?UTF-8?q?=E5=89=94=E9=99=A4=20layedit=20=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/layedit.js | 570 ----------------------------------------- 1 file changed, 570 deletions(-) delete mode 100644 src/modules/layedit.js diff --git a/src/modules/layedit.js b/src/modules/layedit.js deleted file mode 100644 index 87cad7ab..00000000 --- a/src/modules/layedit.js +++ /dev/null @@ -1,570 +0,0 @@ -/** - * layedit 富文本编辑器(该组件已被弃用,为了向下兼容而保留) - */ - -layui.define(['layer', 'form'], function(exports){ - "use strict"; - - var $ = layui.$ - ,layer = layui.layer - ,form = layui.form - ,hint = layui.hint() - ,device = layui.device() - - ,MOD_NAME = 'layedit', THIS = 'layui-this', SHOW = 'layui-show', ABLED = 'layui-disabled' - - ,Edit = function(){ - var that = this; - that.index = 0; - - //全局配置 - that.config = { - //默认工具bar - tool: [ - 'strong', 'italic', 'underline', 'del' - ,'|' - ,'left', 'center', 'right' - ,'|' - ,'link', 'unlink' - ] - ,hideTool: [] - ,height: 280 //默认高 - }; - }; - - //全局设置 - Edit.prototype.set = function(options){ - var that = this; - $.extend(true, that.config, options); - return that; - }; - - //事件 - Edit.prototype.on = function(events, callback){ - return layui.onevent(MOD_NAME, events, callback); - }; - - //建立编辑器 - Edit.prototype.build = function(id, settings){ - settings = settings || {}; - - var that = this - ,config = that.config - ,ELEM = 'layui-layedit', textArea = $(typeof(id)=='string'?'#'+id:id) - ,name = 'LAY_layedit_'+ (++that.index) - ,haveBuild = textArea.next('.'+ELEM) - - ,set = $.extend({}, config, settings) - - ,tool = function(){ - var node = [], hideTools = {}; - layui.each(set.hideTool, function(_, item){ - hideTools[item] = true; - }); - layui.each(set.tool, function(_, item){ - if(tools[item] && !hideTools[item]){ - node.push(tools[item]); - } - }); - return node.join(''); - }() - - - ,editor = $(['
' - ,'
'+ tool +'
' - ,'
' - ,'' - ,'
' - ,'
'].join('')) - - //编辑器不兼容ie8以下 - if(device.ie && device.ie < 8){ - return textArea.removeClass('layui-hide').addClass(SHOW); - } - - haveBuild[0] && (haveBuild.remove()); - - setIframe.call(that, editor, textArea[0], set) - textArea.addClass('layui-hide').after(editor); - - return that.index; - }; - - //获得编辑器中内容 - Edit.prototype.getContent = function(index){ - var iframeWin = getWin(index); - if(!iframeWin[0]) return; - return toLower(iframeWin[0].document.body.innerHTML); - }; - - //获得编辑器中纯文本内容 - Edit.prototype.getText = function(index){ - var iframeWin = getWin(index); - if(!iframeWin[0]) return; - return $(iframeWin[0].document.body).text(); - }; - /** - * 设置编辑器内容 - * @param {[type]} index 编辑器索引 - * @param {[type]} content 要设置的内容 - * @param {[type]} flag 是否追加模式 - */ - Edit.prototype.setContent = function(index, content, flag){ - var iframeWin = getWin(index); - if(!iframeWin[0]) return; - if(flag){ - $(iframeWin[0].document.body).append(content) - }else{ - $(iframeWin[0].document.body).html(content) - }; - layedit.sync(index) - }; - //将编辑器内容同步到textarea(一般用于异步提交时) - Edit.prototype.sync = function(index){ - var iframeWin = getWin(index); - if(!iframeWin[0]) return; - var textarea = $('#'+iframeWin[1].attr('textarea')); - textarea.val(toLower(iframeWin[0].document.body.innerHTML)); - }; - - //获取编辑器选中内容 - Edit.prototype.getSelection = function(index){ - var iframeWin = getWin(index); - if(!iframeWin[0]) return; - var range = Range(iframeWin[0].document); - return document.selection ? range.text : range.toString(); - }; - - //iframe初始化 - var setIframe = function(editor, textArea, set){ - var that = this, iframe = editor.find('iframe'); - - iframe.css({ - height: set.height - }).on('load', function(){ - var conts = iframe.contents() - ,iframeWin = iframe.prop('contentWindow') - ,head = conts.find('head') - ,style = $([''].join('')) - ,body = conts.find('body'); - - head.append(style); - body.attr('contenteditable', 'true').css({ - 'min-height': set.height - }).html(textArea.value||''); - - hotkey.apply(that, [iframeWin, iframe, textArea, set]); //快捷键处理 - toolActive.call(that, iframeWin, editor, set); //触发工具 - - }); - } - - //获得iframe窗口对象 - ,getWin = function(index){ - var iframe = $('#LAY_layedit_'+ index) - ,iframeWin = iframe.prop('contentWindow'); - return [iframeWin, iframe]; - } - - //IE8下将标签处理成小写 - ,toLower = function(html){ - if(device.ie == 8){ - html = html.replace(/<.+>/g, function(str){ - return str.toLowerCase(); - }); - } - return html; - } - - //快捷键处理 - ,hotkey = function(iframeWin, iframe, textArea, set){ - var iframeDOM = iframeWin.document, body = $(iframeDOM.body); - body.on('keydown', function(e){ - var keycode = e.keyCode; - //处理回车 - if(keycode === 13){ - var range = Range(iframeDOM); - var container = getContainer(range) - ,parentNode = container.parentNode; - - if(parentNode.tagName.toLowerCase() === 'pre'){ - if(e.shiftKey) return - layer.msg('请暂时用shift+enter'); - return false; - } - iframeDOM.execCommand('formatBlock', false, '

'); - } - }); - - //给textarea同步内容 - $(textArea).parents('form').on('submit', function(){ - var html = body.html(); - //IE8下将标签处理成小写 - if(device.ie == 8){ - html = html.replace(/<.+>/g, function(str){ - return str.toLowerCase(); - }); - } - textArea.value = html; - }); - - //处理粘贴 - body.on('paste', function(e){ - iframeDOM.execCommand('formatBlock', false, '

'); - setTimeout(function(){ - filter.call(iframeWin, body); - textArea.value = body.html(); - }, 100); - }); - } - - //标签过滤 - ,filter = function(body){ - var iframeWin = this - ,iframeDOM = iframeWin.document; - - //清除影响版面的css属性 - body.find('*[style]').each(function(){ - var textAlign = this.style.textAlign; - this.removeAttribute('style'); - $(this).css({ - 'text-align': textAlign || '' - }) - }); - - //修饰表格 - body.find('table').addClass('layui-table'); - - //移除不安全的标签 - body.find('script,link').remove(); - } - - //Range对象兼容性处理 - ,Range = function(iframeDOM){ - return iframeDOM.selection - ? iframeDOM.selection.createRange() - : iframeDOM.getSelection().getRangeAt(0); - } - - //当前Range对象的endContainer兼容性处理 - ,getContainer = function(range){ - return range.endContainer || range.parentElement().childNodes[0] - } - - //在选区插入内联元素 - ,insertInline = function(tagName, attr, range){ - var iframeDOM = this.document - ,elem = document.createElement(tagName) - for(var key in attr){ - elem.setAttribute(key, attr[key]); - } - elem.removeAttribute('text'); - - if(iframeDOM.selection){ //IE - var text = range.text || attr.text; - if(tagName === 'a' && !text) return; - if(text){ - elem.innerHTML = text; - } - range.pasteHTML($(elem).prop('outerHTML')); - range.select(); - } else { //非IE - var text = range.toString() || attr.text; - if(tagName === 'a' && !text) return; - if(text){ - elem.innerHTML = text; - } - range.deleteContents(); - range.insertNode(elem); - } - } - - //工具选中 - ,toolCheck = function(tools, othis){ - var iframeDOM = this.document - ,CHECK = 'layedit-tool-active' - ,container = getContainer(Range(iframeDOM)) - ,item = function(type){ - return tools.find('.layedit-tool-'+type) - } - - if(othis){ - othis[othis.hasClass(CHECK) ? 'removeClass' : 'addClass'](CHECK); - } - - tools.find('>i').removeClass(CHECK); - item('unlink').addClass(ABLED); - - $(container).parents().each(function(){ - var tagName = this.tagName.toLowerCase() - ,textAlign = this.style.textAlign; - - //文字 - if(tagName === 'b' || tagName === 'strong'){ - item('b').addClass(CHECK) - } - if(tagName === 'i' || tagName === 'em'){ - item('i').addClass(CHECK) - } - if(tagName === 'u'){ - item('u').addClass(CHECK) - } - if(tagName === 'strike'){ - item('d').addClass(CHECK) - } - - //对齐 - if(tagName === 'p'){ - if(textAlign === 'center'){ - item('center').addClass(CHECK); - } else if(textAlign === 'right'){ - item('right').addClass(CHECK); - } else { - item('left').addClass(CHECK); - } - } - - //超链接 - if(tagName === 'a'){ - item('link').addClass(CHECK); - item('unlink').removeClass(ABLED); - } - }); - } - - //触发工具 - ,toolActive = function(iframeWin, editor, set){ - var iframeDOM = iframeWin.document - ,body = $(iframeDOM.body) - ,toolEvent = { - //超链接 - link: function(range){ - var container = getContainer(range) - ,parentNode = $(container).parent(); - - link.call(body, { - href: parentNode.attr('href') - ,target: parentNode.attr('target') - }, function(field){ - var parent = parentNode[0]; - if(parent.tagName === 'A'){ - parent.href = field.url; - } else { - insertInline.call(iframeWin, 'a', { - target: field.target - ,href: field.url - ,text: field.url - }, range); - } - }); - } - //清除超链接 - ,unlink: function(range){ - iframeDOM.execCommand('unlink'); - } - //插入代码 - ,code: function(range){ - code.call(body, function(pre){ - insertInline.call(iframeWin, 'pre', { - text: pre.code - ,'lay-lang': pre.lang - }, range); - }); - } - //帮助 - ,help: function(){ - layer.open({ - type: 2 - ,title: '帮助' - ,area: ['600px', '380px'] - ,shadeClose: true - ,shade: 0.1 - ,skin: 'layui-layer-msg' - ,content: ['', 'no'] - }); - } - } - ,tools = editor.find('.layui-layedit-tool') - - ,click = function(){ - var othis = $(this) - ,events = othis.attr('layedit-event') - ,command = othis.attr('lay-command'); - - if(othis.hasClass(ABLED)) return; - - body.focus(); - - var range = Range(iframeDOM) - ,container = range.commonAncestorContainer - - if(command){ - iframeDOM.execCommand(command); - if(/justifyLeft|justifyCenter|justifyRight/.test(command)){ - iframeDOM.execCommand('formatBlock', false, '

'); - } - setTimeout(function(){ - body.focus(); - }, 10); - } else { - toolEvent[events] && toolEvent[events].call(this, range); - } - toolCheck.call(iframeWin, tools, othis); - } - - ,isClick = /image/ - - tools.find('>i').on('mousedown', function(){ - var othis = $(this) - ,events = othis.attr('layedit-event'); - if(isClick.test(events)) return; - click.call(this) - }).on('click', function(){ - var othis = $(this) - ,events = othis.attr('layedit-event'); - if(!isClick.test(events)) return; - click.call(this) - }); - - //触发内容区域 - body.on('click', function(){ - toolCheck.call(iframeWin, tools); - }); - } - - //超链接面板 - ,link = function(options, callback){ - var body = this, index = layer.open({ - type: 1 - ,id: 'LAY_layedit_link' - ,area: '350px' - ,shade: 0.05 - ,shadeClose: true - ,moveType: 1 - ,title: '超链接' - ,skin: 'layui-layer-msg' - ,content: ['

'].join('') - ,success: function(layero, index){ - var eventFilter = 'submit(layedit-link-yes)'; - form.render('radio'); - layero.find('.layui-btn-primary').on('click', function(){ - layer.close(index); - body.focus(); - }); - form.on(eventFilter, function(data){ - layer.close(link.index); - callback && callback(data.field); - }); - } - }); - link.index = index; - } - - //插入代码面板 - ,code = function(callback){ - var body = this, index = layer.open({ - type: 1 - ,id: 'LAY_layedit_code' - ,area: '550px' - ,shade: 0.05 - ,shadeClose: true - ,moveType: 1 - ,title: '插入代码' - ,skin: 'layui-layer-msg' - ,content: [''].join('') - ,success: function(layero, index){ - var eventFilter = 'submit(layedit-code-yes)'; - form.render('select'); - layero.find('.layui-btn-primary').on('click', function(){ - layer.close(index); - body.focus(); - }); - form.on(eventFilter, function(data){ - layer.close(code.index); - callback && callback(data.field); - }); - } - }); - code.index = index; - } - - //全部工具 - ,tools = { - html: '' - ,strong: '' - ,italic: '' - ,underline: '' - ,del: '' - - ,'|': '' - - ,left: '' - ,center: '' - ,right: '' - ,link: '' - ,unlink: '' - ,face: '' - ,image: '' - ,code: '' - - ,help: '' - } - - ,edit = new Edit(); - - exports(MOD_NAME, edit); -}); From 1ecefbabca9bb65bcbe7049a8880cc1bc6472315 Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <285584806@qq.com> Date: Sat, 6 Aug 2022 02:11:34 +0800 Subject: [PATCH 10/14] =?UTF-8?q?table=20=E4=BF=AE=E5=A4=8D=E5=A4=9A?= =?UTF-8?q?=E7=BA=A7=E8=A1=A8=E5=A4=B4=E9=9A=90=E8=97=8F=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=88=97=E9=87=8D=E8=BD=BD=E4=B9=8B=E5=90=8E=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E9=9A=90=E8=97=8F=E7=9A=84=E5=88=97=E4=B9=8B?= =?UTF-8?q?=E5=90=8E=E5=87=BA=E7=8E=B0=E7=9A=84=E9=94=99=E5=88=97=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/table.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/table.js b/src/modules/table.js index 0e301342..fadb6159 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -491,8 +491,8 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ item2.key = i1 + '-' + i2; item2.hide = item2.hide || false; - item2.colspan = item2.colspan || 1; - item2.rowspan = item2.rowspan || 1; + item2.colspan = item2.colspan || 0; + item2.rowspan = item2.rowspan || 0; //根据列类型,定制化参数 that.initOpts(item2); @@ -2140,8 +2140,8 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ var row = $.extend({ title: th.text() - ,colspan: th.attr('colspan') || 1 //列单元格 - ,rowspan: th.attr('rowspan') || 1 //行单元格 + ,colspan: th.attr('colspan') || 0 //列单元格 + ,rowspan: th.attr('rowspan') || 0 //行单元格 }, itemData); if(row.colspan < 2) cols.push(row); From 19871595bb024b133843f5668a6f1f7d8c8da644 Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <285584806@qq.com> Date: Sun, 7 Aug 2022 01:15:27 +0800 Subject: [PATCH 11/14] =?UTF-8?q?table=20=E4=BF=AE=E5=A4=8D=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E9=97=AE=E9=A2=98=E4=BB=A5=E5=8F=8A=E5=8A=A0=E5=BC=BA?= =?UTF-8?q?=E5=92=8C=E5=B9=B6=E5=88=97=E8=A1=A8=E5=A4=B4=E7=9A=84=E5=AE=BD?= =?UTF-8?q?=E5=BA=A6=E8=87=AA=E9=80=82=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/css/layui.css | 2 +- src/modules/table.js | 54 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/css/layui.css b/src/css/layui.css index 12ba1d30..f4c406b1 100644 --- a/src/css/layui.css +++ b/src/css/layui.css @@ -900,7 +900,7 @@ a cite{font-style: normal; *cursor:pointer;} /* 小表格 */ .layui-table[lay-size="sm"] th, .layui-table[lay-size="sm"] td{padding-top: 5px; padding-right: 10px; padding-bottom: 5px; padding-left: 10px; font-size: 12px;} -.layui-table-view .layui-table[lay-size="sm"] .layui-table-cell{height: 30px; line-height: 20px; padding-top: 5px; padding-right: 5px;} +.layui-table-view .layui-table[lay-size="sm"] .layui-table-cell{height: 30px; line-height: 20px; padding-top: 5px; padding-right: 15px;} /* 数据表格 */ .layui-table[lay-data]{display: none;} diff --git a/src/modules/table.js b/src/modules/table.js index fadb6159..840ad933 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -154,7 +154,7 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ return ''; }() ,'{{# var isSort = !(item2.colGroup) && item2.sort; }}' - ,'' + ,'' ,'
'); + lis.push('
  • '); } }); return lis.join(''); @@ -1721,6 +1761,7 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ var setWidth = dict.ruleWidth + e.clientX - dict.offset[0]; if(setWidth < dict.minWidth) setWidth = dict.minWidth; dict.rule.style.width = setWidth + 'px'; + thisTable.that[thisTable.eventMoveElem.closest('.' + ELEM_VIEW).attr('lay-id')].setGroupWidth(); layer.close(that.tipsIndex); } } @@ -1728,7 +1769,7 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ if(thisTable.eventMoveElem){ dict = {}; _BODY.css('cursor', ''); - that.scrollPatch(); + thisTable.that[thisTable.eventMoveElem.closest('.' + ELEM_VIEW).attr('lay-id')].scrollPatch(); // 清除当前拖拽信息 thisTable.eventMoveElem.removeData(DATA_MOVE_NAME); @@ -1920,11 +1961,12 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ var field = othis.parent().data('field'); var index = othis.parents('tr').eq(0).data('index'); var data = table.cache[that.key][index]; - + var oldValue = data[field]; data[field] = value; // 更新缓存中的值 layui.event.call(this, MOD_NAME, 'edit('+ filter +')', commonMember.call(this, { value: value ,field: field + ,oldValue: oldValue })); }).on('blur', '.'+ELEM_EDIT, function(){ var othis = $(this); From 2bf2493a1d00cc94f531e162a6e3b88b48e17da2 Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <285584806@qq.com> Date: Sun, 7 Aug 2022 01:26:55 +0800 Subject: [PATCH 12/14] =?UTF-8?q?table=20=E4=BF=AE=E5=A4=8D=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E9=97=AE=E9=A2=98=E4=BB=A5=E5=8F=8A=E5=8A=A0=E5=BC=BA?= =?UTF-8?q?=E5=92=8C=E5=B9=B6=E5=88=97=E8=A1=A8=E5=A4=B4=E7=9A=84=E5=AE=BD?= =?UTF-8?q?=E5=BA=A6=E8=87=AA=E9=80=82=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/table.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/table.js b/src/modules/table.js index 840ad933..4908b6d0 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -644,7 +644,6 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ if (options.cols.length > 1) { for (var i = options.cols.length - 1; i >= 0; i--) { // 自下向上处理合并表头的宽度 - debugger; layui.each(that.layHeader.first().find('tr').eq(i).find('>th>div.laytable-cell-group'), function (i1, item1) { item1 = $(item1); var thElem = item1.parent(); From 5b37d0165c146e6e73a79dc8e621b9711ce0b414 Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <285584806@qq.com> Date: Sun, 7 Aug 2022 01:47:04 +0800 Subject: [PATCH 13/14] =?UTF-8?q?table=20=E4=BF=AE=E5=A4=8D=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E9=97=AE=E9=A2=98=E4=BB=A5=E5=8F=8A=E5=8A=A0=E5=BC=BA?= =?UTF-8?q?=E5=92=8C=E5=B9=B6=E5=88=97=E8=A1=A8=E5=A4=B4=E7=9A=84=E5=AE=BD?= =?UTF-8?q?=E5=BA=A6=E8=87=AA=E9=80=82=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/css/layui.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/css/layui.css b/src/css/layui.css index f4c406b1..51ffc0ae 100644 --- a/src/css/layui.css +++ b/src/css/layui.css @@ -900,7 +900,7 @@ a cite{font-style: normal; *cursor:pointer;} /* 小表格 */ .layui-table[lay-size="sm"] th, .layui-table[lay-size="sm"] td{padding-top: 5px; padding-right: 10px; padding-bottom: 5px; padding-left: 10px; font-size: 12px;} -.layui-table-view .layui-table[lay-size="sm"] .layui-table-cell{height: 30px; line-height: 20px; padding-top: 5px; padding-right: 15px;} +.layui-table-view .layui-table[lay-size="sm"] .layui-table-cell{height: 30px; line-height: 20px; padding-top: 5px; padding-left: 5px; padding-right: 5px;} /* 数据表格 */ .layui-table[lay-data]{display: none;} From e585a20964c845d3cdfce31b1368fe6f2755a5d3 Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <470459819@qq.com> Date: Mon, 8 Aug 2022 16:59:47 +0800 Subject: [PATCH 14/14] =?UTF-8?q?=E4=BC=98=E5=8C=96setGroupWidth=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E6=8F=90=E9=AB=98=E6=8B=96=E5=8A=A8=E6=94=B9?= =?UTF-8?q?=E5=8F=98=E5=88=97=E5=AE=BD=E6=97=B6=E5=80=99=E5=90=88=E5=B9=B6?= =?UTF-8?q?=E8=A1=A8=E5=A4=B4=E5=AE=BD=E5=BA=A6=E8=B0=83=E6=95=B4=E7=9A=84?= =?UTF-8?q?=E6=95=88=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/table.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/modules/table.js b/src/modules/table.js index 4908b6d0..25cd0f60 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -638,17 +638,18 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ }; // 设置合并表头的宽度 - Class.prototype.setGroupWidth = function () { + Class.prototype.setGroupWidth = function (thElem) { var that = this; var options = that.config; + var parentKey; if (options.cols.length > 1) { - for (var i = options.cols.length - 1; i >= 0; i--) { + for (var i = thElem ? thElem.closest('tr').index() - 1 : options.cols.length - 1; i >= 0; i--) { // 自下向上处理合并表头的宽度 - layui.each(that.layHeader.first().find('tr').eq(i).find('>th>div.laytable-cell-group'), function (i1, item1) { + parentKey = thElem ? thElem.attr('data-parentkey') : ''; + layui.each(that.layHeader.first().find('tr').eq(i).find('>th' + (parentKey && '[data-key="' + that.index + '-' + parentKey + '"]') + '>div.laytable-cell-group'), function (i1, item1) { item1 = $(item1); - var thElem = item1.parent(); var width = 0; - var key = thElem.attr('data-key'); + var key = item1.parent().attr('data-key'); layui.each(that.layHeader.first().find('th[data-parentkey="' + key.substr(key.indexOf('-') + 1) + '"]'), function (i2, item2) { item2 = $(item2); if (item2.hasClass(HIDE)) { @@ -656,8 +657,8 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ } width += item2.children('div.layui-table-cell').outerWidth(); }); - // item1.outerWidth(width); that.layHeader.find('th[data-key="'+key+'"]').children('div.layui-table-cell').outerWidth(width); + thElem && (thElem = item1.parent()); }) } @@ -1760,7 +1761,7 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ var setWidth = dict.ruleWidth + e.clientX - dict.offset[0]; if(setWidth < dict.minWidth) setWidth = dict.minWidth; dict.rule.style.width = setWidth + 'px'; - thisTable.that[thisTable.eventMoveElem.closest('.' + ELEM_VIEW).attr('lay-id')].setGroupWidth(); + thisTable.that[thisTable.eventMoveElem.closest('.' + ELEM_VIEW).attr('lay-id')].setGroupWidth(thisTable.eventMoveElem); layer.close(that.tipsIndex); } }