Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mmc-common.js 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. 'use strict';
  2. var placeholder = '<span class="placeholder">{0}</span>';
  3. function ActiveChatBox(selector) {
  4. $('#main-chat .chat-single-box').removeClass('active');
  5. $(selector).addClass('active');
  6. }
  7. function removeBoxCollapseClass(selector) {
  8. if ($(selector).hasClass('collapsed')) {
  9. $(selector).removeClass('collapsed');
  10. }
  11. }
  12. function messageScroll() {
  13. setTimeout(function () {
  14. if ($('.messages div').length == 0) {
  15. return;
  16. }
  17. $('.message-scrooler').animate({
  18. scrollTop: $('.messages div:last').offset().top
  19. }, 0);
  20. }, 100);
  21. }
  22. function initialTooltip() {
  23. //tooltip
  24. $('[data-toggle="tooltip"]').tooltip({ delay: 50 });
  25. $('[data-toggle="tooltip"]').tooltip({ delay: 50 });
  26. }
  27. function initialTooltipSiderbarUserList() {
  28. $('[data-toggle="tooltip"]').tooltip({ delay: 50 });
  29. }
  30. function deinitialTooltipSiderbarUserList() {
  31. $('[data-toggle="tooltip"]').tooltip('dispose');
  32. }
  33. function stickersTab() {
  34. setTimeout(function () {
  35. $('.stickers ul.tabs').tabs();
  36. $('.stickers ul.tabs').css({ 'height': '55px' });
  37. }, 1);
  38. }
  39. function hideStickerBox() {
  40. $('#main-chat .chat-single-box .icons').removeClass('show');
  41. $('#main-chat .chat-single-box .icons').find('.smiles-set').removeAttr('style');
  42. }
  43. function hideMinimizedBox() {
  44. if ($('#main-chat .boxs .minimized').hasClass('show')) {
  45. $('#main-chat .boxs .minimized').removeClass('show');
  46. $('#main-chat .boxs .minimized').find('.dropdown').removeAttr('style');
  47. }
  48. }
  49. function NewMessage(dataId) {
  50. $('#main-chat .chat-box .boxs .chat-single-box').each(function () {
  51. if ($(this).data('id') == dataId) {
  52. $(this).addClass('new-message');
  53. }
  54. });
  55. }
  56. function generatePlaceholder() {
  57. setTimeout(function () {
  58. $("#main-chat .textarea").each(function () {
  59. $(this).html(placeholder.format($(this).data('placeholder')));
  60. });
  61. }, 10);
  62. }
  63. function sidebarClosed() {
  64. var windowWidth = $(window).width();
  65. if (windowWidth < 1100) {
  66. $('#main-chat').addClass('sidebar-closed');
  67. } else {
  68. $('#main-chat').removeClass('sidebar-closed');
  69. }
  70. }
  71. //string format function -- use 'hello {0}'.format('demo') -> result : 'hello demo'
  72. String.prototype.format = String.prototype.f = function () {
  73. var s = this,
  74. i = arguments.length;
  75. while (i--) {
  76. s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);
  77. }
  78. return s;
  79. };
  80. $(document).on('click', '#main-chat .chat-single-box .smile-ico', function (e) {
  81. e.stopPropagation();
  82. hideMinimizedBox();
  83. _parent = $(this).parents('.icons');
  84. if (_parent.hasClass('show')) {
  85. hideStickerBox(_parent);
  86. } else {
  87. _bottom = parseInt(_parent.css('height').replace('px', ''), 0) + 10;
  88. _source = _parent.data('source');
  89. _parent.find('.smiles-set').html($('.' + _source).html());
  90. _parent.find('.smiles-set').css({
  91. 'bottom': _bottom,
  92. 'display': 'block'
  93. });
  94. _parent.addClass('show');
  95. stickersTab();
  96. }
  97. });
  98. $(document).on('click', '#main-chat .chat-single-box .stickers', function (e) {
  99. e.stopPropagation();
  100. });
  101. $(document).on('click', '#main-chat .preview-image', function () {
  102. preview = '<div class="preview-overlay"><div class="preview-placeholder"><img class="preview-image" src="{0}"/><div class="preview-caption">{1}</div></div></div>';
  103. imgSrc = $(this).attr('src');
  104. caption = $(this).data('caption');
  105. imgWidth = $(this).css('width');
  106. imgHeight = $(this).css('height');
  107. if ($('#main-chat').hasClass('preview-placeholder')) {
  108. return;
  109. }
  110. $('#main-chat').prepend(preview.format(imgSrc, caption));
  111. var origin = $('.preview-placeholder .preview-image');
  112. var windowWidth = window.innerWidth;
  113. var windowHeight = window.innerHeight;
  114. var originalWidth = origin.width();
  115. var originalHeight = origin.height();
  116. var ratio = 0;
  117. var widthPercent = originalWidth / windowWidth;
  118. var heightPercent = originalHeight / windowHeight;
  119. var newWidth = 0;
  120. var newHeight = 0;
  121. if (widthPercent > heightPercent) {
  122. ratio = originalHeight / originalWidth;
  123. newWidth = windowWidth * 0.9;
  124. newHeight = windowWidth * 0.9 * ratio;
  125. }
  126. else {
  127. ratio = originalWidth / originalHeight;
  128. newWidth = (windowHeight * 0.9) * ratio;
  129. newHeight = windowHeight * 0.9;
  130. }
  131. var _left = $(document).scrollLeft() + windowWidth / 2 - origin.parent('.preview-placeholder').offset().left - newWidth / 2;
  132. var _top = $(document).scrollTop() + windowHeight / 2 - origin.parent('.preview-placeholder').offset().top - newHeight / 2;
  133. $('.preview-placeholder').css({
  134. 'max-width': newWidth,
  135. 'width': originalWidth,
  136. 'top': _top
  137. });
  138. $('.preview-caption').css({
  139. 'top': (newHeight )
  140. });
  141. });
  142. $(document).on('click', '#main-chat .preview-overlay:not(".preview-placeholder")', function () {
  143. $('.preview-overlay').remove();
  144. });
  145. $(document).on('click', '#main-chat .chat-single-box .stickers .tab-content li', function () {
  146. _sendMsg = $(this).parents('.chat-footer').find('.send-message div');
  147. //_src = $(this).find('img').attr('src');
  148. _img = $(this).html();
  149. if ($(this).parents('.chat-footer').find('.send-message div').html() == '<span class="placeholder">{0}</span>'.format(_sendMsg.data('placeholder'))) {
  150. _sendMsg.html(_img);
  151. } else {
  152. _str = _sendMsg.html();
  153. //_sendMsg.html(_str + ' ' + '<div class="send-sticker" style="background-image:url({0})"></div>'.format(_src));
  154. _sendMsg.html(_str + ' ' + _img);
  155. }
  156. });
  157. $(document).on('click', '#main-chat #paper-btn', function (e) {
  158. var _box_message = $(this).parents('.chat-single-box').find('.messages');
  159. var text= $($(e.currentTarget).parent().parent().parent()).find(".input-value").val();
  160. _box_message.append('<div class="message out no-avatar media">' +
  161. '<div class="body media-body text-right p-l-50"><div class="content msg-reply f-12 bg-primary d-inline-block">'+ text +'</div><div class="seen"><i class="icon-clock f-12 m-r-5 txt-muted d-inline-block"></i><span><p class="d-inline-block">a few seconds ago </p></span><div class="clear"></div> </div></div>' +
  162. ' <div class="sender media-right friend-box"><a href="javascript:void(0);" title="Me"><img src="assets/images/avatar-1.jpg" class=" img-chat-profile" alt="Me"></a> </div>' +
  163. '</div>');
  164. hideStickerBox();
  165. messageScroll();
  166. $($(e.currentTarget).parent().parent().parent()).find(".input-value").val('');
  167. return false;
  168. });
  169. $(document).on('click',function () {
  170. hideStickerBox();
  171. hideMinimizedBox();
  172. });