KindEditor 添加默认提示信息

Qt中用这个编辑框可以设置提示信息并且禁用跳转链接
var editor;
var tipFlag = true;
var placeholderText = '';
KindEditor.ready(function(K) {
				editor = K.create('textarea[name="detailContent"]', {
					cssData : 'body {font-family:Microsoft YaHei; font-size:12px;} img{ max-width:100%;}',
					fullscreenMode: true,
					useContextmenu: false,
					filterMode: false,
					afterCreate:function(){
						//阻止点击链接默认跳转操作
						var self = this;
						var doc = this.edit.doc;
						K(doc).click(function(e) {
							if (K(e.target).name === 'a') {
								 e.preventDefault();
							}
						});	
						
						//添加一个提示编辑区
						var frame = this.edit;
						K('<textarea class="ph ke-edit-textarea" placeholder = "" style="width: 100%; padding:5px 5px 5px 7px; background-color:transparent; position: absolute;z-index: 10;top: 0;border: 0;overflow: auto;resize: none; font-size:12px;"></textarea>').appendTo(frame.iframe[0].contentDocument.firstChild);
						frame.iframe[0].contentDocument.firstChild.lastChild.style.height = "100%";
						frame.iframe[0].contentDocument.firstChild.lastChild.placeholder = placeholderText;
						
						var _ua = navigator.userAgent.toLowerCase();
						var _IE = _ua.indexOf('msie') > -1 && _ua.indexOf('opera') == -1;
						if(_IE)
						{
							//IE的事件穿透没做
						}else{
							//事件穿透
							frame.iframe[0].contentDocument.firstChild.lastChild.style.pointerEvents = 'none';
						}
						
						//监听输入事件
						K(frame.doc)[0].oninput = function(e){
							if(tipFlag && editor && editor.text() != '')
							{
								frame.iframe[0].contentDocument.firstChild.lastChild.style.display = "none";
								tipFlag = false;
							}
							else{
								if(editor && editor.text() == '' && !tipFlag)
								{
									frame.iframe[0].contentDocument.firstChild.lastChild.style.display = "block";
									tipFlag = true;
								}
							}
						};
					},
					afterChange:function(){
						if(editor)
						{
							var frame = this.edit;
							if(editor.text() != '' && tipFlag)
							{
								frame.iframe[0].contentDocument.firstChild.lastChild.style.display = "none";
								tipFlag = false;
							}else if(editor.text() == ''&& !tipFlag)
							{
								frame.iframe[0].contentDocument.firstChild.lastChild.style.display = "block";
								tipFlag = true;
							}
							
							frame.doc.body.focus();	
						}
						
					},
					items : [
						'bold','italic','underline','fontname','fontsize','forecolor','hilitecolor','link','selectall','source']
				});
				editor.focus();
			});
			//设置提示信息,这个要在html加载完成以后调用
			function setPlaceholderText(text){
				var data = utf8to16(base64decode(text)).replace(/\s/gi," ");
				placeholderText = data;
				if(editor && editor.edit && editor.edit.iframe[0] && editor.edit.iframe[0].contentDocument && editor.edit.iframe[0].contentDocument.firstChild && editor.edit.iframe[0].contentDocument.firstChild.lastChild){
					editor.edit.iframe[0].contentDocument.firstChild.lastChild.placeholder='';
					editor.edit.iframe[0].contentDocument.firstChild.lastChild.placeholder = data;
				}
				editor.focus();
			}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值