Coder Social home page Coder Social logo

rvera / image-picker Goto Github PK

View Code? Open in Web Editor NEW
906.0 906.0 216.0 2.19 MB

Image Picker is a simple jQuery plugin that transforms a select element into a more user friendly graphical interface.

Home Page: http://rvera.github.com/image-picker

License: Other

CSS 11.72% CoffeeScript 29.01% JavaScript 59.27%

image-picker's People

Contributors

humni avatar jbatchelor avatar jd-robbs avatar kkalpakloglou avatar lloiser avatar rdennis avatar rvera avatar tutuca avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

image-picker's Issues

Selects Multiple in Mobile Chrome browser

I tried to use select multiple.
But I cannot deselect first element after I selected that once.
It only happen in mobile Chrome browser.
Android OS 4.1.2 and 4.3 (Nexus 7)
Chrome Browser 28.0.1500.94

Here is the movie that I comfirmed the situation.
https://www.youtube.com/watch?v=y0r_DYz8iAk

I am debugging and thinking what's happening and how to solve.

And maybe something is happening at image-picker.js , line 160
if (_ref = imagepicker_option.value(), __indexOf.call(this.selected_values(), _ref) >= 0)

But I cannot have solution yet... sorry...

How to allow to retain the selection after form validations

I don't know if it is a bug, or is just me that don't know how to do it.
I have a form with different fields and also an Image-picker select with 5 images (with multiple selection).
When there are some validation error, the message error is displayed, and the values of the other fields are filled with the pre-existing input.
In Laravel4 i can do this easily with value={{ Input::old('InputName') }}
but it does not work with the ImagePicker selection.

Or better, Input::old('') contains all the input from all the fields and also an array with ([0] => 'single room', [1] => 'double rooms'), that it is exactly my selection in the Image-picker select, but i don't know how to pre-select the images, according to this.

Do you understand?
If you have some questions feel free to ask!
Thank you for the attention!

How to change image size - width and height?

My question is how to change the size (width, height in px) in Image-Picker or if in this version there is no such option then I will offer to add option with which you can change the images size - width and height. :)

Option to only show the images when the dropdown is clicked

To save screen space, could the plugin have an option to only show the images when the dropdown is clicked on (I guess also suppressing the dropdown's native elements being displayed as well)? Maybe even also hooking into optional jQuery Animate animations for display/hide once selected?

Shift Key Selection.

While using multiple select and hiding the original select the user should be able to select a range of images using shift key like it does in original select.

Empty value in the select menu shows all items as selected

This was easy enough to fix, i just added in a different value for option menu, but still it would be nice if we could just leave the value="" empty and still have the plugin show only one item selected. This probably has to do with how the plugin defines its index.

hiding image picker

Hi

Firstly thank you for your plug in, its very useful. I am trying to use it to create select option images and it works well but I wondered if you can tell me what I can do to toggle show/hide the images as there are a lot of them and a few options.

Here is the page http://www.pinkequine.com/bespoke/imagechanger.html I apologize for any bad jquery but I only learned it yesterday.

I hope you can help.

change order of events; make event available

Thanks for making this great tool available!
The following would be useful (I'd also need them now):

  1. The order the events are received is: changed, clicked, selected. This means that before the first event, the state of the selection changes, i.e. you cannot know what was the previous state (unless you store the states of all your image-picker objects). If "clicked" came before "changed", then you could use the previous state of the selection, which is sometimes useful (e.g. to restore it if the event is cancelled).
  2. You may need to know if e.g. CTRL is pressed during the click, to be able to modify the meaning. The event (and thus event.ctrlKey, etc.) is available as window.event on Chrome and Internet Explorer, but not on e.g. Firefox. If the event object was passed to the event function, that would make it usable that way universally under all browsers.
  3. Making available the context menu (or right click) event could be useful as well.

Thanks!

Pagination of images

Is it possible to paginate the results? - Say that the select box has 1000 items in it, how would I paginate the thumbnails to only show a subset (50, for instance) at a time?

Demo-Page: Sources for testing

Hello together,

for testing issues, it would be great, if you integrate the sources of the demo-page into this project.

Bye,
Andreas

Rebinding causes issue with Knockout

When calling .imagepicker on a select box that is bound to knockout the first time everything works fine. When that select list is changed and the call is made again (as is recommended) the underlying select list seems to never receive the updates on when an item is selected. the thumbnail does highlight correctly though.

Is there a way to totally destroy the first instance and recreate it? the destroy method seems to leave some stuff behind.

Knockout is mentioned because it is more apparent with knockout. The scenario is items get added to the list from other dom events and would be added or removed from the master select list. The user would then get the option to pick from this master list. Things work great on the first time around but stop once anything is changed on the select list

Feature

Could we create a sort of albums using <optgroup> so that photos from different albums could be "grouped"?

Disabled select doesn't show selected value

Hi,

And thanks for a nice plugin :) I noticed that a disabled select doesn't show the selected value (due to .val() returning null if the select is disabled, see: http://bugs.jquery.com/ticket/13097).

I could get this to work by replacing this line in ImagePickerOption.prototype.is_selected():

var select_value;
select_value = this.picker.select.val();

with:

var select_value, selected_index;
selected_index = this.picker.select.prop('selectedIndex');
select_value = this.picker.picker_options[selected_index].value();

Also it would be nice to get an additional class to the wrapper if select is disabled. What do you think?

Juha

Ajax Support

I know this is a big one, but it would be nice if picker supported accordeon style ajax support. Basically option groups would be all collapsed by default (at initialization any option group can be expanded). Option group content only loads on expansion via ajax. Obviously option group has to be clickable (click when collapsed results in expansion and ajax load, click when expanded results in collapsing).

Making thumbnails responsive

Great plugin! I'm wondering - is there a way to make the thumbnails responsive so they play nicely on mobile devices? Thanks!

David.

Performance above 100 images?

Firstly thanks for an amazing plugin, It's helped me out a lot.

I've noticed the performance of toggling the images slows down a lot with pickers that are very large, like 150 or so images. The lag between the mouse click and the highlight appearing is 1-1.5 seconds.

I wouldn't know where to start to optimise this but I was wondering if you had noticed the same thing with larger pickers?
thanks

image in <li> does not get updated after changing data-img-src

Update - I created a fiddle with simplified code at: http://jsfiddle.net/vSv6k/6/

I am using this lovely plugin to show thumbs of image objects. To speed up the process and show the user a complete list immediately, I am initially generating the imagepicker for all objects with a place holder image and only then replace the thumb one by one. The problem is that after updating the data-img-src by jquery and re-init of imagepicker the select option does contain the correct data-img-src but the list item still contains the placeholder (except for the first object which displays with the correct image instead of the placeholder). Any ideas how to solve this?

This is what I am doing:

First generate initial imagepicker with placeholders:

          $.each(photos_list, function(key, photo ) {
            // add entry to imagepicker with placeholder thumb
              $('#imagepicker').append(
                $("<option>" , {
                  text: photo.name,
                  value: photo.object,
                  'data-img-src' : 'http://placehold.it/100x100&text=Loading+Image'
                })
              );

Then in async.queue replace thumbs one by one:

          // replace placeholder thumb by real thumb
          $('#imagepicker option[value="'+photo.data.object+'"]').attr('data-img-src','data:image/jpeg;base64,'+response);
          // update imagepicker every 10 images
          if (thumbcount%10==0) {
            $("#imagepicker").imagepicker({
              hide_select: true,
              show_label: true
            });
          }

Of course I also call re-init of imagepicker at the drain event of the queue so it will display also the last images.

If I do the same but instead start with an empty list and add select options one by one with the final thumb it works fine.

Get clicked image in clicked function?

I'm trying to figure out how to get the actual image that was clicked (not the option) within the clicked callback. I can see how to get the clicked option, but not the actual image, which I need because I want to run some code on each image as it is clicked... Thanks!

Clarification of the Changed functionality

Can someone clarify in the examples section of the usage of the changed value?

I would like to be able to click on one of the selected images and have that trigger an ajax request.

picker should throw 'change' event

i want to use the selected option immediately in my javascript and tried to listen for a change event with jquery, but it image-picker doesn't throw one :(

i added this at line 185 and it works fine (perhaps it should be also added to line 183):

picker.select.change();

Wrong option selection

If two option are same values,
for example:

<option value="1">a</option>
<option value="1">aa</option>
<option value="2">b</option>

Select the first item or second item, the other same value item will also be selected.

Also, could you add a feature that allows this plugin to show text or html content inside the options? Like this.
http://store.apple.com/us/buy-iphone/iphone5s

Because some time the option is no image, only the text or html.

How to select an item with js

Hi,
Im sure its possible but I cant find it. How can I select en Item with js?
And btw how can i add an item?

Thanks a lot!!
Felix

how to dynamic add a option to select ,use initialized but select is correct,but img not display.what can i do?

Cute Kitten 1 Cute Kitten 2 Cute Kitten 3 Cute Kitten 4 dsfsdf

$("#spaceToolsSelect").imagepicker({
hide_select: true,
show_label: true,
initialized:function(){

                var selectToolType = $("#selectToolType option:selected").val();
                $.getJSON(basePath+'/tool/getToolsByType.action?selectToolType='+selectToolType,function(jsonData){
                       $.each(jsonData, function (i, tool) {
                            // alert(tool.filePath);
                            //<option data-img-label="Awww" data-img-src="http://placekitten.com/220/200" value="1">Cute Kitten 1</option>
                            var toolName = tool.name;
                            var toolId = tool.id;
                            var toolPath = basePath+"/media/" + tool.filePath;
                            $("#spaceToolsSelect").append('<option data-img-label="'+toolName+'" data-img-src="'+toolPath+'" value="'+toolId+'">'+toolName+"</option>");
                             $(".controls thumbnails image_picker_selector").append('<li><div class="thumbnail"><img class="image_picker_image" src="'+toolPath+'"><p>"'+toolName+'"</p></div></li>');

                            });
                });

          }
    });

Help me please

Hi !

First of all great plugin.

How can i show the pics when i'm using the plugin? Like the demo.

Thanks

Strange behavior when adding photos to the list

Hello,

For starters, great plugin.
I have a situation where I'm using bootstrap and your plugin to show a bunch of photos. I have the ability to upload a new photo to that album that is refreshed via ajax.

The problem I have is intermittent (doesn't always happen), but sometimes the pictures are misplaced in the grid (i have a 4xN grid of photos) meaning sometimes a new row will add the first picture in slot no. 2.

problem

As you can see in the image, the second row starts off by 1 picture. Row 3 is ok as well.
I've checked my css classes and nothing unusual is there. The list is

  • for last picture of row 1 and
  • for first picture in row 2 meaning no html no gaps and no padding occur between them.

    Thank you for your time.

  • Selected Option

    I've set a selected option
    option value="xpto" selected
    on the original html select element.

    But the generated div with the images ignores that selection.

    Am I doing something wrong? or this plugin doesn't do this?

    Thanks

    image-picker always selects first image

    Hi
    if i Initialize image-picker by calling $("select").imagepicker() the first image is always selected.

    It would be very cool, if image-picker could keep the selection (third image in this example):

    <select class="image-picker show-html">
      <option data-img-src="img/01.png" value="1">  Page 1  </option>
      <option data-img-src="img/02.png" value="2">  Page 2  </option>
      <option data-img-src="img/03.png" value="3" selected>  Page 3  </option>
    </select>

    How can I achieve this?

    Issue causing image-picker not to work in IE7 and IE8

    In your image-picker.js file, this line here:

    this.picker = $("<ul class='thumbnails image_picker_selector'></div>");

    seems to break IE7 and IE8.

    Changed to:

    this.picker = $("<ul class='thumbnails image_picker_selector'></ul>");

    and seems to fix the issue.

    Doesn't work with jQuery in noConflict mode

    When I try to use the plugin to create an image picker while jQuery is in noConflict mode so it can play nice with other frameworks, the plugin dies with an "TypeError: $ is not a function" error. When noConflict mode is not turned on (allowing jQuery can take over the "$" namespace), the plugin works fine.

    show-html.js ???

    I cannot get this to work but I am missing show-html.js - where can I get this ? Is this likely to be the problem ? - the images will not display

    Font-awesome integration

    Hi,
    what would be the easiest way to use font-awesome icons instead of real images? Is it possible with the current state of the plugin?

    Give link to images

    I want to give links to images in image picker (). I want to show fullsize versions of images when user click on thumbnails. How can I do this ?

    In Explorer is not working deselect.

    In Google, Firefox, Opera, all is working fine.
    In Explorer after i select an image, is not possible to deselect it.
    You can see it, opening this page on Explorer:
    http://rvera.github.io/image-picker/
    It is possible to deselect only the first group, with the title INCLUDE BLANKS,
    all the other groups is not possible to deselect.
    Can you tell me please why in the first group the deselect is working?
    There should be some code there that enable deselect in Explorer.
    (i thought was enough to add a blank field but still is not working)
    Thanks!

    Integrate with drag and drop functionality?

    I am using image-picker to display a grid of images. I would also like to allow the user to re-order the images by dragging and dropping them to swap image position. Has anyone attempted to do this with image-picker? If so, what is the best approach? Not sure if I should re-order the select options or the images and then re-sync with select? Thanks!

    sync_picker_with_select does not work with two select boxes on the page

    Hi there,

    Great plugin. However, I have two tags on my page and I'm trying to use sync_picker_with_select() to update the plugin when the selected option of the 2nd select box is changed by something else on the page. Unfortunately it does not seem to work when I use the following as per the documentation:

    $("#selectbox2").data('picker').sync_picker_with_select();

    If I delete the other select box from the page ("#selectbox1") then it works as expected.

    Any ideas ?

    Thanks
    Tim

    Add ability to customize thumbnail DIV

    I was in need of styling thumbnail div after option translation (had new images in my library and wanted to style the resulting thumbnail with a "new" overlay tag). Ended up enhancing library code:

      var thumbclasses = "";
      if(!(this.option.attr('class')===undefined)) {
          thumbclasses = " " + this.option.attr('class');
      }
    

    Above goes at the very beginning of:

    ImagePickerOption.prototype.create_node = function() {

    Then, including thumbclasses when building the div:

    thumbnail = jQuery("<div class='thumbnail" + thumbclasses + "'>");

    Complete enhanced function:

    ImagePickerOption.prototype.create_node = function() {
      var thumbclasses = "";
      if(!(this.option.attr('class')===undefined)) {
          thumbclasses = " " + this.option.attr('class');
      }
      var image, thumbnail;
      this.node = jQuery("<li/>");
      image = jQuery("<img class='image_picker_image'/>");
      image.attr("src", this.option.data("img-src"));
      thumbnail = jQuery("<div class='thumbnail" + thumbclasses + "'>");
      thumbnail.click({
        option: this
      }, function(event) {
        return event.data.option.clicked();
      });
      thumbnail.append(image);
      if (this.opts.show_label) {
        thumbnail.append(jQuery("<p/>").html(this.label()));
      }
      this.node.append(thumbnail);
      return this.node;
    };
    
    return ImagePickerOption;
    

    })

    With this, I can now define options like this:

    <optgroup label="Beer">
    <option data-img-src='../images/promos/beer/beer-128.png' value='beer/beer'>Generic</option>
    <option class='new' data-img-src='../images/promos/beer/beer_miller-128.png' value='beer/beer_miller'>Miller Lite</option>
    </optgroup>


    And the library will render div thumbs with option class, so a div can be styled:

    <div class="thumbnail"><img class="image_picker_image" src="../images/promos/beer/beer-128.png"><p>Generic</p></div>
    <div class="thumbnail new selected"><img class="image_picker_image" src="../images/promos/beer/beer_miller-128.png"><p>Miller Lite</p></div>


    Figured I'd share since it maybe useful to others. Feel free to merge.

    Reset selected value on external value update?

    (tl;dr) My js is weak... How should I trigger image-picker to update the selected value from external js?

    I have a form which is populated with values from an existing model. If the user feels they have screwed up the form, a button allows them to reset original model values. The image picker js is not triggered, so even though the form value for a select is reset, image-picker is not aware of the select value update, and the form select presentation is incorrect. TIA

    Hide only the original selector?

    Hi Rodrigo,

    first of all many thanks for the great plugin.
    I have some doubt. I understood the documentation in the way that setting hide_select to true must hide only the original select control, leaving the picker visible. When I try to set hide_select to true (or just omit it in the imagepicker call, because it is by default set to true), actually both disappear: the select control and the picker. I assume it is not by design, or?
    I tested with jquery 1.11 and Chrome.

    Add the source to CDNJS

    It would be great if you could add this project to cdnjs so it could be loaded from a CDN without having to include the source in my project.

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google โค๏ธ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.