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

    +160

    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
    function displayFilterElements(typeList){
    	_filter.form.elements["name1"].closest("tr").hidden = (typeList === "Type1") ? false : true;
    	_filter.form.elements["name2"].closest("tr").hidden = (typeList === "Type1") ? false : true;
    	_filter.form.elements["nam3"].closest("tr").hidden = (typeList === "Type1") ? false : true;
    	_filter.form.elements["name4"].closest("tr").hidden = (typeList === "Type1") ? false : true;
    	_filter.form.elements["name5"].closest("tr").hidden = (typeList === "Type1") ? false : true;
    	_filter.form.elements["name6"].closest("tr").hidden = (typeList === "Type1") ? false : true;
    	_filter.form.elements["name7"].closest("tr").hidden = (typeList === "Type1") ? false : true;
    	_filter.form.elements["name8"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name9"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name10"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name11"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name12"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name13"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name14"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name15"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name16"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name17"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name18"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name19"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name20"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name21"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name22"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name23"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name24"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name25"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name26"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name27"].closest("tr").hidden = (typeList === "Type2") ? false : true;
    	_filter.form.elements["name28"].closest("tr").hidden = (typeList === "Type3") ? true : false;
    	_filter.form.elements["name29"].closest("tr").hidden = (typeList === "Type3") ? false : true;
    };
    	
    function stateFilterElements(){
    	let select = false;
    	["name1", "name2", "name3", "name4", "name5", "name6", "name7", "name8", "name9", "name10", "name11", "name12", "name13"].forEach(function(fieldName){
    		if ($.query.hashJSON.has(fieldName))
    			select = true;
    	});
    	return select;
    }

    Получил в доработку модуль сотрудника. Идентификаторы изменены для публикации, не в них суть.

    torbasow, 17 Марта 2015

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $('#Leasing_payment_sum').keyup(function(){
        if($(this).val()/$(this).val()){
            var result = $(this).val()*1+$(this).val()*0.18;
            $('#Leasing_payment_sum_with_nds').val(result.toFixed(2));
        }
    });

    Удивляет проверка...

    creepy-code, 16 Марта 2015

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

    +158

    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
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    eps=0.001;
    
    s1=new Source(1000,0.17);
    mx=new Mixer(1000);
    mb=new Mem(0.15,0.95);
    sp=new Splitter(0.80);
    s2=new Sink();
    s3=new Sink();
    
    mx.in1=s1.out1;
    mx.in2=sp.out2;
    mb.in1=mx.out1;
    sp.in1=mb.out2;
    s3.in1=sp.out1;
    s2.in1=mb.out1;
    
    for (i=0;i<50;i++){
        mx.calc();
        mb.calc();
        sp.calc();
    }
    
    function Stream(v,c){
        this.v=v||null;
        this.c=c||null;
        this.selfCheck=false;
        this.Show=function(){//how to add default values?
            return "volume="+this.v+",conc="+this.c+",selfCheck:"+this.selfCheck+"; ";
        }
    }
    
    function Source(v,c){
        this.out1=new Stream(v,c);
        this.calc=function(){};
    }
    function Sink(){
        this.in1=null;
        this.calc=function(){};
    }
    
    function Mixer(fixedV){
        this.fv=fixedV;
        this.in1=null;
        this.in2=null;
        this.out1=new Stream();
        this.calc=function(){
            this.out1.v=this.fv;//||this.in1.v+this.in2.v;
            this.in2.v=this.in2.v||0;
            this.in2.c=this.in2.c||0;
            this.in1.v=this.out1.v-this.in2.v;
            this.out1.c =(this.in1.v*this.in1.c+this.in2.v*this.in2.c)/this.out1.v;
            this.out1.selfCheck=Math.abs
            ((this.in1.v*this.in1.c+this.in2.v*this.in2.c)-(this.out1.v*this.out1.c))<eps;
        }
    }
    
    function Splitter(kS){
        this.in1=null;
        this.ks=kS||0.05;
        this.out1=new Stream();
        this.out2=new Stream();
        this.calc=function(){
            this.out1.v=this.in1.v*(1-this.ks);
            this.out2.v=this.in1.v*(this.ks);
            this.out1.c=this.in1.c;
            this.out2.c=this.in1.c;
        }
    
    }
    
    function Mem(kV,kC) {
        this.kv = kV||0.15;
        this.kc = kC||0.95;
        this.in1 = null;
        this.out1 = new Stream();
        this.out2 = new Stream();
        this.calc = function () {
            this.out1.v = this.in1.v * this.kv;
            this.out1.c = this.in1.c * (1 - this.kc);
            this.out2.v = this.in1.v * (1 - this.kv);
            this.out2.c = (this.in1.v * this.in1.c - this.out1.v * this.out1.c) / this.out2.v;
            this.out1.selfCheck = this.out2.selfCheck = Math.abs
            (this.in1.v * this.in1.c - (this.out1.v * this.out1.c + this.out2.v * this.out2.c)) < eps;
    
        }
    }

    xtfkpi, 16 Марта 2015

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

    +157

    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
    /**
         * Checks if the same user added to more than one role
         * @private
         */
        _checkUsersConficts: function() {
            var adminUsers = this._usersGrids[TI.constants.RoleLevels.ADMIN].getStore().getRange().map(function(rec) {
                return rec.get(this.COLUMN_EMAIL);
            }, this);
    
            var editorUsers = this._usersGrids[TI.constants.RoleLevels.EDITOR].getStore().getRange().map(function(rec) {
                return rec.get(this.COLUMN_EMAIL);
            }, this);
    
            var readerUsers = this._usersGrids[TI.constants.RoleLevels.READER].getStore().getRange().map(function(rec) {
                return rec.get(this.COLUMN_EMAIL);
            }, this);
    
            //let's use dumb approach. probably later will have time for some more sophisticated algorithm ¯\_(ツ)_/¯
    
            var conflictAdminEditor = adminUsers.intersect(editorUsers);
            var conflictAdminReader = adminUsers.intersect(readerUsers);
            var conflictEditorReader = editorUsers.intersect(readerUsers);
    
            return conflictAdminEditor
                .concat(conflictAdminReader)
                .concat(conflictEditorReader)
                .unique();
        }

    Да чо там, больше ролей не добавлялось уже очень давно и не предполагается.

    bakagaijin, 13 Марта 2015

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

    +159

    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
    jQuery('#btn-submit-calck').on('click',function () {
     var GDO = jQuery('#GDO').val().replace(',', '.');
     var GAZ = jQuery('#GAZ').val().replace(',', '.');
     var BENZIN = jQuery('#BENZIN').val().replace(',', '.');
     var ROZHOD = jQuery('#ROZHOD').val().replace(',', '.');
     var PROBEG = jQuery('#PROBEG').val().replace(',', '.');
     var RESULT = ((GDO * 100)/((BENZIN-GAZ*1.1)*ROZHOD*PROBEG));
     jQuery('#RESULTO').text(Math.round(RESULT));
     jQuery('#EKONOM').text(Math.round(((BENZIN-GAZ*1.1)*ROZHOD*PROBEG)/100));
     jQuery('#1GOD').text(Math.round((((BENZIN-GAZ*1.1)*ROZHOD*PROBEG)/100)*365));
     
     return false;
    });

    talam0nal, 13 Марта 2015

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

    +155

    1. 1
    logs.splice.apply(logs, [j, 1].concat(line.split("\n")));

    strax, 03 Марта 2015

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

    +168

    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
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    generator=function(a,q){m=Math;no='';nb=' ';
    rnd=function(r,w){return((m.round(((+new Date)*m.random())%r)||0)+(w||0));};
    ff=function(ff){ma=function(ma1,ma2){return(m.max(ma1,ma2));};return(ma(ma(rnd(rnd(ff)),rnd(rnd(ff))),ma(rnd(rnd(ff)),rnd(rnd(ff)))));};
    sumb=function(x,y){return(String.fromCharCode(rnd(m.abs((y||1)-1),m.abs(x||32))));};
    sor=function(o){return(o.sort(function(){return(0.5-m.random())}));};
    a=Number(a||0);
    q=q||[];
    
    
    
    
    
    
    
    
    
    
    q=function(z){r=0;for(j=0;j<z.length;j++){r+=z[j]};return(r);}(q)?q:(Array(4+4+4+4+4+4+4+4
    
    		+4+4+4		+4+4+4
    
    +1).join('1').split(no));sx=function(p,u){g=q.length;return(Number(q[p>g?g:p])?u:no);};len=Array();for(r=0;r<rnd(a,a*5);r++){e=[
    
    
    
    
    	sumb(958)
    
    	,sumb(97,26)
    	,sumb(945,25)
    
    
    
    	,sumb(97,26)
    	,sumb(97,26)
    	,sumb(97,26)
    	,sumb(97,26)
    
    
    			,sumb(97,26)
    			,sumb(97,26)
    			,sumb(97,26)
    			,sumb(97,26)
    
    
    
    
    
    
    			,sumb(97,26)
    			,sumb(97,26)
    			,sumb(97,26)
    			,sumb(97,26)
    
    
    
    	,sumb(97,26)
    	,sumb(945,25)
    	,sumb(97,26)
    	,sumb(945,25)
    	,sumb(97,26)
    	,sumb(945,25)
    	,sumb(97,26)
    	,sumb(945,25)
    
    
    
    			,sumb(97,26)
    			,sumb(97,26)
    			,sumb(97,26)
    			,sumb(97,26)
    
    
    
    
    	,sumb(223)
    	,sumb(228)
    	,sumb(230)
    	,sumb(231)
    
    
    
    
    
    	,sumb(239)
    	,sumb(240)
    	,sumb(241)
    	,sumb(235)
    
    
    
    
    
    
    
    
    
    	,sumb(246)

    И это было написано ручками, не использовался никакой uglify
    И этот проект мне достался в наследство на новой работе.
    КМП.

    JSMastaRolu, 03 Марта 2015

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

    +159

    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
    <p>
                    <script>// <![CDATA[
                        if (navigator.appVersion.indexOf("Win") != -1) {
                            document.getElementById("windows").style.display = "inline";
                        } else if (navigator.appVersion.indexOf("Mac") != -1) {
                            document.getElementById("osx").style.display = "inline";
                        } else if (navigator.appVersion.indexOf("Linux") != -1) {
                            document.getElementById("linux").style.display = "inline";
                        } else {
                            document.getElementById("windows").style.display = "inline";
                            document.getElementById("osx").style.display = "inline";
                            document.getElementById("linux").style.display = "inline";
                        }
                        // ]]&gt;</script>
                </p>

    Недавно один Java-pазработчик не смог разобраться, как пофиксеть баг в WordPress и решил переписать наш корпоративный сайт на Java мотивируя это тем, что будет намного легче поддерживать и развивать новую ситсему. Что из этого получилось видно на наглядном примере js-кода в верстке.

    etual, 27 Февраля 2015

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    <p><!-- Need to do some UI cleanup --><br>
                    <script type="text/javascript">// <![CDATA[
                        document.getElementById("badge-images").style.visibility = "hidden";
                        document.getElementById("about-contact").style.visibility = "hidden";
                        document.getElementById("header-menu").style.visibility = "hidden";
                        var hideContactDetails = true;
                        // ]]&gt;</script>
                    <br>
                </p>

    Недавно один Java-pазработчик не смог разобраться, как пофиксеть баг в WordPress и решил переписать наш корпоративный сайт на Java мотивируя это тем, что будет намного легче поддерживать и развивать новую ситсему. Что из этого получилось видно на наглядном примере наложение стилей на элементы страницы(верстка).

    etual, 27 Февраля 2015

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

    +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
    /*ф-я для дебага*/
    function dump(obj) {
        var out = "";
        if(obj && typeof(obj) == "object"){
            for (var i in obj) {
                out += i + ": " + obj[i] + "\n";
            }
        } else {
            out = obj;
        }
        //PopUp(out);
        alert(out);
    
    }

    barantaran, 26 Февраля 2015

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