Giter VIP home page Giter VIP logo

q-imageslider's Introduction

Q Imageslider Build Status

Maintainer: manuelroth

Q Imageslider is one tool of the Q toolbox to compare images with eachother. Test it in the demo.

Table of contents

Installation

git clone [email protected]:nzzdev/Q-imageslider.git
cd Q-imageslider
nvm use
npm install
npm run build

Configuration

There is one env variable IMAGE_SERVICE_URL to be defined. It should contain a URL with 3 parameters that will get replaced before the URL is used to load the images. {key} will be replaced by the string Q-server stored as the key when the file got uploaded through Q-servers /file endpoint provided by the file plugin {width} is replaced by the width the image should be loaded {format} will be png or webp (a picture element is used in the HTML with multiple source elements) Example: https://q-images.nzz.ch/{key}?width={width}&format={format}

If IMAGE_SERVICE_URL is not configured, the image.url property is used directly to load the image. This is mostly useful for dev and testing with fixture data. On production you most certainly want to use an image service to deliver resized and optimized images to the users.

Development

Start the Q dev server:

npx @nzz/q-cli server

Run the Q tool:

node index.js

to the top

Testing

The testing framework used in this repository is Code.

Run the tests:

npm run test

Implementing a new test

When changing or implementing...

  • A route, it needs to be tested in the e2e-tests.js file
  • Something on the frontend, it needs to be tested in the dom-tests.js file

to the top

Deployment

We provide automatically built docker images at https://hub.docker.com/r/nzzonline/q-imageslider/. There are three options for deployment:

  • Use the provided images
  • Build your own docker images
  • Deploy the service using another technology

Use the provided docker images

  1. Deploy nzzonline/q-imageslider to a docker environment
  2. Set the ENV variables as described in the configuration section

Functionality

The tool structure follows the general structure of each Q tool. Further information can be found in Q server documentation - Developing tools.

There are 2 endpoints for renderingInfo:

/rendering-info/web

This is the default endpoint called for web targets. It returnes the complete markup including a picture element for the image in case an exact width is given in toolRuntimeConfig.size.width. In case the width is missing a script measuring the width after the dom is ready is returned. This script will call /rendering-info/web-images with the exact container width passed in the width query parameter.

/rendering-info/web-images

There are 2 places where this route is called from.

  1. From inside the handler for rendering-info/web using server.inject
  2. From the client side script returned from /rendering-info/web if no exact width is given

This route handler renders the view/images.html template and returns a <picture> element containing different <source> elements for the image in different sizes for different screen DPI and png/webp.

to the top

Options

startImage

This is a dynamicEnum and stores the index of the image to be shown initially. You can select something here to not start with the first image when the imageslider gets loaded.

disableFade

This is a boolean and it can be used to disable the fade effect when switching between images.

displayOptions

hideTitle

If checked, the title is not rendered.

to the top

LICENSE

Copyright (c) 2019 Neue Zürcher Zeitung.

This software is licensed under the MIT License.

q-imageslider's People

Contributors

manuelroth avatar fromdusttilldawn avatar philipkueng avatar benib avatar greenkeeper[bot] avatar fgervasi avatar

Watchers

Balz Rittmeyer avatar James Cloos avatar NZZ avatar  avatar  avatar Peter avatar Danijel Beljan avatar Sharon Funke avatar Nikolai Thelitz avatar  avatar Alexandra Kohler avatar Michel Grautstück avatar  avatar

q-imageslider's Issues

An in-range update of uglify-js is breaking the build 🚨

The dependency uglify-js was updated from 3.6.1 to 3.6.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

uglify-js is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details

Release Notes for v3.6.2

 

Commits

