// Bing image searcher // example code from // https://dev.cognitive.microsoft.com/docs/services/56b43f0ccf5ff8098cef3808/operations/571fab09dbe2d933e891028f var urls = []; var srcUrl; var myImg, myId; var minImgWidth = '35%'; var srcImgTops = []; var buttonScreen = false; // ---------------------------------------------------------------------------------------- // code from http://www.dwuser.com/education/content/creating-a-jquery-image-scroller/ $(function(){ // -------------------------------------------------------------------- // begin bing results image scroller code function bingFlower(){ var scrollerB = $('#feedbackBScroller div.innerScrollAreaB'); var scrollerContentB = scrollerB.children('ul'); // scrollerContent.children().clone().appendTo(scrollerContent); var curYB = 0; // need to intervene here during scale scrollerContentB.children().each(function (index){ // console.log("flowing bings " + index); var $this = $(this); $this.css("top", curYB); curYB += $this.outerHeight(true); }); var fullHB = curYB / 2; var viewportHB = scrollerB.height(); scrollerB.css('overflow-y', 'auto'); } // end bing results image scroller // -------------------------------------------------------------------- // -------------------------------------------------------------------- // bind functions to search buttons $("#bingGo").on("click", doBingSearch); $("#googGo").on("click", doGoogSearch); $(".instructionsDiv").on("click", function(){$(this).css({"display":"none"});}); // -------------------------------------------------------------------- // begin source image scroller code var scroller = $('#scroller div.innerScrollArea'); var scrollerContent = scroller.children('ul'); // scrollerContent.children().clone().appendTo(scrollerContent); var curY = 0; // need to intervene here during scale scrollerContent.children().each(function reFlowScroller(){ var $this = $(this); $this.css("top", curY); curY += $this.outerHeight(true); }); var fullH = curY / 2; var viewportH = scroller.height(); scroller.css('overflow-y', 'auto'); // end source image scroller // -------------------------------------------------------------------- // -------------------------------------------------------------------- // begin image zoom code // add click zoom to the source images $("[id|=img]").on("click", growIt); // click zoom function function growIt() { // get the src url from the image clicked srcUrl = $( this ).attr("src"); console.log(srcUrl); function sizedUp() { // called when sizing up is complete $("#feedbackBScroller").css({ "position": "absolute", "display":"inline-block", // "left":"45%", // "top":$(myImg).position().top }); // show buttons $(".bing").css({"display": "inline-block"}); // $(".goog").css({"display": "inline-block"}); // fade out other images $(".innerScrollArea ul li img").not(".selected").fadeTo(200, 0.2); console.log('sized up'); // buttonScreen = true; } function sizedDown() { // called when sizing down is complete // report console.log('sized down'); // invisible the feedback div // $(".feedbackG").css({"display":"none"}); $("#feedbackBScroller").css({"display":"none"}); $(".bing").css({"display": "none"}); // $(".goog").css({"display": "none"}); buttonScreen = false; // invisible the results images $("[id|=result]").css({"display":"none"}); // clear the Urls array for the next query urls = []; // reenable scrolling of source images scroller.css('overflow-y', 'auto'); myImg.removeClass("selected"); // fade in other images $(".innerScrollArea ul li img").not(".selected").fadeTo(200, 1); // remove the results images $("#feedbackBScroller div.innerScrollAreaB ul").children().remove(); console.log(buttonScreen); } // shrink the rest, if clicked on a different one $( ".sourceImageClass" ).each(function() { $(".bing").css({"display": "none"}); // $(".goog").css({"display": "none"}); // buttonScreen = false; var newImg = $(this); console.log("newImgW = "+ newImg.css("width") + ", minImgw = "+ minImgWidth); // if (newImg.width() > minImgWidth) { if (newImg.css("width") > minImgWidth) { newImg.animate({width: minImgWidth, height: "auto"}, 800); sizedDown(); console.log("other scale down, "+ buttonScreen); } }); // grow this one, if clicked on this one $(this).addClass("selected"); myImg = $(this); console.log("target width = " + Math.floor($(".innerScrollArea").innerWidth()*0.85) + ";, myImg.width = "+ Math.floor(myImg.width())); if (myImg.width() < Math.floor($(".innerScrollArea").innerWidth()*0.85)) { myImg.animate({width: Math.floor($(".innerScrollArea").innerWidth()*0.85), height: "auto"}, 800, sizedUp); } else { // if on 'buttons' screen // if(buttonScreen === true) { myImg.animate({width: minImgWidth, height: "auto"}, 800); sizedDown(); console.log("btn "+ buttonScreen); } } // end image zoom // -------------------------------------------------------------------- // -------------------------------------------------------------------- // begin bing search code function doBingSearch() { // make the button invisible $(".bing").css({"display": "none"}); // $(".goog").css({"display": "none"}); // buttonScreen = false; // scroll my image to the top $(".innerScrollArea").animate({scrollTop: myImg.position().top}); // disable scrolling for now // (to be reenabled when?) scroller.css('overflow-y', 'hidden'); console.log("searching ..."); console.log("src = " + srcUrl); doAjax(); } function doAjax() { $.ajax({ // url: "https://api.cognitive.microsoft.com/bing/v5.0/images/search?" + $.param(params), // url: "https://api.cognitive.microsoft.com/bing/v5.0/images/search?modulesRequested=SimilarImages&imgUrl=http://sorrystate.org/penny/penny-blend-v01/penny-img/folder01/02.JPG", url: 'https://api.cognitive.microsoft.com/bing/v5.0/images/search?modulesRequested=SimilarImages&imgUrl=' + srcUrl, beforeSend: function (xhrObj) { // Request headers xhrObj.setRequestHeader('Access-Control-Allow-Origin', '*'); xhrObj.setRequestHeader('Content-Type', 'multipart/form-data'); xhrObj.setRequestHeader('Ocp-Apim-Subscription-Key', window.apiKey); }, // dataType: "JSON", type: 'GET', // Request body // data: "{body}" }) .done(function (data) { console.log('success'); // console.log(data); var myItem, resultDiv, $image, $downloadingImage; // var $images = []; for (var i = 0; i < data.visuallySimilarImages.length; i++) { myItem = data.visuallySimilarImages[i].contentUrl; urls.push(myItem); // this bit needs modification $(".innerScrollAreaB ul").append( '