drooh drooh - 3 months ago 18
Javascript Question

How to use jQuery to load codepress

I am using codepress in a CMS to edit files in the filesystem. Everything works nicely, however when trying to load the same page using jQuery load() function, codepress seems to break.

My javascript code looks like this which loads the php file with codpress, however codepress seems to not fire.

$('.content').on('click', '#fileSystemWrap a', function (event) {
event.preventDefault();
var fileName = $(this).data('file');
$('#rightColWrap').fadeOut(150, function(){
$('#rightColWrap').load('/?url=developer/edit-file.php&open=' + fileName, function(){
$('#rightColWrap').fadeIn(150);
});
});
});


Digging into codepress.js I see this at the end of the file but I'm not understanding if there is something I could add to my initial on click event listner script to help codpress fire.

if(window.attachEvent) window.attachEvent('onload',CodePress.run);
else window.addEventListener('DOMContentLoaded',CodePress.run,false);


Here is the link to codepress on sourceforge
https://sourceforge.net/projects/codepress/

Answer

The answer was that we needed to add parentheses to CodePress.run and after the fadeIn() call.

$('#content').on('click', '#fileSystemWrap a', function (event) {
    event.preventDefault();
    var fileName = $(this).data('file');
    $('#content').fadeOut(150, function(){
        $('#content').load('/?url=developer/edit-file.php&open=' + fileName, function(){
            $('#content').fadeIn(150, function(){
                CodePress.run();
            });
        });
    });
});
Comments