3 'api-list', 'history-hash', 'node-screen', 'node-style', 'pjax',
6 var win = Y.config.win,
7 localStorage = win.localStorage,
17 // Kill pjax functionality unless serving over HTTP.
18 if (!Y.getLocation().protocol.match(/^https?\:/)) {
19 Y.Router.html5 = false;
22 // Create the default route with middleware which enables syntax highlighting
23 // on the loaded content.
24 defaultRoute = Y.Pjax.defaultRoute.concat(function (req, res, next) {
26 bdNode.removeClass('loading');
32 container : '#docs-main',
33 contentSelector: '#docs-main > .content',
34 linkSelector : '#bd a',
35 titleSelector : '#xhr-title',
40 // -- / ----------------------------------------------------------------
42 path : '/(index.html)?',
43 callbacks: defaultRoute
46 // -- /classes/* -------------------------------------------------------
48 path : '/classes/:class.html*',
49 callbacks: [defaultRoute, 'handleClasses']
52 // -- /files/* ---------------------------------------------------------
54 path : '/files/*file',
55 callbacks: [defaultRoute, 'handleFiles']
58 // -- /modules/* -------------------------------------------------------
60 path : '/modules/:module.html*',
61 callbacks: defaultRoute
66 // -- Utility Functions --------------------------------------------------------
68 pjax.checkVisibility = function (tab) {
69 tab || (tab = selectedTab);
73 var panelNode = tab.get('panelNode'),
76 // If no items are visible in the tab panel due to the current visibility
77 // settings, display a message to that effect.
78 visibleItems = panelNode.all('.item,.index-item').some(function (itemNode) {
79 if (itemNode.getComputedStyle('display') !== 'none') {
84 panelNode.all('.no-visible-items').remove();
87 if (Y.one('#index .index-item')) {
89 '<div class="no-visible-items">' +
91 'Some items are not shown due to the current visibility ' +
92 'settings. Use the checkboxes at the upper right of this ' +
93 'page to change the visibility settings.' +
99 '<div class="no-visible-items">' +
101 'This class doesn\'t provide any methods, properties, ' +
102 'attributes, or events.' +
109 // Hide index sections without any visible items.
110 Y.all('.index-section').each(function (section) {
114 section.all('.index-item').each(function (itemNode) {
117 if (itemNode.getComputedStyle('display') !== 'none') {
122 section.toggleClass('hidden', !visibleItems);
123 section.toggleClass('no-columns', visibleItems < 4);
127 pjax.initClassTabView = function () {
128 if (!Y.all('#classdocs .api-class-tab').size()) {
133 classTabView.destroy();
137 classTabView = new Y.TabView({
138 srcNode: '#classdocs',
141 selectionChange: pjax.onTabSelectionChange
145 pjax.updateTabState();
146 classTabView.render();
149 pjax.initLineNumbers = function () {
150 var hash = win.location.hash.substring(1),
151 container = pjax.get('container'),
154 // Add ids for each line number in the file source view.
155 container.all('.linenums>li').each(function (lineNode, index) {
156 lineNode.set('id', 'l' + (index + 1));
157 lineNode.addClass('file-line');
161 // Scroll to the desired line.
162 if (hasLines && /^l\d+$/.test(hash)) {
163 if ((node = container.getById(hash))) {
164 win.scroll(0, node.getY());
169 pjax.initRoot = function () {
170 var terminators = /^(?:classes|files|modules)$/,
171 parts = pjax._getPathRoot().split('/'),
175 for (i = 0, len = parts.length; i < len; i += 1) {
178 if (part.match(terminators)) {
179 // Makes sure the path will end with a "/".
187 pjax.set('root', root.join('/'));
190 pjax.updateTabState = function (src) {
191 var hash = win.location.hash.substring(1),
192 defaultTab, node, tab, tabPanel;
194 function scrollToNode() {
195 if (node.hasClass('protected')) {
196 Y.one('#api-show-protected').set('checked', true);
197 pjax.updateVisibility();
200 if (node.hasClass('private')) {
201 Y.one('#api-show-private').set('checked', true);
202 pjax.updateVisibility();
205 setTimeout(function () {
206 // For some reason, unless we re-get the node instance here,
207 // getY() always returns 0.
208 var node = Y.one('#classdocs').getById(hash);
209 win.scrollTo(0, node.getY() - 70);
217 if (src === 'hashchange' && !hash) {
218 defaultTab = 'index';
221 defaultTab = localStorage.getItem('tab_' + pjax.getPath()) ||
224 defaultTab = 'index';
228 if (hash && (node = Y.one('#classdocs').getById(hash))) {
229 if ((tabPanel = node.ancestor('.api-class-tabpanel', true))) {
230 if ((tab = Y.one('#classdocs .api-class-tab.' + tabPanel.get('id')))) {
231 if (classTabView.get('rendered')) {
232 Y.Widget.getByNode(tab).set('selected', 1);
234 tab.addClass('yui3-tab-selected');
239 // Scroll to the desired element if this is a hash URL.
241 if (classTabView.get('rendered')) {
244 classTabView.once('renderedChange', scrollToNode);
248 tab = Y.one('#classdocs .api-class-tab.' + defaultTab);
250 // When the `defaultTab` node isn't found, `localStorage` is stale.
251 if (!tab && defaultTab !== 'index') {
252 tab = Y.one('#classdocs .api-class-tab.index');
255 if (classTabView.get('rendered')) {
256 Y.Widget.getByNode(tab).set('selected', 1);
258 tab.addClass('yui3-tab-selected');
263 pjax.updateVisibility = function () {
264 var container = pjax.get('container');
266 container.toggleClass('hide-inherited',
267 !Y.one('#api-show-inherited').get('checked'));
269 container.toggleClass('show-deprecated',
270 Y.one('#api-show-deprecated').get('checked'));
272 container.toggleClass('show-protected',
273 Y.one('#api-show-protected').get('checked'));
275 container.toggleClass('show-private',
276 Y.one('#api-show-private').get('checked'));
278 pjax.checkVisibility();
281 // -- Route Handlers -----------------------------------------------------------
283 pjax.handleClasses = function (req, res, next) {
284 var status = res.ioResponse.status;
286 // Handles success and local filesystem XHRs.
287 if (res.ioResponse.readyState === 4 && (!status || (status >= 200 && status < 300))) {
288 pjax.initClassTabView();
294 pjax.handleFiles = function (req, res, next) {
295 var status = res.ioResponse.status;
297 // Handles success and local filesystem XHRs.
298 if (res.ioResponse.readyState === 4 && (!status || (status >= 200 && status < 300))) {
299 pjax.initLineNumbers();
305 // -- Event Handlers -----------------------------------------------------------
307 pjax.onNavigate = function (e) {
309 originTarget = e.originEvent && e.originEvent.target,
313 tab = originTarget && originTarget.ancestor('.yui3-tab', true);
315 if (hash === win.location.hash) {
316 pjax.updateTabState('hashchange');
318 win.location.hash = hash;
325 // Only scroll to the top of the page when the URL doesn't have a hash.
326 this.set('scrollToTop', !e.url.match(/#.+$/));
328 bdNode.addClass('loading');
331 pjax.onOptionClick = function (e) {
332 pjax.updateVisibility();
335 pjax.onTabSelectionChange = function (e) {
337 tabId = tab.get('contentBox').getAttribute('href').substring(1);
341 // If switching from a previous tab (i.e., this is not the default tab),
342 // replace the history entry with a hash URL that will cause this tab to
343 // be selected if the user navigates away and then returns using the back
344 // or forward buttons.
345 if (e.prevVal && localStorage) {
346 localStorage.setItem('tab_' + pjax.getPath(), tabId);
349 pjax.checkVisibility(tab);
352 // -- Init ---------------------------------------------------------------------
354 pjax.on('navigate', pjax.onNavigate);
358 pjax.initClassTabView();
359 pjax.initLineNumbers();
360 pjax.updateVisibility();
362 Y.APIList.rootPath = pjax.get('root');
364 Y.one('#api-options').delegate('click', pjax.onOptionClick, 'input');
366 Y.on('hashchange', function (e) {
367 pjax.updateTabState('hashchange');