├── .gitignore
├── Gruntfile.js
├── README.md
├── bower.json
├── breakpoint-0.0.1.js
├── breakpoint-0.0.1.min.js
├── js
├── breakpoint.js
└── breakpoint.min.js
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | module.exports = function(grunt) {
2 |
3 | grunt.initConfig({
4 | pkg: grunt.file.readJSON('package.json'),
5 | banner:
6 | '/*!\n' +
7 | ' * <%= pkg.name %> v<%= pkg.version %>\n' +
8 | ' *\n' +
9 | ' * BREAKPOINT DIRECTIVE FOR RESPONSIVE WEBSITES\n' +
10 | ' *\n' +
11 | ' * https://github.com/snapjay/angularjs-breakpoint\n' +
12 | ' * http://snapjay.github.com/angularjs-breakpoint/\n' +
13 | ' *\n' +
14 | ' * Apply as a attribute of the body tag. Set\n' +
15 | ' * breakpoint="{1250:\'break1250\', 1000:\'break1000\',1120:\'break1120\'}\n' +
16 | ' *\n' +
17 | ' * Values are available on scope as\n' +
18 | ' * {{breakpoint.class}} = current set class\n' +
19 | ' * {{breakpoint.windowSize}} = current width of window\n' +
20 | ' */\n',
21 |
22 | concat: {
23 | options: {
24 | banner: '<%= banner %>',
25 | stripBanners: false
26 | },
27 | application: {
28 | src: ['js/breakpoint.js'],
29 | dest: '<%= pkg.title %>-<%= pkg.version %>.js'
30 | }
31 | },
32 |
33 | uglify: {
34 | options: {
35 | banner: '<%= banner %>'
36 | },
37 | application: {
38 | src: ['<%= concat.application.dest %>'],
39 | dest: '<%= pkg.title %>-<%= pkg.version %>.min.js'
40 | }
41 | }
42 |
43 | });
44 |
45 | grunt.loadNpmTasks('grunt-contrib-uglify');
46 | grunt.loadNpmTasks('grunt-contrib-concat');
47 |
48 | grunt.registerTask('build', ['concat', 'uglify']);
49 | };
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | AngularJS Breakpoint
2 | --------------------
3 |
4 | http://snapjay.github.com/angularjs-breakpoint/
5 |
6 |
7 | AngularJS directive that set breakpoints for responsive websites.
8 | -----------------------------------------------------------------
9 | Add the breakpoint directive to the body tag
10 | Define as many breakpoints as you want in an object
11 | Current breakpoint class and window width available in scope
12 |
13 |
14 | Setup
15 | -----
16 | Add the breakpoint attribute to the body tag and give it a value off an object defined as follows:
17 | Set the key as the smallest value you want the breakpoint to start at and the value as the name of the class you want added to the body tag.
18 | The values do not need to be in numerical order.
19 | I recommend that the lowest value is 0
20 | ```
21 |
22 | ...
23 |
24 | ```
25 | The 'current class' and 'current window width' are available on the scope as break1500 and 1680
26 |
27 |
28 |
29 | Events
30 | -------
31 | You can set a listener on any scope within your app, by using the scope method $on. The triggered event is called
32 | right after the class of the element has been changed.
33 | ```
34 | $scope.$on('breakpointChange', function(event, breakpoint, oldClass) {
35 | console.log('Entering:' + breakpoint.class);
36 | console.log('Leaving:' + oldClass);
37 | console.log('windowSize' + breakpoint.windowSize);
38 | });
39 | ```
40 |
41 | Contribution
42 | ------------
43 | This project is built with GruntJS. To contribute to this project make sure to install node.js and npm.
44 | Assuming npm is installed, run `$ npm install` inside the project directory to install the dependencies and you should
45 | be ready to go.
46 | Once you make a change, use `$ grunt build` inside the project folder to build the distribution files.
47 | The version number is determined from the `package.json` file inside the project directory.
48 |
49 |
50 | Download on Github
51 | ------------------
52 | Version 0.0.1: https://github.com/snapjay/angularjs-breakpoint
53 |
54 |
55 |
56 | License
57 | -------
58 |
59 | This module is licensed using the MIT License:
60 |
61 | ```
62 | The MIT License (MIT)
63 |
64 | Copyright (c) 2013 Dan Shreim
65 |
66 | Permission is hereby granted, free of charge, to any person obtaining a copy of
67 | this software and associated documentation files (the "Software"), to deal in
68 | the Software without restriction, including without limitation the rights to
69 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
70 | the Software, and to permit persons to whom the Software is furnished to do so,
71 | subject to the following conditions:
72 |
73 | The above copyright notice and this permission notice shall be included in all
74 | copies or substantial portions of the Software.
75 |
76 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
77 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
78 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
79 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
80 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
81 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
82 | ```
83 |
84 |
85 |
86 |
87 | Credit
88 | ------
89 | Dan Shreim
90 | @snapjay
91 | http://snapjay.com
92 | If you use the script, please let me know @snapjay; Don't worry, I won't ask for anything!
93 |
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "angularjs-breakpoint",
3 | "version": "1.0.0",
4 | "main": "js/breakpoint.min.js",
5 | "ignore": [
6 | ".*"
7 | ]
8 | }
9 |
--------------------------------------------------------------------------------
/breakpoint-0.0.1.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * angularjs-breakpoint v0.0.1
3 | *
4 | * BREAKPOINT DIRECTIVE FOR RESPONSIVE WEBSITES
5 | *
6 | * http://snapjay.github.com/angularjs-breakpoint/
7 | * Apply as a attribute of the body tag. Set
8 | * breakpoint="{1250:'break1250', 1000:'break1000',1120:'break1120'}
9 | *
10 | * Values are available on scope as
11 | * {{breakpoint.class}} = current set class
12 | * {{breakpoint.windowSize}} = current width of window
13 | */
14 | var breakpointApp = angular.module('breakpointApp',[]);
15 |
16 | breakpointApp.directive('breakpoint', ['$window', '$rootScope', function($window, $rootScope){
17 | return {
18 | restrict:"A",
19 | link:function(scope, element, attr){
20 | scope.breakpoint = {class:'', windowSize:$window.innerWidth }; // Initialise Values
21 |
22 | var breakpoints = (scope.$eval(attr.breakpoint));
23 | var firstTime = true;
24 |
25 | angular.element($window).bind('resize', setWindowSize);
26 |
27 | scope.$watch('breakpoint.windowSize', function(windowWidth, oldValue){
28 | setClass(windowWidth);
29 | });
30 |
31 | scope.$watch('breakpoint.class', function(newClass, oldClass) {
32 | if (newClass != oldClass || firstTime) {
33 | broadcastEvent(oldClass);
34 | firstTime = false;
35 | }
36 | });
37 |
38 | function broadcastEvent (oldClass) {
39 | $rootScope.$broadcast('breakpointChange', scope.breakpoint, oldClass);
40 | }
41 |
42 | function setWindowSize (){
43 | scope.breakpoint.windowSize = $window.innerWidth;
44 | if(!scope.$$phase) scope.$apply();
45 | }
46 |
47 | function setClass(windowWidth){
48 | var setClass = breakpoints[Object.keys(breakpoints)[0]];
49 | for (var breakpoint in breakpoints){
50 | if (breakpoint < windowWidth) setClass = breakpoints[breakpoint];
51 | element.removeClass(breakpoints[breakpoint]);
52 | }
53 | element.addClass(setClass);
54 | scope.breakpoint.class = setClass;
55 | if(!scope.$$phase) scope.$apply();
56 | }
57 | }
58 | }
59 | }]);
60 |
--------------------------------------------------------------------------------
/breakpoint-0.0.1.min.js:
--------------------------------------------------------------------------------
1 |
2 | /*!
3 | * angularjs-breakpoint v0.0.1
4 | *
5 | * BREAKPOINT DIRECTIVE FOR RESPONSIVE WEBSITES
6 | *
7 | * http://snapjay.github.com/angularjs-breakpoint/
8 | * Apply as a attribute of the body tag. Set
9 | * breakpoint="{1250:'break1250', 1000:'break1000',1120:'break1120'}
10 | *
11 | * Values are available on scope as
12 | * {{breakpoint.class}} = current set class
13 | * {{breakpoint.windowSize}} = current width of window
14 | */
15 | var breakpointApp=angular.module("breakpointApp",[]);breakpointApp.directive("breakpoint",["$window","$rootScope",function(a,b){return{restrict:"A",link:function(c,d,e){function f(a){b.$broadcast("breakpointChange",c.breakpoint,a)}function g(){c.breakpoint.windowSize=a.innerWidth,c.$$phase||c.$apply()}function h(a){var b=i[Object.keys(i)[0]];for(var e in i)a>e&&(b=i[e]),d.removeClass(i[e]);d.addClass(b),c.breakpoint.class=b,c.$$phase||c.$apply()}c.breakpoint={"class":"",windowSize:a.innerWidth};var i=c.$eval(e.breakpoint);angular.element(a).bind("resize",g),c.$watch("breakpoint.windowSize",function(a){h(a)}),c.$watch("breakpoint.class",function(a,b){a!=b&&f()})}}}]);
--------------------------------------------------------------------------------
/js/breakpoint.js:
--------------------------------------------------------------------------------
1 | var breakpointApp = angular.module('breakpointApp',[]);
2 |
3 | breakpointApp.directive('breakpoint', ['$window', '$rootScope', function($window, $rootScope){
4 | return {
5 | restrict:"A",
6 | link:function(scope, element, attr){
7 | scope.breakpoint = {class:'', windowSize:$window.innerWidth }; // Initialise Values
8 |
9 | var breakpoints = (scope.$eval(attr.breakpoint));
10 |
11 | angular.element($window).bind('resize', setWindowSize);
12 |
13 | scope.$watch('breakpoint.windowSize', function(windowWidth, oldValue){
14 | setClass(windowWidth);
15 | });
16 |
17 | scope.$watch('breakpoint.class', function(newClass, oldClass) {
18 | if (newClass != oldClass) broadcastEvent(oldClass);
19 | });
20 |
21 | function broadcastEvent (oldClass) {
22 | $rootScope.$broadcast('breakpointChange', scope.breakpoint, oldClass);
23 | }
24 |
25 | function setWindowSize (){
26 | scope.breakpoint.windowSize = $window.innerWidth;
27 | if(!scope.$$phase) scope.$apply();
28 | }
29 |
30 | function setClass(windowWidth){
31 | var breakpointClass = breakpoints[Object.keys(breakpoints)[0]];
32 | for (var breakpoint in breakpoints){
33 | if (breakpoint < windowWidth) breakpointClass = breakpoints[breakpoint];
34 | element.removeClass(breakpoints[breakpoint]);
35 | }
36 | element.addClass(breakpointClass);
37 | scope.breakpoint.class = breakpointClass;
38 | if(!scope.$$phase) scope.$apply();
39 | }
40 | }
41 | };
42 | }]);
43 |
--------------------------------------------------------------------------------
/js/breakpoint.min.js:
--------------------------------------------------------------------------------
1 | /*
2 | * angularjs-breakpoint v0.0.1
3 | * http://snapjay.github.com/angularjs-breakpoint/
4 | */
5 |
6 | var breakpointApp=angular.module("breakpointApp",[]);breakpointApp.directive("breakpoint",["$window","$rootScope",function(e,t){return{restrict:"A",link:function(n,r,i){function o(e){t.$broadcast("breakpointChange",n.breakpoint,e)}function u(){n.breakpoint.windowSize=e.innerWidth;if(!n.$$phase)n.$apply()}function a(e){var t=s[Object.keys(s)[0]];for(var i in s){if(i