Skip to content

Commit

Permalink
Use select2 for category selects now - #45
Browse files Browse the repository at this point in the history
  • Loading branch information
JayWood committed Sep 30, 2016
1 parent 82d2425 commit 05a785c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion includes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ public function enqueue_admin_script( $hook ) {
wp_enqueue_media();
}

wp_enqueue_script( 'cwv2-admin', $this->plugin->url( "js/admin{$this->plugin->min}.js" ), array( 'jquery' ), $this->plugin->version, true );
wp_enqueue_style( 'select2', $this->plugin->url( "lib/select2-4.0.3/css/select2{$this->plugin->min}.css" ), false, '4.0.3' );
wp_enqueue_script( 'select2', $this->plugin->url( "lib/select2-4.0.3/js/select2{$this->plugin->min}.js" ), array( 'jquery' ), '4.0.3', true );

wp_enqueue_script( 'cwv2-admin', $this->plugin->url( "js/admin{$this->plugin->min}.js" ), array( 'select2' ), $this->plugin->version, true );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public function select2_multi( $args = array() ) {
$option_value = get_option( $field_id, $field_id, $default );

?>
<select name="<?php echo $field_id; ?>" id="<?php echo $field_id; ?>" class="cwv2_select2" multiple="multiple">
<select name="<?php echo $field_id; ?>" id="<?php echo $field_id; ?>" class="cwv2_select2 widefat" multiple="multiple">
<?php foreach ( $options as $k => $v ) : ?>
<option value="<?php echo $k; ?>" <?php $this->selected_array( $option_value, $k ); ?>><?php echo $v; ?></option>
<?php endforeach; ?>
Expand Down
8 changes: 7 additions & 1 deletion js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,23 @@ window.cwv2Admin = {};
app.$c = {
window: $(window),
imgUploadBtn: $( '.upload_image_button' ),
select2Objects: $( '.cwv2_select2' ),
};
};

// Combine all events
app.bindEvents = function() {
app.$c.imgUploadBtn.on( 'click', app.handleImageUploader );
app.$c.window.on( 'load', app.windowLoad );
};

app.windowLoad = function() {
app.$c.select2Objects.select2();
};

// Do we meet the requirements?
app.meetsRequirements = function() {
return app.$c.imgUploadBtn.length;
return app.$c.imgUploadBtn.length && app.$c.select2Objects.length;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion js/admin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 05a785c

Please sign in to comment.