Я хочу проверить узел выделенного текста.Если это span, другая функция будет редактировать примененные к нему классы.Если он совпадает с родительским узлом, код обернет выделение в span и установит его стили.Проблема, с которой я здесь сталкиваюсь, заключается в том, как определить, выбрал ли пользователь весь текст в редакторе или только какой-то текст.Если пользователь выделяет весь текст, я хочу применить стили к родительскому узлу вместо добавления нового диапазона и стилей к нему.Ниже мой код -
var ed=tinyMCE.getInstanceById('textAreaId');
var sel = ed.selection.getContent();
if(trim(sel)!="") {
//get the node of the selection
var thisNode=tinyMCE.activeEditor.selection.getStart().nodeName;
ed_Property=propertyName;
ed_PropertyVal=propertyValue;
//get the root node inside editor
var parentNode=tinyMCE.activeEditor.getBody().firstChild.nodeName;
if(thisNode=="SPAN") {
nodeclass=$(tinyMCE.activeEditor.selection.getNode()).attr('class');
//edit span properties
editSpanProperties(nodeclass,propertyName,propertyValue);
}
else if(thisNode==parentNode) {
var elmType="span";
var Spanid1=createSpanId(targetToStyle,elmType);
Spanid=targetToStyle+"_"+elmType+"_"+Spanid1;
var strStyle=ed_Property+":"+ed_PropertyVal;
//wrap selection in a span
sel = "<span id='"+Spanid+"' style='"+strStyle+"'>" + sel + "</span>";
//set content
ed.selection.setContent(sel);
//retain the selection
ed.selection.select(ed.dom.select('#'+Spanid)[0],false);
}
else {
//here I need to check if user has selected whole text and set properties
setStylesOnEditor(templateSection,propertyName,propertyValue);
}//if ends
}
else if(trim(sel)=="") {
alert('No text selected');
}