123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- (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, '<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], function() {
- var html = '<a href="#" class="thumbnail"' + '>' +
- '<img style="max-width:270px;max-height:250px;" src="local://' + scope.appContent.directory.received + g[1] + '.JPG' + '" alt="" >' +
- '</a>';
- 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 = '<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;
- };
- 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 = '<span class="text-message">' + scope.msg.content + '</span>';
- } 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 = '<span class="text-message"' + ' style="font:' + style.style + ' ' + style.weight + ' ' + style.size + 'pt' + ' ' + style.family + ';color:#' + toColor(style.color) + '">' +
- 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: '275px'
- });
- //element.addClass('file-message');
- var reg = /\?[\W\w]*/;
- var fileName = decodeURIComponent(reg.exec(scope.msg.content).toString().substr(1));
- html = '<div class="file-message">' +
- '<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>';
- }
- console.log(html);
- var newElement = angular.element(html);
- element.append(newElement);
- // $(function() {
- // $("img.lazy").lazyload();
- // });
- message.addEventListener('load', gotoBottom());
- }
- }
- })();
|