<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; JS: Разворот соответствующих блоков следующей страницы — при переходе]]></title>
		<link>http://forum.script-coding.com/viewtopic.php?id=10728</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=10728&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «JS: Разворот соответствующих блоков следующей страницы — при переходе».]]></description>
		<lastBuildDate>Fri, 26 Jun 2015 16:20:00 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: JS: Разворот соответствующих блоков следующей страницы — при переходе]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=94762#p94762</link>
			<description><![CDATA[<p>Сколько угодно: текущая задача, многоуровневые меню и списки, слайдеры, &quot;карусели&quot;.</p>]]></description>
			<author><![CDATA[null@example.com (Rumata)]]></author>
			<pubDate>Fri, 26 Jun 2015 16:20:00 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=94762#p94762</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Разворот соответствующих блоков следующей страницы — при переходе]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=94761#p94761</link>
			<description><![CDATA[<p>Спасибо, этому нужно применение <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></description>
			<author><![CDATA[null@example.com (DD)]]></author>
			<pubDate>Fri, 26 Jun 2015 16:06:57 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=94761#p94761</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Разворот соответствующих блоков следующей страницы — при переходе]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=94760#p94760</link>
			<description><![CDATA[<div class="codebox"><pre><code>
&lt;html&gt;
&lt;head&gt;
&lt;style&gt;

.container {
    border: 1px solid #000;
    width: 300px;
}

.content {
    background-color: #ccc;
}

.hide    {
    display: none;
}

&lt;/style&gt;

&lt;script&gt;

function class2regex(name)
{
    return new RegExp(&#039;(?:^|\\s+)&#039; + name + &#039;(?=\\s+|$)&#039;, &#039;g&#039;);
};

function hasClass(object, name)
{
    var re = class2regex(name);
    return object.className.match(re);
};

function addClass(object, name)
{
    if ( hasClass(object, name) ) {
        return;
    }
    object.className = object.className + &#039; &#039; + name;
};

function removeClass(object, name)
{
    var re = class2regex(name);
    object.className = object.className.replace(re, &#039; &#039;);
};

function toggleClass(object, name)
{
    if ( hasClass(object, name) ) {
        removeClass(object, name);
    } else {
        addClass(object, name);
    }
};

// http://javascript.ru/unsorted/top-10-functions#8-getelementsbyclass
if ( document.getElementsByClassName ) {

    getElementsByClass = function(classList, node) {
        return (node || document).getElementsByClassName(classList);
    };

} else {

    getElementsByClass = function(classList, node) {
        var node = node || document,
        list = node.getElementsByTagName(&#039;*&#039;), 
        length = list.length,  
        classArray = classList.split(/\s+/), 
        classes = classArray.length, 
        result = [], i,j
        for(i = 0; i &lt; length; i++) {
            for(j = 0; j &lt; classes; j++)  {
                if(list[i].className.search(&#039;\\b&#039; + classArray[j] + &#039;\\b&#039;) != -1) {
                    result.push(list[i])
                    break;
                }
            }
        }
        return result;
    };

}

window.onload = function()
{
    var containers = getElementsByClass(&#039;container&#039;);
    for (var i = 0; i &lt; containers.length; i++) {
        containers[i].onclick = function()
        {
            var content = this.getElementsByTagName(&#039;div&#039;)[1];
            toggleClass(content, &#039;hide&#039;);
        };
    }
};

&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;clicker&quot;&gt;CLICK ME&lt;/div&gt;
&lt;div class=&quot;content&quot;&gt;Lorem ipsum&lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;clicker&quot;&gt;CLICK ME&lt;/div&gt;
&lt;div class=&quot;content&quot;&gt;Lorem ipsum&lt;/div&gt;
&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre></div><p>Обратите внимание, идентификаторы намеренно убрал, одни только классы. Используется функция getElementsByClass для кроссбраузерного получения списка объектов по имени класса.</p>]]></description>
			<author><![CDATA[null@example.com (Rumata)]]></author>
			<pubDate>Fri, 26 Jun 2015 15:56:28 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=94760#p94760</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Разворот соответствующих блоков следующей страницы — при переходе]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=94759#p94759</link>
			<description><![CDATA[<p><strong>Rumata</strong>, а если нужно будет увеличить количество блоков с идентификатором &quot;container&quot; в предложенном Вами коде, тогда как быть?</p><p><strong>wisgest</strong>, спасибо: сессионные куки, пожалуй, это заманчиво)) Покумекаю.</p>]]></description>
			<author><![CDATA[null@example.com (DD)]]></author>
			<pubDate>Fri, 26 Jun 2015 15:07:01 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=94759#p94759</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Разворот соответствующих блоков следующей страницы — при переходе]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=94758#p94758</link>
			<description><![CDATA[<div class="quotebox"><cite>wisgest пишет:</cite><blockquote><p>Для обмена данными между страницами, загружаемыми в одно и то же окно, можно воспользоваться свойством window.name (если что, это строка).</p></blockquote></div><div class="quotebox"><cite>DD пишет:</cite><blockquote><p>А в CHM это работает?</p></blockquote></div><p>Легко проверить. Выбраем в меню окна HH.EXE пункт «Перейти по адресу (URL)...» и вводим </p><div class="codebox"><pre><code>javascript:void (window.name=&quot;Запомненное значение&quot;);</code></pre></div><p>переключаем показываемую страницу (переходя по ссылкам или через содержание) и вводим </p><div class="codebox"><pre><code>javascript:alert(window.name);</code></pre></div><div class="quotebox"><cite>DD пишет:</cite><blockquote><p>Впрочем, и назначение стиля по ID подошло бы.</p></blockquote></div><p>Без назначения стиля по ID или изменения правил CSS в любом случае (и с куками) не обойтись. Куки помогут лишь запоминанить какие-то значения, которые всё-равно надо как-то обработать. window.name действует как сессионные куки (т.е. до закрытия окна) и только для одного и того же окна.</p>]]></description>
			<author><![CDATA[null@example.com (wisgest)]]></author>
			<pubDate>Fri, 26 Jun 2015 14:31:50 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=94758#p94758</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Разворот соответствующих блоков следующей страницы — при переходе]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=94757#p94757</link>
			<description><![CDATA[<p>На будущее. предложенное решение со сменой атрибута стиля не самое лучшее. Например, оно работает для блочных элементов, но не работает для текстовых - они становятся блочными. Лучше делать через добавление удаление классого стиля, например как в следующем примере. Кода становится чуть больше, но использование его универсальнее и гораздо проще поддерживать другие решения на его основе. </p><p>Технология предполагает наличие классового стиля <strong>.hide</strong> (это пример, у вас может быть любой другой). Код добавляет и удаляет данный стиль в заданных элементах. </p><div class="codebox"><pre><code>
&lt;html&gt;
&lt;head&gt;
&lt;style&gt;

.container {
    border: 1px solid #000;
    width: 300px;
}

.content {
    background-color: #ccc;
}

.hide    {
    display: none;
}

&lt;/style&gt;

&lt;script&gt;

function class2regex(name)
{
    return new RegExp(&#039;(?:^|\\s+)&#039; + name + &#039;(?=\\s+|$)&#039;, &#039;g&#039;);
};

function hasClass(object, name)
{
    var re = class2regex(name);
    return object.className.match(re);
};

function addClass(object, name)
{
    if ( hasClass(object, name) ) {
        return;
    }
    object.className = object.className + &#039; &#039; + name;
};

function removeClass(object, name)
{
    var re = class2regex(name);
    object.className = object.className.replace(re, &#039; &#039;)
};

function toggleClass(object, name)
{
    if ( hasClass(object, name) ) {
        removeClass(object, name);
    } else {
        addClass(object, name);
    }
};

window.onload = function()
{
    document.getElementById(&#039;container&#039;).onclick = function()
    {
        var content = this.getElementsByTagName(&#039;div&#039;)[1];
        toggleClass(content, &#039;hide&#039;);
    };
};

&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div id=&quot;container&quot; class=&quot;container&quot;&gt;
&lt;div class=&quot;clicker&quot;&gt;CLICK ME&lt;/div&gt;
&lt;div class=&quot;content&quot;&gt;Lorem ipsum&lt;/div&gt;
&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Rumata)]]></author>
			<pubDate>Fri, 26 Jun 2015 13:39:19 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=94757#p94757</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Разворот соответствующих блоков следующей страницы — при переходе]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=94755#p94755</link>
			<description><![CDATA[<p>Спасибо еще раз! На всякий случай прикреплю то что получилось.</p><p><a href="http://forum.script-coding.com/misc.php?action=pun_attachment&amp;item=1002&amp;download=1&amp;secure_str=25263t10728">d.rar</a></p>]]></description>
			<author><![CDATA[null@example.com (DD)]]></author>
			<pubDate>Fri, 26 Jun 2015 11:56:04 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=94755#p94755</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Разворот соответствующих блоков следующей страницы — при переходе]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=94754#p94754</link>
			<description><![CDATA[<p>Если куки с локальными файлами не работают, то просто - никак.</p>]]></description>
			<author><![CDATA[null@example.com (Rumata)]]></author>
			<pubDate>Fri, 26 Jun 2015 11:28:49 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=94754#p94754</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Разворот соответствующих блоков следующей страницы — при переходе]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=94753#p94753</link>
			<description><![CDATA[<p>Спасибо большое, <strong>Rumata</strong>! Отлично работает!<br />Ещё хочется спросить: действительно ли без использования кук, иначе запоминание раскрытого спойлера из блока не сделать?</p>]]></description>
			<author><![CDATA[null@example.com (DD)]]></author>
			<pubDate>Fri, 26 Jun 2015 11:23:08 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=94753#p94753</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Разворот соответствующих блоков следующей страницы — при переходе]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=94752#p94752</link>
			<description><![CDATA[<p>Наколеночное решение. Но уже работает. Надо еще надо шлифовать. </p><p><strong>1.html</strong><br /></p><div class="codebox"><pre><code>
&lt;html&gt;
&lt;body&gt;

&lt;a href=&quot;2.html#id1&quot;&gt;block 1&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;2.html#id2&quot;&gt;block 2&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;2.html#id3&quot;&gt;block 3&lt;/a&gt;&lt;br /&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre></div><p><strong>2.html</strong><br /></p><div class="codebox"><pre><code>
&lt;html&gt;
&lt;head&gt;
&lt;style&gt;

.content    {
    display: none;
}

&lt;/style&gt;
&lt;script&gt;

function toggleContent(block)
{
    var content = block.getElementsByTagName(&#039;div&#039;)[0];
    if ( ! content.className.match(/\bcontent\b/) ) {
        return;
    }

    if ( content.style.display == &#039;block&#039; ) {
        content.style.display = &#039;none&#039;;
    } else {
        content.style.display = &#039;block&#039;;
    }
};

window.onload = function()
{
    var id = window.location.hash;
    if ( ! id ) {
        return;
    }

    id = id.replace(/#/, &#039;&#039;);

    var block = document.getElementById(id);
    if ( ! block ) {
        return;
    }

    toggleContent(block);
};

&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div id=&quot;id1&quot;&gt;BLOCK 1
&lt;div class=&quot;content&quot;&gt;
To be or not to be
&lt;/div&gt;
&lt;/div&gt;

&lt;div id=&quot;id2&quot;&gt;BLOCK 2
&lt;div class=&quot;content&quot;&gt;
Lorem ipsum
&lt;/div&gt;
&lt;/div&gt;
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Rumata)]]></author>
			<pubDate>Fri, 26 Jun 2015 10:01:40 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=94752#p94752</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Разворот соответствующих блоков следующей страницы — при переходе]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=94751#p94751</link>
			<description><![CDATA[<p>На целевой странице javascript-ом делаете проверку на наличие hash и открываете соответвующий div-блок (или какой-то другой). Этот блок должен существовать. При открытии страницы все блоки раскрывающиеся блоки должны быть закрыты (или их надо закрыть сразу после перехода на соответствующую страницу). Надо сконструировать страницу так чтобы, каждому раскрывающемуся блоку соответствовал ской hash в адресе страницы.</p>]]></description>
			<author><![CDATA[null@example.com (Rumata)]]></author>
			<pubDate>Fri, 26 Jun 2015 09:59:53 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=94751#p94751</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Разворот соответствующих блоков следующей страницы — при переходе]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=94749#p94749</link>
			<description><![CDATA[<p>А в CHM это работает? Впрочем, и назначение стиля по ID подошло бы.</p>]]></description>
			<author><![CDATA[null@example.com (DD)]]></author>
			<pubDate>Fri, 26 Jun 2015 08:23:42 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=94749#p94749</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Разворот соответствующих блоков следующей страницы — при переходе]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=94746#p94746</link>
			<description><![CDATA[<div class="quotebox"><cite>DD пишет:</cite><blockquote><p>С куками можно было бы запоминать раскрытые спойлеры из определенных блоков при переходах. Что было бы гибче — потому что, например, при переходе на страницу назад, спойлер из соответствующего блока был бы раскрыт</p></blockquote></div><p>Для обмена данными между страницами, загружаемыми в одно и то же окно, можно воспользоваться свойством <em>window.name</em> (если что, это строка).</p>]]></description>
			<author><![CDATA[null@example.com (wisgest)]]></author>
			<pubDate>Fri, 26 Jun 2015 00:55:32 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=94746#p94746</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Разворот соответствующих блоков следующей страницы — при переходе]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=94745#p94745</link>
			<description><![CDATA[<div class="quotebox"><cite>shiz пишет:</cite><blockquote><p>К чему упомянуты куки?</p></blockquote></div><p>С куками можно было бы запоминать раскрытые спойлеры из определенных блоков при переходах. Что было бы гибче — потому что, например, при переходе на страницу назад, спойлер из соответствующего блока был бы раскрыт. А здесь речь идёт как бы о полу-мере))</p><div class="quotebox"><blockquote><p>Hash знаю, что такое &quot;nash&quot;?</p></blockquote></div><p>Может опечатка была?</p><div class="quotebox"><blockquote><p>Только я в коде страниц (001.html, 002.html) не нашёл элементов с такими id (&quot;blok_1_1&quot;, &quot;blok_1_2&quot;...), к которым мог бы быть применён этот код.</p></blockquote></div><p>А так? —<br /></p><div class="codebox"><pre><code>
&lt;div id=&quot;d1&quot;&gt;data&lt;/div&gt;
&lt;div id=&quot;d2&quot;&gt;data&lt;/div&gt;
&lt;div id=&quot;d3&quot;&gt;data&lt;/div&gt;
</code></pre></div><p>Собственно, ID можно любые подставить.</p>]]></description>
			<author><![CDATA[null@example.com (DD)]]></author>
			<pubDate>Thu, 25 Jun 2015 23:54:56 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=94745#p94745</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Разворот соответствующих блоков следующей страницы — при переходе]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=94744#p94744</link>
			<description><![CDATA[<div class="quotebox"><blockquote><p>можно ли в CHM-файлах (в которых, как я недавно выяснил, куки не работают)</p></blockquote></div><p>К чему упомянуты куки?<br /></p><div class="quotebox"><blockquote><p>Подсказывали, что уместно воспользоваться hash, nash</p></blockquote></div><p>Hash знаю, что такое &quot;nash&quot;?<br /></p><div class="quotebox"><blockquote><p>может и этому есть применение?</p></blockquote></div><p>Только я в коде страниц (001.html, 002.html) не нашёл элементов с такими id (&quot;blok_1_1&quot;, &quot;blok_1_2&quot;...), к которым мог бы быть применён этот код.</p>]]></description>
			<author><![CDATA[null@example.com (shiz)]]></author>
			<pubDate>Thu, 25 Jun 2015 22:46:16 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=94744#p94744</guid>
		</item>
	</channel>
</rss>
