ReduxFramework_sortable

The evolve ReduxFramework sortable class.

Defined (1)

The class is defined in the following location(s).

/library/admin/redux-framework/inc/fields/sortable/field_sortable.php  
  1. class ReduxFramework_sortable { 
  2.  
  3. /** 
  4. * Field Constructor. 
  5. * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function 
  6. * @since Redux_Options 2.0.1 
  7. */ 
  8. function __construct( $field = array(), $value = '', $parent ) { 
  9. $this->parent = $parent; 
  10. $this->field = $field; 
  11. $this->value = $value; 
  12.  
  13. /** 
  14. * Field Render Function. 
  15. * Takes the vars and outputs the HTML for the field in the settings 
  16. * @since Redux_Options 2.0.1 
  17. */ 
  18. function render() { 
  19. if ( empty( $this->field['mode'] ) ) { 
  20. $this->field['mode'] = "text"; 
  21.  
  22. if ( $this->field['mode'] != "checkbox" && $this->field['mode'] != "text" ) { 
  23. $this->field['mode'] = "text"; 
  24.  
  25. $class = ( isset( $this->field['class'] ) ) ? $this->field['class'] : ''; 
  26. $options = $this->field['options']; 
  27.  
  28. // This is to weed out missing options that might be in the default 
  29. // Why? Who knows. Call it a dummy check. 
  30. if ( ! empty( $this->value ) ) { 
  31. foreach ( $this->value as $k => $v ) { 
  32. if ( ! isset( $options[ $k ] ) ) { 
  33. unset( $this->value[ $k ] ); 
  34.  
  35. $noSort = false; 
  36. foreach ( $options as $k => $v ) { 
  37. if ( ! isset( $this->value[ $k ] ) ) { 
  38.  
  39. // A save has previously been done. 
  40. if ( is_array( $this->value ) && array_key_exists( $k, $this->value ) ) { 
  41. $this->value[ $k ] = $v; 
  42.  
  43. // Missing database entry, meaning no save has yet been done. 
  44. } else { 
  45. $noSort = true; 
  46. $this->value[ $k ] = ''; 
  47.  
  48. // If missing database entries are found, it means no save has been done 
  49. // and therefore no sort should be done. Set the default array in the same 
  50. // order as the options array. Why? The sort order is based on the 
  51. // saved default array. If entries are missing, the sort is messed up. 
  52. // - kp 
  53. if ( true == $noSort ) { 
  54. $dummyArr = array(); 
  55.  
  56. foreach ( $options as $k => $v ) { 
  57. $dummyArr[ $k ] = $this->value[ $k ]; 
  58. unset( $this->value ); 
  59. $this->value = $dummyArr; 
  60. unset( $dummyArr ); 
  61.  
  62. $use_labels = false; 
  63. $label_class = ''; 
  64. if ( $this->field['mode'] != "checkbox" ) { 
  65. if ( ( isset( $this->field['label'] ) && $this->field['label'] == true ) ) { 
  66. $use_labels = true; 
  67. $label_class = ' labeled'; 
  68.  
  69. echo '<ul id="' . $this->field['id'] . '-list" class="redux-sortable ' . $class . ' ' . $label_class . '">'; 
  70.  
  71.  
  72. foreach ( $this->value as $k => $nicename ) { 
  73. echo '<li>'; 
  74.  
  75. $checked = ""; 
  76. $name = 'name="' . $this->field['name'] . $this->field['name_suffix'] . '[' . $k . ']' . '" '; 
  77. if ( $this->field['mode'] == "checkbox" ) { 
  78. $value_display = $this->value[ $k ]; 
  79.  
  80. if ( ! empty( $this->value[ $k ] ) ) { 
  81. $checked = 'checked="checked" '; 
  82. $class .= " checkbox_sortable"; 
  83. $name = ""; 
  84. echo '<input type="hidden" name="' . $this->field['name'] . $this->field['name_suffix'] . '[' . $k . ']' . '" id="' . $this->field['id'] . '-' . $k . '-hidden" value="' . $value_display . '" />'; 
  85.  
  86. echo '<div class="checkbox-container">'; 
  87. } else { 
  88. $value_display = isset( $this->value[ $k ] ) ? $this->value[ $k ] : ''; 
  89. $nicename = $this->field['options'][$k]; 
  90.  
  91.  
  92. if ($this->field['mode'] != "checkbox") { 
  93. if ($use_labels) { 
  94. echo '<label class="bugger" for="' . $this->field['id'] . '[' . $k . ']"><strong>' . $k . '</strong></label>'; 
  95. echo "<br />"; 
  96.  
  97. echo '<input rel="' . $this->field['id'] . '-' . $k . '-hidden" class="' . $class . '" ' . $checked . 'type="' . $this->field['mode'] . '" ' . $name . 'id="' . $this->field['id'] . '[' . $k . ']" value="' . esc_attr( $value_display ) . '" placeholder="' . $nicename . '" />'; 
  98.  
  99. echo '<span class="compact drag"><i class="el el-move icon-large"></i></span>'; 
  100. //if ( ( isset( $this->field['label'] ) && $this->field['label'] == true ) ) { 
  101. if ($this->field['mode'] == "checkbox") { 
  102. if ( $this->field['mode'] != "checkbox" ) { 
  103. //echo "<br />"; 
  104. //echo '<label for="' . $this->field['id'] . '[' . $k . ']"><strong>' . $k . '</strong></label>'; 
  105. } else { 
  106. echo '<label for="' . $this->field['id'] . '[' . $k . ']"><strong>' . $options[$k] . '</strong></label>'; 
  107. if ( $this->field['mode'] == "checkbox" ) { 
  108. echo '</div>'; 
  109. echo '</li>'; 
  110. echo '</ul>'; 
  111.  
  112. function enqueue() { 
  113. if ($this->parent->args['dev_mode']) { 
  114. wp_enqueue_style( 
  115. 'redux-field-sortable-css',  
  116. ReduxFramework::$_url . 'inc/fields/sortable/field_sortable.css',  
  117. array(),  
  118. time(),  
  119. 'all' 
  120. ); 
  121.  
  122. wp_enqueue_script( 
  123. 'redux-field-sortable-js',  
  124. ReduxFramework::$_url . 'inc/fields/sortable/field_sortable' . Redux_Functions::isMin() . '.js',  
  125. array( 'jquery', 'redux-js', 'jquery-ui-sortable' ),  
  126. time(),  
  127. true 
  128. );