function getURLVar(key) { var value = []; var query = String(document.location).split('?'); if (query[1]) { var part = query[1].split('&'); for (i = 0; i < part.length; i++) { var data = part[i].split('='); if (data[0] && data[1]) { value[data[0]] = data[1]; } } if (value[key]) { return value[key]; } else { return ''; } } } $(document).ready(function() { //Form Submit for IE Browser $('button[type=\'submit\']').on('click', function() { $("form[id*='form-']").submit(); }); // Highlight any found errors $('.text-danger').each(function() { var element = $(this).parent().parent(); if (element.hasClass('form-group')) { element.addClass('has-error'); } }); // Set last page opened on the menu $('#menu a[href]').on('click', function() { sessionStorage.setItem('menu', $(this).attr('href')); }); if (!sessionStorage.getItem('menu')) { $('#menu #dashboard').addClass('active'); } else { // Sets active and open to selected page in the left column menu. $('#menu a[href=\'' + sessionStorage.getItem('menu') + '\']').parents('li').addClass('active open'); } if (localStorage.getItem('column-left') == 'active') { $('#button-menu i').replaceWith(''); $('#column-left').addClass('active'); // Slide Down Menu $('#menu li.active').has('ul').children('ul').addClass('collapse in'); $('#menu li').not('.active').has('ul').children('ul').addClass('collapse'); } else { $('#button-menu i').replaceWith(''); $('#menu li li.active').has('ul').children('ul').addClass('collapse in'); $('#menu li li').not('.active').has('ul').children('ul').addClass('collapse'); } // Menu button $('#button-menu').on('click', function() { // Checks if the left column is active or not. if ($('#column-left').hasClass('active')) { localStorage.setItem('column-left', ''); $('#button-menu i').replaceWith(''); $('#column-left').removeClass('active'); $('#menu > li > ul').removeClass('in collapse'); $('#menu > li > ul').removeAttr('style'); } else { localStorage.setItem('column-left', 'active'); $('#button-menu i').replaceWith(''); $('#column-left').addClass('active'); // Add the slide down to open menu items $('#menu li.open').has('ul').children('ul').addClass('collapse in'); $('#menu li').not('.open').has('ul').children('ul').addClass('collapse'); } }); // Menu $('#menu').find('li').has('ul').children('a').on('click', function() { if ($('#column-left').hasClass('active')) { $(this).parent('li').toggleClass('open').children('ul').collapse('toggle'); $(this).parent('li').siblings().removeClass('open').children('ul.in').collapse('hide'); } else if (!$(this).parent().parent().is('#menu')) { $(this).parent('li').toggleClass('open').children('ul').collapse('toggle'); $(this).parent('li').siblings().removeClass('open').children('ul.in').collapse('hide'); } }); // Override summernotes image manager $('button[data-event=\'showImageDialog\']').attr('data-toggle', 'image').removeAttr('data-event'); $(document).delegate('button[data-toggle=\'image\']', 'click', function() { $('#modal-image').remove(); $(this).parents('.note-editor').find('.note-editable').focus(); $.ajax({ url: 'index.php?route=common/filemanager&token=' + getURLVar('token'), dataType: 'html', beforeSend: function() { $('#button-image i').replaceWith(''); $('#button-image').prop('disabled', true); }, complete: function() { $('#button-image i').replaceWith(''); $('#button-image').prop('disabled', false); }, success: function(html) { $('body').append('
'; } } // Get all the ones with a categories var category = new Array(); for (i = 0; i < json.length; i++) { if (json[i]['category']) { if (!category[json[i]['category']]) { category[json[i]['category']] = new Array(); category[json[i]['category']]['name'] = json[i]['category']; category[json[i]['category']]['item'] = new Array(); } category[json[i]['category']]['item'].push(json[i]); } } for (i in category) { html += '
' + category[i]['name'] + '
'; for (j = 0; j < category[i]['item'].length; j++) { html += '