Skip to content

Commit

Permalink
Merge 0fd7e14 into dd0f5a9
Browse files Browse the repository at this point in the history
  • Loading branch information
benhuson committed Jan 7, 2016
2 parents dd0f5a9 + 0fd7e14 commit fafcbfc
Show file tree
Hide file tree
Showing 10 changed files with 333 additions and 162 deletions.
5 changes: 5 additions & 0 deletions wp-shopping-cart.php
Expand Up @@ -87,6 +87,11 @@ public function _register_core_components( $components ) {
WPSC_FILE_PATH . '/wpsc-components/marketplace-core-v1/marketplace-core-v1.php'
);

$components['fancy-notifications']['fancy-notifications-v1'] = array(
'title' => __( 'Fancy Notifications v1', 'wpsc' ),
'includes' => WPSC_FILE_PATH . '/wpsc-components/fancy-notifications/fancy-notifications.php'
);

return $components;
}

Expand Down
41 changes: 41 additions & 0 deletions wpsc-components/fancy-notifications/css/fancy-notifications.css
@@ -0,0 +1,41 @@

/**
* WP eCommerce Fancy Notifications CSS
*/

#fancy_notification {
position: absolute;
top: 0;
left: 0;
background: #fff;
border: 4px solid #ccc;
display: none;
height: auto;
z-index: 9;
}

#fancy_notification #loading_animation {
display: none;
}

#fancy_notification #fancy_notification_content {
display: none;
width: 300px;
height: auto;
padding: 8px;
text-align: left;
margin: 0 !important;
}

#fancy_notification #fancy_notification_content span {
margin: 0 0 6px 0;
display: block;
font-weight: normal;
}

#fancy_notification #fancy_notification_content a {
display: block;
float: left;
margin-right: 6px;
margin-bottom: 3px;
}
128 changes: 128 additions & 0 deletions wpsc-components/fancy-notifications/fancy-notifications.php
@@ -0,0 +1,128 @@
<?php

/**
* WP eCommerce Fancy Notifications
*/

add_action( 'wp_enqueue_scripts', array( 'WPSC_Fancy_Notifications', 'enqueue_styles' ) );
add_action( 'wp_enqueue_scripts', array( 'WPSC_Fancy_Notifications', 'enqueue_scripts' ) );
add_action( 'wpsc_add_to_cart_button_form_begin', array( 'WPSC_Fancy_Notifications', 'add_fancy_notifications' ) );
add_action( 'wpsc_theme_footer', array( 'WPSC_Fancy_Notifications', 'fancy_notifications' ) );
add_filter( 'wpsc_add_to_cart_json_response', array( 'WPSC_Fancy_Notifications', 'wpsc_add_to_cart_json_response' ) );

/**
* WP eCommerce Fancy Notifications Class
*/
class WPSC_Fancy_Notifications {

/**
* Fancy Notifications
*
* Container HTML for fancy notifications.
*
* @param boolean $return Return output.
* @return string Output.
*/
public static function fancy_notifications( $return = false ) {

static $already_output = false;

if ( $already_output ) {
return '';
}

$output = '';
if ( 1 == get_option( 'fancy_notifications' ) ) {
$output .= '<div id="fancy_notification">';
$output .= ' <div id="loading_animation">';
$output .= ' <img id="fancy_notificationimage" title="' . esc_attr__( 'Loading', 'wpsc' ) . '" alt="' . esc_attr__( 'Loading', 'wpsc' ) . '" src="' . esc_url( wpsc_loading_animation_url() ) . '" />' . esc_html__( 'Updating', 'wpsc' ) . '...';
$output .= ' </div>';
$output .= ' <div id="fancy_notification_content"></div>';
$output .= '</div>';
}

$already_output = true;

if ( $return ) {
return $output;
}
echo $output;

}

/**
* Fancy Notification Content
*
* @param array $cart_messages Cart message.
* @return string Fancy notification content.
*/
public static function fancy_notification_content( $cart_messages ) {

$output = '';
foreach ( (array)$cart_messages as $cart_message ) {
$output .= '<span>' . $cart_message . '</span><br />';
}
$output .= sprintf( '<a href="%s" class="go_to_checkout">%s</a>', esc_url( get_option( 'shopping_cart_url' ) ), esc_html__( 'Go to Checkout', 'wpsc' ) );
$output .= sprintf( '<a href="#" onclick="jQuery( \'#fancy_notification\' ).css( \'display\', \'none\' ); return false;" class="continue_shopping">%s</a>', esc_html__( 'Continue Shopping', 'wpsc' ) );

return $output;

}

/**
* Add To Cart JSON Response
*
* Adds 'fancy_notification' content to JSON response.
*
* @param array $json_response JSON response.
* @return array Updated JSON response.
*/
public static function wpsc_add_to_cart_json_response( $json_response ) {

if ( is_numeric( $json_response['product_id'] ) && 1 == get_option( 'fancy_notifications' ) ) {
$json_response['fancy_notification'] = str_replace( array( "\n", "\r" ), array( '\n', '\r' ), self::fancy_notification_content( $json_response['cart_messages'] ) );
}

return $json_response;

}

/**
* Add Fancy Notifications
*/
public static function add_fancy_notifications() {

add_action( 'wp_footer', array( 'WPSC_Fancy_Notifications', 'fancy_notifications' ) );

}

/**
* Enqueue Styles
*/
public static function enqueue_styles() {

wp_enqueue_style( 'wpsc-fancy-notifications', self::plugin_url() . '/css/fancy-notifications.css', false, '1.0' );

}

/**
* Enqueue Scripts
*/
public static function enqueue_scripts() {

wp_enqueue_script( 'wpsc-fancy-notifications', self::plugin_url() . '/js/fancy-notifications.js', array( 'jquery' ), '1.0' );

}

/**
* Plugin URL
*
* @return string URL for fancy notifications directory.
*/
public static function plugin_url() {

return plugins_url( '', __FILE__ );

}

}
86 changes: 86 additions & 0 deletions wpsc-components/fancy-notifications/js/fancy-notifications.js
@@ -0,0 +1,86 @@

/**
* WP eCommerce Fancy Notifications JS
*/

var WPEC_Fancy_Notifications;

( function( $ ) {

WPEC_Fancy_Notifications = {

/**
* Move Fancy Notification element to end of HTML body.
*/
appendToBody : function() {

$( '#fancy_notification' ).appendTo( 'body' );

},

/**
* Fancy Notification: Show
*/
wpscAddToCart : function( e ) {

$( 'div.wpsc_loading_animation' ).css( 'visibility', 'hidden' );
WPEC_Fancy_Notifications.fancy_notification();

},

/**
* Fancy Notification: Hide
*/
wpscAddedToCart : function( e ) {

if ( ( e.response ) ) {
if ( e.response.hasOwnProperty( 'fancy_notification' ) && e.response.fancy_notification ) {
if ( $( '#fancy_notification_content' ) ) {
$( '#fancy_notification_content' ).html( e.response.fancy_notification );
$( '#loading_animation').css( 'display', 'none' );
$( '#fancy_notification_content' ).css( 'display', 'block' );
}
}
$( document ).trigger( { type : 'wpsc_fancy_notification', response : e.response } );
}

if ( $( '#fancy_notification' ).length > 0 ) {
$( '#loading_animation' ).css( 'display', 'none' );
}

},

/**
* Fancy Notification
*/
fancy_notification : function() {

var fancyNotificationEl = $( '#fancy_notification' );

if ( typeof WPSC_SHOW_FANCY_NOTIFICATION === 'undefined' ) {
WPSC_SHOW_FANCY_NOTIFICATION = true;
}

if ( ( WPSC_SHOW_FANCY_NOTIFICATION === true ) && ( fancyNotificationEl !== null ) ) {
fancyNotificationEl.css( {
display : 'block',
position : 'fixed',
left : ( $( window ).width() - fancyNotificationEl.outerWidth() ) / 2,
top : ( $( window ).height() - fancyNotificationEl.outerHeight() ) / 2
} );
$( '#loading_animation' ).css( 'display', 'block' );
$( '#fancy_notification_content' ).css( 'display', 'none' );
}

}

};

/**
* Event Handlers
*/
$( document ).on( 'ready', WPEC_Fancy_Notifications.appendToBody );
$( document ).on( 'wpscAddToCart', WPEC_Fancy_Notifications.wpscAddToCart );
$( document ).on( 'wpscAddedToCart', WPEC_Fancy_Notifications.wpscAddedToCart );

} ) ( jQuery );
24 changes: 8 additions & 16 deletions wpsc-components/theme-engine-v1/helpers/ajax.php
Expand Up @@ -183,13 +183,7 @@ function wpsc_add_to_cart() {

$output = _wpsc_ajax_get_cart( false, $cart_messages );

$json_response = $json_response + $output;

if ( is_numeric( $product_id ) && 1 == get_option( 'fancy_notifications' ) ) {
$json_response['fancy_notification'] = str_replace( array( "\n", "\r" ), array( '\n', '\r' ), fancy_notification_content( $cart_messages ) );
}

$json_response = apply_filters( 'wpsc_add_to_cart_json_response', $json_response );
$json_response = apply_filters( 'wpsc_add_to_cart_json_response', $json_response + $output );

die( json_encode( $json_response ) );
}
Expand Down Expand Up @@ -241,13 +235,16 @@ function wpsc_add_to_cart_button( $product_id, $return = false ) {
}
}

