text: 'use strict';define(['EditController','jquery'],function(EditController,$){return function Common(index){var CLASS_OPEN='expanded';var CLASS_CLOSED='collapsed';var editController=EditController();var base=new URI('.').absoluteTo(index).href();var $nav=$('nav[role=toc]');var $main=$('main[role=main]');window.onpopstate=function(event){loadMain(document.location,undefined,false);};return{loadMain:loadMain,initializeMain:initializeMain,isLocal:isLocal};function loadMain(href,$tocLink){var pushState=arguments.length>2&&arguments[2]!==undefined?arguments[2]:true;var abs=new URI(href).absoluteTo(window.location.href).href();if(pushState){history.pushState({},'',href);}$.ajax({url:abs,success:function success(data){updateToc(href,$tocLink);updateMain(data);}});function updateToc(href,$tocLink){$nav.find('.active').removeClass('active');if($tocLink!==undefined){var $li=$tocLink.parent('li');$li.addClass('active');exposeNode($li);}else{var _abs=new URI(href).absoluteTo(window.location.href).href();var _$li=$nav.find('a[href="'+_abs+'"]').parent('li');_$li.addClass('active');exposeNode(_$li);}function exposeNode($li){var $current=$li.parents('li:first');while($current.length){if($current.hasClass(CLASS_CLOSED)){$current.addClass(CLASS_OPEN).removeClass(CLASS_CLOSED);}$current=$current.parents('li:first');}}}function updateMain(data){var $dummy=$('<body>').append($.parseHTML(data));$main.html($dummy.find('[role=main]:first').html());document.title=$dummy.find('title').text();initializeMain();}}function initializeMain(){$main.find('a[href]').filter(isLocal).click(mainClickHandler);editController.createEditLink();function mainClickHandler(event){event.preventDefault();event.stopPropagation();var $target=$(event.currentTarget);var href=$target.attr('href');loadMain(href);}}function isLocal(){var $a=$(this);var abs=new URI($a.attr('href')).absoluteTo(window.location.href).href();return abs.indexOf(base)!==-1;}};});