Skip to content

Commit

Permalink
Added grunt and delete method
Browse files Browse the repository at this point in the history
- Added grunt for uglification
- Added $.breakpoint.remove
- Use jsdoc comments
  • Loading branch information
Martin Jansson committed Apr 28, 2015
1 parent d9f50c5 commit 5625d6b
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 17 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

codekit-config.json
node_modules
20 changes: 20 additions & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
build: {
files: {
'js/jquery.breakpoint-min.js': 'js/jquery.breakpoint.js'
}
}
}
});

// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');

// Default task(s).
grunt.registerTask('default', ['uglify']);
};
5 changes: 1 addition & 4 deletions js/jquery.breakpoint-min.js

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

33 changes: 26 additions & 7 deletions js/jquery.breakpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@

var breakpoints = [];

// Adds a breakpoint object with the following properties:
//
// condition = a function returning a boolean for whether this breakpoint should be active or not.
// first_enter = a function which will execute the FIRST TIME condition() is true.
// enter = a function which will execute everytime condition() turns from false to true.
// exit = a function which will execute everytime condition() turns from true to false.
/**
* Add a breakpoint object
*
* @param {object} breakpoint - Breakpoint to add
* @param {function} breakpoint.condition - Return a boolean for whether this breakpoint should be active or not
* @param {function} breakpoint.first_enter - Will execute the FIRST TIME condition() is true.
* @param {function} breakpoint.enter - Will execute everytime condition() turns from false to true.
* @param {function} breakpoint.exit - Will execute everytime condition() turns from true to false.
* @param {object} [options]
*/
$.breakpoint = function (breakpoint, options) {

options = $.extend(true, {}, $.breakpoint.defaults, options);
Expand All @@ -29,7 +33,22 @@
// Array of all added breakpoints.
$.breakpoint.breakpoints = breakpoints;

// Allow checking a single breakpoint from outside of plugin.
/**
* Remove a breakpoint
* @param {object} breakpoint - Breakpoint object as described in $.breakpoint
*/
$.breakpoint.remove = function (breakpoint) {
var index;

while ((index = $.inArray(breakpoint, $.breakpoint.breakpoints)) !== -1) {
$.breakpoint.breakpoints.splice(index, 1);
}
};

/**
* Remove a breakpoint
* @param {object} breakpoint - Breakpoint object as described in $.breakpoint
*/
$.breakpoint.check = function (breakpoint) {
checkSingleBreakpoint(breakpoint);
};
Expand Down
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "jquery.breakpoint",
"version": "1.2.0",
"description": "A simple way to use media queries in your jQuery javascripts!",
"main": "gruntfile.js",
"directories": {
"test": "tests"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/martinmartinmartin/breakpoint.git"
},
"author": "Martin Jansson [email protected]",
"license": "ISC",
"bugs": {
"url": "https://github.com/martinmartinmartin/breakpoint/issues"
},
"homepage": "https://github.com/martinmartinmartin/breakpoint",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-uglify": "^0.9.1"
}
}
30 changes: 30 additions & 0 deletions tests/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,36 @@
<head>
<meta charset="utf-8" />
<title>breakpoint demo</title>
<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="../js/jquery.breakpoint.js"></script>
<script>
$(function () {
var b = {
condition: function () {
return window.matchMedia('only screen and (min-width:500px)').matches;
},
first_enter: function () {
// Code will run the first time condition() is true.
// Here, you might create elements to use in
// your enter and exit methods.
console.info('First enter breakpoint');
},
enter: function () {
// Code will run whenever condition() becomes true.
console.info('Enter breakpoint');
},
exit: function () {
// Code will run whenever condition() becomes false
// (if it was previously true).
// This is where you revert the things you do in the
// enter method.
console.info('Exit breakpoint');
}
};

$.breakpoint(b);
});
</script>
</head>
<body>
</body>
Expand Down
4 changes: 0 additions & 4 deletions tests/test.js

This file was deleted.

0 comments on commit 5625d6b

Please sign in to comment.