Title: Throwing Javascript Errors
Last modified: August 20, 2016

---

# Throwing Javascript Errors

 *  Resolved [Cory Lamle](https://wordpress.org/support/users/corylamleorg/)
 * (@corylamleorg)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/throwing-javascript-errors/)
 * Keep getting error in sharebar.js line #27
 * Need to add a check to see if top is null. This error only happens on pages (
   not posts) at least on a few of my sites. So the error is not always thrown. 
   Please add an if check to validate offset().top.
 * It seems like every-time an update is made I have to go in and fix it. I have
   submitted this bug several times and it keeps getting ignored. I would greatly
   appreciate it if someone who has access to the source branch could fix it as 
   I love this plugin. It is frustrating that I have to go patch it every-time an
   update is made, let me fix it again and I’ll post the solution.
 * Thanks much!
 * [http://wordpress.org/extend/plugins/sharebar/](http://wordpress.org/extend/plugins/sharebar/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [Cory Lamle](https://wordpress.org/support/users/corylamleorg/)
 * (@corylamleorg)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/throwing-javascript-errors/#post-3429139)
 * Posting code fix. It doesn’t look like the developer answers or checks the threads
   as most of the forum questions remain unresolved.
 * So if you get a JS error like the one above open the sharebar.js file and look
   for a function named function sharebar_init()
 * Replace the contents with this:
 *     ```
       function sharebar_init(){
       	var $sharebar = jQuery(sharebar);
       	if ($sharebar.length > 0) {
       		jQuery(sharebar).css('width',o.swidth+'px');
       		if (o.position == 'left') jQuery(sharebar).css('marginLeft',(0-o.swidth-o.leftOffset));
       		else {
       			jQuery(sharebar).css('marginLeft',(parent+o.rightOffset));
       		}
       		if(w < o.minwidth && o.horizontal) jQuery(sharebarx).slideDown();
       		else jQuery(sharebar).fadeIn();
       		jQuery.event.add(window, "scroll", sharebar_scroll);
       		jQuery.event.add(window, "resize", sharebar_resize);
   
       		return jQuery(sharebar).offset().top;
       	} else {
       		return 0;
       	}
       }
       ```
   
 * I have marked this as resolved but in future updates you might have to fix this
   unless the developer reads some of the forum threads…
 * Hope this helps someone.
 * Cheers!
 *  [pykler](https://wordpress.org/support/users/pykler/)
 * (@pykler)
 * [13 years ago](https://wordpress.org/support/topic/throwing-javascript-errors/#post-3429384)
 * Here is my patch, found this issue after I coded it up and was looking for a 
   way to send it to the developer. Hope s/he starts checking these issues.
 *     ```
       Index: sharebar.php
       ===================================================================
       --- sharebar.php        (revision 707593)
       +++ sharebar.php        (working copy)
       @@ -155,7 +155,7 @@
                       echo '<link rel="stylesheet" href="'.get_bloginfo('wpurl').'/wp-content/plugins/sharebar/css/sharebar.css" type="text/css" media="screen" />';
                       if($horizontal) $hori = 'true'; else $hori = 'false';
                       if(!$width) $width = 1000;
       -               echo "\n"; ?><script type="text/javascript">jQuery(document).ready(function($) { $('.sharebar').sharebar({horizontal:'<?php echo $hori; ?>',swidth:'<?php echo $swidth; ?>',minwidth:<?php echo $width; ?>,position:'<?php echo $position; ?>',leftOffset:<?php echo $leftoffset; ?>,rightOffset:<?php echo $rightoffset; ?>}); });</script><?php echo "\n"; ?><!-- Sharebar Plugin by Monjurul Dolon (http://mdolon.com/) - more info at: http://devgrow.com/sharebar-wordpress-plugin --><?php echo "\n"; ?><?php
       +               echo "\n"; ?><script type="text/javascript">jQuery(document).ready(function($) { if(!$('.sharebar').length){ return; } $('.sharebar').sharebar({horizontal:'<?php echo $hori; ?>',swidth:'<?php echo $swidth; ?>',minwidth:<?php echo $width; ?>,position:'<?php echo $position; ?>',leftOffset:<?php echo $leftoffset; ?>,rightOffset:<?php echo $rightoffset; ?>}); });</script><?php echo "\n"; ?><!-- Sharebar Plugin by Monjurul Dolon (http://mdolon.com/) - more info at: http://devgrow.com/sharebar-wordpress-plugin --><?php echo "\n"; ?><?php
               }
        }
       ```
   
 *  [pykler](https://wordpress.org/support/users/pykler/)
 * (@pykler)
 * [13 years ago](https://wordpress.org/support/topic/throwing-javascript-errors/#post-3429389)
 * Actually my patch does not work as well as @lifeinthegrid patch … here is his
   patch in patchable format
 *     ```
       Index: js/sharebar.js
       ===================================================================
       --- js/sharebar.js      (revision 707593)
       +++ js/sharebar.js      (working copy)
       @@ -15,6 +15,8 @@
               var start = sharebar_init();
   
               function sharebar_init(){
       +               var $sharebar = jQuery(sharebar);
       +               if ($sharebar.length <= 0) { return 0; }
                       jQuery(sharebar).css('width',o.swidth+'px');
                       if (o.position == 'left') jQuery(sharebar).css('marginLeft',(0-o.swidth-o.leftOffset));
                       else {
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Throwing Javascript Errors’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/sharebar.svg)
 * [Sharebar](https://wordpress.org/plugins/sharebar/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/sharebar/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/sharebar/)
 * [Active Topics](https://wordpress.org/support/plugin/sharebar/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/sharebar/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/sharebar/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [pykler](https://wordpress.org/support/users/pykler/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/throwing-javascript-errors/#post-3429389)
 * Status: resolved