- 1
- 2
- 3
- 4
- 5
- 6
- 7
handleNewConfigRuleLoaded: function(
this.handleConfigRuleLoaded0({rule: event.configRule}, true, false);
},
handleConfigRuleLoaded: function(event) {
this.handleConfigRuleLoaded0(event.configRule, false, false);
},
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−1
handleNewConfigRuleLoaded: function(
this.handleConfigRuleLoaded0({rule: event.configRule}, true, false);
},
handleConfigRuleLoaded: function(event) {
this.handleConfigRuleLoaded0(event.configRule, false, false);
},
Старый добрый бэкбон и не знания карринга
0
$.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
0
// 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){
+1
http://pastebin.com/xww1EKP1
http://map.vmr.gov.ua/scripts/__RasPil.js - было тут
0
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 [];
}
}
обычная рекурсия
0
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 (для работы с выделением текста).
+4
while (st.indexOf(" ") != -1)
st = st.replace(" ", " ");
0
/**
* Static Content Helpers
*/
(function (window, ng, app) {
app.service('$StaticContentHelpers', function () {
var instance = null;
/**
* Конструктор хелперов
*
* @returns {Object} Функции-хелперы
* @constructor
*/
function Init () {
/**
* Обертка для статического контента,
* добавляет static домен, который пришел с бэкенда
*
* @param {String} url Урл, к которому необходимо добавить домен для статики
*
* @return {String} Готовый абсолютный url для статического контента
*/
function wrapStaticContent (url) {
// Проверим, от корня ли путь
return window.currentStaticDomain + ((/(^\/)/.test(url)) ? '' : '/') + url;
}
return {
wrapStaticContent: wrapStaticContent
}
}
function getInstance () {
if (!instance) {
instance = new Init();
}
return instance;
}
return {
getInstance: getInstance
};
});
}(window, angular, mainModule));
гуру паттернов..
+5
$(document).on('click', 'a.switcher_link', function(e) {
e.preventDefault();
var btn = $(this);
$.getJSON(btn.attr('href'), {type: 'json'}, function(data) {
btn.parent().parent().parent().parent().parent().parent().parent().parent().replaceWith(data.data);
});
});
Нашел и ахуел....
+4
$ nodejs
> var buffer = new ArrayBuffer(2);
undefined
> var uint16View = new Uint16Array(buffer);
undefined
> var uint8View = new Uint8Array(buffer);
undefined
> uint16View[0]=0xff00
65280
> uint8View[1]
255
> uint8View[0]
0
https://developer.mozilla.org/en/docs/Web/JavaScript/Typed_arrays
endianness - теперь и в жабаскрипте. Почти как union