1// Name: FilteredTextBox.FilteredTextBoxBehavior.debug.js 2// Assembly: AjaxControlToolkit 3// Version: 4.1.7.1213 4// FileVersion: 4.1.7.1213 5// (c) 2010 CodePlex Foundation 6 7 8 9/// <reference name="MicrosoftAjax.debug.js" /> 10/// <reference path="../ExtenderBase/BaseScripts.js" /> 11/// <reference path="../Common/Common.js" /> 12 13(function() { 14var scriptName = "ExtendedFilteredTextBox"; 15 16function execute() { 17 18Type.registerNamespace('Sys.Extended.UI'); 19 20Sys.Extended.UI.FilteredTextBoxBehavior = function(element) { 21 /// <summary> 22 /// The FilteredTextBoxBehavior is used to prevent invalid characters from being entered into a textbox 23 /// </summary> 24 /// <param name="element" type="Sys.UI.DomElement"> 25 /// The textbox element this behavior is associated with 26 /// </param> 27 Sys.Extended.UI.FilteredTextBoxBehavior.initializeBase(this, [element]); 28 29 this._keypressHandler = null; 30 this._changeHandler = null; 31 32 this._intervalID = null; 33 34 this._filterType = Sys.Extended.UI.FilterTypes.Custom; 35 this._filterMode = Sys.Extended.UI.FilterModes.ValidChars; 36 this._validChars = null; 37 this._invalidChars = null; 38 this._filterInterval = 250; 39 40 this.charTypes = { }; 41 this.charTypes.LowercaseLetters = "abcdefghijklmnopqrstuvwxyz"; 42 this.charTypes.UppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 43 this.charTypes.Numbers = "0123456789"; 44} 45Sys.Extended.UI.FilteredTextBoxBehavior.prototype = { 46 initialize : function() { 47 /// <summary> 48 /// Initialize the behavior 49 /// </summary> 50 Sys.Extended.UI.FilteredTextBoxBehavior.callBaseMethod(this, 'initialize'); 51 52 var element = this.get_element(); 53 54 this._keypressHandler = Function.createDelegate(this, this._onkeypress); 55 $addHandler(element, 'keypress', this._keypressHandler); 56 57 this._changeHandler = Function.createDelegate(this, this._onchange); 58 $addHandler(element, 'change', this._changeHandler); 59 60 var callback = Function.createDelegate(this, this._intervalCallback); 61 this._intervalID = window.setInterval(callback, this._filterInterval); 62 }, 63 64 dispose : function() { 65 /// <summary> 66 /// Dispose the behavior 67 /// </summary> 68 var element = this.get_element(); 69 70 $removeHandler(element, 'keypress', this._keypressHandler); 71 this._keypressHandler = null; 72 73 $removeHandler(element, 'change', this._changeHandler); 74 this._changeHandler = null; 75 76 window.clearInterval(this._intervalID); 77 78 Sys.Extended.UI.FilteredTextBoxBehavior.callBaseMethod(this, 'dispose'); 79 }, 80 81 _getValidChars : function() { 82 /// <summary> 83 /// Get all the valid characters 84 /// </summary> 85 /// <returns type="String"> 86 /// All valid characters 87 /// </returns> 88 89 if (this._validChars) return this._validChars; 90 this._validChars = ""; 91 92 for (type in this.charTypes) { 93 var filterType = Sys.Extended.UI.FilterTypes.toString(this._filterType); 94 if (filterType.indexOf(type) != -1) { 95 this._validChars += this.charTypes[type]; 96 } 97 } 98 99 return this._validChars; 100 }, 101 102 _getInvalidChars : function() { 103 /// <summary> 104 /// Get all the invalid characters (in case of custom filtering and InvalidChars mode) 105 /// </summary> 106 /// <returns type="String"> 107 /// All invalid characters 108 /// </returns> 109 110 if (!this._invalidChars) { 111 this._invalidChars = this.charTypes.Custom; 112 } 113 return this._invalidChars; 114 }, 115 116 _onkeypress : function(evt) { 117 /// <summary> 118 /// Handler for the target textbox's key press event 119 /// </summary> 120 /// <param name="evt" type="Sys.UI.DomEvent"> 121 /// Event info 122 /// </param> 123 124 125 var scanCode; 126 127 if ( (((/* ff */ evt.rawEvent.charCode == 0) || 128 (/* opera */ evt.rawEvent.keyCode == evt.rawEvent.which && evt.rawEvent.charCode == undefined)) && 129 ((evt.rawEvent.keyCode == Sys.UI.Key.pageUp) || 130 (evt.rawEvent.keyCode == Sys.UI.Key.pageDown) || 131 (evt.rawEvent.keyCode == Sys.UI.Key.up) || 132 (evt.rawEvent.keyCode == Sys.UI.Key.down) || 133 (evt.rawEvent.keyCode == Sys.UI.Key.left) || 134 (evt.rawEvent.keyCode == Sys.UI.Key.right) || 135 (evt.rawEvent.keyCode == Sys.UI.Key.home) || 136 (evt.rawEvent.keyCode == Sys.UI.Key.end) || 137 (evt.rawEvent.keyCode == 46 /* Delete */))) || 138 (evt.ctrlKey /* Control keys */)) { 139 return; 140 } 141 142 if (evt.rawEvent.keyIdentifier) { 143 if (evt.rawEvent.ctrlKey || evt.rawEvent.altKey || evt.rawEvent.metaKey) { 144 return; 145 } 146 147 if (evt.rawEvent.keyIdentifier.substring(0,2) != "U+") { 148 return; 149 } 150 151 scanCode = evt.rawEvent.charCode; 152 if (scanCode == 63272 /* Delete */) { 153 return; 154 } 155 } else { 156 scanCode = evt.charCode; 157 } 158 159 if (scanCode && scanCode >= 0x20 /* space */) { 160 var c = String.fromCharCode(scanCode); 161 if(!this._processKey(c)) { 162 evt.preventDefault(); 163 } 164 } 165 }, 166 167 _processKey : function(key) { 168 /// <summary> 169 /// Determine whether the key is valid or whether it should be filtered out 170 /// </summary> 171 /// <param name="key" type="String"> 172 /// Character to be validated 173 /// </param> 174 /// <returns type="Boolean"> 175 /// True if the character should be accepted, false if it should be filtered 176 /// </returns> 177 178 179 var filter = ""; 180 var shouldFilter = false; 181 182 if (this._filterMode == Sys.Extended.UI.FilterModes.ValidChars) { 183 filter = this._getValidChars();
184 185 shouldFilter = filter && (filter.length > 0) && (filter.indexOf(key) == -1); 186 } else { 187 filter = this._getInvalidChars(); 188 189 shouldFilter = filter && (filter.length > 0) && (filter.indexOf(key) > -1); 190 } 191 192 var eventArgs = new Sys.Extended.UI.FilteredTextBoxProcessKeyEventArgs(key, Sys.Extended.UI.TextBoxWrapper.get_Wrapper(this.get_element()).get_Value(), shouldFilter); 193 this.raiseProcessKey(eventArgs); 194 195 if (eventArgs.get_allowKey()) { 196 return true; 197 } 198 199 this.raiseFiltered(new Sys.Extended.UI.FilteredTextBoxEventArgs(key)); 200 return false; 201 }, 202 203 _onchange : function() { 204 /// <summary> 205 /// Handler for the target textbox's key change event which will filter 206 /// the text again (to make sure no text was inserted without keypresses, etc.) 207 /// </summary> 208 209 var wrapper = Sys.Extended.UI.TextBoxWrapper.get_Wrapper(this.get_element()); 210 var text = wrapper.get_Value() || ''; 211 var result = new Sys.StringBuilder(); 212 for (var i = 0; i < text.length; i++) { 213 var ch = text.substring(i, i+1); 214 if (this._processKey(ch)) { 215 result.append(ch); 216 } 217 } 218 if (wrapper.get_Value() != result.toString()) { 219 wrapper.set_Value(result.toString()); 220 } 221 }, 222 223 _intervalCallback : function() { 224 /// <summary> 225 /// Method that is repeatedly called to purge invalid characters from the textbox 226 /// </summary> 227 228 this._changeHandler(); 229 }, 230 231 get_ValidChars : function() { 232 /// <value type="String"> 233 /// A string consisting of all characters considered valid for the textbox, if 234 /// "Custom" is specified as the field type. Otherwise this parameter is ignored. 235 /// </value> 236 return this.charTypes.Custom; 237 }, 238 set_ValidChars : function(value) { 239 if (this._validChars != null || this.charTypes.Custom != value) { 240 this.charTypes.Custom = value; 241 this._validChars = null; 242 this.raisePropertyChanged('ValidChars'); 243 } 244 }, 245 246 get_InvalidChars : function() { 247 /// <value type="String"> 248 /// A string consisting of all characters considered invali
248d for the textbox, if "Custom" is specified as the field type. Otherwise this parameter is ignored. 249 /// </value> 250 return this.charTypes.Custom; 251 }, 252 set_InvalidChars : function(value) { 253 if (this._invalidChars != null || this.charTypes.Custom != value) { 254 this.charTypes.Custom = value; 255 this._invalidChars = null; 256 this.raisePropertyChanged('InvalidChars'); 257 } 258 }, 259 260 get_FilterType : function() { 261 /// <value type="Sys.Extended.UI.FilterTypes"> 262 /// FilterType - A the type of filter to apply, as a comma-separated combination of 263 /// Numbers, LowercaseLetters, UppercaseLetters, and Custom. If Custom is specified, 264 /// the ValidChars field will be used in addition to other settings such as Numbers. 265 /// </value> 266 return this._filterType; 267 }, 268 set_FilterType : function(value) { 269 if (this._validChars != null || this._filterType != value) { 270 this._filterType = value; 271 this._validChars = null; 272 this.raisePropertyChanged('FilterType'); 273 } 274 }, 275 276 get_FilterMode : function() { 277 /// <value type="Sys.Extended.UI.FilterModes"> 278 /// FilterMode - The filter mode to apply when custom filtering is activated; supported values are ValidChars and InvalidChars. 279 /// </value> 280 return this._filterMode; 281 }, 282 set_FilterMode : function(value) { 283 if (this._validChars != null || this._invalidChars != null || this._filterMode != value) { 284 this._filterMode = value; 285 this._validChars = null; 286 this._invalidChars = null; 287 this.raisePropertyChanged('FilterMode'); 288 } 289 }, 290 291 get_FilterInterval : function() { 292 /// <value type="int"> 293 /// An integer containing the interval (in milliseconds) in which 294 /// the field's contents are filtered 295 /// </value> 296 return this._filterInterval; 297 }, 298 set_FilterInterval : function(value) { 299 if (this._filterInterval != value) { 300 this._filterInterval = value; 301 this.raisePropertyChanged('FilterInterval'); 302 } 303 }, 304 305 add_processKey : function(handler) { 306 /// <summary> 307 /// Add an event handler for the processKey event 308 /// </summary> 309 /// <param name="handler" type="Function" mayBeNull="false"> 310 /// Event handler 311 /// </param> 312 /// <returns /> 313 this.get_events().addHandler('processKey', handler); 314 }, 315 remove_processKey : function(handler) { 316 /// <summary> 317 /// Remove an event handler from the processKey event 318 /// </summary> 319 /// <param name="handler" type="Function" mayBeNull="false"> 320 /// Event handler 321 /// </param> 322 /// <returns /> 323 this.get_events().removeHandler('processKey', handler); 324 }, 325 raiseProcessKey : function(eventArgs) { 326 /// <summary> 327 /// Raise the processKey event 328 /// </summary> 329 /// <param name="eventArgs" type="Sys.Extended.UI.FilteredTextBoxProcessKeyEventArgs" mayBeNull="false"> 330 /// Event arguments for the processKey event 331 /// </param> 332 /// <returns /> 333 334 var handler = this.get_events().getHandler('processKey'); 335 if (handler) { 336 handler(this, eventArgs); 337 } 338 }, 339 340 add_filtered : function(handler) { 341 /// <summary> 342 /// Add an event handler for the filtered event 343 /// </summary> 344 /// <param name="handler" type="Function" mayBeNull="false"> 345 /// Event handler 346 /// </param> 347 /// <returns /> 348 this.get_events().addHandler('filtered', handler); 349 }, 350 remove_filtered : function(handler) { 351 /// <summary> 352 /// Remove an event handler from the filtered event 353 /// </summary> 354 /// <param name="handler" type="Function" mayBeNull="false"> 355 /// Event handler 356 /// </param> 357 /// <returns /> 358 this.get_events().removeHandler('filtered', handler); 359 }, 360 raiseFiltered : function(eventArgs) { 361 /// <summary> 362 /// Raise the filtered event 363 /// </summary> 364 /// <param name="eventArgs" type="Sys.Extended.UI.FilteredTextBoxEventArgs" mayBeNull="false"> 365 /// Event arguments for the filtered event 366 /// </param> 367 /// <returns /> 368 369 var handler = this.get_events().getHandler('filtered'); 370 if (handler) { 371 handler(this, eventArgs); 372 } 373 } 374} 375Sys.Extended.UI.FilteredTextBoxBehavior.registerClass('Sys.Extended.UI.FilteredTextBoxBehavior', Sys.Extended.UI.BehaviorBase); 376Sys.registerComponent(Sys.Extended.UI.FilteredTextBoxBehavior, { name: "filteredTextBox" }); 377 378Sys.Extended.UI.FilterTypes = function() { 379 /// <summary> 380 /// Character filter to be applied to a textbox 381 /// </summary> 382 /// <field name="Custom" type="Number" integer="true"> 383 /// Custom Characters 384 /// </field> 385 /// <field name="Numbers" type="Number" integer="true"> 386 /// Numbers (0123456789) 387 /// </field> 388 /// <field name="UppercaseLetters" type="Number" integer="true"> 389 /// Uppercase Letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ) 390 /// </field> 391 /// <field name="LowercaseLetters" type="Number" integer="true"> 392 /// Lowercase Letters (abcdefghijklmnopqrstuvwxyz) 393 /// </field>
394 throw Error.invalidOperation(); 395} 396Sys.Extended.UI.FilterTypes.prototype = { 397 Custom : 0x1, 398 Numbers : 0x2, 399 UppercaseLetters : 0x4, 400 LowercaseLetters : 0x8 401} 402Sys.Extended.UI.FilterTypes.registerEnum('Sys.Extended.UI.FilterTypes', true); 403 404Sys.Extended.UI.FilterModes = function() { 405 /// <summary> 406 /// Filter mode to be applied to a textbox 407 /// </summary> 408 /// <field name="ValidChars" type="Number" integer="true"> 409 /// Provide a list of valid characters 410 /// </field> 411 /// <field name="InvalidChars" type="Number" integer="true"> 412 /// Provide a list of invalid characters 413 /// </field> 414 throw Error.invalidOperation(); 415} 416Sys.Extended.UI.FilterModes.prototype = { 417 ValidChars : 0x1, 418 InvalidChars : 0x2 419} 420Sys.Extended.UI.FilterModes.registerEnum('Sys.Extended.UI.FilterModes', true); 421 422Sys.Extended.UI.FilteredTextBoxProcessKeyEventArgs = function(key, text, shouldFilter) { 423 /// <summary> 424 /// Event arguments used when the processKey event is raised 425 /// </summary> 426 /// <param name="key" type="String" mayBeNull="False"> 427 /// Key to be processed 428 /// </param> 429 /// <param name="text" type="String" mayBeNull="True"> 430 /// Current text in the textbox 431 /// </param> 432 /// <param name="shouldFilter" type="Boolean" mayBeNull="False"> 433 /// Whether the character should be filtered given the current 434 /// FilteredTextBox settings 435 /// </param> 436 Sys.Extended.UI.FilteredTextBoxProcessKeyEventArgs.initializeBase(this); 437 438 this._key = key; 439 this._text = text; 440 this._shouldFilter = shouldFilter; 441 this._allowKey = !shouldFilter; 442} 443Sys.Extended.UI.FilteredTextBoxProcessKeyEventArgs.prototype = { 444 get_key : function() { 445 /// <value type="String" mayBeNull="False"> 446 /// Key to be processed 447 /// </value> 448 return this._key; 449 }, 450 451 get_text : function() { 452 /// <value type="String" mayBeNull="True"> 453 /// Current text in the textbox 454 /// </value> 455 return this._text; 456 }, 457 458 get_shouldFilter : function() { 459 /// <value type="Boolean" mayBeNull="False"> 460 /// Whether the character should be filtered given the current 461 /// FilteredTextBox settings 462 /// </value> 463 return this._shouldFilter; 464 }, 465 466 get_allowKey : function() { 467 /// <value type="Boolean" mayBeNull="False"> 468 /// Whether or not the key will be filtered. It defaults to the opposite of 469 /// shouldFilter and should be set by handlers of the processKey event. 470 /// </value> 471 return this._allowKey; 472 }, 473 set_allowKey : function(value) { 474 this._allowKey = value; 475 } 476} 477Sys.Extended.UI.FilteredTextBoxProcessKeyEventArgs.registerClass('Sys.Extended.UI.FilteredTextBoxProcessKeyEventArgs', Sys.EventArgs); 478 479Sys.Extended.UI.FilteredTextBoxEventArgs = function(key) { 480 /// <summary> 481 /// Event arguments used when the filtered event is raised 482 /// </summary> 483 /// <param name="key" type="String" mayBeNull="False"> 484 /// Key that was filtered 485 /// </param> 486 Sys.Extended.UI.FilteredTextBoxEventArgs.initializeBase(this); 487 488 this._key = key; 489} 490Sys.Extended.UI.FilteredTextBoxEventArgs.prototype = { 491 get_key : function() { 492 /// <value type="String" mayBeNull="False"> 493 /// Key that was filtered 494 /// </value> 495 return this._key; 496 } 497} 498Sys.Extended.UI.FilteredTextBoxEventArgs.registerClass('Sys.Extended.UI.FilteredTextBoxEventArgs', Sys.EventArgs); 499 500} // execute 501 502if (window.Sys && Sys.loader) { 503 Sys.loader.registerScript(scriptName, ["ExtendedBase", "ExtendedCommon"], execute); 504} 505else { 506 execute(); 507} 508 509})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.