Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Returns active device detected by Bootstrap
- *
- * @author Petr Knap <dev@petrknap.cz>
- *
- * @param {String} [testerId="getBootstrapDevice"] Identifier used for prepended div element
- * @param {String} [defaultDevice="lg"] Default device
- *
- * @returns {String} Active device (xs|sm|md|lg)
- */
- function getBootstrapDevice(testerId, defaultDevice) {
- var $body, $tester;
- if(!testerId) {
- testerId = "getBootstrapDevice";
- }
- if(!defaultDevice) {
- defaultDevice = "lg";
- }
- $body = $("body");
- $tester = $body.find("#" + testerId);
- if($tester.length == 0) { // Insert tester
- $body.prepend('' +
- '<div id="' + testerId + '" style="position: absolute; z-index: -999">' +
- ' <div class="visible-xs-block"> </div>' +
- ' <div class="visible-sm-block"> </div>' +
- ' <div class="visible-md-block"> </div>' +
- ' <div class="visible-lg-block"> </div>' +
- '</div>' +
- '');
- return getBootstrapDevice(testerId, defaultDevice);
- }
- else {
- $tester.find("div").each(function() {
- if($(this).css("display") == "block") {
- defaultDevice = $(this).attr('class').split("-")[1];
- return false; // Break the loop
- }
- });
- return defaultDevice;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement