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

    +5

    1. 1
    2. 2
    3. 3
    if ($('.b-form__row_hide').hasClass('b-form__row_hide')) {
    	$('.b-form__row_hide').addClass('b-form__row_hide');
    }

    riddick6600, 02 Июня 2016

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

    +2

    1. 1
    $ npm install ember-cli-phone-number --save-dev

    Всё достаточно просто. Нам нужен текстовый инпут, в который пользователь вводит свой номер мобильного телефона. Предназначение: sms-оповещение. Проблема в том, что все существующие решения привязываются к определённому формату номера (US, Canada), а при использовании международного формата для US-номера выясняется, что в нём 11 цифр, а не 12. Пользователь же может иметь номер хоть в ёбаном Вануату. Текущее решение: принимать любой текст в инпут, делать .replace(/[^0-9]/g, ''), схоронять в базу и ебаться с этим потом. Чувствую запашок, но не могу понять откуда. Швабрашвабр про телефонные номера читал. inb4, js не нужен.
    Запашок наверное всё-таки от стандартов телефонных номеров...

    bakagaijin, 01 Июня 2016

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

    +6

    1. 1
    2. 2
    3. 3
    4. 4
    > var x = new String("eval(x.toString())");
    undefined
    > eval(x.toString());
    RangeError: Maximum call stack size exceeded

    Yo dawg, I heard you like evaluation. So I put evaluation in your evaluation so you could evaluate while you evaluate
    Жаль что nodejs не осиливает заоптимизировать это как бесконечный цикл

    j123123, 31 Мая 2016

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

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    /*не знаю, почему на массиве не сработал concat()*/
    function arrPusher (arr) {
        _.forEach(arr, function (i) {
            saveParams.push(i);
        });
    }

    finico, 24 Мая 2016

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

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    handleNewConfigRuleLoaded: function(
        this.handleConfigRuleLoaded0({rule: event.configRule}, true, false);
    },
    
    handleConfigRuleLoaded: function(event) {
        this.handleConfigRuleLoaded0(event.configRule, false, false);
    },

    Старый добрый бэкбон и не знания карринга

    NuclleaR, 24 Мая 2016

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

    0

    1. 1
    2. 2
    $.get( '/scripts/ajax/popup/add_to_favorite.php', { id: productID, ajax_call: 'Y' }, function ( data ) {
                        data = JSON.parse( data );

    $.getJSON
    http://www.sapato.ru/js/ajax/widgets/baseAjaxes.js?bust=208

    nik757, 23 Мая 2016

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

    0

    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
    // jquery required
    
    function trim(str){
    	return str.replace(/^\s+/, "").replace(/\s+$/, "");
    }
    
    function round1000(val){
    	return Math.round(parseInt(val)/1000)*1000;
    }
    function floor1000(val){
    	return Math.floor(parseInt(val)/1000)*1000;
    }
    function ceil1000(val){
    	return Math.ceil(parseInt(val)/1000)*1000;
    }
    
    function setCookie(c_name,value,expiredays){
    	var exdate=new Date();
    	exdate.setDate(exdate.getDate()+expiredays);
    	document.cookie=c_name+'='+escape(value)+((expiredays==null)?'':';expires='+exdate.toGMTString())+';path=/';
    }
    
    function resetCookie(c_name){
      var exdate=new Date(0);
    	document.cookie = c_name + '=0;expires=' + exdate.toUTCString() + ';path=/';
    }
    
    function getCookie(name){
    	var cookies=document.cookie.split(";");
    	for(var i=0;i<cookies.length;i++){
    		var params=cookies[i].split("=");
    		if(trim(params[0])==name){
    			return unescape(params[1]);
    		}
    	}
    	return false;
    }
    
    function asyncScriptLoader(scriptUrl){
    	var d=document,
    	h=d.getElementsByTagName('head')[0],
    	s=d.createElement('script');
    	s.type='text/javascript';
    	s.async=true;
    	s.src=scriptUrl;
    	h.appendChild(s);
    }

    http://www.morton.ru/images/js/main.js

    >> // jquery required
    >> function asyncScriptLoader(scriptUrl){

    nik757, 20 Мая 2016

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

    +1

    1. 1
    http://pastebin.com/xww1EKP1

    http://map.vmr.gov.ua/scripts/__RasPil.js - было тут

    j123123, 18 Мая 2016

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

    0

    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
    function * getTreePost(postsInfo, id) {
      var parent = _.filter(postsInfo, function (item) {
        return Boolean(item._id == id);
      });
    
      var children = _.filter(postsInfo, function (item) {
        return Boolean(item.parentId);
      });
    
      return _.union(parent, findChildren(id, children));
    
      function findChildren(parentId) {
        if (parentId) {
          var data = _.where(children, {parentId: parentId});
          var ret = [];
          if (data.length) {
            _.each(data, function (item, index) {
              var data_r = findChildren(item._id);
              if (data_r.length) {
                ret = _.union(data_r, ret);
              }
            });
            return _.union(data, ret);
          } else
            return [];
        } else return [];
      }
    }

    обычная рекурсия

    volodymyrkoval, 18 Мая 2016

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

    0

    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
    function saveQuestion() {
    	var questionContent = {};
    	var questionResult = {};
    	switch(questionFields.attr('class')) {
    		case 'check-question':
    			questionResult.text = questionFields.children('.question-text')[0].innerText;																				
    			questionResult.type = 'check';
    			questionResult.answers = [];
    			[].forEach.call(questionFields.children('.answer-preview'), function(answerElement, i, arr) {
    				var answer = {};
    				answer.text = $(answerElement).children('.answer-text')[0].innerText;
    				answer.right = ($(answerElement).children('.answer-check')[0].checked) ? 1 : 0;
    				answer.weight = (!answer.right) ? $(answerElement).children('.answer-weight')[0].getPosition() : 1;
    				answer.weight = (answer.weight > 0 && answer.weight <= 1) ? answer.weight : 0;
    				questionResult.answers.push(answer);
    			});
    			
    			if (checkQuestionCorrect(questionResult)) {
    				questionResult= JSON.stringify(questionResult);
    				questionContent = JSON.parse(questionResult); //клонируем объект
    				[].forEach.call(questionContent.answers, function(answer, i, answers) { delete answer.right; delete answer.weight; });
    				questionContent = JSON.stringify(questionContent);
    				console.log('result: ' + questionResult);
    				console.log('content: ' + questionContent);
    				net.addQuestion(loID, questionContent, questionResult, function(r){
    					$('.add-question').slideUp(200, function(){
    						$('.add-question-row').remove();
    						openLOPreview(loID);
    					});
    				});
    			}
    		break;	
    		
    		case 'input-question':
    			var highlights = highlighter.highlights;
    			questionResult.type = 'input';
    			questionResult.text = $('#question-text-area').get(0).innerText;
    			questionResult.answers = [];
    			for (i = 0; i < highlights.length; i++) {
    				var answer = {};
    				answer.id = highlights[i].id;
    				answer.posStart = highlights[i].characterRange.start;
    				answer.posEnd = highlights[i].characterRange.end;
    				answer.text = highlights[i].answerText;
    				answer.strict = ('strict' in highlights[i]) ? highlights[i].strict : true;
    				questionResult.answers.push(answer);
    			}
    			questionResult.answers.sort(function(a, b){ return a.posStart - b.posStart; });
    			questionResult.serializedHighlight = highlighter.serialize();
    			questionResult = JSON.stringify(questionResult);
    			questionContent = JSON.stringify(questionContent);
    			
    			net.addQuestion(loID, questionContent, questionResult, function(r){
    				$('.add-question').slideUp(200, function(){
    						$('.add-question-row').remove();
    						openLOPreview(loID);
    					});
    			});	
    		break;
    		
    		default: break;
    	}							
    }

    Моя дипломная работа по теме "тестирование студентов". Конструктор тестов, обработчик кнопки сохранения вопроса. Используются библиотеки jQuery и Rangy (для работы с выделением текста).

    cotheq, 16 Мая 2016

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