Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
333 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
wpsc-components/fancy-notifications/css/fancy-notifications.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
128
wpsc-components/fancy-notifications/fancy-notifications.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
86
wpsc-components/fancy-notifications/js/fancy-notifications.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.