From 91ac67db9e199e8be4928725d552dbe71307b3f8 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 31 Aug 2016 11:09:48 +0800 Subject: [PATCH] MDL-55774 core_message: ensure selectors are isolated --- message/amd/src/message_area_contacts.js | 20 ++++++++++---------- message/amd/src/message_area_messages.js | 12 ++++++------ message/amd/src/message_area_profile.js | 4 ++-- message/amd/src/message_area_search.js | 18 +++++++++--------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/message/amd/src/message_area_contacts.js b/message/amd/src/message_area_contacts.js index d345fe42519..482a4e9ec04 100644 --- a/message/amd/src/message_area_contacts.js +++ b/message/amd/src/message_area_contacts.js @@ -108,10 +108,10 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust this.messageArea.onDelegateEvent('blur', this.messageArea.SELECTORS.SEARCHBOX, this._clearSearching.bind(this)); // Now enable the ability to infinitely scroll through conversations and contacts. - customEvents.define(this.messageArea.SELECTORS.CONVERSATIONS, [ + customEvents.define(this.messageArea.find(this.messageArea.SELECTORS.CONVERSATIONS), [ customEvents.events.scrollBottom ]); - customEvents.define(this.messageArea.SELECTORS.CONTACTS, [ + customEvents.define(this.messageArea.find(this.messageArea.SELECTORS.CONTACTS), [ customEvents.events.scrollBottom ]); this.messageArea.onDelegateEvent(customEvents.events.scrollBottom, this.messageArea.SELECTORS.CONVERSATIONS, @@ -223,10 +223,10 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust // Add loading icon to the end of the list. return templates.render('core/loading', {}).then(function(html, js) { if (this._numConversationsDisplayed) { - templates.appendNodeContents(this.messageArea.SELECTORS.CONVERSATIONS, + templates.appendNodeContents(this.messageArea.find(this.messageArea.SELECTORS.CONVERSATIONS), "
" + html + "
", js); } else { // No conversations, just replace contents. - templates.replaceNodeContents(this.messageArea.SELECTORS.CONVERSATIONS, + templates.replaceNodeContents(this.messageArea.find(this.messageArea.SELECTORS.CONVERSATIONS), "
" + html + "
", js); } return this._getItems('core_message_data_for_messagearea_conversations', @@ -241,12 +241,12 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust // Only append data if we got data back. if (numberreceived > 0) { // Show the new content. - templates.appendNodeContents(this.messageArea.SELECTORS.CONVERSATIONS, html, js); + templates.appendNodeContents(this.messageArea.find(this.messageArea.SELECTORS.CONVERSATIONS), html, js); // Increment the number of conversations displayed. this._numConversationsDisplayed += numberreceived; } else if (!this._numConversationsDisplayed) { // If we didn't receive any contacts and there are currently none, then we want to show a message. - templates.replaceNodeContents(this.messageArea.SELECTORS.CONVERSATIONS, html, js); + templates.replaceNodeContents(this.messageArea.find(this.messageArea.SELECTORS.CONVERSATIONS), html, js); } // Mark that we are no longer busy loading data. this._isLoadingConversations = false; @@ -276,10 +276,10 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust // Add loading icon to the end of the list. return templates.render('core/loading', {}).then(function(html, js) { if (this._numContactsDisplayed) { - templates.appendNodeContents(this.messageArea.SELECTORS.CONTACTS, + templates.appendNodeContents(this.messageArea.find(this.messageArea.SELECTORS.CONTACTS), "
" + html + "
", js); } else { // No contacts, just replace contents. - templates.replaceNodeContents(this.messageArea.SELECTORS.CONTACTS, + templates.replaceNodeContents(this.messageArea.find(this.messageArea.SELECTORS.CONTACTS), "
" + html + "
", js); } return this._getItems('core_message_data_for_messagearea_contacts', @@ -294,12 +294,12 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust // Only append data if we got data back. if (numberreceived > 0) { // Show the new content. - templates.appendNodeContents(this.messageArea.SELECTORS.CONTACTS, html, js); + templates.appendNodeContents(this.messageArea.find(this.messageArea.SELECTORS.CONTACTS), html, js); // Increment the number of contacts displayed. this._numContactsDisplayed += numberreceived; } else if (!this._numContactsDisplayed) { // If we didn't receive any contacts and there are currently none, then we want to show a message. - templates.replaceNodeContents(this.messageArea.SELECTORS.CONTACTS, html, js); + templates.replaceNodeContents(this.messageArea.find(this.messageArea.SELECTORS.CONTACTS), html, js); } // Mark that we are no longer busy loading data. this._isLoadingContacts = false; diff --git a/message/amd/src/message_area_messages.js b/message/amd/src/message_area_messages.js index e45ded3dd84..9ba02cefcc7 100644 --- a/message/amd/src/message_area_messages.js +++ b/message/amd/src/message_area_messages.js @@ -125,7 +125,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust var numberreceived = 0; // Show loading template. return templates.render('core/loading', {}).then(function(html, js) { - templates.replaceNodeContents(this.messageArea.SELECTORS.MESSAGESAREA, html, js); + templates.replaceNodeContents(this.messageArea.find(this.messageArea.SELECTORS.MESSAGESAREA), html, js); return markMessagesAsRead[0]; }.bind(this)).then(function() { var conversationnode = this.messageArea.find(this.messageArea.SELECTORS.CONVERSATIONS + " " + @@ -142,7 +142,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust // We have the data - lets render the template with it. return templates.render('core_message/message_area_messages_area', data); }).then(function(html, js) { - templates.replaceNodeContents(this.messageArea.SELECTORS.MESSAGESAREA, html, js); + templates.replaceNodeContents(this.messageArea.find(this.messageArea.SELECTORS.MESSAGESAREA), html, js); // Scroll to the bottom. this._scrollBottom(); // Only increment if data was returned. @@ -151,7 +151,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust this._numMessagesDisplayed = numberreceived; } // Now enable the ability to infinitely scroll through messages. - customEvents.define(this.messageArea.SELECTORS.MESSAGES, [ + customEvents.define(this.messageArea.find(this.messageArea.SELECTORS.MESSAGES), [ customEvents.events.scrollTop ]); // Assign the event for scrolling. @@ -176,7 +176,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust var numberreceived = 0; // Show loading template. return templates.render('core/loading', {}).then(function(html, js) { - templates.prependNodeContents(this.messageArea.SELECTORS.MESSAGES, + templates.prependNodeContents(this.messageArea.find(this.messageArea.SELECTORS.MESSAGES), "
" + html + "
", js); return this._getMessages(this._getUserId()); }.bind(this)).then(function(data) { @@ -200,7 +200,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust // Get height before we add the messages. var oldheight = this.messageArea.find(this.messageArea.SELECTORS.MESSAGES)[0].scrollHeight; // Show the new content. - templates.prependNodeContents(this.messageArea.SELECTORS.MESSAGES, html, js); + templates.prependNodeContents(this.messageArea.find(this.messageArea.SELECTORS.MESSAGES), html, js); // Get height after we add the messages. var newheight = this.messageArea.find(this.messageArea.SELECTORS.MESSAGES)[0].scrollHeight; // Make sure scroll bar is at the location before we loaded more messages. @@ -433,7 +433,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust return promises[0].then(function(data) { return templates.render('core_message/message_area_message', data); }).then(function(html, js) { - templates.appendNodeContents(this.messageArea.SELECTORS.MESSAGES, html, js); + templates.appendNodeContents(this.messageArea.find(this.messageArea.SELECTORS.MESSAGES), html, js); // Empty the response text area. this.messageArea.find(this.messageArea.SELECTORS.SENDMESSAGETEXT).val('').trigger('input'); // Scroll down. diff --git a/message/amd/src/message_area_profile.js b/message/amd/src/message_area_profile.js index 92375d99547..a128e8ccc1e 100644 --- a/message/amd/src/message_area_profile.js +++ b/message/amd/src/message_area_profile.js @@ -66,7 +66,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' Profile.prototype._viewProfile = function(event, userid) { // Show loading template. templates.render('core/loading', {}).done(function(html, js) { - templates.replaceNodeContents(this.messageArea.SELECTORS.MESSAGESAREA, html, js); + templates.replaceNodeContents(this.messageArea.find(this.messageArea.SELECTORS.MESSAGESAREA), html, js); }.bind(this)); // Call the web service to return the profile. @@ -82,7 +82,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' return promises[0].then(function(data) { return templates.render('core_message/message_area_profile', data); }).then(function(html, js) { - templates.replaceNodeContents(this.messageArea.SELECTORS.MESSAGESAREA, html, js); + templates.replaceNodeContents(this.messageArea.find(this.messageArea.SELECTORS.MESSAGESAREA), html, js); }.bind(this)).fail(notification.exception); }; diff --git a/message/amd/src/message_area_search.js b/message/amd/src/message_area_search.js index 739327c6846..4c0c55c5f8c 100644 --- a/message/amd/src/message_area_search.js +++ b/message/amd/src/message_area_search.js @@ -127,7 +127,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' }.bind(this)); // Event listeners for scrolling through messages and people in courses. - customEvents.define(this.messageArea.SELECTORS.SEARCHRESULTSAREA, [ + customEvents.define(this.messageArea.find(this.messageArea.SELECTORS.SEARCHRESULTSAREA), [ customEvents.events.scrollBottom ]); this.messageArea.onDelegateEvent(customEvents.events.scrollBottom, this.messageArea.SELECTORS.SEARCHRESULTSAREA, @@ -228,7 +228,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' var numberreceived = 0; // Add loading icon to the end of the list. return templates.render('core/loading', {}).then(function(html, js) { - templates.appendNodeContents(this.messageArea.SELECTORS.SEARCHRESULTSAREA, + templates.appendNodeContents(this.messageArea.find(this.messageArea.SELECTORS.SEARCHRESULTSAREA), "
" + html + "
", js); return promises[0]; }.bind(this)).then(function(data) { @@ -241,12 +241,12 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' // Only append data if we got data back. if (numberreceived > 0) { // Show the new content. - templates.appendNodeContents(this.messageArea.SELECTORS.SEARCHRESULTSAREA, html, js); + templates.appendNodeContents(this.messageArea.find(this.messageArea.SELECTORS.SEARCHRESULTSAREA), html, js); // Increment the number of contacts displayed. this._numMessagesDisplayed += numberreceived; } else if (this._numMessagesDisplayed == 0) { // Must have nothing to begin with. // Replace the new content. - templates.replaceNodeContents(this.messageArea.SELECTORS.SEARCHRESULTSAREA, html, js); + templates.replaceNodeContents(this.messageArea.find(this.messageArea.SELECTORS.SEARCHRESULTSAREA), html, js); } // Mark that we are no longer busy loading data. this._isLoading = false; @@ -274,13 +274,13 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' // Perform the search and replace the content. return templates.render('core/loading', {}).then(function(html, js) { - templates.replaceNodeContents(this.messageArea.SELECTORS.SEARCHRESULTSAREA, + templates.replaceNodeContents(this.messageArea.find(this.messageArea.SELECTORS.SEARCHRESULTSAREA), "
" + html + "
", js); return promises[0]; }.bind(this)).then(function(data) { return templates.render('core_message/message_area_people_search_results', data); }).then(function(html, js) { - templates.replaceNodeContents(this.messageArea.SELECTORS.SEARCHRESULTSAREA, html, js); + templates.replaceNodeContents(this.messageArea.find(this.messageArea.SELECTORS.SEARCHRESULTSAREA), html, js); }.bind(this)).fail(notification.exception); }; @@ -316,7 +316,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' var numberreceived = 0; // Add loading icon to the end of the list. return templates.render('core/loading', {}).then(function(html, js) { - templates.appendNodeContents(this.messageArea.SELECTORS.SEARCHRESULTSAREA, + templates.appendNodeContents(this.messageArea.find(this.messageArea.SELECTORS.SEARCHRESULTSAREA), "
" + html + "
", js); return promises[0]; }.bind(this)).then(function(data) { @@ -329,12 +329,12 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' // Only append data if we got data back. if (numberreceived > 0) { // Show the new content. - templates.appendNodeContents(this.messageArea.SELECTORS.SEARCHRESULTSAREA, html, js); + templates.appendNodeContents(this.messageArea.find(this.messageArea.SELECTORS.SEARCHRESULTSAREA), html, js); // Increment the number of contacts displayed. this._numPeopleDisplayed += numberreceived; } else if (this._numPeopleDisplayed == 0) { // Must have nothing to begin with. // Replace the new content. - templates.replaceNodeContents(this.messageArea.SELECTORS.SEARCHRESULTSAREA, html, js); + templates.replaceNodeContents(this.messageArea.find(this.messageArea.SELECTORS.SEARCHRESULTSAREA), html, js); } // Mark that we are no longer busy loading data. this._isLoading = false;