rvera / image-picker

Image Picker is a simple jQuery plugin that transforms a select element into a more user friendly graphical interface.
http://rvera.github.com/image-picker
Other
906 stars 216 forks source link

Is there any options available as Buttons on the Groups Images #60

Closed yugakiran closed 6 years ago

yugakiran commented 8 years ago

Is there any options available for 'SelectAll' , 'UnSelect All', 'Zoom In/Out' options on the Groups Images

SgtOddball commented 8 years ago

No there isn't but I've written code to do just that with abit of jQuery.

$(function(){
  $('.image-picker').imagepicker({
    show_label: true,
      //This triggers an action once all the images have loaded to add a lightbox trigger (change the trigger to suit what ever zoom tool you use)
      initialized: function(e){
        $('.thumbnail img').each(function(){
          $(this).wrap('<a href="'+$(this).prop('src').replace('thumbnails/','')+'" data-toggle="lightbox">')
        });
        $(document).delegate('*[data-toggle="lightbox"]', 'click', function(event) {
          event.preventDefault();
        });
  })
  //Add a button id="toggleAll" and make sure you've got a multi select list - This takes care of the select all/none issue.
  $('#toggleAll').on('click',function(){
    if($(this).attr('aria-pressed')=='false'){
      $('.image-picker').find($('option')).prop("selected", "selected");
     //this triggers the image picker to check for changes and update the images accordingly
      $('.image-picker').data('picker').sync_picker_with_select();
    }else{
      $('.image-picker').find($('option')).prop("selected", false);
      $('.image-picker').data('picker').sync_picker_with_select();
    }
})
mayconmano commented 8 years ago

image-picker.js

Line: 183

ImagePicker.prototype.toggle = function (imagepicker_option) { var new_values, old_values, selected_value; old_values = this.selected_values(); selected_value = imagepicker_option.value().toString(); if (this.multiple) { if (__indexOf.call(this.selected_values(), selected_value) >= 0) { new_values = this.selected_values();
new_values = jQuery.grep(new_values, function (value) { return value != selected_value; });
this.select.val([]); this.select.val(new_values); } else { if ((this.opts.limit != null) && this.selected_values().length >= this.opts.limit) { if (this.opts.limit_reached != null) { this.opts.limit_reached.call(this.select); } } else { this.select.val(this.selected_values().concat(selected_value)); } } } else { if (this.has_implicit_blanks() && imagepicker_option.is_selected()) { this.select.val(""); } else { this.select.val(selected_value); } } if (!both_array_are_equal(old_values, this.selected_values())) { this.select.change(); if (this.opts.changed != null) { return this.opts.changed.call(this.select, old_values, this.selected_values()); } } };

rvera commented 7 years ago

@SgtOddball implementations is the preferred option, I'd like to keep this lightweight if possible. But this is certainly a good idea to implement.

SgtOddball commented 7 years ago

Not blowing my own trumpet but I agree with @rvera, there's potentially other issues or edge cases for this functionality that would be likely to cause code bloat over time. Keep it simple and use external code for edge cases unless there's a large requirement for this feature.

A good middle ground might be to add the method to make it happen in the documentation? (might be worth taking out the lightbox tweak i added too, again edge cases for my personal requirements).