Единый форум поддержки

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.


Вы здесь » Единый форум поддержки » Корзина » Скрипт спойлера


Скрипт спойлера

Сообщений 1 страница 20 из 28

1

Я добавил на форум скрипт спойлера:

Код:
<script type="text/javascript">
function addSpoiler()
{
 var elm = document.getElementById("pun-main").getElementsByTagName("div");
 for (x in elm)
 if (elm[x].className == "post-content")
  elm[x].innerHTML = elm[x].innerHTML.replace(/\[spoiler\]/g, "<div class='quote-box'><cite onclick='hideSpoiler(this)' style='cursor:pointer;cursor:hand;'><b><u>Текст спойлера</u></b></cite><blockquote style='display:none'>").replace(/\[\/spoiler\]/g, "</blockquote></div>");
 if(form = document.getElementById("form-buttons"))
  form.getElementsByTagName("tr")[0].insertCell(14).innerHTML = "<img style='width:37px;height:21px;' onclick=\"bbcode('[spoiler]', '[/spoiler]')\" src='http://forumupload.ru/uploads/0003/41/8c/1728-1.gif' alt='Спойлер' />";
}

function hideSpoiler(sp)
{
 if (spoiler = sp.parentNode.getElementsByTagName("blockquote")[0])
 {
  if (spoiler.style.display == "none") spoiler.style.display = "inline";
  else spoiler.style.display = "none";
 }
}

addSpoiler();
</script>

Скрипт прекрасно работает, добавилась кнопка spoiler на верхней панели. Но в данной версии нельзя спойлеру присвоить имя. Т.е. приходится писать заголовок, а ниже делать сам спойлер (текст спойлера).
Пример можно посмотреть Здесь
Возможно ли изменить данный скрипт или есть другой рабочий, чтоб вместо слов "Текст спойлера" можно было писать сам заголовок?
Заранее спасибо, жду советов и помощи.
С уважением, Djeday.

0

2

Djeday
Такой подойдёт?

Код:
<style>
#button-spoiler {background-image:url('http://forumupload.ru/uploads/0000/12/13/488-1.gif'); padding:0; line-height:0; background-position:center; background-repeat:no-repeat; height:26px; width:100%}
</style>
<script type="text/javascript">
function tag_spoiler(){
	var y = prompt("Введите описание закрытой кнопки",'');
	if(y!='null' && y!='' && typeof(y)!='object' && typeof(y)!='undefined'){
	var x = prompt("Введите описание открытой кнопки",'');
	if(x=='null' || x=='' || typeof(x)=='object' || typeof(x)=='undefined') bbcode('[spoiler='+y+']','[/spoiler]'); else bbcode('[spoiler='+y+'|'+x+']','[/spoiler]');}
	else bbcode('[spoiler]','[/spoiler]')
}
function addSpoiler(str,from,internal){
	var pos=0,pos2=0,pos_c=0,pos_l=0,newpos=0,string='',close='',open='';
	if((pos=str.indexOf("[spoiler",from))==-1) return str;
	if((pos2=str.indexOf("[/spoiler]"),pos+9)==-1) return str;
	if(((pos_c=str.indexOf("]",pos+8))!=-1) && ((pos_c!=pos+8)&&(pos_c!=pos+9))){
	string = str.substring(pos+9,pos_c);
	if((pos_l = string.indexOf("|"))!=-1){
close = string.substring(0,pos_l);
open = string.substring(pos_l+1,string.length);
	}
	else{
close = string;
open = string;
	}
	}
	else{
close = 'Показать спойлер';
open = 'Скрыть спойлер';
	}
	newpos=str.indexOf("[spoiler",pos+9)
	if(newpos<pos2 && newpos!=-1) str=addSpoiler(str,pos+9,true)
	if((pos2=str.indexOf("[/spoiler]",pos+9))==-1) return str;
	str=str.substring(0,pos)+makeSpoiler(str.substring(pos_c+1,pos2),open,close)+str.substring(pos2+10,str.length)
	if( str.indexOf("[spoiler")!=-1 && internal==false) str=addSpoiler(str,0,false)
	return str;
}

function makeSpoiler(txt,open,close){
	txt='<div class="quote-box" style="padding:1px;background: none; border: 0;"><cite style="width:100%;margin:0;"><input id="'+open+'" class="spoiler-button" style="width:140px;font-size:10px; margin:0;" type="button" value="'+close+'"></cite><blockquote class="quote-box" style="display:none; width: 80%;border: 1px solid black;margin:0;">'+txt+'</blockquote></div>'
	return txt;
}

$(document).ready(function(){
	$("div.quote-box > cite > input.spoiler-button").click(function(){
$(this).parents("div.quote-box:first").find("blockquote.quote-box:first").toggle("slow");
var a = $(this).attr('value');$(this).attr('value',$(this).attr('id'));$(this).attr('id',a);
	});
});

if((document.URL.indexOf("viewtopic.php")!=-1) || (document.URL.indexOf("post.php")!=-1)){
	elm=document.getElementById("pun-main").getElementsByTagName("div")
	for(x in elm) if(elm[x].className=="post-content"){
var post=elm[x]
post.innerHTML=addSpoiler(post.innerHTML,0,false)
	}
}
if(form=document.getElementById("form-buttons"))
	form.getElementsByTagName("tr")[0].insertCell(16).innerHTML="<img  id=\"button-spoiler\" title=\"Спойлер\" onclick=\"tag_spoiler('[spoiler]','[/spoiler]')\" src=\"/i/blank.gif\" />"
</script>

+1

3

Спасибо, этот скрипт намного симпатичнее и удобнее.
Благодарю... :cool:  http://mybb.ru/f/collection/0211.gif

0

4

Подскажите, пожалуйста, как в данном скрипте увеличить размер шрифта (12 подойдет) и сделать его жирным и подчеркнутым?
Да и чтоб надпись слева была а не по центру. Я просто растянул спойлер

Отредактировано Djeday (Сб, 4 Июн 2011 07:54:49)

0

5

Djeday написал(а):

Подскажите, пожалуйста, как в данном скрипте увеличить размер шрифта (12 подойдет) и сделать его жирным и подчеркнутым?Да и чтоб надпись слева была а не по центру.

Я так понимаю, речь идёт про кнопку спойлера?

Код:
<style>
#button-spoiler {background-image:url('http://forumupload.ru/uploads/0000/12/13/488-1.gif'); padding:0; line-height:0; background-position:center; background-repeat:no-repeat; height:26px; width:100%}
</style>
<script type="text/javascript">
function tag_spoiler(){
	var y = prompt("Введите описание закрытой кнопки",'');
	if(y!='null' && y!='' && typeof(y)!='object' && typeof(y)!='undefined'){
	var x = prompt("Введите описание открытой кнопки",'');
	if(x=='null' || x=='' || typeof(x)=='object' || typeof(x)=='undefined') bbcode('[spoiler='+y+']','[/spoiler]'); else bbcode('[spoiler='+y+'|'+x+']','[/spoiler]');}
	else bbcode('[spoiler]','[/spoiler]')
}
function addSpoiler(str,from,internal){
	var pos=0,pos2=0,pos_c=0,pos_l=0,newpos=0,string='',close='',open='';
	if((pos=str.indexOf("[spoiler",from))==-1) return str;
	if((pos2=str.indexOf("[/spoiler]"),pos+9)==-1) return str;
	if(((pos_c=str.indexOf("]",pos+8))!=-1) && ((pos_c!=pos+8)&&(pos_c!=pos+9))){
	string = str.substring(pos+9,pos_c);
	if((pos_l = string.indexOf("|"))!=-1){
close = string.substring(0,pos_l);
open = string.substring(pos_l+1,string.length);
	}
	else{
close = string;
open = string;
	}
	}
	else{
close = 'Показать спойлер';
open = 'Скрыть спойлер';
	}
	newpos=str.indexOf("[spoiler",pos+9)
	if(newpos<pos2 && newpos!=-1) str=addSpoiler(str,pos+9,true)
	if((pos2=str.indexOf("[/spoiler]",pos+9))==-1) return str;
	str=str.substring(0,pos)+makeSpoiler(str.substring(pos_c+1,pos2),open,close)+str.substring(pos2+10,str.length)
	if( str.indexOf("[spoiler")!=-1 && internal==false) str=addSpoiler(str,0,false)
	return str;
}

