1function gcNeutralizeHtml(html) { 2 var tpl = document.createElement('template'); 3 tpl.innerHTML = html == null ? '' : String(html); 4 Array.prototype.forEach.call(tpl.content.querySelectorAll('script'), function(el) { el.remove(); }); 5 Array.prototype.forEach.call(tpl.content.querySelectorAll('*'), function(el) { 6 Array.prototype.slice.call(el.attributes).forEach(function(attr) { 7 var name = attr.name.toLowerCase(); 8 var value = (attr.value || '').replace(/\s+/g, '').toLowerCase(); 9 if (name.indexOf('on') === 0 || (/^(href|src|xlink:href)$/.test(name) && value.indexOf('javascript:') === 0 )) { 10 el.removeAttribute(attr.name); 11 } 12 }); 13 }); 14 return tpl.innerHTML; 15} 16 17jQuery.widget( 'gc.conversationWidget', { 18 options: { 19 conversationParams: null, 20 }, 21 _create: function() { 22 this.loadConversation( this.options.conversationParams ); 23 }, 24 loadConversation: function( id ) { 25 var self = this; 26 ajaxCall( "/pl/talks/conversation/get" , this.options.conversationParams, {}, function( response ) { 27 self.element.html( response.data.html ); 28 //var $tree = self.element.find('.comments-tree'); 29 //var $lastComment = $tree.find('.gc-comment:last'); 30 //if ($lastComment) { 31 // var settings = JSON.parse($lastComment.find('.comment-user-settings-json').html()); 32 // var $lastCommentHtml = $lastComment.find('.comment'); 33 // $($tree).trigger('tree:comment:added', [ 34 // $lastCommentHtml.data('id'), 35 // settings.values.object_id, 36 // settings.values.object_type_id, 37 // $lastCommentHtml.data('user-id'), 38 // window.gcIsActiveTab 39 // ]); 40 //} 41 } ) 42 } 43} ); 44 45 46jQuery.widget( 'gc.conversationAnnotate', { 47 options: { 48 conversation: null, 49 proLabel: '' 50 }, 51 isHashToastLoaded: false, 52 _create: function() { 53 this.textEl = this.element.find('.conversation-text') 54 this.textEl.addClass("emoji-text") 55 56 this.freshCommentEl = this.element.find('.conversation-fresh-comment-count') 57 if ( this.options.conversation ) { 58 this.setConversation( this.options.conversation ); 59 } 60 }, 61 setConversation: function( conversation ) { 62 this.element.addClass( 'conversation-' + conversation.id ) 63 64 this.showConversation( conversation ) 65 this.freshCommentEl.html( conversation.fresh_comment_count ) 66 this.freshCommentEl.data('fresh-comment-count', conversation.fresh_comment_count) 67 68 if ( conversation.fresh_comment_count > 0 ) { 69 this.freshCommentEl.show(); 70 } 71 else { 72 this.freshCommentEl.hide(); 73 } 74 75 this.subscribeToConversation( conversation.id ) 76 77 }, 78 showConversation: function( conversation ) { 79 let proLabel = this.options.proLabel; 80 81 this.element.find('.conversation-img').html( conversation.image ) 82 this.element.find('.conversation-title').html(conversation.title + " " + proLabel) 83 this.element.find('.conversation-object-title').html( conversation.object_title ) 84 85 var onlineEl = this.element.find('.conversation-user-is-online'); 86 if ( onlineEl.length > 0 ){ 87 if ( conversation.main_user_is_online ) { 88 onlineEl.addClass('is-online'); 89 onlineEl.removeClass('is-offline'); 90 } 91 else { 92 onlineEl.addClass('is-offline'); 93 onlineEl.removeClass('is-online'); 94 } 95 } 96 97 this.element.find('.conversation-time').html( conversation.last_comment_at_str ) 98 99 this.showConversationText( 100 conversation.text, 101 conversation.last_comment_user_id, 102 conversation.last_comment_user_name, 103 conversation.last_comment_viewed 104 ); 105 }, 106 showConversationText: function( text, userId, userName, lastCommentViewed ) { 107 var conversationText = text; 108 109 var labelReaded = 'ÐÑоÑиÑано'; 110 var labelYou = 'ÐÑ'; 111 if (typeof Yii != 'undefined') { 112 labelReaded = Yii.t('common', labelReaded); 113 labelYou = Yii.t('common', labelYou); 114 } 115 116 var prefix = ""; 117 if ( userId == window.accountUserId ) { 118 prefix = "<span>" + labelYou + ": </span> "; 119 } 120 else { 121 var conversationTitle = this.element.find('.conversation-title').html() 122 if( userName != conversationTitle ) { 123 prefix = "<span>
123" + userName + ": </span> "; 124 } 125 } 126 127 this.textEl.html(prefix + $.emoji(gcNeutralizeHtml(conversationText) /*+ (lastCommentViewed ? '<br/>ÐÑоÑиÑано' : '') */ )) 128 }, 129 subscribeToConversation: function( conversation_id ) { 130 131 if ( window.conversationSubscribes && window.conversationSubscribes[ conversation_id ] ) { 132 return; 133 } 134 if ( ! window.accountUserWebSocketConnection ) { 135 return; 136 } 137 138 var self = this; 139 const subscribeFunction = (append = '', callbackFn = null, callbackParam = null) => { 140 var channel = "conversation_change_" + conversation_id + append; 141 window.accountUserWebSocketConnection.subscribeChannel( channel, 142 function(message, json){ 143 144 var $block = $('.conversation-' + json.conversation_id ) 145 if ( json.action == "new_comment" ) { 146 if ( json.comment.user_id == window.accountUserId ) { 147 self.updateFreshCommentCount( $block, 'set', 0 ) 148 } 149 else { 150 self.updateFreshCommentCount( $block, 'inc', 1 ) 151 } 152 153 self.showConversationText( json.comment.text, json.comment.user_id, json.comment.user_name ) 154 $(self.element).trigger('comment:added', []); 155 } 156 if ( json.action == "viewed" ) { 157 if ( json.user_id == window.accountUserId ) { 158 self.updateFreshCommentCount( $block, 'set', 0 ) 159 } 160 } 161 } 162 ); 163 164 if ( ! window.conversationSubscribes ) { 165 window.conversationSubscribes = {}; 166 } 167 window.conversationSubscribes[conversation_id] = 1; 168 if (callbackFn) { 169 callbackFn(callbackParam); 170 } 171 }; 172 173 ajaxCall('/pl/user/user/get-ws-hash', {id: conversation_id}, {}, (wsResponse) => { 174 let wsConversationHash = wsResponse.data.result.hash; 175 let wsConversationUntil = parseInt(wsResponse.data.result.seconds_left); 176 let isConversationDynamicHashEnabled = !!wsResponse.data.isConversationDynamicHashEnabled; 177 if (isConversationDynamicHashEnabled) { 178 let callbackFn = (secondsLeft) => { 179 setTimeout(() => { 180 $.toast( 181 Yii.t('apps.users', 'СÑÑаниÑа ÑÑÑаÑела, обновиÑе пожалÑйÑÑа.'), 182 {type: 'danger'} 183 ); 184 }, secondsLeft * 1000); 185 }; 186 subscribeFunction( 187 '_' + window.accountId + wsConversationHash, 188 callbackFn, 189 wsConversationUntil 190 ); 191 } else { 192 subscribeFunction(); 193 } 194 }); 195 }, 196 197 updateFreshCommentCount: function( $container, mode, value ) { 198 199 var $freshCommentCountBlock = $container.find( '.conversation-fresh-comment-count' ) 200 var freshCommentCount = $freshCommentCountBlock.data('fresh-comment-count' ) 201 if ( mode == 'inc' ) { 202 freshCommentCount += value; 203 } 204 else { 205 freshCommentCount = value; 206 } 207 208 $freshCommentCountBlock.data('fresh-comment-count', freshCommentCount ) 209 $freshCommentCountBlock.html( freshCommentCount ) 210 211 if ( freshCommentCount > 0 ) { 212 $freshCommentCountBlock.show(); 213 } 214 else { 215 $freshCommentCountBlock.hide(); 216 } 217 218 } 219} );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.