1. JavaScript / Говнокод #12345

    +148

    1. 1
    $("#ORDER_PROP_5 option[value='7361']").attr("selected", "selected");

    Установка значения в селекте.

    torch1313, 24 Декабря 2012

    Комментарии (12)
  2. JavaScript / Говнокод #12336

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    function postGameOrder(option) {
        // 48 cтрок кода
            if (option == 1) {
                if (!confirm("Are you sure you want to save this configuration?")) {
                    return false;
                }
            }
        // 45 строк кода
    }

    P.S. Умолчу уже о том, что среди тех 48 и 45 строк кода происходит обращение к глобальным переменным.
    На публикацию же вдохновило то, что вот это обращение к option — единственное во всей функции.

    wissenstein, 22 Декабря 2012

    Комментарии (0)
  3. JavaScript / Говнокод #12312

    +146

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    <html>
    <head>
    <style>
    td{text-align:center;width:100;height:100;border:1px solid black}
    table{border:1px solid black}
    </style>
    </head>
    <body>
    <script>
    document.write("<table><tr><td>понедельник</td><td>вторник</td><td>среда</td><td>четверг</td><td>пятница</td><td>суббота</td><td>воскресенье</td></tr><tr>");
    var mes=prompt('Введите месяц');
    var god=prompt('Введите год');
    var i;
    a=new Array("январь","февраль","март","апрель","май","июнь","июль","август","сентябрь","октябрь","ноябрь","декабрь");
    for(i=0;i<12;i++){if(a[i]==mes){break;}}
    d=new Date(god,i,1);
    n=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
    if(d.getYear()%4==0){n[1]=29;}
    var j=n[i];
    var q=d.getDay();
    if(q==0){q=7;}
    for(i=2-q;i<=j;i++)
    {
     if(i<1){document.write("<td></td>");}
     if(i>=1){ document.write("<td>"+i+"</td>"); }
     if(q%7==0){document.write("</tr><tr>");}
     if(i>=1){q=q+1;}
    }
    for(;q%7!=0;q++){document.write("<td></td>");}
    document.write("</tr></table>");
    </script>
    </body>
    </html>

    Я правда спешил.

    dos_, 18 Декабря 2012

    Комментарии (2)
  4. JavaScript / Говнокод #12307

    +153

    1. 1
    $("#datepicker1").datepicker("setDate", new Date((Math.round((new Date().getTime() / 1000)) - x2) * 1000));

    Из недавнего

    varg242, 18 Декабря 2012

    Комментарии (8)
  5. JavaScript / Говнокод #12298

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    findTariffPlans = function(setValue) {findTariffPlans(setValue, null)};
    
    findTariffPlans = function(setValue, closure) {
       // bla-bla-bla
    }

    "Я перегрузил"

    madhead, 16 Декабря 2012

    Комментарии (6)
  6. JavaScript / Говнокод #12287

    +161

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    function setOptionText(the_select1, the_array1, the_select2, the_array2)
    {
        the_select1.options.length=the_array1.length;
        for (loop=0; loop < the_array1.length; loop++)
        {
            the_select1.options[loop].text = the_array1[loop];
            the_select1.options[loop].value = the_array1[loop];
            if (loop==0){
                the_select1.options[loop].selected=true;
            }    
        }
    
        the_select2.options.length=the_array2.length;
        for (loop=0; loop < the_array2.length; loop++)
        {
            the_select2.options[loop].text = the_array2[loop];
            the_select2.options[loop].value = the_array2[loop];
            if (loop==0){
                the_select2.options[loop].selected=true;
            }
        }
    }

    Моему предшественнику, видимо, было лень вызывать два раза одну и ту же функцию, и потому он добавил в неё ещё два параметра и ещё девять строк кода.

    wissenstein, 14 Декабря 2012

    Комментарии (2)
  7. JavaScript / Говнокод #12277

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    this.start = function() {
    		// Инициализирует парсинг выгрузки из Агента Плюс.
    		if (this.open()) {
    			this.catalogs = this.getTags("catalogs", true)[0].childs;
    			this.subdocuments = this.getTags("documents", true)[1].childs;
    			this.guids = this.document.childs[0].childs[0].childs;
    			this.sellhistory = this.getCatalog("ИсторияПродаж").childs[0].childs;
    			this.sellpoints = this.getCatalog("ТорговыеТочки").childs[0].childs;
    			this.contragents = this.getCatalog("Контрагенты").childs[1].childs;
    			this.deals = this.getCatalog("Договоры").childs[0].childs;
    			this.nomenclature = this.getCatalog("Номенклатура").childs;
    			this.measure = this.getCatalog("ЕдиницыИзмерения").childs[0].childs;
    			this.route = this.getDocument("Маршрут").childs[0].childs[0].childs[0].childs[0]
    			this.names = {deals: [], catalog: [], nomenclature: [], measure: [], contragents: [], sellpoints: []};
    			this.info = {deals: [], catalog: [], nomenclature: [], measure: [], contragents: [], sellpoints: []};
    			this.hash = {deals: {}, nomenclature: {}, consts: {}, contragents: {}, sellpoints: [], measure: {}};
    			for (var i = 0; i < this.catalogs.length; i++) {
    				this.names.catalog.push(this.catalogs[i].attrib.Comment.replace(/Справочник\./g, ""));
    				this.info.catalog.push(this.catalogs[i].attrib);
    			}
    			for (var i = 0; i < this.nomenclature[1].childs.length; i++) {
    				this.names.nomenclature.push(this.nomenclature[1].childs[i].attrib.Name);
    				this.info.nomenclature.push(this.nomenclature[1].childs[i].attrib);
    				this.hash.nomenclature[this.nomenclature[1].childs[i].attrib.GUID] = this.nomenclature[1].childs[i].attrib;
    			}
    			for (var i = 0; i < this.deals.length; i++) {
    				this.names.deals.push(this.deals[i].attrib.Name);
    				this.info.deals.push(this.deals[i].attrib);
    				this.hash.deals[this.deals[i].attrib.GUID] = this.deals[i].attrib;
    			}
    			for (var i = 0; i < this.measure.length; i++) {
    				this.names.measure.push(this.measure[i].attrib.Name);
    				this.info.measure.push(this.measure[i].attrib);
    				this.hash.measure[this.measure[i].attrib.GUID] = this.measure[i].attrib;
    			}
    			for (var i = 0; i < this.contragents.length; i++) {
    				this.names.contragents.push(this.contragents[i].attrib.Name);
    				this.info.contragents.push(this.contragents[i].attrib);
    				this.hash.contragents[this.contragents[i].attrib.GUID] = this.contragents[i].attrib;
    			}
    			for (var i = 0; i < this.sellpoints.length; i++) {
    				this.names.sellpoints.push(this.sellpoints[i].attrib.Name);
    				this.info.sellpoints.push(this.sellpoints[i].attrib);
    				this.hash.sellpoints[this.sellpoints[i].attrib.GUID] = this.sellpoints[i].attrib;
    			}
    			for (var i = 0; i < this.guids.length; i++) {
    				this.hash.consts[this.guids[i].attrib.GUID] = this.guids[i].attrib.VALUE;
    			}
    			
    			this.dynamic.routes = new Array();
    			for (var i = 0; i < this.route.childs.length; i++) {
    				var sp = this.getSPointByGUID(this.route.childs[i].attrib.A02);
    				var adr = sp.Name;
    				var ca = this.getCAgentByGUID(this.route.childs[i].attrib.A01);
    				var ptypeguid = this.hash.deals[ca.A08].A06;
    				var cagent = ca.Name;
    				var dealguid = ca.A08;
    				var exists = false;
    				for (var j = 0; j < this.dynamic.routes.length; j++) if (this.dynamic.routes[j].address.trim().toLowerCase() == adr.trim().toLowerCase()) exists = exists || true;
    				if (!exists) this.dynamic.routes.push({ptypeguid: ptypeguid, spointguid: sp.GUID, address: adr, dealguid: dealguid, cagent: cagent, cagentguid: ca.GUID, datestamp: this.convRouteDate(this.route.childs[i].attrib.A03)});
    			}
    		} else return;
    	};

    Маленькая часть нашего скрипта для работы с 1С - Node.JS - WebClient.

    Govnisti_Diavol, 12 Декабря 2012

    Комментарии (9)
  8. JavaScript / Говнокод #12266

    +163

    1. 1
    jQuery("body").trigger( F11 )

    Попытка перейти в полноэкранный режим.. Найдено в недрах одного довольно серьезного проекта.

    diezvl, 10 Декабря 2012

    Комментарии (15)
  9. JavaScript / Говнокод #12253

    +169

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    if(navigator.appName == "Microsoft Internet Explorer") {
    	for(var i=0;i<$('.product_documents').length;i++)  if( ( (firstLaunch_onChangeDocs) && ($('.product_documents')[i].selectedIndex==0)) || (!firstLaunch_onChangeDocs) )
    	{
    	  document.getElementById($('.product_documents')[i].id).innerHTML = '';
    	  document.getElementById($('.product_documents')[i].id).outerHTML = document.getElementById($('.product_documents')[i].id).outerHTML.replace("</SELECT>", jsInternalDocuments + '</select>')
    	}
      } else
    	for(var i=0;i<$('.product_documents').length;i++)  if( ( (firstLaunch_onChangeDocs) && ($('.product_documents')[i].selectedIndex==0)) || (!firstLaunch_onChangeDocs) )
    	  $('.product_documents')[i].innerHTML = jsInternalDocuments;

    Очень альтернативная техника использования jquery.

    clauclauclau, 06 Декабря 2012

    Комментарии (12)
  10. JavaScript / Говнокод #12251

    +160

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    for(var i = 0, l = requestParams.length; i < l; i++) {
        var param_pair = requestParams[i];
    
        key = encodeURIComponent(param_pair[0]);
        val = param_pair[1];
        if ( val && val.constructor.toString().match(/array/i) ) {
            val = val.join('+');
        }
        // ...
    }

    Кусочек велосипеда, который заменяет функционал jQuery.ajax

    Если вдруг наш параметр оказался массивом ... ну что ж еще с ним сделать кроме как соединить через "+". Обратите внимание на саму проверку.

    Elvenfighter, 05 Декабря 2012

    Комментарии (128)