Skip to content

Commit

Permalink
[code-convention] [comment] Update some JS code convention and comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
swashata committed Oct 3, 2024
1 parent 9244b95 commit 99b858a
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 79 deletions.
56 changes: 28 additions & 28 deletions assets/scripts/jquery.form.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
// http://stackoverflow.com/questions/4583703/jquery-post-request-not-ajax
(function ($) {
$.extend({
form: function (url, data, method) {
if (method == null) method = 'POST';
if (data == null) data = {};
(function ( $ ) {
$.extend( {
form: function ( url, data, method ) {
if ( method == null ) method = 'POST';
if ( data == null ) data = {};

var form = $('<form>').attr({
var form = $( '<form>' ).attr( {
method: method,
action: url
}).css({
} ).css( {
display: 'none'
});
} );

var addData = function (name, data) {
if ($.isArray(data)) {
for (var i = 0; i < data.length; i++) {
var value = data[i];
addData(name + '[]', value);
var addData = function ( name, data ) {
if ( $.isArray( data ) ) {
for ( var i = 0; i < data.length; i++ ) {
var value = data[ i ];
addData( name + '[]', value );
}
} else if (typeof data === 'object') {
for (var key in data) {
if (data.hasOwnProperty(key)) {
addData(name + '[' + key + ']', data[key]);
} else if ( typeof data === 'object' ) {
for ( var key in data ) {
if ( data.hasOwnProperty( key ) ) {
addData( name + '[' + key + ']', data[ key ] );
}
}
} else if (data != null) {
form.append($('<input>').attr({
} else if ( data != null ) {
form.append( $( '<input>' ).attr( {
type : 'hidden',
name : String(name),
value: String(data)
}));
name : String( name ),
value: String( data )
} ) );
}
};

for (var key in data) {
if (data.hasOwnProperty(key)) {
addData(key, data[key]);
for ( var key in data ) {
if ( data.hasOwnProperty( key ) ) {
addData( key, data[ key ] );
}
}

return form.appendTo('body');
return form.appendTo( 'body' );
}
});
})(jQuery);
} );
} )( jQuery );
34 changes: 17 additions & 17 deletions includes/class-freemius.php
Original file line number Diff line number Diff line change
Expand Up @@ -1382,22 +1382,22 @@ function _run_garbage_collector() {
static function _handle_submenu_external_link() {
?>
<script type="text/javascript">
(function ($) {
$('.fs-submenu-item').each(function () {
var $this = $(this),
(function ( $ ) {
$( '.fs-submenu-item' ).each( function () {
var $this = $( this ),
$parent = $this.parent(),
externalLink = $this.data('fs-external-url'),
isOpensInNewTab = $this.data('fs-new-tab');
externalLink = $this.data( 'fs-external-url' ),
isOpensInNewTab = $this.data( 'fs-new-tab' );

if (externalLink) {
$parent.attr('href', externalLink);
if ( externalLink ) {
$parent.attr( 'href', externalLink );
}

if (isOpensInNewTab) {
$parent.attr({target: '_blank', rel: 'noopener noreferrer'});
if ( isOpensInNewTab ) {
$parent.attr( { target: '_blank', rel: 'noopener noreferrer' } );
}
});
})(jQuery);
} );
} )( jQuery );
</script>
<?php
}
Expand Down Expand Up @@ -21780,7 +21780,7 @@ function start_trial( $plan_name = false, $add_sticky_notice = false ) {
sprintf( $this->get_text_inline( 'Plan %s does not support a trial period.', 'plan-x-no-trial' ), $plan_name ),
$oops_text,
'error',
$add_sticky_notice
$add_sticky_notice
);

return false;
Expand All @@ -21792,7 +21792,7 @@ function start_trial( $plan_name = false, $add_sticky_notice = false ) {
sprintf( $this->get_text_inline( 'None of the %s\'s plans supports a trial period.', 'no-trials' ), $this->_module_type ),
$oops_text,
'error',
$add_sticky_notice
$add_sticky_notice
);

return false;
Expand All @@ -21810,7 +21810,7 @@ function start_trial( $plan_name = false, $add_sticky_notice = false ) {
$trial_params['trial_token'] = FS_Security::instance()->get_trial_token(
$this->get_plugin(),
$plan,
$trial_params['trial_timestamp']
$trial_params['trial_timestamp']
);
}

Expand All @@ -21823,7 +21823,7 @@ function start_trial( $plan_name = false, $add_sticky_notice = false ) {
$this->get_api_error_message( $trial ),
$oops_text,
'error',
$add_sticky_notice
$add_sticky_notice
);

return false;
Expand Down Expand Up @@ -23307,8 +23307,8 @@ function _addons_page_render() {
function _pricing_page_render() {
$this->_logger->entrance();

fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
fs_enqueue_local_style( 'fs_checkout', '/admin/checkout.css' );
fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
fs_enqueue_local_style( 'fs_checkout', '/admin/checkout.css' );

$vars = array( 'id' => $this->_module_id );

Expand Down
4 changes: 2 additions & 2 deletions templates/checkout.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/**
* @package Freemius
* @copyright Copyright (c) 2015, Freemius, Inc.
* @copyright Copyright (c) 2024, Freemius, Inc.
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
* @since 1.0.3
* @since 2.9.0
*/

/**
Expand Down
15 changes: 6 additions & 9 deletions templates/checkout/frame.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@
* of the SDK is relevant both for plugins and themes, for obvious reasons,
* we only develop and maintain one code base.
*
* This code (and page) will not run for wp.org themes (only plugins).
* This code (and page) will not run for wp.org themes and plugins. It will
* run only for premium version of the plugin/theme that is using the SDK.
*
* In addition, this page loads an i-frame. We intentionally named it 'frame'
* In addition, when this page loads an i-frame. We intentionally named it 'frame'
* so it will pass the "Theme Check" that is looking for the string "i" . "frame".
*
* UPDATE:
* After ongoing conversations with the WordPress.org TRT we received
* an official approval for including i-frames in the theme's WP Admin setting's
* page tab (the SDK will never add any i-frames on the sitefront). i-frames
* were never against the guidelines, but we wanted to get the team's blessings
* before we move forward. For the record, I got the final approval from
* Ulrich Pogson (@grapplerulrich), a team lead at the TRT during WordCamp
* Europe 2017 (June 16th, 2017).
* Following request from the wp.org plugin review team, we have stopped
* embedding the checkout inside an i-frame for wp.org hosted free version
* of plugins and themes. Now they will be redirected instead.
*
* If you have any questions or need clarifications, please don't hesitate
* pinging me on slack, my username is @svovaf.
Expand Down
32 changes: 16 additions & 16 deletions templates/checkout/process-redirect.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/**
* @package Freemius
* @copyright Copyright (c) 2015, Freemius, Inc.
* @copyright Copyright (c) 2024, Freemius, Inc.
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
* @since 1.0.3
* @since 2.9.0
*/

if ( ! defined( 'ABSPATH' ) ) {
Expand Down Expand Up @@ -45,25 +45,25 @@

<script type="text/javascript">
jQuery(function ($) {
var $loader = $('.fs-checkout-process-redirect .fs-ajax-loader'),
action = '<?php echo esc_js( $action ); ?>',
var $loader = $( '.fs-checkout-process-redirect .fs-ajax-loader' ),
action = <?php echo wp_json_encode( $action ); ?>,
data = <?php echo wp_json_encode( $data ); ?>;

$loader.show();

switch (action) {
switch ( action ) {
case 'install':
processInstall(data);
processInstall( data );
break;
case 'pending_activation':
processPendingActivation(data);
processPendingActivation( data );
break;
default:
syncLicense(data);
syncLicense( data );
break;
}

function processInstall(data) {
function processInstall( data ) {
var requestData = {
user_id : data.user.id,
user_secret_key : data.user.secret_key,
Expand All @@ -73,30 +73,30 @@ function processInstall(data) {
install_public_key: data.install.public_key
};

if (true === data.auto_install)
if ( true === data.auto_install )
requestData.auto_install = true;

// Post data to activation URL.
$.form('<?php echo $fs_checkout->get_install_url( $fs, $plugin_id ); ?>', requestData).submit();
$.form( '<?php echo $fs_checkout->get_install_url( $fs, $plugin_id ); ?>', requestData ).submit();
}

function processPendingActivation(data) {
function processPendingActivation( data ) {
var requestData = {
user_email : data.user_email,
support_email_address: data.support_email_address
};

if (true === data.auto_install)
if ( true === data.auto_install )
requestData.auto_install = true;

$.form('<?php echo $fs_checkout->get_pending_activation_url( $fs, $plugin_id ); ?>', requestData).submit();
$.form( '<?php echo $fs_checkout->get_pending_activation_url( $fs, $plugin_id ); ?>', requestData ).submit();
}

function syncLicense(data) {
var redirectUrl = new URL(<?php echo wp_json_encode( $fs->_get_sync_license_url( $plugin_id ) ); ?>);
var redirectUrl = new URL( <?php echo wp_json_encode( $fs->_get_sync_license_url( $plugin_id ) ); ?> );

if (true === data.auto_install) {
redirectUrl.searchParams.set('auto_install', 'true');
redirectUrl.searchParams.set( 'auto_install', 'true' );
}

window.location.href = redirectUrl.toString();
Expand Down
8 changes: 4 additions & 4 deletions templates/checkout/redirect.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/**
* @package Freemius
* @copyright Copyright (c) 2015, Freemius, Inc.
* @copyright Copyright (c) 2024, Freemius, Inc.
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
* @since 1.0.3
* @since 2.9.0
*/

if ( ! defined( 'ABSPATH' ) ) {
Expand Down Expand Up @@ -93,8 +93,8 @@
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function ($) {
$('.fs-checkout-process-redirect .fs-ajax-loader').show();
jQuery( document ).ready( function ( $ ) {
$( '.fs-checkout-process-redirect .fs-ajax-loader' ).show();
window.location.href = <?php echo wp_json_encode($redirect_url ); ?>;
});
</script>
Expand Down
7 changes: 4 additions & 3 deletions templates/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
* of the SDK is relevant both for plugins and themes, for obvious reasons,
* we only develop and maintain one code base.
*
* This code (and page) will not run for wp.org themes (only plugins).
* This code (and page) will not run for wp.org themes or plugins. It will
* run only for premium version of the plugin/theme that is using the SDK.
*
* In addition, this page loads an i-frame. We intentionally named it 'frame'
* In addition, when this page loads an i-frame. We intentionally named it 'frame'
* so it will pass the "Theme Check" that is looking for the string "i" . "frame".
*
* UPDATE:
Expand Down Expand Up @@ -55,7 +56,7 @@
$fs = freemius( $VARS['id'] );
$slug = $fs->get_slug();

$query_params = FS_Contact_Form_Manager::instance()->get_query_params( $fs );
$query_params = FS_Contact_Form_Manager::instance()->get_query_params( $fs );

$view_params = array(
'id' => $VARS['id'],
Expand Down

0 comments on commit 99b858a

Please sign in to comment.