renovations
This commit is contained in:
parent
c7e994d553
commit
dafbae84bf
3 changed files with 89 additions and 40 deletions
|
@ -19,7 +19,7 @@ describe("Возводит x в степень n", function() {
|
|||
});
|
||||
|
||||
it("5 в степени 3 равно 125", function() {
|
||||
assert.equal(pow(5, 3), 25);
|
||||
assert.equal(pow(5, 3), 125);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
|
45
12-extra/10-cookie/cookie.js
Normal file
45
12-extra/10-cookie/cookie.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
// возвращает cookie с именем name, если есть, если нет, то undefined
|
||||
function getCookie(name) {
|
||||
var matches = document.cookie.match(new RegExp(
|
||||
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
|
||||
));
|
||||
return matches ? decodeURIComponent(matches[1]) : undefined;
|
||||
}
|
||||
|
||||
// устанавливает cookie c именем name и значением value
|
||||
// options - объект с свойствами cookie (expires, path, domain, secure)
|
||||
function setCookie(name, value, options) {
|
||||
options = options || {};
|
||||
|
||||
var expires = options.expires;
|
||||
|
||||
if (typeof expires == "number" && expires) {
|
||||
var d = new Date();
|
||||
d.setTime(d.getTime() + expires * 1000);
|
||||
expires = options.expires = d;
|
||||
}
|
||||
if (expires && expires.toUTCString) {
|
||||
options.expires = expires.toUTCString();
|
||||
}
|
||||
|
||||
value = encodeURIComponent(value);
|
||||
|
||||
var updatedCookie = name + "=" + value;
|
||||
|
||||
for (var propName in options) {
|
||||
updatedCookie += "; " + propName;
|
||||
var propValue = options[propName];
|
||||
if (propValue !== true) {
|
||||
updatedCookie += "=" + propValue;
|
||||
}
|
||||
}
|
||||
|
||||
document.cookie = updatedCookie;
|
||||
}
|
||||
|
||||
// удаляет cookie с именем name
|
||||
function deleteCookie(name) {
|
||||
setCookie(name, "", {
|
||||
expires: -1
|
||||
})
|
||||
}
|
|
@ -38,34 +38,41 @@
|
|||
```js
|
||||
//+ no-beautify
|
||||
if (hours > 18) {
|
||||
// Пойти поиграть в теннис
|
||||
// Пойти поиграть в теннис
|
||||
}
|
||||
```
|
||||
|
||||
<ul>
|
||||
<li>**`white-space: pre`:**
|
||||
**`white-space: pre`:**
|
||||
|
||||
[pre]
|
||||
<div class="white-space-example" style="white-space:pre">if (hours > 18) {
|
||||
// Пойти поиграть в теннис
|
||||
```html
|
||||
<!--+ autorun height=100 -->
|
||||
<style>
|
||||
div { font-family: monospace; width: 200px; border: 1px solid black; }
|
||||
</style>
|
||||
|
||||
<div style="white-space:pre">if (hours > 18) {
|
||||
// Пойти поиграть в теннис
|
||||
}
|
||||
</div>
|
||||
[/pre]
|
||||
```
|
||||
|
||||
Здесь пробелы и переводы строк сохранены. В HTML этому значению `white-space` соответствует тег `PRE`.
|
||||
</li>
|
||||
<li>**`white-space: nowrap`:**
|
||||
|
||||
[pre]
|
||||
<div class="white-space-example" style="white-space:nowrap">if (hours > 18) {
|
||||
// Пойти поиграть в теннис
|
||||
**`white-space: nowrap`:**
|
||||
|
||||
```html
|
||||
<!--+ autorun height=100 -->
|
||||
<style>
|
||||
div { font-family: monospace; width: 200px; border: 1px solid black; }
|
||||
</style>
|
||||
|
||||
<div style="white-space:nowrap">if (hours > 18) {
|
||||
// Пойти поиграть в теннис
|
||||
}
|
||||
</div>
|
||||
[/pre]
|
||||
```
|
||||
|
||||
Здесь переводы строки проигнорированы, а подряд идущие пробелы, если присмотреться -- сжаты в один (например, перед комментарием `//`).
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
Допустим, мы хотим разрешить посетителям публиковать код на сайте, с сохранением разметки. Но тег `PRE` и описанные выше значения `white-space` для этого не подойдут!
|
||||
|
||||
|
@ -84,37 +91,34 @@ if (hours > 18) {
|
|||
|
||||
Оба поведения отлично прослеживаются на примерах:
|
||||
|
||||
<ul>
|
||||
<li>**`white-space: pre-wrap`:**
|
||||
**`white-space: pre-wrap`:**
|
||||
|
||||
[pre]
|
||||
<div class="white-space-example" style="white-space:pre-wrap">if (hours > 18) {
|
||||
// Пойти поиграть в теннис
|
||||
```html
|
||||
<!--+ autorun height=100 -->
|
||||
<style>
|
||||
div { font-family: monospace; width: 200px; border: 1px solid black; }
|
||||
</style>
|
||||
|
||||
<div style="white-space:pre-wrap">if (hours > 18) {
|
||||
// Пойти поиграть в теннис
|
||||
}
|
||||
</div>
|
||||
[/pre]
|
||||
```
|
||||
|
||||
Отличный выбор для безопасной вставки кода посетителями.
|
||||
|
||||
</li>
|
||||
<li>**`white-space: pre-line`:**
|
||||
**`white-space: pre-line`:**
|
||||
|
||||
[pre]
|
||||
<div class="white-space-example" style="white-space:pre-line">if (hours > 18) {
|
||||
// Пойти поиграть в теннис
|
||||
```html
|
||||
<!--+ autorun height=100 -->
|
||||
<style>
|
||||
div { font-family: monospace; width: 200px; border: 1px solid black; }
|
||||
</style>
|
||||
|
||||
<div style="white-space:pre-line">if (hours > 18) {
|
||||
// Пойти поиграть в теннис
|
||||
}
|
||||
</div>
|
||||
[/pre]
|
||||
```
|
||||
|
||||
Сохранены переводы строк, ничего не вылезает, но пробелы интерпретированы в режиме обычного HTML.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
[head]
|
||||
<style>
|
||||
.white-space-example {
|
||||
font-family: monospace;
|
||||
width: 200px;
|
||||
border: 1px solid black;
|
||||
}
|
||||
</style>
|
||||
[/head]
|
Loading…
Add table
Add a link
Reference in a new issue