// Object reference maker Object.prototype.$=function $(val){if(val)this.valueOf=this.toSource=this.toString=function(){return val};return val;}; var IDOK = 1; var IDCANCEL = 2; var IDABORT = 3; var IDRETRY = 4; var IDIGNORE = 5; var IDYES = 6; var IDNO = 7; window.onerror = errorHandler; // document.lvl=0; var ImagesInfo = new Array(); //====================================== // Public API //====================================== //-------------------------------------- // Gets a binary object for the memory protocol to display book images in the browser function FillCoverList() { return FillLists(); } function apiGetBinary(id) { var bin_objects=document.all.binobj.getElementsByTagName("DIV"); for(var i=0; ir'; if(type.search("image") != -1) { imghref = "fbw-internal:#" + curid; div.innerHTML += ''; div.innerHTML += ''; } div.innerHTML += ''; div.innerHTML += ''; if(type.search("image") != -1) { var Dims; if(fullpath != "") Dims = window.external.GetImageDimsByPath(fullpath); else Dims = window.external.GetImageDimsByData(data); if(Dims != "") { var imgWidth = Dims.substring(0, Dims.search("x")); var imgHeight = Dims.substring(Dims.search("x") + 1, Dims.length); div.innerHTML += ''; var ImageInfo = new Object(); ImageInfo.src = imghref; ImageInfo.id = curid; ImageInfo.width = imgWidth; ImageInfo.height = imgHeight; ImagesInfo.push(ImageInfo); } } div.all.id.value = curid; div.all.type.value = type; div.base64data = data; div.all.id.setAttribute("oldId",curid); div.all.id.onchange=OnBinaryIdChange; document.all.binobj.appendChild(div); // PutSpacers(document.all.binobj); return curid; } function GetImageData(id) { var bo = document.all.binobj.getElementsByTagName("DIV"); for(var i = 0; i < bo.length; i++) { if(bo[i].all.id.value == id) return bo[i].base64data; } return; } function HighlightBorder(element, override, style, width, color) { if(!element ||!element.style) return; if(override) { element.style.border = style + " " + width + " " + color; } else element.style.border = ""; } function ShowPrevImage(source) { var prevImgPanel = document.getElementById("prevImgPanel"); var prevImg = document.getElementById("prevImg"); if(!prevImgPanel || !prevImg) return; // Shouldn't be shown in Fast mode. /*if(window.external.IsFastMode()) return; }*/ var idx = -1; for(i = 0; i < ImagesInfo.length; ++i) { if(ImagesInfo[i].src == source) { idx = i; break; } } if(idx == -1) return; var imgWidth = ImagesInfo[idx].width; var imgHeight = ImagesInfo[idx].height; var btnHeight = event.srcElement.offsetHeight; coordX = event.clientX; coordY = event.clientY; var scrollX = 0; var scrollY = 0; if(document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) { scrollX += document.documentElement.scrollLeft; scrollY += document.documentElement.scrollTop; } var winWidth = 0;; var winHeight = 0; if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientHeight) { winWidth = document.documentElement.clientWidth; winHeight = document.documentElement.clientHeight; } var place = "top"; var baseWidth = coordX; if(baseWidth > (winWidth - coordX)) baseWidth = winWidth - coordX; baseWidth = baseWidth*2; var baseHeight = coordY; if(baseHeight < (winHeight - coordY)) { baseHeight = winHeight - coordY; place = "bottom"; } baseHeight -= btnHeight; var ratio; if (baseWidth < 200) { ratio = 200/baseWidth; baseWidth = 200; baseHeight *= ratio; } var scaleTo = "width"; ratio = baseWidth/imgWidth; if(imgWidth < imgHeight) { scaleTo = "height"; ratio = baseHeight/imgHeight; } if(imgWidth > baseWidth || imgHeight > baseHeight) { switch (scaleTo) { case "width": imgWidth = baseWidth; imgHeight = ratio * imgHeight; if(imgHeight > baseHeight) { ratio = baseHeight/imgHeight; imgHeight = baseHeight; imgWidth = ratio * imgWidth; } break; case "height": imgHeight = baseHeight; imgWidth = ratio * imgWidth; if(imgWidth > baseWidth) { ratio = baseWidth/imgWidth; imgWidth = baseWidth; imgHeight = ratio * imgHeight; } break; } } prevImg.src = source; prevImg.width = imgWidth ; prevImg.height = imgHeight; prevImg.style.cursor = "default"; prevImgPanel.style.left = (coordX + scrollX - Math.round(imgWidth/2)) + "px"; switch(place) { case "top": prevImgPanel.style.top = (coordY + scrollY - Math.round(imgHeight) - btnHeight) + "px"; break; case "bottom": prevImgPanel.style.top = (coordY + scrollY + btnHeight) + "px"; break; } setTimeout('prevImgPanel.style.visibility = "visible"', 500); } function HidePrevImage() { var prevImgPanel = document.getElementById("prevImgPanel"); var prevImg = document.getElementById("prevImg"); if(!prevImgPanel || !prevImg) return; prevImg.src = ""; prevImg.width = 0; prevImg.height = 0; prevImgPanel.style.visibility = "hidden"; } function ShowFullImage(source) { HidePrevImage(); var fullImgPanel = document.getElementById("fullImgPanel"); var fullImg = document.getElementById("fullImg"); if(!fullImgPanel || !fullImg) return; var idx = -1; for(i = 0; i < ImagesInfo.length; ++i) { if(ImagesInfo[i].src == source) { idx = i; break; } } if(idx == -1) return; var imgWidth = ImagesInfo[idx].width; var imgHeight = ImagesInfo[idx].height; var scrollX = 0; var scrollY = 0; if(document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) { scrollX += document.documentElement.scrollLeft; scrollY += document.documentElement.scrollTop; } var winWidth = 0;; var winHeight = 0; if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientHeight) { winWidth = document.documentElement.clientWidth; winHeight = document.documentElement.clientHeight; } fullImg.src = source; fullImg.width = imgWidth; fullImg.height = imgHeight; if (imgHeight < winHeight ) fullImg.style.top = ((winHeight-imgHeight) / 2)+"px"; else fullImg.style.top = "0px"; fullImg.style.cursor = "default"; fullImgPanel.style.left = "0px"; fullImgPanel.style.width = (winWidth) + "px"; fullImgPanel.style.top = (scrollY) + "px"; if (winHeight < imgHeight) winHeight = imgHeight; fullImgPanel.style.height = (winHeight) + "px"; fullImgPanel.style.visibility = "visible"; } function HideFullImage() { var fullImgPanel = document.getElementById("fullImgPanel"); var fullImg = document.getElementById("fullImg"); if(!fullImgPanel || !fullImg) return; fullImg.src = ""; fullImg.width = 0; fullImg.height = 0; fullImgPanel.style.visibility = "hidden"; } function SaveImage(source) { var bin_objects=document.all.binobj.getElementsByTagName("DIV"); for(var i=0, cnt=0; i6.0 TaF issues 201 var xsl = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.6.0"); // 4.0->6.0 TaF issues 201 xsl.async = false; xsl.setProperty("ResolveExternals", true); // added by TaF issues 201 var proc; xsl.load(path); var doc = xsl.documentElement; var imp = doc.firstChild; var ats = imp.attributes; var href = ats.getNamedItem("href"); if(lang == "russian") href.nodeValue = "rus.xsl"; if(lang == "english") href.nodeValue = "eng.xsl"; if (lang == "ukrainian") href.nodeValue = "ukr.xsl"; if(xsl.parseError.errorCode) { errCantLoad(xsl, path); return false; } xslt.stylesheet = xsl; return xslt; } function ClickOnDesc() { var srcName = event.srcElement.nodeName; if (srcName=="FIELDSET" || srcName=="LABEL" || srcName=="DIV" ||srcName=="LEGEND") { document.body.focus(); } } function ShowCoverImage(prntEl,fullImg) { if (!prntEl) return; var list=prntEl.getElementsByTagName("SELECT"); if (list[0] && list[0].value) if (fullImg) ShowFullImage("fbw-internal:"+list[0].value); ShowPrevImage("fbw-internal:"+list[0].value); } function TransformXML(xslt, dom) { var body = document.getElementById("fbw_body"); if(!body) { return false; } var desc = document.getElementById("fbw_desc"); if(!desc) { return false; } proc=xslt.createProcessor(); proc.input=dom; proc.setStartMode("description"); proc.transform(); desc.innerHTML=proc.output; PutBinaries(dom); SetupDescription(desc); desc.onclick=ClickOnDesc; proc.setStartMode("body"); proc.transform(); body.innerHTML=proc.output; window.external.InflateParagraphs(body); document.fbwFilename=name; document.urlprefix="fbw-internal:"; return true; } function ShowDescElements() { var desc = document.getElementById("fbw_desc"); var spans = desc.getElementsByTagName("SPAN"); for(var i=0; i < spans.length; i++) { var elem_id = spans[i].getAttribute("id"); if(elem_id) ShowElement(elem_id, window.external.GetExtendedStyle(elem_id)); } } function LoadFromDOM(dom, lang) { dom.setProperty("SelectionNamespaces", "xmlns:fb='"+fbNS+"' xmlns:xlink='"+xlNS+"'"); var xpath=window.external.GetStylePath()+"\\fb2.xsl"; var ret = TransformXML(LoadXSL(xpath, lang), dom); ShowDescElements(); // transform to html return ret; } function XmlFromText(text) { var xml = new ActiveXObject("Msxml2.DOMDocument.6.0"); // 4.0->6.0 TaF issues 201 xml.async=false; xml.preserveWhiteSpace = true; xml.loadXML(text); if(xml.parseError.errorCode) { //errCantLoad(xml, path); return xml.parseError; } return xml; } function recursiveChangeNbsp(elem, repChar) { var el=elem; while (el) { if (el.nodeType==3) el.nodeValue=el.nodeValue.replace(/\u00A0/g, repChar); if (el.nodeType==1 && el.firstChild) recursiveChangeNbsp(el.firstChild, repChar); el=el.nextSibling; } } function apiLoadFB2(path, lang) { var css=document.getElementById("css"); var css_filename = css.href; css.href=""; var xml = new ActiveXObject("Msxml2.DOMDocument.6.0"); // 4.0->6.0 TaF issues 201 xml.async=false; xml.preserveWhiteSpace = true; xml.load(path); if(xml.parseError.errorCode) { errCantLoad(xml, path); return false; } pi = xml.firstChild; var encoding; if (pi) { attr = pi.attributes; if (attr) { enc = attr.getNamedItem("encoding"); if(enc) { encoding = enc.text; //alert(encoding); } } } xml.setProperty("SelectionNamespaces", "xmlns:fb='"+fbNS+"' xmlns:xlink='"+xlNS+"'"); if(window.external.GetNBSP()) { var nbspChar=window.external.GetNBSP(); if(nbspChar!="\u00A0") { var sel=xml.selectSingleNode("/fb:FictionBook/fb:description/fb:title-info/fb:annotation"); if(sel) recursiveChangeNbsp(sel,nbspChar); sel=xml.selectSingleNode("/fb:FictionBook/fb:description/fb:document-info/fb:history"); if(sel) recursiveChangeNbsp(sel,nbspChar); sel=xml.selectSingleNode("/fb:FictionBook/fb:body"); while(sel) { if(sel.nodeName=="body") recursiveChangeNbsp(sel,nbspChar); sel=sel.nextSibling; } } } if (!LoadFromDOM(xml, lang)) { MsgBox("Error: can't prepare document for Body mode."); return false; } document.selection.empty(); var desc = document.getElementById("fbw_desc"); var id=desc.all.diID; if(id) if(path.indexOf("blank.fb2") != -1) { id.value=window.external.GetUUID(); } else { id.value=id.value; // ???????? ????????? ????????. ??? ???? ??????? ??? ?????? ??? ???????? ?????????? ????? ?????? ????, ??? ???????? ? ????? ?????????. } apiShowDesc(false); css.href = css_filename; return encoding; } function apiShowDesc(state) { var body=document.getElementById("fbw_body"); if(!body) return; var desc=document.getElementById("fbw_desc"); if(!desc) return; if(state) { document.ScrollSave=document.body.scrollTop; desc.style.display="block"; document.body.scrollTop=0; body.style.display="none"; } else { desc.style.display="none"; body.style.display="block"; document.body.scrollTop=document.ScrollSave; } } function apiRunCmd(path) { window.msgText="Скрипт\n\n"+path+"\n\nне был запущен, т.к. не удалось его успешно загрузить.\n\n"+ "Возможная причина – файл скрипта отсутствует по тому пути, где он должен находиться."; window.Run=function() { if (window.msgText) alert(window.msgText); }; var script=document.getElementById("userCmd"); if(!script) return; script.src="file:///"+path; Run(); window.Run=function() { if (window.msgText) alert(window.msgText); }; } function apiGetClassName(path) { var script=document.getElementById("userCmd"); if(!script) return; script.src="file:///"+path; return GetClassName(); } function apiGetTitle(path) { var script=document.getElementById("userCmd"); if(!script) return; script.src="file:///"+path; return GetTitle(); } function apiProcessCmd(path) { var script=document.getElementById("userCmd"); if(!script) return; script.src="file:///"+path; ProcessCmd(); } function SetInFrame(range, tagName, className) { range.pasteHTML("<" + tagName + " classname=\"" + className + "\">" + range.htmlText + ""); } function RemoveOuterTags(node) { node.removeNode(false); } function apiCleanUp(className) { var divs = document.all.tags("DIV"); for(var i=0; i < divs.length; i++) { if (divs[i].className == className) RemoveOuterTags(divs[i]); } } function apiCheckRunnableScript() { try { if(Run) { return true; } } catch(e) { return false; } } function apiSetFastMode(fast) { var css=document.getElementById("css"); if(!css) return; if(fast) css.href="main_fast.css"; else css.href="main.css"; } //====================================== // Internal private functions //====================================== function MsgBox(str) { window.external.MsgBox(str); } function AskYesNo(str) { return window.external.AskYesNo(str); } function InputBox(msg, value, result) { result.$ = window.external.InputBox(msg, "FBE script message", value); return window.external.GetModalResult(); } //-------------------------------------- // Our own, less scary error handler function errorHandler(msg,url,lno) { MsgBox("Error at line "+lno+":\n"+msg+" "); return true; } function errCantLoad(xd,file) { MsgBox("\""+file+"\" loading error:\n\n"+xd.parseError.reason+" \nLine: "+xd.parseError.line+", char: "+xd.parseError.linepos+"\n"); } function FillImageList(list, bin_objects) { if(list.id=='href') { var cover=list.value; list.innerHTML=''; var newopt=document.createElement('option'); newopt.value=''; newopt.innerHTML=''; list.appendChild(newopt); for(var j=0; j0){ d.parentNode.all.genre.value=v; } } //-------------------------------------- function dClone(obj) { var qn=obj.cloneNode(true); var cn=qn.firstChild; while(cn) { var nn=cn.nextSibling; if(cn.nodeName=="DIV") cn.removeNode(true); cn=nn; } return qn; } //------------------- function Remove(obj) { var pic_id = ""; if(obj.base64data != null) // this is a binary object { if(obj.all.type.value.search("image") != -1) { var idx = -1; for(i = 0; i < ImagesInfo.length; ++i) { if(ImagesInfo[i].id == obj.all.id.value) { idx = i; break; } } if(idx != -1) ImagesInfo.splice(idx, 1); } var inpts = obj.getElementsByTagName("input"); if(inpts[0].id=="id") pic_id = inpts[0].value; else if(inpts[1].id=="id") pic_id = inpts[1].value; } // delete var pn=obj.parentNode; obj.removeNode(true); PutSpacers(pn); // update images if(pic_id!="") { pic_id="fbw-internal:#"+pic_id; var imgs=document.getElementsByTagName("IMG"); for(var i=0; i0 || dv.all.middle.value.length>0 || dv.all.last.value.length>0 || dv.all.nick.value.length==0) { added=MakeText(au,"first-name",dv.all.first.value,true,indent+1) || added; added=MakeText(au,"middle-name",dv.all.middle.value,false,indent+1) || added; added=MakeText(au,"last-name",dv.all.last.value,true,indent+1) || added; if(dv.all.id) added=MakeText(au,"id",dv.all.id.value,false,indent+1) || added; } added=MakeText(au,"nickname",dv.all.nick.value,false,indent+1) || added; added=MakeText(au,"home-page",dv.all.home.value,false,indent+1) || added; added=MakeText(au,"email",dv.all.email.value,false,indent+1) || added; if(added || force) { Indent(node,indent); node.appendChild(au); Indent(au,indent); } return added; } function MakeDate(node,d,v,indent) { var dt=node.ownerDocument.createNode(1,"date",fbNS); var added=false; if(v.length>0){ added=true; SetAttr(dt,"value",v); } if(d.length>0) added=true; dt.appendChild(node.ownerDocument.createTextNode(d)); Indent(node,indent); node.appendChild(dt); return added; } function MakeSeq2(xn,hn,indent) { var added=false; var newxn=xn.ownerDocument.createNode(1,"sequence",fbNS); var name=hn.all("name",0).value; var num=hn.all("number",0).value; SetAttr(newxn,"name",name); if(num.length > 0) SetAttr(newxn,"number",num); for(var cn=hn.firstChild;cn;cn=cn.nextSibling) if(cn.nodeName=="DIV") added=MakeSeq2(newxn,cn,indent+1) || added; if(added || name.length>0 || num.length>0) { Indent(xn,indent); xn.appendChild(newxn); if(newxn.hasChildNodes()) Indent(newxn,indent); added=true; } return added; } function MakeSeq(xn,hn,indent) { var added=false; for(var cn=hn.firstChild;cn;cn=cn.nextSibling) if(cn.nodeName=="DIV") added=MakeSeq2(xn,cn,indent) || added; return added; } function IsEmpty(ii) { if(!ii || !ii.hasChildNodes()) return true; for(var v=ii.firstChild;v;v=v.nextSibling) if(v.nodeType==1 && v.baseName!="empty-line") return false; return true; } function MakeTitleInfo(doc,desc,ann,indent) { var ti=doc.createNode(1,"title-info",fbNS); Indent(desc,indent); desc.appendChild(ti); // genres var list=document.all.tiGenre.getElementsByTagName("DIV"); for(var i=0; i0 && match!="100") SetAttr(ge,"match",match); } ge.appendChild(doc.createTextNode(list.item(i).all.genre.value)); Indent(ti,indent+1); ti.appendChild(ge); } // authors var added=false; list=document.all.tiAuthor.getElementsByTagName("DIV"); for(var i=0; i0) MakeAuthor(ti,"author",list.item(0),true,indent+1); MakeText(ti,"book-title",document.all.tiTitle.value,true,indent+1); // annotation, will be filled by body.xsl if(!IsEmpty(ann)){ Indent(ti,indent+1); ti.appendChild(ann); } MakeText(ti,"keywords",document.all.tiKwd.value,false,indent+1); MakeDate(ti,document.all.tiDate.value,document.all.tiDateVal.value,indent+1); // coverpage images list=document.all.tiCover.getElementsByTagName("DIV"); var cp=doc.createNode(1,"coverpage",fbNS); for(var i=0; i0) { var xn=doc.createNode(1,"image",fbNS); var an=doc.createNode(2,"l:href",xlNS); an.appendChild(doc.createTextNode(list.item(i).all.href.value)); xn.setAttributeNode(an); Indent(cp,indent+2); cp.appendChild(xn); } if(cp.hasChildNodes) { Indent(ti,indent+1); ti.appendChild(cp); } MakeText(ti,"lang",document.all.tiLang.value,false,indent+1); MakeText(ti,"src-lang",document.all.tiSrcLang.value,false,indent+1); // translator list=document.all.tiTrans.getElementsByTagName("DIV"); for(var i=0; i0 || dv.all.middle.value.length>0 || dv.all.last.value.length>0 || dv.all.nick.value.length==0) { exist=IsTextExist(dv.all.first.value) || exist; exist=IsTextExist(dv.all.middle.value) || exist; exist=IsTextExist(dv.all.last.value) || exist; } exist=IsTextExist(dv.all.nick.value) || exist; exist=IsTextExist(dv.all.home.value) || exist; exist=IsTextExist(dv.all.email.value) || exist; return exist; } function IsTextExist(val) { if (val.length==0) return false; return true; } function IsSeqExist2(xn,hn) { var exist=false; var newxn=xn.ownerDocument.createNode(1,"sequence",fbNS); var name=hn.all("name",0).value; var num=hn.all("number",0).value; SetAttr(newxn,"name",name); if (num.length > 0) SetAttr(newxn,"number",num); for (var cn=hn.firstChild;cn;cn=cn.nextSibling) { if (cn.nodeName=="DIV") exist=IsSeqExist2(newxn,cn) || exist; } if (exist || name.length>0 || num.length>0) exist=true; return exist; } function IsSeqExist(xn,hn) { var exist=false; for (var cn=hn.firstChild;cn;cn=cn.nextSibling) if (cn.nodeName=="DIV") exist=IsSeqExist2(xn,cn) || exist; return exist; } function IsSTBFieldTextExist(sti,desc,doc) { var exist=false; // authors var list=document.all.stiAuthor.getElementsByTagName("DIV"); for (var i=0;i0) //exist=false; // book title exist=IsTextExist(document.all.stiTitle.value) || exist; // genres list=document.all.stiGenre.getElementsByTagName("DIV"); for (var i=0;i0) exist=true || exist; if (match.length>0 && match!="100"){ exist=true || exist; } } // annotation, will be filled by body.xsl /*if (!IsEmpty(ann)) { exist=true; }*/ // keywords exist=IsTextExist(document.all.stiKwd.value) || exist; // date var dt=sti.ownerDocument.createNode(1,"date",fbNS); if (document.all.stiDateVal.value.length>0) exist=true; if (document.all.stiDate.value.length>0) exist=true; // coverpage images list=document.all.stiCover.getElementsByTagName("DIV"); var cp=doc.createNode(1,"coverpage",fbNS); for (var i=0;i0) exist=true; } if (cp.hasChildNodes) exist=true; // lang exist=IsTextExist(document.all.stiLang.value) || exist; exist=IsTextExist(document.all.stiSrcLang.value) || exist; // translator list=document.all.stiTrans.getElementsByTagName("DIV"); for (var i=0;i0 && match!="100") SetAttr(ge,"match",match); ge.appendChild(doc.createTextNode(list.item(i).all.genre.value)); Indent(sti,indent+1); sti.appendChild(ge); } // authors var added=false; list=document.all.stiAuthor.getElementsByTagName("DIV"); for (var i=0;i0) MakeAuthor(sti,"author",list.item(0),true,indent+1); MakeText(sti,"book-title",document.all.stiTitle.value,true,indent+1); MakeText(sti,"keywords",document.all.stiKwd.value,false,indent+1); MakeDate(sti,document.all.stiDate.value,document.all.stiDateVal.value,indent+1); // coverpage images list=document.all.stiCover.getElementsByTagName("DIV"); var cp=doc.createNode(1,"coverpage",fbNS); for (var i=0;i0) { var xn=doc.createNode(1,"image",fbNS); var an=doc.createNode(2,"l:href",xlNS); an.appendChild(doc.createTextNode(list.item(i).all.href.value)); xn.setAttributeNode(an); Indent(cp,indent+2); cp.appendChild(xn); } if (cp.hasChildNodes) { Indent(sti,indent+1); sti.appendChild(cp); } MakeText(sti,"lang",document.all.stiLang.value,false,indent+1); MakeText(sti,"src-lang",document.all.stiSrcLang.value,false,indent+1); // translator list=document.all.stiTrans.getElementsByTagName("DIV"); for (var i=0;i0) MakeAuthor(di,"author",list.item(0),true,indent+1); added=MakeText(di,"program-used",document.all.diProgs.value,false,indent+1) || added; added=MakeDate(di,document.all.diDate.value,document.all.diDateVal.value,indent+1) || added; // src-url list=document.all.diURL.getElementsByTagName("INPUT"); for(i=0; i0 || v.length>0) { var ci=doc.createNode(1,"custom-info",fbNS); SetAttr(ci,"info-type",t); ci.appendChild(doc.createTextNode(v)); Indent(desc,indent); desc.appendChild(ci); } } } function MakeStylesheets(doc,indent) { if (!document.getElementById("stylesheetId")) return; var s=document.getElementById("stylesheetId").value; if (s=="") return; var styles=doc.createNode(1,"stylesheet",fbNS); SetAttr(styles, "type", "text/css"); Indent(doc.documentElement,1); doc.documentElement.appendChild(styles); Indent(styles,1); styles.appendChild(doc.createTextNode(s)); } function GetDesc(doc,ann,hist) { MakeStylesheets(doc,1); var desc=doc.createNode(1,"description",fbNS); Indent(doc.documentElement,1); doc.documentElement.appendChild(desc); MakeTitleInfo(doc,desc,ann,2); MakeSourceTitleInfo(doc,desc,ann,2); MakeDocInfo(doc,desc,hist,2); MakePubInfo(doc,desc,2); MakeCustInfo(doc,desc,2); Indent(desc,1); } function GetBinaries(doc) { var bo=document.all.binobj.getElementsByTagName("DIV"); for(var i=0; i3){ nerr-=3; MsgBox(nerr+" more invalid images ignored"); } // update Cover lists FillLists(); } //// == BODY == /////////////////////////////////////////////////////////////////// function KillDivs(e) { var divs = e.getElementsByTagName("DIV"); while(divs.length > 0) divs[0].removeNode(false); } //----------------------------------------------- function GoTo(elem) { if(!elem) return; var b=elem.getBoundingClientRect(); if (b.bottom-b.top<=window.external.getViewHeight()) window.scrollBy(0,(b.top+b.bottom-window.external.getViewHeight())/2); else window.scrollBy(0,b.top); var r=document.selection.createRange(); if (!r || !("compareEndPoints" in r)) return; r.moveToElementText(elem); r.collapse(true); if(r.parentElement!==elem && r.move("character",1)==1) r.move("character",-1); r.select(); } //----------------------------------------------- function SkipOver(np,n1,n2,n3) { while (np) { if(!(np.tagName=="P" && !np.firstChild && !window.external.inflateBlock(np)) && // not an empty P (!n1 || (np.tagName!=n1 && np.className!=n1)) && // and not n1 (!n2 || (np.tagName!=n2 && np.className!=n2)) && // and not n2 (!n3 || (np.tagName!=n3 && np.className!=n3))) // and not n3 break; np=np.nextSibling; } return np; } //----------------------------------------------- function StyleCheck(cp,st) { if(!cp || cp.tagName != "P") return false; var pp=cp.parentElement; if(!pp || pp.tagName != "DIV") return false; switch (st) { case "": if(pp.className!="section" && pp.className!="title" && pp.className!="epigraph" && pp.className!="history" && pp.className!="cite" && pp.className!="annotation") return false; break; case "subtitle": if(pp.className!="section" && pp.className!="stanza" && pp.className!="cite" && pp.className != "annotation") return false; break; case "text-author": if(pp.className!="cite" && pp.className!="epigraph" && (cp.nodeName!="P" || cp.parentNode.className!="stanza" || (cp.previousSibling && cp.previousSibling.className=="title") || (!cp.previousSibling && !cp.parentNode.previousSibling) || (!cp.previousSibling && cp.parentNode.previousSibling && cp.parentNode.previousSibling.className!="stanza") || (cp.parentNode.nextSibling && cp.parentNode.nextSibling.className=="stanza"))) return false; if((cp.nextSibling && cp.nextSibling.className!="text-author")) return false; break; case "code": if((cp.className == "text-author" || cp.className == "subtitle" && pp.className == "section") || (pp.className == "stanza" && cp.tagName == "P") || (cp.className == "" && pp.className == "section" && cp.tagName == "P") || ((cp.className == "td" || cp.className == "th") && pp.className == "tr")) return true; else return false; break; } return true; } //----------------------------------------------- function SetStyle(cp,check,name) { if(!StyleCheck(cp,name)) return; if(check) return true; if(name.length==0) name="normal"; window.external.BeginUndoUnit(document,name+" style"); window.external.SetStyleEx(document, cp, name); //cp.className=name; if (name=="text-author" && cp && cp.parentNode && cp.parentNode.className=="stanza") { var stanza1=cp.parentNode; var node1=cp.removeNode(true); stanza1.parentNode.insertBefore(node1,stanza1.nextSibling); if (!stanza1.firstChild && stanza1.previousSibling) { var rng1=document.body.createTextRange(); rng1.moveToElementText(stanza1.previousSibling); rng1.collapse(false); rng1.select(); } if (!stanza1.firstChild) stanza1.removeNode(true); } /*if (name=="normal") { var stanza1=cp.previousSibling; if (stanza1.className=="stanza") { var node1=cp.removeNode(true); stanza1.appendChild(node1); } }*/ window.external.EndUndoUnit(document); } //----------------------------------------------- function StyleNormal(cp,check) { return SetStyle(cp,check,""); } //----------------------------------------------- function StyleTextAuthor(cp,check) { return SetStyle(cp,check,"text-author"); } //----------------------------------------------- function StyleSubtitle(cp,check) { return SetStyle(cp,check,"subtitle"); } //----------------------------------------------- function StyleCode(check, cp, range) { if(check && cp && range) { // That is due to MSHTML bug if(cp.tagName == "P") { html = new String(range.htmlText); if(html.indexOf("","g"); var re2_=">"; return s.replace(re0,re0_).replace(re1,re1_).replace(re2,re2_); } function AddTitle(cp, check) { if(!cp) return; if(cp.tagName == "P") cp = cp.parentElement; if(cp.tagName != "DIV") return; if(cp.className != "body" && cp.className != "section" && cp.className != "stanza" && cp.className != "poem") return; var np = cp.firstChild; if(np) { if(cp.className == "body" && np.tagName == "DIV" && np.className == "image") np = np.nextSibling; if(np.tagName == "DIV" && np.className == "title") return; } var sel = document.selection.createRange(); if (sel) if (sel.text) if(cp.innerText.length < sel.text.length) return; if(check) return true; window.external.BeginUndoUnit(document, "add title"); var div = document.createElement("DIV"); div.className = "title"; targ = np.tagName; //full = (sel.text == cp.innerText); var del = false; if(sel.text == "" || cp.className=="body") { var pp = document.createElement("P"); pp.innerText=""; window.external.inflateBlock(pp) = true; div.appendChild(pp); } else { if(sel.htmlText.indexOf("

")+"

"; del = true; } } // if(full) // { // var nps = np.nextSibling; // while(nps) // { // nps.removeNode(true); // nps = np.nextSibling; // } // switch(targ) // { // case "P": // np.innerText = ""; // break; // case "DIV": // while(np) // { // var nps = np.nextSibling; // while(nps) // { // nps.removeNode(true); // nps = np.nextSibling; // } // if(np.tagName == "P") // { // var nps = np.nextSibling; // while(nps) // { // nps.removeNode(true); // nps = np.nextSibling; // } // np.innerText = ""; // window.external.inflateBlock(np) = true; // break; // } // else // np = np.firstChild; // } // if(cp.className == "body") // { // cp = cp.firstChild.nextSibling; // while(np.parentElement && np.parentElement != cp) // { // np.parentElement.removeNode(false); // } // } // else if(cp.className == "section") // { // while(np.parentElement && np.parentElement != cp) // { // np.parentElement.removeNode(false); // } // } // break; // } // } if(del) { sel.text = ""; } InsBefore(cp, np, div); GoTo(div); window.external.EndUndoUnit(document); } //----------------------------------------------- function AddBody(check) { if(check) return true; window.external.BeginUndoUnit(document,"add body"); var newbody=document.createElement("DIV"); newbody.className="body"; newbody.innerHTML='

