Giter Site home page Giter Site logo

dahling.js's Introduction

dahling.js

An ultra-simple and lightweight media query js/css loader (~1.4kb minified)

Features

dahling.js provides simple functions at present:

  1. It determines if the browser is currently in a particular media mode (on load). Use the same media query as you would in CSS or in a <link> file.
  2. It provides the ability to load external (plain or versioned) JS or CSS files - individually or as an array.
  3. Load assets and accomplish other tasks using conditional logic.

Methods

  • dahling()
  • load()

Examples

<script type="text/javascript" src="dahling.js"></script>
<script type="text/javascript">

   if (dahling("screen and (max-width:800px)")){
      //do something for the screen
   }
	 
   if (dahling("all and (orientation:portrait)")){
      //react to portrait mode
   } 


// Load external files
   if (dahling("screen and (max-width:481px)")){
      
   // Load required JS file based on max-width
      load('mobile.js');
      
   // Load several files
      load(['mobile.js','mobile.css']);
      
   // Load versioned files
      load('mobile.js?123');
      load('mobile.css?456');
      
   // Log notification to the console
      console.log("Mobile mode");
      
   // Alert the user
      alert("Mobile mode");
      
   }

</script>

Roadmap

  • Include addListeners - enabling loading/actions on media query state changes
  • Add generic classes for desktop, tablet, phone
  • Look at the ability to include queries for specific devices

Forks and contributors welcomed.

License

Copyright © 2010-2013 Nick Harrison <https://github.com/nickhar>

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.

dahling.js's People

Contributors

nickhar avatar

Watchers

 avatar

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.