2017-08-23 19:40:27 +00:00
|
|
|
define(function(require, exports) {
|
2017-12-01 12:24:53 +00:00
|
|
|
var imageUrl = function(path){
|
|
|
|
if(path.substr(0,4) == 'http'){
|
|
|
|
return path;
|
|
|
|
}
|
2018-07-05 13:50:52 +00:00
|
|
|
//gif 预览
|
|
|
|
if(core.pathExt(path) == 'gif'){
|
|
|
|
return core.path2url(path);
|
|
|
|
}
|
|
|
|
|
2017-12-01 12:24:53 +00:00
|
|
|
var imageThumb = G.appHost+'explorer/image';
|
|
|
|
if(G.sid){
|
|
|
|
imageThumb = G.appHost+'share/image&user='+G.user+'&sid='+G.sid;
|
|
|
|
}
|
|
|
|
imageThumb += '&path='+urlEncode(path)+'&thumbWidth=1200';
|
|
|
|
return imageThumb;
|
|
|
|
}
|
|
|
|
|
2017-08-26 09:16:57 +00:00
|
|
|
var itemsArr = [];
|
2017-08-23 19:40:27 +00:00
|
|
|
var getImageArr = function(imagePath){
|
2017-08-26 09:16:57 +00:00
|
|
|
itemsArr = [];
|
2017-08-23 19:40:27 +00:00
|
|
|
var index = -1;
|
2017-08-26 09:16:57 +00:00
|
|
|
var itemsPush = function(path,msrc,$dom){
|
2017-12-01 12:24:53 +00:00
|
|
|
if($dom && $dom.attr('data-src')){
|
|
|
|
path = $dom.attr('data-src');
|
|
|
|
msrc = $dom.attr('data-original');
|
|
|
|
}
|
2017-08-26 09:16:57 +00:00
|
|
|
var width = 0,height = 0;
|
2017-12-01 12:24:53 +00:00
|
|
|
var link = imageUrl(path);
|
2017-08-26 09:16:57 +00:00
|
|
|
if(!msrc){
|
2017-12-01 12:24:53 +00:00
|
|
|
msrc = link;
|
2017-08-23 19:40:27 +00:00
|
|
|
}
|
2017-08-26 09:16:57 +00:00
|
|
|
itemsArr.push({
|
2017-12-01 12:24:53 +00:00
|
|
|
src:link,
|
2017-08-26 09:16:57 +00:00
|
|
|
msrc:msrc,
|
2017-12-01 12:24:53 +00:00
|
|
|
title:core.pathThis(urlDecode(path)),
|
2017-08-26 09:16:57 +00:00
|
|
|
w:width,h:height,
|
|
|
|
$dom:$dom?$dom:false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//打开时最后的target对象dom [文件列表;搜索列表;树目录[编辑器压缩文件预览]]
|
|
|
|
var $lastTarget = kodApp.getLastOpenTarget();
|
|
|
|
//console.log('test',$lastTarget);
|
|
|
|
if(!$lastTarget || _.get($lastTarget,'length') == 0){
|
|
|
|
}else if($lastTarget.hasClass('file-box')){
|
|
|
|
var $continer = $lastTarget.parents('.file-continer');
|
|
|
|
$continer.find('.ico.picture').each(function(i){
|
|
|
|
var $image = $(this).find('img');
|
|
|
|
var thePath = hashDecode($(this).parents('.file').attr('data-path'));
|
|
|
|
if(thePath == imagePath){
|
|
|
|
index = i;
|
|
|
|
}
|
|
|
|
itemsPush(thePath,$image.attr('data-original'),$image);
|
|
|
|
});
|
|
|
|
}else if($lastTarget.parents('.search-result').exists()){//搜索列表
|
|
|
|
var $continer = $lastTarget.parents('.search-result');
|
|
|
|
$continer.find('.file-item').each(function(i){
|
|
|
|
var thePath = hashDecode($(this).attr('data-path'));
|
2017-12-01 12:24:53 +00:00
|
|
|
if($(this).attr('data-src')){
|
|
|
|
thePath = $(this).attr('data-src');
|
|
|
|
}
|
2017-08-26 09:16:57 +00:00
|
|
|
var ext = core.pathExt(thePath);
|
|
|
|
if(!kodApp.appSupportCheck('photoSwipe',ext)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(thePath == imagePath){
|
|
|
|
index = i;
|
|
|
|
}
|
|
|
|
itemsPush(thePath,false,$(this).find('.file-icon'));
|
|
|
|
});
|
|
|
|
}else if($lastTarget.parents('.ztree').exists()){ //树目录:编辑器或压缩文件内打开
|
|
|
|
var id = $lastTarget.parents('.ztree').attr('id');
|
|
|
|
var zTree = $.fn.zTree.getZTreeObj(id);
|
|
|
|
var fileNum = 0;
|
|
|
|
$lastTarget.parent().find('li[treenode]').each(function(){
|
|
|
|
var node = zTree.getNodeByTId($(this).attr('id'));
|
|
|
|
if(!node) return;
|
|
|
|
var thePath = node.path;
|
|
|
|
var ext = core.pathExt(node.path);
|
|
|
|
if(!kodApp.appSupportCheck('photoSwipe',ext)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(thePath == imagePath){
|
|
|
|
index = fileNum;
|
|
|
|
}
|
|
|
|
fileNum ++;
|
|
|
|
itemsPush(thePath,false,$(this).find('.tree_icon'));
|
|
|
|
});
|
2017-08-23 19:40:27 +00:00
|
|
|
}
|
2017-08-26 09:16:57 +00:00
|
|
|
if(itemsArr.length == 0 || index == -1){
|
2017-12-01 12:24:53 +00:00
|
|
|
itemsArr = [];
|
|
|
|
itemsPush(imagePath);
|
|
|
|
index = 0;
|
2017-08-23 19:40:27 +00:00
|
|
|
}
|
2017-08-26 09:16:57 +00:00
|
|
|
return {items:itemsArr,index:index};
|
2017-08-23 19:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var options = {
|
2018-07-05 13:50:52 +00:00
|
|
|
// history: false,
|
2017-08-23 19:40:27 +00:00
|
|
|
focus: true,
|
|
|
|
index: 0,
|
|
|
|
bgOpacity:0.8,
|
|
|
|
maxSpreadZoom:5,
|
|
|
|
closeOnScroll:false,
|
2018-07-05 13:50:52 +00:00
|
|
|
|
|
|
|
shareEl: true,
|
|
|
|
shareButtons: [
|
|
|
|
//{id:'facebook', label:'Facebook', url:'https://www.facebook.com/sharer/sharer.php?u={{url}}'},
|
|
|
|
{id:'open', label:LNG.menu_open_window, url:'{{raw_image_url}}', download:false},
|
|
|
|
],
|
2017-08-23 19:40:27 +00:00
|
|
|
|
|
|
|
showHideOpacity:false,
|
|
|
|
showAnimationDuration: 300,
|
|
|
|
hideAnimationDuration: 300,
|
2018-07-05 13:50:52 +00:00
|
|
|
fullscreenEl : true,
|
|
|
|
|
|
|
|
// captionEl : false,
|
|
|
|
// tapToClose : false,
|
|
|
|
// tapToToggleControls : true,
|
2017-08-23 19:40:27 +00:00
|
|
|
getThumbBoundsFn: function(index) {
|
2017-08-26 09:16:57 +00:00
|
|
|
var item = itemsArr[index];
|
2017-09-06 17:09:41 +00:00
|
|
|
if(!item || !item.$dom || item.$dom.length == 0){//目录切换后没有原图
|
2017-08-26 09:16:57 +00:00
|
|
|
return {x:$(window).width()/2,y:$(window).height()/2,w:1,h:1};
|
2017-08-23 19:40:27 +00:00
|
|
|
}
|
|
|
|
var pageYScroll = window.pageYOffset || document.documentElement.scrollTop;
|
2017-08-26 09:16:57 +00:00
|
|
|
var rect = $(item.$dom).get(0).getBoundingClientRect();
|
|
|
|
return {x:rect.left,y:rect.top + pageYScroll,w:rect.width,h:rect.height};
|
2017-08-23 19:40:27 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//http://dimsemenov.com/plugins/royal-slider/gallery/
|
|
|
|
//http://photoswipe.com/documentation/faq.html
|
|
|
|
return function(imagePath,appStatic,appStaticDefault){
|
|
|
|
require.async([
|
|
|
|
appStaticDefault+'PhotoSwipe/photoSwipe.html',
|
|
|
|
appStatic+'PhotoSwipe/photoswipe.min',
|
|
|
|
appStatic+'PhotoSwipe/photoswipe-ui-default.min',
|
|
|
|
appStatic+'PhotoSwipe/photoswipe.css',
|
|
|
|
appStatic+'PhotoSwipe/default-skin/default-skin.css',
|
|
|
|
],function(photoSwipeTpl){
|
|
|
|
if($('.pswp_content').length == 0){
|
|
|
|
$(photoSwipeTpl).appendTo('body');
|
|
|
|
$('.pswp__caption__center').css({"text-align":"center"});
|
|
|
|
}
|
2017-08-26 09:16:57 +00:00
|
|
|
if($('.pswp').hasClass('pswp--open')){//已经打开
|
|
|
|
return;
|
|
|
|
}
|
2017-08-23 19:40:27 +00:00
|
|
|
|
|
|
|
var image = getImageArr(imagePath);
|
|
|
|
options.index = image.index;
|
|
|
|
var gallery = new PhotoSwipe($('.pswp').get(0),PhotoSwipeUI_Default,image.items,options);
|
|
|
|
gallery.loadFinished = false;
|
|
|
|
gallery.listen('gettingData', function(index, item) {
|
|
|
|
if (item.w < 1 || item.h < 1) {
|
|
|
|
var img = new Image();
|
|
|
|
img.onload = function() {
|
|
|
|
item.w = this.width;
|
|
|
|
item.h = this.height;
|
|
|
|
gallery.updateSize(true);
|
|
|
|
}
|
|
|
|
img.src = item.src;
|
|
|
|
}
|
|
|
|
|
|
|
|
//打开图片,加载动画起始位置
|
|
|
|
if(!gallery.loadFinished){
|
|
|
|
var rect = options.getThumbBoundsFn(index);
|
|
|
|
item.w = rect.w * 25;
|
|
|
|
item.h = rect.h * 25;
|
|
|
|
gallery.loadFinished = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
gallery.init();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|