Дублирую тему со своего сайта.
Метод 1. Он простой, но без красивостей
Итак приступим. Мы будем приделывать модуль спойлера из форумного движка Vbulletin.
Редактируем файл /classes/others/class_ownbb.php
В конец файла (но перед ?>)добавляем:
Цитата
# спойлер
class OwnBbCode_spoiler extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
$params=$params ? Strings::ParseParams($params) : array();
if(isset($params['noparse']))
{
unset($params['noparse']);
return parent::PreEdit($tag,$params,$content,true);
}
If (!isset($params['name'])) {
$params['name']=' >>> Спойлер';}
return '<div style="margin:20px; margin-top:5px"><div class="smallfont" style="margin-bottom:2px"><b>'.$params['name'].' </b><input type="button" value="Показать" style="width:60px;height:17px;font-size:10px;margin:0px;padding:0px;" onClick="if (this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style<</span></span></span>/span>.display != \'\') { this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display = \'\'; this.innerText = \'\'; this.value = \'Скрыть\'; } else { this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.<</span></span></span>/span>display = \'none\'; this.innerText = \'\'; this.value = \'Показать\'; }"></div><div class="alt2" style="margin: 0px; padding: 6px; border: 1px inset;"><div style="display: none;">'.$content.'</div></div></div>';
}
}
class OwnBbCode_spoiler extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
$params=$params ? Strings::ParseParams($params) : array();
if(isset($params['noparse']))
{
unset($params['noparse']);
return parent::PreEdit($tag,$params,$content,true);
}
If (!isset($params['name'])) {
$params['name']=' >>> Спойлер';}
return '<div style="margin:20px; margin-top:5px"><div class="smallfont" style="margin-bottom:2px"><b>'.$params['name'].' </b><input type="button" value="Показать" style="width:60px;height:17px;font-size:10px;margin:0px;padding:0px;" onClick="if (this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style<</span></span></span>/span>.display != \'\') { this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display = \'\'; this.innerText = \'\'; this.value = \'Скрыть\'; } else { this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.<</span></span></span>/span>display = \'none\'; this.innerText = \'\'; this.value = \'Показать\'; }"></div><div class="alt2" style="margin: 0px; padding: 6px; border: 1px inset;"><div style="display: none;">'.$content.'</div></div></div>';
}
}
Вот и все. Теперь в админке создаем bb-код с названием spoiler, и можно использовать.
Спойлеру можно задавать имя с помощью spoiler name="Здесь можно задать имя"
Метод 2. Он сложнее, с участием AJAX, но красивее
Заходим в templates/Uniel/index.php и вставляем код ниже между тегами <head></head>
Цитата
<script type="text/javascript">
$(document).ready(function(){
$('.splLink').click(function(){
$(this).parent().children('div.splCont').toggle('normal');
return false;
});
});
</script>
$(document).ready(function(){
$('.splLink').click(function(){
$(this).parent().children('div.splCont').toggle('normal');
return false;
});
});
</script>
Далее заходим в templates/Uniel/styles/base.css (можно в любой другой файл стиля) и добавляем строчку
Цитата
.splCont{display:none;border:1px solid #cccccc;padding:3px 5px;}
Теперь редактируем файл /classes/others/class_ownbb.php и вставляем туда
Цитата
# спойлер
class OwnBbCode_spoiler extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
$params=$params ? Strings::ParseParams($params) : array();
if(isset($params['noparse']))
{
unset($params['noparse']);
return parent::PreEdit($tag,$params,$content,true);
}
If (!isset($params['name'])) {
$params['name']=' >>> Спойлер';}
return '<div><div class="smallfont" style="margin-bottom:2px"><b>'.$params['name'].'</b> <input type="button" value="Показать" style="width:60px;height:17px;font-size:10px;margin:0px;padding:0px;" onClick="javascript://" class="splLink"><div class="splCont">'.$content.'</div></div></div>';
}
}
class OwnBbCode_spoiler extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
$params=$params ? Strings::ParseParams($params) : array();
if(isset($params['noparse']))
{
unset($params['noparse']);
return parent::PreEdit($tag,$params,$content,true);
}
If (!isset($params['name'])) {
$params['name']=' >>> Спойлер';}
return '<div><div class="smallfont" style="margin-bottom:2px"><b>'.$params['name'].'</b> <input type="button" value="Показать" style="width:60px;height:17px;font-size:10px;margin:0px;padding:0px;" onClick="javascript://" class="splLink"><div class="splCont">'.$content.'</div></div></div>';
}
}
Вот и все. Теперь в админке создаем bb-код с названием spoiler, и можно использовать.
Спойлеру можно задавать имя с помощью spoiler name="Здесь можно задать имя"
Пример: Где то тут
P.S. В спойлерах аттачные картинки отображаются