123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- (function() {
- 'use strict';
- angular
- .module('appMessage')
- .directive('ngHistoryMsg', HistoryMsg);
- HistoryMsg.inject = [];
- function HistoryMsg() {
- var directive = {
- link: link,
- restrict: 'A',
- scope: {
- msg: '=ngHistoryMsg',
- appContent: '=ngAppContent'
- }
- };
- return directive;
- function link(scope, element, attrs) {
- var replaceSystemFace = function(content) {
- //匹配表情
- var g = (/\/\:([\w]+)/).exec(content);
- while (g !== null) {
- scope.appContent.faceConfig.sys.forEach(function(element) {
- content = content.replace(element.shortcut, '<img style="height:56px" src="local://' + scope.appContent.directory.base + element.image + '">');
- }, this);
- g = (/\/\:([\w]+)/).exec(content);
- }
- //匹配截图
- var g = (/\[image\-src=\"([\w\W]+?)\"\]/i).exec(content);
- while (g !== null) {
- content = content.replace(g[0],
- '<a href="#" class="thumbnail"' + '>' +
- '<img class="lazy" style="max-width:270px;max-height:250px;" src="../img/loading.jpg" data-original="local://' + scope.appContent.directory.received + g[1] + '.JPG' + '" alt="" >' +
- '</a>'
- );
- 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 = '<a target="_blank" href="http://' + m[i] + '">' +
- m[i] +
- '</a>';
- else
- html = '<a target="_blank" href="' + m[i] + '">' +
- m[i] +
- '</a>';
- i = i + 1;
- return html;
- });
- return content;
- };
- if (scope.msg.senderDisplayName === undefined || scope.msg.senderDisplayName == '')
- scope.msg.senderDisplayName = scope.msg.sender;
- var html = '';
- // 消息类型([1,文本消息],[2,图片消息],[3,文件消息], [4,位置消息],[5,语音消息])
- if (scope.appContent === undefined || scope.appContent.faceConfig === undefined || scope.appContent.faceConfig.sys === undefined) {
- html = '<span class="text-message">' + scope.msg.content + '</span>';
- } else if (scope.msg.contentType == 1) {
- //var style = { style: "normal", weight: "normal" };
- var style = scope.msg.style;
- html = '<span class="text-message"' + ' style="font:' + style.style + ' ' + style.weight + ' ' + style.size + 'pt' + ' ' + style.family + ';color:#' + style.color.toString(16) + '">' +
- replaceSystemFace(scope.msg.content) + '</span>';
- } else if (scope.msg.contentType == 2) {
- html = '<span class="text-message">' +
- '<a href="#" class="thumbnail" >' +
- '<img src="' + scope.msg.content + '" alt="通用的占位符缩略图" >' +
- '</a>' +
- '</span>';
- } else if (scope.msg.contentType == 3) {
- // element.css({
- // width: '300px'
- // });
- //element.addClass('file-message');
- var reg = /\?[\W\w]*/;
- var fileName = decodeURIComponent(reg.exec(scope.msg.content).toString().substr(1));
- html = '<div class="file-message" style="width:250px">' +
- '<img src="../img/unkown.png" onError= "this.src = \'../img/file/unkown.png\'">' +
- '<span style="float:left; margin:5px 0px 0px 0px">文件名:' + fileName + '<br/>大小:' + scope.msg.length + '</span>' +
- '<div class="p-t-sm text-right">' +
- '<a class="text-primary" role="button"><span>打开</span></a>  ' +
- '<a class="text-primary" role="button"><span>打开文件夹</span></a>' +
- '</div>' +
- '</div>';
- } else if (scope.msg.contentType == 4) {
- html = '<span class="text-message">' +
- '<iframe class="map" border=0 src="' + scope.msg.content + '" frameBorder=no></iframe>' +
- '</span>';
- } else if (scope.msg.contentType == 5) {
- html = '<span class="text-message">' +
- '<audio src="' + scope.msg.content + '" controls="controls">' +
- '</audio>' +
- '</span>';
- }
- var html_g = '<div class="feed-element">' +
- '<div class="media-body" id="loadmore">' +
- '<p><strong>' +
- scope.msg.senderDisplayName +
- '</strong><small class="text-muted">-2017-2-6 15:57:17 ' +
- scope.msg.ts + '</small></p>' +
- '<div class="well m-l-xs m-t-xs fit-content" >' +
- '<div class="text-point"></div>' + html +
- '</div></div></div>';
- angular.element("#loadmore").prepend(html_g);
- $(function() {
- $("img.lazy").lazyload();
- });
- console.log(html_g);
- }
- }
- })();
|