Татьяна5 писал(а): js от мода быстрой правки
У этой быстрой правки нет jsика...
Весь js прописан в
quickedit_header.html
Код: Выделить всё
<script>
/**
* change this to the div you need for your style
* if you don't know what it is, take a look at http://www.m-a-styles.de
*/
var quickedit_div = '#post\%d div.content';
var edited_by_div = '#post\%d div.notice';
/**
* init vars - DO NOT CHANGE
*
*/
var quickedit_open = false;
var cur_post_id = 0;
/**
* init functions
*/
// load the jQuery popup
function qe_loadPopup()
{
$("#quickeditBackground").css({"opacity": "0.7"});
// Now let's make sure we actually see the image
var scroll = $(window).scrollTop();
$("#popupQuickedit").animate({marginTop: scroll}, 'fast', function() {
// Animation complete.
});
$("#quickeditBackground").fadeIn("slow");
$("#popupQuickedit").fadeIn("slow");
}
//centering popup
function qe_centerPopup()
{
//request data for centering
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var popupHeight = $("#popupQuickedit").height();
var popupWidth = $("#popupQuickedit").width();
//centering
$("#popupQuickedit").css({
"position": "absolute",
"top": windowHeight/2-popupHeight/2,
"left": windowWidth/2-popupWidth/2
});
//only need force for IE6
$("#quickeditBackground").css({"height": windowHeight});
}
// close the pop up
function qe_disablePopup()
{
$("#quickeditBackground").fadeOut("slow");
$("#popupQuickedit").fadeOut("slow");
}
// load the jQuery popup
function loadQEError()
{
$("#quickeditErrorBG").css({"opacity": "0.7"});
$("#quickeditErrorBG").fadeIn("slow");
$("#quickeditError").fadeIn("slow");
qe_bind_error_msg();
}
//centering popup
function centerQEError()
{
//request data for centering
var popupOffset = $('#popupQuickedit').offset();
var popupTop = popupOffset.top;
var popupLeft = popupOffset.left;
var scroll = $(window).scrollTop();
var popupHeight = $('#popupQuickedit').height();
var windowHeight = document.documentElement.clientHeight;
var windowWidth = (document.documentElement.clientWidth)/2;
var newTop = windowHeight/2 - popupHeight/2;
var newLeft = (windowWidth/2) - popupLeft/2;
//centering
$('#quickeditError').css({
"position": "absolute",
"top": newTop,
"left": newLeft
});
//only need force for IE6
$("#quickeditErrorBG").css({"height": windowHeight});
}
// close the pop up
function disableQEError()
{
$("#quickeditErrorBG").fadeOut("slow");
$("#quickeditError").fadeOut("slow");
}
/*
* bind the Error events if an error occurs
*/
function qe_bind_error_msg()
{
// Click on error window
$('#quickeditError').bind('click',function() {
var cur_action = $('#quickeditAction').html();
if(cur_action == 'cancel')
{
disableQEError();
qe_disablePopup();
quickedit_open = false;
}
else if(cur_action == 'return')
{
disableQEError();
}
});
}
/*
* Onclick functions for BBCode buttons
*/
function bind_quickedit_buttons()
{
// somebody clicks on the bbcode buttons
$('#quickedit-buttons input').bind('click', function() {
cur_bbcode = $(this).attr('id');
cur_bbcode = cur_bbcode.replace(/bbcode/g, ''); // filter out unneeded parts
// make sure we don't get javascript errors
if (cur_bbcode == parseInt(cur_bbcode))
{
qe_bbstyle(parseInt(cur_bbcode));
}
});
// somebody uses the size dropdown box
$('select#addbbcode202').bind('change', function() {
var cur_size = $('select#addbbcode202 option:selected').val();
qe_bbfontstyle('[size=' + cur_size + ']', '[/size]');
$('select#addbbcode202 option')[2].attr('selected', 'selected');
});
// click on "submit"
$('#submit_jqe').bind('click', function() {
if(quickedit_open == true)
{
content = $('textarea#jqe-message').serialize();
content = content.substring(8); // make sure we get rid of the 'message=' in front of the post text
cur_location = $(location).attr('href');
data = 'mode=submit&post_id=' + post_id + '&contents=' + content + '&location=' + location;
qe_do_ajax('submit', data);
}
});
// click on "cancel"
$('#cancel_jqe').bind('click', function() {
if(quickedit_open == true)
{
$('textarea#jqe-message').val(''); // make sure the user can't see what was in the textbox after clicking cancel
cancel_edit(); // we don't need an ajax request since we just need to close the edit window
quickedit_open = false;
}
});
// click on "advanced edit"
$('#adv_jqe').bind('click', function() {
if(quickedit_open == true)
{
// get current url for forum_id if we have a global announcement
cur_location = $(location).attr('href');
content = $('textarea#jqe-message').serialize();
content = content.substring(8); // make sure we get rid of the 'message=' in front of the post text
data = 'mode=advanced_edit&post_id=' + post_id + '&contents=' + content + '&location=' + location;
qe_do_ajax('advanced_edit', data);
return false;
}
});
}
/**
* Quickedit functions
*/
$(document).ready(function(){
$('.qe-icon a').click(function() {
post_id = $(this).attr('id');
post_id = post_id.replace(/quickedit/g, ''); // filter out the post ID
// check if quick edit is already enabled
if(quickedit_open != true)
{
qe_centerPopup();
qe_loadPopup();
cur_location = $(location).attr('href');
data = 'mode=init&post_id=' + post_id + '&location=' + location;
qe_do_ajax('open', data);
quickedit_open = true;
cur_post_id = post_id;
}
});
});
// open edit window
function open_edit(success)
{
$('#popupQuickedit').html(success);
if($('#quickeditError').html() != '')
{
centerQEError();
loadQEError();
}
else
{
bind_quickedit_buttons();
}
}
// submit edit
function submit_edit(data)
{
var return_data = data.split('{/qe_seperator}');
var qe_error = return_data[0];
var qe_action = return_data[1];
var edited_by = return_data[2];
var post_text = return_data[3];
// if someone actually writes '{/qe_seperator}' into the post_text, we don't want to leave half the text behind
if(return_data.length > 4)
{
var i_end = return_data.length - 1;
for(i = 4; i <= i_end; i++)
{
post_text = post_text + '{/qe_seperator}' + return_data[i];
}
}
if(qe_error != false)
{
$('#quickeditError').html(qe_error);
$('#quickeditAction').html(qe_action);
centerQEError();
loadQEError();
}
else
{
var cur_div = quickedit_div.replace(/\%d/, cur_post_id);
$(cur_div).html(post_text);
if(edited_by != false)
{
var cur_edited_by_div = edited_by_div.replace(/\%d/, cur_post_id);
$(cur_edited_by_div).html(edited_by); // does not work with subsilver2
}
$('textarea#jqe-message').val(''); // make sure the user can't see what was in the textbox after clicking cancel
qe_disablePopup();
quickedit_open = false;
}
}
// cancel quickedit
function cancel_edit()
{
qe_disablePopup();
quickedit_open = false;
}
// open advanced edit
function advanced_edit(success)
{
$('#popupQuickedit').html(success);
if($('#quickeditError').html() != '')
{
centerQEError();
loadQEError();
}
else
{
$('#jqe-adv-form').submit();
}
}
// general AJAX function
function qe_do_ajax(mode, data)
{
$.ajax({
type: 'POST',
data: data,
dataType: 'html',
url: '{U_QUICKEDIT}',
success: function(data){
if(mode == 'open')
{
$('#quickeditError').html('');
open_edit(data);
}
else if(mode == 'submit')
{
submit_edit(data);
}
else if(mode == 'advanced_edit')
{
advanced_edit(data);
}
}
});
}
/**
* some initial vars, needed for the next few functions
*/
// Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version
var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1));
var is_win = ((clientPC.indexOf('win') != -1) || (clientPC.indexOf('16bit') != -1));
var baseHeight;
bbcode = new Array();
qe_bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','
','
','
','[img]','[/img]','
','','[flash=]', '[/flash]','[size=]','[/size]'<!-- BEGIN custom_tags -->, {custom_tags.BBCODE_NAME}<!-- END custom_tags -->);
var qe_txt_name = 'jqe-message';
var qe_txt_name2 = '#jqe-message';
/**
* Fix a bug involving the TextRange object. From
*
http://www.frostjedi.com/terra/scripts/ ... etBug.html
*/
function qe_initInsertions()
{
//var textarea = document.getElementById(qe_txt_name);
var textarea = $(qe_txt_name2);
if (is_ie && typeof(baseHeight) != 'number')
{
textarea.focus();
baseHeight = document.selection.createRange().duplicate().boundingHeight;
}
}
/**
* bbstyle
*/
function qe_bbstyle(bbnumber)
{
if (bbnumber != -1)
{
qe_bbfontstyle(qe_bbtags[bbnumber], qe_bbtags[bbnumber+1]);
}
else
{
qe_insert_text('[*]');
document.getElementById(qe_txt_name).focus();
}
}
/**
* Apply bbcodes
*/
function qe_bbfontstyle(bbopen, bbclose)
{
theSelection = false;
var textarea = document.getElementById(qe_txt_name);
textarea.focus();
if ((clientVer >= 4) && is_ie && is_win)
{
// Get text selection
theSelection = document.selection.createRange().text;
if (theSelection)
{
// Add tags around selection
document.selection.createRange().text = bbopen + theSelection + bbclose;
document.getElementById(qe_txt_name).focus();
theSelection = '';
return;
}
}
else if (document.getElementById(qe_txt_name).selectionEnd && (document.getElementById(qe_txt_name).selectionEnd - document.getElementById(qe_txt_name).selectionStart > 0))
{
qe_mozWrap(document.getElementById(qe_txt_name), bbopen, bbclose);
document.getElementById(qe_txt_name).focus();
theSelection = '';
return;
}
//The new position for the cursor after adding the bbcode
var caret_pos = qe_getCaretPosition(textarea).start;
var new_pos = caret_pos + bbopen.length;
// Open tag
qe_insert_text(bbopen + bbclose);
// Center the cursor when we don't have a selection
// Gecko and proper browsers
if (!isNaN(textarea.selectionStart))
{
textarea.selectionStart = new_pos;
textarea.selectionEnd = new_pos;
}
// IE
else if (document.selection)
{
var range = textarea.createTextRange();
range.move("character", new_pos);
range.select();
qe_storeCaret(textarea);
}
textarea.focus();
return;
}
/**
* Insert text at position
*/
function qe_insert_text(text, spaces, popup)
{
var textarea;
if (!popup)
{
textarea = document.getElementById(qe_txt_name);
}
else
{
textarea = opener.document.getElementById(qe_txt_name);
}
if (spaces)
{
text = ' ' + text + ' ';
}
if (!isNaN(textarea.selectionStart))
{
var sel_start = textarea.selectionStart;
var sel_end = textarea.selectionEnd;
qe_mozWrap(textarea, text, '')
textarea.selectionStart = sel_start + text.length;
textarea.selectionEnd = sel_end + text.length;
}
else if (textarea.createTextRange && textarea.caretPos)
{
if (baseHeight != textarea.caretPos.boundingHeight)
{
textarea.focus();
qe_storeCaret(textarea);
}
var caret_pos = textarea.caretPos;
caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) == ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text;
}
else
{
textarea.value = textarea.value + text;
}
if (!popup)
{
textarea.focus();
}
}
/**
* From
http://www.massless.org/mozedit/
*/
function qe_mozWrap(txtarea, open, close)
{
var selLength = txtarea.textLength;
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
var scrollTop = txtarea.scrollTop;
if (selEnd == 1 || selEnd == 2)
{
selEnd = selLength;
}
var s1 = (txtarea.value).substring(0,selStart);
var s2 = (txtarea.value).substring(selStart, selEnd)
var s3 = (txtarea.value).substring(selEnd, selLength);
txtarea.value = s1 + open + s2 + close + s3;
txtarea.selectionStart = selEnd + open.length + close.length;
txtarea.selectionEnd = txtarea.selectionStart;
txtarea.focus();
txtarea.scrollTop = scrollTop;
return;
}
/**
* Insert at Caret position. Code from
*
http://www.faqts.com/knowledge_base/vie ... 52/fid/130
*/
function qe_storeCaret(textEl)
{
if (textEl.createTextRange)
{
textEl.caretPos = document.selection.createRange().duplicate();
}
}
/**
* Caret Position object
*/
function qe_caretPosition()
{
var start = null;
var end = null;
}
/**
* Get the caret position in an textarea
*/
function qe_getCaretPosition(txtarea)
{
var caretPos = new qe_caretPosition();
// simple Gecko/Opera way
if(txtarea.selectionStart || txtarea.selectionStart == 0)
{
caretPos.start = txtarea.selectionStart;
caretPos.end = txtarea.selectionEnd;
}
// dirty and slow IE way
else if(document.selection)
{
// get current selection
var range = document.selection.createRange();
// a new selection of the whole textarea
var range_all = document.body.createTextRange();
range_all.moveToElementText(txtarea);
// calculate selection start point by moving beginning of range_all to beginning of range
var sel_start;
for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++)
{
range_all.moveStart('character', 1);
}
txtarea.sel_start = sel_start;
// we ignore the end value for IE, this is already dirty enough and we don't need it
caretPos.start = txtarea.sel_start;
caretPos.end = txtarea.sel_start;
}
return caretPos;
}
</script>[/code]
Добавлено спустя 1 минуту 14 секунд:
Чойто в быстрой правке лыжи не едут...вместо клика бьется черти что... гы.
Добавлено спустя 1 минуту 17 секунд:
Да ну его нафиг, тот клик в быстрой правке