Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

JoomlaTune Support Forum    JComments component    Bug-reports    Topic: [solved] I have a patch for 2.3.0
Pages: [1]   Go Down
  Print  
Author Topic: [solved] I have a patch for 2.3.0  (Read 2833 times)
0 Members and 1 Guest are viewing this topic.
kloverde
Newbie
*

Karma: 0
Offline Offline

Gender: Male
Posts: 4


WWW
« on: June 22, 2012, 08:04:40 »

Hi,

First, thank you for creating such a great Joomla extension.  I wanted to let you know that I discovered a couple issues in 2.3.0-stable and wanted to give back to this project by offering a patch.

The first issue is the CSS for ordered and unordered lists doesn't work properly in Chrome.  The line-height of lists is the same as that of a list item.  Firefox and IE adjust as necessary to display multiple items, but Chrome tries to honor the list's line-height, causing line items to be written over top of each other.  I fixed this by adjusting margins and line-height.

The second issue is more of a personal preference, but I believe it affects usability.  Notifications are displayed in a div at the top of the form, which displays for a little while before fading from view.  The issue is if the div is not in the viewable area of the browser window at the time the message displays, the user might never see the message.  I fixed this by jumping to the div when the user clicks the Send button.

The modified files (style.css and jcomments-v2.3.js) are available on my GitHub page:

https://github.com/kloverde/JComments-2.3.0-stable/commits/master

Thanks again for this great extension.
« Last Edit: July 02, 2012, 14:46:52 by smart » Logged
smart
Administrator
Hero Member
*****

Karma: 163
Offline Offline

Gender: Male
Posts: 2161



WWW
« Reply #1 on: June 22, 2012, 13:04:52 »

Thank you! I've applied patch for CSS and this change will be available in update. Regarding second patch... Why message block is not visible when you click Send button? The message's block is inserted into form so there is no too much space between this message and Send button and message should be visible.
Logged

If you use JComments, please post a rating and a review at the Joomla! Extensions Directory
kloverde
Newbie
*

Karma: 0
Offline Offline

Gender: Male
Posts: 4


WWW
« Reply #2 on: June 22, 2012, 14:53:53 »

Regarding the second patch, the message block is only visible if that region of the page is on the user's screen at the time the message displays.  If the user scrolls down too far (or if the user has a lower resolution), placing that region off-screen and then clicks Send, the message will still be written to the page, but the user won't see it.  My change ensures that the message is seen by jumping to the div.
« Last Edit: June 22, 2012, 15:00:49 by kloverde » Logged
smart
Administrator
Hero Member
*****

Karma: 163
Offline Offline

Gender: Male
Posts: 2161



WWW
« Reply #3 on: June 22, 2012, 15:37:56 »

In my mind we have to find more tuned solution and scroll if message is not in visible area only. In other cases page will jump without any real reason. Do you know how to determine in JS if some block in visible area or no? And thank you again - I am really grateful for your suggestions and patch!
Logged

If you use JComments, please post a rating and a review at the Joomla! Extensions Directory
kloverde
Newbie
*

Karma: 0
Offline Offline

Gender: Male
Posts: 4


WWW
« Reply #4 on: June 23, 2012, 23:06:12 »

Yeah, that had crossed my mind.  I was more concerned that a user might not see notifications, but I agree with you.

I do have a solution for determining if the div is in the viewport.  Someone on stackoverflow had already solved this problem, but I had to change it a bit due to a Chrome bug.  It's explained in documentation in the .js file below -- compare it with the version on stackoverflow to see what I changed -- the link is also in the documentation.

I tested this code in Firefox 13 and Chrome 19 on Fedora 14 and Windows XP, and in IE 8 on XP, and it worked.  I'd like to ask people reading this thread to test this on different browsers and browser versions and list their configuration, but I don't anticipate there being problems.

If enough people report back that it worked for them as well, I'll merge it into my JComments fork to test it.  I'm holding off on doing that because testing will require me to create a second Joomla installation on my domain.  Or, smart, if you have a test environment ready to go, you could save me the trouble -- all you'd need to do is include the .js file and wrap my window.location.href setting in a check for !isVisible().

You can remove VisibilityMonitor() -- JComments won't have a use for it.  I just kept it in there because it was in the original code.

visibility.html
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
   <head>
      <script type="text/javascript" src="visibility.js"></script>

      <script type="text/javascript">
         function msgInView()
         {
            window.alert( "element is in view" );
         }

         function msgNotInView()
         {
            window.alert( "element is not in view" );
         }

         /*
          * JComments should do this
          */
         function checkVisibility()
         {
            isVisible(document.getElementById("importantdiv")) ? msgInView() : msgNotInView();
         }

         /*
          * JComments should not do this
          */
         function startVisibilityMonitor()
         {
            VisibilityMonitor( document.getElementById('importantdiv'), msgInView, msgNotInView );
         }
      </script>
   </head>

   <body>
      <button type="button" onclick="checkVisibility();" style="position:fixed;left:150px;top:20px;">check visibility</button>
      <div id="importantdiv" style="position:absolute;top:1000px;border:1px solid #000000">hello</div>

      <!-- puts 'importantdiv' somewhere in the middle of the page, instead of the bottom -->
      <div style="position:absolute;top:2000px;">_</div>
   </body>