'; var body = document.getElementById("fbw_body"); if(!body) return false; body.appendChild(newbody); InflateIt(newbody); window.external.EndUndoUnit(document); GoTo(newbody); } //----------------------------------------------- function GetCP(cp) { if(!cp) return; if(cp.tagName=="P") cp=cp.parentElement; if(cp.tagName=="DIV" && cp.className=="title") cp=cp.parentElement; if(cp.tagName!="DIV") return; return cp; } //----------------------------------------------- function InsBefore(parent,ref,item) { if(ref) ref.insertAdjacentElement("beforeBegin",item); else parent.insertAdjacentElement("beforeEnd",item); } //----------------------------------------------- function InsBeforeHTML(parent,ref,ht) { if(ref) ref.insertAdjacentHTML("beforeBegin",ht); else parent.insertAdjacentHTML("beforeEnd", ht); } //----------------------------------------------- function CloneContainer(cp,check) { cp=GetCP(cp); if(!cp) return; switch(cp.className) { case "section": case "poem": case "stanza": case "cite": case "epigraph": break; default: return; } if(check) return true; window.external.BeginUndoUnit(document,"clone "+cp.className); var ncp=cp.cloneNode(false); switch (cp.className) { case "section": ncp.innerHTML='

'; break; case "poem": ncp.innerHTML='

