• Stars
    star
    801
  • Rank 54,497 (Top 2 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 12 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Responsive design toolkit

Response

Response is an experimental jQuery/Ender/Zepto plugin that gives web designers tools for building responsive websites. It can dynamically swap content based on breakpoints and data attributes. (npm: response.js)

API (0.10)

Breakpoint sets

Response's main feature is its breakpoint sets. They offer the ability to serve different content via breakpoint-based data attributes. They are best applied with a mobile-first approach. Devs can choose custom breakpoints to create exactly data attributes they need. By default none are setup.

Sets are created either by calling Response.create(options) directly, or automatically via JSON stored in a body[data-responsejs]. The options can be a plain object or an array of them.

Response.create({
    prop: "width"  // "width" "device-width" "height" "device-height" or "device-pixel-ratio"
  , prefix: "min-width- r src"  // the prefix(es) for your data attributes (aliases are optional)
  , breakpoints: [1281,1025,961,641,481,320,0] // min breakpoints (defaults for width/device-width)
  , lazy: true // optional param - data attr contents lazyload rather than whole page at once
});

OR

<body data-responsejs='{
  "create": [
    { "prop": "width"
    , "prefix": "min-width- r src"
    , "lazy": true
    , "breakpoints": [1281,1025,961,641,481,320,0] }
  ]}'
>
To write markup like
<div data-min-width-481="markup @ 481px+" data-min-width-961="markup @ 961px+">
  default markup for 480px- or no-js
</div>

Extending

Define a custom breakpoint set that uses a custom test

/**
 * @param {string} prop custom property name (or an existing prop to override)
 * @param {Function} test callback to test min breakpoints for the prop
 */
Response.addTest('viewport-area', function(min) {
  return min >= Response.viewportW() * Response.viewportH();
}).create({
    prop: 'viewport-area' // custom prop name
  , breakpoints: [100000, 1000000, 10000000] // custom breakpoints
  , dynamic: true // set this to true if prop needs to be tested on resize
});

Methods from verge

Response.viewportW() // CSS viewport width
Response.viewportH() // CSS viewport height
Response.mq(mediaQuery) // => boolean
Response.inViewport(elem, cushion?) // => boolean
Response.inX(elem, cushion?) // => boolean
Response.inY(elem, cushion?) // => boolean
Response.scrollX() // => number
Response.scrollY() // => number

Device size

Response.deviceW() // device width
Response.deviceH() // device height
Response.deviceMax() // calculated Math.max(deviceW, deviceH)
Response.deviceMin() // calculated Math.min(deviceW, deviceH)

devicePixelRatio

Response.dpr(1.5) // true when device-pixel-ratio is 1.5+
Response.dpr(2) // true when device-pixel-ratio is 2+
Response.dpr() // get device-pixel-ratio - returns integer or float (0 if undetectable)

Viewport size ranges

Response.band(481) // true in viewports 481px wide and up.
Response.band(0, 480) // true in viewports 0-480px wide.
Response.wave(641) // true in viewport 641px high and up.
Response.wave(0, 640) // true in viewports 0-640px high.

Device size ranges

Response.device.band(481) // true for devices 481px wide and up
Response.device.band(0, 480) // true for devices 0-480px wide.
Response.device.wave(641) // true for devices 641px high and up.
Response.device.wave(0, 640) // true for devices 0-640px high.

Events

Call a function on breakpoint set crossovers

Response.crossover('width', function() {
  // runs when 'width' breakpoints are crossed
})

Response.crossover(function() {
  // runs when any defined breakpoint is crossed
})

@deprecated event utils

Response.ready(fn) // call fn on ready
Response.resize(fn) // call fn on resize
Response.action(fn|fns) // call fn(s) on ready *and* on resize

@deprecated dataset utils

Response.dataset(elem, key) // get
Response.dataset(elem, [key]) // get and render (See Response.render)
Response.dataset(elem, key, value) // set
Response.dataset(elem, atts) // set multiple data atts at once
Response.deletes(elem, keys) // delete one or more data atts
Response.dataset(document.body, "pulpFiction", 5) // sets <body data-pulp-fiction="5">
Response.dataset(document.body, "pulpFiction") // -> "5"
Response.dataset(document.body, ["pulpFiction"]) // -> 5

Response.render(str) // convert stringified primitives to correct value e.g. "true" to true
Response.camelize(str) // convert 'pulp-fiction' or 'data-pulp-fiction' to pulpFiction
Response.datatize(str) // convert 'pulpFiction' to 'data-pulp-fiction'
Response.target(keys) // convert keys like "a b c" or ["a","b","c"] to $("[data-a],[data-b],[data-c]")
Response.access(keys) // access an array of dataset values that correspond to an array of dataset keys
Response.store($elems, key, attrToReadFrom?) // store init content of each elem to data key

@deprecated object utils

Response.affix(stack, prefix?, suffix?) // create array w/ prefix|suffix added to each stack value
Response.each(stack, fn, scope?) // call fn for each item in stack
Response.map(stack, fn, scope?) // map stack into a new array
Response.merge(target, source) // merge source's defined values into target
Response.object(parent) // create a new object that inherits parent (via Object.create where possible)
Response.route(stack|other, fn, scope?) // call fn on each stack value or on a non-stack
Response.sift(stack, fn?, scope|invert?) // like _.compact, [].filter, and jQuery.grep

.noConflict()

Re: fetch

// Unmodify window
Response.noConflict()
// Unmodify window and save reference to our Response
let R = Response.noConflict()
Response.noConflict(function(Response) {
  // Unmodify window and get safe reference to our Response in here
})

AMD usage

define(['jquery'], Response.noConflict);  // define module and unmodify window

Resources

Related Modules

  • verge - viewport utilities
  • actual - @media detector
  • dope - dataset abstraction
  • res - resolution utilities

More Repositories

1

verge

Get viewport dimensions, detect elements in the viewport, trust in <!DOCTYPE html>
JavaScript
696
star
2

actual

Determine actual CSS media query breakpoints via JavaScript
JavaScript
50
star
3

res

Device resolution detection module
JavaScript
39
star
4

eol

JavaScript newline character converter
JavaScript
37
star
5

ux

Website user preference API
JavaScript
30
star
6

flexboxes

CSS flexbox framework with pure flexbox grid ability
HTML
27
star
7

slash

PHP URI and path utilities.
PHP
17
star
8

dope

Cross-browser HTML5 dataset module
JavaScript
15
star
9

draf

double RAF JavaScript module
HTML
13
star
10

css3base

base stylesheets collection
ApacheConf
12
star
11

tunes

HTML5 audio and video playlists
JavaScript
11
star
12

numerologia

dark themed numerology calculator
HTML
9
star
13

energy

Universal JavaScript event emitter
JavaScript
8
star
14

chemical

JavaScript chemical API
JavaScript
7
star
15

fm

JavaScript function modulation
JavaScript
7
star
16

cxn

Network connection JavaScript utility module
JavaScript
7
star
17

symlinked

Got symlinked packages?
JavaScript
7
star
18

cargo

Web storage API JavaScript module
JavaScript
7
star
19

said

Run CLI commands and return output as string
JavaScript
6
star
20

vibe

CSS classes for the masses
JavaScript
6
star
21

ssv

Space Separated Values. JavaScript library for spaced data. Fun and fast for classnames and beyond ๐Ÿ’•
JavaScript
6
star
22

fit

Base responsive CSS for HTML5 elements
CSS
5
star
23

rave

PHP that you can dance to
PHP
5
star
24

traits

Opensource PHP traits
PHP
5
star
25

subtag

Language tag parser for JavaScript and Node.js
JavaScript
5
star
26

action

Extensible HTML5 WordPress parent theme
PHP
5
star
27

speculative

prerender, preconnect, preload, prefetch, dns-prefetch
JavaScript
5
star
28

bypass

WP plugin that allows you to write entry markup in files rather than in the WP editor
PHP
4
star
29

scan

querySelectorAll selector engine
JavaScript
4
star
30

lap

JavaScript performance testing library
JavaScript
4
star
31

elo

Lo-fi JavaScript events module.
JavaScript
4
star
32

spacing

Opensource functional CSS spacing for web spaces
CSS
4
star
33

a11y

accessibility resources
4
star
34

dime

Cross-browser JavaScript dimensions module
JavaScript
4
star
35

mark

JavaScript object tracking system
JavaScript
4
star
36

universal

JavaScript universal module template
JavaScript
3
star
37

arro

left/right arrow keyboard shortcuts
JavaScript
3
star
38

downtime

Do background work during browser idle time.
JavaScript
3
star
39

templace

HTML template tag progressive content loader with minimal JavaScript
HTML
3
star
40

emoter

JavaScript event emitter for state changes
JavaScript
3
star
41

aok

Simple JavaScript test suite API
JavaScript
3
star
42

flish

JavaScript flash message module
JavaScript
3
star
43

dj

JavaScript module integration API
JavaScript
3
star
44

resilient-css

Resilient CSS talk slides
HTML
3
star
45

plays

Detect playable audio and video filetypes
JavaScript
3
star
46

taos

Toggle areas or styles via HTML5 data attributes
JavaScript
3
star
47

map-file

Map a file into another file in Node.js
JavaScript
3
star
48

varam

change CSS var via URL param with this 77 line library called varam
JavaScript
3
star
49

all-filler

Fill function for arrays or strings based on array.fill
JavaScript
2
star
50

path

PHP filesystem utilities
PHP
2
star
51

access

WP plugin to control user access via taxonomy terms
PHP
2
star
52

image_src

WP plugin for image_src
PHP
2
star
53

yearly

Year utility to test or bump year in a string. Useful for keeping license files current.
JavaScript
2
star
54

cueing

JavaScript utility to cue, seek, or cycle items
JavaScript
2
star
55

edit-file

Edit a file in Node.js
JavaScript
2
star
56

blood

JavaScript object life
JavaScript
2
star
57

avant

Cross-browser JavaScript events module
JavaScript
2
star
58

chromosome

JSON-based template engine available for PHP or node.js
PHP
2
star
59

wtb

what the box dimension parser
JavaScript
2
star
60

aaronirwin.com

Aaron Irwin's website
CSS
2
star
61

annex

DOM insertion module
JavaScript
2
star
62

focux

Match :focus-within for better focus experience
HTML
2
star
63

border.css

Opensource functional CSS border classes
HTML
2
star
64

freeform.css

Functional expressive CSS for rapid prototyping
CSS
2
star
65

modder

JavaScript: mod your modules
JavaScript
2
star
66

phat

PHP HTML utility module
PHP
2
star
67

often

Async recursive JavaScript timers
JavaScript
2
star
68

sharp.css

CSS sharp corners
CSS
2
star
69

oi

cross-browser DOM ready module
JavaScript
2
star
70

format

free template for you all blank uno
HTML
2
star
71

skate

JavaScript app state manager
JavaScript
2
star
72

ryanve.github.io

Featured Github Pages
HTML
1
star
73

resume

Heartbearts
HTML
1
star
74

4everstatic

This talk is for creators like you.
1
star
75

media

HTML
1
star
76

admit

JavaScript array admit/ban/check utility module
JavaScript
1
star
77

daw

work in progress
1
star
78

primals

Parse stringified JavaScript primitives
JavaScript
1
star
79

togg

Angular UI toggle behavior directive
HTML
1
star
80

404

404 page examples
1
star
81

overflow.css

CSS overflow classes
CSS
1
star
82

eros

rose
HTML
1
star
83

.github

CSS
1
star
84

ryan

sea
HTML
1
star
85

22

1
star
86

glimpse

moon
CSS
1
star
87

tx.css

Opensource CSS text utility classes
HTML
1
star
88

echo

natal
HTML
1
star
89

woas

opensource phrase guessing game made with static HTML and fresh CSS
HTML
1
star
90

tropicolor

HTML
1
star
91

cue

CSS
1
star
92

sappho

frog awash in butterfly tones
1
star
93

thunder

dub speaking
CSS
1
star
94

refresh

compassion
1
star
95

routine

moon
1
star
96

halfaxa

halfaxa era style like a comeback kid
HTML
1
star
97

moon

0ยบ aquarius
1
star
98

some-own

JavaScript someOwn function
JavaScript
1
star
99

pages

graf
HTML
1
star
100

natal

natal chart
HTML
1
star