右键弹出菜单,给编辑内容增加上下标

//事件注册

                listeners:{
                	render : function() {
						Ext.fly(this.el).on('contextmenu',
								function(e, t) {
									e.preventDefault();
									e.stopPropagation();
									var textBox = document.getElementById(t.id);
									var selection = document.selection;
									var target = e.target;
									insertStart = 0;
									insertEnd = 0;
									if (typeof(target.selectionStart) != 'undefined') {
										insertStart = target.selectionStart;
										insertEnd = target.selectionEnd;
									} else if (selection && selection.createRange) {
										var tr = textBox.createTextRange();
										var r = selection.createRange();
										tr.setEndPoint('endtoend', r);
										insertStart = tr.text.length - r.text.length;
										insertEnd = tr.text.length;
									}
									needInsertObj = textBox;
                    				rightClick.showAt(e.getXY());
								});


// 全局变量

    var needInsertObj;
    var insertStart;
    var insertEnd;

	var rightClick = new Ext.menu.Menu({
				id : 'rightClickCont', // 在HTML文件中必须有个rightClickCont的DIV元素
				items : [{
							id : 'insertSUP',
							handler : insertSUP,// 点击后触发的事件
							text : '插入上标'
						}, {
							id : 'insertSUB',
							handler : insertSUB,
							text : '插入下标'
						}]
			});
	function insertSUP(){
		var itemForm = new Ext.FormPanel({
    	frame : false,
		plain : false,
		bodyStyle : 'padding:5px 5px 0;background:transparent',
		defaultType : 'textfield',
    	items: [{
					fieldLabel : '上标内容',
					id : 'supContent',
					readOnly : false,
					name : 'supContent',
					anchor : '80%'
				}
				]
		});		
		var win = new Ext.Window({
				width : 430,
				//height : 280,
				title : '添加上标',
				modal : true,
				closable : false,
				resizable : false,
				autoDestroy : true,
				//closeAction : 'hide',
				bodyStyle : 'padding:10px 12px 10px 10px ',
				items : [itemForm],
				buttons : [{
							text : '确定',
							handler : function() {
								if(itemForm.findById('supContent').getValue()==''){
								}else{
									needInsertObj.value = 	needInsertObj.value.substring(0,insertStart) 
									+ '<sup>' + itemForm.findById('supContent').getValue() + "</sup>" +
									needInsertObj.value.substring(insertEnd);
								}
								win.close();
							
							}
							},{
							text : '关闭',
							handler : function() {
								win.close();
							}
						}]
			}).show();
	}
	function insertSUB(){
		var itemForm = new Ext.FormPanel({
    	frame : false,
		plain : false,
		bodyStyle : 'padding:5px 5px 0;background:transparent',
		defaultType : 'textfield',
    	items: [{
					fieldLabel : '下标内容',
					id : 'subContent',
					readOnly : false,
					name : 'subContent',
					anchor : '80%'
				}
				]
		});		
		var win = new Ext.Window({
				width : 430,
				//height : 280,
				title : '添加下标',
				modal : true,
				closable : false,
				resizable : false,
				autoDestroy : true,
				//closeAction : 'hide',
				bodyStyle : 'padding:10px 12px 10px 10px ',
				items : [itemForm],
				buttons : [{
							text : '确定',
							handler : function() {
								if(itemForm.findById('subContent').getValue()==''){
								}else{
									needInsertObj.value = 	needInsertObj.value.substring(0,insertStart) 
									+ '<sub>' + itemForm.findById('subContent').getValue() + "</sub>" +
									needInsertObj.value.substring(insertEnd);
								}
								win.close();
							
							}
							},{
							text : '关闭',
							handler : function() {
								win.close();
							}
						}]
			}).show();
	}	






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值