startmin.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. var arr = _webApp_site.replace('http://', '').replace('https://', '').split('/');
  26. arr.splice(0);
  27. path = '/' + arr.join('/') + (arr.length > 0 ? '/' : '');
  28. }
  29. var d = new Date();
  30. d.setTime(d.getTime() + (365 * 24 * 60 * 60 * 1000));
  31. document.cookie = name + "=" + value + "; expires=" + d.toUTCString() + "; path=/";
  32. }
  33. });
  34. //Loads the correct sidebar on window load,
  35. //collapses the sidebar on window resize.
  36. // Sets the min-height of #page-wrapper to window size
  37. $(function() {
  38. $(window).bind("load resize", function() {
  39. topOffset = 50;
  40. width = (this.window.innerWidth > 0) ? this.window.innerWidth : this.screen.width;
  41. if (width < 768) {
  42. $('div.navbar-collapse').addClass('collapse');
  43. topOffset = 100; // 2-row-menu
  44. } else {
  45. $('div.navbar-collapse').removeClass('collapse');
  46. }
  47. height = ((this.window.innerHeight > 0) ? this.window.innerHeight : this.screen.height) - 1;
  48. height = height - topOffset;
  49. if (height < 1) height = 1;
  50. if (height > topOffset) {
  51. $("#page-wrapper").css("min-height", (height) + "px");
  52. }
  53. });
  54. var url = window.location;
  55. var element = $('ul.nav a').filter(function() {
  56. return this.href == url /*|| url.href.indexOf(this.href) == 0*/;
  57. }).addClass('active').parent().parent().addClass('in').parent();
  58. if (element.is('li')) {
  59. element.addClass('active');
  60. }
  61. });