1. Лучший говнокод

    В номинации:
    За время:
  2. PHP / Говнокод #25724

    +1

    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
    <?php
    
    
    $cd = dirname($_SERVER['SCRIPT_NAME'])."/resources";
    
    $type=$_GET["type"];
    
    if($type=="emptyhtml")
    {
    	header("Last-Modified: " . gmdate('D, d M Y H:i:s', time()) . 'GMT');
    	header("Expires: " . gmdate('D, d M Y H:i:s', time() + 2592000) . 'GMT');
    	header("Content-Type: text/html");
    	echo("<html><head><title>EMPTY</title></head><body></body></html>");
    	exit(200);
    }
    else if($type=="script")
    {
    	header("Content-Type: application/oct-stream");      //   -< здесь ишибка
    	
    	?>
    	
    	if(!window.CuteWebUI_AjaxUploader_OnPostback)
    	window.CuteWebUI_AjaxUploader_OnPostback=function()
    	{

    Не существует Content-Type: application/oct-stream
    Существует Content-Type: application/octet-stream
    Код работал с ошибкой 10 лет, перестал через директиву безопасности современный браузеров x-content-type-options: nosniff
    Это разработка Cute Editor for PHP https://cutesoft.net/downloads/17/default.aspx
    Гении тоже допускают ошибку...

    increazon, 17 Июля 2019

    Комментарии (158)
  3. PHP / Говнокод #25723

    +1

    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
    $loop = React\EventLoop\Factory::create();
    
    $server = new React\Http\Server(function (Psr\Http\Message\ServerRequestInterface $request) {
        return new React\Http\Response(
            200,
            array('Content-Type' => 'text/plain'),
            "Hello World!\n"
        );
    });
    
    $socket = new React\Socket\Server(8080, $loop);
    $server->listen($socket);
    
    echo "Server running at http://127.0.0.1:8080\n";
    
    $loop->run();

    "ReactPHP".

    BoeHHblu_nemyx, 16 Июля 2019

    Комментарии (18)
  4. Си / Говнокод #25706

    +1

    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
    #define SWITCHCALL                                                         \
      dtrick                                                                   \
      switch(cnt){                                                             \
      case 0:  r = fp(); break;                                                \
      case 1:  r = fp(d[0]); break;                                            \
      case 2:  r = fp(d[0], d[1]); break;                                      \
      case 3:  r = fp(d[0], d[1], d[2]); break;                                \
      case 4:  r = fp(d[0], d[1], d[2], d[3]); break;                          \
      case 5:  r = fp(d[0], d[1], d[2], d[3], d[4]); break;                    \
      case 6:  r = fp(d[0], d[1], d[2], d[3], d[4], d[5]); break;              \
      case 7:  r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6]); break;        \
      case 8:  r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7]); break;  \
      case 9:  r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8]); break;                                            \
      case 10: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9]); break;                                      \
      case 11: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10]); break;                               \
      case 12: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11]); break;                         \
      case 13: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11],d[12]); break;                   \
      case 14: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11],d[12],d[13]); break;             \
      case 15: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11],d[12],d[13],d[14]); break;       \
      case 16: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15]); break; \
      case 17: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15],         \
                      d[16]); break;                                           \
      case 18: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15],         \
                      d[16],d[17]); break;                                     \
      case 19: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15],         \
                      d[16],d[17],d[18]); break;                               \
      case 20: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15],         \
                      d[16],d[17],d[18],d[19]); break;                         \
      case 21: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15],         \
                      d[16],d[17],d[18],d[19],d[20]); break;                   \
      case 22: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15],         \
                      d[16],d[17],d[18],d[19],d[20],d[21]); break;             \
      case 23: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15],         \
                      d[16],d[17],d[18],d[19],d[20],d[21],d[22]); break;       \
      case 24: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15],         \
                      d[16],d[17],d[18],d[19],d[20],d[21],d[22],d[23]); break; \
      case 25: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15],         \
                      d[16],d[17],d[18],d[19],d[20],d[21],d[22],d[23],         \
                      d[24]);break;                                            \
      case 26: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15],         \
                      d[16],d[17],d[18],d[19],d[20],d[21],d[22],d[23],         \
                      d[24],d[25]);break;                                      \
      case 27: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15],         \
                      d[16],d[17],d[18],d[19],d[20],d[21],d[22],d[23],         \
                      d[24],d[25],d[26]);break;                                \
      case 28: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15],         \
                      d[16],d[17],d[18],d[19],d[20],d[21],d[22],d[23],         \
                      d[24],d[25],d[26],d[27]);break;                          \
      case 29: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15],         \
                      d[16],d[17],d[18],d[19],d[20],d[21],d[22],d[23],         \
                      d[24],d[25],d[26],d[27],d[28]);break;                    \
      case 30: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],          \
                      d[8], d[9], d[10],d[11],d[12],d[13],d[14],d[15],         \
                      d[16],d[17],d[18],d[19],d[20],d[21],d[22],d[23],         \
                      d[24],d[25],d[26],d[27],d[28],d[29]);break;              \
    
    
      /******* ну вы понели *******/

    Какой кавай )))
    https://github.com/jsoftware/jsource/blob/master/jsrc/x15.c

    KaBauHblu_nemyx, 08 Июля 2019

    Комментарии (37)
  5. Swift / Говнокод #25705

    +1

    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
    /* Create a JSON object from JSON data stream. The stream should be opened and configured. All other behavior of this method is the same as the JSONObjectWithData:options:error: method.
         */
    open class func jsonObject(with stream: InputStream, options opt: ReadingOptions = []) throws -> Any {
        var data = Data()
        guard stream.streamStatus == .open || stream.streamStatus == .reading else {
             fatalError("Stream is not available for reading")
         }
         repeat {
             var buffer = [UInt8](repeating: 0, count: 1024)
             var bytesRead: Int = 0
             bytesRead = stream.read(&buffer, maxLength: buffer.count)
             if bytesRead < 0 {
                 throw stream.streamError!
             } else {
                 data.append(&buffer, count: bytesRead)
             }
         } while stream.hasBytesAvailable
         return try jsonObject(with: data, options: opt)
    }

    Потоковое чтение JSON от авторов "iСделаль"

    Desktop, 07 Июля 2019

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

    +1

    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
    var XMLHttpRequest = function(XHR, type, listener) {
    	return function() {
    		var xhr = new XHR;
    		xhr.addEventListener(type, listener);
    		return xhr;
    	};
    }(XMLHttpRequest, 'loadend', function(e) {
    	if (this.status == 0) {
    		console.log(e.type, 'network error');
    	} else {
    		console.log(e.type, this.status);
    	}
    });
    
    // js-library code...

    unicorn, 06 Июля 2019

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    xhr.upload.addEventListener('progress', function (e) {
      if (e.lengthComputable) {
        let percents = Math.round(e.loaded / e.total * 100)
        $(`#preloader-${preloaderId}`).html(`${percents}%`)
        $(`#preloader-${preloaderId}`).append(`<style>#preloader-${preloaderId}:before{ width: ${percents * 0.94}px;}</style>`);
      }
    }, false);

    Прогрессбар на псевдоэлементах.

    mesumev, 05 Июля 2019

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

    +1

    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
    function natRound() {
    
    	var out = []
    	    , fib = [0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233] // etc
    	    , _data = function() { // random values
    
    			var out = []
    				, count = Math.round( Math.random() * 100)
    			;
    
    			for(var i=0; i < count; i++ ) {
    				out.push( Math.random() * 100 ); // in km
    			}
    
    			return out.sort(function(a,b){ return a-b; });
    	    }()
    	    , roundTo = function (value) {
    			var i = fib.length;
    			while(i--) {
    				if ( value < fib[i] ) continue;
    				return i? i: value; // natural sorting
    			}
    	    }
    	;
    
    	for( var i=0; i<_data.length; i++ ) {
    		out.push( 'Value: [' + _data[i] + ']; Sort = [' + roundTo(_data[i]) + ']' );
    	}
    
    	return out;
    }

    Необходимо было учесть дискретность при сортировке расстояний в километрах.
    Например, в синтаксисе Elastic это выглядит так:

    "ranges" => [
    [ "to" => 1 ],
    [ "from" => 1, "to" => 3 ],
    [ "from" => 3, "to" => 5 ],
    [ "from" => 5],
    // etc
    ]

    Используя цепочку чисел Фибоначчи, как наиболее "человечески приятный" ряд, функция roundTo возвращает число для сортировки значений массива.

    bot, 04 Июля 2019

    Комментарии (89)
  9. C# / Говнокод #25691

    +1

    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
    void Start () {
    
            carRight1 = GameObject.Find("CarRight1");
            carRight2 = GameObject.Find("CarRight2");
            carRight3 = GameObject.Find("CarRight3");
            carRight4 = GameObject.Find("CarRight4");
            carRight5 = GameObject.Find("CarRight5");
            carRight6 = GameObject.Find("CarRight6");
            carRight7 = GameObject.Find("CarRight7");
            carRight8 = GameObject.Find("CarRight8");
            carRight9 = GameObject.Find("CarRight9");
            carRight10 = GameObject.Find("CarRight10");
            carRight11 = GameObject.Find("CarRight11");
            carRight12 = GameObject.Find("CarRight12");
            carRight13 = GameObject.Find("CarRight13");
            carRight14 = GameObject.Find("CarRight14");
            carRight15 = GameObject.Find("CarRight15");
            carRight16 = GameObject.Find("CarRight16");
            carRight17 = GameObject.Find("CarRight17");
    
            carLeft1 = GameObject.Find("CarLeft1");
            carLeft2 = GameObject.Find("CarLeft2");
            carLeft3 = GameObject.Find("CarLeft3");
            carLeft4 = GameObject.Find("CarLeft4");
            carLeft5 = GameObject.Find("CarLeft5");
            carLeft6 = GameObject.Find("CarLeft6");
            carLeft7 = GameObject.Find("CarLeft7");
            carLeft8 = GameObject.Find("CarLeft8");
            carLeft9 = GameObject.Find("CarLeft9");
            carLeft10 = GameObject.Find("CarLeft10");
            carLeft11 = GameObject.Find("CarLeft11");
            carLeft12 = GameObject.Find("CarLeft12");
            carLeft13 = GameObject.Find("CarLeft13");
            carLeft14 = GameObject.Find("CarLeft14");
            carLeft15 = GameObject.Find("CarLeft15");
            carLeft16 = GameObject.Find("CarLeft16");
            carLeft17 = GameObject.Find("CarLeft17");
            carLeft18 = GameObject.Find("CarLeft18");
            carLeft19 = GameObject.Find("CarLeft19");
            carLeft20 = GameObject.Find("CarLeft20");
            carLeft21 = GameObject.Find("CarLeft21");
            carLeft22 = GameObject.Find("CarLeft22");
    
            speed = 15f;
            //gameObject.transform.localScale = new Vector3(0, 0, 0);
        }
    	
    	// Update is called once per frame
    	void Update () {
    		
            carRight1.GetComponent<Rigidbody>().velocity = carRight1.transform.forward * speed;
            carRight2.GetComponent<Rigidbody>().velocity = carRight2.transform.forward * speed;
            carRight3.GetComponent<Rigidbody>().velocity = carRight3.transform.forward * speed;
            carRight4.GetComponent<Rigidbody>().velocity = carRight4.transform.forward * speed;
            carRight5.GetComponent<Rigidbody>().velocity = carRight5.transform.forward * speed;
            carRight6.GetComponent<Rigidbody>().velocity = carRight6.transform.forward * speed;
            carRight7.GetComponent<Rigidbody>().velocity = carRight7.transform.forward * speed;
            carRight8.GetComponent<Rigidbody>().velocity = carRight8.transform.forward * speed;
            carRight9.GetComponent<Rigidbody>().velocity = carRight9.transform.forward * speed;
            carRight10.GetComponent<Rigidbody>().velocity = carRight10.transform.forward * speed;
            carRight11.GetComponent<Rigidbody>().velocity = carRight11.transform.forward * speed;
            carRight12.GetComponent<Rigidbody>().velocity = carRight12.transform.forward * speed;
            carRight13.GetComponent<Rigidbody>().velocity = carRight13.transform.forward * speed;
            carRight14.GetComponent<Rigidbody>().velocity = carRight14.transform.forward * speed;
            carRight15.GetComponent<Rigidbody>().velocity = carRight15.transform.forward * speed;
            carRight16.GetComponent<Rigidbody>().velocity = carRight16.transform.forward * speed;
            carRight17.GetComponent<Rigidbody>().velocity = carRight17.transform.forward * speed;
    
            carLeft1.GetComponent<Rigidbody>().velocity = carLeft1.transform.forward * speed;
            carLeft2.GetComponent<Rigidbody>().velocity = carLeft2.transform.forward * speed;
            carLeft3.GetComponent<Rigidbody>().velocity = carLeft3.transform.forward * speed;
            carLeft4.GetComponent<Rigidbody>().velocity = carLeft4.transform.forward * speed;
            carLeft5.GetComponent<Rigidbody>().velocity = carLeft5.transform.forward * speed;
            carLeft6.GetComponent<Rigidbody>().velocity = carLeft6.transform.forward * speed;
            carLeft7.GetComponent<Rigidbody>().velocity = carLeft7.transform.forward * speed;
            carLeft8.GetComponent<Rigidbody>().velocity = carLeft8.transform.forward * speed;
            carLeft9.GetComponent<Rigidbody>().velocity = carLeft9.transform.forward * speed;
            carLeft10.GetComponent<Rigidbody>().velocity = carLeft10.transform.forward * speed;
            carLeft11.GetComponent<Rigidbody>().velocity = carLeft11.transform.forward * speed;
            carLeft12.GetComponent<Rigidbody>().velocity = carLeft12.transform.forward * speed;
            carLeft13.GetComponent<Rigidbody>().velocity = carLeft13.transform.forward * speed;
            carLeft14.GetComponent<Rigidbody>().velocity = carLeft14.transform.forward * speed;
            carLeft15.GetComponent<Rigidbody>().velocity = carLeft15.transform.forward * speed;
            carLeft16.GetComponent<Rigidbody>().velocity = carLeft16.transform.forward * speed;
            carLeft17.GetComponent<Rigidbody>().velocity = carLeft17.transform.forward * speed;
            carLeft18.GetComponent<Rigidbody>().velocity = carLeft18.transform.forward * speed;
            carLeft19.GetComponent<Rigidbody>().velocity = carLeft19.transform.forward * speed;
            carLeft20.GetComponent<Rigidbody>().velocity = carLeft20.transform.forward * speed;
            carLeft21.GetComponent<Rigidbody>().velocity = carLeft21.transform.forward * speed;
            carLeft22.GetComponent<Rigidbody>().velocity = carLeft22.transform.forward * speed;
    
        }

    Обнаружил на ПК у "коллеги" по цеху. AI для машинок... (Сами переменные не влезли, но легко понять как они заданы.)

    Morseliot, 29 Июня 2019

    Комментарии (53)
  10. PHP / Говнокод #25687

    +1

    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
    <script>
        var myMap;
        var ymapsReady = function () {
            myMap = new ymaps.Map('<?= $options['containerId'] ?>', {
                center: [55.751574, 37.573856],
                zoom: 9,
                controls: []
            }, {
                searchControlProvider: 'yandex#search'
            });
    
            <?php
            if(isset($options['centerCoordinates'])){
            ?>
            myMap.setCenter(<?= $options['centerCoordinates'] ?>);
            <?php
            }elseif(isset($options['centerAddress'])){?>
            ymaps.geocode('<?= $options['centerAddress'] ?>', {
                results: 1
            }).then(function (res) {
                var firstGeoObject = res.geoObjects.get(0),
                    coords = firstGeoObject.geometry.getCoordinates();
                myMap.setCenter(coords);
            });
            <?php
            }
    
            if (!empty($options['salesOffices'])) {
                foreach( $options['salesOffices'] as $i => $salesOffice ) {
                $address = ArrayHelper::getValue($salesOffice, 'actual_address');
                ?>
                ymaps.geocode('<?= $address ?>', {
                    results: 1
                }).then(function (res) {
                    let firstGeoObject = res.geoObjects.get(0),
                        coords = firstGeoObject.geometry.getCoordinates();
    
                    ymaps.geocode(coords, {
                        kind: 'metro',
                        results: 2
                    }).then(function (res) {
                        res.geoObjects.each(function (geoObject) {
                            $('#placemark_<?= $i ?>').find('.metro').append("<div class='metro-item'>" + geoObject.getPremise().replace(/(^|\s)метро(\s|$)/g, '').replace(/(^|\s)станция(\s|$)/g, '') + '</div>');
                        });
                    });
    
                    let customIcon = ymaps.templateLayoutFactory.createClass('<div id="placemark_icon_<?= $i ?>" class="placemark-block"><div class="placemark"></div><div class="placemark-text"><?= ArrayHelper::getValue($salesOffice, 'name') ?></div></div>');
    
                    myPlacemark[<?= $i ?>] = new ymaps.Placemark(coords,
                        {
                            balloonContent: '<?= ArrayHelper::getValue($salesOffice, 'name') ?>',
                            iconCaption: customIcon,
    
                            iconLayout: 'default#imageWithContent',
                            iconContentLayout: customIcon
                        }, {
                            hintContent: '<?= ArrayHelper::getValue($salesOffice, 'name') ?>',
                            iconLayout: 'default#imageWithContent',
                            iconImageHref: '',
                            iconImageOffset: [-15, -27],
                            iconContentLayout: customIcon
                        });
    
                    myMap.geoObjects.add(myPlacemark[<?= $i ?>]);
                });
    
                <?php
                }
            }
            ?>
        };
    
        setTimeout(function () {
            ymaps.ready(ymapsReady);
        }, <?=( isset($options['isModal']) ? 500 : 0 )?>);
    </script>

    iErroRi, 25 Июня 2019

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function htmlspecialchars (s) {
        const el = document.createElement('span');
        el.innerText = s;
        return el.innerHTML.replace(/<br>/g, "\n");
    }

    Почему в жепаскрипте нет прямого доступа к этой функции? Почему я должен для этого работать с DOM или сам писать эту поеботу на рагулярках? Почему асё так анально?

    O4epegHou_nemyx, 10 Июня 2019

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