jquery: focus jumps before event runs -
the focus moves next input field before event fired. can me find bug, or figure out how find myself?
the goal catch keyup event, verify tab or shift+tab, , tab though tabbing through table. when focus gets last input visible, 3 rows (see fiddle visual) should move reveal hidden inputs. once end of inputs in row, 3 rows slide down beginning again, kind of carriage return on typewriter, or tabbing different row in table.
right now, tab event moving row holds focus, , moving before script starts run. need know why happening can research how resolve it.
any can offer appreciated. please let me know if need more information.
p.s. using jquery 1.9.1
jquery(document).ready(function ($) { // bind listeners time input fields //$('.timeblock').blur(validatehrs); $('.timeblock').keyup(function () { var caller = $(this); var obj = new layoutobj(caller); if (event.keycode === 9) { if (event.shiftkey) { obj.dir = 'prev'; } obj.navdates(); } }); // bind listeners prev/next buttons $('.previous, .next').on('click', function () { var str = $(this).attr('class'); var caller = $(this); var obj = new layoutobj(caller); obj.src = 'pg'; if (str === 'previous') { obj.dir = 'prev'; } obj.navdates(); }); }); function layoutobj(input) { var today = new date(); var thismonth = today.getmonth(); var thisdate = today.getdate(); var datestr = ''; var fulldates = $('.datenum'); var splitdates = new array(); this.currindex = 0; //currindex defaults 0 this.todayindex; fulldates.each(function (index) { splitdates[index] = $(this).text().split('/'); }); //traverse list of dates in pay period, compare values , stop when/if find today (var = 0; < splitdates.length; i++) { if (thismonth === (parseint(splitdates[i][0], 10) - 1) && thisdate === parseint(splitdates[i][1], 10)) { thismonth += 1; thismonth += ''; thisdate += ''; if (thismonth.length < 2) { datestr = "0" + thismonth + "/"; } else { datestr = thismonth + "/"; } if (thisdate.length < 2) { datestr += "0" + thisdate; } else { datestr += thisdate; } fulldates[i].parentnode.setattribute('class', 'date today'); this.todayindex = i; break; } } //grab of lists & inputs this.window = $('div.timeviewlist'); this.alllists = $('.timeviewlist ul'); this.inputs = $('.timeblock'); //if input`isn't null, set currindex match index of caller if (input !== null) { this.currindex = this.inputs.index(input); } //else if today in pay period, set currindex todayindex else if (this.todayindex !== undefined) { this.currindex = this.todayindex; } //(else default = 0) //grab offsets cell, parent, , lists. this.winoffset = this.window.offset().left; this.celloffset = this.inputs.eq(this.currindex).offset().left; this.listoffset = this.inputs.offset().left; //grab width of cell, parent, , lists this.cellwidth = this.inputs.outerwidth(); this.listwidth = this.inputs.last().offset().left + this.cellwidth - this.inputs.eq(0).offset().left; this.winwidth = this.window.outerwidth(); //calculate maximum (left) offset between lists , parents this.offsetmax = (this.listwidth - this.winwidth); //set default scroll direction fwd, , default nav tab this.dir = 'next'; this.src = 'tab'; //grab offsets cell, parent, , lists. this.celloffset = this.inputs.eq(this.currindex).offset().left; this.listoffset = this.inputs.eq(0).offset().left; this.winoffset = this.alllists.parent().offset().left; //calculate maximum (left) offset between lists , parents this.offsetmax = (this.listwidth - this.winwidth); } layoutobj.prototype.focusdate = function () { this.inputs.eq(this.currindex).focus(); }; layoutobj.prototype.slidelists = function (num) { this.listoffset += num; this.alllists.offset({ left: this.listoffset }); }; layoutobj.prototype.navdates = function () { if (!this.inwindow()) { var slide = 0; switch (this.src) { case 'pg': slide = this.winwidth - this.cellwidth; break; case 'tab': slide = this.cellwidth + 1; break; default: break; } if (this.dir === 'next') { slide = -slide; } this.slidelists(slide); } this.focusdate(); }; layoutobj.prototype.inwindow = function () { //detects if cell intended focus visible in parent div if ((this.celloffset > this.winoffset) && ((this.celloffset + this.cellwidth) < (this.winoffset + this.winwidth))) { return true; } else { return false; } }
all needed 'keydown()' instead of 'keyup().'
Comments
Post a Comment