From ea24a840c90be608dceddf0b651ac220fe4961ff Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 18 May 2015 17:27:30 +0200 Subject: [PATCH] Overhauled WCF.Notice.Dismiss --- .../templates/headIncludeJavaScript.tpl | 2 - com.woltlab.wcf/templates/userNotice.tpl | 28 ++++++--- wcfsetup/install/files/js/WCF.js | 55 ------------------ .../WoltLab/WCF/Controller/Notice/Dismiss.js | 58 +++++++++++++++++++ 4 files changed, 77 insertions(+), 66 deletions(-) create mode 100644 wcfsetup/install/files/js/WoltLab/WCF/Controller/Notice/Dismiss.js diff --git a/com.woltlab.wcf/templates/headIncludeJavaScript.tpl b/com.woltlab.wcf/templates/headIncludeJavaScript.tpl index 2112a9c3ff..ed5024a403 100644 --- a/com.woltlab.wcf/templates/headIncludeJavaScript.tpl +++ b/com.woltlab.wcf/templates/headIncludeJavaScript.tpl @@ -188,8 +188,6 @@ WCF.System.PageNavigation.init('.pageNavigation'); WCF.Date.Picker.init(); - //new WCF.User.ProfilePreview(); - new WCF.Notice.Dismiss(); WCF.User.Profile.ActivityPointList.init(); {event name='javascriptInit'} diff --git a/com.woltlab.wcf/templates/userNotice.tpl b/com.woltlab.wcf/templates/userNotice.tpl index 81a71ced8d..b9cf1bd4fd 100644 --- a/com.woltlab.wcf/templates/userNotice.tpl +++ b/com.woltlab.wcf/templates/userNotice.tpl @@ -22,15 +22,25 @@

{lang}wcf.user.register.needActivation{/lang}

{/if} - {foreach from=$__wcf->getNoticeHandler()->getVisibleNotices() item='notice'} -

- {if $notice->isDismissible} - - {/if} - - {if $notice->noticeUseHtml}{@$notice->notice|language}{else}{@$notice->notice|language|htmlspecialchars|nl2br}{/if} -

- {/foreach} + {hascontent} + {content} + {foreach from=$__wcf->getNoticeHandler()->getVisibleNotices() item='notice'} +

+ {if $notice->isDismissible} + + {/if} + + {if $notice->noticeUseHtml}{@$notice->notice|language}{else}{@$notice->notice|language|htmlspecialchars|nl2br}{/if} +

+ {/foreach} + {/content} + + + {/hascontent} {event name='userNotice'} diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 07177719d5..732f1c1629 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -10113,61 +10113,6 @@ WCF.Condition.PageControllerDependence = Class.extend({ */ WCF.Notice = { }; -/** - * Handles dismissing notices. - */ -WCF.Notice.Dismiss = Class.extend({ - /** - * list with notices - * @var jQuery - */ - _notices: { }, - - /** - * action proxy object - * @var WCF.Action.Proxy - */ - _proxy: null, - - /** - * Initializes a new WCF.Notice.Dismiss object. - */ - init: function() { - this._proxy = new WCF.Action.Proxy({ - success: $.proxy(this._success, this) - }); - - var $dismissButtons = $('.jsDismissNoticeButton').click($.proxy(this._click, this)); - - $dismissButtons.each($.proxy(function(index, element) { - this._notices[$(element).data('objectID')] = $(element).parent(); - }, this)); - }, - - /** - * Handles clicking on - */ - _click: function(event) { - this._proxy.setOption('data', { - actionName: 'dismiss', - className: 'wcf\\data\\notice\\NoticeAction', - objectIDs: [ $(event.currentTarget).data('objectID') ] - }); - this._proxy.sendRequest(); - }, - - /** - * Handles successfull AJAX request. - * - * @param object data - * @param string textStatus - * @param jQuery jqXHR - */ - _success: function(data, textStatus, jqXHR) { - this._notices[data.returnValues.noticeID].wcfFadeOut(); - } -}); - /** * Encapsulate eval() within an own function to prevent problems * with optimizing and minifiny JS. diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Controller/Notice/Dismiss.js b/wcfsetup/install/files/js/WoltLab/WCF/Controller/Notice/Dismiss.js new file mode 100644 index 0000000000..43a5648f25 --- /dev/null +++ b/wcfsetup/install/files/js/WoltLab/WCF/Controller/Notice/Dismiss.js @@ -0,0 +1,58 @@ +/** + * Handles dismissable user notices. + * + * @author Alexander Ebert + * @copyright 2001-2015 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLab/WCF/Controller/Notice/Dismiss + */ +define(function() { + "use strict"; + + /** + * @constructor + */ + function ControllerNoticeDismiss() {}; + ControllerNoticeDismiss.prototype = { + /** + * Initializes dismiss buttons. + */ + setup: function() { + var buttons = document.getElementsByClassName('jsDismissNoticeButton'); + + if (buttons.length) { + var clickCallback = this._click.bind(this); + for (var i = 0, length = buttons.length; i < length; i++) { + buttons[i].addEventListener('click', clickCallback); + } + } + }, + + /** + * Sends a request to dismiss a notice and removes it afterwards. + */ + _click: function(event) { + var button = event.currentTarget; + + new WCF.Action.Proxy({ + autoSend: true, + data: { + actionName: 'dismiss', + className: 'wcf\\data\\notice\\NoticeAction', + objectIDs: [ button.getAttribute('data-object-id') ] + }, + success: function() { + var parent = button.parentNode; + + parent.addEventListener('transitionend', function() { + parent.parentNode.removeChild(parent); + }); + + parent.classList.remove('active'); + } + }); + } + }; + + return new ControllerNoticeDismiss(); +}); -- 2.20.1