J

add_stylesheet로 추가한 스타일 제거하기 함수 추가

제가 작업하던중에 head를 공통으로 쓰다가

어떤 페이지에서는 스타일이 중복되어서 head에 추가된 스타일을 빼야 되는 경우가 생겼습니다.

그래서 수정해봤습니다.

/lib/common.lib.php 수정해주셔야 합니다.

 

"class html_process"

이걸 찾으셔서 위쪽에 추가해 줍니다. 아마 2493줄에 있을꺼예요.

 

function del_stylesheet($stylesheet)
{
    global $html_process;

    if(trim($stylesheet) && method_exists($html_process, 'split_stylesheet') )
        $html_process->split_stylesheet($stylesheet);
}

 

class html_process 안에

 

function split_stylesheet($stylesheet) {
        $links = $this->css;
        $has_item = false;

        for($i=0;$i<count($links);$i++) {
            $link = $links[$i];
            if($link[1] == $stylesheet) {
                $has_item = true;
                break;
            }
        }

        if($has_item)
            array_splice($this->css, $i,1);
}

를 추가해 줍니다.

 

================================================

function del_stylesheet($stylesheet)
{
    global $html_process;

    if(trim($stylesheet) && method_exists($html_process, 'split_stylesheet') )
        $html_process->split_stylesheet($stylesheet);
}

class html_process {
    protected $css = array();
    protected $js  = array();

    ......

    function split_stylesheet($stylesheet) {
        $links = $this->css;
        $has_item = false;

        for($i=0;$i<count($links);$i++) {
            $link = $links[$i];
            if($link[1] == $stylesheet) {
                $has_item = true;
                break;
            }
        }

        if($has_item)
            array_splice($this->css, $i,1);
    }

    ......

}

============================================

이런 모양이 될 것 같습니다.

 

사용법은

del_stylesheet('<link rel="stylesheet" href="'.G5_URL.'/adm/css/admin.css">');

 

본인이 add_stylesheet로 추가했던 내용 그대로 입력하시면 됩니다.

 

|

댓글 5개

선추 후 댓글...
좋은 팁 감사합니다.
오우 감사합니다
추천드려요. 감사해요.
좋은팁 감사합니다.
댓글을 작성하시려면 로그인이 필요합니다.

그누보드5 팁자료실

+
제목 글쓴이 날짜 조회
5년 전 조회 5,545
5년 전 조회 6,371
5년 전 조회 4,191
5년 전 조회 2,689
5년 전 조회 3,490
5년 전 조회 4,579
5년 전 조회 3,905
5년 전 조회 3,786
5년 전 조회 2,998
5년 전 조회 4,238
5년 전 조회 4,707
5년 전 조회 1.3만
5년 전 조회 4,220
5년 전 조회 3,559
5년 전 조회 4,122
5년 전 조회 5,716
5년 전 조회 6,022
5년 전 조회 3,566
5년 전 조회 1만
5년 전 조회 3,572
5년 전 조회 4,478
5년 전 조회 3,997
5년 전 조회 5,008
5년 전 조회 4,197
5년 전 조회 3,636
5년 전 조회 6,544
5년 전 조회 5,190
5년 전 조회 4,229
5년 전 조회 3,739
5년 전 조회 3,548