• Stars
    star
    125
  • Rank 284,712 (Top 6 %)
  • Language
    JavaScript
  • License
    GNU General Publi...
  • Created over 12 years ago
  • Updated over 11 years ago

Reviews

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

Repository Details

Read the blog post which describes these tools with a nice demo:

http://edenspiekermann.com/en/blog/responsive-javascript-helpers

minwidth.js

minwidth.js is a javascript library that helps you create fantastic mobile first websites. You provide a width at which your functions are called.

Several use-cases have occured so many times that it made sense to sort this problem out properly. One thing that happened to us often when designing mobile first web-sites is that some elements need to be in a different place in the DOM on wider screens. Another problem was loading certain scripts only desktop screens.

minwidth.js lets you bind to resize events on an advanced level. You provide a screen width and a callback function which is called whenever this width is crossed. You may provide another function which is called when the window is resized back below that width.

minwidth(600, function() {
  doSomethingLikeLoadFacebook();
});

interface

minwidth(width, forwardCallback, backwardCallback, desktopFirst);

width specifies the breakpoint at which the callbacks should be fired.

forwardCallback is the function that is called if the screen is wider than than the width.

backwardCallback (optional) is the function that is called if the screen becomes smaller than than the width.

desktopFirst (optional) is a boolean which lets you specify that you want to work in a desktop-first fashion. If true, the backwardCallback is then called if the screen is initially smaller than the width, the forwardCallback will only be called if the screen becomes wider than the width, in this case you can pass false as an argument to the forwardCallback.

relocate.js

relocate.js lets you move elements in the DOM from their original place to another when you can't do that desktop design with CSS media queries.

For example move selected items into the sidebar which are mixed into the regular page on mobile devices.

var elements = document.getElementsByClassName("movethis");
var sidebar = document.getElementById("sidebar");
relocate(480, elements, sidebar);

Note: IE8 and less don't have getElementsByClassName, you can use jQuery or this getElementsByClassName polyfill

interface

relocate(width, elements, destinationElement, desktopFirst);

width specifies the breakpoint at which the elements should be relocated.

elements can be a single HTMLElement or an Array of HTMLElements, a NodeList or a HTMLCollection. They will be relocated.

destinationElement is the HTMLElement into which the elements will be relocated.

desktopFirst (optional) is a boolean which lets you specify that you want to work in a desktop-first fashion. If true, the elements will only be relocated if the screen is initially smaller or becomes smaller than the given width.

Minification

rm minwidth-relocate.min.js && cat *.js | uglifyjs -nc > minwidth-relocate.min.js

License

The code is dual-licensed under the GNU General Public License Version 2 (GPLv2) and the MIT License.

More Repositories

1

sprite.sh

A Bash script to build a SVG sprite from a folder of SVG files (typically icons).
JavaScript
327
star
2

a11y-toggle

A tiny script for accessible content toggles.
HTML
304
star
3

iframify

Replace a node with an iframe version of itself
JavaScript
212
star
4

outline-audit

A script to test the heading outline of a document
HTML
114
star
5

faster-react-tabs

JavaScript
48
star
6

gatsby-source-shopify-storefront

Gatsby source plugin for building websites using product data from the Shopify Storefront API
JavaScript
31
star
7

craft3-heroku-starterkit

This is a starter kit for Craft3 which helps you to install the CMS on Heroku
JavaScript
18
star
8

transync

A npm module to synchronise translation files.
JavaScript
10
star
9

nanoc-html5-template

A nanoc template using Sass, Haml and Compass Html5 Boilerplate
JavaScript
10
star
10

espi-devblog

Edenspiekermann Developer Blog
HTML
9
star
11

craft-jwt-auth

Enable authentication to Craft through the use of Javascript Web Tokens (JWT)
PHP
5
star
12

espi-eslint-config

ESLint configuration
JavaScript
3
star
13

espi-dni

PostBot for DNI Project
Elixir
3
star
14

themer

A Tumblr theme parser for local development.
PHP
3
star
15

edenspiekermann-storybook-starter

Boilerplate repo for React-based component libraries
CSS
2
star
16

bright

JavaScript
2
star
17

site-status

Keep track of website development status
Ruby
2
star
18

static-importer

JavaScript
1
star
19

card-builder-docs

Docs to assist with the implementation of Card Builder (http://cards.edenspiekermann.com/)
1
star
20

signals

Signals from content
JavaScript
1
star
21

react-project-examples

Example projects to test styleguide usage
JavaScript
1
star
22

kupong_integration

Ruby
1
star