Permalink
Browse files

updated link processor to support existing hash query

  • Loading branch information...
1 parent 9a0d99b commit eff2226307288954370998a6eabf16e859ef2c28 @CatChen CatChen committed Jun 9, 2012
View
2 Microdata/microdata-to-download-link-processor-demo.html
@@ -12,7 +12,7 @@
(<span itemprop="softwareVersion">1.3</span>)
</a>
<div itemprop="description">Cut the Rope, catch a star, and feed Om Nom candy in this award-winning game! The long-awaited hit game has finally arrived at Android!</div>
- <a itemprop="downloadUrl" href="">Download</a> (<span itemprop="fileSize">18,123,456</span>)
+ <a itemprop="downloadUrl" href="#content-length=18123456">Download</a> (<span itemprop="fileSize">18,123,456</span>)
</div>
</body>
</html>
View
30 Microdata/microdata-to-download-link-processor.js
@@ -22,22 +22,30 @@
var link = links[i];
link.setAttribute('rel', 'download');
+ var hash = {};
+ link.hash.replace(/[\#\&]([^=^&]*)=([^&]*)/g, function(whole, key, value) {
+ hash[key] = value;
+ return whole;
+ })
+
var scopeElement = getNearestScopeElement(link);
var itemProps = getItemProps(scopeElement);
-
- var hashSegments = [];
- if (itemProps.name) {
- hashSegments.push('name=' + encodeURIComponent(itemProps.name));
+ if (itemProps.name && !hash.name) {
+ hash.name = encodeURIComponent(itemProps.name);
}
- if (itemProps.image || itemProps.thumbnailUrl) {
- /* thumbnail/image is not supported until nested properties is supported */
- hashSegments.push('image=' + encodeURIComponent(itemProps.image || itemProps.thumbnailUrl));
+ if ((itemProps.image || itemProps.thumbnailUrl || itemProps.thumbnail.image) && !hash.image) {
+ hash.image = encodeURIComponent(itemProps.image || itemProps.thumbnailUrl || itemProps.thumbnail.image)
}
- if (itemProps.fileSize || itemProps.contentSize) {
- hashSegments.push('size=' + encodeURIComponent(itemProps.fileSize || itemProps.contentSize));
+ if ((itemProps.fileSize || itemProps.contentSize) && !hash['content-length']) {
+ hash['content-length'] = encodeURIComponent(itemProps.fileSize || itemProps.contentSize);
+ }
+
+ var hashArray = [];
+ for (var key in hash) {
+ hashArray.push(key + '=' +hash[key]);
}
- link.hash = hashSegments.join('&');
+ link.hash = '#' + hashArray.join('&');
}
};
@@ -72,7 +80,7 @@
if (propElement.hasAttribute('itemscope')) {
/* embedded struct */
- // TODO: extract embedded item scope
+ property.value = getItemProps(propElement);
} else {
switch (propElement.nodeName) {
case 'META':

0 comments on commit eff2226

Please sign in to comment.