Quantcast
Channel: How can I store user feedback related to any part of a web page? - Stack Overflow
Viewing all articles
Browse latest Browse all 7

Answer by meouw for How can I store user feedback related to any part of a web page?

$
0
0

You could do something like this:

The blocks that you would like to be commented on have a class of 'commentable' and have an id.
The script below is an outline that works for W3C compliant browsers, ie would need to use attachEvent and the global event object.
Propagation of the event is not cancelled so commentable blocks within commentable blocks would would fire the event once each.
The default action of the event is alse not cancelled, so text that is double clicked on will still be highlighted - perhaps your dialog could have a 'click escape to cancel' action?

function CommentDialog() {
    //this is a fake CommentDialog object constructor
    this.display = function( id ) {
        alert( 'you want to comment on the block with id: '+id+', which is outlined in red' );
    } 
}



window.addEventListener( 'dblclick', function(e){ 
    var target = e.target;
    while( /commentable/.test( target.className ) == false ) {
        // if we've hit the body tag then bomb out
        if( target == document.body ) {
            return;
        }
        target = target.parentNode;
    }
    target.style.border = '1px solid red';
    var cmt = new CommentDialog();
    cmt.display( target.id );
 }, false );

Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>