'; break; case "stanza": case "cite": case "epigraph": ncp.innerHTML='

'; break; } InflateIt(ncp); cp.insertAdjacentElement("afterEnd",ncp); window.external.EndUndoUnit(document); GoTo(ncp); } //----------------------------------------------- var imgcode="
"; function InsImage(check, id) { var rng=document.selection.createRange(); if(!rng || !("compareEndPoints" in rng)) return; if(rng.compareEndPoints("StartToEnd",rng)!=0) { rng.collapse(true); if(rng.move("character",1)==1) rng.move("character",-1); } var pe=rng.parentElement(); while(pe && pe.tagName!="DIV") pe=pe.parentElement; if(!pe || pe.className!="section") return; if(check) return true; window.external.BeginUndoUnit(document,"insert image"); if(id=="") rng.pasteHTML(imgcode); else rng.pasteHTML("
"); window.external.EndUndoUnit(document); return rng.parentElement; } //----------------------------------------------- var inlineimgcode=""; function InsInlineImage(check, id) { var rng=document.selection.createRange(); if(!rng || !("compareEndPoints" in rng)) return; if(rng.compareEndPoints("StartToEnd",rng)!=0) { rng.collapse(true); if(rng.move("character",1)==1) rng.move("character",-1); } var pe=rng.parentElement(); while(pe && pe.tagName!="DIV") pe=pe.parentElement; if(!pe || (pe.className.search(/section|annotation|history|title|epigraph|cite|stanza/)<0)) return; if(check) return true; window.external.BeginUndoUnit(document,"insert inline image"); if(id=="") rng.pasteHTML(inlineimgcode); else rng.pasteHTML(""); window.external.EndUndoUnit(document); return rng.parentElement; } //----------------------------------------------- function AddImage(cp, check) { cp=GetCP(cp); if(!cp) return; if(cp.className!="body" && cp.className!="section") return; var np=cp.firstChild; if (cp.className=="body") np=SkipOver(np,null,null,null); else np=SkipOver(np,"title","epigraph",null); if(np && np.tagName=="DIV" && np.className=="image") return; if(check) return true; window.external.BeginUndoUnit(document,"add image"); InsBeforeHTML(cp, np, imgcode); window.external.EndUndoUnit(document); } //----------------------------------------------- function AddEpigraph(cp,check) { cp = GetCP(cp); if(!cp) return; if(cp.className != "body" && cp.className != "section" && cp.className != "poem") return; var pp=cp.firstChild; if(cp.className == "body") // different order pp = SkipOver(pp, "title", "image", "epigraph"); else pp = SkipOver(pp, "title", "epigraph", null); if(check) return true; if (document.selection.type && document.selection.type=="Control") { MsgBox("Вы используете не тот тип выделения, с которым работает вставка эпиграфа. Выделяйте текст для будущего эпиграфа не кликом по картинке, а движением мыши слева направо или справа налево. Либо задайте выделение, используя клавиатуру."); return; } var rng = document.selection.createRange(); var txt = ""; var pps; if(rng && rng.text != "") { var dpps = document.createElement("DIV"); dpps.innerHTML = rng.htmlText; pps = dpps.getElementsByTagName("P"); if(pps.length == 0) { dpps.innerHTML = "

