/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
function CDocumentReaderMode() {
this.DefaultFontSize = 12;
this.CorrectDefaultFontSize = function (size) {
if (size < 6) {
return;
}
this.DefaultFontSize = size;
};
this.CorrectFontSize = function (size) {
var dRes = size / this.DefaultFontSize;
dRes = (1 + dRes) / 2;
dRes = (100 * dRes) >> 0;
dRes /= 100;
return "" + dRes + "em";
};
}
window.USER_AGENT_MACOS = AscBrowser.isMacOs;
window.USER_AGENT_SAFARI_MACOS = AscBrowser.isSafariMacOs;
window.USER_AGENT_IE = AscBrowser.isIE || AscBrowser.isOpera;
window.USER_AGENT_WEBKIT = AscBrowser.isWebkit;
window.GlobalPasteFlagCounter = 0;
window.GlobalPasteFlag = false;
window.PasteEndTimerId = -1;
var COPY_ELEMENT_ID = "SelectId";
var PASTE_ELEMENT_ID = "wrd_pastebin";
var ELEMENT_DISPAY_STYLE = "none";
var copyPasteUseBinery = true;
if (window.USER_AGENT_SAFARI_MACOS) {
var PASTE_ELEMENT_ID = "SelectId";
var ELEMENT_DISPAY_STYLE = "block";
}
var PASTE_EMPTY_COUNTER_MAX = 10;
var PASTE_EMPTY_COUNTER = 0;
var PASTE_EMPTY_USE = AscBrowser.isMozilla;
var g_bIsDocumentCopyPaste = true;
var isOnlyLocalBufferSafariWord = false;
function Editor_Copy_GetElem(api) {
var ElemToSelect = document.getElementById(COPY_ELEMENT_ID);
if (!ElemToSelect) {
ElemToSelect = document.createElement("div");
ElemToSelect.id = COPY_ELEMENT_ID;
ElemToSelect.className = "sdk-element";
ElemToSelect.style.position = "absolute";
ElemToSelect.style.left = "0px";
ElemToSelect.style.top = "-100px";
ElemToSelect.style.width = "10000px";
ElemToSelect.style.height = "100px";
ElemToSelect.style.overflow = "hidden";
ElemToSelect.style.zIndex = -1000;
ElemToSelect.style.MozUserSelect = "text";
ElemToSelect.style["-khtml-user-select"] = "text";
ElemToSelect.style["-o-user-select"] = "text";
ElemToSelect.style["user-select"] = "text";
ElemToSelect.style["-webkit-user-select"] = "text";
ElemToSelect.setAttribute("contentEditable", true);
if (!api || !api.GetCopyPasteDivId) {
document.body.appendChild(ElemToSelect);
} else {
var _div_id = api.GetCopyPasteDivId();
if ("" == _div_id) {
document.body.appendChild(ElemToSelect);
} else {
var _div = document.getElementById(_div_id);
_div.appendChild(ElemToSelect);
}
}
}
return ElemToSelect;
}
function Editor_Copy_Button(api, bCut) {
if (AscBrowser.isIE) {
var ElemToSelect = Editor_Copy_GetElem(api);
ElemToSelect.style.display = "block";
while (ElemToSelect.hasChildNodes()) {
ElemToSelect.removeChild(ElemToSelect.lastChild);
}
document.body.style.MozUserSelect = "text";
delete document.body.style["-khtml-user-select"];
delete document.body.style["-o-user-select"];
delete document.body.style["user-select"];
document.body.style["-webkit-user-select"] = "text";
if (window.USER_AGENT_IE) {
document.onselectstart = function () {};
}
if (null != api.WordControl.m_oLogicDocument) {
var oCopyProcessor = new CopyProcessor(api, ElemToSelect);
oCopyProcessor.Start();
} else {
ElemToSelect.innerHTML = api.WordControl.m_oDrawingDocument.m_oDocumentRenderer.Copy();
}
var selection = window.getSelection();
var rangeToSelect = document.createRange();
rangeToSelect.selectNodeContents(ElemToSelect);
if (ElemToSelect.childElementCount !== 0) {
selection.removeAllRanges();
}
selection.addRange(rangeToSelect);
document.execCommand("copy");
ElemToSelect.style.display = "none";
document.body.style.MozUserSelect = "none";
document.body.style["-khtml-user-select"] = "none";
document.body.style["-o-user-select"] = "none";
document.body.style["user-select"] = "none";
document.body.style["-webkit-user-select"] = "none";
if (window.USER_AGENT_IE) {
document.onselectstart = function () {
return false;
};
}
if (true == bCut) {
api.WordControl.m_oLogicDocument.Remove(1, true, true);
api.WordControl.m_oLogicDocument.Document_UpdateSelectionState();
}
return true;
} else {
var ElemToSelect = Editor_Copy_GetElem(api);
while (ElemToSelect.hasChildNodes()) {
ElemToSelect.removeChild(ElemToSelect.lastChild);
}
if (null != api.WordControl.m_oLogicDocument) {
var oCopyProcessor = new CopyProcessor(api, ElemToSelect);
oCopyProcessor.Start();
} else {
ElemToSelect.innerHTML = api.WordControl.m_oDrawingDocument.m_oDocumentRenderer.Copy();
}
if (true == bCut) {
api.WordControl.m_oLogicDocument.Remove(1, true, true);
api.WordControl.m_oLogicDocument.Document_UpdateSelectionState();
}
return true;
}
return false;
}
function Editor_Copy(api, bCut) {
var ElemToSelect = Editor_Copy_GetElem(api);
ElemToSelect.style.display = "block";
while (ElemToSelect.hasChildNodes()) {
ElemToSelect.removeChild(ElemToSelect.lastChild);
}
document.body.style.MozUserSelect = "text";
delete document.body.style["-khtml-user-select"];
delete document.body.style["-o-user-select"];
delete document.body.style["user-select"];
document.body.style["-webkit-user-select"] = "text";
if (window.USER_AGENT_IE) {
document.onselectstart = function () {};
}
if (null != api.WordControl.m_oLogicDocument) {
var oCopyProcessor = new CopyProcessor(api, ElemToSelect);
oCopyProcessor.Start();
} else {
ElemToSelect.innerHTML = api.WordControl.m_oDrawingDocument.m_oDocumentRenderer.Copy();
}
if (window.getSelection) {
var selection = window.getSelection();
var rangeToSelect = document.createRange();
var is_gecko = AscBrowser.isGecko;
if (is_gecko) {
ElemToSelect.appendChild(document.createTextNode("\xa0"));
ElemToSelect.insertBefore(document.createTextNode("\xa0"), ElemToSelect.firstChild);
rangeToSelect.setStartAfter(ElemToSelect.firstChild);
rangeToSelect.setEndBefore(ElemToSelect.lastChild);
} else {
if (window.USER_AGENT_WEBKIT && (true !== window.USER_AGENT_SAFARI_MACOS)) {
var aChildNodes = ElemToSelect.childNodes;
if (aChildNodes.length == 1) {
var elem = aChildNodes[0];
var wrap = document.createElement("b");
wrap.setAttribute("style", "font-weight:normal");
elem = ElemToSelect.removeChild(elem);
wrap.appendChild(elem);
ElemToSelect.appendChild(wrap);
}
}
rangeToSelect.selectNodeContents(ElemToSelect);
}
selection.removeAllRanges();
selection.addRange(rangeToSelect);
} else {
if (document.body.createTextRange) {
var rangeToSelect = document.body.createTextRange();
rangeToSelect.moveToElementText(ElemToSelect);
rangeToSelect.select();
}
}
var time_interval = 200;
if (window.USER_AGENT_SAFARI_MACOS) {
time_interval = 200;
}
window.setTimeout(function () {
ElemToSelect.style.display = ELEMENT_DISPAY_STYLE;
document.body.style.MozUserSelect = "none";
document.body.style["-khtml-user-select"] = "none";
document.body.style["-o-user-select"] = "none";
document.body.style["user-select"] = "none";
document.body.style["-webkit-user-select"] = "none";
if (window.USER_AGENT_IE) {
document.onselectstart = function () {
return false;
};
}
if (true == bCut) {
api.WordControl.m_oLogicDocument.Remove(-1, true, true);
api.WordControl.m_oLogicDocument.Document_UpdateSelectionState();
}
},
time_interval);
}
function CopyProcessor(api, ElemToSelect) {
this.api = api;
this.oDocument = api.WordControl.m_oLogicDocument;
this.oBinaryFileWriter = new BinaryFileWriter(this.oDocument);
this.fontsArray = api.FontLoader.fontInfos;
this.ElemToSelect = ElemToSelect;
this.Ul = document.createElement("ul");
this.Ol = document.createElement("ol");
this.oTagPr;
this.orPr;
this.aInnerHtml;
this.Para;
this.bOccurEndPar;
this.oCurHyperlink = null;
this.oCurHyperlinkElem = null;
this.oPresentationWriter = new CBinaryFileWriter();
this.oPresentationWriter.Start_UseFullUrl(documentOrigin + editor.DocumentUrl);
this.oPresentationWriter.Start_UseDocumentOrigin(documentOrigin);
}
CopyProcessor.prototype = {
getSrc: function (src) {
var start = src.substring(0, 6);
if (0 != src.indexOf("http:") && 0 != src.indexOf("data:") && 0 != src.indexOf("https:") && 0 != src.indexOf("ftp:") && 0 != src.indexOf("file:")) {
return documentOrigin + src;
} else {
return src;
}
},
RGBToCSS: function (rgb) {
var sResult = "#";
var sR = rgb.r.toString(16);
if (sR.length == 1) {
sR = "0" + sR;
}
var sG = rgb.g.toString(16);
if (sG.length == 1) {
sG = "0" + sG;
}
var sB = rgb.b.toString(16);
if (sB.length == 1) {
sB = "0" + sB;
}
return "#" + sR + sG + sB;
},
CommitList: function (oDomTarget) {
if (this.Ul.childNodes.length > 0) {
this.Ul.style.paddingLeft = "40px";
oDomTarget.appendChild(this.Ul);
this.Ul = document.createElement("ul");
}
if (this.Ol.childNodes.length > 0) {
this.Ol.style.paddingLeft = "40px";
oDomTarget.appendChild(this.Ol);
this.Ol = document.createElement("ol");
}
},
Commit_pPr: function (Item) {
var apPr = new Array();
var Def_pPr = this.oDocument.Styles.Default.ParaPr;
var Item_pPr = Item.CompiledPr.Pr.ParaPr;
if (Item_pPr) {
if (Def_pPr.Ind.Left != Item_pPr.Ind.Left) {
apPr.push("margin-left:" + (Item_pPr.Ind.Left * g_dKoef_mm_to_pt) + "pt");
}
if (Def_pPr.Ind.Right != Item_pPr.Ind.Right) {
apPr.push("margin-right:" + (Item_pPr.Ind.Right * g_dKoef_mm_to_pt) + "pt");
}
if (Def_pPr.Ind.FirstLine != Item_pPr.Ind.FirstLine) {
apPr.push("text-indent:" + (Item_pPr.Ind.FirstLine * g_dKoef_mm_to_pt) + "pt");
}
if (Def_pPr.Jc != Item_pPr.Jc) {
switch (Item_pPr.Jc) {
case align_Left:
apPr.push("text-align:left");
break;
case align_Center:
apPr.push("text-align:center");
break;
case align_Right:
apPr.push("text-align:right");
break;
case align_Justify:
apPr.push("text-align:justify");
break;
}
}
if (Def_pPr.KeepLines != Item_pPr.KeepLines || Def_pPr.WidowControl != Item_pPr.WidowControl) {
if (Def_pPr.KeepLines != Item_pPr.KeepLines && Def_pPr.WidowControl != Item_pPr.WidowControl) {
apPr.push("mso-pagination:none lines-together");
} else {
if (Def_pPr.KeepLines != Item_pPr.KeepLines) {
apPr.push("mso-pagination:widow-orphan lines-together");
} else {
if (Def_pPr.WidowControl != Item_pPr.WidowControl) {
apPr.push("mso-pagination:none");
}
}
}
}
if (Def_pPr.KeepNext != Item_pPr.KeepNext) {
apPr.push("page-break-after:avoid");
}
if (Def_pPr.PageBreakBefore != Item_pPr.PageBreakBefore) {
apPr.push("page-break-before:always");
}
if (Def_pPr.Spacing.Line != Item_pPr.Spacing.Line) {
if (linerule_AtLeast == Item_pPr.Spacing.LineRule) {
apPr.push("line-height:" + (Item_pPr.Spacing.Line * g_dKoef_mm_to_pt) + "pt");
} else {
if (linerule_Auto == Item_pPr.Spacing.LineRule) {
if (1 == Item_pPr.Spacing.Line) {
apPr.push("line-height:normal");
} else {
apPr.push("line-height:" + parseInt(Item_pPr.Spacing.Line * 100) + "%");
}
}
}
}
if (Def_pPr.Spacing.LineRule != Item_pPr.Spacing.LineRule) {
if (linerule_Exact == Item_pPr.Spacing.LineRule) {
apPr.push("mso-line-height-rule:exactly");
}
}
apPr.push("margin-top:" + (Item_pPr.Spacing.Before * g_dKoef_mm_to_pt) + "pt");
apPr.push("margin-bottom:" + (Item_pPr.Spacing.After * g_dKoef_mm_to_pt) + "pt");
if (Def_pPr.Shd.Value != Item_pPr.Shd.Value) {
apPr.push("background-color:" + this.RGBToCSS(Item_pPr.Shd.Color));
}
if (Item_pPr.Tabs.Get_Count() > 0) {
var sRes = "";
for (var i = 0, length = Item_pPr.Tabs.Get_Count(); i < length; i++) {
if (0 != i) {
sRes += " ";
}
sRes += Item_pPr.Tabs.Get(i).Pos / 10 + "cm";
}
apPr.push("tab-stops:" + sRes);
}
if (null != Item_pPr.Brd) {
apPr.push("border:none");
var borderStyle = this._BordersToStyle(Item_pPr.Brd, false, true, "mso-", "-alt");
if (null != borderStyle) {
var nborderStyleLength = borderStyle.length;
if (nborderStyleLength > 0) {
borderStyle = borderStyle.substring(0, nborderStyleLength - 1);
}
apPr.push(borderStyle);
}
}
}
if (apPr.length > 0) {
this.Para.setAttribute("style", apPr.join(";"));
}
},
InitRun: function (bInitPr) {
if (bInitPr) {
this.oTagPr = new Object();
this.orPr = new Object();
}
this.aInnerHtml = new Array();
},
CommitSpan: function (bInitPr) {
if (this.aInnerHtml.length > 0) {
var Run = document.createElement("span");
var sStyle = "";
for (prop in this.orPr) {
sStyle += prop + ":" + this.orPr[prop] + ";";
}
if ("" != sStyle) {
Run.setAttribute("style", sStyle);
}
if (this.aInnerHtml.length > 0) {
var sText = this.aInnerHtml.join("");
sText = sText.replace(/\s+/g, function (str) {
var sResult = "";
for (var i = 0, length = str.length; i < length - 1; i++) {
sResult += " ";
}
sResult += " ";
return sResult;
});
var sStart = "";
var aEnd = new Array();
for (prop in this.oTagPr) {
sStart += "<" + prop + ">";
aEnd.push("" + prop + ">");
}
if ("" != sStart && aEnd.length > 0) {
aEnd.reverse();
sText = sStart + sText + aEnd.join("");
}
Run.innerHTML = sText;
}
if (null != this.oCurHyperlinkElem) {
this.oCurHyperlinkElem.appendChild(Run);
} else {
this.Para.appendChild(Run);
}
}
this.InitRun(bInitPr);
},
parse_para_TextPr: function (Value) {
this.CommitSpan(false);
for (var prop in Value) {
this.SetProp(prop, Value[prop]);
}
},
SetProp: function (prop, val) {
var oPropMap = {
RFonts: function (oThis, val) {
var sFontName = null;
if (null != val.Ascii) {
sFontName = val.Ascii.Name;
} else {
if (null != val.HAnsi) {
sFontName = val.HAnsi.Name;
} else {
if (null != val.EastAsia) {
sFontName = val.EastAsia.Name;
} else {
if (null != val.CS) {
sFontName = val.CS.Name;
}
}
}
}
if (null != sFontName) {
oThis.orPr["font-family"] = "'" + sFontName + "'";
}
},
FontSize: function (oThis, val) {
if (!oThis.api.DocumentReaderMode) {
oThis.orPr["font-size"] = val + "pt";
} else {
oThis.orPr["font-size"] = oThis.api.DocumentReaderMode.CorrectFontSize(val);
}
},
Bold: function (oThis, val) {
if (val) {
oThis.oTagPr["b"] = 1;
} else {
delete oThis.oTagPr["b"];
}
},
Italic: function (oThis, val) {
if (val) {
oThis.oTagPr["i"] = 1;
} else {
delete oThis.oTagPr["i"];
}
},
Underline: function (oThis, val) {
if (val) {
oThis.oTagPr["u"] = 1;
} else {
delete oThis.oTagPr["u"];
}
},
Strikeout: function (oThis, val) {
if (val) {
oThis.oTagPr["s"] = 1;
} else {
delete oThis.oTagPr["s"];
}
},
HighLight: function (oThis, val) {
if (val != highlight_None) {
oThis.orPr["background-color"] = oThis.RGBToCSS(val);
} else {
delete oThis.orPr["background-color"];
}
},
Color: function (oThis, val) {
var color = oThis.RGBToCSS(val);
oThis.orPr["color"] = color;
oThis.orPr["mso-style-textfill-fill-color"] = color;
},
VertAlign: function (oThis, val) {
if (vertalign_SuperScript == val) {
oThis.orPr["vertical-align"] = "super";
} else {
if (vertalign_SubScript == val) {
oThis.orPr["vertical-align"] = "sub";
} else {
delete oThis.orPr["vertical-align"];
}
}
}
};
if ("undefined" != typeof(oPropMap[prop])) {
oPropMap[prop](this, val);
}
},
ParseItem: function (ParaItem, Par, nParIndex, aDocumentContent, nDocumentContentIndex) {
switch (ParaItem.Type) {
case para_Text:
var sValue = ParaItem.Value;
if (sValue) {
sValue = CopyPasteCorrectString(sValue);
this.aInnerHtml.push(sValue);
}
break;
case para_Space:
this.aInnerHtml.push(" ");
break;
case para_Tab:
this.aInnerHtml.push(" ");
break;
case para_NewLine:
if (break_Page == ParaItem.BreakType) {
this.aInnerHtml.push('
');
} else {
this.aInnerHtml.push('
');
}
break;
case para_End:
this.bOccurEndPar = true;
break;
case para_TextPr:
if (null != Par) {
var oCalculateTextPr = Par.Internal_CalculateTextPr(nParIndex);
this.parse_para_TextPr(oCalculateTextPr);
}
break;
case para_Drawing:
var oGraphicObj = ParaItem.GraphicObj;
var sSrc = oGraphicObj.getBase64Img();
if (sSrc.length > 0) {
sSrc = this.getSrc(sSrc);
this.aInnerHtml.push('');
break;
}
break;
case para_FlowObjectAnchor:
var oFlowObj = ParaItem.FlowObject;
if (flowobject_Image == oFlowObj.Get_Type()) {
var sSrc = oFlowObj.Img;
if (sSrc.length > 0) {
sSrc = this.getSrc(sSrc);
var sStyle = "";
var nLeft = oFlowObj.X;
var nRight = nLeft + oFlowObj.W;
if (Math.abs(nLeft - X_Left_Margin) < Math.abs(Page_Width - nRight - X_Right_Margin)) {
sStyle = "float:left;";
} else {
sStyle = "float:right;";
}
if (!this.api.DocumentReaderMode) {
if (null != oFlowObj.Paddings) {
sStyle += "margin:" + (oFlowObj.Paddings.Top * g_dKoef_mm_to_pt) + "pt " + (oFlowObj.Paddings.Right * g_dKoef_mm_to_pt) + "pt " + +(oFlowObj.Paddings.Bottom * g_dKoef_mm_to_pt) + "pt " + +(oFlowObj.Paddings.Left * g_dKoef_mm_to_pt) + "pt;";
}
} else {
sStyle += "margin:0pt 10pt 0pt 10pt;";
}
if (this.api.DocumentReaderMode) {
sStyle += "max-width:100%;";
}
this.aInnerHtml.push('');
break;
}
}
break;
case para_HyperlinkStart:
if (null == this.oCurHyperlinkElem) {
this.CommitSpan(false);
this.oCurHyperlink = ParaItem;
this.oCurHyperlinkElem = document.createElement("a");
if (null != this.oCurHyperlink.Value) {
this.oCurHyperlinkElem.href = this.oCurHyperlink.Value;
}
if (null != this.oCurHyperlink.ToolTip) {
this.oCurHyperlinkElem.setAttribute("title", this.oCurHyperlink.ToolTip);
}
}
break;
case para_HyperlinkEnd:
this.CommitSpan(false);
if (null != this.oCurHyperlinkElem) {
this.Para.appendChild(this.oCurHyperlinkElem);
} else {
var oHyperlink = null;
for (var i = nParIndex - 1; i >= 0; --i) {
var item = Par.Content[i];
if (para_HyperlinkStart == item.Type) {
oHyperlink = item;
break;
}
}
if (null == oHyperlink) {
for (var i = nDocumentContentIndex - 1; i >= 0; --i) {
var item = aDocumentContent[i];
if (type_Paragraph == item.Type) {
for (var j = item.Content.length - 1; j >= 0; --j) {
var Paritem = item.Content[ji];
if (para_HyperlinkStart == Paritem.Type) {
oHyperlink = Paritem;
break;
}
}
}
}
}
if (null != oHyperlink) {
bReset = false;
this.CommitSpan(false);
this.oCurHyperlink = oHyperlink;
this.oCurHyperlinkElem = document.createElement("a");
if (null != this.oCurHyperlink.Value) {
this.oCurHyperlinkElem.href = this.oCurHyperlink.Value;
}
if (null != this.oCurHyperlink.ToolTip) {
this.oCurHyperlinkElem.setAttribute("title", this.oCurHyperlink.ToolTip);
}
for (var i = 0; i < this.Para.childNodes.length; i++) {
var child = this.Para.childNodes[i];
child = this.Para.removeChild(child);
this.oCurHyperlinkElem.appendChild(child);
}
this.Para.appendChild(this.oCurHyperlinkElem);
}
}
this.oCurHyperlink = null;
this.oCurHyperlinkElem = null;
break;
}
},
CopyParagraph: function (oDomTarget, Item, bLast, bUseSelection, aDocumentContent, nDocumentContentIndex) {
var oDocument = this.oDocument;
this.Para = null;
var styleId = Item.Style_Get();
if (styleId) {
var styleName = oDocument.Styles.Get_Name(styleId).toLowerCase();
if (0 == styleName.indexOf("heading")) {
var nLevel = parseInt(styleName.substring("heading".length));
if (1 <= nLevel && nLevel <= 6) {
this.Para = document.createElement("h" + nLevel);
}
}
}
if (null == this.Para) {
this.Para = document.createElement("p");
}
this.bOccurEndPar = false;
var oNumPr;
var bIsNullNumPr = false;
if (g_bIsDocumentCopyPaste) {
oNumPr = Item.Numbering_Get();
bIsNullNumPr = (null == oNumPr || 0 == oNumPr.NumId);
} else {
oNumPr = Item.PresentationPr.Bullet;
bIsNullNumPr = (0 == oNumPr.m_nType);
}
if (bIsNullNumPr) {
this.CommitList(oDomTarget);
} else {
var bBullet = false;
var sListStyle = "";
if (g_bIsDocumentCopyPaste) {
var aNum = this.oDocument.Numbering.Get_AbstractNum(oNumPr.NumId);
if (null != aNum) {
var LvlPr = aNum.Lvl[oNumPr.Lvl];
if (null != LvlPr) {
switch (LvlPr.Format) {
case numbering_numfmt_Decimal:
sListStyle = "decimal";
break;
case numbering_numfmt_LowerRoman:
sListStyle = "lower-roman";
break;
case numbering_numfmt_UpperRoman:
sListStyle = "upper-roman";
break;
case numbering_numfmt_LowerLetter:
sListStyle = "lower-alpha";
break;
case numbering_numfmt_UpperLetter:
sListStyle = "upper-alpha";
break;
default:
sListStyle = "disc";
bBullet = true;
break;
}
}
}
} else {
var _presentation_bullet = Item.PresentationPr.Bullet;
switch (_presentation_bullet.m_nType) {
case numbering_presentationnumfrmt_ArabicPeriod:
case numbering_presentationnumfrmt_ArabicParenR:
sListStyle = "decimal";
break;
case numbering_presentationnumfrmt_RomanLcPeriod:
sListStyle = "lower-roman";
break;
case numbering_presentationnumfrmt_RomanUcPeriod:
sListStyle = "upper-roman";
break;
case numbering_presentationnumfrmt_AlphaLcParenR:
case numbering_presentationnumfrmt_AlphaLcPeriod:
sListStyle = "lower-alpha";
break;
case numbering_presentationnumfrmt_AlphaUcParenR:
case numbering_presentationnumfrmt_AlphaUcPeriod:
sListStyle = "upper-alpha";
break;
default:
sListStyle = "disc";
bBullet = true;
break;
}
}
var Li = document.createElement("li");
Li.setAttribute("style", "list-style-type: " + sListStyle);
Li.appendChild(this.Para);
if (bBullet) {
this.Ul.appendChild(Li);
} else {
this.Ol.appendChild(Li);
}
}
this.Commit_pPr(Item);
this.InitRun(true);
var ParaStart = 0;
var ParaEnd = Item.Content.length - 1;
if (true == bUseSelection) {
ParaStart = Item.Selection.StartPos;
ParaEnd = Item.Selection.EndPos;
if (ParaStart > ParaEnd) {
var Temp2 = ParaEnd;
ParaEnd = ParaStart;
ParaStart = Temp2;
}
}
var oCalculateTextPr = Item.Internal_CalculateTextPr(ParaStart);
this.parse_para_TextPr(oCalculateTextPr);
if (null != this.oCurHyperlink) {
this.oCurHyperlinkElem = document.createElement("a");
if (null != this.oCurHyperlink.Value) {
this.oCurHyperlinkElem.href = this.oCurHyperlink.Value;
}
if (null != this.oCurHyperlink.ToolTip) {
this.oCurHyperlinkElem.setAttribute("title", this.oCurHyperlink.ToolTip);
}
}
if (ParaStart > 0) {
while (Item.Content[ParaStart - 1].Type === para_TextPr || Item.Content[ParaStart - 1].Type === para_HyperlinkStart) {
ParaStart--;
if (0 == ParaStart) {
break;
}
}
}
for (var Index2 = ParaStart; Index2 < ParaEnd; Index2++) {
var ParaItem = Item.Content[Index2];
this.ParseItem(ParaItem, Item, Index2, aDocumentContent, nDocumentContentIndex);
}
this.CommitSpan(true);
if (null != this.oCurHyperlinkElem) {
this.Para.appendChild(this.oCurHyperlinkElem);
}
this.oCurHyperlink = null;
this.oCurHyperlinkElem = null;
if (bLast && false == this.bOccurEndPar) {
if (false == bIsNullNumPr) {
var li = this.Para.parentNode;
var ul = li.parentNode;
ul.removeChild(li);
this.CommitList(oDomTarget);
}
for (var i = 0; i < this.Para.childNodes.length; i++) {
oDomTarget.appendChild(this.Para.childNodes[i].cloneNode(true));
}
} else {
if (this.Para.childNodes.length == 0) {
this.Para.appendChild(document.createTextNode("\xa0"));
}
if (bIsNullNumPr) {
oDomTarget.appendChild(this.Para);
}
}
},
_BorderToStyle: function (border, name) {
var res = "";
if (border_None == border.Value) {
res += name + ":none;";
} else {
bBorder = true;
var size = 0.5;
var color = {
r: 0,
g: 0,
b: 0
};
if (null != border.Size) {
size = border.Size * g_dKoef_mm_to_pt;
}
if (null != border.Color) {
color = border.Color;
}
res += name + ":" + size + "pt solid " + this.RGBToCSS(color) + ";";
}
return res;
},
_MarginToStyle: function (margins, styleName) {
var res = "";
var nMarginLeft = 1.9;
var nMarginTop = 0;
var nMarginRight = 1.9;
var nMarginBottom = 0;
if (null != margins.Left && tblwidth_Mm == margins.Left.Type && null != margins.Left.W) {
nMarginLeft = margins.Left.W;
}
if (null != margins.Top && tblwidth_Mm == margins.Top.Type && null != margins.Top.W) {
nMarginTop = margins.Top.W;
}
if (null != margins.Right && tblwidth_Mm == margins.Right.Type && null != margins.Right.W) {
nMarginRight = margins.Right.W;
}
if (null != margins.Bottom && tblwidth_Mm == margins.Bottom.Type && null != margins.Bottom.W) {
nMarginBottom = margins.Bottom.W;
}
res = styleName + ":" + (nMarginTop * g_dKoef_mm_to_pt) + "pt " + (nMarginRight * g_dKoef_mm_to_pt) + "pt " + (nMarginBottom * g_dKoef_mm_to_pt) + "pt " + (nMarginLeft * g_dKoef_mm_to_pt) + "pt;";
return res;
},
_BordersToStyle: function (borders, bUseInner, bUseBetween, mso, alt) {
var res = "";
if (null == mso) {
mso = "";
}
if (null == alt) {
alt = "";
}
if (null != borders.Left) {
res += this._BorderToStyle(borders.Left, mso + "border-left" + alt);
}
if (null != borders.Top) {
res += this._BorderToStyle(borders.Top, mso + "border-top" + alt);
}
if (null != borders.Right) {
res += this._BorderToStyle(borders.Right, mso + "border-right" + alt);
}
if (null != borders.Bottom) {
res += this._BorderToStyle(borders.Bottom, mso + "border-bottom" + alt);
}
if (bUseInner) {
if (null != borders.InsideV) {
res += this._BorderToStyle(borders.InsideV, "mso-border-insidev");
}
if (null != borders.InsideH) {
res += this._BorderToStyle(borders.InsideH, "mso-border-insideh");
}
}
if (bUseBetween) {
if (null != borders.Between) {
res += this._BorderToStyle(borders.Between, "mso-border-between");
}
}
return res;
},
_MergeProp: function (elem1, elem2) {
if (!elem1 || !elem2) {
return;
}
var p, v;
for (p in elem2) {
if (elem2.hasOwnProperty(p) && false == elem1.hasOwnProperty(p)) {
v = elem2[p];
if (null != v) {
elem1[p] = v;
}
}
}
},
CopyCell: function (tr, cell, tablePr, width, rowspan) {
var tc = document.createElement("td");
var tcStyle = "";
if (width > 0) {
tc.setAttribute("width", Math.round(width * g_dKoef_mm_to_pix));
tcStyle += "width:" + (width * g_dKoef_mm_to_pt) + "pt;";
}
if (rowspan > 1) {
tc.setAttribute("rowspan", rowspan);
}
var cellPr = null;
if (null != cell.CompiledPr && null != cell.CompiledPr.Pr) {
cellPr = cell.CompiledPr.Pr;
if (null != cellPr.GridSpan && cellPr.GridSpan > 1) {
tc.setAttribute("colspan", cellPr.GridSpan);
}
}
if (null != cellPr && null != cellPr.Shd) {
if (shd_Nil != cellPr.Shd.Value) {
tcStyle += "background-color:" + this.RGBToCSS(cellPr.Shd.Color) + ";";
}
} else {
if (null != tablePr && null != tablePr.Shd) {
if (shd_Nil != tablePr.Shd.Value) {
tcStyle += "background-color:" + this.RGBToCSS(tablePr.Shd.Color) + ";";
}
}
}
var oCellMar = new Object();
if (null != cellPr && null != cellPr.TableCellMar) {
this._MergeProp(oCellMar, cellPr.TableCellMar);
}
if (null != tablePr && null != tablePr.TableCellMar) {
this._MergeProp(oCellMar, tablePr.TableCellMar);
}
tcStyle += this._MarginToStyle(oCellMar, "padding");
var oCellBorder = new Object();
if (null != cellPr && null != cellPr.TableCellBorders) {
this._MergeProp(oCellBorder, cellPr.TableCellBorders);
}
if (null != tablePr && null != tablePr.TableBorders) {
this._MergeProp(oCellBorder, tablePr.TableBorders);
}
tcStyle += this._BordersToStyle(oCellBorder, false, false);
if ("" != tcStyle) {
tc.setAttribute("style", tcStyle);
}
this.CopyDocument(tc, cell.Content, false);
tr.appendChild(tc);
},
CopyRow: function (oDomTarget, table, nCurRow, elems, nMaxRow) {
var row = table.Content[nCurRow];
if (null == elems) {
elems = {
gridStart: 0,
gridEnd: table.TableGrid.length - 1,
indexStart: null,
indexEnd: null,
after: null,
before: null,
cells: row.Content
};
}
var tr = document.createElement("tr");
var gridSum = table.TableSumGrid;
var trStyle = "";
var nGridBefore = 0;
var rowPr = null;
if (null != row.CompiledPr && null != row.CompiledPr.Pr) {
rowPr = row.CompiledPr.Pr;
}
if (null != rowPr) {
if (null == elems.before && null != rowPr.GridBefore && rowPr.GridBefore > 0) {
elems.before = rowPr.GridBefore;
elems.gridStart += rowPr.GridBefore;
}
if (null == elems.after && null != rowPr.GridAfter && rowPr.GridAfter > 0) {
elems.after = rowPr.GridAfter;
elems.gridEnd -= rowPr.GridAfter;
}
if (null != rowPr.Height && heightrule_Auto != rowPr.Height.HRule && null != rowPr.Height.Value) {
trStyle += "height:" + (rowPr.Height.Value * g_dKoef_mm_to_pt) + "pt;";
}
}
if (null != elems.before) {
if (elems.before > 0) {
nGridBefore = elems.before;
var nWBefore = gridSum[elems.gridStart - 1] - gridSum[elems.gridStart - nGridBefore - 1];
trStyle += "mso-row-margin-left:" + (nWBefore * g_dKoef_mm_to_pt) + "pt;";
var oNewTd = document.createElement("td");
oNewTd.setAttribute("style", "mso-cell-special:placeholder;border:none;padding:0cm 0cm 0cm 0cm");
oNewTd.setAttribute("width", Math.round(nWBefore * g_dKoef_mm_to_pix));
if (nGridBefore > 1) {
oNewTd.setAttribute("colspan", nGridBefore);
}
var oNewP = document.createElement("p");
oNewP.setAttribute("style", "margin:0cm");
oNewP.appendChild(document.createTextNode("\xa0"));
oNewTd.appendChild(oNewP);
tr.appendChild(oNewTd);
}
}
for (var i in elems.cells) {
var cell = row.Content[i];
if (vmerge_Continue != cell.Get_VMerge()) {
var StartGridCol = cell.Metrics.StartGridCol;
var GridSpan = cell.Get_GridSpan();
var width = gridSum[StartGridCol + GridSpan - 1] - gridSum[StartGridCol - 1];
var nRowSpan = table.Internal_GetVertMergeCount(nCurRow, StartGridCol, GridSpan);
if (nCurRow + nRowSpan - 1 > nMaxRow) {
nRowSpan = nMaxRow - nCurRow + 1;
if (nRowSpan <= 0) {
nRowSpan = 1;
}
}
var tablePr = null;
if (null != table.CompiledPr && null != table.CompiledPr.Pr && null != table.CompiledPr.Pr.TablePr) {
tablePr = table.CompiledPr.Pr.TablePr;
}
this.CopyCell(tr, cell, tablePr, width, nRowSpan);
}
}
if (null != elems.after) {
if (elems.after > 0) {
var nGridAfter = elems.after;
var nWAfter = gridSum[elems.gridEnd + nGridAfter] - gridSum[elems.gridEnd];
trStyle += "mso-row-margin-right:" + (nWAfter * g_dKoef_mm_to_pt) + "pt;";
var oNewTd = document.createElement("td");
oNewTd.setAttribute("style", "mso-cell-special:placeholder;border:none;padding:0cm 0cm 0cm 0cm");
oNewTd.setAttribute("width", Math.round(nWAfter * g_dKoef_mm_to_pix));
if (nGridAfter > 1) {
oNewTd.setAttribute("colspan", nGridAfter);
}
var oNewP = document.createElement("p");
oNewP.setAttribute("style", "margin:0cm");
oNewP.appendChild(document.createTextNode("\xa0"));
oNewTd.appendChild(oNewP);
tr.appendChild(oNewTd);
}
}
if ("" != trStyle) {
tr.setAttribute("style", trStyle);
}
oDomTarget.appendChild(tr);
},
CopyTable: function (oDomTarget, table, aRowElems) {
this.CommitList(oDomTarget);
var DomTable = document.createElement("table");
var Pr = null;
if (null != table.CompiledPr && null != table.CompiledPr.Pr && null != table.CompiledPr.Pr.TablePr) {
Pr = table.CompiledPr.Pr.TablePr;
}
var tblStyle = "";
var bBorder = false;
if (null != Pr) {
var align = "";
if (true != table.Inline && null != table.PositionH) {
var PositionH = table.PositionH;
if (true == PositionH.Align) {
switch (PositionH.Value) {
case c_oAscXAlign.Outside:
case c_oAscXAlign.Right:
align = "right";
break;
case c_oAscXAlign.Center:
align = "center";
break;
}
} else {
if (table.TableSumGrid) {
var TableWidth = table.TableSumGrid[table.TableSumGrid.length - 1];
var nLeft = PositionH.Value;
var nRight = nLeft + TableWidth;
var nFromLeft = Math.abs(nLeft - X_Left_Margin);
var nFromCenter = Math.abs((Page_Width - X_Right_Margin + X_Left_Margin) / 2 - (nLeft + nRight) / 2);
var nFromRight = Math.abs(Page_Width - nRight - X_Right_Margin);
if (nFromRight < nFromLeft || nFromCenter < nFromLeft) {
if (nFromRight < nFromCenter) {
align = "right";
} else {
align = "center";
}
}
}
}
} else {
if (null != Pr.Jc) {
switch (Pr.Jc) {
case align_Center:
align = "center";
break;
case align_Right:
align = "right";
break;
}
}
}
if ("" != align) {
DomTable.setAttribute("align", align);
}
if (null != Pr.TableInd) {
tblStyle += "margin-left:" + (Pr.TableInd * g_dKoef_mm_to_pt) + "pt;";
}
if (null != Pr.Shd && shd_Nil != Pr.Shd.Value) {
tblStyle += "background:" + this.RGBToCSS(Pr.Shd.Color) + ";";
}
if (null != Pr.TableCellMar) {
tblStyle += this._MarginToStyle(Pr.TableCellMar, "mso-padding-alt");
}
if (null != Pr.TableBorders) {
tblStyle += this._BordersToStyle(Pr.TableBorders, true, false);
}
}
var bAddSpacing = false;
if (table.Content.length > 0) {
var firstRow = table.Content[0];
if (null != firstRow.Pr && null != firstRow.Pr.TableCellSpacing) {
bAddSpacing = true;
var cellSpacingMM = firstRow.Pr.TableCellSpacing;
tblStyle += "mso-cellspacing:" + (cellSpacingMM * g_dKoef_mm_to_pt) + "pt;";
DomTable.setAttribute("cellspacing", Math.round(cellSpacingMM * g_dKoef_mm_to_pix));
}
}
if (!bAddSpacing) {
DomTable.setAttribute("cellspacing", 0);
}
DomTable.setAttribute("border", false == bBorder ? 0 : 1);
DomTable.setAttribute("cellpadding", 0);
if ("" != tblStyle) {
DomTable.setAttribute("style", tblStyle);
}
if (null == aRowElems) {
for (var i = 0, length = table.Content.length; i < length; i++) {
this.CopyRow(DomTable, table, i, null, table.Content.length - 1);
}
} else {
var nMaxRow = 0;
for (var i = 0, length = aRowElems.length; i < length; ++i) {
var elem = aRowElems[i];
if (elem.row > nMaxRow) {
nMaxRow = elem.row;
}
}
for (var i = 0, length = aRowElems.length; i < length; ++i) {
var elem = aRowElems[i];
this.CopyRow(DomTable, table, elem.row, elem, nMaxRow);
}
}
oDomTarget.appendChild(DomTable);
},
CopyDocument: function (oDomTarget, oDocument, bUseSelection) {
var Start = 0;
var End = 0;
if (bUseSelection) {
if (true === oDocument.Selection.Use) {
if (selectionflag_DrawingObject === oDocument.Selection.Flag) {
this.Para = document.createElement("p");
this.InitRun();
this.ParseItem(oDocument.Selection.Data.DrawingObject);
this.CommitSpan(false);
for (var i = 0; i < this.Para.childNodes.length; i++) {
this.ElemToSelect.appendChild(this.Para.childNodes[i].cloneNode(true));
}
} else {
Start = oDocument.Selection.StartPos;
End = oDocument.Selection.EndPos;
if (Start > End) {
var Temp = End;
End = Start;
Start = Temp;
}
}
}
} else {
Start = 0;
End = oDocument.Content.length - 1;
}
for (var Index = Start; Index <= End; Index++) {
var Item = oDocument.Content[Index];
if (type_Table === Item.GetType()) {
if (bUseSelection) {
if (table_Selection_Text == Item.Selection.Type) {
var rowIndex = Item.Selection.StartPos.Pos.Row;
var colIndex = Item.Selection.StartPos.Pos.Cell;
if (rowIndex < Item.Content.length) {
var row = Item.Content[rowIndex];
if (colIndex < row.Content.length) {
var cell = row.Content[colIndex];
this.CopyDocument(oDomTarget, cell.Content, bUseSelection);
}
}
} else {
if (table_Selection_Cell == Item.Selection.Type) {
var aSelectedRows = new Array();
var oRowElems = new Object();
if (Item.Selection.Data.length > 0) {
for (var i = 0, length = Item.Selection.Data.length; i < length; ++i) {
var elem = Item.Selection.Data[i];
var rowElem = oRowElems[elem.Row];
if (null == rowElem) {
rowElem = {
row: elem.Row,
gridStart: null,
gridEnd: null,
indexStart: null,
indexEnd: null,
after: null,
before: null,
cells: {}
};
oRowElems[elem.Row] = rowElem;
aSelectedRows.push(rowElem);
}
if (null == rowElem.indexEnd || elem.Cell > rowElem.indexEnd) {
rowElem.indexEnd = elem.Cell;
}
if (null == rowElem.indexStart || elem.Cell < rowElem.indexStart) {
rowElem.indexStart = elem.Cell;
}
rowElem.cells[elem.Cell] = 1;
}
}
aSelectedRows.sort(function (a, b) {
return a.row - b.row;
});
var nMinGrid = null;
var nMaxGrid = null;
var nPrevStartGrid = null;
var nPrevEndGrid = null;
var nPrevRowIndex = null;
for (var i = 0, length = aSelectedRows.length; i < length; ++i) {
var elem = aSelectedRows[i];
var nRowIndex = elem.row;
if (null != nPrevRowIndex) {
if (nPrevRowIndex + 1 != nRowIndex) {
nMinGrid = null;
nMaxGrid = null;
break;
}
}
nPrevRowIndex = nRowIndex;
var row = Item.Content[nRowIndex];
var cellFirst = row.Get_Cell(elem.indexStart);
var cellLast = row.Get_Cell(elem.indexEnd);
var nCurStartGrid = cellFirst.Metrics.StartGridCol;
var nCurEndGrid = cellLast.Metrics.StartGridCol + cellLast.Get_GridSpan() - 1;
if (null != nPrevStartGrid && null != nPrevEndGrid) {
if (nCurStartGrid > nPrevStartGrid) {
for (var j = elem.indexStart - 1; j >= 0; --j) {
var cellCur = row.Get_Cell(j);
if (vmerge_Continue == cellCur.Get_VMerge()) {
var nCurGridCol = cellCur.Metrics.StartGridCol;
if (nCurGridCol >= nPrevStartGrid) {
nCurStartGrid = nCurGridCol;
elem.indexStart = j;
} else {
break;
}
} else {
break;
}
}
}
if (nCurEndGrid < nPrevEndGrid) {
for (var j = elem.indexEnd + 1; j < row.Get_CellsCount(); ++j) {
var cellCur = row.Get_Cell(j);
if (vmerge_Continue == cellCur.Get_VMerge()) {
var nCurGridCol = cellCur.Metrics.StartGridCol + cellCur.Get_GridSpan() - 1;
if (nCurGridCol <= nPrevEndGrid) {
nCurEndGrid = nCurGridCol;
elem.indexEnd = j;
} else {
break;
}
} else {
break;
}
}
}
}
elem.gridStart = nPrevStartGrid = nCurStartGrid;
elem.gridEnd = nPrevEndGrid = nCurEndGrid;
if (null == nMinGrid || nMinGrid > nCurStartGrid) {
nMinGrid = nCurStartGrid;
}
if (null == nMaxGrid || nMaxGrid < nCurEndGrid) {
nMaxGrid = nCurEndGrid;
}
}
if (null != nMinGrid && null != nMaxGrid) {
for (var i = 0, length = aSelectedRows.length; i < length; ++i) {
var elem = aSelectedRows[i];
elem.before = elem.gridStart - nMinGrid;
elem.after = nMaxGrid - elem.gridEnd;
}
this.oBinaryFileWriter.copyParams.bLockCopyElems++;
this.CopyTable(oDomTarget, Item, aSelectedRows);
this.oBinaryFileWriter.copyParams.bLockCopyElems--;
this.oBinaryFileWriter.CopyTable(Item, aSelectedRows, nMinGrid, nMaxGrid);
}
}
}
} else {
this.oBinaryFileWriter.copyParams.bLockCopyElems++;
this.CopyTable(oDomTarget, Item, null);
this.oBinaryFileWriter.copyParams.bLockCopyElems--;
this.oBinaryFileWriter.CopyTable(Item, null);
}
} else {
if (type_Paragraph === Item.GetType()) {
this.oBinaryFileWriter.CopyParagraph(Item);
this.CopyParagraph(oDomTarget, Item, Index == End, bUseSelection, oDocument.Content, Index);
}
}
}
this.CommitList(oDomTarget);
},
Start: function (node) {
this.oBinaryFileWriter.CopyStart();
var oDocument = this.oDocument;
if (g_bIsDocumentCopyPaste) {
if (!this.api.DocumentReaderMode) {
var Def_pPr = oDocument.Styles.Default.ParaPr;
if (docpostype_HdrFtr === oDocument.CurPos.Type) {
if (null != oDocument.HdrFtr && null != oDocument.HdrFtr.CurHdrFtr && null != oDocument.HdrFtr.CurHdrFtr.Content) {
oDocument = oDocument.HdrFtr.CurHdrFtr.Content;
}
}
if (oDocument.CurPos.Type == docpostype_FlowObjects) {
var oData = oDocument.Selection.Data.FlowObject;
switch (oData.Get_Type()) {
case flowobject_Image:
this.Para = document.createElement("p");
this.InitRun();
this.ParseItem(oData);
var oImg = oData;
var sSrc = oImg.Img;
if (sSrc.length > 0) {
sSrc = this.getSrc(sSrc);
if (this.api.DocumentReaderMode) {
this.aInnerHtml.push('');
} else {
this.aInnerHtml.push('');
}
}
this.CommitSpan(false);
this.ElemToSelect.appendChild(this.Para);
return;
case flowobject_Table:
if (null != oData.Table && null != oData.Table.CurCell && null != oData.Table.CurCell.Content) {
oDocument = oData.Table.CurCell.Content;
}
break;
}
}
if (oDocument.CurPos.Type === docpostype_DrawingObjects) {
switch (oDocument.DrawingObjects.curState.id) {
case STATES_ID_TEXT_ADD:
var text_object = oDocument.DrawingObjects.curState.textObject;
if (text_object != null && text_object.GraphicObj != null && text_object.GraphicObj.textBoxContent != null) {
oDocument = text_object.GraphicObj.textBoxContent;
}
break;
case STATES_ID_TEXT_ADD_IN_GROUP:
text_object = oDocument.DrawingObjects.curState.textObject;
if (text_object != null && text_object.textBoxContent != null) {
oDocument = text_object.textBoxContent;
}
break;
case STATES_ID_CHART_TITLE_TEXT:
case STATES_ID_CHART_TITLE_TEXT_GROUP:
var text_object = oDocument.DrawingObjects.curState.title;
if (text_object != null && text_object.txBody != null && text_object.txBody != null) {
oDocument = text_object.txBody.getDocContentForCopyPaste();
}
break;
case STATES_ID_GROUP:
var s_arr = oDocument.DrawingObjects.curState.group.selectionInfo.selectionArray;
this.Para = document.createElement("p");
this.InitRun();
if (copyPasteUseBinery) {
var newArr = null;
var tempAr = null;
if (s_arr) {
tempAr = [];
for (var k = 0; k < s_arr.length; k++) {
tempAr[k] = s_arr[k].absOffsetY;
}
}
tempAr.sort(function (a, b) {
return a - b;
});
newArr = [];
for (var k = 0; k < tempAr.length; k++) {
var absOffsetY = tempAr[k];
for (var i = 0; i < s_arr.length; i++) {
if (absOffsetY == s_arr[i].absOffsetY) {
newArr[k] = s_arr[i];
}
}
}
if (newArr != null) {
s_arr = newArr;
}
}
for (var i = 0; i < s_arr.length; ++i) {
var cur_element = s_arr[i];
if (isRealObject(cur_element.parent)) {
var base64_img = cur_element.parent.getBase64Img();
if (copyPasteUseBinery) {
var wrappingType = cur_element.parent.wrappingType;
var DrawingType = cur_element.parent.DrawingType;
var tempParagraph = new Paragraph(oDocument, oDocument, 0, 0, 0, 0, 0);
var index = 0;
tempParagraph.Content.unshift(new ParaDrawing());
tempParagraph.Content[index].wrappingType = wrappingType;
tempParagraph.Content[index].DrawingType = DrawingType;
tempParagraph.Content[index].GraphicObj = cur_element;
tempParagraph.Selection.EndPos = index + 1;
tempParagraph.Selection.StartPos = index;
tempParagraph.Selection.Use = true;
this.oBinaryFileWriter.CopyParagraph(tempParagraph);
}
var src = this.getSrc(base64_img);
this.aInnerHtml.push('');
this.ElemToSelect.appendChild(this.Para);
}
}
this.CommitSpan(false);
if (copyPasteUseBinery) {
this.oBinaryFileWriter.CopyEnd();
var sBase64 = this.oBinaryFileWriter.GetResult();
if (this.ElemToSelect.children && this.ElemToSelect.children.length == 1 && window.USER_AGENT_SAFARI_MACOS) {
$(this.ElemToSelect.children[0]).css("font-weight", "normal");
$(this.ElemToSelect.children[0]).wrap(document.createElement("b"));
}
if (this.ElemToSelect.children[0]) {
$(this.ElemToSelect.children[0]).addClass("docData;" + sBase64);
}
}
return;
default:
var gr_objects = oDocument.DrawingObjects;
var selection_array = gr_objects.selectionInfo.selectionArray;
this.Para = document.createElement("span");
this.InitRun();
var selectionTrue;
var selectIndex;
for (var i = 0; i < selection_array.length; ++i) {
var cur_element = selection_array[i];
var base64_img = cur_element.getBase64Img();
var src = this.getSrc(base64_img);
this.aInnerHtml.push('');
this.ElemToSelect.appendChild(this.Para);
if (copyPasteUseBinery) {
var parent = cur_element.Parent;
selectionTrue = {
EndPos: parent.Selection.EndPos,
StartPos: parent.Selection.StartPos
};
var inIndex;
for (var k = 0; k < parent.Content.length; k++) {
if (parent.Content[k] == cur_element) {
inIndex = k;
break;
}
}
parent.Selection.EndPos = inIndex + 1;
parent.Selection.StartPos = inIndex;
parent.Selection.Use = true;
this.oBinaryFileWriter.CopyParagraph(parent);
parent.Selection.StartPos = selectionTrue.StartPos;
parent.Selection.EndPos = selectionTrue.EndPos;
}
}
this.CommitSpan(false);
if (copyPasteUseBinery) {
this.oBinaryFileWriter.CopyEnd();
var sBase64 = this.oBinaryFileWriter.GetResult();
if (this.ElemToSelect.children && this.ElemToSelect.children.length == 1 && window.USER_AGENT_SAFARI_MACOS) {
$(this.ElemToSelect.children[0]).css("font-weight", "normal");
$(this.ElemToSelect.children[0]).wrap(document.createElement("b"));
}
if (this.ElemToSelect.children[0]) {
$(this.ElemToSelect.children[0]).addClass("docData;" + sBase64);
}
}
return;
}
}
if (true === oDocument.Selection.Use) {
this.CopyDocument(this.ElemToSelect, oDocument, true);
}
} else {
this.CopyDocument(this.ElemToSelect, oDocument, false);
}
} else {
var presentation = editor.WordControl.m_oLogicDocument;
var pasteString = "";
switch (editor.WordControl.Thumbnails.FocusObjType) {
case FOCUS_OBJECT_MAIN:
var slide = presentation.Slides[presentation.CurPage];
var graphicObjects = slide.graphicObjects;
switch (graphicObjects.State.id) {
case STATES_ID_TEXT_ADD:
case STATES_ID_TEXT_ADD_IN_GROUP:
case STATES_ID_CHART_TEXT_ADD:
if (graphicObjects.State.textObject instanceof CShape || graphicObjects.State.textObject instanceof CChartTitle) {
this.oPresentationWriter.WriteString2("TeamLab1");
this.oPresentationWriter.WriteString2(editor.DocumentUrl);
this.oPresentationWriter.WriteDouble(presentation.Width);
this.oPresentationWriter.WriteDouble(presentation.Height);
this.CopyPresentationText(this.ElemToSelect, graphicObjects.State.textObject.txBody.content, true);
} else {
if (graphicObjects.State.textObject instanceof CGraphicFrame) {
var table = graphicObjects.State.textObject.graphicObject;
switch (table.Selection.Type) {
case table_Selection_Text:
this.oPresentationWriter.WriteString2("TeamLab1");
this.oPresentationWriter.WriteString2(editor.DocumentUrl);
this.oPresentationWriter.WriteDouble(presentation.Width);
this.oPresentationWriter.WriteDouble(presentation.Height);
this.CopyPresentationText(this.ElemToSelect, graphicObjects.State.textObject.graphicObject.CurCell.Content, true);
break;
case table_Selection_Cell:
this.oPresentationWriter.WriteString2("TeamLab4");
this.oPresentationWriter.WriteString2(editor.DocumentUrl);
this.oPresentationWriter.WriteDouble(presentation.Width);
this.oPresentationWriter.WriteDouble(presentation.Height);
this.CopyPresentationTableCells(this.ElemToSelect, graphicObjects.State.textObject);
var selected_objects = graphicObjects.State.id === STATES_ID_GROUP ? graphicObjects.State.group.selectedObjects : graphicObjects.selectedObjects;
for (var i = 0; i < selected_objects.length; ++i) {
var selected_object = selected_objects[i];
this.oPresentationWriter.WriteDouble(selected_object.x);
this.oPresentationWriter.WriteDouble(selected_object.y);
this.oPresentationWriter.WriteDouble(selected_object.extX);
this.oPresentationWriter.WriteDouble(selected_object.extY);
}
break;
}
}
}
break;
default:
if (graphicObjects.selectedObjects.length > 0) {
this.aInnerHtml = [];
this.Para = document.createElement("p");
this.oPresentationWriter.WriteString2("TeamLab2");
this.oPresentationWriter.WriteString2(editor.DocumentUrl);
this.oPresentationWriter.WriteDouble(presentation.Width);
this.oPresentationWriter.WriteDouble(presentation.Height);
var selected_objects = graphicObjects.State.id === STATES_ID_GROUP ? graphicObjects.State.group.selectedObjects : graphicObjects.selectedObjects;
this.oPresentationWriter.WriteULong(selected_objects.length);
for (var i = 0; i < selected_objects.length; ++i) {
if (! (selected_objects[i] instanceof CGraphicFrame)) {
this.oPresentationWriter.WriteBool(true);
this.CopyGraphicObject(this.ElemToSelect, selected_objects[i]);
} else {
this.oPresentationWriter.WriteBool(false);
this.CopyPresentationTableFull(this.ElemToSelect, selected_objects[i]);
}
}
for (var i = 0; i < selected_objects.length; ++i) {
var selected_object = selected_objects[i];
this.oPresentationWriter.WriteDouble(selected_object.x);
this.oPresentationWriter.WriteDouble(selected_object.y);
this.oPresentationWriter.WriteDouble(selected_object.extX);
this.oPresentationWriter.WriteDouble(selected_object.extY);
}
this.CommitSpan(false);
for (var i = 0; i < this.Para.childNodes.length; i++) {
this.ElemToSelect.appendChild(this.Para.childNodes[i].cloneNode(true));
}
}
break;
}
break;
case FOCUS_OBJECT_THUMBNAILS:
var selected_slides = editor.WordControl.Thumbnails.GetSelectedArray();
if (selected_slides.length > 0) {
this.aInnerHtml = [];
this.Para = document.createElement("p");
this.oPresentationWriter.WriteString2("TeamLab3");
this.oPresentationWriter.WriteString2(editor.DocumentUrl);
this.oPresentationWriter.WriteDouble(presentation.Width);
this.oPresentationWriter.WriteDouble(presentation.Height);
this.oPresentationWriter.WriteULong(selected_slides.length);
var layouts_map = {};
var layout_count = 0;
editor.WordControl.m_oLogicDocument.CalculateComments();
for (var i = 0; i < selected_slides.length; ++i) {
this.CopySlide(this.ElemToSelect, editor.WordControl.m_oLogicDocument.Slides[selected_slides[i]]);
if (!layouts_map[editor.WordControl.m_oLogicDocument.Slides[selected_slides[i]].Layout.Get_Id()]) {
++layout_count;
}
layouts_map[editor.WordControl.m_oLogicDocument.Slides[selected_slides[i]].Layout.Get_Id()] = editor.WordControl.m_oLogicDocument.Slides[selected_slides[i]].Layout;
}
this.oPresentationWriter.WriteULong(layout_count);
var arr_layouts_id = [];
var t = 0;
for (var key in layouts_map) {
this.CopyLayout(layouts_map[key]);
arr_layouts_id[t] = layouts_map[key];
++t;
}
var arr_ind = [];
for (var i = 0; i < selected_slides.length; ++i) {
for (t = 0; t < arr_layouts_id.length; ++t) {
if (editor.WordControl.m_oLogicDocument.Slides[selected_slides[i]].Layout === arr_layouts_id[t]) {
arr_ind[i] = t;
break;
}
}
}
for (var i = 0; i < arr_ind.length; ++i) {
this.oPresentationWriter.WriteULong(arr_ind[i]);
}
this.CommitSpan(false);
for (var i = 0; i < this.Para.childNodes.length; i++) {
this.ElemToSelect.appendChild(this.Para.childNodes[i].cloneNode(true));
}
}
break;
}
var sBase64 = this.oPresentationWriter.GetBase64Memory();
sBase64 = "" + this.oPresentationWriter.pos + ";" + sBase64;
if (this.ElemToSelect.children && this.ElemToSelect.children.length == 1 && window.USER_AGENT_SAFARI_MACOS) {
$(this.ElemToSelect.children[0]).css("font-weight", "normal");
$(this.ElemToSelect.children[0]).wrap(document.createElement("b"));
}
if (this.ElemToSelect.children[0]) {
$(this.ElemToSelect.children[0]).addClass("pptData;" + sBase64);
}
}
this.oBinaryFileWriter.CopyEnd();
if (copyPasteUseBinery && this.oBinaryFileWriter.copyParams.itemCount > 0) {
var sBase64 = this.oBinaryFileWriter.GetResult();
if (this.ElemToSelect.children && this.ElemToSelect.children.length == 1 && window.USER_AGENT_SAFARI_MACOS) {
$(this.ElemToSelect.children[0]).css("font-weight", "normal");
$(this.ElemToSelect.children[0]).wrap(document.createElement("b"));
}
if (this.ElemToSelect.children[0]) {
$(this.ElemToSelect.children[0]).addClass("docData;" + sBase64);
}
}
},
CopySlide: function (oDomTarget, slide) {
var sSrc = slide.getBase64Img();
var _bounds_cheker = new CSlideBoundsChecker();
slide.draw(_bounds_cheker, 0);
this.aInnerHtml.push('');
this.oPresentationWriter.WriteString2(slide.Layout.Get_Id());
var table_styles_ids = [];
var sp_tree = slide.cSld.spTree;
for (var i = 0; i < sp_tree.length; ++i) {
if (sp_tree[i] instanceof CGraphicFrame) {
table_styles_ids.push(sp_tree[i].graphicObject.styleIndex);
sp_tree[i].graphicObject.styleIndex = -1;
}
}
this.oPresentationWriter.WriteULong(table_styles_ids.length);
for (var i = 0; i < table_styles_ids.length; ++i) {
this.oPresentationWriter.WriteBool(isRealNumber(table_styles_ids[i]) && table_styles_ids[i] > -1);
if (isRealNumber(table_styles_ids[i]) && table_styles_ids[i] > -1) {
this.oPresentationWriter.WriteULong(table_styles_ids[i]);
}
}
this.oPresentationWriter.WriteSlide(slide);
this.oPresentationWriter.WriteULong(sp_tree.length);
for (var i = 0; i < sp_tree.length; ++i) {
var sp = sp_tree[i];
this.oPresentationWriter.WriteDouble(sp.x);
this.oPresentationWriter.WriteDouble(sp.y);
this.oPresentationWriter.WriteDouble(sp.extX);
this.oPresentationWriter.WriteDouble(sp.extY);
}
var j = 0;
for (var i = 0; i < sp_tree.length; ++i) {
if (sp_tree[i] instanceof CGraphicFrame) {
sp_tree[i].graphicObject.styleIndex = table_styles_ids[j];
++j;
}
}
},
CopyLayout: function (layout) {
this.oPresentationWriter.WriteSlideLayout(layout);
},
CopyPresentationTableCells: function (oDomTarget, graphicFrame) {
var aSelectedRows = new Array();
var oRowElems = new Object();
var Item = graphicFrame.graphicObject;
if (Item.Selection.Data.length > 0) {
for (var i = 0, length = Item.Selection.Data.length; i < length; ++i) {
var elem = Item.Selection.Data[i];
var rowElem = oRowElems[elem.Row];
if (null == rowElem) {
rowElem = {
row: elem.Row,
gridStart: null,
gridEnd: null,
indexStart: null,
indexEnd: null,
after: null,
before: null,
cells: {}
};
oRowElems[elem.Row] = rowElem;
aSelectedRows.push(rowElem);
}
if (null == rowElem.indexEnd || elem.Cell > rowElem.indexEnd) {
rowElem.indexEnd = elem.Cell;
}
if (null == rowElem.indexStart || elem.Cell < rowElem.indexStart) {
rowElem.indexStart = elem.Cell;
}
rowElem.cells[elem.Cell] = 1;
}
}
aSelectedRows.sort(function (a, b) {
return a.row - b.row;
});
var nMinGrid = null;
var nMaxGrid = null;
var nPrevStartGrid = null;
var nPrevEndGrid = null;
var nPrevRowIndex = null;
for (var i = 0, length = aSelectedRows.length; i < length; ++i) {
var elem = aSelectedRows[i];
var nRowIndex = elem.row;
if (null != nPrevRowIndex) {
if (nPrevRowIndex + 1 != nRowIndex) {
nMinGrid = null;
nMaxGrid = null;
break;
}
}
nPrevRowIndex = nRowIndex;
var row = Item.Content[nRowIndex];
var cellFirst = row.Get_Cell(elem.indexStart);
var cellLast = row.Get_Cell(elem.indexEnd);
var nCurStartGrid = cellFirst.Metrics.StartGridCol;
var nCurEndGrid = cellLast.Metrics.StartGridCol + cellLast.Get_GridSpan() - 1;
if (null != nPrevStartGrid && null != nPrevEndGrid) {
if (nCurStartGrid > nPrevStartGrid) {
for (var j = elem.indexStart - 1; j >= 0; --j) {
var cellCur = row.Get_Cell(j);
if (vmerge_Continue == cellCur.Get_VMerge()) {
var nCurGridCol = cellCur.Metrics.StartGridCol;
if (nCurGridCol >= nPrevStartGrid) {
nCurStartGrid = nCurGridCol;
elem.indexStart = j;
} else {
break;
}
} else {
break;
}
}
}
if (nCurEndGrid < nPrevEndGrid) {
for (var j = elem.indexEnd + 1; j < row.Get_CellsCount(); ++j) {
var cellCur = row.Get_Cell(j);
if (vmerge_Continue == cellCur.Get_VMerge()) {
var nCurGridCol = cellCur.Metrics.StartGridCol + cellCur.Get_GridSpan() - 1;
if (nCurGridCol <= nPrevEndGrid) {
nCurEndGrid = nCurGridCol;
elem.indexEnd = j;
} else {
break;
}
} else {
break;
}
}
}
}
elem.gridStart = nPrevStartGrid = nCurStartGrid;
elem.gridEnd = nPrevEndGrid = nCurEndGrid;
if (null == nMinGrid || nMinGrid > nCurStartGrid) {
nMinGrid = nCurStartGrid;
}
if (null == nMaxGrid || nMaxGrid < nCurEndGrid) {
nMaxGrid = nCurEndGrid;
}
}
if (null != nMinGrid && null != nMaxGrid) {
for (var i = 0, length = aSelectedRows.length; i < length; ++i) {
var elem = aSelectedRows[i];
elem.before = elem.gridStart - nMinGrid;
elem.after = nMaxGrid - elem.gridEnd;
}
this.CopyTable(oDomTarget, Item, aSelectedRows);
}
var is_on = History.Is_On();
if (is_on) {
History.TurnOff();
}
var graphic_frame = new CGraphicFrame(graphicFrame.parent);
var grid = [];
for (var i = nMinGrid; i <= nMaxGrid; ++i) {
grid.push(graphicFrame.graphicObject.TableGrid[i]);
}
var table = new CTable(editor.WordControl.m_oDrawingDocument, graphicFrame, false, 0, 0, 0, 0, 0, aSelectedRows.length, nMaxGrid - nMinGrid + 1, grid);
table.setStyleIndex(graphicFrame.graphicObject.styleIndex);
graphic_frame.setGraphicObject(table);
graphic_frame.setXfrm(0, 0, 20, 30, 0, false, false);
var b_style_index = false;
if (isRealNumber(graphic_frame.graphicObject.styleIndex) && graphic_frame.graphicObject.styleIndex > -1) {
b_style_index = true;
}
this.oPresentationWriter.WriteULong(1);
this.oPresentationWriter.WriteBool(false);
this.oPresentationWriter.WriteBool(b_style_index);
if (b_style_index) {
this.oPresentationWriter.WriteULong(graphic_frame.graphicObject.styleIndex);
}
var old_style_index = graphic_frame.graphicObject.styleIndex;
graphic_frame.graphicObject.styleIndex = -1;
this.oPresentationWriter.WriteTable(graphic_frame);
graphic_frame.graphicObject.styleIndex = old_style_index;
if (is_on) {
History.TurnOn();
}
this.oBinaryFileWriter.copyParams.itemCount = 0;
},
CopyPresentationTableFull: function (oDomTarget, graphicFrame) {
var aSelectedRows = new Array();
var oRowElems = new Object();
var Item = graphicFrame.graphicObject;
this.CopyTable(oDomTarget, Item, null);
var b_style_index = false;
if (isRealNumber(graphicFrame.graphicObject.styleIndex) && graphicFrame.graphicObject.styleIndex > -1) {
b_style_index = true;
}
this.oPresentationWriter.WriteBool(b_style_index);
if (b_style_index) {
this.oPresentationWriter.WriteULong(graphicFrame.graphicObject.styleIndex);
}
var old_style_index = graphicFrame.graphicObject.styleIndex;
graphicFrame.graphicObject.styleIndex = -1;
this.oPresentationWriter.WriteTable(graphicFrame);
graphicFrame.graphicObject.styleIndex = old_style_index;
this.oBinaryFileWriter.copyParams.itemCount = 0;
},
CopyPresentationText: function (oDomTarget, oDocument, bUseSelection) {
var Start = 0;
var End = 0;
if (bUseSelection) {
if (true === oDocument.Selection.Use) {
if (selectionflag_DrawingObject === oDocument.Selection.Flag) {
this.Para = document.createElement("p");
this.InitRun();
this.ParseItem(oDocument.Selection.Data.DrawingObject);
this.CommitSpan(false);
for (var i = 0; i < this.Para.childNodes.length; i++) {
this.ElemToSelect.appendChild(this.Para.childNodes[i].cloneNode(true));
}
} else {
Start = oDocument.Selection.StartPos;
End = oDocument.Selection.EndPos;
if (Start > End) {
var Temp = End;
End = Start;
Start = Temp;
}
}
}
} else {
Start = 0;
End = oDocument.Content.length - 1;
}
this.oPresentationWriter.WriteULong(End - Start + 1);
for (var Index = Start; Index <= End; Index++) {
var Item = oDocument.Content[Index];
var selectStart = Item.Selection.Use ? Item.Selection.StartPos : 0;
var selectEnd = Item.Selection.Use ? Item.Selection.EndPos : Item.Content.length;
if (selectStart > selectEnd) {
var Temp = selectEnd;
selectEnd = selectStart;
selectStart = Temp;
}
for (var i = 0; i < selectStart; ++i) {
var content = Item.Content[i];
if (content instanceof ParaText) {
break;
}
}
if (i == selectStart) {
selectStart = 0;
}
this.oPresentationWriter.StartRecord(0);
this.oPresentationWriter.WriteParagraph(Item, selectStart, selectEnd);
this.oPresentationWriter.EndRecord();
this.CopyParagraph(oDomTarget, Item, Index == End, bUseSelection, oDocument.Content, Index);
}
this.CommitList(oDomTarget);
},
CopyGraphicObject: function (oDomTarget, oGraphicObj) {
var sSrc = oGraphicObj.getBase64Img();
if (sSrc.length > 0) {
sSrc = this.getSrc(sSrc);
var _bounds_cheker = new CSlideBoundsChecker();
oGraphicObj.draw(_bounds_cheker, 0);
if (this.api.DocumentReaderMode) {
this.aInnerHtml.push('');
} else {
this.aInnerHtml.push('');
}
if (oGraphicObj instanceof CShape) {
this.oPresentationWriter.WriteShape(oGraphicObj);
} else {
if (oGraphicObj instanceof CImageShape) {
this.oPresentationWriter.WriteImage(oGraphicObj);
} else {
if (oGraphicObj instanceof CGroupShape) {
this.oPresentationWriter.WriteGroupShape(oGraphicObj);
} else {
if (typeof CChartAsGroup != "undefined" && oGraphicObj instanceof CChartAsGroup) {
this.oPresentationWriter.WriteChart(oGraphicObj);
}
}
}
}
}
}
};
function Editor_Paste_GetElem(api, bClean) {
var oWordControl = api.WordControl;
var pastebin = document.getElementById(PASTE_ELEMENT_ID);
if (!pastebin) {
pastebin = document.createElement("div");
pastebin.setAttribute("id", PASTE_ELEMENT_ID);
pastebin.className = "sdk-element";
if (AscBrowser.isIE) {
pastebin.style.position = "fixed";
} else {
pastebin.style.position = "absolute";
}
pastebin.style.top = "-100px";
pastebin.style.left = "0px";
pastebin.style.width = "10000px";
pastebin.style.height = "100px";
pastebin.style.overflow = "hidden";
pastebin.style.zIndex = -1000;
var Def_rPr = oWordControl.m_oLogicDocument.Styles.Default.TextPr;
pastebin.style.fontFamily = Def_rPr.FontFamily.Name;
if (!api.DocumentReaderMode) {
pastebin.style.fontSize = Def_rPr.FontSize + "pt";
} else {
api.DocumentReaderMode.CorrectDefaultFontSize(Def_rPr.FontSize);
pastebin.style.fontSize = "1em";
}
pastebin.style.MozUserSelect = "text";
pastebin.style["-khtml-user-select"] = "text";
pastebin.style["-o-user-select"] = "text";
pastebin.style["user-select"] = "text";
pastebin.style["-webkit-user-select"] = "text";
pastebin.setAttribute("contentEditable", true);
document.body.appendChild(pastebin);
} else {
if (bClean) {
var aChildNodes = pastebin.childNodes;
for (var length = aChildNodes.length, i = length - 1; i >= 0; i--) {
pastebin.removeChild(aChildNodes[i]);
}
}
}
if (!window.USER_AGENT_SAFARI_MACOS) {
pastebin.onpaste = function (e) {
if (!window.GlobalPasteFlag) {
return;
}
Body_Paste(api, e);
pastebin.onpaste = null;
};
}
return pastebin;
}
function Editor_Paste_Button(api) {
if (AscBrowser.isIE) {
document.body.style.MozUserSelect = "text";
delete document.body.style["-khtml-user-select"];
delete document.body.style["-o-user-select"];
delete document.body.style["user-select"];
document.body.style["-webkit-user-select"] = "text";
if (window.USER_AGENT_IE) {
document.onselectstart = function () {};
}
var pastebin = Editor_Paste_GetElem(api, true);
pastebin.style.display = "block";
pastebin.focus();
var selection = window.getSelection();
var rangeToSelect = document.createRange();
rangeToSelect.selectNodeContents(pastebin);
selection.removeAllRanges();
selection.addRange(rangeToSelect);
document.execCommand("paste");
if (!window.USER_AGENT_SAFARI_MACOS) {
pastebin.blur();
}
pastebin.style.display = ELEMENT_DISPAY_STYLE;
document.body.style.MozUserSelect = "none";
document.body.style["-khtml-user-select"] = "none";
document.body.style["-o-user-select"] = "none";
document.body.style["user-select"] = "none";
document.body.style["-webkit-user-select"] = "none";
if (window.USER_AGENT_IE) {
document.onselectstart = function () {
return false;
};
}
History.Create_NewPoint();
Editor_Paste(api, false);
return true;
} else {
var ElemToSelect = document.getElementById(COPY_ELEMENT_ID);
if (ElemToSelect) {
History.Create_NewPoint();
Editor_Paste_Exec(api, ElemToSelect);
}
return true;
}
return false;
}
function CanPaste(oDocument) {
var oTargetDoc = oDocument;
if (g_bIsDocumentCopyPaste) {
if (docpostype_HdrFtr === oTargetDoc.CurPos.Type) {
if (null != oTargetDoc.HdrFtr.CurHdrFtr) {
oTargetDoc = oTargetDoc.HdrFtr.CurHdrFtr.Content;
} else {
return false;
}
}
if (docpostype_FlowObjects == oTargetDoc.CurPos.Type) {
var nType = oTargetDoc.Selection.Data.FlowObject.Get_Type();
if (flowobject_Table == nType) {
var oTable = oTargetDoc.Selection.Data.FlowObject.Table;
if (true == oTable.Selection.Use && table_Selection_Cell == oTable.Selection.Type) {
return false;
}
if (null != oTable.CurCell && null != oTable.CurCell.Content) {
oTargetDoc = oTable.CurCell.Content;
}
}
}
} else {
if (docpostype_FlowObjects == oTargetDoc.CurPos.Type) {
var _cur_slide_elements = oTargetDoc.Slides[oTargetDoc.CurPage].elementsManipulator;
if (_cur_slide_elements.obj != undefined && _cur_slide_elements.obj.txBody && _cur_slide_elements.obj.txBody.content) {
return true;
}
}
}
return true;
}
function Editor_Paste(api, bClean) {
window.GlobalPasteFlagCounter = 1;
var oWordControl = api.WordControl;
oWordControl.bIsEventPaste = false;
var oDocument = oWordControl.m_oLogicDocument;
if (false == CanPaste(oDocument)) {
return;
}
document.body.style.MozUserSelect = "text";
delete document.body.style["-khtml-user-select"];
delete document.body.style["-o-user-select"];
delete document.body.style["user-select"];
document.body.style["-webkit-user-select"] = "text";
if (window.USER_AGENT_IE) {
document.onselectstart = function () {};
}
var Text;
var pastebin = Editor_Paste_GetElem(api, bClean);
pastebin.style.display = "block";
pastebin.focus();
pastebin.appendChild(document.createTextNode("\xa0"));
if (window.getSelection) {
var selection = document.defaultView.getSelection();
selection.removeAllRanges();
var rangeToSelect = document.createRange();
rangeToSelect.selectNodeContents(pastebin);
selection.removeAllRanges();
selection.addRange(rangeToSelect);
} else {
if (document.body.createTextRange) {
var rangeToSelect = document.body.createTextRange();
rangeToSelect.moveToElementText(pastebin);
rangeToSelect.select();
}
}
var func_timeout = function () {
if (PASTE_EMPTY_USE && !oWordControl.bIsEventPaste) {
if (pastebin.innerHTML == " ") {
PASTE_EMPTY_COUNTER++;
if (PASTE_EMPTY_COUNTER < PASTE_EMPTY_COUNTER_MAX) {
window.PasteEndTimerId = window.setTimeout(func_timeout, 100);
return;
}
}
}
if (window.USER_AGENT_SAFARI_MACOS) {
if (window.GlobalPasteFlagCounter != 2 && !window.GlobalPasteFlag) {
window.PasteEndTimerId = window.setTimeout(func_timeout, 10);
return;
}
}
document.body.style.MozUserSelect = "none";
document.body.style["-khtml-user-select"] = "none";
document.body.style["-o-user-select"] = "none";
document.body.style["user-select"] = "none";
document.body.style["-webkit-user-select"] = "none";
if (window.USER_AGENT_IE) {
document.onselectstart = function () {
return false;
};
}
if (!window.USER_AGENT_SAFARI_MACOS) {
pastebin.onpaste = null;
}
if (!oWordControl.bIsEventPaste) {
Editor_Paste_Exec(api, pastebin);
} else {
pastebin.style.display = ELEMENT_DISPAY_STYLE;
}
window.PasteEndTimerId = -1;
};
var _interval_time = window.USER_AGENT_MACOS ? 200 : 0;
if (-1 != window.PasteEndTimerId) {
clearTimeout(window.PasteEndTimerId);
}
PASTE_EMPTY_COUNTER = 0;
window.PasteEndTimerId = window.setTimeout(func_timeout, _interval_time);
}
function CopyPasteCorrectString(str) {
var res = str;
res = res.replace(/&/g, "&");
res = res.replace(//g, ">");
res = res.replace(/'/g, "'");
res = res.replace(/"/g, """);
return res;
}
function Body_Paste(api, e) {
var oWordControl = api.WordControl;
if (e && e.clipboardData && e.clipboardData.getData) {
var bExist = false;
var is_chrome = AscBrowser.isChrome;
var sHtml = null;
var fPasteHtml = function (sHtml) {
if (null != sHtml) {
var ifr = document.getElementById("pasteFrame");
if (!ifr) {
ifr = document.createElement("iframe");
ifr.name = "pasteFrame";
ifr.id = "pasteFrame";
ifr.style.position = "absolute";
ifr.style.top = "-100px";
ifr.style.left = "0px";
ifr.style.width = "10000px";
ifr.style.height = "100px";
ifr.style.overflow = "hidden";
ifr.style.zIndex = -1000;
document.body.appendChild(ifr);
}
var frameWindow = window.frames["pasteFrame"];
if (frameWindow) {
frameWindow.document.open();
frameWindow.document.write(sHtml);
frameWindow.document.close();
if (null != frameWindow.document && null != frameWindow.document.body) {
ifr.style.display = "block";
Editor_Paste_Exec(api, frameWindow.document.body, ifr);
bExist = true;
}
}
}
if (bExist) {
oWordControl.bIsEventPaste = true;
if (e.preventDefault) {
e.stopPropagation();
e.preventDefault();
}
return false;
}
};
var fTest = function (types, sPattern) {
if (!types) {
return false;
}
for (var i = 0, length = types.length; i < length; ++i) {
if (sPattern == types[i]) {
return true;
}
}
return false;
};
if (fTest(e.clipboardData.types, "text/html")) {
var sHtml = e.clipboardData.getData("text/html");
var nIndex = sHtml.lastIndexOf("