fd-gulp-convert-encoding
Version:
convert file to assigned charset
176 lines (142 loc) • 4.79 kB
JavaScript
/**
* gallery view交互逻辑
*/
define('detail.modules.gallery.View',
['jQuery', 'Class', 'lofty.ui.Swipe', 'lofty.ui.Popup',
'detail.modules.gallery.Fav', 'detail.modules.gallery.Share'],
function($, Class, Swipe, Popup, Fav, Share) {
return Class({
init: function(view, config) {
this.onEvent = $.os.supportsTouch ? 'tap' : 'click';
this.div = view;
this.config = config;
this.swipe = $('div.d-swipe', view);
this.swipePopup = $('div.d-swipe-popup');
this.swipeIndex = 0;
this.initSwipe();
// this.slideFullPic();
this.showFullPic();
this._initFav();
this._initShare();
this._bindImgLoadEvent();
},
initSwipe: function(){
var $li = $('ul.swipe-nav li', this.swipe),
swipe, that = this;
if (!this.swipe.length){
return;
}
swipe = new Swipe({
tpl: "#d-swipe",
auto: 0,
callback: function(index, elm){
that.swipeIndex = index;
$li.removeClass('active').removeClass('activeSp');
$($li.slice(0, index+1)).addClass('activeSp');
}
});
},
slideFullPic: function(){
var $swipePane = $('div.swipe-pane', this.swipe),
$swipeNav = $('ul.swipe-nav', this.swipe),
start = {}, delta = {};
$swipePane.on('touchstart', function(e){
var touches = e.touches[0];
start = {
x: touches.pageX,
y: touches.pageY
};
delta = {};
});
$swipePane.on('touchmove', function(e){
var touches = e.touches[0],
elm = $(this);
delta = {
x: touches.pageX,
y: touches.pageY
};
var xDelta = Math.abs(start.x - delta.x),
yDelta = Math.abs(start.y - delta.y);
if (xDelta < yDelta && start.y < delta.y) {
$swipeNav.addClass('swipe-shadow');
elm.css('marginTop', -30 + yDelta/2);
elm.css('marginBottom', -30 + yDelta/2);
}
});
$swipePane.on('touchend', function(e){
var elm = $(this);
if (elm.css('marginTop').replace('px', '') * 1 < -30){
elm.css('marginTop', -30);
elm.css('marginBottom', -30);
return;
}
var timer = setInterval(function() {
if (elm.css('marginTop').replace('px', '') * 1 < -28){
clearInterval(timer);
$swipeNav.removeClass('swipe-shadow');
}
elm.css('marginTop', elm.css('marginTop').replace('px', '') * 1 - 1);
elm.css('marginBottom', elm.css('marginBottom').replace('px', '') * 1 - 1);
}, 5, 'linear');
});
},
showFullPic: function(){
var $swipe = this.swipe,
$swipePopup = this.swipePopup,
$curPageNum = $('span.cur-page', $swipePopup),
swipePopup,
that = this;
if (!this.swipe.length){
return;
}
var popup = new Popup({
tpl: '.d-swipe-popup',
isModal: true,
maskAttr: {
maskColor: '#4d4d4d',
maskOpacity: '1'
}
});
swipePopup = new Swipe({
tpl: "#d-swipe-popup",
auto: 0,
callback: function(index, elm){
$curPageNum.text(index + 1);
}
});
$curPageNum.text(that.swipeIndex + 1);
$swipe.on(this.onEvent, function(e){
e.preventDefault();
popup.show();
swipePopup.slide(that.swipeIndex ? that.swipeIndex : 0);
that.hideBodyOverflow();
});
$swipePopup.on('doubleTap', function(e){
e.preventDefault();
popup.hide();
that.showBodyOverflow();
});
},
_bindImgLoadEvent: function(){
$('img', this.div).bind('load',function(){
if (this.width >= 300){
$(this).css('width', '100%');
}
$(this).css('visibility', 'visible');
});
},
hideBodyOverflow: function(){
this.bodyOverflow = $('body').css('overflow');
$('body').css('overflow','hidden');
},
showBodyOverflow: function(){
$('body').css('overflow', this.bodyOverflow);
},
_initFav: function(){
var fav = new Fav(this.div, this.config);
},
_initShare: function(){
var fav = new Share(this.div, this.config);
}
});
});