App-SocialCalc-Multiplayer
view release on metacpan or search on metacpan
socialcalc/socialcalctableeditor.js view on Meta::CPAN
this.firstscrollingcol = null; // column number of top col in last (the scrolling) pane
this.firstscrollingcolleft = null; // position of top col in last (the scrolling) pane
this.lastnonscrollingcol = null; // col number of last displayed column in last non-scrolling
// pane, or zero (for thumb position calculations)
this.lastvisiblecol = null; // used for paging right
this.rowpositions = []; // screen positions of the top of some rows
this.colpositions = []; // screen positions of the left side of some rows
this.rowheight = []; // size in pixels of each row when last checked, or null/undefined, for page up
this.colwidth = []; // size in pixels of each column when last checked, or null/undefined, for page left
this.ecell = null; // either null or {coord: c, row: r, col: c}
this.state = "start"; // the keyboard states: see EditorProcessKey
this.workingvalues = {}; // values used during keyboard editing, etc.
// Constants:
this.imageprefix = scc.defaultImagePrefix; // URL prefix for images (e.g., "/images/sc")
this.idPrefix = scc.defaultTableEditorIDPrefix;
this.pageUpDnAmount = scc.defaultPageUpDnAmount; // number of rows to move cursor on PgUp/PgDn keys (numeric)
// Callbacks
// recalcFunction: if present, function(editor) {...}, called to do a recalc
// Default (sheet.RecalcSheet) does all the right stuff.
this.recalcFunction = function(editor) {
if (editor.context.sheetobj.RecalcSheet) {
editor.context.sheetobj.RecalcSheet(SocialCalc.EditorSheetStatusCallback, editor);
}
else return null;
};
// ctrlkeyFunction: if present, function(editor, charname) {...}, called to handle ctrl-V, etc., at top level
// Returns true (pass through for continued processing) or false (stop processing this key).
this.ctrlkeyFunction = function(editor, charname) {
var ta, ha, cell, position, cmd, sel, cliptext;
switch (charname) {
case "[ctrl-c]":
case "[ctrl-x]":
ta = editor.pasteTextarea;
ta.value = "";
cell=SocialCalc.GetEditorCellElement(editor, editor.ecell.row, editor.ecell.col);
if (cell) {
position = SocialCalc.GetElementPosition(cell.element);
ta.style.left = (position.left-1)+"px";
ta.style.top = (position.top-1)+"px";
}
if (editor.range.hasrange) {
sel = SocialCalc.crToCoord(editor.range.left, editor.range.top)+
":"+SocialCalc.crToCoord(editor.range.right, editor.range.bottom);
}
else {
sel = editor.ecell.coord;
}
// get what to copy to clipboard
cliptext = SocialCalc.ConvertSaveToOtherFormat(SocialCalc.CreateSheetSave(editor.context.sheetobj, sel), "tab");
if (charname == "[ctrl-c]" || editor.noEdit) { // if copy or cut but in no edit
cmd = "copy "+sel+" formulas";
}
else { // [ctrl-x]
cmd = "cut "+sel+" formulas";
}
editor.EditorScheduleSheetCommands(cmd, true, false); // queue up command to put on SocialCalc clipboard
/* Copy as HTML: This fails rather badly as it won't paste into Notepad as tab-delimited text. Oh well.
ha = editor.pasteHTMLarea;
if (editor.range.hasrange) {
cell = SocialCalc.GetEditorCellElement(editor, editor.range.top, editor.range.left);
}
else {
cell = SocialCalc.GetEditorCellElement(editor, editor.ecell.row, editor.ecell.col);
}
if (cell) position = SocialCalc.GetElementPosition(cell.element);
if (ha) {
if (position) {
ha.style.left = (position.left-1)+"px";
ha.style.top = (position.top-1)+"px";
}
ha.style.visibility="visible";
cliptext = SocialCalc.ConvertSaveToOtherFormat(SocialCalc.CreateSheetSave(editor.context.sheetobj, sel), "html");
ha.innerHTML = cliptext.replace(/<tr\b[^>]*>[\d\D]*?<\/tr\b[^>]*>/i, '');
ha.focus();
var range = document.body.createControlRange();
range.addElement(ha.childNodes[0]);
range.select();
}
*/
ta.style.display = "block";
ta.value = cliptext; // must follow "block" setting for Webkit
ta.focus();
ta.select();
window.setTimeout(function() {
if (!SocialCalc.GetSpreadsheetControlObject) return; // in case not loaded
var s = SocialCalc.GetSpreadsheetControlObject();
if (!s) return;
var editor = s.editor;
/*
var ha = editor.pasteHTMLarea;
if (ha) {
ha.blur();
ha.innerHTML = '';
ha.style.visibility = 'hidden';
}
*/
var ta = editor.pasteTextarea;
ta.blur();
ta.style.display = "none";
SocialCalc.KeyboardFocus();
}, 200);
return true;
case "[ctrl-v]":
if (editor.noEdit) return true; // not if no edit
var showPasteTextArea = function() {
ta = editor.pasteTextarea;
ta.value = "";
cell=SocialCalc.GetEditorCellElement(editor, editor.ecell.row, editor.ecell.col);
socialcalc/socialcalctableeditor.js view on Meta::CPAN
ta.value = ""; // must follow "block" setting for Webkit
ta.focus();
};
ha = editor.pasteHTMLarea;
if (ha) {
/* Pasting via HTML - Currently IE only */
ha.style.visibility = "visible";
ha.focus();
}
else {
showPasteTextArea();
}
window.setTimeout(function() {
if (!SocialCalc.GetSpreadsheetControlObject) return;
var s = SocialCalc.GetSpreadsheetControlObject();
if (!s) return;
var editor = s.editor;
var value = null;
var isPasteSameAsClipboard = false;
ha = editor.pasteHTMLarea;
if (ha) {
/* IE: We append a U+FFFC to every TD that's not the last of its row,
* then we obtain innerText, then turn U+FFFC back to \t,
* thereby preserving the cell separations (which gets discarded
* if we simply paste via textarea.
*/
var _ObjectReplacementCharacter_ = String.fromCharCode(0xFFFC);
var html = ha.innerHTML;
if (html.search(/<(?![Bb][Rr])[A-Za-z]/) >= 0) {
/* HTML Paste: Mark TDs with U+FFFC accordingly.. */
ha.innerHTML = html.replace(
/(?:<\/[Tt][Dd]>)/g,
_ObjectReplacementCharacter_
);
}
else {
/* Text Paste: In IE, \t is transformed into , so replace them with U+FFFC. */
ha.innerHTML = html.replace(
/&[Nn][Bb][Ss][Pp];/g,
_ObjectReplacementCharacter_
);
}
value = ha.innerText.replace(new RegExp(_ObjectReplacementCharacter_, 'g'), '\t');
ha.innerHTML = '';
ha.blur();
ha.style.visibility = "hidden";
}
else {
var ta = editor.pasteTextarea;
value = ta.value;
ta.blur();
ta.style.display = "none";
}
value = value.replace(/\r\n/g, "\n").replace(/\n?$/, '\n');
var clipstr = SocialCalc.ConvertSaveToOtherFormat(SocialCalc.Clipboard.clipboard, "tab");
if (value == clipstr || (value.length-clipstr.length==1 && value.substring(0,value.length-1)==clipstr)) {
isPasteSameAsClipboard = true;
}
var cmd = "";
// pastes SocialCalc clipboard if did a Ctrl-C and contents still the same
// Webkit adds an extra blank line, so need to allow for that
if (!isPasteSameAsClipboard) {
cmd = "loadclipboard "+
SocialCalc.encodeForSave(SocialCalc.ConvertOtherFormatToSave(value, "tab")) + "\n";
}
var cr;
if (editor.range.hasrange) {
cr = SocialCalc.crToCoord(editor.range.left, editor.range.top);
}
else {
cr = editor.ecell.coord;
}
cmd += "paste "+cr+" formulas";
editor.EditorScheduleSheetCommands(cmd, true, false);
SocialCalc.KeyboardFocus();
}, 200);
return true;
case "[ctrl-z]":
editor.EditorScheduleSheetCommands("undo", true, false);
return false;
case "[ctrl-s]": // !!!! temporary hack
window.setTimeout(
function() {
if (!SocialCalc.GetSpreadsheetControlObject) return;
var s = SocialCalc.GetSpreadsheetControlObject();
if (!s) return;
var editor = s.editor;
var sheet = editor.context.sheetobj;
var cell = sheet.GetAssuredCell(editor.ecell.coord);
var ntvf = cell.nontextvalueformat ? sheet.valueformats[cell.nontextvalueformat-0] || "" : "";
var newntvf = window.prompt("Advanced Feature:\n\nCustom Numeric Format or Command", ntvf);
if (newntvf != null) { // not cancelled
if (newntvf.match(/^cmd:/)) {
cmd = newntvf.substring(4); // execute as command
}
else if (newntvf.match(/^edit:/)) {
cmd = newntvf.substring(5); // execute as command
if (SocialCalc.CtrlSEditor) {
SocialCalc.CtrlSEditor(cmd);
}
return;
}
else {
if (editor.range.hasrange) {
sel = SocialCalc.crToCoord(editor.range.left, editor.range.top)+
":"+SocialCalc.crToCoord(editor.range.right, editor.range.bottom);
}
else {
sel = editor.ecell.coord;
}
cmd = "set "+sel+" nontextvalueformat "+newntvf;
}
editor.EditorScheduleSheetCommands(cmd, true, false);
}
},
200);
return false;
default:
break;
}
( run in 0.650 second using v1.01-cache-2.11-cpan-2398b32b56e )