Skip to content
This repository has been archived by the owner on Oct 18, 2018. It is now read-only.

Commit

Permalink
Improved the way the context-menu keyword creation finds the form. An…
Browse files Browse the repository at this point in the history
… alert sheet is shown if the DOM traversal fails.
  • Loading branch information
Alexander Staubo committed Mar 15, 2009
1 parent c7f3a8a commit b1ab2b7
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions KeywurlPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,45 @@ - (void) createKeywordSearchFromForm: (id) sender {
NSString* documentUrl = (NSString*) [parameters objectAtIndex: 0];
DOMElement* inputElement = (DOMElement*) [parameters objectAtIndex: 1];
DOMElement* formElement = nil;
DOMNode* node = inputElement;
while (node) {
if ([node nodeType] == DOM_ELEMENT_NODE) {
DOMElement* element = (DOMElement*) node;
if ([[element tagName] isEqualToString: @"FORM"]) {
formElement = element;
break;
if ([inputElement respondsToSelector: @selector(form)]) {
formElement = [inputElement form];
}
if (!formElement) {
DOMNode* node = inputElement;
while (node) {
NSLog(@"looking at node: %@", node);
if ([node nodeType] == DOM_ELEMENT_NODE) {
DOMElement* element = (DOMElement*) node;
NSLog(@" element: %@", [element tagName]);
if ([[element tagName] isEqualToString: @"FORM"]) {
formElement = element;
break;
}
}
node = [node parentNode];
}
node = [node parentNode];
}
if (inputElement && formElement) {
KeywordSaveController* controller = [[KeywordSaveController alloc] initWithUrl: documentUrl
inputElement: inputElement
formElement: formElement];
} else {
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle: @"OK"];
[alert setMessageText: @"Could not create keyword"];
[alert setInformativeText: [NSString stringWithFormat:
@"The field you clicked on seem to be constructed in a way that Keywurl \
does not understand. \
\
For example, the field may be JavaScript/AJAX-based, or the HTML may be malformed. \
Keywurl can only deal with good old-fashioned HTML forms. \
\
Sorry."]];
[alert setAlertStyle: NSInformationalAlertStyle];
[alert beginSheetModalForWindow: [NSApp keyWindow]
modalDelegate: nil
didEndSelector: nil
contextInfo: nil];
}
}

Expand Down

0 comments on commit b1ab2b7

Please sign in to comment.