(function($) { $.fn.drilldown = function(options) { //set default options var defaults = { wrapper_class: 'drilldown panel panel-default sys-bd-off sys-box-shadow-off sys-mg-off-b', menu_class: 'drilldown-menu', submenu_class: 'list-group', parent_class: 'dd-parent list-group-item', parent_class_link: 'dd-parent-a', active_class: 'active', header_class_list: 'breadcrumb', header_class: 'panel-heading', class_selected: 'dd-selected', // show_count : true, count_class: 'dd-count', default_text: 'Select item', header_tag: 'div', // h3 header_tag_class: 'list-group-item active', // hidden list-group-item active }; //call in the default options var options = $.extend(defaults, options); //act upon the element that is passed into the design return this.each(function(options) { var $ddObj = this; $($ddObj).addClass(defaults.menu_class); $($ddObj).addClass(defaults.submenu_class); $($ddObj).removeClass('hidden'); var $wrapperObj = '
'; $($ddObj).wrap($wrapperObj); var $wrapper = $($ddObj).parent(); var objIndex = $($wrapper).index('.' + defaults.wrapper_class.replace(/ /g, '.')); var idHeader = defaults.header_class.replace(/ /g, '_') + '-' + objIndex; var idWrapper = defaults.wrapper_class.replace(/ /g, '_') + '-' + objIndex; $($wrapper).attr('id', idWrapper); var $header = ''; setUpDrilldown(); resetDrilldown($ddObj, $wrapper); $('#sidebar-wrapper').on('transitionend', function(a) { resizeDrilldown($ddObj, $wrapper); $(this).off(a); }); $(window).bind('resizeEnd', function() { if ( SYSPRO_VB.openWindow === 'dataWindow' || SYSPRO_VB.openWindow === 'dataEditWindow' || SYSPRO_VB.openWindow === 'tileWindow' || SYSPRO_VB.openWindow === 'tileEditWindow' ) { resizeDrilldown($ddObj, $wrapper); } }); $('li a', $ddObj).click(function(e) { $link = this; $activeLi = $(this) .parent('li') .stop(); $siblingsLi = $($activeLi).siblings(); // Drilldown action if ($('> ul', $activeLi).length) { if ($($link).hasClass(defaults.active_class)) { $('ul a', $activeLi).removeClass(defaults.active_class); $('ul ul', $activeLi).removeClass(defaults.active_class); resetDrilldown($ddObj, $wrapper); } else { actionDrillDown($activeLi, $wrapper, $ddObj); } } // scroll to top on click $($wrapper, $ddObj).scrollTop(0); // Prevent browsing to link if has child links if ($(this).next('ul').length > 0) { e.preventDefault(); e.stopPropagation(); $($link).trigger('drilldown.parentclick'); } else { //$($link).trigger('click'); $($link).addClass(defaults.active_class); } $($link).trigger('drilldown.linklclick'); }); // $('li a',$ddObj).click(function(e){ //--------------------------------------------- // Breadcrumbs //$('#'+idHeader+' a').live('click',function(e){ $('#' + idHeader).on('click', 'a', function(e) { // Get link index var linkIndex = parseInt($(this).index('#' + idHeader + ' a')); if (linkIndex == 0) { $('a', $ddObj).removeClass(defaults.active_class); $('ul', $ddObj).removeClass(defaults.active_class); } else { // Select equivalent active link linkIndex = linkIndex - 1; $('a.' + defaults.active_class + ':gt(' + linkIndex + ')', $ddObj).removeClass( defaults.active_class ); $('ul.' + defaults.active_class + ':gt(' + linkIndex + ')', $ddObj).removeClass( defaults.active_class ); } resetDrilldown($ddObj, $wrapper); e.preventDefault(); $($ddObj).trigger('drilldown.linklclick'); }); //--------------------------------------------- // helper functions //--------------------------------------------- // Set up accordion function setUpDrilldown() { $('ul', $ddObj).each(function() { $(this).addClass(defaults.submenu_class); }); $($ddObj).before($header); $arrow = 'keyboard_arrow_right'; // Get width of menu container & height of list item var menuWidth = $($ddObj).actual('outerWidth', { includeMargin: true }) + 3; menuWidth += 'px'; var itemHeight = $('li', $ddObj).actual('outerHeight', { includeMargin: true }); // Get height of largest sub menu var objUl = $('ul', $ddObj); var maxItems = findMaxHeight(objUl); // Get level of largest sub menu //var maxUl = $(objUl+'[rel="'+maxItems+'"]'); var maxUl = $('[rel="' + maxItems + '"]', objUl); var getIndex = findMaxIndex(maxUl); // Set menu container height menuHeight = itemHeight * maxItems + 5; //------------------------------- var showObj = $('> ul', $wrapper); var itemCount = $('>li', showObj).length; var menuHeight = itemHeight * itemCount; var menuHeightAll = itemHeight * itemCount + $($header).height(); $($wrapper).css({ height: menuHeightAll + 'px', width: menuWidth }); $($ddObj).css({ height: menuHeight + 'px', width: menuWidth }); //------------------------------- // Set sub menu width and offset $('li', $ddObj).each(function() { $(this).css({ width: menuWidth }); $('ul', this).css({ width: menuWidth, marginRight: '-' + menuWidth, marginTop: '0' }); if ($('> ul', this).length) { $(this).addClass(defaults.parent_class); // if(defaults.show_count == true){ /* var parentLink = $('> ul > li',this); var countParent = parseInt($(parentLink).length); getCount = countParent; $('> a',this).append(' ('+getCount+')'); */ // } $('> a', this) .addClass(defaults.parent_class_link) .append($arrow); } }); //------------------------------- // Add css class $('ul', $wrapper).each(function() { //$(this).addClass(defaults.submenu_class); $('li:last', this).addClass('last'); }); $('> ul > li:last', $wrapper).addClass('last'); } // function setUpDrilldown(){ this.drillto = function(element) { actionDrillDown(element, $wrapper, $ddObj); }; this.resetDdMenu = function() { $('a', $ddObj).removeClass(defaults.active_class); $('ul', $ddObj).removeClass(defaults.active_class); resetDrilldown($ddObj, $wrapper); $($wrapper, $ddObj).scrollTop(0); }; this.partResetDdMenu = function() { resetDrilldown($ddObj, $wrapper); }; //--------------------------------------------- }); // return this.each(function(options){ //------------------------------------------------- // Drill Down function actionDrillDown(element, wrapper, obj) { //actionDrillDown($activeLi, $wrapper, $ddObj); var showObj = $('> ul', element); showObj.css('opacity', 0); // element.closest('.dd-parent').css({ // borderColor: '#fff', // backgroundColor: '#fff' // }); // Declare header var $header = $('.' + defaults.header_class, wrapper); // Get new breadcrumb and header text var getNewBreadcrumb = $(defaults.header_tag, $header).text(); // .html() var getNewHeaderClone = $('> a', element).clone(); getNewHeaderClone.find('.material-icons').remove(); var getNewHeaderText = getNewHeaderClone.text(); // .html() // Add new breadcrumb if (!$('ul', $header).length) { $($header).prepend('