JS Challenge

  • Thread starter Thread starter ragtek
  • Start date Start date
R

ragtek

Guest
This is my current code:

Code:
<script type="text/javascript">
    !function($, window, document, _undefined) {
        XenForo.NUNS =
        {
            Init: function() {

                $conversationcb = $('#ctrl_optionsragtek_NUNS_welcomeConversationActive_1');
                $('#ctrl_optionsragtek_NUNS_welcomeConversationSender').addClass('AutoComplete AcSingle');
                $('#ctrl_optionsragtek_NUNS_newUserThreadCreater').addClass('AutoComplete AcSingle');
                $('#ctrl_optionsragtek_NUNS_teamNotification').addClass('AutoComplete');

                $conversationSender = $('#ctrl_optionsragtek_NUNS_welcomeConversationSender').parent().parent();
                $conversationClosed = $('#ctrl_optionsragtek_NUNS_welcomeConversationClosed_1').parent().parent().parent().parent().parent()

                $newUserThreadCb = $('#ctrl_optionsragtek_NUNS_newUserThreadActive_1');
                $newUserThreadForum = $('#ctrl_optionsragtek_NUNS_newUserThreadForum').parent().parent();
                $newUserThreadCreater = $('#ctrl_optionsragtek_NUNS_newUserThreadCreater').parent().parent();


                $cb2 = $('#ctrl_optionsragtek_NUNS_TeamNotificationActive_1');
                $cb2Childs = $('#ctrl_optionsragtek_NUNS_teamNotification').parent().parent();

                if (!$conversationcb.is(":checked")) {
                    $conversationSender.hide();
                    $conversationClosed.hide();
                }


                if (!$newUserThreadCb.is(":checked")) {
                    $newUserThreadForum.hide();
                    $newUserThreadCreater.hide();
                }

                if (!$cb2.is(":checked")) {
                    $cb2Childs.hide();
                }

                $conversationcb.click(function() {
                    $conversationSender.toggle();
                    $conversationClosed.toggle();
                });

                $newUserThreadCb.click(function() {
                    $newUserThreadForum.toggle();
                    $newUserThreadCreater.toggle();
                });

                $cb2.click(function() {
                    $cb2Childs.toggle();
                });
            }
        };
    }
            (jQuery, this, document);
    XenForo.NUNS.Init();
As you see, there are many similar things happening (ugly DRY:D )

Now the challange:
Who can do this stuff with less lines as me? (i think everybody:D )

1. prize: my respect:P

terms: if you post in this thread, you allow the threadstarter (ragtek) to use your code in his NUNS add-on;)
 
I have no solution but questions, hope you wouldn't mind :D
  1. It looks like you are trying to use username suggestion / auto complete with your fields. Why don't add the classes in your template? If you can add custom id like that, you can simply add the classes, no?
  2. You seemed to reinvent the wheel when you did all the hide() and toggle() by yourself. Why don't you just use the Disabler?
 
I have no solution but questions, hope you wouldn't mind :D
  1. It looks like you are trying to use username suggestion / auto complete with your fields. Why don't add the classes in your template? If you can add custom id like that, you can simply add the classes, no?
  2. You seemed to reinvent the wheel when you did all the hide() and toggle() by yourself. Why don't you just use the Disabler?

1. Because i didn't know how to add the class;)

2. AFAIK the disabler only disable the stuff instead of hiding it!
Isn't it much more sexy if the user don't see the unnecessary part?;) I hate long forms, where 70% of the input fields are disabled and wait for an action (for example checkbox activation) to be enabled
 
Top Bottom