Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. /**
  2. * Returns active device detected by Bootstrap
  3. *
  4. * @author Petr Knap <dev@petrknap.cz>
  5. *
  6. * @param {String} [testerId="getBootstrapDevice"] Identifier used for prepended div element
  7. * @param {String} [defaultDevice="lg"] Default device
  8. *
  9. * @returns {String} Active device (xs|sm|md|lg)
  10. */
  11. function getBootstrapDevice(testerId, defaultDevice) {
  12. var $body, $tester;
  13.  
  14. if(!testerId) {
  15. testerId = "getBootstrapDevice";
  16. }
  17.  
  18. if(!defaultDevice) {
  19. defaultDevice = "lg";
  20. }
  21.  
  22. $body = $("body");
  23. $tester = $body.find("#" + testerId);
  24.  
  25. if($tester.length == 0) { // Insert tester
  26. $body.prepend('' +
  27. '<div id="' + testerId + '" style="position: absolute; z-index: -999">' +
  28. ' <div class="visible-xs-block">&nbsp;</div>' +
  29. ' <div class="visible-sm-block">&nbsp;</div>' +
  30. ' <div class="visible-md-block">&nbsp;</div>' +
  31. ' <div class="visible-lg-block">&nbsp;</div>' +
  32. '</div>' +
  33. '');
  34. return getBootstrapDevice(testerId, defaultDevice);
  35. }
  36. else {
  37. $tester.find("div").each(function() {
  38. if($(this).css("display") == "block") {
  39. defaultDevice = $(this).attr('class').split("-")[1];
  40. return false; // Break the loop
  41. }
  42. });
  43. return defaultDevice;
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement