startmin.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. $(function() {
  2. $('#side-menu').metisMenu();
  3. $("#contract").click(function(e){
  4. e.preventDefault();
  5. var w = $("#wrapper");
  6. if (w.hasClass("contracted")) {
  7. w.removeClass("contracted");
  8. setCookie('sidebar-contracted', '0');
  9. }else {
  10. w.addClass("contracted");
  11. setCookie('sidebar-contracted', '1');
  12. }
  13. setLinkContent();
  14. $(window).trigger('resize');
  15. });
  16. setLinkContent();
  17. function setLinkContent() {
  18. if ($("#wrapper").hasClass("contracted"))
  19. $("#contract").html('<i class="fa fa-arrow-circle-o-right fa-fw"></i> <span>Cerrar menu</span>');
  20. else
  21. $("#contract").html('<i class="fa fa-arrow-circle-o-left fa-fw"></i> <span>Cerrar menu</span>');
  22. }
  23. function setCookie(name, value, path) {
  24. if (path == null)
  25. path = _webApp_site ;
  26. var d = new Date();
  27. d.setTime(d.getTime() + (365 * 24 * 60 * 60 * 1000));
  28. document.cookie = name + "=" + value + "; expires=" + d.toUTCString() + "; path=" + path;
  29. }
  30. });
  31. //Loads the correct sidebar on window load,
  32. //collapses the sidebar on window resize.
  33. // Sets the min-height of #page-wrapper to window size
  34. $(function() {
  35. $(window).bind("load resize", function() {
  36. topOffset = 50;
  37. width = (this.window.innerWidth > 0) ? this.window.innerWidth : this.screen.width;
  38. if (width < 768) {
  39. $('div.navbar-collapse').addClass('collapse');
  40. topOffset = 100; // 2-row-menu
  41. } else {
  42. $('div.navbar-collapse').removeClass('collapse');
  43. }
  44. height = ((this.window.innerHeight > 0) ? this.window.innerHeight : this.screen.height) - 1;
  45. height = height - topOffset;
  46. if (height < 1) height = 1;
  47. if (height > topOffset) {
  48. $("#page-wrapper").css("min-height", (height) + "px");
  49. }
  50. });
  51. var url = window.location;
  52. var element = $('ul.nav a').filter(function() {
  53. return this.href == url /*|| url.href.indexOf(this.href) == 0*/;
  54. }).addClass('active').parent().parent().addClass('in').parent();
  55. if (element.is('li')) {
  56. element.addClass('active');
  57. }
  58. });