(function() { 'use strict'; angular .module('appMessage') .directive('ngCurrentMsg', CurrentMsg); CurrentMsg.inject = ['$location', '$anchorScroll', '$timeout']; function CurrentMsg($location, $anchorScroll, $timeout) { var directive = { link: link, restrict: 'A', scope: { msg: '=ngCurrentMsg', appContent: '=ngAppContent' } }; return directive; function link(scope, element, attrs) { var gotoBottom = function() { $location.hash("bottom"); $anchorScroll(); }; var extend = function(dest, source) { for (var key in source) { if (source.hasOwnProperty(key)) { dest[key] = source[key]; } } return dest; }; var toColor = function(num) { var color = num.toString(16); while (color.length < 6) { color = '0' + color; } return color; } var replaceSystemFace = function(content) { //匹配表情 var g = (/\/\:([\w]+)/).exec(content); while (g !== null) { scope.appContent.faceConfig.sys.forEach(function(element) { content = content.replace(element.shortcut, ''); }, this); g = (/\/\:([\w]+)/).exec(content); } //匹配截图 var g = (/\[image\-src=\"([\w\W]+?)\"\]/i).exec(content); while (g !== null) { content = content.replace(g[0], function() { var html = '' + '' + ''; loadImg("local://" + scope.appContent.directory.received + g[1] + ".JPG", addImg); function loadImg(url, callback) { var img = new Image(); img.onload = function() { img.onload = null; callback(img); } img.src = url; //img.attr("defaulturl", "../images/img.png"); } function addImg(img) { //$(img).appendTo($(".image")); gotoBottom(); } return html; }); g = (/\[image\-src=\"([\w\W]+?)\"\]/i).exec(content); } //匹配网址 var i = 0; var m = content.match(/(((((http|ftp|https|HTTP|FTP|HTTPS):\/\/)[\w\-_]+)|www|WWW|[0-9]+)(\.(?!gif|jpg|png|mp3)[\w\-_]+)+([\w\-\.,@?^=%:/~\+#]*[\w\-\@?^=%/~\+#\r\n]))/ig); console.log(m); if (m == null) return content; content = content.replace(/(((((http|ftp|https|HTTP|FTP|HTTPS):\/\/)[\w\-_]+)|www|WWW|[0-9]+)(\.(?!gif|jpg|png|mp3)[\w\-_]+)+([\w\-\.,@?^=%:/~\+#]*[\w\-\@?^=%/~\+#\r\n]))/ig, function() { var html = ''; var g = (/((((http|ftp|https|HTTP|FTP|HTTPS):\/\/)[\w\-_]+)(\.[\w\-_]+)+([\w\-\.,@?^=%:/~\+#]*[\w\-\@?^=%/~\+#\r\n]))/ig).exec(m[i]); if (g == null) html = '' + m[i] + ''; else html = '' + m[i] + ''; i = i + 1; return html; }); return content; }; var replaceImage = function(content) {} var html = ''; var message = document.getElementById("message"); // 消息类型([1,文本消息],[2,图片消息],[3,文件消息], [4,位置消息],[5,语音消息]) if (scope.appContent === undefined || scope.appContent.faceConfig === undefined || scope.appContent.faceConfig.sys === undefined) { html = '' + scope.msg.content + ''; } else if (scope.msg.contentType == 1) { //var style = { style: "normal", weight: "normal" }; var style = JSON.parse(scope.msg.style); style = extend({ style: 'normal', weight: 'normal', size: 9, family: '微软雅黑', color: 0 }, style); html = '' + replaceSystemFace(scope.msg.content) + ''; } else if (scope.msg.contentType == 2) { html = '' + '' + '通用的占位符缩略图' + '' + ''; } else if (scope.msg.contentType == 3) { element.css({ width: '275px' }); //element.addClass('file-message'); var reg = /\?[\W\w]*/; var fileName = decodeURIComponent(reg.exec(scope.msg.content).toString().substr(1)); html = '
' + '' + '文件名:' + fileName + '
大小:' + scope.msg.length + '
' + '
' + '打开  ' + '打开文件夹' + '
' + '
'; } else if (scope.msg.contentType == 4) { html = '' + '' + ''; } else if (scope.msg.contentType == 5) { html = '' + '' + ''; } console.log(html); var newElement = angular.element(html); element.append(newElement); // $(function() { // $("img.lazy").lazyload(); // }); message.addEventListener('load', gotoBottom()); } } })();