Created
April 16, 2014 12:36
-
-
Save birkestroem/10867159 to your computer and use it in GitHub Desktop.
Quick and dirty bootstrap state thing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bootstrapState = { | |
current: null, | |
last: null | |
}; | |
_.extend(bootstrapState, Backbone.Events); | |
(function () { | |
var last; | |
function findState() { | |
var envValues = ["xs", "sm", "md", "lg"]; | |
var $el = $('<div>'); | |
$el.appendTo($('body')); | |
for (var i = envValues.length - 1; i >= 0; i--) { | |
var envVal = envValues[i]; | |
$el.addClass('hidden-' + envVal); | |
if ($el.is(':hidden')) { | |
$el.remove(); | |
return envVal; | |
} | |
}; | |
return null; | |
} | |
var update = _.throttle(function () { | |
var state = findState(); | |
if (last !== state) { | |
bootstrapState.current = state; | |
bootstrapState.last = last; | |
bootstrapState.trigger('change', state, last); | |
last = state; | |
} | |
}, 500); | |
$(window).resize(update); | |
update(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment