PageRenderTime 39ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/Documentation/script/hs-enlargeimage.js

#
JavaScript | 77 lines | 63 code | 6 blank | 8 comment | 16 complexity | bf3e220478ac4162bab01c420c15be4a MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. // This function retained for legacy and custom Dynamic Image Widgets - current standard Widget uses hsToggleImage below
  2. // for localization support
  3. function hsEnlargeImage(img, link, inplace) {
  4. var newsrc;
  5. var newlinktext;
  6. if (img) {
  7. if (!img.src)
  8. img = documentElement(img);
  9. if (img) {
  10. if (img.src.substring(img.src.length - 9, img.src.length - 4).toLowerCase() == 'thumb') {
  11. newsrc = img.src.substring(0, img.src.length - 10) + img.src.substring(img.src.length - 4);
  12. newlinktext = link.innerHTML.replace(/enlarge/gi, "shrink");
  13. }
  14. else {
  15. newsrc = img.src.substring(0, img.src.length - 4) + '_thumb' + img.src.substring(img.src.length - 4);
  16. newlinktext = link.innerHTML.replace(/shrink/gi, "enlarge");
  17. }
  18. if (!inplace) {
  19. var newimage = new Image();
  20. newimage.src = newsrc;
  21. hsOpenWindow(newimage.src, newimage.width + 20, newimage.height + 25);
  22. }
  23. else {
  24. img.src = newsrc;
  25. link.innerHTML = newlinktext;
  26. }
  27. }
  28. }
  29. }
  30. function hsToggleImage(img, link, inplace) {
  31. var newsrc;
  32. var newlinktext;
  33. var newlinkimgsrc;
  34. if (img) {
  35. if (!img.src)
  36. img = documentElement(img);
  37. if (img) {
  38. var imgId = img.id;
  39. var expandDiv = document.getElementById(imgId + "_expand");
  40. var shrinkDiv = document.getElementById(imgId + "_shrink");
  41. if (img.src.substring(img.src.length - 9, img.src.length - 4).toLowerCase() == 'thumb') {
  42. // Currently collapsed - expand
  43. expandDiv.style.display = "none";
  44. shrinkDiv.style.display = "block";
  45. // New img src
  46. newsrc = img.src.substring(0, img.src.length - 10) + img.src.substring(img.src.length - 4);
  47. }
  48. else {
  49. // Currently expanded - collapse
  50. expandDiv.style.display = "block";
  51. shrinkDiv.style.display = "none";
  52. // New img src
  53. newsrc = img.src.substring(0, img.src.length - 4) + '_thumb' + img.src.substring(img.src.length - 4);
  54. }
  55. // Update the img with the new src
  56. if (!inplace) {
  57. var newimage = new Image();
  58. newimage.src = newsrc;
  59. hsOpenWindow(newimage.src, newimage.width + 20, newimage.height + 25);
  60. }
  61. else {
  62. img.src = newsrc;
  63. }
  64. }
  65. }
  66. }
  67. function hsOpenWindow(strURL,strWidth,strHeight)
  68. {
  69. /* open a new browser window based on info passed to the function */
  70. window.open(strURL,"","Width=" + strWidth + ",Height=" + strHeight,0);
  71. }