Skip to content

Instantly share code, notes, and snippets.

@mikedoubintchik
Created February 20, 2017 20:45
Show Gist options
  • Save mikedoubintchik/e9854df1ab20a43d2440e6a0727e379b to your computer and use it in GitHub Desktop.
Save mikedoubintchik/e9854df1ab20a43d2440e6a0727e379b to your computer and use it in GitHub Desktop.
// Check if fields are blank
$.fn.isFilled = function () {
var fields = $(this).serializeArray();
for (var i = 0; i < fields.length; i++) {
if (fields[i].value == '') {
return false;
}
}
return true;
};
var _ctq = _ctq || [];
// Create 'compare to' strip object
_ctq.push(['newCompareToStrip', 'a']);
_ctq.push(['a.setPublisherID', 4]);
_ctq.push(['a.setAnchorID', 'ctAnchor']);
_ctq.push(['a.setFormID', 'ctSearchForm']);
// TODO: Attach the correct API methods to our search form, this is a 'Hotel Citywide' search.
_ctq.push(['a.setCityNameID', 'ctCity']);
_ctq.push(['a.setCheckInID', 'ctDate1']);
_ctq.push(['a.setCheckOutID', 'ctDate2']);
_ctq.push(['a.setGuestsID', 'ctGuests']);
_ctq.push(['a.setRoomsID', 'ctRooms']);
_ctq.push(['a.setReferralURL', 'http://www.clicktripz.com/oneliner_applicant_test.php']);
_ctq.push(['a.optMaxChecked', 1]);
_ctq.push(['a.optMaxAdvertisers', 7]);
_ctq.push(['a.optMaxSearchesPerDay', 9999]);
_ctq.push(['a.optHardLimitSearchesPerSeconds', '9999:1']);
// TODO: Add command to force a tabbed window to launch instead of individual advertiser pages.
_ctq.push(['a.optForceTabbedMode', 'true']);
// TODO: Add command(s) to force tabbed window to launch as a popunder on IE/FF/Chrome and a popover on Safari
// If browser isn't Safari, use popunder, otherwise use popover (default)
if (!BrowserIsSafari) {
_ctq.push(['a.optPopUnder', 'false']);
} else {
_ctq.push(['a.optPopUnder', 'true']);
}
_ctq.push(['a.optThumbSize', 'small']);
_ctq.push(['a.draw']);
(function () {
var ct = document.createElement('script');
ct.type = 'text/javascript';
ct.async = true;
ct.src = '//static.clicktripz.com/scripts/js/ct.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ct, s);
})();
// TODO: Add handler to sync search inputs and launch the ClickTripz Tabbed Window
/**
* Define Variables
* @type {null}
*/
var dateInterval = null;
/**
* Prepops
*/
function prePop() {
_ctPrepop();
}
/**
* Functions to sync values
* @constructor
*/
function SyncFields() {
var city = $('#city').val();
var checkIn = $('#date1').val();
var checkOut = $('#date2').val();
var guests = null;
var rooms = null;
if (this.BrowserIsIE()) {
guests = parseInt($('#guests').val()) + 1;
rooms = parseInt($('#rooms').val()) + 1;
} else {
guests = parseInt($('#guests option:selected').text());
rooms = parseInt($('#rooms option:selected').text());
}
$('#ctCity').val(city);
$('#ctDate1').val(checkIn);
$('#ctDate2').val(checkOut);
$('#ctGuests').val(guests);
$('#ctRooms').val(rooms);
}
function RedrawCT() {
_ctq.push(['a.draw']);
}
/**
* Set up real time sync event handlers
*/
$('#city, #guests, #rooms').change(function () {
SyncFields();
RedrawCT();
});
// Special handing of dates
$('#date1, #date2').focusout(function () {
if (dateInterval === null) {
SyncDatesWhenReady();
}
});
/**
* Date processing
* @constructor
*/
function SyncDatesWhenReady() {
dateInterval = setInterval(function () {
SyncFields();
ClearDateInterval();
}, 300);
}
function ClearDateInterval() {
if (dateInterval !== null) {
clearInterval(dateInterval);
dateInterval = null;
}
}
/**
* Browser detect
* @returns {boolean}
* @constructor
*/
function BrowserIsChrome() {
return this.BrowserIsWebkit() && (navigator.userAgent.toLowerCase().indexOf('chrome') > -1);
};
function BrowserIsFF4Plus() {
return !(typeof window.mozPaintCount == "undefined");
};
function BrowserIsWebkit() {
return /webkit/i.test(navigator.userAgent);
};
function BrowserIsIE() {
return /msie/i.test(navigator.userAgent) || /(trident)\/([\w.]+)/i.test(navigator.userAgent);
};
function BrowserIsIE11Plus() {
return this.BrowserIsIE() && (/(trident)\/7/i.test(navigator.userAgent) || !(window.ActiveXObject));
};
function BrowserIsSafari() {
return navigator.userAgent.indexOf("Safari") > -1;
};
/**
* Submit form
*/
$(document)
.on('focusout', '#date1, #date1 + .ui-datepicker-trigger', prePop)
.on('click', '#search-button', function () {
SyncFields();
if ($('#hotelSmallSearchForm:not(:submit)').isFilled()) {
_ctq.push(['a.processSubmit']);
} else {
console.log('There are empty fields');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment