var $imgMsg, naturalWidthSize, naturalWidth, $img, winWidth, winHeight, isW; var $imgMenuMsk; var $imgmenuwrapper; var menuShowed = false; mui.plusReady(function(){ $('#__MUI_PREVIEWIMAGE').prepend('
'); $('body').prepend( // ' '+ ' '); $imgMenuMsk = $('.img-menu-msk'); $imgmenuwrapper = $('.img-menu-wrapper'); bindEvts(); }) function bindEvts(){ /** * 右上角按钮点击事件 */ $('.img-bar').on('tap', function(){ if(menuShowed) { hideMenu(); } else { showMenu(); } return false; }) /** * 取消 */ $('.img-menu-cancle').on('tap', function(){ hideMenu(); return false; }) /** * 保存图片 */ $('#savePic').on('tap', function(){ downLoadImg($('.mui-slider-item.mui-zoom-wrapper.mui-active img').attr('src')); return false; }) /** * 定位聊天位置 */ $('#loc_chat').on('tap', function(){ hideMenu(); prevImage.close(); plus.nativeUI.showWaiting(); locationImg($('.mui-slider-item.mui-zoom-wrapper.mui-active img').attr('data-code')); return false; }) /** * 转发图片 */ $('#zftp').on('tap', function(){ toZf([{content: $('.mui-slider-item.mui-zoom-wrapper.mui-active img').attr('src'), type: 2}]); return false; }) } function showMenu(){ if(!menuShowed){ menuShowed = true; $imgMenuMsk.show(); $imgmenuwrapper.fadeIn('fast'); } } function hideMenu(){ if(menuShowed){ menuShowed = false; $imgMenuMsk.hide(); $imgmenuwrapper.fadeOut('fast'); } } /*$('body').on('tap', '.mui-slider.mui-preview-image', function(){ $('.img-bar').fadeOut(500); }) $('body').on('tap', '.word-bread img', function(){ $('.img-bar').show(); $img.css({'min-height': 'initial', 'top': 'auto', 'left': 'auto', 'width': 'auto', 'height': 'auto'}) .addClass('orign') .attr('src', $(this).attr('src')); winWidth = $(window).width(); winHeight = $(window).height(); naturalWidthSize = getNaturalSize($img); naturalWidth = naturalWidthSize.w; $imgMsg.fadeIn("normal", function(){ if(naturalWidthSize.w > winWidth || naturalWidthSize.h > winHeight){ if(naturalWidthSize.w > naturalWidthSize.h){ $img.css('min-height', $img.height() +'px'); } else { $img.css('min-height', '100%'); } } else { $img.css('min-height', naturalWidthSize.h+ "px"); } }); return false; }) */ $('body').on('tap', '.img-menu-msk', function(){ if(menuShowed){ hideMenu(); } else $imgMsg.fadeOut("normal"); return false; }) var ssx1, ssy1, ssx2, ssy2, targets; var distance = 0, oldWidth, oldH, oTop, oLeft; var isDouble = false; $('body').on('touchstart', '.img-msk', function(e){ targets = e.originalEvent.touches; if(targets.length==2 && !menuShowed){ e.preventDefault(); isDouble = true; ssx1 = targets[0].screenX; ssy1 = targets[0].screenY; ssx2 = targets[1].screenX; ssy2 = targets[1].screenY; oldWidth = $img.width(); oldH = $img.height(); distance = getDistance(ssx1, ssy1, ssx2, ssy2); } else if(targets.length==1){ isDouble = false; } else { isDouble = false; } }).on('touchmove', '.img-msk', function(e){ targets = e.originalEvent.touches; if(targets.length==2 && !menuShowed){ e.preventDefault(); var off = getDistance(targets[0].screenX, targets[0].screenY, targets[1].screenX, targets[1].screenY); var dis = (off-distance) * 2; $img.height(oldH + dis); $img.removeClass('orign'); } else if(targets.length==1 && !isDouble){ } else return false; }) function getDistance(x1, y1, x2, y2){ return Math.sqrt( Math.pow((x1-x2), 2) + Math.pow((y1-y2), 2) ) } function getNaturalSize($img) { var image = new Image() image.src = $img.attr('src'); return {w: image.width, h: image.height} } /** * 下载图片 * @param {Object} url */ function downLoadImg(url){ var dtask = plus.downloader.createDownload( url, {filename: "_downloads/"}, function ( d, status ) { if ( status == 200 ) { hideMenu(); plus.gallery.save( plus.io.convertLocalFileSystemURL( d.filename ), function(){ mui.toast("图片已保存至相册"); }, function(){ mui.toast("图片保存失败!") }); } else { mui.toast("图片保存失败!") } }); dtask.start(); }