Skip to content

Commit

Permalink
* New: Script Optimization - Give now only loads one minified JS scri…
Browse files Browse the repository at this point in the history
…pt and one CSS file to keep load times fast and minimize footprint

* New: Using Grunt to generate POT file now for much more timely and accurate translations
* Fix: Incorrect amount formatting when currency separators set to "," for both thousands and decimals. @see: #150
  • Loading branch information
devin committed Jun 3, 2015
1 parent 47fd70c commit b2e7966
Show file tree
Hide file tree
Showing 8 changed files with 1,305 additions and 1,217 deletions.
128 changes: 128 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
module.exports = function ( grunt ) {

// Load multiple grunt tasks using globbing patterns
require( 'load-grunt-tasks' )( grunt );

// Project configuration.
grunt.initConfig( {
pkg: grunt.file.readJSON( 'package.json' ),

checktextdomain: {
options: {
text_domain : 'give',
create_report_file: true,
keywords : [
'__:1,2d',
'_e:1,2d',
'_x:1,2c,3d',
'esc_html__:1,2d',
'esc_html_e:1,2d',
'esc_html_x:1,2c,3d',
'esc_attr__:1,2d',
'esc_attr_e:1,2d',
'esc_attr_x:1,2c,3d',
'_ex:1,2c,3d',
'_n:1,2,3,4d',
'_nx:1,2,4c,5d',
'_n_noop:1,2,3d',
'_nx_noop:1,2,3c,4d',
' __ngettext:1,2,3d',
'__ngettext_noop:1,2,3d',
'_c:1,2d',
'_nc:1,2,4c,5d'
]
},
files : {
src : [
'**/*.php', // Include all files
'!node_modules/**', // Exclude node_modules/
'!build/.*'// Exclude build/
],
expand: true
}
},

makepot: {
target: {
options: {
domainPath : '/languages/', // Where to save the POT file.
exclude : ['includes/libraries/.*', '.js'],
mainFile : 'give.php', // Main project file.
potFilename : 'give.pot', // Name of the POT file.
potHeaders : {
poedit : true, // Includes common Poedit headers.
'x-poedit-keywordslist': true // Include a list of all possible gettext functions.
},
type : 'wp-plugin', // Type of project (wp-plugin or wp-theme).
updateTimestamp: true, // Whether the POT-Creation-Date should be updated without other changes.
processPot : function ( pot, options ) {
pot.headers['report-msgid-bugs-to'] = 'https://givewp.com/';
pot.headers['last-translator'] = 'WP-Translations (http://wp-translations.org/)';
pot.headers['language-team'] = 'WP-Translations <wpt@wp-translations.org>';
pot.headers['language'] = 'en_US';
var translation, // Exclude meta data from pot.
excluded_meta = [
'Plugin Name of the plugin/theme',
'Plugin URI of the plugin/theme',
'Author of the plugin/theme',
'Author URI of the plugin/theme'
];
for ( translation in pot.translations[''] ) {
if ( 'undefined' !== typeof pot.translations[''][translation].comments.extracted ) {
if ( excluded_meta.indexOf( pot.translations[''][translation].comments.extracted ) >= 0 ) {
console.log( 'Excluded meta: ' + pot.translations[''][translation].comments.extracted );
delete pot.translations[''][translation];
}
}
}
return pot;
}
}
}
},

exec: {
txpull : { // Pull Transifex translation - grunt exec:txpull
cmd: 'tx pull -a -f --minimum-perc=1' // Change the percentage with --minimum-perc=yourvalue
},
txpush_s: { // Push pot to Transifex - grunt exec:txpush_s
cmd: 'tx push -s'
}
},

dirs: {
lang: 'languages'
},

potomo: {
dist: {
options: {
poDel: true
},
files : [{
expand: true,
cwd : '<%= dirs.lang %>',
src : ['*.po'],
dest : '<%= dirs.lang %>',
ext : '.mo',
nonull: true
}]
}
}


} );

// Default task. - grunt makepot
grunt.registerTask( 'default', 'makepot' );

// Makepot and push it on Transifex task(s).
grunt.registerTask( 'tx-push', ['makepot', 'exec:txpush_s'] );

// Pull from Transifex and create .mo task(s).
grunt.registerTask( 'tx-pull', ['exec:txpull', 'potomo'] );

// Build task(s).
// grunt.registerTask( 'build', ['clean', 'copy', 'compress'] );

};
13 changes: 13 additions & 0 deletions assets/js/frontend/give.all.min.js

Large diffs are not rendered by default.

30 changes: 25 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ var gulp = require( 'gulp' ),
/* Paths
------------------------------------- */
var source_paths = {
admin_styles : ['./assets/scss/**/give-admin.scss'],
frontend_styles: ['./assets/scss/frontend/give-frontend.scss'],
scripts : ['./assets/js/**/*.js', '!./assets/js/**/*.min.js']
admin_styles : ['./assets/scss/**/give-admin.scss'],
frontend_styles : ['./assets/scss/frontend/give-frontend.scss'],
scripts : ['./assets/js/**/*.js', '!./assets/js/**/*.min.js'],
frontend_scripts: [
'./assets/js/plugins/jQuery.blockUI.min.js',
'./assets/js/plugins/jquery.qtip.min.js',
'./assets/js/plugins/jquery.maskMoney.min.js',
'./assets/js/plugins/give-magnific.min.js',
'./assets/js/frontend/*.min.js' //Frontend scripts need to be loaded last
]
};

/* Admin SCSS Task
Expand All @@ -38,7 +45,7 @@ gulp.task( 'admin_styles', function () {
errLogToConsole: true
} ) )
.pipe( rename( 'give-admin.css' ) )
.pipe( sourcemaps.write('.') )
.pipe( sourcemaps.write( '.' ) )
.pipe( gulp.dest( './assets/css' ) )
.pipe( rename( 'give-admin.min.css' ) )
.pipe( minifyCSS() )
Expand Down Expand Up @@ -90,6 +97,19 @@ gulp.task( 'scripts', function () {
.pipe( livereload() );
} );

gulp.task( 'concat_scripts', function () {
return gulp.src( source_paths.frontend_scripts )
.pipe( uglify( {
preserveComments: 'all'
} ) )
.pipe( concat( 'give.all.min.js' ) ) //Add all compressed frontend JS scripts into one minified file for production
.pipe( gulp.dest( 'assets/js/frontend' ) )
.pipe( notify( {
message: 'Concat scripts task complete!',
onLast : true //only notify on completion of task (prevents multiple notifications per file)
} ) )
} );

/* Watch Files For Changes
------------------------------------- */
gulp.task( 'watch', function () {
Expand Down Expand Up @@ -129,6 +149,6 @@ var onError = function ( err ) {
/* Default Gulp task
------------------------------------- */
gulp.task( 'default', function () {
gulp.start( 'admin_styles', 'frontend_styles', 'scripts', 'watch' );
gulp.start( 'admin_styles', 'frontend_styles', 'scripts', 'concat_scripts', 'watch' );
notify( {message: 'Default task complete'} )
} );
47 changes: 24 additions & 23 deletions includes/gateways/offline-donations.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,14 @@ function give_offline_process_payment( $purchase_data ) {
*
* @description Sends a notice to the donor with offline instructions; can be customized per form
*
* @param int $payment_id
*
* @since 1.0
* @return void
*/
function give_offline_send_donor_instructions( $payment_id = 0 ) {

$payment_data = give_get_payment_meta( $payment_id );
$payment_data = give_get_payment_meta( $payment_id );
$post_offline_customization_option = get_post_meta( $payment_data['form_id'], '_give_customize_offline_donations', true );

//Customize email content depending on whether the single form has been customized
Expand All @@ -153,7 +155,6 @@ function give_offline_send_donor_instructions( $payment_id = 0 ) {
$email_content = get_post_meta( $payment_data['form_id'], '_give_offline_donation_email', true );
}


$from_name = give_get_option( 'from_name', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) );
$from_name = apply_filters( 'give_purchase_from_name', $from_name, $payment_id, $payment_data );

Expand Down Expand Up @@ -268,39 +269,39 @@ function give_offline_add_settings( $settings ) {
),
),
array(
'name' => __( 'Request Billing Information', 'give' ),
'desc' => __( 'This option will enable the billing details section for this form\'s offline donation payment gateway. The fieldset will appear above the offline donation instructions.', 'give' ),
'id' => $prefix . 'offline_donation_enable_billing_fields_single',
'name' => __( 'Request Billing Information', 'give' ),
'desc' => __( 'This option will enable the billing details section for this form\'s offline donation payment gateway. The fieldset will appear above the offline donation instructions.', 'give' ),
'id' => $prefix . 'offline_donation_enable_billing_fields_single',
'row_classes' => 'give-subfield',
'type' => 'checkbox'
'type' => 'checkbox'
),
array(
'id' => $prefix . 'offline_checkout_notes',
'name' => __( 'Offline Donation Instructions', 'give' ),
'desc' => __( 'Enter the instructions you want to display to the donor during the donation process. Most likely this would include important information like mailing address and who to make the check out to.', 'give' ),
'default' => give_get_default_offline_donation_content(),
'type' => 'wysiwyg',
'id' => $prefix . 'offline_checkout_notes',
'name' => __( 'Offline Donation Instructions', 'give' ),
'desc' => __( 'Enter the instructions you want to display to the donor during the donation process. Most likely this would include important information like mailing address and who to make the check out to.', 'give' ),
'default' => give_get_default_offline_donation_content(),
'type' => 'wysiwyg',
'row_classes' => 'give-subfield',
'options' => array(
'options' => array(
'textarea_rows' => 6,
)
),
array(
'id' => $prefix . 'offline_donation_subject',
'name' => __( 'Offline Donation Email Instructions Subject', 'give' ),
'desc' => __( 'Enter the subject line for the donation receipt email.', 'give' ),
'default' => __( '{donation} - Offline Donation Instructions', 'give' ),
'id' => $prefix . 'offline_donation_subject',
'name' => __( 'Offline Donation Email Instructions Subject', 'give' ),
'desc' => __( 'Enter the subject line for the donation receipt email.', 'give' ),
'default' => __( '{donation} - Offline Donation Instructions', 'give' ),
'row_classes' => 'give-subfield',
'type' => 'text'
'type' => 'text'
),
array(
'id' => $prefix . 'offline_donation_email',
'name' => __( 'Offline Donation Email Instructions', 'give' ),
'desc' => __( 'Enter the instructions you want emailed to the donor after they have submitted the donation form. Most likely this would include important information like mailing address and who to make the check out to.', 'give' ),
'default' => give_get_default_offline_donation_email_content(),
'type' => 'wysiwyg',
'id' => $prefix . 'offline_donation_email',
'name' => __( 'Offline Donation Email Instructions', 'give' ),
'desc' => __( 'Enter the instructions you want emailed to the donor after they have submitted the donation form. Most likely this would include important information like mailing address and who to make the check out to.', 'give' ),
'default' => give_get_default_offline_donation_email_content(),
'type' => 'wysiwyg',
'row_classes' => 'give-subfield',
'options' => array(
'options' => array(
'textarea_rows' => 6,
)
)
Expand Down
81 changes: 51 additions & 30 deletions includes/scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,16 @@
*/
function give_load_scripts() {

global $give_options, $post;
global $give_options;

$js_dir = GIVE_PLUGIN_URL . 'assets/js/frontend/';
$js_plugins = GIVE_PLUGIN_URL . 'assets/js/plugins/';

// Use minified libraries if SCRIPT_DEBUG is turned off
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';

if ( give_is_cc_verify_enabled() ) {
wp_enqueue_script( 'give-cc-validator', $js_plugins . 'jquery.creditCardValidator' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION );
}

wp_enqueue_script( 'give-blockui', $js_plugins . 'jquery.blockUI' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION );
wp_enqueue_script( 'give-qtip', $js_plugins . 'jquery.qtip' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION );
wp_enqueue_script( 'give-mask-money', $js_plugins . 'jquery.maskMoney' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION );
wp_enqueue_script( 'give-magnific', $js_plugins . 'give-magnific' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION );
wp_enqueue_script( 'give-checkout-global', $js_dir . 'give-checkout-global' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION );
wp_localize_script( 'give-checkout-global', 'give_global_vars', array(
//Localize / PHP to AJAX vars
$localize_give_checkout = apply_filters( 'give_global_script_vars', array(
'ajaxurl' => give_get_ajax_url(),
'checkout_nonce' => wp_create_nonce( 'give_checkout_nonce' ),
'currency_sign' => give_currency_filter( '' ),
Expand All @@ -55,26 +47,55 @@ function give_load_scripts() {
'purchase_loading' => __( 'Please Wait...', 'give' ),
'give_version' => GIVE_VERSION
) );
$localize_give_ajax = apply_filters( 'give_global_ajax_vars', array(
'ajaxurl' => give_get_ajax_url(),
'position_in_cart' => isset( $position ) ? $position : - 1,
'loading' => __( 'Loading', 'give' ),
// General loading message
'select_option' => __( 'Please select an option', 'give' ),
// Variable pricing error with multi-purchase option enabled
'ajax_loader' => set_url_scheme( apply_filters( 'give_ajax_preloader_img', GIVE_PLUGIN_URL . 'assets/images/spinner-2x.gif' ), 'relative' ),
// Ajax loading image
'default_gateway' => give_get_default_gateway( null ),
'permalinks' => get_option( 'permalink_structure' ) ? '1' : '0'
) );


//DEBUG is On
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {

if ( give_is_cc_verify_enabled() ) {
wp_enqueue_script( 'give-cc-validator', $js_plugins . 'jquery.creditCardValidator' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION );
}

wp_enqueue_script( 'give-blockui', $js_plugins . 'jquery.blockUI' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION );
wp_enqueue_script( 'give-qtip', $js_plugins . 'jquery.qtip' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION );
wp_enqueue_script( 'give-mask-money', $js_plugins . 'jquery.maskMoney' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION );
wp_enqueue_script( 'give-magnific', $js_plugins . 'give-magnific' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION );
wp_enqueue_script( 'give-checkout-global', $js_dir . 'give-checkout-global' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION );

//General scripts
wp_enqueue_script( 'give-scripts', $js_dir . 'give' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION );

// Load AJAX scripts, if enabled
wp_enqueue_script( 'give-ajax', $js_dir . 'give-ajax' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION );

//Localize / Pass AJAX vars from PHP
wp_localize_script( 'give-checkout-global', 'give_global_vars', $localize_give_checkout );
wp_localize_script( 'give-ajax', 'give_scripts', $localize_give_ajax );


} else {

//DEBUG is OFF (one JS file to rule them all!)
wp_enqueue_script( 'give', $js_dir . 'give.all.min.js', array( 'jquery' ), GIVE_VERSION );

//Localize / Pass AJAX vars from PHP
wp_localize_script( 'give', 'give_global_vars', $localize_give_checkout );
wp_localize_script( 'give', 'give_scripts', $localize_give_ajax );

}

//General scripts
wp_enqueue_script( 'give-scripts', $js_dir . 'give' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION );

// Load AJAX scripts, if enabled
wp_enqueue_script( 'give-ajax', $js_dir . 'give-ajax' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION );
wp_localize_script( 'give-ajax', 'give_scripts', apply_filters( 'give_global_script_vars', array(
'ajaxurl' => give_get_ajax_url(),
'position_in_cart' => isset( $position ) ? $position : - 1,
'loading' => __( 'Loading', 'give' ),
// General loading message
'select_option' => __( 'Please select an option', 'give' ),
// Variable pricing error with multi-purchase option enabled
'ajax_loader' => set_url_scheme( apply_filters( 'give_ajax_preloader_img', GIVE_PLUGIN_URL . 'assets/images/spinner-2x.gif' ), 'relative' ),
// Ajax loading image
'default_gateway' => give_get_default_gateway( null ),
'permalinks' => get_option( 'permalink_structure' ) ? '1' : '0'
)
)
);

}

Expand Down
Loading

0 comments on commit b2e7966

Please sign in to comment.