Skip to content

Commit

Permalink
Fix reference for this
Browse files Browse the repository at this point in the history
Optimize assets loading in frontend editor and backend editor
Fix loading in frontend editor
Use save_always for checkbox without STD
Optimize performance with registering param type only when needed
Fix codestyle issues
  • Loading branch information
pavelthq committed Oct 24, 2016
1 parent ad9d44e commit 68177f8
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 47 deletions.
68 changes: 35 additions & 33 deletions assets/vc-custom-checkbox.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
(function ( $ ) {
/*
Class used in edit form and editor models to save/render shortcode
*/
vc.atts.custom_checkbox = {
/**
* Used to save multiple values in single string for saving/parsing/opening
* @param param
* @returns {string}
$( function () {
/*
Class used in edit form and editor models to save/render param type
*/
parse: function ( param ) {
var arr, newValue;
window.vc.atts.custom_checkbox = {
/**
* Used to save multiple values in single string for saving/parsing/opening
* @param param
* @returns {string}
*/
parse: function ( param ) {
var arr, newValue;

arr = [];
newValue = '';
$( 'input[name=' + param.param_name + ']', this.content() ).each( function () {
var self;
arr = [];
newValue = '';
$( 'input[name=' + param.param_name + ']', this.content() ).each( function () {
var self;

self = $( this );
if ( this.checked ) {
arr.push( self.attr( 'value' ) );
self = $( this );
if ( this.checked ) {
arr.push( self.attr( 'value' ) );
}
} );
if ( 0 < arr.length ) {
newValue = arr.join( ',' );
}
} );
if ( 0 < arr.length ) {
newValue = arr.join( ',' );
return newValue;
},
/**
* Used in shortcode saving
* Default: '' empty (unchecked)
* Can be overwritten by 'std'
* @param param
* @returns {string}
*/
defaults: function ( param ) {
return ''; // needed for saving - without this default value for param will be first value in array
}
return newValue;
},
/**
* Used in shortcode saving
* Default: '' empty (unchecked)
* Can be overwritten by 'std'
* @param param
* @returns {string}
*/
defaults: function ( param ) {
return ''; // needed for saving - without this default value for param will be first value in array
}
};
};
} );
})( window.jQuery );
22 changes: 15 additions & 7 deletions param/class-vc-custom-checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,34 @@ class VcCustomCheckbox {

public function __construct() {
add_action( 'vc_load_default_params', array(
&$this,
$this,
'vc_load_vc_custom_checkbox_param',
) );

add_action( 'vc_backend_editor_render', array(
&$this,
'vc_enqueue_editor_scripts_befe',
add_action( 'vc_backend_editor_enqueue_js_css', array(
$this,
'vc_enqueue_editor_scripts_be',
) );
add_action( 'vc_frontend_editor_enqueue_js_css', array(
$this,
'vc_enqueue_editor_scripts_fe',
) );
}

public function vc_enqueue_editor_scripts_be() {
wp_enqueue_script( 'vc-custom-checbox-fe', preg_replace( '/\s/', '%20', plugins_url( 'assets/vc-custom-checkbox.js', vc_custom_checkbox_path() ) ) );
}

public function vc_enqueue_editor_scripts_befe() {
wp_enqueue_script( 'vc-custom-checbox-befe', preg_replace( '/\s/', '%20', plugins_url( 'assets/vc-custom-checkbox.js', vc_custom_checkbox_path() ) ) );
public function vc_enqueue_editor_scripts_fe() {
wp_enqueue_script( 'vc-custom-checbox-fe', preg_replace( '/\s/', '%20', plugins_url( 'assets/vc-custom-checkbox.js', vc_custom_checkbox_path() ) ) );
}

/**
* Add custom param to system
*/
public function vc_load_vc_custom_checkbox_param() {
vc_add_shortcode_param( 'custom_checkbox', array(
&$this,
$this,
'vc_custom_checkbox_form_field',
) );
}
Expand Down
17 changes: 15 additions & 2 deletions shortcode/shortcode-vc-test-custom-checkbox-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
'type' => 'custom_checkbox',
'heading' => __( 'Checked1', 'js_composer' ),
'param_name' => 'custom_checkbox',
'std' => '', // default unchecked
'std' => '',
// default unchecked
'value' => array(
__( 'Test1', 'js_composer' ) => 'Test1',
__( 'Test2', 'js_composer' ) => 'Test2',
__( 'Test3', 'js_composer' ) => 'Test3',
),
),
// No STD means that default is first value in array
// No STD means that default is first value in array, and if empty it will take first as Default value
array(
'type' => 'custom_checkbox',
'heading' => __( 'Checked2', 'js_composer' ),
Expand All @@ -28,6 +29,18 @@
__( 'Test3', 'js_composer' ) => 'Test3',
),
),
array(
'type' => 'custom_checkbox',
'heading' => __( 'Checked2-with save always', 'js_composer' ),
'param_name' => 'custom_checkbox2_save_always',
'value' => array(
__( 'Test1', 'js_composer' ) => 'Test1',
__( 'Test2', 'js_composer' ) => 'Test2',
__( 'Test3', 'js_composer' ) => 'Test3',
),
'save_always' => true,
// This will allow to force save empty value (otherwise in case if emtpy it will take first value in array)
),
// Std='Test2' - means that default is Test2 checked
array(
'type' => 'custom_checkbox',
Expand Down
10 changes: 5 additions & 5 deletions vc-custom-checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Vc Custom Checkbox
Plugin URI: http://vc.wpbakery.com/
Description: Custom checkbox Visual Composer on Steroids
Version: 1.0
Version: 1.1
Author: WPBakery
Author URI: http://wpbakery.com
License: http://codecanyon.net/licenses
Expand All @@ -12,16 +12,16 @@
die( '' ); // Don't call directly
}

add_action( 'vc_after_init', 'vc_custom_checkbox_init' );
add_action( 'vc_build_admin_page', 'vc_custom_checkbox_init' );
add_action( 'vc_after_init', 'vc_custom_checkbox_shortcode' );
function vc_custom_checkbox_init() {
require_once "param/class-vc-custom-checkbox.php";
require_once 'param/class-vc-custom-checkbox.php';
$checkbox = new VcCustomCheckbox();
}

function vc_custom_checkbox_shortcode() {
require_once "shortcode/shortcode-vc-test-custom-checkbox-lean-map.php";
require_once "shortcode/shortcode-vc-test-custom-checkbox-class.php";
require_once 'shortcode/shortcode-vc-test-custom-checkbox-lean-map.php';
require_once 'shortcode/shortcode-vc-test-custom-checkbox-class.php';
}

function vc_custom_checkbox_path() {
Expand Down

0 comments on commit 68177f8

Please sign in to comment.