/** * @globals CZRHSParams * Inspired by the GPLv3 work of Pippin Williamson and Zack Katz with the GF plugin * Adapted by Nicolas Guillaume * License: GPLv3 */ var CZRHSParams = CZRHSParams || {}; var HS_Search; jQuery( function($) { HS_Search = $.extend( CZRHSParams, { searching: false, /** Prevent new results from being shown by setting to true */ cancelled: false, has_searched: false, count: 0, query: '', /** Hold the ms since the user stopped typing */ timeout: null, /** Search field container */ wrap: $( '.frm_form_fields .helpscout-docs' ), form: $( '.frm_form_fields .helpscout-docs' ).closest( '.frm-show-form' ), field: $( '.frm_form_fields .helpscout-docs' ).find( 'input[type="text"]' ), onclick : '', keypress : '', results: {}, performed_search : 0, performed_search_list : [], visited_doc_articles : [], //when resolved => HS_Search.form.find('.go-next-step').show(); has_searched_enough : ( function() { return $.Deferred( function() { var dfd = this, _resolveAfterDelay = function() { _.delay( function() { //if at least one search has been performed, resolve. If not, fire again if ( HS_Search.performed_search > 0 ) { dfd.resolve(); } else { _resolveAfterDelay(); } }, 20000 ); }; _resolveAfterDelay(); return dfd.promise(); }); })(), init: function () { HS_Search.form.find('.go-next-step').hide(); HS_Search.has_searched_enough.done( function() { HS_Search.form.find('.go-next-step').show(); }); HS_Search.form .on( 'keypress', function(e) { var code = e.which || e.keyCode; if( ! HS_Search.field.is(':focus') ) { return; } if( code == 13 && ! $( e.target ).is( 'textarea,input[type="submit"],input[type="button"]' ) ) { e.preventDefault(); return false; } }); HS_Search.wrap .append( '