forked from jquery/jquery-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.js
More file actions
100 lines (94 loc) · 2.22 KB
/
editor.js
File metadata and controls
100 lines (94 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Inline Editor
*
* Depends on:
* widget
*
* Optional:
* spinner
*/
(function( $ ) {
$.widget( "ui.editor", {
options: {
editor: null,
editorOptions: null,
// callbacks
cancel: null,
submit: null
},
_create: function() {
this.inner = this.element.wrapInner( "<div class='editor-wrapper'></div>" ).children();
this._on({
dblclick: function( event ) {
if ( this.input.is(":visible") ) {
return;
}
this.start( event );
}
});
this.input = this.inputWrapper = $( "<input>" );
// TODO improve this to match the actual available space
// works only so-so for regular inputs, really bad for spinner
this.input.width( this.inner.width() );
if (this.options.editor in $.ui.editor.editors) {
this.inputWrapper = $.ui.editor.editors[ this.options.editor ]( this.input, this.options.editorOptions );
}
this.inputWrapper.hide().appendTo( this.element );
this._on( this.inputWrapper, {
focusin: function() {
clearTimeout( this.timer );
},
focusout: function( event ) {
var that = this;
this.timer = setTimeout( function() {
if ( !that.input.is(":visible") ) {
return;
}
that.submit( event );
}, 100 );
},
keydown: function( event ) {
event.stopPropagation();
},
keyup: function( event ) {
event.stopPropagation();
if ( event.keyCode === $.ui.keyCode.ENTER || event.keyCode === $.ui.keyCode.NUMPAD_ENTER ) {
this.submit( event );
} else if ( event.keyCode === $.ui.keyCode.ESCAPE ) {
this.cancel( event );
}
}
});
},
start: function( event ) {
this.inner.hide();
this.inputWrapper.show();
this.input.val( this.inner.text() ).focus();
this._trigger("start", event );
},
_hide: function( event ) {
this.input.blur();
this.inputWrapper.hide();
this.inner.show();
},
submit: function( event ) {
var newValue = this.input.val(),
ui = {
value: newValue
};
if ( this._trigger( "submit", event, ui ) !== false ) {
this.inner.text( newValue );
}
this._hide();
},
cancel: function( event ) {
this._hide();
this._trigger( "cancel", event );
}
});
$.ui.editor.editors = {
spinner: function( input, options ) {
return input.spinner( options ).spinner("widget");
}
};
})( jQuery );