/* 19-02-09
* add to cart shortcode function used for shortcodes calls the function in
/**
* Add to cart shortcode function used for shortcodes calls the function in
* product_display_functions.php
*
* @since 19-02-2009
*
* Note: Really old legacy shortcode support for add to cart buttons.
* This isn't a proper WordPress shortcode!
*/

function add_to_cart_shortcode( $content = '' ) {
static $fancy_notification_output = false;
if ( ! in_the_loop() )
return $content;

Expand All @@ -257,11 +254,6 @@ function add_to_cart_shortcode( $content = '' ) {
$output = wpsc_add_to_cart_button( $product_id, true );
$content = str_replace( $original_string, $output, $content );
}

if ( ! $fancy_notification_output ) {
$content .= wpsc_fancy_notifications( true );
$fancy_notification_output = true;
}
}
return $content;
}
Expand Down
41 changes: 0 additions & 41 deletions wpsc-components/theme-engine-v1/helpers/product.php
@@ -1,6 +1,5 @@
<?php
add_action( 'save_post' , 'wpsc_refresh_page_urls', 10, 2 );
add_action( 'wpsc_theme_footer', 'wpsc_fancy_notifications' );

if ( get_option( 'wpsc_replace_page_title' ) == 1 ) {
add_filter( 'wp_title', 'wpsc_replace_wp_title', 10, 2 );
Expand Down Expand Up @@ -774,46 +773,6 @@ function wpsc_loading_animation_url() {
return apply_filters( 'wpsc_loading_animation_url', WPSC_CORE_THEME_URL . 'wpsc-images/indicator.gif' );
}

function fancy_notifications() {
return wpsc_fancy_notifications( true );
}
function wpsc_fancy_notifications( $return = false ) {
static $already_output = false;

if ( $already_output )
return '';

$output = "";
if ( get_option( 'fancy_notifications' ) == 1 ) {
$output = "";
$output .= "<div id='fancy_notification'>\n\r";
$output .= " <div id='loading_animation'>\n\r";
$output .= '<img id="fancy_notificationimage" title="' . esc_attr__( 'Loading', 'wp-e-commerce' ) . '" alt="' . esc_attr__( 'Loading', 'wp-e-commerce' ) . '" src="' . wpsc_loading_animation_url() . '" />' . __( 'Updating', 'wp-e-commerce' ) . "...\n\r";
$output .= " </div>\n\r";
$output .= " <div id='fancy_notification_content'>\n\r";
$output .= " </div>\n\r";
$output .= "</div>\n\r";
}

$already_output = true;

if ( $return )
return $output;
else
echo $output;
}

function fancy_notification_content( $cart_messages ) {
$siteurl = get_option( 'siteurl' );
$output = '';
foreach ( (array)$cart_messages as $cart_message ) {
$output .= "<span>" . $cart_message . "</span><br />";
}
$output .= "<a href='" . get_option( 'shopping_cart_url' ) . "' class='go_to_checkout'>" . __( 'Go to Checkout', 'wp-e-commerce' ) . "</a>";
$output .= "<a href='#' onclick='jQuery(\"#fancy_notification\").css(\"display\", \"none\"); return false;' class='continue_shopping'>" . __( 'Continue Shopping', 'wp-e-commerce' ) . "</a>";
return $output;
}

/*
* wpsc product url function, gets the URL of a product,
* Deprecated, all parameters past the first unused. use get_permalink
Expand Down

0 comments on commit fafcbfc

Please sign in to comment.