142
St
startsInvasion / files
startsInvasion / libs / node_modules / bean / support / syn / key.js
21.9 KB
1(function(){ 2var h = Syn.helpers, 3 S = Syn, 4 5// gets the selection of an input or textarea 6getSelection = function(el){ 7 // use selectionStart if we can 8 if (el.selectionStart !== undefined) { 9 // this is for opera, so we don't have to focus to type how we think we would 10 if(document.activeElement 11 && document.activeElement != el 12 && el.selectionStart == el.selectionEnd 13 && el.selectionStart == 0){ 14 return {start: el.value.length, end: el.value.length}; 15 } 16 return {start: el.selectionStart, end: el.selectionEnd} 17 }else{ 18 //check if we aren't focused 19 //if(document.activeElement && document.activeElement != el){ 20 21 22 //} 23 try { 24 //try 2 different methods that work differently (IE breaks depending on type) 25 if (el.nodeName.toLowerCase() == 'input') { 26 var real = h.getWindow(el).document.selection.createRange(), r = el.createTextRange(); 27 r.setEndPoint("EndToStart", real); 28 29 var start = r.text.length 30 return { 31 start: start, 32 end: start + real.text.length 33 } 34 } 35 else { 36 var real = h.getWindow(el).document.selection.createRange(), r = real.duplicate(), r2 = real.duplicate(), r3 = real.duplicate(); 37 r2.collapse(); 38 r3.collapse(false); 39 r2.moveStart('character', -1) 40 r3.moveStart('character', -1) 41 //select all of our element 42 r.moveToElementText(el) 43 //now move our endpoint to the end of our real range 44 r.setEndPoint('EndToEnd', real); 45 var start = r.text.length - real.text.length, end = r.text.length; 46 if (start != 0 && r2.text == "") { 47 start += 2; 48 } 49 if (end != 0 && r3.text == "") { 50 end += 2; 51 } 52 //if we aren't at the start, but previous is empty, we are at start of newline 53 return { 54 start: start, 55 end: end 56 } 57 } 58 }catch(e){ 59 return {start: el.value.length, end: el.value.length}; 60 } 61 } 62}, 63// gets all focusable elements 64getFocusable = function(el){ 65 var document = h.getWindow(el).document, 66 res = []; 67 68 var els = document.getElementsByTagName('*'), 69 len = els.length; 70 71 for(var i=0; i< len; i++){ 72 Syn.isFocusable(els[i]) && els[i] != document.documentElement && res.push(els[i]) 73 } 74 return res; 75 76 77}; 78 79/** 80 * @add Syn static 81 */ 82h.extend(Syn,{ 83 /** 84 * @attribute 85 * A list of the keys and their keycodes codes you can type. 86 * You can add type keys with 87 * @codestart 88 * Syn('key','delete','title'); 89 * 90 * //or 91 * 92 * Syn('type','One Two Three[left][left][delete]','title') 93 * @codeend 94 * 95 * The following are a list of keys you can type: 96 * @codestart text 97 * \b - backspace 98 * \t - tab 99 * \r - enter 100 * ' ' - space 101 * a-Z 0-9 - normal characters 102 * /!@#$*,.? - All other typeable characters 103 * page-up - scrolls up 104 * page-down - scrolls down 105 * end - scrolls to bottom 106 * home - scrolls to top 107 * insert - changes how keys are entered 108 * delete - deletes the next character 109 * left - moves cursor left 110 * right - moves cursor right 111 * up - moves the cursor up 112 * down - moves the cursor down 113 * f1-12 - function buttons 114 * shift, ctrl, alt - special keys 115 * pause-break - the pause button 116 * scroll-lock - locks scrolling 117 * caps - makes caps 118 * escape - escape button 119 * num-lock - allows numbers on keypad 120 * print - screen capture 121 * @codeend 122 */ 123 keycodes: { 124 //backspace 125 '\b':'8', 126 127 //tab 128 '\t':'9', 129 130 //enter 131 '\r':'13', 132 133 //special 134 'shift':'16','ctrl':'17','alt':'18', 135 136 //weird 137 'pause-break':'19', 138 'caps':'20', 139 'escape':'27', 140 'num-lock':'144', 141 'scroll-lock':'145', 142 'print' : '44', 143 144 //navigation 145 'page-up':'33','page-down':'34','end':'35','home':'36', 146 'left':'37','up':'38','right':'39','down':'40','insert':'45','delete':'46', 147 148 //normal characters 149 ' ':'32', 150 '0':'48','1':'49','2':'50','3':'51','4':'52','5':'53','6':'54','7':'55','8':'56','9':'57', 151 'a':'65','b':'66','c':'67','d':'68','e':'69','f':'70','g':'71','h':'72','i':'73','j':'74','k':'75','l':'76','m':'77', 152 'n':'78','o':'79','p':'80','q':'81','r':'82','s':'83','t':'84','u':'85','v':'86','w':'87','x':'88','y':'89','z':'90', 153 //normal-characters, numpad 154 'num0':'96','num1':'97','num2':'98','num3':'99','num4':'100','num5':'101','num6':'102','num7':'103','num8':'104','num9':'105', 155 '*':'106','+':'107','-':'109','.':'110', 156 //normal-characters, others 157 '/':'111', 158 ';':'186', 159 '=':'187', 160 ',':'188', 161 '-':'189', 162 '.':'190', 163 '/':'191', 164 '`':'192', 165 '[':'219', 166 '\\':'220', 167 ']':'221', 168 "'":'222', 169 170 //ignore these, you shouldn't use them 171 'left window key':'91','right window key':'92','select key':'93', 172 173 174 'f1':'112','f2':'113','f3':'114','f4':'115','f5':'116','f6':'117', 175 'f7':'118','f8':'119','f9':'120','f10':'121','f11':'122','f12':'123' 176 }, 177 178 // what we can type in 179 typeable : /input|textarea/i, 180 181 // selects text on an element 182 selectText: function( el, start, end ) { 183 if(el.setSelectionRange){ 184 if(!end){ 185 el.focus(); 186 el.setSelectionRange(start, start); 187 } else { 188 el.selectionStart = start; 189 el.selectionEnd = end; 190 } 191 }else if (el.createTextRange) { 192 //el.focus(); 193 var r = el.createTextRange(); 194 r.moveStart('character', start); 195 end = end || start; 196 r.moveEnd('character', end - el.value.length); 197 198 r.select(); 199 } 200 }, 201 getText: function( el ) { 202 //first check if the el has anything selected .. 203 if(Syn.typeable.test(el.nodeName)){ 204 var sel = getSelection(el); 205 return el.value.substring(sel.start, sel.end) 206 } 207 //otherwise get from page 208 var win = Syn.helpers.getWindow(el); 209 if (win.getSelection) { 210 return win.getSelection().toString(); 211 } 212 else if (win.document.getSelection) { 213 return win.document.getSelection().toString() 214 } 215 else { 216 return win.document.selection.createRange().text; 217 } 218 }, 219 getSelection : getSelection 220}); 221 222h.extend(Syn.key,{ 223 // retrieves a description of what events for this character should look like 224 data: function( key ) { 225 //check if it is described directly 226 if(S.key.browser[key]){ 227 return S.key.browser[key]; 228 } 229 for(var kind in S.key.kinds){ 230 if(h.inArray(key, S.key.kinds[kind] ) > -1){ 231 return S.key.browser[kind] 232 } 233 } 234 return S.key.browser.character 235 }, 236 237 //returns the special key if special 238 isSpecial: function( keyCode ) { 239 var specials = S.key.kinds.special; 240 for(var i=0; i < specials.length; i++){ 241 if(Syn.keycodes[ specials[i] ] == keyCode){ 242 return specials[i]; 243 } 244 } 245 }, 246 /** 247 * @hide 248 * gets the options for a key and event type ... 249 * @param {Object} key 250 * @param {Object} event 251 */ 252 options: function( key, event ) { 253 var keyData = Syn.key.data(key); 254 255 if(!keyData[event]){ 256 //we shouldn't be creating this event 257 return null; 258 } 259 260 var charCode = keyData[event][0], 261 keyCode = keyData[event][1], 262 result = {}; 263 264 if(keyCode == 'key'){ 265 result.keyCode = Syn.keycodes[key] 266 } else if (keyCode == 'char'){ 267 result.keyCode = key.charCodeAt(0) 268 }else{ 269 result.keyCode = keyCode; 270 } 271 272 if(charCode == 'char'){ 273 result.charCode = key.charCodeAt(0) 274 }else if(charCode !== null){ 275 result.charCode = charCode; 276 } 277 278 279 return result 280 }, 281 //types of event keys 282 kinds : { 283 special : ["shift",'ctrl','alt','caps'], 284 specialChars : ["\b"], 285 navigation: ["page-up",'page-down','end','home','left','up','right','down','insert','delete'], 286 'function' : ['f1','f2','f3','f4','f5','f6','f7','f8','f9','f10','f11','f12'] 287 }, 288 //returns the default function 289 getDefault: function( key ) { 290 //check if it is described directly 291 if(Syn.key.defaults[key]){ 292 return Syn.key.defaults[key]; 293 } 294 for(var kind in Syn.key.kinds){ 295 if(h.inArray(key, Syn.key.kinds[kind])> -1 && Syn.key.defaults[kind] ){ 296 return Syn.key.defaults[kind]; 297 } 298 } 299 return Syn.key.defaults.character 300 }, 301 // default behavior when typing 302 defaults : { 303 'character' : function( options, scope, key, force, sel ) { 304 if(/num\d+/.test(key)){ 305 key = key.match(/\d+/)[0] 306 } 307 308 if(force || (!S.support.keyCharacters && Syn.typeable.test(this.nodeName))){ 309 var current = this.value, 310 before = current.substr(0,sel.start), 311 after = current.substr(sel.end), 312 character = key; 313 314 console.log("setting",this.value,before, character, after) 315 this.value = before+character+after; 316 //handle IE inserting \r\n 317 var charLength = character == "\n" && S.support.textareaCarriage ? 2 : character.length; 318 Syn.selectText(this, before.length + charLength) 319 } 320 }, 321 'c' : function( options, scope, key, force, sel ) { 322 if(Syn.key.ctrlKey){ 323 Syn.key.clipboard = Syn.getText(this) 324 }else{ 325 Syn.key.defaults.character.apply(this, arguments); 326 } 327 }, 328 'v' : function( options, scope, key, force, sel ) { 329 if(Syn.key.ctrlKey){ 330 Syn.key.defaults.character.call(this, options,scope, Syn.key.clipboard, true,sel); 331 }else{ 332 Syn.key.defaults.character.apply(this, arguments); 333 } 334 }, 335 'a' : function( options, scope, key, force, sel ) { 336 if(Syn.key.ctrlKey){ 337 Syn.selectText(this, 0, this.value.length) 338 }else{ 339 Syn.key.defaults.character.apply(this, arguments); 340 } 341 }, 342 'home' : function() { 343 Syn.onParents(this, function(el){ 344 if(el.scrollHeight != el.clientHeight){ 345 el.scrollTop = 0; 346 return false; 347 } 348 }) 349 }, 350 'end' : function() { 351 Syn.onParents(this, function(el){ 352 if(el.scrollHeight != el.clientHeight){ 353 el.scrollTop = el.scrollHeight; 354 return false; 355 } 356 }) 357 }, 358 'page-down' : function() { 359 //find the first parent we can scroll 360 Syn.onParents(this, function(el){ 361 if(el.scrollHeight != el.clientHeight){ 362 var ch = el.clientHeight 363 el.scrollTop += ch; 364 return false; 365 } 366 }) 367 }, 368 'page-up' : function() { 369 Syn.onParents(this, function(el){ 370 if(el.scrollHeight != el.clientHeight){ 371 var ch = el.clientHeight 372 el.scrollTop -= ch; 373 return false; 374 } 375 }) 376 }, 377 '\b' : function( options, scope, key, force, sel ) { 378 //this assumes we are deleting from the end 379 if(!S.support.backspaceWorks && Syn.typeable.test(this.nodeName)){ 380 var current = this.value, 381 before = current.substr(0,sel.start), 382 after = current.substr(sel.end); 383 384 if(sel.start == sel.end && sel.start > 0){ 385 //remove a character 386 this.value = before.substring(0, before.length - 1)+after 387 Syn.selectText(this, sel.start-1) 388 }else{ 389 this.value = before+after; 390 Syn.selectText(this, sel.start) 391 } 392 393 //set back the selection 394 } 395 }, 396 'delete' : function( options, scope, key, force, sel ) { 397 if(!S.support.backspaceWorks && Syn.typeable.test(this.nodeName)){ 398 var current = this.value, 399 before = current.substr(0,sel.start), 400 after = current.substr(sel.end); 401 if(sel.start == sel.end && sel.start <= this.value.length - 1){ 402 this.value = before+after.substring(1) 403 }else{ 404 this.value = before+after; 405 406 } 407 Syn.selectText(this, sel.start) 408 } 409 }, 410 '\r' : function( options, scope, key, force, sel ) { 411 412 var nodeName = this.nodeName.toLowerCase() 413 // submit a form 414 if(!S.support.keypressSubmits && nodeName == 'input'){ 415 var form = Syn.closest(this, "form"); 416 if(form){ 417 Syn.trigger("submit", {}, form); 418 } 419 420 } 421 //newline in textarea 422 if(!S.support.keyCharacters && nodeName == 'textarea'){ 423 Syn.key.defaults.character.call(this, options, scope, "\n", undefined, sel) 424 } 425 // 'click' hyperlinks 426 if(!S.support.keypressOnAnchorClicks && nodeName == 'a'){ 427 Syn.trigger("click", {}, this); 428 } 429 }, 430 // 431 // Gets all focusable elements. If the element (this) 432 // doesn't have a tabindex, finds the next element after. 433 // If the element (this) has a tabindex finds the element 434 // with the next higher tabindex OR the element with the same 435 // tabindex after it in the document. 436 // @return the next element 437 // 438 '\t' : function( options, scope ) { 439 // focusable elements 440 var focusEls = getFocusable(this), 441 // the current element's tabindex 442 tabIndex = Syn.tabIndex(this), 443 // will be set to our guess for the next element 444 current = null, 445 // the next index we care about 446 currentIndex = 1000000000, 447 // set to true once we found 'this' element 448 found = false, 449 i = 0, 450 el, 451 //the tabindex of the tabable element we are looking at 452 elIndex, 453 firstNotIndexed, 454 prev; 455 orders = []; 456 for(; i< focusEls.length; i++){ 457 orders.push([focusEls[i], i]); 458 } 459 var sort = function(order1, order2){ 460 var el1 = order1[0], 461 el2 = order2[0], 462 tab1 = Syn.tabIndex(el1) || 0, 463 tab2 = Syn.tabIndex(el2) || 0; 464 if(tab1 == tab2){ 465 return order1[1] - order2[1] 466 }else{ 467 if(tab1 == 0){ 468 return 1; 469 }else if(tab2 == 0){ 470 return -1; 471 }else{ 472 return tab1-tab2; 473 } 474 } 475 } 476 orders.sort(sort); 477 //now find current 478 for(i=0; i< orders.length; i++){ 479 el = orders[i][0]; 480 if(this== el ){ 481 if(!Syn.key.shiftKey){ 482 current = orders[i+1][0]; 483 if(!current){ 484 current = orders[0][0] 485 } 486 }else{ 487 current = orders[i-1][0]; 488 if(!current){ 489 current = orders[focusEls.length-1][0] 490 } 491 } 492 493 } 494 } 495 496 //restart if we didn't find anything 497 if(!current){ 498 current = firstNotIndexed; 499 } 500 current && current.focus(); 501 return current; 502 }, 503 'left' : function( options, scope, key, force, sel ) { 504 if( Syn.typeable.test(this.nodeName) ){ 505 if(Syn.key.shiftKey){ 506 Syn.selectText(this, sel.start == 0 ? 0 : sel.start - 1, sel.end) 507 }else{ 508 Syn.selectText(this, sel.start == 0 ? 0 : sel.start - 1) 509 } 510 } 511 }, 512 'right' : function( options, scope, key, force, sel ) { 513 if( Syn.typeable.test(this.nodeName) ){ 514 if(Syn.key.shiftKey){ 515 Syn.selectText(this, sel.start, sel.end+1 > this.value.length ? this.value.length : sel.end+1) 516 }else{ 517 Syn.selectText(this, sel.end+1 > this.value.length ? this.value.length : sel.end+1) 518 } 519 } 520 }, 521 'up' : function() { 522 if(/select/i.test(this.nodeName)){ 523 524 this.selectedIndex = this.selectedIndex ? this.selectedIndex-1 : 0; 525 //set this to change on blur? 526 } 527 }, 528 'down' : function() { 529 if(/select/i.test(this.nodeName)){ 530 Syn.changeOnBlur(this, "selectedIndex", this.selectedIndex) 531 this.selectedIndex = this.selectedIndex+1; 532 //set this to change on blur? 533 } 534 }, 535 'shift' : function() { 536 return null; 537 } 538 } 539}); 540 541 542h.extend(Syn.create,{ 543 keydown : { 544 setup: function( type, options, element ) { 545 if(h.inArray(options,Syn.key.kinds.special ) != -1){ 546 Syn.key[options+"Key"] = element; 547 } 548 } 549 }, 550 keypress : { 551 setup : function(type, options, element){ 552 // if this browsers supports writing keys on events 553 // but doesn't write them if the element isn't focused 554 // focus on the element (ignored if already focused) 555 if(S.support.keyCharacters && !S.support.keysOnNotFocused){ 556 element.focus() 557 } 558 } 559 }, 560 keyup : { 561 setup: function( type, options, element ) { 562 if(h.inArray(options,Syn.key.kinds.special )!= -1){ 563 Syn.key[options+"Key"] = null; 564 } 565 } 566 }, 567 key: { 568 // return the options for a key event 569 options: function(type, options, element){ 570 //check if options is character or has character 571 options = typeof options != "object" ? { 572 character: options 573 } : options; 574 575 //don't change the orignial 576 options = h.extend({}, options) 577 if (options.character) { 578 h.extend(options, S.key.options(options.character, type)); 579 delete options.character; 580 } 581 582 options = h.extend({ 583 ctrlKey: !!Syn.key.ctrlKey, 584 altKey: !!Syn.key.altKey, 585 shiftKey: !!Syn.key.shiftKey, 586 metaKey: !!Syn.key.metaKey 587 }, options) 588 589 return options; 590 }, 591 // creates a key event 592 event: function(type, options, element){ //Everyone Else 593 var doc = h.getWindow(element).document; 594 if (doc.createEvent) { 595 var event; 596 597 try { 598 599 event = element.ownerDocument.createEvent("KeyEvents"); 600 event.initKeyEvent(type, true, true, window, options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.keyCode, options.charCode); 601 } 602 catch (e) { 603 event = h.createBasicStandardEvent(type, options, doc); 604 } 605 event.synthetic = true; 606 return event; 607 } 608 else { 609 var event = h.createEventObject.apply(this, arguments); 610 h.extend(event, options) 611 612 return event; 613 } 614 } 615 } 616}); 617 618var convert = { 619 "enter" : "\r", 620 "backspace" : "\b", 621 "tab" : "\t", 622 "space" : " " 623 } 624 625/** 626 * @add Syn prototype 627 */ 628h.extend(Syn.init.prototype, 629{ 630 /** 631 * @function key 632 * Types a single key. The key should be 633 * a string that matches a 634 * [Syn.static.keycodes]. 635 * 636 * The following sends a carridge return 637 * to the 'name' element. 638 * @codestart 639 * Syn.key('\r','name') 640 * @codeend 641 * For each character, a keydown, keypress, and keyup is triggered if 642 * appropriate. 643 * @param {String} options 644 * @param {HTMLElement} [element] 645 * @param {Function} [callback] 646 * @return {HTMLElement} the element currently focused. 647 */ 648 _key: function( options, element, callback ) { 649 //first check if it is a special up 650 if(/-up$/.test(options) 651 && h.inArray(options.replace("-up",""),Syn.key.kinds.special )!= -1){ 652 Syn.trigger('keyup',options.replace("-up",""), element ) 653 callback(true, element); 654 return; 655 } 656 657 658 var caret = Syn.typeable.test(element.nodeName) && getSelection(element), 659 key = convert[options] || options, 660 // should we run default events 661 runDefaults = Syn.trigger('keydown',key, element ), 662 663 // a function that gets the default behavior for a key 664 getDefault = Syn.key.getDefault, 665 666 // how this browser handles preventing default events 667 prevent = Syn.key.browser.prevent, 668 669 // the result of the default event 670 defaultResult, 671 672 // options for keypress 673 keypressOptions = Syn.key.options(key, 'keypress') 674 675 676 if(runDefaults){ 677 //if the browser doesn't create keypresses for this key, run default 678 if(!keypressOptions){ 679 defaultResult = getDefault(key).call(element, keypressOptions, h.getWindow(element), key, undefined, caret) 680 }else{ 681 //do keypress 682 runDefaults = Syn.trigger('keypress',keypressOptions, element ) 683 if(runDefaults){ 684 defaultResult = getDefault(key).call(element, keypressOptions, h.getWindow(element), key, undefined, caret) 685 } 686 } 687 }else{ 688 //canceled ... possibly don't run keypress 689 if(keypressOptions && h.inArray('keypress',prevent.keydown) == -1 ){ 690 Syn.trigger('keypress',keypressOptions, element ) 691 } 692 } 693 if(defaultResult && defaultResult.nodeName){ 694 element = defaultResult 695 } 696 697 if(defaultResult !== null){ 698 setTimeout(function(){ 699 Syn.trigger('keyup',Syn.key.options(key, 'keyup'), element ) 700 callback(runDefaults, element) 701 },1) 702 }else{ 703 callback(runDefaults, element) 704 } 705 706 707 //do mouseup 708 709 return element; 710 // is there a keypress? .. if not , run default 711 // yes -> did we prevent it?, if not run ... 712 713 }, 714 /** 715 * @function type 716 * Types sequence of [Syn.prototype.key key actions]. Each 717 * character is typed, one at a type. 718 * Multi-character keys like 'left' should be 719 * enclosed in square brackents. 720 * 721 * The following types 'JavaScript MVC' then deletes the space. 722 * @codestart 723 * Syn.type('JavaScript MVC[left][left][left]\b','name') 724 * @codeend 725 * 726 * Type is able to handle (and move with) tabs (\t). 727 * The following simulates tabing and entering values in a form and 728 * eventually submitting the form. 729 * @codestart 730 * Syn.type("Justin\tMeyer\t27\tjustinbmeyer@gmail.com\r") 731 * @codeend 732 * @param {String} options the text to type 733 * @param {HTMLElement} [element] an element or an id of an element 734 * @param {Function} [callback] a function to callback 735 */ 736 _type: function( options, element, callback ) { 737 //break it up into parts ... 738 //go through each type and run 739 var parts = options.match(/(\[[^\]]+\])|([^\[])/g), 740 self = this, 741 runNextPart = function(runDefaults, el){ 742 var part = parts.shift(); 743 if(!part){ 744 callback(runDefaults, el); 745 return; 746 } 747 el = el || element; 748 if(part.length > 1){ 749 part = part.substr(1,part.length - 2) 750 } 751 self._key(part, el, runNextPart) 752 } 753 754 runNextPart(); 755 756 } 757}); 758 759 760//do support code 761(function(){ 762 if(!document.body){ 763 setTimeout(arguments.callee,1) 764 return; 765 } 766 767 var div = document.createElement("div"), 768 checkbox, 769 submit, 770 form, 771 input, 772 submitted = false, 773 anchor, 774 textarea, 775 inputter; 776 777 div.innerHTML = "<form id='outer'>"+ 778 "<input name='checkbox' type='checkbox'/>"+ 779 "<input name='radio' type='radio' />"+ 780 "<input type='submit' name='submitter'/>"+ 781 "<input type='input' name='inputter'/>"+ 782 "<input name='one'>"+ 783 "<input name='two'/>"+ 784 "<a href='#abc'></a>"+ 785 "<textarea>1\n2</textarea>" 786 "</form>"; 787 788 document.documentElement.appendChild(div); 789 form = div.firstChild; 790 checkbox = form.childNodes[0]; 791 submit = form.childNodes[2]; 792 anchor = form.getElementsByTagName("a")[0]; 793 textarea = form.getElementsByTagName("textarea")[0]; 794 inputter = form.childNodes[3]; 795 796 form.onsubmit = function(ev){ 797 if (ev.preventDefault) 798 ev.preventDefault(); 799 S.support.keypressSubmits = true; 800 ev.returnValue = false; 801 return false; 802 }; 803 // Firefox 4 won't write key events if the element isn't focused 804 inputter.focus(); 805 Syn.trigger("keypress", "\r", inputter); 806 807 808 Syn.trigger("keypress", "a", inputter); 809 S.support.keyCharacters = inputter.value == "a"; 810 811 812 inputter.value = "a"; 813 Syn.trigger("keypress", "\b", inputter); 814 S.support.backspaceWorks = inputter.value == ""; 815 816 817 818 inputter.onchange = function(){ 819 S.support.focusChanges = true; 820 } 821 inputter.focus(); 822 Syn.trigger("keypress", "a", inputter); 823 form.childNodes[5].focus(); // this will throw a change event 824 825 Syn.trigger("keypress", "b", inputter); 826 S.support.keysOnNotFocused = inputter.value == "ab"; 827 828 //test keypress \r on anchor submits 829 S.bind(anchor,"click",function(ev){ 830 if (ev.preventDefault) 831 ev.preventDefault(); 832 S.support.keypressOnAnchorClicks = true; 833 ev.returnValue = false; 834 return false; 835 }) 836 Syn.trigger("keypress", "\r", anchor); 837 838 S.support.textareaCarriage = textarea.value.length == 4 839 document.documentElement.removeChild(div); 840 841 S.support.ready++; 842})(); 843}())