jQuery and/or markItUp! choking on CTRL key
I've inherited the company website and a hastily thrown together CMS along with it. Got my first bug today and I'm stumped.
The CMS uses markItUp!, which I'd never heard of before. The problem is this: whenever someone types the CTRL character into the affected textarea, jQuery throws a lovely Syntax error, unrecognized expression: [ctrl character]
exception.
I'm looking at the markItUp! keyPressed function and I don't see how it would ever work, under the circumstances. To use the shortcuts, you must preface them with CTRL, but keyPressed will always fire after you press CTRL, not find CTRL in the set, hence error in Sizzle.filter
.
Press CTRL with textarea in focus, then:
//jquery.markitup.js
function keyPressed(e) {
shiftKey = e.shiftKey;
altKey = e.altKey;
ctrlKey = (!(e.altKey && e.ctrlKey)) ? e.ctrlKey : false;
if (e.type === 'keydown') {
if (ctrlKey === true) {
//Line below attempts to find an anchor tag with accesskey CTRL character
li = $("a[accesskey="+String.fromCharCode(e.keyCode)+"]", header).parent('li');
//SNIP
}
}
}
//jquery-1.5.js
Sizzle.filter = function( expr, set, inplace, not ) {
var count = 0;
var match, anyFound,
old = expr,
result = [],
curLoop = set,
isXMLFilter = set && set[0] && Sizzle.isXML( set[0] );
//expr = the CTRL character, set = the markItUp! default set
while ( expr && set.length) {
for ( var type in Expr.filter ) {
if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {
//SNIP
}
}
// Improper expression
if ( expr === old ) {
if ( anyFound == null ) {
Sizzle.error( expr );
} else {
break;
}
}
old = expr;
}
return curLoop;
};
Sizzle.error = function( msg ) {
throw "Syntax error, unreco开发者_StackOverflow中文版gnized expression: " + msg;
};
What am I missing here?
For me it only happens with a new version of jQuery (1.7.1). If I use 1.4.2, it doesn't report any error. No matter which browser I use.
The problem has been fixed with the jquery 1.5 compatibility patch in this commit.
The relevant line in the patch was:
- li = $("a[accesskey="+String.fromCharCode(e.keyCode)+"]", header).parent('li');
+ li = $('a[accesskey="'+String.fromCharCode(e.keyCode)+'"]', header).parent('li');
精彩评论