var dropdown_hide_delay = 3000, active_panel = '#p-results', wellknowntunesLetter = 'A', wellknowntunesSort = 'a', composerLetter = 'A', composerSort = 'l', panel_changed = 0, criteria = {}, mcriteria = {}, searchby = {}, // differences panel_loaded = {}, libs_matched = {}, expand_section = 0; function reset_criteria() { criteria.keywords = {}; criteria.keywordgroups = {}; criteria.musicfor = {}; criteria.genres = {}; criteria.moods = {}; criteria.instruments = {}; criteria.bpm = {}; criteria.duration = {}; criteria.tempos = {}; criteria.periods = {}; criteria.regions = {}; criteria.dances = {}; criteria.misckeywords = {}; criteria.wellknowntunes = {}; criteria.catalogs = {}; criteria.composers = {}; criteria.rpage = 1; panel_loaded['musicfor'] = false; panel_loaded['genres'] = false; panel_loaded['moods'] = false; panel_loaded['instruments'] = false; panel_loaded['tempos'] = false; // also BPM & Duration panel_loaded['periods'] = false; panel_loaded['regions'] = false; panel_loaded['dances'] = false; panel_loaded['misckeywords'] = false; panel_loaded['wellknowntunes'] = false; panel_loaded['catalogs'] = false; panel_loaded['composers'] = false; } function reset_mcriteria() { mcriteria = JSON.parse( JSON.stringify( criteria ) ); } function initialize_criteria() { reset_criteria(); criteria.search_by = {}; criteria.srt = 'bestmatch'; criteria.rnpp = 50; } initialize_criteria(); reset_mcriteria(); function keep_modifications() { reset_criteria(); for( var k in mcriteria.keywords ) criteria.keywords[k] = mcriteria.keywords[k]; for( var k in mcriteria.keywordgroups ) criteria.keywordgroups[k] = mcriteria.keywordgroups[k]; for( var k in mcriteria.musicfor ) criteria.musicfor[k] = mcriteria.musicfor[k]; for( var k in mcriteria.genres ) criteria.genres[k] = mcriteria.genres[k]; for( var k in mcriteria.moods ) criteria.moods[k] = mcriteria.moods[k]; for( var k in mcriteria.instruments ) criteria.instruments[k] = mcriteria.instruments[k]; for( var k in mcriteria.bpm ) criteria.bpm[k] = mcriteria.bpm[k]; criteria.duration = {}; for( var k in mcriteria.duration ) criteria.duration[k] = mcriteria.duration[k]; for( var k in mcriteria.tempos ) criteria.tempos[k] = mcriteria.tempos[k]; for( var k in mcriteria.periods ) criteria.periods[k] = mcriteria.periods[k]; for( var k in mcriteria.regions ) criteria.regions[k] = mcriteria.regions[k]; for( var k in mcriteria.dances ) criteria.dances[k] = mcriteria.dances[k]; for( var k in mcriteria.misckeywords ) criteria.misckeywords[k] = mcriteria.misckeywords[k]; for( var k in mcriteria.wellknowntunes ) criteria.wellknowntunes[k] = mcriteria.wellknowntunes[k]; for( var k in mcriteria.catalogs ) criteria.catalogs[k] = mcriteria.catalogs[k]; for( var k in mcriteria.composers ) criteria.composers[k] = mcriteria.composers[k]; for( var k in mcriteria.search_by ) criteria.search_by[k] = mcriteria.search_by[k]; if( mcriteria.srt ) criteria.srt = mcriteria.srt; criteria.rpage = mcriteria.rpage; } function lose_modifications() { reset_mcriteria(); load_tab( '#p-musicfor', 'musicfor', '/p-musicfor.php', true ); load_tab( '#p-genres', 'genres', '/p-genres.php', true ); load_tab( '#p-moods', 'moods', '/p-moods.php', true ); load_tab( '#p-instruments', 'instruments', '/p-instruments.php', true ); load_tab( '#p-tempos', 'tempos', '/p-tempos.php', true ); load_tab( '#p-periods', 'periods', '/p-periods.php', true ); load_tab( '#p-regions', 'regions', '/p-regions.php', true ); load_tab( '#p-dances', 'dances', '/p-dances.php', true ); load_tab( '#p-misckeywords', 'misckeywords', '/p-misckeywords.php', true ); load_tab( '#p-wellknowntunes', 'wellknowntunes', '/p-wellknowntunes.php', true ); load_tab( '#p-catalogs', 'catalogs', '/p-catalogs.php', true ); load_tab( '#p-composers', 'composers', '/p-composers.php', true ); } var ani_speed = 200; var ani_close_timer; function split( val ) { //return val.split( /,\s*/ ); return val.split( ' ' ); } function extractLast( term ) { return split( term ).pop(); } /*$(document).on( 'keydown', function(e) { // don't navigate away from the field on tab when selecting an item if( e.keyCode === $.ui.keyCode.TAB && $( this ).autocomplete( 'instance' ).menu.active ) e.preventDefault(); });*/ $(function(){ var initial_value = $('#kw').val(); //console.log( 'kw initial_value: ' + initial_value ); $('#kw').focus(function() { if( this.value == initial_value ) { this.value = ''; } }); $('#kw').blur(function() { if( this.value == '' ) { this.value = initial_value; } }); /*$('#kw').autocomplete({ 'source': function( request, response ) { $.getJSON( 'search_hints.php', { 'term': extractLast( request.term ) }, response ); }, 'search': function() { // custom minLength var term = extractLast( this.value ); if( term.length < 2 ) return false; }, 'focus': function() { // prevent value inserted on focus return false; }, 'select': function( e, ui ) { set_keyword_to( ui.item.value ); do_search(); return false; }, 'delay': 200 });*/ $(document).on( 'click', 'input[type=checkbox].searchby', function(e){ var total = 0; $('input[type=checkbox].searchby').each(function( i, e ){ total += $(e).prop('checked') ? 1 : 0; }); var ct = $(e.currentTarget); //console.log( 'search checkbox clicked; last: ' + ct.attr('name') + ', total: ' + total ); if( 0 == total ) { //console.log( 'oops! re-check last one.' ); alt_checkbox( ct, true ); //alert( 'You must have at least one checkbox checked.' ); } }); $('div.our_search_dropdown input[type=checkbox]').each(function(){ searchby[ $(this).attr('name') ] = $(this).prop('checked'); //console.log( 'init searchby:', searchby ); }); $(document).on( 'click', 'input.panel_apply', function(){ apply_panel(1); }); var our_search_dropdown_options_height = $('div.our_search_dropdown .options').height(); //console.log( 'our_search_dropdown_options_height: ' + our_search_dropdown_options_height ); $(document).on( 'mouseenter', 'div.our_search_dropdown', function(e){ clearTimeout( ani_close_timer ); $('div.our_search_dropdown div.options').css( { 'border-left': '1px solid #ccc', 'border-right': '1px solid #ccc', 'border-bottom': '1px solid #ccc' } ); $('div.our_search_dropdown div.options').animate( { 'height': our_search_dropdown_options_height }, { 'duration': ani_speed, 'queue': false, 'complete': function(){ $('div.our_search_dropdown div.options').css( { 'border-left': '1px solid #ccc', 'border-right': '1px solid #ccc', 'border-bottom': '1px solid #ccc' } ); } } ); $('div.our_search_dropdown input[type=checkbox]').each(function(){ searchby[ $(this).attr('name') ] = $(this).prop('checked'); //console.log( 'searchby:', searchby ); }); }); $(document).on( 'mouseleave', 'div.our_search_dropdown', function(e){ ani_close_timer = setTimeout( function(){ dropdown_hide(); }, 500 ); }); var initial_hide = setTimeout( function(){ $('div.our_search_dropdown').trigger( 'mouseleave' ); }, dropdown_hide_delay ); $(document).on( 'click', '.xdelete', function(e){ var type = $(this).attr('t'); var item = $(this).attr('i'); if( item ) item = item.replace( '\\', '' ); // strip backslashes var group = $(this).attr('g'); switch( type ) { case 'kw': remove_keyword( item ); break; case 'musicfor': remove_musicfor( item ); break; case 'genres': if( item ) remove_genre( item ); if( group ) remove_genres_group( group ); break; case 'moods': if( item ) remove_mood( item ); if( group ) remove_mood_group( group ); break; case 'instruments': if( item ) remove_instrument( item ); if( group ) remove_instrument_group( group ); break; case 'bpm': remove_bpm( item ); break; case 'duration': remove_duration( item ); break; case 'tempo': remove_tempo( item ); break; case 'period': remove_period( item ); break; case 'region': remove_region( item ); break; case 'dance': remove_dance( item ); break; case 'misckeyword': remove_misckeyword( item ); break; case 'wellknowntune': remove_well_known_tune( item ); break; case 'catalog': remove_catalog( item ); break; case 'composer': remove_composer( item ); break; } }); $(document).on( 'click', '#clear_all', function(e){ clear_all(); }); $(document).on( 'change', '.panel input[type=checkbox]', function(e){ var panel = $(this).parents('div.panel').attr('id').substr(2); //console.log( 'checkbox changed; panel:', panel ); panel_changed = 1; }); $(document).on( 'change', '#showexactmatches', function(e){ do_search(1); }); // BPM single $(document).on( 'click change', '#bpmsingle', function(e){ if($('#bpmsingle').is(':checked')){ $('#bpmExact').removeAttr('disabled'); $('#bpmExact').focus(); } else { $('#bpmExact').attr('disabled', true); } }); // BPM range $(document).on( 'click change', '#bpmdouble', function(e){ if($('#bpmdouble').is(':checked')){ $('#bpmMin, #bpmMax').removeAttr('disabled'); $('#bpmMin').focus(); } else { $('#bpmMin, #bpmMax').attr('disabled', true); } }); // BPM changed single $(document).on( 'change', '#bpmExact', function(){ if( isNumeric(parseInt($(this).val())) && parseInt($(this).val()) > 0 ) { panel_changed = 1; } else { alert('Only numbers > than 0 are allowed'); $(this).val('0'); } }); // BPM changed double $(document).on( 'change', '#bpmMin', function(){ if( isNumeric( parseInt( $(this).val() ) ) && parseInt( $(this).val() ) < parseInt( $('#bpmMax').val() ) ) { panel_changed = 1; } else { alert( 'Only numbers less than ' + $('#bpmMax').val() + ' are allowed' ); $(this).val('0'); } }); // bpmMax $(document).on( 'change', '#bpmMax', function(){ if( isNumeric( parseInt( $(this).val() ) ) && parseInt( $(this).val() ) > parseInt( $('#bpmMin').val() ) ) { panel_changed = 1; } else { alert('Only numbers greater than ' + $('#bpmMin').val() + ' are allowed'); $(this).val(parseInt($('#bpmMin').val()) + 1); } }); // Duration single $(document).on( 'click change', '#dursingle', function(e){ if($('#dursingle').is(':checked')){ $('#durExact').removeAttr('disabled'); $('#durExact').focus(); } else { $('#durExact').attr( 'disabled', 'disabled' ); } }); $(document).on( 'change', '#durExact', function(e){ convertValueFromMinColonSecToSecs( $(this) ); if( isNumeric( parseInt( $(this).val() ) ) && parseInt( $(this).val() ) > 0 ) { panel_changed = 1; } else { alert('Only numbers > than 0 are allowed'); $(this).val('0'); } }); //Duration range $(document).on( 'click change', '#durdouble', function(e){ if($('#durdouble').is(':checked')){ $('#durMin, #durMax').removeAttr('disabled'); $('#durMin').focus(); } else { $('#durMin, #durMax').attr( 'disabled', 'disabled' ); } }); $(document).on( 'change', '#durMin', function(e){ convertValueFromMinColonSecToSecs( $(this) ); if( isNumeric( parseInt( $(this).val() ) ) && parseInt( $(this).val() ) < parseInt( $('#durMax').val() ) ) { panel_changed = 1; } else { alert('Only numbers < than ' + $('#durMax').val() + ' are allowed'); $(this).val('0'); } }); $(document).on( 'change', '#durMax', function(e){ convertValueFromMinColonSecToSecs( $(this) ); if( isNumeric( parseInt( $(this).val() ) ) && parseInt( $(this).val() ) > parseInt( $('#durMin').val() ) ) { panel_changed = 1; } else { alert('Only numbers > than ' + parseInt( $('#durMin').val() ) + ' and > minimum are allowed'); $(this).val( parseInt( $('#durMin').val() ) + 1 ); } }); $(document).on( 'click', '#durChoices .multi', function(e){ panel_changed = 1; }); $(document).on( 'click', '.acttab_catalogs', function(e){ $('#t-catalogs').trigger('click'); }); $(document).on( 'click', '.tab_trigger', function(e){ expand_section = $(this).attr('g'); $( '#t-' + $(this).attr('tab') ).trigger('click'); }); // parent click select children $(document).on( 'change', '.parent_filter input[type=checkbox]', function(){ var w = '#wrap-' + $(this).attr('g'); section_expand( $(this).attr('g') ); if( ! $('#showexactmatches').is(':checked') ) { if( $(this).is(':checked') ) { $(this).prev('a').removeClass('partial_checkbox'); // alt-checkboxes $(w + ' input[type=checkbox]').each(function(i,e){ alt_checkbox( e, true ); }); } else { $(w + ' input[type=checkbox]').each(function(i,e){ alt_checkbox( e, false ); }); } } }); $(document).on( 'change', '.child_filter input[type=checkbox]', function(e) { set_parent_checkbox( $(this).attr('g') ); }); // track details expand trigger & function, new and improved $(document).on( 'click', '#tsr-wrapper .exp_details', function(e){ var parentId = $(this).attr('pid'); var song_id = $(this).attr('song_id'); var rn = ( $(this).attr('rn') ? $(this).attr('rn') : '' ); var passed_duration = ( $('#passed_duration').val() ? $('#passed_duration').val() : '' ); if( ! $('#tsr-parent-' + parentId).hasClass('tsrExpanded') ) { $(this).parent('tr').find('td.exp_details').each(function(i,e){ $(e).attr( 'title', 'Click to hide versions' ); }); $(this).parent('tr').find('i.expando').hide(); $(this).parent('tr').find('i.contracto').show(); $('.tsr-child-' + parentId).removeClass('gone'); $('#tsr-parent-' + parentId).addClass('tsrExpanded'); $('.tsr-details-' + parentId).load( '/p-details.php', { 'song_id': song_id, 'rn': rn, 'passed_duration': passed_duration } ); } else { $(this).parent('tr').find('td.exp_details').each(function(i,e){ $(e).attr( 'title', 'Click to show versions' ); }); $(this).parent('tr').find('i.expando').show(); $(this).parent('tr').find('i.contracto').hide(); $('.tsr-child-' + parentId).addClass('gone'); $('#tsr-parent-' + parentId).removeClass('tsrExpanded'); $('.child-player-area').addClass('gone'); player_children_stop(); } }); // rows per page change $(document).on( 'change', '#tsr-per-pg', function(){ criteria.rnpp = parseInt( $(this).val() ) || 50; do_search(); }); // sort change $(document).on( 'change', '#tsr-sortby', function(){ mcriteria.srt = $(this).val(); do_search(); }); // pagination $(document).on( 'click', '#pagination div.item:not(.inactive)', function(){ var page = parseInt( $(this).attr('p') ) || 1; if( page ) { do_search(page); $(document).scrollTop(126); } }); $(document).on( 'click', '#btnUpdatePreferences', function(e){ update_preferences(e); }); $(document).on( 'click', 'div#save_as_default', function(e){ if(0) console.log( 'save_as_default:', 'cat', $('#chk-categories').is(':checked'), 'des', $('#chk-description').is(':checked'), 'trt', $('#chk-tracktitle').is(':checked'), 'cdt', $('#chk-cdtitle').is(':checked'), 'lyr', $('#chk-lyrics').is(':checked') ); //console.log( 'save_as_default:', criteria.search_by ); $.ajax( '/mymegatrax/my-preferences-save.php', { 'type': 'POST', 'data': { 'a': 'search_prefs_only', 'search_categories': $('#chk-categories').is(':checked') ? '1' : '0', 'search_description': $('#chk-description').is(':checked') ? '1' : '0', 'search_track_title': $('#chk-tracktitle').is(':checked') ? '1' : '0', 'search_cd_title': $('#chk-cdtitle').is(':checked') ? '1' : '0', 'search_lyrics': $('#chk-lyrics').is(':checked') ? '1' : '0' }, 'success': function(r){ if( '1' == r ) alert( 'Search preferences saved.' ); else console.log( r ); } }); }); }); function dropdown_hide() { $('div.our_search_dropdown div.options').animate( { 'height': '0' }, { 'duration': ani_speed, 'queue': false, 'complete': function(){ $('div.our_search_dropdown div.options').css( 'border', '0px' ); } } ); var differences = 0; $('div.our_search_dropdown input[type=checkbox]').each(function(){ if( $(this).prop('checked') && ! searchby[ $(this).attr('name') ] || ! $(this).prop('checked') && searchby[ $(this).attr('name') ] ) { //console.log( 'different!', $(this) ); differences++; } }); //console.log( 'differences:', differences ); if( differences ) do_search(); } function set_url_hash() { var h = ''; //console.log( 'set_url_hash; criteria:', criteria ); if( criteria.keywords && Object.keys(criteria.keywords).length ) { //console.log( 'found criteria.keywords:', criteria.keywords ); var csl = ''; for( var k in criteria.keywords ) { //console.log( 'k:', k ); csl += k.replace( /[^a-zA-Z0-9\s_&\-\+\.']+/g, '' ) + ','; } csl = csl.substr( 0, csl.length - 1 ); h += 'k=' + csl + ';'; } //console.log( 'h:', h ); if( criteria.keywordgroups && Object.keys(criteria.keywordgroups).length ) { var csl = ''; for( var k in criteria.keywordgroups ) { csl += k.replace( /[^a-zA-Z0-9\s_&\-\+\.']+/g, '' ) + ','; } csl = csl.substr( 0, csl.length - 1 ); h += 'kg=' + csl + ';'; } if( criteria.musicfor && Object.keys(criteria.musicfor).length ) { var csl = ''; for( var k in criteria.musicfor ) { csl += parseInt( k ) + ','; } csl = csl.substr( 0, csl.length - 1 ); h += 'mf=' + csl + ';'; } if( criteria.genres && Object.keys(criteria.genres).length ) { var csl = ''; for( var k in criteria.genres ) { csl += parseInt( k ) + ','; } csl = csl.substr( 0, csl.length - 1 ); h += 'g=' + csl + ';'; } if( criteria.moods && Object.keys(criteria.moods).length ) { var csl = ''; for( var k in criteria.moods ) { csl += parseInt( k ) + ','; } csl = csl.substr( 0, csl.length - 1 ); h += 'm=' + csl + ';'; } if( criteria.instruments && Object.keys(criteria.instruments).length ) { var csl = ''; for( var k in criteria.instruments ) { csl += parseInt( k ) + ','; } csl = csl.substr( 0, csl.length - 1 ); h += 'i=' + csl + ';'; } if( criteria.bpm && Object.keys(criteria.bpm).length ) { var csl = ''; for( var k in criteria.bpm ) { csl += k + ':' + criteria.bpm[k] + ','; } csl = csl.substr( 0, csl.length - 1 ); h += 'b=' + csl + ';'; } if( criteria.duration && Object.keys(criteria.duration).length ) { var csl = ''; for( var k in criteria.duration ) { if( 'e' == k || 'n' == k || 'x' == k ) csl += k + ':' + criteria.duration[k] + ','; else csl += k + ','; } csl = csl.substr( 0, csl.length - 1 ); h += 'd=' + csl + ';'; } if( criteria.tempos && Object.keys(criteria.tempos).length ) { var csl = ''; for( var k in criteria.tempos ) csl += k + ','; csl = csl.substr( 0, csl.length - 1 ); h += 't=' + csl + ';'; } if( criteria.periods && Object.keys(criteria.periods).length ) { var csl = ''; for( var k in criteria.periods ) csl += k + ','; csl = csl.substr( 0, csl.length - 1 ); h += 'p=' + csl + ';'; } if( criteria.regions && Object.keys(criteria.regions).length ) { var csl = ''; for( var k in criteria.regions ) csl += k + ','; csl = csl.substr( 0, csl.length - 1 ); h += 'r=' + csl + ';'; } if( criteria.dances && Object.keys(criteria.dances).length ) { var csl = ''; for( var k in criteria.dances ) csl += k + ','; csl = csl.substr( 0, csl.length - 1 ); h += 'c=' + csl + ';'; } if( criteria.misckeywords && Object.keys(criteria.misckeywords).length ) { var csl = ''; for( var k in criteria.misckeywords ) csl += k + ','; csl = csl.substr( 0, csl.length - 1 ); h += 'mk=' + csl + ';'; } if( criteria.wellknowntunes && Object.keys(criteria.wellknowntunes).length ) { var csl = ''; for( var k in criteria.wellknowntunes ) csl += k + ','; csl = csl.substr( 0, csl.length - 1 ); h += 'w=' + csl + ';'; } if( criteria.catalogs && Object.keys(criteria.catalogs).length ) { var csl = ''; for( var k in criteria.catalogs ) csl += k + ','; csl = csl.substr( 0, csl.length - 1 ); h += 'l=' + csl + ';'; } if( criteria.composers && Object.keys(criteria.composers).length ) { var csl = ''; for( var k in criteria.composers ) csl += k + ','; csl = csl.substr( 0, csl.length - 1 ); h += 'o=' + csl + ';'; } if( $('#chk-categories').is(':checked') ) h += 'cc=1;'; if( $('#chk-description').is(':checked') ) h += 'cd=1;'; if( $('#chk-tracktitle').is(':checked') ) h += 'ct=1;'; if( $('#chk-cdtitle').is(':checked') ) h += 'ce=1;'; if( $('#chk-lyrics').is(':checked') ) h += 'cl=1;'; if( $('#showexactmatches').is(':checked') ) h += 'ex=1;'; if( $('#withinresults').is(':checked') ) h += 'wi=1;'; else h += 'wi=0;'; if( criteria.srt ) h += 'st=' + criteria.srt + ';'; if( parseInt( criteria.rnpp ) ) h += 'rnpp=' + parseInt( criteria.rnpp ) + ';'; h += 'rp=' + ( parseInt( mcriteria.rpage ) || 1 ) + ';'; //console.log( 'h:', h ); ch = LZString.compressToEncodedURIComponent(h); // "compress" it //console.log( 'h.length:', h.length, ', ch.length:', ch.length ); window.location.hash = ch; // no hash mark (#) } function check_for_search_code() { var full_url = window.location.toString(); //console.log( 'full_url:', full_url ); var h = full_url.match( /\bsearch_code=([\w\d%]+)/ ); if( h ) { //console.log( 'found search_code:', h ); if( 0 ) window.location = window.location.protocol + '//' + window.location.host + window.location.pathname + '#' + h[1]; return true; } else { return false; } } function parse_hash() { var h = decodeURI( LZString.decompressFromEncodedURIComponent( window.location.hash.substr(1) ) ); // .substr to remove hash mark (#) if( null === h ) h = ''; //console.log( 'parse_hash; h (after "decompress"):', h ); if( h.match(/\bex=1/) ) alt_checkbox( $('#showexactmatches'), true ); else alt_checkbox( $('#showexactmatches'), false ); if( h.match(/\bcc=1/) ) alt_checkbox( $('#chk-categories'), true ); else alt_checkbox( $('#chk-categories'), false ); if( h.match(/\bcd=1/) ) alt_checkbox( $('#chk-description'), true ); else alt_checkbox( $('#chk-description'), false ); if( h.match(/\bct=1/) ) alt_checkbox( $('#chk-tracktitle'), true ); else alt_checkbox( $('#chk-tracktitle'), false ); if( h.match(/\bce=1/) ) alt_checkbox( $('#chk-cdtitle'), true ); else alt_checkbox( $('#chk-cdtitle'), false ); if( h.match(/\bcl=1/) ) alt_checkbox( $('#chk-lyrics'), true ); else alt_checkbox( $('#chk-lyrics'), false ); if( h.match(/\bst=[\w_]+;/) ) { mcriteria.srt = h.match(/\bst=([\w_]+);/)[1]; } if( h.match(/\brp=\d+;/) ) mcriteria.rpage = parseInt( h.match(/\brp=(\d+);/)[1] ); else mcriteria.rpage = 1; //console.log( 'mcriteria.rpage:', mcriteria.rpage ); if( h.match(/\brnpp=\d+;/) ) criteria.rnpp = parseInt( h.match(/\brnpp=(\d+);/)[1] ); if( h.match(/\bwi=\d;/) ) alt_checkbox( $('#withinresults'), parseInt( h.match(/\bwi=(\d);/)[1] ) ); else alt_checkbox( $('#withinresults'), false ); var matched_keywords = ''; if( h.match(/\bk=[\w\s_&\-\+\.,']+/) ) { mcriteria.keywords = {}; matched_keywords = h.match(/\bk=([\w_&\-\+\.,']+);?/)[1]; //console.log( 'matched_keywords:', matched_keywords ); var t = matched_keywords.split(','); //console.log( 't:', t ); t.forEach(function(v,i){ mcriteria.keywords[v] = v; }); } /*console.log( 'parse_hash; criteria.keywords:', criteria.keywords, ', mcriteria.keywords:', mcriteria.keywords );*/ var matched_keywordgroups = ''; if( h.match(/\bkg=[\w\s_&\-\+\.,']+/) ) { mcriteria.keywordgroups = {}; matched_keywordgroups = h.match(/\bkg=([\w_&\-\+\.,'\s]+);?/)[1]; //console.log( 'matched_keywordgroups:', matched_keywordgroups ); var t = matched_keywordgroups.split(','); //console.log( 't:', t ); t.forEach(function(v,i){ mcriteria.keywordgroups[v] = v; }); } var matched_musicfor = ''; if( h.match(/\bmf=[\d,]+/) ) { mcriteria.musicfor = {}; matched_musicfor = h.match(/\bmf=([\d,]+);?/)[1]; var t = matched_musicfor.split(','); t.forEach(function(v,i){ mcriteria.musicfor[v] = v; }); load_tab( '#p-musicfor', 'musicfor', '/p-musicfor.php', true ); } var matched_genres = ''; if( h.match(/\bg=[\d,]+/) ) { mcriteria.genres = {}; matched_genres = h.match(/\bg=([\d,]+);?/)[1]; var t = matched_genres.split(','); t.forEach(function(v,i){ mcriteria.genres[v] = v; }); load_tab( '#p-genres', 'genres', '/p-genres.php', true ); } var matched_moods = ''; if( h.match(/\bm=[\d,]+/) ) { mcriteria.moods = {}; matched_moods = h.match(/\bm=([\d,]+);?/)[1]; var t = matched_moods.split(','); t.forEach(function(v,i){ mcriteria.moods[v] = v; }); //console.log( 'criteria.moods:', criteria.moods ); load_tab( '#p-moods', 'moods', '/p-moods.php', true ); } var matched_instruments = ''; if( h.match(/\bi=[\d,]+/) ) { mcriteria.instruments = {}; matched_instruments = h.match(/\bi=([\d,]+);?/)[1]; var t = matched_instruments.split(','); t.forEach(function(v,i){ //console.log( 'instrument, v:', v, ', i:', i ); mcriteria.instruments[v] = v; }); load_tab( '#p-instruments', 'instruments', '/p-instruments.php', true ); } var matched_bpm = ''; if( h.match(/\bb=[\w\d:,]+/) ) { mcriteria.bpm = {}; matched_bpm = h.match(/\bb=([\w\d:,]+);?/)[1]; var t = matched_bpm.split(','); t.forEach(function(v,i){ var ig = v.split(':'); mcriteria.bpm[ ig[0] ] = parseInt( ig[1] ); }); load_tab( '#p-tempos', 'tempos', '/p-tempos.php', true ); } var matched_duration = ''; if( h.match(/\bd=[\w\d\-:,]+;/) ) { mcriteria.duration = {}; matched_duration = h.match(/\bd=([\w\d\-:,]+);/)[1]; var t = matched_duration.split(','); t.forEach(function(v,i){ var ig = v.split(':'); if( ig[0] && ig[1] ) mcriteria.duration[ ig[0] ] = parseInt( ig[1] ); else mcriteria.duration[v] = v; }); load_tab( '#p-tempos', 'tempos', '/p-tempos.php', true ); } var matched_tempos = ''; if( h.match(/\bt=[\d,]+;/) ) { mcriteria.tempos = {}; matched_tempos = h.match(/\bt=([\d,]+);/)[1]; var t = matched_tempos.split(','); t.forEach(function(v,i){ mcriteria.tempos[v] = v; }); load_tab( '#p-tempos', 'tempos', '/p-tempos.php', true ); } var matched_periods = ''; if( h.match(/\bp=[\d,]+;/) ) { mcriteria.periods = {}; matched_periods = h.match(/\bp=([\d,]+);/)[1]; var t = matched_periods.split(','); t.forEach(function(v,i){ mcriteria.periods[v] = v; }); load_tab( '#p-periods', 'periods', '/p-periods.php', true ); } var matched_regions = ''; if( h.match(/\br=[\d,]+;/) ) { mcriteria.regions = {}; matched_regions = h.match(/\br=([\d,]+);/)[1]; var t = matched_regions.split(','); t.forEach(function(v,i){ mcriteria.regions[v] = v; }); load_tab( '#p-regions', 'regions', '/p-regions.php', true ); } var matched_dances = ''; if( h.match(/\bc=[\d,]+;/) ) { mcriteria.dances = {}; matched_dances = h.match(/\bc=([\d,]+);/)[1]; var t = matched_dances.split(','); t.forEach(function(v,i){ mcriteria.dances[v] = v; }); load_tab( '#p-dances', 'dances', '/p-dances.php', true ); } var matched_misckeywords = ''; if( h.match(/\bmk=[\d,]+;/) ) { mcriteria.misckeywords = {}; matched_misckeywords = h.match(/\bmk=([\d,]+);/)[1]; var t = matched_misckeywords.split(','); t.forEach(function(v,i){ mcriteria.misckeywords[v] = v; }); load_tab( '#p-misckeywords', 'misckeywords', '/p-misckeywords.php', true ); } var matched_wellknowntunes = ''; if( h.match(/\bw=[\d,]+;/) ) { mcriteria.wellknowntunes = {}; matched_wellknowntunes = h.match(/\bw=([\d,]+);/)[1]; var t = matched_wellknowntunes.split(','); t.forEach(function(v,i){ mcriteria.wellknowntunes[v] = v; }); load_tab( '#p-wellknowntunes', 'wellknowntunes', '/p-wellknowntunes.php', true ); } var matched_catalogs = ''; if( h.match(/\bl=[\d,]+;/) ) { mcriteria.catalogs = {}; matched_catalogs = h.match(/\bl=([\d,]+);/)[1]; var t = matched_catalogs.split(','); t.forEach(function(v,i){ mcriteria.catalogs[v] = v; }); load_tab( '#p-catalogs', 'catalogs', '/p-catalogs.php', true ); } var matched_composers = ''; if( h.match(/\bo=[\d,]+;/) ) { mcriteria.composers = {}; matched_composers = h.match(/\bo=([\d,]+);/)[1]; var t = matched_composers.split(','); t.forEach(function(v,i){ mcriteria.composers[v] = v; }); load_tab( '#p-composers', 'composers', '/p-composers.php', true ); } } function loading_show() { $('#overlay,#loading').show(); } function loading_hide() { $('#loading,#overlay').hide(); $('#p-results-overlay').hide(); } function clear_all() { reset_criteria(); reset_mcriteria(); $('.panel').empty(); do_search(); } function convertValueFromMinColonSecToSecs( t ) { var timeElements = t.val().split(':'); if( isNumeric( timeElements[0] ) && isNumeric( timeElements[1] ) ) { t.val( ( parseInt(timeElements[0]) * 60 ) + parseInt(timeElements[1]) ); } } // preferences download_filename_format change $(document).on( 'change', '#formPreferences #download_filename_format', function(e){ var fmt = $(this).val(); switch (fmt){ case 'ms_track_sample_file-ext': var caution = 1; $('#formPreferences #download-format-sample').html('ie: MX001_10.aif'); break; case 'ms_track_sample_file-ms_track_title-ext': var caution = 1; $('#formPreferences #download-format-sample').html('ie: MX001_10-Heartbeat Pulse.aif'); break; case 'ms_track_sample_file-format-ext': var caution = 0; $('#formPreferences #download-format-sample').html('ie: MX001_10-441khz.aif'); break; case 'ms_track_sample_file-ms_track_title-format-ext': var caution = 0; $('#formPreferences #download-format-sample').html('ie: MX001_10-Heartbeat Pulse-441khz.aif'); break; default: var caution = 0; } if(caution == 1) { $('#formPreferences #download-format-sample').append('

Caution:

Excluding the format (44khz or 48khz) from AIF or WAV formats will not generate
unique filenames during the download, if you select both 44khz and 48khz.

'); } }); function set_search_by_from_criteria() { if( criteria.hasOwnProperty('search_by') ) { if( criteria.search_by.hasOwnProperty('exact') ) alt_checkbox( $('#showexactmatches'), criteria.search_by.exact ); else alt_checkbox( $('#showexactmatches'), false ); if( criteria.search_by.hasOwnProperty('sCat') ) alt_checkbox( $('#chk-categories'), criteria.search_by.sCat ); else alt_checkbox( $('#chk-categories'), false ); if( criteria.search_by.hasOwnProperty('sDes') ) alt_checkbox( $('#chk-description'), criteria.search_by.sDes ); else alt_checkbox( $('#chk-description'), false ); if( criteria.search_by.hasOwnProperty('sTrt') ) alt_checkbox( $('#chk-tracktitle'), criteria.search_by.sTrt ); else alt_checkbox( $('#chk-tracktitle'), false ); if( criteria.search_by.hasOwnProperty('sCdt') ) alt_checkbox( $('#chk-cdtitle'), criteria.search_by.sCdt ); else alt_checkbox( $('#chk-cdtitle'), false ); if( criteria.search_by.hasOwnProperty('sLyr') ) alt_checkbox( $('#chk-lyrics'), criteria.search_by.sLyr ); else alt_checkbox( $('#chk-lyrics'), false ); } } function load_saved_search( search_id, search_code ) { //console.log( 'load_saved_search; search_id:', search_id, ', search_code:', search_code ); $.ajax( '/p-saved-search-load.php', { 'type': 'GET', 'data': { 'search_id': search_id, 'search_code': search_code }, 'success': function(r) { reset_criteria(); var loaded_criteria = JSON.parse(r); //console.log( 'loaded_criteria:', loaded_criteria ); for( var k in loaded_criteria ) mcriteria[k] = loaded_criteria[k]; //console.log( 'mcriteria:', mcriteria ); if( ! Object.keys(mcriteria.search_by).length || ( ! mcriteria.search_by.exact + mcriteria.search_by.sCat + mcriteria.search_by.sDes + mcriteria.search_by.sTrt + mcriteria.search_by.sCdt + mcriteria.search_by.sLyr ) ) { //console.log( 'setting default search-by options.' ); mcriteria.search_by = { 'exact': 0, 'sCat': 1, 'sDes': 1 }; // default search-by } keep_modifications(); set_search_by_from_criteria(); set_url_hash(); if(0) { console.log( 'new url: ' + window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.hash ); console.log( 'decompressed:', LZString.decompressFromEncodedURIComponent( window.location.hash.substr(1) ) ); } else { do_search(); } } }); } $(document).on( 'click', '.loadSearchTrigger', function(e) { // load saved search load_saved_search( $(this).attr('search_id'), '' ); }); $(document).on( 'click', '.showShareSearchTrigger', function(e){ //var link = 'http://www.megatrax.com/search.php?search_code=' + $(this).attr('share_search'); //var link = 'http://www.megatrax.com/search.php#' + $(this).attr('share_search'); var link = 'http://www.megatrax.com/search.php?search_code=' + $(this).attr('share_search_code'); window.prompt( 'Copy to clipboard: Ctrl+C or Command+C, Enter', link ); }); $(document).on( 'click', '.delSavedSearchTrigger', function(e) { //delete saved search $('#p-saved-searches').load( '/p-saved-searches.php', { 'search_id': $(this).attr('id') } ); }); $(document).on( 'click', '#save_search_prompt', function(e) { var keywords = Object.keys(criteria.keywords).length; var tot_cri = Object.keys(criteria.musicfor).length + Object.keys(criteria.genres).length + Object.keys(criteria.moods).length + Object.keys(criteria.instruments).length + Object.keys(criteria.bpm).length + Object.keys(criteria.duration).length + Object.keys(criteria.tempos).length + Object.keys(criteria.periods).length + Object.keys(criteria.regions).length + Object.keys(criteria.dances).length + Object.keys(criteria.misckeywords).length + Object.keys(criteria.wellknowntunes).length + Object.keys(criteria.catalogs).length + Object.keys(criteria.composers).length; if( keywords + tot_cri < 1 ) { alert('You must complete a valid search before saving'); return false; } else { var search_title = ''; for( k in criteria.keywords ) search_title += k + ' '; $('input#save_search').attr( 'disabled', false ); //console.log( 'search_title:', search_title ); $('#search_title').val( '2017-12-11 ' + search_title ); $('#save_search_interface').removeClass('gone'); $('#overlay').show(); } }); $(document).on( 'click', '#cancel_save_search', function(e){ $('#save_search_interface').addClass('gone'); $('#overlay').hide(); }); $(document).on( 'submit', 'form#form_save_search', function(e) { e.preventDefault(); $('input#save_search').attr( 'disabled', true ); var title = $('#form_save_search #search_title').val(); if( $('#chk-categories').is(':checked') ) var sCat = 1; else var sCat = 0; if( $('#chk-description').is(':checked') ) var sDes = 1; else var sDes = 0; if( $('#chk-tracktitle').is(':checked') ) var sTrt = 1; else var sTrt = 0; if( $('#chk-cdtitle').is(':checked') ) var sCdt = 1; else var sCdt = 0; if( $('#chk-lyrics').is(':checked') ) var sLyr = 1; else var sLyr = 0; if( $('#showexactmatches').is(':checked') ) var exact_matching = 1; else var exact_matching = 0; $.ajax( '/mymegatrax/save-search.php', { type: 'POST', cache: false, timeout: 60000, data: { 'title': title, 'criteria': criteria, 'exact_matching': exact_matching, 'sCat': sCat, 'sDes': sDes, 'sTrt': sTrt, 'sCdt': sCdt, 'sLyr': sLyr }, success: function(rs){ alert(rs); $('#save_search_interface').addClass('gone'); $('#overlay').hide(); }, error: function(u){ alert('error:' + u); //$('#save_search_interface').addClass('gone'); } }); }); // tab triggers $(document).on( 'click', '#tdTabs ul li a', function(){ var target = $(this).attr('id').substr(2); var nextPanel = '#p-' + target; var clickedTab = '#t-' + target; //console.log( 'active_panel = ' + active_panel + ', nextPanel = ' + nextPanel ); apply_panel(); $('#tdTabs ul li a[id^=t-]').removeClass('selected'); if( active_panel == nextPanel ) { //if same panel is clicked just close leaving p-results $(active_panel).hide(); active_panel = '#p-results'; $(active_panel).show(); $('#p-results-overlay').hide(); } else { //$('#p-results').hide(); var actual_target = '/p-' + target + '.php'; if( 'preferences' == target ) { actual_target = '/mymegatrax/my-preferences.php'; $('#formPreferences #preferences-msg').html(''); } //console.log( 'active_panel:', active_panel, ', nextPanel:', nextPanel ); load_tab( nextPanel, target, actual_target ); if( '#p-results' != active_panel ) $(active_panel).hide(); else $('#p-results-overlay').show(); $(nextPanel).show(); active_panel = nextPanel; $(clickedTab).addClass('selected'); } }); function set_alt_checkboxes() { $('input[type=checkbox].disabled').altCheckbox( { 'iconClass': 'fa-check', 'sizeClass': 'normal', 'customClass': 'disabled', 'labelSameSize': false, 'outlineUnchecked': true } ); $('input[type=checkbox].checkbox_partial').altCheckbox( { 'iconClass': 'fa-check', 'sizeClass': 'normal', 'customClass': 'partial_checkbox', 'labelSameSize': false, 'outlineUnchecked': true } ); $('input[type=checkbox]').altCheckbox( { 'iconClass': 'fa-check', 'sizeClass': 'normal', 'customClass': '', 'labelSameSize': false, 'outlineUnchecked': true } ); } function load_tab( nextPanel, target, actual_target, force_load ) { if( null == force_load ) force_load = false; //console.log( 'load_tab; nextPanel:', nextPanel, 'target:', target ); // ex: load_tab( '#p-wellknowntunes', 'wellknowntunes', '/p-wellknowntunes.php' ); if( ! panel_loaded[target] || force_load ) { //console.log( 'load_tab; target:', target, ' is not loaded, or force_load:', force_load ); var data = {}; if( 'composers' == target ) data = { 's': composerSort, 'c': composerLetter }; if( 'wellknowntunes' == target ) data = { 'ws': wellknowntunesSort, 'wc': wellknowntunesLetter }; if( 'catalogs' == target ) data = { 'libs_matched': libs_matched }; data['showexactmatches'] = $('#showexactmatches').is(':checked'); $.ajax( actual_target, { 'type': 'GET', 'data': data, 'beforeSend': function(){ $(nextPanel).empty(); }, 'success': function(r){ $(nextPanel).html(r); if( target !== 'catalogs' // not catalogs, as it needs to be loaded each and every time (for the totals) && target !== 'saved-searches' // and not saved-searches, as it needs to be loaded each and every time ) panel_loaded[target] = true; set_alt_checkboxes(); }, 'complete': function(){ // load up checkboxes from pre-sets if( '#p-musicfor' == nextPanel && criteria.musicfor ) for( var i in criteria.musicfor ) alt_checkbox( $('#add-'+i), true ); if( '#p-genres' == nextPanel && criteria.genres ) for( var i in criteria.genres ) alt_checkbox( $('#add-'+i), true ); if( '#p-moods' == nextPanel && criteria.moods ) for( var i in criteria.moods ) alt_checkbox( $('#add-'+i), true ); if( '#p-instruments' == nextPanel && criteria.instruments ) for( var i in criteria.instruments ) alt_checkbox( $('#add-'+i), true ); if( '#p-tempos' == nextPanel ) { for( var i in criteria.bpm ) { // BPM if( 'e' == i ) { // exact, user-supplied alt_checkbox( $('#bpmsingle'), true ); $('#bpmExact').val( criteria.bpm[i] ); } if( 'n' == i ) { // min, user-supplied alt_checkbox( $('#bpmdouble'), true ); $('#bpmMin').val( criteria.bpm[i] ); } if( 'x' == i ) { // max, user-supplied alt_checkbox( $('#bpmdouble'), true ); $('#bpmMax').val( criteria.bpm[i] ); } } for( var i in criteria.duration ) { // Duration if( 'e' == i ) { alt_checkbox( $('#dursingle'), true ); $('#durExact').val( parseInt( criteria.duration[i] ) ); } else if( 'n' == i ) { alt_checkbox( $('#durdouble'), true ); $('#durMin').val( parseInt( criteria.duration[i] ) ); } else if( 'x' == i ) { alt_checkbox( $('#durdouble'), true ); $('#durMax').val( parseInt( criteria.duration[i] ) ); } else { alt_checkbox( $('#dur_'+i), true ); } } for( var i in criteria.tempos ) // Tempos alt_checkbox( $('#add-'+i), true ); apply_tempo_dur_bpm(); } if( '#p-periods' == nextPanel && criteria.periods ) for( var i in criteria.periods ) alt_checkbox( $('#add-'+i), true ); if( '#p-regions' == nextPanel && criteria.regions ) for( var i in criteria.regions ) alt_checkbox( $('#add-'+i), true ); if( '#p-dances' == nextPanel && criteria.dances ) for( var i in criteria.dances ) alt_checkbox( $('#add-'+i), true ); if( '#p-misckeywords' == nextPanel && criteria.misckeywords ) for( var i in criteria.misckeywords ) alt_checkbox( $('#add-'+i), true ); if( '#p-wellknowntunes' == nextPanel && criteria.wellknowntunes ) tab_set_wellknowntunes(); if( '#p-catalogs' == nextPanel && criteria.catalogs ) for( var i in criteria.catalogs ) alt_checkbox( $('#cat-'+i), true ); if( '#p-composers' == nextPanel && criteria.composers ) tab_set_composers(); if( '#p-preferences' == nextPanel ) $('#formPreferences #download_filename_format').trigger('change'); if( expand_section ) { section_expand( expand_section ); expand_section = 0; } catalogs_pane(); } // end 'complete' .ajax }); } else { if( expand_section ) { //console.log( 'expand_section:', expand_section ); section_expand( expand_section ); expand_section = 0; } } } function tab_set_wellknowntunes() { set_alt_checkboxes(); for( var i in criteria.wellknowntunes ) if( $('#add-'+i).length ) alt_checkbox( $('#add-'+i), true ); } function tab_set_composers() { set_alt_checkboxes(); for( var i in criteria.composers ) if( $('#com-'+i).length ) alt_checkbox( $('#com-'+i), true ); } $(document).on( 'click', '.panel_close,.panelClose', function(){ // cancelBtn / close button lose_modifications(); $('#tdTabs ul li a[id^=t-]').removeClass('selected'); $(active_panel).hide(); panel_loaded[ active_panel.split('-')[1] ] = false; parse_hash(); active_panel = '#p-results'; $(active_panel).show(); $('#p-results-overlay').hide(); panel_changed = 0; }); $(document).on( 'click', '#alphaWellKnownTunes li a', function(){ var t = $(this).attr('title'); wellknowntunes_switch( wellknowntunesSort, t ); }); $(document).on( 'click', '#alphaComposer li a', function(){ var t = $(this).attr('title'); composer_switch( composerSort, t ); }); //input box default class $('.default-value').each(function() { var default_value = this.value; $(this).focus(function() { if(this.value == default_value) { this.value = ''; } }); $(this).blur(function() { if(this.value == '') { this.value = default_value; } }); }); //results column header sorts $(document).on( 'click', '#sortLibrary, #sortCd, #sortTrack, #sortTitle, #sortDescription', function(e){ mcriteria.srt = $(this).attr('p'); do_search(); }); // panel expand attribute $(document).on( 'click', '.expandCat', function(){ var attribute = $(this).attr('id').substr(4); if( $(this).attr('src') == 'images/srch-arrow-d.png' ) { $(this).attr('src','images/srch-arrow-r.png' ); } else { $(this).attr('src','images/srch-arrow-d.png' ); } $('#wrap-' + attribute).toggleClass( 'gone' ); }); function section_expand( attrid ) { $('#img-'+attrid).attr('src','images/srch-arrow-d.png'); $('#wrap-'+attrid).toggleClass( 'gone', false ); } $('#menu-a li:nth-child(2) a').addClass('current'); //$('#srch #tdTabs ul').css('zIndex', 25); //$('#p-results').css('zIndex', 4); function apply_panel( a ) { if( ! a ) a = 0; //console.log( 'apply_panel; active_panel:', active_panel, ', a:', a ); if( active_panel == '#p-musicfor' ) apply_musicfor(a); else if( active_panel == '#p-genres' ) apply_genre(a); else if( active_panel == '#p-moods' ) apply_moods(a); else if( active_panel == '#p-instruments' ) apply_instruments(a); else if( active_panel == '#p-tempos' ) apply_tempo_dur_bpm(a); else if( active_panel == '#p-periods' ) apply_periods(a); else if( active_panel == '#p-regions' ) apply_regions(a); else if( active_panel == '#p-dances' ) apply_dances(a); else if( active_panel == '#p-misckeywords' ) apply_misckeywords(a); else if( active_panel == '#p-wellknowntunes' ) apply_wellknowntunes(a); else if( active_panel == '#p-catalogs' ) apply_catalogs(a); else if( active_panel == '#p-composers' ) apply_composers(a); panel_changed = 0; } function isNumeric(n) { var n2 = n; n = parseFloat(n); return (n!='NaN' && n2==n); } function do_search( page ) { page = parseInt( page ) || 0; if( page ) mcriteria.rpage = page; else page = mcriteria.rpage; set_url_hash(); if( check_for_search_code() ) { //console.log( 'Loading saved search...' ); $('#p-results').html( '

