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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    var s = '';
    	s += (hours)  ? ( (hours>9)  ? hours  + ':' : '0' + hours  + ':') : '00:';
    	s += (minute) ? ( (minute>9) ? minute + ':' : '0' + minute + ':') : '00:';
    	s += (second) ? ( (second>9) ? second + '.' : '0' + second + '.') : '00.';

    почему бы не сделать так:
    var s = '';
    s += (hours<10) ? '0' + hours : hours) + ':';
    // и так далее...

    rudolff, 05 Августа 2010

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

    +168

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    var count = response.data.length;
    var all_count = count;
    if(all_count > count) {
        count = all_count - count;
    }

    Уличная магия. О_о (Мапед не мой)

    Alex_Slubsky, 04 Августа 2010

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

    +144

    1. 1
    $('.margin20').append(' ').append($('<button>Save</button>');

    jquery нам подарил много выдающихся личностей.

    вот так мы создаем кнопку. что за класс .margin20 можно догадаться из названия )

    Lure Of Chaos, 03 Августа 2010

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

    +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
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    function doIframe(){
    	o = document.getElementsByTagName('iframe');
    	for(i=0;i<o.length;i++){
    		if (/\bautoHeight\b/.test(o[i].className)){
    			setHeight(o[i]);
    			addEvent(o[i],'load', doIframe);
    		}
    	}
    }
    
    function setHeight(e){
    	if(e.contentDocument){
    		e.height = e.contentDocument.body.offsetHeight + 35;
    	} else {
    		e.height = e.contentWindow.document.body.scrollHeight;
    	}
    }
    
    function addEvent(obj, evType, fn){
    	if(obj.addEventListener)
    	{
    	obj.addEventListener(evType, fn,false);
    	return true;
    	} else if (obj.attachEvent){
    	var r = obj.attachEvent("on"+evType, fn);
    	return r;
    	} else {
    	return false;
    	}
    }
    
    if (document.getElementById && document.createTextNode){
     addEvent(window,'load', doIframe);	
    }

    http://www.lost-in-code.com/wp-content/projects/auto-iframe-height/jquery.autoheight.js

    striker, 02 Августа 2010

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function create (char, repeat) {
    var string = '';
    while (repeat--) string += char;
    return string;
    }

    Заполняем строку одинаковыми символами

    eval, 01 Августа 2010

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

    +157

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    function writemsg(msg, colors)
    {
    	length = msg.length;
    	i=0;
    	while(i<length)
    	{
    		document.getElementById("msgbox").innerHTML = document.getElementById("msgbox").innerHTML + "<br><font color="+colors[i]+">"+msg[i]+"</font>";
    		i=i+1; //z
    	}
    	return true;
    }

    XyHb, 31 Июля 2010

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

    +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 posit(texta,  textb)
    {
    	texta = texta + "";
    	return texta.indexOf(textb+"");
    }
    function trimme(texta)
    {
    	var trimming = true;
    	while(trimming == true)
    	{
    		if((posit(texta, "  ")+1)>0)
    		{
    			texta = texta+" ";
    			texta = texta.substr(0, posit(texta, "  "));	
    		}
    		if((posit(texta, "  ")+1) == 0)
    		{
    			trimming = false;
    		}
    	}
    	return texta;
    }

    Тихий ужас

    XyHb, 29 Июля 2010

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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    function repeattimer(functionname, looptime){
    	eval(functionname+"();");
    	setTimeout("repeattimer(\""+functionname+"\", "+looptime+");", looptime);
    }

    Не знаю насчёт того, ГК это или нет, но я бы сделал совсем не таким способом.

    XyHb, 28 Июля 2010

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

    +167

    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
    function createIMG(src,id,width,height,border)
    {
    	var s='<IMG SRC=';
    	s+=addquo(src);
    	if(id!='')
    		s+=' ID='+id;
    	if(width&&height)
    	{
    		if(width>0)
    			s+=' WIDTH='+width;
    		if(height>0)
    			s+=' HEIGHT='+height;
    	}
    	s+=' BORDER='+border+'>';
    	return s;
    }

    Оно делает картинку

    ursus, 27 Июля 2010

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

    +170

    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
    star1.onmouseover = function () {
    star1.className = 'selected';
    }
    star1.onmouseout = function () {
    star1.className = 'not-selected';
    }
    star2.onmouseover = function () {
    star1.className = 'selected';
    star2.className = 'selected';
    }
    star2.onmouseout = function () {
    star1.className = 'not-selected';
    star2.className = 'not-selected';
    }
    star3.onmouseover = function () {
    star1.className = 'selected';
    star2.className = 'selected';
    star3.className = 'selected';
    }
    star3.onmouseout = function () {
    star1.className = 'not-selected';
    star2.className = 'not-selected';
    star3.className = 'not-selected';
    }
    star4.onmouseover = function () {
    star1.className = 'selected';
    star2.className = 'selected';
    star3.className = 'selected';
    star4.className = 'selected';
    }
    star4.onmouseout = function () {
    star1.className = 'not-selected';
    star2.className = 'not-selected';
    star3.className = 'not-selected';
    star4.className = 'not-selected';
    }
    star5.onmouseover = function () {
    star1.className = 'selected';
    star2.className = 'selected';
    star3.className = 'selected';
    star4.className = 'selected';
    star5.className = 'selected';
    }
    star5.onmouseout = function () {
    star1.className = 'not-selected';
    star2.className = 'not-selected';
    star3.className = 'not-selected';
    star4.className = 'not-selected';
    star5.className = 'not-selected';
    }

    Реализация звёздочек для рейтинга. При наведении мышкой на звёздочку все предшествующие ей звёздочки "загораются", при отведении — "потухают".

    eval, 25 Июля 2010

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