Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

0.3

  • Loading branch information...
commit 9cb514fba373729dafd53cea659bfb558e2a9306 1 parent a31fc5f
James Koster authored
5 assets/js/jquery.gridlistview.js
View
@@ -26,11 +26,6 @@ jQuery(document).ready(function(){
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');
2  assets/js/jquery.gridlistview.min.js
View
@@ -1,2 +1,2 @@
// The toggle
-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()})});
+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()})});
72 grid-list-toggle.php
View
@@ -3,7 +3,7 @@
Plugin Name: WooCommerce Grid / List toggle
Plugin URI: http://jameskoster.co.uk/tag/grid-list-toggle/
Description: Adds a grid/list view toggle to product archives
-Version: 0.2.3
+Version: 0.3
Author: jameskoster
Author URI: http://jameskoster.co.uk
Requires at least: 3.1
@@ -32,13 +32,56 @@ class WC_List_Grid {
public function __construct() {
// Hooks
add_action( 'wp' , array(&$this, 'setup_gridlist' ) , 20);
+
+ // Init settings
+ $this->settings = array(
+ array(
+ 'name' => __( 'Default catalog view', 'wc_list_grid_toggle' ),
+ 'type' => 'title',
+ 'id' => 'wc_glt_options'
+ ),
+ array(
+ 'name' => __( 'Default catalog view', 'wc_list_grid_toggle' ),
+ 'desc_tip' => __( 'Display products in grid or list view by default', 'wc_list_grid_toggle' ),
+ 'id' => 'wc_glt_default',
+ 'type' => 'select',
+ 'options' => array(
+ 'grid' => __('Grid', 'wc_list_grid_toggle'),
+ 'list' => __('List', 'wc_list_grid_toggle')
+ )
+ ),
+ array( 'type' => 'sectionend', 'id' => 'wc_glt_options' ),
+ );
+
+ // Default options
+ add_option( 'wc_glt_default', 'grid' );
+ add_option( 'wc_apm_google', 'no' );
+ add_option( 'wc_apm_mastercard', 'no' );
+ add_option( 'wc_apm_paypal', 'no' );
+ add_option( 'wc_apm_visa', 'no' );
+
+ // Admin
+ add_action( 'woocommerce_settings_image_options_after', array( &$this, 'admin_settings' ), 20);
+ add_action( 'woocommerce_update_options_catalog', array( &$this, 'save_admin_settings' ) );
+ }
+
+ /*-----------------------------------------------------------------------------------*/
+ /* Class Functions */
+ /*-----------------------------------------------------------------------------------*/
+
+ function admin_settings() {
+ woocommerce_admin_fields( $this->settings );
+ }
+
+ function save_admin_settings() {
+ woocommerce_update_options( $this->settings );
}
- // Functions
// Setup
function setup_gridlist() {
if ( is_shop() || is_product_category() || is_product_tag() ) {
- add_action( 'get_header', array(&$this, 'setup_scripts_styles'), 20);
+ add_action( 'wp_enqueue_scripts', array(&$this, 'setup_scripts_styles'), 20);
+ add_action( 'wp_enqueue_scripts', array(&$this, 'setup_scripts_script'), 20);
add_action( 'woocommerce_before_shop_loop', array(&$this, 'gridlist_toggle_button'), 30);
add_action( 'woocommerce_after_shop_loop_item', array(&$this, 'gridlist_buttonwrap_open'), 9);
add_action( 'woocommerce_after_shop_loop_item', array(&$this, 'gridlist_buttonwrap_close'), 11);
@@ -50,18 +93,23 @@ function setup_gridlist() {
// Scripts & styles
function setup_scripts_styles() {
if ( is_shop() || is_product_category() || is_product_tag() ) {
- wp_enqueue_script( 'cookie', plugins_url( '/assets/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ) );
- wp_enqueue_script( 'grid-list-scripts', plugins_url( '/assets/js/jquery.gridlistview.min.js', __FILE__ ), array( 'jquery' ) );
wp_enqueue_style( 'grid-list-layout', plugins_url( '/assets/css/style.css', __FILE__ ) );
wp_enqueue_style( 'grid-list-button', plugins_url( '/assets/css/button.css', __FILE__ ) );
}
}
+ function setup_scripts_script() {
+ if ( is_shop() || is_product_category() || is_product_tag() ) {
+ wp_enqueue_script( 'cookie', plugins_url( '/assets/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ) );
+ wp_enqueue_script( 'grid-list-scripts', plugins_url( '/assets/js/jquery.gridlistview.min.js', __FILE__ ), array( 'jquery' ) );
+ add_action( 'wp_footer', array(&$this, 'gridlist_set_default_view') );
+ }
+ }
// Toggle button
function gridlist_toggle_button() {
?>
<nav class="gridlist-toggle">
- <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>
+ <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>
</nav>
<?php
}
@@ -84,6 +132,18 @@ function gridlist_hr() {
<hr />
<?php
}
+
+ function gridlist_set_default_view() {
+ $default = get_option( 'wc_glt_default' );
+ ?>
+ <script>
+ if (jQuery.cookie('gridcookie') == null) {
+ jQuery('ul.products').addClass('<?php echo $default; ?>');
+ jQuery('.gridlist-toggle #<?php echo $default; ?>').addClass('active');
+ }
+ </script>
+ <?php
+ }
}
$WC_List_Grid = new WC_List_Grid();
}
7 readme.txt
View
@@ -3,7 +3,7 @@ Contributors: jameskoster
Tags: woocommerce, grid, list, products, ecommerce
Requires at least: 3.3
Tested up to: 3.5
-Stable tag: 0.2.3
+Stable tag: 0.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -17,6 +17,8 @@ The list view arranges products in a vertical list and pulls in the excerpt to g
The grid view you will be familiar with as this is WooCommerce's default layout for product archives.
+The store owner can choose whether grid or list view be set as the default.
+
Please feel free to contribute on <a href="https://github.com/jameskoster/woocommerce-grid-list-toggle">github</a>.
== Installation ==
@@ -62,6 +64,9 @@ function remove_gridlist_styles() {
== Changelog ==
+= 0.3 - 30/01/2013 =
+* Added option to choose default view
+
= 0.2.3 - 28/01/2013 =
* Fixed active class bug on the toggle button
* Styled the star-rating in list view
Please sign in to comment.
Something went wrong with that request. Please try again.