source: [view]
if(node){
var w = this.editor.window;
var self = this;
var convertNode = function(cNode){
if(cNode.nodeType == 1){
if(cNode.id !== "dijitEditorBody"){
var style = cNode.style;
var tag = cNode.tagName?cNode.tagName.toLowerCase():"";
var sTag;
if(style && tag != "table" && tag != "ul" && tag != "ol"){
// Avoid wrapper blocks that have specific underlying structure, as injecting
// spans/etc there is invalid.
// Lets check and convert certain node/style types.
var fw = style.fontWeight? style.fontWeight.toLowerCase() : "";
var fs = style.fontStyle? style.fontStyle.toLowerCase() : "";
var td = style.textDecoration? style.textDecoration.toLowerCase() : "";
var s = style.fontSize?style.fontSize.toLowerCase() : "";
var bc = style.backgroundColor?style.backgroundColor.toLowerCase() : "";
var c = style.color?style.color.toLowerCase() : "";
var wrapNodes = function(wrap, pNode){
if(wrap){
while(pNode.firstChild){
wrap.appendChild(pNode.firstChild);
}
if(tag == "span" && !pNode.style.cssText){
// A styler tag with nothing extra in it, so lets remove it.
dojo.place(wrap, pNode, "before");
pNode.parentNode.removeChild(pNode);
pNode = wrap;
}else{
pNode.appendChild(wrap);
}
}
return pNode;
};
switch(fw){
case "bold":
case "bolder":
case "700":
case "800":
case "900":
sTag = dojo.withGlobal(w, "create", dojo, ["b", {}] );
cNode.style.fontWeight = "";
break;
}
cNode = wrapNodes(sTag, cNode);
sTag = null;
if(fs == "italic"){
sTag = dojo.withGlobal(w, "create", dojo, ["i", {}] );
cNode.style.fontStyle = "";
}
cNode = wrapNodes(sTag, cNode);
sTag = null;
if(td){
var da = td.split(" ");
var count = 0;
dojo.forEach(da, function(s){
switch(s){
case "underline":
sTag = dojo.withGlobal(w, "create", dojo, ["u", {}] );
break;
case "line-through":
sTag = dojo.withGlobal(w, "create", dojo, ["strike", {}] );
break;
}
count++;
if(count == da.length){
// Last one, clear the decor and see if we can span strip on wrap.
cNode.style.textDecoration = "";
}
cNode = wrapNodes(sTag, cNode);
sTag = null;
});
}
if(s){
var sizeMap = {
"xx-small": 1,
"x-small": 2,
"small": 3,
"medium": 4,
"large": 5,
"x-large": 6,
"xx-large": 7,
"-webkit-xxx-large": 7
};
// Convert point or px size to size
// to something roughly mappable.
if(s.indexOf("pt") > 0){
s = s.substring(0,s.indexOf("pt"));
s = parseInt(s);
if(s < 5){
s = "xx-small";
}else if(s < 10){
s = "x-small";
}else if(s < 15){
s = "small";
}else if(s < 20){
s = "medium";
}else if(s < 25){
s = "large";
}else if(s < 30){
s = "x-large";
}else if(s > 30){
s = "xx-large";
}
}else if(s.indexOf("px") > 0){
s = s.substring(0,s.indexOf("px"));
s = parseInt(s);
if(s < 5){
s = "xx-small";
}else if(s < 10){
s = "x-small";
}else if(s < 15){
s = "small";
}else if(s < 20){
s = "medium";
}else if(s < 25){
s = "large";
}else if(s < 30){
s = "x-large";
}else if(s > 30){
s = "xx-large";
}
}
var size = sizeMap[s];
if(!size){
size = 3;
}
sTag = dojo.withGlobal(w, "create", dojo, ["font", {size: size}] );
cNode.style.fontSize = "";
}
cNode = wrapNodes(sTag, cNode);
sTag = null;
if(bc && tag !== "font" && self._isInline(tag)){
// IE doesn't like non-font background color crud.
// Also, don't move it in if the background color is set on a block style node,
// as it won't color properly once put on inline font.
bc = new dojo.Color(bc).toHex();
sTag = dojo.withGlobal(w, "create", dojo, ["font", {style: {backgroundColor: bc}}] );
cNode.style.backgroundColor = "";
}
if(c && tag !== "font"){
// IE doesn't like non-font background color crud.
c = new dojo.Color(c).toHex();
sTag = dojo.withGlobal(w, "create", dojo, ["font", {color: c}] );
cNode.style.color = "";
}
cNode = wrapNodes(sTag, cNode);
sTag = null;
}
}
if(cNode.childNodes){
// Clone it, since we may alter its position
var nodes = [];
dojo.forEach(cNode.childNodes, function(n){ nodes.push(n);});
dojo.forEach(nodes, convertNode);
}
}
return cNode;
};
return this._normalizeTags(convertNode(node));
}
return node;