Loading saved search...

' ); document.location = document.location.origin + document.location.pathname + document.location.hash; } else { //console.log( 'do_search; criteria:', criteria ); //console.log( 'do_search; mcriteria:', mcriteria ); loading_show(); var have_some_mcriteria = 0; have_some_mcriteria += Object.keys(mcriteria.keywords).length + Object.keys(mcriteria.keywordgroups).length + Object.keys(mcriteria.musicfor).length + Object.keys(mcriteria.genres).length + Object.keys(mcriteria.moods).length + Object.keys(mcriteria.instruments).length + Object.keys(mcriteria.bpm).length + Object.keys(mcriteria.duration).length + Object.keys(mcriteria.tempos).length + Object.keys(mcriteria.periods).length + Object.keys(mcriteria.regions).length + Object.keys(mcriteria.dances).length + Object.keys(mcriteria.misckeywords).length + Object.keys(mcriteria.wellknowntunes).length + Object.keys(mcriteria.catalogs).length + Object.keys(mcriteria.composers).length; //console.log( 'have_some_mcriteria:', have_some_mcriteria ); if( ! $('#withinresults').is(':checked') && have_some_mcriteria && 1 == page ) { //console.log( 'search within results only, resetting criteria.' ); reset_criteria(); reset_mcriteria(); panel_changed = 1; } if( panel_changed ) apply_panel(); panel_changed = 0; set_keyword(); $('#tdTabs ul li a[id^=t-]').removeClass('selected'); if( $('#chk-categories').is(':checked') ) var sCat = 1; else var sCat = 0; if( $('#chk-cdtitle').is(':checked') ) var sCdt = 1; else var sCdt = 0; if( $('#chk-lyrics').is(':checked') ) var sLyr = 1; else var sLyr = 0; if( $('#chk-description').is(':checked') ) var sDes = 1; else var sDes = 0; if( $('#chk-tracktitle').is(':checked') ) var sTrt = 1; else var sTrt = 0; if( sCat + sCdt + sLyr + sDes + sTrt < 1 ) { loading_hide(); alert( 'Please select at least one "search by" checkbox.' ); } else { //console.log( 'do_search; criteria:', criteria ); keep_modifications(); var exactmatches = 0; if( $('#showexactmatches').is(':checked') ) exactmatches = 1; var presults_script = '/p-results.php'; set_url_hash(); $.ajax( presults_script, { 'type': 'POST', 'data': { // why not just send criteria? 'criteria': criteria, 'sCat': sCat, 'sCdt': sCdt, 'sLyr': sLyr, 'sDes': sDes, 'sTrt': sTrt, 'exactmatches': exactmatches }, 'success': function(r){ $('#p-results').html(r); if(active_panel !== '#p-results') { $(active_panel).hide(); $('#p-results').show(); } active_panel = '#p-results'; }, 'complete': function(){ loading_hide(); } }); } } } function apply_musicfor(a) { $('#p-musicfor input[type=checkbox]').each(function(){ var v = $(this).val(); // 1470 if( this.checked ) { mcriteria.musicfor[v] = v; //console.log( 'apply_musicfor set; mcriteria.musicfor: ', mcriteria.musicfor ); } else { //delete criteria.musicfor[v]; delete mcriteria.musicfor[v]; //console.log( 'apply_musicfor del; mcriteria.musicfor: ', mcriteria.musicfor ); } }); if(a) do_search(1); } function apply_genre(a) { $('#p-genres input[type=checkbox]').each(function(){ var v = $(this).val(); // ex: 420 if( this.checked ) mcriteria.genres[v] = v; else delete mcriteria.genres[v]; }); if(a) do_search(1); } function apply_moods(a) { $('#p-moods input[type=checkbox]').each(function(){ var v = $(this).val(); if( this.checked ) mcriteria.moods[v] = v; else delete mcriteria.moods[v]; }); if(a) do_search(1); } function apply_instruments(a) { $('#p-instruments input[type=checkbox]').each(function(){ var v = $(this).val(); if( this.checked ) mcriteria.instruments[v] = v; else delete mcriteria.instruments[v]; }); if(a) do_search(1); } function apply_tempo_dur_bpm(a) { mcriteria.bpm = {}; if( $('#bpmsingle').is(':checked') ) { mcriteria.bpm['e'] = parseInt( $('#bpmExact').val() ); } else { $('#bpmExact').attr( 'disabled', true ); } if( $('#bpmdouble').is(':checked') ) { mcriteria.bpm['n'] = parseInt( $('#bpmMin').val() ); mcriteria.bpm['x'] = parseInt( $('#bpmMax').val() ); } else { $('#bpmMin,#bpmMax').attr( 'disabled', true ); } mcriteria.duration = {}; if( $('#dursingle').is(':checked') ) { mcriteria.duration['e'] = parseInt( $('#durExact').val() ); } else { $('#durExact').attr( 'disabled', true ); } if( $('#durdouble').is(':checked') ) { if( parseInt($('#durMin').val()) + parseInt($('#durMax').val()) !== 0 ) { mcriteria.duration['n'] = parseInt( $('#durMin').val() ); mcriteria.duration['x'] = parseInt( $('#durMax').val() ); } } else { $('#durMin,#durMax').attr( 'disabled', true ); } $('#duration_choices input[type=checkbox].multi').filter(':checked').each(function(){ mcriteria.duration[ $(this).val() ] = $(this).val(); }); //tempos mcriteria.tempos = {}; $('#tempos_choices input[type=checkbox]').each(function(){ var v = $(this).val(); if( this.checked ) mcriteria.tempos[v] = v; }); if(a) do_search(1); } function apply_periods(a) { $('#p-periods input[type=checkbox]').each(function(){ var v = $(this).val(); if( this.checked ) mcriteria.periods[v] = v; else delete mcriteria.periods[v]; }); if(a) do_search(1); } function apply_regions(a) { $('#p-regions input[type=checkbox]').each(function(){ var v = $(this).val(); if( this.checked ) mcriteria.regions[v] = v; else delete mcriteria.regions[v]; }); if(a) do_search(1); } function apply_dances(a) { $('#p-dances input[type=checkbox]').each(function(){ var v = $(this).val(); if( this.checked ) mcriteria.dances[v] = v; else delete mcriteria.dances[v]; }); if(a) do_search(1); } function apply_misckeywords(a) { mcriteria.misckeywords = {}; $('#p-misckeywords input[type=checkbox]').each(function(){ var v = $(this).val(); if( this.checked ) mcriteria.misckeywords[v] = v; }); if(a) do_search(1); } function apply_wellknowntunes(a) { $('#p-wellknowntunes input[type=checkbox]').each(function(){ var v = $(this).val(); if( this.checked ) mcriteria.wellknowntunes[v] = v; else delete mcriteria.wellknowntunes[v]; }); if(a) do_search(1); } function apply_catalogs(a) { mcriteria.catalogs = {}; $('#p-catalogs input[type=checkbox]').each(function(){ var v = $(this).val(); if( this.checked ) mcriteria.catalogs[v] = v; }); if(a) do_search(1); } function apply_composers(a) { $('#p-composers input[type=checkbox]').each(function(){ var v = $(this).val(); if( this.checked ) mcriteria.composers[v] = v; else delete mcriteria.composers[v]; }); if(a) do_search(1); } function remove_musicfor(f) { delete criteria.musicfor[f]; alt_checkbox( $('#add-' + f), false ); apply_musicfor(1); } function remove_genre( f ) { delete criteria.genres[f]; alt_checkbox( $('#add-' + f), false ); //add-419 apply_genre(1); } function remove_genres_group( g ) { $('input[type=checkbox][g='+g+']').each(function(i,e){ delete criteria.genres[ $(e).val() ]; alt_checkbox( e, false ); $(e).prev('a').removeClass('partial_checkbox'); // alt-checkbox }); apply_genre(1); } function remove_mood(f) { delete criteria.moods[f]; alt_checkbox( $('#add-' + f), false ); apply_moods(1); } function remove_mood_group(g) { $('input[type=checkbox][g='+g+']').each(function(i,e){ delete criteria.moods[ $(e).val() ]; alt_checkbox( e, false ); $(e).prev('a').removeClass('partial_checkbox'); }); apply_moods(1); } function remove_instrument(f) { delete criteria.instruments[f]; alt_checkbox( $('#add-' + f), false ); apply_instruments(1); } function remove_instrument_group(g) { $('input[type=checkbox][g='+g+']').each(function(i,e){ delete criteria.instruments[ $(e).val() ]; alt_checkbox( e, false ); $(e).prev('a').removeClass('partial_checkbox'); }); apply_instruments(1); } function remove_bpm(f) { if( f.indexOf('-') > 0 ) { // range delete criteria.bpm['n']; delete criteria.bpm['x']; alt_checkbox( $('#bpmdouble'), false ); } else { // exact value delete criteria.bpm['e']; alt_checkbox( $('#bpmsingle'), false ); } apply_tempo_dur_bpm(1); } function remove_duration(f) { if( 'e' == f ) { alt_checkbox( $('#dursingle'), false ); $('#dursingle').trigger('change'); } else if( 'd' == f ) { alt_checkbox( $('#durdouble'), false ); $('#durdouble').trigger('change'); } else alt_checkbox( $('#dur_' + f), false ); apply_tempo_dur_bpm(1); } function remove_tempo(f) { delete criteria.tempos[f]; alt_checkbox( $('#add-' + f), false ); apply_tempo_dur_bpm(1); } function remove_period(f) { delete criteria.periods[f]; alt_checkbox( $('#add-' + f), false ); apply_periods(1); } function remove_region(f) { delete criteria.regions[f]; alt_checkbox( $('#add-' + f), false ); apply_regions(1); } function remove_dance(f) { delete criteria.dances[f]; alt_checkbox( $('#add-' + f), false ); apply_dances(1); } function remove_misckeyword(f) { delete criteria.misckeywords[f]; alt_checkbox( $('#add-' + f), false ); apply_misckeywords(1); } function remove_well_known_tune(f) { delete criteria.wellknowntunes[f]; delete mcriteria.wellknowntunes[f]; alt_checkbox( $('#add-' + f), false ); apply_wellknowntunes(1); } function remove_catalog(f) { delete criteria.catalogs[f]; alt_checkbox( $('#cat-' + f), false ); apply_catalogs(1); } function remove_composer(f) { delete criteria.composers[f]; delete mcriteria.composers[f]; alt_checkbox( $('#com-' + f), false ); apply_composers(1); } function remove_keyword( f, ds ) { if( typeof(ds) === 'undefined' ) ds = 1; // Do Search after removal, default to yes delete criteria.keywords[f]; delete mcriteria.keywords[f]; delete criteria.keywordgroups[f]; delete mcriteria.keywordgroups[f]; if( ds ) do_search(1); } function wellknowntunes_switch(s,c) { apply_wellknowntunes(0); wellknowntunesLetter = c; wellknowntunesSort = s; //console.log( 'wellknowntunes_switch; s:', s, ', c:', c ); $('#p-wellknowntunes').load( '/p-wellknowntunes.php', { 'p' : 'wellknowntunes', 'ws': s, 'wc': c }, function(){ if( s == 'f' ) { $('#wellknowntunesSelectSort').attr( 'selectedIndex', 0 ); } else { $('#wellknowntunesSelectSort').attr( 'selectedIndex', 1 ); } tab_set_wellknowntunes(); } ); } function composer_switch(s,c) { apply_composers(0); composerLetter = c; composerSort = s; //console.log( 's:', s, ', c:', c ); $('#p-composers').load( '/p-composers.php', { 'p': 'composer', 's': s, 'c': c }, function(){ if( s == 'f' ) { $('#composerSelectSort').attr( 'selectedIndex', 0 ); } else { $('#composerSelectSort').attr( 'selectedIndex', 1 ); } tab_set_composers(); } ); } function set_keyword() { var kwrd = $('#kw').val(); //fix for [mx 255] to make it [mx255] kwrd = kwrd.replace( /(\D{2,3})\s(\d{3})/gi, '$1$2' ); if( kwrd !== '' && kwrd !== 'Enter search term...' ) { var kwArray = new Array(); //create array from keywords mcriteria.rpage = 1; if( ! $('#withinresults').is(':checked') ) { reset_criteria(); reset_mcriteria(); } kwrd = kwrd.replace( /[^a-zA-Z0-9\s_&\-\+\.']+/g, '' ); //console.log( 'set_keyword; kwrd: ', kwrd ); kwArray = kwrd.split(' '); var kwArrayLen = kwArray.length; if( kwArrayLen > 1 ) { if( kwrd ) mcriteria.keywordgroups[kwrd] = kwrd; //console.log( 'set_keyword; criteria.keywordgroups: ', criteria.keywordgroups ); } $('#kw').val('Enter search term...'); for( i = 0; i < kwArrayLen; i++ ) { var kw = kwArray[i]; if( kw && '-' != kw ) mcriteria.keywords[kw] = kw; } } $('#kw').blur(); } // end set_keyword() function set_keyword_to( kw ) { $('#kw').val( kw ); set_keyword(); } if( window.location.hash.length > 3 ) { parse_hash(); do_search(); } else { clear_all(); } function update_preferences(e) { if( $('#formPreferences').validate({ // none of this matters; is it necessary? rules: { language_code: { required: false }, mymegatrax_default_tab: { required: false } }, messages: { language_code: { required: '' }, mymegatrax_default_tab: { required: '' } } }).form() ) { $.ajax( '/mymegatrax/my-preferences-save.php', { 'type': 'POST', 'data': $('#formPreferences').serialize(), 'success': function(data) { $('#formPreferences #preferences-msg').html('Preferences updated successfully'); sCat = $('#formPreferences input[type=checkbox][name=search_categories]').is(':checked'); sDes = $('#formPreferences input[type=checkbox][name=search_description]').is(':checked'); sTrt = $('#formPreferences input[type=checkbox][name=search_track_title]').is(':checked'); sCdt = $('#formPreferences input[type=checkbox][name=search_cd_title]').is(':checked'); sLyr = $('#formPreferences input[type=checkbox][name=search_lyrics]').is(':checked'); var exactmatches = $('#formPreferences input[type=checkbox][name=search_exact]').is(':checked'); //console.log( 'sCat: ' + sCat + ', sDes: ' + sDes + ', sTrt: ' + sTrt + ', sCdt: ' + sCdt + ', sLyr: ' + sLyr + ', exactmatches: ' + exactmatches ); alt_checkbox( $('#chk-categories'), sCat ); alt_checkbox( $('#chk-description'), sDes ); alt_checkbox( $('#chk-tracktitle'), sTrt ); alt_checkbox( $('#chk-cdtitle'), sCdt ); alt_checkbox( $('#chk-lyrics'), sLyr ); alt_checkbox( $('#showexactmatches'), exactmatches ); $('#tdTabs ul li a[id^=t-]').removeClass('selected'); $(active_panel).hide(); panel_loaded[ active_panel.split('-')[1] ] = false; $('#p-results-overlay').hide(); active_panel = '#p-results'; $(active_panel).show(); do_search(); } }); } else { $('#formPreferences #preferences-msg').html('Please fix preferences errors in RED'); } } function set_parent_checkbox( group ) { //console.log( 'set_parent_checkbox; group: ', group ); var total_children = $('.child_filter input[g='+group+']').length; var num_checked = $('.child_filter input[g='+group+']:checked').length; //console.log( 'set_parent_checkbox; total_children: ', total_children, ', num_checked: ', num_checked ); if( total_children ) { var parent = $('input[g='+group+'][value='+group+']'); var parent_a = parent.prev('a'); // alt-checkboxes if( num_checked ) { parent.prop( 'checked', true ); parent_a.addClass('checked'); if( num_checked == total_children ) { //console.log( 'set_parent_checkbox; ALL are checked.' ); parent_a.removeClass('partial_checkbox'); } else { //console.log( 'set_parent_checkbox; SOME are checked.' ); parent_a.addClass('partial_checkbox'); parent.prop( 'checked', false ); // but not the parents } $('#wrap-'+group).removeClass('gone'); // expand, always } else { //console.log( 'set_parent_checkbox; NONE are checked.' ); parent.prop( 'checked', false ); parent_a.removeClass('checked'); parent_a.removeClass('partial_checkbox'); } } } $(document).on( 'change', 'input[type=checkbox].catalog', function(e){ catalogs_pane(); }); function catalogs_pane() { var num_checked = 0; $('#p-catalogs input[type=checkbox]').each(function(i,e){ if( $(this).is(':checked') ) num_checked++; }); if( 0 == num_checked ) { $('#p-catalogs a.alt-checkbox').addClass( 'ghost' ); } else { $('#p-catalogs a.alt-checkbox').removeClass( 'ghost' ); } }