</html>

visibility.js
Code:
/*
 * This library was written by bobince and has been modified by Kurtis LoVerde.
 *
 * Bobince
 *    Profile:  http://stackoverflow.com/users/18936/bobince
 *    Code obtained from:  http://stackoverflow.com/questions/2158991/fire-javascript-event-when-a-div-is-in-view
 *
 * Kurtis LoVerde
 *    Homepage:  http://www.loverde.org
 *
 *
 * Changes by Kurtis:
 *
 *    1.  Chrome has a bug which puts scrollTop/scrollLeft in the wrong object when
 *        operating in standards mode, breaking logic bobince used to determine
 *        where to pull the values from.  As of the date this comment was written,
 *        the Chrome bug was marked "won't fix" without explanation:
 *
 *        http://code.google.com/p/chromium/issues/detail?id=2891
 *
 *        I changed bobince's logic to look at document.documentElement *and*
 *        document.body, favoring document.documentElement.  Standards/quirks mode
 *        detection has been removed.
 *
 *    2.  Added isVisible(element) to perform one-off visibility checks.
 */

/*
 * Perform a one-time check of an item's visibility.
 * Returns true if the element is in view, false if not.
 */
function isVisible(element)
{
   return rectsIntersect( getPageRect(), getElementRect(element) );
}

/*
 * Assign a VisibilityMonitor to an element.  The monitor will check
 * the element's visibility after every scroll or resize event and will
 * execute a function whenever the element enters or leaves view.
 */
function VisibilityMonitor(element, showfn, hidefn)
{
   var isshown= false;

   function check()
   {
      if (rectsIntersect(getPageRect(), getElementRect(element)) !== isshown)
      {
         isshown= !isshown;
         isshown? showfn() : hidefn();
      }
   };

   window.onscroll=window.onresize= check;
   check();
}


function getPageRect()
{
   var x= document.documentElement.scrollLeft || document.body.scrollLeft;
   var y= document.documentElement.scrollTop || document.body.scrollTop;
   var w= 'innerWidth' in window? window.innerWidth : (document.documentElement.clientWidth || document.body.clientWidth);
   var h= 'innerHeight' in window? window.innerHeight : (document.documentElement.clientHeight || document.body.clientHeight);

   return [x, y, x+w, y+h];
}

function getElementRect(element)
{
   var x= 0, y= 0;
   var w= element.offsetWidth, h= element.offsetHeight;

   while (element.offsetParent!==null)
   {
      x+= element.offsetLeft;
      y+= element.offsetTop;
      element= element.offsetParent;
   }

   return [x, y, x+w, y+h];
}

function rectsIntersect(a, b)
{
   return a[0]<b[2] && a[2]>b[0] && a[1]<b[3] && a[3]>b[1];
}
« Last Edit: June 24, 2012, 02:11:45 by kloverde » Logged
smart
Administrator
Hero Member
*****

Karma: 163
Offline Offline

Gender: Male
Posts: 2161



WWW
« Reply #5 on: June 26, 2012, 14:26:27 »

I know why it works so. The scrollTo method works properly and getElementRect works properly too. But before we call the scroll method we are setting focus to  to the form's element which is related to this message and the browser scrolls page to this control. And after this message is visible and scroll method is not perform scroll.

So I've changed order in jcomments.error function - we show message and after this set focus. Now seems all works fine. Could test?
« Last Edit: June 27, 2012, 13:25:01 by smart » Logged

If you use JComments, please post a rating and a review at the Joomla! Extensions Directory
smart
Administrator
Hero Member
*****

Karma: 163
Offline Offline

Gender: Male
Posts: 2161



WWW
« Reply #6 on: June 27, 2012, 13:28:18 »

Oh, sorry. I've updated JComments on demo site but I've made mistake and attach here old file. Now I've attached new file.

* jcomments-v2.3.js (28.46 KB - downloaded 93 times.)
Logged

If you use JComments, please post a rating and a review at the Joomla! Extensions Directory
kloverde
Newbie
*

Karma: 0
Offline Offline

Gender: Male
Posts: 4


WWW
« Reply #7 on: June 28, 2012, 05:11:03 »

I re-ran my previous tests -- it's working exactly as expected, and the behavior is identical in each configuration.

Hooray!  Looks like we're done here.
Logged
Pages: [1]   Go Up
  Print  
JoomlaTune Support Forum    JComments component    Bug-reports    Topic: [solved] I have a patch for 2.3.0
 
Jump to: