Authored by gaoqiang xu

[feature] H5页面点击图片,增加class标记识别 reviewed by 戴强

... ... @@ -196,7 +196,8 @@
NSString *string = [NSString stringWithFormat:@"var imageElement = document.elementFromPoint(%f, %f);\
var rect = imageElement.getBoundingClientRect();\
var frame = {x:rect.left, y:rect.top, width:rect.width, height:rect.height};\
var dataSet = { url:imageElement.src, displayFrame:frame };\
var className = imageElement.className;\
var dataSet = { url:imageElement.src, displayFrame:frame, class:className, tagName:imageElement.tagName, id:imageElement.id };\
JSON.stringify(dataSet);", p.x, p.y];
return string;
}
... ... @@ -225,8 +226,14 @@
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:resultData
options:0
error:nil];
if ([self.delegate respondsToSelector:@selector(explorer:didClickPicture:)]) {
[self.delegate explorer:self.webViewController didClickPicture:json];
if (json) {
NSString *tagName = [json[@"tagName"] lowercaseString];
if ([tagName isEqualToString:@"img"] && [self.delegate respondsToSelector:@selector(explorer:didClickPicture:)]) {
[self.delegate explorer:self.webViewController didClickPicture:json];
}
}
}
}
... ...
... ... @@ -160,12 +160,31 @@
- (void)explorer:(YHExplorerViewController *)explorer didClickPicture:(NSDictionary *)pictureInfo {
NSLog(@"explorer didClickPicture: \n%@", pictureInfo);
// 获取点击的img的url
NSString *imageUrl = pictureInfo[@"url"];
// 如果为空,那么不处理
if (imageUrl.length == 0) {
return;
}
// 如果要根据class里含有`product-picture`的来执行逻辑,参考如下代码:
#if 0
NSString *destClassName = @"product-picture";
BOOL matchClass = NO;
NSString *classString = pictureInfo[@"class"];
NSArray<NSString *> *classArray = [classString componentsSeparatedByString:@" "];
for (NSString *aClass in classArray) {
if ([aClass isEqualToString:destClassName]) {
matchClass = YES;
break;
}
}
if (!matchClass) {
return;
}
#endif
//
CGFloat width = CGRectGetWidth(self.view.frame);
CGFloat height = CGRectGetHeight(self.view.frame)-CGRectGetMaxY(self.navigationController.navigationBar.frame);
... ...