Overhauled WCF.Notice.Dismiss
authorAlexander Ebert <ebert@woltlab.com>
Mon, 18 May 2015 15:27:30 +0000 (17:27 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 18 May 2015 15:27:30 +0000 (17:27 +0200)
com.woltlab.wcf/templates/headIncludeJavaScript.tpl
com.woltlab.wcf/templates/userNotice.tpl
wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/js/WoltLab/WCF/Controller/Notice/Dismiss.js [new file with mode: 0644]

index 2112a9c3ffca1d90ccf206aae2ba29381f837400..ed5024a4037314b32c04557e42dbeacd51348709 100644 (file)
                
                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'}
index 81a71ced8de590789d19b4c390c70b3b8f689f8c..b9cf1bd4fde0d3745ed61a3bed6a9f8854007786 100644 (file)
                <p class="warning">{lang}wcf.user.register.needActivation{/lang}</p>
        {/if}
        
-       {foreach from=$__wcf->getNoticeHandler()->getVisibleNotices() item='notice'}
-               <p class="{$notice->cssClassName} notice{if $notice->isDismissible} noticeDismissible{/if}">
-                       {if $notice->isDismissible}
-                               <span class="icon icon16 fa-times pointer jsDismissNoticeButton jsTooltip" data-object-id="{$notice->noticeID}" title="{lang}wcf.notice.button.dismiss{/lang}"></span>
-                       {/if}
-                       
-                       {if $notice->noticeUseHtml}{@$notice->notice|language}{else}{@$notice->notice|language|htmlspecialchars|nl2br}{/if}
-               </p>
-       {/foreach}
+       {hascontent}
+               {content}
+                       {foreach from=$__wcf->getNoticeHandler()->getVisibleNotices() item='notice'}
+                               <p class="{$notice->cssClassName} notice{if $notice->isDismissible} noticeDismissible{/if}">
+                                       {if $notice->isDismissible}
+                                               <span class="icon icon16 fa-times pointer jsDismissNoticeButton jsTooltip" data-object-id="{$notice->noticeID}" title="{lang}wcf.notice.button.dismiss{/lang}"></span>
+                                       {/if}
+                                       
+                                       {if $notice->noticeUseHtml}{@$notice->notice|language}{else}{@$notice->notice|language|htmlspecialchars|nl2br}{/if}
+                               </p>
+                       {/foreach}
+               {/content}
+               
+               <script data-relocate="true">
+                       require(['WoltLab/WCF/Controller/Notice/Dismiss'], function(ControllerNoticeDismiss) {
+                               ControllerNoticeDismiss.setup();
+                       });
+               </script>
+       {/hascontent}
        
        {event name='userNotice'}
 </div>
index 07177719d5cb115bb0f5465769ee05abf8e1806c..732f1c1629642fb8ab5965ac04350008b8d47f40 100755 (executable)
@@ -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 (file)
index 0000000..43a5648
--- /dev/null
@@ -0,0 +1,58 @@
+/**
+ * Handles dismissable user notices.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2015 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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();
+});