From 240b34e07f3d626c7772fdbd52615db31fd3f576 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 9 Jun 2014 13:54:30 +0200 Subject: [PATCH] Added ability to purge popover content --- wcfsetup/install/files/js/WCF.User.js | 27 +++++++++++++++++++ wcfsetup/install/files/js/WCF.js | 39 +++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/wcfsetup/install/files/js/WCF.User.js b/wcfsetup/install/files/js/WCF.User.js index b7ff6393d0..82fe229764 100644 --- a/wcfsetup/install/files/js/WCF.User.js +++ b/wcfsetup/install/files/js/WCF.User.js @@ -1803,6 +1803,9 @@ WCF.User.ProfilePreview = WCF.Popover.extend({ this._proxy = new WCF.Action.Proxy({ showLoadingOverlay: false }); + + // register instance + WCF.System.ObjectStore.add('WCF.User.ProfilePreview', this); }, /** @@ -1843,6 +1846,18 @@ WCF.User.ProfilePreview = WCF.Popover.extend({ }); this._proxy.sendRequest(); } + }, + + /** + * Purages a cached user profile. + * + * @param integer userID + */ + purge: function(userID) { + delete this._userProfiles[userID]; + + // purge content cache + this._data = { }; } }); @@ -1954,6 +1969,12 @@ WCF.User.Action.Follow = Class.extend({ var $notification = new WCF.System.Notification(); $notification.show(); + + // force rebuilding of popover cache + var self = this; + WCF.System.ObjectStore.invoke('WCF.User.ProfilePreview', function(profilePreview) { + profilePreview.purge(self._userID); + }); } }); @@ -2060,6 +2081,12 @@ WCF.User.Action.Ignore = Class.extend({ var $notification = new WCF.System.Notification(); $notification.show(); + + // force rebuilding of popover cache + var self = this; + WCF.System.ObjectStore.invoke('WCF.User.ProfilePreview', function(profilePreview) { + profilePreview.purge(self._userID); + }); } }); diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 02c4cfebc5..c0122c4b73 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -6740,6 +6740,45 @@ WCF.System.Mobile.UX = { } }; +/** + * Stores object references for global access. + */ +WCF.System.ObjectStore = { + /** + * list of objects grouped by identifier + * @var object + */ + _objects: { }, + + /** + * Adds a new object to the collection. + * + * @param string identifier + * @param object object + */ + add: function(identifier, obj) { + if (this._objects[identifier] === undefined) { + this._objects[identifier] = [ ]; + } + + this._objects[identifier].push(obj); + }, + + /** + * Invokes a callback passing the matching objects as a parameter. + * + * @param string identifier + * @param object callback + */ + invoke: function(identifier, callback) { + if (this._objects[identifier]) { + for (var $i = 0; $i < this._objects[identifier].length; $i++) { + callback(this._objects[identifier][$i]); + } + } + } +}; + WCF.System.Page = { }; WCF.System.Page.Multiple = Class.extend({ -- 2.20.1