source: js/viewer-f0/js/library/jquery.comment.js

Last change on this file was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1// This jQuery plugin will gather the comments within
2// the current jQuery collection, returning all the
3// comments in a new jQuery collection.
4//
5// NOTE: Comments are wrapped in DIV tags.
6
7jQuery.fn.comments = function( blnDeep ){
8    var blnDeep = (blnDeep || false);
9    var jComments = $( [] );
10
11    // Loop over each node to search its children for
12    // comment nodes and element nodes (if deep search).
13    this.each(
14        function( intI, objNode ){
15            var objChildNode = objNode.firstChild;
16            var strParentID = $( this ).attr( "id" );
17
18            // Keep looping over the top-level children
19            // while we have a node to examine.
20            while (objChildNode){
21
22                // Check to see if this node is a comment.
23                if (objChildNode.nodeType === 8){
24
25                    // We found a comment node. Add it to
26                    // the nodes collection wrapped in a
27                    // DIV (as we may have HTML).
28                    jComments = jComments.add(
29                        "<div rel='" + strParentID + "'>" +
30                            objChildNode.nodeValue +
31                            "</div>"
32                    );
33
34                } else if (
35                    blnDeep &&
36                        (objChildNode.nodeType === 1)
37                    ) {
38
39                    // Traverse this node deeply.
40                    jComments = jComments.add(
41                        $( objChildNode ).comments( true )
42                    );
43
44                }
45
46                // Move to the next sibling.
47                objChildNode = objChildNode.nextSibling;
48
49            }
50
51        }
52    );
53
54    // Return the jQuery comments collection.
55    return( jComments );
56}
Note: See TracBrowser for help on using the repository browser.