$.fn.extend({ animateCss: function (animationName, callback) { var animationEnd = (function (el) { var animations = { animation: 'animationend', OAnimation: 'oAnimationEnd', MozAnimation: 'mozAnimationEnd', WebkitAnimation: 'webkitAnimationEnd', }; for (var t in animations) { if (el.style[t] !== undefined) { return animations[t]; } } })(document.createElement('div')); this.addClass('animated ' + animationName).one(animationEnd, function () { //$(this).removeClass('animated ' + animationName); callback && callback.call(this, $(this), animationName); }); return this; }, }); var app = { /** * 请求id */ id: location.search.substring(1).replace(/ID=|\&pic=1/gi, ''), /** * 切换风格id */ switchId: 0, /** * 我的相片列表 */ imgList: [], /** * 广告切换 */ adsSwiper: function () { var html = []; var $elem = $('.ads-swiper') __config.adsPath && __config.adsPath.forEach(function (item) { html.push('
') }) if (!html.length) { html.push(' ') } $elem.find('.swiper-wrapper').html(html.join('')) new Swiper($elem[0], { autoplay: { delay: 3000, stopOnLastSlide: false, disableOnInteraction: true, }, pagination: { el: $elem.find('.swiper-pagination')[0], } }); }, /** * 画风切换 */ stlSwiper: function () { var $elem = $('.stl-swiper') new Swiper($elem[0], { //speed: 300, freeMode: true, slidesPerView: 3.5, }); var time; $elem.find('.swiper-slide').on('click', function () { var $this = $(this); var msg = $this.data('msg') app.checkOperationTimeout() if ('switch ' + app.switchId == msg) { // 已选择的不再执行 return; } if (!app.sendCheck()) { return; } if (time && (Date.now() - time < __config.switchInterval * 1000)) { app.showLoadingSwitch(function () { $elem.find('.swiper-slide').removeClass('active'); $this.addClass('active'); }) } else { $elem.find('.swiper-slide').removeClass('active') $this.addClass('active') } time = Date.now(); app.switchId = msg.split(' ')[1] app.send(msg) }); $elem.find('.swiper-slide').each(function () { var style = $(this).data('msg').split(' ')[1]; if (style) { var img = new Image() img.src = (__config.staticUrl || 'static') + '/images/styles/' + style + '-active.png'; } }) }, /** * 我的相片滚动 */ picSwiper: function () { if (this.picSwiper.swiper) { this.picSwiper.swiper.destroy() } this.picSwiper.swiper = new Swiper($('.pic-swiper')[0], { speed: 300, slidesPerView: 'auto', freeMode: true, direction: 'vertical', setWrapperSize: true, scrollbar: { el: '.swiper-scrollbar', }, }); }, events: function () { var self = this, $picList = $('.my-pic-list'); if (__config.link) { $('.logo').attr('href', __config.link) } $picList.find('header').on('touchstart', function (event) { event.preventDefault(); }); $picList.find('.btn-back').on('touchend', function (event) { event.preventDefault(); $picList.hide() }); $('.btn-pic-list').on('click', function (event) { app.send('close') $picList.show() self.renderPictures() }); $('.btn-pic-take').on('click', function (event) { app.checkOperationTimeout() if (!app.sendCheck()) { return; } self.send('photo empty') }); $('.app-view .close').on('click', function (event) { self.hideView() }); $('.app-alert .btn-use').on('click', function () { var $alert = $('.app-alert') app.hideMask() $alert.removeClass($alert.data('class') + ' animated zoomIn') var text = $(this).text(); if (text == '尝试使用' || text == '再次使用') { app.send('request') } }) $('.app-alert .btn-link').on('click', function () { if ($(this).text() == '重新拍照') { var $alert = $('.app-alert') app.hideMask() $alert.removeClass($alert.data('class') + ' animated zoomIn') $('.btn-pic-take').click() } }) }, showMask: function (clazz) { var $elem = $('.app-mask'); if (clazz) { $elem.addClass(this.showMask._clazz = clazz) } $elem.css('display', 'block') }, hideMask: function () { var $elem = $('.app-mask'); if (this.showMask._clazz) { $elem.removeClass(this.showMask._clazz) this.showMask._clazz = null } $elem.css('display', 'none') }, showAlert: function (msg, icon) { this.showMask(); var $alert = $('.app-alert'); var $btns = $alert.find('.btns a'); $alert.data('class', icon).addClass(icon).animateCss('zoomIn') $alert.find('.tips').html(msg) if (/error|used/.test(icon)) { $btns.eq(0).text('尝试使用') } else if (/timeout|stop/.test(icon)) { $btns.eq(0).text('再次使用') } else if (/fail/.test(icon)) { $btns.eq(0).text('重选画风') } if (/used|timeout|stop|error/.test(icon)) { $btns.eq(1).text('试试在线版').attr('href', $btns.eq(1).data('href')) } else if (/fail/.test(icon)) { $btns.eq(1).text('重新拍照').attr('href', 'javascript:;') } }, showActionTips: function (delay, done) { var $elem = $('.app-action-tips'); var flag = flag || 1; delay = delay || 1000; app.showMask('white') $elem.find('.content').hide() $elem.find('.content.face-' + flag).show() $elem.animateCss('zoomIn', function () { var timer = setInterval(() => { if (++flag > 4) { $elem.removeClass('animated zoomIn'); clearInterval(timer) if (!app.is_action) { app.hideMask('white') done && done() } return; } $elem.find('.content').hide() $elem.find('.content.face-' + flag).show() }, delay); }) }, showLoading: function (msg) { msg = msg || '相片正在生成中,请耐心等候' this.showMask(); $('.app-action-tips .content').css('display', 'none'); $('.app-action-tips .content.loading').css('display', 'block').find('.tips').html(msg); $('.app-action-tips').addClass('animated zoomIn') //.animateCss('zoomIn') }, hideLoading: function () { this.hideMask(); $('.app-action-tips .content.loading').css('display', 'none'); $('.app-action-tips').removeClass('animated zoomIn') }, showLoadingSwitch: function (done) { this.showMask(); $('.app-action-tips .content').css('display', 'none'); $('.app-action-tips .content.loading-switch').css('display', 'block') $('.app-action-tips').animateCss('zoomIn', function ($elem, aname) { setTimeout(function () { app.hideMask(); $elem.removeClass('animated ' + aname); done && done() }, 1000); }) }, renderPictures() { var html = []; this.imgList.forEach(function (item) { html.push(' '); }) if (!html.length) { html.push(' '); } $('.pic-swiper .swiper-wrapper').html(html.join('')); $('.pic-swiper .swiper-wrapper img').click(function () { wx.previewImage({ current: this.src, urls: app.imgList.map(function (item) { return item.url }) }); }); this.picSwiper(); }, showView: function (json) { this.hideLoading() setTimeout(function () { // app.showMask(); // $('.app-view').animateCss('zoomIn', function () { // app.send('close') // }).find('.img').html('