1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

JS Challenge

Discussion in 'XenForo Development Discussions' started by ragtek, Apr 22, 2011.

  1. ragtek

    ragtek Guest

    This is my current 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');
                    $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")) {
                    if (!$newUserThreadCb.is(":checked")) {
                    if (!$cb2.is(":checked")) {
                    $conversationcb.click(function() {
                    $newUserThreadCb.click(function() {
                    $cb2.click(function() {
                (jQuery, this, document);
    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;)
  2. xfrocks

    xfrocks Well-Known Member

    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?
  3. ragtek

    ragtek Guest

    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
  4. xfrocks

    xfrocks Well-Known Member

Share This Page