1. Demand
Web page editing of third-party plug-ins a lot, I need to do a mobile phone on the release of pictures + text of the Lite Editor, text and pictures on the top-down arrangement is over.
IFrame has a lot of implementation architectures.
2. Realize
2.1 IFRAME Definition
2.2 Editing mode settings and focus fetching
Ifedit = This.getelementbyxid ("Ifedit"). Contentwindow;
Edit mode
IfEdit.document.designMode = "on";
IfEdit.document.contentEditable = true;
var GetPos = function () {
Debugger
Ifedit.pos = IfEdit.document.selection.createRange ();
};
IfEdit.document.body.onclick = GetPos;
IfEdit.document.body.onselect = GetPos;
IfEdit.document.body.onkeyup = GetPos;
2.3 Image Insertion function
function (HtmlElement) {
"<p><br>" + htmlelement + "</p>";
Ifedit.focus ();
var _image = document.createelement ("img");
_image.src=htmlelement;
_image.border= "0";
var iftemp = document.getElementById ("Ifedittemp");
Debugger
if (ifEdit.document.selection.type.toLowerCase ()! = "None")
{
IfEdit.document.selection.clear ();
}
IfEdit.pos.pasteHTML (_image.outerhtml);
Ifedit.focus ();
};
3. Questions
WeX5 schema, IFRAME does not selection this property. Dubugger found Event.target can get to the current node
3.1 Initializing an IFRAME
Ifedit = This.getelementbyxid ("Ifedit"). Contentwindow;
//edit mode
IfEdit.document.designMode = "on";
ifEdit.document.contentEditable = true;
var GetPos = function (event) {
debugger;
Ifedit.pos = event.target;// IfEdit.document.selection.createRange ();
};
IfEdit.document.body.onclick = GetPos;
ifEdit.document.body.onselect = GetPos;
ifEdit.document.body.onkeyup = GetPos;
3.2 Adding a child node on the body
Model.prototype.insertHtml = function (htmlelement) {
"<p><br>" + htmlelement + "</p>";
Ifedit.focus ();
var _image = document.createelement ("img");
_image.src=htmlelement;
_image.border= "0";
var iftemp = document.getElementById ("Ifedittemp");
Debugger
/*
if (ifEdit.document.selection.type.toLowerCase ()! = "None")
{
IfEdit.document.selection.clear ();
}*/
POS does not get focus, no last node, last node equals current node, append to Last
if (!ifedit.pos | |!ifedit.document.body.lastchild | |
IfEdit.document.body.lastChild = = Ifedit.pos) {
IfEdit.document.body.appendChild (_image);
}
else{
IfEdit.document.body.insertBefore (_image,ifedit.pos.nextsibling);
}
Ifedit.focus ();
};
"Web page editing" mode of text sending