卡布奇诺:键盘事件在 reCAPTCHA 输入字段中被压缩
我正在将 reCAPTCHA 集成到我的卡布奇诺应用程序中,除了 reCAPTCHA 输入文本字段中的这个奇怪的输入功能之外,它一切正常:只有一些键似乎可以工作,“qwrszcv”和其他一些字母可以正常工作,但大多数其他键都可以正常工作不工作。
我借用了一些mapkit代码将reCAPTCHA脚本文件注入头部,然后将reCAPTCHA div注入到我制作的自定义CPView类中。
这是我的构造函数代码:
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
if (self != nil)
{
var DOMScriptElement = document.createElement("script");
DOMScriptElement.src = "http://www.google.com/recaptcha/api/js/recaptcha_ajax.js";
DOMScriptElement.type = "text/javascript";
document.getElementsByTagName("head")[0].appendChild(DOMScriptElement);
needsInitialization = YES;
console.log(self);
}
return self;
}
和我的初始化代码:
- (id)initializeRecaptcha
{
if (needsInitialization)
{
DOMRecaptchaElement = document.createElement("div");
DOMRecaptchaElement.id = "recaptcha_div_id";
var style = DOMRecaptchaElement.style,
bounds = [self bounds],
width = CGRectGetWidth(bounds),
height = CGRectGetHeight(bounds);
style.overflow = "hidden";
style.position = "absolute";
style.visibility = "visible";
style.zIndex = 0;
style.left = "0px";
style.top = "0px";
style.width = width + "px";
style.height = height + "px";
_DOMElement.appendChild(DOMRecaptchaElement);
window.Recaptcha.create("my-recaptcha-key",
"recaptcha_div_id",
{
theme: "clean",
callback: window.Recaptcha.focus_response_field
}
);
needsInitialization = NO;
}
else
{
window.Recaptcha.reload();
}
}
我认为它与 Cappuccino 传播事件的方式有关,但在我的一生中,我无法找到一种方法来让这个输入工作。
I'm integrating a reCAPTCHA into my Cappuccino app and I have it all working besides this odd input functionality in the reCAPTCHA input text field: Only some keys seem to work, "qwrszcv" and a few other letters work fine, but most other keys don't work.
I borrowed some of the mapkit code to inject the reCAPTCHA script file in the head, then I inject the reCAPTCHA div into a custom CPView class I made.
Here is my constructor code:
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
if (self != nil)
{
var DOMScriptElement = document.createElement("script");
DOMScriptElement.src = "http://www.google.com/recaptcha/api/js/recaptcha_ajax.js";
DOMScriptElement.type = "text/javascript";
document.getElementsByTagName("head")[0].appendChild(DOMScriptElement);
needsInitialization = YES;
console.log(self);
}
return self;
}
And my initialization code:
- (id)initializeRecaptcha
{
if (needsInitialization)
{
DOMRecaptchaElement = document.createElement("div");
DOMRecaptchaElement.id = "recaptcha_div_id";
var style = DOMRecaptchaElement.style,
bounds = [self bounds],
width = CGRectGetWidth(bounds),
height = CGRectGetHeight(bounds);
style.overflow = "hidden";
style.position = "absolute";
style.visibility = "visible";
style.zIndex = 0;
style.left = "0px";
style.top = "0px";
style.width = width + "px";
style.height = height + "px";
_DOMElement.appendChild(DOMRecaptchaElement);
window.Recaptcha.create("my-recaptcha-key",
"recaptcha_div_id",
{
theme: "clean",
callback: window.Recaptcha.focus_response_field
}
);
needsInitialization = NO;
}
else
{
window.Recaptcha.reload();
}
}
I figure it has something to do with the way Cappuccino propagated events, but for the life of me I can't figure out a way to get this input to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Cappuccino 在文档级别附加按键事件侦听器以处理键盘快捷键。我不确定为什么有些字符能够通过而其他字符却不能,但如果它以某种方式对应于潜在的卡布奇诺键盘快捷键,我不会感到惊讶。您可能需要检查
CPPlatformWindow+DOM.j
以获取更多详细信息。与此同时,解决实际问题的一个简单方法是将整个 recaptcha 小部件放入 iframe 中(您可以使用 CPWebView 或自己制作)。请记住,在 iframe 内部的事件处理程序中,您可能需要使用
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
手动泵入事件队列,以便在您对外部代码进行更改后重新显示 Cappuccino。运行循环。Cappuccino attaches key event listeners at the document level in order to handle keyboard shortcuts. I'm not sure why some characters are getting through and others are not, but I wouldn't be surprised if it somehow corresponded to potential Cappuccino keyboard shortcuts. You might want to check
CPPlatformWindow+DOM.j
for more details on this.In the meantime, an easy solution to your actual problem is to just drop the whole recaptcha widget into an iframe (you could use
CPWebView
or make your own). Just remember that in your event handlers inside of iframes you may have to pump the event queue manually with[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
to let Cappuccino redisplay after you made changes from code outside of the run loop.我找到了解决方法。我从 CPTextField 中的 keyDown 方法复制了代码,该方法将事件传播到浏览器窗口到保存验证码的自定义视图中的 keyDown 方法:
I found a fix. I copied code from the keyDown method in CPTextField that propagates the events to the browser window to the keyDown method in my custom view that holds the recaptcha: