Skip to content

Commit f83027a

Browse files
author
Maciej Gurban
committed
Merge pr4 with master, update docs
1 parent 2418aaa commit f83027a

File tree

6 files changed

+49
-49
lines changed

6 files changed

+49
-49
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
### Changelog
22

3+
**2.3.0**
4+
5+
Removing the requirement to insert visibility divs into the document.
6+
37
**2.2.0**
48

59
Introducing `current` method returning breakpoint alias, and `breakpoints` property allowing to specify your own breakpoint names.

README.md

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ if (viewport.is('lg')) {
2828
````javascript
2929
$(window).bind('resize', function() {
3030
viewport.changed(function() {
31-
31+
3232
// do some other stuff!
33-
33+
3434
})
3535
});
3636
````
@@ -40,9 +40,9 @@ $(window).bind('resize', function() {
4040
````javascript
4141
$(window).bind('resize', function() {
4242
viewport.changed(function() {
43-
43+
4444
// do some other stuff!
45-
45+
4646
}, 600)
4747
});
4848
````
@@ -52,9 +52,9 @@ $(window).bind('resize', function() {
5252
````javascript
5353
$(window).bind('resize', function() {
5454
viewport.changed(function() {
55-
55+
5656
console.log( 'Current breakpoint: '+ viewport.current() );
57-
57+
5858
})
5959
});
6060
````
@@ -64,7 +64,7 @@ $(window).bind('resize', function() {
6464

6565
````css
6666
h1 {
67-
@include set(font-size, (xs: 20px, sm: 24px, md: 24px, lg: 30px) );
67+
@include set(font-size, (xs: 20px, sm: 24px, md: 24px, lg: 30px) );
6868
}
6969
````
7070

@@ -98,16 +98,10 @@ Output:
9898
Include just before `</body>`
9999

100100
````html
101-
<!-- Mandatory for Responsive Bootstrap Toolkit to operate -->
102-
<div class="device-xs visible-xs"></div>
103-
<div class="device-sm visible-sm"></div>
104-
<div class="device-md visible-md"></div>
105-
<div class="device-lg visible-lg"></div>
106-
107101
<!-- Responsive Bootstrap Toolkit -->
108102
<script src="js/bootstrap-toolkit.min.js"></script>
109103

110-
<!-- Your scripts using Bootstrap Toolkit -->
104+
<!-- Your scripts using Responsive Bootstrap Toolkit -->
111105
<script src="js/main.js"></script>
112106
````
113107

@@ -125,5 +119,3 @@ Copy contents of `compass/bootstrap-toolkit` directory into your project. File `
125119
**CSS features:**
126120
1. SASS 3.3+
127121
2. Compass
128-
129-

index.html

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<link rel="stylesheet" type="text/css" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"/>
1010
<!-- Include stylesheet of this example -->
1111
<link rel="stylesheet" type="text/css" href="style.css" rel="stylesheet"/>
12-
</head>
13-
12+
</head>
13+
1414
<body>
1515

1616
<div class="wrapper">
@@ -31,13 +31,6 @@ <h4>Example #1</h4>
3131

3232
</div>
3333

34-
<!-- Mandatory for Responsive Bootstrap Toolkit to operate -->
35-
<div class="device-xs visible-xs"></div>
36-
<div class="device-sm visible-sm"></div>
37-
<div class="device-md visible-md"></div>
38-
<div class="device-lg visible-lg"></div>
39-
<!-- end mandatory -->
40-
4134
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
4235
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
4336

@@ -46,5 +39,3 @@ <h4>Example #1</h4>
4639

4740
</body>
4841
</html>
49-
50-

js/bootstrap-toolkit.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,68 @@
22
* Responsive Bootstrap Toolkit
33
* Author: Maciej Gurban
44
* License: MIT
5-
* Version: 2.2.0 (2015-01-06)
5+
* Version: 2.3.0 (2015-02-15)
66
* Origin: https://github.com/maciej-gurban/responsive-bootstrap-toolkit
77
*/
88
;var ResponsiveBootstrapToolkit = (function($){
99

1010
// Methods and properties
1111
var self = {
1212

13-
// Determines interval between firing 'changed' method
13+
/**
14+
* Determines default interval between firing 'changed' method
15+
*/
1416
interval: 300,
1517

16-
// Breakpoint aliases
17-
breakpoints: [
18-
'xs', 'sm', 'md', 'lg'
19-
],
18+
/**
19+
* Breakpoint aliases
20+
*/
21+
breakpoints: {
22+
'xs': $('<div class="device-xs visible-xs"></div>').appendTo('body'),
23+
'sm': $('<div class="device-sm visible-sm"></div>').appendTo('body'),
24+
'md': $('<div class="device-md visible-md"></div>').appendTo('body'),
25+
'lg': $('<div class="device-lg visible-lg"></div>').appendTo('body')
26+
},
2027

21-
// Used to calculate intervals between consecutive function executions
28+
/**
29+
* Used to calculate intervals between consecutive function executions
30+
*/
2231
timer: new Date(),
2332

24-
// Returns true if current breakpoint matches passed alias
33+
/**
34+
* Returns true if current breakpoint matches passed alias
35+
*/
2536
is: function( alias ) {
26-
return $('.device-' + alias).is(':visible');
37+
return self.breakpoints[alias].is(':visible');
2738
},
2839

29-
// Returns current breakpoint alias
40+
/**
41+
* Returns current breakpoint alias
42+
*/
3043
current: function(){
3144
var name = 'unrecognized';
32-
self.breakpoints.forEach(function(alias){
33-
if(self.is(alias)) {
45+
$.each(self.breakpoints, function(alias){
46+
if (self.is(alias)) {
3447
name = alias;
3548
}
3649
});
3750
return name;
3851
},
3952

40-
/*
53+
/*
4154
* Waits specified number of miliseconds before executing a function
4255
* Source: http://stackoverflow.com/a/4541963/2066118
4356
*/
4457
changed: function() {
4558
var timers = {};
46-
return function (callback, ms) {
59+
return function(callback, ms) {
4760
// Get unique timer ID
4861
var uID = (!uID) ? self.timer.getTime() : null;
4962
if (timers[uID]) {
5063
clearTimeout(timers[uID]);
5164
}
5265
// Use default interval if none specified
53-
if(typeof ms === "undefined") {
66+
if (typeof ms === "undefined") {
5467
var ms = self.interval;
5568
}
5669
timers[uID] = setTimeout(callback, ms);

js/bootstrap-toolkit.min.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Responsive Bootstrap Toolkit
33
* Author: Maciej Gurban
44
* License: MIT
5-
* Version: 2.2.0 (2015-01-06)
5+
* Version: 2.3.0 (2015-02-15)
66
* Origin: https://github.com/maciej-gurban/responsive-bootstrap-toolkit
77
*/
8-
;var ResponsiveBootstrapToolkit=function(f){var b={interval:300,breakpoints:["xs","sm","md","lg"],timer:new Date,is:function(a){return f(".device-"+a).is(":visible")},current:function(){var a="unrecognized";b.breakpoints.forEach(function(c){b.is(c)&&(a=c)});return a},changed:function(){var a={};return function(c,e){var d=d?null:b.timer.getTime();a[d]&&clearTimeout(a[d]);"undefined"===typeof e&&(e=b.interval);a[d]=setTimeout(c,e)}}()};return b}(jQuery);
8+
;var ResponsiveBootstrapToolkit=function(e){var i={interval:300,breakpoints:{xs:e('<div class="device-xs visible-xs"></div>').appendTo("body"),sm:e('<div class="device-sm visible-sm"></div>').appendTo("body"),md:e('<div class="device-md visible-md"></div>').appendTo("body"),lg:e('<div class="device-lg visible-lg"></div>').appendTo("body")},timer:new Date,is:function(e){return i.breakpoints[e].is(":visible")},current:function(){var n="unrecognized";return e.each(i.breakpoints,function(e){i.is(e)&&(n=e)}),n},changed:function(){var e={};return function(n,s){var d=d?null:i.timer.getTime();if(e[d]&&clearTimeout(e[d]),"undefined"==typeof s)var s=i.interval;e[d]=setTimeout(n,s)}}()};return i}(jQuery);

js/main.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@
2929
);
3030
}
3131
}
32-
33-
32+
33+
3434

3535
// Executes once whole document has been loaded
3636
$(document).ready(function() {
3737

3838
resizeTopBar();
3939

40-
console.log( 'Current breakpoint:', viewport.current() );
40+
console.log( 'Current breakpoint:', viewport.current() );
4141

4242
});
4343

44-
44+
4545
// Executes each time window size changes
4646
$(window).bind('resize', function() {
4747
viewport.changed(function(){
@@ -53,5 +53,5 @@
5353
});
5454
});
5555

56-
56+
5757
})(jQuery, document, window, ResponsiveBootstrapToolkit);

0 commit comments

Comments
 (0)