PageRenderTime 25ms CodeModel.GetById 1ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 1ms

/Documentation/script/hs-enlargeimage.js

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