-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathSystem.Web.UI.HtmlControls.TextBox.debug.js
More file actions
320 lines (310 loc) · 11.4 KB
/
System.Web.UI.HtmlControls.TextBox.debug.js
File metadata and controls
320 lines (310 loc) · 11.4 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
//=============================================================================
// Jocys.com JavaScript.NET Classes (In C# Object Oriented Style)
// Created by Evaldas Jocys <evaldas@jocys.com>
//=============================================================================
/// <reference path="System.debug.js" />
//=============================================================================
// Namespaces
//-----------------------------------------------------------------------------
// <PropertyGroup>
// <RootNamespace>System.Web.UI.HtmlControls.TextBox</RootNamespace>
// <PropertyGroup>
//-----------------------------------------------------------------------------
System.Type.RegisterNamespace("System.Web.UI.HtmlControls.TextBox");
//=============================================================================
//-------------------------------------------------------------------------
// Converted from:
// * Javascript Lib V1.2
// * CONTACT: jerry.wang@clochase.com
//-------------------------------------------------------------------------
System.Web.UI.HtmlControls.TextBox.GetCursorStartPos = function (obj) {
var nPosition = parseInt(obj.getAttribute("position"), 10);
if (nPosition >= 0) return nPosition;
// IE
if (document.selection) {
var cur = document.selection.createRange();
var pos = 0;
if (obj && cur) {
var tr = obj.createTextRange();
if (tr) {
while (cur.compareEndPoints("StartToStart", tr) > 0) {
tr.moveStart("character", 1);
pos++;
}
return pos;
}
}
return -1;
} else if (obj.selectionStart !== null) { // FF
return obj.selectionStart;
} else {
return -1;
}
};
//-----------------------------------------------------------------------------
System.Web.UI.HtmlControls.TextBox.GetCursorEndPos = function (obj) {
var nPosition = parseInt(obj.getAttribute("position"), 10);
if (nPosition >= 0) return nPosition;
// IE
if (document.selection) {
var cur = document.selection.createRange();
var pos = 0;
if (obj && cur) {
var tr = obj.createTextRange();
if (tr) {
while (cur.compareEndPoints("EndToStart", tr) > 0) {
tr.moveStart("character", 1);
pos++;
}
return pos;
}
}
return -1;
}
else if (obj.selectionStart !== null) { // FF
return obj.selectionEnd;
} else {
return -1;
}
};
//-------------------------------------------------------------------------
System.Web.UI.HtmlControls.TextBox.SetCursorPosition = function (obj, pos) {
if (obj.setSelectionRange) {
obj.focus();
obj.setSelectionRange(pos, pos);
} else if (obj.createTextRange) {
var range = obj.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
};
//-------------------------------------------------------------------------
System.Web.UI.HtmlControls.TextBox.ReplaceText = function (obj, strText, nStart, nEnd) {
// IE
if (document.all) {
var tr = obj.createTextRange();
tr.moveEnd("character", nEnd - obj.value.length);
tr.moveStart("character", nStart);
tr.text = strText;
tr.select();
} else {
// FF
var strBefore = obj.value.substr(0, nStart);
var strSelected = obj.value.substr(nStart, nEnd - nStart);
var strAfter = obj.value.substr(nEnd, obj.value.length - nEnd);
obj.value = strBefore + strText + strAfter;
}
};
// ===================================================================
// Original author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
// -------------------------------------------------------------------
// autoComplete (text_input, select_input, ["text"|"value"], [true|false])
// Use this function when you have a SELECT box of values and a text
// input box with a fill-in value. Often, onChange of the SELECT box
// will fill in the selected value into the text input (working like
// a Windows combo box). Using this function, typing into the text
// box will auto-select the best match in the SELECT box and do
// auto-complete in supported browsers.
// Arguments:
// field = text input field object
// select = select list object containing valid values
// property = either "text" or "value". This chooses which of the
// SELECT properties gets filled into the text box -
// the 'value' or 'text' of the selected option
// forcematch = true or false. Set to 'true' to not allow any text
// in the text box that does not match an option. Only
// supported in IE (possible future Netscape).
// -------------------------------------------------------------------
System.Web.UI.HtmlControls.TextBox.AutoComplete = function (field, select, property, forcematch) {
var found = false;
for (var i = 0; i < select.options.length; i++) {
if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) === 0) {
found = true; break;
}
}
if (found) { select.selectedIndex = i; }
else { select.selectedIndex = -1; }
if (field.createTextRange) {
if (forcematch && !found) {
field.value = field.value.substring(0, field.value.length - 1);
return;
}
var cursorKeys = "8;46;37;38;39;40;33;34;35;36;45;";
if (cursorKeys.indexOf(event.keyCode + ";") === -1) {
var r1 = field.createTextRange();
var oldValue = r1.text;
var newValue = found ? select.options[i][property] : oldValue;
if (newValue !== field.value) {
field.value = newValue;
var rNew = field.createTextRange();
rNew.moveStart('character', oldValue.length);
rNew.select();
}
}
}
};
//=============================================================================
// CLASS: System.Web.UI.HtmlControls.TextBox.CommandLine
//-----------------------------------------------------------------------------
System.Web.UI.HtmlControls.TextBox.CommandLine = function (input, context) {
/// <summary>
/// Convert TextBox to Comand Line.
/// </summary>
//---------------------------------------------------------
// Public properties.
this.Context;
this.LineNode;
this.MemoNode;
// Capture on Command event;
this.Command;
//---------------------------------------------------------
// Private properties.
//---------------------------------------------------------
function createInterface(input) {
// Set objects.
this.LineNode = input;
this.MemoNode = this.Context.getElementById(input.id + "Memo");
// If memo for TextBox does not exist, then...
if (this.MemoNode === null) {
// ...create one.
this.MemoNode = this.Context.createElement("select");
this.MemoNode.id = input.id + "Memo";
this.MemoNode.style.display = "none";
}
// Append <select></select> after TextBox.
input.parentNode.appendChild(this.MemoNode);
}
//---------------------------------------------------------
this.AddToHistory = function (commandText) {
/// <summary>
/// Add one command to history select box.
/// </summary>
var addCommand = true;
// Don't add command to History if it is empty.
if (commandText.replace(" ", "") === "") addCommand = false;
// Don't add command to History if it is same as previous.
var commandsCount = this.MemoNode.options.length;
if (commandsCount > 0) {
var previousCommand = this.MemoNode.item(commandsCount - 1).text;
if (previousCommand === commandText) addCommand = false;
}
// Add command.
if (addCommand) {
var item = this.Context.createElement("option");
this.MemoNode.options.add(item);
item.text = commandText;
item.selected = true;
}
};
//---------------------------------------------------------
function LineNode_KeyDown(sender, e) {
// Get code of pressssed key.
var keyCode = window.ActiveXObject ? e.keyCode : e.which;
//Trace.Write("keyCode: "+keyCode);
var commandHistory = "";
var keyIsArrow = false;
switch (keyCode) {
case 13: // [Enter]
this.AddToHistory(this.LineNode.value);
// Rise on command event.
var e1 = new System.EventArgs("Command");
e1["Command"] = this.LineNode.value;
this.LineNode.value = "";
this.RiseEvent(e1);
break;
case 38: // [KeyUp]
keyIsArrow = true;
break;
case 40: // [KeyDown]
keyIsArrow = true;
break;
case 27: // [Escape]
//alert("0");
this.LineNode.value = "";
//alert("1");
//Trace.Write("Clean Line");
//alert("1a");
break;
}
//alert("2");
if (keyIsArrow) {
var commandsCount = this.MemoNode.options.length;
// Get index of current selected command in history.
var memoSelectedIndex = this.MemoNode.selectedIndex;
//Trace.Write("memoSelectedIndex: "+memoSelectedIndex);
// If CommandHisory is Empty Then just exit this function.
if (commandsCount === 0) return;
if (commandsCount === 1) {
//Trace.Write("commandsCount == 1");
if (this.LineNode.value === "") {
this.LineNode.value = this.MemoNode.item(memoSelectedIndex).text;
} else {
this.LineNode.value = "";
}
}
if (commandsCount > 1) {
// If command line is empty Then just paste from CommandHitory.
if (this.LineNode.value === "") {
this.LineNode.value = this.MemoNode.value;
} else {
switch (keyCode) {
case 38: // [KeyUp]
// If it is not the top of CommandHistory then...
if (memoSelectedIndex > 0) {
// Select next command.
this.MemoNode.selectedIndex = memoSelectedIndex - 1;
this.LineNode.value = this.MemoNode.value;
} else {
this.LineNode.value = "";
}
break;
case 40: // [KeyDown]
// If it is not the bottom of CommandHistory then...
if (memoSelectedIndex < commandsCount - 1) {
// Select next command.
this.MemoNode.selectedIndex = memoSelectedIndex + 1;
this.LineNode.value = this.MemoNode.value;
} else {
this.LineNode.value = "";
}
break;
default:
break;
}
}
memoSelectedIndex = this.MemoNode.selectedIndex;
//Trace.Write("memoSelectedIndex2: "+memoSelectedIndex);
}
}
}
//---------------------------------------------------------
function MemoNode_Change(sender, e) {
// Get index of current selected command in history.
memoSelectedIndex = this.MemoNode.selectedIndex;
//objCommandLine.value = this.MemoNode.item(memoSelectedIndex).innerHtml;
}
//---------------------------------------------------------
function attachEvents() {
// Attach event to ChatCommand to capture key presses.
Events.Add(this.LineNode, "keyup", new System.EventHandler(this, LineNode_KeyDown), false);
//Events.Add(this.MemoNode, "change", new System.EventHandler(this, MemoNode_Change), true);
}
//---------------------------------------------------------
this.RiseEvent = function (e) { if (this[e.Name]) this[e.Name](this, e); };
//---------------------------------------------------------
function initialize(input, context) {
// Set submited values or default values.
this.Context = context ? context : document;
// Create Interface.
//this.CreateInterface();
createInterface.call(this, input);
attachEvents.call(this, input);
}
initialize.apply(this, arguments);
};
//==============================================================================
// END
//------------------------------------------------------------------------------