原文地址: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();
}
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)