Q2W3 Fixed Widget - Version 1.0.2

Version Description

  • Fixed problem with widgets displayed only on certain pages.
  • Optimized javascript code.
Download this release

Release Info

Developer Max Bond
Plugin Icon 128x128 Q2W3 Fixed Widget
Version 1.0.2
Comparing to
See all releases

Code changes from version 1.0.1 to 1.0.2

Files changed (3) hide show
  1. js/functions.js +19 -23
  2. q2w3-fixed-widget.php +5 -5
  3. readme.txt +6 -3
js/functions.js CHANGED
@@ -1,31 +1,27 @@
1
  jQuery(window).load(function () {
2
- var i = 0;
3
  var vertical_offset = 10;
4
- while ( q2w3_fixed_widgets[i] ) {
5
- q2w3_fixed_widget(q2w3_fixed_widgets[i], vertical_offset);
6
- vertical_offset += jQuery('#' + q2w3_fixed_widgets[i]).outerHeight(true);
7
- i++;
 
 
8
  }
9
  });
10
-
11
- function q2w3_fixed_widget(widget_id, vertical_offset) {
12
- var widget_width = jQuery('#' + widget_id).css('width');
13
- var widget_margin = jQuery('#' + widget_id).css('margin');
14
- var widget_padding = jQuery('#' + widget_id).css('padding');
15
- var top = jQuery('#' + widget_id).offset().top;
16
- top -= vertical_offset;
17
-
18
  jQuery(window).scroll(function (event) {
19
- if ( jQuery(this).scrollTop() >= top ) {
20
- // fixed
21
- jQuery('#' + widget_id).css('position', 'fixed');
22
- jQuery('#' + widget_id).css('width', widget_width);
23
- jQuery('#' + widget_id).css('margin', widget_margin);
24
- jQuery('#' + widget_id).css('padding', widget_padding);
25
- jQuery('#' + widget_id).css('top', vertical_offset);
26
- } else {
27
- // normal
28
- jQuery('#' + widget_id).css('position', 'static');
29
  }
30
  });
31
  }
1
  jQuery(window).load(function () {
 
2
  var vertical_offset = 10;
3
+ for (var i = 0; i < q2w3_fixed_widgets.length; i++) {
4
+ widget = jQuery('#' + q2w3_fixed_widgets[i]);
5
+ if ( widget.attr('id') ) { // element existsts
6
+ q2w3_fixed_widget(widget, vertical_offset);
7
+ vertical_offset += widget.outerHeight(true);
8
+ }
9
  }
10
  });
11
+ function q2w3_fixed_widget(widget, vertical_offset) {
12
+ var widget_width = widget.css('width');
13
+ var widget_margin = widget.css('margin');
14
+ var widget_padding = widget.css('padding');
15
+ var top = widget.offset().top - vertical_offset;
 
 
 
16
  jQuery(window).scroll(function (event) {
17
+ if ( jQuery(this).scrollTop() >= top ) { // fixed
18
+ widget.css('position', 'fixed');
19
+ widget.css('width', widget_width);
20
+ widget.css('margin', widget_margin);
21
+ widget.css('padding', widget_padding);
22
+ widget.css('top', vertical_offset);
23
+ } else { // normal
24
+ widget.css('position', 'static');
 
 
25
  }
26
  });
27
  }
q2w3-fixed-widget.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Q2W3 Fixed Widget
4
  Plugin URI: http://www.q2w3.ru/q2w3-fixed-widget-wordpress-plugin/
5
  Description: Fixes positioning of the selected widgets, when the page is scrolled down.
6
  Author: Max Bond
7
- Version: 1.0.1
8
  Author URI: http://www.q2w3.ru/
9
  */
10
 
@@ -21,8 +21,8 @@ if ( is_admin() ) {
21
  add_action('template_redirect', array( 'q2w3_fixed_widget', 'init' ));
22
 
23
  add_filter('widget_display_callback', array( 'q2w3_fixed_widget', 'check' ), 10, 3);
24
-
25
- add_action('wp_footer', array( 'q2w3_fixed_widget', 'action' ));
26
 
27
  }
28
 
@@ -44,7 +44,7 @@ class q2w3_fixed_widget {
44
 
45
  wp_enqueue_script('jquery');
46
 
47
- wp_enqueue_script('q2w3-fixed-widget', plugin_dir_url( __FILE__ ) . 'js/functions.js', array('jquery'), '1.1', true);
48
 
49
  }
50
 
@@ -55,7 +55,7 @@ class q2w3_fixed_widget {
55
  return $instance;
56
 
57
  }
58
-
59
  public static function action() {
60
 
61
  if ( is_array(self::$fixed_widgets) && !empty(self::$fixed_widgets) ) {
4
  Plugin URI: http://www.q2w3.ru/q2w3-fixed-widget-wordpress-plugin/
5
  Description: Fixes positioning of the selected widgets, when the page is scrolled down.
6
  Author: Max Bond
7
+ Version: 1.0.2
8
  Author URI: http://www.q2w3.ru/
9
  */
10
 
21
  add_action('template_redirect', array( 'q2w3_fixed_widget', 'init' ));
22
 
23
  add_filter('widget_display_callback', array( 'q2w3_fixed_widget', 'check' ), 10, 3);
24
+
25
+ add_action('wp_footer', array( 'q2w3_fixed_widget', 'action' ), 1);
26
 
27
  }
28
 
44
 
45
  wp_enqueue_script('jquery');
46
 
47
+ wp_enqueue_script('q2w3-fixed-widget', plugin_dir_url( __FILE__ ) . 'js/functions.js', array('jquery'), '1.2', true);
48
 
49
  }
50
 
55
  return $instance;
56
 
57
  }
58
+
59
  public static function action() {
60
 
61
  if ( is_array(self::$fixed_widgets) && !empty(self::$fixed_widgets) ) {
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.q2w3.ru/q2w3-fixed-widget-wordpress-plugin/#donate
4
  Tags: q2w3, widget, fixed, scroll, fixed scroll, floating, floating widget, fixed widget, sticky, sticky widget, sidebar
5
  Requires at least: 3.0
6
  Tested up to: 3.4.2
7
- Stable tag: 1.0.1
8
 
9
  Fixes positioning of the selected widgets, when the page is scrolled down.
10
 
@@ -33,7 +33,7 @@ There are several reasons:
33
 
34
  1. No `wp_head()` and `wp_footer()` functions in template. Check header.php and footer.php files of your current template.
35
  2. Widgets have no unique IDs. How to check. Place two text widgets in your sidebar. Then look at html source of your site. If these two widgets have the same IDs (widget_text) - that's the problem. How to fix. Find `register_sidebar()` function (look first at functions.php file). Parameter `before_widget` should be like this: `<li id="%1$s" class="widget-container %2$s">`. Attention to this part: `id="%1$s"`.
36
- 3. jQuery errors on page. Commonly caused by buggy plugins. Check javascript console of your browser. If you find errors, try to locate its source.
37
 
38
 
39
  == Screenshots ==
@@ -42,12 +42,15 @@ There are several reasons:
42
 
43
  == Other Notes ==
44
 
45
-
46
  * [Code Insert Manager](http://wordpress.org/extend/plugins/q2w3-inc-manager/)
47
  * [Q2W3 Post Order](http://wordpress.org/extend/plugins/q2w3-post-order/)
48
 
49
  == Changelog ==
50
 
 
 
 
 
51
  = 1.0.1 =
52
  * Improved compatibility with Webkit based browsers (like Chrome and Safari).
53
  * Removed unnecessary CSS.
4
  Tags: q2w3, widget, fixed, scroll, fixed scroll, floating, floating widget, fixed widget, sticky, sticky widget, sidebar
5
  Requires at least: 3.0
6
  Tested up to: 3.4.2
7
+ Stable tag: 1.0.2
8
 
9
  Fixes positioning of the selected widgets, when the page is scrolled down.
10
 
33
 
34
  1. No `wp_head()` and `wp_footer()` functions in template. Check header.php and footer.php files of your current template.
35
  2. Widgets have no unique IDs. How to check. Place two text widgets in your sidebar. Then look at html source of your site. If these two widgets have the same IDs (widget_text) - that's the problem. How to fix. Find `register_sidebar()` function (look first at functions.php file). Parameter `before_widget` should be like this: `<li id="%1$s" class="widget-container %2$s">`. Attention to this part: `id="%1$s"`.
36
+ 3. Javascript errors on page. Commonly caused by buggy plugins. Check javascript console of your browser. If you find errors, try to locate its source.
37
 
38
 
39
  == Screenshots ==
42
 
43
  == Other Notes ==
44
 
 
45
  * [Code Insert Manager](http://wordpress.org/extend/plugins/q2w3-inc-manager/)
46
  * [Q2W3 Post Order](http://wordpress.org/extend/plugins/q2w3-post-order/)
47
 
48
  == Changelog ==
49
 
50
+ = 1.0.2 =
51
+ * Fixed problem with widgets displayed only on certain pages.
52
+ * Optimized javascript code.
53
+
54
  = 1.0.1 =
55
  * Improved compatibility with Webkit based browsers (like Chrome and Safari).
56
  * Removed unnecessary CSS.