[에디터] CKeditor4.x 에디터 툴바 고정하기

페이지 정보

yadolee 루루아빠 3,965 1 2016.05.24 01:32:05

평점

  • 평점 : 0점 (0명 참여)

본문

CKeditor4.x 에디터 사용시 본문이 길 경우 툴바 메뉴를 사용하기 위해 마우스 휠을 사용해야 하는 수고스러움이 있다.
그 수고스러움을 덜어보자

1. 그누보드5/plugin/CKeditor4.x/config.js 를 열어 소스 가장 하단 }; 바로 위쪽에 다음 소스를 추가한다.

window.CKEDITOR.on('instanceReady', function () {
    var toolbar = document.getElementsByClassName('cke_top').item(0),
                  boxTop = toolbar.getBoundingClientRect().top,
                  offsetTop = 45; // toolbar offset top

    window.addEventListener('scroll', function () {
        window.requestAnimationFrame(function () {
            var scrollTop =document.body.scrollTop;
            if ((scrollTop + offsetTop) > boxTop) {
                toolbar.style.top = scrollTop + offsetTop - boxTop + 'px';
            } else {
                toolbar.style.top = 0;
            }
        });
    }, false);
});
2. 동일 폴더 contents.css 를 열어 다음 스타일을 추가한다.


.cke_top {
    position: relative;
    top: 0;
    left: 0;
    right: 0;
    will-change: top;
}

추천인
  • 추천해 주세요
yadolee
6
루루아빠 - 회원등급 : 최고관리자 - 포인트 : 1,333,250
레벨 100
경험치 1,489,406

Progress Bar 14.69%

- 가입일 : 2015-03-04 03:24:54
- 서명 : KNOW YOUR LIMITS BUT NEVER STOP TRYING TO EXCEED THEM !!
- 자기소개 : 루루의 자랑 루루아빠랍니다~~

댓글1

루루아빠님의 댓글

yadolee
루루아빠 글쓴이 2016.06.01 01:35
상기 소스를 이용하는 것보다 플러그인을 활용하는 게 더 효과적이였다. http://ckeditor.com/addon/fixed 상기 애드온을 다운 받아 소스를 plugin.js 를 아래 소스롤 덮어 씌워 사용하자



CKEDITOR.plugins.add( 'fixed', {
    init: function( editor ) {
      editor.on('instanceReady', function (readyEvent) {
        if (CKEDITOR.toolbarFixer == undefined) {      // To prevent double activation - event listener and its handler should be set only once
          CKEDITOR.toolbarFixer = function toolbarFixerF(event) {
            for(var i=0; i document.body.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;

              toolbar.style.width = content.offsetWidth + "px";
              toolbar.style.top = "0px";
              toolbar.style.left = "0px";
              toolbar.style.right = "0px";
              toolbar.style.margin = "0 auto";
              toolbar.style.boxSizing = "border-box";

              if (editor.offsetTop <= scrollvalue && (editor.offsetTop + editor.offsetHeight) > (scrollvalue + toolbar.offsetHeight + 100)) {
                toolbar.style.position = "fixed";
                content.style.marginTop = toolbar.offsetHeight + "px";
              } else {
                toolbar.style.position = "relative";
                content.style.marginTop = "0px";
              }
            }
          };
          CKEDITOR.toolbarFixer.ckeRootNodes = [];
          window.addEventListener('scroll', CKEDITOR.toolbarFixer, false);
        }
        CKEDITOR.toolbarFixer.ckeRootNodes.push(readyEvent.editor.container.$);
        readyEvent.editor.container.$.getElementsByClassName('cke_top').item(0).style.zIndex = 100;    // For codemirror plugin compatibility
      });
    }
});

Total 7621526 페이지

제목 글쓴이 날짜 조회 추천
이윰  🏆 Eyoom Builder 3.0.6 패치 shadow2fox 2018.09.18 2,710 0
제로  댓글+1🏆 서버OS가 WindowsNT일경우 가입폼에서 메일체크 에러방지 루루아빠 2005.07.07 2,708 0
제로  🏆 태그 사용 체크 후 "취소" 하면 자동으로 체크 해제 루루아빠 2005.07.05 2,708 0
이윰  🏆 Eyoom Builder 1.3.15 패치 루루아빠 2018.01.05 2,706 0
이윰  🏆 이윰빌더 외부이미지 로컬 저장시 용량 줄이기 루루아빠 2017.11.23 2,705 0
그누•영카트  🏆 그누보드 5.2.9.3 패치 루루아빠 2017.09.14 2,695 0
그누•영카트  🏆 🎞️ 영카트 5.1.6 패치 루루아빠 2015.11.17 2,694 0
그누•영카트  🏆 영카트 5.1.16 패치 루루아빠 2016.04.23 2,690 0
그누•영카트  🏆 그누보드 5.3.1.3 패치 루루아빠 2018.05.29 2,684 0
그누•영카트  🏆 그누보드 5.1.18 패치 루루아빠 2016.05.17 2,680 0
그누•영카트  🏆 그누보드 5.2.9.8.3 패치 루루아빠 2018.03.22 2,678 0
그누•영카트  🏆 그누보드 5.1.1 패치 루루아빠 2015.08.28 2,678 0
그누•영카트  🏆 영카트 5.2.9.8.4 패치 루루아빠 2018.03.30 2,676 0
이윰  🏆 Eyoom Builder 1.3.4 패치 루루아빠 2017.11.21 2,666 0
그누•영카트  🏆 영카트 5.2.9.7 패치 루루아빠 2017.12.16 2,665 0
제로  🏆 검색 버그 고치기 루루아빠 2005.07.08 2,661 0
그누•영카트  🏆 그누보드 5.2.1 패치 루루아빠 2016.08.22 2,660 0
이윰  🏆 게시판 관리자의 레벨이 글쓰기 권한보다 낮더라도 태그 작성하기 루루아빠 2017.05.03 2,655 0
이윰  🏆 최신글 카테고리 추출 옵션 루루아빠 2016.02.25 2,654 0
그누•영카트  🏆 영카트 5.3.1.2 보안 패치 루루아빠 2018.04.21 2,653 0
이윰  🏆 전체검색 리스트 페이지에서 동영상 썸네일 이미지도 사용하기 루루아빠 2018.05.04 2,650 0
이윰  🏆 Eyoom Builder 3.0.3 - 패치에 문제가 있는 버전입니다. shadow2fox 2018.08.20 2,646 0
이윰  🏆 🎞️ 게시글 본문에 동영상(HTML5)이 있을 시 아이콘 보여주기 루루아빠 2018.01.29 2,644 0
CSS  🏆 div 클래스에 :last-child css 스타일 적용하기 루루아빠 2016.03.15 2,644 0
이윰  🏆 Eyoom Builder 1.3.6 패치 루루아빠 2017.11.21 2,643 0
그누•영카트  댓글+1🏆 그누보드 5.4.2.3 shadow2fox 2020.03.14 2,641 1
그누•영카트  댓글+2🏆 그누보드 5.4.2.9 shadow2fox 2020.10.08 2,640 2
그누•영카트  댓글+1🏆 그누보드 5.4.2.7 shadow2fox 2020.06.12 2,631 1
그누•영카트  🏆 인기검색어 갯수와 일자 수정하기 루루아빠 2015.08.24 2,631 0
그누•영카트  🏆 그누보드 5.1.4 패치 (2015.10.26) 루루아빠 2015.11.09 2,627 0