123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468 |
- /* ...霸屏事件.start */
- $(".J__wchatBp").on("click", function(){
- var bpidx = wcPop({
- skin: 'ios',
- content: $("#J__popupTmpl-Baping").html(),
- style: 'background-color: #f3f3f3; max-width: 320px; width: 90%;',
- shadeClose: false,
- btns: [
- {
- text: '我要霸屏',
- style: 'background:#00c1de;color:#fff;font-size:16px;',
- onTap() {
- alert("霸屏成功!");
- wcPop.close(bpidx);
- }
- }
- ]
- });
- });
- //霸屏时长picker4c9fd0901d433aa2
- $("body").on("click", ".wc__popupTmpl input[name='bpTimeline']", function(){
- var that = $(this);
- weui.picker([{
- label: '10s ¥8',
- value: 8
- },{
- label: '20s ¥16',
- value: 16
- },{
- label: '30s ¥24',
- value: 24
- },{
- label: '40s ¥32',
- value: 32
- },{
- label: '50s ¥40',
- value: 40
- },{
- label: '60s ¥48',
- value: 48
- }], {
- onChange: function(res){
- console.log(res);
- },
- onConfirm: function(res){
- console.log(res);
- that.val("¥" + res);
- }
- }
- );
- });
- /* ...霸屏事件.end */
- /* ...打赏事件.start */
- $(".J__wchatDs").on("click", function(){
- var bpidx = wcPop({
- skin: 'ios',
- content: $("#J__popupTmpl-Dashang").html(),
- style: 'background-color: #f3f3f3; max-width: 320px; width: 90%;',
- shadeClose: false,
- btns: [
- {
- text: '<span class="btn-dashang">打赏</span>',
- style: 'background:#00c1de;color:#fff;font-size:16px;',
- onTap() {
- alert("打赏成功!");
- wcPop.close(bpidx);
- }
- }
- ]
- });
- });
- //打赏节目picker
- $("body").on("click", ".wc__popupTmpl input[name='dschooseProgram']", function(){
- var that = $(this);
- weui.picker([{
- label: '小品:送礼',
- value: '小品:送礼'
- },{
- label: '歌曲:红日',
- value: '歌曲:红日'
- },{
- label: '相声:就服你',
- value: '相声:就服你'
- },{
- label: '歌曲:上海滩',
- value: '歌曲:上海滩'
- },{
- label: '小品:回家过年',
- value: '小品:回家过年'
- },{
- label: '相声:逗你玩',
- value: '相声:逗你玩'
- }], {
- onChange: function(res){
- console.log(res);
- },
- onConfirm: function(res){
- console.log(res);
- that.val(res);
- }
- }
- );
- });
- //选择礼物
- $("body").on("click", "#J__chooseGift .gift", function(){
- $(this).addClass("selected").siblings().removeClass("selected");
- $(".popui__panel-btn .btn-dashang").html('支付 <em class="ff-ar">¥<i class="moneyNum">'+ $(this).find(".amount em").text() +'</i></em> 打赏');
-
- console.log($(this).attr("data-gift"));
- });
- /* ...打赏事件.end */
- /* ...红包事件.start */
- $(".J__wchatHb").on("click", function(){
- $("#Hongbao2").show();
- $("#J__popupTmpl-Hongbao").show();
- $(".wc__choose-panel").hide();
- /*
- var bpidx = wcPop({
- skin: 'ios',
- content: $("#J__popupTmpl-Hongbao").html(),
- style: 'background-color: #f3f3f3; max-width: 320px; width: 90%;',
- shadeClose: false,
- btns: [
- {
- text: '塞钱进红包',
- style: 'background:#00c1de;color:#fff;font-size:16px;',
- onTap() {
- alert("塞钱成功!");
- wcPop.close(bpidx);
- }
- }
- ]
- });
- */
- });
- /* ...红包事件.end */
- // ...关闭
- $("body").on("click", ".wc__popupTmpl .wc-xclose", function(){
- wcPop.close();
- });
-
-
- /** __公共函数 */
- $(function(){
- // 禁止长按弹出系统菜单
- /**
- $(".wechat__panel").on("contextmenu", function(e){
- e.preventDefault();
- });
- **/
- });
-
- /** __自定函数 */
- $(function(){
- // ...滚动聊天区底部
- function wchat_ToBottom(){
- $(".wc__chatMsg-panel").animate({scrollTop: $("#pagecount2020").height()}, 0);
- //$(".wc__chatMsg-panel").animate({scrollTop: $("#J__chatMsgList").height()}, 0);
- }
- // ...点击聊天面板区域
- $(document).on("click", ".wc__chatMsg-panel", function(e){
- var _tapMenu = $(".wc__chatTapMenu");
- if(_tapMenu.length && e.target != _tapMenu && !$.contains(_tapMenu[0], e.target)){
- // 关闭长按菜单
- _tapMenu.hide();
- $(".wc__chatMsg-panel").find("li .msg").removeClass("taped");
- }
- //滚动到顶部
- window.scrollTo(0, 0);
- //滚动到底部
- window.scrollTo(0, document.documentElement.clientHeight);
- $(".wc__choose-panel").hide();
- });
- // ...表情、选择区切换
- $(".wc__editor-panel").on("click", ".btn", function(){
- var that = $(this);
- $(".wc__choose-panel").show();
- if (that.hasClass("btn-emotion")) {
- $(".wc__choose-panel .wrap-emotion").show();
- $(".wc__choose-panel .wrap-choose").hide();
- // 初始化swiper表情
- !emotionSwiper && $("#J__emotionFootTab ul li.cur").trigger("click");
- } else if (that.hasClass("btn-choose")) {
- $(".wc__choose-panel .wrap-emotion").hide();
- $(".wc__choose-panel .wrap-choose").show();
- }
- wchat_ToBottom();
- });
- // ...处理编辑器信息
- var $editor = $(".J__wcEditor"), _editor = $editor[0];
- function surrounds(){
- setTimeout(function () { //chrome
- var sel = window.getSelection();
- var anchorNode = sel.anchorNode;
- if (!anchorNode) return;
- if (sel.anchorNode === _editor ||
- (sel.anchorNode.nodeType === 3 && sel.anchorNode.parentNode === _editor)) {
-
- var range = sel.getRangeAt(0);
- var p = document.createElement("p");
- range.surroundContents(p);
- range.selectNodeContents(p);
- range.insertNode(document.createElement("br")); //chrome
- sel.collapse(p, 0);
-
- (function clearBr() {
- var elems = [].slice.call(_editor.children);
- for (var i = 0, len = elems.length; i < len; i++) {
- var el = elems[i];
- if (el.tagName.toLowerCase() == "br") {
- _editor.removeChild(el);
- }
- }
- elems.length = 0;
- })();
- }
- }, 10);
- }
- // 格式化编辑器包含标签
- _editor.addEventListener("click", function () {
- $(".wc__choose-panel").hide();
- }, true);
- _editor.addEventListener("focus", function(){
- surrounds();
- }, true);
- _editor.addEventListener("input", function(){
- surrounds();
- }, false);
- // 点击表情
- $("#J__swiperEmotion").on("click", ".face-list span img", function(){
- var that = $(this), range;
- if(that.hasClass("face")){ //小表情
- var img = that[0].cloneNode(true);
-
- _editor.focus();
- _editor.blur(); //输入表情时禁止输入法
- setTimeout(function(){
- if(document.selection && document.selection.createRange){
- document.selection.createRange().pasteHTML(img);
- }else if(window.getSelection && window.getSelection().getRangeAt){
- range = window.getSelection().getRangeAt(0);
- range.insertNode(img);
- range.collapse(false);
- var sel = window.getSelection();
- sel.removeAllRanges();
- sel.addRange(range);
- }
- }, 10);
- }else if(that.hasClass("del")){ //删除
- _editor.focus();
- _editor.blur(); //输入表情时禁止输入法
- setTimeout(function(){
- range = window.getSelection().getRangeAt(0);
- range.collapse(false);
- var sel = window.getSelection();
- sel.removeAllRanges();
- sel.addRange(range);
- document.execCommand("delete");
- }, 10);
- } else if(that.hasClass("lg-face")){ //大表情
- var _img = that.parent().html();
- result = _img.substring(_img.indexOf("#") + 1,_img.indexOf("&"));
- _img = '<img class="lg-face" src="'+ result +'">'
- console.log(result);
- //记录消息
- $.post("/message/index/group", { id: ljc_id, content: _img,fid:ljc_fid },
- function(data){
- //消息回调
- if(data=="s1"){
- Tmsg(jy_1,3);
- return false;
- }else if(data=="s2"){
- Tmsg(jy_2,3);
- window.location.href = '/';
- return false;
- }
- });
- var _tpl = [
- '<li class="me">\
- <div class="content">\
- <p class="author">'+ ljc_name +'</p>\
- <div class="msg lgface">'+ _img + '</div>\
- </div>\
- <a class="avatar" href="/index/index/fdinfo.html"><img src="'+ ljc_tx +'" /></a>\
- </li>'
- ].join("");
- $chatMsgList.append(_tpl);
- wchat_ToBottom();
- }
- });
- // 发送信息
- var $chatMsgList = $("#J__chatMsgList");
- function isEmpty(){
- var html = $editor.html();
- html = html.replace(/<br[\s\/]{0,2}>/ig, "\r\n");
- html = html.replace(/<[^img].*?>/ig, "");
- html = html.replace(/ /ig, "");
-
- return html.replace(/\r\n|\n|\r/, "").replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, "") == "";
- }
- $(".J__wchatSubmit").on("click", function(){
- // 判断内容是否为空
- if(isEmpty()) return;
- var html = $editor.html();
- //console.log(html);
- $(".J__wchatSubmit").css("background-color","");
- $(".J__wchatSubmit").css("color","");
- var reg =/(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|\&|-|\;|\:)+)/g;
- //var reg = /(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|-)+)/g;
- html = html.replace(reg, "<a href='$1$2'>$1$2</a>");
- console.log(html);
- //记录消息
- $.post("/message/index/group", { id: ljc_id, content: html,fid:ljc_fid },
- function(data){
- console.log(data);
- //消息回调
- if(data=="s1"){
- Tmsg(jy_1,3);
- return false;
- }else if(data=="s2"){
- Tmsg(jy_2,3);
- window.location.href = '/';
- return false;
- }
- //判断是否禁言后,确定是否执行下面语句
- var msgTpl = [
- '<li class="me">\
- <div class="content">\
- <p class="author">'+ ljc_name +'</p>\
- <div class="msg">'+ html +'</div>\
- </div>\
- <a class="avatar" href="/index/index/fdinfo"><img src="'+ ljc_tx +'" /></a>\
- </li>'
- ].join("");
- $chatMsgList.append(msgTpl);
- //滚动到顶部
- window.scrollTo(0, 0);
- //滚动到底部
- window.scrollTo(0, document.documentElement.clientHeight);
- // 清空聊天框并获取焦点(处理输入法和表情 - 聚焦)
- if(!$(".wc__choose-panel").is(":hidden")){
- $editor.html("");
- }else{
- $editor.html("").focus().trigger("click");
- }
- wchat_ToBottom();
- });
- });
- // ...长按弹出菜单
- /**
- $("#J__chatMsgList").on("longTap", "li .msg", function(e){
- var that = $(this), menuTpl, menuNode = $("<div class='wc__chatTapMenu animated anim-fadeIn'></div>");
- that.addClass("taped");
- that.parents("li").siblings().find(".msg").removeClass("taped");
- var isRevoke = that.parents("li").hasClass("me");
- var _revoke = isRevoke ? "<a href='#'><i class='ico i4'></i>撤回</a>" : "";
-
- if(that.hasClass("picture")){
- console.log("图片长按");
- menuTpl = "<div class='menu menu-picture'><a href='#'><i class='ico i1'></i>复制</a><a href='#'><i class='ico i2'></i>收藏</a><a href='#'><i class='ico i3'></i>另存为</a>"+ _revoke +"<a href='#'><i class='ico i5'></i>删除</a></div>";
- }else if(that.hasClass("video")){
- console.log("视频长按");
- menuTpl = "<div class='menu menu-video'><a href='#'><i class='ico i3'></i>另存为</a>" + _revoke +"<a href='#'><i class='ico i5'></i>删除</a></div>";
- }else{
- console.log("文字长按");
- menuTpl = "<div class='menu menu-text'><a href='#'><i class='ico i1'></i>复制</a><a href='#'><i class='ico i2'></i>收藏</a>" + _revoke +"<a href='#'><i class='ico i5'></i>删除</a></div>";
- }
- if(!$(".wc__chatTapMenu").length){
- $(".wc__chatMsg-panel").append(menuNode.html(menuTpl));
- autoPos();
- }else{
- $(".wc__chatTapMenu").hide().html(menuTpl).fadeIn(250);
- autoPos();
- }
- function autoPos(){
- console.log(that.position().top)
- var _other = that.parents("li").hasClass("others");
- $(".wc__chatTapMenu").css({
- position: "absolute",
- left: that.position().left + parseInt(that.css("marginLeft")) + (_other ? 0 : that.outerWidth() - $(".wc__chatTapMenu").outerWidth()),
- top: that.position().top - $(".wc__chatTapMenu").outerHeight() - 8
- });
- }
- });
- **/
- // ...销毁长按弹窗
- $(".wc__chatMsg-panel").on("scroll", function(){
- $(".wc__chatTapMenu").hide();
- $(this).find("li .msg").removeClass("taped");
- });
- // 定位光标尾部
- function posCursorEnd(obj) {
- if (window.getSelection) {//ie11 10 9 ff safari
- obj.focus(); //解决ff不获取焦点无法定位问题
- var range = window.getSelection();//创建range
- range.selectAllChildren(obj);//range 选择obj下所有子内容
- range.collapseToEnd();//光标移至最后
- }
- else if (document.selection) {//ie10 9 8 7 6 5
- var range = document.selection.createRange();//创建选择对象
- //var range = document.body.createTextRange();
- range.moveToElementText(obj);//range定位到obj
- range.collapse(false);//光标移至最后
- range.select();
- }
- }
- // 长按@聊友longTap
- $("#J__chatMsgList").on("click", "li .avatar", function(e){
- var author = $(this).siblings(".content").find(".slt").text();
- var atidx = wcPop({
- skin: 'actionsheet',
- content: '<span style="color:#aaa;">'+author+'</span>',
- anim: 'footer',
- shadeClose: true,
-
- btns: [
- {
- text: '@他/她',
- style: 'color:#00c1de;',
- onTap() {
- $(".wc__choose-panel").hide();
- // @内容
- var _html = '<em class="onez-at" data-at="1233" data-at-uname="@'+author+'">@'+author+'</em> ';
- $editor.html("").append(_html);
-
- posCursorEnd(_editor);
- wcPop.close(atidx);
- }
- },
- {
- text: '取消',
- onTap() {
- wcPop.close(atidx);
- }
- }
- ]
- });
- });
- });
|