Commit 04304c6a authored by Alexander.Trofimov's avatar Alexander.Trofimov

cell/model/clipboard to function-closure

parent 7ab18ea3
......@@ -1080,7 +1080,7 @@ var editor;
}
if (window.USER_AGENT_SAFARI_MACOS) {
setInterval(SafariIntervalFocus2, 10);
setInterval(AscCommonExcel.SafariIntervalFocus2, 10);
}
};
......
......@@ -44,6 +44,15 @@
var copyPasteUseBinary = true;
var copyPasteFromWordUseBinary = true;
var COPY_ELEMENT_ID2 = "clipboard-helper";
var kElementTextId = "clipboard-helper-text";
var isNeedEmptyAfterCut = false;
if (window.USER_AGENT_SAFARI_MACOS)
{
PASTE_ELEMENT_ID = COPY_ELEMENT_ID2;
}
function number2color(n) {
if( typeof(n)=="string" && n.indexOf("rgb")>-1)
return n;
......@@ -5146,207 +5155,200 @@
}
};
/*
* Export
* -----------------------------------------------------------------------------
*/
window["Asc"].CopyProcessor = CopyProcessor;
window["Asc"].Clipboard = Clipboard;
window["Asc"].pasteFromBinaryWord = pasteFromBinaryWord;
window["Asc"].DocumentContentBounds = DocumentContentBounds;
}
)(jQuery, window);
function SafariIntervalFocus2()
{
var api = window["Asc"]["editor"];
if (api)
{
if((api.wb && api.wb.cellEditor && api.wb.cellEditor != null && api.wb.cellEditor.isTopLineActive) || (api.wb && api.wb.getWorksheet() && api.wb.getWorksheet().isSelectionDialogMode))
return;
var pastebin = document.getElementById(COPY_ELEMENT_ID2);
var pastebinText = document.getElementById(kElementTextId);
if(pastebinText && (api.wb && api.wb.getCellEditMode()) && api.IsFocus)
{
pastebinText.focus();
}
else if (pastebin && api.IsFocus)
pastebin.focus();
else if(!pastebin || !pastebinText)
{
// create
Editor_CopyPaste_Create2(api);
}
}
}
var COPY_ELEMENT_ID2 = "clipboard-helper";
var kElementTextId = "clipboard-helper-text";
var isNeedEmptyAfterCut = false;
if (window.USER_AGENT_SAFARI_MACOS)
{
PASTE_ELEMENT_ID = COPY_ELEMENT_ID2;
}
function SafariIntervalFocus2()
{
var api = window["Asc"]["editor"];
if (api)
{
if((api.wb && api.wb.cellEditor && api.wb.cellEditor != null && api.wb.cellEditor.isTopLineActive) || (api.wb && api.wb.getWorksheet() && api.wb.getWorksheet().isSelectionDialogMode))
return;
var pastebin = document.getElementById(COPY_ELEMENT_ID2);
var pastebinText = document.getElementById(kElementTextId);
if(pastebinText && (api.wb && api.wb.getCellEditMode()) && api.IsFocus)
function Editor_Copy_Event_Excel(e, ElemToSelect, isCut, isAlreadyReadyHtml)
{
pastebinText.focus();
}
else if (pastebin && api.IsFocus)
pastebin.focus();
else if(!pastebin || !pastebinText)
{
// create
Editor_CopyPaste_Create2(api);
}
}
}
function Editor_Copy_Event_Excel(e, ElemToSelect, isCut, isAlreadyReadyHtml)
{
var api = window["Asc"]["editor"];
var wb = api.wb;
var ws = wb.getWorksheet();
var sBase64;
if(!isAlreadyReadyHtml)
{
if (window["AscDesktopEditorButtonMode"] === true && window["AscDesktopEditor"])
sBase64 = wb.clipboard._getHtmlBase64(ws.getSelectedRange(), ws, isCut, true);
else
sBase64 = wb.clipboard.copyRange(ws.getSelectedRange(), ws, isCut, true);
}
var api = window["Asc"]["editor"];
var wb = api.wb;
var ws = wb.getWorksheet();
if(isCut)
ws.emptySelection(Asc.c_oAscCleanOptions.All);
if(sBase64)
e.clipboardData.setData("text/x-custom", sBase64);
e.clipboardData.setData("text/html", ElemToSelect.innerHTML);
//TODO для вставки в ячейку(пересмотреть!!!)
e.clipboardData.setData("text/plain", ElemToSelect.innerText);
}
function Editor_CopyPaste_Create2(api)
{
var ElemToSelect = document.createElement("div");
ElemToSelect.id = COPY_ELEMENT_ID2;
ElemToSelect.setAttribute("class", COPYPASTE_ELEMENT_CLASS);
ElemToSelect.style.left = '0px';
ElemToSelect.style.top = '100px';
if(window.USER_AGENT_MACOS)
ElemToSelect.style.width = '1000px';
else
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);
ElemToSelect.style.lineHeight = "1px";
ElemToSelect.oncopy = function(e){
var api = window["Asc"]["editor"];
if(api.controller.isCellEditMode)
return;
Editor_Copy_Event_Excel(e, ElemToSelect);
e.preventDefault();
};
ElemToSelect.oncut = function(e){
var api = window["Asc"]["editor"];
if(api.controller.isCellEditMode)
return;
Editor_Copy_Event_Excel(e, ElemToSelect, true);
e.preventDefault();
};
ElemToSelect.onpaste = function(e){
var api = window["Asc"]["editor"];
var wb = api.wb;
var ws = wb.getWorksheet();
wb.clipboard._bodyPaste(ws,e);
e.preventDefault();
};
ElemToSelect["onbeforecut"] = function(e){
var api = window["Asc"]["editor"];
if(api.controller.isCellEditMode)
return;
var selection = window.getSelection();
var rangeToSelect = document.createRange();
var sBase64;
if(!isAlreadyReadyHtml)
{
if (window["AscDesktopEditorButtonMode"] === true && window["AscDesktopEditor"])
sBase64 = wb.clipboard._getHtmlBase64(ws.getSelectedRange(), ws, isCut, true);
else
sBase64 = wb.clipboard.copyRange(ws.getSelectedRange(), ws, isCut, true);
}
ElemToSelect.innerText = "&nbsp";
rangeToSelect.selectNodeContents (ElemToSelect);
selection.removeAllRanges ();
selection.addRange (rangeToSelect);
};
if(isCut)
ws.emptySelection(Asc.c_oAscCleanOptions.All);
ElemToSelect["onbeforecopy"] = function(e){
var api = window["Asc"]["editor"];
if(api.controller.isCellEditMode)
return;
var selection = window.getSelection();
var rangeToSelect = document.createRange();
ElemToSelect.innerText = "&nbsp";
if(sBase64)
e.clipboardData.setData("text/x-custom", sBase64);
e.clipboardData.setData("text/html", ElemToSelect.innerHTML);
//TODO для вставки в ячейку(пересмотреть!!!)
e.clipboardData.setData("text/plain", ElemToSelect.innerText);
}
rangeToSelect.selectNodeContents (ElemToSelect);
function Editor_CopyPaste_Create2(api)
{
var ElemToSelect = document.createElement("div");
ElemToSelect.id = COPY_ELEMENT_ID2;
ElemToSelect.setAttribute("class", COPYPASTE_ELEMENT_CLASS);
ElemToSelect.style.left = '0px';
ElemToSelect.style.top = '100px';
if(window.USER_AGENT_MACOS)
ElemToSelect.style.width = '1000px';
else
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);
ElemToSelect.style.lineHeight = "1px";
ElemToSelect.oncopy = function(e){
var api = window["Asc"]["editor"];
if(api.controller.isCellEditMode)
return;
selection.removeAllRanges ();
selection.addRange (rangeToSelect);
};
document.body.appendChild( ElemToSelect );
//******для редактора ячейки
var elementText = document.createElement("textarea");
Editor_Copy_Event_Excel(e, ElemToSelect);
e.preventDefault();
};
elementText.id = kElementTextId;
elementText.style.position = "absolute";
ElemToSelect.oncut = function(e){
var api = window["Asc"]["editor"];
if(api.controller.isCellEditMode)
return;
if(window.USER_AGENT_MACOS)
ElemToSelect.style.width = '100px';
else
ElemToSelect.style.width = '10000px';
elementText.style.height = '100px';
elementText.style.left = '0px';
elementText.style.top = '100px';
elementText.style.overflow = 'hidden';
elementText.style.zIndex = -1000;
elementText.style.display = ELEMENT_DISPAY_STYLE;
elementText.setAttribute("contentEditable", true);
elementText.setAttribute("class", COPYPASTE_ELEMENT_CLASS);
elementText["onbeforecopy"] = function(e){
if((api.wb && api.wb.getWorksheet() && api.wb.getWorksheet().isCellEditMode))
{
var v = api.wb.cellEditor.copySelection();
if (v) {api.wb.clipboard.copyCellValue(v);}
}
};
elementText["onbeforecut"] = function(e){
api.wb.clipboard.copyRange(api.wb.getWorksheet().getSelectedRange(), api.wb.getWorksheet());
if(isNeedEmptyAfterCut == true)
{
isNeedEmptyAfterCut = false;
if((api.wb && api.wb.getWorksheet() && api.wb.getWorksheet().isCellEditMode))
{
var v = api.wb.cellEditor.cutSelection();
if (v) {api.wb.clipboard.copyCellValue(v);}
}
Editor_Copy_Event_Excel(e, ElemToSelect, true);
e.preventDefault();
};
ElemToSelect.onpaste = function(e){
var api = window["Asc"]["editor"];
var wb = api.wb;
var ws = wb.getWorksheet();
wb.clipboard._bodyPaste(ws,e);
e.preventDefault();
};
ElemToSelect["onbeforecut"] = function(e){
var api = window["Asc"]["editor"];
if(api.controller.isCellEditMode)
return;
var selection = window.getSelection();
var rangeToSelect = document.createRange();
ElemToSelect.innerText = "&nbsp";
rangeToSelect.selectNodeContents (ElemToSelect);
selection.removeAllRanges ();
selection.addRange (rangeToSelect);
};
ElemToSelect["onbeforecopy"] = function(e){
var api = window["Asc"]["editor"];
if(api.controller.isCellEditMode)
return;
var selection = window.getSelection();
var rangeToSelect = document.createRange();
ElemToSelect.innerText = "&nbsp";
rangeToSelect.selectNodeContents (ElemToSelect);
selection.removeAllRanges ();
selection.addRange (rangeToSelect);
};
document.body.appendChild( ElemToSelect );
//******для редактора ячейки
var elementText = document.createElement("textarea");
elementText.id = kElementTextId;
elementText.style.position = "absolute";
if(window.USER_AGENT_MACOS)
ElemToSelect.style.width = '100px';
else
ElemToSelect.style.width = '10000px';
elementText.style.height = '100px';
elementText.style.left = '0px';
elementText.style.top = '100px';
elementText.style.overflow = 'hidden';
elementText.style.zIndex = -1000;
elementText.style.display = ELEMENT_DISPAY_STYLE;
elementText.setAttribute("contentEditable", true);
elementText.setAttribute("class", COPYPASTE_ELEMENT_CLASS);
elementText["onbeforecopy"] = function(e){
if((api.wb && api.wb.getWorksheet() && api.wb.getWorksheet().isCellEditMode))
{
var v = api.wb.cellEditor.copySelection();
if (v) {api.wb.clipboard.copyCellValue(v);}
}
};
elementText["onbeforecut"] = function(e){
api.wb.clipboard.copyRange(api.wb.getWorksheet().getSelectedRange(), api.wb.getWorksheet());
if(isNeedEmptyAfterCut == true)
{
isNeedEmptyAfterCut = false;
if((api.wb && api.wb.getWorksheet() && api.wb.getWorksheet().isCellEditMode))
{
var v = api.wb.cellEditor.cutSelection();
if (v) {api.wb.clipboard.copyCellValue(v);}
}
}
else
isNeedEmptyAfterCut = true;
};
document.body.appendChild(elementText);
}
else
isNeedEmptyAfterCut = true;
};
/*
* Export
* -----------------------------------------------------------------------------
*/
window["Asc"].CopyProcessor = CopyProcessor;
window["Asc"].Clipboard = Clipboard;
window["Asc"].pasteFromBinaryWord = pasteFromBinaryWord;
window["Asc"].DocumentContentBounds = DocumentContentBounds;
document.body.appendChild(elementText);
}
\ No newline at end of file
window['AscCommonExcel'] = window['AscCommonExcel'] || {};
window["AscCommonExcel"].SafariIntervalFocus2 = SafariIntervalFocus2;
}
)(jQuery, window);
......@@ -928,7 +928,7 @@
{
if (0 === window.GlobalPasteFlagCounter)
{
SafariIntervalFocus2();
AscCommonExcel.SafariIntervalFocus2();
window.GlobalPasteFlag = true;
t.handlers.trigger("paste");
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment