Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] Allow long captions #1

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2c3e794
website: Fix inline style and indentation (mix of spaces and tabs).
PeterSweetAndSour Apr 7, 2020
fa8dc3f
Rename framework.createEl to framework.createElement for clarity
PeterSweetAndSour Apr 16, 2020
21ae260
Question about fake caption container
PeterSweetAndSour Apr 16, 2020
203a335
Rename function argument of a DOM node from 'captionEl' to 'captionEl…
PeterSweetAndSour Apr 16, 2020
c3e971e
Add some extra whitespace to separate functions.
PeterSweetAndSour Apr 16, 2020
af9e8d7
Rename options to make clear that these are booleans, not DOM elements.
PeterSweetAndSour Apr 16, 2020
e71b030
Capture the calculated size of the image and set an option for the ca…
PeterSweetAndSour Apr 16, 2020
e0aa68d
Move new option to the UI file.
PeterSweetAndSour Apr 16, 2020
14b3c72
Fix whitespace in photoswipe-ui-default.js. Add some explanatory comm…
PeterSweetAndSour Apr 21, 2020
bfb2560
First pass with something that works. Need to fix z-index on captionE…
PeterSweetAndSour Apr 23, 2020
140bdce
Add some lines to seperate functions
PeterSweetAndSour Apr 23, 2020
1d3b1c7
Rename button to be consistent pattern with others. Fix z-index issue…
PeterSweetAndSour Apr 23, 2020
940d898
Fix display/hiding of expand control when switching photos.
PeterSweetAndSour Apr 23, 2020
dfe1ec5
Set data attributes on .pswp__item to carry initial image height and …
PeterSweetAndSour Apr 24, 2020
dcf9926
Rename function to indicate that it is private.
PeterSweetAndSour Apr 25, 2020
38d5dfb
Save so far now that positioning is correct. Need to fix hiding and s…
PeterSweetAndSour Apr 29, 2020
398619a
Somewhat closer. Accounting for scale but only on first load. :-( Cap…
PeterSweetAndSour May 1, 2020
dcf57fd
Seems to work.
PeterSweetAndSour May 3, 2020
ef3c99d
Stop accidental scroll on close. Add a box at the end of the caption …
PeterSweetAndSour May 5, 2020
7048891
Various fixes
PeterSweetAndSour May 7, 2020
5da7317
Sorted out weirdness with tap behavior. Now preventing closing when t…
PeterSweetAndSour May 7, 2020
61e5806
Renaming option name and removing redundant code.
PeterSweetAndSour May 8, 2020
3fcd840
Drag up on collapsed caption will expand it.
PeterSweetAndSour May 8, 2020
44fabb2
Expand and collapse caption with just the mouse wheel. Had to overrid…
PeterSweetAndSour May 9, 2020
a69fb0b
Run setupDesktopZoom regardless. As noted in the comment, a timing is…
PeterSweetAndSour May 9, 2020
6a80c85
Swap out two lines of SVG for two dozen lines of CSS to make the expa…
PeterSweetAndSour May 9, 2020
e47f580
Back to SVG background images but now Base64 encoded and background s…
PeterSweetAndSour May 10, 2020
b3d4525
Reset default for allowLongCaptions to false.
PeterSweetAndSour May 9, 2020
e98d6c0
Ensure HTML exists for caption control and change title on button whe…
PeterSweetAndSour May 10, 2020
d6f50fe
Allow left/right buttons to show above expanded caption overlay when …
PeterSweetAndSour May 12, 2020
510d5ae
Now with keyboard control.
PeterSweetAndSour May 13, 2020
e945a8a
Moving the setting of tabindex and focus on the innerCaptionElement t…
PeterSweetAndSour May 13, 2020
a275376
Animate expansion and collapse of caption.
PeterSweetAndSour May 13, 2020
5b52d5d
Get around cross-site security issue by creating a new stylesheet rat…
PeterSweetAndSour May 13, 2020
d4e2d1d
A bit of rearrangement as I discovered that dragging to a new photo o…
PeterSweetAndSour May 14, 2020
c67b066
Increase the width of the caption if long captions are selected.
PeterSweetAndSour May 14, 2020
78c88f1
Added section for caption expand/collapse by vertical swipe/drag.
PeterSweetAndSour May 17, 2020
b02454a
Add "FYI" to console notices explaining that two options are overridd…
PeterSweetAndSour May 17, 2020
d40b745
Remove some console output
PeterSweetAndSour May 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/css/default-skin/default-skin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
width: 70px;
height: 100px;
position: absolute;
z-index: 3;
z-index: 1;
}

