Posted By

dne on 04/03/09


Tagged

javascript blog web Services blogger zanox contextual


Versions (?)

zanox Web Services - Contextual Product Search Widget for blogger.com


 / Published in: JavaScript
 

zanox Web Services - Contextual Product Search Widget for blogger.com

  1. <ul id="zxAdList"></ul>
  2.  
  3. <script type="text/javascript">
  4.  
  5. function addScript(url) {
  6. var script = document.createElement('script');
  7. script.src = url + '&t=' + new Date().getMinutes();
  8. script.type = 'text/javascript';
  9. document.getElementsByTagName('head')[0].appendChild(script);
  10. }
  11.  
  12. function productSearch(version, applicationid, adspace, region, programs, minPrice, maxPrice, category, page, items, q, callback) {
  13. var url = 'http://api.zanox.com/json';
  14. if (version) url+= '/' + version;
  15. url += '/products?applicationid=' + applicationid;
  16. if (adspace) url += '&adspace=' + adspace;
  17. if (region) url += '&region=' + region;
  18. if (programs) url += '&programs=' + programs;
  19. if (category) url += '&category=' + category;
  20. if (page) url += '&page=' + page;
  21. if (items) url += '&items=' + items;
  22. if (minPrice) url += '&minPrice=' + minPrice;
  23. if (maxPrice) url += '&maxPrice=' + maxPrice;
  24. if (callback) url += '&callback=' + callback;
  25. if (q) url += '&q=' + q;
  26. addScript(url);
  27. }
  28.  
  29.  
  30. function renderLinkListItem(content, link, itemContainer) {
  31. var li = document.createElement("li");
  32. li.innerHTML = '<a href="' + link + '">' + content + '</a>';
  33. itemContainer.appendChild(li);
  34. }
  35.  
  36.  
  37.  
  38.  
  39. function handler(data) {
  40. if (data.productsResult) {
  41. var productItems = data.productsResult.productItem;
  42. var zxAdList = document.getElementById('zxAdList'); //ID of a UL HTML element
  43.  
  44. for (var i = 0; i < productItems.length; i++) {
  45. var productItem = productItems[i];
  46. var link = '';
  47. if (productItem.url.adspace instanceof Array) {
  48. // select tracking link related to the first Adspace
  49. link = productItem.url.adspace[0].$;
  50. }
  51. else {
  52. link = productItem.url.adspace.$;
  53. }
  54. var content = productItem.name + ' bei ' + productItem.program.$ + ' für ' + productItem.price + ' ' + productItem.currency;
  55. renderLinkListItem(content, link, zxAdList);
  56. }
  57. }
  58.  
  59. }
  60.  
  61. var zx_query = document.getElementsByTagName('h3').item(0).getElementsByTagName('a').item(0).innerHTML;
  62.  
  63. //contextual product search parameters: version, applicationid, adspace, region, programs, minPrice, maxPrice, category, page, items, q, callback
  64.  
  65. productSearch(null, 'BE94C4947839E8AB4D67', null, 'de', '660', null, null, null, 0, 5, zx_query, 'handler');
  66.  
  67. </script>

Report this snippet  

You need to login to post a comment.