테스트 사이트 - 개발 중인 베타 버전입니다

ajax + froalra (js 로드문제) 채택완료

그레이코드82 1년 전 조회 1,385

</p>

<pre>
(function() {
    var isLoading = false;
    var currentUrl = window.location.pathname;
    var sidebarLoaded = false;
    var sidebarCache = null;

    if (typeof window.input === 'undefined') {
        window.input = {};
    }

    function loadContent(url, isPopState) {
        if (isLoading || currentUrl === url) return;

        isLoading = true;
        currentUrl = url;

        $.ajax({
            url: url,
            type: 'GET',
            cache: true,
            success: function(response) {
                var $html = $('<div>').html(response);
                var $newContent = $html.find('#content');

                if ($newContent.length) {
                    $('#content').html($newContent.html());

                    $html.find('script').each(function() {
                        var scriptSrc = $(this).attr('src');
                        if (scriptSrc && scriptSrc.indexOf('<') === -1) {
                            if (!$('script[src="' + scriptSrc + '"]').length) {
                                $.getScript(scriptSrc).done(function() {
                                    checkAndInitializeFroalaEditor();
                                }).fail(function(jqxhr, settings, exception) {
                                    console.log('Failed to load ' + scriptSrc);
                                });
                            }
                        } else {
                            var scriptContent = $(this).text();
                            if (scriptContent && scriptContent.indexOf('<') === -1) {
                                $.globalEval(scriptContent);
                            }
                        }
                    });

                    initializeContent();

                    if (!sidebarLoaded) {
                        reloadSidebar();
                    }
                } else {
                    $('#content').html('<p>해당 콘텐츠가 존재하지 않습니다.</p>');
                }
            },
            error: function(xhr, status, error) {
                $('#content').html('<p>콘텐츠를 불러오는 중 오류가 발생했습니다.</p>');
            },
            complete: function() {
                isLoading = false;
            }
        });

        if (!isPopState) {
            window.history.pushState(null, '', url);
        }
    }

    function reloadSidebar() {
        if ($('#sidebar').length) {
            if (sidebarCache) {
                $('#sidebar').html(sidebarCache);
            } else {
                $('#sidebar').load(location.href + ' #sidebar > *', function() {
                    sidebarCache = $('#sidebar').html();
                    sidebarLoaded = true;
                });
            }
        }
    }

    function initializeContent() {
        if (typeof viewImageResize === 'function') {
            viewImageResize();
        }

        if (typeof initializeTheme === 'function') {
            initializeTheme();
        }

        $(document).off('click', 'a.ajax-link').on('click', 'a.ajax-link', function(e) {
            e.preventDefault();
            var url = $(this).attr('href');
            sidebarLoaded = false;
            loadContent(url, false);
        });
    }

    function checkAndInitializeFroalaEditor() {
        if (typeof FroalaEditor !== "undefined" && $('#wr_content').length > 0) {
            initializeFroalaEditor();
        } else {
            // 500ms 후 다시 체크
            setTimeout(checkAndInitializeFroalaEditor, 500);
        }
    }

    function initializeFroalaEditor() {
        if (typeof FroalaEditor !== "undefined" && $('#wr_content').length > 0) {
            new FroalaEditor('#wr_content', {
                language: 'ko',
                heightMin: 300,
            });
        } else {
            console.error("FroalaEditor is not defined or element not found.");
        }
    }

    function loadFroalaEditorScripts() {
        // FroalaEditor CSS
        var froalaCssPath = '/plugin/editor/froala_editor_4.2.0/css/froala_editor.pkgd.css';
        if (!$('link[href="' + froalaCssPath + '"]').length) {
            $('<link>', {
                rel: 'stylesheet',
                type: 'text/css',
                href: froalaCssPath
            }).appendTo('head');
        }

        // Froala custom CSS
        var froalaCustomCssPath = '/plugin/editor/froala_editor_4.2.0/css/sir_custom.css';
        if (!$('link[href="' + froalaCustomCssPath + '"]').length) {
            $('<link>', {
                rel: 'stylesheet',
                type: 'text/css',
                href: froalaCustomCssPath
            }).appendTo('head');
        }

        // FroalaEditor JS
        var froalaJsPath = '/plugin/editor/froala_editor_4.2.0/js/froala_editor.pkgd.min.js';
        if (!$('script[src="' + froalaJsPath + '"]').length) {
            $.getScript(froalaJsPath)
                .done(function() {
                    // FroalaEditor 스크립트가 로드된 후 초기화
                    window.addEventListener('DOMContentLoaded', checkAndInitializeFroalaEditor);
                    window.addEventListener('load', checkAndInitializeFroalaEditor);
                })
                .fail(function() {
                    console.error("Failed to load FroalaEditor script.");
                });
        } else {
            // FroalaEditor 스크립트가 이미 로드된 경우
            window.addEventListener('DOMContentLoaded', checkAndInitializeFroalaEditor);
            window.addEventListener('load', checkAndInitializeFroalaEditor);
        }
    }

    $(document).ready(function() {
        loadContent(window.location.pathname, true);
        initializeContent();
        loadFroalaEditorScripts();

        $(window).on('popstate', function() {
            loadContent(location.pathname, true);
        });
    });
})();
</pre>

<p>

 

https://graycode.io/

test / 1234

 

디자인소스 > 게시물을 클릭하면 댓글 에디터가 비정상 적으로 나오는 ㅜㅜ

ajax로 전체 페이지를 그냥 불러오는 방식인데 새로고침이나 직접 주소로 들어가면 오류가 없는데 이게 무슨 조화일까요 ㅜㅜ

아마도 js파일을 제대로 호출을 못해서 그런것 같은데 고수님들의 따끔한 조언을 부탁드립니다 ㅜ

 

진짜 ajax도 아니고 통째로 그냥 불러오는 방식인데도 쉽지가 않네요 ㅜㅜ

댓글을 작성하려면 로그인이 필요합니다.

답변 5개

채택된 답변
+20 포인트
1년 전

데이터를 로드 할 때 키 라이선스를 인식하지 못해서 발생하는 문제입니다.

 

키 값을 재로드 하지 마시고, 상단에 배치 하세요 

 

그러니깐 다시 표현해서 script 자체를 재 로드 하지마시라는 뜻입니다.

 

"프로알라 사용자 + 댓글 에디터 + ajax 댓글 사용자입니다."

 

view.comment.skin.php 파일 상단에 로드 파일을 작성하시면 해결 될껍니다.

 

​​​​​​

 

 

로그인 후 평가할 수 있습니다

답변에 대한 댓글 2개

그레이코드82
1년 전
재로드를 안하면 아예 에디터를 못불러올텐데요 ㅜㅜ
미니님a
1년 전
제가 그렇게 사용중이에요 ^^;;

댓글을 작성하려면 로그인이 필요합니다.

그레이코드82

ㅜㅜ 질문을 전부 그냥 패스하고 링크를 가시는 군요 ㅜ

새로고침을 하면 그냥 정상인 상태인데 ajax로 링크로 이동하면 생기는 버그에 대한 질문입니다 흑흑

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

그레이코드82

원래는 이런 모양입니다. 새로고침을 하면 아마 정상으로 나올거예요ㄷㄷㄷ

내용이 그런 내용입니다 ajax로 링크를 해서 들어간 상태라 이런 문제가 있다는 이야기 입니다 ㅡㅜ

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

미니님a
1년 전
라이센스 때문에 발생하는 문제네요 라이센스 키값 적용하시면 정상적으로 잘 보이네요
(라이센스 부분만 삭제 시 위 이미지대로 보여집니다)

댓글을 작성하려면 로그인이 필요합니다.

1년 전

 

어떤 부분인지요 ?

 

잘 나옵니다.

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

웅푸
1년 전

https://graycode.io/cm_free/1 댓글 잘나오는데요?

로그인 후 평가할 수 있습니다

답변에 대한 댓글 2개

그레이코드82
1년 전
켁 거기는 아예 건들지도 않은 일반 게시판 입니다 ㅜㅜ

디자인소스 > 벡터 게시판을 봐주셔야 합니다 ㅜㅜ
웅프
1년 전
https://sir.kr/g5_skin/49718?sfl=wr_subject&stx=%EC%97%90%EB%94%94%ED%84%B0 //이것참고하세요

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인