From cd2770e6011210a3f41c1efa47dd8ea90c2396f0 Mon Sep 17 00:00:00 2001 From: hzliujunwei Date: Sat, 8 Jul 2017 10:55:51 +0800 Subject: [PATCH] =?UTF-8?q?@dev=20=E6=B7=BB=E5=8A=A0setPlaceholder?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=94=A8=E4=BA=8E=E8=AE=BE=E7=BD=AEplacehold?= =?UTF-8?q?er?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _examples/completeDemo.html | 351 ++++++++++++++++++------------------ _src/core/Editor.js | 35 ++++ 2 files changed, 211 insertions(+), 175 deletions(-) diff --git a/_examples/completeDemo.html b/_examples/completeDemo.html index a25959c6b..ced483d2d 100755 --- a/_examples/completeDemo.html +++ b/_examples/completeDemo.html @@ -1,175 +1,176 @@ - - - - 完整demo - - - - - - - - - - -
-

完整demo

- -
-
-
- - - - - - - - - - - -
-
- - - - - - - -
- -
- - -
- -
-
- - -
- - - - \ No newline at end of file + + + + 完整demo + + + + + + + + + + +
+

完整demo

+ +
+
+
+ + + + + + + + + + + +
+
+ + + + + + + + +
+ +
+ + +
+ +
+
+ + +
+ + + + diff --git a/_src/core/Editor.js b/_src/core/Editor.js index 2a99d6013..f11fb7d8b 100644 --- a/_src/core/Editor.js +++ b/_src/core/Editor.js @@ -301,6 +301,38 @@ } }, + /** + * 该方法用于设置placeholder + * @method setPlaceholder + * @param { String } placeholder 编辑器的placeholder文案 + * @example + * ```javascript + * editor.setPlaceholder('请输入内容'); + * ``` + */ + setPlaceholder: function(){ + + function contentChange(){ + var localHtml = this.getPlainTxt(); + if(!localHtml.trim()){ + UE.dom.domUtils.addClass( this.body, 'empty' ); + }else{ + UE.dom.domUtils.removeClasses( this.body, 'empty' ); + } + } + + return function(placeholder){ + var _editor = this; + + _editor.ready(function () { + contentChange.call(_editor); + _editor.body.setAttribute('placeholder', placeholder); + }); + _editor.removeListener('keyup contentchange', contentChange); + _editor.addListener('keyup contentchange', contentChange); + } + }(), + /** * 该方法是提供给插件里面使用,设置配置项默认值 * @method setOpt @@ -437,7 +469,10 @@ ".view{padding:0;word-wrap:break-word;cursor:text;height:90%;}\n" + //设置默认字体和字号 //font-family不能呢随便改,在safari下fillchar会有解析问题 + "body{margin:8px;font-family:sans-serif;font-size:16px;}" + + //设置placeholder + "body.empty:before{content:attr(placeholder);position:absolute;color:#999;}"+ //设置段落间距 "p{margin:5px 0;}" + (options.iframeCssUrl