"+rng.htmlText+"

"; pps = dpps.getElementsByTagName("P"); if(pps.length == 0) { txt = rng.text; } } } window.external.BeginUndoUnit(document,"add epigraph"); var ep=document.createElement("DIV"); ep.className="epigraph"; if(txt != "") { var pwt = document.createElement("P"); pwt.innerHTML = txt; ep.appendChild(pwt); } else if(pps && pps.length > 0) { var upTag = ""; for(i = 0; i < pps.length; ++i) { var pwt = document.createElement("P"); if(i == pps.length - 2 && pps[i].children && pps[i].children.length && pps[i].children.length == 1) { upTag = pps[i].children[0].tagName; } if(i == pps.length - 1) { var pptext = pps[i].innerText; var pptags = new Array(); var ppall = pps[i].all; var j = 0; for(k = 0; k < ppall.length; ++k) { if(ppall[k].innerText && ppall[k].innerText == pptext) pptags[j++] = ppall[k].tagName; } if (pptags.length > 0 && pps.length > 1) { for(pptag in pptags) { if(pptag != upTag) { pwt.className = "text-author"; break; } } } } pwt.innerHTML = pps[i].innerHTML; ep.appendChild(pwt); } } else ep.appendChild(document.createElement("P")); InsBefore(cp, pp, ep); InflateIt(ep); rng.pasteHTML(""); if(pp && (!pp.innerText || pp.innerText == "" || pp.innerText == " ") && pp.className!="image") pp.removeNode(true); window.external.EndUndoUnit(document); GoTo(ep); } //----------------------------------------------- function AddAnnotation(cp, check) { cp=GetCP(cp); if(!cp) return; if(cp.className!="section") return; var pp=SkipOver(cp.firstChild,"title","epigraph","image"); if(pp && pp.tagName=="DIV" && pp.className=="annotation") return; if(check) return true; window.external.BeginUndoUnit(document,"add annotation"); var ep=document.createElement("DIV"); ep.className="annotation"; ep.appendChild(document.createElement("P")); InsBefore(cp,pp,ep); InflateIt(ep); window.external.EndUndoUnit(document); GoTo(ep); } //----------------------------------------------- function AddTA(cp,check) { cp=GetCP(cp); while(cp) { if(cp.tagName=="DIV" && (cp.className=="poem" || cp.className=="epigraph" || cp.className=="cite")) break; cp=cp.parentElement; } if(!cp) return; var lc=cp.lastChild; if(lc && lc.tagName=="P" && lc.className=="text-author") return; if(check) return true; window.external.BeginUndoUnit(document,"add text author"); var np=document.createElement("P"); np.className="text-author"; window.external.inflateBlock(np)=true; cp.appendChild(np); window.external.EndUndoUnit(document); GoTo(np); } //----------------------------------------------- function IsCtSection(s) { for(s=s.firstChild; s; s=s.nextSibling) if(s.nodeName=="P") return false; return true; } //----------------------------------------------- function FindSE(cp,name) { for(cp=cp.firstChild;cp;cp=cp.nextSibling) { if(cp.nodeName !="DIV") return; if(cp.className==name) return cp; if(cp.className=="section") return; } } //----------------------------------------------- function MergeContainers(cp,check) { cp=GetCP(cp); if(!cp) return; if(cp.className!="section" && cp.className!="stanza" && cp.className!="cite") return; var nx=cp.nextSibling; if(!nx || nx.tagName!="DIV" || nx.className!=cp.className) return; if(check) return true; window.external.BeginUndoUnit(document,"merge "+cp.className+"s"); if(cp.className=="cite") { for (kj=cp.firstChild; kj; kj=kj.nextSibling) if (kj.nodeName=="P" && kj.className=="text-author") kj.removeAttribute("className"); } if(!IsCtSection(cp)) { // delete all nested sections var pi, ii=nx.firstChild; while(ii) { if(ii.tagName=="DIV") { if(ii.className=="title") { var pp=ii.getElementsByTagName("P"); for(var l=0; l