Skip to content

Commit dafbae8

Browse files
committed
renovations
1 parent c7e994d commit dafbae8

3 files changed

Lines changed: 89 additions & 40 deletions

File tree

1-js/3-writing-js/4-testing/3-pow-test-wrong/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe("Возводит x в степень n", function() {
1919
});
2020

2121
it("5 в степени 3 равно 125", function() {
22-
assert.equal(pow(5, 3), 25);
22+
assert.equal(pow(5, 3), 125);
2323
});
2424
});
2525
```

12-extra/10-cookie/cookie.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// возвращает cookie с именем name, если есть, если нет, то undefined
2+
function getCookie(name) {
3+
var matches = document.cookie.match(new RegExp(
4+
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
5+
));
6+
return matches ? decodeURIComponent(matches[1]) : undefined;
7+
}
8+
9+
// устанавливает cookie c именем name и значением value
10+
// options - объект с свойствами cookie (expires, path, domain, secure)
11+
function setCookie(name, value, options) {
12+
options = options || {};
13+
14+
var expires = options.expires;
15+
16+
if (typeof expires == "number" && expires) {
17+
var d = new Date();
18+
d.setTime(d.getTime() + expires * 1000);
19+
expires = options.expires = d;
20+
}
21+
if (expires && expires.toUTCString) {
22+
options.expires = expires.toUTCString();
23+
}
24+
25+
value = encodeURIComponent(value);
26+
27+
var updatedCookie = name + "=" + value;
28+
29+
for (var propName in options) {
30+
updatedCookie += "; " + propName;
31+
var propValue = options[propName];
32+
if (propValue !== true) {
33+
updatedCookie += "=" + propValue;
34+
}
35+
}
36+
37+
document.cookie = updatedCookie;
38+
}
39+
40+
// удаляет cookie с именем name
41+
function deleteCookie(name) {
42+
setCookie(name, "", {
43+
expires: -1
44+
})
45+
}

8-css-for-js/8-white-space/article.md

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,41 @@
3838
```js
3939
//+ no-beautify
4040
if (hours > 18) {
41-
// Пойти поиграть в теннис
41+
// Пойти поиграть в теннис
4242
}
4343
```
4444

45-
<ul>
46-
<li>**`white-space: pre`:**
45+
**`white-space: pre`:**
46+
47+
```html
48+
<!--+ autorun height=100 -->
49+
<style>
50+
div { font-family: monospace; width: 200px; border: 1px solid black; }
51+
</style>
4752

48-
[pre]
49-
<div class="white-space-example" style="white-space:pre">if (hours > 18) {
50-
// Пойти поиграть в теннис
53+
<div style="white-space:pre">if (hours > 18) {
54+
// Пойти поиграть в теннис
5155
}
5256
</div>
53-
[/pre]
57+
```
5458

5559
Здесь пробелы и переводы строк сохранены. В HTML этому значению `white-space` соответствует тег `PRE`.
56-
</li>
57-
<li>**`white-space: nowrap`:**
5860

59-
[pre]
60-
<div class="white-space-example" style="white-space:nowrap">if (hours > 18) {
61-
// Пойти поиграть в теннис
61+
**`white-space: nowrap`:**
62+
63+
```html
64+
<!--+ autorun height=100 -->
65+
<style>
66+
div { font-family: monospace; width: 200px; border: 1px solid black; }
67+
</style>
68+
69+
<div style="white-space:nowrap">if (hours > 18) {
70+
// Пойти поиграть в теннис
6271
}
6372
</div>
64-
[/pre]
73+
```
6574

6675
Здесь переводы строки проигнорированы, а подряд идущие пробелы, если присмотреться -- сжаты в один (например, перед комментарием `//`).
67-
</li>
68-
</ul>
6976

7077
Допустим, мы хотим разрешить посетителям публиковать код на сайте, с сохранением разметки. Но тег `PRE` и описанные выше значения `white-space` для этого не подойдут!
7178

@@ -84,37 +91,34 @@ if (hours > 18) {
8491

8592
Оба поведения отлично прослеживаются на примерах:
8693

87-
<ul>
88-
<li>**`white-space: pre-wrap`:**
94+
**`white-space: pre-wrap`:**
95+
96+
```html
97+
<!--+ autorun height=100 -->
98+
<style>
99+
div { font-family: monospace; width: 200px; border: 1px solid black; }
100+
</style>
89101

90-
[pre]
91-
<div class="white-space-example" style="white-space:pre-wrap">if (hours > 18) {
92-
// Пойти поиграть в теннис
102+
<div style="white-space:pre-wrap">if (hours > 18) {
103+
// Пойти поиграть в теннис
93104
}
94105
</div>
95-
[/pre]
106+
```
107+
96108
Отличный выбор для безопасной вставки кода посетителями.
97109

98-
</li>
99-
<li>**`white-space: pre-line`:**
110+
**`white-space: pre-line`:**
111+
112+
```html
113+
<!--+ autorun height=100 -->
114+
<style>
115+
div { font-family: monospace; width: 200px; border: 1px solid black; }
116+
</style>
100117

101-
[pre]
102-
<div class="white-space-example" style="white-space:pre-line">if (hours > 18) {
103-
// Пойти поиграть в теннис
118+
<div style="white-space:pre-line">if (hours > 18) {
119+
// Пойти поиграть в теннис
104120
}
105121
</div>
106-
[/pre]
122+
```
107123

108124
Сохранены переводы строк, ничего не вылезает, но пробелы интерпретированы в режиме обычного HTML.
109-
</li>
110-
</ul>
111-
112-
[head]
113-
<style>
114-
.white-space-example {
115-
font-family: monospace;
116-
width: 200px;
117-
border: 1px solid black;
118-
}
119-
</style>
120-
[/head]

0 commit comments

Comments
 (0)