Skip to content

Mini Help System with jQuery

Tip 조회 수 5611 추천 수 0 2013.01.23 15:10:56

a1.jpg

index.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>Mini Help System with jQuery | Tutorialzine </title>

        <!-- Our stylesheet -->
        <link rel="stylesheet" href="assets/css/styles.css" />

    </head>
    <body>

        <div id="widget">

            <div id="header">
                <input type="text" id="search" placeholder="Search in the text" />
            </div>

            <div id="content">
                <!-- Your help text goes here -->
            </div>
        </div>​​

        <!-- JavaScript Includes -->
        <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
        <script src="assets/js/highlight.jquery.js"></script>
        <script src="assets/js/jquery.scrollTo.min.js"></script>
        <script src="assets/js/script.js"></script>
    </body>
</html>


assets/js/highlight.jquery.js

(function($) {

    var termPattern;

    $.fn.highlight = function(term, callback) {

        return this.each(function() {

            var elem = $(this);

            if (!elem.data('highlight-original')) {

                // Save the original element content
                elem.data('highlight-original', elem.html());

            } else {

                // restore the original content
                elem.highlightRestore();

            }

            termPattern = new RegExp('(' + term + ')', 'ig');

            // Search the element's contents
            walk(elem);

            // Trigger the callback
            callback && callback(elem.find('.match'));

        });
    };

    $.fn.highlightRestore = function() {

        return this.each(function() {
            var elem = $(this);
            elem.html(elem.data('highlight-original'));
        });

    };

    function walk(elem) {

        elem.contents().each(function() {

            if (this.nodeType == 3) { // text node

                if (termPattern.test(this.nodeValue)) {
                    // wrap the match in a span:
                    $(this).replaceWith(this.nodeValue.replace(termPattern, '<span class="match">$1</span>'));
                }
            } else {
                // recursively call the function on this element
                walk($(this));
            }
        });
    }

})(jQuery);



assets/js/script.js

$(function() {

    var search = $('#search'),
        content = $('#content'),
        matches = $(), index = 0;

    // Listen for the text input event
    search.on('input', function(e) {

        // Only search for strings 2 characters or more
        if (search.val().length >= 2) {

            // Use the highlight plugin
            content.highlight(search.val(), function(found) {

                matches = found;

                if(matches.length && content.is(':not(:animated)')){
                    scroll(0);
                }

            });
        } else {
            content.highlightRestore();
        }

    });

    search.on('keypress', function(e) {

        if(e.keyCode == 13){ // The enter key
            scrollNext();
        }

    });

    function scroll(i){
        index = i;

        // Trigger the scrollTo plugin. Limit it
        // to the y axis (vertical scroll only)
        content.scrollTo(matches.eq(i), 800, { axis:'y' } );
    }

    function scrollNext(){
        matches.length && scroll( (index + 1) % matches.length );
    }
});



profile

I see no changes, wake up in the morning and I ask myself

Is life worth living should I blast myself

Things would never be the same.

첨부
엮인글 :
http://adminplay.com/169206/dd1/trackback

l2zeo님은 글작성 및 댓글 포인트 ...

2013.01.23 15:10:56
*.52.33.196

l2zeo님은 50포인트에 당첨되셨습니다.
List of Articles
번호 제목 글쓴이 날짜 조회 수sort
47 Tip 모바일에서도 이미지 리사이징 기능 적용하기 l2zeo 2013-01-24 51266
46 Tip 그누보드4(G4) 변수들 l2zeo 2013-01-22 48999
45 플러그인 게시판의 정렬을 이용한 최신글 file ADMINPLAY 2012-01-16 28515
44 플러그인 코멘트 Ajax 처리 - 아직도 코멘트(댓글)쓰고 전체 페이지 로딩되나요? ADMINPLAY 2012-01-16 16636
43 Tip 그누보드 메타태그(description, keywords) 설정 file [1] ADMINPLAY 2012-01-16 15397
42 Tip IE css핵 (css hack)과 IE filter file [1] l2zeo 2013-07-03 14542
41 플러그인 그누보드 내글 모니터 (쿠키 및 구글 스타일 변환) file ADMINPLAY 2012-01-16 13178
40 플러그인 네이버 스타일 아웃로그인 스킨(?) file ADMINPLAY 2012-01-16 11837
39 Tip SSL 보안인증 로그인,회원가입 적용하기 [1] l2zeo 2012-08-15 11800
38 플러그인 게시물 순위를 이전과 비교해서 등수 출력 file ADMINPLAY 2012-01-16 11496
37 Tip 그누보드 팁. $wr_id 값을 사용하지 않습니다_라고 뜰때 해결방법 1 (그누보드 관련 게시판이 있다면....) ADMINPLAY 2012-01-16 11362
36 Tip 공지사항 리스트에 이중 출력 안되도록. ADMINPLAY 2012-01-16 10403
35 Tip [Lazy Load Plugin for jQuery] 효율적인 이미지 로딩 file l2zeo 2013-01-23 10217
34 Tip 오늘의 주인공 onfocus="this.blur();"와 a:visited를 소개합니다. ADMINPLAY 2012-01-16 9991
33 Tip 페이스북 담벼락에 자동 게시하는 법 l2zeo 2013-01-23 9614
32 Tip 그누보드 회원 포인트 일괄삭제 하기 (mb_point + 포인트 내역) ADMINPLAY 2012-01-16 9585
31 Tip robots.txt 관련 Tip. l2zeo 2013-05-30 9507
30 Tip 포인트가 마이너스일때 = 포인트 마이너스 회원들 포인트를 0으로 ... l2zeo 2013-03-15 9504
29 Tip 출석시 과거 특정날짜 자동출석 인정하는 방법 - 미션출석부 l2zeo 2012-03-12 9322
28 최적화 그누보드에서 효율적으로 디비에 쿼리수 줄이기 ADMINPLAY 2012-01-16 9004

Copyright ADMINPLAY corp. All rights reserved.

abcXYZ, 세종대왕,1234

abcXYZ, 세종대왕,1234