Created
March 2, 2013 21:01
-
-
Save thinkphp/5073272 to your computer and use it in GitHub Desktop.
Instagram Search based on cuba.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function(){ | |
| var timer; | |
| function instaSearch() { | |
| //add loading | |
| cuba.select("#s").addClass("loading") | |
| var q = cuba.select("#s").value[0].value | |
| var url = "proxy.php?q=" + q; | |
| cuba.ajax("GET", url, function( data ){ | |
| //eval JSON received from proxy.php | |
| data = eval("(" + data + ")"); | |
| //remove the loading | |
| cuba.select("#s").removeClass("loading") | |
| //define an empty variable | |
| var output = ''; | |
| //loop through each object and assemble the result | |
| cuba.each(data, function(item, i) { | |
| output += '<div class="p"><a href="'+data[i].src+'" class="fullsize" target="_blank"><img src="full-image.png" alt="fullsize"></a> <a href="'+data[i].url+'" target="_blank"><img src="'+data[i].thumb+'"></a></div>'; | |
| }); | |
| //insert the result to the container | |
| cuba.select("#photos").html( output ); | |
| }) | |
| } | |
| /** | |
| * keycode glossary | |
| * 32 = SPACE | |
| * 188 = COMMA | |
| * 189 = DASH | |
| * 190 = PERIOD | |
| * 191 = BACKSLASH | |
| * 13 = ENTER | |
| * 219 = LEFT BRACKET | |
| * 220 = FORWARD SLASH | |
| * 221 = RIGHT BRACKET | |
| */ | |
| cuba.select("#s").on("keydown",function( e ){ | |
| if(e.keyCode == '32' || e.keyCode == '188' || e.keyCode == '189' || e.keyCode == '13' || e.keyCode == '190' || e.keyCode == '219' || e.keyCode == '221' || e.keyCode == '191' || e.keyCode == '220') { | |
| e.preventDefault(); | |
| } else { | |
| clearTimeout(timer); | |
| timer = setTimeout(function() { | |
| instaSearch(); | |
| }, 900); | |
| } | |
| }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment