Added proper support for 'enableoptions' in user profile
authorAlexander Ebert <ebert@woltlab.com>
Wed, 11 Jun 2014 18:10:56 +0000 (20:10 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 11 Jun 2014 18:10:56 +0000 (20:10 +0200)
com.woltlab.wcf/templates/userProfileAboutEditable.tpl
wcfsetup/install/files/acp/js/WCF.ACP.js
wcfsetup/install/files/acp/templates/option.tpl
wcfsetup/install/files/js/WCF.js

index 93de8ee5ce9a99deebbf68624b66cb47265bafe8..0c301086b15cb5f5297a030d4150d3c4d82620b2 100644 (file)
@@ -28,4 +28,9 @@
                <button class="buttonPrimary" accesskey="s" data-type="save">{lang}wcf.global.button.save{/lang}</button>
                <button data-type="restore">{lang}wcf.global.button.cancel{/lang}</button>
        </div>
-</div>
\ No newline at end of file
+</div>
+<script data-relocate="true">
+       $(function() {
+               new WCF.Option.Handler();
+       });
+</script>
\ No newline at end of file
index 54e26960190172b4610399a3ffa9887c5533ee04..845c5b5c96bf17143ed06050ff936e1c838193c5 100644 (file)
@@ -1687,151 +1687,6 @@ WCF.ACP.PluginStore.PurchasedItems.Search = Class.extend({
        }
 });
 
-/**
- * Handles option selection.
- */
-WCF.ACP.Options = Class.extend({
-       /**
-        * Initializes options.
-        */
-       init: function() {
-               $('.jsEnablesOptions').each($.proxy(this._initOption, this));
-       },
-       
-       /**
-        * Initializes an option.
-        * 
-        * @param       integer         index
-        * @param       object          option
-        */
-       _initOption: function(index, option) {
-               // execute action on init
-               this._change(option);
-               
-               // bind event listener
-               $(option).change($.proxy(this._handleChange, this));
-       },
-       
-       /**
-        * Applies whenever an option is changed.
-        * 
-        * @param       object          event
-        */
-       _handleChange: function(event) {
-               this._change($(event.target));
-       },
-       
-       /**
-        * Enables or disables options on option value change.
-        * 
-        * @param       object          option
-        */
-       _change: function(option) {
-               option = $(option);
-               
-               var $disableOptions = eval(option.data('disableOptions'));
-               var $enableOptions = eval(option.data('enableOptions'));
-               
-               // determine action by type
-               switch(option.getTagName()) {
-                       case 'input':
-                               switch(option.attr('type')) {
-                                       case 'checkbox':
-                                               this._execute(option.prop('checked'), $disableOptions, $enableOptions);
-                                       break;
-                                       
-                                       case 'radio':
-                                               if (option.prop('checked')) {
-                                                       this._execute(true, $disableOptions, $enableOptions);
-                                               }
-                                       break;
-                               }
-                       break;
-                       
-                       case 'select':
-                               var $value = option.val();
-                               var $disableOptions = $enableOptions = [];
-                               
-                               if (option.data('disableOptions').length > 0) {
-                                       for (var $index in option.data('disableOptions')) {
-                                               var $item = option.data('disableOptions')[$index];
-                                               
-                                               if ($item.value == $value) {
-                                                       $disableOptions.push($item.option);
-                                               }
-                                       }
-                               }
-                               
-                               if (option.data('enableOptions').length > 0) {
-                                       for (var $index in option.data('enableOptions')) {
-                                               var $item = option.data('enableOptions')[$index];
-                                               
-                                               if ($item.value == $value) {
-                                                       $enableOptions.push($item.option);
-                                               }
-                                       }
-                               }
-                               
-                               this._execute(true, $disableOptions, $enableOptions);
-                       break;
-               }
-       },
-       
-       /**
-        * Enables or disables options.
-        * 
-        * @param       boolean         isActive
-        * @param       array           disableOptions
-        * @param       array           enableOptions
-        */
-       _execute: function(isActive, disableOptions, enableOptions) {
-               if (disableOptions.length > 0) {
-                       for (var $i = 0, $size = disableOptions.length; $i < $size; $i++) {
-                               var $target = disableOptions[$i];
-                               if ($.wcfIsset($target)) {
-                                       this._enableOption($target, !isActive);
-                               }
-                       }
-               }
-               
-               if (enableOptions.length > 0) {
-                       for (var $i = 0, $size = enableOptions.length; $i < $size; $i++) {
-                               var $target = enableOptions[$i];
-                               if ($.wcfIsset($target)) {
-                                       this._enableOption($target, isActive);
-                               }
-                       }
-               }
-       },
-       
-       /**
-        * Enables an option.
-        * 
-        * @param       string          target
-        * @param       boolean         enable
-        */
-       _enableOption: function(target, enable) {
-               var $targetElement = $('#' + $.wcfEscapeID(target));
-               var $tagName = $targetElement.getTagName();
-               
-               if ($tagName == 'select' || ($tagName == 'input' && ($targetElement.attr('type') == 'checkbox' || $targetElement.attr('type') == 'radio'))) {
-                       if (enable) $targetElement.enable();
-                       else $targetElement.disable();
-               }
-               else {
-                       if (enable) $targetElement.removeAttr('readonly');
-                       else $targetElement.attr('readonly', true);
-               }
-               
-               if (enable) {
-                       $targetElement.closest('dl').removeClass('disabled');
-               }
-               else {
-                       $targetElement.closest('dl').addClass('disabled');
-               }
-       }
-});
-
 /**
  * Worker support for ACP.
  * 
index 4d82259f6b33961aff4adcfc29b066caac7f5adf..93e48eb100eefb779d5baea2e66e26c3966c332d 100644 (file)
@@ -6,7 +6,7 @@
        //<![CDATA[
        $(function() {
                WCF.TabMenu.init();
-               new WCF.ACP.Options();
+               new WCF.Option.Handler();
                
                {if $optionName}
                        var $option = $('#' + $.wcfEscapeID('{$optionName}'));
index 41ca18cc2787382ebd5cab18a6dbf4be1a164c09..fe9cd49c67f4216c5e12bdf067b29dfc4550e0ad 100755 (executable)
@@ -5479,6 +5479,165 @@ WCF.DOMNodeRemovedHandler = {
        }
 };
 
+/**
+ * Namespace for option handlers.
+ */
+WCF.Option = { };
+
+/**
+ * Handles option selection.
+ */
+WCF.Option.Handler = Class.extend({
+       /**
+        * Initializes the WCF.Option.Handler class.
+        */
+       init: function() {
+               this._initOptions();
+               
+               WCF.DOMNodeInsertedHandler.addCallback('WCF.Option.Handler', $.proxy(this._initOptions));
+       },
+       
+       /**
+        * Initializes all options.
+        */
+       _initOptions: function() {
+               $('.jsEnablesOptions').each($.proxy(this._initOption, this));
+       },
+       
+       /**
+        * Initializes an option.
+        * 
+        * @param       integer         index
+        * @param       object          option
+        */
+       _initOption: function(index, option) {
+               // execute action on init
+               this._change(option);
+               
+               // bind event listener
+               $(option).change($.proxy(this._handleChange, this));
+       },
+       
+       /**
+        * Applies whenever an option is changed.
+        * 
+        * @param       object          event
+        */
+       _handleChange: function(event) {
+               this._change($(event.target));
+       },
+       
+       /**
+        * Enables or disables options on option value change.
+        * 
+        * @param       object          option
+        */
+       _change: function(option) {
+               option = $(option);
+               
+               var $disableOptions = eval(option.data('disableOptions'));
+               var $enableOptions = eval(option.data('enableOptions'));
+               
+               // determine action by type
+               switch(option.getTagName()) {
+                       case 'input':
+                               switch(option.attr('type')) {
+                                       case 'checkbox':
+                                               this._execute(option.prop('checked'), $disableOptions, $enableOptions);
+                                       break;
+                                       
+                                       case 'radio':
+                                               if (option.prop('checked')) {
+                                                       this._execute(true, $disableOptions, $enableOptions);
+                                               }
+                                       break;
+                               }
+                       break;
+                       
+                       case 'select':
+                               var $value = option.val();
+                               var $disableOptions = $enableOptions = [];
+                               
+                               if (option.data('disableOptions').length > 0) {
+                                       for (var $index in option.data('disableOptions')) {
+                                               var $item = option.data('disableOptions')[$index];
+                                               
+                                               if ($item.value == $value) {
+                                                       $disableOptions.push($item.option);
+                                               }
+                                       }
+                               }
+                               
+                               if (option.data('enableOptions').length > 0) {
+                                       for (var $index in option.data('enableOptions')) {
+                                               var $item = option.data('enableOptions')[$index];
+                                               
+                                               if ($item.value == $value) {
+                                                       $enableOptions.push($item.option);
+                                               }
+                                       }
+                               }
+                               
+                               this._execute(true, $disableOptions, $enableOptions);
+                       break;
+               }
+       },
+       
+       /**
+        * Enables or disables options.
+        * 
+        * @param       boolean         isActive
+        * @param       array           disableOptions
+        * @param       array           enableOptions
+        */
+       _execute: function(isActive, disableOptions, enableOptions) {
+               if (disableOptions.length > 0) {
+                       for (var $i = 0, $size = disableOptions.length; $i < $size; $i++) {
+                               var $target = disableOptions[$i];
+                               if ($.wcfIsset($target)) {
+                                       this._enableOption($target, !isActive);
+                               }
+                       }
+               }
+               
+               if (enableOptions.length > 0) {
+                       for (var $i = 0, $size = enableOptions.length; $i < $size; $i++) {
+                               var $target = enableOptions[$i];
+                               if ($.wcfIsset($target)) {
+                                       this._enableOption($target, isActive);
+                               }
+                       }
+               }
+       },
+       
+       /**
+        * Enables an option.
+        * 
+        * @param       string          target
+        * @param       boolean         enable
+        */
+       _enableOption: function(target, enable) {
+               var $targetElement = $('#' + $.wcfEscapeID(target));
+               var $tagName = $targetElement.getTagName();
+               
+               if ($tagName == 'select' || ($tagName == 'input' && ($targetElement.attr('type') == 'checkbox' || $targetElement.attr('type') == 'radio'))) {
+                       if (enable) $targetElement.enable();
+                       else $targetElement.disable();
+               }
+               else {
+                       if (enable) $targetElement.removeAttr('readonly');
+                       else $targetElement.attr('readonly', true);
+               }
+               
+               if (enable) {
+                       $targetElement.closest('dl').removeClass('disabled');
+               }
+               else {
+                       $targetElement.closest('dl').addClass('disabled');
+               }
+       }
+});
+
 WCF.PageVisibilityHandler = {
        /**
         * list of callbacks