hostname = 'https://www.doctor.com';
window.ddcWidget = {
"log_enabled": true,
"data": {
"page": 1,
"pageProfile": 1,
"showNext": false,
"showPrev": false,
"showNextProfile": false,
"showPrevProfile": false,
"total": 0,
"pagingInProgress": false,
"providers": [],
"providersAuxNav": [],
"zipcode": '',
"paramzipcode": '',
"markers": [],
"baseUrl": '',
"querystring": '',
"map": null,
"bounds": [],
"partner_site_id": '',
"size": '6',
"location": {},
"pat_svy": '',
"params": {},
"geopoint": '',
"providerSelected": {},
"binded": false,
"trackingParams": undefined
},
"createAndAddScript": function (src, action, onload) {
if (src) {
var s = document.createElement('script');
s.type = 'text/javascript';
s.src = src;
if (onload) {
s.onload = onload;
}
var c = document.getElementsByTagName('script')[0];
c.parentNode.insertBefore(s, c);
}
if (action) {
var s = document.createElement('script');
s.type = 'text/javascript';
s.innerHTML = action;
var c = document.getElementsByTagName('script')[0];
c.parentNode.insertBefore(s, c);
}
},
"createAndAddStyle": function (src) {
if (src) {
let s = document.createElement('link');
s.type = 'text/css';
s.rel= 'stylesheet';
s.href = src;
document.head.appendChild(s);
}
},
"runWhenJQueryIsLoaded": function (callback) {
var that = this;
if (window.$) {
//possibly some other JQuery checks to make sure that everything is loaded here
callback();
} else {
setTimeout(function () {
that.runWhenJQueryIsLoaded(callback);
}, 500);
}
},
"addTracker": function (partner, src, action) {
if (typeof DoctorTracker !== 'function') {
//this.createAndAddScript(src, action, "window.ddcWidget.addTracker('" + partner + "')");
this.createAndAddScript(src, action, function () {
window.pdi_tracking = new DoctorTracker(partner);
});
}
},
"addTrackerPromise": function (partner, src, action) {
const that = this
return new Promise (function (resolve, reject) {
try {
if (typeof DoctorTracker !== 'function') {
//this.createAndAddScript(src, action, "window.ddcWidget.addTracker('" + partner + "')");
that.createAndAddScript(src, action, function () {
window.pdi_tracking = new DoctorTracker(partner);
resolve(true)
});
}
} catch (e) {
reject(e)
}
})
},
"search": function (zipcode, pat_svy, params) {
console.log('running search')
pat_svy = !!pat_svy ? pat_svy : '';
params = !!params ? params : {};
this.data.zipcode = zipcode;
this.data.paramzipcode = zipcode
$('#locationFilter').val(zipcode)
this.data.pat_svy = pat_svy;
const sort = !!params.sort ? params.sort : '';
var params = {
"sort": sort,
"zipcode": zipcode,
"pat_svy": pat_svy,
"size": this.data.size ? parseInt(this.data.size) : '6'
};
this.data.params = params
const querystring = $.param(params) + '&' + this.data.querystring;
const that = this;
$.getJSON(this.data.baseUrl + '/widget?output=js&doRender=true&callback=?', querystring, function (res) {
// do we have our default container?
if ($('#ddcWidget').length) {
// yes
$('#ddcWidget').html(res.body);
} else {
// no, use an alternative
$('.paragraph--type--dr-finder-tool:first').html(res.body);
// set the id to ours for css compatibility
$('.paragraph--type--dr-finder-tool:first').prop('id', 'ddcWidget');
}
that.data.showPrev = $('#ddcPaginationData').data('showprev');
that.data.showNext = $('#ddcPaginationData').data('shownext');
that.data.total = $('#ddcPaginationData').data('total');
that.updateUI();
that.bindForm();
ddcWidget.addShearchViewTracking();
});
},
"find": function (params, callback) {
var querystring = $('#ddcFilterForm').serialize();
querystring = this.updateQueryString(params, querystring)
this.toggleLoading();
this.executeWidgetCallback(querystring, callback)
},
"refreshTotals": function (newHtml) {
var pagination = $(newHtml).find('.ddc-count').first();
$('.ddc-count').replaceWith(pagination);
if ($('.ddc-count:first').text() == '0 providers') {
$('.ddc-count:first').text('');
}
const newZipcode = $('input[name$="ddcFilter[location]"]').val();
const text = 'Zip Code: ' + newZipcode;
$('a.ddcZip').text(text);
this.getFiltersQuantity();
$('.js-location-options').empty();
},
"updateUI": function () {
if (this.data.showNext) {
$('.ddc-next').css('visibility', 'visible');
} else {
$('.ddc-next').css('visibility', 'hidden');
}
if (this.data.showPrev) {
$('.ddc-prev').css('visibility', 'visible');
} else {
$('.ddc-prev').css('visibility', 'hidden');
}
if (this.data.total) {
$('.ddcResultCount').html(this.data.total);
}
if ($('.ddcFormZipcode input').val()) {
$('.ddcZip').html('Zip Code ' + $('.ddcFormZipcode input').val());
}
// do we have our default container?
if ($('#ddcWidget').length) {
// yes
if ($('#ddcWidget').width() < 800) {
$('#ddcWidget').addClass('ddcSM');
}
} else {
// no, use an alternative
if ($('.paragraph--type--dr-finder-tool:first').width() < 800) {
$('.paragraph--type--dr-finder-tool:first').addClass('ddcSM');
// set the id to ours for css compatibility
$('.paragraph--type--dr-finder-tool:first').prop('id', 'ddcWidget');
}
}
},
"bindForm": function () {
if (this.data.binded) return true
console.log('Init form')
this.data.binded = true
this.data.paramzipcode = this.data.zipcode
$('#locationFilter').val(this.data.paramzipcode)
/**
* Submit form when filters change
*/
var that = this;
$("#ddcFilterForm").on('change', function () {
var size = that.data.size ? parseInt(that.data.size) : 6;
var params = {
page: 1,
size: size,
output: 'js',
doRender: true
}
that.find(params, function (body) {
console.log('Form updated, used ddcFind!');
that.refreshTotals(body);
});
});
/**
* Toggle filters
*/
$('.ddcFilterToggle').on('click', function () {
$('.ddcFilterInner').removeClass('filter-inner-display');
$('.ddcFilterInner').toggle();
if ($('.ddcFilterInner').is(":visible")) {
if ($('.ddcFilterToggle').hasClass('toggle-off-radius')) {
$('.ddcFilterToggle').removeClass('toggle-off-radius');
$('.ddcFilterToggle').addClass('toggle-on-radius');
}
if ($('.ddcFilterToggleArrow i').hasClass('fa')) {
$('.ddcFilterToggleArrow i').removeClass('fa-angle-down');
$('.ddcFilterToggleArrow i').addClass('fa-angle-up');
} else {
$('.ddcFilterToggleArrow i').removeClass('ddcArrowDown');
$('.ddcFilterToggleArrow i').addClass('ddcArrowUp');
}
$('.ddcFilterInner').addClass('filter-inner-display');
} else {
if ($('.ddcFilterToggle').hasClass('toggle-on-radius')) {
$('.ddcFilterToggle').removeClass('toggle-on-radius');
$('.ddcFilterToggle').addClass('toggle-off-radius');
}
if ($('.ddcFilterToggleArrow i').hasClass('fa')) {
$('.ddcFilterToggleArrow i').removeClass('fa-angle-up');
$('.ddcFilterToggleArrow i').addClass('fa-angle-down');
} else {
$('.ddcFilterToggleArrow i').addClass('ddcArrowDown');
$('.ddcFilterToggleArrow i').removeClass('ddcArrowUp');
}
}
});
$("#ddcFilterForm").on('submit', function () {
// IF enter key was pressed, just ignore and let the 'change'
// handler process the search.
return false;
});
$("#ddcFilterFormNew").on('submit', function () {
// IF enter key was pressed, just ignore and let the 'change'
// handler process the search.
return false;
});
$('.geo-location-span').on('mouseover', function () {
$('#locationFilter').val('Click to use/cancel your location')
})
$('.geo-location-span').on('mouseout', function () {
$('#locationFilter').val(ddcWidget.data.zipcode)
})
$('#geo-location-icon').on('click', function () {
window.ddcWidget.setGeoLocationFilter()
console.log('geo click')
})
$('#times-icon').on('click', function () {
window.ddcWidget.cancelGeoLocationFilter()
console.log('cancel geo click')
})
this.getFiltersQuantity()
},
"checkBindForm": function () {
if(window.ddcWidget && !window.ddcWidget.data.binded) {
this.bindForm()
$('#zipcode').hide();
$('#ddcSearchButton').hide();
if(!window.pdi_tracking) {
this.addShearchViewTracking();
}
if (window.ddcWidgetGeo) {
window.ddcWidgetGeo.initGeoLocation();
}
}
},
"paginate": function (dir) {
if (this.data.pagingInProgress) {
return false;
}
if (dir === 'next') {
this.data.page++;
} else {
if (this.data.page > 1) {
this.data.page--;
}
if (this.data.page === 1) {
$('.ddc-prev').css('visibility', 'hidden');
} else {
$('.ddc-prev').css('visibility', 'visible');
}
}
this.callPaginate();
},
"paginateByPageNumber": function (page) {
if (this.data.pagingInProgress) {
return false;
}
this.data.page = page;
this.callPaginate();
},
"callPaginate": function () {
var size = this.data.size ? parseInt(this.data.size) : 6;
var params = {
page: this.data.page,
size: size,
output: 'js',
doRender: true,
useProfileModal: true,
showPagination: true,
zipcode: this.data.zipcode
}
this.data.pagingInProgress = true;
this.findNew(params, function (body) {
ddcWidget.data.pagingInProgress = false;
});
},
"paginateJsonProfile": function (dir) {
var that = this
return new Promise(function (resolve) {
if (that.data.pagingInProgress) {
return false;
}
if (dir === 'next') {
that.data.pageProfile++;
} else {
if (that.data.pageProfile > 1) {
that.data.pageProfile--;
}
}
that.data.showPrevProfile = that.data.pageProfile > 1
var size = that.data.size ? parseInt(that.data.size) : 6;
var params = {
page: that.data.pageProfile,
size: size,
output: 'json',
doRender: false,
zipcode: that.data.zipcode
}
that.findJson(params, function (response) {
resolve(response);
});
})
},
"makeInfoWindowEvent": function (map, infowindow, provider, marker) {
google.maps.event.addListener(marker, 'click', function () {
var partnerSiteId = window.ddcWidget.data.partner_site_id;
if (typeof hostname === 'undefined') {
hostname = '';
}
window.ddcWidget.modals.profile.show(hostname + '/widget/profile?providerId=' + provider.attributes.provider_id + "&partner_site_id=" + partnerSiteId);
pdi_tracking.track('PROFILE', {provider_id: provider.attributes.provider_id});
});
google.maps.event.addListener(marker, 'mouseover', function () {
var name = provider.attributes.first_name + ' ' + provider.attributes.last_name;
infowindow.setContent(name);
infowindow.open(map, marker);
});
google.maps.event.addListener(marker, 'mouseout', function () {
infowindow.close();
});
},
"myMap": function (latitude, longitude) {
var mapProp = {
center: new google.maps.LatLng(latitude, longitude),
zoom: 10,
disableDefaultUI: true
};
this.data.map = new google.maps.Map(document.getElementById("providersMap"), mapProp);
},
"placeMarkers": function () {
var infowindow = new google.maps.InfoWindow();
var that = this;
var bounds = new google.maps.LatLngBounds();
this.data.providers.forEach(function (provider) {
// console.log(provider);
var practices = provider.attributes.practice;
var name = provider.attributes.first_name + ' ' + provider.attributes.last_name;
var lat = practices.length > 0 ? provider.relevantPractice.attributes.latitude : provider.attributes.latitude;
var lon = practices.length > 0 ? provider.relevantPractice.attributes.longitude : provider.attributes.longitude;
var myLatlng = new google.maps.LatLng(lat, lon);
bounds.extend(myLatlng);
if (typeof hostname === 'undefined') {
hostname = '';
}
var marker = new google.maps.Marker({
position: myLatlng,
icon: hostname + '/images/v4/providerMarker.png'
});
// To add the marker to the map, call setMap();
marker.setMap(that.data.map);
that.data.markers.push(marker);
that.makeInfoWindowEvent(that.data.map, infowindow, provider, marker);
});
setTimeout(function () {
that.data.map.fitBounds(bounds);
that.data.map.panToBounds(bounds);
}, 500);
},
"removeMarkers": function () {
if (this.data.markers.length > 0) {
for (var i = 0; i < this.data.markers.length; i++) {
var marker = this.data.markers[i];
marker.setMap(null);
}
}
this.data.markers = [];
},
"hideShowMap": function () {
var myMapClasses = document.getElementById("providersMap").classList;
var ddcOptionClasses = document.getElementById("ddcViewOption").classList;
var isActive = false;
for (var i = 0; i < myMapClasses.length; i++) {
var data = myMapClasses[i];
if (data === 'is-active') {
isActive = true;
}
}
if (isActive) {
myMapClasses.remove("is-active");
ddcOptionClasses.remove("is-active");
} else {
myMapClasses.add("is-active");
ddcOptionClasses.add("is-active");
}
},
"log": function (thing) {
if (this.log_enabled && typeof console != 'undefined') {
console.log('>>>> DDC LOG START');
console.log(thing);
console.log('>>>> DDC LOG END');
}
},
"initIframeModals": function () {
console.log('init iframe modals');
this.copyStylesToParent();
this.copyTemplatesToParent();
this.initParentModals();
},
"copyStylesToParent": function () {
console.log('iframe modals - copy styles to parent');
var href = "www.doctor.com";
var cssElem = '';
$('head', window.parent.document).append(cssElem);
},
"copyTemplatesToParent": function () {
console.log('iframe modals - Copy templates to parent');
var el = $('#modal_template');
$('body', window.parent.document).append(el);
},
"initParentModals": function () {
console.log('iframe modals - init parent modals');
var html = $('#modal_template', window.parent.document).html();
$('body', window.parent.document).append(html);
$('#ddc-profile-modal-close', window.parent.document).click(function () {
$('#ddc-profile-modal', window.parent.document).hide();
});
},
"openParentProfileModal": function (url) {
console.log('opening modal')
$('#ddcLoading').toggleClass('show');
$.get(url)
.done(function (html) {
$('#ddcLoading').toggleClass('show');
$('.ddc-profile-modal-content', window.parent.document).html(html);
$('#ddc-profile-modal', window.parent.document).show();
})
.fail(function (e) {
$('#ddcLoading').toggleClass('show');
ddcWidget.log('Something failed!');
ddcWidget.log(e);
});
},
"addShearchViewTracking": function () {
var providers = window.ddcWidget.data.providers;
var providerIds = [];
for (var i = 0; i < providers.length; i++) {
providerIds.push(providers[i].attributes.provider_id);
}
if(!window.pdi_tracking && this.data.trackingParams) {
this.addTrackerPromise(this.data.trackingParams.partner, this.data.trackingParams.src).then (function () {
window.pdi_tracking.track("SEARCH_VIEW", {providers: providerIds});
})
} else {
window.pdi_tracking.track("SEARCH_VIEW", {providers: providerIds});
}
console.log("SEARCH VIEW TRACKING", providerIds);
},
"addFonts": function () {
if(this.data.partner_site_id === '76') {
var headID = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'https://fonts.googleapis.com/css2?family=Open+Sans&family=Source+Sans+Pro:wght@400;900&display=swap';
headID.appendChild(link);
}
},
"changeLocation": function (e) {
const location = e.originalEvent.target.innerText;
$('#locationFilter').val(location)
this.data.zipcode = location
this.data.location = e.originalEvent.target.attributes['data-coords'].value;
},
"changeForm": function () {
// this.data.paramzipcode = this.data.paramzipcode || this.data.zipcode
if (!this.checkZipcode()) return false;
this.data.zipcode = $('#locationFilter').val()
const that = this;
const size = this.data.size ? parseInt(this.data.size) : 6;
const params = {
page: 1,
size: size,
output: 'js',
doRender: true,
zipcode: this.data.zipcode
}
this.findNew(params, function (body) {
console.log('Form updated, used ddcFind!');
that.refreshTotals(body);
});
},
"findNew": function (params, callback) {
let querystring = $('#ddcFilterFormNew').serialize();
querystring = this.updateQueryString(params, querystring);
this.toggleLoading();
this.executeWidgetCallback(querystring, callback);
},
"findJson": function (params, callback) {
let querystring = $('#ddcFilterFormNew').serialize();
querystring = this.updateQueryString(params, querystring);
this.executeWidgetJsonCallback(querystring, callback);
},
"updateQueryString": function (params, querystring) {
params.zipcode = params.zipcode === 'Current position' ? undefined : params.zipcode
querystring += '&' + $.param(params) + '&' + this.data.querystring;
querystring += !params.zipcode && this.data.geopoint ? "&geopoint=" + encodeURI(this.data.geopoint) : ''
console.log('Zipcode: ' + this.data.zipcode)
console.log('Geopoint: ' + this.data.geopoint)
// console.log('Query String: ' + querystring)
return querystring
},
'getCurrentPosition': function () {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(this.geoSuccess, null)
}
return false
},
"geoSuccess": function (position) {
ddcWidget.data.geopoint = position.coords.latitude + ', ' + position.coords.longitude
ddcWidget.changeForm()
},
"geoError": function () {
return false
},
"toggleLoading": function () {
$('#ddcLoading').toggleClass('show');
},
"executeWidgetCallback": function (querystring, callback) {
const that = this
$.getJSON(this.data.baseUrl + '/widget?callback=?', querystring, function (res) {
var newHtml = '
' + res.body + '
'; // Wrap in a div for selectors to work
var results = $(newHtml).find('.ddcResults').first();
var pagination = $(newHtml).find('#ddcPaginationData').first();
ddcWidget.data.total = pagination.data('total');
ddcWidget.data.page = pagination.data('page');
ddcWidget.data.pageProfile = pagination.data('page');
ddcWidget.data.showNext = pagination.data('shownext');
ddcWidget.data.showPrev = pagination.data('showprev');
if (!ddcWidget.data.total) {
ddcWidget.data.total = $(newHtml).find('.ddcResultCount').text();
}
ddcWidget.log('find method');
ddcWidget.log('pagination data: ' + pagination.data('total'));
ddcWidget.log('result count: ' + $(newHtml).find('.ddcResultCount').text());
ddcWidget.log('TOTAL RESULTS: ' + ddcWidget.data.total);
that.toggleLoading();
// do we have our default container?
if ($('#ddcWidgetContent').length) {
// yes
if (results.html().trim() != '') {
$('#ddcWidgetContent .ddcResults').html(results.html());
} else {
$('#ddcWidgetContent .ddcResults').html('
Sorry, no matching providers found.
');
}
} else {
// no, use an alternative
if (results.html().trim() != '') {
$('.paragraph--type--dr-finder-tool:first .ddcResults').html(results.html());
} else {
$('#ddcWidgetContent .ddcResults').html('
Sorry, no matching providers found.
');
}
// set the id to ours for css compatibility
$('.paragraph--type--dr-finder-tool:first').prop('id', 'ddcWidget');
}
ddcWidget.addShearchViewTracking();
that.updateUI();
callback(res.body);
}).fail(function () {
console.log("Error al llamar a :" + url);
});
},
"executeWidgetJsonCallback": function (querystring, callback) {
const url = this.data.baseUrl + '/widget?callback=?' + querystring
$.getJSON(url, function (res) {
callback(res);
}).fail(function () {
console.log("Error al llamar a :" + url);
});
},
"cleanFilters": function () {
this.cancelGeoLocationFilter()
$('#gender-filter').val(undefined)
$('#rating-filter').val(undefined)
$('#insurance-filter').val(undefined)
$('#ddcFilter_onlineScheduling').prop("checked", false)
$('#ddcFilter_boardCertified').prop("checked", false)
$('.js-location-options').empty();
this.data.zipcode = this.data.paramzipcode
this.changeForm()
},
"getFiltersQuantity": function () {
let quantity = $('#locationFilter').val() ? 1 : 0
quantity += $('#gender-filter').val() ? 1 : 0
quantity += $('#rating-filter').val() ? 1 : 0
quantity += $('#insurance-filter').val() ? 1 : 0
quantity += $('#ddcFilter_onlineScheduling').prop("checked") ? 1 : 0
quantity += $('#ddcFilter_boardCertified').prop("checked") ? 1 : 0
quantity === 0 ? $('#filter-quantity').html('') : $('#filter-quantity').html(' Filters ( ' + quantity + ' ) ')
},
"checkZipcode": function () {
/*if ($('#locationFilter').val() && ddcWidget.data.zipcode !== $('#locationFilter').val() && ddcWidget.data.zipcode !== 'Current position') {
alert('You must select one value from the list')
$('#locationFilter').val(ddcWidget.data.zipcode)
return false
}*/
return true
},
"clickOpenProfile": function (providerId) {
this.data.pageProfile = this.data.page
this.data.providerSelected = this.data.providers.filter(function(provider) {
return parseInt(provider.attributes.provider_id, 10) === parseInt(providerId, 10)
})[0]
},
"getProfileUrl": function () {
return this.data.baseUrl + '/widget/profile?providerId=' + this.data.providerSelected.attributes.provider_id + '&partner_site_id=' + this.data.providerSelected.partnerSiteId;
},
"changeProfile": function (direction) {
this.modals['profile'].content.html('
');
const providerSelected = this.data.providerSelected
const providers = this.data.providers
const providersAuxNav = this.data.providersAuxNav
let that = this
let array = that.arrayIsNotEmpty(providersAuxNav) ? providersAuxNav : providers
let idx = array.indexOf(providerSelected)
idx = direction === 'next' ? idx + 1 : idx - 1
if (idx!==-1 && array[idx]) {
this.data.providerSelected = array[idx]
this.changeProfileModal()
} else {
this.paginateJsonProfile(direction).then(function (response) {
that.data.providersAuxNav = response.result ? response.result.providers : response
if (that.arrayIsNotEmpty(that.data.providersAuxNav)) {
const newIdx = direction === 'next' ? 0 : that.data.providersAuxNav.length - 1
that.data.providerSelected = that.data.providersAuxNav[newIdx]
that.changeProfileModal()
}
})
}
},
"changeProfileModal": function () {
$('#ddcLoading').toggleClass('show');
var that = this
$.get(this.getProfileUrl())
.done(function (html) {
that.modals['profile'].content.html(html);
$('#ddc-profile-modal').css('display', 'block');
// Progress bar (heavily adapted from search-ui.js)
// We don't have access to jQuery plugins here
ddcWidget.setProfileModalComponents()
})
.fail(function (e) {
ddcWidget.log('Something failed!');
ddcWidget.log(e);
});
},
"setProfileModalComponents": function () {
// Progress bar (heavily adapted from search-ui.js)
// We don't have access to jQuery plugins here
$(".ddc-progress-bar").html(function () {
var progData = $(this).data();
var label = progData.label;
var progress = (progData && progData.progress) ? progData.progress : 0;
var max = progData.max ? progData.max : 0;
return '' + label + '/' + max + '';
});
$(".ddc-progress-bar .ddc-progress-graph").css({
width: function () {
var progData = $(this).parent('.ddc-progress-bar').data();
var ratio = progData.progress / progData.max;
var progWidth = ratio * 100;
return Math.round(progWidth) + '%';
},
background: function () {
var progData = $(this).parent('.ddc-progress-bar').data();
var ratio = progData.progress / progData.max;
if (ratio <= .3) return '#EA7E37';
if (ratio > .3 && ratio < .7) return '#F4C319';
if (ratio >= .7) return '#AEE239';
}
});
// Just set the progress directly for now
var progData = $('.ddc-progress-bar').data();
var progress = (progData && progData.progress) ? progData.progress : 0;
$('.ddc-current-count').html(progress);
// Stars (heavily adapted from search-ui.js)
$('.ddc-star-rating').each(function () {
if ($(this).data("starsActive") == undefined) {
$(this).data("starsActive", 1)
.append(
'' +
'' +
'' +
'' +
'');
}
});
$('#ddcLoading').toggleClass('show');
$('#right-profile-nav').click(function () {
ddcWidget.changeProfile('next')
})
$('#left-profile-nav').click(function () {
ddcWidget.changeProfile('prev')
})
this.checkProfileArrows()
},
"checkProfileArrows": function () {
const providerSelected = this.data.providerSelected
const providers = this.data.providers
const providersAuxNav = this.data.providersAuxNav
const showPrevProfile = this.data.showPrevProfile
const array = this.arrayIsNotEmpty(providersAuxNav) ? providersAuxNav : providers
const showPrev = $('#ddc-prev').css('pointer-events') !== 'none'
const showNext = $('#ddc-next').css('pointer-events') !== 'none'
const previous = $('#left-profile-nav')
const next = $('#right-profile-nav')
const idx = array.indexOf(providerSelected)
const idxInit1 = idx + 1
if (idx === 0) {
const allowDisable = this.allowDisablePrev(providersAuxNav, providers, idx)
if ((!showPrev && !showPrevProfile) && allowDisable) {
previous.prop('disabled', true);
previous.attr("disabled", "disabled").off('click')
previous.addClass('nav-disabled')
} else {
previous.prop('disabled', false);
previous.attr("disabled", "enabled").on('click')
previous.removeClass('nav-disabled')
}
}
if (this.isLastResult(idxInit1, array)) {
if (!showNext) {
next.prop('disabled', true);
next.attr("disabled", "disabled").off('click')
next.addClass('nav-disabled')
} else {
next.prop('disabled', false);
next.attr("disabled", "enabled").on('click')
next.removeClass('nav-disabled')
}
}
},
"isLastResult": function (currentPosition, array) {
return (this.data.page == this.data.pageProfile ? this.data.page : this.data.pageProfile) == this.data.total && currentPosition === array.length
},
"arrayIsNotEmpty": function (array) {
return array && array.length > 0
},
"arrayIsEmpty": function (array) {
return !array || array.length === 0
},
"allowDisablePrev": function (providersAuxNav, providers, idx) {
return this.arrayIsEmpty(providersAuxNav)
|| (this.arrayIsNotEmpty(providersAuxNav) && providersAuxNav[idx].attributes.provider_id !== providers[idx].attributes.provider_id)
},
"setGeoLocationFilter": function () {
const permitGeo = ddcWidget.checkGeoLocationPermission()
$('#locationFilter').val('Current position')
$('#locationFilter').prop("readonly", true)
this.data.zipcode = 'Current position'
$('#geo-location-icon').css('display', 'none')
$('#times-icon').css('display', 'inline')
console.log('this.data.geopoint: ' + this.data.geopoint)
if (!this.data.geopoint) {
this.getCurrentPosition()
} else {
this.changeForm()
}
},
"cancelGeoLocationFilter": function () {
this.data.zipcode = this.data.paramzipcode
$('#locationFilter').val(this.data.paramzipcode)
$('#locationFilter').prop("readonly", false)
$('#geo-location-icon').css('display', 'inline')
$('#times-icon').css('display', 'none')
ddcWidget.changeForm()
},
"checkGeoLocationPermission": function () {
navigator.geolocation.watchPosition(function (position) {
return true
},
function (error) {
if (error.code == error.PERMISSION_DENIED)
alert('You must accept geolocation to filter by position')
ddcWidget.cancelGeoLocationFilter()
return false
});
}
};
window.ddcWidget.baseModal = function (modalTemplateId, modalId) {
this.modalTemplate = modalTemplateId;
this.modalId = modalId;
this.modal = null;
this.closeButton = null;
this.content = null;
this.mounted = false;
};
window.ddcWidget.baseModal.prototype.open = function () {
this.modal.css('display', 'block');
};
window.ddcWidget.baseModal.prototype.load = function (url, callback) {
this.content.load(url, function () {
callback();
});
};
window.ddcWidget.baseModal.prototype.close = function () {
ddcWidget.data.providersAuxNav = []
this.modal.css('display', 'none');
$(document).trigger("ddc:modalClose");
};
window.ddcWidget.baseModal.prototype.setContent = function (content) {
this.content.html(content);
};
window.ddcWidget.baseModal.prototype.init = function () {
var html = $(this.modalTemplate).html();
$('body').append(html);
this.modal = $(this.modalId);
this.closeButton = $(this.modalId).find('.ddc-modal-close');
this.content = $(this.modalId).find('.ddc-modal-content');
$('body').click(function (event) {
if (!!$(event.target).closest(this.modal[0]).length &&
!!$(event.target).is(this.modal[0])) {
this.close();
}
}.bind(this)).bind(this);
// Close button
this.closeButton.click(this.close.bind(this));
this.mounted = true;
};
window.ddcWidget.profileModal = function (modalTemplateId, modalId) {
window.ddcWidget.baseModal.call(this, modalTemplateId, modalId);
};
window.ddcWidget.profileModal.prototype = Object.create(window.ddcWidget.baseModal.prototype);
window.ddcWidget.profileModal.prototype.show = function (url) {
if (!this.mounted) {
this.init();
}
$('#ddcLoading').toggleClass('show');
$(document).trigger("ddc:modalOpen");
var that = this;
$.get(url)
.done(function (html) {
//console.log('Container length: ' + $('#ddc-profile-modal .ddc-profile-modal-content-ctr').length);
//$('#ddc-profile-modal-content-ctr .ddc-profile-modal-content').html(html);
//console.log(html);
that.content.html(html);
ddcWidget.setProfileModalComponents()
that.open();
})
.fail(function (e) {
ddcWidget.log('Something failed!');
ddcWidget.log(e);
});
};
window.ddcWidget.insuranceModal = function (modalTemplateId, modalId) {
this.insurances = [];
this.selectedInsurance = '';
window.ddcWidget.baseModal.call(this, modalTemplateId, modalId);
};
window.ddcWidget.insuranceModal.prototype = Object.create(window.ddcWidget.baseModal.prototype);
window.ddcWidget.insuranceModal.prototype.show = function (insurancesJson) {
if (!this.mounted) {
this.init();
this.insurances = JSON.parse(insurancesJson);
for (var i = 0; i < this.insurances.length; i++) {
this.content.find('.js-insurance-options').append('');
}
this.setupChangeListener();
this.setupTextFilter();
}
this.open();
};
window.ddcWidget.insuranceModal.prototype.setupTextFilter = function () {
var that = this;
$('input.js-insurance-search').on('keyup', function (event) {
var value = event.target.value || "";
var newOptionsArr = that.insurances.filter(function (obj) {
return obj.name.toLowerCase().indexOf(value.toLowerCase()) !== -1
});
var options = '';
for (var i = 0; i < newOptionsArr.length; i++) {
if (newOptionsArr[i].id === that.selectedInsurance) {
options = '' + options;
} else {
options += '';
}
}
$('.js-insurance-options').empty();
$('.js-insurance-options').append(options);
$('input.js-filter-insurance').on('change', function () {
$('input.js-filter-insurance').not(this).prop('checked', false);
that.selectedInsurance = this.attributes.value.value;
that.close();
});
});
}
window.ddcWidget.insuranceModal.prototype.setupChangeListener = function () {
var that = this;
$('input.js-filter-insurance').on('change', function () {
$('input.js-filter-insurance').not(this).prop('checked', false);
that.selectedInsurance = this.attributes.value.value;
that.close();
});
}
window.ddcWidget.distanceModal = function (modalTemplateId, modalId) {
window.ddcWidget.baseModal.call(this, modalTemplateId, modalId);
};
window.ddcWidget.distanceModal.prototype = Object.create(window.ddcWidget.baseModal.prototype);
window.ddcWidget.distanceModal.prototype.show = function () {
var that = this;
if (!this.mounted) {
this.init();
$('input.js-filter-distance').on('change', function () {
$('input.js-filter-distance').not(this).prop('checked', false);
that.close();
});
}
this.open();
};
window.ddcWidget.reviewModal = function (modalTemplateId, modalId) {
window.ddcWidget.baseModal.call(this, modalTemplateId, modalId);
};
window.ddcWidget.reviewModal.prototype = Object.create(window.ddcWidget.baseModal.prototype);
window.ddcWidget.reviewModal.prototype.show = function () {
var that = this;
if (!this.mounted) {
this.init();
$('input.js-filter-rating').on('change', function () {
$('input.js-filter-rating').not(this).prop('checked', false);
that.close();
});
}
this.open();
};
window.ddcWidget.moreModal = function (modalTemplateId, modalId) {
window.ddcWidget.baseModal.call(this, modalTemplateId, modalId);
};
window.ddcWidget.moreModal.prototype = Object.create(window.ddcWidget.baseModal.prototype);
window.ddcWidget.moreModal.prototype.show = function () {
var that = this;
if (!this.mounted) {
this.init();
//Showing of different panels
$('.js-show-filters').click(function (event) {
$('[data-panel="main"]').removeClass("is-active");
$('[data-panel="' + event.target.value + '"]').addClass("is-active");
});
//Checkbox Handling
$('input.js-filter-accepts-new').on('change', function () {
$('input.js-filter-accepts-new').not(this).prop('checked', false);
that.close();
});
$('input.js-filter-more-rating').on('change', function () {
$('input.js-filter-more-rating').not(this).prop('checked', false);
that.close();
});
$('input.js-filter-gender').on('change', function () {
$('input.js-filter-gender').not(this).prop('checked', false);
that.close();
});
}
$('[data-panel="main"]').addClass("is-active");
$('[data-panel="availability"]').removeClass("is-active");
$('[data-panel="moreReviews"]').removeClass("is-active");
$('[data-panel="gender"]').removeClass("is-active");
$('[data-panel="moreLocation"]').removeClass("is-active");
this.open();
};
window.ddcWidget.locationModal = function (modalTemplateId, modalId) {
window.ddcWidget.baseModal.call(this, modalTemplateId, modalId);
};
window.ddcWidget.locationModal.prototype = Object.create(window.ddcWidget.baseModal.prototype);
window.ddcWidget.locationModal.prototype.show = function () {
var that = this;
if (!this.mounted) {
this.init();
this.setup();
}
$('.js-location-search').val("");
$('.js-location-options').empty();
this.open();
};
window.ddcWidget.locationModal.prototype.setup = function () {
var that = this;
$('input.js-location-search').on('keyup', function (event) {
var timeout;
var value = event.target.value || "";
if (3 <= value.length) {
if (!!timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(function () {
if (typeof hostname === 'undefined') {
hostname = '';
}
$.ajax({
url: hostname + "/widget/autocomplete?query=" + value,
// data: filtersToApply,
type: "POST",
dataType: "html",
success: function (response) {
// $('#ddcLoading').hide();
var options = '';
var response = JSON.parse(response);
for (var i = 0; i < response.length; i++) {
options += '';
}
$('.js-location-options').empty();
$('.js-location-options').append(options);
$('button.ddc-suggestion').click(function (e) {
window.ddcWidget.filters.changeLocation(e);
//Change view more with new zipcode
var currentURL = $('.ddcMore a').attr('href');
var url = new URL(currentURL);
var zipCode = url.searchParams.get("s_location");
var newURL = currentURL.replace(zipCode, e.originalEvent.target.innerText);
$('.ddcMore a').attr('href', newURL);
that.close();
});
},
error: function (xhr, status) {
// $('#ddcLoading').hide();
alert("Sorry, there was a problem!");
},
complete: function (xhr, status) {
// $('#ddcLoading').hide();
}
});
}, 500);
}
});
}
window.ddcWidget.leaveModal = function (modalTemplateId, modalId) {
this.url = '';
window.ddcWidget.baseModal.call(this, modalTemplateId, modalId);
};
window.ddcWidget.leaveModal.prototype = Object.create(window.ddcWidget.baseModal.prototype);
window.ddcWidget.leaveModal.prototype.setup = function () {
var that = this;
if (!this.mounted) {
this.init();
$('body').on('click', '.ddcExtras a, .ddc-modal a, #ddcWidget a', function (event) {
if (this.href.indexOf('doctor')!==-1) {
that.url = this.href;
event.stopPropagation();
that.open();
return false;
}
return true;
});
$('.js-interstitial-leave').click(function () {
window.open(that.url);
that.close();
});
$('.ddc-interstitial-cancel').click(function () {
that.close();
});
}
};
window.ddcWidget.modals = {
"profile": new window.ddcWidget.profileModal('#modal_template', '#ddc-profile-modal'),
"insurance": new window.ddcWidget.insuranceModal('#insurance_modal_template', '#ddc-profile-insurance-modal'),
"distance": new window.ddcWidget.distanceModal('#distance_modal_template', '#ddc-profile-distance-modal'),
"review": new window.ddcWidget.reviewModal('#review_modal_template', '#ddc-profile-review-modal'),
"more": new window.ddcWidget.moreModal('#more_modal_template', '#ddc-profile-more-modal'),
"location": new window.ddcWidget.locationModal('#location_modal_template', '#ddc-profile-location-modal')
};
window.ddcWidget.filters = {
appliedFilters: [],
availableFilters: ['distance', 'insurance', 'rating', 'acceptingNewPatients', 'gender', 'geopoint'],
submit: function () {
if (typeof hostname === 'undefined') {
hostname = '';
}
var partnerSiteId = window.ddcWidget.data.partner_site_id;
var url = hostname + "/widget?callback=?&filter=true&partner_site_id=" + partnerSiteId;
var querystring = '';
//remove zip code if we have geopoint
if (!!this.appliedFilters.geopoint) {
delete this.appliedFilters.zipcode;
} else {
this.appliedFilters.zipcode = window.ddcWidget.data.zipcode;
}
for (var key in this.appliedFilters) {
if (key === 'partner_site_id') {
continue;
}
if (key === 'zipcode' || key === 'page' || key === 'size') {
querystring += "&" + key + "=" + this.appliedFilters[key];
} else if (key === 'geopoint') {
querystring += "&" + key + "=" + encodeURI(this.appliedFilters[key]);
} else {
querystring += "&ddcFilter[" + key + "]=" + this.appliedFilters[key];
}
}
var size = window.ddcWidget.data.size ? parseInt(window.ddcWidget.data.size) : 6;
var params = {
output: 'js',
doRender: true,
useProfileModal: true,
size: size,
sort: $('.ddcSortBy').val()
};
querystring += '&' + $.param(params);
$('#ddcLoading').toggleClass('show');
$.getJSON(url, querystring, function (response) {
var newHtml = '