//###################### // Detect Mobile //###################### var isMobile = (/iPhone|iPod|Android|BlackBerry/).test(navigator.userAgent); var isInIFrame = (window.location != window.parent.location) ? true : false; //###################### // Set Search Criteria After Clicking Back Button //###################### if ($('body').is('.index') || $('body').is('.create')) { currentPage = window.location.hash.substr(1); if (isInIFrame === false && currentPage !== '') { //alert(currentPage); //$('#search_category').change(); // Super slow way to do this - refreshing the page window.location = currentPage; } else { } } //###################### // Create Modal //###################### $.fn.createModal = function() { // if($('#modal').length) { // } else { // $('body').append(''); // } $('#modal').prepend('
Close
'); $('body').append('
'); var maskHeight = $(document).height(); var maskWidth = $(window).width(); $('.modalmask').css({'width':'100%','height':maskHeight}); $('.modalmask').fadeTo(100,0.8); var winH = $(window).height(); var winW = $(window).width(); $('#modal').fadeTo(10, 0, function () { maskWinTop = winH/2-$('#modal').height()/2; if (maskWinTop <= 90) { $('#modal').css('top', 90); } else { $('#modal').css('top', maskWinTop); } $('#modal').css('left', winW/2-$('#modal').width()/2); $('#modal').fadeTo(0, 1); }); $(document).on('touchstart click', '.modalclose', function(e){ e.preventDefault(); $('.modalmask, .modalwindow').fadeOut(250, function() { $('.modalwindow, .modalmask').remove(); }); }); $(document).on('touchstart click', '.modalmask', function(){ $('.modalmask, .modalwindow').fadeOut(250, function() { $('.modalwindow, .modalmask').remove(); }); }); } //###################### // TipTip Tooltips //###################### if ($('.tip').length) { $(function(){ $('.tip').tipTip({activation: 'click', keepAlive: 'false', maxWidth: '260px', delay: 0, defaultPosition: 'top'}); }); } //###################### // Escape Special Characters //###################### String.prototype.escapeSpecialChars = function() { return this.replace(/\\/g, "\\\\") .replace(/\n/g, "\\n") .replace(/\r/g, "\\r") .replace(/\t/g, "\\t") .replace(/\f/g, "\\f") .replace(/"/g, "\\\"") .replace(/'/g, "\\\'") .replace(/\&/g, "\\&"); } //###################### // Responsive //###################### var delay = (function(){ var timer = 0; return function(callback, ms){ clearTimeout (timer); timer = setTimeout(callback, ms); }; })(); $(function() { var pause = 100; $(window).resize(function() { delay(function() { var width = $(window).width(); if( width <= 575 ) { if ($('.site-wrapper').length) { return false; } else { $('body').addClass("mobile-view").wrapInner('
'); $('.mainmenu .primary').clone().appendTo('body'); $('.mainmenu .user').clone().appendTo('body'); $('.mainmenu').append(''); if ($('.mainmenu .admin').length) { $('.mainmenu .admin').clone().appendTo('body'); } if ($('.mainmenu .admin').length) { $('body > .admin nav').removeClass('usermenu'); $('body > .primary, body > .user, body > .admin').wrapAll('
'); } else { $('body > .primary, body > .user').wrapAll('
'); } $('.primary .browseall a').text('Browse All Categories'); } } else if (width >= 576) { if ($('.site-wrapper').length) { $('body').removeClass("mobile-view"); $('.mobilemenu, .menubutton').remove(); $('.site-wrapper').transition({ x: '0' }, 500, 'easeOutSine', function() { menuState = false; }); $('.site-wrapper').contents().unwrap(); $('.primary .browseall a').text('Browse All Weights & Reviews'); } else { return false; } } }, pause ); }); $(window).resize(); }); //###################### // Remove no-js's //###################### if ($('body').is('.no-js')) { $('body').removeClass('no-js'); } //###################### // Reset User Values on Submit Weight //###################### function resetUserValues() { $('.uservalues').css({"left": "-9999px", "position": "fixed"}); $('.uservalues').find('li.formerror').removeClass('formerror'); $('#submitbutton').addClass('disabled').attr('disabled', 'disabled'); $('.phperror').remove(); } //###################### // Custom File Input Function //###################### // Modified from http://www.onextrapixel.com/2012/12/10/how-to-create-a-custom-file-input-with-jquery-css3-and-php/ // Browser supports HTML5 multiple file? var multipleSupport = typeof $('')[0].multiple !== 'undefined', isIE = /msie/i.test( navigator.userAgent ); $.fn.customFile = function() { return this.each(function() { var $file = $(this).addClass('customfile'), // the original file input $wrap = $('
'), $input = $(''), // Button that will be used in non-IE browsers $button = $(''), // Hack for IE $label = $(''); // Hide by shifting to the left so we // can still trigger events $file.css({ position: 'absolute', left: '-9999px' }); $wrap.insertAfter( $file ) .append( $file, $input, ( isIE ? $label : $button ) ); $input.hide(); // Prevent focus $file.attr('tabIndex', -1); $button.attr('tabIndex', -1); $button.click(function () { $file.focus().click(); // Open dialog }); $file.change(function() { var files = [], fileArr, filename; // If multiple is supported then extract // all filenames from the file array if ( multipleSupport ) { fileArr = $file[0].files; for ( var i = 0, len = fileArr.length; i < len; i++ ) { files.push( fileArr[i].name ); } filename = files.join(', '); // If not supported then just take the value // and remove the path to just show the filename } else { filename = $file.val().split('\\').pop(); } $input.show(); $input.val( filename ) // Set the value .attr('title', filename) // Show filename in title tootlip .focus(); // Regain focus }); $input.on({ blur: function() { $file.trigger('blur'); }, keydown: function( e ) { if ( e.which === 13 ) { // Enter if ( !isIE ) { $file.trigger('click'); } } else if ( e.which === 8 || e.which === 46 ) { // Backspace & Del // On some browsers the value is read-only // with this trick we remove the old input and add // a clean clone with all the original events attached $file.replaceWith( $file = $file.clone( true ) ); $file.trigger('change'); $input.val('').hide(); } else if ( e.which === 9 ){ // TAB return; } else { // All other keys return false; } } }); }); }; // Old browser fallback if ( !multipleSupport ) { $( document ).on('change', 'input.customfile', function() { var $this = $(this), // Create a unique ID so we // can attach the label to the input uniqId = 'customfile_'+ (new Date()).getTime(), $wrap = $this.parent(), // Filter empty input $inputs = $wrap.siblings().find('.customfile-filename') .filter(function(){ return !this.value }), $file = $(''); // 1ms timeout so it runs after all other events // that modify the value have triggered setTimeout(function() { // Add a new input if ( $this.val() ) { // Check for empty fields to prevent // creating new inputs when changing files if ( !$inputs.length ) { $wrap.after( $file ); $file.customFile(); } // Remove and reorganize inputs } else { $inputs.parent().remove(); // Move the input so it's always last on the list $wrap.appendTo( $wrap.parent() ); $wrap.find('input').focus(); } }, 1); }); } //###################### // Document Ready //###################### $(document).ready(function() { if ($('.numbersonly').length) { $('.numbersonly').keyup(function () { if (this.value != this.value.replace(/[^0-9\.]/g, '')) { this.value = this.value.replace(/[^0-9\.]/g, ''); } }); //Chosen Plugin $('.findsubmitweight select').chosen({width: "95%"}); } //Custom File Input $('input[type=file]').customFile(); //HTML5 Placeholder $('input, textarea').placeholder(); // Masonry var $container = $('.categorylist'); $container.masonry({ columnWidth: 50, itemSelector: '.category' }); // Submit Weight Form $('.submitweight #submitbutton, #addreview #submit_review').on('click', function(e) { //e.preventDefault(); var hasError = false; // var confirmWeight = false; var confirmRec = false; var confirmPhoto = false; var confirmEmail = false; var emailRegex = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; var confirmEmailRegex = false; // if ($('#submit_property-measured_weight').val() == "") { // $('#submit_property-measured_weight').parent('li').addClass('formerror'); // confirmWeight = true; // hasError = true; // } else { // $('#submit_property-measured_weight').parent('li').removeClass('formerror'); // confirmWeight = false; // } if ($('#submit_property-photo').val() != "") { var ext = $('#submit_property-photo').val().split('.').pop().toLowerCase(); if($.inArray(ext, ['jpg','jpeg']) == -1) { $('#submit_property-photo').closest('li').addClass('formerror'); confirmPhoto = true; hasError = true; } } else { $('#submit_property-photo').closest('li').removeClass('formerror'); confirmPhoto = false; } if ($('#submit_property-recommendation').val() == "") { $('#submit_property-recommendation').parent('li').addClass('formerror'); confirmRec = true; hasError = true; } else { $('#submit_property-recommendation').parent('li').removeClass('formerror'); confirmRec = false; } if ($('#user-email').val() == "") { $('#user-email').parent('li').addClass('formerror'); confirmEmail = true; hasError = true; } else if ($('#user-email').length) { if (!emailRegex.test($('#user-email').val())) { $('#user-email').parent('li').addClass('formerror'); confirmEmailRegex = true; hasError = true; } } else { $('#user-email').parent('li').removeClass('formerror'); confirmEmail = false; } if (hasError == true) { e.preventDefault(); $('.phperror').remove(); // if (confirmWeight == true) { // confirmWeight = '
  • Please enter a measured weight.
  • '; // } else { // confirmWeight = ''; // } if (confirmPhoto == true) { confirmPhoto = '
  • Only .jpg photos are allowed.
  • '; } else { confirmPhoto = ''; } if (confirmRec == true) { confirmRec = '
  • Please choose a recommendation.
  • '; } else { confirmRec = ''; } if (confirmEmail == true) { confirmEmail = '
  • Please enter your email address.
  • '; } else if (confirmEmailRegex == true) { confirmEmail = '
  • Please enter a valid email address.
  • '; } else { confirmEmail = ''; } // $('.uservalues, #addreview').before('
    Please fix the following errors:
      '+confirmWeight+confirmPhoto+confirmRec+confirmEmail+'
    '); $('.uservalues, #addreview').before('
    Please fix the following errors:
      '+confirmPhoto+confirmRec+confirmEmail+'
    '); return false; } else { if($('input#submit_property-photo').val() !== '') { $(this).after('
    Waiting for the photo to upload... This could take some time if you’re uploading a large image.
    ').hide(); } } }); // Mobile Menu var menuState = false; $(document).on('touchstart click', '.mainmenu .menubutton', function(e) { if ($('body').is('.mobile-view')) { if (menuState === false) { e.preventDefault(); $('.site-wrapper').transition({ x: '-80%' }, 500, 'easeOutSine', function() { menuState = true; }); } } }); $(document).on('touchstart click', '.site-wrapper', function(e) { if ($('body').is('.mobile-view')) { if (menuState === true) { e.preventDefault(); $('.site-wrapper').transition({ x: '0' }, 500, 'easeOutSine', function() { menuState = false; }); } } }); // Measurement Photo Modals if (!isMobile) { $('.measurement-photo').on('click', function(e) { e.preventDefault(); var imageURL = $(this).attr('href'); $('body').append(''); $('.modalimage').attr('src', imageURL).load(function() { $(window).createModal(); }); }); } // Search for Weights $(document).on('change', '.findcategory select, .findpart select, .findmanufacturer select, .findmodel select, .findyear select, .submitcategory select, .submitpart select, .submitmanufacturer select, .submitmodel select, .submityear select, .submitproperties select, #create_model_values select', function() { var itemSelected = $(this).attr('id'); // console.log(itemSelected); if (itemSelected === 'search_category') { $('#search_year').attr('disabled', 'disabled').trigger('chosen:updated').trigger('chosen:resize'); } if (itemSelected === 'submit_category') { $('#submit_year').attr('disabled', 'disabled').trigger('chosen:updated').trigger('chosen:resize'); } if (itemSelected === 'add_category') { $('#add_year').attr('disabled', 'disabled'); } $(this).parent('li').nextAll('li').find('select option:first-child').attr('selected', 'selected'); if ($(this).parents('form').is('#findweight')) { var formData = $('#findweight').find('input[name=sel_context], input[name=selection], select').serialize(); var context = 'search'; } else if ($(this).parents('form').is('#submitweight')) { var formData = $('#submitweight').find('input[name=sel_context], input[name=selection], select').serialize(); var context = 'submit'; } else if ($(this).parents('form').is('#create_model_values')) { var formData = $('#create_model_values').serialize(); var context = 'add'; } // console.log(formData); //if (context === 'search') { window.location.href= '#?'+formData; $('input[name="query_string"]').attr('value', formData); //} $.ajax({ type: 'GET', url: 'handle-search_categories.php', data: formData, dataType: 'json' }).success(function(result) { // console.log('success'); if (itemSelected === context + '_category') { //console.log(context + '_category'); // console.log(result); // Behavior for default selections $('.submitproperties li, .addproperties li').remove(); selectedval = $('#' + context + '_category').find(':selected[value]').val(); if (selectedval === '' || selectedval === 'Not Listed') { $('#' + context + '_part').attr('disabled', 'disabled').trigger('chosen:updated').trigger('chosen:resize'); $('#' + context + '_manufacturer').attr('disabled', 'disabled').trigger('chosen:updated').trigger('chosen:resize'); $('#' + context + '_model').attr('disabled', 'disabled').trigger('chosen:updated').trigger('chosen:resize'); $('#' + context + '_year').attr('disabled', 'disabled').trigger('chosen:updated').trigger('chosen:resize'); if (selectedval === 'Not Listed') { $('.uservalues').css({"left": "auto", "position": "static"}); $('.uservalues .notice').show(); $('#submitbutton').removeClass('disabled').removeAttr('disabled'); } else { resetUserValues(); } } else { $('#' + context + '_part').removeAttr('disabled').html(result).trigger('chosen:updated').trigger('chosen:resize'); // $('#search_part').parent('div').removeClass('disabled'); $('#' + context + '_manufacturer').attr('disabled', 'disabled').children('option:first-child').attr('selected', 'selected').trigger('chosen:updated').trigger('chosen:resize'); $('#' + context + '_model').attr('disabled', 'disabled').children('option:first-child').attr('selected', 'selected').trigger('chosen:updated').trigger('chosen:resize'); resetUserValues(); } } else if (itemSelected === context + '_part') { // console.log(context + '_part'); // console.log(result.result1); // Behavior for default selections selectedval = $('#' + context + '_part').find(':selected[value]').val(); $('.submitproperties li, .addproperties li').remove(); if (selectedval === '' || selectedval === 'Not Listed') { $('#' + context + '_manufacturer').attr('disabled', 'disabled').trigger('chosen:updated').trigger('chosen:resize'); $('#' + context + '_year').attr('disabled', 'disabled').trigger('chosen:updated').trigger('chosen:resize'); if (selectedval === 'Not Listed') { $('.uservalues').css({"left": "auto", "position": "static"}); $('.uservalues .notice').show(); $('#submitbutton').removeClass('disabled').removeAttr('disabled'); } else { resetUserValues(); } } else { $('#' + context + '_manufacturer').removeAttr('disabled').html(result.result1).trigger('chosen:updated').trigger('chosen:resize'); if (context === 'search') { $('#' + context + '_year').removeAttr('disabled').html(result.result2).trigger('chosen:updated').trigger('chosen:resize'); } else if (context === 'submit') { $('#' + context + '_year').attr('disabled', 'disabled').trigger('chosen:updated').trigger('chosen:resize'); } else if (context === 'add') { $('#' + context + '_year').attr('disabled', 'disabled').trigger('chosen:updated').trigger('chosen:resize'); } resetUserValues(); } // $('#search_manufacturer').parent('div').removeClass('disabled'); $('#' + context + '_model').attr('disabled', 'disabled').children('option:first-child').attr('selected', 'selected').trigger('chosen:updated').trigger('chosen:resize'); //console.log('availableyears'); // console.log(result.result2); // $('#search_year').parent('div').removeClass('disabled'); } else if (itemSelected === context + '_manufacturer') { // console.log('search_manufacturer'); // console.log(result.result1); // Behavior for default selections $('.submitproperties li, .addproperties li').remove(); selectedval = $('#' + context + '_manufacturer').find(':selected[value]').val(); if (selectedval === '' || selectedval === 'Not Listed') { $('#' + context + '_model').attr('disabled', 'disabled').trigger('chosen:updated').trigger('chosen:resize'); if (context === 'search') { $('#' + context + '_year').removeAttr('disabled').html(result.result2).trigger('chosen:updated').trigger('chosen:resize'); } else if (context === 'submit') { $('#' + context + '_year').attr('disabled', 'disabled').trigger('chosen:updated').trigger('chosen:resize'); if (selectedval === 'Not Listed') { $('.uservalues').css({"left": "auto", "position": "static"}); $('.uservalues .notice').show(); $('#submitbutton').removeClass('disabled').removeAttr('disabled'); } else { resetUserValues(); } } else if (context === 'add') { $('#' + context + '_year').attr('disabled', 'disabled').trigger('chosen:updated').trigger('chosen:resize'); if (selectedval === 'Not Listed') { $('.uservalues').css({"left": "auto", "position": "static"}); $('.uservalues .notice').show(); $('#submitbutton').removeClass('disabled').removeAttr('disabled'); } else { resetUserValues(); } } } else { $('#' + context + '_model').removeAttr('disabled').html(result.result1).trigger('chosen:updated').trigger('chosen:resize'); if (context === 'search') { $('#' + context + '_year').removeAttr('disabled').html(result.result2).trigger('chosen:updated').trigger('chosen:resize'); } else if (context === 'submit') { $('#' + context + '_year').attr('disabled', 'disabled').trigger('chosen:updated').trigger('chosen:resize'); } else if (context === 'add') { $('#' + context + '_year').attr('disabled', 'disabled').trigger('chosen:updated').trigger('chosen:resize'); } resetUserValues(); } //$('#' + context + '_model').removeAttr('disabled').html(result.result1); // $('#search_model').parent('div').removeClass('disabled'); // console.log('availableyears'); // console.log(result.result2); // $('#search_year').parent('div').removeClass('disabled'); } else if (itemSelected === context + '_model') { // console.log('search_model'); // console.log(result); // Behavior for default selections $('.submitproperties li, .addproperties li').remove(); selectedval = $('#' + context + '_model').find(':selected[value]').val(); if (selectedval === '' || selectedval === 'Not Listed') { $('#' + context + '_year').removeAttr('disabled').html(result.result2).trigger('chosen:updated').trigger('chosen:resize'); if (context === 'submit') { $('#' + context + '_year').attr('disabled', 'disabled').trigger('chosen:updated').trigger('chosen:resize'); if (selectedval === 'Not Listed') { $('.uservalues').css({"left": "auto", "position": "static"}); $('.uservalues .notice').show(); $('#submitbutton').removeClass('disabled').removeAttr('disabled'); } else { resetUserValues(); } } else if (context === 'add') { $('#' + context + '_year').attr('disabled', 'disabled').trigger('chosen:updated').trigger('chosen:resize'); if (selectedval === 'Not Listed') { $('.uservalues').css({"left": "auto", "position": "static"}); $('.uservalues .notice').show(); $('#submitbutton').removeClass('disabled').removeAttr('disabled'); } else { resetUserValues(); } } } else if (itemSelected === 'add_model') { $('.submitproperties, .addproperties').html(result); $('.submitproperties select').chosen().trigger('chosen:updated').trigger('chosen:resize'); resetUserValues(); } else { $('#' + context + '_year').removeAttr('disabled').html(result).trigger('chosen:updated').trigger('chosen:resize'); resetUserValues(); } // $('#search_year').parent('div').removeClass('disabled'); } else if (itemSelected === 'submit_year') { selectedval = $('#' + context + '_year').find(':selected[value]').val(); if (selectedval === '') { $('.submitproperties li, .addproperties li').remove(); $('input[name="sel_model_post"]').attr('value',''); $('input[name="data_not_listed"]').attr('value', ''); resetUserValues(); } else if (selectedval === 'Not Listed') { $('.submitproperties, .addproperties').html(result.result1); $('.submitproperties select').chosen().trigger('chosen:updated').trigger('chosen:resize'); $('input[name="sel_model_post"]').attr('value', result.result2); $('.uservalues .notice').show(); $('input[name="data_not_listed"]').attr('value', 'true'); if (result.result3 == 'showuservalues') { $('.uservalues').css({"left": "auto", "position": "static"}); $('#submitbutton').removeClass('disabled').removeAttr('disabled'); } else { resetUserValues(); } } else if (result.result4 == 'noproperties') { $('.submitproperties, .addproperties').html(result.result1); $('.submitproperties select').chosen().trigger('chosen:updated').trigger('chosen:resize'); $('input[name="sel_model_post"]').attr('value', result.result2); if (result.result3 == 'showuservalues') { $('.uservalues').css({"left": "auto", "position": "static"}); $('#submitbutton').removeClass('disabled').removeAttr('disabled'); } else { resetUserValues(); } } else { $('.submitproperties, .addproperties').html(result.result1); $('.submitproperties select').chosen().trigger('chosen:updated').trigger('chosen:resize'); resetUserValues(); } } else if (itemSelected.indexOf('submit_property') != -1) { selectedval = $('#' + itemSelected).find(':selected[value]').val(); if (selectedval === '') { $('#' + itemSelected).parent('li').nextAll('li').children('select').attr('disabled', 'disabled').trigger('chosen:updated').trigger('chosen:resize'); resetUserValues(); $('input[name="sel_model_post"]').attr('value',''); $('input[name="data_not_listed"]').attr('value', ''); } else { $('.submitproperties li, .addproperties li').remove(); //$('.uservalues').hide(); $('.submitproperties, .addproperties').html(result.result1); $('.submitproperties select').chosen().trigger('chosen:updated').trigger('chosen:resize'); $('input[name="sel_model_post"]').attr('value', result.result2); //$('.uservalues').html(result.result3); if (result.result3 == 'showuservalues') { $('.uservalues').css({"left": "auto", "position": "static"}); $('#submitbutton').removeClass('disabled').removeAttr('disabled'); } else { resetUserValues(); } if (result.result5 == 'shownotice') { $('.uservalues .notice').show(); $('input[name="data_not_listed"]').attr('value', 'true'); } else { $('.uservalues .notice').hide(); } } } }).fail(function() { $('.jsmessage').html('Oops! Looks like we ran into a problem.'); }); return false; }); // Create Single Item Form $(document).on('submit', '.single', function() { var tableName = $(this).find('.thetable').attr('value'); var fieldName = $(this).find('.thedata').attr('name'); var fieldValue = $(this).find('.thedata').val(); if($(this).find('.thedata').val() === '') { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    Please enter a ' + fieldName + ' value for the ' + tableName + ' table.

    '); return false; } $.ajax({ type: 'POST', url: 'handle-create_single.php', data: '&table=' + tableName + '&field=' + fieldName + '&' + fieldName + '='+ fieldValue, dataType: 'text' }).success(function() { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    ' + fieldValue + ' was successfully created.

    '); }).fail(function() { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    Oops! Looks like we ran into a problem.

    '); }); return false; }); // Create Part Form $('#create_part').submit(function() { if($('#part_name').val() === '') { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    Please enter a part name.

    '); return false; } else if($('#part_category').val() === '') { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    Please choose a category.

    '); return false; } else { var formData = $(this).serialize(); } $.ajax({ type: 'POST', url: 'handle-create_part.php', data: formData, dataType: 'text' }).success(function() { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    The part ' + $('#part_name').val() + ' was successfully created.

    '); }).fail(function() { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    Oops! Looks like we ran into a problem.

    '); }); return false; }); // Create Model Form $('#create_model').submit(function() { if($('#model_name').val() === '') { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    Please enter a model name.

    '); return false; } else if($('#model_manufacturer').val() === '') { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    Please choose a manufacturer.

    '); return false; } else if($('#model_part').val() === '') { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    Please choose a part.

    '); return false; } else { var formData = $(this).serialize(); } $.ajax({ type: 'POST', url: 'handle-create_model.php', data: formData, dataType: 'text' }).success(function() { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    The model ' + $('#model_name').val() + ' was successfully created.

    '); }).fail(function() { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    Oops! Looks like we ran into a problem.

    '); }); return false; }); // Create Part Properties Dropdown $(document).on('change', '#pp_lu_part', function() { //var itemSelected = $(this).val(); //alert(itemSelected); var formData = $('#create_part_properties').serialize(); // if (itemSelected === 'search_category') { // $('#search_year').attr('disabled', 'disabled'); // } //console.log(formData); $.ajax({ type: 'POST', url: 'handle-create_part_properties.php', data: formData, dataType: 'json' }).success(function(result) { //console.log(result); $('.propertylist').html(result); }).fail(function() { // console.log('Oops! Looks like we ran into a problem.'); $('.jsmessage').html('Oops! Looks like we ran into a problem.'); }); }); // Create Part Properties Checkboxes $('#create_part_properties').submit(function() { if($('#pp_lu_part').val() === '') { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    Please choose a part.

    '); return false; } else if($('input:checkbox:checked').length = 0) { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    Please choose one or more properties.

    '); return false; } else { var formData = $(this).serialize() + '&submit=Create Part Properties'; // console.log(formData); } $.ajax({ type: 'POST', url: 'handle-create_part_properties.php', data: formData, dataType: 'text' }).success(function() { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    The properties for ' + $('#pp_lu_part option:selected').text() + ' were successfully created.

    '); }).fail(function() { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    Oops! Looks like we ran into a problem.

    '); }); return false; }); // Create Model Values $('#create_model_values').submit(function() { if(($('#add_category').val() === '') || ($('#add_part').val() === '') || ($('#add_manufacturer').val() === '') || ($('#add_model').val() === '')) { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    Please select from all the drop downs.

    '); return false; } else { var formData = $(this).serialize(); } $.ajax({ type: 'POST', url: 'handle-create_value.php', data: formData, dataType: 'text' }).success(function() { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    The values for ' + $('#add_model option:selected').text() + ' were successfully created.

    '); }).fail(function() { $('.jsmessage').remove(); $('#adminarea .content').prepend('

    Oops! Looks like we ran into a problem.

    '); }); return false; }); // Individual Model Posts Show/Hide $('.results .filter, .results .flag, .results .addpost').on('click', function (e) { e.stopPropagation(); }); // $(document).on('click', '.model .flagform',function (event) { // event.stopPropagation(); // }); $('.results .post').hide(); $('.results .model.hasposts').on('click', function () { if ($('.results .model.hasposts').is('.active')) { } else { if ($(this).is('.expanded')) { //$(this).find('.expand').html('+'); $(this).removeClass('expanded'); } else { //$('.results .model.hasposts').removeClass('expanded'); $(this).addClass('expanded'); //$(this).find('.expand').html('–'); } var tr = $(this).nextAll('tr'); for (i = 0; i < tr.length; i++) { var classname = $(tr[i]).attr('class'); if (classname == 'post') { $(tr[i]).toggle(200); } else if (classname == 'model hasposts' || classname == 'model hasposts expanded') { return; } } } }); // Put in the background image after JS. if ($('body').is('.index')) { $.get('photo_bgs.xml', function(data) { var photoSrc = []; var photoAuth = []; var photoLink = []; var photoW = []; var photoH = []; var photo_count = 0; $(data).find('photo').each(function(){ var $photo = $(this); photoSrc.push($photo.find('src').text()); photoAuth.push($photo.find('author').text()); photoLink.push($photo.find('link').text()); photoW.push($photo.find('width').text()); photoH.push($photo.find('height').text()); photo_count++; }); var imageSet = Math.floor(Math.random()*photo_count); //var imageSet = 10; if (!isMobile) { $('body .bggradient').before('
    Photo by '+photoAuth[imageSet]+'').after('
    '); $('.bg').css('display', 'none').fadeIn(1000, 'easeOutSine'); } }); } // Post Votes $('.postvote').on('click', '.voteup, .votedown', function(e) { e.preventDefault(); var $this = $(this); var $parent = $(this).parent().parent('div'); $this.parent().children('.voteup, .votedown').removeClass('voted'); var vote = $(this).attr('href').split('?'); $.ajax({ type: 'GET', url: vote[0] + '/handle-user_vote.php', data: vote[1] + '&ajax=true', dataType: 'json' }).success(function(result) { if (result.response == 'notsignedin') { $('You must be signed in to vote on posts.').hide().appendTo($parent).show().delay(3000).fadeOut(1000); } else if (result.response == 'errorwritignnewvote') { $('There was an error saving your vote.').hide().appendTo($parent).show().delay(3000).fadeOut(1000); } else if (result.response == 'errorupdatingvote') { $('There was an error updating your vote.').hide().appendTo($parent).show().delay(3000).fadeOut(1000); } else if (result.response == 'success' || result.response == 'duplicatevote') { $this.addClass('voted'); $('Vote Saved').hide().appendTo($parent).show().delay(1500).fadeOut(1000); } }).fail(function() { $('.jsmessage').remove(); $('#contentwrapper').prepend('

    Oops! Looks like we ran into a problem.

    '); }); }); // Model Flags $('.results .flag').on('click', function() { if ($(this).is('.active')) { return false; } var $this = $(this); var $parent = $(this).parent('div'); flagurl = $(this).find('a').attr('href').split('?'); flagaddress = flagurl[0].split('/flag.php'); $.ajax({ type: 'GET', url: flagaddress[0] + '/handle-user_flag.php', data: flagurl[1] + '&checkexisting=true', dataType: 'json' }).success(function(result) { $this.addClass('active'); $this.parents('.model, .post').addClass('active'); if (result.response == 'existingflag') { if ($this.parents('.model').length) { var flagids = flagurl[1].split('&'); var flagmodel = flagids[0].split('model='); $('

    Please be as descriptive as possible.

    Cancel
    ').hide().appendTo($parent).show(); } else if ($this.parents('.post').length) { var flagids = flagurl[1].split('&'); var flagmodel = flagids[0].split('model='); var flagpost = flagids[1].split('post='); $('

    Please be as descriptive as possible.

    Cancel
    ').hide().appendTo($parent).show(); } } else if (result.response == 'noexistingflag') { if ($this.parents('.model').length) { var flagids = flagurl[1].split('&'); var flagmodel = flagids[0].split('model='); $('

    Please be as descriptive as possible.

    Cancel
    ').hide().appendTo($parent).show(); } else if ($this.parents('.post').length) { var flagids = flagurl[1].split('&'); var flagmodel = flagids[0].split('model='); var flagpost = flagids[1].split('post='); $('

    Please be as descriptive as possible.

    Cancel
    ').hide().appendTo($parent).show(); } } else if (result.response == 'notsignedin') { $this.removeClass('active'); $this.parents('.model, .post').removeClass('active'); if ($this.parents('.model').length) { $('You must be signed in to flag models.').hide().appendTo($parent).show().delay(3000).fadeOut(1000); } else if ($this.parents('.post').length) { $('You must be signed in to flag posts.').hide().appendTo($parent).show().delay(3000).fadeOut(1000); } } // Hide Flag Form if User Clicks Elsewhere var mouse_in; $(document).on('mouseenter', '.flagform, .flag.active', function(){ mouse_in=true; //console.log(mouse_in) }); $(document).on('mouseleave', '.flagform, .flag.active', function(){ mouse_in=false; //console.log(mouse_in) }); $(document).on('mouseup', function(){ if(mouse_in == false) { $('.flagform, .flag.active').off('mouseenter, mouseleave'); $this.removeClass('active'); $this.parents('.model, .post').removeClass('active'); $('.flagform').remove(); mouse_in = null; } }); $(document).on('click', '.flagform .cancel', function(e) { e.preventDefault(); $('.flagform, .flag.active').off('mouseenter, mouseleave'); $this.removeClass('active'); $this.parents('.model, .post').removeClass('active'); $('.flagform').remove(); mouse_in = null; }); }).fail(function() { $('.jsmessage').remove(); $('#contentwrapper').prepend('

    Oops! Looks like we ran into a problem.

    '); }); }); $('.results .flag').on('click', 'a', function(e) { e.preventDefault(); }); $(document).on('click', '.flagform #submitflag', function(e) { e.preventDefault(); var $this = $(this); var $parent = $(this).parent().parent().parent('div'); var formData = $this.parents('.flagform form').serialize(); $.ajax({ type: 'POST', url: flagaddress[0] + '/handle-user_flag.php', data: formData + '&ajax=true', dataType: 'json' }).success(function(result) { if (result.response == 'notsignedin') { $('You must be signed in to flag models.').hide().appendTo($parent).show().delay(3000).fadeOut(1000); } else if (result.response == 'errorwritignnewflag') { $('There was an error saving your flag.').hide().appendTo($parent).show().delay(3000).fadeOut(1000); } else if (result.response == 'errorupdatingflag') { $('There was an error updating your flag.').hide().appendTo($parent).show().delay(3000).fadeOut(1000); } else if (result.response == 'emptytext') { $('You must enter a reason for flagging this.').hide().appendTo($parent).show().delay(3000).fadeOut(1000); } else if (result.response == 'success' || result.response == 'duplicateflag') { $this.parents('.model, .post').find('.flag').addClass('flagged'); $('Flag Saved').hide().appendTo($parent).show().delay(1500).fadeOut(1000); } $this.parents('.model, .post').find('.flag').removeClass('active'); $this.parents('.model, .post').removeClass('active'); $this.parents('.flagform').remove(); }).fail(function() { $('.jsmessage').remove(); $('#contentwrapper').prepend('

    Oops! Looks like we ran into a problem.

    '); }); }); $('.results .addpost').on('click', function(e) { //e.preventDefault(); //alert('This isn’t working yet, ignore it.') }); $('#adminarea .delete-user').on('click', function(e) { var answer = confirm("Are you sure?") if (!answer) { e.preventDefault(); } }); });