thedesk/app/js/ui/img.js

292 lines
8.6 KiB
JavaScript
Raw Normal View History

2018-01-28 23:22:43 +11:00
/*イメージビューワー*/
//postのimg.jsとは異なります。
2018-02-14 03:19:44 +11:00
function imgv(id, key, acct_id) {
2018-04-07 14:31:09 +10:00
$("#imgprog").text(0);
2018-09-19 02:41:48 +10:00
$('#imgmodal').hide();
2019-02-05 13:33:32 +11:00
$('#imgmodal').attr('src', '../../img/loading.svg');
2018-01-28 23:22:43 +11:00
var murl = $("#" + id + "-image-" + key).attr("data-url");
var type = $("#" + id + "-image-" + key).attr("data-type");
2018-02-14 03:19:44 +11:00
$("#imagemodal").attr("data-id",id);
$("#imagemodal").attr("data-acct",acct_id);
2018-01-28 23:22:43 +11:00
$(document).ready(function() {
if (type == "image") {
$('#imagemodal').modal('open');
2018-04-07 14:31:09 +10:00
xhr = new XMLHttpRequest;
xhr.open('GET', murl, true);
xhr.addEventListener('progress', function (event) {
if (event.lengthComputable) {
var total=event.total;
var now=event.loaded;
var per=now/total*100;
2018-07-07 03:51:48 +10:00
$("#imgprog").text(Math.floor(per));
2018-04-07 14:31:09 +10:00
}
}, false);
xhr.addEventListener('loadend', function (event) {
var total=event.total;
var now=event.loaded;
var per=now/total*100;
2018-07-07 03:51:48 +10:00
$("#imgprog").text(Math.floor(per));
2018-04-07 14:31:09 +10:00
}, false);
xhr.send();
2018-01-28 23:22:43 +11:00
$('#imgmodal').attr('src', murl);
$('#imagewrap').dragScroll(); // ドラッグスクロール設定
2018-09-19 02:41:48 +10:00
$('#imgmodal').show();
2018-01-28 23:22:43 +11:00
$('#imagemodal').attr('data-key', key);
$('#imagemodal').attr('data-id', id);
} else if (type == "video" || type == "gifv") {
$('#video').attr('src', murl);
$('#videomodal').modal('open');
2018-09-19 02:41:48 +10:00
$('#imgmodal').show();
2018-01-28 23:22:43 +11:00
}
var element = new Image();
var width;
element.onload = function() {
var width = element.naturalWidth;
var height = element.naturalHeight;
2018-02-14 03:19:44 +11:00
var windowH = $(window).height();
var windowW = $(window).width();
$("#imagemodal").css("bottom","0")
$("#imagemodal img").css("width","auto")
if(height<windowH){
$("#imagemodal").css("height",height+60+"px")
$("#imagemodal img").css("height","100%")
if(width>windowW*0.8){
$("#imagemodal").css("width","80vw")
$("#imagemodal img").css("width","100%")
var heightS=windowW*0.8/width*height;
$("#imagemodal").css("height",heightS+60+"px")
}else{
$("#imagemodal").css("width",width+"px")
}
2018-02-14 03:19:44 +11:00
}else{
$("#imagemodal img").css("width","auto")
var widthS=windowH/height*width;
if(widthS<windowW){
$("#imagemodal").css("width",widthS+"px")
2018-02-17 00:08:43 +11:00
}else{
$("#imagemodal").css("width","100vw")
2018-02-17 00:08:43 +11:00
}
$("#imagemodal").css("height","100vh")
$("#imagemodal img").css("height","calc(100vh - 60px)")
2018-02-14 03:19:44 +11:00
}
2018-03-18 02:00:53 +11:00
2018-01-28 23:22:43 +11:00
}
if ($("#" + id + "-image-" + (key * 1 + 1)).length == 0) {
$("#image-next").prop("disabled", true);
2018-01-29 01:01:18 +11:00
} else {
$("#image-next").prop("disabled", false);
2018-01-28 23:22:43 +11:00
}
if ($("#" + id + "-image-" + (key * 1 - 1)).length == 0) {
$("#image-prev").prop("disabled", true);
2018-01-29 01:01:18 +11:00
} else {
$("#image-prev").prop("disabled", false);
2018-01-28 23:22:43 +11:00
}
element.src = murl;
});
}
//イメージビューワーの送り
function imgCont(type) {
2018-04-07 14:31:09 +10:00
$("#imgprog").text(0);
2018-01-28 23:22:43 +11:00
var key = $('#imagemodal').attr('data-key');
var id = $('#imagemodal').attr('data-id');
if (type == "next") {
key++;
} else if (type == "prev") {
key = key * 1 - 1;
}
var murl = $("#" + id + "-image-" + key).attr("data-url");
2018-01-29 01:01:18 +11:00
if(murl){
2019-02-05 13:33:32 +11:00
$('#imgmodal').attr('src', '../../img/loading.svg');
2018-01-28 23:22:43 +11:00
var type = $("#" + id + "-image-" + key).attr("data-type");
$(document).ready(function() {
if (type == "image") {
2018-04-07 14:31:09 +10:00
xhr = new XMLHttpRequest;
xhr.open('GET', murl, true);
2019-01-26 14:24:26 +11:00
xhr.responseType = "arraybuffer";
2018-04-07 14:31:09 +10:00
xhr.addEventListener('progress', function (event) {
if (event.lengthComputable) {
var total=event.total;
var now=event.loaded;
var per=now/total*100;
2018-07-07 03:51:48 +10:00
$("#imgprog").text(Math.floor(per));
2018-04-07 14:31:09 +10:00
}
}, false);
xhr.addEventListener('loadend', function (event) {
var total=event.total;
var now=event.loaded;
var per=now/total*100;
2018-07-07 03:51:48 +10:00
$("#imgprog").text(Math.floor(per));
2018-04-07 14:31:09 +10:00
}, false);
xhr.send();
2018-01-28 23:22:43 +11:00
$('#imgmodal').attr('src', murl);
$('#imagewrap').dragScroll(); // ドラッグスクロール設定
$('#imagemodal').attr('data-key', key);
$('#imagemodal').attr('data-id', id);
} else if (type == "video" || type == "gifv") {
$('#video').attr('src', murl);
$('#videomodal').modal('open');
}
var element = new Image();
var width;
element.onload = function() {
var width = element.naturalWidth;
var height = element.naturalHeight;
2018-02-14 03:19:44 +11:00
var windowH = $(window).height();
var windowW = $(window).width();
2019-03-16 16:05:04 +11:00
$("#imagemodal").css("bottom","0")
$("#imagemodal img").css("width","auto")
if(height<windowH){
$("#imagemodal").css("height",height+60+"px")
$("#imagemodal img").css("height","100%")
if(width>windowW*0.8){
$("#imagemodal").css("width","80vw")
$("#imagemodal img").css("width","100%")
var heightS=windowW*0.8/width*height;
$("#imagemodal").css("height",heightS+60+"px")
}else{
$("#imagemodal").css("width",width+"px")
}
2018-02-14 03:19:44 +11:00
}else{
2019-03-16 16:05:04 +11:00
$("#imagemodal img").css("width","auto")
var widthS=windowH/height*width;
if(widthS<windowW){
$("#imagemodal").css("width",widthS+"px")
2018-02-17 00:08:43 +11:00
}else{
2019-03-16 16:05:04 +11:00
$("#imagemodal").css("width","100vw")
2018-02-17 00:08:43 +11:00
}
2019-03-16 16:05:04 +11:00
$("#imagemodal").css("height","100vh")
$("#imagemodal img").css("height","calc(100vh - 60px)")
2018-02-14 03:19:44 +11:00
}
2018-01-28 23:22:43 +11:00
}
2019-03-08 05:19:26 +11:00
if ($("#" + id + "-image-" + (key * 1 + 1)).length === 0) {
2018-01-28 23:22:43 +11:00
$("#image-next").prop("disabled", true);
} else {
$("#image-next").prop("disabled", false);
}
2019-03-08 05:19:26 +11:00
if ($("#" + id + "-image-" + (key * 1 - 1)).length === 0) {
2018-01-28 23:22:43 +11:00
$("#image-prev").prop("disabled", true);
} else {
$("#image-prev").prop("disabled", false);
}
element.src = murl;
2018-01-29 01:01:18 +11:00
2018-01-28 23:22:43 +11:00
});
2018-01-29 01:01:18 +11:00
}
2018-01-28 23:22:43 +11:00
}
//ズームボタン(z:倍率)
function zoom(z) {
var wdth = $('#imagewrap img').width();
var wdth = wdth * z;
2018-02-14 03:19:44 +11:00
$('#imagewrap img').css("width", wdth+"px");
var hgt = $('#imagewrap img').height();
var hgt = hgt * z;
$('#imagewrap img').css("height", hgt+"px");
2018-01-28 23:22:43 +11:00
}
//スマホ対応ドラッグ移動システム
(function() {
$.fn.dragScroll = function() {
var target = this;
$(this).mousedown(function(event) {
$(this)
.data('down', true)
.data('x', event.clientX)
.data('y', event.clientY)
.data('scrollLeft', this.scrollLeft)
.data('scrollTop', this.scrollTop);
return false;
}).css({
'overflow': 'hidden', // スクロールバー非表示
'cursor': 'move'
});
// ウィンドウから外れてもイベント実行
$(document).mousemove(function(event) {
if ($(target).data('down') == true) {
// スクロール
target.scrollLeft($(target).data('scrollLeft') + $(target).data('x') -
event.clientX);
target.scrollTop($(target).data('scrollTop') + $(target).data('y') -
event.clientY);
return false; // 文字列選択を抑止
}
}).mouseup(function(event) {
$(target).data('down', false);
});
$(this).on('touchstart', function(event) {
$(this)
.data('down', true)
.data('x', getX(event))
.data('y', getY(event))
.data('scrollLeft', this.scrollLeft)
.data('scrollTop', this.scrollTop);
return false;
}).css({
'overflow': 'hidden', // スクロールバー非表示
'cursor': 'move'
}); //指が触れたか検知
$(this).on('touchmove', function(event) {
2019-03-08 05:19:26 +11:00
if ($(target).data('down') === true) {
2018-01-28 23:22:43 +11:00
// スクロール
target.scrollLeft($(target).data('scrollLeft') + $(target).data('x') -
getX(event));
target.scrollTop($(target).data('scrollTop') + $(target).data('y') -
getY(event));
return false; // 文字列選択を抑止
} else {}
}); //指が動いたか検知
$(this).on('touchend', function(event) {
$(target).data('down', false);
});
return this;
}
})(jQuery);
function getX(event) {
return event.originalEvent.touches[0].pageX;
}
function getY(event) {
return event.originalEvent.touches[0].pageY;
}
//マウスホイールで拡大
var element = document.getElementById("imagemodal");
element.onmousewheel = function(e) {
var delta = e.wheelDelta;
if (delta > 0) {
zoom(1.1)
} else {
zoom(0.9)
}
}
2018-03-31 13:39:06 +11:00
2018-02-18 16:43:11 +11:00
//当該トゥート
2018-02-14 03:19:44 +11:00
function detFromImg(){
var id=$("#imagemodal").attr("data-id");
var acct_id=$("#imagemodal").attr("data-acct");
$('#imagemodal').modal('close');
details(id,acct_id);
2018-02-17 00:08:43 +11:00
}
2018-02-18 16:43:11 +11:00
//画像保存
2018-02-17 00:08:43 +11:00
function dlImg(){
var url=$("#imgmodal").attr("src");
var electron = require("electron");
var ipc = electron.ipcRenderer;
2018-09-06 02:47:27 +10:00
if(localStorage.getItem("savefolder")){
var save=localStorage.getItem("savefolder");
}else{
var save="";
}
ipc.send('general-dl', [url,save,false]);
2018-02-17 00:08:43 +11:00
ipc.on('general-dl-prog', function (event, arg) {
2019-05-19 16:17:05 +10:00
console.log("Progress: "+arg);
2018-02-17 00:08:43 +11:00
})
ipc.on('general-dl-message', function (event, arg) {
2019-04-03 14:59:29 +11:00
var argC=arg.replace(/\\/g,"\\\\")+"\\\\.";
Materialize.toast(lang.lang_img_DLDone+arg+'<button class="btn-flat toast-action" onclick="openFinder(\''+argC+'\')">Show</button>', 5000);
2018-02-17 00:08:43 +11:00
})
2019-04-03 14:59:29 +11:00
}
function openFinder(dir){
ipc.send('open-finder', dir);
2018-02-14 03:19:44 +11:00
}