Authored by gaoqiang xu

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

@@ -196,7 +196,8 @@ @@ -196,7 +196,8 @@
196 NSString *string = [NSString stringWithFormat:@"var imageElement = document.elementFromPoint(%f, %f);\ 196 NSString *string = [NSString stringWithFormat:@"var imageElement = document.elementFromPoint(%f, %f);\
197 var rect = imageElement.getBoundingClientRect();\ 197 var rect = imageElement.getBoundingClientRect();\
198 var frame = {x:rect.left, y:rect.top, width:rect.width, height:rect.height};\ 198 var frame = {x:rect.left, y:rect.top, width:rect.width, height:rect.height};\
199 - var dataSet = { url:imageElement.src, displayFrame:frame };\ 199 + var className = imageElement.className;\
  200 + var dataSet = { url:imageElement.src, displayFrame:frame, class:className, tagName:imageElement.tagName, id:imageElement.id };\
200 JSON.stringify(dataSet);", p.x, p.y]; 201 JSON.stringify(dataSet);", p.x, p.y];
201 return string; 202 return string;
202 } 203 }
@@ -225,11 +226,17 @@ @@ -225,11 +226,17 @@
225 NSDictionary *json = [NSJSONSerialization JSONObjectWithData:resultData 226 NSDictionary *json = [NSJSONSerialization JSONObjectWithData:resultData
226 options:0 227 options:0
227 error:nil]; 228 error:nil];
228 - if ([self.delegate respondsToSelector:@selector(explorer:didClickPicture:)]) { 229 +
  230 + if (json) {
  231 +
  232 + NSString *tagName = [json[@"tagName"] lowercaseString];
  233 +
  234 + if ([tagName isEqualToString:@"img"] && [self.delegate respondsToSelector:@selector(explorer:didClickPicture:)]) {
229 [self.delegate explorer:self.webViewController didClickPicture:json]; 235 [self.delegate explorer:self.webViewController didClickPicture:json];
230 } 236 }
231 } 237 }
232 } 238 }
  239 + }
233 } 240 }
234 241
235 #pragma mark - Method Forwarding 242 #pragma mark - Method Forwarding
@@ -160,12 +160,31 @@ @@ -160,12 +160,31 @@
160 - (void)explorer:(YHExplorerViewController *)explorer didClickPicture:(NSDictionary *)pictureInfo { 160 - (void)explorer:(YHExplorerViewController *)explorer didClickPicture:(NSDictionary *)pictureInfo {
161 NSLog(@"explorer didClickPicture: \n%@", pictureInfo); 161 NSLog(@"explorer didClickPicture: \n%@", pictureInfo);
162 162
  163 + // 获取点击的img的url
163 NSString *imageUrl = pictureInfo[@"url"]; 164 NSString *imageUrl = pictureInfo[@"url"];
164 - 165 + // 如果为空,那么不处理
165 if (imageUrl.length == 0) { 166 if (imageUrl.length == 0) {
166 return; 167 return;
167 } 168 }
168 169
  170 + // 如果要根据class里含有`product-picture`的来执行逻辑,参考如下代码:
  171 +#if 0
  172 + NSString *destClassName = @"product-picture";
  173 + BOOL matchClass = NO;
  174 + NSString *classString = pictureInfo[@"class"];
  175 + NSArray<NSString *> *classArray = [classString componentsSeparatedByString:@" "];
  176 + for (NSString *aClass in classArray) {
  177 + if ([aClass isEqualToString:destClassName]) {
  178 + matchClass = YES;
  179 + break;
  180 + }
  181 + }
  182 + if (!matchClass) {
  183 + return;
  184 + }
  185 +#endif
  186 + //
  187 +
169 CGFloat width = CGRectGetWidth(self.view.frame); 188 CGFloat width = CGRectGetWidth(self.view.frame);
170 CGFloat height = CGRectGetHeight(self.view.frame)-CGRectGetMaxY(self.navigationController.navigationBar.frame); 189 CGFloat height = CGRectGetHeight(self.view.frame)-CGRectGetMaxY(self.navigationController.navigationBar.frame);
171 190