Skip to content

TagSpaces is an offline, open source, document manager with tagging support

Image sizes set on image load

Borislav Sapundzhievcab5c6014c2d
diff --git a/data/ext/perspectiveImageSwiper/extension.js b/data/ext/perspectiveImageSwiper/extension.js
index 3befd1d4a..a783f7ee6 100644
--- a/data/ext/perspectiveImageSwiper/extension.js
+++ b/data/ext/perspectiveImageSwiper/extension.js
@@ -47,6 +47,7 @@ define(function(require, exports, module) {
console.log("Loading perspective " + extensionID);
$viewContainer.children().remove();
UI.load($viewContainer, template, TSCORE.fileList);
+ TSCORE.hideLoadingAnimation();
};
var clearSelectedFiles = function() {
diff --git a/data/ext/perspectiveImageSwiper/galleryTMPL.html b/data/ext/perspectiveImageSwiper/galleryTMPL.html
index 8aae61ce9..afd30eeb8 100644
--- a/data/ext/perspectiveImageSwiper/galleryTMPL.html
+++ b/data/ext/perspectiveImageSwiper/galleryTMPL.html
@@ -6,8 +6,8 @@
{{#each data}}
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
- <a href={{path}} itemprop="contentUrl" >
- <img src={{thumbnail}} itemprop="thumbnail" alt={{name}} />
+ <a href={{path}} itemprop="contentUrl">
+ <img src={{thumbnail}} itemprop="thumbnail" alt={{name}}/>
</a>
<figcaption itemprop="caption description">{{name}}</figcaption>
</figure>
diff --git a/data/ext/perspectiveImageSwiper/perspectiveUI.js b/data/ext/perspectiveImageSwiper/perspectiveUI.js
index 8d3db55fd..07641c0b0 100644
--- a/data/ext/perspectiveImageSwiper/perspectiveUI.js
+++ b/data/ext/perspectiveImageSwiper/perspectiveUI.js
@@ -25,10 +25,11 @@ define(function(require, exports, module) {
thumbnail: defaultThumnailPath,
title: fileInfo[TSCORE.fileListTITLE]
}
+
data.push(doc);
}
});
-
+
var html = compiledTemplate({data: data});
container.append(html);
initPhotoSwipeFromDOM('.my-gallery');
@@ -61,12 +62,8 @@ define(function(require, exports, module) {
linkEl = figureEl.children[0]; // <a> element
- //size = linkEl.getAttribute('data-size').split('x');
+ size = [0,0]; //linkEl.getAttribute('data-size').split('x');
- var img = new Image();
- img.src = linkEl.getAttribute('href');
- size = [img.width, img.height];
-
// create slide object
item = {
src: linkEl.getAttribute('href'),
@@ -132,8 +129,6 @@ define(function(require, exports, module) {
nodeIndex++;
}
-
-
if(index >= 0) {
// open PhotoSwipe if valid index found
openPhotoSwipe( index, clickedGallery );
@@ -141,34 +136,6 @@ define(function(require, exports, module) {
return false;
};
- // parse picture index and gallery index from URL (#&pid=1&gid=2)
- var photoswipeParseHash = function() {
- var hash = window.location.hash.substring(1),
- params = {};
-
- if(hash.length < 5) {
- return params;
- }
-
- var vars = hash.split('&');
- for (var i = 0; i < vars.length; i++) {
- if(!vars[i]) {
- continue;
- }
- var pair = vars[i].split('=');
- if(pair.length < 2) {
- continue;
- }
- params[pair[0]] = pair[1];
- }
-
- if(params.gid) {
- params.gid = parseInt(params.gid, 10);
- }
-
- return params;
- };
-
var openPhotoSwipe = function(index, galleryElement, disableAnimation, fromURL) {
var pswpElement = document.querySelectorAll('.pswp')[0],
gallery,
@@ -177,9 +144,7 @@ define(function(require, exports, module) {
items = parseThumbnailElements(galleryElement);
- // define options (if needed)
options = {
-
// define gallery index (for URL)
galleryUID: galleryElement.getAttribute('data-pswp-uid'),
@@ -191,30 +156,13 @@ define(function(require, exports, module) {
return {x:rect.left, y:rect.top + pageYScroll, w:rect.width};
}
-
};
- // PhotoSwipe opened from URL
- if(fromURL) {
- if(options.galleryPIDs) {
- // parse real index when custom PIDs are used
- // http://photoswipe.com/documentation/faq.html#custom-pid-in-url
- for(var j = 0; j < items.length; j++) {
- if(items[j].pid == index) {
- options.index = j;
- break;
- }
- }
- } else {
- // in URL indexes start from 1
- options.index = parseInt(index, 10) - 1;
- }
- } else {
- options.index = parseInt(index, 10);
- }
+ options.index = parseInt(index, 10);
// exit if index not found
if( isNaN(options.index) ) {
+ console.log("PhotoSwipe error: index not found");
return;
}
@@ -229,6 +177,17 @@ define(function(require, exports, module) {
gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
gallery.init();
+
+ gallery.listen('imageLoadComplete', function(index, item) {
+
+ var img = new Image();
+ img.src = item.src;
+ item.w = img.width;
+ item.h = img.height;
+ gallery.updateSize(true);
+ img = undefined;
+ });
+
});
};
@@ -239,11 +198,5 @@ define(function(require, exports, module) {
galleryElements[i].setAttribute('data-pswp-uid', i+1);
galleryElements[i].onclick = onThumbnailsClick;
}
-
- // Parse URL and open gallery if it contains #&pid=3&gid=1
- var hashData = photoswipeParseHash();
- if(hashData.pid && hashData.gid) {
- openPhotoSwipe( hashData.pid , galleryElements[ hashData.gid - 1 ], true, true );
- }
};
});
\ No newline at end of file