container of sub UL and add CSS class
$header.data('$dest', $submenu) // set up relationship between header and sub menu DIV
$submenu.data('$parent', $header)
if ($subul.data('selected') == 1){
menuinstance.s.selectedul = $subul
}
menuinstance.buildcount++ // increment unique buildcount var to uniquely label each header/sub menu pair
$('
').prepend(menuinstance.s.backarrow).prependTo($submenu) // add breadcrumb div to top of each sub menu DIV
},
function($mainul){ // top level root UL (after being flattened with no branches)
$mainul.wrap('
')
if ($anchor != null){ //if $anchor param defined, meaning $mainul is a sub UL of an anchor element (ie: due to lazy loading of a sub UL), treat $mainul like another sub menu
var $header = $anchor // set $header to $anchor param
$headers = $headers.add($header)
var headerbuildnum = $header.prop('className').match(/header(\d+)/i)[1] // find xx number inside class="header header xx"
var $submenu = $mainul.parent() // reference outermost
container of sub UL
$submenu.addClass('submenu submenu' + headerbuildnum)
$header.data('$dest', $submenu) // set up relationship between header and sub menu DIV
$submenu.data('$parent', $header)
$('
' + $header.text() + '
').prepend(menuinstance.s.backarrow).prependTo($submenu) // add breadcrumb div to top of main sub UL DIV
}
else{
if ($mainul.data('lazyload')){ // if "data-lazyload" and data-reverseheader="#reverseheaderid, header title" defined inside top most UL
var headerinfo = $mainul.data('reverseheader').split(/,\s*/)
$reversebreadcrumb = $('
' + headerinfo[1] + '
').prepend(menuinstance.s.backarrow).prependTo($mainul) // add reverse breadcrumb to main UL
$reversebreadcrumb.data('lazyload', $mainul.data('lazyload')) // inside reverse breadcrumb store info about parent menu to fetch when clicked on
$reversebreadcrumb.data('headerid', headerinfo[0].substr(1))
}
}
if ($mainul.data('selected') == 1){
menuinstance.s.selectedul = $mainul
}
}
) // end flattenuls()
if ($anchor == null && cloneulBol){ // if $flattened is a clone of original UL
$ul.before($flattened) // insert $flattened before original UL
$ul.remove() // then remove original UL
}
else{ // else, just add flattened UL to $nav
this.$nav.append($flattened)
}
if ($reverseanchor){ // if $reverseanchor defined, meaning a breadcrumb when clicked on should fetch parent menu
menuinstance.buildcount++
var $dynamicheader = $('#' + $reverseanchor.data('headerid')) // target to-be-fetched header
if ($dynamicheader.length == 1){
$dynamicheader.addClass('header header' + menuinstance.buildcount).find('a:eq(0)').append(menuinstance.s.rightarrow)
var $submenu = $reverseanchor.parent().parent('div.drawer').addClass('submenu submenu' + menuinstance.buildcount) // sub menu target header is assoc with
$dynamicheader.data('$dest', $submenu) // set up relationship between header and sub menu DIV
$submenu.data('$parent', $dynamicheader)
$headers = $headers.add($dynamicheader)
}
}
$headers.each(function(i){ // loop through each $header LI (one that carries a sub UL) again
var $header = $(this)
var $headermenu = $header.parents('div.drawer:eq(0)') // reference outer DIV.drawer that contains the header LI
var $submenu = $header.data('$dest')
var $breadcrumb = $submenu.find('div.breadcrumb')
$header.on('click.showsubmenu', function(e){ // when user clicks on header
$headermenu.css({zIndex: menuzindex++}).animate({left: '-100%'}, menuinstance.s.slideduration, menuinstance.s.easing)
$submenu.css({zIndex: menuzindex++ , left: '100%'}).animate({left: 0}, menuinstance.s.slideduration, menuinstance.s.easing)
e.preventDefault()
})
$breadcrumb.on('click', function(e){ // when user clicks on brumcrumb div at the top of each sub UL DIV
$headermenu.css({zIndex: menuzindex++, left: '-100%'}).animate({left: 0}, menuinstance.s.slideduration, menuinstance.s.easing)
$submenu.animate({left: '100%'}, menuinstance.s.slideduration, menuinstance.s.easing)
})
})
var $lazyheaders= this.$nav.find('li[data-lazyload]').addClass('header header' + menuinstance.buildcount++) // find LIs with attribute "data-lazyload"
$lazyheaders.find('a:eq(0)').append(menuinstance.s.rightarrow) // add right arrow to them
if ($reversebreadcrumb){
$lazyheaders = $lazyheaders.add($reversebreadcrumb)
}
$lazyheaders.on('click.lazyload', function(e){ // when user clicks on a LI with "data-lazyload"
menuinstance.$loadingscreen.css({visibility: 'visible'})
var $header = $(this)
menuinstance.loadmenu($header, $header.data('lazyload')) // Ajax fetch file specified inside "data-lazyload"
$header.removeAttr('data-lazyload') // remove "data-lazyload" attr from header while still retaining data('lazyload') value
e.preventDefault()
})
this.$loadingscreen.css({visibility: 'hidden'})
},
selectMenu: function(selector){
var $targetmenu
if (typeof selector == "number"){
$targetmenu = this.$nav.find('div.drawer').eq(selector)
}
else{ // if string or jquery object
$targetmenu = $(selector).parent('div.drawer')
}
if ($targetmenu.length == 0){
$targetmenu = this.$nav.find('div.drawer').eq(0)
}
$targetmenu.css({left:0, zIndex: menuzindex++})
}
}
})(window, jQuery)