var ewave = { 'copy': { 'init': function () { $(".ewave-copy-link").each(function () { var $that = $(this); var links = $that.attr("data-url"); ewave.copy.set(this, links); }); $(".ewave-copy").each(function () { var $that = $(this); var text = $that.attr("data-text"); ewave.copy.set(this, text); }); $(".ewave-copy-html").each(function () { var $that = $(this); var html = $that.parent().find(".content").html(); ewave.copy.set(this, html); }); }, 'set': function (id, content) { var clipboard = new clipboardjs(id, { text: function () { return content; } }); clipboard.on('success', function (e) { layer.msg('复制成功'); }); clipboard.on("error", function (e) { ewave.layer.error('复制失败,请手动复制'); }); } }, 'fav': function (u, s) { try { window.external.addfavorite(u, s); } catch (e) { try { window.sidebar.addpanel(s, u, ""); } catch (e) { ewave.layer.error('加入收藏出错,请使用键盘ctrl+d进行添加'); } } }, 'ajax': function (url, type, datatype, data, sfun, efun, bfun, cfun) { type = type || 'get'; datatype = datatype || 'json'; data = data || ''; efun = efun || ''; bfun = bfun || ''; cfun = cfun || ''; $.ajax({ url: url, type: type, datatype: datatype, data: data, timeout: 5000, beforesend: function () { if (bfun) bfun(); }, error: function (xhr, textstatus, errorthrown) { if (efun) efun(xhr, textstatus, errorthrown); }, success: function (data) { sfun(data); }, complete: function (xhr, ts) { if (cfun) cfun(xhr, ts); } }) }, 'layer': { 'error': function (text, time) { time = time || ''; layer.msg(text, { time: time ? time : 1500, anim: 6, }); }, 'img': function (title, src, text) { layer.open({ type: 1, title: title, skin: 'layui-layer-rim', content: '
' + text + '
' }); }, 'html': function (title, html, end_fun) { end_fun = end_fun || ''; layer.open({ type: 1, closebtn: 2, title: title, skin: 'layui-layer-rim', content: html, success: function (layero, index) { if (end_fun) end_fun(); } }); }, 'div': function (id) { layer.open({ type: 1, title: false, skin: 'layui-layer-rim', content: $(id) }); }, 'notice': function (name, title, html, day, wide, high) { var noticed = mac.cookie.get(name); var html = $(html).html(); if (!noticed) { layer.open({ type: 1, title: title, skin: 'layui-layer-rim', content: html, area: [wide + 'px', high + 'px'], cancel: function () { mac.cookie.set(name, 1, day); } }); } } }, 'image': { 'init': function () { ewave.image.lazyload.show(); ewave.image.verify.init(); ewave.image.qrcode.init(); }, 'lazyload': { 'show': function () { $(".lazyload").lazyload({ threshold: 200, failurelimit: 50, skip_invisible: false }); }, 'box': function ($id) { $($id).find(".lazyload").lazyload({ threshold: 200, failurelimit: 50, skip_invisible: false }); } }, 'verify': { 'init': function () { $("body").on('click', '.ewave-verify-img', function () { ewave.image.verify.refresh($(this)); }); }, 'refresh': function (obj) { obj.attr('src', maccms.path + '/index.php/verify/index.html?r=' + math.random()); } }, 'qrcode': { 'init': function () { $('.ewave-qrcode').each(function () { var $that = $(this); $that.qrcode({ text: $that.attr("data-url") || location.href, //设置二维码内容,必须 render: "canvas", //设置渲染方式 (有两种方式 table和canvas,默认是canvas) width: $that.attr("data-width") || 120, //设置宽度 height: $that.attr("data-height") || 120, //设置高度 typenumber: -1, //计算模式 correctlevel: 0, //纠错等级 background: "#ffffff", //背景颜色 foreground: "#000000" //前景颜色 }); }); } }, }, 'swiper': { 'init': function () { if ($('.ewave-swiper').length == 0) { return false; } if ($('.ewave-swiper-nav').length) { var navswiper = new array(); $('.ewave-swiper-nav').each(function (index) { var $that = $(this); var $index = index; if ($that.find(".swiper-slide").length) { navswiper.push = new swiper($that.get(0), { freemode: true, slidesperview: 'auto', roundlengths: true, lazy: { loadprevnext: true, loadprevnextamount: 8, }, navigation: { nextel: '.swiper-button-next', prevel: '.swiper-button-prev', }, on: { 'init': function () { if (this.$el.find(".active").length) { this.slideto(this.$el.find(".active").index() - 2); } }, 'slidechangetransitionend': function () { if (this.$el.find(".active").length) { this.translateto(this.translate - $(this.slides).eq(this.$el.find(".active").index() - 2).outerwidth(true) / 2, 300, this.off('slidechangetransitionend'), true); } } } }); } }); } if ($('.ewave-swiper-image').length) { var imageswiper = new array(); $('.ewave-swiper-image').each(function () { var $that = $(this); if ($that.find(".swiper-slide").length) { imageswiper.push = new swiper($that.get(0), { initialslide: $that.find(".active").index(), lazy: { elementclass: $that.attr("data-lazy-class") || 'swiper-lazy', loadprevnext: true, loadprevnextamount: 8, }, loop: $that.attr("data-loop") == 'false' ? false : true, centeredslides: $that.attr("data-center") == 'false' ? false : true, centeredslidesbounds: true, autoplay: { disableoninteraction: false, pauseonmouseenter: true, }, effect: $that.attr("data-effect") || 'slide', fadeeffect: { crossfade: true, }, slidesperview: 'auto', pagination: { el: $that.attr("data-pagination") || '.swiper-pagination', clickable: true, bulletclass: $that.attr("data-pagination-class") || 'swiper-pagination-bullet', bulletactiveclass: $that.attr("data-pagination-active-class") || 'swiper-pagination-bullet-active', renderbullet: function (index, classname) { if ($that.find(".swiper-pagination-html").length) { return '' + $(this.slides).eq(index).find(".swiper-pagination-html").html() + ''; } else { return ''; } }, }, navigation: { nextel: '.swiper-button-next', prevel: '.swiper-button-prev', }, }); } }); } } }, 'star': { 'static': 0, //判断页面是否为静态 'obj': '.ewave-star', 'init': function () { if ($(ewave.star.obj).length == 0) { return; } if (ewave.star.static == 0) { ewave.star.view(); } else { ewave.star.get(); } }, 'get': function () { mac.ajax(maccms.path + '/index.php/ajax/score?mid=' + $(ewave.star.obj).attr('data-mid') + '&id=' + $(ewave.star.obj).attr('data-id'), 'get', 'json', '', function (e) { $(ewave.star.obj).attr({ 'score': e.data.score, 'data-star': math.ceil(e.data.score / 2), 'data-score-num': e.data.score_num }); $(".ewave-star-num").text(e.data.score); $(".ewave-star-count").text(e.data.score_num); ewave.star.view(); }); }, 'view': function () { $(ewave.star.obj).raty({ startype: 'li', number: 5, numbermax: 5, space: false, score: function () { $(".ewave-star-num").text($(ewave.star.obj).attr('score')); return $(ewave.star.obj).attr('data-star'); }, hints: ['很差', '较差', '还行', '推荐', '力荐'], staroff: 'ewave-star-item fa fa-star-o', staron: 'ewave-star-item fa fa-star', target: $(".ewave-star-text"), targetkeep: $(ewave.star.obj).attr('data-score-num') > 0 ? true : false, targettext: '暂无', click: function (score, evt) { mac.ajax(maccms.path + '/index.php/ajax/score?mid=' + $(ewave.star.obj).attr('data-mid') + '&id=' + $(ewave.star.obj).attr('data-id') + '&score=' + (score * 2), 'get', 'json', '', function (r) { if (r.code == 1) { $(ewave.star.obj).attr({ 'score': r.data.score, 'data-star': math.ceil(r.data.score / 2), 'data-score-num': r.data.score_num }); $(".ewave-star-num").text(r.data.score); $(".ewave-star-count").text(r.data.score_num); $(ewave.star.obj).raty('set', { 'score': math.ceil(r.data.score / 2), }); layer.msg('评分成功'); } else { $(ewave.star.obj).raty('score', $(ewave.star.obj).attr('data-star')); layer.msg(r.msg); } }, function () { $(ewave.star.obj).raty('score', $(ewave.star.obj).attr('data-star')); layer.msg('网络异常'); }); } }); } }, 'digg': { 'init': function () { $('body').on('click', '.ewave-digg,.ewave-digg-link', function (e) { var $that = $(this); if ($that.attr("data-id")) { mac.ajax(maccms.path + '/index.php/ajax/digg.html?mid=' + $that.attr("data-mid") + '&id=' + $that.attr("data-id") + '&type=' + $that.attr("data-type"), 'get', 'json', '', function (r) { if (r.code == 1) { $that.addclass("active"); if ($that.attr("data-type") == 'up') { $that.find('.ewave-digg-num').html(r.data.up); } else { $that.find('.ewave-digg-num').html(r.data.down); } } else { ewave.layer.error(r.msg); } }, function () { ewave.layer.error('网络出错,,请稍后重试'); }); } }); } }, 'player': { 'offset': 0, 'init': function () { if ($(".ewave-player").length == 0) { return false; } if ($(".ewave-player-fixed").length) { ewave.player.offset = $(".ewave-player-fixed").offset().top + $(".ewave-player-fixed").height(); ewave.player.fixed(); $(window).resize(function () { ewave.player.offset = $(".ewave-player-fixed").offset().top + $(".ewave-player-fixed").height(); ewave.player.fixed(); }); $(window).scroll(ewave.player.fixed); } if ($(".ewave-player-full").length) { ewave.player.full(); } }, 'fixed': function () { if ($(window).scrolltop() >= ewave.player.offset) { $(".ewave-player-fixed").addclass("active"); } else { $(".ewave-player-fixed").removeclass("active"); } $('body').on('click', '.ewave-player-fixed-close', function () { $(".ewave-player-fixed").removeclass("active ewave-player-fixed"); }); }, 'full': function () { $('.ewave-player-full-toggle').click(function () { $('.ewave-player-full').toggleclass("active"); ewave.player.offset = $(".ewave-player-fixed").offset().top + $(".ewave-player-fixed").height(); }); } }, 'xunlei': { 'init': function () { if ($(".ewave-downlist-tools").length) { $(".ewave-downlist-tools .ewave-downlist-copyall").click(function (e) { e.preventdefault(); if (mac.checkbox.count($(this).attr("data-target")) == 0) { ewave.layer.error("请至少选择一个数据"); return false; } var copylist = new array; $(".ewave-downlist-checkbox[name='" + $(this).attr("data-target") + "']").each(function () { if (this.checked) { copylist.push(this.value); } }); ewave.copy.set(".ewave-downlist-copyall", copylist.join('\n\r')); }); } if ($(".ewave-xunlei-item").length) { ewave.ajax('//open.thunderurl.com/thunder-link.js', 'get', 'script', '', function () { $(".ewave-downlist-btns .ewave-downlist-download").click(function () { thunderlink.newtask({ tasks: [{ url: $(this).attr("data-url") }] }); }); $(".ewave-downlist-tools .ewave-downlist-download").click(function () { if (mac.checkbox.count($(this).attr("data-target")) == 0) { ewave.layer.error("请至少选择一个数据"); return false; } var downlist = new array; $(".ewave-downlist-checkbox[name='" + $(this).attr("data-target") + "']").each(function () { if (this.checked) { downlist.push('{url:"' + this.value + '"}'); } }); var downlist_str = '[' + downlist.join(',') + ']' thunderlink.newtask({ tasks: eval(downlist_str) }); }); }, function () { console.log('加载迅雷组件出错'); }); $(".ewave-downlist-url input").click(function () { $(this).select(); }); } } }, 'countdown': { 'init': function () { if ($(".ewave-countdown").length == 0) { return false; } $(".ewave-countdown").each(function () { var $that = $(this); ewave.countdown.jump($that); }); }, 'jump': function (obj) { var $that = obj; var countdown = $that.attr('data-time') ? $that.attr('data-time') : $that.text(); ewave.countdown.run($that, countdown, function () { if ($that.attr("data-time")) { $that.attr("data-time", countdown--); } $that.text(countdown--); ewave.check.jump($that); }, function () { if ($that.attr("data-time")) { $that.attr("data-time", countdown--); } $that.text(countdown--); }); }, 'run': function (obj, time, end_fun, loop_fun) { end_fun = end_fun || ''; loop_fun = loop_fun || ''; if (time <= 0) { if (end_fun) end_fun(); return true; } else { if (loop_fun) loop_fun(); } time--; settimeout(function () { ewave.countdown.run(obj, time, end_fun, loop_fun); }, 1000); } }, 'check': { 'form': function (obj, callback) { var $that = obj; var form_config = {}; form_config.action = $that.attr('data-action') || $that.attr('action'); if ($that.parents("form").length && (form_config.action == '' || form_config.action == undefined)) { form_config.action = $that.parents("form").eq(0).attr('data-action') || $that.parents("form").eq(0).attr('action'); } if (form_config.action == '' || form_config.action == undefined) { ewave.layer.error('表单未配置action项'); return false; } form_config.method = $that.attr('data-method') || $that.attr('method') || 'post'; form_config.type = $that.attr('data-type') || 'json'; if ($that.hasclass("ewave-form")) { var empty_input = 0; $that.find("input,textarea,select").each(function () { if ($(this).val() == '' && !$(this).hasclass("empty-allowed")) { empty_input++; if ($(this).parents(".form-group").length) { $(this).focus().parents(".form-group").addclass("has-error"); } else { $(this).focus().parent().addclass("has-error"); } if ($(this).attr("data-tip")) { ewave.layer.error($(this).attr("data-tip")); return false; } else if ($(this).attr("data-label")) { ewave.layer.error("请输入" + $(this).attr("data-label")); return false; } else if ($(this).attr("placeholder")) { ewave.layer.error($(this).attr("placeholder")); return false; } else { ewave.layer.error("请输入必填项目" + $(this).attr("name")); return false; } } }); if (empty_input > 0) return false; } if ($that.hasclass("ewave-send-code")) { var ac = $that.parents("form").find('input[name="ac"]').val(); var to = $that.parents("form").find('.ewave-to').val(); if (ac == 'email') { var pattern = /^([a-za-z0-9]+[_|\_|\.]?)*[a-za-z0-9]+@([a-za-z0-9]+[_|\_|\.]?)*[a-za-z0-9]+\.[a-za-z]{2,3}$/; var ex = pattern.test(to); if (!ex) { ewave.layer.error('邮箱格式不正确'); return false; } } else if (ac == 'phone') { var pattern = /^[1][0-9]{10}$/; var ex = pattern.test(to); if (!ex) { ewave.layer.error('手机号格式不正确'); return false; } } else { ewave.layer.error('ac参数错误'); return false; } } if ($that.hasclass("ewave-confirm")) { if (!$that.attr("data-tip")) { ewave.layer.error('表单data-tip项未配置'); return false; } } callback(form_config); }, 'jump': function (obj, data) { var $that = obj; var r = data || ''; var refresh; if (self != top) { refresh = top.location; } else { refresh = location; } if (!$that.attr("data-jump")) { settimeout(function () { refresh.reload(); }, 1000); } else if ($that.attr("data-jump") == 'refresh') { refresh.reload(); } else if ($that.attr("data-jump") == 'refresh-wait') { settimeout(function () { refresh.reload(); }, 1000); } else if ($that.attr("data-jump") == 'function') { let jump_func = new function('return ' + $that.attr("data-function")); jump_func(); } else if ($that.attr("data-jump") == 'stop') { return false; } else if ($that.attr("data-jump") == 'switch-to-login') { $(".ewave-login-switch").click(); } else if ($that.attr("data-jump") == 'switch-to-reg') { $(".ewave-reg-switch").click(); } else if ($that.attr("data-jump").indexof('?order_code=') > -1) { refresh.href = $that.attr("data-jump") + r.data.order_code; } else if ($that.attr("data-jump")) { refresh.href = $that.attr("data-jump"); } }, }, 'form': { 'init': function () { $("body").on('input propertychange', '.ewave-form input,.ewave-form textarea,.ewave-form select', function () { $(".has-success,.has-warning,.has-error").removeclass("has-success has-warning has-error"); }); $("body").on('submit', '.ewave-form', function (event) { event.preventdefault(); ewave.form.submit($(this)); }); $("body").on('click', '.ewave-send-code', function (event) { event.preventdefault(); ewave.form.sendcode($(this)); }); $("body").on('click', '.ewave-confirm', function (event) { event.preventdefault(); ewave.form.confirm($(this)); }); $("body").on('click', '.member-delete,.member-delete-one,.member-clear', function () { if (!$(this).hasclass("member-delete-one") && parseint($(this).attr("data-all")) == 0 && mac.checkbox.ids('ids[]') == '') { ewave.layer.error("请至少选择一个数据"); return false; } var mydata = { type: $(this).parents("form").eq("0").find("input[name='type']").val(), all: parseint($(this).attr("data-all")), ids: $(this).hasclass("member-delete-one") ? $(this).attr("data-id") : mac.checkbox.ids('ids[]'), }; ewave.form.confirm($(this), mydata); }); }, 'submit': function (obj) { var $that = obj; ewave.check.form($that, function (data) { ewave.ajax(data.action, data.method, data.type, $that.serialize(), function (r) { layer.closeall('loading'); if (r.code == 1) { layer.msg(r.msg); ewave.check.jump($that, r); } else { ewave.layer.error(r.msg); ewave.image.verify.refresh($that.find(".ewave-verify-img")); } }, function (xhr, textstatus, errorthrown) { layer.closeall('loading'); ewave.layer.error('提交失败,请稍后重试'); console.log(xhr.responsetext); }, function () { layer.load(); settimeout(function () { layer.closeall('loading'); }, 5000); }); }); }, 'confirm': function (obj, config) { var $that = obj; var confirm_data = config || $that.attr("data-data"); ewave.check.form($that, function (data) { layer.confirm($that.attr("data-tip"), function () { ewave.ajax(data.action, data.method, data.type, confirm_data, function (r) { if (r.code == 1) { layer.msg(r.msg); ewave.check.jump($that, r); } else { ewave.layer.error(r.msg); } }, function () { ewave.layer.error('操作失败,请稍候重试'); }); }, function () { }); }); }, 'sendcode': function (obj) { var $that = obj; ewave.check.form($that, function (data) { ewave.ajax(data.action, data.method, data.type, $that.parents("form").eq(0).serialize(), function (r) { layer.closeall('loading'); if (r.code == 1) { layer.msg(r.msg); var countdown = 60; ewave.countdown.run($that, countdown, function () { $that.val("获取验证码").removeattr("disabled"); }, function () { $that.prop("disabled", true).val("重新发送(" + countdown + ")"); countdown--; }); } else { ewave.layer.error(r.msg); } }, function (r) { layer.closeall('loading'); ewave.layer.error('发送失败,请稍候重试'); }, function () { layer.load(); settimeout(function () { layer.closeall('loading'); }, 5000); }); }); }, }, 'gbook': { 'login': 0, 'init': function () { if ($(".ewave-gbook-remaining").length) { $('body').on('keyup', '.ewave-gbook-content', function (e) { mac.remaining($(this), 200, '.ewave-gbook-remaining') }); } $('body').on('focus', '.ewave-gbook-content', function (e) { if (ewave.gbook.login == 1 && ewave.user.islogin != 1) { $(".ewave-gbook-content").blur(); ewave.user.login(); } }); $('body').on('click', '.ewave-gbook-report', function () { if ($(this).attr("data-id")) { if (ewave.gbook.login == 1 && ewave.user.islogin != 1) { $(".ewave-gbook-content").blur(); ewave.user.login(); } else { ewave.gbook.report('编号【' + $(this).attr("data-id") + '】 名称【' + $(this).attr("data-name") + '】 页面地址' + location.href + ' 此视频不能正常观看请检查修复', $(this).attr("data-id")); } } }); }, 'report': function (name, id) { mac.ajax(maccms.path + '/index.php/gbook/report.html?id=' + id + '&name=' + encodeuricomponent(name), 'post', 'json', '', function (r) { ewave.layer.html('数据报错', r, function () { $(".ewave-gbook-content").focus(); ewave.image.verify.refresh($(".ewave-verify-img-report")); }); }, function (xhr, textstatus, errorthrown) { ewave.layer.html('数据报错', xhr.responsetext, function () { $(".ewave-gbook-content").focus(); ewave.image.verify.refresh($(".ewave-verify-img-report")); }); }); } }, 'history': { 'boxshow': 0, 'limit': 10, 'days': 7, 'json': '', 'init': function () { if ($('.ewave-history').length == 0) { return false; } $("body").on('click', '.ewave-history-clear', function () { ewave.history.clear(); }); var jsondata = []; if (this.json) { jsondata = this.json; } else { var jsonstr = mac.cookie.get('ewave_history'); if (jsonstr != undefined) { jsondata = eval(jsonstr); } } var history_html = '