Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/

like image 662
drooh Avatar asked Aug 04 '16 02:08

drooh


1 Answers

To be logic : when the data are loaded, we want to initialize CodePress. So your code should look like :

$('.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(){
            CodePress.run();
            $('#rightColWrap').fadeIn(150);
        });
    });
});

If this didn't work please provide error from the console.

Edit : corrected answer, seen Robson França's comment. Last issue was that CodePress.run; should have been written CodePress.run();

like image 139
technico Avatar answered Oct 03 '22 07:10

technico