Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #258 from funkedgeek/master

Refactored cloning
  • Loading branch information...
commit cdfc1cc9aceb4c50be698661a30cc328b4e3832a 2 parents f8f2297 + e8d1a3b
@rilwis authored
View
26 js/clone.js
@@ -25,31 +25,15 @@ jQuery( document ).ready( function( $ )
// Toggle remove buttons
toggle_remove_buttons( $input );
-
- // Fix color picker
- if ( 'function' === typeof rwmb_update_color_picker )
- rwmb_update_color_picker();
-
- // Fix date picker
- if ( 'function' === typeof rwmb_update_date_picker )
- rwmb_update_date_picker();
-
- // Fix time picker
- if ( 'function' === typeof rwmb_update_time_picker )
- rwmb_update_time_picker();
-
- // Fix datetime picker
- if ( 'function' === typeof rwmb_update_datetime_picker )
- rwmb_update_datetime_picker();
-
- // Fix select_advanced
- if ( 'function' === typeof rwmb_update_select_advanced )
- rwmb_update_select_advanced();
+
+ //Trigger custom clone event
+ $input.trigger( 'clone' );
}
// Add more clones
- $( '.add-clone' ).on( 'click', function()
+ $( '.add-clone' ).on( 'click', function( e )
{
+ e.stopPropagation();
var $input = $( this ).parents( '.rwmb-input' ),
$clone_group = $( this ).parents( '.rwmb-field' ).attr( "clone-group" );
View
36 js/color.js
@@ -2,25 +2,12 @@
* Update color picker element
* Used for static & dynamic added elements (when clone)
*/
-function rwmb_update_color_picker()
-{
- var $ = jQuery;
- $( '.rwmb-color-picker' ).each( function()
- {
- var $this = $( this ),
- $input = $this.siblings( 'input.rwmb-color' );
-
- // Make sure the value is displayed
- if ( !$input.val() )
- $input.val( '#' );
-
- $this.farbtastic( $input );
- } );
-}
-
jQuery( document ).ready( function( $ )
{
- $( '.rwmb-input' ).on( 'focus', '.rwmb-color', function()
+
+ $( ':input.rwmb-color' ).each( rwmb_update_color_picker );
+ $( '.rwmb-input' ).on( 'clone', ':input.rwmb-color', rwmb_update_color_picker )
+ .on( 'focus', '.rwmb-color', function()
{
$( this ).siblings( '.rwmb-color-picker' ).show();
return false;
@@ -29,7 +16,18 @@ jQuery( document ).ready( function( $ )
$( this ).siblings( '.rwmb-color-picker' ).hide();
return false;
} );
+
+ function rwmb_update_color_picker()
+ {
+ var $this = $( this ),
+ $color_picker = $this.siblings( '.rwmb-color-picker' );
+
+ // Make sure the value is displayed
+ if ( !$this.val() )
+ $this.val( '#' );
+
+ $color_picker.farbtastic( $this );
+
+ }
-
- rwmb_update_color_picker();
} );
View
18 js/date.js
@@ -2,22 +2,18 @@
* Update date picker element
* Used for static & dynamic added elements (when clone)
*/
-function rwmb_update_date_picker()
+jQuery( document ).ready( function( $ )
{
- var $ = jQuery;
-
- $( '.rwmb-date' ).each( function()
+ $( ':input.rwmb-date' ).each( rwmb_update_date_picker );
+ $( '.rwmb-input' ).on( 'clone', ':input.rwmb-date', rwmb_update_date_picker );
+
+ function rwmb_update_date_picker()
{
var $this = $( this ),
options = $this.data( 'options' );
-
+
$this.siblings( '.ui-datepicker-append' ).remove(); // Remove appended text
$this.removeClass( 'hasDatepicker' ).attr( 'id', '' ).datepicker( options );
- } );
-}
+ }
-jQuery( function( $ )
-{
- $.datepicker.setDefaults( $.datepicker.regional[RWMB_Datepicker.lang] );
- rwmb_update_date_picker();
} );
View
21 js/datetime.js
@@ -2,23 +2,18 @@
* Update datetime picker element
* Used for static & dynamic added elements (when clone)
*/
-function rwmb_update_datetime_picker()
+jQuery( document ).ready( function( $ )
{
- var $ = jQuery;
-
- $( '.rwmb-datetime' ).each( function()
+ $( ':input.rwmb-datetime' ).each( rwmb_update_datetime_picker );
+ $( '.rwmb-input' ).on( 'clone', ':input.rwmb-datetime', rwmb_update_datetime_picker );
+
+ function rwmb_update_datetime_picker()
{
var $this = $( this ),
options = $this.data( 'options' );
-
+
$this.siblings( '.ui-datepicker-append' ).remove(); // Remove appended text
$this.removeClass( 'hasDatepicker' ).attr( 'id', '' ).datetimepicker( options );
- } );
-}
-
-jQuery( function( $ )
-{
- $.datepicker.setDefaults( $.datepicker.regional[RWMB_Datetimepicker.lang] );
- $.timepicker.setDefaults( $.timepicker.regional[RWMB_Datetimepicker.lang] );
- rwmb_update_datetime_picker();
+
+ }
} );
View
20 js/select-advanced.js
@@ -2,20 +2,16 @@
* Update select2
* Used for static & dynamic added elements (when clone)
*/
-function rwmb_update_select_advanced()
-{
- var $ = jQuery;
-
- $( ':input.rwmb-select-advanced' ).each( function ()
+jQuery( document ).ready( function ( $ )
+{
+ $( ':input.rwmb-select-advanced' ).each( rwmb_update_select_advanced );
+ $( '.rwmb-input' ).on( 'clone', ':input.rwmb-select-advanced', rwmb_update_select_advanced );
+
+ function rwmb_update_select_advanced()
{
var $this = $( this ),
options = $this.data( 'options' );
$this.siblings('.select2-container').remove();
- $this.select2( options );
- } );
-}
-
-jQuery( document ).ready( function ()
-{
- rwmb_update_select_advanced();
+ $this.select2( options );
+ }
} );
View
20 js/time.js
@@ -2,22 +2,18 @@
* Update datetime picker element
* Used for static & dynamic added elements (when clone)
*/
-function rwmb_update_time_picker()
+jQuery( document ).ready( function( $ )
{
- var $ = jQuery;
-
- $( '.rwmb-time' ).each( function()
+ $( ':input.rwmb-time' ).each( rwmb_update_time_picker );
+ $( '.rwmb-input' ).on( 'clone', ':input.rwmb-time', rwmb_update_time_picker );
+
+ function rwmb_update_time_picker()
{
var $this = $( this ),
options = $this.data( 'options' );
-
+
$this.siblings( '.ui-datepicker-append' ).remove(); // Remove appended text
$this.removeClass( 'hasDatepicker' ).attr( 'id', '' ).timepicker( options );
- } );
-}
-
-jQuery( function( $ )
-{
- $.timepicker.setDefaults( $.timepicker.regional[RWMB_Timepicker.lang] );
- rwmb_update_time_picker();
+
+ }
} );
Please sign in to comment.
Something went wrong with that request. Please try again.