jQuery.fn.tag = function() { return this.prop("tagName").toLowerCase(); }; function toc_h3_json(id) { //flat var a = []; $(id).find('h3').each(function() { var el = $(this); var cid = 'toc_h3_'+el.text().replace(/[^a-z0-9]/ig, ' ').replace(/\s+/g, '-').toLowerCase(); l = ''+el.text()+''; e = {'label':l,'id':cid}; $('').attr('id', cid).insertBefore(el); a.push(e); }); return a; } function toc_hierarchy_json(id) { var depth = 0; var a = []; var current = {}; var children = []; $(id).find('h3,h4').each(function() { var el = $(this); el.children().each(function() { $(this).remove(); }); cid = 'toc_'+el.text().replace(/[^a-z0-9]/ig, ' ').replace(/\s+/g, '-').toLowerCase(); l = ''+el.text()+''; $('').attr('id', cid).insertBefore(el); if ((el.tag() == 'h3') && (depth == 3)) { // new el if (jQuery.isEmptyObject(children)) { current.label = ''+current.label; } else { current.children = children; } a.push(current); current = {}; children = []; } if ((el.tag() == 'h3') && (depth == 4)) { // new el if (jQuery.isEmptyObject(children)) { current.label = ''+current.label; } else { current.children = children; } a.push(current); current = {}; children = []; } if (el.tag() == 'h3') { current = {'label':l,'id':cid}; depth = 3; } if (el.tag() == 'h4') { children.push({label:l,id:cid}); depth = 4; } }); if (jQuery.isEmptyObject(current.children) && !(jQuery.isEmptyObject(current))) { //last one; current.label = ''+current.label; } a.push(current); return a; } function sensitivityTwistieAction($id) { $twistie = '#twistie_'+$id; $toggle = '#toggle_'+$id; if ($($twistie).hasClass('fa-plus-square')) { $($twistie).addClass('fa-minus-square').removeClass('fa-plus-square'); } else { $($twistie).addClass('fa-plus-square').removeClass('fa-minus-square'); } $($toggle).toggle(); return false; } function twistieAction($id) { $twistie = '#_'+$id; $toggle = '#toggle_'+$id; if ($($twistie).hasClass('fa-plus-square')) { $($twistie).addClass('fa-minus-square').removeClass('fa-plus-square'); } else { $($twistie).addClass('fa-plus-square').removeClass('fa-minus-square'); } $($toggle).toggle(); return false; } function resizedetailmap() { var ch = $('#carousel-species-detail').height(); var fh = $('#matched-footer').height() + 20; //inc. padding console.log(ch+'|'+fh); $('#matched-map').height( ch - fh ); } $(document).ready(function() { //Initialise some states $('.sensitivityhide').hide(); $('.starttogglehidden').hide(); //Initialise some plugins $('.popoverme').popover({trigger:'focus',html:true}).on('click', function(e) {e.preventDefault(); return true;}); $('a[data-toggle="tooltip"]').tooltip(); $('img[data-toggle="tooltip"]').tooltip(); $('.marlin-button-group').each(function(index,element) { var mytype = $(this).attr('data-children'); $(this).find('a').each(function(index,element) { $(element).addClass('btn').addClass('btn-'+mytype); }); }); // Focus state for append/prepend inputs (Search boxes) $('.input-group').on('focus', '.form-control', function () { $(this).closest('.input-group, .form-group').addClass('focus'); }).on('blur', '.form-control', function () { $(this).closest('.input-group, .form-group').removeClass('focus'); }); $('body').on('click', 'a.disabled', function(event) { event.preventDefault(); }); resizedetailmap(); $('.wall').each(function(index) { $(this).imagesLoaded ( function() { $('.wall').masonry({ itemSelector:'.galleryitem', columnWidth:'.galleryitem' }); }); }); }); $(window).resize(function() { resizedetailmap(); });