Git Product home page Git Product logo

unison's Introduction

Unison.js

NOTE: I'm looking for someone to take over maintaining this repo. See more here.

Syncing named breakpoints across CSS, JS, and HTML.

Demo and more information here.

SASS Integration

Declare breakpoints and specify names in _breakpoints.scss

// declare breakpoints
$usn-x-small         : 200px;
$usn-small           : 400px;
$usn-small-medium    : 600px;
$usn-medium          : 800px;
$usn-large-medium    : 1000px;
$usn-large           : 1200px;
$usn-x-large         : 1400px;

// create sass list to pass media query data
// if a breakpoint name changes, remember to
// update it in the list below as well
$mq-sync:
  usn-x-small        $usn-x-small,
  usn-small          $usn-small,
  usn-small-medium   $usn-small-medium,
  usn-medium         $usn-medium,
  usn-large-medium   $usn-large-medium,
  usn-large          $usn-large,
  usn-x-large        $usn-x-large
;

LESS Integration

Declare breakpoints and specify names in breakpoints.less

// declare breakpoints
@usn-x-small         : 200px;
@usn-small           : 400px;
@usn-small-medium    : 600px;
@usn-medium          : 800px;
@usn-large-medium    : 1000px;
@usn-large           : 1200px;
@usn-x-large         : 1400px;

// create list to pass media query data
// if a breakpoint name changes, remember to
// update it in the list below as well
@breakpoints: "usn-x-small @{usn-x-small}",
              "usn-small @{usn-small}",
              "usn-small-medium @{usn-small-medium}",
              "usn-medium @{usn-medium}",
              "usn-large-medium @{usn-large-medium}",
              "usn-large @{usn-large}",
              "usn-x-large @{usn-x-large}";

// you need to explicity tell LESS how many
// breakpoints you have
@number-of-breakpoints: 7;

Stylus Integration

Declase breakpoints and specify names in breakpoints.styl

// declare breakpoints
$usn-x-small         = 200px
$usn-small           = 400px
$usn-small-medium    = 600px
$usn-medium          = 800px
$usn-large-medium    = 1000px
$usn-large           = 1200px
$usn-x-large         = 1400px

// create list to pass media query data
// if a breakpoint name changes, remember to
// update it in the list below as well
$mq-sync = usn-x-small        $usn-x-small,
           usn-small          $usn-small,
           usn-small-medium   $usn-small-medium,
           usn-medium         $usn-medium,
           usn-large-medium   $usn-large-medium,
           usn-large          $usn-large,
           usn-x-large        $usn-x-large

Manual Installation

Include unison.min.js on your page:

<script src="unison.min.js"></script>

Verify everything is working by entering Unison.fetch.all() in the javascript console of your browser. If the CSS is not set up properly, or your page is missing the title tag, the returned value will be null.

Bower Installation

If you're using Bower:

bower install unison

Then point to the script within the bower_components directory:

<script src="bower_components/unison/js/unison.min.js"></script>

The various preprocessor partials can be found in bower_components/unison/css/.

Unison Responsive Comments

Please view the demo page to see how Responsive Comments conditional loading is implemented via Unison.

Version History

0.6.0 - Mar 20, 2014 - Added events and refactored conditional comments to not use matchMedia.

0.5.1 - Jan 15, 2014 - Updated to include Bower integration.

0.5.0 - Dec 29, 2013 - First release. Basic breakpoint syncing.

License

The MIT License (MIT)

Copyright (c) 2014 Dan Chilton

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

unison's People

Contributors

bjork24 avatar dilrajahdan avatar glockops avatar jason-cooke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unison's Issues

Add LESS support

I know you mentioned this and it's on the way. Just creating this issue so that I'll get an email update when done.

Thx a lot!

Conditional comment loading

Not an issue as such but you should be aware that some anti virus programs that actively scan users website behaviour treat (and thus block the page) certain hidden html comments as a threat.

We came across this behaviour last year when commenting out a link to a facebook group page in some html and Kaspersky Antivirus picked it up as a false positive and blocked the entire page from rendering, displaying to the user that the site was compromised. Once the comment was removed the site was fine.

I have contacted Kaspersky regarding this and they say it's expected and intended behaviour.

The moral of the story is be careful what you're commenting out as it may be seen and blocked by third party software and if you don't run the software (like me) then you may never find out and may lose traffic/users etc until someone nice points it out :)

Breakpoint is confusing

When I read the title and documentation I was really confused. I was thinking about JavaScript debugging breakpoint. I tried to figure out what a HTML breakpoint means (maybe when some properties change in a DOM node) and I couldn't find a reasonable explanation for CSS.

I took me half of the documentation to realize that you were talking about different sizes of browsers.

I would recommend to clearly define breakpoint very early in your docs :)

DOMContentLoaded fired before loading Unison

I'm using Unison with Require.js

require.config({
    paths: {
    unison: '../bower_components/unison/js/unison'
  },
    shim: {
        'unison': { exports: 'Unison' }
    }
});

But then, Unison is loaded after DOMContentLoaded event, and because Unison is registering listener to that event to initialize itself, it will not start correctly.

doc.addEventListener('DOMContentLoaded', function(){
      unisonReady = win.getComputedStyle(head, null).getPropertyValue('clear') !== 'none';
      breakpoints.update();
    });

I managed to fix it, but I'm not sure if it's good approach

if (document.readyState == "complete" || document.readyState == "loaded") {
     // init()
} else {
  doc.addEventListener('DOMContentLoaded', function(){
    // init();
  });
}

Listen from js for breakpoint change event

I think it'd be very useful if unison.js provided a way for listening when the breakpoint changes.

Something like:

Unison.getBreakpoints().onChange(function(newBreakpoint){
});

Documentation improvement

Nothing big, but could clear up some confusion folks might have.

In the "How does it work" section you create the breakpoint variables, add them into the $mq-sync list, add the script, and call it done. In reality, that's not all it takes to get this working though because you mention in the next section "Behind the scenes" that there's a breakpoint file where the media queries are generated and some information is saved into the head.

Without reading that part, which comes after things are said to be working, or looking into the repo and looking through breakpoints files it's pretty easy to get lost along the way.

I'd make a pull request of it if the HTML was available in the repo, but it's a pretty small fix anyway. Great job though, looks like a tool with some really interesting possibilities!

Looking for contributors

As you can see from my lack of updates, I haven't had time to properly maintain Unison.js. If any of you would be willing to take over and contribute, please let me know. Thanks!

LESS 1.3.6 > extract is not defined

Trying to get Unison up and running.

Less watcher is throwing the following error:

SytaxError: JavaScript evaluation error: 'ReferenceError: extract is not defined' in ....

Any ideas? Where can I find the extract function/mixin?

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.