Q2W3 Fixed Widget - Version 1.0

Version Description

  • First public release.
Download this release

Release Info

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

Version 1.0

Files changed (5) hide show
  1. css/style.css +6 -0
  2. js/function.js +34 -0
  3. q2w3-fixed-widget.php +107 -0
  4. readme.txt +52 -0
  5. screenshot-1.jpg +0 -0
css/style.css ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ @CHARSET "UTF-8";
2
+
3
+ .q2w3-fixed-widget {
4
+ position: fixed;
5
+ top: 10px;
6
+ }
js/function.js ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(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 - parseFloat(jQuery('#' + widget_id).css('marginTop').replace(/auto/, 0));
16
+ top -= vertical_offset;
17
+ jQuery(window).scroll(function (event) {
18
+ // what the y position of the scroll is
19
+ var y = jQuery(this).scrollTop();
20
+
21
+ // whether that's below the form
22
+ if (y >= top) {
23
+ // if so, ad the fixed class
24
+ jQuery('#' + widget_id).addClass('q2w3-fixed-widget');
25
+ jQuery('#' + widget_id).css('width', widget_width);
26
+ jQuery('#' + widget_id).css('margin', widget_margin);
27
+ jQuery('#' + widget_id).css('padding', widget_padding);
28
+ jQuery('#' + widget_id).css('top', vertical_offset);
29
+ } else {
30
+ // otherwise remove it
31
+ jQuery('#' + widget_id).removeClass('q2w3-fixed-widget');
32
+ }
33
+ });
34
+ }
q2w3-fixed-widget.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ 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
8
+ Author URI: http://www.q2w3.ru/
9
+ */
10
+
11
+ // Hooks
12
+
13
+ if ( is_admin() ) {
14
+
15
+ add_action('in_widget_form', array( 'q2w3_fixed_widget', 'add_option' ), 10, 3);
16
+
17
+ add_filter('widget_update_callback', array( 'q2w3_fixed_widget', 'update_option' ), 10, 3);
18
+
19
+ } else {
20
+
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
+
29
+
30
+ // if class allready loaded return control to the main script
31
+
32
+ if ( class_exists('q2w3_fixed_widget', false) ) return;
33
+
34
+
35
+ // Plugin class
36
+
37
+ class q2w3_fixed_widget {
38
+
39
+ protected static $fixed_widgets;
40
+
41
+
42
+
43
+ public static function init() {
44
+
45
+ $plugin_url = plugin_dir_url( __FILE__ );
46
+
47
+ wp_enqueue_style('q2w3-fixed-widget', $plugin_url . 'css/style.css', false, '1.0', 'all');
48
+
49
+ wp_enqueue_script('jquery');
50
+
51
+ wp_enqueue_script('q2w3-fixed-widget', $plugin_url . 'js/function.js', array('jquery'), '1.0', true);
52
+
53
+ }
54
+
55
+ public static function check($instance, $widget, $args){
56
+
57
+ if ( $instance['q2w3_fixed_widget'] ) self::$fixed_widgets[$widget->id] = "'". $widget->id ."'";
58
+
59
+ return $instance;
60
+
61
+ }
62
+
63
+ public static function action() {
64
+
65
+ if ( is_array(self::$fixed_widgets) && !empty(self::$fixed_widgets) ) {
66
+
67
+ $array = implode(',', self::$fixed_widgets);
68
+
69
+ echo '<script type="text/javascript">q2w3_fixed_widgets = new Array('. $array .');</script>'.PHP_EOL;
70
+
71
+ } else {
72
+
73
+ echo '<script type="text/javascript">q2w3_fixed_widgets = new Array();</script>'.PHP_EOL;
74
+
75
+ }
76
+
77
+ }
78
+
79
+ public static function add_option($widget, $return, $instance) {
80
+
81
+ echo '<p>'.PHP_EOL;
82
+
83
+ echo '<input type="checkbox" name="'. $widget->get_field_name('q2w3_fixed_widget') .'" value="1" '. checked( $instance['q2w3_fixed_widget'], 1, false ) .'/>'.PHP_EOL;
84
+
85
+ echo '<label for="'. $widget->get_field_id('q2w3_fixed_widget') .'">'. __('Fixed widget', 'q2w3_fixed_widget') .'</label>'.PHP_EOL;
86
+
87
+ echo '</p>'.PHP_EOL;
88
+
89
+ }
90
+
91
+ public static function update_option($instance, $new_instance, $old_instance){
92
+
93
+ if ( isset($new_instance['q2w3_fixed_widget']) && $new_instance['q2w3_fixed_widget'] ) {
94
+
95
+ $instance['q2w3_fixed_widget'] = 1;
96
+
97
+ } else {
98
+
99
+ $instance['q2w3_fixed_widget'] = false;
100
+
101
+ }
102
+
103
+ return $instance;
104
+
105
+ }
106
+
107
+ }
readme.txt ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Q2W3 Fixed Widget (Sticky Widget) ===
2
+ Contributors: Max Bond
3
+ 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
8
+
9
+ Fixes positioning of the selected widgets, when the page is scrolled down.
10
+
11
+ == Description ==
12
+
13
+ This is a very lightweight plugin with great functionality! )
14
+
15
+ Enable "Fixed widget" option on ANY active widget (see [screenshot](http://wordpress.org/extend/plugins/q2w3-fixed-widget/screenshots/)) and it will be always in sight when page is scrolled down.
16
+
17
+ There is no problem to "Fix" (or "Stick") more than one widget, but remember about browser window height! Too many widgets can overlap with footer or always be out of sight.
18
+
19
+ [Watch the demo](http://store.places-finder.com/cp-ajax-post-load).
20
+ Right sidebar, last two widgets. Scroll down to the bottom.
21
+
22
+ == Installation ==
23
+
24
+ 1. Follow standard WordPress plugin installation procedure
25
+ 2. Activate the plugin through the Plugins menu in WordPress
26
+ 3. Go to Appearance -> Widgets, enable "Fixed Widget" option on any active widget ([screenshot](http://wordpress.org/extend/plugins/q2w3-fixed-widget/screenshots/))
27
+
28
+ == Frequently Asked Questions ==
29
+
30
+ = Why plugin is not working? =
31
+
32
+ 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 ==
40
+
41
+ 1. Widget with enabled "Fixed widget" option
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 =
52
+ * First public release.
screenshot-1.jpg ADDED
Binary file