Skip to content

Commit c842025

Browse files
committed
parseFormula global, copy/paste IE old, set borders prev.
1 parent d6044ef commit c842025

File tree

2 files changed

+100
-72
lines changed

2 files changed

+100
-72
lines changed

dist/jexcel.css

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -640,44 +640,16 @@
640640
display:none;
641641
}
642642

643-
/*.copying
643+
.jexcel_border
644644
{
645-
border-top:1px solid #ccc !important;
646-
border-left:1px solid #ccc !important;
647-
border-right:1px solid #fff !important;
648-
border-bottom:1px solid #fff !important;
649-
}
650-
651-
.copying-top
652-
{
653-
border-top:1px solid transparent !important;
654-
}
655-
656-
.copying-bottom
657-
{
658-
border-bottom:1px solid transparent !important;
659-
}
660-
661-
.copying-left
662-
{
663-
border-left:1px solid transparent !important;
664-
}
665-
666-
.copying-right
667-
{
668-
border-right:1px solid transparent !important;
669-
}
670-
671-
.copying
672-
{
673-
background: linear-gradient(white, white) padding-box, repeating-linear-gradient(-45deg, black 0, black 25%, transparent 0, transparent 50%) 0 / .6em .6em !important;
674-
animation: ants 12s linear infinite;
645+
position:absolute;
646+
border:1px solid transparent;
647+
pointer-events: none;
675648
}
676649

677-
@keyframes ants
650+
.jexcel_copying
678651
{
679-
to
680-
{
681-
background-position: 50% 50%
682-
}
683-
}*/
652+
border:1px solid transparent;
653+
border-image: url('data:image/gif;base64,R0lGODlhCgAKAJECAAAAAP///////wAAACH/C05FVFNDQVBFMi4wAwEAAAAh/wtYTVAgRGF0YVhNUDw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOT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KyopKCcmJSQjIiEgHx4dHBsaGRgXFhUUExIREA8ODQwLCgkIBwYFBAMCAQAAIfkEBQoAAgAsAAAAAAoACgAAAhWEERkn7W3ei7KlagMWF/dKgYeyGAUAIfkEBQoAAgAsAAAAAAoACgAAAg+UYwLJ7RnQm7QmsCyVKhUAIfkEBQoAAgAsAAAAAAoACgAAAhCUYgLJHdiinNSAVfOEKoUCACH5BAUKAAIALAAAAAAKAAoAAAIRVISAdusPo3RAzYtjaMIaUQAAIfkEBQoAAgAsAAAAAAoACgAAAg+MDiem7Q8bSLFaG5il6xQAIfkEBQoAAgAsAAAAAAoACgAAAg+UYRLJ7QnQm7SmsCyVKhUAIfkEBQoAAgAsAAAAAAoACgAAAhCUYBLJDdiinNSEVfOEKoECACH5BAUKAAIALAAAAAAKAAoAAAIRFISBdusPo3RBzYsjaMIaUQAAOw==') 8% repeat;
654+
pointer-events: none;
655+
}

dist/jexcel.js

Lines changed: 91 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* (c) jExcel v3.4.2
2+
* (c) jExcel v3.4.3
33
*
44
* Author: Paul Hodel <[email protected]>
55
* Website: https://bossanova.uk/jexcel/
@@ -111,10 +111,13 @@ var jexcel = (function(el, options) {
111111
meta: null,
112112
// Style
113113
style:null,
114+
// Execute formulas
115+
parseFormulas:true,
114116
// Event handles
115117
onload:null,
116118
onchange:null,
117119
onbeforechange:null,
120+
onafterchange:null,
118121
onbeforeinsertrow: null,
119122
oninsertrow:null,
120123
onbeforeinsertcolumn: null,
@@ -220,6 +223,7 @@ var jexcel = (function(el, options) {
220223
obj.style = [];
221224
obj.meta = [];
222225
obj.data = null;
226+
obj.border = {};
223227

224228
// Internal controllers
225229
obj.cursor = null;
@@ -830,7 +834,7 @@ var jexcel = (function(el, options) {
830834
td.appendChild(img);
831835
}
832836
} else {
833-
if ((''+value).substr(0,1) == '=') {
837+
if ((''+value).substr(0,1) == '=' && obj.options.parseFormulas == true) {
834838
value = obj.executeFormula(value, i, j)
835839
}
836840
if (obj.options.columns[i].mask) {
@@ -1668,6 +1672,13 @@ var jexcel = (function(el, options) {
16681672

16691673
// Update table with custom configurations if applicable
16701674
obj.updateTable();
1675+
1676+
// On after change
1677+
if (! obj.ignoreEvents) {
1678+
if (typeof(obj.options.onafterchange) == 'function') {
1679+
obj.options.onafterchange(el, records, value);
1680+
}
1681+
}
16711682
}
16721683

16731684
/**
@@ -1694,6 +1705,13 @@ var jexcel = (function(el, options) {
16941705

16951706
// Update table with custom configurations if applicable
16961707
obj.updateTable();
1708+
1709+
// On after change
1710+
if (! obj.ignoreEvents) {
1711+
if (typeof(obj.options.onafterchange) == 'function') {
1712+
obj.options.onafterchange(el, records, value);
1713+
}
1714+
}
16971715
}
16981716

16991717
/**
@@ -1719,6 +1737,13 @@ var jexcel = (function(el, options) {
17191737
records:records,
17201738
selection:obj.selectedCell,
17211739
});
1740+
1741+
// On after change
1742+
if (! obj.ignoreEvents) {
1743+
if (typeof(obj.options.onafterchange) == 'function') {
1744+
obj.options.onafterchange(el, records);
1745+
}
1746+
}
17221747
}
17231748
}
17241749

@@ -1812,7 +1837,7 @@ var jexcel = (function(el, options) {
18121837
obj.options.data[y][x] = value;
18131838
}
18141839
// Label
1815-
if (('' + value).substr(0,1) == '=') {
1840+
if (('' + value).substr(0,1) == '=' && obj.options.parseFormulas == true) {
18161841
value = obj.executeFormula(value, x, y);
18171842
}
18181843
if (obj.options.columns[x].mask) {
@@ -1973,6 +1998,42 @@ var jexcel = (function(el, options) {
19731998

19741999
// Update table with custom configuration if applicable
19752000
obj.updateTable();
2001+
2002+
// On after change
2003+
if (! obj.ignoreEvents) {
2004+
if (typeof(obj.options.onafterchange) == 'function') {
2005+
obj.options.onafterchange(el, records);
2006+
}
2007+
}
2008+
}
2009+
2010+
obj.setBorder = function(x1, y1, x2, y2, border) {
2011+
if (! obj.border[border]) {
2012+
obj.border[border] = document.createElement('div');
2013+
obj.border[border].classList.add('jexcel_border');
2014+
if (border == 'copying') {
2015+
obj.border[border].classList.add('jexcel_copying');
2016+
} else {
2017+
obj.border[border].style.borderColor = border;
2018+
//obj.border[border].style.backgroundColor = 'rgba(0,0,0,0.1)';
2019+
}
2020+
el.appendChild(obj.border[border]);
2021+
}
2022+
2023+
// Get last cell
2024+
var first = obj.records[x1][y1].getBoundingClientRect();
2025+
var x1 = first.left;
2026+
var y1 = first.top;
2027+
2028+
var last = obj.records[x2][y2].getBoundingClientRect();
2029+
var w1 = (last.left + last.width) - first.left - 2;
2030+
var h1 = (last.top + last.height) - first.top - 2;
2031+
2032+
// Place the corner in the correct place
2033+
obj.border[border].style.top = y1 + 'px';
2034+
obj.border[border].style.left = x1 + 'px';
2035+
obj.border[border].style.width = w1 + 'px';
2036+
obj.border[border].style.height = h1 + 'px';
19762037
}
19772038

19782039
/**
@@ -5121,34 +5182,14 @@ var jexcel = (function(el, options) {
51215182
obj.textarea.value = str;
51225183
}
51235184
obj.textarea.select();
5124-
jexcel.copyControls.enabled = false;
51255185
document.execCommand("copy");
5126-
jexcel.copyControls.enabled = true;
51275186
}
51285187

51295188
// Keep data
51305189
obj.data = str;
51315190
// Keep non visible information
51325191
obj.hashString = obj.hash(obj.textarea.value);
51335192

5134-
// Highlight
5135-
/*for (var i = 0; i < obj.highlighted.length; i++) {
5136-
obj.highlighted[i].classList.add('copying');
5137-
5138-
if (obj.highlighted[i].classList.contains('highlight-top')) {
5139-
obj.highlighted[i].classList.add('copying-top');
5140-
}
5141-
if (obj.highlighted[i].classList.contains('highlight-right')) {
5142-
obj.highlighted[i].classList.add('copying-right');
5143-
}
5144-
if (obj.highlighted[i].classList.contains('highlight-bottom')) {
5145-
obj.highlighted[i].classList.add('copying-bottom');
5146-
}
5147-
if (obj.highlighted[i].classList.contains('highlight-left')) {
5148-
obj.highlighted[i].classList.add('copying-left');
5149-
}
5150-
}*/
5151-
51525193
return str;
51535194
}
51545195

@@ -5238,13 +5279,13 @@ var jexcel = (function(el, options) {
52385279
oldStyle:oldStyle,
52395280
});
52405281

5282+
// Update table
5283+
obj.updateTable();
5284+
52415285
// Paste event
52425286
if (typeof(obj.options.onpaste) == 'function') {
52435287
obj.options.onpaste(el, records);
52445288
}
5245-
5246-
// Update table
5247-
obj.updateTable();
52485289
}
52495290
}
52505291

@@ -5912,8 +5953,6 @@ jexcel.destroy = function(element, destroyEventHandlers) {
59125953
document.removeEventListener("mousemove", jexcel.mouseMoveControls);
59135954
document.removeEventListener("mouseover", jexcel.mouseOverControls);
59145955
document.removeEventListener("dblclick", jexcel.doubleClickControls);
5915-
document.removeEventListener("copy", jexcel.copyControls);
5916-
document.removeEventListener("cut", jexcel.cutControls);
59175956
document.removeEventListener("paste", jexcel.pasteControls);
59185957
document.removeEventListener("contextmenu", jexcel.contextMenuControls);
59195958
document.removeEventListener("touchstart", jexcel.touchStartControls);
@@ -5931,8 +5970,6 @@ jexcel.build = function() {
59315970
document.addEventListener("mousemove", jexcel.mouseMoveControls);
59325971
document.addEventListener("mouseover", jexcel.mouseOverControls);
59335972
document.addEventListener("dblclick", jexcel.doubleClickControls);
5934-
document.addEventListener("copy", jexcel.copyControls);
5935-
document.addEventListener("cut", jexcel.cutControls);
59365973
document.addEventListener("paste", jexcel.pasteControls);
59375974
document.addEventListener("contextmenu", jexcel.contextMenuControls);
59385975
document.addEventListener("touchstart", jexcel.touchStartControls);
@@ -6198,6 +6235,25 @@ jexcel.keyDownControls = function(e) {
61986235
// Ctrl + Z
61996236
jexcel.current.undo();
62006237
e.preventDefault();
6238+
} else if (e.which == 67) {
6239+
// Ctrl + C
6240+
jexcel.current.copy(true);
6241+
e.preventDefault();
6242+
} else if (e.which == 67) {
6243+
// Ctrl + C
6244+
jexcel.current.copy(true);
6245+
e.preventDefault();
6246+
} else if (e.which == 88) {
6247+
// Ctrl + X
6248+
if (jexcel.current.options.editable == true) {
6249+
jexcel.cutControls();
6250+
} else {
6251+
jexcel.copyControls();
6252+
}
6253+
e.preventDefault();
6254+
} else if (e.which == 86) {
6255+
// Ctrl + V
6256+
jexcel.pasteControls();
62016257
}
62026258
} else {
62036259
if (jexcel.current.selectedCell) {
@@ -6829,11 +6885,13 @@ jexcel.cutControls = function(e) {
68296885
jexcel.pasteControls = function(e) {
68306886
if (jexcel.current && jexcel.current.selectedCell) {
68316887
if (! jexcel.current.edition) {
6832-
if (e.clipboardData) {
6833-
if (jexcel.current.options.editable == true) {
6888+
if (jexcel.current.options.editable == true) {
6889+
if (e && e.clipboardData) {
68346890
jexcel.current.paste(jexcel.current.selectedCell[0], jexcel.current.selectedCell[1], e.clipboardData.getData('text'));
6891+
e.preventDefault();
6892+
} else if (window.clipboardData) {
6893+
jexcel.current.paste(jexcel.current.selectedCell[0], jexcel.current.selectedCell[1], window.clipboardData.getData('text'));
68356894
}
6836-
e.preventDefault();
68376895
}
68386896
}
68396897
}
@@ -6911,8 +6969,6 @@ jexcel.touchEndControls = function(e) {
69116969
}
69126970
}
69136971

6914-
jexcel.copyControls.enabled = true;
6915-
69166972
/**
69176973
* Jquery Support
69186974
*/

0 commit comments

Comments
 (0)