admin-import-export.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. jQuery( document ).ready( function( $ ) {
  2. var clickedElement;
  3. $(document).off( 'mousedown' ).on( 'mousedown', function( e ) {
  4. clickedElement = e.target;
  5. });
  6. $( '#nf_export_form_2' ).off( 'focus' ).on( 'focus', function () {
  7. //show the dropdown on focus of the input
  8. $( '.nf-form-dropdown' ).show();
  9. });
  10. $( '#nf_export_form_2' ).off( 'keyup' ).on( 'keyup', function () {
  11. //show the dropdown if it isn't show
  12. $( '.nf-form-dropdown' ).show();
  13. // get the value of the input, which we filter on
  14. var filter = $( this ).val();
  15. if( '' === filter ) {
  16. //if the filter val is empty, show all form options
  17. $( '.nf-form-dropdown' ).find( 'li' ).show();
  18. } else {
  19. $.each( $( '#nf_form_export_options span' ), function ( index, span ) {
  20. var tmpSpan = $( span );
  21. // test to see if span text contains the entered value
  22. if ( 0 <= tmpSpan.text().toLowerCase().indexOf( filter.toLowerCase() ) ) {
  23. // shows options that DO contain the text entered
  24. tmpSpan.parent().show();
  25. } else {
  26. // hides options the do not contain the text entered
  27. tmpSpan.parent().hide();
  28. }
  29. });
  30. }
  31. });
  32. $( '#nf_export_form_2' ).off( 'blur' ).on( 'blur' , function( e ) {
  33. if( 'undefined' !== typeof clickedElement ) {
  34. if ( ! $( clickedElement ).hasClass( 'nf-form-option-item' ) ) {
  35. $( '#nf_export_form_2' ).val( '' );
  36. $( '.nf-form-dropdown' ).hide();
  37. }
  38. }
  39. });
  40. $( '.nf-form-option' ).off( 'click' ).on( 'click', function() {
  41. // on click get the value of the input
  42. var val = $( this ).data( 'val' );
  43. // nf_export_form is now a hidden field instead of select element
  44. $( '#nf_export_form' ).val( val );
  45. // set the text of the input field
  46. $( '#nf_export_form_2' ).val( '' );
  47. // and hide the option.
  48. $( '.nf-form-dropdown' ).hide();
  49. });
  50. });