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

cell/model/clipboard to function-closure

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