// testing autofill /* $(document).bind("pagecreate", function()... called many times, so only use appropriately $(document).bind("mobileinit", function()... didn't work as needed $(document).bind('pageinit', function()... called once PER LOGIN. */ // bind autofill handlers $(document).bind('pageinit', function() { /* ajax autocomplete experimentation. "on" is preferred to "delegate", now. bind is old as well (see above use and convert). binding to pagecreate seems to be the place to do things like this. .on works for later/dynamically created elements. they don't have to pre-exist. */ /* make sure we only bind the following handlers once */ if (Fse.mobileInitialized) { return true; } else { Fse.mobileInitialized = true; } /* this is the layout/hierarchy of the typical autofill input field. reference this for understanding selector references below
*/ /* new search testing (keyup)*/ // AUTO SEARCH INPUT CLEAR BUTTON // '.fse-autofill-input + .ui-input-clear' was not reliable. when required class in place, an element is inserted between the two. // this makes it broader handler than i wanted, but in the case of search fields that are not auto fill, this stuff fires, but does nothing. //$(document).on('click', '.fse-autofill-input + .ui-input-clear', function () { $(document).on('click', '.ui-input-clear', function () { var fldName = $(this).parent().find('.fse-autofill-input').attr("fse:fieldname"); var _callBack = $(this).parent().find('.fse-autofill-input').attr("fse:callbackClear"); $(this).parent().parent().find('.fse-autofill-target').html( "" ); $("#"+fldName).val(""); if ( _callBack && _callBack != '') { eval(_callBack); } $(this).parent().find('.fse-autofill-input').focus(); /* didn't work unless after call back */ }); // AUTO SEARCH ITEM SELECT $(document).on('click', '.fse-autofill-target li', function (e, data) { if (!$(this).hasClass("fse-afstatus")) { var _display = $(this).text(); var _value = $(this).attr("fse:val"); var _fieldName = $(this).parent().parent().find('.fse-autofill-input').attr("fse:fieldname"); var _onSelectShow = $(this).parent().parent().find('.fse-autofill-input').attr("fse:onSelectShow"); var _callBack = $(this).parent().parent().find('.fse-autofill-input').attr("fse:callbackSelect"); if (!_onSelectShow) { _onSelectShow = "display"; } if (_onSelectShow == "value") { //console.log("Setting input value to: "+_value); $(this).parent().parent().find('.fse-autofill-input').val(_value); } else if ( _onSelectShow == "nothing" ) { $(this).parent().parent().find('.fse-autofill-input').val(""); } else { //console.log("Setting input value to: "+_display); $(this).parent().parent().find('.fse-autofill-input').val(_display); } if (_fieldName) { $(this).parent().parent().find('#'+_fieldName).val(_value); } $(this).parent().html(""); if ( _callBack && _callBack != '') { eval(_callBack); } } }); // AUTO SEARCH INPUT FIELD /* using "input" as event because: - triggers on keystrokes nicely - triggers on suggested spell correction from phone, keyup did not (important) - does NOT trigger on programatic change of input value (important) - Problem: input is funky with android. selecting item first time sets it, clears ul, then repopulates it. using "keyup change" together is supposed to cover the bases of key input and other imput (paste etc). - in firefox, if has same effect (negative) as android above. Good in that I can recreate/emulate android issue in firefox. maybe it can be worked around. Solution for now: "input" works well for iOS, but quirky for android. We will detect platform and use "input" for iOS and "keyup" for android. "keyup" will not respond to paste or phone spell correct suggestions, but better than other quirky side effect of "input" on android. */ if ( navigator.userAgent.toLowerCase().search("android") > 0 ) { var _afEvents = "keyup"; } else { var _afEvents = "input"; } $(document).on( _afEvents, '.fse-autofill-input', Fse.autoSearchKeystrokeHandler ); /* other misc handlers, unrelated to auto search (todo: move to another appropriate location) */ /* go top button. careful programming to this event. excessive code will slow down scrolling. */ $(window).scroll(function(){ if ( $(window).scrollTop() > $(window).height() + 50 ) { $(".scroll-top-btn").show(); } else { $(".scroll-top-btn").hide(); } }); /* first letter search (fls), used in contacts - DISABLED, NOT USED */ /* $(document).on('click', '.fls-on', function (e, data) { if (document.frmsrchcont.startsWith) { document.frmsrchcont.startsWith.value = $(this).text(); } Fse.submitContactSearch('1'); }); */ /* generic swipe handler */ /* z_jsMaster\lib\mobile\fseMobile.js contains setting for horizontal swipe threshold!!! */ $(document).on('swiperight swipeleft', '.fse-swipe', function (e, data) { var sSwipeFunc = $(this).attr("fse:"+e.type); if (sSwipeFunc && sSwipeFunc != '') { eval(sSwipeFunc); } /* let the first element respond to the event, and then cut it off for others. for example, we swipe right on photo to see next, but don't want the page to respond and go back to previous page was well. */ e.stopPropagation() }); /* drop down logos filtering */ $(document).on('keyup', '.ddlogos-filter', function (e, data) { var containerId = $(this).attr('fse:containerid'); var $logos = $('.'+containerId+'-logos-filter'); var re = new RegExp(this.value, "i"); // "i" means it's case-insensitive if (this.value == '') { $('#'+containerId+'-filter-clear').hide(); } else { $('#'+containerId+'-filter-clear').show(); } $logos.show().filter(function() { return !re.test($(this).attr("fse:mfr")); }).hide(); }); /* 1FS home page mfr search */ var $logos = $('.mfr-icon-filter'); $('.1FS-logo-filter').keyup(function() { $('#suggest-mfr').hide(); $('.1FS-logo-filter-clr').show(); var re = new RegExp($(this).val(), "i"); // "i" means it's case-insensitive $logos.show().filter(function() { return !re.test($(this).attr("mfrname")); }).hide(); }); /* 1FS home page mfr search - input search clear button */ $(document).on('click', '.1FS-logo-filter + .ui-input-clear', function () { $('.mfr-icon-filter').fadeIn(); $('.1FS-logo-filter-clr').fadeOut(); }); /* handler to allow deselect of radio btn in radio-toolbar-float displays */ $(document).on('click', '.allowradiodeselect input', function (e, data) { if (this.getAttribute('fse:checked')=='Y') { this.checked=false; this.setAttribute('fse:checked','N'); var _id = this.getAttribute('id'); $("input[id='" + _id + "']").change(); // trigger onchange when setting back to unchecked } else { var _nam = this.getAttribute('name'); $("input[name='" + _nam + "']").attr('fse:checked','N'); // set all to N this.setAttribute('fse:checked','Y') // set current one to Y } }); /* expander */ $(document).on('click', '.fse-expander', function (e, data) { var _contentClass = $( this ).attr('fse:contentclass'); var _expanded = $('.'+_contentClass).first().is(":visible"); $('.' + _contentClass).slideToggle(); if ( !_expanded ) { Fse.scrollTo( $( this ).offset().top-50, 500 ); }; }); }); Fse.clrAutoSrchById = function(asId) { /* id of the div wrapper */ var _fld = $("#"+asId).find(".fse-autofill-input").attr("fse:fieldname"); if (_fld) { $("#"+_fld).val(""); } $("#"+asId).find(".fse-autofill-input").val(""); $("#"+asId).find(".fse-autofill-target").html(""); } Fse.clrAutoSrchResults = function(e) { $(e).parent().parent().html(""); } Fse.autoSearchKeystrokeHandler = function (e, data) { var $ul = $(this).parent().parent().find('.fse-autofill-target'), qrytype = $(this).attr("fse:qrytype"), addparams = $(this).attr("fse:addparams"), allowfreeform = $(this).attr("fse:allowfreeform"), fldname = $(this).attr("fse:fieldname"), value = this.value, words = value.split(" "), delay = $(this).attr("fse:delay"), minchars = $(this).attr("fse:minchars"), html = ""; if (addparams == undefined) { addparams = ""; } else { addparams = "?" + addparams; } if (allowfreeform == undefined) { allowfreeform = false; } if (delay == undefined) { delay = 400; } if (minchars == undefined) { minchars = 3; } try { if (pendingSearch) { clearTimeout(pendingSearch); } } catch(err) { } pendingSearch = setTimeout(function () { if ( !value || value.length < minchars ) { $ul.html( "" ); } else { /* if server doesn't respond within 1 second, show "searching" message */ var searchDispTimer = setTimeout(function(){ $ul.html( '
  • searching...
  • ' ); }, 1000); $.ajax({ url: "index.cfm" + addparams, dataType: "jsonp", crossDomain: false, data: { app: 'fnd', view: 'autofill-'+qrytype, q: value } }) .then( function ( response,status,request ) { clearTimeout(searchDispTimer); if (allowfreeform) { var _clrLink = 'dismiss'; } else { var _clrLink = ''; } /* fyi class="fse-afstatus" used to style status and also prevent it from being selected */ if ( request.getResponseHeader("FSEunauthorized") == 'true') { alert('Session timed out.'); Fse.handleUnauthorized(); } else if ( request.getResponseHeader('x-fse-items') == "0" ) { if (allowfreeform) { html = ''; } else { html = '
  • no matches' + _clrLink + '
  • '; $("#"+fldname).val(""); } } else if ( request.getResponseHeader('x-fse-items') == request.getResponseHeader('x-fse-maxitems') ) { html = '
  • Results Limited to ' + request.getResponseHeader('x-fse-maxitems') + _clrLink + '
  • '; } else if ( request.getResponseHeader('x-fse-items') >= 5 ) { html = '
  • ' + request.getResponseHeader('x-fse-items') + ' matches' + _clrLink + '
  • '; } else { if (_clrLink != '') { html = '
  •  ' + _clrLink + '
  • '; } } $.each( response.items, function ( i, element ) { if (element.v == '') { html += '
  • ' + element.d + '
  • '; } else { // highlight keywords. don't do for dividers above as it may break embeded html, if any for (i = 0; i < words.length; i++) { element.d = element.d.replace(eval('/'+words[i]+'/gi'), function($1){ return String.fromCharCode(14) + $1 + String.fromCharCode(15) }); } html += '
  • ' + element.d + '
  • '; } }); html = html.replace( eval('/'+String.fromCharCode(14)+'/g'), '' ); html = html.replace( eval('/'+String.fromCharCode(15)+'/g'), '' ); $ul.html( html ); }); } /* 8/12/15 original setting 400, trying slower setting (longer delay) to reduce trips to server on keystroke entry. hitting server every keystroke would be fine if searches were responsive enough. the general search is covering more data, so it is not as responsive and the slightly longer delay helps. 8/26 now this is an optional parameter, with 400 default */ }, delay); }