Skip to content

[PROPOSAL] Strategy implementation #28

@thom4parisot

Description

@thom4parisot

The intention

Imager replaces a DIV (or container) tag by a placeholder image prior to its width URL calculation. The logic of Imager might pleased everybody but users have different contraints:

  • their CMS is too complicated to hack
  • for design reasons, you might want to add the placeholder image inside the container

The proposal

The user can decide how the responsive image is treated without altering the internals of Imager.

Here are the various options to implement that.

One buildfile per strategy

  • imager-core.js + imager-strategy-replacer.js = imager.js
  • imager-core.js + imager-strategy-container.js = imager-container.js
  • function Imager() + (Imager.prototype.getPlaceholder + Imager.prototype.processPlaceholder()) = imager-custom.js
<script src="imager.js">
<script>
var imgr = new Imager();
</script>

or

<script src="imager-container.js">
<script>
var imgr = new Imager();
</script>

Pros:

  • Nothing to configure, just dropping in the good file

Cons:

  • would not be possible to mix strategies together within a same page
  • might be more complicated for someone wanting to bake his own strategy

DIY

<script src="imager.js">
<script src="imager-strategy-replacer.js">
<script src="imager-strategy-container.js">
<script>
// by default it will look for the `replacer` one
var imgr = new Imager();

// or we can specify which strategy we want to use
var imgr_sidebar = new Imager({ strategy: 'container' });
</script>

Pros:

  • Freedom to make Imager working the exact way you want
  • Ability to use different replacements within a same page

Cons:

  • May be slightly less intuitive than the other proposal

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions