From 4f3ea195d8e0ef30c3bf1c1371cab988678fd885 Mon Sep 17 00:00:00 2001 From: xiweicheng Date: Sat, 23 Nov 2019 12:52:25 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/blog/blog.js | 4 +- src/chat/chat.js | 4 +- src/resources/attributes/attr-attr.js | 4 +- src/resources/attributes/attr-autosize.js | 4 +- src/resources/attributes/attr-c2c.js | 3 + src/resources/attributes/attr-dimmer.js | 7 ++ src/resources/attributes/attr-dropzone.js | 6 ++ src/resources/attributes/attr-fancybox.js | 17 ++- src/resources/attributes/attr-modaal.js | 6 ++ src/resources/attributes/attr-pastable.js | 23 +++- src/resources/attributes/attr-scrollbar.js | 4 + src/resources/attributes/attr-tablesort.js | 17 ++- src/resources/attributes/attr-task.js | 1 + src/resources/attributes/attr-textcomplete.js | 29 ++++- src/resources/attributes/attr-ui-checkbox.js | 4 + .../attributes/attr-ui-dropdown-action.js | 4 + .../attr-ui-dropdown-hover-action.js | 4 + .../attributes/attr-ui-dropdown-hover.js | 4 + src/resources/attributes/attr-ui-dropdown.js | 4 + src/resources/attributes/attr-ui-popup.js | 5 + src/resources/attributes/attr-ui-pp.js | 7 +- src/resources/attributes/attr-ui-tab.js | 4 + .../elements/em-chat-content-item-footbar.js | 19 +++- .../elements/em-chat-content-item.js | 102 +++++++++++++----- src/resources/elements/em-chat-share.js | 10 ++ src/resources/elements/em-user-avatar.js | 9 ++ 26 files changed, 264 insertions(+), 41 deletions(-) diff --git a/src/blog/blog.js b/src/blog/blog.js index a0721e7..8a06153 100644 --- a/src/blog/blog.js +++ b/src/blog/blog.js @@ -44,8 +44,8 @@ export class Blog { // var socket = new SockJS('http://localhost:8080/ws'); let socket = new SockJS('/ws'); window.stompClient = Stomp.over(socket); - // window.stompClient.debug = () => {}; - stompClient.debug = (msg) => { console.log(msg) }; + window.stompClient.debug = () => {}; + // stompClient.debug = (msg) => { console.log(msg) }; window.stompClient.connect({}, (frame) => { // 注册发送消息 stompClient.subscribe('/blog/update', (msg) => { diff --git a/src/chat/chat.js b/src/chat/chat.js index a869939..978d2d9 100644 --- a/src/chat/chat.js +++ b/src/chat/chat.js @@ -60,8 +60,8 @@ export class Chat { // var socket = new SockJS('http://localhost:8080/ws'); let socket = new SockJS('/ws'); window.stompClient = Stomp.over(socket); - // window.stompClient.debug = () => {}; - stompClient.debug = (msg) => { console.log(msg) }; + window.stompClient.debug = () => {}; + // stompClient.debug = (msg) => { console.log(msg) }; window.stompClient.connect({}, (frame) => { // 同步在线用户 this.getOnlineUsers(); diff --git a/src/resources/attributes/attr-attr.js b/src/resources/attributes/attr-attr.js index 537cbe6..7db9ef2 100644 --- a/src/resources/attributes/attr-attr.js +++ b/src/resources/attributes/attr-attr.js @@ -30,5 +30,7 @@ export class AttrAttr { this.valueChanged(this.value); } - unbind() {} + unbind() { + this.element = null; + } } diff --git a/src/resources/attributes/attr-autosize.js b/src/resources/attributes/attr-autosize.js index 45afcf2..d830cf6 100644 --- a/src/resources/attributes/attr-autosize.js +++ b/src/resources/attributes/attr-autosize.js @@ -21,6 +21,8 @@ export class AttrAutosize { * 当数据绑定引擎从视图解除绑定时被调用 */ unbind() { - autosize.destroy(this.elements) + console.log('AttrAutosize--unbind'); + autosize.destroy(this.element); + this.element = null; } } diff --git a/src/resources/attributes/attr-c2c.js b/src/resources/attributes/attr-c2c.js index c829f47..554c71e 100644 --- a/src/resources/attributes/attr-c2c.js +++ b/src/resources/attributes/attr-c2c.js @@ -37,6 +37,9 @@ export class AttrC2cCustomAttribute { } unbind() { + console.log('AttrC2cCustomAttribute--unbind'); this.clipboard && this.clipboard.destroy(); + this.clipboard = null; + this.element = null; } } diff --git a/src/resources/attributes/attr-dimmer.js b/src/resources/attributes/attr-dimmer.js index 0e1076f..508eb6b 100644 --- a/src/resources/attributes/attr-dimmer.js +++ b/src/resources/attributes/attr-dimmer.js @@ -23,4 +23,11 @@ export class AttrDimmer { this.valueChanged(this.value); } + unbind() { + console.log('AttrDimmer--unbind'); + this.$dimmer && this.$dimmer.remove(); + this.$dimmer = null; + this.element = null; + } + } diff --git a/src/resources/attributes/attr-dropzone.js b/src/resources/attributes/attr-dropzone.js index a9242d1..42dbf9a 100644 --- a/src/resources/attributes/attr-dropzone.js +++ b/src/resources/attributes/attr-dropzone.js @@ -105,6 +105,7 @@ export class AttrDropzone { * 当数据绑定引擎从视图解除绑定时被调用 */ unbind() { + console.log('AttrDropzone--unbind'); try { $.each(this.dropzones, (i, dropzone) => { dropzone.destroy(); @@ -112,5 +113,10 @@ export class AttrDropzone { } catch (e) { console.log(e); } + this.target = null; + this.dropzones = []; + this.eventAggregator = null; + this.subscribe.dispose(); + Dropzone = null; } } diff --git a/src/resources/attributes/attr-fancybox.js b/src/resources/attributes/attr-fancybox.js index 040e6f6..2835a80 100644 --- a/src/resources/attributes/attr-fancybox.js +++ b/src/resources/attributes/attr-fancybox.js @@ -11,7 +11,8 @@ export class AttrFancyboxCustomAttribute { } valueChanged(newValue, oldValue) { - $(this.element).on('click', 'img', (event) => { + + this.imgHandler = (event) => { event.preventDefault(); let $img = $(event.target); var imgs = []; @@ -23,6 +24,7 @@ export class AttrFancyboxCustomAttribute { } }); + // https://fancyapps.com/fancybox/3/docs/#api $.fancybox.open(imgs, { i18n: { 'zh': { @@ -56,10 +58,21 @@ export class AttrFancyboxCustomAttribute { ], }, initialIndexOnArray); - }); + }; + + $(this.element).on('click', 'img', this.imgHandler); } bind(bindingContext) { this.valueChanged(this.value); } + + unbind() { + console.log('AttrFancyboxCustomAttribute--unbind'); + $(this.element).off('click', 'img', this.imgHandler); + this.imgHandler = null; + this.element = null; + + $.fancybox.destroy(); + } } diff --git a/src/resources/attributes/attr-modaal.js b/src/resources/attributes/attr-modaal.js index 417772a..db67697 100644 --- a/src/resources/attributes/attr-modaal.js +++ b/src/resources/attributes/attr-modaal.js @@ -44,4 +44,10 @@ export class AttrModaalCustomAttribute { }); } + + unbind() { + console.log('AttrModaalCustomAttribute--unbind'); + $(this.element).modaal('close'); + this.element = null; + } } diff --git a/src/resources/attributes/attr-pastable.js b/src/resources/attributes/attr-pastable.js index f3e91a3..9f3a269 100644 --- a/src/resources/attributes/attr-pastable.js +++ b/src/resources/attributes/attr-pastable.js @@ -12,8 +12,8 @@ export class AttrPastable { } valueChanged(newValue, oldValue) { - // clipboard paste image - $(this.element).pastableTextarea().on('pasteImage', (ev, data) => { + + this.pasteHandler = (ev, data) => { $.post('/admin/file/base64', { dataURL: data.dataURL, @@ -29,12 +29,27 @@ export class AttrPastable { .replace(/\{uuidName\}/g, data.data.uuidName)); } }); - }).on('pasteImageError', (ev, data) => { + }; + + this.errHandler = (ev, data) => { toastr.error(data.message, '剪贴板粘贴图片错误!'); - }); + }; + + // https://github.com/layerssss/paste.js + // clipboard paste image + $(this.element).pastableTextarea().on('pasteImage', this.pasteHandler).on('pasteImageError', this.errHandler); } bind(bindingContext) { this.valueChanged(this.value); } + + unbind() { + console.log('AttrPastable--unbind'); + $(this.element).pastableTextarea().off('pasteImage', this.pasteHandler).off('pasteImageError', this.errHandler); + this.element = null; + this.pasteHandler = null; + this.errHandler = null; + + } } diff --git a/src/resources/attributes/attr-scrollbar.js b/src/resources/attributes/attr-scrollbar.js index 700a132..1df48c7 100644 --- a/src/resources/attributes/attr-scrollbar.js +++ b/src/resources/attributes/attr-scrollbar.js @@ -29,8 +29,12 @@ export class AttrScrollbarCustomAttribute { * 当数据绑定引擎从视图解除绑定时被调用 */ unbind() { + + console.log('AttrScrollbarCustomAttribute--unbind'); try { jQuery(this.element).removeClass(this.cls).scrollbar('destroy'); } catch (err) {} + + this.element = null; } } diff --git a/src/resources/attributes/attr-tablesort.js b/src/resources/attributes/attr-tablesort.js index d7fb290..bb1a129 100644 --- a/src/resources/attributes/attr-tablesort.js +++ b/src/resources/attributes/attr-tablesort.js @@ -14,13 +14,26 @@ export class AttrTablesortCustomAttribute { _init() { if ($(this.element).is('table')) { + // https://github.com/kylefox/jquery-tablesort $(this.element).addClass('sortable').tablesort(); + this.tablesort = $(this.element).data('tablesort'); } else { - console.warn('tablesort element is not table tag!'); + console.warn('tablesort element is not table tag!'); } } bind() { - this._init(); + this._init(); + } + + unbind() { + + console.log('AttrTablesortCustomAttribute--unbind'); + + this.tablesort && this.tablesort.destroy(); + + this.element = null; + this.tablesort = null; + } } diff --git a/src/resources/attributes/attr-task.js b/src/resources/attributes/attr-task.js index 7ab7464..ae8bb89 100644 --- a/src/resources/attributes/attr-task.js +++ b/src/resources/attributes/attr-task.js @@ -32,6 +32,7 @@ export class AttrTask { } unbind() { + console.log('AttrTask--unbind'); this.element = null; this.task = null; this.bindingCtx = null; diff --git a/src/resources/attributes/attr-textcomplete.js b/src/resources/attributes/attr-textcomplete.js index 5cf58b9..916a4f2 100644 --- a/src/resources/attributes/attr-textcomplete.js +++ b/src/resources/attributes/attr-textcomplete.js @@ -26,9 +26,12 @@ export class AttrTextcompleteCustomAttribute { } valueChanged() { + if (this.value) { this.members = this.value.users; this.channel = this.value.channel; + + // https://github.com/yuku/jquery-textcomplete $(this.element).textcomplete([{ // chat msg help match: /(|\b)(\/.*)$/, search: (term, callback) => { @@ -120,8 +123,12 @@ export class AttrTextcompleteCustomAttribute { initHotkeys() { + this.keydowns = []; + _.each(_.filter(_.values(tips), 'key'), (value) => { - $(this.element).bind('keydown', value.key, (evt) => { + + let key = value.key; + let handler = (evt) => { evt.preventDefault(); $(this.element).insertAtCaret(value.value); let cr = utils.getCursortPosition(this.element); @@ -130,14 +137,34 @@ export class AttrTextcompleteCustomAttribute { _.defer(() => { autosize.update(this.element); }); + }; + + this.keydowns.push({ + key: key, + handler: handler }); + + $(this.element).bind('keydown', key, handler); }); } unbind() { + + console.log('AttrTextcompleteCustomAttribute--unbind'); + try { $(this.element).textcomplete('destroy'); } catch (err) {} + + + _.each(this.keydowns, (item) => { + $(this.element).unbind('keydown', item.key, item.handler); + }); + + this.members = null; + this.channel = null; + this.element = null; + this.keydowns = []; } } diff --git a/src/resources/attributes/attr-ui-checkbox.js b/src/resources/attributes/attr-ui-checkbox.js index f9ad7ed..ca03d5a 100644 --- a/src/resources/attributes/attr-ui-checkbox.js +++ b/src/resources/attributes/attr-ui-checkbox.js @@ -12,4 +12,8 @@ export class AttrUiCheckboxCustomAttribute { valueChanged(newValue, oldValue) { $(this.element).checkbox(); } + + unbind() { + this.element = null; + } } diff --git a/src/resources/attributes/attr-ui-dropdown-action.js b/src/resources/attributes/attr-ui-dropdown-action.js index c8c9aca..7e4aabe 100644 --- a/src/resources/attributes/attr-ui-dropdown-action.js +++ b/src/resources/attributes/attr-ui-dropdown-action.js @@ -24,4 +24,8 @@ export class AttrUiDropdownActionCustomAttribute { bind() { this._init(this.value ? this.value : window); } + + unbind() { + this.element = null; + } } diff --git a/src/resources/attributes/attr-ui-dropdown-hover-action.js b/src/resources/attributes/attr-ui-dropdown-hover-action.js index fee6b5f..5c757a2 100644 --- a/src/resources/attributes/attr-ui-dropdown-hover-action.js +++ b/src/resources/attributes/attr-ui-dropdown-hover-action.js @@ -25,4 +25,8 @@ export class AttrUiDropdownHoverActionCustomAttribute { bind() { this._init(this.value ? this.value : window); } + + unbind() { + this.element = null; + } } diff --git a/src/resources/attributes/attr-ui-dropdown-hover.js b/src/resources/attributes/attr-ui-dropdown-hover.js index 4ffdf22..ea2f0b3 100644 --- a/src/resources/attributes/attr-ui-dropdown-hover.js +++ b/src/resources/attributes/attr-ui-dropdown-hover.js @@ -24,4 +24,8 @@ export class AttrUiDropdownHoverCustomAttribute { bind() { this._init(this.value ? this.value : 'hide'); } + + unbind() { + this.element = null; + } } diff --git a/src/resources/attributes/attr-ui-dropdown.js b/src/resources/attributes/attr-ui-dropdown.js index 1592b20..193abb4 100644 --- a/src/resources/attributes/attr-ui-dropdown.js +++ b/src/resources/attributes/attr-ui-dropdown.js @@ -23,4 +23,8 @@ export class AttrUiDropdownCustomAttribute { bind() { this._init(this.value ? this.value : 'hide'); } + + unbind() { + this.element = null; + } } diff --git a/src/resources/attributes/attr-ui-popup.js b/src/resources/attributes/attr-ui-popup.js index 6f1513c..f788a42 100644 --- a/src/resources/attributes/attr-ui-popup.js +++ b/src/resources/attributes/attr-ui-popup.js @@ -32,4 +32,9 @@ export class AttrUiPopupCustomAttribute { }); } + + unbind() { + $(this.element).popup('destroy'); + this.element = null; + } } diff --git a/src/resources/attributes/attr-ui-pp.js b/src/resources/attributes/attr-ui-pp.js index fbc5a64..e7cff89 100644 --- a/src/resources/attributes/attr-ui-pp.js +++ b/src/resources/attributes/attr-ui-pp.js @@ -17,4 +17,9 @@ export class AttrUiPpCustomAttribute { }); } -} \ No newline at end of file + + unbind() { + $(this.element).popup('destroy'); + this.element = null; + } +} diff --git a/src/resources/attributes/attr-ui-tab.js b/src/resources/attributes/attr-ui-tab.js index a30a132..fbb6c93 100644 --- a/src/resources/attributes/attr-ui-tab.js +++ b/src/resources/attributes/attr-ui-tab.js @@ -21,4 +21,8 @@ export class AttrUiTabCustomAttribute { bind() { this._init(); } + + unbind() { + this.element = null; + } } diff --git a/src/resources/elements/em-chat-content-item-footbar.js b/src/resources/elements/em-chat-content-item-footbar.js index 6612600..e1fe562 100644 --- a/src/resources/elements/em-chat-content-item-footbar.js +++ b/src/resources/elements/em-chat-content-item-footbar.js @@ -49,7 +49,23 @@ export class EmChatContentItemFootbar { /** * 构造函数 */ - constructor() { + constructor() {} + + detached() { + console.log('EmChatContentItemFootbar--detached'); + + $([this.addEmojiRef]).popup('destroy'); + $([this.addTagRef]).popup('destroy'); + + this.chat = null; + this.myTags = null; + this.tags = null; + this.addEmojiRef = null; + this.addTagRef = null; + this.tagRef = null; + } + + bind() { this.tags = tags; } @@ -57,6 +73,7 @@ export class EmChatContentItemFootbar { * 当视图被附加到DOM中时被调用 */ attached() { + $([this.addEmojiRef]) .popup({ inline: true, diff --git a/src/resources/elements/em-chat-content-item.js b/src/resources/elements/em-chat-content-item.js index d69bc7c..7b32480 100644 --- a/src/resources/elements/em-chat-content-item.js +++ b/src/resources/elements/em-chat-content-item.js @@ -140,25 +140,66 @@ export class EmChatContentItem { this.subscribe2.dispose(); } + detached() { + + $(document).unbind('keydown', 'e', this.keydownHandler); + $('.tms-content-body').off('click', '.markdown-body .at-user', this.atUserHandler); + $('.tms-content-body').off('click', '.markdown-body .at-group', this.atGroupHandler); + $('.tms-chat').off('mouseenter', '.markdown-body a[href*="#/chat/"]:not(.pp-not)', this.msgPpMiHandler); + $('.tms-chat').off('mouseleave', '.markdown-body a[href*="#/chat/"]:not(.pp-not)', this.msgPpMlHandler); + $('.tms-chat').off('mouseenter', '.tms-content-body .em-chat-content-item', this.wikiDirMiHandler); + $('.tms-chat').off('mouseleave', '.tms-content-body .em-chat-content-item', this.wikiDirMlHandler); + $('.tms-chat').off('click', '.panel-wiki-dir .wiki-dir-item', this.wikiDirItemClickHandler); + $('.tms-chat').off('mouseenter', 'span[data-value].at-user:not(.pp-not),span[data-value].at-group:not(.pp-not),a[data-value].author:not(.pp-not)', this.userInfoPpMiHandler); + $('.tms-chat').off('mouseleave', 'span[data-value].at-user:not(.pp-not),span[data-value].at-group:not(.pp-not),a[data-value].author:not(.pp-not)', this.userInfoPpMlHandler); + + + this.keydownHandler = null; + this.atUserHandler = null; + this.atGroupHandler = null; + this.msgPpMiHandler = null; + this.msgPpMlHandler = null; + this.wikiDirMiHandler = null; + this.wikiDirMlHandler = null; + this.wikiDirItemClickHandler = null; + this.userInfoPpMiHandler = null; + this.userInfoPpMlHandler = null; + + this.chats = null; + this.loginUser = null; + this.isAt = null; + this.channel = null; + this.markId = null; + this.chatTo = null; + this.members = []; + + this.hoverMsgTimeoutRef = null; + this.hoverMsgTarget = null; + + } + /** * 当视图被附加到DOM中时被调用 */ attached() { - $('.tms-content-body').on('click', '.markdown-body .at-user', (event) => { + this.atUserHandler = (event) => { event.preventDefault(); ea.publish(nsCons.EVENT_CHAT_MSG_INSERT, { content: `{~${$(event.currentTarget).attr('data-value')}} ` }); - }); - $('.tms-content-body').on('click', '.markdown-body .at-group', (event) => { + }; + + this.atGroupHandler = (event) => { event.preventDefault(); ea.publish(nsCons.EVENT_CHAT_MSG_INSERT, { content: `{!~${$(event.currentTarget).attr('data-value')}} ` }); - }); + }; - // 消息popup - $('.tms-chat').on('mouseenter', '.markdown-body a[href*="#/chat/"]:not(.pp-not)', (event) => { + $('.tms-content-body').on('click', '.markdown-body .at-user', this.atUserHandler); + $('.tms-content-body').on('click', '.markdown-body .at-group', this.atGroupHandler); + + this.msgPpMiHandler = (event) => { event.preventDefault(); let target = event.currentTarget; @@ -181,9 +222,9 @@ export class EmChatContentItem { this.hoverMsgTimeoutRef = null; }, 500); - }); + }; - $('.tms-chat').on('mouseleave', '.markdown-body a[href*="#/chat/"]:not(.pp-not)', (event) => { + this.msgPpMlHandler = (event) => { event.preventDefault(); if (this.hoverMsgTimeoutRef) { if (this.hoverMsgTarget === event.currentTarget) { @@ -191,10 +232,14 @@ export class EmChatContentItem { this.hoverMsgTimeoutRef = null; } } - }); + }; - // wiki dir - $('.tms-chat').on('mouseenter', '.tms-content-body .em-chat-content-item', (event) => { + // 消息popup + $('.tms-chat').on('mouseenter', '.markdown-body a[href*="#/chat/"]:not(.pp-not)', this.msgPpMiHandler); + $('.tms-chat').on('mouseleave', '.markdown-body a[href*="#/chat/"]:not(.pp-not)', this.msgPpMlHandler); + + + this.wikiDirMiHandler = (event) => { event.preventDefault(); var $c = $(event.currentTarget); @@ -205,23 +250,28 @@ export class EmChatContentItem { let chat = _.find(this.chats, { id: +$c.attr('data-id') }); chat && (chat._hovered = true); chat && (chat.__hovered = true); - }); + }; - $('.tms-chat').on('mouseleave', '.tms-content-body .em-chat-content-item', (event) => { + this.wikiDirMlHandler = (event) => { event.preventDefault(); var $c = $(event.currentTarget); let chat = _.find(this.chats, { id: +$c.attr('data-id') }); chat && (chat._hovered = false); - }); + }; + + // wiki dir + $('.tms-chat').on('mouseenter', '.tms-content-body .em-chat-content-item', this.wikiDirMiHandler); + $('.tms-chat').on('mouseleave', '.tms-content-body .em-chat-content-item', this.wikiDirMlHandler); - $('.tms-chat').on('click', '.panel-wiki-dir .wiki-dir-item', (event) => { + this.wikiDirItemClickHandler = (event) => { event.preventDefault(); ea.publish(nsCons.EVENT_CHAT_CONTENT_SCROLL_TO, { target: $('#' + $(event.currentTarget).attr('data-id')) }); - }); + }; - // 用户信息popup - $('.tms-chat').on('mouseenter', 'span[data-value].at-user:not(.pp-not),span[data-value].at-group:not(.pp-not),a[data-value].author:not(.pp-not)', (event) => { + $('.tms-chat').on('click', '.panel-wiki-dir .wiki-dir-item', this.wikiDirItemClickHandler); + + this.userInfoPpMiHandler = (event) => { event.preventDefault(); let target = event.currentTarget; @@ -246,10 +296,9 @@ export class EmChatContentItem { this.hoverTimeoutRef = null; }, 500); - }); + }; - // 用户信息popup - $('.tms-chat').on('mouseleave', 'span[data-value].at-user:not(.pp-not),span[data-value].at-group:not(.pp-not),a[data-value].author:not(.pp-not)', (event) => { + this.userInfoPpMlHandler = (event) => { event.preventDefault(); if (this.hoverTimeoutRef) { if (this.hoverUserTarget === event.currentTarget) { @@ -258,7 +307,11 @@ export class EmChatContentItem { } } - }); + }; + + // 用户信息popup + $('.tms-chat').on('mouseenter', 'span[data-value].at-user:not(.pp-not),span[data-value].at-group:not(.pp-not),a[data-value].author:not(.pp-not)', this.userInfoPpMiHandler); + $('.tms-chat').on('mouseleave', 'span[data-value].at-user:not(.pp-not),span[data-value].at-group:not(.pp-not),a[data-value].author:not(.pp-not)', this.userInfoPpMlHandler); this.initHotkeys(); } @@ -304,13 +357,14 @@ export class EmChatContentItem { } initHotkeys() { - $(document).bind('keydown', 'e', (evt) => { + this.keydownHandler = (evt) => { evt.preventDefault(); let chat = _.findLast(this.chats, c => c.creator.username == this.loginUser.username); if (chat) { this.editHandler(chat, $(`.em-chat-content-item[data-id="${chat.id}"]`).find('> .content > textarea')); } - }); + }; + $(document).bind('keydown', 'e', this.keydownHandler); } editHandler(item, editTxtRef) { diff --git a/src/resources/elements/em-chat-share.js b/src/resources/elements/em-chat-share.js index 39697a0..62634ac 100644 --- a/src/resources/elements/em-chat-share.js +++ b/src/resources/elements/em-chat-share.js @@ -71,6 +71,16 @@ export class EmChatShare { }); } + detached() { + $(this.shareRef).popup('destroy'); + + this.chat = null; + this.channel = null; + this.loginUser = null; + this.shareRef = null; + this.searchRef = null; + } + shareSearchKeyupHandler(event) { if (event.keyCode === 13 && !$(this.searchRef).search('is visible')) { let val = $(this.inputSearchRef).val(); diff --git a/src/resources/elements/em-user-avatar.js b/src/resources/elements/em-user-avatar.js index c33021d..e81409a 100644 --- a/src/resources/elements/em-user-avatar.js +++ b/src/resources/elements/em-user-avatar.js @@ -32,11 +32,20 @@ export class EmUserAvatar { * 当视图被附加到DOM中时被调用 */ attached() { + $(this.avatarRef).hover(() => { this._calcNameChar(false); }, () => { this._calcNameChar(); }); + + } + + detached() { + console.log('EmUserAvatar--detached'); + $(this.avatarRef).unbind('mouseenter').unbind('mouseleave'); + this.avatarRef = null; + this.user = null; } dblclickHandler() { -- Gitee From b0f0f1319f0750ca518a9ebf17331c2ab8631c6f Mon Sep 17 00:00:00 2001 From: xiweicheng Date: Sat, 23 Nov 2019 13:12:49 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/resources/attributes/attr-dropzone.js | 2 +- src/resources/elements/em-channel-task.js | 26 ++++++++++++++----- .../elements/em-channel-tasks-modal.js | 5 ++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/resources/attributes/attr-dropzone.js b/src/resources/attributes/attr-dropzone.js index 42dbf9a..df3f269 100644 --- a/src/resources/attributes/attr-dropzone.js +++ b/src/resources/attributes/attr-dropzone.js @@ -117,6 +117,6 @@ export class AttrDropzone { this.dropzones = []; this.eventAggregator = null; this.subscribe.dispose(); - Dropzone = null; + // Dropzone = null; } } diff --git a/src/resources/elements/em-channel-task.js b/src/resources/elements/em-channel-task.js index 86a417f..63e16ef 100644 --- a/src/resources/elements/em-channel-task.js +++ b/src/resources/elements/em-channel-task.js @@ -7,9 +7,9 @@ export class EmChannelTask { @bindable loginUser; channelChanged() { - _.each(this.mapping, (v, k) => { - this[v] = {}; - }); + // _.each(this.mapping, (v, k) => { + // this[v] = {}; + // }); this._sortMembers(); } @@ -68,7 +68,7 @@ export class EmChannelTask { this.talkVm.show(payload); }); - + this.subscribe4 = ea.subscribe(nsCons.EVENT_MARKDOWN_TASK_ITEM_STATUS_TOGGLE, (payload) => { // console.log(payload); @@ -237,6 +237,18 @@ export class EmChannelTask { }); } + detached() { + + this.drake.destroy(); + this.drake = null; + + $('.em-channel-task').off('click', '.tms-task-filter > .text .remove.icon', this.taskClickHandler); + + this.taskClickHandler = null; + this.channel = null; + this.loginUser = null; + } + attached() { this.drake = dragula($(this.containerRef).find('.tms-dd-container').toArray(), { // isContainer: function(el) { @@ -287,7 +299,7 @@ export class EmChannelTask { }); - $('.em-channel-task').on('click', '.tms-task-filter > .text .remove.icon', event => { + this.taskClickHandler = event => { let $dd = $(event.currentTarget).parents('.tms-task-filter'); $dd.dropdown('clear').dropdown('hide'); @@ -298,7 +310,9 @@ export class EmChannelTask { item._hidden = false; }); } - }) + }; + + $('.em-channel-task').on('click', '.tms-task-filter > .text .remove.icon', this.taskClickHandler); } _sortMembers() { diff --git a/src/resources/elements/em-channel-tasks-modal.js b/src/resources/elements/em-channel-tasks-modal.js index 604208c..c6a4f64 100644 --- a/src/resources/elements/em-channel-tasks-modal.js +++ b/src/resources/elements/em-channel-tasks-modal.js @@ -20,6 +20,11 @@ export class EmChannelTasksModal { }); } + detached() { + this.channel = null; + this.loginUser = null; + } + /** * 当数据绑定引擎从视图解除绑定时被调用 */ -- Gitee From 06d69d51d05d52318f83fbe29b0d5033e4ee8241 Mon Sep 17 00:00:00 2001 From: xiweicheng Date: Sat, 23 Nov 2019 13:50:46 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E7=95=8C=E9=9D=A2=E4=BC=98=E5=8C=96...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/resources/attributes/attr-autosize.js | 2 +- src/resources/attributes/attr-c2c.js | 2 +- src/resources/attributes/attr-dimmer.js | 2 +- src/resources/attributes/attr-dropzone.js | 2 +- src/resources/attributes/attr-fancybox.js | 2 +- src/resources/attributes/attr-modaal.js | 2 +- src/resources/attributes/attr-pastable.js | 2 +- src/resources/attributes/attr-scrollbar.js | 2 +- src/resources/attributes/attr-tablesort.js | 2 +- src/resources/attributes/attr-task.js | 2 +- src/resources/attributes/attr-textcomplete.js | 2 +- src/resources/elements/em-chat-content-item-footbar.js | 5 +++-- src/resources/elements/em-user-avatar.js | 2 +- 13 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/resources/attributes/attr-autosize.js b/src/resources/attributes/attr-autosize.js index d830cf6..c7e5a10 100644 --- a/src/resources/attributes/attr-autosize.js +++ b/src/resources/attributes/attr-autosize.js @@ -21,7 +21,7 @@ export class AttrAutosize { * 当数据绑定引擎从视图解除绑定时被调用 */ unbind() { - console.log('AttrAutosize--unbind'); + window.__debug && console.log('AttrAutosize--unbind'); autosize.destroy(this.element); this.element = null; } diff --git a/src/resources/attributes/attr-c2c.js b/src/resources/attributes/attr-c2c.js index 554c71e..92debfb 100644 --- a/src/resources/attributes/attr-c2c.js +++ b/src/resources/attributes/attr-c2c.js @@ -37,7 +37,7 @@ export class AttrC2cCustomAttribute { } unbind() { - console.log('AttrC2cCustomAttribute--unbind'); + window.__debug && console.log('AttrC2cCustomAttribute--unbind'); this.clipboard && this.clipboard.destroy(); this.clipboard = null; this.element = null; diff --git a/src/resources/attributes/attr-dimmer.js b/src/resources/attributes/attr-dimmer.js index 508eb6b..565b754 100644 --- a/src/resources/attributes/attr-dimmer.js +++ b/src/resources/attributes/attr-dimmer.js @@ -24,7 +24,7 @@ export class AttrDimmer { } unbind() { - console.log('AttrDimmer--unbind'); + window.__debug && console.log('AttrDimmer--unbind'); this.$dimmer && this.$dimmer.remove(); this.$dimmer = null; this.element = null; diff --git a/src/resources/attributes/attr-dropzone.js b/src/resources/attributes/attr-dropzone.js index df3f269..f79cb2a 100644 --- a/src/resources/attributes/attr-dropzone.js +++ b/src/resources/attributes/attr-dropzone.js @@ -105,7 +105,7 @@ export class AttrDropzone { * 当数据绑定引擎从视图解除绑定时被调用 */ unbind() { - console.log('AttrDropzone--unbind'); + window.__debug && console.log('AttrDropzone--unbind'); try { $.each(this.dropzones, (i, dropzone) => { dropzone.destroy(); diff --git a/src/resources/attributes/attr-fancybox.js b/src/resources/attributes/attr-fancybox.js index 2835a80..9f01a6d 100644 --- a/src/resources/attributes/attr-fancybox.js +++ b/src/resources/attributes/attr-fancybox.js @@ -68,7 +68,7 @@ export class AttrFancyboxCustomAttribute { } unbind() { - console.log('AttrFancyboxCustomAttribute--unbind'); + window.__debug && console.log('AttrFancyboxCustomAttribute--unbind'); $(this.element).off('click', 'img', this.imgHandler); this.imgHandler = null; this.element = null; diff --git a/src/resources/attributes/attr-modaal.js b/src/resources/attributes/attr-modaal.js index db67697..cfc92ab 100644 --- a/src/resources/attributes/attr-modaal.js +++ b/src/resources/attributes/attr-modaal.js @@ -46,7 +46,7 @@ export class AttrModaalCustomAttribute { } unbind() { - console.log('AttrModaalCustomAttribute--unbind'); + window.__debug && console.log('AttrModaalCustomAttribute--unbind'); $(this.element).modaal('close'); this.element = null; } diff --git a/src/resources/attributes/attr-pastable.js b/src/resources/attributes/attr-pastable.js index 9f3a269..5bd9191 100644 --- a/src/resources/attributes/attr-pastable.js +++ b/src/resources/attributes/attr-pastable.js @@ -45,7 +45,7 @@ export class AttrPastable { } unbind() { - console.log('AttrPastable--unbind'); + window.__debug && console.log('AttrPastable--unbind'); $(this.element).pastableTextarea().off('pasteImage', this.pasteHandler).off('pasteImageError', this.errHandler); this.element = null; this.pasteHandler = null; diff --git a/src/resources/attributes/attr-scrollbar.js b/src/resources/attributes/attr-scrollbar.js index 1df48c7..4fd20a6 100644 --- a/src/resources/attributes/attr-scrollbar.js +++ b/src/resources/attributes/attr-scrollbar.js @@ -30,7 +30,7 @@ export class AttrScrollbarCustomAttribute { */ unbind() { - console.log('AttrScrollbarCustomAttribute--unbind'); + window.__debug && console.log('AttrScrollbarCustomAttribute--unbind'); try { jQuery(this.element).removeClass(this.cls).scrollbar('destroy'); } catch (err) {} diff --git a/src/resources/attributes/attr-tablesort.js b/src/resources/attributes/attr-tablesort.js index bb1a129..1b78015 100644 --- a/src/resources/attributes/attr-tablesort.js +++ b/src/resources/attributes/attr-tablesort.js @@ -28,7 +28,7 @@ export class AttrTablesortCustomAttribute { unbind() { - console.log('AttrTablesortCustomAttribute--unbind'); + window.__debug && console.log('AttrTablesortCustomAttribute--unbind'); this.tablesort && this.tablesort.destroy(); diff --git a/src/resources/attributes/attr-task.js b/src/resources/attributes/attr-task.js index ae8bb89..c1100aa 100644 --- a/src/resources/attributes/attr-task.js +++ b/src/resources/attributes/attr-task.js @@ -32,7 +32,7 @@ export class AttrTask { } unbind() { - console.log('AttrTask--unbind'); + window.__debug && console.log('AttrTask--unbind'); this.element = null; this.task = null; this.bindingCtx = null; diff --git a/src/resources/attributes/attr-textcomplete.js b/src/resources/attributes/attr-textcomplete.js index 916a4f2..820bc28 100644 --- a/src/resources/attributes/attr-textcomplete.js +++ b/src/resources/attributes/attr-textcomplete.js @@ -151,7 +151,7 @@ export class AttrTextcompleteCustomAttribute { unbind() { - console.log('AttrTextcompleteCustomAttribute--unbind'); + window.__debug && console.log('AttrTextcompleteCustomAttribute--unbind'); try { $(this.element).textcomplete('destroy'); diff --git a/src/resources/elements/em-chat-content-item-footbar.js b/src/resources/elements/em-chat-content-item-footbar.js index e1fe562..538a3af 100644 --- a/src/resources/elements/em-chat-content-item-footbar.js +++ b/src/resources/elements/em-chat-content-item-footbar.js @@ -44,7 +44,7 @@ export class EmChatContentItemFootbar { type: 'emoji' }]; - myTags = nsCtx.myTags; + myTags; /** * 构造函数 @@ -52,7 +52,7 @@ export class EmChatContentItemFootbar { constructor() {} detached() { - console.log('EmChatContentItemFootbar--detached'); + window.__debug && console.log('EmChatContentItemFootbar--detached'); $([this.addEmojiRef]).popup('destroy'); $([this.addTagRef]).popup('destroy'); @@ -67,6 +67,7 @@ export class EmChatContentItemFootbar { bind() { this.tags = tags; + this.myTags = nsCtx.myTags; } /** diff --git a/src/resources/elements/em-user-avatar.js b/src/resources/elements/em-user-avatar.js index e81409a..e6d6bcc 100644 --- a/src/resources/elements/em-user-avatar.js +++ b/src/resources/elements/em-user-avatar.js @@ -42,7 +42,7 @@ export class EmUserAvatar { } detached() { - console.log('EmUserAvatar--detached'); + window.__debug && console.log('EmUserAvatar--detached'); $(this.avatarRef).unbind('mouseenter').unbind('mouseleave'); this.avatarRef = null; this.user = null; -- Gitee From b353893c05fc94f8838b8c2c3eb8d9bedb003789 Mon Sep 17 00:00:00 2001 From: xiweicheng Date: Sat, 23 Nov 2019 18:23:26 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E7=95=8C=E9=9D=A2=E4=BC=98=E5=8C=96...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../em-channel-chat-task-talk-modal.html | 2 +- .../em-channel-chat-task-talk-modal.js | 12 ++++++ .../elements/em-channel-task-create.js | 6 +++ src/resources/elements/em-chat-input.js | 7 +++ src/resources/elements/em-chat-topic.html | 2 +- src/resources/elements/em-chat-topic.js | 43 ++++++++++++++++--- src/resources/elements/em-dropdown.js | 8 ++++ 7 files changed, 72 insertions(+), 8 deletions(-) diff --git a/src/resources/elements/em-channel-chat-task-talk-modal.html b/src/resources/elements/em-channel-chat-task-talk-modal.html index 15c8aaa..0f7f6b7 100644 --- a/src/resources/elements/em-channel-chat-task-talk-modal.html +++ b/src/resources/elements/em-channel-chat-task-talk-modal.html @@ -3,7 +3,7 @@
频道任务评论
- +
diff --git a/src/resources/elements/em-channel-chat-task-talk-modal.js b/src/resources/elements/em-channel-chat-task-talk-modal.js index 695b761..fe6c0e8 100644 --- a/src/resources/elements/em-channel-chat-task-talk-modal.js +++ b/src/resources/elements/em-channel-chat-task-talk-modal.js @@ -32,6 +32,17 @@ export class EmChannelChatTaskTalkModal { }); } + detached() { + window.__debug && console.log('EmChannelChatTaskTalkModal--detached'); + + this.channel = null; + this.task = null; + this.actived = null; + this.chatTopicVm = null; + this.emModal = null; + + } + /** * 当数据绑定引擎从视图解除绑定时被调用 */ @@ -40,6 +51,7 @@ export class EmChannelChatTaskTalkModal { } approveHandler(modal) { + this.chatTopicVm.commit(); this.emModal.hide(); } } diff --git a/src/resources/elements/em-channel-task-create.js b/src/resources/elements/em-channel-task-create.js index 71a0b6b..d781483 100644 --- a/src/resources/elements/em-channel-task-create.js +++ b/src/resources/elements/em-channel-task-create.js @@ -55,6 +55,12 @@ export class EmChannelTaskCreate { }); this.simplemde.value(this.taskItem.content); + + _.delay(() => { + // this.simplemde.codemirror.focus(); + this.simplemde.value(this.taskItem.content); + }, 500); + } /** diff --git a/src/resources/elements/em-chat-input.js b/src/resources/elements/em-chat-input.js index 7981ba5..102c651 100644 --- a/src/resources/elements/em-chat-input.js +++ b/src/resources/elements/em-chat-input.js @@ -66,6 +66,13 @@ export class EmChatInput { this.initHotkeys(); } + detached() { + window.__debug && console.log('EmChatInput--detached'); + try { + $(this.$chatMsgInputRef).textcomplete('destroy'); + } catch (err) {} + } + initPaste() { let $paste; diff --git a/src/resources/elements/em-chat-topic.html b/src/resources/elements/em-chat-topic.html index 8129c24..c4b9a44 100644 --- a/src/resources/elements/em-chat-topic.html +++ b/src/resources/elements/em-chat-topic.html @@ -72,7 +72,7 @@ - +
回复话题消息会自动关注话题,接收话题更新邮件通知
diff --git a/src/resources/elements/em-chat-topic.js b/src/resources/elements/em-chat-topic.js index e8ab407..d9a37a8 100644 --- a/src/resources/elements/em-chat-topic.js +++ b/src/resources/elements/em-chat-topic.js @@ -211,8 +211,29 @@ export class EmChatTopic { } + detached() { + window.__debug && console.log('EmChatTopic--detached'); + + $(this.commentsRef).off('dblclick', '.comment.tms-reply', this.replydblclickHandler); + $(this.commentsRef).off('click', '.markdown-body .at-user', this.atUserHandler); + $(this.commentsRef).off('click', '.markdown-body .at-group', this.atGroupHandler); + + this.replydblclickHandler = null; + this.atUserHandler = null; + this.atGroupHandler = null; + + this.actived = null; + this.channel = null; + this.members = []; + this.chat = []; + this.commentsRef = null; + this.ajaxTopic = null; + this.followers = null; + } + attached() { - $(this.commentsRef).on('dblclick', '.comment.tms-reply', (event) => { + + this.replydblclickHandler = (event) => { if (event.ctrlKey && event.shiftKey) { let chatId = $(event.currentTarget).attr('data-id'); let $t = $(event.currentTarget).find('.content > textarea'); @@ -229,23 +250,29 @@ export class EmChatTopic { autosize.update($t.get(0)); }); } - }); + }; + + $(this.commentsRef).on('dblclick', '.comment.tms-reply', this.replydblclickHandler); - $(this.commentsRef).on('click', '.markdown-body .at-user', (event) => { + this.atUserHandler = (event) => { event.preventDefault(); ea.publish(nsCons.EVENT_CHAT_TOPIC_MSG_INSERT, { from: this.name, content: `{~${$(event.currentTarget).attr('data-value')}} ` }); - }); + }; - $(this.commentsRef).on('click', '.markdown-body .at-group', (event) => { + $(this.commentsRef).on('click', '.markdown-body .at-user', this.atUserHandler); + + this.atGroupHandler = (event) => { event.preventDefault(); ea.publish(nsCons.EVENT_CHAT_TOPIC_MSG_INSERT, { from: this.name, content: `{!~${$(event.currentTarget).attr('data-value')}} ` }); - }); + }; + + $(this.commentsRef).on('click', '.markdown-body .at-group', this.atGroupHandler); } unbind() { @@ -551,4 +578,8 @@ export class EmChatTopic { content: `{~${item.creator.username}} ` }); } + + commit() { + this.chatTopicInputVm.sendChatMsgHandler(); + } } diff --git a/src/resources/elements/em-dropdown.js b/src/resources/elements/em-dropdown.js index 3795bb8..36996e8 100644 --- a/src/resources/elements/em-dropdown.js +++ b/src/resources/elements/em-dropdown.js @@ -39,4 +39,12 @@ export class EmDropdown { }); } } + + detached() { + window.__debug && console.log('EmDropdown--detached'); + + this.selectedItem = null; + this.menuItems = []; + this.dropdown = null; + } } -- Gitee From cd776636dbe61b3b3124f4f73f5c90f990ae4314 Mon Sep 17 00:00:00 2001 From: xiweicheng Date: Sat, 23 Nov 2019 19:01:21 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E5=88=A4null=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/chat.js | 2 +- src/resources/elements/em-blog-comment.js | 2 +- src/resources/elements/em-chat-topic.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chat/chat.js b/src/chat/chat.js index 978d2d9..43d9e8b 100644 --- a/src/chat/chat.js +++ b/src/chat/chat.js @@ -1084,7 +1084,7 @@ export class Chat { scrollToAfterImgLoaded(to) { _.defer(() => { - new ImagesLoaded(this.commentsRef).always(() => { + this.commentsRef && new ImagesLoaded(this.commentsRef).always(() => { this._scrollTo(to); }); diff --git a/src/resources/elements/em-blog-comment.js b/src/resources/elements/em-blog-comment.js index a980500..52b03d8 100644 --- a/src/resources/elements/em-blog-comment.js +++ b/src/resources/elements/em-blog-comment.js @@ -785,7 +785,7 @@ export class EmBlogComment { scrollToAfterImgLoaded(to) { _.defer(() => { - new ImagesLoaded($('.em-blog-content')[0]).always(() => { + ($('.em-blog-content').length > 0) && new ImagesLoaded($('.em-blog-content')[0]).always(() => { this._scrollTo(to); }); diff --git a/src/resources/elements/em-chat-topic.js b/src/resources/elements/em-chat-topic.js index d9a37a8..6b6e466 100644 --- a/src/resources/elements/em-chat-topic.js +++ b/src/resources/elements/em-chat-topic.js @@ -202,7 +202,7 @@ export class EmChatTopic { scrollToAfterImgLoaded(to) { _.defer(() => { - new ImagesLoaded(this.commentsRef).always(() => { + this.commentsRef && new ImagesLoaded(this.commentsRef).always(() => { this._scrollTo(to); }); -- Gitee From 9d4fc6b025a741b44e218cb11f7b04e570ea237b Mon Sep 17 00:00:00 2001 From: xiweicheng Date: Sat, 23 Nov 2019 19:10:09 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E7=95=8C=E9=9D=A2=E4=BC=98=E5=8C=96...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 2 +- src/environment.js | 4 ++-- src/resources/elements/em-chat-topic.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index ef48322..f4a4fd5 100644 --- a/index.html +++ b/index.html @@ -28,7 +28,7 @@ - + diff --git a/src/environment.js b/src/environment.js index 3495e9a..da32a4b 100644 --- a/src/environment.js +++ b/src/environment.js @@ -1,4 +1,4 @@ export default { - debug: true, - testing: true + debug: false, + testing: false }; diff --git a/src/resources/elements/em-chat-topic.js b/src/resources/elements/em-chat-topic.js index 6b6e466..474d838 100644 --- a/src/resources/elements/em-chat-topic.js +++ b/src/resources/elements/em-chat-topic.js @@ -226,7 +226,7 @@ export class EmChatTopic { this.channel = null; this.members = []; this.chat = []; - this.commentsRef = null; + // this.commentsRef = null; this.ajaxTopic = null; this.followers = null; } -- Gitee From c835feb8a5102b038987edee2f61af4bd092a9f1 Mon Sep 17 00:00:00 2001 From: xiweicheng Date: Sat, 23 Nov 2019 20:46:05 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E7=95=8C=E9=9D=A2=E4=BC=98=E5=8C=96...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 2 +- src/common/common-imgs-loaded.js | 4 ++-- src/environment.js | 4 ++-- src/resources/elements/em-chat-topic.js | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index f4a4fd5..ef48322 100644 --- a/index.html +++ b/index.html @@ -28,7 +28,7 @@ - + diff --git a/src/common/common-imgs-loaded.js b/src/common/common-imgs-loaded.js index 47a67fc..536131b 100644 --- a/src/common/common-imgs-loaded.js +++ b/src/common/common-imgs-loaded.js @@ -132,9 +132,9 @@ function listener(element, eventName, handler, remove) { var events = eventName.split(' '); for (var i = 0, l = events.length; i < l; i++) { - if (element.addEventListener) { + if (element && element.addEventListener) { element[remove ? 'removeEventListener' : 'addEventListener'](events[i], handler, false); - } else if (element.attachEvent) { + } else if (element && element.attachEvent) { element[remove ? 'detachEvent' : 'attachEvent']('on' + events[i], handler); } } diff --git a/src/environment.js b/src/environment.js index da32a4b..3495e9a 100644 --- a/src/environment.js +++ b/src/environment.js @@ -1,4 +1,4 @@ export default { - debug: false, - testing: false + debug: true, + testing: true }; diff --git a/src/resources/elements/em-chat-topic.js b/src/resources/elements/em-chat-topic.js index 474d838..6b6e466 100644 --- a/src/resources/elements/em-chat-topic.js +++ b/src/resources/elements/em-chat-topic.js @@ -226,7 +226,7 @@ export class EmChatTopic { this.channel = null; this.members = []; this.chat = []; - // this.commentsRef = null; + this.commentsRef = null; this.ajaxTopic = null; this.followers = null; } -- Gitee From 29b090ec72542ca49c5812b4a33f2f1aebd5dd2e Mon Sep 17 00:00:00 2001 From: xiweicheng Date: Sun, 24 Nov 2019 12:01:39 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 2 + src/resources/attributes/attr-textcomplete.js | 4 +- src/resources/elements/em-blog-comment.js | 177 ++++++++--- src/resources/elements/em-blog-content.js | 283 ++++++++++++------ src/resources/elements/em-blog-write.js | 161 +++++++--- .../elements/em-chat-content-item.js | 2 +- src/resources/elements/em-chat-input.js | 97 ++++-- src/resources/elements/em-chat-msg.js | 20 +- .../elements/em-chat-sidebar-left.js | 22 +- .../elements/em-chat-sidebar-right.js | 9 + src/resources/elements/em-chat-top-menu.js | 44 ++- src/resources/elements/em-chat-topic-input.js | 103 +++++-- 12 files changed, 691 insertions(+), 233 deletions(-) diff --git a/src/main.js b/src/main.js index 6808377..dc46de4 100644 --- a/src/main.js +++ b/src/main.js @@ -8,6 +8,8 @@ Promise.config({ } }); +// window.__debug = true; + export function configure(aurelia) { aurelia.use .standardConfiguration() diff --git a/src/resources/attributes/attr-textcomplete.js b/src/resources/attributes/attr-textcomplete.js index 820bc28..fefba24 100644 --- a/src/resources/attributes/attr-textcomplete.js +++ b/src/resources/attributes/attr-textcomplete.js @@ -26,7 +26,7 @@ export class AttrTextcompleteCustomAttribute { } valueChanged() { - + if (this.value) { this.members = this.value.users; this.channel = this.value.channel; @@ -159,7 +159,7 @@ export class AttrTextcompleteCustomAttribute { _.each(this.keydowns, (item) => { - $(this.element).unbind('keydown', item.key, item.handler); + $(this.element).unbind('keydown', item.handler); }); this.members = null; diff --git a/src/resources/elements/em-blog-comment.js b/src/resources/elements/em-blog-comment.js index 52b03d8..127927d 100644 --- a/src/resources/elements/em-blog-comment.js +++ b/src/resources/elements/em-blog-comment.js @@ -18,7 +18,7 @@ export class EmBlogComment { offset = 0; isSuper = nsCtx.isSuper; loginUser = nsCtx.loginUser; - users = nsCtx.users; + users; @bindable blog; @@ -26,6 +26,77 @@ export class EmBlogComment { this._refresh(); } + bind() { + this.users = nsCtx.users; + } + + detached() { + window.__debug && console.log('EmBlogComment--detached'); + + this.comments = null; + this.users = null; + this.blog = null; + this.focusedComment = null; + + // 消息popup + $('.em-blog-comment .comments').off('mouseenter', '.markdown-body a[href*="#/blog/"]:not(.pp-not)', this.blogCommentMeHandler); + $('.em-blog-comment .comments').off('mouseleave', '.markdown-body a[href*="#/blog/"]:not(.pp-not)', this.blogCommentMlHandler); + this.blogCommentMeHandler = null; + this.blogCommentMlHandler = null; + + $('.em-blog-comment .comments').off('dblclick', '.comment', this.commentsDblHandler); + $('.em-blog-comment .comments').off('click', '.comment', this.commentsClHandler); + this.commentsDblHandler = null; + this.commentsClHandler = null; + + $(document).unbind('keydown', this.kdRHandler).unbind('keydown', this.kdAltUpHandler).unbind('keydown', this.kdAltDownHandler); + this.kdRHandler = null; + this.kdAltUpHandler = null; + this.kdAltDownHandler = null; + + if (this.$paste) { + this.$paste.off('pasteImage', this.pasteHandler).off('pasteImageError', this.errHandler); + this.pasteHandler = null; + this.errHandler = null; + + this.$paste = null; + } + + $('.CodeMirror-wrap', this.markdownRef).each((index, elem) => { + let dd = Dropzone.forElement(elem); + dd && dd.destroy(); + }); + + $('.editor-toolbar .fa.fa-upload', this.markdownRef).each((index, elem) => { + let dd = Dropzone.forElement(elem); + dd && dd.destroy(); + }); + + $('.editor-toolbar .fa.fa-file-excel-o', this.markdownRef).each((index, elem) => { + let dd = Dropzone.forElement(elem); + dd && dd.destroy(); + }); + this.markdownRef = null; + + try { + + if (this.simplemde) { + this.simplemde.codemirror.off('keyup', this.editKeyHandler); + this.editKeyHandler = null; + + // https://github.com/sparksuite/simplemde-markdown-editor + this.simplemde.toTextArea(); + this.simplemde = null; + } + + $(this.$chatMsgInputRef).textcomplete('destroy'); + this.$chatMsgInputRef = null; + } catch (err) { + console.error(err); + } + + } + /** * 构造函数 */ @@ -174,8 +245,7 @@ export class EmBlogComment { attached() { this._init(); - // 消息popup - $('.em-blog-comment .comments').on('mouseenter', '.markdown-body a[href*="#/blog/"]:not(.pp-not)', (event) => { + this.blogCommentMeHandler = (event) => { event.preventDefault(); let target = event.currentTarget; @@ -199,10 +269,9 @@ export class EmBlogComment { this.hoverTimeoutRef = null; }, 500); - }); + }; - // 消息popup - $('.em-blog-comment .comments').on('mouseleave', '.markdown-body a[href*="#/blog/"]:not(.pp-not)', (event) => { + this.blogCommentMlHandler = (event) => { event.preventDefault(); if (this.hoverTimeoutRef) { if (this.hoverUserTarget === event.currentTarget) { @@ -210,9 +279,13 @@ export class EmBlogComment { this.hoverTimeoutRef = null; } } - }); + }; - $('.em-blog-comment .comments').on('dblclick', '.comment', (event) => { + // 消息popup + $('.em-blog-comment .comments').on('mouseenter', '.markdown-body a[href*="#/blog/"]:not(.pp-not)', this.blogCommentMeHandler); + $('.em-blog-comment .comments').on('mouseleave', '.markdown-body a[href*="#/blog/"]:not(.pp-not)', this.blogCommentMlHandler); + + this.commentsDblHandler = (event) => { if (event.ctrlKey && event.shiftKey) { let cid = $(event.currentTarget).attr('data-id'); let $t = $(event.currentTarget).find('.content > textarea'); @@ -221,33 +294,43 @@ export class EmBlogComment { this.editHandler(item, $t); } } - }); + }; - $('.em-blog-comment .comments').on('click', '.comment', (event) => { + this.commentsClHandler = (event) => { this.focusedComment = $(event.currentTarget); - }); + }; + + $('.em-blog-comment .comments').on('dblclick', '.comment', this.commentsDblHandler); + $('.em-blog-comment .comments').on('click', '.comment', this.commentsClHandler); this.initHotkeys(); } initHotkeys() { - $(document).bind('keydown', 'r', (evt) => { // reply + + this.kdRHandler = (evt) => { // reply evt.preventDefault(); $('.em-blog-content').scrollTo(`max`, 120, { offset: 0 }); this.simplemde.codemirror.focus(); - }).bind('keydown', 'alt+up', (evt) => { // comment pre + }; + + this.kdAltUpHandler = (evt) => { // comment pre evt.preventDefault(); $('.em-blog-content').scrollTo(this.getScrollTargetComment(true), 120, { offset: 0 }); - }).bind('keydown', 'alt+down', (evt) => { // comment next + }; + + this.kdAltDownHandler = (evt) => { // comment next evt.preventDefault(); $('.em-blog-content').scrollTo(this.getScrollTargetComment(), 120, { offset: 0 }); - }); + }; + + $(document).bind('keydown', 'r', this.kdRHandler).bind('keydown', 'alt+up', this.kdAltUpHandler).bind('keydown', 'alt+down', this.kdAltDownHandler); } @@ -412,13 +495,15 @@ export class EmBlogComment { }, }); - this.simplemde.codemirror.on('keyup', (cm, e) => { + this.editKeyHandler = (cm, e) => { if (e.ctrlKey && e.keyCode == 13) { // Ctrl+Enter this.addHandler(); } else if (e.keyCode == 27) { // Esc this.simplemde.value(''); } - }); + }; + + this.simplemde.codemirror.on('keyup', this.editKeyHandler); this.$chatMsgInputRef = $(this.markdownRef).find('.CodeMirror textarea'); if (this.$chatMsgInputRef.size() === 0) { @@ -607,9 +692,12 @@ export class EmBlogComment { _reset() { this.blog = null; - this.simplemde.value(''); - this.simplemde.toTextArea(); - this.simplemde = null; + + if (this.simplemde) { + this.simplemde.value(''); + this.simplemde.toTextArea(); + this.simplemde = null; + } } /** @@ -698,31 +786,38 @@ export class EmBlogComment { initPaste() { - let $paste; if (this.$chatMsgInputRef.is('textarea')) { - $paste = $(this.$chatMsgInputRef).pastableTextarea(); + this.$paste = $(this.$chatMsgInputRef).pastableTextarea(); } else { - $paste = $(this.$chatMsgInputRef).pastableContenteditable(); + this.$paste = $(this.$chatMsgInputRef).pastableContenteditable(); } - $paste && ($paste.on('pasteImage', (ev, data) => { - - $.post('/admin/file/base64', { - dataURL: data.dataURL, - type: data.blob.type, - toType: 'Blog' - }, (data, textStatus, xhr) => { - if (data.success) { - this.insertContent('![{name}]({baseURL}{path}{uuidName})' - .replace(/\{name\}/g, data.data.name) - .replace(/\{baseURL\}/g, utils.getBaseUrl() + '/') - .replace(/\{path\}/g, data.data.path) - .replace(/\{uuidName\}/g, data.data.uuidName)); - } - }); - }).on('pasteImageError', (ev, data) => { - toastr.error(data.message, '剪贴板粘贴图片错误!'); - })); + if (this.$paste) { + + this.pasteHandler = (ev, data) => { + + $.post('/admin/file/base64', { + dataURL: data.dataURL, + type: data.blob.type, + toType: 'Blog' + }, (data, textStatus, xhr) => { + if (data.success) { + this.insertContent('![{name}]({baseURL}{path}{uuidName})' + .replace(/\{name\}/g, data.data.name) + .replace(/\{baseURL\}/g, utils.getBaseUrl() + '/') + .replace(/\{path\}/g, data.data.path) + .replace(/\{uuidName\}/g, data.data.uuidName)); + } + }); + }; + + this.errHandler = (ev, data) => { + toastr.error(data.message, '剪贴板粘贴图片错误!'); + }; + + this.$paste.on('pasteImage', this.pasteHandler).on('pasteImageError', this.errHandler); + + } } initUploadDropzone(domRef, getInputTargetCb, clickable) { diff --git a/src/resources/elements/em-blog-content.js b/src/resources/elements/em-blog-content.js index a600df4..71c4153 100644 --- a/src/resources/elements/em-blog-content.js +++ b/src/resources/elements/em-blog-content.js @@ -13,9 +13,15 @@ export class EmBlogContent { blog; - loginUser = nsCtx.loginUser; - isSuper = nsCtx.isSuper; - isAdmin = nsCtx.isAdmin; + loginUser; + isSuper; + isAdmin; + + bind() { + this.loginUser = nsCtx.loginUser; + this.isSuper = nsCtx.isSuper; + this.isAdmin = nsCtx.isAdmin; + } /** * 构造函数 @@ -289,6 +295,59 @@ export class EmBlogContent { this.subscribe7.dispose(); } + detached() { + window.__debug && console.log('EmBlogContent--detached'); + + this.blog = null; + this.loginUser = null; + this.isSuper = null; + this.isAdmin = null; + + $('.em-blog-content').off('click', 'code[data-code]', this.codeClHandler); + $('.em-blog-content').off('click', '.pre-code-wrapper', this.preCodeClHandler); + $('.em-blog-right-sidebar').off('click', '.panel-blog-dir .wiki-dir-item', this.wikiDirClHandler); + $(this.mkbodyRef).off('dblclick', this.mkDblHandler); + $('.em-blog-content').off('scroll', this.blogContentScrollHandler); + $(this.feedRef).off('mouseenter', '.event a[href*="#/blog/"]:not(.pp-not)', this.feedMeHandler); + $(this.feedRef).off('mouseleave', '.event a[href*="#/blog/"]:not(.pp-not)', this.feedMlHandler); + $('.tms-blog').off('mouseenter', 'span[data-value].at-user:not(.pp-not),span[data-value].at-group:not(.pp-not),a[data-value].author:not(.pp-not)', this.userInfoMeHandler); + $('.tms-blog').off('mouseleave', 'span[data-value].at-user:not(.pp-not),span[data-value].at-group:not(.pp-not),a[data-value].author:not(.pp-not)', this.userInfoMlHandler); + + window.removeEventListener && window.removeEventListener('message', this.messageHandler, false); + + this.codeClHandler = null; + this.preCodeClHandler = null; + this.wikiDirClHandler = null; + this.mkDblHandler = null; + this.blogContentScrollHandler = null; + this.feedMeHandler = null; + this.feedMlHandler = null; + this.userInfoMeHandler = null; + this.userInfoMlHandler = null; + this.messageHandler = null; + + try { + $(document).unbind('keyup', this.docKuEHandler) + .unbind('keyup', this.docKuWHandler) + .unbind('keydown', this.docKuDHandler) + .unbind('keydown', this.docKuSHandler) + .unbind('keydown', this.docKuFHandler) + .unbind('keydown', this.docKuTHandler) + .unbind('keydown', this.docKuBHandler) + .unbind('keydown', this.docKuAltRHandler) + .unbind('keydown', this.docKuAltHHandler) + .unbind('keydown', this.docKuAltLHandler) + .unbind('keydown', this.docKuAltSHandler) + .unbind('keydown', this.docKuAltCHandler) + .unbind('keydown', this.docKuAltMHandler) + .unbind('keydown', this.docKuAltOHandler) + .unbind('keydown', this.docKuAltTHandler) + .unbind('keydown', this.docKuAltEHandler) + .unbind('keydown', this.docKuAltCtrlDHandler); + } catch (err) { console.log(err); } + + } + /** * 当视图被附加到DOM中时被调用 */ @@ -302,7 +361,7 @@ export class EmBlogContent { toastr.error('复制到剪贴板失败!'); }); - $('.em-blog-content').on('click', 'code[data-code]', function(event) { + this.codeClHandler = function(event) { if (event.ctrlKey || event.metaKey) { event.stopImmediatePropagation(); event.preventDefault(); @@ -311,9 +370,9 @@ export class EmBlogContent { (err) => { toastr.error('复制到剪贴板失败!'); } ); } - }); + }; - $('.em-blog-content').on('click', '.pre-code-wrapper', function(event) { + this.preCodeClHandler = function(event) { if (event.ctrlKey || event.metaKey) { event.stopImmediatePropagation(); event.preventDefault(); @@ -322,9 +381,12 @@ export class EmBlogContent { (err) => { toastr.error('复制到剪贴板失败!'); } ); } - }); + }; - $('.em-blog-right-sidebar').on('click', '.panel-blog-dir .wiki-dir-item', (event) => { + $('.em-blog-content').on('click', 'code[data-code]', this.codeClHandler); + $('.em-blog-content').on('click', '.pre-code-wrapper', this.preCodeClHandler); + + this.wikiDirClHandler = (event) => { event.preventDefault(); if ($(window).width() <= 768) { ea.publish(nsCons.EVENT_BLOG_RIGHT_SIDEBAR_TOGGLE, { isHide: true }); @@ -332,17 +394,21 @@ export class EmBlogContent { $('.em-blog-content').scrollTo(`#${$(event.currentTarget).attr('data-id')}`, 200, { offset: 0 }); - }); + }; - $(this.mkbodyRef).on('dblclick', (event) => { + $('.em-blog-right-sidebar').on('click', '.panel-blog-dir .wiki-dir-item', this.wikiDirClHandler); + + this.mkDblHandler = (event) => { if (event.ctrlKey && event.shiftKey) { if (this.blog.openEdit || this.isSuper || this.blog.creator.username == this.loginUser.username) { this.editHandler(); } } - }); + }; - $('.em-blog-content').scroll(_.throttle((event) => { + $(this.mkbodyRef).on('dblclick', this.mkDblHandler); + + this.blogContentScrollHandler = _.throttle((event) => { try { let sHeight = $('.em-blog-content')[0].scrollHeight; let sTop = $('.em-blog-content')[0].scrollTop; @@ -354,10 +420,11 @@ export class EmBlogContent { } catch (err) { this.progressWidth = 0; } - }, 10)); + }, 10); - // 消息popup - $(this.feedRef).on('mouseenter', '.event a[href*="#/blog/"]:not(.pp-not)', (event) => { + $('.em-blog-content').scroll(this.blogContentScrollHandler); + + this.feedMeHandler = (event) => { event.preventDefault(); let target = event.currentTarget; let cid = utils.urlQuery('cid', $(target).attr('href')); @@ -379,10 +446,9 @@ export class EmBlogContent { }); this.hoverTimeoutRef = null; }, 500); - }); + }; - // 消息popup - $(this.feedRef).on('mouseleave', '.event a[href*="#/blog/"]:not(.pp-not)', (event) => { + this.feedMlHandler = (event) => { event.preventDefault(); if (this.hoverTimeoutRef) { if (this.hoverUserTarget === event.currentTarget) { @@ -390,10 +456,13 @@ export class EmBlogContent { this.hoverTimeoutRef = null; } } - }); + }; - // 用户信息popup - $('.tms-blog').on('mouseenter', 'span[data-value].at-user:not(.pp-not),span[data-value].at-group:not(.pp-not),a[data-value].author:not(.pp-not)', (event) => { + // 消息popup + $(this.feedRef).on('mouseenter', '.event a[href*="#/blog/"]:not(.pp-not)', this.feedMeHandler); + $(this.feedRef).on('mouseleave', '.event a[href*="#/blog/"]:not(.pp-not)', this.feedMlHandler); + + this.userInfoMeHandler = (event) => { event.preventDefault(); let target = event.currentTarget; @@ -416,10 +485,9 @@ export class EmBlogContent { }); this.hoverTimeoutRef = null; }, 500); - }); + }; - // 用户信息popup - $('.tms-blog').on('mouseleave', 'span[data-value].at-user:not(.pp-not),span[data-value].at-group:not(.pp-not),a[data-value].author:not(.pp-not)', (event) => { + this.userInfoMlHandler = (event) => { event.preventDefault(); if (this.hoverTimeoutRef) { if (this.hoverUserTarget === event.currentTarget) { @@ -427,11 +495,14 @@ export class EmBlogContent { this.hoverTimeoutRef = null; } } - }); + }; + // 用户信息popup + $('.tms-blog').on('mouseenter', 'span[data-value].at-user:not(.pp-not),span[data-value].at-group:not(.pp-not),a[data-value].author:not(.pp-not)', this.userInfoMeHandler); + $('.tms-blog').on('mouseleave', 'span[data-value].at-user:not(.pp-not),span[data-value].at-group:not(.pp-not),a[data-value].author:not(.pp-not)', this.userInfoMlHandler); this.initHotkeys(); - window.addEventListener && window.addEventListener('message', function(ev) { + this.messageHandler = function(ev) { // console.info('message from parent:', ev.data); if (ev.origin != window.location.origin) return; @@ -444,7 +515,9 @@ export class EmBlogContent { ev.data.from = 'html'; ea.publish(nsCons.EVENT_BLOG_CHANGED, ev.data); - }, false); + }; + + window.addEventListener && window.addEventListener('message', this.messageHandler, false); } fixDirItem() { @@ -478,67 +551,103 @@ export class EmBlogContent { } initHotkeys() { - try { - $(document).bind('keyup', 'e', (evt) => { // edit - evt.preventDefault(); - if (this.blog.openEdit || this.isSuper || this.blog.creator.username == this.loginUser.username) { - this.throttleEditHandler(); - } - }).bind('keyup', 'w', (evt) => { // create - evt.preventDefault(); - this.throttleCreateHandler(); - }).bind('keydown', 'd', (evt) => { // dir - evt.preventDefault(); - if (this.dir) { - this.catalogHandler(); - } - }).bind('keydown', 's', (evt) => { // share - evt.preventDefault(); - this.blogShareVm.show(); - }).bind('keydown', 'f', (evt) => { // follow - evt.preventDefault(); - this.followerHandler(); - }).bind('keydown', 't', (event) => { // scroll top - event.preventDefault(); - $('.em-blog-content').scrollTo(0, 200, { - offset: 0 - }); - }).bind('keydown', 'b', (event) => { // scroll bottom - event.preventDefault(); - $('.em-blog-content').scrollTo(`max`, 200, { - offset: 0 - }); - }).bind('keydown', 'alt+r', (event) => { // refresh - event.preventDefault(); - this.refreshHandler(); - }).bind('keydown', 'alt+h', (event) => { // history - event.preventDefault(); - this.historyHandler(); - }).bind('keydown', 'alt+l', (event) => { // history - event.preventDefault(); - this.authHandler(); - }).bind('keydown', 'alt+s', (event) => { // stow - event.preventDefault(); - this.stowHandler(); - }).bind('keydown', 'alt+c', (event) => { // copy - event.preventDefault(); - this.throttleCopyHandler(); - }).bind('keydown', 'alt+m', (event) => { // move space - event.preventDefault(); - this.updateSpaceHandler(); - }).bind('keydown', 'alt+o', (event) => { // open edit - event.preventDefault(); - this.openEditHandler(); - }).bind('keydown', 'alt+t', (event) => { // tpl edit - event.preventDefault(); - this.tplEditHandler(); - }).bind('keydown', 'alt+e', (event) => { // change editor - event.preventDefault(); - this.changeEditorHandler(); - }).bind('keydown', 'alt+ctrl+d', (event) => { // delete - event.preventDefault(); - this.deleteHandler(); + + + this.docKuEHandler = (evt) => { // edit + evt.preventDefault(); + if (this.blog.openEdit || this.isSuper || this.blog.creator.username == this.loginUser.username) { + this.throttleEditHandler(); + } + }; + this.docKuWHandler = (evt) => { // create + evt.preventDefault(); + this.throttleCreateHandler(); + }; + this.docKuDHandler = (evt) => { // dir + evt.preventDefault(); + if (this.dir) { + this.catalogHandler(); + } + }; + this.docKuSHandler = (evt) => { // share + evt.preventDefault(); + this.blogShareVm.show(); + }; + this.docKuFHandler = (evt) => { // follow + evt.preventDefault(); + this.followerHandler(); + }; + this.docKuTHandler = (event) => { // scroll top + event.preventDefault(); + $('.em-blog-content').scrollTo(0, 200, { + offset: 0 + }); + }; + this.docKuBHandler = (event) => { // scroll bottom + event.preventDefault(); + $('.em-blog-content').scrollTo(`max`, 200, { + offset: 0 }); + }; + this.docKuAltRHandler = (event) => { // refresh + event.preventDefault(); + this.refreshHandler(); + }; + this.docKuAltHHandler = (event) => { // history + event.preventDefault(); + this.historyHandler(); + }; + this.docKuAltLHandler = (event) => { // auth + event.preventDefault(); + this.authHandler(); + }; + this.docKuAltSHandler = (event) => { // stow + event.preventDefault(); + this.stowHandler(); + }; + this.docKuAltCHandler = (event) => { // copy + event.preventDefault(); + this.throttleCopyHandler(); + }; + this.docKuAltMHandler = (event) => { // move space + event.preventDefault(); + this.updateSpaceHandler(); + }; + this.docKuAltOHandler = (event) => { // open edit + event.preventDefault(); + this.openEditHandler(); + }; + this.docKuAltTHandler = (event) => { // tpl edit + event.preventDefault(); + this.tplEditHandler(); + }; + this.docKuAltEHandler = (event) => { // change editor + event.preventDefault(); + this.changeEditorHandler(); + }; + this.docKuAltCtrlDHandler = (event) => { // delete + event.preventDefault(); + this.deleteHandler(); + }; + + try { + $(document).bind('keyup', 'e', this.docKuEHandler) + .bind('keyup', 'w', this.docKuWHandler) + .bind('keydown', 'd', this.docKuDHandler) + .bind('keydown', 's', this.docKuSHandler) + .bind('keydown', 'f', this.docKuFHandler) + .bind('keydown', 't', this.docKuTHandler) + .bind('keydown', 'b', this.docKuBHandler) + .bind('keydown', 'alt+r', this.docKuAltRHandler) + .bind('keydown', 'alt+h', this.docKuAltHHandler) + .bind('keydown', 'alt+l', this.docKuAltLHandler) + .bind('keydown', 'alt+s', this.docKuAltSHandler) + .bind('keydown', 'alt+c', this.docKuAltCHandler) + .bind('keydown', 'alt+m', this.docKuAltMHandler) + .bind('keydown', 'alt+o', this.docKuAltOHandler) + .bind('keydown', 'alt+t', this.docKuAltTHandler) + .bind('keydown', 'alt+e', this.docKuAltEHandler) + .bind('keydown', 'alt+ctrl+d', this.docKuAltCtrlDHandler); } catch (err) { console.log(err); } } diff --git a/src/resources/elements/em-blog-write.js b/src/resources/elements/em-blog-write.js index 87780a0..13c7ba2 100644 --- a/src/resources/elements/em-blog-write.js +++ b/src/resources/elements/em-blog-write.js @@ -16,6 +16,64 @@ export class EmBlogWrite { baseRes = utils.getResourceBase(); + detached() { + + window.__debug && console.log('EmBlogWrite--detached'); + + this.members = null; + this.blog = null; + + if (this.$paste) { + this.$paste.off('pasteImage', this.pasteHandler).off('pasteImageError', this.errHandler); + this.pasteHandler = null; + this.errHandler = null; + + this.$paste = null; + } + + $('#blog-save-btn').off('click', this.blogSaveHandler); + $('#switch-html').off('click', this.switchHandler); + + this.blogSaveHandler = null; + this.switchHandler = null; + + $('#blog-title-input').off('keyup', this.blogTitleInputKuHandler); + + $('.CodeMirror-wrap', '#txt-blog-write-wrapper').each((index, elem) => { + let dd = Dropzone.forElement(elem); + dd && dd.destroy(); + }); + + $('.editor-toolbar .fa.fa-upload', '#txt-blog-write-wrapper').each((index, elem) => { + let dd = Dropzone.forElement(elem); + dd && dd.destroy(); + }); + + $('.editor-toolbar .fa.fa-file-excel-o', '#txt-blog-write-wrapper').each((index, elem) => { + let dd = Dropzone.forElement(elem); + dd && dd.destroy(); + }); + + try { + + $(this.$chatMsgInputRef).textcomplete('destroy'); + this.$chatMsgInputRef = null; + + if (this.simplemde) { + + this.simplemde.codemirror.off('keyup', this.editKuHandler); + this.editKuHandler = null; + + this.simplemde.value(''); + this.simplemde.toTextArea(); + this.simplemde = null; + } + + } catch (err) { + console.error(err); + } + } + /** * 构造函数 */ @@ -53,23 +111,25 @@ export class EmBlogWrite { }); - this.blogTitleInputKeyupInit = _.once(() => { - $('#blog-title-input').keyup((e) => { - let $t = $(e.currentTarget); + this.blogTitleInputKuHandler = (e) => { + let $t = $(e.currentTarget); - if (!e.shiftKey && e.keyCode == 13) { // Enter - if (this.simplemde.value()) { - this.save(e, true); - } else { - this.simplemde.codemirror.focus(); - } - - } else if (e.shiftKey && e.keyCode == 13) { // Esc + if (!e.shiftKey && e.keyCode == 13) { // Enter + if (this.simplemde.value()) { + this.save(e, true); + } else { this.simplemde.codemirror.focus(); - } else if (e.keyCode == 27) { // Esc - $t.val(''); } - }); + + } else if (e.shiftKey && e.keyCode == 13) { // Esc + this.simplemde.codemirror.focus(); + } else if (e.keyCode == 27) { // Esc + $t.val(''); + } + }; + + this.blogTitleInputKeyupInit = _.once(() => { + $('#blog-title-input').keyup(this.blogTitleInputKuHandler); }); } @@ -89,9 +149,12 @@ export class EmBlogWrite { $('#blog-save-btn span').text('保存'); $('#blog-save-btn').attr('title', 'ctrl+click快速保存'); $('#blog-title-input').val(''); - this.simplemde.value(''); - this.simplemde.toTextArea(); - this.simplemde = null; + if (this.simplemde) { + this.simplemde.value(''); + this.simplemde.toTextArea(); + this.simplemde = null; + } + } _editInit() { @@ -276,7 +339,7 @@ export class EmBlogWrite { }, }); - this.simplemde.codemirror.on('keyup', (cm, e) => { + this.editKuHandler = (cm, e) => { if (e.ctrlKey && e.keyCode == 13) { // Ctrl+Enter this.save(e, true); } else if (e.keyCode == 27) { // Esc @@ -290,7 +353,9 @@ export class EmBlogWrite { } } } - }); + }; + + this.simplemde.codemirror.on('keyup', this.editKuHandler); this.$chatMsgInputRef = $('#txt-blog-write-wrapper').find('.CodeMirror textarea'); if (this.$chatMsgInputRef.size() === 0) { @@ -488,31 +553,37 @@ export class EmBlogWrite { initPaste() { - let $paste; if (this.$chatMsgInputRef.is('textarea')) { - $paste = $(this.$chatMsgInputRef).pastableTextarea(); + this.$paste = $(this.$chatMsgInputRef).pastableTextarea(); } else { - $paste = $(this.$chatMsgInputRef).pastableContenteditable(); + this.$paste = $(this.$chatMsgInputRef).pastableContenteditable(); } - $paste && ($paste.on('pasteImage', (ev, data) => { + if (this.$paste) { - $.post('/admin/file/base64', { - dataURL: data.dataURL, - type: data.blob.type, - toType: 'Blog' - }, (data, textStatus, xhr) => { - if (data.success) { - this.insertContent('![{name}]({baseURL}{path}{uuidName})' - .replace(/\{name\}/g, data.data.name) - .replace(/\{baseURL\}/g, utils.getBaseUrl() + '/') - .replace(/\{path\}/g, data.data.path) - .replace(/\{uuidName\}/g, data.data.uuidName)); - } - }); - }).on('pasteImageError', (ev, data) => { - toastr.error(data.message, '剪贴板粘贴图片错误!'); - })); + this.pasteHandler = (ev, data) => { + + $.post('/admin/file/base64', { + dataURL: data.dataURL, + type: data.blob.type, + toType: 'Blog' + }, (data, textStatus, xhr) => { + if (data.success) { + this.insertContent('![{name}]({baseURL}{path}{uuidName})' + .replace(/\{name\}/g, data.data.name) + .replace(/\{baseURL\}/g, utils.getBaseUrl() + '/') + .replace(/\{path\}/g, data.data.path) + .replace(/\{uuidName\}/g, data.data.uuidName)); + } + }); + }; + + this.errHandler = (ev, data) => { + toastr.error(data.message, '剪贴板粘贴图片错误!'); + }; + + this.$paste.on('pasteImage', this.pasteHandler).on('pasteImageError', this.errHandler); + } } initUploadDropzone(domRef, getInputTargetCb, clickable) { @@ -599,13 +670,17 @@ export class EmBlogWrite { * 当视图被附加到DOM中时被调用 */ attached() { - $('#blog-save-btn').click((event) => { + + this.blogSaveHandler = (event) => { this.save(event); - }); + }; - $('#switch-html').click((event) => { + this.switchHandler = (event) => { this.switchEditorHandler(); - }); + }; + + $('#blog-save-btn').click(this.blogSaveHandler); + $('#switch-html').click(this.switchHandler); } save(event, isKey) { diff --git a/src/resources/elements/em-chat-content-item.js b/src/resources/elements/em-chat-content-item.js index 7b32480..1a51321 100644 --- a/src/resources/elements/em-chat-content-item.js +++ b/src/resources/elements/em-chat-content-item.js @@ -142,7 +142,7 @@ export class EmChatContentItem { detached() { - $(document).unbind('keydown', 'e', this.keydownHandler); + $(document).unbind('keydown', this.keydownHandler); $('.tms-content-body').off('click', '.markdown-body .at-user', this.atUserHandler); $('.tms-content-body').off('click', '.markdown-body .at-group', this.atGroupHandler); $('.tms-chat').off('mouseenter', '.markdown-body a[href*="#/chat/"]:not(.pp-not)', this.msgPpMiHandler); diff --git a/src/resources/elements/em-chat-input.js b/src/resources/elements/em-chat-input.js index 102c651..a7201b3 100644 --- a/src/resources/elements/em-chat-input.js +++ b/src/resources/elements/em-chat-input.js @@ -5,6 +5,9 @@ import emojis from 'common/common-emoji'; import { default as SimpleMDE } from 'simplemde'; +import { + default as Dropzone +} from 'dropzone'; @containerless export class EmChatInput { @@ -68,39 +71,87 @@ export class EmChatInput { detached() { window.__debug && console.log('EmChatInput--detached'); + + this.chatTo = null; + this.isAt = null; + this.channel = null; + this.members = []; + + if (this.$paste) { + this.$paste.off('pasteImage', this.pasteHandler).off('pasteImageError', this.errHandler); + this.pasteHandler = null; + this.errHandler = null; + + this.$paste = null; + } + + $(this.chatBtnRef).popup('destroy'); + this.chatBtnRef = null; + + $('.CodeMirror-wrap', this.inputRef).each((index, elem) => { + let dd = Dropzone.forElement(elem); + dd && dd.destroy(); + }); + this.inputRef = null; + + $(this.btnItemUploadRef).children().andSelf().each((index, elem) => { + let dd = Dropzone.forElement(elem); + dd && dd.destroy(); + }); + this.btnItemUploadRef = null; + + $(this.btnItemCsvRef).children().andSelf().each((index, elem) => { + let dd = Dropzone.forElement(elem); + dd && dd.destroy(); + }); + this.btnItemCsvRef = null; + try { + // https://github.com/sparksuite/simplemde-markdown-editor + this.simplemde.toTextArea(); + this.simplemde = null; + $(this.$chatMsgInputRef).textcomplete('destroy'); - } catch (err) {} + this.$chatMsgInputRef = null; + } catch (err) { + console.error(err); + } + } initPaste() { - let $paste; if (this.$chatMsgInputRef.is('textarea')) { - $paste = $(this.$chatMsgInputRef).pastableTextarea(); + this.$paste = $(this.$chatMsgInputRef).pastableTextarea(); } else { - $paste = $(this.$chatMsgInputRef).pastableContenteditable(); + this.$paste = $(this.$chatMsgInputRef).pastableContenteditable(); } - $paste && ($paste.on('pasteImage', (ev, data) => { - - $.post('/admin/file/base64', { - dataURL: data.dataURL, - type: data.blob.type, - toType: nsCtx.isAt ? 'User' : 'Channel', - toId: nsCtx.chatTo - }, (data, textStatus, xhr) => { - if (data.success) { - this.insertContent('![{name}]({baseURL}{path}{uuidName})' - .replace(/\{name\}/g, data.data.name) - .replace(/\{baseURL\}/g, utils.getBaseUrl() + '/') - .replace(/\{path\}/g, data.data.path) - .replace(/\{uuidName\}/g, data.data.uuidName)); - } - }); - }).on('pasteImageError', (ev, data) => { - toastr.error(data.message, '剪贴板粘贴图片错误!'); - })); + if (this.$paste) { + + this.pasteHandler = (ev, data) => { + + $.post('/admin/file/base64', { + dataURL: data.dataURL, + type: data.blob.type, + toType: nsCtx.isAt ? 'User' : 'Channel', + toId: nsCtx.chatTo + }, (data, textStatus, xhr) => { + if (data.success) { + this.insertContent('![{name}]({baseURL}{path}{uuidName})' + .replace(/\{name\}/g, data.data.name) + .replace(/\{baseURL\}/g, utils.getBaseUrl() + '/') + .replace(/\{path\}/g, data.data.path) + .replace(/\{uuidName\}/g, data.data.uuidName)); + } + }); + }; + + this.errHandler = (ev, data) => { + toastr.error(data.message, '剪贴板粘贴图片错误!'); + }; + this.$paste.on('pasteImage', this.pasteHandler).on('pasteImageError', this.errHandler); + } } initDropzone() { diff --git a/src/resources/elements/em-chat-msg.js b/src/resources/elements/em-chat-msg.js index df27b07..f8d89d8 100644 --- a/src/resources/elements/em-chat-msg.js +++ b/src/resources/elements/em-chat-msg.js @@ -20,12 +20,28 @@ export class EmChatMsg { this.initHotkeys(); } + detached() { + window.__debug && console.log('EmChatMsg--detached'); + + $(document).unbind('keydown', this.openKeydownHandler); + + this.openKeydownHandler = null; + this.loginUser = null; + this.channel = null; + this.chats = null; + this.actived = null; + + } + initHotkeys() { - $(document).bind('keydown', 'o', (event) => { + + this.openKeydownHandler = (event) => { event.preventDefault(); let item = _.find(this.chats, { isHover: true }); item && (item.isOpen = !item.isOpen); - }); + }; + + $(document).bind('keydown', 'o', this.openKeydownHandler); } diff --git a/src/resources/elements/em-chat-sidebar-left.js b/src/resources/elements/em-chat-sidebar-left.js index 80cd6f0..3b405bb 100644 --- a/src/resources/elements/em-chat-sidebar-left.js +++ b/src/resources/elements/em-chat-sidebar-left.js @@ -54,13 +54,29 @@ export class EmChatSidebarLeft { this.subscribe2.dispose(); } + detached() { + window.__debug && console.log('EmChatSidebarLeft--detached'); + + $(this.logoRef).off('mouseenter', this.logoMeHandler); + + this.logoMeHandler = null; + this.users = null; + this.loginUser = null; + this.channels = null; + this.onlines = null; + + } + /** * 当视图被附加到DOM中时被调用 */ attached() { - $(this.logoRef).on('mouseenter', (event) => { + + this.logoMeHandler = (event) => { $(this.logoRef).animateCss('flip'); - }); + }; + + $(this.logoRef).on('mouseenter', this.logoMeHandler); } _filter() { @@ -164,7 +180,7 @@ export class EmChatSidebarLeft { // } isSubscribed(item) { - return _.some(item.subscriber, { username: this.loginUser.username }); + return _.some(item.subscriber, { username: this.loginUser ? this.loginUser.username : '' }); } subscribeHandler(item) { diff --git a/src/resources/elements/em-chat-sidebar-right.js b/src/resources/elements/em-chat-sidebar-right.js index 7948987..bc5e81f 100644 --- a/src/resources/elements/em-chat-sidebar-right.js +++ b/src/resources/elements/em-chat-sidebar-right.js @@ -56,6 +56,15 @@ export class EmChatSidebarRight { this.subscribe2.dispose(); } + detached() { + window.__debug && console.log('EmChatSidebarRight--detached'); + + this.loginUser = null; + this.channels = null; + this.actived = null; + + } + attachHandler(payload) { this.chatAttachVm.fetch(); } diff --git a/src/resources/elements/em-chat-top-menu.js b/src/resources/elements/em-chat-top-menu.js index 23d57e8..8a0994d 100644 --- a/src/resources/elements/em-chat-top-menu.js +++ b/src/resources/elements/em-chat-top-menu.js @@ -30,6 +30,29 @@ export class EmChatTopMenu { channelLinks = []; channelGantts = []; + + detached() { + window.__debug && console.log('EmChatTopMenu--detached'); + + window.removeEventListener && window.removeEventListener('message', this.messageHandler, false); + $(document).unbind('keydown', this.sidebarHandler); + + this.messageHandler = null; + this.sidebarHandler = null; + + this.loginUser = null; + this.chatUser = null; + this.users = null; + this.channels = null; + this.channel = null; + this.chatId = null; + this.chatTo = null; + this.onlines = null; + this.channelLinks = []; + this.channelGantts = []; + + } + loginUserChanged() { if (this.loginUser) { this.isSuper = utils.isSuperUser(this.loginUser); @@ -242,14 +265,16 @@ export class EmChatTopMenu { } }); - window.addEventListener && window.addEventListener('message', function(ev) { + this.messageHandler = function(ev) { // console.info('message from parent:', ev.data); if (ev.origin != window.location.origin) return; if (ev.data.source != 'gantt') return; ea.publish(nsCons.EVENT_CHANNEL_GANTTS_REFRESH, ev.data); - }, false); + }; + + window.addEventListener && window.addEventListener('message', this.messageHandler, false); $('.tms-em-chat-top-menu .tms-notice').css({ 'max-width': $(window).width() - 1000 }); } @@ -360,16 +385,17 @@ export class EmChatTopMenu { } initHotkeys() { - $(document).bind('keydown', 's', (event) => { // sidebar + + this.sidebarHandler = (event) => { // sidebar event.preventDefault(); this.toggleRightSidebar(); - }).bind('keydown', 'ctrl+k', (event) => { - event.preventDefault(); - }); + }; - $(this.filterChatToUser).bind('keydown', 'ctrl+k', (event) => { - event.preventDefault(); - }); + $(document).bind('keydown', 's', this.sidebarHandler); + + // $(this.filterChatToUser).bind('keydown', 'ctrl+k', (event) => { + // event.preventDefault(); + // }); } searchFocusHandler() { diff --git a/src/resources/elements/em-chat-topic-input.js b/src/resources/elements/em-chat-topic-input.js index c38f551..78baa05 100644 --- a/src/resources/elements/em-chat-topic-input.js +++ b/src/resources/elements/em-chat-topic-input.js @@ -5,6 +5,9 @@ import emojis from 'common/common-emoji'; import { default as SimpleMDE } from 'simplemde'; +import { + default as Dropzone +} from 'dropzone'; @containerless export class EmChatTopicInput { @@ -46,6 +49,56 @@ export class EmChatTopicInput { this.subscribe2.dispose(); } + detached() { + window.__debug && console.log('EmChatTopicInput--detached'); + + this.channel = null; + this.chat = null; + this.name = null; + this.members = []; + + if (this.$paste) { + this.$paste.off('pasteImage', this.pasteHandler).off('pasteImageError', this.errHandler); + this.pasteHandler = null; + this.errHandler = null; + + this.$paste = null; + } + + $(this.chatBtnRef).popup('destroy'); + this.chatBtnRef = null; + + $('.CodeMirror-wrap', this.inputRef).each((index, elem) => { + let dd = Dropzone.forElement(elem); + dd && dd.destroy(); + }); + this.inputRef = null; + + $(this.btnItemUploadRef).children().andSelf().each((index, elem) => { + let dd = Dropzone.forElement(elem); + dd && dd.destroy(); + }); + this.btnItemUploadRef = null; + + $(this.btnItemCsvRef).children().andSelf().each((index, elem) => { + let dd = Dropzone.forElement(elem); + dd && dd.destroy(); + }); + this.btnItemCsvRef = null; + + try { + // https://github.com/sparksuite/simplemde-markdown-editor + this.simplemde.toTextArea(); + this.simplemde = null; + + $(this.$chatMsgInputRef).textcomplete('destroy'); + this.$chatMsgInputRef = null; + } catch (err) { + console.error(err); + } + + } + /** * 当视图被附加到DOM中时被调用 */ @@ -57,32 +110,38 @@ export class EmChatTopicInput { initPaste() { - let $paste; if (this.$chatMsgInputRef.is('textarea')) { - $paste = $(this.$chatMsgInputRef).pastableTextarea(); + this.$paste = $(this.$chatMsgInputRef).pastableTextarea(); } else { - $paste = $(this.$chatMsgInputRef).pastableContenteditable(); + this.$paste = $(this.$chatMsgInputRef).pastableContenteditable(); } - $paste && ($paste.on('pasteImage', (ev, data) => { - - $.post('/admin/file/base64', { - dataURL: data.dataURL, - type: data.blob.type, - toType: nsCtx.isAt ? 'User' : 'Channel', - toId: nsCtx.chatTo - }, (data, textStatus, xhr) => { - if (data.success) { - this.insertContent('![{name}]({baseURL}{path}{uuidName})' - .replace(/\{name\}/g, data.data.name) - .replace(/\{baseURL\}/g, utils.getBaseUrl() + '/') - .replace(/\{path\}/g, data.data.path) - .replace(/\{uuidName\}/g, data.data.uuidName)); - } - }); - }).on('pasteImageError', (ev, data) => { - toastr.error(data.message, '剪贴板粘贴图片错误!'); - })); + if (this.$paste) { + + this.pasteHandler = (ev, data) => { + + $.post('/admin/file/base64', { + dataURL: data.dataURL, + type: data.blob.type, + toType: nsCtx.isAt ? 'User' : 'Channel', + toId: nsCtx.chatTo + }, (data, textStatus, xhr) => { + if (data.success) { + this.insertContent('![{name}]({baseURL}{path}{uuidName})' + .replace(/\{name\}/g, data.data.name) + .replace(/\{baseURL\}/g, utils.getBaseUrl() + '/') + .replace(/\{path\}/g, data.data.path) + .replace(/\{uuidName\}/g, data.data.uuidName)); + } + }); + }; + + this.errHandler = (ev, data) => { + toastr.error(data.message, '剪贴板粘贴图片错误!'); + }; + + this.$paste.on('pasteImage', this.pasteHandler).on('pasteImageError', this.errHandler); + } } initDropzone() { -- Gitee