3402 |
15 Jun 15 |
nicklas |
1 |
|
3402 |
15 Jun 15 |
nicklas |
var Thumbnail = function() |
3402 |
15 Jun 15 |
nicklas |
3 |
{ |
3402 |
15 Jun 15 |
nicklas |
var thumb = {}; |
3409 |
18 Jun 15 |
nicklas |
var HOME = null; |
3402 |
15 Jun 15 |
nicklas |
6 |
|
3409 |
18 Jun 15 |
nicklas |
// Add click handler to thumbnail images in the list page |
3409 |
18 Jun 15 |
nicklas |
thumb.initElements = function(element, autoInit) |
3403 |
16 Jun 15 |
nicklas |
9 |
{ |
3409 |
18 Jun 15 |
nicklas |
if (autoInit == 'thumbnail') |
3403 |
16 Jun 15 |
nicklas |
11 |
{ |
3409 |
18 Jun 15 |
nicklas |
Events.addEventHandler(element, 'click', thumb.showImage); |
3409 |
18 Jun 15 |
nicklas |
element.title = 'Click to show full image'; |
3421 |
24 Jun 15 |
nicklas |
if (element.complete) |
3421 |
24 Jun 15 |
nicklas |
15 |
{ |
3421 |
24 Jun 15 |
nicklas |
thumb.imageLoaded(element); |
3421 |
24 Jun 15 |
nicklas |
17 |
} |
3421 |
24 Jun 15 |
nicklas |
else |
3421 |
24 Jun 15 |
nicklas |
19 |
{ |
3421 |
24 Jun 15 |
nicklas |
Events.addEventHandler(element, 'load', thumb.onImageLoaded); |
3421 |
24 Jun 15 |
nicklas |
21 |
} |
3409 |
18 Jun 15 |
nicklas |
22 |
} |
3409 |
18 Jun 15 |
nicklas |
else if (autoInit == 'thumbnail-proxy') |
3409 |
18 Jun 15 |
nicklas |
24 |
{ |
3409 |
18 Jun 15 |
nicklas |
// The image file info is on the proxy element |
3409 |
18 Jun 15 |
nicklas |
// An <img> is created and inserted as a child to the 'target' element |
3409 |
18 Jun 15 |
nicklas |
var fileId = Data.int(element, 'file-id'); |
3409 |
18 Jun 15 |
nicklas |
var size = Data.get(element, 'size', 'XLARGE'); |
6047 |
12 Nov 20 |
nicklas |
var rotate = Data.get(element, 'rotate'); |
6047 |
12 Nov 20 |
nicklas |
var imageIndex = Data.int(element, 'image-index', -1); |
3409 |
18 Jun 15 |
nicklas |
var target = Data.get(element, 'target', 'main.properties.content'); |
3403 |
16 Jun 15 |
nicklas |
32 |
|
3403 |
16 Jun 15 |
nicklas |
var home = thumb.getHome(); |
3403 |
16 Jun 15 |
nicklas |
var url = home + 'Thumbnails.servlet?ID='+App.getSessionId(); |
3403 |
16 Jun 15 |
nicklas |
url += '&file='+fileId; |
3409 |
18 Jun 15 |
nicklas |
url += '&size='+size; |
6047 |
12 Nov 20 |
nicklas |
if (rotate) url += '&rotate='+rotate; |
6047 |
12 Nov 20 |
nicklas |
if (imageIndex >= 0) url += '&index='+imageIndex; |
3403 |
16 Jun 15 |
nicklas |
39 |
|
3403 |
16 Jun 15 |
nicklas |
var img = document.createElement('img'); |
3403 |
16 Jun 15 |
nicklas |
img.src = url; |
6048 |
12 Nov 20 |
nicklas |
img.className = 'thumbnail-img thumbnail-view '+size.toLowerCase()+' loading'; |
3403 |
16 Jun 15 |
nicklas |
Data.set(img, 'file-id', fileId); |
3403 |
16 Jun 15 |
nicklas |
Events.addEventHandler(img, 'click', thumb.showImage); |
3421 |
24 Jun 15 |
nicklas |
Events.addEventHandler(img, 'load', thumb.onImageLoaded); |
3403 |
16 Jun 15 |
nicklas |
46 |
|
3409 |
18 Jun 15 |
nicklas |
Doc.element(target).appendChild(img); |
3409 |
18 Jun 15 |
nicklas |
Doc.hide(element.parentNode); |
3403 |
16 Jun 15 |
nicklas |
49 |
} |
3403 |
16 Jun 15 |
nicklas |
50 |
} |
3403 |
16 Jun 15 |
nicklas |
51 |
|
3403 |
16 Jun 15 |
nicklas |
// Find the <script> tag for 'thumbnail.js' and extract the path to it |
3403 |
16 Jun 15 |
nicklas |
thumb.getHome = function() |
3403 |
16 Jun 15 |
nicklas |
54 |
{ |
3409 |
18 Jun 15 |
nicklas |
if (HOME != null) return HOME; |
3409 |
18 Jun 15 |
nicklas |
56 |
|
3403 |
16 Jun 15 |
nicklas |
var scripts = document.getElementsByTagName('script'); |
3403 |
16 Jun 15 |
nicklas |
for (var i = scripts.length - 1; i >= 0; i--) |
3403 |
16 Jun 15 |
nicklas |
59 |
{ |
3403 |
16 Jun 15 |
nicklas |
var src = scripts[i].src; |
3403 |
16 Jun 15 |
nicklas |
var end = src.indexOf('thumbnails.js'); |
3403 |
16 Jun 15 |
nicklas |
if (end > 0) |
3403 |
16 Jun 15 |
nicklas |
63 |
{ |
3403 |
16 Jun 15 |
nicklas |
var start = src.indexOf(App.getRoot()); |
3409 |
18 Jun 15 |
nicklas |
HOME = src.substring(start, end); |
3403 |
16 Jun 15 |
nicklas |
66 |
} |
3403 |
16 Jun 15 |
nicklas |
67 |
} |
3403 |
16 Jun 15 |
nicklas |
// Fallback that should never happen! |
3409 |
18 Jun 15 |
nicklas |
if (HOME == null) HOME = App.getRoot() + 'extensions/thumbnails.jar/'; |
3409 |
18 Jun 15 |
nicklas |
return HOME; |
3403 |
16 Jun 15 |
nicklas |
71 |
} |
3403 |
16 Jun 15 |
nicklas |
72 |
|
3403 |
16 Jun 15 |
nicklas |
// Show the full image when a thumbnail is clicked |
3402 |
15 Jun 15 |
nicklas |
thumb.showImage = function(event) |
3402 |
15 Jun 15 |
nicklas |
75 |
{ |
3402 |
15 Jun 15 |
nicklas |
var fileId = Data.int(event.currentTarget, 'file-id'); |
3402 |
15 Jun 15 |
nicklas |
77 |
|
3402 |
15 Jun 15 |
nicklas |
var controller = Items.getController('FILE'); |
3402 |
15 Jun 15 |
nicklas |
var url = App.getRoot() + controller.url; |
3402 |
15 Jun 15 |
nicklas |
url += '?ID='+App.getSessionId(); |
3402 |
15 Jun 15 |
nicklas |
url += '&cmd=ViewFile&item_id='+fileId; |
3402 |
15 Jun 15 |
nicklas |
82 |
|
3402 |
15 Jun 15 |
nicklas |
var options = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes'; |
3402 |
15 Jun 15 |
nicklas |
window.open(url, 'FullImage'+fileId, options); |
3402 |
15 Jun 15 |
nicklas |
85 |
} |
3402 |
15 Jun 15 |
nicklas |
86 |
|
3421 |
24 Jun 15 |
nicklas |
thumb.onImageLoaded = function(event) |
3421 |
24 Jun 15 |
nicklas |
88 |
{ |
3421 |
24 Jun 15 |
nicklas |
thumb.imageLoaded(event.currentTarget); |
3421 |
24 Jun 15 |
nicklas |
90 |
} |
3421 |
24 Jun 15 |
nicklas |
91 |
|
3421 |
24 Jun 15 |
nicklas |
thumb.imageLoaded = function(element) |
3421 |
24 Jun 15 |
nicklas |
93 |
{ |
3421 |
24 Jun 15 |
nicklas |
Doc.removeClass(element, 'loading'); |
3421 |
24 Jun 15 |
nicklas |
95 |
} |
3421 |
24 Jun 15 |
nicklas |
96 |
|
3402 |
15 Jun 15 |
nicklas |
return thumb; |
3402 |
15 Jun 15 |
nicklas |
98 |
}(); |
3402 |
15 Jun 15 |
nicklas |
99 |
|
3402 |
15 Jun 15 |
nicklas |
Doc.addElementInitializer(Thumbnail.initElements); |