WooCommerce Grid / List toggle - Version 0.3

Version Description

  • 30/01/2013 =
  • Added option to choose default view
Download this release

Release Info

Developer jameskoster
Plugin Icon 128x128 WooCommerce Grid / List toggle
Version 0.3
Comparing to
See all releases

Code changes from version 0.2.3 to 0.3

assets/js/jquery.gridlistview.js CHANGED
@@ -26,11 +26,6 @@ jQuery(document).ready(function(){
26
  jQuery('ul.products, #gridlist-toggle').addClass(jQuery.cookie('gridcookie'));
27
  }
28
 
29
- if (jQuery.cookie('gridcookie') == null) {
30
- jQuery('ul.products').addClass('grid');
31
- jQuery('.gridlist-toggle #grid').addClass('active');
32
- }
33
-
34
  if (jQuery.cookie('gridcookie') == 'grid') {
35
  jQuery('.gridlist-toggle #grid').addClass('active');
36
  jQuery('.gridlist-toggle #list').removeClass('active');
26
  jQuery('ul.products, #gridlist-toggle').addClass(jQuery.cookie('gridcookie'));
27
  }
28
 
 
 
 
 
 
29
  if (jQuery.cookie('gridcookie') == 'grid') {
30
  jQuery('.gridlist-toggle #grid').addClass('active');
31
  jQuery('.gridlist-toggle #list').removeClass('active');
assets/js/jquery.gridlistview.min.js CHANGED
@@ -1,2 +1,2 @@
1
  // The toggle
2
- jQuery(document).ready(function(){jQuery("#grid").click(function(){jQuery(this).addClass("active");jQuery("#list").removeClass("active");jQuery.cookie("gridcookie","grid",{path:"/"});jQuery("ul.products").fadeOut(300,function(){jQuery(this).addClass("grid").removeClass("list").fadeIn(300)});return!1});jQuery("#list").click(function(){jQuery(this).addClass("active");jQuery("#grid").removeClass("active");jQuery.cookie("gridcookie","list",{path:"/"});jQuery("ul.products").fadeOut(300,function(){jQuery(this).removeClass("grid").addClass("list").fadeIn(300)});return!1});jQuery.cookie("gridcookie")&&jQuery("ul.products, #gridlist-toggle").addClass(jQuery.cookie("gridcookie"));if(jQuery.cookie("gridcookie")==null){jQuery("ul.products").addClass("grid");jQuery(".gridlist-toggle #grid").addClass("active")}if(jQuery.cookie("gridcookie")=="grid"){jQuery(".gridlist-toggle #grid").addClass("active");jQuery(".gridlist-toggle #list").removeClass("active")}if(jQuery.cookie("gridcookie")=="list"){jQuery(".gridlist-toggle #list").addClass("active");jQuery(".gridlist-toggle #grid").removeClass("active")}jQuery("#gridlist-toggle a").click(function(e){e.preventDefault()})});
1
  // The toggle
2
+ jQuery(document).ready(function(){jQuery("#grid").click(function(){jQuery(this).addClass("active");jQuery("#list").removeClass("active");jQuery.cookie("gridcookie","grid",{path:"/"});jQuery("ul.products").fadeOut(300,function(){jQuery(this).addClass("grid").removeClass("list").fadeIn(300)});return!1});jQuery("#list").click(function(){jQuery(this).addClass("active");jQuery("#grid").removeClass("active");jQuery.cookie("gridcookie","list",{path:"/"});jQuery("ul.products").fadeOut(300,function(){jQuery(this).removeClass("grid").addClass("list").fadeIn(300)});return!1});jQuery.cookie("gridcookie")&&jQuery("ul.products, #gridlist-toggle").addClass(jQuery.cookie("gridcookie"));if(jQuery.cookie("gridcookie")=="grid"){jQuery(".gridlist-toggle #grid").addClass("active");jQuery(".gridlist-toggle #list").removeClass("active")}if(jQuery.cookie("gridcookie")=="list"){jQuery(".gridlist-toggle #list").addClass("active");jQuery(".gridlist-toggle #grid").removeClass("active")}jQuery("#gridlist-toggle a").click(function(e){e.preventDefault()})});
grid-list-toggle.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WooCommerce Grid / List toggle
4
  Plugin URI: http://jameskoster.co.uk/tag/grid-list-toggle/
5
  Description: Adds a grid/list view toggle to product archives
6
- Version: 0.2.3
7
  Author: jameskoster
8
  Author URI: http://jameskoster.co.uk
9
  Requires at least: 3.1
@@ -32,13 +32,56 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g
32
  public function __construct() {
33
  // Hooks
34
  add_action( 'wp' , array(&$this, 'setup_gridlist' ) , 20);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  }
36
 
37
- // Functions
38
  // Setup
39
  function setup_gridlist() {
40
  if ( is_shop() || is_product_category() || is_product_tag() ) {
41
- add_action( 'get_header', array(&$this, 'setup_scripts_styles'), 20);
 
42
  add_action( 'woocommerce_before_shop_loop', array(&$this, 'gridlist_toggle_button'), 30);
43
  add_action( 'woocommerce_after_shop_loop_item', array(&$this, 'gridlist_buttonwrap_open'), 9);
44
  add_action( 'woocommerce_after_shop_loop_item', array(&$this, 'gridlist_buttonwrap_close'), 11);
@@ -50,18 +93,23 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g
50
  // Scripts & styles
51
  function setup_scripts_styles() {
52
  if ( is_shop() || is_product_category() || is_product_tag() ) {
53
- wp_enqueue_script( 'cookie', plugins_url( '/assets/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ) );
54
- wp_enqueue_script( 'grid-list-scripts', plugins_url( '/assets/js/jquery.gridlistview.min.js', __FILE__ ), array( 'jquery' ) );
55
  wp_enqueue_style( 'grid-list-layout', plugins_url( '/assets/css/style.css', __FILE__ ) );
56
  wp_enqueue_style( 'grid-list-button', plugins_url( '/assets/css/button.css', __FILE__ ) );
57
  }
58
  }
 
 
 
 
 
 
 
59
 
60
  // Toggle button
61
  function gridlist_toggle_button() {
62
  ?>
63
  <nav class="gridlist-toggle">
64
- <a href="#" id="grid" class="active" title="<?php _e('Grid view', 'wc_list_grid_toggle'); ?>">&#8862; <span><?php _e('Grid view', 'wc_list_grid_toggle'); ?></span></a><a href="#" id="list" title="<?php _e('List view', 'wc_list_grid_toggle'); ?>">&#8863; <span><?php _e('List view', 'wc_list_grid_toggle'); ?></span></a>
65
  </nav>
66
  <?php
67
  }
@@ -84,6 +132,18 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g
84
  <hr />
85
  <?php
86
  }
 
 
 
 
 
 
 
 
 
 
 
 
87
  }
88
  $WC_List_Grid = new WC_List_Grid();
89
  }
3
  Plugin Name: WooCommerce Grid / List toggle
4
  Plugin URI: http://jameskoster.co.uk/tag/grid-list-toggle/
5
  Description: Adds a grid/list view toggle to product archives
6
+ Version: 0.3
7
  Author: jameskoster
8
  Author URI: http://jameskoster.co.uk
9
  Requires at least: 3.1
32
  public function __construct() {
33
  // Hooks
34
  add_action( 'wp' , array(&$this, 'setup_gridlist' ) , 20);
35
+
36
+ // Init settings
37
+ $this->settings = array(
38
+ array(
39
+ 'name' => __( 'Default catalog view', 'wc_list_grid_toggle' ),
40
+ 'type' => 'title',
41
+ 'id' => 'wc_glt_options'
42
+ ),
43
+ array(
44
+ 'name' => __( 'Default catalog view', 'wc_list_grid_toggle' ),
45
+ 'desc_tip' => __( 'Display products in grid or list view by default', 'wc_list_grid_toggle' ),
46
+ 'id' => 'wc_glt_default',
47
+ 'type' => 'select',
48
+ 'options' => array(
49
+ 'grid' => __('Grid', 'wc_list_grid_toggle'),
50
+ 'list' => __('List', 'wc_list_grid_toggle')
51
+ )
52
+ ),
53
+ array( 'type' => 'sectionend', 'id' => 'wc_glt_options' ),
54
+ );
55
+
56
+ // Default options
57
+ add_option( 'wc_glt_default', 'grid' );
58
+ add_option( 'wc_apm_google', 'no' );
59
+ add_option( 'wc_apm_mastercard', 'no' );
60
+ add_option( 'wc_apm_paypal', 'no' );
61
+ add_option( 'wc_apm_visa', 'no' );
62
+
63
+ // Admin
64
+ add_action( 'woocommerce_settings_image_options_after', array( &$this, 'admin_settings' ), 20);
65
+ add_action( 'woocommerce_update_options_catalog', array( &$this, 'save_admin_settings' ) );
66
+ }
67
+
68
+ /*-----------------------------------------------------------------------------------*/
69
+ /* Class Functions */
70
+ /*-----------------------------------------------------------------------------------*/
71
+
72
+ function admin_settings() {
73
+ woocommerce_admin_fields( $this->settings );
74
+ }
75
+
76
+ function save_admin_settings() {
77
+ woocommerce_update_options( $this->settings );
78
  }
79
 
 
80
  // Setup
81
  function setup_gridlist() {
82
  if ( is_shop() || is_product_category() || is_product_tag() ) {
83
+ add_action( 'wp_enqueue_scripts', array(&$this, 'setup_scripts_styles'), 20);
84
+ add_action( 'wp_enqueue_scripts', array(&$this, 'setup_scripts_script'), 20);
85
  add_action( 'woocommerce_before_shop_loop', array(&$this, 'gridlist_toggle_button'), 30);
86
  add_action( 'woocommerce_after_shop_loop_item', array(&$this, 'gridlist_buttonwrap_open'), 9);
87
  add_action( 'woocommerce_after_shop_loop_item', array(&$this, 'gridlist_buttonwrap_close'), 11);
93
  // Scripts & styles
94
  function setup_scripts_styles() {
95
  if ( is_shop() || is_product_category() || is_product_tag() ) {
 
 
96
  wp_enqueue_style( 'grid-list-layout', plugins_url( '/assets/css/style.css', __FILE__ ) );
97
  wp_enqueue_style( 'grid-list-button', plugins_url( '/assets/css/button.css', __FILE__ ) );
98
  }
99
  }
100
+ function setup_scripts_script() {
101
+ if ( is_shop() || is_product_category() || is_product_tag() ) {
102
+ wp_enqueue_script( 'cookie', plugins_url( '/assets/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ) );
103
+ wp_enqueue_script( 'grid-list-scripts', plugins_url( '/assets/js/jquery.gridlistview.min.js', __FILE__ ), array( 'jquery' ) );
104
+ add_action( 'wp_footer', array(&$this, 'gridlist_set_default_view') );
105
+ }
106
+ }
107
 
108
  // Toggle button
109
  function gridlist_toggle_button() {
110
  ?>
111
  <nav class="gridlist-toggle">
112
+ <a href="#" id="grid" title="<?php _e('Grid view', 'wc_list_grid_toggle'); ?>">&#8862; <span><?php _e('Grid view', 'wc_list_grid_toggle'); ?></span></a><a href="#" id="list" title="<?php _e('List view', 'wc_list_grid_toggle'); ?>">&#8863; <span><?php _e('List view', 'wc_list_grid_toggle'); ?></span></a>
113
  </nav>
114
  <?php
115
  }
132
  <hr />
133
  <?php
134
  }
135
+
136
+ function gridlist_set_default_view() {
137
+ $default = get_option( 'wc_glt_default' );
138
+ ?>
139
+ <script>
140
+ if (jQuery.cookie('gridcookie') == null) {
141
+ jQuery('ul.products').addClass('<?php echo $default; ?>');
142
+ jQuery('.gridlist-toggle #<?php echo $default; ?>').addClass('active');
143
+ }
144
+ </script>
145
+ <?php
146
+ }
147
  }
148
  $WC_List_Grid = new WC_List_Grid();
149
  }
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: jameskoster
3
  Tags: woocommerce, grid, list, products, ecommerce
4
  Requires at least: 3.3
5
  Tested up to: 3.5
6
- Stable tag: 0.2.3
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -17,6 +17,8 @@ The list view arranges products in a vertical list and pulls in the excerpt to g
17
 
18
  The grid view you will be familiar with as this is WooCommerce's default layout for product archives.
19
 
 
 
20
  Please feel free to contribute on <a href="https://github.com/jameskoster/woocommerce-grid-list-toggle">github</a>.
21
 
22
  == Installation ==
@@ -38,7 +40,7 @@ Thanks! Please fork the repo on <a href="https://github.com/jameskoster/woocomme
38
  Add the following code to the functions.php file in your theme / child theme:
39
 
40
  `
41
- add_action('get_header', 'remove_gridlist_styles', 30);
42
  function remove_gridlist_styles() {
43
  wp_dequeue_style( 'grid-list-button' );
44
  }
@@ -62,6 +64,9 @@ function remove_gridlist_styles() {
62
 
63
  == Changelog ==
64
 
 
 
 
65
  = 0.2.3 - 28/01/2013 =
66
  * Fixed active class bug on the toggle button
67
  * Styled the star-rating in list view
3
  Tags: woocommerce, grid, list, products, ecommerce
4
  Requires at least: 3.3
5
  Tested up to: 3.5
6
+ Stable tag: 0.3
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
17
 
18
  The grid view you will be familiar with as this is WooCommerce's default layout for product archives.
19
 
20
+ The store owner can choose whether grid or list view be set as the default.
21
+
22
  Please feel free to contribute on <a href="https://github.com/jameskoster/woocommerce-grid-list-toggle">github</a>.
23
 
24
  == Installation ==
40
  Add the following code to the functions.php file in your theme / child theme:
41
 
42
  `
43
+ add_action( 'wp_enqueue_scripts', 'remove_gridlist_styles', 30 );
44
  function remove_gridlist_styles() {
45
  wp_dequeue_style( 'grid-list-button' );
46
  }
64
 
65
  == Changelog ==
66
 
67
+ = 0.3 - 30/01/2013 =
68
+ * Added option to choose default view
69
+
70
  = 0.2.3 - 28/01/2013 =
71
  * Fixed active class bug on the toggle button
72
  * Styled the star-rating in list view