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

페이지 정보

yadolee 루루아빠 3,948 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,332,705
레벨 100
경험치 1,488,154

Progress Bar 10.52%

- 가입일 : 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 7622239 페이지

제목 글쓴이 날짜 조회 추천
기타  🏆 Font Awesome 4.7.0 - Transportation, Gender, Medical, Currency, Payment, Brand 루루아빠 2017.11.20 5,026 0
이윰  🏆 📸 Eyoom Builder 1.3.0 시즌3 루루아빠 2017.11.21 3,100 0
이윰  🏆 Eyoom Builder 1.3.1 패치 루루아빠 2017.11.21 2,408 0
이윰  🏆 Eyoom Builder 1.3.2 패치 루루아빠 2017.11.21 2,752 0
이윰  🏆 Eyoom Builder 1.3.3 패치 루루아빠 2017.11.21 2,498 0
이윰  🏆 Eyoom Builder 1.3.4 패치 루루아빠 2017.11.21 2,660 0
이윰  🏆 Eyoom Builder 1.3.5 패치 루루아빠 2017.11.21 3,267 0
이윰  🏆 Eyoom Builder 1.3.6 패치 루루아빠 2017.11.21 2,630 0
이윰  🏆 Eyoom Builder 1.3.7 패치 루루아빠 2017.11.21 3,018 0
이윰  🏆 Eyoom Builder 1.3.8 패치 루루아빠 2017.11.21 2,802 0
이윰  🏆 Eyoom Builder 1.3.9 패치 루루아빠 2017.11.21 2,617 0
이윰  🏆 Eyoom Builder 1.3.10 패치 루루아빠 2017.11.21 2,604 0
이윰  🏆 Eyoom Builder 1.3.11 패치 루루아빠 2017.11.21 2,851 0
이윰  🏆 Eyoom Builder 1.3.12 패치 루루아빠 2017.11.21 3,101 0
이윰  🏆 Eyoom Builder 1.3.13 패치 루루아빠 2017.11.21 2,734 0
그누•영카트  🏆 그누보드 5.2.9.6 패치 루루아빠 2017.11.21 2,775 0
그누•영카트  🏆 영카트 5.2.9.6 패치 루루아빠 2017.11.21 3,183 0
이윰  🏆 이윰빌더 외부이미지 로컬 저장 https 보안서버도 적용하기 루루아빠 2017.11.22 2,896 0
이윰  🏆 이윰빌더 외부이미지 로컬 저장시 용량 줄이기 루루아빠 2017.11.23 2,680 0
이윰  🏆 이윰빌더 출석부 PHP 7.1.x에서 오류 해결하기 루루아빠 2017.11.24 3,036 0