function makeSpoiler(txt,open,close){
	txt='<div class="quote-box" style="padding:1px;background: none; border: 0;"><cite style="width:100%;margin:0;"><input id="'+open+'" class="spoiler-button" style="width: 800px; font-size: 12px; font-weight: bold; text-align: left; margin: 0;" type="button" value="'+close+'"></cite><blockquote class="quote-box" style="display:none; width: 90%;border: 1px solid black;margin:0;">'+txt+'</blockquote></div>'
	return txt;
}

$(document).ready(function(){
	$("div.quote-box > cite > input.spoiler-button").click(function(){
$(this).parents("div.quote-box:first").find("blockquote.quote-box:first").toggle("slow");
var a = $(this).attr('value');$(this).attr('value',$(this).attr('id'));$(this).attr('id',a);
	});
});

if((document.URL.indexOf("viewtopic.php")!=-1) || (document.URL.indexOf("post.php")!=-1)){
	elm=document.getElementById("pun-main").getElementsByTagName("div")
	for(x in elm) if(elm[x].className=="post-content"){
var post=elm[x]
post.innerHTML=addSpoiler(post.innerHTML,0,false)
	}
}
if(form=document.getElementById("form-buttons"))
	form.getElementsByTagName("tr")[0].insertCell(16).innerHTML="<img  id=\"button-spoiler\" title=\"Спойлер\" onclick=\"tag_spoiler('[spoiler]','[/spoiler]')\" src=\"/i/blank.gif\" />"
</script>

0

6

rps
Спасибо, самое то

0

7

rps
НЕ можете подсказать одну вещь?
У меня темный стиль и хотелось бы выделить спойлер серой оконтовкой. Что нужно изменить или добавить в код спойлера из 5 поста?

0

8

Djeday
Такой вариант подойдет?

Код:
<style>
#button-spoiler {background-image:url('http://forumupload.ru/uploads/0000/12/13/488-1.gif'); padding:0; line-height:0; background-position:center; background-repeat:no-repeat; height:26px; width:100%}
</style>
<script type="text/javascript">
function tag_spoiler(){
	var y = prompt("Введите описание закрытой кнопки",'');
	if(y!='null' && y!='' && typeof(y)!='object' && typeof(y)!='undefined'){
	var x = prompt("Введите описание открытой кнопки",'');
	if(x=='null' || x=='' || typeof(x)=='object' || typeof(x)=='undefined') bbcode('[spoiler='+y+']','[/spoiler]'); else bbcode('[spoiler='+y+'|'+x+']','[/spoiler]');}
	else bbcode('[spoiler]','[/spoiler]')
}
function addSpoiler(str,from,internal){
	var pos=0,pos2=0,pos_c=0,pos_l=0,newpos=0,string='',close='',open='';
	if((pos=str.indexOf("[spoiler",from))==-1) return str;
	if((pos2=str.indexOf("[/spoiler]"),pos+9)==-1) return str;
	if(((pos_c=str.indexOf("]",pos+8))!=-1) && ((pos_c!=pos+8)&&(pos_c!=pos+9))){
	string = str.substring(pos+9,pos_c);
	if((pos_l = string.indexOf("|"))!=-1){
close = string.substring(0,pos_l);
open = string.substring(pos_l+1,string.length);
	}
	else{
close = string;
open = string;
	}
	}
	else{
close = 'Показать спойлер';
open = 'Скрыть спойлер';
	}
	newpos=str.indexOf("[spoiler",pos+9)
	if(newpos<pos2 && newpos!=-1) str=addSpoiler(str,pos+9,true)
	if((pos2=str.indexOf("[/spoiler]",pos+9))==-1) return str;
	str=str.substring(0,pos)+makeSpoiler(str.substring(pos_c+1,pos2),open,close)+str.substring(pos2+10,str.length)
	if( str.indexOf("[spoiler")!=-1 && internal==false) str=addSpoiler(str,0,false)
	return str;
}

function makeSpoiler(txt,open,close){
	txt='<div class="quote-box" style="padding:1px;background: none; border: 0;"><cite style="width:100%;margin:0;"><input id="'+open+'" class="spoiler-button" style="width: 800px; font-size: 12px; font-weight: bold; text-align: left; margin: 0;" type="button" value="'+close+'"></cite><blockquote class="quote-box" style="display:none; width: 90%; border: 2px solid #708090 !important; margin:0;">'+txt+'</blockquote></div>'
	return txt;
}

$(document).ready(function(){
	$("div.quote-box > cite > input.spoiler-button").click(function(){
$(this).parents("div.quote-box:first").find("blockquote.quote-box:first").toggle("slow");
var a = $(this).attr('value');$(this).attr('value',$(this).attr('id'));$(this).attr('id',a);
	});
});

if((document.URL.indexOf("viewtopic.php")!=-1) || (document.URL.indexOf("post.php")!=-1)){
	elm=document.getElementById("pun-main").getElementsByTagName("div")
	for(x in elm) if(elm[x].className=="post-content"){
var post=elm[x]
post.innerHTML=addSpoiler(post.innerHTML,0,false)
	}
}
if(form=document.getElementById("form-buttons"))
	form.getElementsByTagName("tr")[0].insertCell(16).innerHTML="<img  id=\"button-spoiler\" title=\"Спойлер\" onclick=\"tag_spoiler('[spoiler]','[/spoiler]')\" src=\"/i/blank.gif\" />"
</script>

+1

9

Да, спасибо. Снова очень помогли.
+ вам в профиль.

0

10

У меня форум 1bb. Куда нужно вставлять этот скрипт? Вроде как html верха и низа у меня не наблюдается...

0

11

Guyver2011 написал(а):

Вроде как html верха и низа у меня не наблюдается...

если вы администратор своего форума, то у вас в меню должен быть пункт - Администрирование
в нём раздел Настройки
в этих настройках есть поля для добавления кодов html-верх и html-низ (как на сайтах head и body)

p.s. а вообще странно, что данный вопрос в этом разделе форума обсуждается

0

12

Romych
Они с бывшего РуХелпа, насколько я понимаю, и у них другой движок там...

0

13

Я администратор своего форума. Вхожу:

панель Администрирования Форума:

Администрирование:
- Фильтр нецензурных слов
- Настройка смайликов
- Настройка помощи
- Пересчёт статистики

Двиг, по-видимому, совсем другой... Никто не поможет, куда скрипт вставлять?

0

14

Guyver2011 написал(а):

Двиг, по-видимому, совсем другой... Никто не поможет, куда скрипт вставлять?

адрес вашего форума дайте,
посмотрим что за движок

0

15

Удалено...

Отредактировано Guyver2011 (Вс, 17 Июл 2011 19:26:29)

0

16

Guyver2011
всё понятно у вас движок ipb 1.3
под ваш движок достаточно написано скриптов и модов, в том числе мною
можете их найти на сервисе, ссылки на который здесь блокируются из-за соображений конкурирования
наберите в Яндексе

Создать форум IP.Board бесплатно без рекламы

и вы найдёте тот самый сервис (в доменной зоне su), зайдите на форум технической поддержки,
там всё найдёте, и спойлер, и прочее

0

17

Спасибо большое.

0

18

Подскажите, пожалуйста. Ставил уже несколько различный вариаций спойлеров, но с каждым одна и та же проблема. Если он находится в закрепленном первом посте, то открывается только с первой страницы. На всех остальных страницах темы нажатие на кнопку не срабатывает.
Пример:вот тут
Как-то можно поправить? :'(

0

19

Valandil Fefalas написал(а):

страницы. На всех остальных страницах темы нажатие на кнопку не срабатывает.

есть такой Скрипты от пользователей пост 481 но у него тег другой - или теги перебивать или ставить пока оба скрипта( можн отключить использование старого в постах - оставив его ток на отображение старых вариантов, чтобы потихоньку перешли на новый

0

20

Не помогло(((

0


Вы здесь » Единый форум поддержки » Корзина » Скрипт спойлера