1+ 'use strict' ;
2+
3+ Object . defineProperty ( exports , "__esModule" , {
4+ value : true
5+ } ) ;
6+
7+ var _utils = require ( '../../src/utils/utils.js' ) ;
8+
9+ var _utils2 = _interopRequireDefault ( _utils ) ;
10+
11+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
12+
13+ exports . default = {
14+
15+ methods : {
16+ cellEdit : function cellEdit ( e , callback ) {
17+
18+ var target = e . target ,
19+ oldVal = void 0 ,
20+ editInput = void 0 ,
21+ editInputLen = void 0 ,
22+ _actionFun = void 0 ,
23+ textAlign = void 0 ;
24+
25+ while ( target . className && target . className . indexOf ( 'v-table-body-cell' ) === - 1 || ! target . className ) {
26+ target = target . parentNode ;
27+ }
28+
29+ if ( target . classList . contains ( 'cell-editing' ) ) {
30+ return false ;
31+ }
32+
33+ target . classList . add ( 'cell-editing' ) ;
34+
35+ oldVal = target . innerText ;
36+
37+ if ( target . style . textAlign ) {
38+
39+ textAlign = target . style . textAlign ;
40+ }
41+
42+ target . innerHTML = '<input type=\'text\' value="' + oldVal + '" class=\'cell-edit-input\' style=\'width:100%;height: 100%;text-align: ' + textAlign + ';\'>' ;
43+
44+ editInput = target . querySelector ( '.cell-edit-input' ) ;
45+ editInput . focus ( ) ;
46+
47+ editInputLen = editInput . value . length ;
48+ if ( document . selection ) {
49+ var ctr = editInput . createTextRange ( ) ;
50+ ctr . moveStart ( 'character' , editInputLen ) ;
51+ ctr . collapse ( ) ;
52+ ctr . select ( ) ;
53+ } else if ( typeof editInput . selectionStart == 'number' && typeof editInput . selectionEnd == 'number' ) {
54+ editInput . selectionStart = editInput . selectionEnd = editInputLen ;
55+ }
56+
57+ _actionFun = function actionFun ( e ) {
58+
59+ if ( typeof e . keyCode === 'undefined' || e . keyCode == 13 ) {
60+
61+ if ( target . classList . contains ( 'cell-editing' ) ) {
62+ target . classList . remove ( 'cell-editing' ) ;
63+ } else {
64+ return false ;
65+ }
66+
67+ target . innerText = this . value ;
68+
69+ callback ( this . value , oldVal ) ;
70+
71+ _utils2 . default . unbind ( editInput , 'blur' , _actionFun ) ;
72+ _utils2 . default . unbind ( editInput , 'keydown' , _actionFun ) ;
73+ }
74+ } ;
75+
76+ _utils2 . default . bind ( editInput , 'blur' , _actionFun ) ;
77+ _utils2 . default . bind ( editInput , 'keydown' , _actionFun ) ;
78+ }
79+ }
80+ } ;
0 commit comments