The new version differs by 9 commits.

  • c3ca293 v3.6.2
  • 516b67a minor tweaks to CI test scripts (#3467)
  • eba3a37 fix boolean context detection (#3466)
  • 6d57ca1 improve source map handling (#3464)
  • 3320251 update benchmark URLs (#3462)
  • 33c94d3 detect boolean context across IIFEs (#3461)
  • b18f717 improve readability of --help ast (#3460)
  • a0d4b64 remove extraneous property (#3459)
  • 6db880e clean up AST_Binary optimisation logic (#3458)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Allow adding different size variants

Tasks

  • Add a property called variants of type array to the schema
  • A variant has a file and a minWidth property
  • The image will be choosen based on the minWidth property
  • Variants should only be visible to users with expert-imageslider role

Responsive Images

The goal with responsive images is to load the smallest image possible based on the real-world size on screen or display resolution of the device. There are different strategies to achieve this. In this issue I want to explain the once which work for the usecase of imageslider.

Use Case 1: The width is known

If we know that the image is gonna have a fixed width (article on desktop) we can allow the browser to choose an image with the appropriate resolution for the device. So if the device accessing the page has a standard resolution (1x) the 320w.jpg image will be loaded. If the device has a high resolution (2x) the 640w.jpg image will be loaded. The width provided by LivingDocs will be chosen as the 1x value.

<img srcset="320w.jpg 1x,
  480w.jpg 1.5x,
  640w.jpg 2x"
  src="640w.jpg">

Use Case 2: The width is not known

If the element is embedded on other pages than the main page or shown on a mobile device, we don't know the width of the image upfront. In this case a client-side script will measure the width and set the srcset and src tag to the measured width.

Picture element

Browsers support different image formats. The picture element allows to define image sources with different image formats. The browser will choose the one it can render. For old browsers if will fall back to jpg.

<picture>
  <source type="image/webp" srcset="https://image.com/500.png 1x,  https://image.com/1000.png 2x">
  <source srcset="https://image.com/500.png 1x, https://image.com/1000.png 2x">
  <img src="https://image.com/1000.png">
</picture>

Approach which doesn't works

There exists an approach to let the browser choose an image base on the device width. There are two attributes. With srcset we tell the browser the different available versions and the width of them. And with in the sizes string we declare how much space the image will take on the different viewports. The browser will then choose the appropriate image based on the available space.

<img srcset="320w.jpg 320w,
  480w.jpg 480w,
  800w.jpg 800w"
  sizes="(max-width: 320px) 280px,
              (max-width: 480px) 440px,
              800px"
  src="800w.jpg">

The problem with this approach is that the media conditions (screen widths) defined in the sizes attribute are always based on the viewport. But the imageslider is not always as wide as the entire viewport. Thats why this approach doesn't work for the imageslider.

I tested what happens if the sizes attribute is not defined. In this case the browser will choose the image assuming it will be shown on 100% of the viewport.

use image resizing/transformation proxy for image delivery

  • The base URL of the proxy should be configurable via ENV variable.
  • The service running is imaginary https://github.com/h2non/imaginary
  • Images should be delivered with a reasonable number of pixels for the size they are displayed in
  • Images should be delivered in double resolution only to users width a high dpi screen
  • user agents understanding webp should load the images in webp format

image resizing service is running at http://img.st-staging.nzz.ch for everything uploaded from staging or dev. For production there will be a CDN in front, thats the reason why this URL needs to be configurable by ENV variable.

An example of a resized image request:
https://img.st-staging.nzz.ch/resize?url=https://nzz-q-assets-stage.s3.eu-west-1.amazonaws.com/2018/01/15/a39f19db-d0ca-47a2-9c60-69f2b883a75c.jpeg&width=500&nocrop=true

PaddingBottom value should be calculated separately for each image

Introduction

At the moment we calculate the paddingBottom value only for the tallest image. This is a workaround for the case if images have different heights. We are starting to use the imageslider more and more for graphics where its more common to have images with different heights.

Possible solution

The paddingBottom value should be calculated foreach image separately and set when switching between the images. This could result in jumping of the text below. On mobile the user probably doesn't notice the jumping as its not visible, but its a problem on desktop.

An in-range update of @hapi/inert is breaking the build 🚨

The dependency @hapi/inert was updated from 5.2.1 to 5.2.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@hapi/inert is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details

Commits

The new version differs by 7 commits.

  • 9c08c72 5.2.2
  • 05d2784 Update joi. Closes #130
  • 3a1d137 Merge pull request #124 from zimokha/broken-links
  • 8b20992 Update deps
  • 4492bc5 adding slash for top level if path does not end with slash
  • 6e76104 make readable comment
  • e731098 fixing broken links in directory listing

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of @hapi/joi is breaking the build 🚨

The dependency @hapi/joi was updated from 15.0.0 to 15.0.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@hapi/joi is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details

Commits

The new version differs by 29 commits.

  • 2d6f1b5 15.0.1
  • 48decc3 Update .travis.yml
  • 58a8c9d Update README.md
  • 3d186a5 Merge pull request #1792 from jvolonda42/master
  • b1fe0b0 minDomainAtoms is not available in 15.0 we need to use minDomainSegments instead
  • af17adb Merge pull request #1791 from thebinarypenguin/master
  • 9591ffe Change npm install command
  • e52b29a Regenerate package lock
  • a0dc9df Run validation even for schemas returned by setup. Fixes #1747.
  • 21ddcab Merge pull request #1750 from WesTyler/object_pattern_refs
  • 144e713 Pass options to pattern validation to support refs
  • 06bd220 Merge pull request #1765 from kanongil/less-throws
  • f51e98f Pass state to pattern validations. Fixes #1761.
  • 3516cf0 Merge pull request #1704 from luciferankon/master
  • 83c9bdc Merge pull request #1741 from emekadev/master

There are 29 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Adjust dynamicEnum and availabilityChecks to new configuration format

Task

We made changes to the configuration format of dynamicEnums and availabilityChecks. The schema and corresponding routes need to be adjusted as following (more details on the config format can be found here):

DynamicEnums

Current:

"dynamicEnum": {
  "type": "ToolEndpoint",
  "withData": true,
  "endpoint": "dynamic-enum/selectedColumn"
}

New:

"dynamicEnum": {
  "type": "ToolEndpoint",
  "config": {
    "endpoint": "dynamic-enum/selectedColumn",
    "fields": ["options", "data"]
  }
}

Additionally the /dynamic-enum now receives an object containing the item and optionally and options property. The route needs to be adjusted to this.

AvailabilityChecks

Current:

{
  "type": "ToolEndpoint",
  "withData": true,
  "endpoint": "option-availability/invertColors"
}

New:

{
  "type": "ToolEndpoint",
  "config": {
    "endpoint": "option-availability/invertColors",
    "fields": ["options", "data"]
  } 
}

Additionally the /option-availability now receives an object containing the item and optionally and options property. The route needs to be adjusted to this.

An in-range update of @hapi/hapi is breaking the build 🚨

The dependency @hapi/hapi was updated from 18.3.2 to 18.4.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@hapi/hapi is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details

Commits

The new version differs by 30 commits.

There are 30 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of @hapi/joi is breaking the build 🚨

The dependency @hapi/joi was updated from 15.0.2 to 15.0.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@hapi/joi is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details

Commits

The new version differs by 2 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Consistent Code Formatting

What we want:

  • Consistent code formatting without many changes on existing codebase

Possible tools:

  • Prettier - Does only code formatting (JavaScript, SCSS, JSON and more)
  • ESLint - Can do both code formatting and linting, everything configurable
  • StandardJS - Uses a ESLint configuration to format and lint code, doesn't allow any configuration on purpose

Prettier

  • Only code formatting
  • Uses predefined configuration (can be extended)
  • Supports most common languages such as JavaScript, SCSS and JSON without adding additional dev-dependencies
  • Pro: Formatting on save with VS Code Extension

ESLint

  • Allows to configure everything
  • There are popular ESLint configuration such as Airbnb's Javascript Styleguide ect. which all try to do code formatting and linting in one
  • Cons: For each language a plugin needs to be added to dev-dependancies

StandardJS

  • Tries to end the discussion around formatting conventions
  • Provides a "standard" configuration for code formatting and linting
  • Differs from our current code style (without semicolon)
  • Pro: No configuration files
  • Con: Possibly a lot of code changes in older repo's

My Opinion

  • Its a good thing to separate code formatting and linting
  • Prettier does one thing well and lets us format code on save
  • Code linting can be added separately using ESLint for example

An in-range update of @hapi/joi is breaking the build 🚨

The dependency @hapi/joi was updated from 15.0.1 to 15.0.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@hapi/joi is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details

Commits

The new version differs by 5 commits.

  • 2c36ab3 15.0.2
  • ea9facf Merge pull request #1801 from lerouxb/remove-strip-default
  • 3029ea6 Merge pull request #1804 from adamreisnz/patch-1
  • c62ac45 Clarify referenced parameter resolution
  • 97cc246 remove strip from defaults now that it has been removed

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

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.