lodev09 / bootstrap-suggest

A jQuery plugin for bootstrap that pops-up a dropdown in textarea or input textbox
http://lodev09.github.io/bootstrap-suggest/
MIT License
96 stars 50 forks source link

Lazy load images #2

Closed vhf closed 9 years ago

vhf commented 9 years ago

Hi, and thank you for this excellent project.

Would it be possible to modify it to lazy load images, and if so how would you go about it? I'm ready to give it a try and open a PR.

In one of my projects I'm using it to insert emojis, but on page load my 1,000+ emojis are all loaded one by one, which is of course not ideal.

lodev09 commented 9 years ago

how are you currently loading emojis? I'm using emojis too but I'm initializing the plugin on focus event of the input/textarea and using emojify plugin.

Anyway, feel free to submit your PR and I'll have a look. :)

vhf commented 9 years ago

I was using code that looks like this :

    map: function (emoji) {
      if (emoji && emoji.hasOwnProperty('code') && emoji.hasOwnProperty('img')) {
        return {
          value: emoji.code,
          text: '<img height="20px;" src="static/'+emoji.img+'"> <small>:'+emoji.code+'</small>'
        };
      }
    },

And it tried to download them all at once on page load.

I changed my code to make the onShow and onLookup populate the src field, thus loading emojis on demand instead of on page load.