Skip to content

Commit

Permalink
refactor; complete api testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kingdido999 committed Dec 16, 2016
1 parent b58b4f4 commit c817593
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 60 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ Under project folder:

`yarn watch`

Now open up `index.html` and play around with it!
Open up `index.html` and play around with it!

## Test

Open up `test.html` for browser testing.
Open up `test.html` for browser testing (keep your cursor away from the browser window).

## Methods

Expand Down Expand Up @@ -103,8 +103,8 @@ Takes an options object. Available options:
| enableGrab | Boolean | true | To be able to grab and drag the image for extra zoom-in. |
| preloadImage | Boolean | true | Preload images with attribute `data-original`. |
| transitionDuration | Number | 0.4 | Transition duration in seconds. [More](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-duration) |
| transitionTimingFunction | String | 'cubic-bezier(.4,0,0,1)' | Transition timing function. [More](https://developer.mozilla.org/en-US/docs/Web/CSS/single-transition-timing-function) |
| bgColor | String | '#fff' | Overlay background color. |
| transitionTimingFunction | String | 'cubic-bezier(0.4, 0, 0, 1)' | Transition timing function. [More](https://developer.mozilla.org/en-US/docs/Web/CSS/single-transition-timing-function) |
| bgColor | String | 'rgb(255, 255, 255)' | Overlay background color. |
| bgOpacity | Number | 1 | Overlay background capacity. |
| scaleBase | Number | 1.0 | The base scale factor for zooming. By default scale to fit the window. |
| scaleExtra | Number | 0.5 | The extra scale factor when grabbing the image. |
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zooming",
"version": "0.6.3",
"version": "0.6.4",
"homepage": "https://github.com/kingdido999/zooming",
"authors": [
"Desmond Ding <[email protected]>"
Expand Down
44 changes: 22 additions & 22 deletions build/zooming.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/zooming.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/zooming.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/zooming.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zooming",
"version": "0.6.3",
"version": "0.6.4",
"description": "Image zoom that makes sense.",
"main": "src/zooming.js",
"repository": {
Expand Down
21 changes: 0 additions & 21 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
// webkit prefix
const prefix = 'WebkitAppearance' in document.documentElement.style ? '-webkit-' : ''

const options = {
defaultZoomable: 'img[data-action="zoom"]',
enableGrab: true,
preloadImage: true,
transitionDuration: 0.4,
transitionTimingFunction: 'cubic-bezier(.4,0,0,1)',
bgColor: '#fff',
bgOpacity: 1,
scaleBase: 1.0,
scaleExtra: 0.5,
scrollThreshold: 40,
onOpen: null,
onClose: null,
onRelease: null,
onBeforeOpen: null,
onBeforeClose: null,
onBeforeGrab: null,
onBeforeRelease: null
}

const sniffTransition = (el) => {
let ret = {}
const trans = ['webkitTransition', 'transition', 'mozTransition']
Expand Down Expand Up @@ -90,7 +70,6 @@ const preloadImage = (url) => (new Image()).src = url

export {
prefix,
options,
sniffTransition,
checkTrans,
toggleListeners,
Expand Down
19 changes: 19 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const options = {
defaultZoomable: 'img[data-action="zoom"]',
enableGrab: true,
preloadImage: true,
transitionDuration: 0.4,
transitionTimingFunction: 'cubic-bezier(0.4, 0, 0, 1)',
bgColor: 'rgb(255, 255, 255)',
bgOpacity: 1,
scaleBase: 1.0,
scaleExtra: 0.5,
scrollThreshold: 40,
onOpen: null,
onClose: null,
onRelease: null,
onBeforeOpen: null,
onBeforeClose: null,
onBeforeGrab: null,
onBeforeRelease: null
}
6 changes: 4 additions & 2 deletions src/zooming.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { prefix, options, sniffTransition, checkTrans, toggleListeners, preloadImage } from './helpers'
import { prefix, sniffTransition, checkTrans, toggleListeners, preloadImage } from './helpers'
import { options } from './options'

// elements
const body = document.body
Expand Down Expand Up @@ -176,9 +177,10 @@ const eventHandler = {

// init ------------------------------------------------------------------------

overlay.setAttribute('id', 'zoom-overlay')
setStyle(overlay, {
zIndex: 998,
background: options.bgColor,
backgroundColor: options.bgColor,
position: 'fixed',
top: 0,
left: 0,
Expand Down
Loading

0 comments on commit c817593

Please sign in to comment.