Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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();
            }
        });    
  });
});