PK WA5J3 3 2 spreadsheet/codebase/dhtmlxgrid_borderselection.js3/**
(c) DHTMLX Ltd, 2011
Licensing: You allowed to use this component for free under GPL or you need to obtain Commercial/Enterprise license to use it in non-GPL project
Contact: sales@dhtmlx.com
**/
dhtmlXGridObject.prototype.addBorderSelection = function(LeftTopRow, LeftTopCol, RightBottomRow, RightBottomCol) {
if (typeof(this._borders_store) === 'undefined') this._borders_store = [];
var border = {
id: this.uid(),
LeftTopRow: LeftTopRow,
LeftTopCol: LeftTopCol,
RightBottomRow: RightBottomRow,
RightBottomCol: RightBottomCol
};
for (var i = 0; i < this._borders_store.length; i++) {
var bord = this._borders_store[i];
if ((border.LeftTopRow === bord.LeftTopRow)&&(border.LeftTopCol === bord.LeftTopCol)&&(border.RightBottomRow === bord.RightBottomRow)&&(border.RightBottomCol === bord.RightBottomCol)) {
border = this._borders_store[i];
return border;
}
}
this._borders_store.push(border);
this.showBorderSelection();
return border;
};
dhtmlXGridObject.prototype.showBorderSelection = function() {
for (var i = 0; i < this._borders_store.length; i++)
this._showBorderSelection(this._borders_store[i]);
};
dhtmlXGridObject.prototype._showBorderSelection = function(border) {
this._unsetBorderSelection(border.obj);
// border goes out of grid range
var cell1_exists = this.doesCellExist(border.LeftTopRow, border.LeftTopCol);
var cell2_exists = this.doesCellExist(border.RightBottomRow, border.RightBottomCol);
if ((!cell1_exists) || (!cell2_exists)) return null;
if (typeof(border.color) === 'undefined')
border.color = this.generateBorderColor();
border.obj = {};
border.obj.top = document.createElement('div');
border.obj.top.className = 'border_selection_top' + (border.classname ? (' ' + border.classname) : '');
border.obj.top.style.borderColor = border.color;
border.obj.left = document.createElement('div');
border.obj.left.className = 'border_selection_left' + (border.classname ? (' ' + border.classname) : '');
border.obj.left.style.borderColor = border.color;
border.obj.bottom = document.createElement('div');
border.obj.bottom.className = 'border_selection_bottom' + (border.classname ? (' ' + border.classname) : '');
border.obj.bottom.style.borderColor = border.color;
border.obj.right = document.createElement('div');
border.obj.right.className = 'border_selection_right' + (border.classname ? (' ' + border.classname) : '');
border.obj.right.style.borderColor = border.color;
var offset = this.getPosition(this.obj);
var cell1 = this.cells(border.LeftTopRow, border.LeftTopCol).cell;
var cell2 = this.cells(border.RightBottomRow, border.RightBottomCol).cell;
var pos1 = this.getPosition(cell1);
var pos2 = this.getPosition(cell2);
var x1, x2, y1, y2;
var borderwidth = 2;
if (pos2[0] > pos1[0]) {
x1 = pos1[0];
x2 = pos2[0] + cell2.offsetWidth;
} else {
x1 = pos2[0];
x2 = pos1[0] + cell1.offsetWidth;
}
if (pos2[1] > pos1[1]) {
y1 = pos1[1];
y2 = pos2[1] + cell2.offsetHeight;
} else {
y1 = pos2[1];
y2 = pos1[1] + cell1.offsetHeight;
}
var x = (x1 - offset[0]);
var y = (y1 - offset[1]);
var width = (Math.abs(x1 - x2) - borderwidth);
var height = (Math.abs(y1 - y2) - borderwidth);
border.obj.top.style.left = x + 'px';
border.obj.top.style.top = y + 'px';
border.obj.top.style.width = width + 'px';
border.obj.bottom.style.left = x + 'px';
border.obj.bottom.style.top = (y + height) + 'px';
border.obj.bottom.style.width = width + 'px';
border.obj.left.style.left = x + 'px';
border.obj.left.style.top = y + 'px';
border.obj.left.style.height = height + 'px';
border.obj.right.style.left = (x + width) + 'px';
border.obj.right.style.top = y + 'px';
border.obj.right.style.height = height + 'px';
this.objBox.appendChild(border.obj.top);
this.objBox.appendChild(border.obj.left);
this.objBox.appendChild(border.obj.bottom);
this.objBox.appendChild(border.obj.right);
return border;
};
dhtmlXGridObject.prototype.getPosition = function(e) {
var left = 0;
var top = 0;
while (e.offsetParent) {
left += e.offsetLeft - e.scrollLeft;
top += e.offsetTop - e.scrollTop;
e = e.offsetParent;
}
left += e.offsetLeft;
top += e.offsetTop;
return {x:left, y:top};
};
dhtmlXGridObject.prototype.setColorsBorderSelection = function() {
if (!this._default_borders_colors)
this._default_borders_colors = [];
var presets = [
'#ff0000',
'#00ff00',
'#0000ff',
'#00ffff',
'#ff00ff',
'#533B9C',
'#689C00',
'#D65200',
'#8F7F36',
'#FF9100',
'#00B530',
'#FF0084',
'#B300A4',
'#4754FF',
'#00C3FF'
];
this._borders_colors = presets.concat(this._default_borders_colors);
};
dhtmlXGridObject.prototype.generateBorderColor = function() {
var color;
if (typeof(this._borders_colors) === 'undefined')
// the most popular colors
this.setColorsBorderSelection();
if (this._borders_colors.length === 0) {
// generate any color
color = '#';
for (var i = 0; i < 3; i++) {
var c = Math.round(Math.random()*254).toString(16).toLowerCase();
if (c.length == 1) c = '0' + c;
color += c;
}
this._default_borders_colors.push(color);
return color;
}
var index = 0;
color = this._borders_colors[index];
this._borders_colors.splice(index, 1);
return color;
};
dhtmlXGridObject.prototype.detachBorderSelection = function(id) {
for (var i = 0; i < this._borders_store.length; i++)
if (this._borders_store[i].id === id) {
if (typeof(this._borders_store[i].obj) !== 'undefined')
this._borders_store[i].obj.parentNode.removeChild(this._borders_store[i].obj);
this._borders_store.splice(i, 1);
this.showBorderSelection();
return true;
}
return false;
};
dhtmlXGridObject.prototype.clearBorderSelection = function() {
this.setColorsBorderSelection();
if (typeof(this._borders_store) !== 'undefined')
for (var i = 0; i < this._borders_store.length; i++)
this._unsetBorderSelection(this._borders_store[i].obj);
this._borders_store = [];
};
dhtmlXGridObject.prototype._unsetBorderSelection = function(obj) {
if (typeof(obj) !== 'undefined') {
if (typeof(obj.top) != 'undefined') obj.top.parentNode.removeChild(obj.top);
if (typeof(obj.left) != 'undefined') obj.left.parentNode.removeChild(obj.left);
if (typeof(obj.bottom) != 'undefined') obj.bottom.parentNode.removeChild(obj.bottom);
if (typeof(obj.right) != 'undefined') obj.right.parentNode.removeChild(obj.right);
}
};
dhtmlXGridObject.prototype.enableBorderSelection = function(mode) {
if (mode !== false) mode = true;
var self = this;
if (mode) {
if (!this._bs_enabled) {
this._bs_enabled = true;
this._objmousedown = this.obj.onmousedown;
this._objmouseclick = this.obj.onclick;
this.obj.onmousedown = function(e) {
e = e || event;
self.startBorderSelection(e);
};
this.obj.onclick = function(e) {};
}
} else {
if (this._border_hover) {
this._border_hover.parentNode.removeChild(this._border_hover);
this._border_hover = null;
}
this._bs_enabled = false;
if (this._objmousedown)
this.obj.onmousedown = this._objmousedown;
if (this._objmouseclick)
this.obj.onclick = this._objmouseclick;
if (this._mousemovecallback)
this.obj.onmousemove = this._mousemovecallback;
}
};
dhtmlXGridObject.prototype.startBorderSelection = function(e) {
// disable editable cells closing
e = e || event;
var obj = (e.target || e.srcElement).parentNode;
if (obj.className.indexOf('editable') !== -1) return true;
var offset = this.getPosition(this.obj);
var x = e.clientX - offset[0] + document.body.scrollLeft + this.obj.scrollLeft;
var y = e.clientY - offset[1] + document.body.scrollTop + this.obj.scrollTop;
var cell = this._getCellByPos(x, y);
this._border_start = cell;
this._border_end = cell;
var pos = this.getPosition(cell);
x = pos[0] - offset[0];
y = pos[1] - offset[1];
var width = cell.offsetWidth - 4;
var height = cell.offsetHeight - 3;
var result = this.callEvent("onBorderSelectionStart",[cell.parentNode.idd, cell._cellIndex]);
if (result === false) return false;
if (this._border_hover)
this._border_hover.parentNode.removeChild(this._border_hover);
this._border_hover = document.createElement('div');
this._border_hover.className = 'border_selection';
this._border_hover.style.borderColor = this.generateBorderColor();
this._border_hover.style.width = '100px';
this._border_hover.style.height = '100px';
this._border_hover.style.left = x + 'px';
this._border_hover.style.top = y + 'px';
this._border_hover.style.width = width + 'px';
this._border_hover.style.height = height + 'px';
this.objBox.appendChild(this._border_hover);
this._mousemovecallback = this.obj.onmousemove;
this._bodymouseup = window.onmouseup;
var self = this;
this.obj.onmousemove = this._border_hover.onmousemove = function(e) {
e = e || event;
self.moveBorderSelection(e);
};
document.body.onmouseup = function(e) {
e = e || event;
self.endBorderSelection(e);
};
return true;
};
dhtmlXGridObject.prototype.moveBorderSelection = function(e) {
var offset = this.getPosition(this.obj);
var x = e.clientX - offset[0] + document.body.scrollLeft + this.obj.scrollLeft;
var y = e.clientY - offset[1] + document.body.scrollTop + this.obj.scrollTop;
var cell1 = this._border_start;
var cell2 = this._getCellByPos(x, y);
if (cell2)
this._border_end = cell2;
else
cell2 = this._border_end;
var cell1_pos = this.getPosition(cell1);
var x1 = cell1_pos[0] - offset[0];
var y1 = cell1_pos[1] - offset[1];
var cell2_pos = this.getPosition(cell2);
var x2 = cell2_pos[0] - offset[0];
var y2 = cell2_pos[1] - offset[1];
var result = this.callEvent("onBorderSelectionMove",[cell1.parentNode.idd, cell1._cellIndex, cell2.parentNode.idd, cell2._cellIndex]);
if (result === false) return false;
x = (x1 < x2) ? x1 : x2;
var width = Math.abs(x2 - x1) + ((x1 < x2) ? cell2.offsetWidth : cell1.offsetWidth) - 2;
y = (y1 < y2) ? y1 : y2;
var height = Math.abs(y2 - y1) + ((y1 < y2) ? cell2.offsetHeight : cell1.offsetHeight) - 1;
width -= 2;
height -= 2;
this._border_hover.style.left = x + 'px';
this._border_hover.style.top = y + 'px';
this._border_hover.style.width = width + 'px';
this._border_hover.style.height = height + 'px';
/* AUTO SCROLL */
var BottomRightX = this.objBox.scrollLeft + this.objBox.clientWidth;
var BottomRightY = this.objBox.scrollTop + this.objBox.clientHeight;
var TopLeftX = this.objBox.scrollLeft;
var TopLeftY = this.objBox.scrollTop;
var X = e.clientX - offset[0];
var Y = e.clientY - offset[1];
var nextCall=false;
if (this._brsTimer) window.clearTimeout(this._brsTimer);
if (X+20 >= BottomRightX) {
var scrollLeft = this.objBox.scrollLeft;
this.objBox.scrollLeft = this.objBox.scrollLeft+20;
if (scrollLeft !== this.objBox.scrollLeft)
nextCall=true;
} else if (X-20 < TopLeftX) {
if (this.objBox.scrollLeft > 0) {
this.objBox.scrollLeft = this.objBox.scrollLeft-20;
nextCall=true;
}
}
if (Y+20 >= BottomRightY) {
var scrollTop = this.objBox.scrollTop;
this.objBox.scrollTop = this.objBox.scrollTop+20;
if (scrollTop !== this.objBox.scrollTop) {
nextCall=true;
}
} else {
if (Y-20 < TopLeftY) {
if (this.objBox.scrollTop > 0) {
this.objBox.scrollTop = this.objBox.scrollTop-20;
nextCall=true;
}
}
}
if (nextCall){
var a = e.clientX;
var b = e.clientY;
var self = this;
this._blsTimer=window.setTimeout(function(){ self.moveBorderSelection({clientX:a,clientY:b}); },100);
}
return true;
};
dhtmlXGridObject.prototype.endBorderSelection = function(e) {
this.obj.onmousemove = this._mousemovecallback;
this._border_hover.onmousemove = null;
this._border_hover.onmouseup = null;
this._mousemovecallback = null;
if (typeof(this._bodymouseup) !== 'undefined')
document.body.onmouseup = this._bodymouseup;
var cell1 = this._border_start;
var cell2 = this._border_end;
var rId1 = cell1.parentNode.idd;
var cInd1 = cell1._cellIndex;
var rId2 = cell2.parentNode.idd;
var cInd2 = cell2._cellIndex;
this.callEvent("onBorderSelected",[rId1, cInd1, rId2, cInd2]);
if (this._border_hover) {
this._border_hover.parentNode.removeChild(this._border_hover);
this._border_hover = null;
}
};
dhtmlXGridObject.prototype._getCellByPos = function(x,y){
var _x=0;
for (var i=0; i < this.obj.rows.length; i++) {
y-=this.obj.rows[i].offsetHeight;
if (y<=0) {
_x=this.obj.rows[i];
break;
}
}
if (!_x || !_x.idd) return null;
for (var i=0; i < this._cCount; i++) {
x-=this.obj.rows[0].childNodes[i].offsetWidth;
if (x<=0) {
while(true){
if (_x._childIndexes && _x._childIndexes[i+1]==_x._childIndexes[i])
_x=_x.previousSibling;
else
return this.cells(_x.idd,i).cell;
}
}
}
return null;
};
dhtmlXGridObject.prototype.doesCellExist = function(rId, cInd) {
if ((this.doesRowExist(rId)) && (cInd < this.getColumnsNum()))
return true;
else
return false;
};PK WATVE
a \ ) spreadsheet/codebase/dhtmlxgrid_reset.css\div.gridbox table.obj.row20px tr td {
line-height: 13px;
vertical-align: middle !important;
padding-left: 4px !important;
padding-right: 4px !important;
padding-bottom: 0px !important;
border-collapse: separate !important;
}
div.gridbox table.obj th, div.gridbox table.hdr th {
margin: 0 !important;
padding: 0 !important;
border-spacing: 0px;
border: none;
}
div.gridbox_dhx_skyblue table.hdr td {
border-collapse: separate !important;
border-top: 1px solid #FDFDFD !important;
padding: 5px 0 !important;
}
.dhx_toolbar_base_dhx_skyblue div.dhx_toolbar_btn div {
line-height: 13px;
}
div.gridbox table.hdr {
border-collapse: separate !important;
}
div.gridbox table.obj.row20px {
margin: 0px !important;
border-collapse: separate !important;
}
div.gridbox table.obj tr td.editable {
padding: 0px !important;
}
.header_editor {
font-size: 11px !important;
line-height: 13px !important;
font-family: Tahoma !important;
margin: 0px !important;
height: 12px !important;
border: 1px solid #7f9db9 !important;
}
.header_editor:focus {
border: 1px solid #7f9db9 !important;
}
.dhx_combo_edit:focus {
border: none !important;
}
div.gridbox table.obj.row20px tr td:first-child,
div.gridbox table.obj.row20px tr td:first-child {
border-color: #FDFDFD #A4BED4 #A4BED4 #FDFDFD !important;
border-width: 1px 0 !important;
}
div.dhx_toolbar_poly_dhx_skyblue table.buttons_cont td.td_btn_img {
line-height: 2.4px !important;
}
div.gridbox table.hdr,
div.gridbox table.obj.row20px {
border: none !important;
margin: 0px;
}PK WA, ) spreadsheet/codebase/dhtmlxgrid_shcell.js
/**
(c) DHTMLX Ltd, 2011
Licensing: You allowed to use this component for free under GPL or you need to obtain Commercial/Enterprise license to use it in non-GPL project
Contact: sales@dhtmlx.com
**/
/*
(c) DHTMLX Ltd, 2011
Licensing: You allowed to use this component for free under GPL or you need to obtain Commercial/Enterprise license to use it in non-GPL project
Contact: sales@dhtmlx.com
*/
if (typeof(SpreadSheetMathHint) === 'undefined')
var SpreadSheetMathHint;
function eXcell_edsh(cell){
if (cell){
this.cell=cell;
this.grid=this.cell.parentNode.grid;
}
this.dont_take_care = false;
this.edit=function(){
this.cell.atag=((!this.grid.multiLine)&&(_isKHTML||_isMacOS||_isFF)) ? "INPUT" : "TEXTAREA";
this.val=this.getRealValue();
this.obj=document.createElement(this.cell.atag);
this.obj.setAttribute("autocomplete", "off");
this.obj.style.height=(this.cell.offsetHeight-(_isIE ? 8 : 4))+"px";
this.obj.className="dhx_combo_edit";
this.obj.wrap="soft";
this.obj.style.textAlign=this.cell.style.textAlign;
this.obj.onclick=function(e){
(e||event).cancelBubble=true;
};
this.obj.onmousedown=function(e){
(e||event).cancelBubble=true;
};
this.obj.onmouseup=function(e){
(e||event).cancelBubble=true;
};
this.obj.value=this.val;
this.cell.innerHTML="";
this.cell.appendChild(this.obj);
if (this.grid.ssheet.settings.math) {
SpreadSheetMathHint.attachEvent(this.obj, this.grid.ssheet);
SpreadSheetMathHint.showBorders(this.obj);
SpreadsheetBuffer.callback = this.grid.ssheet;
if (this.val.substring(0, 1) === '=')
this.grid.enableBorderSelection();
}
if (_isFF && !window._KHTMLrv){
this.obj.style.overflow="visible";
if ((this.grid.multiLine)&&(this.obj.offsetHeight >= 18)&&(this.obj.offsetHeight < 40)){
this.obj.style.height="36px";
this.obj.style.overflow="scroll";
}
}
this.obj.onselectstart=function(e){
if (!e)
e=event;
e.cancelBubble=true;
return true;
};
this.obj.focus();
if (this.grid.ssheet.settings.math)
SpreadSheetMathHint.setCursorPos(this.obj, this.obj.value.length);
};
this.getRealValue = function() {
return this.cell.getAttribute('real_value');
};
this.getFormattedValue = function() {
return this.cell.getAttribute('formatted_value');
};
this.detach=function(mode){
if (mode === false) {
this.dont_take_care = true;
this.obj.value = this.getFormattedValue();
this.setCValue(this.getFormattedValue(), this.getRealValue());
return true;
}
this.grid.enableBorderSelection(false);
SpreadSheetMathHint.hide();
this.obj.value = SpreadSheetMathHint.function_ending(this.obj.value);
if (this.obj.value === this.getRealValue()) {
this.obj.value = this.getFormattedValue();
this.dont_take_care = true;
this.setCValue(this.obj.value, this.getRealValue());
} else {
this.setCValue(this.obj.value, this.obj.value);
}
return this.obj.val != this.getRealValue();
};
this.getRealChanged = function(change) {
if (this.dont_take_care === true) {
if (change)
this.dont_take_care = false;
return false;
}
return true;
};
this.setCValue=function(val, val2){
this.cell._clearCell=true;
this.cell.innerHTML=' ';
this.cell.appendChild(document.createTextNode(val));
this.cell.setAttribute('real_value', (val2 || val));
this.cell.setAttribute('formatted_value', val);
if (( typeof(val) !== "number")&&(!val||val.toString()._dhx_trim() === "")){
val=" ";
this.cell._clearCell=true;
} else
this.cell._clearCell=false;
this.grid.callEvent("onCellChanged", [
this.cell.parentNode.idd,
this.cell._cellIndex,
(arguments.length > 1 ? val2 : val)
]);
};
this.setValue=function(val){
if (this.dont_take_care === true) return false;
this.setCValue(val, this.getRealValue());
};
}
eXcell_edsh.prototype=new eXcell_edtxt;
eXcell_rotxt.prototype.getRealValue = eXcell_rotxt.prototype.getValue;PK WA#"
' spreadsheet/codebase/dhtmlxsh_buffer.js
0/**
(c) DHTMLX Ltd, 2011
Licensing: You allowed to use this component for free under GPL or you need to obtain Commercial/Enterprise license to use it in non-GPL project
Contact: sales@dhtmlx.com
**/
SpreadsheetBuffer = {
area_id: 'spreadsheet_buffer_area',
area: null,
coords: null,
cmd: 0,
init: function() {
if (SpreadsheetBuffer.area) return true;
this.getArea();
dhtmlxEvent(document.body, "keydown", function(e) {
if (!SpreadsheetBuffer.callback) return true;
var code = e.which;
var ctrl = e.ctrlKey || false;
var meta = e.metaKey || false;
// insert functionality
if (code == 86 && (ctrl === true || meta === true)) {
SpreadsheetBuffer.from_area();
SpreadsheetBuffer.unselect(SpreadsheetBuffer.callback);
}
// ctrl + c
if (code == 67 && (ctrl === true || meta === true)) {
SpreadsheetBuffer.callback.dumpCopy();
SpreadsheetBuffer.select(SpreadsheetBuffer.callback);
}
// ctrl + x
if (code == 88 && (ctrl === true || meta === true)) {
SpreadsheetBuffer.callback.dumpCopy();
SpreadsheetBuffer.select(SpreadsheetBuffer.callback);
SpreadsheetBuffer.from_area();
SpreadsheetBuffer.callback.mapSelection(function(row, col) {
if (this.isLocked(row, col)) return false;
var style = this.getCellStyle(row, col);
style.set('bgcolor', 'ffffff');
style.set('color', '000000');
style.set('bold', 'false');
style.set('italic', 'false');
style.set('align', 'left');
style.set('lock', 'false');
style.set('validator', 'false');
SpreadsheetBuffer.callback.applyStyles(row, col);
this.renderCell(row, col);
return true;
});
}
return true;
});
},
getArea: function() {
if (this.area) return this.area;
var div = document.createElement('div');
div.className = 'editable';
var area = document.createElement('textarea');
area.id = this.area_id;
area.className = 'spread_buffer_area';
div.appendChild(area);
document.body.appendChild(div);
SpreadsheetBuffer.area = area;
return this.area;
},
to_area: function(callback, coords) {
if (coords === null) return;
coords.LeftTopRow = parseInt(coords.LeftTopRow, 10);
coords.RightBottomRow = parseInt(coords.RightBottomRow, 10);
if (typeof(callback) != "undefined") {
SpreadsheetBuffer.callback = callback;
}
var text;
if (coords === null)
text = "";
else {
text = callback.getBlockText(coords);
}
SpreadsheetBuffer.area.value = text;
SpreadsheetBuffer.range = coords;
window.setTimeout(function() {
if (callback.dont_lose_focus) return false;
SpreadsheetBuffer.area.focus();
SpreadsheetBuffer.area.select();
}, 1);
},
from_area: function() {
window.setTimeout(function() {
var text = SpreadsheetBuffer.area.value;
if (SpreadsheetBuffer.callback.grid.editor) return false;
SpreadsheetBuffer.callback.setBlockText(text);
SpreadsheetBuffer.area.focus();
SpreadsheetBuffer.area.select();
return true;
}, 100);
},
select: function(ssheet) {
if (!SpreadsheetBuffer.range) return false;
var r = SpreadsheetBuffer.range;
r.color = "#9E9E9E";
r.classname = 'solid';
this.unselect(ssheet);
delete r.obj;
this._copyborder = ssheet.grid._showBorderSelection(r);
return true;
},
unselect: function(ssheet) {
if (this._copyborder)
ssheet.grid._unsetBorderSelection(this._copyborder.obj);
this._copyborder = null;
}
};PK WAb ' spreadsheet/codebase/dhtmlxsh_config.js/**
(c) DHTMLX Ltd, 2011
Licensing: You allowed to use this component for free under GPL or you need to obtain Commercial/Enterprise license to use it in non-GPL project
Contact: sales@dhtmlx.com
**/
var SpreadSheetConfig = {
init:function(){
if (!SpreadSheetConfig.win){
var str = "
";
str += "
";
str += "";
str += "";
str += "
";
str += "";
str += "";
str += "
";
str += "";
str += "";
str += "
";
str += "";
str += "";
str += "
";
str += "";
str += "";
str += "
";
str += "
";
var d = SpreadSheetConfig.win = document.createElement("DIV");
d.className = "dhx_spread_window";
d.style.display="none";
document.body.appendChild(d);
d.innerHTML = str;
var save = document.getElementById("spread_config_save");
dhtmlxEvent(save, "click", function() {
var config = SpreadSheetConfig.get();
SpreadSheetConfig.callback.refresh(config);
SpreadSheetConfig.hide();
});
var cancel = document.getElementById("spread_config_cancel");
dhtmlxEvent(cancel, "click", function() {
SpreadSheetConfig.hide();
});
}
return SpreadSheetConfig;
},
show: function(callback, x, y) {
SpreadSheetConfig.callback = callback;
var pos = SpreadSheetConfig.get_pos(callback.settings.parent.parent);
var width = callback.settings.parent.grid.offsetWidth;
var height = callback.settings.parent.toolbar.offsetHeight + callback.settings.parent.grid.offsetHeight;
// SpreadSheetModal.size(width, height);
SpreadSheetModal.show(callback.settings.parent.parent);
SpreadSheetConfig.set_pos(x, y);
SpreadSheetConfig.win.style.display="";
document.getElementById('spread_config_rows').focus();
},
hide: function() {
SpreadSheetModal.hide();
SpreadSheetConfig.win.style.display="none";
SpreadSheetConfig.callback = null;
},
get: function() {
var config = {};
config.rows = parseInt(document.getElementById('spread_config_rows').value, 10);
config.cols = parseInt(document.getElementById('spread_config_cols').value, 10);
config.show_row_numbers = document.getElementById('show_row_numbers').checked;
config.show_export_buttons = document.getElementById('show_export_buttons').checked;
return config;
},
set: function(config) {
document.getElementById('spread_config_rows').value = config.rows;
document.getElementById('spread_config_cols').value = config.cols;
document.getElementById('show_row_numbers').checked = (config.show_row_numbers == 1) ? true : false;
document.getElementById('show_export_buttons').checked = (config.show_export_buttons == 1) ? true : false;
},
set_pos: function(x, y) {
SpreadSheetConfig.win.style.left = x + "px";
SpreadSheetConfig.win.style.top = y + "px";
},
/*! returns position of html object
@param e
html object
@return
object { x: left, y: top }
*/
get_pos: function (e) {
var left = 0;
var top = 0;
while (e.offsetParent) {
left += e.offsetLeft - e.scrollLeft;
top += e.offsetTop - e.scrollTop;
e = e.offsetParent;
}
left += e.offsetLeft;
top += e.offsetTop;
return {x:left, y:top};
}
};PK WA0! ( spreadsheet/codebase/dhtmlxsh_context.js}/**
(c) DHTMLX Ltd, 2011
Licensing: You allowed to use this component for free under GPL or you need to obtain Commercial/Enterprise license to use it in non-GPL project
Contact: sales@dhtmlx.com
**/
dhtmlxSpreadSheet.prototype.addContext = function() {
var menu;
if (this.context) {
menu = this.context;
} else {
menu = new dhtmlXMenuObject();
menu.setImagePath(this.settings.image_path);
menu.setIconPath(this.settings.icons_path);
menu.renderAsContextMenu();
menu.addNewChild(null, 1, "lock", "Lock", false, "lock.png");
menu.addNewChild(null, 2, "validator", "Validate", false, "validate.png");
menu.addRadioButton("child", "validator", 1, "none", "None", "validators", true, false);
menu.addRadioButton("child", "validator", 2, "number", "Number", "validators", false, false);
menu.addRadioButton("child", "validator", 3, "email", "Email", "validators", false, false);
menu.addRadioButton("child", "validator", 4, "positive", "Positive", "validators", false, false);
menu.addRadioButton("child", "validator", 5, "not_empty", "Not empty", "validators", false, false);
var self = this;
this.grid.attachEvent("onBeforeContextMenu", function(row, col){
self._ctxCells = [{ row: row, col: col }];
return self.onBeforeContextMenu(row, col);
});
menu.attachEvent("onBeforeContextMenu", function(){
var block = self.grid.getSelectedBlock();
if (block === null) return false;
var cells = [];
for (var i = block.LeftTopRow; i <= block.RightBottomRow; i++) {
for (var j = block.LeftTopCol; j <= block.RightBottomCol; j++) {
cells.push({ row: i, col: j });
}
}
self._ctxCells = cells;
return self.onBeforeContextMenu(cells[0].row, cells[0].col);
});
menu.attachEvent("onRadioClick", function(menuitemId, type) {
self._validatorIsSetted(menuitemId,type);
return true;
});
menu.attachEvent("onClick", function(id) {
switch (id) {
case 'lock':
var range = self._old_ctx();
var value = self.isLocked(range.minrow, range.mincol);
for (var i = 0; i < self._ctxCells.length; i++)
self.lockCell(self._ctxCells[i].row, self._ctxCells[i].col, !value);
break;
default:
break;
}
});
this.context = menu;
}
return menu;
};
dhtmlxSpreadSheet.prototype._old_ctx = function() {
if (!this._ctxCells) return;
var minrow = 100000;
var mincol = 100000;
var maxrow = -1;
var maxcol = -1;
for (var i = 0; i < this._ctxCells.length; i++) {
minrow = Math.min(minrow, this._ctxCells[i].row);
mincol = Math.min(mincol, this._ctxCells[i].col);
maxrow = Math.max(maxrow, this._ctxCells[i].row);
maxcol = Math.max(maxcol, this._ctxCells[i].col);
}
this._old("cells", [minrow, mincol, maxrow, maxcol]);
return {
minrow: minrow,
mincol: mincol,
maxrow: maxrow,
maxcol: maxcol
};
};
dhtmlxSpreadSheet.prototype.onBeforeContextMenu = function(row, col){
if (col == 0) return false;
var style = this.getCellStyle(row, col);
// this._ctxCells = {style: style, row: row, col: col};
var json = style.get_json();
this.context.setRadioChecked("validators", json.validator);
this.context.setItemText("lock", json.lock == "true" ? "Unlock" : "Lock");
return true;
}
dhtmlxSpreadSheet.prototype._validatorIsSetted = function(menuitemid, type) {
if (!this._ctxCells) return;
var self = this;
window.setTimeout(function() {
var value = self.context.getRadioChecked("validators");
self.context.hideContextMenu();
self._old_ctx();
for (var i = 0; i < self._ctxCells.length; i++) {
var row = self._ctxCells[i].row;
var col = self._ctxCells[i].col;
if (self.isLocked(row, col)) continue;
var style = self.getCellStyle(row, col);
style.set('validator', value);
self.to_stack(row, col);
self.validateCell(row, col);
}
self._ctxCells = null;
}, 1);
};
dhtmlxSpreadSheet.prototype.lockCell = function(row, col, value) {
this.context.hideContextMenu();
var style = this.getCellStyle(row, col);
var lock = style.get('lock');
var inverse_value = lock == 'false' ? 'true' : 'false';
if (typeof(value) != 'undefined')
value = (value == true) ? 'true' : 'false';
else
value = inverse_value;
style.set('lock', value);
this.to_stack(row, col);
this.renderCell(row, col);
};
dhtmlxSpreadSheet.prototype.isLocked = function(row, col) {
var style = this.getCellStyle(row, col);
var lock = style.get('lock');
return lock == 'false' ? false : true;
};
dhtmlxSpreadSheet.prototype.validate = function() {
for (var i = 0; i < this.settings.rows; i++) {
var row = i + 1;
for (var j = 1; j <= this.settings.cols; j++) {
this.validateCell(row, j);
}
}
}
dhtmlxSpreadSheet.prototype.validateCell = function(row, col) {
var cell = this.grid.cells(row, col);
var style = this.getCellStyle(row, col);
var json = style.get_json();
var validator = this.validators[json.validator]
var value = cell.getValue();
if (validator && this[validator] && this[validator](value) == false) {
cell.cell.className += ' invalid';
} else {
cell.cell.className = cell.cell.className.replace(/ invalid/g, '');
}
};
dhtmlxSpreadSheet.prototype.render = function() {
for (var i = 0; i < this.settings.rows; i++) {
var row = i + 1;
for (var j = 1; j <= this.settings.cols; j++) {
this.renderCell(row, j);
}
}
};
dhtmlxSpreadSheet.prototype.renderCell = function(row, col) {
var cell = this.grid.cells(row, col);
var style = this.getCellStyle(row, col);
var json = style.get_json();
this.validateCell(row, col);
if (json.lock == 'true') {
cell.cell.className += ' locked';
} else {
cell.cell.className = cell.cell.className.replace(/ locked/g, '');
}
};
dhtmlxSpreadSheet.prototype._is_number = function(value) {
var reg = /^\-?\d+(\.\d+)?$/;
value = value.toString().trim();
if (reg.test(value)) return true;
return false;
}
dhtmlxSpreadSheet.prototype._is_email = function(value) {
var reg = /^.+@.+\..{2,4}$/;
value = value.toString().trim();
if (reg.test(value)) return true;
return false;
}
dhtmlxSpreadSheet.prototype._is_positive = function(value) {
var reg = /^\d+(\.\d+)?$/;
value = value.toString().trim();
if (reg.test(value)) return true;
return false;
}
dhtmlxSpreadSheet.prototype._is_not_empty = function(value) {
value = value.toString().trim();
if (value) return true;
return false;
}
dhtmlxSpreadSheet.prototype.validators = {
"none": null,
"number": "_is_number",
"email": "_is_email",
"positive": "_is_positive",
"not_empty": "_is_not_empty"
};
/*! additional event which occurs when block-selection container is shown.
* is used to make double click on selected cell a little better.
**/
dhtmlXGridObject.prototype._ShowSelection = function()
{
if (this._selectionObj) {
this.callEvent("onBlockSelectionShown", []);
this._selectionObj.style.display = '';
}
}PK WAIp# $ spreadsheet/codebase/dhtmlxsh_css.js /**
(c) DHTMLX Ltd, 2011
Licensing: You allowed to use this component for free under GPL or you need to obtain Commercial/Enterprise license to use it in non-GPL project
Contact: sales@dhtmlx.com
**/
/*! class for cells style control
**/
function SpreadSheetCss() {
this.rules = {
bold: "false",
italic: "false",
color: "000000",
bgcolor: "ffffff",
align: "left",
validator: "none",
lock: "false"
};
}
SpreadSheetCss.prototype = {
/*! set rule
* @param name
* rule name
* @param value
* rule value
**/
set: function(name, value) {
this.rules[name] = value;
},
/*! returns rule by name
* @param name
* rule name
* @return
* value if exists or false otherwise
**/
get: function(name) {
if (this.rules[name])
return this.rules[name];
else
return false;
},
/*! returns rules as object
**/
get_json: function() {
return this.rules;
},
set_json: function(rules) {
this.rules = rules;
},
get_css: function() {
var css = '';
for (var i in this.rules)
if (this[i + "_to_css"]) css += this[i + "_to_css"](this.rules[i]);
return css;
},
bold_to_css: function(value) {
if (value == "true")
return "font-weight: bold;";
else
return "font-weight: normal;";
},
italic_to_css: function(value) {
if (value == "true")
return "font-style: italic;";
else
return "font-style: normal;";
},
bgcolor_to_css: function(value) {
return "background-color: #" + value + ";";
},
align_to_css: function(value) {
return "text-align: " + value + ";";
},
color_to_css: function(value){
return "color:#"+value+";";
},
validator_to_css: function(value){
return "";
},
lock_to_css: function(value){
return "";
},
serialize: function() {
var style = [];
for (var i in this.rules)
if (this.rules[i] == 'true')
style.push('1');
else if (this.rules[i] == 'false')
style.push('0');
else
style.push(this.rules[i]);
return style.join(";");
},
unserialize: function(style) {
style = style.split(';');
var c = 0;
for (var i in this.rules) {
var value = style[c];
if (value == '0') value = 'false';
if (value == '1') value = 'true';
this.rules[i] = value;
c++;
}
}
};PK WA ms n ' spreadsheet/codebase/dhtmlxsh_export.jsn/**
(c) DHTMLX Ltd, 2011
Licensing: You allowed to use this component for free under GPL or you need to obtain Commercial/Enterprise license to use it in non-GPL project
Contact: sales@dhtmlx.com
**/
dhtmlxSpreadSheet.prototype.toPDF = function(url) {
var xml = this._getExport(true);
var form = document.createElement('div');
form.style.display = 'none';
document.body.appendChild(form);
form.innerHTML = '';
form.firstChild.firstChild.value = xml;
form.firstChild.submit();
form.parentNode.removeChild(form);
};
dhtmlxSpreadSheet.prototype.toExcel = function(url) {
var xml = this._getExport();
var iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.name = 'dhx_' + this.grid.uid();
iframe.onload = function() {
window.setTimeout(function() {
iframe.parentNode.removeChild(iframe);
}, 3000);
};
document.body.appendChild(iframe);
var form = document.createElement('div');
form.style.display = 'none';
document.body.appendChild(form);
form.innerHTML = '';
form.firstChild.firstChild.value = xml;
form.firstChild.submit();
form.parentNode.removeChild(form);
};
dhtmlxSpreadSheet.prototype._getExport = function(firstcol) {
var maxrow = 0, maxcol = 1;
this.mapCells(1, 1, this.settings.rows, this.settings.cols, function(row, col) {
var cell = this.getCellValue(row, col);
if (cell.value.length > 0) {
if (row > maxrow) maxrow = row;
if (col > maxcol) maxcol = col;
}
});
if (maxrow < 5) maxrow = Math.min(5 || this.settings.rows);
if (maxcol < 5) maxcol = Math.min(5 || this.settings.cols);
var head = this._getExportHeader(maxrow, maxcol, firstcol);
var rows = this._getExportData(maxrow, maxcol, firstcol);
var orient = this._getExportWidth(maxrow, maxcol, firstcol);
var xml = '' + head + '' + rows + '';
return xml;
};
dhtmlxSpreadSheet.prototype._getExportHeader = function(maxrow, maxcol, firstcol) {
var cols = [];
if (firstcol) {
var firstcol = this._headToXML({ name: '#', width: 100 });
cols.push(firstcol);
}
var summarywidth = 0;
for (var i = 1; i <= maxcol; i++) {
var col = this.getCol(i);
summarywidth += col.width;
var xml = this._headToXML(col);
cols.push(xml);
}
if (firstcol) cols[0] = this._headToXML({ name: '#', width: Math.round(summarywidth*0.04) });
return '' + cols.join('') + '';
};
dhtmlxSpreadSheet.prototype._getExportWidth = function(maxrow, maxcol, firstcol) {
var summarywidth = 0;
for (var i = 1; i <= maxcol; i++)
summarywidth += this.getCol(i).width;
if (firstcol) summarywidth += summarywidth*0.04;
if (summarywidth < 1200) return '';
return ' orientation="landscape"';
};
dhtmlxSpreadSheet.prototype._headToXML = function(col) {
var xml = '';
return xml;
};
dhtmlxSpreadSheet.prototype._getExportData = function(maxrow, maxcol, firstcol) {
var rows = [];
this.mapCells(1, 1, maxrow, maxcol, function(row, col, rind, cind) {
var cell = this.getCellValue(row, col);
cell.style = this.getCellStyle(row, col);
if (!rows[rind]) {
rows[rind] = [];
if (firstcol) rows[rind].push('' + row + '');
}
rows[rind].push(this._cellToXML(cell));
});
for (var i = 0; i < rows.length; i++)
rows[i] = '' + rows[i].join('') + ''
return rows.join('');
};
dhtmlxSpreadSheet.prototype._cellToXML = function(cell) {
var xml = "";
xml += cell.value || ' ';
xml += "";
return xml;
};PK WAԅY
) spreadsheet/codebase/dhtmlxsh_headedit.js
/**
(c) DHTMLX Ltd, 2011
Licensing: You allowed to use this component for free under GPL or you need to obtain Commercial/Enterprise license to use it in non-GPL project
Contact: sales@dhtmlx.com
**/
var SpreadSheetHeaderEditor = {
ed: null,
init:function(){
dhtmlxEvent(document.body, "mousedown", function(e) {
var target = e.target || e.srcElement;
if (target == SpreadSheetHeaderEditor.ed) return;
SpreadSheetHeaderEditor.editStop();
});
return SpreadSheetHeaderEditor;
},
get_input: function() {
var ed = document.createElement('input');
SpreadSheetHeaderEditor.target.innerHTML = '';
SpreadSheetHeaderEditor.target.appendChild(ed);
SpreadSheetHeaderEditor.target.className = SpreadSheetHeaderEditor.target.className + ' no_paddings';
ed.className = 'header_editor';
ed.value = SpreadSheetHeaderEditor.value;
return ed;
},
editStart: function(target, value, callback) {
if (target === SpreadSheetHeaderEditor.ed) return false;
SpreadSheetHeaderEditor.target = target;
value = value.replace(/</g, '<');
value = value.replace(/>/g, '>');
SpreadSheetHeaderEditor.value = value;
SpreadSheetHeaderEditor.callback = callback;
SpreadSheetHeaderEditor.ed = SpreadSheetHeaderEditor.get_input();
target.parentNode.className += ' no_paddings_parent';
dhtmlxEvent(SpreadSheetHeaderEditor.ed, "keydown", function(e) {
var code = e.which||e.keyCode;
if (code == 13 || code == 9)
SpreadSheetHeaderEditor.editStop();
else if (code == 27)
SpreadSheetHeaderEditor.editStop(true);
});
SpreadSheetHeaderEditor.ed.focus();
},
editStop: function(dont_save) {
if (SpreadSheetHeaderEditor.ed === null) return;
dont_save = dont_save || false;
var value = (dont_save === true) ? SpreadSheetHeaderEditor.value : SpreadSheetHeaderEditor.ed.value;
value = value.replace(//g, '>');
SpreadSheetHeaderEditor.target.removeChild(SpreadSheetHeaderEditor.ed);
SpreadSheetHeaderEditor.target.innerHTML = value;
SpreadSheetHeaderEditor.target.className = SpreadSheetHeaderEditor.target.className.replace(' no_paddings', '');
SpreadSheetHeaderEditor.target.parentNode.className = SpreadSheetHeaderEditor.target.parentNode.className.replace(' no_paddings_parent', '');
if (SpreadSheetHeaderEditor.callback && SpreadSheetHeaderEditor.value != value)
SpreadSheetHeaderEditor.callback[0].saveHeadCell(SpreadSheetHeaderEditor.callback[1], value, SpreadSheetHeaderEditor.callback[2]);
SpreadSheetHeaderEditor.unload();
},
unload: function() {
SpreadSheetHeaderEditor.ed = null;
SpreadSheetHeaderEditor.value = null;
SpreadSheetHeaderEditor.callback = null;
SpreadSheetHeaderEditor.target = null;
}
};PK WA},M H % spreadsheet/codebase/dhtmlxsh_keys.jsH/**
(c) DHTMLX Ltd, 2011
Licensing: You allowed to use this component for free under GPL or you need to obtain Commercial/Enterprise license to use it in non-GPL project
Contact: sales@dhtmlx.com
**/
dhtmlxSpreadSheet.prototype.attachGridKeys = function(grid) {
if (!grid._key_events.k13_0_0_original) {
var k13_0_0_original = grid._key_events.k13_0_0;
var k13_0_0 = function() {
if (this.ssheet.settings.math === true && this.editor && SpreadSheetMathHint.used(false)) return false;
this.editStop();
this.callEvent("onEnter", [
(this.row ? this.row.idd : null),
(this.cell ? this.cell._cellIndex : null)
]);
k13_0_0_original.call(this);
this._still_active=true;
};
grid._key_events.k13_0_0 = function() {
k13_0_0.apply(grid, arguments);
};
}
// clear selected cells functionality
grid._key_events.k46_0_0 = function() {
if (this.editor) return false;
SpreadsheetBuffer.getArea().value = "";
SpreadsheetBuffer.from_area();
};
// tab is pressed
grid._key_events.k9_0_0 = function() {
this.editStop();
if (!this.callEvent("onTab",[true])) return true;
if (this.cell && (this.cell._cellIndex+1)>=this._cCount) return;
this._clearBlockSelection();
var z=this._getNextCell(null,1);
if (z && this.row==z.parentNode){
this.selectCell(z.parentNode,z._cellIndex,true,true);
this._still_active=true;
}
};
// shift + left
grid._key_events.k39_0_1 = function() {
if (this.editor) return false;
this._selectionLeft(1);
};
// shift + right
grid._key_events.k37_0_1 = function() {
if (this.editor) return false;
this._selectionRight(1);
};
// shift + up
grid._key_events.k38_0_1 = function() {
if (this.editor) return false;
this._selectionUp(1);
};
// shift + down
grid._key_events.k40_0_1 = function() {
if (this.editor) return false;
this._selectionDown(1);
};
// shift + page_up
grid._key_events.k33_0_1 = function() {
if (this.editor) return false;
this._selectionUp(30);
};
// shift + page_down
grid._key_events.k34_0_1 = function() {
if (this.editor) return false;
this._selectionDown(30);
};
// hide block selection when right
if (!grid._key_events.k39_0_0_original) {
var k39_0_0_original = grid._key_events.k39_0_0;
grid._key_events.k39_0_0 = function() {
if (this.editor) return false;
this._clearBlockSelection();
k39_0_0_original.call(this);
};
}
// hide block selection when left
if (!grid._key_events.k37_0_0_original) {
var k37_0_0_original = grid._key_events.k37_0_0;
grid._key_events.k37_0_0 = function() {
if (this.editor) return false;
this._clearBlockSelection();
k37_0_0_original.call(this);
};
}
// hide block selection when left
if (!grid._key_events.k38_0_0_original) {
var k38_0_0_original = grid._key_events.k38_0_0;
grid._key_events.k38_0_0 = function() {
if (this.editor) return false;
this._clearBlockSelection();
k38_0_0_original.call(this);
};
}
// hide block selection when left
if (!grid._key_events.k40_0_0_original) {
var k40_0_0_original = grid._key_events.k40_0_0;
grid._key_events.k40_0_0 = function() {
if (this.editor) return false;
this._clearBlockSelection();
k40_0_0_original.call(this);
};
}
grid._key_events.k37_1_0 = function(){
if (this.editor) return false;
this.selectCell(this.row,1,true);
};
// ctrl+A hot key
grid._key_events.k65_1_0 = function() {
if (this.editor) return false;
this._selectAll();
};
// ctrl + Home
grid._key_events.k36_1_0 = function() {
if (this.editor || !this.rowsCol.length) return false;
this.selectCell(this.rowsCol[0],1,true);
};
// ctrl+I - italic
grid._key_events.k73_1_0 = function() {
if (this.editor) return false;
var state = this.ssheet.toolbar.getItemState('italic');
this.ssheet.setCellsStyle('italic', !state);
};
// Ctrl+B - bold
grid._key_events.k66_1_0 = function() {
if (this.editor) return false;
var state = this.ssheet.toolbar.getItemState('bold');
this.ssheet.setCellsStyle('bold', !state);
};
// Ctrl+Z
grid._key_events.k90_1_0 = function() {
if (this.editor) return false;
this.ssheet._undo("undo");
};
// Ctrl+Y
grid._key_events.k89_1_0 = function() {
if (this.editor) return false;
this.ssheet._undo("redo");
};
grid._key_events.k_other = function(ev) {
if (this.editor) return false;
if (!ev.ctrlKey && !ev.metaKey && ev.keyCode>=40 && (ev.keyCode < 91 || (ev.keyCode >95 && ev.keyCode <111) || ev.keyCode >= 187))
if (this.cell) {
var c=this.cells4(this.cell);
if (c.isDisabled()) return false;
var t=c.getValue();
this.editCell();
if (this.editor) {
this.editor.val=t;
if (this.editor.obj && this.editor.obj.select)
this.editor.obj.select();
} else c.setValue(t);
}
};
};PK WA ' spreadsheet/codebase/dhtmlxsh_loader.js /**
(c) DHTMLX Ltd, 2011
Licensing: You allowed to use this component for free under GPL or you need to obtain Commercial/Enterprise license to use it in non-GPL project
Contact: sales@dhtmlx.com
**/
SpreadsheetLoader = {
request: function(url, params, callback, master, method) {
method = method || 'ajax';
switch (method) {
case 'jsonp':
this.jsonp(url, params, callback, master);
break;
case 'ajax':
default:
this.ajax(url, params, callback, master);
break;
}
},
jsonp: function(url, params, callback, master){
var id = "dhx_jsonp_" + this.uid();
var script = document.createElement('script');
script.id = id;
script.type = 'text/javascript';
var head = document.getElementsByTagName("head")[0];
if (!params)
params = {};
params.jsonp = "SpreadsheetLoader."+id;
this[id]=function(){
callback.apply(master||window, arguments);
script.parentNode.removeChild(script);
callback = head = master = script = null;
delete this[id];
};
var vals = [];
for (var key in params)
if (typeof(params[key]) == "object")
for (var index in params[key])
vals.push(key + '[' + index + ']=' + encodeURIComponent(params[key][index]));
else
vals.push(key + "=" + encodeURIComponent(params[key]));
url += (url.indexOf("?") == -1 ? "?" : "&") + vals.join("&");
script.src = url;
head.appendChild(script);
},
ajax: function(url, params, callback) {
params = this.serialize(params);
dhtmlxAjax.post(url, params, function(response) {
if (response.xmlDoc.responseText !== '')
callback(eval('(' + response.xmlDoc.responseText + ')'));
});
},
serialize: function(params, parent) {
var parent_start = (!parent) ? '' : parent + '[';
var parent_end = (!parent) ? '' : ']';
var text = [];
for (var i in params) {
if (typeof(params[i]) == 'function') continue;
if (typeof(params[i]) == 'object')
text.push(this.serialize(params[i], (!parent)? i : parent + '[' + i + ']'));
else
text.push(parent_start + i + parent_end + "=" + encodeURIComponent(params[i]));
}
return text.join('&');
},
uid: function() {
if (!this._seed) this._seed=(new Date).valueOf(); //init seed with timestemp
this._seed++;
return this._seed;
}
};PK WA:)WG G ) spreadsheet/codebase/dhtmlxsh_mathhint.jsGW/**
(c) DHTMLX Ltd, 2011
Licensing: You allowed to use this component for free under GPL or you need to obtain Commercial/Enterprise license to use it in non-GPL project
Contact: sales@dhtmlx.com
**/
if (typeof(SpreadSheetConfig) === 'undefined')
var SpreadSheetConfig;
var SpreadSheetMathHint = {
selected: null,
input: null,
init: function(input) {
for (var i = 0; i < this.details.length; i++)
this.hints[this.details[i].regexp] = this.details[i].hint;
this.mathHint = document.createElement('div');
this.mathHint.className = 'mathHint';
var self = this;
this.mathHint.onclick = function(e) {
e = e || window.event;
e.cancelBubble = true;
self.filter(self.input.value);
};
this.input = input;
document.body.appendChild(this.mathHint);
},
filter: function(text) {
if (text.substring(0, 1) !== '=') return true;
var regexp = /([A-Z0-9]+\()[^\)]*\)?$/i;
var match = regexp.exec(text);
if ((match)&&(typeof(match[1]) != 'undefined')) {
match[0] = match[1];
} else {
regexp = /[A-Z0-9]+\(?$/i;
match = regexp.exec(text);
}
if (match) {
if (typeof(match[0]) != 'undefined')
match = match[0];
else {
this.mathHint.style.display = 'none';
return true;
}
} else {
this.mathHint.style.display = 'none';
return true;
}
match = match.toUpperCase();
var matches = [];
for (var i in this.hints)
if (i.indexOf(match) === 0)
matches.push(this.hints[i]);
if (matches.length > 0)
this.show();
else
this.hide();
this.set(matches);
},
show: function() {
var object = (this.input.parentNode && this.input.parentNode.tagName.toLowerCase() == 'td') ? this.input.parentNode : this.input;
var pos = SpreadSheetConfig.get_pos(object);
this.mathHint.style.left = pos.x + 'px';
this.mathHint.style.top = (pos.y + this.input.offsetHeight - 1) + 'px';
this.mathHint.style.display = 'block';
},
hide: function() {
if (this.mathHint)
this.mathHint.style.display = 'none';
},
next: function() {
var list = this.mathHint.firstChild;
var selected = false;
if (list && list.childNodes.length > 0) {
for (var i = 0; i < list.childNodes.length; i++) {
if (list.childNodes[i].className.indexOf(' selected') !== -1) {
list.childNodes[i].className = list.childNodes[i].className.replace(' selected', '');
selected = true;
break;
}
}
if (selected) {
var index = i + 1;
if (index >= list.childNodes.length) index = 0;
list.childNodes[index].className += ' selected';
this.selected = list.childNodes[index].innerHTML;
}
}
},
prev: function() {
var list = this.mathHint.firstChild;
var selected = false;
if (list && list.childNodes.length > 0) {
for (var i = list.childNodes.length - 1; i >= 0; i--) {
if (list.childNodes[i].className.indexOf(' selected') !== -1) {
list.childNodes[i].className = list.childNodes[i].className.replace(' selected', '');
selected = true;
break;
}
}
if (selected) {
var index = i - 1;
if (index < 0) index = list.childNodes.length - 1;
list.childNodes[index].className += ' selected';
this.selected = list.childNodes[index].innerHTML;
}
}
},
first: function() {
var list = this.mathHint.firstChild;
this.unselect();
if (list && list.childNodes.length > 0) {
list.firstChild.className += ' selected';
this.selected = list.firstChild.innerHTML;
}
},
unselect: function() {
var list = this.mathHint.firstChild;
for (var i = 0; i < list.childNodes.length; i++)
list.childNodes[i].className = list.childNodes[i].className.replace(' selected', '');
},
select: function(innerHTML) {
this.unselect();
var list = this.mathHint.firstChild;
if (list && list.childNodes.length > 0) {
for (var i = 0; i < list.childNodes.length; i++)
if (list.childNodes[i].innerHTML == innerHTML) {
list.childNodes[i].className += ' selected';
this.selected = innerHTML;
return true;
}
}
return false;
},
set: function(hints) {
for (var i = 0; i < hints.length; i++)
hints[i] = '
' + hints[i] + '
';
this.mathHint.innerHTML = '
' + hints.join("") + '
';
if (this.selected) {
if (!this.select(this.selected))
this.first();
} else
this.first();
},
getHintsNumber: function() {
var list = this.mathHint.firstChild;
if (list)
return list.childNodes.length;
else
return 0;
},
use: function() {
var text = this.input.value;
var regexp = /[A-Z0-9]+\(?$/i;
var match = regexp.exec(text);
if (match) {
for (var i in this.hints) {
if (this.hints[i] == this.selected)
text = text.replace(regexp, i);
}
this.input.value = text;
window.setTimeout(function() {
SpreadSheetMathHint.input.focus();
SpreadSheetMathHint.lookAtCursor(SpreadSheetMathHint.input);
}, 50);
return true;
} else {
window.setTimeout(function() {
SpreadSheetMathHint.input.focus();
}, 50);
return false;
}
},
used: function(check) {
var text = this.input.value;
check = check || false;
if (this.getHintsNumber() === 0) return true;
var regexp = /([A-Z0-9]+\(\))$/i;
var match = regexp.exec(text);
if (!match) {
regexp = /([A-Z0-9]+\()$/i;
match = regexp.exec(text);
}
if (!match) {
regexp = /([A-Z0-9]+\()[^\)]*\)?$/i;
match = regexp.exec(text);
}
if ((match)&&(typeof(match[1]) != 'undefined')) {
match = match[1].toUpperCase();
for (var i in this.hints) {
if (i.indexOf(match) === 0)
if (match == i || check === true)
return true;
}
}
return false;
},
attachEvent: function(input, ssheet) {
this.set([]);
this.input = input;
var self = this;
this.cursor = input.value.length - 1;
input.ssheet = ssheet;
input.onmousedown = function(e) {
e = window.event||e;
var el = e.srcElement||e.target;
window.setTimeout(function() {
self.lookAtCursor(el);
}, 10);
return true;
};
if (!input._math_added)
dhtmlxEvent(input, "keydown", function(e) {
e = e||window.event;
var code = e.keyCode||e.which;
if ((code === 9)&&(SpreadSheetMathHint.used(true) === true)) {
return (ssheet.grid.editor ? true : false);
}
if (code !== 13) {
var el = e.srcElement||e.target;
window.setTimeout(function() {
self.lookAtCursor(el);
}, 10);
}
return self.mathKeyDown(e);
});
input._math_added = true;
window.setTimeout(function() {
self.showBorders(input);
self.lookAtCursor(input);
}, 10);
},
lookAtCursor: function(el) {
if (typeof(el.ssheet) === 'undefined')
return false;
if (!el.parentNode) return;
this.cursor = this.getCursorPos(el);
if (this.cursor === -1)
this.cursor = el.value.length;
},
getCaret: function(node) {
if (typeof(node.selectionStart) !== 'undefined') {
return node.selectionStart;
} else if (!document.selection) {
return 0;
}
var c = "\001";
var sel = document.selection.createRange();
var dul = sel.duplicate();
var len = 0;
dul.moveToElementText(node);
sel.text = c;
len = dul.text.indexOf(c);
sel.moveStart('character',-1);
sel.text = "";
return len;
},
mathKeyDown: function(e) {
var self = this;
var input = this.input;
var code = e.keyCode||e.which;
if (code == 40) {
this.next();
return false;
}
if (code == 38) {
this.prev();
return false;
}
if (code == 13) {
if (this.used()) {
input.ssheet.grid.clearBorderSelection();
input.ssheet.mathSave(input);
input.ssheet.grid._key_events.k13_0_0();
return true;
} else {
input.ssheet.grid.autocomplete = true;
this.use(input);
}
}
if (code == 27) {
input.ssheet.grid.clearBorderSelection();
input.ssheet.mathCancel();
return true;
}
window.setTimeout(function() {
self.showBorders(input);
self.lookAtCursor(input);
self.filter(input.value);
}, 100);
return true;
},
showBorders: function(input) {
if (typeof(input.ssheet) === 'undefined')
return false;
if (input.value.substring(0, 1) !== '=') {
input.ssheet.grid.clearBorderSelection();
input.ssheet.grid.enableBorderSelection(false);
return true;
}
input.ssheet.grid.enableBorderSelection(true);
input.ssheet.grid.clearBorderSelection();
var regexp = /\$?([A-Z]+)\$?(\d+):\$?([A-Z]+)\$?(\d+)/i;
var value = input.value;
while (regexp.test(value)) {
var matches = regexp.exec(value);
value = value.replace(regexp, '');
var LeftTopRow = matches[2];
var LeftTopCol = input.ssheet.getColIndex(matches[1]);
var RightBottomRow = matches[4];
var RightBottomCol = input.ssheet.getColIndex(matches[3]);
input.ssheet.grid.addBorderSelection(LeftTopRow, LeftTopCol, RightBottomRow, RightBottomCol);
}
regexp = /\$?([A-Z]+)\$?(\d+)/i;
while (regexp.test(value)) {
var matches = regexp.exec(value);
value = value.replace(regexp, '');
var LeftTopRow = matches[2];
var LeftTopCol = input.ssheet.getColIndex(matches[1]);
var RightBottomRow = LeftTopRow;
var RightBottomCol = LeftTopCol;
input.ssheet.grid.addBorderSelection(LeftTopRow, LeftTopCol, RightBottomRow, RightBottomCol);
}
},
setRange: function(range) {
var formula = this.input.value.substring(0, this.cursor);
var regexp = /\$?([A-Z]+)\$?(\d+):\$?([A-Z]+)\$?(\d+)$/i;
if (regexp.test(formula)) {
formula = formula.replace(regexp, range);
} else {
regexp = /\$?([A-Z]+)\$?(\d+)$/i;
if (regexp.test(formula))
formula = formula.replace(regexp, range);
else {
formula += range;
}
}
var pos = formula.length;
formula += this.input.value.substring(this.cursor);
this.input.value = formula;
this.cursor = formula.length;
this.setCursorPos(this.input, pos);
this.cursor = pos;
this.filter(this.input.value);
this.showBorders(this.input);
},
getCursorPos: function(el) {
el.focus();
if(el.selectionStart) {
return el.selectionStart;
}
if (document.selection) {
var r = document.selection.createRange();
if (r === null) {
return el.value.length;
}
var re = el.createTextRange();
var rc = re.duplicate();
re.moveToBookmark(r.getBookmark());
rc.setEndPoint('EndToStart', re);
return rc.text.length;
}
return el.value.length;
},
setCursorPos: function(el, pos) {
el.focus();
if (el.setSelectionRange) {
el.setSelectionRange(pos, pos);
} else if (el.createTextRange) {
var range = el.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
},
hints: {},
details: [
{
name: 'SUM',
regexp: 'SUM(',
hint: 'SUM(arg1; arg2; arg3; ...)',
dsc: 'Sums the arquments ',
samples: '=SUM(1; 3; 5) // the result is 9'
}, {
name: 'SUB',
regexp: 'SUB(',
hint: 'SUB(arg1; arg2; arg3; ...)',
dsc: 'Subtracts the second and subsequent arguments from the first argument',
samples: '=SUB(10; 3; 5) // the result is 2'
}, {
name: 'MULT',
regexp: 'MULT(',
hint: 'MULT(arg1; arg2; arg3; ...)',
dsc: 'Multiplies the arquments',
samples: '=MULT(2; 3; 5) // the result is 30'
}, {
name: 'DIV',
regexp: 'DIV(',
hint: 'DIV(arg1; arg2; arg3; ...)',
dsc: 'Divides the first argument by the second and subsequent arguments',
samples: '=DIV(20;2;5) // the result is 2'
}, {
name: 'SQRT',
regexp: 'SQRT(',
hint: 'SQRT(arg1)',
dsc: 'Returns the square root of the argument ',
samples: '=SQRT(16) // the result is 4'
}, {
name: 'SQR',
regexp: 'SQR(',
hint: 'SQR(arg1)',
dsc: 'Returns the square of the arqument',
samples: '=SQR(3) // the result is 9'
}, {
name: 'POW',
regexp: 'POW(',
hint: 'POW(arg1; arg2)',
dsc: 'Returns the first argument raised to power of the second argument ',
samples: '=POW(2;5) // the result is 32'
}, {
name: 'MOD',
regexp: 'MOD(',
hint: 'MOD(arg1; arg2)',
dsc: 'Returns the remainder after the first argument is divided by the second argument',
samples: '=MOD(10;4) // the result is 2'
}, {
name: 'ABS',
regexp: 'ABS(',
hint: 'ABS(arg1)',
dsc: ' Returns the absolute value of the argument ',
samples: '=ABS(-5) // the result is 5 =ABS(5) // the result is 5'
}, {
name: 'EXP',
regexp: 'EXP(',
hint: 'EXP(arg1)',
dsc: 'Returns e raised to power of the argument ',
samples: '=EXP(2) // the result is 7.3890561 '
}, {
name: 'LN',
regexp: 'LN(',
hint: 'LN(arg1)',
dsc: 'Returns the natural logarithm of the argument ',
samples: '=LN(7.3890561) // the result is 2 '
}, {
name: 'LOG',
regexp: 'LOG(',
hint: 'LOG(arg1; arg2)',
dsc: 'Returns the logarithm of the first argument to a base of the second argument',
samples: '=LOG(32;2) // the result is 5 '
}, {
name: 'LOG10',
regexp: 'LOG10(',
hint: 'LOG10(arg1)',
dsc: 'Returns the base-10 logarithm of the argument ',
samples: '=LOG10(100) // the result is 2 '
}, {
name: 'SIN',
regexp: 'SIN(',
hint: 'SIN(arg1)',
dsc: 'Returns the sine of the argument ',
samples: '=SIN(0) // the result is 0 '
}, {
name: 'COS',
regexp: 'COS(',
hint: 'COS(arg1)',
dsc: 'Returns the cosine of the arqument ',
samples: '=COS(0) // the result is 1 '
}, {
name: 'TAN',
regexp: 'TAN(',
hint: 'TAN(arg1)',
dsc: 'Returns the tangent of the argument ',
samples: '=TAN(0) // the result is 0 '
}, {
name: 'ASIN',
regexp: 'ASIN(',
hint: 'ASIN(arg1)',
dsc: 'Returns the arcsine (in radians) of the argument ',
samples: '=ASIN(0) // the result is 0 '
}, {
name: 'ACOS',
regexp: 'ACOS(',
hint: 'ACOS(arg1)',
dsc: 'Returns the arccosine (in radians) of the arqument ',
samples: '=ACOS(1) // the result is 0 '
}, {
name: 'ATAN',
regexp: 'ATAN(',
hint: 'ATAN(arg)',
dsc: 'Returns the arctangent (in radians) of the argument ',
samples: '=ATAN(1) // the result is 0.78539816 '
}, {
name: 'PI',
regexp: 'PI()',
hint: 'PI()',
dsc: 'Returns the mathematical constant called pi',
samples: '=PI() // the result is 3.14159265'
}
],
all: function(parent, callback) {
SpreadSheetModal.show(parent);
var d = document.createElement("DIV");
d.className = "dhx_spread_window functions_window";
parent.appendChild(d);
d.innerHTML = this.getForm();
var left = (parent.offsetWidth - d.offsetWidth)/2 + 'px';
var top = (parent.offsetHeight - d.offsetHeight)/2 + 'px';
d.style.left = left;
d.style.top = top;
this._all_cont = d;
var btns = d.getElementsByTagName('input');
var self = this;
// insert callback
btns[0].onclick = function() { self.functions_enter(callback); };
// cancel callback
btns[1].onclick = function() { self.functions_escape(callback); };
var sel = this._all_cont.getElementsByTagName('select');
sel = sel[0];
dhtmlxEvent(sel, "keydown", function() {
var code = e.keyCode||e.which;
if (code === 13) self.functions_enter(callback);
if (code == 27) self.functions_escape(callback);
});
dhtmlxEvent(sel, "dblclick", function() {
self.functions_enter(callback);
});
sel.focus();
this.functionDetails(this.details[0].name);
},
getForm: function() {
var str = "
";
str += "
";
str += "";
str += "
";
str += "";
str += "
";
str += "";
str += "";
str += "
";
str += "
";
str += "";
return str;
},
functionDetails: function(f) {
if (!this._all_cont) return;
var sel = this._all_cont.getElementsByTagName('select');
sel = sel[0];
if (f)
sel.value = f;
else
f = sel.options[sel.selectedIndex].value;
var item = this.function_by_name(f);
if (item === false) return;
var str = "
Name: " + item.name + "
";
str += "
Description: " + item.dsc + "
";
str += "
Usage: " + item.hint + "
";
if (item.samples)
str += "
Example: " + item.samples + "
";
this._all_cont.childNodes[0].childNodes[1].innerHTML = str;
},
close_all: function() {
this._all_cont.parentNode.removeChild(this._all_cont);
SpreadSheetModal.hide();
},
get_all_selection: function() {
var sel = this._all_cont.getElementsByTagName('select');
sel = sel[0];
var f = sel.options[sel.selectedIndex].value;
return this.function_by_name(f);
},
function_by_name: function(name) {
for (var i = 0; i < this.details.length; i++)
if (this.details[i].name == name) {
return this.details[i];
break;
}
return false;
},
functions_enter: function(callback) {
var f = this.get_all_selection();
this.close_all();
if (typeof(callback.insert) !== 'undefined') callback.insert(f);
},
functions_escape: function(callback) {
this.close_all();
if (typeof(callback.insert) !== 'undefined') callback.cancel();
},
function_ending: function(value) {
var regexp = /^=.*\([^\)]*$/i;
var match = regexp.exec(value);
if (match) value += ')';
return value;
}
};PK WAl4l &