[Phonegap+Sencha Touch] 移动开发66 sencha touch可编辑的div(ContentEditable=true)下,长按不弹出“复制粘贴”菜单的解决办法

原文地址:http://blog.csdn.net/lovelyelfpop/article/details/49000709




<div id="example" contenteditable="true">

上述可编辑的div,可以代替textarea做一些高级的功能,比如富文本、@好友等。


但是sencha touch框架,在使用ContentEditable的div的时候,长按时却弹不出“复制粘贴”的菜单,这个现象只影响安卓4.4及以上和iOS。


解决办法:

找到文件\touch\src\viewport\Default.js

1、在Ext.viewport.Default类中添加一个函数

isContentEditable: function(node){
    return node && node.tagName == 'DIV' && node.contentEditable == "true";
},



2、找到doBlurInput函数,将下面的代码:

if (focusedElement && focusedElement.nodeName.toUpperCase() != 'BODY' && !this.isInputRegex.test(target.tagName)) {
    delete this.focusedElement;
    focusedElement.blur();
}

修改如下:

if (focusedElement && focusedElement.nodeName.toUpperCase() != 'BODY' && !this.isInputRegex.test(target.tagName) && !this.isContentEditable(target)) {
    delete this.focusedElement;
    focusedElement.blur();
}



3、doPreventPanning函数,将下面代码:

if (this.isInteractiveWebComponentRegEx.test(target.tagName) && e.touches && e.touches.length > 0) {
    touch = e.touches[0];
    if (touch && touch.target && this.isInputRegex.test(touch.target.tagName)) {
        return;
    }
}
if (target && target.nodeType === 1 && !this.isInputRegex.test(target.tagName)) {
    e.preventDefault();
}

修改如下:

if (this.isInteractiveWebComponentRegEx.test(target.tagName) && e.touches && e.touches.length > 0) {
    touch = e.touches[0];
    if (touch && touch.target && this.isInputRegex.test(touch.target.tagName) && this.isContentEditable(touch.target)) {
        return;
    }
}
if (target && target.nodeType === 1 && !this.isInputRegex.test(target.tagName) && !this.isContentEditable(target)) {
    e.preventDefault();
}


4、doPreventZooming函数,将下面代码:

if (this.isInteractiveWebComponentRegEx.test(target.tagName) && e.touches && e.touches.length > 0) {
    touch = e.touches[0];
    if (touch && touch.target && this.isInputRegex.test(touch.target.tagName)) {
        return;
    }
}
if (target && target.nodeType === 1 && !this.isInputRegex.test(target.tagName)) {
    e.preventDefault();
}

修改如下:

if (this.isInteractiveWebComponentRegEx.test(target.tagName) && e.touches && e.touches.length > 0) {
    touch = e.touches[0];
    if (touch && touch.target && this.isInputRegex.test(touch.target.tagName) && this.isContentEditable(touch.target)) {
        return;
    }
}
if (target && target.nodeType === 1 && !this.isInputRegex.test(target.tagName) && !this.isContentEditable(target)) {
    e.preventDefault();
}



这样,“复制粘贴”的菜单在长按可编辑DIV的时候,就可以弹出来了。









欢迎加入Sencha Touch + Phonegap交流群

1群:194182999 (满)

2群:419834979

共同学习交流(博主QQ:479858761


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

神秘_博士

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值