mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:23:25 +08:00
Merge pull request #4831 from gdpelican/image-gallery
FEATURE: Use image gallery functionality in magnific
This commit is contained in:
commit
64787e7fa4
|
@ -2,47 +2,47 @@ import loadScript from 'discourse/lib/load-script';
|
|||
import { escapeExpression } from 'discourse/lib/utilities';
|
||||
|
||||
export default function($elem) {
|
||||
$("a.lightbox", $elem).each(function(i, e) {
|
||||
loadScript("/javascripts/jquery.magnific-popup-min.js").then(function() {
|
||||
const $e = $(e);
|
||||
// do not lightbox spoiled images
|
||||
if ($e.parents(".spoiler").length > 0 || $e.parents(".spoiled").length > 0) { return; }
|
||||
if (!$elem) { return; }
|
||||
loadScript("/javascripts/jquery.magnific-popup.min.js").then(function() {
|
||||
const spoilers = $elem.find('.spoiler a.lightbox, .spoiled a.lightbox');
|
||||
$elem.find('a.lightbox').not(spoilers).magnificPopup({
|
||||
type: "image",
|
||||
closeOnContentClick: false,
|
||||
removalDelay: 300,
|
||||
mainClass: "mfp-zoom-in",
|
||||
|
||||
$e.magnificPopup({
|
||||
type: "image",
|
||||
closeOnContentClick: false,
|
||||
removalDelay: 300,
|
||||
mainClass: "mfp-zoom-in",
|
||||
gallery: {
|
||||
enabled: true
|
||||
},
|
||||
|
||||
callbacks: {
|
||||
open() {
|
||||
const wrap = this.wrap,
|
||||
img = this.currItem.img,
|
||||
maxHeight = img.css("max-height");
|
||||
callbacks: {
|
||||
open() {
|
||||
const wrap = this.wrap,
|
||||
img = this.currItem.img,
|
||||
maxHeight = img.css("max-height");
|
||||
|
||||
wrap.on("click.pinhandler", "img", function() {
|
||||
wrap.toggleClass("mfp-force-scrollbars");
|
||||
img.css("max-height", wrap.hasClass("mfp-force-scrollbars") ? "none" : maxHeight);
|
||||
});
|
||||
},
|
||||
beforeClose() {
|
||||
this.wrap.off("click.pinhandler");
|
||||
this.wrap.removeClass("mfp-force-scrollbars");
|
||||
}
|
||||
wrap.on("click.pinhandler", "img", function() {
|
||||
wrap.toggleClass("mfp-force-scrollbars");
|
||||
img.css("max-height", wrap.hasClass("mfp-force-scrollbars") ? "none" : maxHeight);
|
||||
});
|
||||
},
|
||||
|
||||
image: {
|
||||
titleSrc(item) {
|
||||
const href = item.el.data("download-href") || item.src;
|
||||
let src = [escapeExpression(item.el.attr("title")), $("span.informations", item.el).text().replace('x', '×')];
|
||||
if (!Discourse.SiteSettings.prevent_anons_from_downloading_files || Discourse.User.current()) {
|
||||
src.push('<a class="image-source-link" href="' + href + '">' + I18n.t("lightbox.download") + '</a>');
|
||||
}
|
||||
return src.join(' · ');
|
||||
}
|
||||
beforeClose() {
|
||||
this.wrap.off("click.pinhandler");
|
||||
this.wrap.removeClass("mfp-force-scrollbars");
|
||||
}
|
||||
},
|
||||
|
||||
image: {
|
||||
titleSrc(item) {
|
||||
const href = item.el.data("download-href") || item.src;
|
||||
let src = [escapeExpression(item.el.attr("title")), $("span.informations", item.el).text().replace('x', '×')];
|
||||
if (!Discourse.SiteSettings.prevent_anons_from_downloading_files || Discourse.User.current()) {
|
||||
src.push('<a class="image-source-link" href="' + href + '">' + I18n.t("lightbox.download") + '</a>');
|
||||
}
|
||||
return src.join(' · ');
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
4
public/javascripts/jquery.magnific-popup.min.js
vendored
Normal file
4
public/javascripts/jquery.magnific-popup.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -39,7 +39,7 @@
|
|||
//= require plugin_tests
|
||||
//= require_self
|
||||
//
|
||||
//= require jquery.magnific-popup-min.js
|
||||
//= require jquery.magnific-popup.min.js
|
||||
|
||||
window.inTestEnv = true;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user