Skip to content

Commit

Permalink
0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskoster committed Jan 30, 2013
1 parent a31fc5f commit 9cb514f
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 13 deletions.
5 changes: 0 additions & 5 deletions assets/js/jquery.gridlistview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion assets/js/jquery.gridlistview.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 66 additions & 6 deletions grid-list-toggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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
}
Expand All @@ -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();
}
Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 ==
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9cb514f

Please sign in to comment.