مای بی بی MyBB , پلاگین , قالب

RE: ویرایشگر پیشرفته CKEditor

(۱۳ شهریور ۱۳۹۳، ۰۷:۳۰ ق.ظ)amirestiri نوشته:  چرا  پاسخ ب صورت آجاکس نیتس.


بزودی نسخه‌ی 0.8.1 منتشر میشه که باگ‌های پراهمیت پلاگین در آن رفع خواهد شد.
فعلن برای رفع این مشکل می‌توانید فایل jscripts/ckeditor/editor.js را به کد زیر تبدیل کنید:
کد پی‌اچ‌پی:
var autosave = function($btnemessage)
{
    if(
typeof(Storage) == "undefined") return;
    $.
getScript(CKEDITOR.getUrl('extra/moment-with-langs.js'), function()
    {
        
moment.lang(e.editor.config.language);
        
date = new Date();
        var 
timenow date.valueOf();

        $(
'body').append('<div class="autosaveblock" id="autosaveblock_' e.editor.id '"></div>');
        
$elm = $('#autosaveblock_' e.editor.id);

        if(!
message)
        {
            
$elm.html('<h3>'lang.ckeditor_autosaves +'</h3><div class="autosavecontent" style="height:250px"></div>');
            var 
0;
            if(
e.editor.config.clearautosave == 1)
            {
                
$elm.find('.autosavecontent').prepend(lang.ckeditor_autosave_disabled);
            }
            else
            {
                if(
localStorage.getItem('autosave'))
                {
                    
myautosave JSON.parse(localStorage.getItem('autosave'));
                    $.
eachmyautosave, function( keyvalue ) {
                        
value decodeURIComponent(value);
                        
key key.replace('a_''');
                        if(
key timenow 24 60 60 1000 || value.length 5)
                        {
                            
delete myautosave['a_' key];
                            
localStorage.setItem('autosave'JSON.stringify(myautosave));
                            return;
                        }
                        ++
i;
                        
row_time moment.unix(key 1000).fromNow();
                        
message value.substr(050);
                        if(
value.length 50)
                        {
                            
message += '...';
                        }
                        
message message.replace(/>/g'>');
                        
message message.replace(/</g'<');
                        
$row = $('<div class="autosaverow" data-timenow="'+key+'" />');
                        
$row.click(function(ev){
                            
//timenow = $(this).data('timenow');
                            
if($(ev.target).closest('.autosaverow_remove').length == 0) {
                                
e.editor.setData(value);
                            }
                            
delete myautosave['a_' key];
                            
localStorage.setItem('autosave'JSON.stringify(myautosave));

                            $(
this).slideUp();
                        });
                        
$row.append('<a class="autosaverow_remove" href="javascript:;">x</a>');
                        
$row.append('<span class="autosaverow_time">' row_time '</span>');
                        
$row.append('<div class="autosaverow_content">' message '</span>');
                        
$elm.find('.autosavecontent').prepend($row);
                    });
                }
                if(
== 0)
                {
                    
$elm.find('.autosavecontent').prepend(lang.ckeditor_no_autosave);
                }
            }
        }
        else
        {
            
$elm.html(message);
        }

        var 
offset $btn.offset();
        
offset.top -= $elm.outerHeight() + 20;
        if(
e.editor.config.direction == 'ltr')
            
offset.left -= $elm.outerWidth() - 30;

        
$elm.css({
            
position'absolute',
            
topoffset.top,
            
leftoffset.left 7
        
});

        $(
'body, html, textarea, input, iframe').bind('click', function(elv) {
            if($(
elv.target).closest($elm).length == && $(elv.target).closest($btn).length == 0) {
                
$elm.remove();
            }
        });
        
e.editor.on('focus', function(ev) {
            
$elm.remove();
        });
        $(
'body, html, textarea, input, iframe').bind('focus', function(elv) {
            if($(
elv.target).closest($elm).length == && $(elv.target).closest($btn).length == 0) {
                
$elm.remove();
            }
        });
    });
}

var 
messageEditor = (function()
{
    function 
messageEditor()
    {}
    
    function 
setup(textarea)
    {
        
this.editorid textarea;
        if (
typeof CKEDITOR == 'undefined') {
            
document.write(unescape("%3Cscript src=\'"+this.baseURL+"ckeditor/ckeditor.js\' type=\'text/javascript\'%3E%3C/script%3E"));
        }
        eval(
'this.editor = CKEDITOR.instances.'+this.editorid+';');
        
        
// Update Old Textarea:
        
var updatePreview = function(e) {
            var 
consoleEl CKEDITOR.document.getByIde.editor.name );
            
consoleEl.addClass'updated' );
            
setTimeout( function() { consoleEl.removeClass'updated' ); }, 500 );
            
// IE needs <br>, it doesn't even understand new lines.
            
consoleEl.setHtmle.editor.getData());
        }

        var 
checkUpdatePreview = function(e) {
            
setTimeout( function() {
                if ( 
e.editor.checkDirty() ) {
                    
updatePreview(e);
                    
e.editor.resetDirty();
                }
            }, 
);
        }

        
this.editor.on'instanceReady'updatePreview );
        
this.editor.on'key'checkUpdatePreview );
        
this.editor.on'selectionChange'checkUpdatePreview );

        if(
CKEDITOR.config.autosave 0)
        {
            
this.editor.on('instanceReady'this.editor_autosave);
        }
        
this.editor.on('instanceReady'this.stylesheet);
    };

    function 
stylesheet(e)
    {
        var 
stylesheet document.createElement('link');
        
stylesheet.setAttribute('rel''stylesheet');
        
stylesheet.setAttribute('type''text/css');
        
stylesheet.setAttribute('href'CKEDITOR.getUrl('stylesheet.'+e.editor.config.direction+'.css'));
        
document.getElementsByTagName('head')[0].appendChild(stylesheet);
    }

    function 
bindSmilieInserter(id)
    {
        if(!$(
'#' id))
        {
            return 
false;
        }
        var 
that this;

        var 
smilies = $('#' id).find('.smilie');

        if(
smilies.length 0)
        {
            
smilies.each(function()
            {
                $(
this).click(function()
                {
                    $.
proxy(that'insertSmilie'this);
                });
                $(
this).css('cursor'"pointer");
            });
        }
    };
    
/* این از فایل اصلی ویرایشگر ساده برای حالت منبع اضافه شده است... */

    
function performInsert(open_tagclose_tagis_singleignore_selection)
    {
        
this.textarea = $('#cke_' this.editorid).find('textarea').first();
        var 
is_closed true;

        if(!
ignore_selection)
        {
            var 
ignore_selection false;
        }

        if(!
close_tag)
        {
            var 
close_tag "";
        }
        var 
textarea this.textarea;
        
textarea.focus();

        if(
document.selection)
        {
            var 
selection document.selection;
            var 
range selection.createRange();

            if(
ignore_selection != false)
            {
                
selection.collapse;
            }

            if((
selection.type == "Text" || selection.type == "None") && range != null && ignore_selection != true)
            {
                if(
close_tag != "" && range.text.length 0)
                {
                    var 
keep_selected true;
                    
range.text open_tag+range.text+close_tag;
                }
                else
                {
                    var 
keep_selected false;

                    if(
is_single)
                    {
                        
is_closed false;
                    }
                    
range.text open_tag+close_tag;
                }
                
range.select();
            }
            else
            {
                
textarea.value += open_tag+close_tag;
            }
        }
        else if(
typeof(textarea[0].selectionEnd) != 'undefined')
        {
            var 
select_start textarea[0].selectionStart;
            var 
select_end textarea[0].selectionEnd;
            var 
scroll_top textarea[0].scrollTop;

            var 
start textarea.val().substring(0select_start);
            var 
middle textarea.val().substring(select_startselect_end);
            var 
end textarea.val().substring(select_endtextarea.textLength);

            if(
select_end select_start && ignore_selection != true && close_tag != "")
            {
                var 
keep_selected true;
                
middle open_tag+middle+close_tag;
            }
            else
            {
                var 
keep_selected false;
                if(
is_single)
                {
                    
is_closed false;
                }
                
middle open_tag+close_tag;
            }

            
textarea.val(start+middle+end);

            if(
keep_selected == true && ignore_selection != true)
            {
                
textarea[0].selectionStart select_start;
                
textarea[0].selectionEnd select_start middle.length;
            }
            else if(
ignore_selection != true)
            {
                
textarea[0].selectionStart select_start middle.length;
                
textarea[0].selectionEnd textarea[0].selectionStart;
            }
            
textarea[0].scrollTop scroll_top;
        }
        else
        {
            
textarea.val(open_tag+close_tag);

            if(
is_single)
            {
                
is_closed false;
            }
        }
        
//this.updateOldArea();
        
textarea.focus();
        
//this.trackingCaret = true;
        //this.storeCaret();
        //this.trackingCaret = false;
        
return is_closed;
    };

    function 
Insert(texthtml) {
        if(!
html) {
            
html text;
        }
        if(
this.editor.mode == 'wysiwyg') {
            
this.editor.insertHtml(html);
        } else {
            $.
proxy(this'performInsert'text);
        }
    };
    
    function 
execCommand(e,o) {
        if(!
ofalse;
        if(
|| this.editor.mode == 'wysiwyg') {
            return 
this.editor.execCommand(e);
        }
    };
    
    function 
openGetMoreSmilies(editor)
    {
        
this.execCommand('smiley'true);
    };
    
    function 
insertSmilie(e)
    {
        
element e;

        if(!
element || !element.attr('alt'))
        {
            return 
false;
        }
        $.
proxy(this'Insert'element.attr('alt'), '<img src="'+element.attr('src')+'" data-cke-saved-src="'+element.attr('src')+'" title="'+smilieyurlmap[element.attr('src')]+'" alt="'+smilieyurlmap[element.attr('src')]+'">');
    };

    function 
insertAttachment(aid)
    {
        $.
proxy(this'Insert'"+aid+"" title="Attach">فايل پيوست");
    };
    
    function 
editor_autosave(e)
    {
        if(
typeof(Storage) == "undefined") return;
        
$footer = $('#' e.editor.id '_bottom');
        
$footer.append('<a href="javascript:;" id="'+e.editor.id+'_autosave" title="Auto Save" class="autosave"><img src="images/ckeditor/autosave.png" alt="AutoSave" title="Auto Save" /></a>');
        
$autosave = $('#' e.editor.id+'_autosave');
        
$autosave.click(function(){
            
autosave($autosavee);
        });
        
setInterval(function(){
            if(
e.editor.config.clearautosave == 0)
            {
                
myautosave JSON.parse(localStorage.getItem('autosave'));
                
message e.editor.getData();
                
date = new Date();
                var 
timenow date.valueOf();
                
ok false;

                if(
message.length 10 || message == e.editor.config.placeholder)
                    return;
                
                
message encodeURIComponent(message);

                if(
myautosave)
                {
                    $.
eachmyautosave, function( keyvalue ) {
                        if(
value == messageok true;
                    });
                }
                else
                {
                    
myautosave = {};
                }
                if(
ok)
                    return;

                
                
myautosave['a_' timenow] = message;
                
                
localStorage.setItem('autosave'JSON.stringify(myautosave));
            }
        }, 
CKEDITOR.config.autosave*1000);
    };

    
messageEditor.prototype = {
        
setupsetup,
        
editoridnull,
        
editornull,
        
baseURLnull,
        
textareanull,
        
stylesheetstylesheet,
        
bindSmilieInserterbindSmilieInserter,
        
performInsertperformInsert,
        
InsertInsert,
        
execCommandexecCommand,
        
openGetMoreSmiliesopenGetMoreSmilies,
        
insertSmilieinsertSmilie,
        
editor_autosaveeditor_autosave
    
};
    
    return 
messageEditor;
})();

if(
typeof Thread != 'undefined')
{
    
Thread.multiQuotedLoaded = function(request)
    {
        var 
json = $.parseJSON(request.responseText);
        if(
typeof json == 'object')
        {
            if(
json.hasOwnProperty("errors"))
            {
                $.
each(json.errors, function(imessage)
                {
                    $.
jGrowl(lang.post_fetch_error ' ' message);
                });
                return 
false;
            }
        }

        if(
typeof clickableEditor != 'undefined')
        {
            var 
id clickableEditor.editor;
            
value id.getData();
            if(
value)
            {
                
value += "\n";
            }
            
value += json.message;
            
id.setData(value);
            
id.focus();
        }
        else if(
typeof $('textarea').sceditor != 'undefined')
        {
            $(
'textarea').sceditor('instance').insert(json.message);
        }
        else
        {
            var 
id = $('#message');
            if(
id.value)
            {
                
id.value += "\n";
            }
            
id.val(id.val() + json.message);
        }

        
Thread.clearMultiQuoted();
        $(
'#quickreply_multiquote').hide();
        $(
'#quoted_ids').val('all');

        $(
'#message').focus();
    };
    
    
Thread.quickReplyDone = function(requeststatus)
    {
        
this.quick_replying 0;

        var 
json = $.parseJSON(request.responseText);
        if(
typeof json == 'object')
        {
            if(
json.hasOwnProperty("errors"))
            {
                $(
".jGrowl").jGrowl("close");

                $.
each(json.errors, function(imessage)
                {
                    $.
jGrowl(lang.quick_reply_post_error ' ' message);
                });
            }
        }

        if($(
'#captcha_trow'))
        {
            
cap json.data.match(/^<captcha>([0-9a-zA-Z]+)(\|([0-9a-zA-Z]+)|)<\/captcha>/);
            if(
cap)
            {
                
json.data json.data.replace(/^<captcha>(.*)<\/captcha>/, '');

                if(
cap[1] == "reload")
                {
                    
Recaptcha.reload();
                }
                else if($(
"#captcha_img"))
                {
                    if(
cap[1])
                    {
                        
imghash cap[1];
                        $(
'#imagehash').val(imghash);
                        if(
cap[3])
                        {
                            $(
'#imagestring').attr('type''hidden').val(cap[3]);
                            
// hide the captcha
                            
$('#captcha_trow').css('display''none');
                        }
                        else
                        {
                            $(
'#captcha_img').attr('src'"captcha.php?action=regimage&imagehash="+imghash);
                            $(
'#imagestring').attr('type''text').val('');
                            $(
'#captcha_trow').css('display''');
                        }
                    }
                }
            }
        }
        
        if(
json.hasOwnProperty("errors"))
            return 
false;

        if(
json.data.match(/id="post_([0-9]+)"/))
        {
            var 
pid json.data.match(/id="post_([0-9]+)"/)[1];
            var 
post document.createElement("div");

            $(
'#posts').append(json.data);
            
            if (
typeof inlineModeration != "undefined"// Guests don't have this object defined
                
$("#inlinemod_" pid).on('change'inlineModeration.checkItem);
                
            
Thread.quickEdit("#pid_" pid);

            
/*if(MyBB.browser == "ie" || MyBB.browser == "opera" || MyBB.browser == "safari" || MyBB.browser == "chrome")
            {*/
                // Eval javascript
                
$(json.data).filter("script").each(function(e) {
                    eval($(
this).text());
                });
            
//}

            
$('#quick_reply_form')[0].reset();
            if(
typeof clickableEditor != 'undefined')
            {
                
clickableEditor.editor.setData('');
            }

            var 
lastpid = $('#lastpid');
            if(
lastpid)
            {
                
lastpid.val(pid);
            }
        }
        else
        {
            
// Eval javascript
            
$(json.data).filter("script").each(function(e) {
                eval($(
this).text());
            });
        }

        $(
".jGrowl").jGrowl("close");
    };
    
    
Thread.quickEdit = function(el)
    {
        if(!
elel '.post_body';

        $(
el).each(function()
        {
            
// Take pid out of the id attribute
            
id = $(this).attr('id');
            
pid id.replace( /[^\d.]/g'');

            $(
'#pid_' pid).editable("xmlhttp.php?action=edit_post&do=update_post&pid=" pid '&my_post_key=' my_post_key,
            {
                
indicatorspinner,
                
loadurl"xmlhttp.php?action=edit_post&do=get_post&pid=" pid,
                
type"textarea",
                
rows12,
                
submitlang.save_changes,
                
cancellang.cancel_edit,
                
event"edit" pid// Triggered by the event "edit_[pid]",
                
onblur"ignore",
                
dataType"json",
                
submitdata: function (valuessettings)
                {
                    
id = $(this).attr('id');
                    
pid id.replace( /[^\d.]/g'');
                    if(
typeof CKEDITOR != 'undefined')
                    {
                        
values CKEDITOR.instances['quickedit_' pid].getData();
                    }
                    return {
                        
editreason: $("#quickedit_" pid "_editreason").val(),
                        
valuevalues
                    
}
                },
                
callback: function(valuessettings)
                {
                    
id = $(this).attr('id');
                    
pid id.replace( /[^\d.]/g'');
                    
                    var 
json = $.parseJSON(values);
                    if(
typeof json == 'object')
                    {
                        if(
json.hasOwnProperty("errors"))
                        {
                            $(
".jGrowl").jGrowl("close");

                            $.
each(json.errors, function(imessage)
                            {
                                $.
jGrowl(lang.quick_edit_update_error ' ' message);
                            });
                            $(
this).html($('#pid_' pid '_temp').html());
                        }
                        else if(
json.hasOwnProperty("moderation_post"))
                        {
                            $(
".jGrowl").jGrowl("close");

                            $(
this).html(json.message);

                            
// No more posts on this page? (testing for "1" as the last post would be removed here)
                            
if($('.post').length == 1)
                            {
                                
alert(json.moderation_post);
                                
window.location json.url;
                            }
                            else
                            {
                                $.
jGrowl(json.moderation_post);
                                $(
'#post_' pid).slideToggle();
                            }
                        }
                        else if(
json.hasOwnProperty("moderation_thread"))
                        {
                            $(
".jGrowl").jGrowl("close");

                            $(
this).html(json.message);
                            
                            
alert(json.moderation_thread);
                            
                            
// Redirect user to forum
                            
window.location json.url;
                        }    
                        else
                        {
                            
// Change html content
                            
$(this).html(json.message);
                            $(
'#edited_by_' pid).html(json.editedmsg);
                        }
                    }
                    else
                    {
                        
// Change html content
                        
$(this).html(json.message);
                        $(
'#edited_by_' pid).html(json.editedmsg);
                    }
                    $(
'#pid_' pid '_temp').remove();
                }
            });
        });

        $(
'.quick_edit_button').each(function()
        {
            $(
this).bind("click", function(e)
            {
                
e.preventDefault();

                
// Take pid out of the id attribute
                
id = $(this).attr('id');
                
pid id.replace( /[^\d.]/g'');

                
// Create a copy of the post
                
if($('#pid_' pid '_temp').length == 0)
                {
                    $(
'#pid_' pid).clone().attr('id','pid_' pid '_temp').css('display','none').appendTo("body");
                }

                
// Trigger the edit event
                
$('#pid_' pid).trigger("edit" pid);

                
// Edit Reason
                
$('#pid_' pid ' textarea').attr('id''quickedit_' pid);
                if(
allowEditReason == && $('#quickedit_' pid '_editreason').length == 0)
                {
                    $(
'#quickedit_' pid).after('<label for="editreason">' lang.editreason ':</label> <input type="text" class="textbox" style="margin: 6px 0;" name="editreason" size="40" maxlength="150" id="quickedit_' pid '_editreason" /><br />');
                }
                if(
typeof opt_editor == 'object')
                {
                    var 
qucikeditor CKEDITOR.replace('quickedit_' pidopt_editor);
                    
qucikeditor.updatePreview = function(e) {
                        var 
consoleEl CKEDITOR.document.getByIde.editor.name );
                        
consoleEl.addClass'updated' );
                        
setTimeout( function() { consoleEl.removeClass'updated' ); }, 500 );
                        
// IE needs <br>, it doesn't even understand new lines.
                        
consoleEl.setHtmle.editor.getData());
                    };

                    
qucikeditor.checkUpdatePreview = function(e) {
                        
setTimeout( function() {
                            if ( 
e.editor.checkDirty() ) {
                                
qucikeditor.updatePreview(e);
                                
e.editor.resetDirty();
                            }
                        }, 
);
                    };

                    
qucikeditor.on'instanceReady'qucikeditor.updatePreview );
                    
qucikeditor.on'key'qucikeditor.checkUpdatePreview );
                    
qucikeditor.on'selectionChange'qucikeditor.checkUpdatePreview );
                }
            });
        });

        return 
false;
    };