js: Extract lightbox.js from ui.js.

This commit is contained in:
Tim Abbott 2017-03-17 16:50:39 -07:00
parent a51caceea5
commit ed90879602
5 changed files with 62 additions and 52 deletions

View File

@ -25,6 +25,7 @@
"popovers": false, "popovers": false,
"server_events": false, "server_events": false,
"ui": false, "ui": false,
"lightbox": false,
"stream_color": false, "stream_color": false,
"people": false, "people": false,
"navigate": false, "navigate": false,

View File

@ -523,12 +523,12 @@ $(function () {
e.stopPropagation(); e.stopPropagation();
if ($target.parent().hasClass("youtube-video")) { if ($target.parent().hasClass("youtube-video")) {
ui.lightbox({ lightbox.open({
type: "youtube", type: "youtube",
id: $target.data("id"), id: $target.data("id"),
}); });
} else { } else {
ui.lightbox({ lightbox.open({
type: "photo", type: "photo",
image: img, image: img,
user: user, user: user,

58
static/js/lightbox.js Normal file
View File

@ -0,0 +1,58 @@
var lightbox = (function () {
var exports = {};
function display_image(image, user) {
// image should be an Image Object in JavaScript.
var url = $(image).attr("src");
var title = $(image).parent().attr("title");
$("#overlay .player-container").hide();
$("#overlay .image-actions, .image-description, .download").show();
var img = new Image();
img.src = url;
$("#overlay .image-preview").html("").show()
.append(img);
$(".image-description .title").text(title || "N/A");
$(".image-description .user").text(user);
$(".image-actions .open, .image-actions .download").attr("href", url);
}
function display_youtube_video(id) {
$("#overlay .image-preview, .image-description, .download").hide();
var iframe = document.createElement("iframe");
iframe.width = window.innerWidth;
iframe.height = window.innerWidth * 0.5625;
iframe.src = "https://www.youtube.com/embed/" + id;
iframe.setAttribute("frameborder", 0);
iframe.setAttribute("allowfullscreen", true);
$("#overlay .player-container").html("").show().append(iframe);
$(".image-actions .open").attr("href", "https://youtu.be/" + id);
}
exports.open = function (data) {
switch (data.type) {
case "photo":
display_image(data.image, data.user);
break;
case "youtube":
display_youtube_video(data.id);
break;
default:
break;
}
$("#overlay").addClass("show");
popovers.hide_all();
};
return exports;
}());
if (typeof module !== 'undefined') {
module.exports = lightbox;
}

View File

@ -262,22 +262,6 @@ exports.show_failed_message_success = function (message_id) {
}); });
}; };
exports.lightbox = function (data) {
switch (data.type) {
case "photo":
exports.lightbox_photo(data.image, data.user);
break;
case "youtube":
exports.youtube_video(data.id);
break;
default:
break;
}
$("#overlay").addClass("show");
popovers.hide_all();
};
$(document).ready(function () { $(document).ready(function () {
var info_overlay_toggle = components.toggle({ var info_overlay_toggle = components.toggle({
name: "info-overlay-toggle", name: "info-overlay-toggle",
@ -311,40 +295,6 @@ exports.show_info_overlay = function (target) {
} }
}; };
exports.lightbox_photo = function (image, user) {
// image should be an Image Object in JavaScript.
var url = $(image).attr("src");
var title = $(image).parent().attr("title");
$("#overlay .player-container").hide();
$("#overlay .image-actions, .image-description, .download").show();
var img = new Image();
img.src = url;
$("#overlay .image-preview").html("").show()
.append(img);
$(".image-description .title").text(title || "N/A");
$(".image-description .user").text(user);
$(".image-actions .open, .image-actions .download").attr("href", url);
};
exports.youtube_video = function (id) {
$("#overlay .image-preview, .image-description, .download").hide();
var iframe = document.createElement("iframe");
iframe.width = window.innerWidth;
iframe.height = window.innerWidth * 0.5625;
iframe.src = "https://www.youtube.com/embed/" + id;
iframe.setAttribute("frameborder", 0);
iframe.setAttribute("allowfullscreen", true);
$("#overlay .player-container").html("").show().append(iframe);
$(".image-actions .open").attr("href", "https://youtu.be/" + id);
};
// k3O01EfM5fU
var loading_more_messages_indicator_showing = false; var loading_more_messages_indicator_showing = false;
exports.show_loading_more_messages_indicator = function () { exports.show_loading_more_messages_indicator = function () {
if (! loading_more_messages_indicator_showing) { if (! loading_more_messages_indicator_showing) {

View File

@ -848,6 +848,7 @@ JS_SPECS = {
'js/condense.js', 'js/condense.js',
'js/resize.js', 'js/resize.js',
'js/floating_recipient_bar.js', 'js/floating_recipient_bar.js',
'js/lightbox.js',
'js/ui.js', 'js/ui.js',
'js/pointer.js', 'js/pointer.js',
'js/click_handlers.js', 'js/click_handlers.js',