123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- var $imgMsg, naturalWidthSize, naturalWidth, $img, winWidth, winHeight, isW;
- var $imgMenuMsk;
- var $imgmenuwrapper;
- var menuShowed = false;
- mui.plusReady(function(){
- $('#__MUI_PREVIEWIMAGE').prepend('<div class="img-bar">···</div>');
-
- $('body').prepend(
- // '<div class="img-bar">···</div>'+
- '<div class="img-menu-msk" >' +
- '<div class="img-menu-wrapper">' +
- '<ul class="img-menu">' +
- '<li id="zftp">转发给其他人</li>' +
- '<li id="savePic">保存到本地</li>' +
- '<li id="loc_chat">定位到聊天位置</li>' +
- '</ul>' +
- '<div class="img-menu-cancle">取消</div>' +
- '</div>' +
- '</div>');
-
- $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();
- }
|