Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Popups having texteditor feature not working in jquery

I'm trying to develop a code in which I've content editable items in the different tag once these contents are hovered it displays the border of the tag and when clicked inside the border box it becomes editable and button is displayed adjacent to the border, when button is clicked a pop up box is displayed used to format the edits like text editor. Now the problem I'm facing is with the popups which is not coming up accordingly. I'm taking the mouse position too to get the X and Y axis so that button displays at the click location, where is should be placed above the border.

Code is as below:

JQuery Function:

$(function() { // DOM loaded    
  $('[data-nitspagelabel]').hover(function(){
      $(this).css('border', 'solid 1px #777');

  }, function(){
     $(this).css('border','none');
 });
 $('[data-nitspagelabel]').click(function(){
   $(this).attr('contenteditable','true');
   var mouseX;
   var mouseY;
   var modal = false;
   $(document).mousemove(function(f){
       mouseX = f.pageX;
       mouseY = f.pageY;
    });

   var openPopup = function(e) { // Function to open the popup
            $(e).fadeIn(400);
            $('#mask, .nitstextpopup').fadeIn(400).css({'top':mouseY, 'left':mouseX}).draggable({ containment: 'body' });
            $('#mask').css({'top': 0, 'left': 0});
            $('#nitstextbutton').hide();
        };    

    var closePopup = function() { // Function to close the popup
            $('#mask, .nitstextpopup').fadeOut(400);
            $('#nitstextbutton').show();
    };
   $('[data-nitspagelabel]').click(function(e){
       if (modal == false){
           modal = true;

            $('#nitstextbutton').css({'top':mouseY, 'left':mouseX}).fadeIn(400).click(function(e){
            e.preventDefault();
            var popupbox = $(this).attr('href');
            openPopup(popupbox);
           });
        }
   });
   $('#mask').on('click', function(e) {
        e.stopPropagation();
            closePopup();
       modal = false;
       $('#nitstextbutton').hide();
   });

        $(document).keyup(function(e) {
            if (e.keyCode == 27) {
                closePopup();
                modal = false;
                $('#nitstextbutton').hide();
            }
        });    
  });
});