.pswp__button--arrow--left {
Expand Down Expand Up @@ -351,7 +351,7 @@ a.pswp__share--download {
max-width: 420px;
margin: 0 auto;
font-size: 13px;
padding: 20px 10px 10px 10px;
padding: 18px 10px 10px 10px;
line-height: 20px;
color: #FFF;
background-color: #000;
Expand All @@ -363,6 +363,10 @@ a.pswp__share--download {
color: #FFF;
}

p {
margin: 0 0 0 10px;
}

p:last-child::after {
display: inline-block;
height: 10px;
Expand All @@ -371,7 +375,6 @@ a.pswp__share--download {
margin-left: 6px;
margin-bottom: -1px;
content: ' ';

}
}

Expand Down
6 changes: 5 additions & 1 deletion src/js/desktop-zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ _registerModule('DesktopZoom', {

if (!_options.closeOnScroll || _numAnimations || _isDragging) {
var source = e.target || e.srcElement;
if(!source.classList.contains("pswp__caption__center")) {
if(source.classList.contains("pswp__caption__center")) {
if(source.class.contains("pswp__button--caption--ctrl--expand")) {
toggleCaption(source.parentNode);
}
} else {
e.preventDefault();
}
} else if(_transformKey && Math.abs(e.deltaY) > 2) {
Expand Down
23 changes: 22 additions & 1 deletion src/js/framework-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,25 @@ if(framework.features.oldIE) {
}
};

}
}

// Polyfill for closest() for IE11 from https://developer.mozilla.org/en-US/docs/Web/API/Element/closest.
// Not bothering with versions older than 11 and it is debatable whether we should worry even about 11 now.
if (!Element.prototype.matches) {
Element.prototype.matches = Element.prototype.msMatchesSelector ||
Element.prototype.webkitMatchesSelector;
}

if (!Element.prototype.closest) {
Element.prototype.closest = function(s) {
var el = this;

do {
if (Element.prototype.matches.call(el, s)) {
return el;
}
el = el.parentElement || el.parentNode;
} while (el !== null && el.nodeType === 1);
return null;
};
}
13 changes: 0 additions & 13 deletions src/js/items-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,25 +509,12 @@ _registerModule('Controller', {
if(!_initialContentSet && index === _currentItemIndex) {
_currZoomElementStyle = baseDiv.style;
_showOrHide(item, (img ||item.img) );

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L507 + 508 remove

// var cssTransform = baseDiv.style.transform; // e.g. "translate3d(65px, 87px, 0px) scale(0.875912)";
// if(/^translate.*scale.*$/.test(cssTransform)) {
// var translateY = cssTransform.replace(/^translate(3d)?\([0-9]*px, /, "").replace(/px.*$/, "");
// scale = cssTransform.replace(/^.*scale\(/, "").replace(/\)/, "");
// console.log("scale: " + scale + ", image height: " + imageSize.height);
// }
} else {
// console.log("Doing applyZoomPanToItem instead");
_applyZoomPanToItem(item);
}

holder.el.innerHTML = '';
holder.el.appendChild(baseDiv);

// holder.el.dataset.viewportHeight = _viewportSize.y;
// holder.el.dataset.gapTop = item.vGap.top;
// holder.el.dataset.imagePositionTop = item.initialPosition.y;
// holder.el.dataset.imageHeight = Math.round(imageSize.height * parseFloat(scale));
},

cleanSlide: function( item ) {
Expand Down
37 changes: 24 additions & 13 deletions src/js/ui/photoswipe-ui-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@
// Show the 'expand' control only if caption extends out of view. Reset height first.
innerCaptionElement.style.height = 'auto';
var captionCtrl = captionElement.querySelector(".pswp__button--caption--ctrl");
if(innerCaptionElement.clientHeight > layoutData.captionInitialHeight) {
if(innerCaptionElement.clientHeight - 10 > layoutData.captionInitialHeight) {
captionCtrl.classList.add("pswp__button--caption--ctrl--expand");
//captionCtrl.addEventListener("click", _toggleCaption);
}
else {
captionCtrl.classList.remove("pswp__button--caption--ctrl--expand");
Expand Down Expand Up @@ -124,7 +123,6 @@

indexIndicatorSep: ' / ',
fitControlsWidth: 1200

},
_blockControlsTap,
_blockControlsTapTimeout;
Expand Down Expand Up @@ -158,12 +156,10 @@

if(captionCtrl.classList.contains("pswp__button--caption--ctrl--expand")) { // Expand caption
if(captionElement.clientHeight < layoutData.captionMaxHeight) { // It fits in space below top bar
console.log("caption height: "+ captionElement.clientHeight + ", space available: " + layoutData.captionMaxHeight);
captionElement.style.top = (window.innerHeight - captionElement.clientHeight) + "px";
innerCaptionElement.style.height = 'auto';
}
else {
console.log("Caption won't fit. Gap at top: " + layoutData.gapTop);
captionElement.style.top = layoutData.gapTop + "px";
innerCaptionElement.style.height = layoutData.captionMaxHeight + "px";
innerCaptionElement.style.overflowY = "auto";
Expand Down Expand Up @@ -228,7 +224,7 @@
},

_fitControlsInViewport = function() {
return !pswp.likelyTouchDevice || _options.mouseUsed || screen.width > _options.fitControlsWidth;
return !pswp.likelyTouchDevice || _options.mouseUsed || screen.width > _options.fitControlsWidth || _options.verticalScrollForCaption;
},

_togglePswpClass = function(el, cName, add) {
Expand All @@ -254,7 +250,6 @@

_shareModalHidden = !_shareModalHidden;


if(!_shareModalHidden) {
_toggleShareModalClass();
setTimeout(function() {
Expand Down Expand Up @@ -479,6 +474,19 @@
}
},

_overrideOptionsIfVerticalScrollForCaptionsTrue = function() {
// Don't close gallery when tapping on caption
if(_options.verticalScrollForCaption) {
var index = _options.closeElClasses.indexOf('caption');
if (index > -1) {
_options.closeElClasses.splice(index, 1);
}
}

// Don't hide/show controls on tap
_options.tapToToggleControls = false;
},

_setupHidingControlsDuringGestures = function() {

// Hide controls on vertical drag
Expand Down Expand Up @@ -659,7 +667,7 @@
// create local link
_listen = pswp.listen;


_overrideOptionsIfVerticalScrollForCaptionsTrue();
_setupHidingControlsDuringGestures();

// update controls when slides change
Expand Down Expand Up @@ -852,8 +860,8 @@
}
} else {

// tap anywhere (except buttons) to toggle visibility of controls
if(_options.tapToToggleControls) {
// tap anywhere (except buttons and caption) to toggle visibility of controls
if(_options.tapToToggleControls && !target.classList.contains("pswp__caption__center")) {
if(_controlsVisible) {
ui.hideControls();
} else {
Expand All @@ -870,6 +878,7 @@

}
};

ui.onMouseOver = function(e) {
e = e || window.event;
var target = e.target || e.srcElement;
Expand Down Expand Up @@ -917,8 +926,6 @@
eventK: 'moz' + tF
};



} else if(dE.webkitRequestFullscreen) {
api = {
enterK: 'webkitRequestFullscreen',
Expand Down Expand Up @@ -948,13 +955,17 @@
return pswp.template[this.enterK]();
}
};

api.exit = function() {
_options.closeOnScroll = _initalCloseOnScrollValue;

return document[this.exitK]();

};
api.isFullscreen = function() { return document[this.elementK]; };

api.isFullscreen = function() {
return document[this.elementK];
};
}

return api;
Expand Down