summaryrefslogtreecommitdiffstats
path: root/tools/droiddoc/templates/assets/android-developer-docs.js
blob: 58da11689ed433733c60460cef84868394a1966d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
var resizePackagesNav;
var classesNav;
var devdocNav;
var sidenav;
var content;
var HEADER_HEIGHT = 103;
var cookie_style = 'android_dev_docs';

function addLoadEvent(newfun) {
  var current = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = newfun;
  } else {
    window.onload = function() {
      current();
      newfun();
    }
  }
}

addLoadEvent(prepare);
window.onresize = resizeAll;

function restoreWidth(navWidth) {
  var windowWidth = $(window).width() + "px";
  content.css({marginLeft:navWidth, width:parseInt(windowWidth) - parseInt(navWidth) + "px"});
  sidenav.css({width:navWidth});
  resizePackagesNav.css({width:navWidth});
  classesNav.css({width:navWidth});
  $("#packages-nav").css({width:navWidth});
}

function restoreHeight(packageHeight) {
  var windowHeight = ($(window).height() - HEADER_HEIGHT);
  sidenav.css({height:windowHeight + "px"});
  content.css({height:windowHeight + "px"});
  resizePackagesNav.css({maxHeight:windowHeight + "px", height:packageHeight});
  classesNav.css({height:windowHeight - parseInt(packageHeight) + "px"});
  $("#packages-nav").css({height:parseInt(packageHeight) - 6 + "px"}); //move 6px to give space for the resize handle
  devdocNav.css({height:sidenav.css("height")});
}

function getCookie(cookie) {
  var myCookie = cookie_style+"_"+cookie+"=";
  if (document.cookie) {
    var index = document.cookie.indexOf(myCookie);
    if (index != -1) {
      var valStart = index + myCookie.length;
      var valEnd = document.cookie.indexOf(";", valStart);
      var val = document.cookie.substring(valStart, valEnd);
      return val;
    }
  }
  return 0;
}

function writeCookie(cookie, val) {
  if (location.href.indexOf("reference") != -1) {
    document.cookie = cookie_style+'_'+cookie+'='+val+'; path=/gae/reference';
  }
} 

function prepare() {
  $("#side-nav").css({position:"absolute",left:0});
  content = $("#doc-content");
  resizePackagesNav = $("#resize-packages-nav");
  classesNav = $("#classes-nav");
  sidenav = $("#side-nav");
  devdocNav = $("#devdoc-nav");

  var cookieWidth = getCookie('width');
  var cookieHeight = getCookie('height');
  if (cookieWidth) {
    restoreWidth(cookieWidth);
  } else {
    resizeWidth();
  }
  if (cookieHeight) {
    restoreHeight(cookieHeight);
  } else {
    resizeHeight();
  }

  if (devdocNav.length) { 
    highlightNav(location.href); 
  }
}

function highlightNav(fullPageName) {
  var lastSlashPos = fullPageName.lastIndexOf("/");
  var firstSlashPos = fullPageName.indexOf("/",8); // first slash after http://
  if (lastSlashPos == (fullPageName.length - 1)) { // if the url ends in slash (index.html)
    fullPageName = fullPageName + "index.html";
  }
  var htmlPos = fullPageName.lastIndexOf(".html", fullPageName.length);
  var pageName = fullPageName.slice(firstSlashPos, htmlPos + 5);
  var link = $("#devdoc-nav a[href$='"+pageName+"']");
  if (link.length == 0) { // if there's no match, maybe the nav url ends in a slash, also
    link = $("#devdoc-nav a[href$='"+pageName.slice(0,pageName.indexOf("index.html"))+"']");
  }
  link.parent().addClass('selected');
}

function resizeHeight() {
  var windowHeight = ($(window).height() - HEADER_HEIGHT);
  sidenav.css({height:windowHeight + "px"});
  content.css({height:windowHeight + "px"});
  resizePackagesNav.css({maxHeight:windowHeight + "px"});
  classesNav.css({height:windowHeight - parseInt(resizePackagesNav.css("height")) + "px"});
  $("#packages-nav").css({height:parseInt(resizePackagesNav.css("height")) - 6 + "px"}); //move 6px for handle
  devdocNav.css({height:sidenav.css("height")});
  writeCookie("height", resizePackagesNav.css("height"));
}

function resizeWidth() {
  var windowWidth = $(window).width() + "px";
  if (sidenav.length) {
    var sidenavWidth = sidenav.css("width");
  } else {
    var sidenavWidth = 0;
  }
  content.css({marginLeft:sidenavWidth, width:parseInt(windowWidth) - parseInt(sidenavWidth) + "px"});
  resizePackagesNav.css({width:sidenavWidth});
  classesNav.css({width:sidenavWidth});
  $("#packages-nav").css({width:sidenavWidth});
  writeCookie("width", sidenavWidth);
}

function resizeAll() {
  resizeHeight();
  resizeWidth();
}

//added to onload when the bottom-left panel is empty
function maxPackageHeight() { 
  var windowHeight = resizePackagesNav.css("maxHeight");
  resizePackagesNav.css({height:windowHeight}); 
  $("#packages-nav").css({height:windowHeight}); 
}

$(document).ready(function(){
  $("#resize-packages-nav").resizable({handles: "s", resize: function(e, ui) { resizeHeight(); } });
  $(".side-nav-resizable").resizable({handles: "e", resize: function(e, ui) { resizeWidth(); } });
});