beautify_js

This commit is contained in:
Ilya Kantor 2015-03-09 18:48:58 +03:00
parent 0febe4f5fd
commit 5c2f32e184
208 changed files with 3891 additions and 1474 deletions

View file

@ -1,12 +1,24 @@
describe("Тест", function() { describe("Тест", function() {
before(function() { alert("Начало всех тестов"); }); before(function() {
after(function() { alert("Окончание всех тестов"); }); alert("Начало всех тестов");
});
after(function() {
alert("Окончание всех тестов");
});
beforeEach(function() { alert("Вход в тест"); }); beforeEach(function() {
afterEach(function() { alert("Выход из теста"); }); alert("Вход в тест");
});
afterEach(function() {
alert("Выход из теста");
});
it('тест 1', function() { alert('1'); }); it('тест 1', function() {
it('тест 2', function() { alert('2'); }); alert('1');
});
it('тест 2', function() {
alert('2');
});
}); });

View file

@ -4,6 +4,8 @@ describe("isEmpty", function() {
}); });
it("если у объекта есть любое свойство, не важно какое - возвращает false", function() { it("если у объекта есть любое свойство, не важно какое - возвращает false", function() {
assert.isFalse( isEmpty({ anything: false }) ); assert.isFalse(isEmpty({
anything: false
}));
}); });
}); });

View file

@ -1,5 +1,6 @@
function getMaxSubSum(arr) { function getMaxSubSum(arr) {
var maxSum = 0, partialSum = 0; var maxSum = 0,
partialSum = 0;
for (var i = 0; i < arr.length; i++) { for (var i = 0; i < arr.length; i++) {
partialSum += arr[i]; partialSum += arr[i];
maxSum = Math.max(maxSum, partialSum); maxSum = Math.max(maxSum, partialSum);
@ -7,4 +8,3 @@ function getMaxSubSum(arr) {
} }
return maxSum; return maxSum;
} }

View file

@ -1,7 +1,9 @@
describe("addClass", function() { describe("addClass", function() {
it("добавляет класс, которого нет", function() { it("добавляет класс, которого нет", function() {
var obj = { className: 'open menu' }; var obj = {
className: 'open menu'
};
addClass(obj, 'new'); addClass(obj, 'new');
assert.deepEqual(obj, { assert.deepEqual(obj, {
className: 'open menu new' className: 'open menu new'
@ -9,7 +11,9 @@ describe("addClass", function() {
}); });
it("не добавляет класс, который уже есть", function() { it("не добавляет класс, который уже есть", function() {
var obj = { className: 'open menu' }; var obj = {
className: 'open menu'
};
addClass(obj, 'open'); addClass(obj, 'open');
assert.deepEqual(obj, { assert.deepEqual(obj, {
className: 'open menu' className: 'open menu'
@ -17,7 +21,9 @@ describe("addClass", function() {
}); });
it("не добавляет лишних пробелов, который уже есть", function() { it("не добавляет лишних пробелов, который уже есть", function() {
var obj = { className: '' }; var obj = {
className: ''
};
addClass(obj, 'open'); addClass(obj, 'open');
assert.deepEqual(obj, { assert.deepEqual(obj, {
className: 'open' className: 'open'

View file

@ -1,7 +1,8 @@
describe("unique", function() { describe("unique", function() {
it("убирает неуникальные элементы из массива", function() { it("убирает неуникальные элементы из массива", function() {
var strings = ["кришна", "кришна", "харе", "харе", var strings = ["кришна", "кришна", "харе", "харе",
"харе", "харе", "кришна", "кришна", "8-()"]; "харе", "харе", "кришна", "кришна", "8-()"
];
assert.deepEqual(unique(strings), ["кришна", "харе", "8-()"]); assert.deepEqual(unique(strings), ["кришна", "харе", "8-()"]);
}); });

View file

@ -1,7 +1,9 @@
describe("removeClass", function() { describe("removeClass", function() {
it("ничего не делает, если класса нет", function() { it("ничего не делает, если класса нет", function() {
var obj = { className: 'open menu' }; var obj = {
className: 'open menu'
};
removeClass(obj, 'new'); removeClass(obj, 'new');
assert.deepEqual(obj, { assert.deepEqual(obj, {
className: 'open menu' className: 'open menu'
@ -9,7 +11,9 @@ describe("removeClass", function() {
}); });
it("не меняет пустое свойство", function() { it("не меняет пустое свойство", function() {
var obj = { className: '' }; var obj = {
className: ''
};
removeClass(obj, 'new'); removeClass(obj, 'new');
assert.deepEqual(obj, { assert.deepEqual(obj, {
className: "" className: ""
@ -17,7 +21,9 @@ describe("removeClass", function() {
}); });
it("удаляет класс, не оставляя лишних пробелов", function() { it("удаляет класс, не оставляя лишних пробелов", function() {
var obj = { className: 'open menu' }; var obj = {
className: 'open menu'
};
removeClass(obj, 'open'); removeClass(obj, 'open');
assert.deepEqual(obj, { assert.deepEqual(obj, {
className: "menu" className: "menu"
@ -25,7 +31,9 @@ describe("removeClass", function() {
}); });
it("если класс один и он удалён, то результат - пустая строка", function() { it("если класс один и он удалён, то результат - пустая строка", function() {
var obj = { className: "menu" }; var obj = {
className: "menu"
};
removeClass(obj, 'menu'); removeClass(obj, 'menu');
assert.deepEqual(obj, { assert.deepEqual(obj, {
className: "" className: ""

View file

@ -19,4 +19,3 @@ it("приводит всё к строке", function() {
buffer(false); buffer(false);
assert.equal(buffer(), "nullfalse"); assert.equal(buffer(), "nullfalse");
}); });

View file

@ -9,4 +9,3 @@ function inBetween(a, b) {
function inArray(arr) { function inArray(arr) {
// ...ваш код... // ...ваш код...
} }

View file

@ -35,11 +35,15 @@ describe("inBetween", function() {
describe("filter", function() { describe("filter", function() {
it("фильтрует через func", function() { it("фильтрует через func", function() {
assert.deepEqual( filter(arr, function(a) { return a % 2 == 0; }), [2,4,6] ); assert.deepEqual(filter(arr, function(a) {
return a % 2 == 0;
}), [2, 4, 6]);
}); });
it("не модифицирует исходный массив", function() { it("не модифицирует исходный массив", function() {
filter(arr, function(a) { return a % 2 == 0; }); filter(arr, function(a) {
return a % 2 == 0;
});
assert.deepEqual(arr, [1, 2, 3, 4, 5, 6, 7]); assert.deepEqual(arr, [1, 2, 3, 4, 5, 6, 7]);
}); });

View file

@ -12,4 +12,3 @@ var calculator = {
this.b = +prompt('b?', 0); this.b = +prompt('b?', 0);
} }
} }

View file

@ -33,7 +33,9 @@ describe("makeLogging", function() {
var log = []; var log = [];
var calculator = { var calculator = {
double: function(x) { return x*2; } double: function(x) {
return x * 2;
}
} }
calculator.double = sinon.spy(calculator.double); calculator.double = sinon.spy(calculator.double);

View file

@ -7,9 +7,3 @@ function makeLogging(f, log) {
return wrapper; return wrapper;
} }

View file

@ -1,4 +1,3 @@
describe("makeLogging", function() { describe("makeLogging", function() {
it("записывает вызовы в массив log", function() { it("записывает вызовы в массив log", function() {
var work = sinon.spy(); var work = sinon.spy();
@ -8,10 +7,15 @@ describe("makeLogging", function() {
assert.deepEqual(log, []); assert.deepEqual(log, []);
work(1, 2); work(1, 2);
assert.deepEqual( log, [[1, 2]]); assert.deepEqual(log, [
[1, 2]
]);
work(3, 4); work(3, 4);
assert.deepEqual( log, [[1, 2], [3,4]]); assert.deepEqual(log, [
[1, 2],
[3, 4]
]);
}); });
it("передаёт вызов функции, возвращает её результат", function() { it("передаёт вызов функции, возвращает её результат", function() {
@ -34,7 +38,9 @@ describe("makeLogging", function() {
var log = []; var log = [];
var calculator = { var calculator = {
sum: function(a, b) { return a + b; } sum: function(a, b) {
return a + b;
}
} }
calculator.sum = sinon.spy(calculator.sum); calculator.sum = sinon.spy(calculator.sum);

View file

@ -9,6 +9,7 @@ describe("delay", function() {
it("вызывает функцию через указанный таймаут", function() { it("вызывает функцию через указанный таймаут", function() {
var start = Date.now(); var start = Date.now();
function f(x) { function f(x) {
assert.equal(Date.now() - start, 1000); assert.equal(Date.now() - start, 1000);
} }

View file

@ -11,7 +11,9 @@ function debounce(f, ms) {
state = COOLDOWN; state = COOLDOWN;
setTimeout(function() { state = null }, ms); setTimeout(function() {
state = null
}, ms);
} }
} }

View file

@ -9,16 +9,25 @@ describe("debounce", function() {
it("вызывает функцию не чаще чем раз в ms миллисекунд", function() { it("вызывает функцию не чаще чем раз в ms миллисекунд", function() {
var log = ''; var log = '';
function f(a) { log += a; }
function f(a) {
log += a;
}
f = debounce(f, 1000); f = debounce(f, 1000);
f(1); // выполнится сразу же f(1); // выполнится сразу же
f(2); // игнор f(2); // игнор
setTimeout(function() { f(3) }, 100); // игнор (рановато) setTimeout(function() {
setTimeout(function() { f(4) }, 1100); // выполнится (таймаут прошёл) f(3)
setTimeout(function() { f(5) }, 1500); // игнор }, 100); // игнор (рановато)
setTimeout(function() {
f(4)
}, 1100); // выполнится (таймаут прошёл)
setTimeout(function() {
f(5)
}, 1500); // игнор
this.clock.tick(5000); this.clock.tick(5000);
assert.equal(log, "14"); assert.equal(log, "14");

View file

@ -1,7 +1,10 @@
describe("throttle(f, 1000)", function() { describe("throttle(f, 1000)", function() {
var f1000; var f1000;
var log = ""; var log = "";
function f(a) { log += a; }
function f(a) {
log += a;
}
before(function() { before(function() {
f1000 = throttle(f, 1000); f1000 = throttle(f, 1000);

View file

@ -1,4 +1,3 @@
function Clock(options) { function Clock(options) {
this._template = options.template; this._template = options.template;
} }

View file

@ -1,4 +1,3 @@
function Clock(options) { function Clock(options) {
this._template = options.template; this._template = options.template;
} }

View file

@ -1,5 +1,3 @@
function ExtendedClock(options) { function ExtendedClock(options) {
Clock.apply(this, arguments); Clock.apply(this, arguments);
this._precision = +options.precision || 1000; this._precision = +options.precision || 1000;

View file

@ -1,4 +1,3 @@
function Clock(options) { function Clock(options) {
this._template = options.template; this._template = options.template;
} }

View file

@ -1,5 +1,3 @@
function ExtendedClock(options) { function ExtendedClock(options) {
Clock.apply(this, arguments); Clock.apply(this, arguments);
this._precision = +options.precision || 1000; this._precision = +options.precision || 1000;

View file

@ -1,4 +1,3 @@
function Clock(options) { function Clock(options) {
this._template = options.template; this._template = options.template;
} }

View file

@ -3,6 +3,7 @@ function extend(Child, Parent) {
Child.prototype.constructor = Child; Child.prototype.constructor = Child;
Child.parent = Parent.prototype; Child.parent = Parent.prototype;
} }
function inherit(proto) { function inherit(proto) {
function F() {} function F() {}
F.prototype = proto; F.prototype = proto;

View file

@ -1,5 +1,6 @@
if (!window.setImmediate) window.setImmediate = (function() { if (!window.setImmediate) window.setImmediate = (function() {
var head = { }, tail = head; // очередь вызовов, 1-связный список var head = {},
tail = head; // очередь вызовов, 1-связный список
var ID = Math.random(); // уникальный идентификатор var ID = Math.random(); // уникальный идентификатор
@ -18,7 +19,9 @@ if (!window.setImmediate) window.setImmediate = (function() {
} }
return window.postMessage ? function(func) { return window.postMessage ? function(func) {
tail = tail.next = { func: func }; tail = tail.next = {
func: func
};
window.postMessage(ID, "*"); window.postMessage(ID, "*");
} : } :
function(func) { // IE7- function(func) { // IE7-

View file

@ -17,7 +17,8 @@ function fixIERangeObject(range, win) { //Only for IE8 and below.
var _findTextNode = function(parentElement, text) { var _findTextNode = function(parentElement, text) {
//Iterate through all the child text nodes and check for matches //Iterate through all the child text nodes and check for matches
//As we go through each text node keep removing the text value (substring) from the beginning of the text variable. //As we go through each text node keep removing the text value (substring) from the beginning of the text variable.
var container=null,offset=-1; var container = null,
offset = -1;
for (var node = parentElement.firstChild; node; node = node.nextSibling) { for (var node = parentElement.firstChild; node; node = node.nextSibling) {
if (node.nodeType == 3) { //Text node if (node.nodeType == 3) { //Text node
var find = node.nodeValue; var find = node.nodeValue;
@ -33,11 +34,16 @@ function fixIERangeObject(range, win) { //Only for IE8 and below.
} }
//Debug Message //Debug Message
//alert(container.nodeValue); //alert(container.nodeValue);
return {node: container,offset: offset}; //nodeInfo return {
node: container,
offset: offset
}; //nodeInfo
} }
var rangeCopy1=range.duplicate(), rangeCopy2=range.duplicate(); //Create a copy var rangeCopy1 = range.duplicate(),
var rangeObj1=range.duplicate(), rangeObj2=range.duplicate(); //More copies :P rangeCopy2 = range.duplicate(); //Create a copy
var rangeObj1 = range.duplicate(),
rangeObj2 = range.duplicate(); //More copies :P
rangeCopy1.collapse(true); //Go to beginning of the selection rangeCopy1.collapse(true); //Go to beginning of the selection
rangeCopy1.moveEnd('character', 1); //Select only the first character rangeCopy1.moveEnd('character', 1); //Select only the first character
@ -46,7 +52,8 @@ function fixIERangeObject(range, win) { //Only for IE8 and below.
//Debug Message //Debug Message
// alert(rangeCopy1.text); //Should be the first character of the selection // alert(rangeCopy1.text); //Should be the first character of the selection
var parentElement1=rangeCopy1.parentElement(), parentElement2=rangeCopy2.parentElement(); var parentElement1 = rangeCopy1.parentElement(),
parentElement2 = rangeCopy2.parentElement();
//If user clicks the input button without selecting text, then moveToElementText throws an error. //If user clicks the input button without selecting text, then moveToElementText throws an error.
if (parentElement1 instanceof HTMLInputElement || parentElement2 instanceof HTMLInputElement) { if (parentElement1 instanceof HTMLInputElement || parentElement2 instanceof HTMLInputElement) {
@ -78,8 +85,7 @@ function getRangeObject(win) { //Gets the first range object
try { try {
return win.getSelection().getRangeAt(0); //W3C DOM Range Object return win.getSelection().getRangeAt(0); //W3C DOM Range Object
} catch (e) { /*If no text is selected an exception might be thrown*/ } } catch (e) { /*If no text is selected an exception might be thrown*/ }
} } else if (win.document.selection) { // IE8
else if(win.document.selection) { // IE8
var range = win.document.selection.createRange(); //Microsoft TextRange Object var range = win.document.selection.createRange(); //Microsoft TextRange Object
return fixIERangeObject(range, win); return fixIERangeObject(range, win);
} }

View file

@ -37,5 +37,3 @@ DragZone.prototype.onDragStart = function(downX, downY, event) {
return avatar; return avatar;
}; };

View file

@ -74,8 +74,7 @@ DropTarget.prototype.onDragEnd = function(avatar, event) {
/** /**
* Вход аватара в DropTarget * Вход аватара в DropTarget
*/ */
DropTarget.prototype.onDragEnter = function(fromDropTarget, avatar, event) { DropTarget.prototype.onDragEnter = function(fromDropTarget, avatar, event) {};
};
/** /**
* Выход аватара из DropTarget * Выход аватара из DropTarget
@ -84,5 +83,3 @@ DropTarget.prototype.onDragLeave = function(toDropTarget, avatar, event) {
this._hideHoverIndication(); this._hideHoverIndication();
this._targetElem = null; this._targetElem = null;
}; };

View file

@ -1,4 +1,3 @@
function TreeDragAvatar(dragZone, dragElem) { function TreeDragAvatar(dragZone, dragElem) {
DragAvatar.apply(this, arguments); DragAvatar.apply(this, arguments);
} }
@ -42,4 +41,3 @@ TreeDragAvatar.prototype.onDragCancel = function() {
TreeDragAvatar.prototype.onDragEnd = function() { TreeDragAvatar.prototype.onDragEnd = function() {
this._destroy(); this._destroy();
}; };

View file

@ -1,4 +1,3 @@
function TreeDragZone(elem) { function TreeDragZone(elem) {
DragZone.apply(this, arguments); DragZone.apply(this, arguments);
} }

View file

@ -1,4 +1,3 @@
function TreeDropTarget(elem) { function TreeDropTarget(elem) {
TreeDropTarget.parent.constructor.apply(this, arguments); TreeDropTarget.parent.constructor.apply(this, arguments);
} }

View file

@ -37,5 +37,3 @@ DragZone.prototype.onDragStart = function(downX, downY, event) {
return avatar; return avatar;
}; };

View file

@ -74,8 +74,7 @@ DropTarget.prototype.onDragEnd = function(avatar, event) {
/** /**
* Вход аватара в DropTarget * Вход аватара в DropTarget
*/ */
DropTarget.prototype.onDragEnter = function(fromDropTarget, avatar, event) { DropTarget.prototype.onDragEnter = function(fromDropTarget, avatar, event) {};
};
/** /**
* Выход аватара из DropTarget * Выход аватара из DropTarget
@ -84,5 +83,3 @@ DropTarget.prototype.onDragLeave = function(toDropTarget, avatar, event) {
this._hideHoverIndication(); this._hideHoverIndication();
this._targetElem = null; this._targetElem = null;
}; };

View file

@ -1,4 +1,3 @@
function TreeDragAvatar(dragZone, dragElem) { function TreeDragAvatar(dragZone, dragElem) {
DragAvatar.apply(this, arguments); DragAvatar.apply(this, arguments);
} }
@ -42,4 +41,3 @@ TreeDragAvatar.prototype.onDragCancel = function() {
TreeDragAvatar.prototype.onDragEnd = function() { TreeDragAvatar.prototype.onDragEnd = function() {
this._destroy(); this._destroy();
}; };

View file

@ -1,4 +1,3 @@
function TreeDragZone(elem) { function TreeDragZone(elem) {
DragZone.apply(this, arguments); DragZone.apply(this, arguments);
} }

View file

@ -1,4 +1,3 @@
function TreeDropTarget(elem) { function TreeDropTarget(elem) {
TreeDropTarget.parent.constructor.apply(this, arguments); TreeDropTarget.parent.constructor.apply(this, arguments);
} }

View file

@ -1,4 +1,3 @@
function getCoords(elem) { function getCoords(elem) {
var box = elem.getBoundingClientRect(); var box = elem.getBoundingClientRect();
@ -14,7 +13,10 @@ function getCoords(elem) {
var top = box.top + scrollTop - clientTop; var top = box.top + scrollTop - clientTop;
var left = box.left + scrollLeft - clientLeft; var left = box.left + scrollLeft - clientLeft;
return { top: Math.round(top), left: Math.round(left) }; return {
top: Math.round(top),
left: Math.round(left)
};
} }
function getElementUnderClientXY(elem, clientX, clientY) { function getElementUnderClientXY(elem, clientX, clientY) {

View file

@ -1,4 +1,3 @@
function bench(test, times) { function bench(test, times) {
var sum = 0; var sum = 0;
for (var i = 0; i < times; i++) { for (var i = 0; i < times; i++) {

View file

@ -1,4 +1,3 @@
/* 1. Вставляет TBODY в документ сразу. а затем элементы */ /* 1. Вставляет TBODY в документ сразу. а затем элементы */
var appendFirst = new function() { var appendFirst = new function() {
var benchTable; var benchTable;

View file

@ -1,5 +1,3 @@
var elems = document.querySelectorAll('form,div,p'); var elems = document.querySelectorAll('form,div,p');
for (var i = 0; i < elems.length; i++) { for (var i = 0; i < elems.length; i++) {

View file

@ -1,4 +1,3 @@
var form = document.querySelector('form'); var form = document.querySelector('form');
form.onclick = function(event) { form.onclick = function(event) {

View file

@ -1,4 +1,3 @@
var elems = document.querySelectorAll('form,div,p'); var elems = document.querySelectorAll('form,div,p');
for (var i = 0; i < elems.length; i++) { for (var i = 0; i < elems.length; i++) {

View file

@ -1,4 +1,3 @@
function HoverIntent(options) { function HoverIntent(options) {
options = Object.create(options); // not to modify the object options = Object.create(options); // not to modify the object
@ -74,4 +73,3 @@ function HoverIntent(options) {
} }
} }

View file

@ -1,5 +1,3 @@
function HoverIntent(options) { function HoverIntent(options) {
/* ваш код */ /* ваш код */
} }

View file

@ -1,4 +1,3 @@
// элемент TD, внутри которого сейчас курсор // элемент TD, внутри которого сейчас курсор
var currentElem = null; var currentElem = null;

View file

@ -1,4 +1,3 @@
table.onmouseover = function(event) { table.onmouseover = function(event) {
var target = event.target; var target = event.target;
target.style.background = 'pink'; target.style.background = 'pink';

View file

@ -1,4 +1,3 @@
table.onmouseenter = table.onmouseleave = log; table.onmouseenter = table.onmouseleave = log;
function log(event) { function log(event) {

View file

@ -1,4 +1,3 @@
function log(event) { function log(event) {
text.value += event.type + ' [target: ' + event.target.className + ']\n'; text.value += event.type + ' [target: ' + event.target.className + ']\n';
text.scrollTop = text.scrollHeight; text.scrollTop = text.scrollHeight;

View file

@ -1,4 +1,3 @@
function mouselog(event) { function mouselog(event) {
text.value += event.type + ' [target: ' + event.target.className + ']\n' text.value += event.type + ' [target: ' + event.target.className + ']\n'
text.scrollTop = text.scrollHeight text.scrollTop = text.scrollHeight

View file

@ -17,6 +17,7 @@ function clearText() {
var lastMessageTime = 0; var lastMessageTime = 0;
var lastMessage = ""; var lastMessage = "";
var repeatCounter = 1; var repeatCounter = 1;
function log(message) { function log(message) {
if (lastMessageTime == 0) lastMessageTime = new Date(); if (lastMessageTime == 0) lastMessageTime = new Date();

View file

@ -1,5 +1,3 @@
document.onmousedown = function(e) { document.onmousedown = function(e) {
var dragElement = e.target; var dragElement = e.target;

View file

@ -155,4 +155,3 @@ function getCoords(elem) { // кроме IE8-
}; };
} }

View file

@ -1,4 +1,3 @@
kinput.onkeydown = kinput.onkeyup = kinput.onkeypress = handle; kinput.onkeydown = kinput.onkeyup = kinput.onkeypress = handle;
var lastTime = Date.now(); var lastTime = Date.now();

View file

@ -1,4 +1,3 @@
var table = document.getElementById('bagua-table'); var table = document.getElementById('bagua-table');
var editingTd; var editingTd;
@ -61,4 +60,3 @@ function finishTdEdit(td, isOk) {
td.classList.remove('edit-td'); // remove edit class td.classList.remove('edit-td'); // remove edit class
editingTd = null; editingTd = null;
} }

View file

@ -1,4 +1,3 @@
var table = document.getElementById('bagua-table'); var table = document.getElementById('bagua-table');
/* ваш код */ /* ваш код */

View file

@ -1,4 +1,3 @@
function ListSelect(options) { function ListSelect(options) {
var elem = options.elem; var elem = options.elem;

View file

@ -1,4 +1,3 @@
function Voter(options) { function Voter(options) {
var elem = this._elem = options.elem; var elem = this._elem = options.elem;
this._voteElem = elem.querySelector('.vote'); this._voteElem = elem.querySelector('.vote');
@ -30,4 +29,3 @@ Voter.prototype._voteDecrease = function() {
Voter.prototype.setVote = function(vote) { Voter.prototype.setVote = function(vote) {
this._voteElem.innerHTML = +vote; this._voteElem.innerHTML = +vote;
}; };

View file

@ -1,4 +1,3 @@
function Voter(options) { function Voter(options) {
var elem = this._elem = options.elem; var elem = this._elem = options.elem;
this._voteElem = elem.querySelector('.vote'); this._voteElem = elem.querySelector('.vote');
@ -30,4 +29,3 @@ Voter.prototype._voteDecrease = function() {
Voter.prototype.setVote = function(vote) { Voter.prototype.setVote = function(vote) {
this._voteElem.innerHTML = +vote; this._voteElem.innerHTML = +vote;
}; };

View file

@ -1,7 +1,9 @@
function Menu(options) { function Menu(options) {
var elem = options.elem; var elem = options.elem;
elem.onmousedown = function() { return false; } elem.onmousedown = function() {
return false;
}
elem.onclick = function(event) { elem.onclick = function(event) {
if (event.target.closest('.title')) { if (event.target.closest('.title')) {

View file

@ -7,7 +7,9 @@ function Menu(options) {
} }
function render() { function render() {
var html = options.template({title: options.title}); var html = options.template({
title: options.title
});
elem = document.createElement('div'); elem = document.createElement('div');
elem.innerHTML = html; elem.innerHTML = html;
@ -33,7 +35,9 @@ function Menu(options) {
function renderItems() { function renderItems() {
if (elem.querySelector('ul')) return; if (elem.querySelector('ul')) return;
var listHtml = options.listTemplate({items: options.items}); var listHtml = options.listTemplate({
items: options.items
});
elem.insertAdjacentHTML("beforeEnd", listHtml); elem.insertAdjacentHTML("beforeEnd", listHtml);
} }

View file

@ -7,7 +7,9 @@ function Menu(options) {
} }
function render() { function render() {
var html = options.template({title: options.title}); var html = options.template({
title: options.title
});
elem = document.createElement('div'); elem = document.createElement('div');
elem.innerHTML = html; elem.innerHTML = html;
@ -27,7 +29,9 @@ function Menu(options) {
function renderItems() { function renderItems() {
if (elem.querySelector('ul')) return; if (elem.querySelector('ul')) return;
var listHtml = options.listTemplate({items: options.items}); var listHtml = options.listTemplate({
items: options.items
});
elem.insertAdjacentHTML("beforeEnd", listHtml); elem.insertAdjacentHTML("beforeEnd", listHtml);
} }

View file

@ -7,7 +7,9 @@ function Menu(options) {
} }
function render() { function render() {
var html = options.template({title: options.title}); var html = options.template({
title: options.title
});
elem = document.createElement('div'); elem = document.createElement('div');
elem.innerHTML = html; elem.innerHTML = html;
@ -27,7 +29,9 @@ function Menu(options) {
function renderItems() { function renderItems() {
if (elem.querySelector('ul')) return; if (elem.querySelector('ul')) return;
var listHtml = options.listTemplate({items: options.items}); var listHtml = options.listTemplate({
items: options.items
});
elem.insertAdjacentHTML("beforeEnd", listHtml); elem.insertAdjacentHTML("beforeEnd", listHtml);
} }

View file

@ -28,7 +28,10 @@ function Voter(options) {
function setVote(vote) { function setVote(vote) {
voteElem.innerHTML = +vote; voteElem.innerHTML = +vote;
var widgetEvent = new CustomEvent("change", { bubbles: true, detail: +vote }); var widgetEvent = new CustomEvent("change", {
bubbles: true,
detail: +vote
});
elem.dispatchEvent(widgetEvent); elem.dispatchEvent(widgetEvent);
}; };

View file

@ -1,4 +1,3 @@
function ListSelect(options) { function ListSelect(options) {
var elem = options.elem; var elem = options.elem;

View file

@ -7,7 +7,9 @@ function Menu(options) {
} }
function render() { function render() {
var html = options.template({title: options.title}); var html = options.template({
title: options.title
});
elem = document.createElement('div'); elem = document.createElement('div');
elem.innerHTML = html; elem.innerHTML = html;
@ -33,7 +35,9 @@ function Menu(options) {
function renderItems() { function renderItems() {
if (elem.querySelector('ul')) return; if (elem.querySelector('ul')) return;
var listHtml = options.listTemplate({items: options.items}); var listHtml = options.listTemplate({
items: options.items
});
elem.insertAdjacentHTML("beforeEnd", listHtml); elem.insertAdjacentHTML("beforeEnd", listHtml);
} }

View file

@ -7,7 +7,9 @@ function Menu(options) {
} }
function render() { function render() {
var html = options.template({title: options.title}); var html = options.template({
title: options.title
});
elem = document.createElement('div'); elem = document.createElement('div');
elem.innerHTML = html; elem.innerHTML = html;
@ -33,7 +35,9 @@ function Menu(options) {
function renderItems() { function renderItems() {
if (elem.querySelector('ul')) return; if (elem.querySelector('ul')) return;
var listHtml = options.listTemplate({items: options.items}); var listHtml = options.listTemplate({
items: options.items
});
elem.insertAdjacentHTML("beforeEnd", listHtml); elem.insertAdjacentHTML("beforeEnd", listHtml);
} }

View file

@ -46,4 +46,3 @@ function scriptRequest(url, onSuccess, onError) {
document.body.appendChild(script); document.body.appendChild(script);
} }

View file

@ -1,7 +1,9 @@
var http = require('http'); var http = require('http');
var url = require('url'); var url = require('url');
var static = require('node-static'); var static = require('node-static');
var file = new static.Server('.', { cache: 0 }); var file = new static.Server('.', {
cache: 0
});
function accept(req, res) { function accept(req, res) {
@ -35,4 +37,3 @@ if (!module.parent) {
} else { } else {
exports.accept = accept; exports.accept = accept;
} }

View file

@ -1,7 +1,9 @@
var http = require('http'); var http = require('http');
var url = require('url'); var url = require('url');
var static = require('node-static'); var static = require('node-static');
var file = new static.Server('.', { cache: 0 }); var file = new static.Server('.', {
cache: 0
});
var multiparty = require('multiparty'); var multiparty = require('multiparty');
function accept(req, res) { function accept(req, res) {
@ -38,5 +40,3 @@ if (!module.parent) {
} else { } else {
exports.accept = accept; exports.accept = accept;
} }

View file

@ -1,8 +1,8 @@
var IframeComet = new function() { var IframeComet = new function() {
var self = this; var self = this;
var connectTries = 0, reconnectTimer; var connectTries = 0,
reconnectTimer;
var htmlfile; // for ie only var htmlfile; // for ie only
var iframe; var iframe;

View file

@ -1,14 +1,17 @@
var http = require('http'); var http = require('http');
var url = require('url'); var url = require('url');
var static = require('node-static'); var static = require('node-static');
var file = new static.Server('.', { cache: 0 }); var file = new static.Server('.', {
cache: 0
});
function accept(req, res) { function accept(req, res) {
if (req.url == '/comet') { if (req.url == '/comet') {
res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'}); res.writeHead(200, {
'Content-Type': 'text/html; charset=utf-8'
});
res.write('<!DOCTYPE HTML><html> \ res.write('<!DOCTYPE HTML><html> \
<head><meta junk="' + new Array(2000).join('*') + '"/> \ <head><meta junk="' + new Array(2000).join('*') + '"/> \
@ -38,5 +41,3 @@ if (!module.parent) {
} else { } else {
exports.accept = accept; exports.accept = accept;
} }

View file

@ -1,5 +1,3 @@
function createIframe(name, src, debug) { function createIframe(name, src, debug) {
src = src || 'javascript:false'; // пустой src src = src || 'javascript:false'; // пустой src
@ -92,5 +90,3 @@ function iframePost(url, data, onSuccess, onError) {
postToIframe(url, data, iframeName); postToIframe(url, data, iframeName);
} }

View file

@ -1,7 +1,9 @@
var http = require('http'); var http = require('http');
var url = require('url'); var url = require('url');
var static = require('node-static'); var static = require('node-static');
var file = new static.Server('.', { cache: 0 }); var file = new static.Server('.', {
cache: 0
});
var multiparty = require('multiparty'); var multiparty = require('multiparty');
function accept(req, res) { function accept(req, res) {
@ -38,5 +40,3 @@ if (!module.parent) {
} else { } else {
exports.accept = accept; exports.accept = accept;
} }

View file

@ -28,4 +28,3 @@ if (!module.parent) {
} else { } else {
exports.accept = accept; exports.accept = accept;
} }

View file

@ -2,7 +2,9 @@ var http = require('http');
var url = require('url'); var url = require('url');
var querystring = require('querystring'); var querystring = require('querystring');
var static = require('node-static'); var static = require('node-static');
var file = new static.Server('.', { cache: 0 }); var file = new static.Server('.', {
cache: 0
});
function accept(req, res) { function accept(req, res) {
@ -26,4 +28,3 @@ if (!module.parent) {
} else { } else {
exports.accept = accept; exports.accept = accept;
} }

View file

@ -2,7 +2,9 @@ var http = require('http');
var url = require('url'); var url = require('url');
var querystring = require('querystring'); var querystring = require('querystring');
var static = require('node-static'); var static = require('node-static');
var file = new static.Server('.', { cache: 0 }); var file = new static.Server('.', {
cache: 0
});
function accept(req, res) { function accept(req, res) {
@ -26,4 +28,3 @@ if (!module.parent) {
} else { } else {
exports.accept = accept; exports.accept = accept;
} }

View file

@ -2,7 +2,9 @@ var http = require('http');
var url = require('url'); var url = require('url');
var querystring = require('querystring'); var querystring = require('querystring');
var static = require('node-static'); var static = require('node-static');
var file = new static.Server('.', { cache: 0 }); var file = new static.Server('.', {
cache: 0
});
function accept(req, res) { function accept(req, res) {
@ -26,4 +28,3 @@ if (!module.parent) {
} else { } else {
exports.accept = accept; exports.accept = accept;
} }

View file

@ -2,7 +2,9 @@ var http = require('http');
var url = require('url'); var url = require('url');
var querystring = require('querystring'); var querystring = require('querystring');
var static = require('node-static'); var static = require('node-static');
var file = new static.Server('.', { cache: 0 }); var file = new static.Server('.', {
cache: 0
});
function accept(req, res) { function accept(req, res) {
@ -26,4 +28,3 @@ if (!module.parent) {
} else { } else {
exports.accept = accept; exports.accept = accept;
} }

View file

@ -2,7 +2,9 @@ var http = require('http');
var url = require('url'); var url = require('url');
var querystring = require('querystring'); var querystring = require('querystring');
var static = require('node-static'); var static = require('node-static');
var file = new static.Server('.', { cache: 0 }); var file = new static.Server('.', {
cache: 0
});
function accept(req, res) { function accept(req, res) {
@ -34,4 +36,3 @@ if (!module.parent) {
} else { } else {
exports.accept = accept; exports.accept = accept;
} }

View file

@ -32,7 +32,9 @@ function onUpload(req, res) {
// если байт 0, то создать новый файл, иначе проверить размер и дописать // если байт 0, то создать новый файл, иначе проверить размер и дописать
if (startByte == 0) { if (startByte == 0) {
upload.bytesReceived = 0; upload.bytesReceived = 0;
var fileStream = fs.createWriteStream(filePath, {flags: 'w'}); var fileStream = fs.createWriteStream(filePath, {
flags: 'w'
});
console.log("New file created: " + filePath); console.log("New file created: " + filePath);
} else { } else {
if (upload.bytesReceived != startByte) { if (upload.bytesReceived != startByte) {
@ -41,7 +43,9 @@ function onUpload(req, res) {
return; return;
} }
// добавляем в существующий файл // добавляем в существующий файл
fileStream = fs.createWriteStream(filePath, {flags: 'a'}); fileStream = fs.createWriteStream(filePath, {
flags: 'a'
});
console.log("File reopened: " + filePath); console.log("File reopened: " + filePath);
} }
@ -113,4 +117,3 @@ if (!module.parent) {
} else { } else {
exports.accept = accept; exports.accept = accept;
} }

View file

@ -94,7 +94,8 @@ function Uploader(file, onSuccess, onFail, onProgress) {
function hashCode(str) { function hashCode(str) {
if (str.length == 0) return 0; if (str.length == 0) return 0;
var hash = 0, i, chr, len; var hash = 0,
i, chr, len;
for (i = 0; i < str.length; i++) { for (i = 0; i < str.length; i++) {
chr = str.charCodeAt(i); chr = str.charCodeAt(i);
hash = ((hash << 5) - hash) + chr; hash = ((hash << 5) - hash) + chr;

View file

@ -74,4 +74,3 @@ if (!module.parent) {
} else { } else {
exports.accept = accept; exports.accept = accept;
} }

View file

@ -108,4 +108,3 @@ if (!module.parent) {
} else { } else {
exports.accept = accept; exports.accept = accept;
} }

View file

@ -73,7 +73,8 @@ function Uploader(file, onSuccess, onError, onProgress) {
function hashCode(str) { function hashCode(str) {
if (str.length == 0) return 0; if (str.length == 0) return 0;
var hash = 0, i, chr, len; var hash = 0,
i, chr, len;
for (i = 0; i < str.length; i++) { for (i = 0; i < str.length; i++) {
chr = str.charCodeAt(i); chr = str.charCodeAt(i);
hash = ((hash << 5) - hash) + chr; hash = ((hash << 5) - hash) + chr;

View file

@ -115,7 +115,9 @@ function DraggableWindow(options) {
function submit(message) { function submit(message) {
// добавить // добавить
var newMessageElem = $('<div>', {text: message }).appendTo(contentElem); var newMessageElem = $('<div>', {
text: message
}).appendTo(contentElem);
// прокрутить к новому сообщению // прокрутить к новому сообщению
contentElem.prop('scrollTop', 999999999); contentElem.prop('scrollTop', 999999999);
@ -123,4 +125,3 @@ function DraggableWindow(options) {
} }

View file

@ -38,7 +38,9 @@ function DraggableWindow(options) {
} }
function onFocus() { function onFocus() {
$(self).triggerHandler({ type: 'focus' }); $(self).triggerHandler({
type: 'focus'
});
} }
function onTitleMouseDown(e) { function onTitleMouseDown(e) {
@ -119,7 +121,9 @@ function DraggableWindow(options) {
function submit(message) { function submit(message) {
// добавить // добавить
var newMessageElem = $('<div>', {text: message }).appendTo(contentElem); var newMessageElem = $('<div>', {
text: message
}).appendTo(contentElem);
// прокрутить к новому сообщению // прокрутить к новому сообщению
contentElem.prop('scrollTop', 999999999); contentElem.prop('scrollTop', 999999999);
@ -139,4 +143,3 @@ function DraggableWindow(options) {
} }
} }

View file

@ -93,7 +93,11 @@ function Calendar(options) {
function onDateCellClick(e) { function onDateCellClick(e) {
day = $(e.target).html(); day = $(e.target).html();
self.setValue({year: year, month: month, day: day}); self.setValue({
year: year,
month: month,
day: day
});
} }
@ -155,4 +159,3 @@ function Calendar(options) {
} }
} }

View file

@ -50,7 +50,10 @@ function DatePicker(options) {
if (!calendarCache[key]) { if (!calendarCache[key]) {
calendar = calendarCache[key] = new Calendar({ calendar = calendarCache[key] = new Calendar({
value: {year: year, month: month} value: {
year: year,
month: month
}
}); });
$(calendar).on("select", onCalendarSelect); $(calendar).on("select", onCalendarSelect);
} else { } else {

View file

@ -93,7 +93,11 @@ function Calendar(options) {
function onDateCellClick(e) { function onDateCellClick(e) {
day = $(e.target).html(); day = $(e.target).html();
self.setValue({year: year, month: month, day: day}); self.setValue({
year: year,
month: month,
day: day
});
} }
@ -155,4 +159,3 @@ function Calendar(options) {
} }
} }

View file

@ -1,5 +1,7 @@
var result = { var result = {
0: { children: [] } 0: {
children: []
}
}; };
$('div[id^="region"]').each(function() { $('div[id^="region"]').each(function() {

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,3 @@
function Tree(options) { function Tree(options) {
var self = this; var self = this;

View file

@ -88,7 +88,11 @@ function Calendar(options) {
function onDateCellClick(e) { function onDateCellClick(e) {
day = $(e.target).html(); day = $(e.target).html();
self.setValue({year: year, month: month, day: day}); self.setValue({
year: year,
month: month,
day: day
});
} }
@ -150,4 +154,3 @@ function Calendar(options) {
} }
} }

View file

@ -68,6 +68,7 @@ function Autocomplete(options) {
function onInputFocus() { function onInputFocus() {
var inputValue = input.val(); var inputValue = input.val();
function checkInput() { function checkInput() {
if (inputValue != input.val()) { if (inputValue != input.val()) {