1Notifications = { 2 subscribe: [], 3 add: function(data) { 4 if (!$('#notificationsTemplate').length) { 5 try { 6 loadCustomTemplates(); 7 } catch (error) { 8 console.log(error); 9 } 10 } 11 12 var notificationsTemplate = _.template( $('#notificationsTemplate').html() ), 13 notificationsChatTemplate = _.template( $('#notificationsChatTemplate').html() ), 14 notificationsHeaderTemplate = _.template( $('#notificationsHeaderTemplate').html() ), 15 resultHtml = '', 16 wrapper = $('#notifications'); 17 18 if (data.subtype === 'chat_new_message' || 19 data.subtype === 'chat_message_delete' || 20 data.subtype === 'chat_room_close' || 21 data.subtype === 'chat_message_like' || 22 data.subtype === 'chat_message_answer' || 23 data.subtype === 'chat_verify_message') { 24 resultHtml += notificationsChatTemplate({ data: data }); 25 } else { 26 resultHtml += notificationsTemplate({ data: data }); 27 } 28 29 if (!$('.notifications__header').length) { 30 wrapper.append( notificationsHeaderTemplate({}).trim() ); 31 } 32 33 wrapper.prepend( resultHtml.trim() ); 34 35 new Audio('/i/open-ended.mp3').play(); 36 }, 37 getSubscribe: function() { 38 return $.ajax({ 39 url: '/services/notification/subscribe/get_comet/' 40 }) 41 }, 42 setChatRoom: function(room_id, active) { 43 $.ajax({ 44 url: '/services/notification/subscribe/set_comet_chat_room/', 45 data: { 46 room_id: room_id, 47 active: active 48 } 49 }).done(function() { 50 var item = Notifications.subscribe.filter(function(item) { 51 return item.type === 'chat_room' && +item.room_id === +room_id; 52 })[0]; 53 54 if (item) { 55 item.is_active = active 56 } else { 57 Notifications.subscribe.push({ 58 type: 'chat_room', 59 room_id: room_id, 60 is_active: active 61 }) 62 } 63 }) 64 }, 65 setAllChats: function(active) { 66 $.ajax({ 67 url: '/services/notification/subscribe/set_comet_allchats/', 68 data: { 69 active: active 70 } 71 }).done(function() { 72 var item = Notifications.subscribe.filter(function(item) { 73 return item.type === 'all_chats'; 74 })[0]; 75 76 if (item) { 77 item.is_active = active 78 } else { 79 Notifications.subscribe.push({ 80 type: 'all_chats', 81 is_active: active 82 }) 83 } 84 }) 85 }, 86 setAllMail: function(active) { 87 return $.ajax({ 88 url: '/services/notification/subscribe/set_mail_all/', 89 data: { 90 active: active 91 } 92 }) 93 }, 94 isRoomDisabled: function(room_id) { 95 var result = Notifications.isAllChatsDisabled(); 96 var room = Notifications.subscribe.filter(function(item) { 97 return item.type === 'chat_room' && +item.room_id === +room_id; 98 }) 99 100 if (room.length && room[0].is_active === 1) { 101 // РкомнаÑе вклÑÑÐµÐ½Ñ ÑÐ²ÐµÐ´Ð¾Ð¼Ð»ÐµÐ½Ð¸Ñ 102 result = false;
103 } else if (room.length && room[0].is_active === 0) { 104 // РкомнаÑе вÑклÑÑÐµÐ½Ñ ÑÐ²ÐµÐ´Ð¾Ð¼Ð»ÐµÐ½Ð¸Ñ 105 result = true; 106 } 107 108 return result; 109 }, 110 isAllChatsDisabled: function() { 111 return !!Notifications.subscribe.filter(function(item) { 112 return item.type === 'all_chats' && item.is_active === 0; 113 }).length 114 }, 115 init: function(callback) { 116 this.getSubscribe().done(function(response) { 117 var data = response && JSON ? JSON.parse(response) : {}; 118 119 if (data.subscribe) { 120 Notifications.subscribe = data.subscribe; 121 } 122 123 if (callback && callback instanceof Function) { 124 callback(); 125 } 126 }); 127 } 128} 129 130if (GLOBAL && GLOBAL.auth && GLOBAL.auth.status === 'ok') { 131 Notifications.init(); 132} 133 134$(function() { 135 var wrapper = $('#notifications'); 136 137 // ÐакÑÑÑÑ Ñведомление 138 wrapper.on('click', '.notifications__item-close', function() { 139 var item = $(this).closest('.notifications__item'), 140 id = item.data('id'); 141 142 item.fadeOut('fast', function() { 143 $(this).remove(); 144 145 // УдалиÑÑ Ð²Ð¾ вÑÐµÑ ÑÐ°Ð±Ð°Ñ 146 localStorage.setItem('notification_remove', id); 147 148 if (!wrapper.find('.notifications__item').length) { 149 $('.notifications__header').fadeOut('fast', function() { 150 $(this).remove(); 151 }); 152 } 153 }); 154 }); 155 156 window.onstorage = function(e) { 157 // УдалиÑÑ Ð²Ð¾ вÑÐµÑ ÑÐ°Ð±Ð°Ñ 158 if (e.key === 'notification_remove') { 159 wrapper.find('.notifications__item').filter('[data-id=' + e.newValue + ']').find('.notifications__item-close').trigger('click'); 160 } 161 }; 162 163 // ÐакÑÑÑÑ Ð²Ñе ÑÐ²ÐµÐ´Ð¾Ð¼Ð»ÐµÐ½Ð¸Ñ 164 wrapper.on('click', '#notificationsHide', function() { 165 $('.notifications__header').fadeOut('fast', function() { 166 $(this).remove(); 167 }); 168 169 wrapper.find('.notifications__item').each(function() { 170 $(this).find('.notifications__item-close').trigger('click'); 171 }) 172 }); 173 174 // ÐÑкÑÑÑÑ/закÑÑÑÑ Ð½Ð°ÑÑÑойки 175 wrapper.on('click', '#notificationsSettingsMore', function() { 176 wrapper.toggleClass('m-settings-open'); 177 }); 178 179 // ÐÑклÑÑиÑÑ ÑÐ²ÐµÐ´Ð¾Ð¼Ð»ÐµÐ½Ð¸Ñ 180 wrapper.on('click', '.notifications__item-on span', function() { 181 var btn = $(this), 182 room_id = btn.closest('.notifications__item-on').data('room_id'); 183 184 btn.addClass('m-hidden').siblings().removeClass('m-hidden'); 185 186 Notifications.setChatRoom(room_id, Notifications.isRoomDisabled(room_id) ? 1 : 0) 187 }) 188 189 // ÐÑклÑÑиÑÑ Ð²Ñе ÑÐ²ÐµÐ´Ð¾Ð¼Ð»ÐµÐ½Ð¸Ñ 190 wrapper.on('change', '#notificationsSettingsFormDisableAll', function() { 191 Notifications.setAllChats( $(this).is(':checked') ? 1 : 0 ); 192 }) 193 194 // ÐеÑейÑи к комнаÑе 195 wrapper.on('click', '.notifications__goto_room', function() { 196 var room_id = $(this).data('room_id'); 197 198 ria_chat_manager.openArticleRoom(room_id); 199 }); 200 201 // ÐеÑейÑи к ÑообÑÐµÐ½Ð¸Ñ 202 wrapper.on('click', '.notifications__goto_message', function() { 203 var room_id = $(this).data('room_id'), 204 message_id = $(this).data('message_id'); 205 206 ria_chat.state.goto_message = message_id; 207 ria_chat_manager.openArticleRoom(room_id); 208 }); 209 210 // ÐодпиÑка на ÑÐ²ÐµÐ´Ð¾Ð¼Ð»ÐµÐ½Ð¸Ñ 211 ria_sock.on('user_notify', function(data) { 212 if (data.type === 'user_notify') { 213 Notifications.add(data); 214 } 215 }); 216 217 if ('ontouchstart' in document.documentElement) { 218 var element = $('#notifications'), 219 mc = new Hammer(element[0]), 220 init_height = 0, 221 total_height = 0, 222 is_dragging = false; 223 224 mc.get('pan').set({ 225 direction: Hammer.DIRECTION_VERTICAL, 226 threshold: 0 227 }); 228 229 mc.on("pan", function(e) { 230 var new_height, 231 min_height = 160; 232 233 if (!is_dragging) { 234 is_dragging = true; 235 total_height = 0; 236 237 element.children().each(function(){ 238 total_height = total_height + $(this).outerHeight(true); 239 }); 240 241 init_height = element.outerHeight(); 242 } 243 244 new_height = init_height - e.deltaY; 245 new_height = Math.max(new_height, min_height); 246 new_height = Math.min(new_height, total_height); 247 248 element.css({ 249 'maxHeight': new_height 250 }); 251 252 if (e.isFinal) { 253 is_dragging = false;
254 } 255 }); 256 } 257 258 GLOBAL.events.subscribe('login', function (data) { 259 Notifications.init(function() { 260 ria_chat_manager.auth(); 261 }); 262 }) 263});
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.