Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I may have found a solution to your problem. It's not the cleanest solution but it works. I had to use mouse position to track where the click came from bc the <code>focusout</code> event fires before the click and there was no way to tell where the click came from other than mouse location.</p> <p>The part that isn't so 'clean' is the if statement i had to use to check if the click was within the confines of the toolbar. Maybe you can figure out a better way of checking that.</p> <p>JS:</p> <pre><code>var mousePos; var hasFocus = false;//This is used to prevent the window.click from firing after a focus event jQuery(document).ready(function(){ $(document).mousemove(function(e){ mousePos = e; }); }); $(".comment-box").keydown(function () { var parent = $(this).parent(); var text_max = 140; var length_reached = $(this).val().length; var remaining = text_max - length_reached; $(parent).find('.counter').html(remaining); if (remaining &lt; 5 || remaining &gt;= text_max) $(parent).find(".btn").prop("disabled", true); else $(parent).find(".btn").prop("disabled", false); }); $(".comment-box").focus(function(e){ var parent = $(this).parent(); $('#' + this.id).css({ 'height' : '80px' }); $(parent).find('.comment-toolbar').css({ 'visibility' : 'visible'}); hasFocus = true; }); $('.comment-box').focusout(function(e){ var parent = $(this).parent(); var toolbox = $(parent).find('.comment-toolbar'); var offset = $(toolbox).offset(); //Check if click occured within toolbar if(mousePos.pageX &gt;= offset.left &amp;&amp; mousePos.pageY &gt;= offset.top &amp;&amp; mousePos.pageX &lt;= (offset.left + $(toolbox).width()) &amp;&amp; mousePos.pageY &lt;= (offset.top + $(toolbox).height())) { } else if($(this).val().length &gt; 0){ } else{ $('#' + this.id).css({ 'height' : '19px' }); $(parent).find('.comment-toolbar').css({ 'visibility' : 'hidden' }); } hasFocus = false; }); $(window).click(function(){ console.log('window click'); if(!hasFocus) { for(var i=0;$('.comment-box').length;i++) { var commentbox = $('.comment-box')[i]; var toolbox = $('.comment-toolbar')[i]; var offset = $(toolbox).offset(); if(mousePos.pageX &gt;= offset.left &amp;&amp; mousePos.pageY &gt;= offset.top &amp;&amp; mousePos.pageX &lt;= (offset.left + $(toolbox).width()) &amp;&amp; mousePos.pageY &lt;= (offset.top + $(toolbox).height())) { return false; } else if($(commentbox).val().length &gt; 0){ } else{ $(commentbox).css({ 'height' : '19px' }); $(toolbox).css({ 'visibility' : 'hidden' }); } } } }); </code></pre> <p>I had to make a minor CSS change bc the toolbar was getting a weird positioning after the first focusout.</p> <p>CSS:</p> <pre><code>.comment-toolbar{ margin-top: 10px; display: block; border: 1px solid red; width: 420px; height: 45px; float: right; visibility: hidden;/* Use visibility instead of display to show/hide toolbar */ } </code></pre> <p><a href="http://jsfiddle.net/ExceptionLimeCat/Gx3tV/" rel="nofollow">http://jsfiddle.net/ExceptionLimeCat/Gx3tV/</a></p> <p>Hopefully that helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload