Antichat снова доступен.
Форум Antichat (Античат) возвращается и снова открыт для пользователей.
Здесь обсуждаются безопасность, программирование, технологии и многое другое.
Сообщество снова собирается вместе.
Новый адрес: forum.antichat.xyz
 |
|

17.02.2009, 20:44
|
|
Постоянный
Регистрация: 11.11.2006
Сообщений: 834
Провел на форуме: 3941248
Репутация:
668
|
|
Код HTML:
<script type="text/javascript">
//Javasript BBC text editor designed by Rakuli - www.openthource.com (You can get rid of this if you want ;)
// Javascript can have abstraction too, so let's abstract just about EVERYTHING
// Let's define the class In this one I have hard-coded a lot of things which kinda sux but we'll live
// it still makes thing easier to change later on...
// The code here will be longer than your current code but nothing will be embedded in your html
function createTextEditor(txtName)
// this takes the name of the textarea which needs to also be the name of the variable (just for ease of user and self referencing)
// We will create the variable later using var myTextEditor = new createTextEditor('myTextEditor');
{
this.id = txtName; // Name our object
this.textarea = document.getElementById(txtName); // Store a reference to textarea
this.textarea.onselect = function () {this.storeCursor(this)};
this.textarea.onchange = function () {this.storeCursor(this)};
this.textarea.onkeyup = function () {this.storeCursor(this)};
this.textarea.onclick = function () {this.storeCursor(this)};
this.textarea.storeCursor = function () {
// Make it easier to track the cursor in IE
if (typeof(this.createTextRange) != "undefined")
this.cursorPos = document.selection.createRange().duplicate();
};
// Okay, now we'll create an object for each of the formatting options you want
// Same as the main, pass the ID of the
// To ease everything we'll give each child a parent propery
this.boldText = new createSimpleText('boldText', 'Bold', 'b', this);
this.italicText = new createSimpleText('italicText', 'Italicise', 'i', this);
this.underLine = new createSimpleText('underLine', 'Underline', 'u', this);
this.mail = new createSimpleText('mail', 'Email', 'mail', this);
this.quote = new createSimpleText('quote', 'Quote', 'quote', this, '[quote=AuthorName]Text[/quote]');
this.url = new createSimpleText('url', 'URL', 'url', this, '[url=URL]Link Name[/url]');
this.fontColor = new createSelectBoxText('fontColor', 'Font Color', 'color', this, '[color=colorName]Text[/color]');
this.fontSize = new createSelectBoxText('fontSize', 'Font Size', 'size', this, '[size=fontSize]Text[/size]');
//the ID of the help box
this.helpBox = document.getElementById('helpBox');
this.showHelp = function (helpTxt)
{
this.helpBox.innerHTML = helpTxt;
};
this.updateText = function (tagOpen, tagClose)
{
// See if we have a selection and whether to replace or add or just slot in
// IE makes this easy because we used the onselect function earlier
if (typeof(this.textarea.cursorPos) != "undefined" && this.textarea.createTextRange)
{
var cursorPos = this.textarea.cursorPos, stored_length = cursorPos.text.length;
cursorPos.text = cursorPos.text.charAt(cursorPos.text.length - 1) == ' ' ? tagOpen + cursorPos.text + tagClose + ' ' : tagOpen + cursorPos.text + tagClose;
// If we are just inserting the tag where the cursor is sitting then we will place the cursor
// between the tags (nifty ;) )
if (stored_length == 0)
{
cursorPos.moveStart("character", -tagClose.length);
cursorPos.moveEnd("character", -tagClose.length);
cursorPos.select();
}
else
this.textarea.focus(cursorPos);
}
// A little bit messier with REAL browsers ...
else if (typeof(this.textarea.selectionStart) != "undefined")
{
// store the text before the selection
var strt = this.textarea.value.substr(0, this.textarea.selectionStart);
// the actual selected text
var selection = this.textarea.value.substr(this.textarea.selectionStart, this.textarea.selectionEnd - this.textarea.selectionStart);
// store the text after the selection
var fin = this.textarea.value.substr(this.textarea.selectionEnd);
// put the cursor at the endo of the selection
var cursorPos = this.textarea.selectionStart;
var scrollPos = this.textarea.scrollTop; // make sure the cursor isn't invisible when we place it in
this.textarea.value = strt + tagOpen + selection + tagClose + fin; // Write the tags
if (this.textarea.setSelectionRange)
{
if (selection.length == 0)
// put the cursor in the middle again if nothing is selected
this.textarea.setSelectionRange(cursorPos + tagOpen.length, cursorPos + tagOpen.length);
else
// else place the cursor after the tag
this.textarea.setSelectionRange(cursorPos, cursorPos + tagOpen.length + selection.length + tagClose.length);
this.textarea.focus();
}
// scroll the required position
this.textarea.scrollTop = scrollPos;
}
// Dunno what happened here, something went wrong so just plug it at the end...
else
{
this.textarea.value += tagOpen + tagClose;
this.textarea.focus(this.textarea.value.length - 1);
}
}
this.insertSingleTag = function (tag) // This will insert a sinlge tag (like smilies or a <br /> or something)
{
// Pretty much same as above, but just one tag going in (this will overwrite selected text -- like pasting sometthing would)
// Thankfully IE makes this easier too
if (typeof(this.textarea.cursorPos) != "undefined" && this.textarea.createTextRange)
{
var cursorPos = this.textarea.cursorPos;
cursorPos.text = cursorPos.text.charAt(cursorPos.text.length - 1) == ' ' ? tag + ' ' : tag;
cursorPos.select();
}
// But messiness comes with real browsers
else if (typeof(this.textarea.selectionStart) != "undefined")
{
var strt = this.textarea.value.substr(0, this.textarea.selectionStart);
var fin = this.textarea.value.substr(this.textarea.selectionEnd);
var scrollPos = this.textarea.scrollTop;
this.textarea.value = strt + tag + fin
if (this.textarea.setSelectionRange)
{
this.textarea.focus();
this.textarea.setSelectionRange(strt.length + tag.length, strt.length + tag.length);
}
this.textarea.scrollTop = scrollPos;
}
// Just put it on the end.
else
{
this.textarea.value += tag;
this.textarea.focus(this.textarea.value.length - 1);
}
}
}
// Basically pass the id of the input, the name of the style, the opening tag, the closing tag, the parent and optionally an additional bit of text
// Use this function for creating simple things like [u][/u] [quote][/quote] where nothing needs to be dynamically added to the BBC tags..
function createSimpleText(inpName, txtName, tag, theParent, addHelpTxt)
{
this.inpName = document.getElementById(inpName); // store an object reference
this.inpName._parent = theParent;
this.inpName.tagOpen = '[' + tag + ']'; // wrap up the tag in the square brackets
this.inpName.tagClose = '[/' + tag + ']';
this.inpName.helpString = '<strong>' + txtName + ' Text : </strong> ' + this.inpName.tagOpen + ' text ' + this.inpName.tagClose + (addHelpTxt ? ' or ' + addHelpTxt : '');
this.inpName.onmouseover = function () { this._parent.showHelp(this.helpString); };
this.inpName.onmouseout = function () { this._parent.showHelp('');};
this.inpName.onclick = function () { this._parent.updateText(this.tagOpen, this.tagClose);};
}
function createSelectBoxText (inpName, txtName, tag, theParent, addHelpTxt)
{
this.inpName = document.getElementById(inpName); // store an object reference
this.inpName._parent = theParent;
this.inpName.tagOpen = '[' + tag + '='; // add the parameter from the value of the selectBox
this.inpName.tagClose = '[/' + tag + ']';
this.inpName.helpString = '<strong>' + txtName + ': </strong> ' + addHelpTxt;
this.inpName.onmouseover = function () { this._parent.showHelp(this.helpString); };
this.inpName.onmouseout = function () { this._parent.showHelp('');};
this.inpName.onchange = function () { this._parent.updateText(this.tagOpen + this.options[this.selectedIndex].value + ']', this.tagClose);};
}
</script>
есть код а как его юзать хз =) с JS никада не работал и не пойму как скрипт к форме привязать =\\
|
|
|

18.02.2009, 13:36
|
|
Познающий
Регистрация: 25.12.2008
Сообщений: 34
Провел на форуме: 63045
Репутация:
6
|
|
подскажите, есть ли в javascript функции аналогичные
strip_tags(), addslashes и trim
|
|
|

18.02.2009, 13:49
|
|
Участник форума
Регистрация: 26.02.2007
Сообщений: 259
Провел на форуме: 302951
Репутация:
67
|
|
Сообщение от DMajere
подскажите, есть ли в javascript функции аналогичные
strip_tags(), addslashes и trim
PHP код:
function strip_tags( str )
{
return str.replace(/<\/?[^>]+>/gi, '');
}
function addslashes( str )
{
return (str+'').replace(/([\\"'])/g, "\\$1").replace(/\0/g, "\\0");
}
function trim(string)
{
return string.replace(/(^\s+)|(\s+$)/g, "");
}
провда не проверял, пашет или нет, вот проверишь напиши=)
|
|
|

18.02.2009, 13:52
|
|
Познающий
Регистрация: 25.12.2008
Сообщений: 34
Провел на форуме: 63045
Репутация:
6
|
|
спасибо за код. я так понял, что встроенных подобных функций нет?
хм. отчего-то не работает ваш код, Корвин
даже могу сказать почему. в первой функции использован обр слеш как ограничитель шаблона
(/</?[^>]+>/gi, '')
шаблон будет закрываться раньше. ну да это ничего. это мы сами допрем)))
еще раз спасибо за ответ
Последний раз редактировалось DMajere; 18.02.2009 в 16:08..
|
|
|

19.02.2009, 21:04
|
|
Новичок
Регистрация: 22.08.2007
Сообщений: 12
Провел на форуме: 26020
Репутация:
0
|
|
1) JavaScript. Обычные часы вида hh:mm:ss но время на них должно показывать серверное. php использовать можно.
2) такой же отсчет на JavaScript только обратный, без часов только минуты и секунды. Когда он по нулям нужно обновление страницы, но так чтобы элементы $_POST[]; сохранялись. Как это сделать.
Кто может помогите пожалуйста.
|
|
|

20.02.2009, 14:21
|
|
Banned
Регистрация: 07.09.2008
Сообщений: 48
Провел на форуме: 127764
Репутация:
-1
|
|
|
|
|

20.02.2009, 21:29
|
|
Он хакер.
Регистрация: 01.11.2008
Сообщений: 1,756
Провел на форуме: 6462214
Репутация:
3171
|
|
Грубо говоря,есть массив в php, пускай в 100 значений.
Необходимо.
Вывод на страницу,по 20 штук,тоесть 20 страниц.Но!При нажатии "Перейти на следующую страницу" чтобы небыло обновления страницы,а тупо показывались следубщие 20 ну и так далее.В яве совсем не силен,так чтоо расчитываю на вашу помошщь.
|
|
|

20.02.2009, 21:43
|
|
Постоянный
Регистрация: 29.05.2007
Сообщений: 852
Провел на форуме: 4832771
Репутация:
1916
|
|
Тут явой и не пахнет, это Javascript/AJAX
файл 1
PHP код:
<script>
function pages(p){
var httpRequest = '';
if(window.XMLHttpRequest){
httpRequest = new XMLHttpRequest();
}else{
if(window.ActiveXObject){
try{
httpRequest = new ActiveXObject('Msxml2.XMLHTTP');
}catch(e){
httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
}
}
}
httpRequest.open('GET', 'page.php?p=' + p, true);
httpRequest.send(null);
httpRequest.onreadystatechange = function result(){
if (httpRequest.readyState == 4 || httpRequest.readyState == 'complete'){
document.getElementById('content').innerHTML = httpRequest.responseText;
}
};
}
</script>
Страницы: <a href="javascript:pages(1)"></a> <a href="javascript:(2)"></a> <a href="javascript:(3)"></a>
<div id="content"></div>
файл 2
PHP код:
<?php
$pages = array(
'1' => 'Это контент первой страницы',
'2' => 'Это контент второй страницы',
'3' => 'Это контент третьей страницы');
$p = !empty($_GET['p']) && is_numeric($_GET['p']) ? intval($_GET['p']) : '';
if($p) echo $pages[$p];
?>
примерно так
|
|
|

20.02.2009, 21:54
|
|
Он хакер.
Регистрация: 01.11.2008
Сообщений: 1,756
Провел на форуме: 6462214
Репутация:
3171
|
|
Такс,опробывал,вроде хорошо,но.
Нужно чтобы был один массив,его делило по 20 например.
И страницы генерились автоматом,тоесть,номера:
перейти на: 1,2,3,4,...тоесть сколько кусков стоко и нумеров.
|
|
|

20.02.2009, 22:03
|
|
Постоянный
Регистрация: 29.05.2007
Сообщений: 852
Провел на форуме: 4832771
Репутация:
1916
|
|
Сообщение от m0Hze
Такс,опробывал,вроде хорошо,но.
Нужно чтобы был один массив,его делило по 20 например.
И страницы генерились автоматом,тоесть,номера:
перейти на: 1,2,3,4,...тоесть сколько кусков стоко и нумеров.
И в чём проблема? Циклы, циклы, циклы...
Но это уже php, а не JS
|
|
|
|
 |
|
|
Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
|
|
|
|