Use drupal_add_js($var, 'setting') instead of drupal_add_js('js_var = ' . $php_var . ';', 'inline')
KevinHerrington - September 22, 2009 - 18:38
| Project: | UC Store Credit |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | task |
| Priority: | minor |
| Assigned: | Unassigned |
| Status: | active |
Description
Instead of:
drupal_add_js('uc_store_credit_hide_method = '. variable_get('uc_store_credit_hide_method', 0) .';', 'inline');
drupal_add_js('uc_store_credit_user_total = '. uc_store_credit_user_total() .';', 'inline');
drupal_add_js('uc_store_credit_cart_total = '. uc_store_credit_cart_total() .';', 'inline');
drupal_add_js('uc_store_credit_line_item_rate = '. variable_get('uc_store_credit_conversion_rate', 100) .';', 'inline');
drupal_add_js("uc_store_credit_subtotal_string = '". t('Subtotal') ."';", 'inline');Use:
drupal_add_js(
array(
'uc_store_credit' => array(
'hide_method' => variable_get('uc_store_credit_hide_method', 0),
'user_total' => uc_store_credit_user_total(),
'cart_total' => uc_store_credit_cart_total(),
'line_item_rate' => variable_get('uc_store_credit_conversion_rate', 100),
'subtotal_string' => t('Subtotal'),
),
),
'setting'
);Your variables are then available as Drupal.settings.uc_store_credit.hide_method instead.
