$(document).ready(function () { $('.saveitem').on('click', function(e) { e.preventDefault(); $("#alertModal").modal("show"); }); $("input:file").change(function() { var imageFile = this.files[0]; var url = window.URL.createObjectURL(imageFile); $('#photo-src').attr('src', url); }); //Lazy Load Images ; (function ($) { $.fn.unveil = function (threshold, callback) { var $w = $(window), th = threshold || 0, retina = window.devicePixelRatio > 1, attrib = retina ? "data-src-retina" : "data-src", images = this, loaded; this.one("unveil", function () { var source = this.getAttribute(attrib); source = source || this.getAttribute("data-src"); if (source) { this.setAttribute("src", source); if (typeof callback === "function") callback.call(this); } }); function unveil() { var inview = images.filter(function () { var $e = $(this); if ($e.is(":hidden")) return; var wt = $w.scrollTop(), wb = wt + $w.height(), et = $e.offset().top, eb = et + $e.height(); return eb >= wt - th && et <= wb + th; }); loaded = inview.trigger("unveil"); images = images.not(loaded); } $w.on("scroll.unveil resize.unveil lookup.unveil", unveil); unveil(); return this; }; })(window.jQuery || window.Zepto); $("img").unveil(500); var isMobile = window.matchMedia("only screen and (max-width: 760px)"); $(document).on("click", ".savetotrip", function () { var itemId = $(this).data('id'); $(".modal-body #item").val(itemId); }); $(".save").on("click", function (e) { e.preventDefault(); var gotourl = $(this).attr("href") + "&item_id=" + $(".modal-body #item").val(); $.ajax({ type: "GET", url: gotourl, async: false, success: function (text) { $('.modal-body').html("Saved to Trip!"); $('#trip-modal').modal('hide'); } }); }); if (isMobile.matches == true) { $('.nav a').on('click', function () { $(".btn-navbar").click(); $(".navbar-toggle").click(); }); } $('#top-search-form').submit(function (e) { e.preventDefault(); var keyword = encodeURI($("#k").val().split("-").join("~").split(" ").join("-")); window.location = 'https://www.tripgrab.com/in/' + keyword + ".htm"; }); $('#mobile-search-form').submit(function (e) { e.preventDefault(); var keyword = encodeURI($("#m-k").val().split("-").join("~").split(" ").join("-")); window.location = 'https://www.tripgrab.com/in/' + keyword + ".htm"; }); $('#search-form').submit(function (e) { e.preventDefault(); var keyword = encodeURI($("#i-k").val().split("-").join("~").split(" ").join("-")); window.location = 'https://www.tripgrab.com/in/' + keyword + ".htm"; }); $('#save-trip').on('click', function (e) { e.preventDefault(); var gotourl = "https://www.tripgrab.com/tools/add-a-trip.php?trip_name=" + encodeURIComponent($('#name').val()); $.ajax({ type: "GET", url: gotourl, async: false, success: function (text) { $('#tripModal').modal('hide'); } }); }); $('.delete-trip').on('click', function (e) { e.preventDefault(); var gotourl = $(this).attr("href"); $.ajax({ type: "GET", url: gotourl, async: false, success: function (text) { location.reload(); } }); }); $('.remove').on('click', function (e) { e.preventDefault(); var gotourl = $(this).attr("href"); $.ajax({ type: "GET", url: gotourl, async: false, success: function (text) { location.reload(); } }); }); $('.savetrip').on('click', function (e) { e.preventDefault(); var gotourl = $(this).attr('data-href'); $.ajax({ type: "GET", url: gotourl, async: false, success: function (text) { } }); if (gotourl.indexOf("delete_id") >= 0) { $(this).parent().html('Removed!'); } else { $(this).parent().html('Saved!'); } }); $('#addtag').on('click', function (e) { e.preventDefault(); var response = ''; var gotourl = $(this).attr('data-href') + "&tag=" + encodeURI($('#tag').val()); $.ajax({ type: "GET", url: gotourl, async: false, success: function (text) { $('#addtag').hide(); $('.tagit').html("Thanks for Tagging!"); } }); }); $("#my-trips, #trending-destinations, #luxury-travel, #adventure-travel, #family-travel, #tag-travel").touchCarousel({ pagingNav: false, snapToItems: false, itemsPerMove: 4, scrollToLast: false, loopItems: false, scrollbar: false }); $(".replace-button").on("click", function (e) { var src = $(this).attr("data-src"); $("#replaceModal iframe").attr("src", src); }); $(".delete-button").on("click", function (e) { var src = $(this).attr("data-src"); $("#replaceModal iframe").attr("src", src); }); $("#thumbs-up").on("click", function (e) { var gotourl = "https://www.tripgrab.com/tools/thumbsup.php?id="; $.ajax({ type: "GET", url: gotourl, async: false, success: function (text) { var new_thumbed = $("#thumbed").html() * 1 + text * 1; $("#thumbed").html(new_thumbed); } }); }); $('#toggle-button').click(function () { var window_width = $(window).width(); if (window_width > 768) { var toggleWidth = ($("#menu").css("width") == "450px") ? "0" : "450px"; var toggleLeft = ($("#toggle-button").css("left") == "404px") ? "-41px" : "404px"; var togglePanelLeft = ($("#panel").css("margin-left") == "480px") ? "0" : "480px"; $('#menu').animate({ width: toggleWidth }, 300); $("#toggle-button").animate({ left: toggleLeft }, 300); $("#panel").animate({ marginLeft: togglePanelLeft }, 300); } else { var toggleWidth = ($("#menu").css("width") == "310px") ? "0" : "310px"; var togglePanelLeft = ($("#panel").css("margin-left") == "310px") ? "0" : "310px"; $('#menu').animate({ width: toggleWidth }, 300); $("#menu").show(); $("#panel").animate({ marginLeft: togglePanelLeft }, 300); } $(window).trigger('resize'); }); var $animThumb = $('#animated-thumbnails'); if ($animThumb.length) { $animThumb.justifiedGallery({ border: 6 }).on('jg.complete', function () { $animThumb.lightGallery({ thumbnail: true, thumbWidth: 120, thumbContHeight: 50 }); }); }; $('#loginWindow').on('click', function(e) { var myWindow = window.open("https://www.tripgrab.com/login/login.php", "MsgWindow", "width=400,height=200"); }); $('button.callModal').on('click', function(e) { var src = $(this).attr('data-src'); var height = $(this).attr('data-height') || 300; var width = $(this).attr('data-width') || 400; $(".modal iframe").attr({'src':src, 'height': height, 'width': width}); }); });