/*
* (c) Copyright Ascensio System SIA 2010-2015
*
* 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
*
*/
"use strict";
(function ($, window, undefined) {
var doc = window.document;
var isTruePaste = false;
var activateLocalStorage = false;
var isOnlyLocalBufferSafari = false;
var copyPasteUseBinary = true;
var copyPasteFromWordUseBinary = true;
var Base64 = {
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
encode: function (input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
input = Base64._utf8_encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else {
if (isNaN(chr3)) {
enc4 = 64;
}
}
output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
}
return output;
},
decode: function (input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < input.length) {
enc1 = this._keyStr.indexOf(input.charAt(i++));
enc2 = this._keyStr.indexOf(input.charAt(i++));
enc3 = this._keyStr.indexOf(input.charAt(i++));
enc4 = this._keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
}
output = Base64._utf8_decode(output);
return output;
},
_utf8_encode: function (string) {
string = string.replace(/\r\n/g, "\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
} else {
if ((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
} else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
}
return utftext;
},
_utf8_decode: function (utftext) {
var string = "";
var i = 0;
var c1, c2, c3;
while (i < utftext.length) {
c1 = utftext.charCodeAt(i);
if (c1 < 128) {
string += String.fromCharCode(c1);
i++;
} else {
if ((c1 > 191) && (c1 < 224)) {
c2 = utftext.charCodeAt(i + 1);
string += String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
i += 2;
} else {
c2 = utftext.charCodeAt(i + 1);
c3 = utftext.charCodeAt(i + 2);
string += String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
}
return string;
}
};
function number2color(n) {
if (typeof(n) == "string" && n.indexOf("rgb") > -1) {
return n;
}
return "rgb(" + (n >> 16 & 255) + "," + (n >> 8 & 255) + "," + (n & 255) + ")";
}
function Clipboard() {
this.element = undefined;
this.ppix = 96;
this.ppiy = 96;
this.Api = null;
this.fullUrl;
this.activeRange = null;
this.lStorage = {};
this.fontsNew = {};
return this;
}
Clipboard.prototype = {
constructor: Clipboard,
init: function () {
var t = this;
var found = true;
if (!t.element) {
t.element = doc.getElementById(COPY_ELEMENT_ID2);
if (!t.element) {
found = false;
t.element = doc.createElement("DIV");
}
}
t.element.id = COPY_ELEMENT_ID2;
t.element.setAttribute("class", COPYPASTE_ELEMENT_CLASS);
t.element.style.position = "absolute";
t.element.style.top = "-100px";
t.element.style.left = "0px";
if (window.USER_AGENT_MACOS) {
t.element.style.width = "100px";
} else {
t.element.style.width = "10000px";
}
t.element.style.height = "100px";
t.element.style.overflow = "hidden";
t.element.style.zIndex = -1000;
t.element.style.display = ELEMENT_DISPAY_STYLE2;
t.element.setAttribute("contentEditable", true);
if (!found) {
doc.body.appendChild(t.element);
}
if (!AscBrowser.isMobileVersion) {
var foundText = true;
if (!t.elementText) {
t.elementText = doc.getElementById(kElementTextId);
if (!t.elementText) {
foundText = false;
t.elementText = doc.createElement("textarea");
}
}
t.elementText.id = kElementTextId;
t.elementText.style.position = "absolute";
if (window.USER_AGENT_MACOS) {
t.element.style.width = "100px";
} else {
t.element.style.width = "10000px";
}
t.elementText.style.height = "100px";
t.elementText.style.left = "0px";
t.elementText.style.top = "-100px";
t.elementText.style.overflow = "hidden";
t.elementText.style.zIndex = -1000;
t.elementText.style.display = ELEMENT_DISPAY_STYLE2;
t.elementText.setAttribute("contentEditable", true);
if (!foundText) {
doc.body.appendChild(t.elementText);
}
}
var div = doc.createElement("DIV");
div.setAttribute("style", "position:absolute; visibility:hidden; padding:0; height:1in; width:1in;");
doc.body.appendChild(div);
this.ppix = div.clientWidth;
this.ppiy = div.clientHeight;
doc.body.removeChild(div);
},
destroy: function () {
var p;
if (this.element) {
p = this.element.parentNode;
if (p) {
p.removeChild(this.element);
}
this.element = undefined;
}
},
copyRange: function (range, worksheet, isCut) {
var t = this;
t._cleanElement();
var objectRender = worksheet.objectRender;
var isIntoShape = objectRender.controller.getTargetDocContent();
var text = t._makeTableNode(range, worksheet, isCut, isIntoShape);
if (text == false) {
return;
}
if (window.USER_AGENT_SAFARI_MACOS && !worksheet.isCellEditMode) {
this._startCopyOrPaste();
this.element.appendChild(text);
History.TurnOff();
var sBase64 = this._getBinaryForCopy(worksheet);
if (isIntoShape) {
sBase64 = null;
}
if (sBase64) {
if (this.element.children && this.element.children.length == 1 && (window.USER_AGENT_WEBKIT || window.USER_AGENT_SAFARI_MACOS)) {
$(this.element.children[0]).css("font-weight", "normal");
$(this.element.children[0]).wrap(document.createElement("b"));
}
if (this.element.children[0]) {
$(this.element.children[0]).addClass("xslData;" + sBase64);
}
this.lStorage = sBase64;
}
History.TurnOn();
this._endCopyOrPaste();
return sBase64;
} else {
this._startCopyOrPaste();
if ($(text).find("td")[0] && $(text).find("td")[0].innerText == "" && AscBrowser.isOpera) {
$(text).find("td")[0].innerHTML = " ";
}
t.element.appendChild(text);
if (!copyPasteUseBinary) {
t.copyText = t._getTextFromTable(t.element.children[0]);
var randomVal = Math.floor(Math.random() * 10000000);
t.copyText.pasteFragment = "pasteFragment_" + randomVal;
if (text) {
$(text).addClass("pasteFragment_" + randomVal);
}
}
if ($(text).find("img")[0] && AscBrowser.isOpera) {
$(text)[0].innerHTML = "
|
";
if (t.copyText.isImage) {
t.copyText.text = " ";
}
}
History.TurnOff();
if (copyPasteUseBinary) {
if (isIntoShape) {
this.lStorage = {};
this.lStorage.htmlInShape = text;
} else {
var sBase64 = this._getBinaryForCopy(worksheet);
if (this.element.children && this.element.children.length == 1 && (window.USER_AGENT_WEBKIT || window.USER_AGENT_SAFARI_MACOS)) {
$(this.element.children[0]).css("font-weight", "normal");
$(this.element.children[0]).wrap(document.createElement("b"));
}
if (this.element.children[0]) {
$(this.element.children[0]).addClass("xslData;" + sBase64);
}
this.lStorage = sBase64;
}
}
History.TurnOn();
if (AscBrowser.isMozilla) {
t._selectElement(t._getStylesSelect);
} else {
t._selectElement();
}
this._endCopyOrPaste();
}
},
_getBinaryForCopy: function (worksheet) {
var fullUrl = this._getUseFullUrl();
window.global_pptx_content_writer.Start_UseFullUrl(fullUrl);
var cloneActiveRange = worksheet.activeRange.clone();
var temp;
if (cloneActiveRange.c1 > cloneActiveRange.c2) {
temp = cloneActiveRange.c1;
cloneActiveRange.c1 = cloneActiveRange.c2;
cloneActiveRange.c2 = temp;
}
if (cloneActiveRange.r1 > cloneActiveRange.r2) {
temp = cloneActiveRange.r1;
cloneActiveRange.r1 = cloneActiveRange.r2;
cloneActiveRange.r2 = temp;
}
var oBinaryFileWriter = new Asc.BinaryFileWriter(worksheet.model.workbook, cloneActiveRange);
var sBase64 = oBinaryFileWriter.Write();
window.global_pptx_content_writer.End_UseFullUrl();
return sBase64;
},
copyRangeButton: function (range, worksheet, isCut) {
if (AscBrowser.isIE) {
this._cleanElement();
var text = this._makeTableNode(range, worksheet);
if (text == false) {
return true;
}
this.element.appendChild(text);
if (copyPasteUseBinary) {
if (isIntoShape) {
this.lStorage = {};
this.lStorage.htmlInShape = text;
} else {
var fullUrl = this._getUseFullUrl();
window.global_pptx_content_writer.Start_UseFullUrl(fullUrl);
var oBinaryFileWriter = new Asc.BinaryFileWriter(worksheet.model.workbook, worksheet.activeRange);
var sBase64 = oBinaryFileWriter.Write();
if (this.element.children && this.element.children.length == 1 && window.USER_AGENT_WEBKIT && (true !== window.USER_AGENT_SAFARI_MACOS)) {
$(this.element.children[0]).css("font-weight", "normal");
$(this.element.children[0]).wrap(document.createElement("b"));
}
if (this.element.children[0]) {
$(this.element.children[0]).addClass("xslData;" + sBase64);
}
this.lStorage = sBase64;
window.global_pptx_content_writer.End_UseFullUrl();
}
}
var t = this,
selection, rangeToSelect, overflowBody;
overflowBody = document.body.style.overflow;
document.body.style.overflow = "hidden";
if (window.getSelection) {
selection = window.getSelection();
rangeToSelect = doc.createRange();
if (AscBrowser.isGecko) {
t.element.appendChild(doc.createTextNode("\xa0"));
t.element.insertBefore(doc.createTextNode("\xa0"), t.element.firstChild);
rangeToSelect.setStartAfter(t.element.firstChild);
rangeToSelect.setEndBefore(t.element.lastChild);
} else {
rangeToSelect.selectNodeContents(t.element);
}
selection.removeAllRanges();
selection.addRange(rangeToSelect);
} else {
if (doc.body.createTextRange) {
rangeToSelect = doc.body.createTextRange();
rangeToSelect.moveToElementText(t.element);
rangeToSelect.select();
}
}
document.execCommand("copy");
window.setTimeout(function () {
document.body.style.overflow = overflowBody;
t.element.style.display = "none";
doc.body.style.MozUserSelect = "none";
doc.body.style["-khtml-user-select"] = "none";
doc.body.style["-o-user-select"] = "none";
doc.body.style["user-select"] = "none";
doc.body.style["-webkit-user-select"] = "none";
},
0);
return true;
} else {
if (copyPasteUseBinary) {
var t = this;
var objectRender = worksheet.objectRender;
var isIntoShape = objectRender.controller.getTargetDocContent();
var text = t._makeTableNode(range, worksheet, isCut, isIntoShape);
if (text == false) {
return true;
}
if (isIntoShape) {
this.lStorage = {};
this.lStorage.htmlInShape = text;
} else {
var fullUrl = this._getUseFullUrl();
window.global_pptx_content_writer.Start_UseFullUrl(fullUrl);
var oBinaryFileWriter = new Asc.BinaryFileWriter(worksheet.model.workbook, worksheet.activeRange);
var sBase64 = oBinaryFileWriter.Write();
this.lStorage = sBase64;
window.global_pptx_content_writer.End_UseFullUrl();
}
while (this.element.hasChildNodes()) {
this.element.removeChild(this.element.lastChild);
}
if (text !== false) {
this.element.appendChild(text);
}
if (this.element.children[0] && sBase64) {
$(this.element.children[0]).addClass("xslData;" + sBase64);
}
return true;
} else {
if (activateLocalStorage) {
var t = this;
var table = t._makeTableNode(range, worksheet, isCut);
if (table !== false) {
t.copyText = t._getTextFromTable(table);
}
return true;
}
}
}
return false;
},
pasteRange: function (worksheet) {
var t = this;
if (AscBrowser.isMozilla) {
t._editorPaste(worksheet, t._getStylesSelect);
} else {
t._editorPaste(worksheet);
}
},
pasteRangeButton: function (worksheet) {
if (AscBrowser.isIE) {
var t = this;
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";
var pastebin = t._editorPasteGetElem(worksheet, 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");
pastebin.blur();
pastebin.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";
t._editorPasteExec(worksheet, pastebin);
return true;
} else {
if (activateLocalStorage || copyPasteUseBinary) {
var t = this;
var onlyFromLocalStorage = true;
t._editorPasteExec(worksheet, t.lStorage, false, onlyFromLocalStorage);
return true;
}
}
return false;
},
copyCellValue: function (value) {
var t = this;
t._startCopyOrPaste();
if (activateLocalStorage || copyPasteUseBinary) {
t._addValueToLocalStrg(value);
}
var nodes = t._makeNodesFromCellValue(value);
var outer;
if (AscBrowser.isWebkit && nodes.length === 1) {
outer = doc.createElement("B");
outer.style.fontWeight = "normal";
outer.appendChild(nodes[0]);
nodes[0] = outer;
}
t._cleanElement();
nodes.forEach(function (node) {
t.element.appendChild(node);
});
if (AscBrowser.isMozilla) {
t._selectElement(t._getStylesSelect, true);
} else {
t._selectElement();
}
this._endCopyOrPaste();
},
copyCellValueButton: function (value) {
if (AscBrowser.isIE) {
var t = this;
var nodes = t._makeNodesFromCellValue(value);
var outer;
if (AscBrowser.isWebkit && nodes.length === 1) {
outer = doc.createElement("B");
outer.style.fontWeight = "normal";
outer.appendChild(nodes[0]);
nodes[0] = outer;
}
while (this.element.hasChildNodes()) {
this.element.removeChild(this.element.lastChild);
}
nodes.forEach(function (node) {
t.element.appendChild(node);
});
var t = this,
selection, rangeToSelect;
if (window.getSelection) {
selection = window.getSelection();
rangeToSelect = doc.createRange();
if (AscBrowser.isGecko) {
t.element.appendChild(doc.createTextNode("\xa0"));
t.element.insertBefore(doc.createTextNode("\xa0"), t.element.firstChild);
rangeToSelect.setStartAfter(t.element.firstChild);
rangeToSelect.setEndBefore(t.element.lastChild);
} else {
rangeToSelect.selectNodeContents(t.element);
}
selection.removeAllRanges();
selection.addRange(rangeToSelect);
} else {
if (doc.body.createTextRange) {
rangeToSelect = doc.body.createTextRange();
rangeToSelect.moveToElementText(t.element);
rangeToSelect.select();
}
}
document.execCommand("copy");
window.setTimeout(function () {
t.element.style.display = "none";
doc.body.style.MozUserSelect = "none";
doc.body.style["-khtml-user-select"] = "none";
doc.body.style["-o-user-select"] = "none";
doc.body.style["user-select"] = "none";
doc.body.style["-webkit-user-select"] = "none";
},
0);
return true;
} else {
if (activateLocalStorage || copyPasteUseBinary) {
var t = this;
t._addValueToLocalStrg(value);
var nodes = t._makeNodesFromCellValue(value);
while (t.element.hasChildNodes()) {
t.element.removeChild(t.element.lastChild);
}
nodes.forEach(function (node) {
t.element.appendChild(node);
});
return true;
}
}
return false;
},
pasteAsText: function (callback) {
var t = this;
t.elementText.style.display = "block";
t._startCopyOrPaste();
t.elementText.value = "\xa0";
t.elementText.focus();
t.elementText.select();
delete doc.body.style["-khtml-user-select"];
delete doc.body.style["-o-user-select"];
delete doc.body.style["user-select"];
doc.body.style["-webkit-user-select"] = "text";
doc.body.style.MozUserSelect = "text";
var _interval_time = 0;
if (AscBrowser.isMozilla) {
_interval_time = 10;
} else {
if (window.USER_AGENT_MACOS && window.USER_AGENT_WEBKIT) {
_interval_time = 200;
}
}
window.setTimeout(function () {
t.element.style.display = ELEMENT_DISPAY_STYLE2;
doc.body.style.MozUserSelect = "none";
doc.body.style["-khtml-user-select"] = "none";
doc.body.style["-o-user-select"] = "none";
doc.body.style["user-select"] = "none";
doc.body.style["-webkit-user-select"] = "none";
t.elementText.style.display = ELEMENT_DISPAY_STYLE2;
var textInsert = t.elementText.value;
if (isOnlyLocalBufferSafari && navigator.userAgent.toLowerCase().indexOf("safari") > -1 && navigator.userAgent.toLowerCase().indexOf("mac") && t.lStorageText) {
textInsert = t.lStorageText;
}
if (callback) {
callback(textInsert, []);
}
if (AscBrowser.isMozilla) {
t._getStylesSelect();
}
t._endCopyOrPaste();
},
_interval_time);
},
pasteAsTextButton: function (callback) {
var t = this;
if (AscBrowser.isIE) {
t.elementText.style.display = "block";
t.elementText.value = "\xa0";
t.elementText.focus();
t.elementText.select();
delete doc.body.style["-khtml-user-select"];
delete doc.body.style["-o-user-select"];
delete doc.body.style["user-select"];
doc.body.style["-webkit-user-select"] = "text";
doc.body.style.MozUserSelect = "text";
document.execCommand("paste");
window.setTimeout(function () {
t.element.style.display = "none";
doc.body.style.MozUserSelect = "none";
doc.body.style["-khtml-user-select"] = "none";
doc.body.style["-o-user-select"] = "none";
doc.body.style["user-select"] = "none";
doc.body.style["-webkit-user-select"] = "none";
t.elementText.style.display = "none";
callback(t.elementText.value, []);
},
0);
return true;
} else {
if (activateLocalStorage || copyPasteUseBinary) {
if (t.lStorageText) {
callback(t.lStorageText, []);
}
return true;
}
}
return false;
},
bIsEmptyClipboard: function (isCellEditMode) {
var result = false;
if (isCellEditMode && (!t.lStorageText || t.lStorageText == null || t.lStorageText == "")) {
result = true;
} else {
if (!isCellEditMode && !t.lStorage) {
result = true;
}
}
return result;
},
_cleanElement: function () {
if (!window.USER_AGENT_SAFARI_MACOS) {
this.element.style.left = "0px";
this.element.style.top = "-100px";
}
this.element.style.display = "block";
while (this.element.hasChildNodes()) {
this.element.removeChild(this.element.lastChild);
}
delete doc.body.style["-khtml-user-select"];
delete doc.body.style["-o-user-select"];
delete doc.body.style["user-select"];
doc.body.style["-webkit-user-select"] = "text";
doc.body.style.MozUserSelect = "text";
this.element.style.MozUserSelect = "all";
},
_getUseFullUrl: function (recalculate) {
if (this.fullUrl == undefined || recalculate === true) {
var api = window["Asc"]["editor"];
var sProtocol = window.location.protocol;
var documentOrigin;
var sHost = window.location.host;
documentOrigin = "";
if (sProtocol && "" != sProtocol) {
documentOrigin = sProtocol + "//" + sHost;
} else {
documentOrigin = sHost;
}
this.fullUrl = documentOrigin + g_sResourceServiceLocalUrl + api.documentId + "/";
}
return this.fullUrl;
},
_getStylesSelect: function (worksheet) {
document.body.style.MozUserSelect = "";
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";
},
_editorPaste: function (worksheet, callback) {
if (window.USER_AGENT_SAFARI_MACOS) {
return;
}
this._startCopyOrPaste();
var t = this;
window.GlobalPasteFlagCounter = 1;
isTruePaste = false;
var is_chrome = AscBrowser.isChrome;
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";
var overflowBody = document.body.style.overflow;
document.body.style.overflow = "hidden";
var Text;
var pastebin = t._editorPasteGetElem(worksheet, true);
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 && !isTruePaste) {
if (pastebin.innerHTML == " ") {
PASTE_EMPTY_COUNTER++;
if (PASTE_EMPTY_COUNTER < PASTE_EMPTY_COUNTER_MAX) {
window.setTimeout(func_timeout, 100);
return;
}
}
}
if (window.USER_AGENT_SAFARI_MACOS) {
if (window.GlobalPasteFlagCounter != 2 && !window.GlobalPasteFlag) {
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";
document.body.style.overflow = overflowBody;
if (!isTruePaste) {
t._editorPasteExec(worksheet, pastebin);
}
t._endCopyOrPaste();
pastebin.style.display = ELEMENT_DISPAY_STYLE2;
if (AscBrowser.isIE) {
pastebin.style.display = ELEMENT_DISPAY_STYLE2;
}
if (callback && callback.call) {
callback();
}
};
var _interval_time = window.USER_AGENT_MACOS ? 200 : 100;
PASTE_EMPTY_COUNTER = 0;
window.setTimeout(func_timeout, _interval_time);
},
_editorPasteGetElem: function (worksheet, bClean) {
var t = this;
var pastebin = document.getElementById(PASTE_ELEMENT_ID2);
if (!pastebin) {
pastebin = document.createElement("div");
pastebin.setAttribute("id", PASTE_ELEMENT_ID2);
pastebin.setAttribute("class", COPYPASTE_ELEMENT_CLASS);
pastebin.style.position = "absolute";
pastebin.style.top = "100px";
pastebin.style.left = "0px";
if (window.USER_AGENT_MACOS) {
t.element.style.width = "100px";
} else {
t.element.style.width = "10000px";
}
pastebin.style.height = "100px";
pastebin.style.overflow = "hidden";
pastebin.style.zIndex = -1000;
pastebin.style.lineHeight = "1px";
pastebin.setAttribute("contentEditable", true);
pastebin.onpaste = function (e) {
if (!window.GlobalPasteFlag) {
return;
}
t._bodyPaste(worksheet, e);
pastebin.onpaste = null;
};
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]);
}
pastebin.onpaste = function (e) {
if (!window.GlobalPasteFlag) {
return;
}
t._bodyPaste(worksheet, e);
pastebin.onpaste = null;
};
}
}
return pastebin;
},
_getTableFromText: function (sText) {
var t = this;
var sHtml = "";
var sCurPar = "";
var sCurChar = "";
for (var i = 0, length = sText.length; i < length; i++) {
var Char = sText.charAt(i);
var Code = sText.charCodeAt(i);
var Item = null;
if ("\n" === Char) {
if ("" == sCurChar && sCurPar == "") {
sHtml += " |
";
} else {
if (sCurPar == "") {
sHtml += "" + sCurChar + " |
";
sCurChar = "";
} else {
if (sCurPar != "") {
if (sCurChar == "") {
sCurPar += " | ";
} else {
sCurPar += "" + sCurChar + " | ";
}
sHtml += "" + sCurPar + "
";
sCurChar = "";
sCurPar = "";
}
}
}
} else {
if (13 === Code) {
continue;
} else {
if (32 == Code || 160 == Code) {
sCurChar += " ";
} else {
if (9 === Code) {
sCurPar += "" + sCurChar + " | ";
if (i == length - 1) {
sHtml += "" + sCurPar + "
";
}
sCurChar = "";
} else {
sCurChar += t._copyPasteCorrectString(Char);
if (i == length - 1) {
sCurPar += "" + sCurChar + " | ";
sHtml += "" + sCurPar + "
";
}
}
}
}
}
}
sHtml += "
";
return sHtml;
},
_getTextFromTable: function (table) {
var images = $(table).find("img");
if (images.length != 0 && images.length == $(table).children().length) {
var stringImg = {};
stringImg.isImage = true;
stringImg.text = "";
for (var i = 0; i < images.length; i++) {
stringImg.text += images[i].name + ";";
}
return stringImg;
}
if (table.children && table.children[0] && table.children[0].nodeName.toLowerCase() == "br") {
$(table.children[0]).remove();
}
if ((table.children[0] && table.children[0].tagName.toLowerCase() == "table" && table.children.length == 1)) {
table = table.children[0];
}
var textNode = {};
if (table.tagName.toLowerCase() != "table") {
textNode.text = $(table).text();
} else {
textNode.text = $(table).text();
if (table.rows) {
textNode.rows = table.rows.length;
} else {
textNode.rows = 0;
}
if (table.rows[0] && table.rows[0].cells) {
textNode.cols = table.rows[0].cells.length + table.rows[0].cells[0].colSpan - 1;
}
}
return textNode;
},
_bodyPaste: function (worksheet, e) {
var t = this;
if (e && e.clipboardData && e.clipboardData.getData) {
var bExist = false;
var is_chrome = AscBrowser.isChrome;
var sHtml = null;
var isText = 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("