Guest User

Untitled

a guest
Feb 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. // Check if images load properly
  2. // returns false if image not loaded
  3. function imgOK(img) {
  4. if (!img.complete) {
  5. return false;
  6. }
  7. if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
  8. return false;
  9. }
  10. return true;
  11. }
  12.  
  13. // Note: using prototype js library for $, $$
  14. // Test if images load ok
  15. var tnLink = $$('.more-views a');
  16. // Hide links to more views when images do no load properly.
  17. if (tnLink.length>0) {
  18. document.observe("dom:loaded", function() {
  19. tnLink.each(function(s, index) {
  20. var tnImg = tnLink[index].firstDescendant();
  21. var obj = $(s).firstDescendant();
  22. console.log(tnImg.src + " > is ok : " + imgOK(obj));
  23. if ( imgOK(obj) == false) {
  24. console.log('bad image!');
  25. $(s).addClassName('no-display');
  26. }
  27. });
  28. });
  29. }
  30.  
  31. /*
  32. need to Define a CSS class to hide the link with a bad image :
  33.  
  34. .no-display {
  35. display: none;
  36. }
  37. */
Add Comment
Please, Sign In to add comment